From 5e57f34f35416530ca6ea3424ef0818542f4d43c Mon Sep 17 00:00:00 2001 From: drowe67 Date: Sat, 21 Feb 2015 10:54:44 +0000 Subject: [PATCH] tuner code for downsampling to 10 kHz working OK, ready for tetsing on real signals git-svn-id: https://svn.code.sf.net/p/freetel/code@2043 01035d8c-6547-0410-b346-abe4f91aad63 --- codec2-dev/stm32/Makefile | 1 + codec2-dev/stm32/src/iir_tuner.c | 164 ++++++++++++++++++++++- codec2-dev/stm32/src/stm32f4_adc_tuner.c | 20 ++- codec2-dev/stm32/src/tuner_ut.c | 56 ++++++-- 4 files changed, 225 insertions(+), 16 deletions(-) diff --git a/codec2-dev/stm32/Makefile b/codec2-dev/stm32/Makefile index 8e5d822f..0ebb6c2a 100644 --- a/codec2-dev/stm32/Makefile +++ b/codec2-dev/stm32/Makefile @@ -354,6 +354,7 @@ fdmdv_dump_rt.elf: $(FDMDV_DUMP_RT_SRCS) src/stm32f4_dac.o src/stm32f4_adc.o TUNER_UT_SRCS=\ src/tuner_ut.c \ +gdb_stdio.c \ ../src/fifo.c \ src/stm32f4_dac.c \ src/iir_tuner.c \ diff --git a/codec2-dev/stm32/src/iir_tuner.c b/codec2-dev/stm32/src/iir_tuner.c index 05e6c209..334ff778 100644 --- a/codec2-dev/stm32/src/iir_tuner.c +++ b/codec2-dev/stm32/src/iir_tuner.c @@ -9,7 +9,7 @@ Unit testing: - ~/codec2-dev/stm32$ gcc -D__UNITTEST__ -Iinc src/iir_tuner.c -o iir_tuner -lm -Wal + ~/codec2-dev/stm32$ gcc -D__UNITTEST__ -Iinc src/iir_tuner.c -o iir_tuner -lm -Wall ~/codec2-dev/stm32$ ./iir_tuner \*---------------------------------------------------------------------------*/ @@ -56,7 +56,7 @@ float y_2, y_1, z_2, z_1; ADC -> signed conversion - IIR BPF - Decimate - FIR Equaliser -> FIFO */ -void iir_tuner(float dec_buf[], unsigned short adc_buf[]) { +void iir_tuner(float dec_50[], unsigned short adc_buf[]) { int i, j, k; float x, y, z; @@ -76,13 +76,30 @@ void iir_tuner(float dec_buf[], unsigned short adc_buf[]) { IIR BPF passband response */ z = y + BETA2*z_2; - dec_buf[j] = z; + dec_50[j] = z; z_2 = z_1; z_1 = y; } } +/* BPF at 12.5 kHz +/- 2000 Hz, and decimate down to Fs = 10kHz */ + +static float fir_50_to_10[]; +void iir_tuner_dec_50_to_10(float dec_10[], float dec_50[], int n) { + int i,j,k; + float acc; + + for(i=0,k=0; i Fs=10kHz short ---------------------------------------------*/ + + for(i=0; iODR = (1 << 0); + //#define DUMMY_SIGNAL + #ifdef DUMMY_SIGNAL + + /* Fs/4 sine wave, right in the middle of the pass band ! */ + + for(i=0; i +#include +#include "gdb_stdio.h" #include "stm32f4_dac.h" #include "stm32f4_adc_tuner.h" +#include "iir_tuner.h" #include "sm1000_leds_switches.h" +#define REC_TIME_SECS 10 +#define FS 50000 +#define N 10000 + +extern int adc_overflow1; + int main(void) { - float tuner_out[ADC_TUNER_N]; + float tuner_out[IIR_TUNER_DEC_50_10_FILT_MEM+N/2]; + float dec_10[(N/2)/5]; + short dec_10_short[(N/2)/5]; + int bufs, i, j, fifo_sz; + FILE *ftuner; - dac_open(4*DAC_BUF_SZ); - adc_open(4*ADC_TUNER_N); + ftuner = fopen("tuner.raw", "wb"); + if (ftuner == NULL) { + printf("Error opening input file: tuner.raw\n\nTerminating....\n"); + exit(1); + } + bufs = FS*REC_TIME_SECS/N; + fifo_sz = ((4*N/ADC_TUNER_N)+1)*ADC_TUNER_N; + printf("Starting! bufs: %d %d\n", bufs, fifo_sz); + + //dac_open(DAC_BUF_SZ); + adc_open(fifo_sz); sm1000_leds_switches_init(); - while (1) { + for(i=0; i