From a13347fa4a438cd8867d62c5a3f4e3f6bd5901d1 Mon Sep 17 00:00:00 2001 From: drowe67 Date: Mon, 19 Jun 2017 22:04:58 +0000 Subject: [PATCH] correct timing instant when timing_en==0, added timing_est and sample_point and rx_np vectors and scatter plot, looking gd with all estimators on except freq_offset git-svn-id: https://svn.code.sf.net/p/freetel/code@3225 01035d8c-6547-0410-b346-abe4f91aad63 --- codec2-dev/octave/tofdm.m | 54 +++++++++++++++++++++++++------------ codec2-dev/src/ofdm.c | 5 ++++ codec2-dev/unittest/tofdm.c | 21 ++++++++++++--- 3 files changed, 60 insertions(+), 20 deletions(-) diff --git a/codec2-dev/octave/tofdm.m b/codec2-dev/octave/tofdm.m index 8ade1366..63391aac 100644 --- a/codec2-dev/octave/tofdm.m +++ b/codec2-dev/octave/tofdm.m @@ -42,12 +42,18 @@ states.rxbuf(Nrxbuf-nin+1:Nrxbuf) = rx(prx:nin); prx += nin; rxbuf_log = []; rxbuf_in_log = []; rx_sym_log = []; foff_hz_log = []; +timing_est_log = []; sample_point_log = []; phase_est_pilot_log = []; rx_amp_log = []; -rx_bits_log = []; +rx_np_log = []; rx_bits_log = []; -states.timing_en = 0; -states.foff_est_en = 1; -states.phase_est_en = 0; +states.timing_en = 1; +states.foff_est_en = 0; +states.phase_est_en = 1; + +if states.timing_en == 0 + % manually set ideal timing instant + states.sample_point = Ncp; +end for f=1:Nframes @@ -74,6 +80,9 @@ for f=1:Nframes phase_est_pilot_log = [phase_est_pilot_log; aphase_est_pilot_log]; rx_amp_log = [rx_amp_log arx_amp]; foff_hz_log = [foff_hz_log; states.foff_est_hz]; + timing_est_log = [timing_est_log; states.timing_est]; + sample_point_log = [sample_point_log; states.sample_point]; + rx_np_log = [rx_np_log arx_np]; rx_bits_log = [rx_bits_log rx_bits]; end @@ -91,28 +100,37 @@ system(path_to_tofdm); load tofdm_out.txt; -stem_sig_and_error(1, 111, tx_bits_log_c, tx_bits_log - tx_bits_log_c, 'tx bits', [1 length(tx_bits_log) -1.5 1.5]) +fg = 1; +figure(fg++); clf; plot(rx_np_log,'+'); title('Octave Scatter Diagram'); axis([-1.5 1.5 -1.5 1.5]); +figure(fg++); clf; plot(rx_np_log_c,'+'); title('C Scatter Diagram'); axis([-1.5 1.5 -1.5 1.5]); + +stem_sig_and_error(fg++, 111, tx_bits_log_c, tx_bits_log - tx_bits_log_c, 'tx bits', [1 length(tx_bits_log) -1.5 1.5]) -stem_sig_and_error(2, 211, real(tx_log_c), real(tx_log - tx_log_c), 'tx re', [1 length(tx_log_c) -0.1 0.1]) -stem_sig_and_error(2, 212, imag(tx_log_c), imag(tx_log - tx_log_c), 'tx im', [1 length(tx_log_c) -0.1 0.1]) +stem_sig_and_error(fg, 211, real(tx_log_c), real(tx_log - tx_log_c), 'tx re', [1 length(tx_log_c) -0.1 0.1]) +stem_sig_and_error(fg++, 212, imag(tx_log_c), imag(tx_log - tx_log_c), 'tx im', [1 length(tx_log_c) -0.1 0.1]) -stem_sig_and_error(3, 211, real(rxbuf_in_log_c), real(rxbuf_in_log - rxbuf_in_log_c), 'rxbuf in re', [1 length(rxbuf_in_log_c) -0.1 0.1]) -stem_sig_and_error(3, 212, imag(rxbuf_in_log_c), imag(rxbuf_in_log - rxbuf_in_log_c), 'rxbuf in im', [1 length(rxbuf_in_log_c) -0.1 0.1]) +stem_sig_and_error(fg, 211, real(rxbuf_in_log_c), real(rxbuf_in_log - rxbuf_in_log_c), 'rxbuf in re', [1 length(rxbuf_in_log_c) -0.1 0.1]) +stem_sig_and_error(fg++, 212, imag(rxbuf_in_log_c), imag(rxbuf_in_log - rxbuf_in_log_c), 'rxbuf in im', [1 length(rxbuf_in_log_c) -0.1 0.1]) -stem_sig_and_error(4, 211, real(rxbuf_log_c), real(rxbuf_log - rxbuf_log_c), 'rxbuf re', [1 length(rxbuf_log_c) -0.1 0.1]) -stem_sig_and_error(4, 212, imag(rxbuf_log_c), imag(rxbuf_log - rxbuf_log_c), 'rxbuf im', [1 length(rxbuf_log_c) -0.1 0.1]) +stem_sig_and_error(fg, 211, real(rxbuf_log_c), real(rxbuf_log - rxbuf_log_c), 'rxbuf re', [1 length(rxbuf_log_c) -0.1 0.1]) +stem_sig_and_error(fg++, 212, imag(rxbuf_log_c), imag(rxbuf_log - rxbuf_log_c), 'rxbuf im', [1 length(rxbuf_log_c) -0.1 0.1]) -stem_sig_and_error(5, 211, real(rx_sym_log_c), real(rx_sym_log - rx_sym_log_c), 'rx sym re', [1 length(rx_sym_log_c) -1.5 1.5]) -stem_sig_and_error(5, 212, imag(rx_sym_log_c), imag(rx_sym_log - rx_sym_log_c), 'rx sym im', [1 length(rx_sym_log_c) -1.5 1.5]) +stem_sig_and_error(fg, 211, real(rx_sym_log_c), real(rx_sym_log - rx_sym_log_c), 'rx sym re', [1 length(rx_sym_log_c) -1.5 1.5]) +stem_sig_and_error(fg++, 212, imag(rx_sym_log_c), imag(rx_sym_log - rx_sym_log_c), 'rx sym im', [1 length(rx_sym_log_c) -1.5 1.5]) % for angles pi and -pi are the same + d = phase_est_pilot_log - phase_est_pilot_log_c; d = angle(exp(j*d)); -stem_sig_and_error(6, 211, phase_est_pilot_log_c, d, 'phase est pilot', [1 length(phase_est_pilot_log_c) -1.5 1.5]) -stem_sig_and_error(6, 212, rx_amp_log_c, rx_amp_log - rx_amp_log_c, 'rx amp', [1 length(rx_amp_log_c) -1.5 1.5]) -stem_sig_and_error(7, 111, foff_hz_log_c, (foff_hz_log - foff_hz_log_c), 'foff hz', [1 length(foff_hz_log_c) -1.5 1.5]) +stem_sig_and_error(fg, 211, phase_est_pilot_log_c, d, 'phase est pilot', [1 length(phase_est_pilot_log_c) -1.5 1.5]) +stem_sig_and_error(fg++, 212, rx_amp_log_c, rx_amp_log - rx_amp_log_c, 'rx amp', [1 length(rx_amp_log_c) -1.5 1.5]) + +stem_sig_and_error(fg++, 111, foff_hz_log_c, (foff_hz_log - foff_hz_log_c), 'foff hz', [1 length(foff_hz_log_c) -1.5 1.5]) + +stem_sig_and_error(fg, 211, timing_est_log_c, (timing_est_log - timing_est_log_c), 'timing est', [1 length(timing_est_log_c) -1.5 1.5]) +stem_sig_and_error(fg++, 212, sample_point_log_c, (sample_point_log - sample_point_log_c), 'sample point', [1 length(sample_point_log_c) -1.5 1.5]) -stem_sig_and_error(8, 111, rx_bits_log_c, rx_bits_log - rx_bits_log_c, 'rx bits', [1 length(rx_bits_log) -1.5 1.5]) +stem_sig_and_error(fg++, 111, rx_bits_log_c, rx_bits_log - rx_bits_log_c, 'rx bits', [1 length(rx_bits_log) -1.5 1.5]) % Run through checklist ----------------------------- @@ -124,5 +142,7 @@ check(rxbuf_log, rxbuf_log_c, 'rxbuf'); check(rx_sym_log, rx_sym_log_c, 'rx_sym'); check(phase_est_pilot_log, phase_est_pilot_log_c, 'phase_est_pilot', tol=1E-3, its_an_angle=1); check(rx_amp_log, rx_amp_log_c, 'rx_amp'); +check(timing_est_log, timing_est_log_c, 'timing_est'); +check(sample_point_log, sample_point_log_c, 'sample_point'); check(foff_hz_log, foff_hz_log_c, 'foff_est_hz'); check(rx_bits_log, rx_bits_log_c, 'rx_bits'); diff --git a/codec2-dev/src/ofdm.c b/codec2-dev/src/ofdm.c index 4637ef03..04c40c00 100644 --- a/codec2-dev/src/ofdm.c +++ b/codec2-dev/src/ofdm.c @@ -372,6 +372,11 @@ void ofdm_set_verbose(struct OFDM *ofdm, int level) { void ofdm_set_timing_enable(struct OFDM *ofdm, bool val) { ofdm->timing_en = val; + + if (ofdm->timing_en == false) { + /* manually set ideal timing instant */ + ofdm->sample_point = OFDM_NCP-1; + } } void ofdm_set_foff_est_enable(struct OFDM *ofdm, bool val) { diff --git a/codec2-dev/unittest/tofdm.c b/codec2-dev/unittest/tofdm.c index 4113d585..10088039 100644 --- a/codec2-dev/unittest/tofdm.c +++ b/codec2-dev/unittest/tofdm.c @@ -60,9 +60,12 @@ int main(int argc, char *argv[]) COMP rxbuf_log[OFDM_RXBUF*NFRAMES]; COMP rx_sym_log[(OFDM_NS + 3)*NFRAMES][OFDM_NC + 2]; float phase_est_pilot_log[OFDM_ROWSPERFRAME*NFRAMES][OFDM_NC]; + COMP rx_np_log[OFDM_ROWSPERFRAME*OFDM_NC*NFRAMES]; float rx_amp_log[OFDM_ROWSPERFRAME*OFDM_NC*NFRAMES]; float foff_hz_log[NFRAMES]; int rx_bits_log[OFDM_BITSPERFRAME*NFRAMES]; + int timing_est_log[OFDM_BITSPERFRAME*NFRAMES]; + int sample_point_log[OFDM_BITSPERFRAME*NFRAMES]; FILE *fout; int f,i,j; @@ -112,9 +115,9 @@ int main(int argc, char *argv[]) /* disable estimators for initial testing */ ofdm_set_verbose(ofdm, true); - ofdm_set_timing_enable(ofdm, false); - ofdm_set_foff_est_enable(ofdm, true); - ofdm_set_phase_est_enable(ofdm, false); + ofdm_set_timing_enable(ofdm, true); + ofdm_set_foff_est_enable(ofdm, false); + ofdm_set_phase_est_enable(ofdm, true); for(f=0; frx_np[i]); + rx_np_log[OFDM_ROWSPERFRAME*OFDM_NC*f + i].imag = cimagf(ofdm->rx_np[i]); + } + /* note phase/amp ests the same for each col, but check them all anyway */ for (i = 0; i < OFDM_ROWSPERFRAME; i++) { @@ -176,6 +186,8 @@ int main(int argc, char *argv[]) } foff_hz_log[f] = ofdm->foff_est_hz; + timing_est_log[f] = ofdm->timing_est + 1; /* offset by 1 to match Octave */ + sample_point_log[f] = ofdm->sample_point + 1; /* offset by 1 to match Octave */ memcpy(&rx_bits_log[OFDM_BITSPERFRAME*f], rx_bits, sizeof(rx_bits)); } @@ -197,6 +209,9 @@ int main(int argc, char *argv[]) octave_save_float(fout, "phase_est_pilot_log_c", (float*)phase_est_pilot_log, OFDM_ROWSPERFRAME*NFRAMES, OFDM_NC, OFDM_NC); octave_save_float(fout, "rx_amp_log_c", (float*)rx_amp_log, 1, OFDM_ROWSPERFRAME*OFDM_NC*NFRAMES, OFDM_ROWSPERFRAME*OFDM_NC*NFRAMES); octave_save_float(fout, "foff_hz_log_c", foff_hz_log, NFRAMES, 1, 1); + octave_save_int(fout, "timing_est_log_c", timing_est_log, NFRAMES, 1); + octave_save_int(fout, "sample_point_log_c", sample_point_log, NFRAMES, 1); + octave_save_complex(fout, "rx_np_log_c", (COMP*)rx_np_log, 1, OFDM_ROWSPERFRAME*OFDM_NC*NFRAMES, OFDM_ROWSPERFRAME*OFDM_NC*NFRAMES); octave_save_int(fout, "rx_bits_log_c", rx_bits_log, 1, OFDM_BITSPERFRAME*NFRAMES); fclose(fout); -- 2.25.1