added demod function, mod and demo use raw files as wave functions in Octave seemed...
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Thu, 1 Mar 2012 05:12:35 +0000 (05:12 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Thu, 1 Mar 2012 05:12:35 +0000 (05:12 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@334 01035d8c-6547-0410-b346-abe4f91aad63

codec2-dev/octave/fdmdv_demod.m [new file with mode: 0644]
codec2-dev/octave/fdmdv_mod.m

diff --git a/codec2-dev/octave/fdmdv_demod.m b/codec2-dev/octave/fdmdv_demod.m
new file mode 100644 (file)
index 0000000..f19d994
--- /dev/null
@@ -0,0 +1,64 @@
+% fdmdv_demod.m
+%
+% Demodulator function for FDMDV modem.
+%
+% Copyright David Rowe 2012
+% This program is distributed under the terms of the GNU General Public License 
+% Version 2
+%
+
+function fdmdv_demod(rawfilename)
+
+fdmdv; % include modem code
+
+fin = fopen(rawfilename, "rb");
+rx_fdm = fread(fin, Inf, "short");
+gain = 1000;
+rx_fdm /= gain;
+frames = floor(length(rx_fdm)/M);
+
+total_bit_errors = 0;
+total_bits = 0;
+
+rx_timing_log = [];
+rx_symbols_log = [];
+
+% Main loop ----------------------------------------------------
+
+for i=1:frames
+  rx_baseband = fdm_downconvert(rx_fdm((i-1)*M+1:i*M));
+  rx_filt = rx_filter(rx_baseband);
+
+  [rx_symbols rx_timing] = rx_est_timing(rx_filt, rx_baseband);
+  rx_timing_log = [rx_timing_log rx_timing];
+
+  rx_symbols_log = [rx_symbols_log rx_symbols];
+  rx_bits = qpsk_to_bits(rx_symbols);
+
+  [sync bit_errors] = put_test_bits(rx_bits);
+
+  if sync == 1
+    total_bit_errors = total_bit_errors + bit_errors;
+    total_bits = total_bits + Ntest_bits;
+  endif
+
+  end
+
+end
+
+ber = total_bit_errors/total_bits;
+printf("%d bits  %d errors  Meas BER: %1.4f\n", total_bits, total_bit_errors,ber);
+
+figure(1)
+clf;
+[n m] = size(rx_symbols_log);
+plot(real(rx_symbols_log(:,20:m)),imag(rx_symbols_log(:,20:m)),'+')
+figure(2)
+clf;
+subplot(211)
+plot(rx_timing_log)
+subplot(212)
+Nfft=Fs;
+S=fft(rx_fdm,Nfft);
+SdB=20*log10(abs(S));
+plot(SdB(1:Fs/4))
index fe55456f3817356170fffccdc4c03b4b3dd60b30..7148619c7c9db357746cf3437eba8789bd86bfe7 100644 (file)
@@ -7,15 +7,13 @@
 % Version 2
 %
 
-function tx_fdm = fdmdv_mod(wavefilename, nbits)
-
-% Main loop ----------------------------------------------------
+function tx_fdm = fdmdv_mod(rawfilename, nbits)
 
 fdmdv; % include modem code
 
 frames = floor(nbits/(Nc*Nb));
 tx_fdm = [];
-tx_gain = 1000;
+gain = 1000; % Sccle up to 16 bit shorts
 
 for i=1:frames
   tx_bits = get_test_bits(Nc*Nb);
@@ -24,6 +22,6 @@ for i=1:frames
   tx_fdm = [tx_fdm fdm_upconvert(tx_baseband)];
 end
 
-tx_fdm *= tx_gain;
-
-wavwrite(tx_fdm',8000,16,wavefilename)
+tx_fdm *= gain;
+fout = fopen(rawfilename,"wb");
+fwrite(fout, tx_fdm, "short");