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


function [ModulateResult,index]=modulation(code,index) 
%/// QPSK,16-QAM,64QAM modulations 
I=0; 
Q=0; 
if index<4 
    %QPSK modulations 
    index=1; 
    ModulateResult=zeros(1,length(code)/2); 
    for k=1:length(ModulateResult) 
        ModulateResult(k)=2*code(2*k-1)-1+(2*code(2*k)-1)*i; 
    end 
    ModulateResult=ModulateResult/sqrt(2); 
elseif index==5|index==4 
    %16-QAM modulations 
    index=2; 
    ModulateResult=zeros(1,length(code)/4); 
    for k=1:length(ModulateResult) 
        if code((k-1)*4+2)==0 
            I=3*(2*code((k-1)*4+1)-1); 
        else 
            I=2*code((k-1)*4+1)-1; 
        end 
        if code(k*4)==0 
            Q=3*(2*code((k-1)*4+3)-1); 
        else 
            Q=2*code((k-1)*4+3)-1; 
        end 
        ModulateResult(k)=I+i*Q; 
    end 
    ModulateResult=ModulateResult/sqrt(10); 
else 
    %64-QAM modulations 
    index=3; 
    ModulateResult=zeros(1,length(code)/6); 
    for k=1:length(ModulateResult) 
        if code((k-1)*6+5:k*6)==[0 0] 
            Q=7*(2*code((k-1)*6+4)-1); 
        elseif code((k-1)*6+5:k*6)==[0 1] 
            Q=5*(2*code((k-1)*6+4)-1); 
        elseif code((k-1)*6+5:k*6)==[1 1] 
            Q=3*(2*code((k-1)*6+4)-1); 
        else 
            Q=2*code((k-1)*6+4)-1; 
        end 
        if code((k-1)*6+2:(k-1)*6+3)==[0 0] 
            I=7*(2*code((k-1)*6+1)-1); 
        elseif code((k-1)*6+2:(k-1)*6+3)==[0 1] 
            I=5*(2*code((k-1)*6+1)-1); 
        elseif code((k-1)*6+2:(k-1)*6+3)==[1 1] 
            I=3*(2*code((k-1)*6+1)-1); 
        else 
            I=2*code((k-1)*6+1)-1; 
        end 
        ModulateResult(k)=I+i*Q; 
    end 
    ModulateResult=ModulateResult/sqrt(42); 
end