本文主要是介绍OFDM matlab仿真不同保护间隔的ISI影响,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
OFDM matlab仿真不同保护间隔的ISI影响
主程序:
NgType=1; % 对于CP或ZP,NgType=1或2
if NgType1
nt=‘CP’;
elseif NgType2
nt=‘ZP’;
end
Ch=0; % 对于AWGN/多径瑞利信道,channelCh=0/1
if Ch==0
chType=‘AWGN’;
Target_neb=100;
else
chType=‘CH’;
Target_neb=500;
end
PowerdB=[0 -8 -17 -21 -25]; % 信道抽头功率特性(dB)
Delay=[0 3 5 6 8]; % 信道时延(采样点)
Power=10.^(PowerdB/10); % 信道抽头功率特性(线性尺度)
Ntap=length(PowerdB); % 信道抽头数
Lch=Delay(end)+1; % 信道长度
Nbps=4; M=2^Nbps; % 调制阶数=2/4/6:QPSK/16-QAM/64-QAM
Nfft=64; % FFT大小
Ng=Nfft/4; % GI(保护间隔)长度,没保护间隔时,Ng=0
Nsym=Nfft+Ng; % 符号周期
Nvc=Nfft/4; % Nvc=0 :没有VC(虚拟载波)
Nused=Nfft-Nvc;
EbN0=(0:3:30); % Eb/N0
N_iter=1e3; % 对于每一个EbN0的迭代次数
Nframe=3; % 每一帧的符号数
sigPow=0; % 初始信号功率
file_name=[‘OFDM_BER_’ chType ‘’ nt '’ ‘GL’ num2str(Ng) ‘.dat’];
fid=fopen(file_name, ‘w+’);
norms=[1 sqrt(2) 0 sqrt(10) 0 sqrt(42)]; % BPSK 4-QAM 16-QAM
for i=0:length(EbN0)
randn(‘state’,0);rand(‘state’,0);
%Ber2=ber(); 初始化BER
Neb=0; % 初始化错误比特数
Ntb=0; % 初始化总比特数
for m=1:N_iter
% Tx_______________________________________________________________________________
X= randi([0 M-1],1,NusedNframe); % bit: 整数向量(问题:randint怎么换成randi)
Xmod= qammod(X,M,‘gray’)/norms(Nbps);
if NgType~=2
x_GI=zeros(1,NframeNsym);
elseif NgType2
x_GI= zeros(1,Nframe*Nsym+Ng);
% 用Ng个零扩展OFDM符号
end
kk1=(1:Nused/2);
kk2=(Nused/2+1:Nused);
kk3=1:Nfft;
kk4=1:Nsym;
for k=1:Nframe
if Nvc~=0
X_shift= [0 Xmod(kk2) zeros(1,Nvc-1) Xmod(kk1)];
else
X_shift= [Xmod(kk2) Xmod(kk1)];
end
x= ifft(X_shift);
x_GI(kk4)= guard_interval(Ng,Nfft,NgType,x);
kk1=kk1+Nused;
kk2= kk2+Nused;
kk3=kk3+Nfft;
kk4=kk4+Nsym;
end
if Ch0
y= x_GI; % 没有信道
else % 多径衰落信道
channel=(randn(1,Ntap)+1irandn(1,Ntap)).sqrt(Power/2);
h=zeros(1,Lch); %信道脉冲响应
h(Delay+1)=channel;
y = conv(x_GI,h);
end
if i==0 % 只测量增加的AWGN噪声的信号功率
y1=y(1:NframeNsym);
sigPow = sigPow + y1y1’;
continue;
end
% 加AWGN噪声________________________________________________
snr = EbN0(i)+10log10(Nbps(Nused/Nfft)); % SNR vs. Eb/N0 by Eq.(4.28)
noise_mag = sqrt((10.^(-snr/10))sigPow/2);
y_GI = y + noise_mag(randn(size(y))+1i*randn(size(y)));
% Rx_____________________________________________________________kk1=(NgType==2)*Ng+(1:Nsym); kk2=1:Nfft;kk3=1:Nused; kk4=Nused/2+Nvc+1:Nfft; kk5=(Nvc~=0)+(1:Nused/2);if Ch==1H= fft([h zeros(1,Nfft-Lch)]); % 信道频率响应H_shift(kk3)= [H(kk4) H(kk5)];endfor k=1:NframeY(kk2)= fft(remove_GI(Ng,Nsym,NgType,y_GI(kk1)));Y_shift=[Y(kk4) Y(kk5)];if Ch==0Xmod_r(kk3) = Y_shift;elseXmod_r(kk3)=Y_shift./H_shift; % 均衡器endkk1=kk1+Nsym; kk2=kk2+Nfft; kk3=kk3+Nused; kk4=kk4+Nfft;kk5=kk5+Nfft;endX_r=qamdemod(Xmod_r*norms(Nbps),M,'gray');Neb=Neb+sum(sum(de2bi(X_r,Nbps)~=de2bi(X,Nbps))); % 判决Ntb=Ntb+Nused*Nframe*Nbps; %[Ber,Neb,Ntb]=ber(bit_Rx,bit,Nbps);if Neb>Target_neb,break;end
end
if i==0sigPow= sigPow/Nsym/Nframe/N_iter;
elseBer = Neb/Ntb;fprintf('EbN0=%3d[dB], BER=%4d/%8d =%11.3e\n', EbN0(i), Neb,Ntb,Ber)fprintf(fid, '%d\t%11.3e\n', EbN0(i), Ber);if Ber<1e-6, break; end
end
end
if (fid~=0)
fclose(fid);
end
disp(‘Simulation is finished’)
ber_AWGN = ber_QAM(EbN0,M,‘AWGN’);
ber_Rayleigh = ber_QAM(EbN0,M,‘Rayleigh’);
semilogy(EbN0,ber_AWGN,‘r:’), hold on
semilogy(EbN0,ber_Rayleigh,‘m-’)
a= load(file_name);
semilogy(a(:,1),a(:,2),‘b–d’), grid on
xlabel(‘EbN0[dB]’), ylabel(‘BER’)
axis([a(1,1) 30 1e-4 1])
Ch=1; % 对于AWGN/多径瑞利信道,channelCh=0/1
file_name=[‘OFDM_BER_’ chType ‘’ nt '’ ‘GL’ num2str(Ng) ‘.dat’];
fid=fopen(file_name, ‘w+’);
for i=0:length(EbN0)
randn(‘state’,0);rand(‘state’,0);
%Ber2=ber(); 初始化BER
Neb=0; % 初始化错误比特数
Ntb=0; % 初始化总比特数
for m=1:N_iter
% Tx______________________________________________________________
X= randi([0 M-1],1,NusedNframe); % bit: 整数向量(问题:randint怎么换成randi)
Xmod= qammod(X,M,‘gray’)/norms(Nbps);
if NgType~=2
x_GI=zeros(1,NframeNsym);
elseif NgType2
x_GI= zeros(1,Nframe*Nsym+Ng);
% 用Ng个零扩展OFDM符号
end
kk1=(1:Nused/2);
kk2=(Nused/2+1:Nused);
kk3=1:Nfft;
kk4=1:Nsym;
for k=1:Nframe
if Nvc~=0
X_shift= [0 Xmod(kk2) zeros(1,Nvc-1) Xmod(kk1)];
else
X_shift= [Xmod(kk2) Xmod(kk1)];
end
x= ifft(X_shift);
x_GI(kk4)= guard_interval(Ng,Nfft,NgType,x);
kk1=kk1+Nused;
kk2= kk2+Nused;
kk3=kk3+Nfft;
kk4=kk4+Nsym;
end
if Ch0
y= x_GI; % 没有信道
else % 多径衰落信道
channel=(randn(1,Ntap)+1irandn(1,Ntap)).sqrt(Power/2);
h=zeros(1,Lch); %信道脉冲响应
h(Delay+1)=channel;
y = conv(x_GI,h);
end
if i==0 % 只测量增加的AWGN噪声的信号功率
y1=y(1:NframeNsym);
sigPow = sigPow + y1y1’;
continue;
end
% 加AWGN噪声________________________________________________
snr = EbN0(i)+10log10(Nbps(Nused/Nfft)); % SNR vs. Eb/N0 by Eq.(4.28)
noise_mag = sqrt((10.^(-snr/10))sigPow/2);
y_GI = y + noise_mag(randn(size(y))+1i*randn(size(y)));
% Rx_____________________________________________________________kk1=(NgType==2)*Ng+(1:Nsym); kk2=1:Nfft;kk3=1:Nused; kk4=Nused/2+Nvc+1:Nfft; kk5=(Nvc~=0)+(1:Nused/2);if Ch==1H= fft([h zeros(1,Nfft-Lch)]); % 信道频率响应H_shift(kk3)= [H(kk4) H(kk5)];endfor k=1:NframeY(kk2)= fft(remove_GI(Ng,Nsym,NgType,y_GI(kk1)));Y_shift=[Y(kk4) Y(kk5)];if Ch==0Xmod_r(kk3) = Y_shift;elseXmod_r(kk3)=Y_shift./H_shift; % 均衡器endkk1=kk1+Nsym; kk2=kk2+Nfft; kk3=kk3+Nused; kk4=kk4+Nfft;kk5=kk5+Nfft;endX_r=qamdemod(Xmod_r*norms(Nbps),M,'gray');Neb=Neb+sum(sum(de2bi(X_r,Nbps)~=de2bi(X,Nbps))); % 判决Ntb=Ntb+Nused*Nframe*Nbps; %[Ber,Neb,Ntb]=ber(bit_Rx,bit,Nbps);if Neb>Target_neb,break;end
end
if i==0sigPow= sigPow/Nsym/Nframe/N_iter;
elseBer = Neb/Ntb;fprintf('EbN0=%3d[dB], BER=%4d/%8d =%11.3e\n', EbN0(i), Neb,Ntb,Ber)fprintf(fid, '%d\t%11.3e\n', EbN0(i), Ber);if Ber<1e-6, break; end
end
end
if (fid~=0)
fclose(fid);
end
disp(‘Simulation is finished’)
a= load(file_name);
semilogy(a(:,1),a(:,2),‘g–*’), grid on
NgType=2; % 对于CP或ZP,NgType=1或2
file_name=[‘OFDM_BER_’ chType ‘’ nt '’ ‘GL’ num2str(Ng) ‘.dat’];
fid=fopen(file_name, ‘w+’);
for i=0:length(EbN0)
randn(‘state’,0);rand(‘state’,0);
%Ber2=ber(); 初始化BER
Neb=0; % 初始化错误比特数
Ntb=0; % 初始化总比特数
for m=1:N_iter
% Tx______________________________________________________________
X= randi([0 M-1],1,NusedNframe); % bit: 整数向量(问题:randint怎么换成randi)
Xmod= qammod(X,M,‘gray’)/norms(Nbps);
if NgType~=2
x_GI=zeros(1,NframeNsym);
elseif NgType2
x_GI= zeros(1,Nframe*Nsym+Ng);
% 用Ng个零扩展OFDM符号
end
kk1=(1:Nused/2);
kk2=(Nused/2+1:Nused);
kk3=1:Nfft;
kk4=1:Nsym;
for k=1:Nframe
if Nvc~=0
X_shift= [0 Xmod(kk2) zeros(1,Nvc-1) Xmod(kk1)];
else
X_shift= [Xmod(kk2) Xmod(kk1)];
end
x= ifft(X_shift);
x_GI(kk4)= guard_interval(Ng,Nfft,NgType,x);
kk1=kk1+Nused;
kk2= kk2+Nused;
kk3=kk3+Nfft;
kk4=kk4+Nsym;
end
if Ch0
y= x_GI; % 没有信道
else % 多径衰落信道
channel=(randn(1,Ntap)+1irandn(1,Ntap)).sqrt(Power/2);
h=zeros(1,Lch); %信道脉冲响应
h(Delay+1)=channel;
y = conv(x_GI,h);
end
if i==0 % 只测量增加的AWGN噪声的信号功率
y1=y(1:NframeNsym);
sigPow = sigPow + y1y1’;
continue;
end
% 加AWGN噪声________________________________________________
snr = EbN0(i)+10log10(Nbps(Nused/Nfft)); % SNR vs. Eb/N0 by Eq.(4.28)
noise_mag = sqrt((10.^(-snr/10))sigPow/2);
y_GI = y + noise_mag(randn(size(y))+1i*randn(size(y)));
% Rx_____________________________________________________________kk1=(NgType==2)*Ng+(1:Nsym); kk2=1:Nfft;kk3=1:Nused; kk4=Nused/2+Nvc+1:Nfft; kk5=(Nvc~=0)+(1:Nused/2);if Ch==1H= fft([h zeros(1,Nfft-Lch)]); % 信道频率响应H_shift(kk3)= [H(kk4) H(kk5)];endfor k=1:NframeY(kk2)= fft(remove_GI(Ng,Nsym,NgType,y_GI(kk1)));Y_shift=[Y(kk4) Y(kk5)];if Ch==0Xmod_r(kk3) = Y_shift;elseXmod_r(kk3)=Y_shift./H_shift; % 均衡器endkk1=kk1+Nsym; kk2=kk2+Nfft; kk3=kk3+Nused; kk4=kk4+Nfft;kk5=kk5+Nfft;endX_r=qamdemod(Xmod_r*norms(Nbps),M,'gray');Neb=Neb+sum(sum(de2bi(X_r,Nbps)~=de2bi(X,Nbps))); % 判决Ntb=Ntb+Nused*Nframe*Nbps; %[Ber,Neb,Ntb]=ber(bit_Rx,bit,Nbps);if Neb>Target_neb,break;end
end
if i==0sigPow= sigPow/Nsym/Nframe/N_iter;
elseBer = Neb/Ntb;fprintf('EbN0=%3d[dB], BER=%4d/%8d =%11.3e\n', EbN0(i), Neb,Ntb,Ber)fprintf(fid, '%d\t%11.3e\n', EbN0(i), Ber);if Ber<1e-6, break; end
end
end
if (fid~=0)
fclose(fid);
end
disp(‘Simulation is finished’)
a= load(file_name);
semilogy(a(:,1),a(:,2),‘k–s’), grid on
legend(‘AWGN analytic’,‘Rayleigh fading analytic’, ‘AWGN,no guard interval’,‘Channel,CP:16’,‘Channel,ZP:16’)
功能函数:
function ber=ber_QAM(EbN0dB,M,AWGN_or_Rayleigh)
% 找到AWGN或瑞利信道中M-QAM的BER
% EbN0dB: AWGN信道的每比特信号与噪声功率比[dB]
% =rdB : Average SNR(2sigma Eb/N0)[dB] for Rayleigh channel
% M = 调制阶数 (星座大小)
N= length(EbN0dB);
sqM= sqrt(M);
a= 2(1-power(sqM,-1))/log2(sqM);
b= 6log2(sqM)/(M-1);
if nargin<3
AWGN_or_Rayleigh=‘AWGN’;
end
if lower(AWGN_or_Rayleigh(1))==‘a’
ber = aQ(sqrt(b10.^(EbN0dB/10))); % ber=berawgn(EbN0dB,’QAM’,M) Eq.(4.25)
else % diversity_order=1; ber=berfading(EbN0dB,’QAM’,M,diversity_order)
rn=b10.^(EbN0dB/10)/2;
ber = 0.5a(1-sqrt(rn./(rn+1))); % Eq.(4.26)
end
function y = guard_interval(Ng,Nfft,NgType,ofdmSym)
if NgType1
y=[ofdmSym(Nfft-Ng+1:Nfft) ofdmSym(1:Nfft)];
elseif NgType2
y=[zeros(1,Ng) ofdmSym(1:Nfft)];
end
function y=remove_GI(Ng,Lsym,NgType,ofdmSym)
if Ng~=0
if NgType1
y=ofdmSym(Ng+1:Lsym); % 循环前缀
elseif NgType2 % 循环后缀
y=ofdmSym(1:Lsym-Ng)+[ofdmSym(Lsym-Ng+1:Lsym) zeros(1,Lsym-2*Ng)];
end
else
y=ofdmSym;
end
function y=Q(x)
% 误差函数: 1/sqrt(2*pi) * int_x^inf exp(-t^2/2) dt. % Eq.(4.27)
y=erfc(x/sqrt(2))/2;
这篇关于OFDM matlab仿真不同保护间隔的ISI影响的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!