⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ofdm_fading_new.m

📁 在高斯与一径瑞利衰落信道下对OFDM系统(QPSK调制)的功率普的仿真
💻 M
字号:
% Program 4-2
% ofdm_fading.m
%
% Simulation program to realize OFDM transmission system
% (under one path fading)
%
% programmed by T.Yamamura and H.Harada
%

%********************** preparation part ***************************
clear;
para=2048;   % Number of parallel channel to transmit (points)
fftlen=2048; % FFT length
noc=2048;    % Number of carrier
nd=10;       % 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=64;   % Length of guard interval (points)
ebn0=0:2:10;    % Eb/N0
ebn01=0:0.1:10;

%******************* Fading initialization ********************
% If you use fading function "sefade", you can initialize all of parameters.
% Otherwise you can comment out the following initialization.
% The detailed explanation of all of valiables are mentioned in Program 2-8.

% Time resolution

tstp=1/sr/(fftlen+gilen); 

% Arrival time for each multipath normalized by tstp
% If you would like to simulate under one path fading model, you have only to set 
% direct wave.

itau = [0];

% Mean power for each multipath normalized by direct wave.
% If you would like to simulate under one path fading model, you have only to set 
% direct wave.
dlvl = [0];

% Number of waves to generate fading for each multipath.
% In normal case, more than six waves are needed to generate Rayleigh fading
n0=[6];

% Initial Phase of delayed wave
% In this simulation 20-path Rayleigh fading are considered.
th1=[0];

% Number of fading counter to skip 
itnd0=nd*(fftlen+gilen)*10;

% Initial value of fading counter
% In this simulation one-path Rayleigh fading are considered.
% Therefore one fading counter are needed.
  
itnd1=[1000];

% Number of directwave + Number of delayed wave
% In this simulation one-path Rayleigh fading are considered
now1=1;        

% Maximum Doppler frequency [Hz]
% You can insert your favorite value
fd=320;       

% You can decide two mode to simulate fading by changing the variable flat
% flat     : flat fading or not 
% (1->flat (only amplitude is fluctuated),0->nomal(phase and amplitude are fluctutated)
flat =0;

%************************** main loop part **************************
for j=1:length(ebn0)
nloop=10;  % Number of simulation loops
noee=0;
noe = 0;    % Number of error data
nod = 0;    % Number of transmitted data
eop=0;      % Number of error packet
eopp=0;
nop=0;      % Number of transmitted packet
nopp=0;
nodd=0;
for iii=1:nloop

%************************** transmitter *********************************

%************************** Data generation **************************** 

seldata=rand(1,para*nd*ml)>0.5;  %  rand : built in function

%****************** Serial to parallel conversion ***********************

paradata=reshape(seldata,para,nd*ml); %  reshape : built in function

%************************** QPSK modulation ***************************** 

[ich,qch]=qpskmod(paradata,para,nd,ml);
kmod=1/sqrt(2); %  sqrt : built in function
ich1=ich.*kmod;
qch1=qch.*kmod;

%******************* 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

%********* Gurad interval insertion **********

[ich3,qch3]= giins(ich2,qch2,fftlen,gilen,nd);
fftlen2=fftlen+gilen;

%********* Attenuation Calculation *********

spow=sum(ich3.^2+qch3.^2)/nd./para;  %  sum : built in function
attn=0.5*spow*sr/br*10.^(-ebn0(j)/10);
attn=sqrt(attn);

%********************** Fading channel **********************

% Generated data are fed into a fading simulator
[ifade,qfade]=sefade(ich3,qch3,itau,dlvl,th1,n0,itnd1,now1,length(ich3),tstp,fd,flat);
  
% Updata fading counter
itnd1 = itnd1+ itnd0;

%***************************  Receiver  *****************************
%***************** AWGN addition ********* 

[ich4,qch4]=comb(ifade,qfade,attn);
[ich44,qch44]=comb(ich3,qch3,attn);

%****************** Guard interval removal *********

[ich5,qch5]= girem(ich4,qch4,fftlen2,gilen,nd);
[ich55,qch55]=girem(ich44,qch44,fftlen2,gilen,nd);
%******************  FFT  ******************

rx=ich5+qch5.*i;
rxx=ich55+qch55.*i;
ry=fft(rx);   	% fft : built in function
ryy=fft(rxx);
ich6=real(ry);	% real : built in function
qch6=imag(ry);	% imag : built in function
ich66=real(ryy);
qch66=imag(ryy);
%***************** demoduration *******************
ich77=ich66./kmod;
qch77=qch66./kmod;
ich7=ich6./kmod;
qch7=qch6./kmod;
[demodata]=qpskdemod(ich7,qch7,para,nd,ml);   
[demodataa]=qpskdemod(ich77,qch77,para,nd,ml);
%**************  Parallel to serial conversion  *****************
demodataa1=reshape(demodataa,1,para*nd*ml);
demodata1=reshape(demodata,1,para*nd*ml);

%************************** Bit Error Rate (BER) ****************************

% instantaneous number of error and data
noe2=sum(abs(demodata1-seldata));  %  sum : built in function
noe22=sum(abs(demodataa1-seldata));
nod2=length(seldata);  %  length : built in function

% cumulative the number of error and data in noe and nod
noe=noe+noe2;
noee=noee+noe22;
nod=nod+nod2;
nodd=nodd+nod2;

% calculating PER
if noe2~=0  
   eop=eop+1;
else
   eop=eop;
end   
   eop;
   nop=nop+1;
if noe22~=0
    eopp=eopp+1;
else
    eopp=eopp;
end
eopp;
nopp=nopp+1;

%fprintf('%d\t%e\t%d\n',iii,noe2/nod2,eop);  %  fprintf : built in function
   
end

%********************** Output result ***************************
per1(j)=eopp/nopp;
ber1(j)=noee/nodd;
per(j)=eop/nop;
ber(j)=noe/nod;

%fprintf('%f\t%e\t%e\t%d\t\n',ebn0,ber,per,nloop);
%fid = fopen('BERofdmfad.dat','a');
%fprintf(fid,'%f\t%e\t%e\t%d\t\n',ebn0,ber,per,nloop);
%fclose(fid);
end
for ii=1:length(ebn01),
    SNR=exp(ebn01(ii)*log(10)/10);
    AWGN_theo(ii)=0.5*erfc(sqrt(SNR));        % AWGN theoretical bit error rate
    Ray_theo(ii)=0.5*(1-1/sqrt(1+1/SNR));     % Rayleigh theoretical bit error rate
   
end
% plot commands
figure(1)
semilogy(ebn0,ber,'ro');
hold on;
semilogy(ebn0,per,'r*');
hold on;
semilogy(ebn0,ber1,'o');
hold on;
semilogy(ebn0,per1,'*');
hold on;
semilogy(ebn01,AWGN_theo);
semilogy(ebn01,Ray_theo,'r');
xlabel('Eb/No');ylabel('BER');
legend('QPSK 1 path Rayleigh ber','QPSK 1 path Rayleigh per','QPSK AWGN ber','QPSK AWGN per','AWGN theory','1 path Rayleigh theory','Location','SouthWest');
figure(2)
ebn0=10;
figure(2)
subplot(2,2,1),plot(ifade),title('After Ray-chn I-channel signal');
subplot(2,2,2),psd(ifade),title('After Ray-chn I-channel signal power spectrum');
subplot(2,2,3),plot(qfade),title('After Ray-chn Q-channel signal');
subplot(2,2,4),psd(qfade),title('After Ray-chn Q-channel signal power spectrum');
%******************** end of file ***************************

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -