📄 syn_m2.m
字号:
%syn_m2.m
%高斯与1径瑞利衰落信道下正确符号定时的概率
% (under one path fading)
%********************** preparation part ***************************
clear;
para=2048; % Number of parallel channel to transmit (points)
fftlen=2048; % FFT length
noc=2048; % Number of carrier
nd=5; % Number of information OFDM symbol for one loop
ml=4; % Modulation level : 16QAM
sr=250000; % Symbol rate
br=sr.*ml; % Bit rate per carrier
gilen=64; % Length of guard interval (points)
ebn0=0:4:20; % Eb/N0
%******************* Fading initialization ********************
% If you use fading function "sefade", you can initialize all of parameters.
% Otherwise you can comment out the following initialization.
% 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.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
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 **************************
for j=1:length(ebn0)
nloop=100; % Number of simulation loops
noee=0; % Number of error data
noe = 0; % Number of error data
nod = 0; % Number of transmitted data
nodd=0; % Number of transmitted data
z(j)=ebn0(j)/(ebn0(j)+1)/2; % corelated factor of ML algorithm
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);
%***************received signal**********************
r=ich4+qch4*i;
rr=ich44+qch44*i;
%**************** ML estimation*******************************
for ii=1:noc; % FFT窗口移动的距离
data1=r(ii:gilen+ii-1); % 取gilen长个数据存data1
data2=r(noc+ii:noc+gilen+ii-1); % 取相距noc的gilen长个数据存data2
data11=rr(ii:gilen+ii-1);
data22=rr(noc+ii:noc+gilen+ii-1);
s=data1*data2'; % 求互相关值
ss=data11*data22';
cor(ii)=abs(s); % abs: built in function
corr(ii)=abs(ss);
%************** 求能量项 **********************
data3=abs(data1).^2;
data4=abs(data2).^2;
data33=abs(data11).^2;
data44=abs(data22).^2;
data5=(data3+data4)*z(j);
data6=sum(data5);
con(ii)=data6;
data55=(data33+data44)*z(j);
data66=sum(data55);
conn(ii)=data66;
%************ ML时间变量估计 ********************
data7(ii)=cor(ii)-con(ii);
data77(ii)=corr(ii)-conn(ii);
end
a=max(data7); % 求最大值
jest(iii)=find(data7==a); % 求最大值所在位置
aa=max(data77);
jestt(iii)=find(data77==aa);
end
%******************* 粗符号正确定时的概率 *****************
A=ones(1,nloop); % 产生nloop个全1数组
noe1=sum((jest-A)==0); % 正确定时符号个数
nod1=nloop; % 定时符号总个数
noee1=sum((jestt-A)==0);
nodd1=nloop;
noe=noe+noe1;
nod=nod+nod1;
noee=noee+noee1;
nodd=nodd+nodd1;
ser(j)=noe/nod; %正确定时符号率
serr(j)=noee/nodd;
end
%******************plot *********
figure(1)
plot(ebn0,serr,'ro-');
hold on;
plot(ebn0,ser,'r*-');
hold on;
xlabel('信噪比/dB');ylabel('正确符号定时的概率');
legend('AWGN信道正确符号定时概率','Rayleigh信道正确符号定时概率');
%**********end of file******************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -