1 //
2 //
3 //
4 
5 #include <stdio.h>
6 #include <math.h>
7 #include <string.h>
8 
9 #include "liquid.h"
10 
11 #define OUTPUT_FILENAME "ofdmframegen_example.m"
12 
main()13 int main() {
14     // options
15     unsigned int num_subcarriers=64;//
16     unsigned int cp_len=16;         // cyclic prefix length
17     //unsigned int num_symbols=2;     // number of ofdm symbols
18 
19     //
20     unsigned int frame_len = num_subcarriers + cp_len;
21 
22     //unsigned int num_samples = num_subcarriers * num_frames;
23 
24     // create synthesizer/analyzer objects
25     ofdmframegen fg = ofdmframegen_create(num_subcarriers, cp_len);
26     ofdmframegen_print(fg);
27 
28     FILE*fid = fopen(OUTPUT_FILENAME,"w");
29     fprintf(fid,"%% %s: auto-generated file\n\n", OUTPUT_FILENAME);
30     fprintf(fid,"clear all;\nclose all;\n\n");
31     fprintf(fid,"num_subcarriers=%u;\n", num_subcarriers);
32     fprintf(fid,"cp_len=%u;\n", cp_len);
33     fprintf(fid,"frame_len=%u;\n", frame_len);
34 
35     fprintf(fid,"X = zeros(1,num_subcarriers);\n");
36     fprintf(fid,"x = zeros(1,frame_len);\n");
37 
38     unsigned int i;
39     float complex X[num_subcarriers];   // channelized symbols
40     float complex x[frame_len];         // time-domain samples
41 
42     for (i=0; i<num_subcarriers; i++) {
43         X[i] = i==4 ? 0.707f + _Complex_I*0.707f : 0.0f;
44     }
45 
46     ofdmframegen_execute(fg,X,x);
47 
48     //
49     for (i=0; i<num_subcarriers; i++)
50         fprintf(fid,"X(%3u) = %12.4e + j*%12.4e;\n", i+1, crealf(X[i]), cimagf(X[i]));
51 
52     //
53     for (i=0; i<frame_len; i++)
54         fprintf(fid,"x(%3u) = %12.4e + j*%12.4e;\n", i+1, crealf(x[i]), cimagf(x[i]));
55 
56     // print results
57     fprintf(fid,"\n\n");
58     fprintf(fid,"figure;\n");
59     fprintf(fid,"t=0:(frame_len-1);\n");
60     fprintf(fid,"plot(t,real(x),t,imag(x));\n");
61 
62     fclose(fid);
63     printf("results written to %s\n", OUTPUT_FILENAME);
64 
65     // destroy objects
66     ofdmframegen_destroy(fg);
67 
68     printf("done.\n");
69     return 0;
70 }
71 
72