📄 ieee802_16_ctc.m
字号:
function [sys_bits, ctc_codedbits, zp_info_bits]=ieee802_16_ctc(info_bits, interleaver_type);
%implement the convolutional
%turbo encoder in IEEE 802.16-SCa standard (page 368)
%with some modifications:
%for long information blocks: make it into blocks of 256*8 bit length.
%
%
%Aijun Song
byte=8;
nibble=4;
if nargin<1 | nargin>3
disp('[ieee802_16_ctc]Number of input not supported.')
return;
end
num_infobits=length(info_bits);
%Make N=(num_infobits/2) multiple of 4, but not multiple of 7.
tval=mod(num_infobits, 8);
if tval~=0,
zp_info_bits=[info_bits; zeros(8-tval, 1)];
disp('[ieee802_16_ctc]Warning: source infobits has been padded(for multiple-8).');
else
zp_info_bits=info_bits;
end
tval=mod(num_infobits, 14);
if tval==0,
zp_info_bits=[info_bits; zeros(8, 1)];
disp('[ieee802_16_ctc]Warning: source infobits has been padded(for not multiple-7).');
else
zp_info_bits=info_bits;
end
%if the length is less than 32 byte, ctc is not suitable.
%specified in 802-16 standard.
num_infobits=length(zp_info_bits);
if num_infobits<32*byte,
disp('[ieee802_16_ctc]The number of source bits is less than 32 byte.');
output=[]; zp_info_bits=[];
return;
end
if nargin==1 & num_infobits<256*byte
interleaver_type='arp';
elseif nargin==1 & num_infobits>256*byte
interleaver_type='random';
end
if isempty(interleaver_type) & num_infobits<256*byte
interleaver_type='arp';
elseif isempty(interleaver_type) & num_infobits>256*byte
interleaver_type='random';
end
%choose a number for random interleaver state.
if strcmp(lower(interleaver_type), 'random'),
interleaver_state=99828;
end
%for large block, trim it into 256*byte*nF
if num_infobits>512*byte & strcmp(lower(interleaver_type), 'arp'),
nF= floor(num_infobits/(256*byte));
if nF*256*byte~=length(zp_info_bits),
disp('[ieee802_16_ctc]Warning: info bits beyond 512*byte trimmed.');
end
zp_info_bits=zp_info_bits(1: nF*256*byte);
info_bits_mat=zp_info_bits(1: nF*256*byte);
info_bits_mat=reshape(info_bits_mat, 256*byte, nF);
else
info_bits_mat=zp_info_bits;
end
trellis=ieee802_16_ctc_trellis;
convenc_type='notailing';
codedbits_mat=[];
for ic=1: size(info_bits_mat, 2),
%Get infobits
cinfobits=info_bits_mat(:, ic);
%encoded by C1 without interleaver
%Try to code first and find circulation state
[tval, ES]=trellis_encoder(cinfobits, trellis, 0, convenc_type);
%get trellis variable compatible with MATLAB
tt=trellis;
tt=rmfield(tt,'numTotalInput');
tt=rmfield(tt,'numTotalOutput');
[tval2, ES2]=convenc(double(cinfobits), tt, 0);
if tval~=tval2 | ES~=ES2
disp('[ieee802_16_ctc]Error: trellis encoding errors spotted by CONVENC.');
else
%disp('[ieee802_16_ctc]Trellis encoding has been confirmed right.');
end
cs=ieee802_16_ctc_circulations_state(ES, length(cinfobits)/2);
%encoded by C1 without interleaver but with circulation state
[coded_bits_c1, currentState]=trellis_encoder(cinfobits, trellis, cs, convenc_type);
if cs~=currentState
disp('[ieee802_16_ctc]Errors in circulation state caculation.')
return;
end
[tval2, currentState2]=convenc(double(cinfobits), tt, cs);
if coded_bits_c1~=tval2 | currentState~=currentState2
disp('[ieee802_16_ctc]Error: trellis encoding errors spotted by CONVENC.');
else
%disp('[ieee802_16_ctc]Trellis encoding has been confirmed right.');
end
%encoded by C2 with interleaver
%Try to code first and find circulation state
%interleaving
if strcmp(lower(interleaver_type), 'arp'),
cint_infobits=ieee802_16_ctc_interleaver(cinfobits);
elseif strcmp(lower(interleaver_type), 'random'),
cint_infobits=randintrlv(double(cinfobits), interleaver_state);
end
[tval, ES]=trellis_encoder(cint_infobits, trellis, 0, convenc_type);
cs=ieee802_16_ctc_circulations_state(ES, length(cint_infobits)/2);
%encoded by C2 with interleaver/circulation state
[coded_bits_c2, currentState]=trellis_encoder(cint_infobits, trellis, cs, convenc_type);
if cs~=currentState
disp('[ieee802_16_ctc]Errors in circulation state caculation.')
return;
end
codedbits_mat=[codedbits_mat; coded_bits_c1 coded_bits_c2];
end
%all the coded bits into two column: first column for C1
%second column for C2.
ctc_codedbits=[codedbits_mat];
sys_bits=zp_info_bits;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -