?? ofdm.m
字號:
%ofdm system simulation preference <<simulation and software radio for
%mobile communication
%********************** start of file *************************************
para=128; %Number of pararrel channel
fftlen=128; %FFT length
noc=128; %Number of carrier
nd=6; %Number of 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 internal
ebn0=100; %ebn0=Eb/N0
%4 us Symbol time(tstp=1./sr) and a 1/4 tstp guard interval
nloop=100; %Number of simulation loops
noe=0; %Number of error data
nod=0; %Number of transmitted data
eop=0; %Number of error packet
nop=0; %Number of transmitted packet
for iii=1:nloop
%************************ transmitter *************************************
%********************* Data generation ************************************
seridata=rand(1,para*nd*ml)>0.5; %generating random serial data
paradata=reshape(seridata,para,nd*ml); %converting seridata into paradata
[ich,qch]=qpskmod(paradata,para,nd,ml);%The parallel data were converted into modulated parallel data of two channels,Ich and Qch.
%Nomalize the data
kmod=1/sqrt(2);
ich1=ich.*kmod;
qch1=qch.*kmod;
%IFFT transform
x=ich1+qch1*i;
y=ifft(x);
ich2=real(y);
qch2=imag(y);
%Guard intervals were inserted to eliminate ISI caused by multipath fading
[ich3,qch3]=giins(ich2,qch2,fftlen,gilen,nd);
fftlen2=fftlen+gilen;
%Contaminating the transmitted data with AWGN
spow=sum(ich3.^qch3)./nd./para;
attn=0.5*spow*sr/br*10.^(-ebn0/10);
attn=sqrt(attn);
[ich4,qch4]=comb(ich3,qch3,attn);
%The guard interval was removed from received signals ich4 and qch4
[ich5,qch5]=girem(ich4,qch4,fftlen2,gilen,nd);
%FFT transform
rx=ich5+qch5.*i;
ry=fft(rx);
ich6=real(ry);
qch6=imag(ry);
%Unnormalizing the data and feeding into the demodulation function
ich7=ich6./kmod;
qch7=qch6./kmod;
[demodata]=qpskdemod(ich7,qch7,para,nd,ml);
demodata1=reshape(demodata,1,para*nd*ml);
%instantaneous number of errors and data bits
noe2=sum(abs(seridata-demodata1));
nod2=length(seridata);
%cumulative number of errors and data bits 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
%obtain the BER and PER by using the following operation
ber=noe/nod;
per=eop/nop;
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 + -