From a02a6a33d2cc8a1ca8cf126b5187339ffdf89b93 Mon Sep 17 00:00:00 2001 From: drowe67 Date: Mon, 19 Jun 2017 00:42:20 +0000 Subject: [PATCH] added phase_est_pilot and rx_amp, working OK with phase est swicthed off git-svn-id: https://svn.code.sf.net/p/freetel/code@3215 01035d8c-6547-0410-b346-abe4f91aad63 --- codec2-dev/octave/autotest.m | 10 ++++++++-- codec2-dev/octave/ofdm_dev.m | 2 +- codec2-dev/octave/ofdm_lib.m | 2 +- codec2-dev/octave/tofdm.m | 19 +++++++++++++++---- codec2-dev/src/ofdm.c | 19 ++++++++++++++++--- codec2-dev/unittest/tofdm.c | 16 +++++++++++++++- 6 files changed, 56 insertions(+), 12 deletions(-) diff --git a/codec2-dev/octave/autotest.m b/codec2-dev/octave/autotest.m index b6623d8a..05ff935c 100644 --- a/codec2-dev/octave/autotest.m +++ b/codec2-dev/octave/autotest.m @@ -44,7 +44,7 @@ function plot_sig_and_error(plotnum, subplotnum, sig, error, titlestr, axisvec) endfunction -function check(a, b, test_name, tol) +function check(a, b, test_name, tol, its_an_angle = 0) global passes; global fails; @@ -65,7 +65,13 @@ function check(a, b, test_name, tol) end printf(": "); - e = sum(sum(abs(a - b))/ll); + if its_an_angle + % take into account pi is close to -pi for angles in rads + e = sum(sum(abs(exp(j*a) - exp(j*b)))/ll); + else + e = sum(sum(abs(a - b))/ll); + end + if e < tol printf("OK\n"); passes++; diff --git a/codec2-dev/octave/ofdm_dev.m b/codec2-dev/octave/ofdm_dev.m index f66e08cb..bb356754 100644 --- a/codec2-dev/octave/ofdm_dev.m +++ b/codec2-dev/octave/ofdm_dev.m @@ -454,7 +454,7 @@ function [sim_out rx states] = run_sim(sim_in) title('Scatter'); figure(2); clf; - plot(phase_est_pilot_log(:,2:Nc+1),'g+', 'markersize', 5); + plot(phase_est_pilot_log,'g+', 'markersize', 5); title('Phase est'); axis([1 Nrp -pi pi]); diff --git a/codec2-dev/octave/ofdm_lib.m b/codec2-dev/octave/ofdm_lib.m index 6044db41..323fbfde 100644 --- a/codec2-dev/octave/ofdm_lib.m +++ b/codec2-dev/octave/ofdm_lib.m @@ -383,7 +383,7 @@ function [rx_bits states aphase_est_pilot_log rx_np rx_amp] = ofdm_demod(states, end rx_bits = [rx_bits abit]; end % c=2:Nc+1 - aphase_est_pilot_log = [aphase_est_pilot_log; aphase_est_pilot]; + aphase_est_pilot_log = [aphase_est_pilot_log; aphase_est_pilot(2:Nc+1)]; end % Adjust nin to take care of sample clock offset diff --git a/codec2-dev/octave/tofdm.m b/codec2-dev/octave/tofdm.m index c1f43e61..8ade1366 100644 --- a/codec2-dev/octave/tofdm.m +++ b/codec2-dev/octave/tofdm.m @@ -41,7 +41,9 @@ nin = Nsamperframe+2*(M+Ncp); states.rxbuf(Nrxbuf-nin+1:Nrxbuf) = rx(prx:nin); prx += nin; -rxbuf_log = []; rxbuf_in_log = []; rx_sym_log = []; foff_hz_log = []; rx_bits_log = []; +rxbuf_log = []; rxbuf_in_log = []; rx_sym_log = []; foff_hz_log = []; +phase_est_pilot_log = []; rx_amp_log = []; +rx_bits_log = []; states.timing_en = 0; states.foff_est_en = 1; @@ -69,6 +71,8 @@ for f=1:Nframes rxbuf_in_log = [rxbuf_in_log rxbuf_in]; rxbuf_log = [rxbuf_log states.rxbuf]; rx_sym_log = [rx_sym_log; states.rx_sym]; + 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]; rx_bits_log = [rx_bits_log rx_bits]; @@ -83,7 +87,7 @@ end if exist("path_to_tofdm", "var") == 0 path_to_tofdm = "../build_linux/unittest/tofdm"; end -system(path_to_tofdm) +system(path_to_tofdm); load tofdm_out.txt; @@ -101,9 +105,14 @@ stem_sig_and_error(4, 212, imag(rxbuf_log_c), imag(rxbuf_log - rxbuf_log_c), 'rx 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(6, 111, foff_hz_log_c, (foff_hz_log - foff_hz_log_c), 'foff hz', [1 length(foff_hz_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, 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(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(8, 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 ----------------------------- @@ -113,5 +122,7 @@ check(tx_log, tx_log_c, 'tx'); check(rxbuf_in_log, rxbuf_in_log_c, 'rxbuf in'); 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(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 52d0071f..5397e444 100644 --- a/codec2-dev/src/ofdm.c +++ b/codec2-dev/src/ofdm.c @@ -602,6 +602,9 @@ void ofdm_demod(struct OFDM *ofdm, int *rx_bits, COMP *rxbuf_in) { aphase_est_pilot_rect += vector_sum(symbol, 3); aphase_est_pilot[i] = cargf(aphase_est_pilot_rect); + + /* TODO David: WTF 12.0 constant? Something to do with LDPC input scaling? */ + aamp_est_pilot[i] = cabsf(aphase_est_pilot_rect / 12.0f); } @@ -624,7 +627,17 @@ void ofdm_demod(struct OFDM *ofdm, int *rx_bits, COMP *rxbuf_in) { } ofdm->rx_np[(rr * OFDM_ROWSPERFRAME) + (i - 1)] = rx_corr; - ofdm->rx_amp[(rr * OFDM_ROWSPERFRAME) + (i - 1)] = aamp_est_pilot[i]; + + /* note even though amp ests are the same for each col, + the FEC decoder likes to have one amplitude per symbol + so convenient to log them all */ + + ofdm->rx_amp[(rr * OFDM_NC) + (i - 1)] = aamp_est_pilot[i]; + + /* note like amps in this implementation phase ests the + same for each col, but we log them for each symbol anyway */ + + ofdm->aphase_est_pilot_log[(rr * OFDM_NC) + (i - 1)] = aphase_est_pilot[i]; if (OFDM_BPS == 1) { rx_bits[bit_index++] = crealf(rx_corr) > 0.0f; @@ -633,9 +646,9 @@ void ofdm_demod(struct OFDM *ofdm, int *rx_bits, COMP *rxbuf_in) { rx_bits[bit_index++] = abit[1]; rx_bits[bit_index++] = abit[0]; } - } - ofdm->aphase_est_pilot_log[(rr * OFDM_ROWSPERFRAME) + (i - 1)] = aphase_est_pilot[i]; + } + } /* Adjust nin to take care of sample clock offset */ diff --git a/codec2-dev/unittest/tofdm.c b/codec2-dev/unittest/tofdm.c index aca6609e..4113d585 100644 --- a/codec2-dev/unittest/tofdm.c +++ b/codec2-dev/unittest/tofdm.c @@ -48,7 +48,8 @@ int main(int argc, char *argv[]) int max_samples_per_frame = ofdm_get_max_samples_per_frame(); struct OFDM *ofdm; - COMP tx[samples_per_frame]; /* one frame of tx samples */ + COMP tx[samples_per_frame]; /* one frame of tx samples */ + int rx_bits[OFDM_BITSPERFRAME]; /* one frame of rx bits */ /* log arrays */ @@ -58,6 +59,8 @@ int main(int argc, char *argv[]) COMP rxbuf_in_log[max_samples_per_frame*NFRAMES]; 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]; + float rx_amp_log[OFDM_ROWSPERFRAME*OFDM_NC*NFRAMES]; float foff_hz_log[NFRAMES]; int rx_bits_log[OFDM_BITSPERFRAME*NFRAMES]; @@ -163,6 +166,15 @@ int main(int argc, char *argv[]) } } + /* note phase/amp ests the same for each col, but check them all anyway */ + + for (i = 0; i < OFDM_ROWSPERFRAME; i++) { + for (j = 0; j < OFDM_NC; j++) { + phase_est_pilot_log[OFDM_ROWSPERFRAME*f+i][j] = ofdm->aphase_est_pilot_log[OFDM_NC*i+j]; + rx_amp_log[OFDM_ROWSPERFRAME*OFDM_NC*f+OFDM_NC*i+j] = ofdm->rx_amp[OFDM_NC*i+j]; + } + } + foff_hz_log[f] = ofdm->foff_est_hz; memcpy(&rx_bits_log[OFDM_BITSPERFRAME*f], rx_bits, sizeof(rx_bits)); @@ -182,6 +194,8 @@ int main(int argc, char *argv[]) octave_save_complex(fout, "rxbuf_in_log_c", (COMP*)rxbuf_in_log, 1, nin_tot, nin_tot); octave_save_complex(fout, "rxbuf_log_c", (COMP*)rxbuf_log, 1, OFDM_RXBUF*NFRAMES, OFDM_RXBUF*NFRAMES); octave_save_complex(fout, "rx_sym_log_c", (COMP*)rx_sym_log, (OFDM_NS + 3)*NFRAMES, OFDM_NC + 2, OFDM_NC + 2); + 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, "rx_bits_log_c", rx_bits_log, 1, OFDM_BITSPERFRAME*NFRAMES); fclose(fout); -- 2.25.1