From dfc9d752f827ec5d059108e9b3bfb7a85596600a Mon Sep 17 00:00:00 2001 From: drowe67 Date: Fri, 16 Jun 2017 07:17:18 +0000 Subject: [PATCH] basic ofdm rx tests working git-svn-id: https://svn.code.sf.net/p/freetel/code@3199 01035d8c-6547-0410-b346-abe4f91aad63 --- codec2-dev/octave/tofdm.m | 26 ++++++++++----- codec2-dev/unittest/tofdm.c | 66 +++++++++++++++++++++++++++++++++++-- 2 files changed, 81 insertions(+), 11 deletions(-) diff --git a/codec2-dev/octave/tofdm.m b/codec2-dev/octave/tofdm.m index 82fd2cc0..d581628c 100644 --- a/codec2-dev/octave/tofdm.m +++ b/codec2-dev/octave/tofdm.m @@ -4,7 +4,7 @@ % Octave script for comparing Octave and C versions of OFDZM modem -Nframes = 2; +Nframes = 3; more off; ofdm_lib; @@ -42,24 +42,28 @@ states.rxbuf(Nrxbuf-nin+1:Nrxbuf) = rx(prx:nin); prx += nin; rxbuf_log = []; +rxbuf_in_log = []; for f=1:Nframes % insert samples at end of buffer, set to zero if no samples % available to disable phase estimation on future pilots on last % frame of simulation - - lnew = min(Nsam-prx,states.nin); - rxbuf_in = zeros(1,states.nin); - + + nin = states.nin; + lnew = min(Nsam-prx+1,nin); + rxbuf_in = zeros(1,nin); + %printf("nin: %d prx: %d lnew: %d\n", nin, prx, lnew); if lnew rxbuf_in(1:lnew) = rx(prx:prx+lnew-1); end - prx += states.nin; + prx += lnew; +#{ [rx_bits_raw states aphase_est_pilot_log arx_np arx_amp] = ofdm_demod(states, rxbuf_in); - +#} % log some states for comparison to C + rxbuf_in_log = [rxbuf_in_log rxbuf_in]; rxbuf_log = [rxbuf_log states.rxbuf]; end @@ -72,10 +76,16 @@ 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]) 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), real(tx_log - tx_log_c), 'tx im', [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(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(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]) % Run through checklist ----------------------------- check(W, W_c, 'W'); check(tx_bits_log, tx_bits_log_c, 'tx_bits'); check(tx_log, tx_log_c, 'tx'); +check(rxbuf_in_log, rxbuf_in_log_c, 'rxbuf in'); +check(rxbuf_log, rxbuf_log_c, 'rxbuf'); diff --git a/codec2-dev/unittest/tofdm.c b/codec2-dev/unittest/tofdm.c index 39d8c48b..ce64b274 100644 --- a/codec2-dev/unittest/tofdm.c +++ b/codec2-dev/unittest/tofdm.c @@ -40,15 +40,19 @@ #include "octave.h" #include "test_bits_ofdm.h" -#define NFRAMES 2 +#define NFRAMES 3 int main(int argc, char *argv[]) { struct OFDM *ofdm; COMP tx[OFDM_SAMPLESPERFRAME]; /* one frame of tx samples */ + int rx_bits[OFDM_BITSPERFRAME]; /* one frame of rx bits */ + + /* log arrays */ int tx_bits_log[OFDM_BITSPERFRAME*NFRAMES]; COMP tx_log[OFDM_SAMPLESPERFRAME*NFRAMES]; + COMP rxbuf_in_log[OFDM_SAMPLESPERFRAME*NFRAMES]; COMP rxbuf_log[OFDM_RXBUF*NFRAMES]; FILE *fout; @@ -79,8 +83,63 @@ int main(int argc, char *argv[]) Demod \*---------------------------------------------------------*/ + COMP *rx = tx_log; + + /* Init rx with ideal timing so we can test with timing estimation disabled */ + + int Nsam = OFDM_SAMPLESPERFRAME*NFRAMES; + int prx = 0; + int nin = OFDM_SAMPLESPERFRAME + 2*(OFDM_M+OFDM_NCP); + + int lnew; + COMP rxbuf_in[OFDM_SAMPLESPERFRAME]; + + for (i=0; irxbuf[OFDM_RXBUF-nin+i] = rx[prx].real + I*rx[prx].imag; + } + + int nin_tot = 0; + for(f=0; fnin; + assert(nin == OFDM_SAMPLESPERFRAME); + + /* Insert samples at end of buffer, set to zero if no samples + available to disable phase estimation on future pilots on + last frame of simulation. */ + + if ((Nsam-prx) < nin) { + lnew = Nsam-prx; + } else { + lnew = nin; + } + //printf("nin: %d prx: %d lnew: %d\n", nin, prx, lnew); + for(i=0; irxbuf[i]); rxbuf_log[OFDM_RXBUF*f+i].imag = cimagf(ofdm->rxbuf[i]); @@ -98,7 +157,8 @@ int main(int argc, char *argv[]) octave_save_complex(fout, "W_c", (COMP*)ofdm->W, OFDM_NC + 2, OFDM_M, OFDM_M); octave_save_int(fout, "tx_bits_log_c", tx_bits_log, 1, OFDM_BITSPERFRAME*NFRAMES); octave_save_complex(fout, "tx_log_c", (COMP*)tx_log, 1, OFDM_SAMPLESPERFRAME*NFRAMES, OFDM_SAMPLESPERFRAME*NFRAMES); - octave_save_complex(fout, "rxbuf_c", (COMP*)rxbuf_log, 1, OFDM_RXBUF*NFRAMES, OFDM_RXBUF*NFRAMES); + 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); fclose(fout); ofdm_destroy(ofdm); -- 2.25.1