From: drowe67 Date: Mon, 21 Jul 2014 10:50:21 +0000 (+0000) Subject: fdmdv stm32f4 UT working. mod fast enough but demod too slow, have traced to filtering. X-Git-Url: http://git.whiteaudio.com/gitweb/?a=commitdiff_plain;h=61d231d2bc04e5e0d7b5284d8a75af4bdedc97d2;p=freetel-svn-tracking.git fdmdv stm32f4 UT working. mod fast enough but demod too slow, have traced to filtering. git-svn-id: https://svn.code.sf.net/p/freetel/code@1767 01035d8c-6547-0410-b346-abe4f91aad63 --- diff --git a/codec2-dev/src/fdmdv.c b/codec2-dev/src/fdmdv.c index 0498aea0..cd117d77 100644 --- a/codec2-dev/src/fdmdv.c +++ b/codec2-dev/src/fdmdv.c @@ -45,10 +45,15 @@ #include "kiss_fft.h" #include "hanning.h" #include "os.h" +#include "machdep.h" static int sync_uw[] = {1,-1,1,-1,1,-1}; -/*---------------------------------------------------------------------------* \ +#ifdef __EMBEDDED__ +#define printf gdb_stdio_printf +#endif + +/*---------------------------------------------------------------------------*\ FUNCTIONS @@ -521,11 +526,16 @@ void fdmdv_mod(struct FDMDV *fdmdv, COMP tx_fdm[], int tx_bits[], int *sync_bit) { COMP tx_symbols[NC+1]; COMP tx_baseband[NC+1][M]; + TIMER_VAR(mod_start, tx_filter_start, fdm_upconvert_start); + TIMER_SAMPLE(mod_start); bits_to_dqpsk_symbols(tx_symbols, fdmdv->Nc, fdmdv->prev_tx_symbols, tx_bits, &fdmdv->tx_pilot_bit, fdmdv->old_qpsk_mapping); memcpy(fdmdv->prev_tx_symbols, tx_symbols, sizeof(COMP)*(fdmdv->Nc+1)); + TIMER_SAMPLE_AND_LOG(tx_filter_start, mod_start, " bits_to_dqpsk_symbols"); tx_filter(tx_baseband, fdmdv->Nc, tx_symbols, fdmdv->tx_filter_memory); + TIMER_SAMPLE_AND_LOG(fdm_upconvert_start, tx_filter_start, " tx_filter"); fdm_upconvert(tx_fdm, fdmdv->Nc, tx_baseband, fdmdv->phase_tx, fdmdv->freq); + TIMER_SAMPLE_AND_LOG2(fdm_upconvert_start, " fdm_upconvert"); *sync_bit = fdmdv->tx_pilot_bit; } @@ -910,6 +920,7 @@ void down_convert_and_rx_filter(COMP rx_filt[NC+1][P+1], int Nc, COMP rx_fdm[], float windback_phase, mag; COMP windback_phase_rect; COMP rx_baseband[NFILTER+M]; + TIMER_VAR(windback_start, downconvert_start, filter_start); /* update memory of rx_fdm */ @@ -933,10 +944,12 @@ void down_convert_and_rx_filter(COMP rx_filt[NC+1][P+1], int Nc, COMP rx_fdm[], phase continuity. */ + TIMER_SAMPLE(windback_start); windback_phase = -freq_pol[c]*NFILTER; windback_phase_rect.real = cosf(windback_phase); windback_phase_rect.imag = sinf(windback_phase); phase_rx[c] = cmult(phase_rx[c],windback_phase_rect); + TIMER_SAMPLE_AND_LOG(downconvert_start, windback_start, " windback"); /* down convert all samples in buffer */ @@ -948,6 +961,7 @@ void down_convert_and_rx_filter(COMP rx_filt[NC+1][P+1], int Nc, COMP rx_fdm[], phase_rx[c] = cmult(phase_rx[c], freq[c]); rx_baseband[i] = cmult(rx_fdm_mem[i],cconj(phase_rx[c])); } + TIMER_SAMPLE_AND_LOG(filter_start, downconvert_start, " downconvert"); /* now we can filter this carrier's P symbols */ @@ -959,6 +973,7 @@ void down_convert_and_rx_filter(COMP rx_filt[NC+1][P+1], int Nc, COMP rx_fdm[], for(m=0; msync == 0) fdmdv->foff = foff_coarse; fdmdv_freq_shift(rx_fdm_fcorr, rx_fdm, -fdmdv->foff, &fdmdv->foff_phase_rect, *nin); - + TIMER_SAMPLE_AND_LOG(down_convert_and_rx_filter_start, fdmdv_freq_shift_start, " fdmdv_freq_shift"); + /* baseband processing */ down_convert_and_rx_filter(rx_filt, fdmdv->Nc, rx_fdm_fcorr, fdmdv->rx_fdm_mem, fdmdv->phase_rx, fdmdv->freq, fdmdv->freq_pol, *nin); + TIMER_SAMPLE_AND_LOG(rx_est_timing_start, down_convert_and_rx_filter_start, " down_convert_and_rx_filter"); fdmdv->rx_timing = rx_est_timing(rx_symbols, fdmdv->Nc, rx_filt, fdmdv->rx_filter_mem_timing, env, *nin); + TIMER_SAMPLE_AND_LOG(qpsk_to_bits_start, rx_est_timing_start, " rx_est_timing"); /* Adjust number of input samples to keep timing within bounds */ @@ -1398,11 +1420,14 @@ void fdmdv_demod(struct FDMDV *fdmdv, int rx_bits[], foff_fine = qpsk_to_bits(rx_bits, &sync_bit, fdmdv->Nc, fdmdv->phase_difference, fdmdv->prev_rx_symbols, rx_symbols, fdmdv->old_qpsk_mapping); memcpy(fdmdv->prev_rx_symbols, rx_symbols, sizeof(COMP)*(fdmdv->Nc+1)); + TIMER_SAMPLE_AND_LOG(snr_update_start, qpsk_to_bits_start, " qpsk_to_bits"); snr_update(fdmdv->sig_est, fdmdv->noise_est, fdmdv->Nc, fdmdv->phase_difference); + TIMER_SAMPLE_AND_LOG(freq_state_start, snr_update_start, " snr_update"); /* freq offset estimation state machine */ fdmdv->sync = freq_state(reliable_sync_bit, sync_bit, &fdmdv->fest_state, &fdmdv->timer, fdmdv->sync_mem); + TIMER_SAMPLE_AND_LOG2(freq_state_start, " freq_state"); fdmdv->foff -= TRACK_COEFF*foff_fine; } @@ -1425,8 +1450,8 @@ float calc_snr(int Nc, float sig_est[], float noise_est[]) S = 0.0; for(c=0; cNc; i++) - fprintf(stderr," %1.3f", cabsolute(f->phase_tx[i])); + fprintf(stderr," %1.3f", (double)cabsolute(f->phase_tx[i])); fprintf(stderr,"\nfreq[]:\n"); for(i=0; i<=f->Nc; i++) - fprintf(stderr," %1.3f", cabsolute(f->freq[i])); - fprintf(stderr,"\nfoff_phase_rect: %1.3f", cabsolute(f->foff_phase_rect)); + fprintf(stderr," %1.3f", (double)cabsolute(f->freq[i])); + fprintf(stderr,"\nfoff_phase_rect: %1.3f", (double)cabsolute(f->foff_phase_rect)); fprintf(stderr,"\nphase_rx[]:\n"); for(i=0; i<=f->Nc; i++) - fprintf(stderr," %1.3f", cabsolute(f->phase_rx[i])); + fprintf(stderr," %1.3f", (double)cabsolute(f->phase_rx[i])); fprintf(stderr, "\n\n"); } diff --git a/codec2-dev/stm32/Makefile b/codec2-dev/stm32/Makefile index 661b21aa..fcaea9a1 100644 --- a/codec2-dev/stm32/Makefile +++ b/codec2-dev/stm32/Makefile @@ -13,7 +13,7 @@ SIZE=$(BINPATH)/arm-none-eabi-size ################################################### -CFLAGS = -std=gnu99 -O0 -g -Wall -Tstm32_flash.ld -DSTM32F4XX -DCORTEX_M4 +CFLAGS = -std=gnu99 -O2 -g -Wall -Tstm32_flash.ld -DSTM32F4XX -DCORTEX_M4 CFLAGS += -mlittle-endian -mthumb -mthumb-interwork -nostartfiles -mcpu=cortex-m4 ifeq ($(FLOAT_TYPE), hard) diff --git a/codec2-dev/stm32/src/fdmdv_profile.c b/codec2-dev/stm32/src/fdmdv_profile.c index 2826b309..988152e4 100644 --- a/codec2-dev/stm32/src/fdmdv_profile.c +++ b/codec2-dev/stm32/src/fdmdv_profile.c @@ -48,14 +48,47 @@ #endif #define TEST_FRAMES 25 +#define CHANNEL_BUF_SIZE (10*FDMDV_NOM_SAMPLES_PER_FRAME) + +static int channel_count = 0; +static COMP channel[CHANNEL_BUF_SIZE]; + +static void channel_in(COMP tx_fdm[], int nout) { + int i; + + /* add M tx samples to end of buffer */ + + assert((channel_count + nout) < CHANNEL_BUF_SIZE); + for(i=0; i