From f026f61c5e4abee73737f9b141fb30ed9223fb01 Mon Sep 17 00:00:00 2001 From: drowe67 Date: Wed, 14 Jun 2017 21:08:01 +0000 Subject: [PATCH] starting rx side of tofdm.[cm] git-svn-id: https://svn.code.sf.net/p/freetel/code@3193 01035d8c-6547-0410-b346-abe4f91aad63 --- codec2-dev/octave/tofdm.m | 48 +++++++++++++++++++++++++++++++++---- codec2-dev/unittest/tofdm.c | 22 ++++++++++------- 2 files changed, 58 insertions(+), 12 deletions(-) diff --git a/codec2-dev/octave/tofdm.m b/codec2-dev/octave/tofdm.m index ffff746a..82fd2cc0 100644 --- a/codec2-dev/octave/tofdm.m +++ b/codec2-dev/octave/tofdm.m @@ -4,13 +4,15 @@ % Octave script for comparing Octave and C versions of OFDZM modem -Frames = 1; +Nframes = 2; more off; ofdm_lib; autotest; -% Run a few frames of Octave version +% --------------------------------------------------------------------- +% Run Octave version +% --------------------------------------------------------------------- Ts = 0.018; Tcp = 0.002; Rs = 1/Ts; bps = 2; Nc = 16; Ns = 8; states = ofdm_init(bps, Rs, Tcp, Ns, Nc); @@ -19,13 +21,51 @@ ofdm_load_const; rand('seed',1); tx_bits = round(rand(1,Nbitsperframe)); +% Run tx loop + tx_bits_log = []; tx_log = []; -for f=1:Frames +for f=1:Nframes tx_bits_log = [tx_bits_log tx_bits]; tx_log = [tx_log ofdm_mod(states, tx_bits)]; end -% Run C version and plot Octave and C states and differences ----------------------------- +% Channel simulation + +rx = tx_log; + +% Init rx with ideal timing so we can test with timing estimation disabled + +Nsam = length(rx); +prx = 1; +nin = Nsamperframe+2*(M+Ncp); +states.rxbuf(Nrxbuf-nin+1:Nrxbuf) = rx(prx:nin); +prx += nin; + +rxbuf_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); + + if lnew + rxbuf_in(1:lnew) = rx(prx:prx+lnew-1); + end + prx += states.nin; + [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_log = [rxbuf_log states.rxbuf]; +end + +% --------------------------------------------------------------------- +% Run C version and plot Octave and C states and differences +% --------------------------------------------------------------------- system('../build_linux/unittest/tofdm'); load tofdm_out.txt; diff --git a/codec2-dev/unittest/tofdm.c b/codec2-dev/unittest/tofdm.c index 61e3a3dc..39d8c48b 100644 --- a/codec2-dev/unittest/tofdm.c +++ b/codec2-dev/unittest/tofdm.c @@ -40,24 +40,25 @@ #include "octave.h" #include "test_bits_ofdm.h" -#define FRAMES 1 +#define NFRAMES 2 int main(int argc, char *argv[]) { struct OFDM *ofdm; COMP tx[OFDM_SAMPLESPERFRAME]; /* one frame of tx samples */ - int tx_bits_log[OFDM_BITSPERFRAME*FRAMES]; - COMP tx_log[OFDM_SAMPLESPERFRAME*FRAMES]; + int tx_bits_log[OFDM_BITSPERFRAME*NFRAMES]; + COMP tx_log[OFDM_SAMPLESPERFRAME*NFRAMES]; + COMP rxbuf_log[OFDM_RXBUF*NFRAMES]; FILE *fout; - int f; + int f,i; ofdm = ofdm_create(); assert(ofdm != NULL); /* Main Loop ---------------------------------------------------------------------*/ - for(f=0; frxbuf[i]); + rxbuf_log[OFDM_RXBUF*f+i].imag = cimagf(ofdm->rxbuf[i]); + } } /*---------------------------------------------------------*\ @@ -91,8 +96,9 @@ int main(int argc, char *argv[]) assert(fout != NULL); fprintf(fout, "# Created by tofdm.c\n"); 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*FRAMES); - octave_save_complex(fout, "tx_log_c", (COMP*)tx_log, 1, OFDM_SAMPLESPERFRAME*FRAMES, OFDM_SAMPLESPERFRAME*FRAMES); + 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); fclose(fout); ofdm_destroy(ofdm); -- 2.25.1