% Octave script for comparing Octave and C versions of OFDZM modem
-Nframes = 2;
+Nframes = 3;
more off;
ofdm_lib;
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
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');
#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;
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; i<nin; i++,prx++) {
+ ofdm->rxbuf[OFDM_RXBUF-nin+i] = rx[prx].real + I*rx[prx].imag;
+ }
+
+ int nin_tot = 0;
+
for(f=0; f<NFRAMES; f++) {
- /* todo: run demod and log states as it runs */
+ /* For initial testng, timing est is off, so nin is always
+ fixed. TODO: we need a constant for rxbuf_in[] size that
+ is the maximum possible nin */
+
+ nin = ofdm->nin;
+ 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; i<nin; i++) {
+ rxbuf_in[i].real = 0.0;
+ rxbuf_in[i].imag = 0.0;
+ }
+
+ if (lnew) {
+ for(i=0; i<lnew; i++, prx++) {
+ rxbuf_in[i] = rx[prx];
+ }
+ }
+ assert(prx <= OFDM_SAMPLESPERFRAME*NFRAMES);
+#ifdef T
+
+ //ofdm_demod(ofdm, rx_bits, rxbuf_in);
+
+ /* rx vector logging -----------------------------------*/
+
+#endif
+ assert(nin_tot < OFDM_SAMPLESPERFRAME*NFRAMES);
+ memcpy(&rxbuf_in_log[nin_tot], rxbuf_in, sizeof(COMP)*nin);
+ nin_tot += nin;
+
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]);
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);