www.pudn.com > ctc-matlab.rar > main.m, change:2005-03-21,size:2251b


clear; 
FrameNum=10000;%码块数目 
leng=128;%码块信息长的一半,即协议中的N 
data=randint(1,FrameNum*leng*2,2);%产生随机数 
L1=4;%用于估计编码器状态的迭代次数 
niter=L1+8;%总的迭代次数 
if leng==96 
    index=1; 
    CodeBlockSize=48*8;%编码后码块长度,单位是比特 
    rate=0.5;%码率 
elseif leng==128 
    index=2; 
    CodeBlockSize=48*8; 
    rate=2/3; 
elseif leng==144 
    index=3; 
    CodeBlockSize=48*8; 
    rate=0.75; 
elseif leng==192 
    index=4; 
    CodeBlockSize=96*8; 
    rate=0.5; 
elseif leng==288 
    index=5; 
    CodeBlockSize=96*8; 
    rate=0.75; 
elseif leng==384 
    index=6; 
    CodeBlockSize=144*8; 
    rate=2/3; 
elseif leng==432 
    index=7; 
    CodeBlockSize=144*8; 
    rate=0.75; 
end 
EbN0=5; 
x=zeros(1,CodeBlockSize*FrameNum);%x存放编码结果 
ratio=zeros(length(EbN0),length(L1));%BER 
FrameErrNum=zeros(length(EbN0),length(L1));%PER 
%// encoding 
for i=1:FrameNum 
    x((i-1)*CodeBlockSize+1:i*CodeBlockSize)=CtcEncoder(data((i-1)*leng*2+1:i*leng*2),index); 
end 
%// modulation 
[ModulateResult,nindex]=modulation(x,index); 
snr=EbN0+1.25;%根据各个码的码率以及调制方式计算EbN0与snr之间的差值.1.25是第二种ctc的修正值 
for i=1:length(EbN0) 
    i 
    %// adding noise 
    NoiseSignal=awgn(ModulateResult,snr(i),'measured'); 
    %// demodulation 
    DemoduResult=demodulation(NoiseSignal,nindex); 
    %// multiplied by the reliability value of the channel 
    en=10^(EbN0(i)/10); 
    L_c=4*en*rate;%为了防止计算溢出,对于16-QAM调制,再乘一个因子(1/sqrt(10)),64-QAM乘以(1/sqrt(42)) 
    y=0.5*L_c*DemoduResult; 
%CtcDecode存放译码结果 
    CtcDecode=zeros(1,FrameNum*leng*2); 
    for k=1:length(L1) 
%迭代译码,统计BER和PER 
        for j=1:FrameNum 
            CtcDecode((j-1)*leng*2+1:j*leng*2)=CtcDecoder(y((j-1)*CodeBlockSize+1:j*CodeBlockSize),niter(k),index,L1(k)); 
            [num,frameratio]=biterr(CtcDecode((j-1)*leng*2+1:j*leng*2),data((j-1)*leng*2+1:j*leng*2)); 
            if num~=0 
                FrameErrNum(i,k)=FrameErrNum(i,k)+1; 
            end    
        end 
        [num,ratio(i,k)]=biterr(data,CtcDecode); 
        fid=fopen('FrameErrRatio.dat','a'); 
        fprintf(fid,'%d,%d:ber:%f,fer:%f\n',i,k,ratio(i,k),FrameErrNum(i,k)/FrameNum); 
        fclose(fid); 
    end 
end