1 //
2 // symstreamcf_example.c
3 //
4
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <math.h>
8
9 #include "liquid.h"
10
11 #define OUTPUT_FILENAME "symstreamcf_example.m"
12
main()13 int main()
14 {
15 // symstream parameters
16 int ftype = LIQUID_FIRFILT_ARKAISER;
17 unsigned int k = 4;
18 unsigned int m = 9;
19 float beta = 0.30f;
20 int ms = LIQUID_MODEM_QPSK;
21
22 // spectral periodogram options
23 unsigned int nfft = 2400; // spectral periodogram FFT size
24 unsigned int num_samples = 80000; // number of samples
25
26 unsigned int i;
27
28 // create spectral periodogram
29 spgramcf periodogram = spgramcf_create_default(nfft);
30
31 unsigned int buf_len = 1024;
32 float complex buf[buf_len];
33
34 // create stream generator
35 symstreamcf gen = symstreamcf_create_linear(ftype,k,m,beta,ms);
36
37 unsigned int total_samples = 0;
38 while (total_samples < num_samples) {
39 // write samples to buffer
40 symstreamcf_write_samples(gen, buf, buf_len);
41
42 // push resulting sample through periodogram
43 spgramcf_write(periodogram, buf, buf_len);
44
45 // accumulated samples
46 total_samples += buf_len;
47 }
48 printf("total samples: %u\n", total_samples);
49
50 // compute power spectral density output
51 float psd[nfft];
52 spgramcf_get_psd(periodogram, psd);
53
54 // destroy objects
55 symstreamcf_destroy(gen);
56 spgramcf_destroy(periodogram);
57
58 //
59 // export output file
60 //
61 FILE * fid = fopen(OUTPUT_FILENAME,"w");
62 fprintf(fid,"%% %s : auto-generated file\n", OUTPUT_FILENAME);
63 fprintf(fid,"clear all;\n");
64 fprintf(fid,"close all;\n\n");
65 fprintf(fid,"nfft = %u;\n", nfft);
66 fprintf(fid,"f = [0:(nfft-1)]/nfft - 0.5;\n");
67 fprintf(fid,"H = zeros(1,nfft);\n");
68
69 for (i=0; i<nfft; i++)
70 fprintf(fid,"H(%6u) = %12.4e;\n", i+1, psd[i]);
71
72 fprintf(fid,"figure;\n");
73 fprintf(fid,"plot(f, H, '-', 'LineWidth',1.5);\n");
74 fprintf(fid,"xlabel('Normalized Frequency [f/F_s]');\n");
75 fprintf(fid,"ylabel('Power Spectral Density [dB]');\n");
76 fprintf(fid,"grid on;\n");
77 fprintf(fid,"axis([-0.5 0.5 -120 20]);\n");
78
79 fclose(fid);
80 printf("results written to %s.\n", OUTPUT_FILENAME);
81
82 printf("done.\n");
83 return 0;
84 }
85
86