QAM仿真代码(matlab)

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

1/5%16QAM系统仿真function[ber_AWGN,ber_Ray]=M16QAM()EbN0dB=1:3:30。EbN0dB1=1:10。N=4*100000。forii=1:length(EbN0dB)sigma2(ii)=2.5/(2*4*(10^(EbN0dB(ii)/10)))。sigma21(ii)=2.5/(2*4*(10^(EbN0dB1(ii)/10)))。bits=randint(1,N)。%调制s=M16QAM_modulate(bits,length(bits(:)))。%Rayleign信道干扰noise=sqrt(sigma2(ii))*(randn(1,N/4)+1i*randn(1,N/4))。h=sqrt(0.5)*(randn(1,N/4)+1i*randn(1,N/4))。receiver=s.*h+noise。%Rayleign衰减信道%高斯信道干扰noise1=sqrt(sigma21(ii))*(randn(1,N/4)+1i*randn(1,N/4))。receiver1=s+noise1。%高斯信道%信道均衡receiver=receiver./h。%解调并计算误码率Rayleign信道demodata=M16QAM_demodulate(receiver,length(receiver(:)))。errCount=sum(abs(bits-demodata))。ber_Ray(ii)=errCount/N。%解调并计算误码率高斯信道demodata=M16QAM_demodulate(receiver1,length(receiver1(:)))。errCount=sum(abs(bits-demodata))。ber_AWGN(ii)=errCount/N。endend%16QAM调制function[s]=M16QAM_modulate(bits,N)ii=0。fori=1:4:Nii=ii+1。ifbits(i)==0&&bits(i+1)==0&&bits(i+2)==0&&bits(i+3)==0s(ii)=sqrt(2)/2*exp(1i*pi/4)。elseifbits(i)==1&&bits(i+1)==0&&bits(i+2)==0&&bits(i+3)==0s(ii)=sqrt(2)/2*exp(1i*3*pi/4)。elseifbits(i)==1&&bits(i+1)==0&&bits(i+2)==1&&bits(i+3)==0s(ii)=sqrt(2)/2*exp(1i*5*pi/4)。elseifbits(i)==0&&bits(i+1)==0&&bits(i+2)==1&&bits(i+3)==0s(ii)=sqrt(2)/2*exp(1i*7*pi/4)。2/5elseifbits(i)==0&&bits(i+1)==1&&bits(i+2)==0&&bits(i+3)==0s(ii)=sqrt(10)/2*exp(1i*atan(1/3))。elseifbits(i)==0&&bits(i+1)==0&&bits(i+2)==0&&bits(i+3)==1s(ii)=sqrt(10)/2*exp(1i*atan(3))。elseifbits(i)==1&&bits(i+1)==0&&bits(i+2)==0&&bits(i+3)==1s(ii)=sqrt(10)/2*exp(1i*(atan(1/3)+pi/2))。elseifbits(i)==1&&bits(i+1)==1&&bits(i+2)==0&&bits(i+3)==0s(ii)=sqrt(10)/2*exp(1i*(pi-atan(1/3)))。elseifbits(i)==1&&bits(i+1)==1&&bits(i+2)==1&&bits(i+3)==0s(ii)=sqrt(10)/2*exp(1i*(atan(1/3)+pi))。elseifbits(i)==1&&bits(i+1)==0&&bits(i+2)==1&&bits(i+3)==1s(ii)=sqrt(10)/2*exp(1i*(3*pi/2-atan(1/3)))。elseifbits(i)==0&&bits(i+1)==0&&bits(i+2)==1&&bits(i+3)==1s(ii)=sqrt(10)/2*exp(1i*(atan(1/3)+3*pi/2))。elseifbits(i)==0&&bits(i+1)==1&&bits(i+2)==1&&bits(i+3)==0s(ii)=sqrt(10)/2*exp(1i*(2*pi-atan(1/3)))。elseifbits(i)==0&&bits(i+1)==1&&bits(i+2)==0&&bits(i+3)==1s(ii)=sqrt(2)*3/2*exp(1i*pi/4)。elseifbits(i)==1&&bits(i+1)==1&&bits(i+2)==0&&bits(i+3)==1s(ii)=sqrt(2)*3/2*exp(1i*3*pi/4)。elseifbits(i)==1&&bits(i+1)==1&&bits(i+2)==1&&bits(i+3)==1s(ii)=sqrt(2)*3/2*exp(1i*5*pi/4)。elseifbits(i)==0&&bits(i+1)==1&&bits(i+2)==1&&bits(i+3)==1s(ii)=sqrt(2)*3/2*exp(1i*7*pi/4)。endendend%16QAM解调function[demodata]=M16QAM_demodulate(receiver,N)A=[0101。-1001。-10-10。01-10。1inf01。011inf。-101inf。-inf-101。-inf-1-10。-10-inf-1。01-inf-1。1inf-10。1inf1inf。-inf-11inf。-inf-1-inf-1。1inf-inf-1]。fork=1:Nif(real(receiver(k))=A(1,1))&&(real(receiver(k))A(1,2))&&...(imag(receiver(k))=A(1,3))&&(imag(receiver(k))A(1,4))demodata(k*4-3)=0。demodata(k*4-2)=0。demodata(k*4-1)=0。demodata(k*4)=0。elseif(real(receiver(k))=A(2,1))&&(real(receiver(k))A(2,2))...&&(imag(receiver(k))=A(2,3))&&(imag(receiver(k))A(2,4))demodata(k*4-3)=1。3/5demodata(k*4-2)=0。demodata(k*4-1)=0。demodata(k*4)=0。elseif(real(receiver(k))=A(3,1))&&(real(receiver(k))A(3,2))...&&(imag(receiver(k))=A(3,3))&&(imag(receiver(k))A(3,4))demodata(k*4-3)=1。demodata(k*4-2)=0。demodata(k*4-1)=1。demodata(k*4)=0。elseif(real(receiver(k))=A(4,1))&&(real(receiver(k))A(4,2))...&&(imag(receiver(k))=A(4,3))&&(imag(receiver(k))A(4,4))demodata(k*4-3)=0。demodata(k*4-2)=0。demodata(k*4-1)=1。demodata(k*4)=0。elseif(real(receiver(k))=A(5,1))&&(real(receiver(k))A(5,2))...&&(imag(receiver(k))=A(5,3))&&(imag(receiver(k))A(5,4))demodata(k*4-3)=0。demodata(k*4-2)=1。demodata(k*4-1)=0。demodata(k*4)=0。elseif(real(receiver(k))=A(6,1))&&(real(receiver(k))A(6,2))...&&(imag(receiver(k))=A(6,3))&&(imag(receiver(k))A(6,4))demodata(k*4-3)=0。demodata(k*4-2)=0。demodata(k*4-1)=0。demodata(k*4)=1。elseif(real(receiver(k))=A(7,1))&&(real(receiver(k))A(7,2))...&&(imag(receiver(k))=A(7,3))&&(imag(receiver(k))A(7,4))demodata(k*4-3)=1。demodata(k*4-2)=0。demodata(k*4-1)=0。demodata(k*4)=1。elseif(real(receiver(k))=A(8,1))&&(real(receiver(k))A(8,2))...&&(imag(receiver(k))=A(8,3))&&(imag(receiver(k))A(8,4))demodata(k*4-3)=1。demodata(k*4-2)=1。demodata(k*4-1)=0。demodata(k*4)=0。elseif(real(receiver(k))=A(9,1))&&(real(receiver(k))A(9,2))...&&(imag(receiver(k))=A(9,3))&&(imag(receiver(k))A(9,4))demodata(k*4-3)=1。demodata(k*4-2)=1。4/5demodata(k*4-1)=1。demodata(k*4)=0。elseif(real(receiver(k))=A(10,1))&&(real(receiver(k))A(10,2))...&&(imag(receiver(k))=A(10,3))&&(imag(receiver(k))A(10,4))demodata(k*4-3)=1。demodata(k*4-2)=0。demodata(k*4-1)=1。demodata(k*4)=1。elseif(real(receiver(k))=A(11,1))&&(real(receiver(k))A(11,2))...&&(imag(receiver(k))=A(11,3))&&(imag(receiver(k))A(11,4))demodata(k*4-3)=0。demodata(k*4-2)=0。demodata(k*4-1)=1。demodata(k*4)=1。elseif(real(receiver(k))=A(12,1))&&(real(receiver(k))A(12,2))...&&(imag(receiver(k))=A(12,3))&&(imag(receiver(k))A(12,4))demodata(k*4-3)=0。demodata(k*4-2)=1。demodata(k*4-1)=1。demodata(k*4)=0。elseif(real(receiver(k))=A(13,1))&&(real(receiver(k))A(13,2))...&&(imag(receiver(k))=A(13,3))&&(imag(receiver(k))A(13,4))demodata(k*4-

1 / 5
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功