From: drowe67 Date: Wed, 8 Apr 2015 00:42:42 +0000 (+0000) Subject: refactoring cohpsk to remove some warnings and support out of sync logic X-Git-Url: http://git.whiteaudio.com/gitweb/?a=commitdiff_plain;h=9b088451de0347c716af34d7bdce808ffd69de4b;p=freetel-svn-tracking.git refactoring cohpsk to remove some warnings and support out of sync logic git-svn-id: https://svn.code.sf.net/p/freetel/code@2106 01035d8c-6547-0410-b346-abe4f91aad63 --- diff --git a/codec2-dev/octave/tcohpsk.m b/codec2-dev/octave/tcohpsk.m index 64b210b0..ea2de931 100644 --- a/codec2-dev/octave/tcohpsk.m +++ b/codec2-dev/octave/tcohpsk.m @@ -6,26 +6,6 @@ % output of the reference versions of the same functions written in % Octave. % -% Ideas: -% [ ] EB/No v BER curves changing Np, freq offset etc -% + can do these pretty fast in C, if we have the channel models -% [ ] better interpolation between two signals -% [ ] feedback to correct out freq offset est -% [ ] fading channel -% [ ] freq drift -% [ ] timing drift -% [ ] one version to compare Octave to C -% [ ] just compare C at some spot points -% + drive C simul from command line? -% + drive from octave? -% [ ] one version to unit test against various impairments -% [ ] measure/plot BER against impairments and ideal and tune -% + 100 errors -% [ ] freq offset -% + feeback fine freq? This will cause IL -% [ ] fading ch, compared to ideal -% [ ] smaller freq est block size to min ram req -% [ ] freq tracking eeback loop graphics_toolkit ("gnuplot"); diff --git a/codec2-dev/src/cohpsk.c b/codec2-dev/src/cohpsk.c index 1ecc0177..758aca8a 100644 --- a/codec2-dev/src/cohpsk.c +++ b/codec2-dev/src/cohpsk.c @@ -5,7 +5,20 @@ DATE CREATED: March 2015 Functions that implement a coherent PSK FDM modem. - + + TODO: + + [ ] Code to plot EB/No v BER curves for + [ ] AWGN channel + [ ] freq offset + [ ] fading channel + [ ] freq drift + [ ] timing drift + [ ] tune and meas impl loss perf for above + [ ] out of sync state + [ ] freq offset/drift feedback loop + [ ] smaller freq est block size to min ram req + \*---------------------------------------------------------------------------*/ /* @@ -52,6 +65,8 @@ static COMP qpsk_mod[] = { {-1.0, 0.0} }; +void corr_with_pilots(COMP *corr_out, float *mag_out, struct COHPSK *coh, int sampling_points[], int t, float f_fine); + /*---------------------------------------------------------------------------*\ FUNCTIONS @@ -323,6 +338,28 @@ void coarse_freq_offset_est(struct COHPSK *coh, struct FDMDV *fdmdv, COMP ch_fdm } +void corr_with_pilots(COMP *corr_out, float *mag_out, struct COHPSK *coh, int sampling_points[], int t, float f_fine) +{ + COMP corr, f_fine_rect, f_corr; + float mag; + int c, p; + + corr.real = 0.0; corr.imag = 0.0; mag = 0.0; + for (c=0; cct_symb_buf[t+sampling_points[p]][c]); + corr = cadd(corr, fcmult(coh->pilot2[p][c], f_corr)); + mag += cabsolute(f_corr); + } + } + + *corr_out = corr; + *mag_out = mag; +} + + /*---------------------------------------------------------------------------*\ FUNCTION....: frame_sync_fine_timing_est() @@ -341,9 +378,9 @@ void coarse_freq_offset_est(struct COHPSK *coh, struct FDMDV *fdmdv, COMP ch_fdm void frame_sync_fine_freq_est(struct COHPSK *coh, COMP ch_symb[][PILOTS_NC], int sync, int *next_sync) { int sampling_points[] = {0, 1, 6, 7}; - int r,c,i,p,t; + int r,c,i,t; float f_fine, mag, max_corr, max_mag; - COMP f_fine_rect, f_corr, corr; + COMP corr; /* update memory in symbol buffer */ @@ -369,16 +406,7 @@ void frame_sync_fine_freq_est(struct COHPSK *coh, COMP ch_symb[][PILOTS_NC], int max_corr = 0; for (f_fine=-20; f_fine<=20; f_fine+=1.0) { for (t=0; tct_symb_buf[t+sampling_points[p]][c]); - corr = cadd(corr, fcmult(coh->pilot2[p][c], f_corr)); - mag += cabsolute(f_corr); - } - } + corr_with_pilots(&corr, &mag, coh, sampling_points, t, f_fine); //printf(" f: %f t: %d corr: %f %f\n", f_fine, t, corr.real, corr.imag); if (cabsolute(corr) > max_corr) { max_corr = cabsolute(corr); @@ -540,7 +568,7 @@ void cohpsk_demod(struct COHPSK *coh, int rx_bits[], int *reliable_sync_bit, COM COMP rx_fdm_frame_bb[M*NSYMROWPILOT]; COMP rx_baseband[PILOTS_NC][M+M/P]; COMP rx_filt[PILOTS_NC][P+1]; - float env[NT*P], rx_timing; + float env[NT*P], __attribute__((unused)) rx_timing; COMP ch_symb[NSYMROWPILOT][PILOTS_NC]; COMP rx_onesym[PILOTS_NC]; int sync, next_sync, nin, r, c; diff --git a/codec2-dev/src/comp_prim.h b/codec2-dev/src/comp_prim.h index 8d86ac7e..41fe8178 100644 --- a/codec2-dev/src/comp_prim.h +++ b/codec2-dev/src/comp_prim.h @@ -34,7 +34,7 @@ \*---------------------------------------------------------------------------*/ -static COMP cneg(COMP a) +inline static COMP cneg(COMP a) { COMP res; @@ -44,7 +44,7 @@ static COMP cneg(COMP a) return res; } -static COMP cconj(COMP a) +inline static COMP cconj(COMP a) { COMP res; @@ -54,7 +54,7 @@ static COMP cconj(COMP a) return res; } -static COMP cmult(COMP a, COMP b) +inline static COMP cmult(COMP a, COMP b) { COMP res; @@ -64,7 +64,7 @@ static COMP cmult(COMP a, COMP b) return res; } -static COMP fcmult(float a, COMP b) +inline static COMP fcmult(float a, COMP b) { COMP res; @@ -74,7 +74,7 @@ static COMP fcmult(float a, COMP b) return res; } -static COMP cadd(COMP a, COMP b) +inline static COMP cadd(COMP a, COMP b) { COMP res; @@ -84,7 +84,7 @@ static COMP cadd(COMP a, COMP b) return res; } -static float cabsolute(COMP a) +inline static float cabsolute(COMP a) { return sqrtf(powf(a.real, 2.0) + powf(a.imag, 2.0)); } diff --git a/codec2-dev/unittest/test_cohpsk_ch.c b/codec2-dev/unittest/test_cohpsk_ch.c index 089a54f2..8b850a08 100644 --- a/codec2-dev/unittest/test_cohpsk_ch.c +++ b/codec2-dev/unittest/test_cohpsk_ch.c @@ -1,6 +1,6 @@ /*---------------------------------------------------------------------------*\ - FILE........: ttest_cohpsk_ch.c + FILE........: test_cohpsk_ch.c AUTHOR......: David Rowe DATE CREATED: April 2015 @@ -38,7 +38,7 @@ #include "comp_prim.h" #include "noise_samples.h" -#define FRAMES 35 +#define FRAMES 350 #define FOFFHZ 10.5 int main(int argc, char *argv[]) @@ -63,7 +63,7 @@ int main(int argc, char *argv[]) ptest_bits_coh_end = (int*)test_bits_coh + sizeof(test_bits_coh)/sizeof(int); phase_ch.real = 1.0; phase_ch.imag = 0.0; noise_r = 0; - noise_end = sizeof(noise)/sizeof(int); + noise_end = sizeof(noise)/sizeof(COMP); /* Main Loop ---------------------------------------------------------------------*/