1 // 2 // asgramcf_example.c 3 // 4 // ASCII spectrogram example for complex inputs. This example demonstrates 5 // the functionality of the ASCII spectrogram. A sweeping complex sinusoid 6 // is generated and the resulting spectral periodogram is printed to the 7 // screen. 8 // 9 10 #include <unistd.h> // usleep 11 #include <string.h> 12 #include <stdio.h> 13 #include <math.h> 14 15 #include "liquid.h" 16 main()17int main() { 18 // options 19 unsigned int nfft = 64; // transform size 20 unsigned int num_frames = 200; // total number of frames 21 unsigned int msdelay = 50; // delay between transforms [ms] 22 float noise_floor = -40.0f; // noise floor 23 24 // initialize objects 25 asgramcf q = asgramcf_create(nfft); 26 asgramcf_set_scale(q, noise_floor+15.0f, 5.0f); 27 28 unsigned int i; 29 unsigned int n; 30 float theta = 0.0f; // current instantaneous phase 31 float dtheta = 0.0f; // current instantaneous frequency 32 float phi = 0.0f; // phase of sinusoidal frequency drift 33 float dphi = 0.003f; // frequency of sinusoidal frequency drift 34 35 float complex x[nfft]; 36 float nstd = powf(10.0f,noise_floor/20.0f); // noise standard deviation 37 for (n=0; n<num_frames; n++) { 38 // generate a frame of data samples 39 for (i=0; i<nfft; i++) { 40 // complex exponential 41 x[i] = cexpf(_Complex_I*theta); 42 43 // add noise to signal 44 x[i] += nstd * (randnf() + _Complex_I*randnf()) * M_SQRT1_2; 45 46 // adjust frequency and phase 47 theta += dtheta; 48 dtheta = 0.9f*M_PI*sinf(phi) * hamming(n, num_frames); 49 phi += dphi; 50 } 51 52 // write block of samples to the spectrogram object 53 asgramcf_write(q, x, nfft); 54 55 // print result to screen 56 asgramcf_print(q); 57 58 // sleep for some time before generating the next frame 59 usleep(msdelay*1000); 60 } 61 62 asgramcf_destroy(q); 63 printf("done.\n"); 64 return 0; 65 } 66 67