From: drowe67 Date: Thu, 19 Mar 2015 09:37:06 +0000 (+0000) Subject: most rx filtering working in C, next step add coarse timing (frame snyc) in C X-Git-Url: http://git.whiteaudio.com/gitweb/?a=commitdiff_plain;h=ac9444bf2f89c64a7c569f0144870ac94d991579;p=freetel-svn-tracking.git most rx filtering working in C, next step add coarse timing (frame snyc) in C git-svn-id: https://svn.code.sf.net/p/freetel/code@2083 01035d8c-6547-0410-b346-abe4f91aad63 --- diff --git a/codec2-dev/octave/autotest.m b/codec2-dev/octave/autotest.m index 9901535b..38e99903 100644 --- a/codec2-dev/octave/autotest.m +++ b/codec2-dev/octave/autotest.m @@ -44,10 +44,14 @@ function plot_sig_and_error(plotnum, subplotnum, sig, error, titlestr, axisvec) endfunction -function check(a, b, test_name) +function check(a, b, test_name, tol) global passes; global fails; + if nargin == 3 + tol = 1E-3; + end + [m n] = size(a); printf("%s", test_name); for i=1:(25-length(test_name)) @@ -55,8 +59,8 @@ function check(a, b, test_name) end printf(": "); - e = sum(abs(a - b))/n; - if e < 1E-3 + e = sum(sum(abs(a - b))/n); + if e < tol printf("OK\n"); passes++; else diff --git a/codec2-dev/octave/fdmdv.m b/codec2-dev/octave/fdmdv.m index 4fcdc153..c91d6034 100644 --- a/codec2-dev/octave/fdmdv.m +++ b/codec2-dev/octave/fdmdv.m @@ -263,6 +263,11 @@ function [rx_baseband fdmdv] = fdm_downconvert(fdmdv, rx_fdm, nin) end end + for c=1:Nc+1 + mag = abs(phase_rx(c)); + phase_rx(c) /= mag; + end + fdmdv.phase_rx = phase_rx; endfunction diff --git a/codec2-dev/octave/gmsk.m b/codec2-dev/octave/gmsk.m index 0549c338..40cd0cda 100644 --- a/codec2-dev/octave/gmsk.m +++ b/codec2-dev/octave/gmsk.m @@ -884,7 +884,7 @@ function gmsk_rx(rx_file_name, err_file_name) rx_power_dB = 10*log10(rx_power); figure; subplot(211) - plot(rx_filt(1000:5*Fs)); + plot(rx_filt(1000:length(rx_filt))); title('GMSK Power (narrow filter)'); subplot(212) plot(rx_power_dB); @@ -923,7 +923,6 @@ function gmsk_rx(rx_file_name, err_file_name) printf("Estimated S: %3.1f N: %3.1f Nbw: %4.0f Hz SNR: %3.1f CNo: %3.1f EbNo: %3.1f BER theory: %f\n", signal, noise, Fs*noise_bw, snr, CNo, EbNo, ber_theory); - end % FM signal is centred on 12 kHz and 16 kHz wide so lets also work out noise there @@ -953,6 +952,7 @@ function gmsk_rx(rx_file_name, err_file_name) grid("minor") legend("boxoff"); title('FM C/No'); + end % spectrum of a chunk of GMSK signal just after preamble @@ -1014,5 +1014,5 @@ endfunction %gmsk_rx("ssb25db.wav") %gmsk_rx("~/Desktop/ssb_fm_gmsk_high.wav") %gmsk_rx("~/Desktop/test_gmsk_28BER.raw") -gmsk_rx("~/Desktop/gmsk_rec1.wav") +gmsk_rx("~/Desktop/gmsk_rec_reverse.wav") diff --git a/codec2-dev/octave/tcohpsk.m b/codec2-dev/octave/tcohpsk.m index 57906e4f..bc76eee6 100644 --- a/codec2-dev/octave/tcohpsk.m +++ b/codec2-dev/octave/tcohpsk.m @@ -104,10 +104,11 @@ fdmdv.rx_filter_memory = zeros(fdmdv.Nc+1, fdmdv.Nfilter); rx_filt_log = []; rx_fdm_filter_log = []; rx_baseband_log = []; +rx_fdm_log = []; fbb_phase_rx = 1; -% frame of just pilots ofr coarse sync +% frame of just pilots for coarse sync tx_bits = zeros(1,framesize); [tx_symb_pilot tx_bits prev_tx_sym] = bits_to_qpsk_symbols(sim_in, tx_bits, [], []); @@ -117,6 +118,7 @@ end ct_symb_buf = zeros(2*sim_in.Nsymbrowpilot, sim_in.Nc); +prev_tx_bits = []; % main loop -------------------------------------------------------------------- for i=1:frames @@ -142,6 +144,10 @@ for i=1:frames end tx_fdm_log = [tx_fdm_log tx_fdm_frame]; + % + % Demod ---------------------------------------------------------------------- + % + nin = M; % shift frame down to complex baseband @@ -153,6 +159,7 @@ for i=1:frames end mag = abs(fbb_phase_rx); fbb_phase_rx /= mag; + rx_fdm_log = [rx_fdm_log rx_fdm_frame_bb]; ch_symb = zeros(sim_in.Nsymbrowpilot, Nc); for r=1:sim_in.Nsymbrowpilot @@ -213,21 +220,31 @@ end end prev_tx_bits2 = prev_tx_bits; prev_tx_bits = tx_bits; + end stem_sig_and_error(1, 111, tx_bits_log_c(1:n), tx_bits_log(1:n) - tx_bits_log_c(1:n), 'tx bits', [1 n -1.5 1.5]) 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(ch_symb_log_c(1:n)), real(ch_symb_log(1:n) - ch_symb_log_c(1:n)), 'ch symb re', [1 n -1.5 1.5]) -stem_sig_and_error(3, 212, imag(ch_symb_log_c(1:n)), imag(ch_symb_log(1:n) - ch_symb_log_c(1:n)), 'ch symb im', [1 n -1.5 1.5]) -stem_sig_and_error(4, 211, rx_amp_log_c(1:n), rx_amp_log(1:n) - rx_amp_log_c(1:n), 'Amp Est', [1 n -1.5 1.5]) -stem_sig_and_error(4, 212, rx_phi_log_c(1:n), rx_phi_log(1:n) - rx_phi_log_c(1:n), 'Phase Est', [1 n -4 4]) -stem_sig_and_error(5, 211, real(rx_symb_log_c(1:n)), real(rx_symb_log(1:n) - rx_symb_log_c(1:n)), 'rx symb re', [1 n -1.5 1.5]) -stem_sig_and_error(5, 212, imag(rx_symb_log_c(1:n)), imag(rx_symb_log(1:n) - rx_symb_log_c(1:n)), 'rx symb im', [1 n -1.5 1.5]) -stem_sig_and_error(6, 111, rx_bits_log_c(1:n), rx_bits_log(1:n) - rx_bits_log_c(1:n), 'rx bits', [1 n -1.5 1.5]) + +stem_sig_and_error(3, 211, real(tx_fdm_log_c(1:n)), real(tx_fdm_log(1:n) - tx_fdm_log_c(1:n)), 'tx fdm re', [1 n -10 10]) +stem_sig_and_error(3, 212, imag(tx_fdm_log_c(1:n)), imag(tx_fdm_log(1:n) - tx_fdm_log_c(1:n)), 'tx fdm im', [1 n -10 10]) + +stem_sig_and_error(4, 211, real(ch_symb_log_c(1:n)), real(ch_symb_log(1:n) - ch_symb_log_c(1:n)), 'ch symb re', [1 n -2 2]) +stem_sig_and_error(4, 212, imag(ch_symb_log_c(1:n)), imag(ch_symb_log(1:n) - ch_symb_log_c(1:n)), 'ch symb im', [1 n -2 2]) +stem_sig_and_error(5, 211, rx_amp_log_c(1:n), rx_amp_log(1:n) - rx_amp_log_c(1:n), 'Amp Est', [1 n -1.5 1.5]) +stem_sig_and_error(5, 212, rx_phi_log_c(1:n), rx_phi_log(1:n) - rx_phi_log_c(1:n), 'Phase Est', [1 n -4 4]) +stem_sig_and_error(6, 211, real(rx_symb_log_c(1:n)), real(rx_symb_log(1:n) - rx_symb_log_c(1:n)), 'rx symb re', [1 n -1.5 1.5]) +stem_sig_and_error(6, 212, imag(rx_symb_log_c(1:n)), imag(rx_symb_log(1:n) - rx_symb_log_c(1:n)), 'rx symb im', [1 n -1.5 1.5]) +stem_sig_and_error(7, 111, rx_bits_log_c(1:n), rx_bits_log(1:n) - rx_bits_log_c(1:n), 'rx bits', [1 n -1.5 1.5]) check(tx_bits_log, tx_bits_log_c, 'tx_bits'); check(tx_symb_log, tx_symb_log_c, 'tx_symb'); +check(tx_fdm_log, tx_fdm_log_c, 'tx_fdm'); +check(rx_fdm_log, rx_fdm_log_c, 'rx_fdm'); +check(rx_baseband_log, rx_baseband_log_c, 'rx_baseband',0.01); +check(rx_filt_log, rx_filt_log_c, 'rx_filt'); +check(ch_symb_log, ch_symb_log_c, 'ch_symb',0.01); check(rx_amp_log, rx_amp_log_c, 'rx_amp_log'); check(rx_phi_log, rx_phi_log_c, 'rx_phi_log'); check(rx_symb_log, rx_symb_log_c, 'rx_symb'); diff --git a/codec2-dev/src/fdmdv.c b/codec2-dev/src/fdmdv.c index 931adabe..1d5cf986 100644 --- a/codec2-dev/src/fdmdv.c +++ b/codec2-dev/src/fdmdv.c @@ -400,8 +400,8 @@ void tx_filter(COMP tx_baseband[NC+1][M], int Nc, COMP tx_symbols[], COMP tx_fil AUTHOR......: David Rowe DATE CREATED: 13 August 2014 - Given Nc*NB bits construct M samples (1 symbol) of Nc+1 filtered - symbols streams. + Given Nc symbols construct M samples (1 symbol) of Nc+1 filtered + and upconverted symbols. \*---------------------------------------------------------------------------*/ @@ -878,30 +878,14 @@ void fdm_downconvert(COMP rx_baseband[NC+1][M+M/P], int Nc, COMP rx_fdm[], COMP assert(nin <= (M+M/P)); - /* Nc/2 tones below centre freq */ + /* downconvert */ - for (c=0; cphase_tx[c].real = 1.0; + fdmdv->phase_tx[c].imag = 0.0; + + freq_hz = fdmdv->fsep*( -PILOTS_NC/2 - 0.5 + c + 1.0 ); + fdmdv->freq[c].real = cosf(2.0*M_PI*freq_hz/FS); + fdmdv->freq[c].imag = sinf(2.0*M_PI*freq_hz/FS); + fdmdv->freq_pol[c] = 2.0*M_PI*freq_hz/FS; + + //printf("c: %d %f %f\n",c,freq_hz,fdmdv->freq_pol[c]); + for(i=0; iNc , tx_onesym, fdmdv->tx_filter_memory, + fdmdv->phase_tx, fdmdv->freq, &fdmdv->fbb_phase_tx, fdmdv->fbb_rect); + } + + #ifdef TMP for(r=0; rfbb_phase_rx, nin); + fdm_downconvert(rx_baseband, fdmdv->Nc, &rx_fdm[r*M], fdmdv->phase_rx, fdmdv->freq, nin); + rx_filter(rx_filt, fdmdv->Nc, rx_baseband, rx_filter_memory, nin); + rx_timing = rx_est_timing(rx_onesym, fdmdv->Nc, rx_filt, fdmdv->rx_filter_mem_timing, env, nin); + + for(c=0; cpilot_lut, 1, NPILOT_LUT, NPILOT_LUT); octave_save_complex(fout, "pilot_baseband1_log_c", pilot_baseband1_log, 1, NPILOTBASEBAND*FRAMES, NPILOTBASEBAND*FRAMES); octave_save_complex(fout, "pilot_baseband2_log_c", pilot_baseband2_log, 1, NPILOTBASEBAND*FRAMES, NPILOTBASEBAND*FRAMES);