📄 ofdm.m
字号:
clear all;
para=128; % Number of parallel channel to transmit (points)
fftlen=128; % FFT长度
noc=128; % 载波数
nd=100; % Number of information OFDM symbol for one loop
ml=2; % Modulation level : QPSK
sr=250000; % Symbol rate
br=sr.*ml; % Bit rate per carrier
gilen=32; % Length of guard interval (points)
ebn0=2:0.5:10; % Eb/N0
for iiii=1:length(ebn0);
nloop=100; % 仿真循环次数
noe = 0; % 差错数初值
nod = 0; % 传输数据初值
eop=0; % 差错信息包数初值
nop=0; % 传输信息包数初值
for iii=1:nloop
%seldata=rand(1,para*ml*nd)>0.5; % 产生信源
seldata=randint(1,para*ml*nd);
%Serial to parallel conversion
paradata=reshape(seldata,para,ml*nd);
% QPSK modulation
[ich,qch]=qpskmod(paradata,para,nd,ml);
kmod=1/sqrt(2); %归一化
ich1=ich.*kmod;
qch1=qch.*kmod;
%IFFT
x=ich1+qch1.*i;
y=ifft(x);
ich2=real(y);
qch2=imag(y);
%Gurad interval insertion
[ich3,qch3]= giins(ich2,qch2,fftlen,gilen,nd); %parallel to Serial conversion
fftlen2=fftlen+gilen;
%Attenuation Calculation
spow=sum(ich3.^2+qch3.^2)/nd./para;
attn(iiii)=0.5*spow*sr/br*10.^(-ebn0(iiii)/10);
attn(iiii)=sqrt(attn(iiii));
%Receiver
%AWGN addition
ich4=ich3+attn(iiii)*randn(1,length(ich3));
qch4=qch3+attn(iiii)*randn(1,length(qch3));
% [ich4,qch4]=comb(ich3,qch3,attn(iiii));
%Guard interval removal
[ich5,qch5]= girem(ich4,qch4,fftlen2,gilen,nd); %Serial to parallel conversion
%FFT
rx=ich5+qch5.*i;
ry=fft(rx);
ich6=real(ry);
qch6=imag(ry);
% demoduration
ich7=ich6./kmod;
qch7=qch6./kmod;
[demodata]=qpskdemod(ich7,qch7,para,nd,ml);
%Parallel to serial conversion
demodata1=reshape(demodata,1,para*nd*ml);
% Bit Error Rate (BER)
% instantaneous number of error and data
noe2=sum(abs(demodata1-seldata));
nod2=length(seldata);
% cumulative the number of error and data in noe and nod
noe=noe+noe2;
nod=nod+nod2;
% calculating PER
if noe2~=0
eop=eop+1;
else
eop=eop;
end
eop;
nop=nop+1;
end
% 输出结果
per(iiii)=eop/nop;
ber(iiii)=noe/nod;
fprintf('%f\t%e\t%e\t%d\t\n',ebn0(iiii),ber(iiii),per(iiii),nloop);
end
semilogy(ebn0,ber,'*-');
grid on
xlabel('ebn0');ylabel('Probability of Bit Error');
legend('OFDM');
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -