Advertisement
stiansjogren

generatesignal.c

Jun 3rd, 2016
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.32 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4. #include "complex.h"
  5.  
  6. //#define M_PI 3.141592653
  7. void gen_sig(float *sig, int size);
  8.  
  9. void g_sig(struct complex *data, struct complex32 *data32, struct complex16 *data16,int size, const double foff, const double FS);
  10.  
  11. int main(){
  12.     const int size = 307200;
  13.     const double FS = 30.72e6;
  14.     const double foff = 200; // 200 Hz
  15.     printf("%d\n", size);
  16.     float sig[size];
  17.     struct complex *data;
  18.     struct complex32 *data32;
  19.     struct complex16 *data16;
  20.  
  21.     //data   = malloc(sizeof(struct complex));
  22.    // data32 = malloc(sizeof(struct complex32));
  23.     //data16 = malloc(sizeof(struct complex16));
  24.  
  25.     printf("FS: %f\n" ,FS);
  26.     if ((data=malloc(sizeof(struct complex)*(size_t)size))==NULL)
  27.     {
  28.       fprintf(stderr, "Out of memory!\n");
  29.       exit(1);
  30.     }
  31.  
  32.   if ((data16=malloc(sizeof(struct complex16)*(size_t)size))==NULL)
  33.     {
  34.       fprintf(stderr, "Out of memory!\n");
  35.       exit(1);
  36.     }
  37.  
  38.   if ((data32=malloc(sizeof(struct complex32)*(size_t)size))==NULL)
  39.     {
  40.       fprintf(stderr, "Out of memory!\n");
  41.       exit(1);
  42.     }
  43.  
  44.  
  45.     g_sig(data,data32, data16, size, foff,FS);
  46.  
  47. return 0;
  48. }
  49.  
  50. void g_sig(struct complex *data, struct complex32 *data32, struct complex16 *data16,int size, const double foff, const double FS){
  51.  
  52.     int write = 0;
  53.     // Generating a table got 100 MHz channel
  54.     int cp0 = 160; // First cyclic prefix
  55.     int cp  = 144; // Normal cyclic prefix
  56.     int cpe = 512; // Extended cyclic prefix
  57.     int deltaF = 200; //Hz
  58.     int ofdm_size = 2048;
  59.     int j;
  60.     /*for (j=0; j<size;j++){
  61.         data[j].r = 0.0    
  62.         data[j].r = 0.0    
  63.         data16[j].r = 0.0  
  64.         data16[j].r = 0.0  
  65.         data32[j].r = 0.0  
  66.         data32[j].r = 0.0  
  67.  
  68.     }
  69.     */
  70.  
  71.     for (int k=0;k<size;k++){
  72.         data[k].r = cos(2*M_PI*foff*(double)k/FS);//Is is Mhz on this line;
  73.         data[k].i = sin(2*M_PI*foff*(double)k/FS);
  74.         //printf("%f\n" ,data[k].r);
  75.     }
  76.  
  77.     printf("%f\n" ,data[2000].r*(1<<15));
  78.  
  79.     //printf("%d",(1<<15));
  80.     //Truncate data to fixed-point representation
  81.     // I've used 16 and 32 bits representation,
  82.     for (j=0; j<size;j++){
  83.         data16[j].r = (short)(data[j].r*(1<<15)-1);
  84.         data16[j].i = (short)(data[j].i*(1<<15)-1);
  85.         data32[j].r = (int)(data[j].r*(1<<15)-1);
  86.         data32[j].i = (int)(data[j].i*(1<<15)-1);
  87.         printf("%d\n %d\n", data32[j].r, data32[j].i);
  88.         printf("%hd\n %hd\n", data16[j].r, data16[j].i);
  89.  
  90.     }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement