code_param.bits_per_symbol = log2(mod_order);\r
endfunction\r
\r
+% inserts a unique word into a frame of bits\r
+\r
+function frameout = insert_uw(framein, uw)\r
+\r
+ luw = length(uw);\r
+ lframein = length(framein);\r
+ spacing = lframein/luw;\r
+\r
+ frameout = [];\r
+\r
+ for i=1:luw\r
+ frameout(1+(i-1)*spacing+i-1:i*spacing+i-1) = framein(1+(i-1)*spacing:i*spacing);\r
+ frameout(i*spacing+i) = uw(i);\r
+ end\r
+\r
+endfunction\r
+\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
detected_data = x_hat(max_iterations,:);\r
endfunction\r
\r
-function sim_out = ldpc_proc(sim_in, resfile)\r
-\r
- rate = 3/4; \r
- framesize = 576; \r
-\r
- mod_order = 4; \r
- modulation = 'QPSK';\r
- mapping = 'gray';\r
-\r
- demod_type = 0;\r
- decoder_type = 0;\r
- max_iterations = 100;\r
-\r
- code_param = ldpc_init(rate, framesize, modulation, mod_order, mapping);\r
-\r
- Ntrials = 84;\r
- EsNo=10;\r
-\r
- Tbits = Terrs = Ferrs = 0;\r
- \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
+% Packs a binary array into an array of 8 bit bytes, MSB first\r
+\r
+function packed = packmsb(unpacked)\r
+ packed = zeros(1,floor(length(unpacked)+7)/8);\r
+ bit = 7; byte = 1;\r
+ for i=1:length(unpacked)\r
+ packed(byte) = bitor(packed(byte), bitshift(unpacked(i),bit));\r
+ bit--;\r
+ if (bit < 0)\r
+ bit = 7;\r
+ byte++;\r
+ end \r
end\r
-\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
- if Nerrs>0, Ferrs = Ferrs +1; end\r
- Terrs = Terrs + Nerrs;\r
- Tbits = Tbits + code_param.data_bits_per_frame; \r
- end\r
-\r
endfunction\r
\r
-\r
-%test batch file for the FSO-OOK simulations\r
+% ldpcenc.m\r
+% David Rowe 20 Dec 2013\r
% \r
-% this version uses WiMax eIRA codes and includes erasures \r
+% LDPC encoder test program. Encodes and modulates a random data stream \r
\r
-currentdir = pwd;\r
-thiscomp = computer;\r
+% Start CML library\r
\r
+currentdir = pwd;\r
addpath '/home/david/tmp/cml/mat' % assume the source files stored here\r
cd /home/david/tmp/cml\r
-CmlStartup % note that this is not in the cml path!\r
-disp('added cluster path and run CmlStartup')\r
-\r
+CmlStartup % note that this is not in the cml path!\r
cd(currentdir)\r
\r
+% Our LDPC library\r
+\r
ldpc;\r
\r
-%\r
-%sim_in.Eprob = 0.1; \r
-%disp([' test with erasure probability of ' num2str(sim_in.Eprob)]); \r
+% Start simulation\r
+\r
+rate = 3/4; \r
+framesize = 576; \r
+\r
+mod_order = 4; \r
+modulation = 'QPSK';\r
+mapping = 'gray';\r
+\r
+demod_type = 0;\r
+decoder_type = 0;\r
+max_iterations = 100;\r
+\r
+vocoderframesize = 52;\r
+nvocoderframes = 8;\r
+\r
+code_param = ldpc_init(rate, framesize, modulation, mod_order, mapping);\r
\r
-%sim_in.comment = 'test ldpc';\r
-%sim_in.Esvec = 8:1/2:11; \r
+data = [];\r
+r = []; \r
\r
-%sim_in.rate = 3/4;\r
-%sim_in.framesize = 16200\r
+% Encode a bunch of frames\r
\r
-% sim_in.rate = 0.5;\r
-% sim_in.framesize = 204;\r
+Nframes = 100;\r
\r
-sim_in.rate = 3/4; \r
-sim_in.framesize = 576; \r
+% repeat same codeword frame for now to ease testing\r
\r
-sim_in.mod_order = 4; \r
-sim_in.modulation = 'QPSK';\r
-sim_in.mapping = 'gray';\r
+vd = round( rand( 1, vocoderframesize*nvocoderframes) );\r
+d = insert_uw(vd, [1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0]);\r
\r
-sim_in.Lim_Ferrs= 30;\r
-sim_in.Ntrials = 1000;\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
+packedcodeword = packmsb(codeword);\r
\r
+fc=fopen("codeword.bin","wb");\r
+for nn = 1: Nframes \r
+ fwrite(fc,packedcodeword,"char");\r
+end\r
+fclose(fc);\r
\r
-if exist('deb')~=1, deb = 0; end\r
-sim_in.deb = deb;\r
+printf("framesize: %d data_bits_per_frame: %d code_bits_per_frame: %d\n", ...\r
+ framesize, code_param.data_bits_per_frame, code_param.code_bits_per_frame);\r
\r
-% init enc and dec\r
-% generate bits\r
-% encode\r
-% decode\r
-% measure BER\r
-ldpc_proc(sim_in, 'test.mat');\r
\r
+ \r