stiansjogren icon

generatesignal.c

stiansjogren | PRO | 06/03/16 12:11:04 PM UTC | 0 ⭐ | 719 👁️ | Never ⏰ | []
C |

2.32 KB

|

None

|

0 👍

/

0 👎

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "complex.h"
 
//#define M_PI 3.141592653
void gen_sig(float *sig, int size);
 
void g_sig(struct complex *data, struct complex32 *data32, struct complex16 *data16,int size, const double foff, const double FS);
 
int main(){
    const int size = 307200;
    const double FS = 30.72e6;
    const double foff = 200; // 200 Hz
    printf("%d\n", size);
    float sig[size];
    struct complex *data;
    struct complex32 *data32;
    struct complex16 *data16;
 
    //data   = malloc(sizeof(struct complex));
   // data32 = malloc(sizeof(struct complex32));
    //data16 = malloc(sizeof(struct complex16));
 
    printf("FS: %f\n" ,FS);
    if ((data=malloc(sizeof(struct complex)*(size_t)size))==NULL)
    {
      fprintf(stderr, "Out of memory!\n");
      exit(1);
    }
 
  if ((data16=malloc(sizeof(struct complex16)*(size_t)size))==NULL)
    {
      fprintf(stderr, "Out of memory!\n");
      exit(1);
    }
 
  if ((data32=malloc(sizeof(struct complex32)*(size_t)size))==NULL)
    {
      fprintf(stderr, "Out of memory!\n");
      exit(1);
    }
 
 
    g_sig(data,data32, data16, size, foff,FS);
 
return 0;
}
 
void g_sig(struct complex *data, struct complex32 *data32, struct complex16 *data16,int size, const double foff, const double FS){
 
    int write = 0;
    // Generating a table got 100 MHz channel
    int cp0 = 160; // First cyclic prefix
    int cp  = 144; // Normal cyclic prefix
    int cpe = 512; // Extended cyclic prefix
    int deltaF = 200; //Hz
    int ofdm_size = 2048;
    int j;
    /*for (j=0; j<size;j++){
        data[j].r = 0.0     
        data[j].r = 0.0     
        data16[j].r = 0.0   
        data16[j].r = 0.0   
        data32[j].r = 0.0   
        data32[j].r = 0.0   
 
    }
    */
 
    for (int k=0;k<size;k++){
        data[k].r = cos(2*M_PI*foff*(double)k/FS);//Is is Mhz on this line;
        data[k].i = sin(2*M_PI*foff*(double)k/FS);
        //printf("%f\n" ,data[k].r);
    }
 
    printf("%f\n" ,data[2000].r*(1<<15));
 
    //printf("%d",(1<<15));
    //Truncate data to fixed-point representation
    // I've used 16 and 32 bits representation,
    for (j=0; j<size;j++){
        data16[j].r = (short)(data[j].r*(1<<15)-1);
        data16[j].i = (short)(data[j].i*(1<<15)-1);
        data32[j].r = (int)(data[j].r*(1<<15)-1);
        data32[j].i = (int)(data[j].i*(1<<15)-1);
        printf("%d\n %d\n", data32[j].r, data32[j].i);
        printf("%hd\n %hd\n", data16[j].r, data16[j].i);
 
    }
}

Comments