📄 ofdm.m
字号:
% ofdm.m
% 实现OFDM传输的仿真程序
% programmed by ZuFei Chen
%********************** 准备部分 ***************************
para=128; % 并行子信道的个数
fftlen=128; % FFT的长度
noc=128; % 载波的个数(这里我认为其数目和子信道数目相同)
nd=6; % 循环一次OFDM的符号个数
ml=2; % 采用QPSK调制
sr=250000; % 符号速率
br=sr.*ml; % 每个载波的比特速率
gilen=32; % 保护间隔的长度
ebn0=3; % (Eb/N0 - Signal to noise ration per bit , SNR - Signal to noise ratio)
%************************** 主循环部分 **************************
nloop=100; % 仿真循环次数
noe = 0; % 错误数据的个数
nod = 0; % 传输数据的个数
eop=0; % 错误包的个数
nop=0; % 传输包的个数
for iii=1:nloop
%****************** 发射部分 ******************************************************
%****************** 产生数据 **********************
seldata=rand(1,para*nd*ml)>0.5; % rand : built in function
%****************** 串并转换 ***********************
paradata=reshape(seldata,para,nd*ml); % reshape : built in function
%****************** QPSK调制 ***********************
[ich,qch]=qpskmod(paradata,para,nd,ml);
kmod=1/sqrt(2); % sqrt : built in function
ich1=ich.*kmod;
qch1=qch.*kmod; % QPSK调制时,要乘上1/sqrt(2)系数
%****************** IFFT(离散傅里叶反变换) *********
x=ich1+qch1.*i;
y=ifft(x); % ifft : built in function
ich2=real(y); % real : built in function
qch2=imag(y); % imag : built in function
%****************** 插入保护间隔 *******************
[ich3,qch3]= giins(ich2,qch2,fftlen,gilen,nd);
fftlen2=fftlen+gilen;
%****************** 衰减计算 ************************
spow=sum(ich3.^2+qch3.^2)/nd./para; % sum : built in function
attn=0.5*spow*sr/br*10.^(-ebn0/10);
attn=sqrt(attn);
%****************** 高斯白信道 *****************************************************
[ich4,qch4]=comb(ich3,qch3,attn);
%****************** 接收部分 ******************************************************
%****************** 去除保护间隔 ********************
[ich5,qch5]= girem(ich4,qch4,fftlen2,gilen,nd);
%****************** FFT(离散傅里叶变换) ************
rx=ich5+qch5.*i;
ry=fft(rx); % fft : built in function
ich6=real(ry); % real : built in function
qch6=imag(ry); % imag : built in function
%***************** QPSK解调 **************************
ich7=ich6./kmod;
qch7=qch6./kmod;
[demodata]=qpskdemod(ich7,qch7,para,nd,ml);
%************** 并串变换 ***************************
demodata1=reshape(demodata,1,para*nd*ml);
%*************** 比特误码率 (BER) *********************
% instantaneous number of error and data
noe2=sum(abs(demodata1-seldata)); % sum : built in function
nod2=length(seldata); % length : built in function
% 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;
fprintf('%d\t%e\t%d\n',iii,noe2/nod2,eop); % fprintf : built in function
end
%****************** 结果输出 ***************************
per=eop/nop;
ber=noe/nod;
fprintf('%f\t%e\t%e\t%d\t\n',ebn0,ber,per,nloop);
fid = fopen('BERofdm.dat','a');
fprintf(fid,'%f\t%e\t%e\t%d\t\n',ebn0,ber,per,nloop);
fclose(fid);
%****************** end of file ******************************************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -