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

```function DemoduResult=demodulation(input,index)
% QPSK,16-QAM,64-QAM demodulation
if index==1
%QPSK
input=input*sqrt(2);
DemoduResult=zeros(1,length(input)*2);
for k=1:length(input)
DemoduResult(2*k-1)=real(input(k));
DemoduResult(2*k)=imag(input(k));
end
elseif index==2
%16-QAM
DemoduResult=zeros(1,length(input)*4);
input=input*sqrt(10);
for k=1:length(input)
if abs(real(input(k)))<=2
DemoduResult(4*k-3)=real(input(k));
elseif real(input(k))>2
DemoduResult(4*k-3)=2*(real(input(k))-1);
else
DemoduResult(4*k-3)=2*(real(input(k))+1);
end
if real(input(k))>=0
DemoduResult(4*k-2)=2-real(input(k));
else
DemoduResult(4*k-2)=2+real(input(k));
end
if abs(imag(input(k)))<=2
DemoduResult(4*k-1)=imag(input(k));
elseif imag(input(k))>2
DemoduResult(4*k-1)=2*(imag(input(k))-1);
else
DemoduResult(4*k-1)=2*(imag(input(k))+1);
end
if imag(input(k))>=0
DemoduResult(4*k)=2-imag(input(k));
else
DemoduResult(4*k)=2+imag(input(k));
end
end
else
%64-QAM
DemoduResult=zeros(1,length(input)*6);
input=input*sqrt(42);
for k=1:length(input)
% b0 & b3
if abs(real(input(k)))<=2
DemoduResult(6*k-5)=real(input(k));
elseif real(input(k))>2&real(input(k))<=4
DemoduResult(6*k-5)=2*(real(input(k))-1);
elseif real(input(k))>4&real(input(k))<=6
DemoduResult(6*k-5)=3*(real(input(k))-2);
elseif real(input(k))>6
DemoduResult(6*k-5)=4*(real(input(k))-3);
elseif real(input(k))>=-4&real(input(k))<-2
DemoduResult(6*k-5)=2*(real(input(k))+1);
elseif real(input(k))>=-6&real(input(k))<-4
DemoduResult(6*k-5)=3*(real(input(k))+2);
else
DemoduResult(6*k-5)=4*(real(input(k))+3);
end
if abs(imag(input(k)))<=2
DemoduResult(6*k-2)=imag(input(k));
elseif imag(input(k))>2&imag(input(k))<=4
DemoduResult(6*k-2)=2*(imag(input(k))-1);
elseif imag(input(k))>4&imag(input(k))<=6
DemoduResult(6*k-2)=3*(imag(input(k))-2);
elseif imag(input(k))>6
DemoduResult(6*k-2)=4*(imag(input(k))-3);
elseif imag(input(k))>=-4&imag(input(k))<-2
DemoduResult(6*k-2)=2*(imag(input(k))+1);
elseif imag(input(k))>=-6&imag(input(k))<-4
DemoduResult(6*k-2)=3*(imag(input(k))+2);
else
DemoduResult(6*k-2)=4*(imag(input(k))+3);
end
% b1 & b4
if real(input(k))>0&real(input(k))<=2
DemoduResult(6*k-4)=2*(3-real(input(k)));
elseif real(input(k))>2&real(input(k))<=6
DemoduResult(6*k-4)=4-real(input(k));
elseif real(input(k))>6
DemoduResult(6*k-4)=2*(5-real(input(k)));
elseif real(input(k))>-2&real(input(k))<=0
DemoduResult(6*k-4)=2*(3+real(input(k)));
elseif real(input(k))>-6&real(input(k))<=-2
DemoduResult(6*k-4)=4+real(input(k));
else
DemoduResult(6*k-4)=2*(5+real(input(k)));
end
if imag(input(k))>0&imag(input(k))<=2
DemoduResult(6*k-1)=2*(3-imag(input(k)));
elseif imag(input(k))>2&imag(input(k))<=6
DemoduResult(6*k-1)=4-imag(input(k));
elseif imag(input(k))>6
DemoduResult(6*k-1)=2*(5-imag(input(k)));
elseif imag(input(k))>-2&imag(input(k))<=0
DemoduResult(6*k-1)=2*(3+imag(input(k)));
elseif imag(input(k))>-6&imag(input(k))<=-2
DemoduResult(6*k-1)=4+imag(input(k));
else
DemoduResult(6*k-1)=2*(5+imag(input(k)));
end
% b2 & b5
if real(input(k))>4
DemoduResult(6*k-3)=6-real(input(k));
elseif real(input(k))<-4
DemoduResult(6*k-3)=6+real(input(k));
elseif real(input(k))>0&real(input(k))<=4
DemoduResult(6*k-3)=real(input(k))-2;
else
DemoduResult(6*k-3)=-2-real(input(k));
end
if imag(input(k))>4
DemoduResult(6*k)=6-imag(input(k));
elseif imag(input(k))<-4
DemoduResult(6*k)=6+imag(input(k));
elseif imag(input(k))>0&imag(input(k))<=4
DemoduResult(6*k)=imag(input(k))-2;
else
DemoduResult(6*k)=-2-imag(input(k));
end
end
end```