📄 qpsk_ofdm_ce.asv
字号:
% Program 4-8
% ofdmce.m
%
% Simulation program to realize OFDM transmission system
%
% Programmed by T.Yamamura and H.Harada
%
% GI CE GI data GI data...(data 6symbols)
% (CE: Chanel estimation symbol, GI Guard interval)
%
%********************** preparation part ***************************
%para=52; % Number of parallel channel to transmit (points)
para=128;
%fftlen=64; % FFT length
fftlen=128; % FFT length
%noc=53; % Number of carriers
nd=6; % Number of information OFDM symbol for one loop
knd=1; % Number of known channel estimation (CE) OFDM symbol
ml=4; % Modulation level : 16qam
sr=250000; % OFDM symbol rate (250 ksyombol/s)
br=sr.*ml; % Bit rate per carrier
%gilen=16; % Length of guard interval (points)
gilen=32; % Length of guard interval (points)
%ebn0=3; % Eb/N0
ebn0=5:5:50;
for m=1:10
%%%%%%%%%%%%% fading initialization %%%%%%%%%%%
%tstp=1/sr/(fftlen+gilen); % Time resolution
tstp=1/sr/(fftlen+gilen); % Time resolution
%itau=[0]; % Arrival time for each multipath normalized by tstp
itau=[0,1,2,3]; % Arrival time for each multipath normalized by tstp
%dlvl1=[0]; % Mean power for each multipath normalized by direct wave.
dlvl1=[0,2,10,20]; % Mean power for each multipath normalized by direct wave.
%n0=[6]; % Number of waves to generate fading n0(1),n0(2)
n0=[6,7,6,7]; % Number of waves to generate fading n0(1),n0(2)
%th1=[0.0]; % Initial Phase of delayed wave
th1=[0.0,0.0,0.0,0.0]; % Initial Phase of delayed wave
%itnd1=[1000]; % set fading counter
%itnd1=[1000,2000]; % set fading counter
itnd1=[1000,2000,3000,4000]; % set fading counter
itnd21=[1000,2000,3000,4000];
itnd22=[100000,102000,10300,10400];
%now1=1; % Number of directwave + Number of delayed wave
now1=4; % Number of directwave + Number of delayed wave
fd=150; % Maximum Doppler frequency
flat=0; % Flat or not (see ofdm_fading.m)
%itnd0=nd*(fftlen+gilen)*20; % Number of fading counter to skip
itnd0=nd*(fftlen+gilen)*20; % Number of fading counter to skip
%************************** main loop part **************************
nloop=325; % Number of simulation loops
noe = 0; % Number of error data
noe0 = 0; % Number of error data
nod = 0; % Number of transmitted data
eop=0; % Number of error packet
nop=0; % Number of transmitted packet
%************************** transmitter *****************************
for iii=1:nloop
seridata=rand(1,para*nd*ml)>0.5; % DC=0
%paradata=reshape(seridata,para,nd*ml); %size(51 * nd*ml)
%-------------- ml modulation ----------------
[ich,qch]=qammod(seridata,1,para*nd,ml);
ch0=ich+sqrt(-1).*qch;
ch1=ch0;
%-------------------stbc--------------------
[st_out1,st_out2]=st2tr(ch1,para);
ch11=reshape(st_out1,para,nd);
ch12=reshape(st_out2,para,nd);
ch10=reshape(ch1,para,nd);
%------------------- IFFT -------------------
ch20=ifft(ch10);
ch21=ifft(ch11);
ch22=ifft(ch12);
%---------- Gurad interval insertion ---------
ch30= giins(ch20,fftlen,gilen,nd);
ch31= giins(ch21,fftlen,gilen,nd);
ch32= giins(ch22,fftlen,gilen,nd);
fftlen2=fftlen+gilen;
ch31=(1/sqrt(2)).*ch31;
ch32=(1/sqrt(2)).*ch32;
ich30=real(ch30);
qch30=imag(ch30);
% ich41=real(ch41);
% qch41=imag(ch41);
% ich42=real(ch42);
% qch42=imag(ch42);
%---------- Attenuation Calculation ----------
spow=sum(ich30.^2+qch30.^2)/nd./para;
attn=0.5*spow*sr/br*10.^(-ebn0(m)/10);
attn=sqrt(attn);
%********************** fading channel ******************************
[ch40]=sefade(ch30,itau,dlvl1,th1,n0,itnd1,now1,length(ch30),tstp,fd,flat);
[ch41]=sefade(ch31,itau,dlvl1,th1,n0,itnd21,now1,length(ch31),tstp,fd,flat);
[ch42]=sefade(ch32,itau,dlvl1,th1,n0,itnd22,now1,length(ch32),tstp,fd,flat);
itnd1 = itnd1+itnd0; % Updata fading counter
itnd21 = itnd21+itnd0;
itnd22 = itnd22+itnd0;
h0=calcha(ch20,ch40,para,fftlen2,gilen,nd);
h21=calcha(ch21,ch41,para,fftlen2,gilen,nd);
h22=calcha(ch22,ch42,para,fftlen2,gilen,nd);
%*************************** Receiver *****************************
%--------------- AWGN addition ---------------
%
ch5=comb1(ch42,ch41,attn);
ch50=comb1(ch40,0,attn);
% ch5=comb1(ch42,ch41,0);
% ch50=comb1(ch40,0,0);
%----Perfect fading compensation for one path fading ----
%If you would like to simulate performance under perfect compensation, please remove "*"
%from the following four sentenses
%ifade2=1./ramp.*(rcos(1,:).*ich5+rsin(1,:).*qch5);
%qfade2=1./ramp.*(-rsin(1,:).*ich5+rcos(1,:).*qch5);
%ich5=ifade2;
%qch5=qfade2;
%----------- Guard interval removal ----------
ch60= girem(ch50,fftlen2,gilen,nd);
ch6= girem(ch5,fftlen2,gilen,nd);
% ch6=reshape(ch5,para,(nd+1));
% ch60=reshape(ch50,para,(nd+1));
% ch61=reshape(ch51,para,(nd+1));
% ch62=reshape(ch52,para,(nd+1));
%------------------ FFT --------------------
ch70=fft(ch60);
ch7=fft(ch6);
ch7=reshape(ch7,1,para*nd);
ch70=reshape(ch70,1,para*nd);
ch70=ch70./h0;
%----------------signal combine-------------
%h1=1;
%h2=1; %理想信道
s=signalcombine21(ch7,h21,h22,fftlen,nd);%signalcombine2t1r:
%2发射天线一接收天线的信号合并
%---------------空时解码--------------------
for n=1:para*nd %de_st(n) 是空时解码的输出
de_st(n)=de_st_out(s(n),h21(n),h22(n)); %这里的de_st_out是对16qam的空时解码
end
ch8=de_st;
ich8=real(ch8);
qch8=imag(ch8);
ch80=ch70;
ich80=real(ch80);
qch80=imag(ch80);
%----------------- demoduration --------------
[demodata0]=qamdemod(ich80,qch80,1,para*nd,ml);
[demodata]=qamdemod(ich8,qch8,1,para*nd,ml);
%-------------- error calculation ----------
demodata0=reshape(demodata0,1,para*nd*ml);
demodata=reshape(demodata,1,para*nd*ml);
noe2=sum(abs(demodata-seridata)); % 2-发射天线
noe1=sum(abs(demodata0-seridata)); % 1-发射天线
nod2=length(seridata);
% calculating BER
noe=noe+noe2;
noe0=noe0+noe1;
nod=nod+nod2;
%fprintf('%d\t%e\t%d\n',iii,noe2/nod2,eop);
end
m
ber(m)=noe/nod
ber0(m)=noe0/nod;
%ber_stand(m)=(3/8)*(1-1/sqrt(1+5/10^(0.1*ebn0(m)/2)))
ber_stand(m)=(3/8)*(1-1/sqrt(1+5/(2*10^(0.1*ebn0(m)))));
%********************** Output result ***************************
%fprintf('%f\t%e\t%e\t%d\t%d\n',ebn0,ber,per,nloop,fd);
%fid = fopen('BERofdmce.dat','a');
%fprintf(fid,'%f\t%e\t%e\t%d\t\n',ebn0,ber,per,nloop);
%fclose(fid);
%******************** end of file ***************************
end
semilogy(ebn0,ber,'s-r',ebn0,ber0,'*-b',ebn0,ber_stand,'g');
xlabel('SNR (dB)');
ylabel('BER');
legend('2Tx-1Rx OFDM','1Tx-1Rx OFDM','theory');
title('Performance over COST 207 4 path channel u')
grid;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -