From: drowe67 Date: Sun, 29 Mar 2015 02:40:02 +0000 (+0000) Subject: refactored codea little, starting to (re)port C code X-Git-Url: http://git.whiteaudio.com/gitweb/?a=commitdiff_plain;h=684f3dfd74cf90a618883aabecaa6773d30db2ab;p=freetel-svn-tracking.git refactored codea little, starting to (re)port C code git-svn-id: https://svn.code.sf.net/p/freetel/code@2095 01035d8c-6547-0410-b346-abe4f91aad63 --- diff --git a/codec2-dev/octave/cohpsk.m b/codec2-dev/octave/cohpsk.m index f7978dd5..966af97b 100644 --- a/codec2-dev/octave/cohpsk.m +++ b/codec2-dev/octave/cohpsk.m @@ -95,6 +95,8 @@ function sim_in = symbol_rate_init(sim_in) sim_in.ff_phase = 1; + sim_in.ct_symb_ff_buf = zeros(Nsymbrowpilot + 2, Nc); + % Init LDPC -------------------------------------------------------------------- if ldpc_code @@ -558,6 +560,60 @@ function [next_sync cohpsk] = frame_sync_fine_timing_est(cohpsk, ch_symb, sync, endfunction +% fine freq correction + +function acohpsk = fine_freq_correct(acohpsk, sync, next_sync); + ct_symb_ff_buf = acohpsk.ct_symb_ff_buf; + + % We can decode first frame that we achieve sync. Need to fine freq + % correct all of it's symbols, including pilots. From then on, just + % correct new symbols into frame. make copy, so if we lose sync we + % havent fine freq corrected ct_symb_buf if next_sync == 4 correct + % all 8 if sync == 2 correct latest 6 + + if (next_sync == 4) || (sync == 4) + + if next_sync == 4 + + % first frame, we've just gotten sync so fine freq correct all Nsymbrowpilot+2 samples + + ct_symb_ff_buf = acohpsk.ct_symb_buf(acohpsk.ct+1:acohpsk.ct+acohpsk.Nsymbrowpilot+2,:); + for r=1:acohpsk.Nsymbrowpilot+2 + acohpsk.ff_phase *= acohpsk.ff_rect'; + ct_symb_ff_buf(r,:) *= acohpsk.ff_phase; + end + + else + + % second and subsequent frames, just fine freq correct the latest Nsymbrowpilot + + ct_symb_ff_buf(1:2,:) = ct_symb_ff_buf(Nsymbrowpilot+1:Nsymbrowpilot+2,:); + ct_symb_ff_buf(3:Nsymbrowpilot+2,:) = acohpsk.ct_symb_buf(acohpsk.ct+3:acohpsk.ct+acohpsk.Nsymbrowpilot+2,:); + for r=3:acohpsk.Nsymbrowpilot+2 + afdmdv.ff_phase *= afdmdv.ff_rect'; + ct_symb_ff_buf(r,:) *= afdmdv.ff_phase; + end + + end + + mag = abs(acohpsk.ff_phase); + acohpsk.ff_phase /= mag; + + acohpsk.ct_symb_ff_buf = ct_symb_ff_buf; + end +endfunction + + +% misc sync state machine code, just wanted it in a function + +function sync = sync_state_machine(sync, next_sync) + if sync == 1 + next_sync = 2; + end + sync = next_sync; +endfunction + + % Rate Rs BER tests ------------------------------------------------------------------------------ function sim_out = ber_test(sim_in) diff --git a/codec2-dev/octave/tcohpsk.m b/codec2-dev/octave/tcohpsk.m index 593dbfb1..a6737ee5 100644 --- a/codec2-dev/octave/tcohpsk.m +++ b/codec2-dev/octave/tcohpsk.m @@ -235,52 +235,14 @@ for i=1:frames [next_sync acohpsk] = frame_sync_fine_timing_est(acohpsk, ch_symb, sync, next_sync); %acohpsk.ff_rect = exp(j*2*pi*(-1.0)/Rs); - if sync == 1 - next_sync = 2; - end - - %printf("i: %d sync: %d next_sync: %d\n", i, sync, next_sync); - sync = next_sync; - if (i==1000) xx end - % We can decode first that we get sync on. Need to fine freq correct all of it's symbols, - % including pilots. From then on, just correct new symbols into frame. - % make copy, so if we lose sync we havent fine freq corrected ct_symb_buf - % if next_sync == 4 correct all 8 - % if sync == 2 correct latest 6 - - if (next_sync == 4) || (sync == 4) - - if next_sync == 4 - - % first frame, we've just gotten sync so fine freq correct all Nsymbrowpilot+2 samples - - ct_symb_ff_buf = acohpsk.ct_symb_buf(acohpsk.ct+1:acohpsk.ct+acohpsk.Nsymbrowpilot+2,:); - for r=1:acohpsk.Nsymbrowpilot+2 - acohpsk.ff_phase *= acohpsk.ff_rect'; - ct_symb_ff_buf(r,:) *= acohpsk.ff_phase; - end + acohpsk = fine_freq_correct(acohpsk, sync, next_sync); - else - - % second and subsequent frames, just fine freq correct the latest Nsymbrowpilot - - ct_symb_ff_buf(1:2,:) = ct_symb_ff_buf(Nsymbrowpilot+1:Nsymbrowpilot+2,:); - ct_symb_ff_buf(3:Nsymbrowpilot+2,:) = acohpsk.ct_symb_buf(acohpsk.ct+3:acohpsk.ct+acohpsk.Nsymbrowpilot+2,:); - for r=3:acohpsk.Nsymbrowpilot+2 - afdmdv.ff_phase *= afdmdv.ff_rect'; - ct_symb_ff_buf(r,:) *= afdmdv.ff_phase; - end - - end - - mag = abs(acohpsk.ff_phase); - acohpsk.ff_phase /= mag; - - [rx_symb rx_bits amp_ phi_ EsNo_] = qpsk_symbols_to_bits(acohpsk, ct_symb_ff_buf); + if (sync == 4) || (next_sync == 4) + [rx_symb rx_bits amp_ phi_ EsNo_] = qpsk_symbols_to_bits(acohpsk, acohpsk.ct_symb_ff_buf); rx_symb_log = [rx_symb_log; rx_symb]; rx_amp_log = [rx_amp_log; amp_]; rx_phi_log = [rx_phi_log; phi_]; @@ -296,6 +258,8 @@ for i=1:frames end end + sync = sync_state_machine(sync, next_sync); + prev_tx_bits2 = prev_tx_bits; prev_tx_bits = tx_bits;