#include #include #include #include #include #include //radiola #include #include #include #define SAMPLE_RATE 2048000 #define CENTER_FREQ 446500000 #define FFT_LEVEL 10 #define FFT_SIZE (1 << FFT_LEVEL) #define SAMPLE_LENGHT (2 * FFT_SIZE) #define PRESCALE 8 #define POSTSCALE 2 int16_t* Sinewave; int N_WAVE, LOG2_N_WAVE; double* power_table; void helper( char *exec_name ) { const char help_str[]="Usage: ./%s [OPTIONS]\n\ -f [FREQ] - set center frequency\n\ -s [SAMPLE] - set sample rate\n\ -d [DEVICE] - choose device\n\ -? - print help\n\ "; printf( help_str, exec_name ); } //better to have size size mod olen == 0 int normalise( uint8_t *ibuf, int ilen, uint8_t *obuf, int olen ) { int i,j,m; int ppi; /* if ( ilen >= olen ) { ppi = ilen / olen; } else { return -1; } */ ppi = 1; m = 0; i = 0; while ( (i < ilen) && (m < olen) ) { uint32_t sum=0; for ( j=0; j> 14; b = c & 0x01; return (c >> 1) + b; } int32_t real_conj(int16_t real, int16_t imag) /* real(n * conj(n)) */ { return ((int32_t)real*(int32_t)real + (int32_t)imag*(int32_t)imag); } int fix_fft(int16_t iq[], int m) /* interleaved iq[], 0 <= n < 2**m, changes in place */ { int mr, nn, i, j, l, k, istep, n, shift; int16_t qr, qi, tr, ti, wr, wi; n = 1 << m; if (n > N_WAVE) {return -1;} mr = 0; nn = n - 1; /* decimation in time - re-order data */ for (m=1; m<=nn; ++m) { l = n; do {l >>= 1;} while (mr+l > nn); mr = (mr & (l-1)) + l; if (mr <= m) {continue;} // real = 2*m, imag = 2*m+1 tr = iq[2*m]; iq[2*m] = iq[2*mr]; iq[2*mr] = tr; ti = iq[2*m+1]; iq[2*m+1] = iq[2*mr+1]; iq[2*mr+1] = ti; } l = 1; k = LOG2_N_WAVE-1; while (l < n) { shift = 1; istep = l << 1; for (m=0; m>= 1; wi >>= 1;} for (i=m; i>= 1; qi >>= 1;} iq[2*j] = qr - tr; iq[2*j+1] = qi - ti; iq[2*i] = qr + tr; iq[2*i+1] = qi + ti; } } --k; l = istep; } return 0; } //fftize int simple_fft( uint8_t *buf, int len ) { int i,j; uint16_t p; uint16_t buf1[SAMPLE_LENGHT]; uint16_t buf2[SAMPLE_LENGHT]; int fft_len; for (i=0; idongle = NULL; goto main_exit; } dongle = sdr_get_device_id( sdr, config_device ); ret = 0; ret != dongle_set_freq( dongle, config_freq ); ret != dongle_set_sample_rate( dongle, config_sample_rate ); ret != dongle_set_gain( dongle, 0 ); ret != dongle_set_agc( dongle, 40 ); if (ret != 0) { printf("Cannot properly config device\n"); } sine_table( FFT_LEVEL ); //printf("%x\n",t); //open GUI if ( glui_init( &t ) == -1 ) { printf("Cannot set glui\n"); return 1; } //printf("%x\n",t); if ( glui_waterfall( &t, &w ) == -1 ) { printf("Cannot set waterfall\n"); return 1; } /* dev_num = rtlsdr_get_device_count(); if ( dev_num < 1 ) { printf( "Cannot find any device" ); goto main_exit; } */ //screen normilised buffer to draw buf_len = sizeof(char)*w->w; buf = malloc( buf_len ); sample_len = SAMPLE_LENGHT; sample_buf = malloc( sample_len ); srand(0); //fake seed for ( i=0; i<4000;i++ ) { //for (j=0; j