\r
1;\r
\r
-function dummy\r
+function code_param = ldpc_init(rate, framesize, modulation, mod_order, mapping)\r
+ [code_param.H_rows, code_param.H_cols, code_param.P_matrix] = InitializeWiMaxLDPC( rate, framesize, 0 );\r
+ code_param.data_bits_per_frame = length(code_param.H_cols) - length( code_param.P_matrix );\r
+ code_param.S_matrix = CreateConstellation( modulation, mod_order, mapping );\r
+ code_param.bits_per_symbol = log2(mod_order);\r
endfunction\r
\r
-function sim_out = ldpc_proc(sim_in, resfile)\r
-\r
-Eprob = sim_in.Eprob; \r
-\r
-framesize = sim_in.framesize;\r
-rate = sim_in.rate;\r
-modulation = sim_in.modulation;\r
-mod_order = sim_in.mod_order;\r
-mapping = sim_in.mapping;\r
-\r
-\r
-Lim_Ferrs = sim_in.Lim_Ferrs;\r
-Ntrials = sim_in.Ntrials;\r
-Esvec = sim_in.Esvec;\r
-deb = sim_in.deb;\r
+function [codeword s] = ldpc_enc(data, code_param)\r
+ codeword = LdpcEncode( data, code_param.H_rows, code_param.P_matrix );\r
+ s = Modulate( codeword, code_param.S_matrix );\r
+endfunction\r
\r
+function detected_data = ldpc_dec(code_param, max_iterations, demod_type, decoder_type, r, EsNo)\r
+ symbol_likelihood = Demod2D( r, code_param.S_matrix, EsNo);\r
+ \r
+ % initialize the extrinsic decoder input\r
+ input_somap_c = zeros(1, code_param.code_bits_per_frame );\r
+ bit_likelihood = Somap( symbol_likelihood, demod_type, input_somap_c );\r
+ \r
+ input_decoder_c = bit_likelihood(1:code_param.code_bits_per_frame);\r
+ \r
+ x_hat= MpDecode( -input_decoder_c, code_param.H_rows, code_param.H_cols, ...\r
+ max_iterations, decoder_type, 1, 1);\r
+ detected_data = x_hat(max_iterations,:);\r
+endfunction\r
\r
-demod_type = 0;\r
-decoder_type = 0;\r
-max_iterations = 100;\r
-code_param.bits_per_symbol = log2(mod_order);\r
-bps = code_param.bits_per_symbol;\r
+function sim_out = ldpc_proc(sim_in, resfile)\r
\r
-[code_param.H_rows, code_param.H_cols, code_param.P_matrix] = InitializeWiMaxLDPC( rate, sim_in.framesize, 0 );\r
+ rate = 3/4; \r
+ framesize = 576; \r
\r
-code_param.data_bits_per_frame = length(code_param.H_cols) - length( code_param.P_matrix );\r
+ mod_order = 4; \r
+ modulation = 'QPSK';\r
+ mapping = 'gray';\r
\r
-code_param.S_matrix = CreateConstellation( modulation, mod_order, mapping );\r
+ demod_type = 0;\r
+ decoder_type = 0;\r
+ max_iterations = 100;\r
\r
-errfilename = '/home/david/codec2-dev/octave/mod_test_2000_poor_4dB.err';\r
-fin = fopen(errfilename, "rb");\r
-err = fread(fin,Inf, "short");\r
-length(err)\r
-Ntrials = floor(length(err)/framesize)\r
+ code_param = ldpc_init(rate, framesize, modulation, mod_order, mapping);\r
\r
-for ne = 1:length(Esvec)\r
- Es = Esvec(ne);\r
- EsNo = 10^(Es/10);\r
+ Ntrials = 84;\r
+ EsNo=10;\r
\r
+ Tbits = Terrs = Ferrs = 0;\r
\r
- Terrs = 0; Tbits =0; Ferrs =0;\r
- for nn = 1: Ntrials\r
- \r
- data = round( rand( 1, code_param.data_bits_per_frame ) );\r
- \r
- codeword = LdpcEncode( data, code_param.H_rows, code_param.P_matrix );\r
- code_param.code_bits_per_frame = length( codeword );\r
- Nsymb = code_param.code_bits_per_frame/bps;\r
- \r
- % modulate\r
- s = Modulate( codeword, code_param.S_matrix );\r
- code_param.symbols_per_frame = length( s );\r
- \r
- s = Modulate(codeword, code_param.S_matrix );\r
- code_param.symbols_per_frame = length( s );\r
- \r
- \r
- variance = 1/(2*EsNo);\r
- noise = sqrt(variance)*( randn(1,code_param.symbols_per_frame) + ...\r
- j*randn(1,code_param.symbols_per_frame) );\r
- a=ones(1, code_param.symbols_per_frame); \r
- r = a.*s + noise;\r
-\r
- Nr = length(r); \r
-% erasures = rand(1,Nr)<Eprob; \r
-% r(erasures) = 0; \r
- \r
- st = (nn-1)*Nr+1;\r
- en = nn*Nr;\r
- evec = err(st:en);\r
- r(find(evec)) = 0;\r
+ data = [];\r
+ r = []; \r
+ for nn = 1: Ntrials \r
+ d = round( rand( 1, code_param.data_bits_per_frame ) );\r
+ data = [data d];\r
+ [codeword, s] = ldpc_enc(d, code_param);\r
+ code_param.code_bits_per_frame = length(codeword);\r
+ code_param.symbols_per_frame = length(s);\r
+ r = [r s];\r
+ end\r
\r
- symbol_likelihood = Demod2D( r, code_param.S_matrix, EsNo);\r
- \r
- % initialize the extrinsic decoder input\r
- input_somap_c = zeros(1, code_param.code_bits_per_frame );\r
- bit_likelihood = Somap( symbol_likelihood, demod_type, input_somap_c );\r
- \r
- input_decoder_c = bit_likelihood(1:code_param.code_bits_per_frame);\r
- \r
- x_hat= MpDecode( -input_decoder_c, code_param.H_rows, code_param.H_cols, ...\r
- max_iterations, decoder_type, 1, 1);\r
- detected_data = x_hat(max_iterations,:);\r
- error_positions = xor( detected_data(1:code_param.data_bits_per_frame), data );\r
+ for nn = 1: Ntrials \r
+ st = (nn-1)*code_param.symbols_per_frame + 1;\r
+ en = (nn)*code_param.symbols_per_frame;\r
+ detected_data = ldpc_dec(code_param, max_iterations, demod_type, decoder_type, r(st:en), EsNo);\r
+ st = (nn-1)*code_param.data_bits_per_frame + 1;\r
+ en = (nn)*code_param.data_bits_per_frame;\r
+ error_positions = xor( detected_data(1:code_param.data_bits_per_frame), data(st:en) );\r
Nerrs = sum( error_positions);\r
\r
if Nerrs>0, fprintf(1,'x'), else fprintf(1,'.'), end\r
- if (rem(nn, 50)==0), fprintf(1,'\n'), end\r
- \r
- \r
- \r
+ if (rem(nn, 50)==0), fprintf(1,'\n'), end \r
if Nerrs>0, Ferrs = Ferrs +1; end\r
Terrs = Terrs + Nerrs;\r
- Tbits = Tbits + code_param.data_bits_per_frame;\r
- \r
- if Ferrs > Lim_Ferrs, disp(['exit loop with #cw errors = ' ...\r
- num2str(Ferrs)]); break, end\r
- end\r
- \r
- TERvec(ne) = Terrs;\r
- FERvec(ne) = Ferrs;\r
- BERvec(ne) = Terrs/ Tbits;\r
- Ebvec = Esvec - 10*log10(code_param.bits_per_symbol * rate);\r
- \r
- cparams= [code_param.data_bits_per_frame code_param.symbols_per_frame ...\r
- code_param.code_bits_per_frame];\r
- \r
- sim_out.BERvec = BERvec;\r
- sim_out.Ebvec = Ebvec;\r
- sim_out.FERvec = FERvec;\r
- sim_out.TERvec = TERvec;\r
- sim_out.cpumins = cputime/60;\r
- \r
- if length(resfile)>0\r
- save(resfile, 'sim_in', 'sim_out', 'cparams');\r
- disp(['Saved results to ' resfile ' at Es =' num2str(Es) 'dB']);\r
+ Tbits = Tbits + code_param.data_bits_per_frame; \r
end\r
- end\r
- \r
+\r
endfunction\r
\r
\r