From f0056a96bb2383a4956b6f640bb6258a72e57523 Mon Sep 17 00:00:00 2001 From: drowe67 Date: Thu, 9 Jan 2014 06:44:56 +0000 Subject: [PATCH] first pass of integrating fdmdv modem with ldpc simulation in Octave git-svn-id: https://svn.code.sf.net/p/freetel/code@1353 01035d8c-6547-0410-b346-abe4f91aad63 --- codec2-dev/octave/fdmdv.m | 26 +++++++++++++++++++++++ codec2-dev/octave/fdmdv_demod.m | 37 ++++++++++++++++++++++++++++++--- codec2-dev/octave/ldpcdec.m | 20 +++++++++++------- 3 files changed, 73 insertions(+), 10 deletions(-) diff --git a/codec2-dev/octave/fdmdv.m b/codec2-dev/octave/fdmdv.m index 2a8da1e8..a0b9b6a5 100644 --- a/codec2-dev/octave/fdmdv.m +++ b/codec2-dev/octave/fdmdv.m @@ -964,6 +964,32 @@ function png_file(fig, pngfilename) print(pngname, '-dpng', "-S800,600") endfunction + +% dump rx_bits in hex + +function dump_bits(rx_bits) + + % pack into bytes, MSB first + + packed = zeros(1,floor(length(rx_bits)+7)/8); + bit = 7; byte = 1; + for i=1:length(rx_bits) + packed(byte) = bitor(packed(byte), bitshift(rx_bits(i),bit)); + bit--; + if (bit < 0) + bit = 7; + byte++; + end + end + + for i=1:length(packed) + printf("0x%02x ", packed(i)); + end + printf("\n"); + +endfunction + + % Initialise ---------------------------------------------------- global pilot_bit; diff --git a/codec2-dev/octave/fdmdv_demod.m b/codec2-dev/octave/fdmdv_demod.m index b0e313f2..2fe42702 100644 --- a/codec2-dev/octave/fdmdv_demod.m +++ b/codec2-dev/octave/fdmdv_demod.m @@ -8,7 +8,7 @@ % Version 2 % -function fdmdv_demod(rawfilename, nbits, NumCarriers, errorpatternfilename) +function fdmdv_demod(rawfilename, nbits, NumCarriers, errorpatternfilename, symbolfilename) fdmdv; % include modem code @@ -46,7 +46,7 @@ function fdmdv_demod(rawfilename, nbits, NumCarriers, errorpatternfilename) % misc states - nin = M; % timing correction for sample rate differences + nin = M; % timing correction for sample rate differences foff = 0; track_log = []; track = 0; @@ -59,6 +59,14 @@ function fdmdv_demod(rawfilename, nbits, NumCarriers, errorpatternfilename) spec_mem=zeros(1,Nspec); SdB = zeros(1,Nspec); + % optionally save output symbols + + if nargin == 5 + fm = fopen(symbolfilename,"wb"); + dual_rx_symbols = zeros(1, 2*Nc); + dual_rx_bits = zeros(1,2*Nc*Nb); + end + % Main loop ---------------------------------------------------- for f=1:frames @@ -117,6 +125,28 @@ function fdmdv_demod(rawfilename, nbits, NumCarriers, errorpatternfilename) rx_symbols_log = [rx_symbols_log rx_symbols]; endif [rx_bits sync f_err pd] = psk_to_bits(prev_rx_symbols, rx_symbols, modulation); + + % optionally save output symbols + + if (nargin == 5) && (track == 1) + if sync == 1 + dual_rx_symbols(Nc+1:2*Nc) = rx_symbols(1:Nc).*conj(prev_rx_symbols(1:Nc)./abs(prev_rx_symbols(1:Nc))); + dual_rx_symbols_float32 = []; k = 1; + for i=1:2*Nc + dual_rx_symbols_float32(k++) = real(dual_rx_symbols(i)); + dual_rx_symbols_float32(k++) = imag(dual_rx_symbols(i)); + end + fwrite(fm, dual_rx_symbols_float32, "float32"); + dual_rx_bits(Nc*Nb+1:2*Nc*Nb) = rx_bits; + dump_bits(dual_rx_bits); + else + dual_rx_symbols(1:Nc) = rx_symbols(1:Nc).*conj(prev_rx_symbols(1:Nc)./abs(prev_rx_symbols(1:Nc))); + dual_rx_bits(1:Nc*Nb) = rx_bits; + end + end + + % update some states + [sig_est noise_est] = snr_update(sig_est, noise_est, pd); snr_est = calc_snr(sig_est, noise_est); snr_est_log = [snr_est_log snr_est]; @@ -285,7 +315,7 @@ if 0 axis([1 lep/(Nc*Nb) 0 Nc]) end - % save error pattern file + % optionally save error pattern file if nargin == 4 fout = fopen(errorpatternfilename, "wb"); @@ -293,4 +323,5 @@ end fclose(fout); end + endfunction diff --git a/codec2-dev/octave/ldpcdec.m b/codec2-dev/octave/ldpcdec.m index 0b75aefd..6e261cd1 100644 --- a/codec2-dev/octave/ldpcdec.m +++ b/codec2-dev/octave/ldpcdec.m @@ -31,7 +31,7 @@ demod_type = 0; decoder_type = 0; max_iterations = 100; EsNo = 10; -Eprob = 0.15; +Eprob = 0.0; vocoderframesize = 52; nvocoderframes = 8; @@ -43,8 +43,6 @@ code_param.code_bits_per_frame = 576; data = []; r = []; -% Encoder: Generate simulated vocoder data, insert UW, and LPDC encode --------------- - Nframes = 100; uw = [1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0]; @@ -64,12 +62,14 @@ lmod_codeword = code_param.code_bits_per_frame/2; Terrs = 0; Ferrs = 0; Tbits = 0; Tframes = 0; nerr = []; corr = []; n = 0; sync_state = 0; sync_count = 0; +mod_unpackedmodem_log = []; [mod_unpackedmodem_float32, count] = fread(fm,nbitspermodemframe, "float32"); while (count == nbitspermodemframe) n++; mod_unpackedmodem = mod_unpackedmodem_float32(1:2:nbitspermodemframe) + j*mod_unpackedmodem_float32(2:2:nbitspermodemframe); + mod_unpackedmodem_log = [mod_unpackedmodem_log mod_unpackedmodem]; erasures = rand(1,length(mod_unpackedmodem)) < Eprob; mod_unpackedmodem(erasures) = 0; @@ -121,7 +121,13 @@ while (count == nbitspermodemframe) end fprintf(1,"\nFrames: %d bits: %d errors: %d BER = %f FER = %f\n", Tframes, Tbits, Terrs, Terrs/Tbits, Ferrs/Tframes); -subplot(211) -plot(corr); -subplot(212) -plot(nerr); +%subplot(211) +%plot(corr); +%subplot(212) +%plot(nerr); +figure(1) +clf; +[n m] = size(mod_unpackedmodem_log); +plot( real(mod_unpackedmodem_log), imag(mod_unpackedmodem_log), '+') +axis([-2 2 -2 2]); +title('Scatter Diagram'); -- 2.25.1