📄 ofdm.m
字号:
%Matlab Script for OFDM Simulation
N=32;
NS=10000;
SNRindB1=0:2:15;
SNRindB2=0:0.1:15;
for w=1:length(SNRindB1),
snr_in_dB = SNRindB1(w);
SNR=10^(snr_in_dB/10);
N0=2.5/SNR; %(Eav=10)
error=0;
for i=1:NS,
b=2*randint(1,4*N)-1;
b=reshape(b,N,4);
%Generate the 16QAM points.
XX=2*b(:,1)+b(:,2)+j*(2*b(:,3)+b(:,4));
X=XX';
sn=ifft(X,32);
noise=sqrt(N0/2)*(crandn(1,N));
r=sn*1+noise/N^.5; %Notice here, Matlab fft and ifft have scale problem.
Y=fft(r,32);
% Detect the nearest neighbor in the 16QAM constellation
for k=1:N,
if real(Y(1,k))>0,
if real(Y(1,k))>2,
Z(1,k)=3;
else
Z(1,k)=1;
end;
else
if real(Y(1,k))<-2,
Z(1,k)=-3;
else
Z(1,k)=-1;
end;
end;
if imag(Y(1,k))>0,
if imag(Y(1,k))>2,
Z(1,k)=Z(1,k)+3*j;
else,
Z(1,k)=Z(1,k)+j;
end;
else
if imag(Y(1,k))<-2,
Z(1,k)=Z(1,k)-3*j;
else
Z(1,k)=Z(1,k)-j;
end;
end;
end;
error=error+sum(Z~=X);
end;
error_rate(w)=error/(N*NS);
end
M=16;
k=4;
for i=1:length(SNRindB2),
SNR=exp(SNRindB2(i)*log(10)/10); % signal to noise ratio
% theoretical symbol error rate
theo_err_prb(i)=4*qfunc(sqrt(3*k*SNR/(M-1)));
end
% Plotting commands follow
semilogy(SNRindB1,error_rate,'*');
hold
semilogy(SNRindB2,theo_err_prb);
title('16-QAM Symbol Error rate with OFDM');
xlabel('{SNR in dB}');
ylabel('SER');
legend('simulation','16-QAM theoretical');
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -