1% fdmdv_demod_c.m 2% 3% Plots Octave dump file information from C FDMDV demodulator program, 4% to give a similar set of plots to fdmdv_demod.m. Useful for off 5% line analysis of demod performance. 6% 7% Copyright David Rowe 2012 8% This program is distributed under the terms of the GNU General Public License 9% Version 2 10% 11 12function fdmdv_demod_c(dumpfilename, bits) 13 14 fdmdv; % include modem code 15 f = fdmdv_init; 16 Nc = f.Nc; Nb = f.Nb; Rs = f.Rs; M = f.M; Fs = f.Fs; 17 test_bits = f.test_bits; 18 19 frames = bits/(Nc*Nb); 20 21 load(dumpfilename); 22 23 % BER stats 24 25 total_bit_errors = 0; 26 total_bits = 0; 27 bit_errors_log = []; 28 sync_log = []; 29 test_frame_sync_log = []; 30 test_frame_sync_state = 0; 31 32 % Run thru received bits to look for test pattern 33 34 bits_per_frame = Nc*Nb; 35 36 for fr=1:frames 37 38 rx_bits = rx_bits_log_c((fr-1)*bits_per_frame+1:fr*bits_per_frame); 39 40 % count bit errors if we find a test frame 41 42 [test_frame_sync bit_errors error_pattern f] = put_test_bits(f, test_bits, rx_bits); 43 if (test_frame_sync == 1) 44 total_bit_errors = total_bit_errors + bit_errors; 45 total_bits = total_bits + f.Ntest_bits; 46 bit_errors_log = [bit_errors_log bit_errors/f.Ntest_bits]; 47 else 48 bit_errors_log = [bit_errors_log 0]; 49 end 50 51 % test frame sync state machine, just for more informative plots 52 53 next_test_frame_sync_state = test_frame_sync_state; 54 if (test_frame_sync_state == 0) 55 if (test_frame_sync == 1) 56 next_test_frame_sync_state = 1; 57 test_frame_count = 0; 58 end 59 end 60 61 if (test_frame_sync_state == 1) 62 % we only expect another test_frame_sync pulse every 4 symbols 63 test_frame_count++; 64 if (test_frame_count == 4) 65 test_frame_count = 0; 66 if ((test_frame_sync == 0)) 67 next_test_frame_sync_state = 0; 68 end 69 end 70 end 71 test_frame_sync_state = next_test_frame_sync_state; 72 test_frame_sync_log = [test_frame_sync_log test_frame_sync_state]; 73 end 74 75 ber = total_bit_errors / total_bits; 76 printf("%d bits %d errors BER: %1.4f\n",total_bits, total_bit_errors, ber); 77 78 % --------------------------------------------------------------------- 79 % Plots 80 % --------------------------------------------------------------------- 81 82 xt = (1:frames)/Rs; 83 secs = frames/Rs; 84 85 figure(1) 86 clf; 87 plot(real(rx_symbols_log_c(1:Nc+1,15:frames)),imag(rx_symbols_log_c(1:Nc+1,15:frames)),'+') 88 %plot(real(rx_symbols_log_c(Nc+1,15:frames)),imag(rx_symbols_log_c(Nc+1,15:frames)),'+') 89 axis([-2 2 -2 2]); 90 title('Scatter Diagram'); 91 92 figure(2) 93 clf; 94 subplot(211) 95 plot(xt, rx_timing_log_c(1:frames)) 96 title('timing offset (samples)'); 97 subplot(212) 98 plot(xt, foff_log_c(1:frames), '-;freq offset;') 99 hold on; 100 plot(xt, sync_log_c(1:frames)*75, 'r;course-fine;'); 101 hold off; 102 title('Freq offset (Hz)'); 103 grid 104 105 figure(3) 106 clf; 107 subplot(211) 108 b = M*frames; 109 xt1 = (1:b)/Fs; 110 plot(xt1, rx_fdm_log_c(1:b)); 111 title('Rx FDM Signal'); 112 subplot(212); 113 plot_specgram(rx_fdm_log_c(1:b), 8000); 114 title('FDM Rx Spectrogram'); 115 116 figure(4) 117 clf; 118 subplot(311) 119 stem(xt, sync_bit_log_c(1:frames)) 120 axis([0 secs 0 1.5]); 121 title('BPSK Sync') 122 subplot(312) 123 stem(xt, bit_errors_log); 124 title('Bit Errors for test frames') 125 subplot(313) 126 plot(xt, test_frame_sync_log); 127 axis([0 secs 0 1.5]); 128 title('Test Frame Sync') 129 130 figure(5) 131 clf; 132 plot(xt, snr_est_log_c(1:frames)); 133 title('SNR Estimates') 134 135endfunction 136