gen_75KHz.cpp 2.71 KB
Newer Older
laurent's avatar
laurent committed
1 2 3 4 5 6 7 8 9 10
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <malloc.h>
#include <assert.h>
#include <complex>
#include <cmath>
#include <map>
#include <PHY/MODULATION/modulation_extern.h>
using namespace std;
laurent's avatar
laurent committed
11 12 13 14 15 16 17 18 19 20
extern "C" {
  void gen_sig(int RB, int len, double ratio, int16_t *table_n, int16_t *table_e ) {
    double samplerate = 30.72e6*ratio;
    double ofdm_size = 2048*ratio;
    double PI = std::acos(-1);
    std::complex<int> tt;
    complex<double> t[len];
    int index=0;
    double cp0 = 160*ratio;
    double cp = 144*ratio;
laurent's avatar
laurent committed
21

laurent's avatar
laurent committed
22
    for (int i=-cp0; i<ofdm_size; i++)
laurent's avatar
laurent committed
23
      t[index++] = polar( 32767.0, -2*PI*i*7.5e3/samplerate);
laurent's avatar
laurent committed
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44

    for(int x=0 ; x <6 ; x++)
      for (int i=-cp; i<ofdm_size; i++)
        t[index++] = polar( 32767.0, -2*PI*i*7.5e3/samplerate);

    for (int i=0; i < len ; i++) {
      table_n[i*2] = floor(real(t[i]));
      table_n[i*2+1] = floor(imag(t[i]));
    }

    index=0;
    double cpe = 512*ratio;

    for(int x=0 ; x <6 ; x++)
      for (int i=-cpe; i<ofdm_size; i++)
        t[index++] = polar( 32767.0, -2*PI*i*7.5e3/samplerate);

    for (int i=0; i < len ; i++) {
      table_e[i*2] = floor(real(t[i]));
      table_e[i*2+1] = floor(imag(t[i]));
    }
laurent's avatar
laurent committed
45 46
  }

laurent's avatar
laurent committed
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
  int16_t *s6n_kHz_7_5;
  int16_t *s6e_kHz_7_5;
  int16_t *s15n_kHz_7_5;
  int16_t *s15e_kHz_7_5;
  int16_t *s25n_kHz_7_5;
  int16_t *s25e_kHz_7_5;
  int16_t *s50n_kHz_7_5;
  int16_t *s50e_kHz_7_5;
  int16_t *s75n_kHz_7_5;
  int16_t *s75e_kHz_7_5;
  int16_t *s100n_kHz_7_5;
  int16_t *s100e_kHz_7_5;
  int16_t **tables[12]= {&s6n_kHz_7_5,&s6e_kHz_7_5,
                         &s15n_kHz_7_5,&s15e_kHz_7_5,
                         &s25n_kHz_7_5,&s25e_kHz_7_5,
                         &s50n_kHz_7_5,&s50e_kHz_7_5,
                         &s75n_kHz_7_5,&s75e_kHz_7_5,
                         &s100n_kHz_7_5,&s100e_kHz_7_5,
                        };
  int tables_size_bytes[12];
laurent's avatar
laurent committed
67
#define MyAssert(x) { if(!(x)) { printf("Error in table intialization: %s:%d\n",__FILE__,__LINE__); exit(1);}}
laurent's avatar
laurent committed
68 69 70
  void init_7_5KHz(void) {
    const map<int,double> tables_7_5KHz= {{6,1.0/16},{15,1.0/8},{25,1.0/4},{50,1.0/2},{75,3.0/4},{100,1.0}};
    int tables_idx=0;
laurent's avatar
laurent committed
71

laurent's avatar
laurent committed
72 73 74 75 76 77 78 79 80 81 82
    for (auto it=tables_7_5KHz.begin(); it!=tables_7_5KHz.end(); ++it) {
      int len=15360*it->second;
      tables_size_bytes[tables_idx]=sizeof(int16_t)*2*len;
      tables_size_bytes[tables_idx+1]=sizeof(int16_t)*2*len;
      MyAssert(0==posix_memalign((void **)tables[tables_idx],
                                 16,tables_size_bytes[tables_idx]));
      MyAssert(0==posix_memalign((void **)tables[tables_idx+1],
                                 16,tables_size_bytes[tables_idx+1]));
      gen_sig(it->first, len, it->second, *tables[tables_idx], *tables[tables_idx+1]);
      tables_idx+=2;
    }
laurent's avatar
laurent committed
83 84
  }
}