From: drowe67 Date: Mon, 16 Dec 2013 08:32:44 +0000 (+0000) Subject: refactored ldpc funcs, partially completed X-Git-Url: http://git.whiteaudio.com/gitweb/?a=commitdiff_plain;h=4a56eae7bc8930619fe6b004b00f46d8dae95c3e;p=freetel-svn-tracking.git refactored ldpc funcs, partially completed git-svn-id: https://svn.code.sf.net/p/freetel/code@1344 01035d8c-6547-0410-b346-abe4f91aad63 --- diff --git a/codec2-dev/octave/ldpc.m b/codec2-dev/octave/ldpc.m index f30d6883..addaafa6 100644 --- a/codec2-dev/octave/ldpc.m +++ b/codec2-dev/octave/ldpc.m @@ -13,128 +13,79 @@ 1; -function dummy +function code_param = ldpc_init(rate, framesize, modulation, mod_order, mapping) + [code_param.H_rows, code_param.H_cols, code_param.P_matrix] = InitializeWiMaxLDPC( rate, framesize, 0 ); + code_param.data_bits_per_frame = length(code_param.H_cols) - length( code_param.P_matrix ); + code_param.S_matrix = CreateConstellation( modulation, mod_order, mapping ); + code_param.bits_per_symbol = log2(mod_order); endfunction -function sim_out = ldpc_proc(sim_in, resfile) - -Eprob = sim_in.Eprob; - -framesize = sim_in.framesize; -rate = sim_in.rate; -modulation = sim_in.modulation; -mod_order = sim_in.mod_order; -mapping = sim_in.mapping; - - -Lim_Ferrs = sim_in.Lim_Ferrs; -Ntrials = sim_in.Ntrials; -Esvec = sim_in.Esvec; -deb = sim_in.deb; +function [codeword s] = ldpc_enc(data, code_param) + codeword = LdpcEncode( data, code_param.H_rows, code_param.P_matrix ); + s = Modulate( codeword, code_param.S_matrix ); +endfunction +function detected_data = ldpc_dec(code_param, max_iterations, demod_type, decoder_type, r, EsNo) + symbol_likelihood = Demod2D( r, code_param.S_matrix, EsNo); + + % initialize the extrinsic decoder input + input_somap_c = zeros(1, code_param.code_bits_per_frame ); + bit_likelihood = Somap( symbol_likelihood, demod_type, input_somap_c ); + + input_decoder_c = bit_likelihood(1:code_param.code_bits_per_frame); + + x_hat= MpDecode( -input_decoder_c, code_param.H_rows, code_param.H_cols, ... + max_iterations, decoder_type, 1, 1); + detected_data = x_hat(max_iterations,:); +endfunction -demod_type = 0; -decoder_type = 0; -max_iterations = 100; -code_param.bits_per_symbol = log2(mod_order); -bps = code_param.bits_per_symbol; +function sim_out = ldpc_proc(sim_in, resfile) -[code_param.H_rows, code_param.H_cols, code_param.P_matrix] = InitializeWiMaxLDPC( rate, sim_in.framesize, 0 ); + rate = 3/4; + framesize = 576; -code_param.data_bits_per_frame = length(code_param.H_cols) - length( code_param.P_matrix ); + mod_order = 4; + modulation = 'QPSK'; + mapping = 'gray'; -code_param.S_matrix = CreateConstellation( modulation, mod_order, mapping ); + demod_type = 0; + decoder_type = 0; + max_iterations = 100; -errfilename = '/home/david/codec2-dev/octave/mod_test_2000_poor_4dB.err'; -fin = fopen(errfilename, "rb"); -err = fread(fin,Inf, "short"); -length(err) -Ntrials = floor(length(err)/framesize) + code_param = ldpc_init(rate, framesize, modulation, mod_order, mapping); -for ne = 1:length(Esvec) - Es = Esvec(ne); - EsNo = 10^(Es/10); + Ntrials = 84; + EsNo=10; + Tbits = Terrs = Ferrs = 0; - Terrs = 0; Tbits =0; Ferrs =0; - for nn = 1: Ntrials - - data = round( rand( 1, code_param.data_bits_per_frame ) ); - - codeword = LdpcEncode( data, code_param.H_rows, code_param.P_matrix ); - code_param.code_bits_per_frame = length( codeword ); - Nsymb = code_param.code_bits_per_frame/bps; - - % modulate - s = Modulate( codeword, code_param.S_matrix ); - code_param.symbols_per_frame = length( s ); - - s = Modulate(codeword, code_param.S_matrix ); - code_param.symbols_per_frame = length( s ); - - - variance = 1/(2*EsNo); - noise = sqrt(variance)*( randn(1,code_param.symbols_per_frame) + ... - j*randn(1,code_param.symbols_per_frame) ); - a=ones(1, code_param.symbols_per_frame); - r = a.*s + noise; - - Nr = length(r); -% erasures = rand(1,Nr)0, fprintf(1,'x'), else fprintf(1,'.'), end - if (rem(nn, 50)==0), fprintf(1,'\n'), end - - - + if (rem(nn, 50)==0), fprintf(1,'\n'), end if Nerrs>0, Ferrs = Ferrs +1; end Terrs = Terrs + Nerrs; - Tbits = Tbits + code_param.data_bits_per_frame; - - if Ferrs > Lim_Ferrs, disp(['exit loop with #cw errors = ' ... - num2str(Ferrs)]); break, end - end - - TERvec(ne) = Terrs; - FERvec(ne) = Ferrs; - BERvec(ne) = Terrs/ Tbits; - Ebvec = Esvec - 10*log10(code_param.bits_per_symbol * rate); - - cparams= [code_param.data_bits_per_frame code_param.symbols_per_frame ... - code_param.code_bits_per_frame]; - - sim_out.BERvec = BERvec; - sim_out.Ebvec = Ebvec; - sim_out.FERvec = FERvec; - sim_out.TERvec = TERvec; - sim_out.cpumins = cputime/60; - - if length(resfile)>0 - save(resfile, 'sim_in', 'sim_out', 'cparams'); - disp(['Saved results to ' resfile ' at Es =' num2str(Es) 'dB']); + Tbits = Tbits + code_param.data_bits_per_frame; end - end - + endfunction diff --git a/codec2-dev/octave/ldpcenc.m b/codec2-dev/octave/ldpcenc.m index 233c9a3b..3a9a51d3 100644 --- a/codec2-dev/octave/ldpcenc.m +++ b/codec2-dev/octave/ldpcenc.m @@ -41,9 +41,10 @@ sim_in.Ntrials = 1000; if exist('deb')~=1, deb = 0; end sim_in.deb = deb; -sim_out = ldpc_proc(sim_in, 'test.mat'); +% init enc and dec +% generate bits +% encode +% decode +% measure BER +ldpc_proc(sim_in, 'test.mat'); -figure(100); -semilogy(sim_out.Ebvec, sim_out.BERvec) -xlabel('Eb/N0') -ylabel('BER')