📄 ofdm,qpsk,高斯信道.m
字号:
%ofdm1.m
%QPSK调制、AWGN信道下仿真程序
%**********************初始参数***************************
para=52;%并行信道数
fftlen=64;%FFT长度
noc=52;%载波数
nd=6;%每循环中OFDM符号数
ml=2;%调制水平:QPSK
gilen=16;%保护间隔长度(points)
ebn0=2;%信噪比
sr=250000;%OFDM symbol rate(250 ksyombol/s)
br=sr.*ml;%Bit rate per carrier
%**************************主循环部分**************************
nloop=200;%仿真的循环数
noe1=0;%信道解码前错误数据数
nod1=0;%信道解码前传输数据数
noe2=0;%信道解码后错误数据数
nod2=0;%信道解码后传输数据数
%**************************发射机*********************************
for iii=1:nloop
%**************************数据产生****************************
%信源编码
t=[0:pi/25:2*pi];
xx=sin(t);
init=[-1:.1:1];
partition=[-1:.1:.9];
predictor=[0 1];
encode=dpcmenco(xx,init,partition,predictor);
encode2=reshape(encode,51,1);
bin=deci22bin(encode2,6);
recode=reshape(bin,1,306);
%信道编码
k0=1;
G=[1 0 1 1 0 1 1;1 1 1 1 0 0 1];
channelencode=cnv_encd(G,k0,recode);
%******************串并转换***********************
paradata=reshape(channelencode,para,nd*ml);%reshape:内建功能
%**************************QPSK调制*****************************
[ich,qch]=qpskmod1(paradata,para,nd,ml);
kmod=1/sqrt(2);%sqrt:内建功能
ich=ich.*kmod;
qch=qch.*kmod;
%数据映射
[ich1,qch1]=crmapping(ich,qch,fftlen,nd);
%*******************IFFT************************
x=ich1+qch1.*i;
y=ifft(x);%ifft:内建功能
ich2=real(y);%real:内建功能(实部)
qch2=imag(y);%imag:内建功能(虚部)
%*********插入保护间隔**********
[ich3,qch3]=giins1(ich2,qch2,fftlen,gilen,nd);
fftlen2=fftlen+gilen;
%----------Attenuation Calculation----------
spow=sum(ich3.^2+qch3.^2)/nd./para;%sum:内建功能
attn=0.5*spow*sr/br*10.^(-ebn0/10);
attn=sqrt(attn);
%---------------AWGN addition---------------
[ich4,qch4]=comb(ich3,qch3,attn);
%******************去除保护间隔*********
[ich5,qch5]=girem1(ich4,qch4,fftlen2,gilen,nd);
%******************FFT******************
rx=ich5+qch5.*i;
ry=fft(rx);
ich6=real(ry);
qch6=imag(ry);
%载波逆映射
[ich7,qch7]=crdemapping(ich6,qch6,fftlen,nd);
%*****************解调*******************
ich7=ich7./kmod;
qch7=qch7./kmod;
[demodata]=qpskdemod1(ich7,qch7,para,nd,ml);
%**************并串转换*****************
demodata1=reshape(demodata,1,para*nd*ml);
%信道解码
[channeldecode]=viterbi(G,k0,demodata1);
%信源解码
reshapechanneldecode=reshape(channeldecode,51,6);
deci=bin22deci(reshapechanneldecode);
redeci=reshape(deci,1,51);
codebook=[-1:.1:5.3];
decode=dpcmdeco(redeci,codebook,predictor);
%**************************Bit Error Rate(BER)****************************
noe10=sum(abs(demodata1-channelencode));
nod10=length(channelencode);
noe20=sum(abs(channeldecode-recode));
nod20=length(recode);
noe1=noe10+noe1;
nod1=nod10+nod1;
noe2=noe20+noe2;
nod2=nod20+nod2;
fprintf('%d\t%e\t%e\n',iii,noe10/nod10,noe20/nod20);
end
ber1=noe1/nod1;
ber2=noe2/nod2;
%**********************输出结果***************************
fprintf('%f\t%e\t%e\t%d\t\n',ebn0,ber1,ber2,nloop);
%************************end of file***********************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -