2
0

fdmdv_demod_c.m 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. function fdmdv_demod_c(dumpfilename, bits)
  12. fdmdv; % include modem code
  13. frames = bits/(Nc*Nb);
  14. load(dumpfilename);
  15. % BER stats
  16. total_bit_errors = 0;
  17. total_bits = 0;
  18. bit_errors_log = [];
  19. sync_log = [];
  20. test_frame_sync_log = [];
  21. test_frame_sync_state = 0;
  22. % Run thru received bits to look for test pattern
  23. bits_per_frame = Nc*Nb;
  24. for f=1:frames
  25. rx_bits = rx_bits_log_c((f-1)*bits_per_frame+1:f*bits_per_frame);
  26. % count bit errors if we find a test frame
  27. [test_frame_sync bit_errors] = put_test_bits(rx_bits);
  28. if (test_frame_sync == 1)
  29. total_bit_errors = total_bit_errors + bit_errors;
  30. total_bits = total_bits + Ntest_bits;
  31. bit_errors_log = [bit_errors_log bit_errors/Ntest_bits];
  32. else
  33. bit_errors_log = [bit_errors_log 0];
  34. end
  35. % test frame sync state machine, just for more informative plots
  36. next_test_frame_sync_state = test_frame_sync_state;
  37. if (test_frame_sync_state == 0)
  38. if (test_frame_sync == 1)
  39. next_test_frame_sync_state = 1;
  40. test_frame_count = 0;
  41. end
  42. end
  43. if (test_frame_sync_state == 1)
  44. % we only expect another test_frame_sync pulse every 4 symbols
  45. test_frame_count++;
  46. if (test_frame_count == 4)
  47. test_frame_count = 0;
  48. if ((test_frame_sync == 0))
  49. next_test_frame_sync_state = 0;
  50. end
  51. end
  52. end
  53. test_frame_sync_state = next_test_frame_sync_state;
  54. test_frame_sync_log = [test_frame_sync_log test_frame_sync_state];
  55. end
  56. % ---------------------------------------------------------------------
  57. % Plots
  58. % ---------------------------------------------------------------------
  59. xt = (1:frames)/Rs;
  60. secs = frames/Rs;
  61. figure(1)
  62. clf;
  63. plot(real(rx_symbols_log_c(1:Nc+1,15:frames)),imag(rx_symbols_log_c(1:Nc+1,15:frames)),'+')
  64. axis([-2 2 -2 2]);
  65. title('Scatter Diagram');
  66. figure(2)
  67. clf;
  68. subplot(211)
  69. plot(xt, rx_timing_log_c(1:frames))
  70. title('timing offset (samples)');
  71. subplot(212)
  72. plot(xt, foff_log_c(1:frames), '-;freq offset;')
  73. hold on;
  74. plot(xt, coarse_fine_log_c(1:frames)*75, 'r;course-fine;');
  75. hold off;
  76. title('Freq offset (Hz)');
  77. grid
  78. figure(3)
  79. clf;
  80. subplot(211)
  81. b = M*frames;
  82. xt1 = (1:b)/Fs;
  83. plot(xt1, rx_fdm_log_c(1:b));
  84. title('Rx FDM Signal');
  85. subplot(212)
  86. spec(rx_fdm_log_c(1:b),8000);
  87. title('FDM Rx Spectrogram');
  88. figure(4)
  89. clf;
  90. subplot(311)
  91. stem(xt, sync_bit_log_c(1:frames))
  92. axis([0 secs 0 1.5]);
  93. title('BPSK Sync')
  94. subplot(312)
  95. stem(xt, bit_errors_log);
  96. title('Bit Errors for test frames')
  97. subplot(313)
  98. plot(xt, test_frame_sync_log);
  99. axis([0 secs 0 1.5]);
  100. title('Test Frame Sync')
  101. figure(5)
  102. clf;
  103. plot(xt, snr_est_log_c(1:frames));
  104. title('SNR Estimates')
  105. endfunction