From ac661c8f66216ce539f84299647699048f73a9ba Mon Sep 17 00:00:00 2001 From: drowe67 Date: Mon, 30 Dec 2013 05:17:10 +0000 Subject: [PATCH] ldpc decode and sync working with no errors git-svn-id: https://svn.code.sf.net/p/freetel/code@1349 01035d8c-6547-0410-b346-abe4f91aad63 --- codec2-dev/octave/ldpc.m | 31 ++++++++++++++++++++++++++----- codec2-dev/octave/ldpcenc.m | 29 +++++++++++++++++++++++++---- 2 files changed, 51 insertions(+), 9 deletions(-) diff --git a/codec2-dev/octave/ldpc.m b/codec2-dev/octave/ldpc.m index dfed5d45..917b7efa 100644 --- a/codec2-dev/octave/ldpc.m +++ b/codec2-dev/octave/ldpc.m @@ -23,12 +23,12 @@ endfunction % Gray coded QPSK modulation function function symbol = qpsk_mod(two_bits) - two_bits_decimal = sum(two_bits .* [1 2]); + two_bits_decimal = sum(two_bits .* [2 1]); switch(two_bits_decimal) - case (0) symbol = 1+j; - case (1) symbol = -1+j; - case (2) symbol = 1-j; - case (3) symbol = -1-j; + case (0) symbol = 1; + case (1) symbol = j; + case (2) symbol = -j; + case (3) symbol = -1; endswitch endfunction @@ -56,9 +56,30 @@ function frameout = insert_uw(framein, uw) pout += 2; luw -= 2; end +endfunction + +% removes a unique word from a frame of bits. The UW bits are spread +% throughout the input frame 2 bits at a time. + +function frameout = remove_uw(framein, lvd, luw) + + spacing = 2*lvd/luw; + + frameout = []; + + pin = 1; pout = 1; + while (luw) + %printf("pin %d pout %d luw %d ", pin, pout, luw); + %printf("pin+spacing-1 %d lvd %d lframein: %d\n", pin+spacing-1, lvd, length(framein)); + frameout(pout:pout+spacing-1) = framein(pin:pin+spacing-1); + pin += spacing + 2; + pout += spacing; + luw -= 2; + end endfunction + % builds up a sparse QPSK modulated version version of the UW for use % in UW sync at the rx diff --git a/codec2-dev/octave/ldpcenc.m b/codec2-dev/octave/ldpcenc.m index 9773e79f..9d7dde0b 100644 --- a/codec2-dev/octave/ldpcenc.m +++ b/codec2-dev/octave/ldpcenc.m @@ -27,6 +27,7 @@ mapping = 'gray'; demod_type = 0; decoder_type = 0; max_iterations = 100; +EsNo = 10; vocoderframesize = 52; nvocoderframes = 8; @@ -58,8 +59,8 @@ for nn = 1: Nframes end fclose(fc); -printf("framesize: %d data_bits_per_frame: %d code_bits_per_frame: %d\n", ... - framesize, code_param.data_bits_per_frame, code_param.code_bits_per_frame); +%printf("framesize: %d data_bits_per_frame: %d code_bits_per_frame: %d\n", ... +% framesize, code_param.data_bits_per_frame, code_param.code_bits_per_frame); % rx simulation (separate later) @@ -71,7 +72,7 @@ lpackedmodem = 72/8; mod_codeword = zeros(1, code_param.code_bits_per_frame/2); lmod_codeword = code_param.code_bits_per_frame/2; -for m=1:16 +for m=1:8 % read in one modem frame at a time @@ -89,8 +90,28 @@ for m=1:16 mod_codeword(1:lmod_codeword-length(mod_unpackedmodem)) = mod_codeword(length(mod_unpackedmodem)+1:lmod_codeword); mod_codeword(lmod_codeword-length(mod_unpackedmodem)+1:lmod_codeword) = mod_unpackedmodem; - look_for_uw(10*mod_codeword(1:length(mod_uw)), mod_uw) + uw_sync = look_for_uw(mod_codeword(1:length(mod_uw)), mod_uw); + if (uw_sync) + % force UW symbols as they are known (is this needed?) + + % LDPC decode + + detected_data = ldpc_dec(code_param, max_iterations, demod_type, decoder_type, mod_codeword, EsNo); + + % unpack payload data, removing UW + + vd_rx = remove_uw(detected_data(1:code_param.data_bits_per_frame), length(vd), length(uw)); + + % measure BER + + error_positions = xor(vd, vd_rx); + Nerrs = sum(error_positions); + if Nerrs>0, fprintf(1,'x'), else fprintf(1,'.'), end + + % save packed payload data to disk + end end +fprintf(1,'\n') fclose(fc); -- 2.25.1