16QAM仿真代码(matlab) Lt
D
% 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)+ 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(receiv er(:)) );
errCount=sum(abs(bits-demodata));
ber_Ray(ii)=errCount/N;
%解调并计算误码率高斯信道
demodata = M16QAM_demodulate( receiver1,length(recei ver1(:))  );
errCount=sum(abs(bits-demodata));
ber_AWGN(ii)=errCount/N;
end
end
modulate
%  16QAM 调制
function [ s ] = M16QAM_modulate( bits,N) ii=0;
for i=1:4:N
ii=ii+1;
if
bits(i)==0&&bits(i+1)==0&&bits(i+2)==0&&b its(i+3)==0
s(ii)=sqrt(2)/2*exp(1i*pi/4);
elseif
bits(i)==1&&bits(i+1)==0&&bits(i+2)==0&&b its(i+3)==0
s(ii)=sqrt(2)/2*exp(1i*3*pi/4);
elseif
bits(i)==1&&bits(i+1)==0&&bits(i+2)==1&&b its(i+3)==0
s(ii)=sqrt(2)/2*exp(1i*5*pi/4);
elseif
bits(i)==0&&bits(i+1)==0&&bits(i+2)==1&&b its(i+3)==0
s(ii)=sqrt(2)/2*exp(1i*7*pi/4);
elseif
bits(i)==0&&bits(i+1)==1&&bits(i+2)==0&&b its(i+3)==0
s(ii)=sqrt(10)/2*exp(1i*atan(1/3));
elseif
bits(i)==0&&bits(i+1)==0&&bits(i+2)==0&&b its(i+3)==1
s(ii)=sqrt(10)/2*exp(1i*atan(3));
elseif
bits(i)==1&&bits(i+1)==0&&bits(i+2)==0&&b its(i+3)==1
s(ii)=sqrt(10)/2*exp(1i*(atan(1/3)+pi/2)) ;
elseif

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。