www.gusucode.com > matlab编程pi4-DQPSK的仿真程序,GUI界面,可以计算误码率源码程序 > gusucode/test111.m

    param.NumSig=100;
param.srState=12345;
param.dpt=3;
param.State=71;

x=randint(1,param.NumSig,[0 1],param.srState);

xCoded_Block=[];
xCoded_Cyclic=[];
xCoded_Interleaver=[];

tt=mod(param.NumSig,4);
if tt
    x=[x zeros(1,4-tt)];
end
% Linear coding.
xCode=zeros(1,4);
for k=1:4:param.NumSig
    xCode(1)=x(k);
    xCode(2)=x(k+1);
    xCode(3)=x(k+2);
    xCode(4)=x(k+3);
    
    BlockGen=[1 0 0 0 1 1 1;0 1 0 0 1 1 0;0 0 1 0 1 0 1; 0 0 0 1 0 1 1];
    xCoded_Block=[xCoded_Block rem(xCode*BlockGen,2)];
end

% xCoded_Block must be the mutiple of 4
tt=mod(length(xCoded_Block),4);
if tt
    xCoded_Block=[xCoded_Block zeros(1,4-tt)];
end

% Cyclic coding
i=1;
for k=1:4:length(xCoded_Block)
    xCode(1)=xCoded_Block(k);
    xCode(2)=xCoded_Block(k+1);
    xCode(3)=xCoded_Block(k+2);
    xCode(4)=xCoded_Block(k+3);
    
    %CyclicPoly=[1 0 1 1];
    CyclicGen=[1 0 1 1 0 0 0;1 1 1 0 1 0 0;1 1 0 0 0 1 0;0 1 1 0 0 0 1];
    %xCoded_Cyclic=[xCoded_Cyclic rem(tx*CyclicGen,2)];
    xCoded_Cyclic(i,:)=rem(xCode*CyclicGen,2);
    i=i+1;
end


tt=mod(i-1,param.dpt);
if tt
    xCoded_Cyclic=[xCoded_Cyclic;zeros(param.dpt-tt,7)];
end

% Interleaver coding
[n,m]=size(xCoded_Cyclic);
for k=1:param.dpt:n
    for cln=1:7
       for j=0:param.dpt-1
           xCoded_Interleaver=[xCoded_Interleaver xCoded_Cyclic(k+j,cln)];
       end
    end
end

% convert to 1-D column vector
xCoded_Interleaver=xCoded_Interleaver(:);

tt=mod(length(xCoded_Interleaver),2);
odd_check=0;
if tt
    xCoded_Interleaver=[xCoded_Interleaver;0];
    odd_check=1;
end

% convert to  2-D column vector
for k=1:2:length(xCoded_Interleaver)
    bit_txSig((k+1)/2,1)=xCoded_Interleaver(k);
    bit_txSig((k+1)/2,2)=xCoded_Interleaver(k+1);
end

[n,m]=size(bit_txSig);
for i=1:n
    int_txSig(i,1)=bit_txSig(i,1)*2+bit_txSig(i,2);
end




[n,m]=size(int_txSig);
% convert to n x 2 dimension bit vector
for i=1:n
    switch int_txSig(i)
        case 0
            rxSigBit(i,1)=0;
            rxSigBit(i,2)=0;
        case 1
            rxSigBit(i,1)=0;
            rxSigBit(i,2)=1;
        case 2
            rxSigBit(i,1)=1;
            rxSigBit(i,2)=0;
        case 3
            rxSigBit(i,1)=1;
            rxSigBit(i,2)=1;
        otherwise
    end
end

% convert to N x 1 bit vector
for i=1:n
    rxSig_cln(2*i-1,1)=rxSigBit(i,1);
    rxSig_cln(2*i,1)=rxSigBit(i,2);
end

[n,m]=size(rxSig_cln);
if odd_check
    rxSig_cln=rxSig_cln(1:n-1);
end

[n,m]=size(rxSig_cln);
if mod(n,param.dpt)
    error('find some error ');
end

%
k=1;
for i=1:param.dpt:n
    rxSig_dpt(k,:)=[rxSig_cln(i) rxSig_cln(i+1) rxSig_cln(i+2)];
    k=k+1;
end

[n,m]=size(rxSig_dpt);
rxdecoded_Interleaver=[];
for i=1:7:n
    for j=1:m
        for k=0:6
            rxdecoded_Interleaver=[rxdecoded_Interleaver rxSig_dpt(i+k,j)];
        end
    end
end


rxdecoded_Cyclic=decode(rxdecoded_Interleaver,7,4,'cyclic',[1 0 1 1]);

[n,m]=size(rxdecoded_Cyclic);
tt=mod(n,7);
if tt
    rxdecoded_Cyclic=[rxdecoded_Cyclic;zeros(7-tt,1)];
end

%assignin('base','sddd',rxdecoded_Cyclic);

% 
rxdecoded_Linear=decode(rxdecoded_Cyclic,7,4,'linear',BlockGen);

xx=x(1:param.NumSig).';

%
[bitNum,bitRatio]=biterr(xx,rxdecoded_Linear(1:param.NumSig));