% 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);
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;
#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; f<FRAMES; f++) {
+ for(f=0; f<NFRAMES; f++) {
/* --------------------------------------------------------*\
Mod
Demod
\*---------------------------------------------------------*/
- for(f=0; f<FRAMES; f++) {
+ for(f=0; f<NFRAMES; f++) {
/* todo: run demod and log states as it runs */
+ for(i=0; i<OFDM_RXBUF; i++) {
+ rxbuf_log[OFDM_RXBUF*f+i].real = crealf(ofdm->rxbuf[i]);
+ rxbuf_log[OFDM_RXBUF*f+i].imag = cimagf(ofdm->rxbuf[i]);
+ }
}
/*---------------------------------------------------------*\
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);