From 4a1b311c007ab30ab6911474d41e0d2b5d42adad Mon Sep 17 00:00:00 2001 From: FreeArtMan Date: Thu, 22 Oct 2015 17:20:12 +0100 Subject: test/sdr_fm added initial fm support, too much noise, bit possible to recognise station --- test/sdr_fm.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 79 insertions(+), 9 deletions(-) (limited to 'test') diff --git a/test/sdr_fm.c b/test/sdr_fm.c index 7d99f10..97c3a4a 100644 --- a/test/sdr_fm.c +++ b/test/sdr_fm.c @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -11,8 +12,8 @@ #define SAMPLE_RATE 1000000 #define RESAMPLE_RATE 50000 -#define CENTER_FREQ 446500000 -#define FFT_LEVEL 10 +#define CENTER_FREQ 101100000 +#define FFT_LEVEL 12 #define FFT_SIZE (1 << FFT_LEVEL) #define SAMPLE_LENGHT (2 * FFT_SIZE) #define PRESCALE 8 @@ -167,13 +168,39 @@ void rotate_90(uint8_t *buf, uint32_t len) } } +float to_float(uint8_t x) { + return (1.0f/127.0f)*(((float)x)-127.0f); +} + +//float ph_ch( uint8_t i1, uint8_t q1, uint8_t i2, uint8_t q2) +float ph_ch( uint8_t i1, uint8_t q1 ) +{ + static float complex last=CMPLXF(0.0f, 0.0f); + float out; + float complex xy,c1; + //float c2; + + //c1 = to_float(i1) + I*to_float(q1); + c1 = CMPLXF( to_float(i1), to_float(q1) ); + //c2 = to_float(i2) + I*to_float(q2); + //c2 = CMPLXF( to_float(i2), to_float(q2) ); + xy = conjf(last)*c1; + out = cargf( xy ); + last = c1; + + return out; +} + int main( int argc, char **argv ) { int c; int ret; + int i,j,m; - uint8_t *buf, *sample_buf; + uint8_t *buf, *sample_buf; + float *fbuf; + signed short *sound_buf; int buf_len, sample_len; //commandline config params @@ -232,28 +259,71 @@ int main( int argc, char **argv ) 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 ); + ret != dongle_set_agc( dongle, 10 ); if (ret != 0) { printf("Cannot properly config device\n"); } sample_len = SAMPLE_LENGHT; - sample_buf = malloc( sample_len ); + sample_buf = malloc( SAMPLE_LENGHT ); + fbuf = malloc( SAMPLE_LENGHT*sizeof(float) ); + sound_buf = malloc( (SAMPLE_LENGHT/20)*sizeof(signed short) ); while ( 1 ) { //read plain samples - dongle_read_samples( dongle, sample_buf, sample_len ); + dongle_read_samples( dongle, sample_buf, SAMPLE_LENGHT ); + //convert data to float + //for ( i=0; i