From 72536a83d55d5154b958177dafeff1be4fdf66d2 Mon Sep 17 00:00:00 2001 From: drowe67 Date: Sun, 5 Apr 2015 01:06:09 +0000 Subject: [PATCH] refactoring Octave coh psk code git-svn-id: https://svn.code.sf.net/p/freetel/code@2102 01035d8c-6547-0410-b346-abe4f91aad63 --- codec2-dev/octave/tcohpsk.m | 71 +++++++++++++++-------------- codec2-dev/unittest/noise_samples.h | 51 ++++++++++++++++++++- codec2-dev/unittest/tcohpsk.c | 2 +- 3 files changed, 88 insertions(+), 36 deletions(-) diff --git a/codec2-dev/octave/tcohpsk.m b/codec2-dev/octave/tcohpsk.m index f55113ab..de25f5ea 100644 --- a/codec2-dev/octave/tcohpsk.m +++ b/codec2-dev/octave/tcohpsk.m @@ -8,10 +8,25 @@ % % Ideas: % [ ] EB/No v BER curves changing Np, freq offset etc -% + can do these pretty fast in C, if we jave the channel models +% + 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"); @@ -22,17 +37,21 @@ autotest; rand('state',1); randn('state',1); +% test parameters ---------------------------------------------------------- + n = 840; frames = 35; -framesize = 32; -foff = 0; - +foff = 10.5; EsNodB = 8; + EsNo = 10^(EsNodB/10); variance = 1/EsNo; +% modem constants ---------------------------------------------------------- + Rs = 50; Nc = 4; +framesize = 32; % -------------------------------------------------------------------------- @@ -52,9 +71,7 @@ afdmdv.Fcentre = 1500; afdmdv.fbb_rect = exp(j*2*pi*Fcentre/Fs); afdmdv.fbb_phase_tx = 1; - -afdmdv.fbb_rect_rx = exp(j*2*pi*(Fcentre)/Fs); -fbb_phase_rx = 1; +afdmdv.fbb_phase_rx = 1; afdmdv.Nrxdec = 31; afdmdv.rxdec_coeff = fir1(afdmdv.Nrxdec-1, 0.25)'; @@ -160,22 +177,6 @@ for i=1:frames % Channel -------------------------------------------------------------------- % - % [X] calibrated noise for 1% errors - % [ ] req of x % probability of sync in y ms? - % + take foff est, run filter for XXX symbols? - % + look for a couple of rows of pilots, take metric - % + try to decode frame, say between two pilots?, get corr metric? - % + try again - % [ ] manually test at +/-75 Hz - % [ ] good BER with freq offset - % [ ] Integrate offset est into demod - % + slow application or block based? - % + just need to get a workable first pass for now - % [ ] module in cohpsk - % [ ] C port - % [ ] smaller block size to min ram req - % [ ] Feeback loop - [ch_fdm_frame phase_ch] = freq_shift(tx_fdm_frame, foff, Fs, phase_ch); % each carrier has power = 2, total power 2Nc, total symbol rate NcRs, noise BW B=Fs @@ -203,16 +204,9 @@ for i=1:frames % shift entire FDM signal to 0 Hz - afdmdv.fbb_rect_rx = exp(j*2*pi*acohpsk.f_est/afdmdv.Fs); - rx_fdm_frame_bb = zeros(1, acohpsk.Nsymbrowpilot*M); - for r=1:acohpsk.Nsymbrowpilot*M - fbb_phase_rx = fbb_phase_rx*afdmdv.fbb_rect_rx'; - rx_fdm_frame_bb(r) = ch_fdm_frame(r)*fbb_phase_rx; - end - mag = abs(fbb_phase_rx); - fbb_phase_rx /= mag; + [rx_fdm_frame_bb afdmdv.fbb_phase_rx] = freq_shift(ch_fdm_frame, -acohpsk.f_est, Fs, afdmdv.fbb_phase_rx); rx_fdm_frame_bb_log = [rx_fdm_frame_bb_log rx_fdm_frame_bb]; - + % sample rate demod processing ch_symb = zeros(acohpsk.Nsymbrowpilot, Nc); @@ -267,8 +261,8 @@ stem_sig_and_error(1, 111, tx_bits_log_c(1:n), tx_bits_log(1:n) - tx_bits_log_c( stem_sig_and_error(2, 211, real(tx_symb_log_c(1:n)), real(tx_symb_log(1:n) - tx_symb_log_c(1:n)), 'tx symb re', [1 n -1.5 1.5]) stem_sig_and_error(2, 212, imag(tx_symb_log_c(1:n)), imag(tx_symb_log(1:n) - tx_symb_log_c(1:n)), 'tx symb im', [1 n -1.5 1.5]) -stem_sig_and_error(3, 211, real(tx_fdm_log_c(1:n)), real(tx_fdm_frame_log(1:n) - tx_fdm_frame_log_c(1:n)), 'tx fdm frame re', [1 n -10 10]) -stem_sig_and_error(3, 212, imag(tx_fdm_log_c(1:n)), imag(tx_fdm_frame_log(1:n) - tx_fdm_frame_log_c(1:n)), 'tx fdm frame im', [1 n -10 10]) +stem_sig_and_error(3, 211, real(tx_fdm_frame_log_c(1:n)), real(tx_fdm_frame_log(1:n) - tx_fdm_frame_log_c(1:n)), 'tx fdm frame re', [1 n -10 10]) +stem_sig_and_error(3, 212, imag(tx_fdm_frame_log_c(1:n)), imag(tx_fdm_frame_log(1:n) - tx_fdm_frame_log_c(1:n)), 'tx fdm frame im', [1 n -10 10]) stem_sig_and_error(4, 211, real(ch_fdm_frame_log_c(1:n)), real(ch_fdm_frame_log(1:n) - ch_fdm_frame_log_c(1:n)), 'ch fdm frame re', [1 n -10 10]) stem_sig_and_error(4, 212, imag(ch_fdm_frame_log_c(1:n)), imag(ch_fdm_frame_log(1:n) - ch_fdm_frame_log_c(1:n)), 'ch fdm frame im', [1 n -10 10]) stem_sig_and_error(5, 211, real(rx_fdm_frame_bb_log_c(1:n)), real(rx_fdm_frame_bb_log(1:n) - rx_fdm_frame_bb_log_c(1:n)), 'rx fdm frame bb re', [1 n -10 10]) @@ -308,6 +302,15 @@ ber = Nerrs/Tbits; printf("EsNodB: %4.1f ber..: %3.2f Nerrs..: %d Tbits..: %d\n", EsNodB, ber, Nerrs, Tbits); printf("EsNodB: %4.1f ber_c: %3.2f Nerrs_c: %d Tbits_c: %d\n", EsNodB, ber_c, Nerrs_c, Tbits_c); +% some other useful plots + +if 0 +figure +plot(rx_symb_log,'+') +figure +plot(xor(tx_bits_prev_log, rx_bits_log_c),'+') +end + % C header file of noise samples so C version gives extacly the same results function write_noise_file(noise_log) diff --git a/codec2-dev/unittest/noise_samples.h b/codec2-dev/unittest/noise_samples.h index fbf2fa69..d31a1484 100644 --- a/codec2-dev/unittest/noise_samples.h +++ b/codec2-dev/unittest/noise_samples.h @@ -33601,4 +33601,53 @@ COMP noise[]={ {-2.201099,8.147500}, {-0.854860,-3.217227}, {2.865000,3.780455} -}; \ No newline at end of file +};03688}, + {3.947704,2.591331}, + {-13.355771,-1.640064}, + {-6.981492,2.597217}, + {-3.238346,-5.647247}, + {-6.181055,1.810279}, + {-3.202626,-1.235126}, + {-3.157657,-5.482706}, + {-2.648149,0.392058}, + {-0.511225,-0.631106}, + {2.175415,0.068423}, + {4.481758,2.334373}, + {2.427512,6.953592}, + {-3.374617,3.710045}, + {-1.207558,0.621048}, + {-0.177510,-0.751545}, + {5.995835,-4.081549}, + {3.144007,-0.692084}, + {17.133404,0.486124}, + {3.646924,-4.741484}, + {2.323303,1.063447}, + {-2.397030,5.749218}, + {-3.236087,-2.329649}, + {-4.288638,3.571241}, + {-6.484552,1.256784}, + {-7.055667,0.299616}, + {-0.975544,-2.110141}, + {-6.905026,3.049075}, + {-6.688080,-2.805814}, + {-1.846770,-10.936074}, + {-3.303769,4.626817}, + {4.776190,1.080799}, + {-3.797495,-1.150984}, + {-3.722335,4.753599}, + {-0.111050,1.675908}, + {-2.614292,-2.621500}, + {-5.546542,10.839913}, + {2.920223,0.688586}, + {5.758427,6.683944}, + {-7.829388,-8.163553}, + {-3.567825,2.562626}, + {-4.198519,3.407382}, + {-4.599247,6.985142}, + {1.677356,1.667125}, + {-2.453346,-2.577718}, + {-6.986411,-3.614714}, + {-2.331341,-2.549597}, + {-7.382277,-0.327108}, + {6.535084,-3.545155}, + {0.437164,4.358225}, diff --git a/codec2-dev/unittest/tcohpsk.c b/codec2-dev/unittest/tcohpsk.c index b0916083..9adf872a 100644 --- a/codec2-dev/unittest/tcohpsk.c +++ b/codec2-dev/unittest/tcohpsk.c @@ -46,7 +46,7 @@ #define FRAMES 35 #define RS 50 -#define FOFF 0 +#define FOFF 10.5 extern float pilots_coh[][PILOTS_NC]; -- 2.25.1