From cd6d55da23c3835b3a48fd04d8beb930a416190a Mon Sep 17 00:00:00 2001 From: baobrien Date: Sat, 19 Sep 2015 00:56:38 +0000 Subject: [PATCH] Added Stuart's patches for fifo/dac free test git-svn-id: https://svn.code.sf.net/p/freetel/code@2346 01035d8c-6547-0410-b346-abe4f91aad63 --- codec2-dev/octave/fsk4.m | 58 ++++++++++++++---------------- codec2-dev/src/codec2_fifo.h | 11 +++++- codec2-dev/src/fifo.c | 17 ++++----- codec2-dev/stm32/Makefile | 2 +- codec2-dev/stm32/inc/stm32f4_dac.h | 2 ++ codec2-dev/stm32/src/stm32f4_dac.c | 8 +++++ 6 files changed, 57 insertions(+), 41 deletions(-) diff --git a/codec2-dev/octave/fsk4.m b/codec2-dev/octave/fsk4.m index 75e58f10..4dc8081a 100644 --- a/codec2-dev/octave/fsk4.m +++ b/codec2-dev/octave/fsk4.m @@ -118,13 +118,8 @@ function bits = fsk4_demod_thing(fsk4_states, rx) [x iv] = max([sym1m; sym2m; sym3m; sym4m;]); bits = zeros(1,length(iv*2)); - iveven = iv(2:2:length(iv)); - ivodd = iv(1:2:length(iv)); figure(3); - hist(iveven); - figure(4); - hist(ivodd); - %iv = iveven; + hist(iv); for i=1:length(iv) bits(1+(i-1)*2:i*2) = [[1 1];[1 0];[0 1];[0 0]](iv(i),(1:2)); end @@ -143,10 +138,10 @@ function bits = fsk4_demod_two(fsk4_states,rx) t = (1:length(rx)); fsk4_symbols rx = filter(rx_filter, 1, rx); - sym1dc = exp(-j*2*pi*(fsk4_symbols(1)/Fs)*t) .* rx; - sym2dc = exp(-j*2*pi*(fsk4_symbols(2)/Fs)*t) .* rx; - sym3dc = exp(-j*2*pi*(fsk4_symbols(3)/Fs)*t) .* rx; - sym4dc = exp(-j*2*pi*(fsk4_symbols(4)/Fs)*t) .* rx; + sym1dc = exp(j*2*pi*(fsk4_symbols(1)/Fs)*t) .* rx; + sym2dc = exp(j*2*pi*(fsk4_symbols(2)/Fs)*t) .* rx; + sym3dc = exp(j*2*pi*(fsk4_symbols(3)/Fs)*t) .* rx; + sym4dc = exp(j*2*pi*(fsk4_symbols(4)/Fs)*t) .* rx; figure(1); %plot(t(1:20:length(t)),abs(idmp(sym1dc,20)),t(1:20:length(t)),abs(idmp(sym2dc,20))); @@ -184,38 +179,39 @@ function bits = fsk4_demod_two(fsk4_states,rx) hist(syms); endfunction + +%My fourth attempt at a 4fsk demodulator. Based on the same paper as the previous. +function bits = fsk4_demod_four(fsk4_states,rx) + +endfunction %incoherent demod loosly based on another paper. Works, more or less. % Paper is titled "Design and Implementation of a Fully Digital 4FSK Demodulator" function [bits err] = fsk4_demod_fmrid(fsk4_states, rx) rxd = analog_fm_demod(fsk4_states.fm_states,rx); - % rx_filt = filter(fsk4_states.tx_filter, 1, rxd); - rx_filt=rxd; - sym = afsym = idmp(rx_filt,fsk4_states.M/2); - + rx_filt = filter(fsk4_states.tx_filter, 1, rxd); + %rx_filt=rxd; + figure(1) + eyediagram(rxd,40); + sym = afsym = idmp(rx_filt,fsk4_states.M); + figure(4) + eyediagram(afsym,2); % Demod symbol map. I should probably figure a better way to do this. % After integrating, the high symbol tends to be about 7.5 - dmsyms = rot90(fsk4_states.symmap * 10); + dmsyms = rot90(fsk4_states.symmap * 20); oddsyms = afsym(1:2:length(afsym)); evensyms = afsym(2:2:length(afsym)); - hist(evensyms); - [errseven,deceven] = min(abs(evensyms - dmsyms)); - [errsodd ,decodd ] = min(abs(oddsyms - dmsyms)); - - terreven = mean(errseven); - terrodd = mean(errsodd ); - - if terreven < terrodd - sym = deceven; - err = errseven; - else - sym = decodd; - err = errsodd; - end + figure(2) + hist(evensyms,30); + + [err, sym] = min(abs(afsym-dmsyms)); + bits = zeros(1,length(sym)*2); %Translate symbols back into bits + figure(3) + hist(sym); for i=1:length(sym) bits(1+(i-1)*2:i*2) = [[1 1];[1 0];[0 1];[0 0]](sym(i),(1:2)); end @@ -247,8 +243,8 @@ function ber = nfbert(aEsNodB) nsam = length(tx); noise = sqrt(variance/2)*(randn(1,nsam) + j*randn(1,nsam)); rx = tx*exp(j*pi/2) + noise; - rx = rx(20:length(rx)); - rx_bits = fsk4_demod_thing(fsk4_states,rx); + rx = rx(10:length(rx)); + rx_bits = fsk4_demod_fmrid(fsk4_states,rx); ber = 1; %thing to account for offset from input data to output data diff --git a/codec2-dev/src/codec2_fifo.h b/codec2-dev/src/codec2_fifo.h index dc93e157..383254f6 100644 --- a/codec2-dev/src/codec2_fifo.h +++ b/codec2-dev/src/codec2_fifo.h @@ -42,7 +42,16 @@ struct FIFO *fifo_create(int nshort); void fifo_destroy(struct FIFO *fifo); int fifo_write(struct FIFO *fifo, short data[], int n); int fifo_read(struct FIFO *fifo, short data[], int n); -int fifo_used(struct FIFO *fifo); + +/*! + * Return the number of bytes stored in the FIFO. + */ +int fifo_used(const struct FIFO * const fifo); + +/*! + * Return the space available in the FIFO. + */ +int fifo_free(const struct FIFO * const fifo); #ifdef __cplusplus } diff --git a/codec2-dev/src/fifo.c b/codec2-dev/src/fifo.c index 566d77ab..d562a6ac 100644 --- a/codec2-dev/src/fifo.c +++ b/codec2-dev/src/fifo.c @@ -64,19 +64,13 @@ void fifo_destroy(struct FIFO *fifo) { int fifo_write(struct FIFO *fifo, short data[], int n) { int i; - int fifo_free; short *pdata; short *pin = fifo->pin; assert(fifo != NULL); assert(data != NULL); - // available storage is one less than nshort as prd == pwr - // is reserved for empty rather than full - - fifo_free = fifo->nshort - fifo_used(fifo) - 1; - - if (n > fifo_free) { + if (n > fifo_free(fifo)) { return -1; } else { @@ -125,7 +119,7 @@ int fifo_read(struct FIFO *fifo, short data[], int n) return 0; } -int fifo_used(struct FIFO *fifo) +int fifo_used(const struct FIFO * const fifo) { short *pin = fifo->pin; short *pout = fifo->pout; @@ -140,3 +134,10 @@ int fifo_used(struct FIFO *fifo) return used; } +int fifo_free(const struct FIFO * const fifo) +{ + // available storage is one less than nshort as prd == pwr + // is reserved for empty rather than full + + return fifo->nshort - fifo_used(fifo) - 1; +} diff --git a/codec2-dev/stm32/Makefile b/codec2-dev/stm32/Makefile index ba9ceeb1..3ad049c9 100644 --- a/codec2-dev/stm32/Makefile +++ b/codec2-dev/stm32/Makefile @@ -30,7 +30,7 @@ endif PERIPHLIBURL = http://www.st.com/st-web-ui/static/active/en/st_prod_software_internet/resource/technical/software/firmware/ PERIPHLIBZIP = stm32f4_dsp_stdperiph_lib.zip -PERIPHLIBVER = V1.4.0 +PERIPHLIBVER = V1.6.0 PERIPHLIBNAME = STM32F4xx_DSP_StdPeriph_Lib PERIPHLIBDIR = $(PERIPHLIBNAME) CMSIS = $(PERIPHLIBDIR)/Libraries/CMSIS diff --git a/codec2-dev/stm32/inc/stm32f4_dac.h b/codec2-dev/stm32/inc/stm32f4_dac.h index d0b82592..aa30415b 100644 --- a/codec2-dev/stm32/inc/stm32f4_dac.h +++ b/codec2-dev/stm32/inc/stm32f4_dac.h @@ -32,6 +32,8 @@ void dac_open(int fifo_sz); int dac1_write(short buf[], int n); /* DAC1 pin PA4 */ +int dac1_free(); int dac2_write(short buf[], int n); /* DAC2 pin PA5 */ +int dac2_free(); #endif diff --git a/codec2-dev/stm32/src/stm32f4_dac.c b/codec2-dev/stm32/src/stm32f4_dac.c index 75416a39..ef65a7f5 100644 --- a/codec2-dev/stm32/src/stm32f4_dac.c +++ b/codec2-dev/stm32/src/stm32f4_dac.c @@ -111,6 +111,14 @@ int dac2_write(short buf[], int n) { return fifo_write(dac2_fifo, buf, n); } +int dac1_free() { + return fifo_free(dac1_fifo); +} + +int dac2_free() { + return fifo_free(dac2_fifo); +} + static void tim6_config(void) { TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; -- 2.25.1