From: drowe67 Date: Thu, 3 May 2012 06:33:49 +0000 (+0000) Subject: C and Octave versions of fdmdv_demod now exactly the same, and have the same instrume... X-Git-Url: http://git.whiteaudio.com/gitweb/?a=commitdiff_plain;h=07bfb82a7729b48792549c1b2962e5bb348d6c3c;p=freetel-svn-tracking.git C and Octave versions of fdmdv_demod now exactly the same, and have the same instrumentation git-svn-id: https://svn.code.sf.net/p/freetel/code@391 01035d8c-6547-0410-b346-abe4f91aad63 --- diff --git a/codec2-dev/octave/fdmdv_demod.m b/codec2-dev/octave/fdmdv_demod.m index b30b497c..0ef4f673 100644 --- a/codec2-dev/octave/fdmdv_demod.m +++ b/codec2-dev/octave/fdmdv_demod.m @@ -166,9 +166,9 @@ function fdmdv_demod(rawfilename, nbits, pngname) plot(xt, rx_timing_log) title('timing offset (samples)'); subplot(212) - plot(xt, foff_log) + plot(xt, foff_log, '-;freq offset;') hold on; - plot(xt, track_log*75, 'r'); + plot(xt, track_log*75, 'r;course-fine;'); hold off; title('Freq offset (Hz)'); grid @@ -181,11 +181,8 @@ function fdmdv_demod(rawfilename, nbits, pngname) plot(xt1, rx_fdm_log); title('Rx FDM Signal'); subplot(212) - Nfft=Fs; - S=fft(rx_fdm_log,Nfft); - SdB=20*log10(abs(S)); - plot(SdB(1:Fs/4)) - title('FDM Rx Spectrum'); + spec(rx_fdm_log,8000); + title('FDM Rx Spectrogram'); figure(4) clf; diff --git a/codec2-dev/octave/fdmdv_demod_c.m b/codec2-dev/octave/fdmdv_demod_c.m index 09b7e82f..e83cf392 100644 --- a/codec2-dev/octave/fdmdv_demod_c.m +++ b/codec2-dev/octave/fdmdv_demod_c.m @@ -12,10 +12,63 @@ function fdmdv_demod_c(dumpfilename, bits) fdmdv; % include modem code + frames = bits/(Nc*Nb); load(dumpfilename); + % BER stats + + total_bit_errors = 0; + total_bits = 0; + bit_errors_log = []; + sync_log = []; + test_frame_sync_log = []; + test_frame_sync_state = 0; + + % Run thru received bits to look for test pattern + + bits_per_frame = Nc*Nb; + + for f=1:frames + + rx_bits = rx_bits_log_c((f-1)*bits_per_frame+1:f*bits_per_frame); + + % count bit errors if we find a test frame + + [test_frame_sync bit_errors] = put_test_bits(rx_bits); + if (test_frame_sync == 1) + total_bit_errors = total_bit_errors + bit_errors; + total_bits = total_bits + Ntest_bits; + bit_errors_log = [bit_errors_log bit_errors/Ntest_bits]; + else + bit_errors_log = [bit_errors_log 0]; + end + + % test frame sync state machine, just for more informative plots + + next_test_frame_sync_state = test_frame_sync_state; + if (test_frame_sync_state == 0) + if (test_frame_sync == 1) + next_test_frame_sync_state = 1; + test_frame_count = 0; + end + end + + if (test_frame_sync_state == 1) + % we only expect another test_frame_sync pulse every 4 symbols + test_frame_count++; + if (test_frame_count == 4) + test_frame_count = 0; + if ((test_frame_sync == 0)) + next_test_frame_sync_state = 0; + end + end + end + test_frame_sync_state = next_test_frame_sync_state; + test_frame_sync_log = [test_frame_sync_log test_frame_sync_state]; + end + % --------------------------------------------------------------------- % Plots % --------------------------------------------------------------------- @@ -35,11 +88,37 @@ function fdmdv_demod_c(dumpfilename, bits) plot(xt, rx_timing_log_c(1:frames)) title('timing offset (samples)'); subplot(212) - plot(xt, foff_log_c(1:frames)) + plot(xt, foff_log_c(1:frames), '-;freq offset;') hold on; - plot(xt, coarse_fine_log_c(1:frames)*75, 'r'); + plot(xt, coarse_fine_log_c(1:frames)*75, 'r;course-fine;'); hold off; title('Freq offset (Hz)'); grid + figure(3) + clf; + subplot(211) + b = M*frames; + xt1 = (1:b)/Fs; + plot(xt1, rx_fdm_log_c(1:b)); + title('Rx FDM Signal'); + subplot(212) + spec(rx_fdm_log_c(1:b),8000); + title('FDM Rx Spectrogram'); + + figure(4) + clf; + subplot(311) + stem(xt, sync_bit_log_c(1:frames)) + axis([0 secs 0 1.5]); + title('BPSK Sync') + subplot(312) + stem(xt, bit_errors_log); + title('Bit Errors for test frames') + subplot(313) + plot(xt, test_frame_sync_log); + axis([0 secs 0 1.5]); + title('Test Frame Sync') + + endfunction diff --git a/codec2-dev/src/fdmdv_demod.c b/codec2-dev/src/fdmdv_demod.c index cfb2667a..cfd3132a 100644 --- a/codec2-dev/src/fdmdv_demod.c +++ b/codec2-dev/src/fdmdv_demod.c @@ -8,6 +8,10 @@ outputs a file of bits. The output file is assumed to be arranged as codec frames of 56 bits (7 bytes) which are received as two 28 bit modem frames. + + Demod states can be optionally logged to an Octave file for display + using the Octave script fdmdv_demod_c.m. This is useful for + checking demod performance. \*---------------------------------------------------------------------------*/ @@ -60,13 +64,17 @@ int main(int argc, char *argv[]) int sync_bit; int state, next_state; - int frames; + int f; FILE *foct = NULL; struct FDMDV_STATS stats; + float rx_fdm_log[FDMDV_MAX_SAMPLES_PER_FRAME*MAX_FRAMES]; + int rx_fdm_log_col_index; COMP rx_symbols_log[FDMDV_NSYM][MAX_FRAMES]; int coarse_fine_log[MAX_FRAMES]; float rx_timing_log[MAX_FRAMES]; float foff_log[MAX_FRAMES]; + int sync_bit_log[MAX_FRAMES]; + int rx_bits_log[FDMDV_BITS_PER_FRAME*MAX_FRAMES]; if (argc < 3) { printf("usage: %s InputModemRawFile OutputBitFile [OctaveDumpFile]\n", argv[0]); @@ -89,9 +97,10 @@ int main(int argc, char *argv[]) } fdmdv = fdmdv_create(); - frames = 0; + f = 0; state = 0; nin = FDMDV_NOM_SAMPLES_PER_FRAME; + rx_fdm_log_col_index = 0; while(fread(rx_fdm_scaled, sizeof(short), nin, fin) == nin) { @@ -101,14 +110,23 @@ int main(int argc, char *argv[]) /* log data for optional Octave dump */ - if (frames < MAX_FRAMES) { + if (f < MAX_FRAMES) { fdmdv_get_demod_stats(fdmdv, &stats); + + /* log modem states for later dumping to Octave log file */ + + memcpy(&rx_fdm_log[rx_fdm_log_col_index], rx_fdm, sizeof(float)*nin); + rx_fdm_log_col_index += nin; + for(c=0; c