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

📄 ofdmsimulation1.m

📁 新一代无线通信核心技术OFDM的matlab仿真源程序!!!!!
💻 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 ***************************

para=128;   % Number of parallel channel to transmit (points)
fftlen=128; % FFT length
noc=128;    % Number of carrier
nd=6;       % Number of information OFDM symbol for one loop
ml=1;       % Modulation level : BPSK
sr=250000;  % Symbol rate
br=sr.*ml;  % Bit rate per carrier
gilen=32;   % Length of guard interval (points)
ebn0=10;    % Eb/N0
IPOINT=8;    % Number of oversamples

%******************* 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 four-path Rayleigh fading are considered.
th1=[0.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 =1;

%************************** main loop part **************************

nloop=500;  % Number of simulation loops
eop=0;      % Number of error packet
nop=0;      % Number of transmitted packet
noe = 0;    % Number of error data
nod = 0;    % Number of transmitted data

for iii=1:nloop

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

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

data=rand(1,para*nd*ml)>0.5;  %  rand : built in function
%****************** Serial to parallel conversion ***********************

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


%************************** BPSK modulation *****************************
   
    data1=paradata.*2-1;


%******************* IFFT ************************

                                   
y=ifft(data1);      %  ifft : built in function

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

data4= bpsk_giins(y,fftlen,gilen,nd);
fftlen2=fftlen+gilen;

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

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

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

  % Generated data are fed into a fading simulator
  % In the case of BPSK, only Ich data are fed into fading counter
  [ifade,qfade]=sefade(data4,zeros(1,length(data4)),itau,dlvl,th1,n0,itnd1,now1,length(data4),tstp,fd,flat);
  
  % Updata fading counter
  itnd1 = itnd1+ itnd0;

%***************************  Receiver  *****************************
%***************** AWGN addition ********* 
 inoise=randn(1,length(ifade)).*attn;  % randn: built in function
	data5=ifade+inoise;


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

data6= bpsk_girem(data5,fftlen2,gilen,nd);

%******************  FFT  ******************


data7=fft(data6);   	% fft : built in function

%***************** demoduration *******************

       demodata=data7 > 0;
 %**************  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-data));  %  sum : built in function
nod2=length(data);  %  length : built in function
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

%********************** Output result ***************************

per=eop/nop;
ber=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 of file ***************************

⌨️ 快捷键说明

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