Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- #include "complex.h"
- #define FS 32.78 *pow(10,6)
- void gen_sig(float *sig, int size);
- void g_sig(struct complex *data, struct complex32 *data32, struct complex16 *data16,int size);
- int main(){
- const int size = 307200;
- 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);
- return 0;
- }
- void g_sig(struct complex *data, struct complex32 *data32, struct complex16 *data16,int size){
- int write = 0;
- int j;
- // 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;
- for (j=0;j<size;j++){
- data[j].r = cos(20*pow(10,6)*j/FS);//Is is Mhz on this line;
- data[j].i = sin(20*pow(10,6)*j/FS);
- }
- //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("%f\n %f\n", data16[j].r, data16[j].i);
- }
- }
- void gen_sig(float *sig, int size){
- 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;
- if (write){ //write to file.txt
- FILE *f;
- f = fopen("file.txt", "w");
- if(f==NULL){
- exit(1);
- }
- fprintf(f, "x[%d]={ ", size);
- for (int i=1;i<size; i+=2){
- sig[i-1] = sin(20*i/FS);
- sig[i] = cos(20*i/FS);
- fprintf(f, "%f, ", sig[i-1]);
- }
- fprintf(f,"}; \n");
- }
- for (int i=1;i<size; i+=2){
- sig[i-1] = sin(20*i/FS);
- sig[i] = cos(20*i/FS);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement