From: drowe67 Date: Fri, 27 Dec 2013 09:13:13 +0000 (+0000) Subject: unique word insertion for ldpc frame sync X-Git-Url: http://git.whiteaudio.com/gitweb/?a=commitdiff_plain;h=7efbe346b6500a9fc31550f0b4c880c1002fe177;p=freetel-svn-tracking.git unique word insertion for ldpc frame sync git-svn-id: https://svn.code.sf.net/p/freetel/code@1347 01035d8c-6547-0410-b346-abe4f91aad63 --- diff --git a/codec2-dev/octave/ldpc.m b/codec2-dev/octave/ldpc.m index addaafa6..c0081478 100644 --- a/codec2-dev/octave/ldpc.m +++ b/codec2-dev/octave/ldpc.m @@ -20,6 +20,23 @@ function code_param = ldpc_init(rate, framesize, modulation, mod_order, mapping) code_param.bits_per_symbol = log2(mod_order); endfunction +% inserts a unique word into a frame of bits + +function frameout = insert_uw(framein, uw) + + luw = length(uw); + lframein = length(framein); + spacing = lframein/luw; + + frameout = []; + + for i=1:luw + frameout(1+(i-1)*spacing+i-1:i*spacing+i-1) = framein(1+(i-1)*spacing:i*spacing); + frameout(i*spacing+i) = uw(i); + end + +endfunction + 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 ); @@ -39,53 +56,18 @@ function detected_data = ldpc_dec(code_param, max_iterations, demod_type, decode detected_data = x_hat(max_iterations,:); endfunction -function sim_out = ldpc_proc(sim_in, resfile) - - rate = 3/4; - framesize = 576; - - mod_order = 4; - modulation = 'QPSK'; - mapping = 'gray'; - - demod_type = 0; - decoder_type = 0; - max_iterations = 100; - - code_param = ldpc_init(rate, framesize, modulation, mod_order, mapping); - - Ntrials = 84; - EsNo=10; - - Tbits = Terrs = Ferrs = 0; - - data = []; - r = []; - for nn = 1: Ntrials - d = round( rand( 1, code_param.data_bits_per_frame ) ); - data = [data d]; - [codeword, s] = ldpc_enc(d, code_param); - code_param.code_bits_per_frame = length(codeword); - code_param.symbols_per_frame = length(s); - r = [r s]; +% Packs a binary array into an array of 8 bit bytes, MSB first + +function packed = packmsb(unpacked) + packed = zeros(1,floor(length(unpacked)+7)/8); + bit = 7; byte = 1; + for i=1:length(unpacked) + packed(byte) = bitor(packed(byte), bitshift(unpacked(i),bit)); + bit--; + if (bit < 0) + bit = 7; + byte++; + end end - - for nn = 1: Ntrials - st = (nn-1)*code_param.symbols_per_frame + 1; - en = (nn)*code_param.symbols_per_frame; - detected_data = ldpc_dec(code_param, max_iterations, demod_type, decoder_type, r(st:en), EsNo); - st = (nn-1)*code_param.data_bits_per_frame + 1; - en = (nn)*code_param.data_bits_per_frame; - error_positions = xor( detected_data(1:code_param.data_bits_per_frame), data(st:en) ); - Nerrs = sum( error_positions); - - if Nerrs>0, fprintf(1,'x'), else fprintf(1,'.'), 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; - end - endfunction - diff --git a/codec2-dev/octave/ldpcenc.m b/codec2-dev/octave/ldpcenc.m index 6c449272..0f8c5f98 100644 --- a/codec2-dev/octave/ldpcenc.m +++ b/codec2-dev/octave/ldpcenc.m @@ -1,50 +1,64 @@ -%test batch file for the FSO-OOK simulations +% ldpcenc.m +% David Rowe 20 Dec 2013 % -% this version uses WiMax eIRA codes and includes erasures +% LDPC encoder test program. Encodes and modulates a random data stream -currentdir = pwd; -thiscomp = computer; +% Start CML library +currentdir = pwd; addpath '/home/david/tmp/cml/mat' % assume the source files stored here cd /home/david/tmp/cml -CmlStartup % note that this is not in the cml path! -disp('added cluster path and run CmlStartup') - +CmlStartup % note that this is not in the cml path! cd(currentdir) +% Our LDPC library + ldpc; -% -%sim_in.Eprob = 0.1; -%disp([' test with erasure probability of ' num2str(sim_in.Eprob)]); +% Start simulation + +rate = 3/4; +framesize = 576; + +mod_order = 4; +modulation = 'QPSK'; +mapping = 'gray'; + +demod_type = 0; +decoder_type = 0; +max_iterations = 100; + +vocoderframesize = 52; +nvocoderframes = 8; + +code_param = ldpc_init(rate, framesize, modulation, mod_order, mapping); -%sim_in.comment = 'test ldpc'; -%sim_in.Esvec = 8:1/2:11; +data = []; +r = []; -%sim_in.rate = 3/4; -%sim_in.framesize = 16200 +% Encode a bunch of frames -% sim_in.rate = 0.5; -% sim_in.framesize = 204; +Nframes = 100; -sim_in.rate = 3/4; -sim_in.framesize = 576; +% repeat same codeword frame for now to ease testing -sim_in.mod_order = 4; -sim_in.modulation = 'QPSK'; -sim_in.mapping = 'gray'; +vd = round( rand( 1, vocoderframesize*nvocoderframes) ); +d = insert_uw(vd, [1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0]); -sim_in.Lim_Ferrs= 30; -sim_in.Ntrials = 1000; +data = [data d]; +[codeword, s] = ldpc_enc(d, code_param); +code_param.code_bits_per_frame = length(codeword); +code_param.symbols_per_frame = length(s); +packedcodeword = packmsb(codeword); +fc=fopen("codeword.bin","wb"); +for nn = 1: Nframes + fwrite(fc,packedcodeword,"char"); +end +fclose(fc); -if exist('deb')~=1, deb = 0; end -sim_in.deb = deb; +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); -% init enc and dec -% generate bits -% encode -% decode -% measure BER -ldpc_proc(sim_in, 'test.mat'); +