1、% 16QAM 系统仿真function ber_AWGN,ber_Ray = M16QAM()EbN0dB=1:3:30;EbN0dB1=1:10;N=4*100000;for ii=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)+
2、 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(:)
3、);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;for i=1:4:Nii=ii+1;if bits(i)=0elseif bits(i)=1elseif
4、 bits(i)=1elseif bits(i)=0elseif bits(i)=0elseif bits(i)=0elseif bits(i)=1elseif bits(i)=1elseif bits(i)=1elseif bits(i)=1elseif bits(i)=0elseif bits(i)=0elseif bits(i)=0elseif bits(i)=1elseif bits(i)=1elseif bits(i)=0endendend% 16 QAM 解调function demodata = M16QAM_demodulate( receiver ,N)A=0 1 0 1; -1 0 0 1;-1 0 -1 0;0 1 -1 0;1 inf 0 1;0 1 1 inf;-1 0 1 inf;-inf -1 0 1;-inf -1 -1 0;-1 0 -inf -1;0 1 -inf -1;1 inf -1 0;1 inf 1 inf;-inf -1 1 inf;-inf -1 -inf -1;1 inf -inf -1;for k=1:Nif (real(receiver(k)=A(1,1)demodata(k*4-2)=1;demodata(k*4-1)=1;demodata(k*4)=1; endendend