?? test_data.m
字號(hào):
%ofdm2.m
%16QAM調(diào)制、AWGN信道下仿真程序
%**********************初始參數(shù)***************************
clear
para=52;%并行信道數(shù)
fftlen=64;%FFT長度
noc=52;%載波數(shù)
nd=3;%每循環(huán)中OFDM符號(hào)數(shù)
ml=4;%調(diào)制水平:16QAM
gilen=16;%保護(hù)間隔長度(points)
sr=250000;%OFDM symbol rate(250 ksyombol/s)
br=sr.*ml;%Bit rate per carrier
%**************************主循環(huán)部分*************************
nloop=10;%仿真的循環(huán)數(shù)
noe1=0;%信道解碼前錯(cuò)誤數(shù)據(jù)數(shù)
nod1=0;%信道解碼前傳輸數(shù)據(jù)數(shù)
noe2=0;%信道解碼后錯(cuò)誤數(shù)據(jù)數(shù)
nod2=0;%信道解碼后傳輸數(shù)據(jù)數(shù)
%**************************發(fā)射機(jī)*****************************
for ebn0=0:50;%信噪比
for iii=1:nloop
%**************************數(shù)據(jù)產(chǎn)生***************************
%信源編碼
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);
%******************串并轉(zhuǎn)換***********************
paradata=reshape(channelencode,para,nd*ml);%reshape:內(nèi)建功能
%**************************16QAM調(diào)制*************************
[ich,qch]=qammod2(paradata,para,nd,ml);
%數(shù)據(jù)映射
[ich1,qch1]=crmapping(ich,qch,fftlen,nd);
%*******************IFFT************************
x=ich1+qch1.*i;
y=ifft(x);%ifft:內(nèi)建功能
ich2=real(y);%real:內(nèi)建功能
qch2=imag(y);%imag:內(nèi)建功能
%*********插入保護(hù)間隔**********
[ich3,qch3]=giins1(ich2,qch2,fftlen,gilen,nd);
fftlen2=fftlen+gilen;
%----------Attenuation Calculation----------
spow=sum(ich3.^2+qch3.^2)/nd./para;%sum:內(nèi)建功能
attn=0.5*spow*sr/br*10.^(-ebn0/10);
attn=sqrt(attn);
%---------------AWGN addition---------------
[ich4,qch4]=comb(ich3,qch3,attn);
%******************去除保護(hù)間隔*********
[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);
%*****************解調(diào)*******************
[demodata]=qamdemod2(ich7,qch7,para,nd,ml);
%**************并串轉(zhuǎn)換*****************
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;
%**********************輸出結(jié)果***************************
err(ebn0+1,1)=ebn0;
err(ebn0+1,2)=ber2;
end
semilogy(err(:,1),err(:,2),'o-');
hold on
%ofdm22.m
%16QAM調(diào)制、單徑瑞利信道下仿真程序
%**********************初始參數(shù)***************************
para=52;%并行信道數(shù)
fftlen=64;%FFT長度
noc=52;%載波數(shù)
nd=3;%每循環(huán)中OFDM符號(hào)數(shù)
ml=4;%調(diào)制水平:QAM
gilen=16;%保護(hù)間隔長度(points)
sr=250000;%OFDM symbol rate(250 ksyombol/s)
br=sr.*ml;%Bit rate per carrier
%%%%%%%%%%%%%衰落初始值%%%%%%%%%%%
tstp=1/sr/(fftlen+gilen);%判決時(shí)間
itau=[0];%由tstp歸一化的到達(dá)時(shí)間
dlvl1=[0];%由直接波歸一化的每徑能量.
n0=[6];%產(chǎn)生衰落的波數(shù)
itnd1=[1000];%衰落計(jì)數(shù)器
now1=1;%路徑數(shù)
fd=150;%最大多普勒頻率
flat=1;%衰落模式
itnd0=nd*(fftlen+gilen)*10;%每次更新的間隔
%**************************主循環(huán)部分**************************
nloop=20;%仿真的循環(huán)數(shù)
noe1=0;%信道解碼前錯(cuò)誤數(shù)據(jù)數(shù)
nod1=0;%信道解碼前傳輸數(shù)據(jù)數(shù)
noe2=0;%信道解碼后錯(cuò)誤數(shù)據(jù)數(shù)
nod2=0;%信道解碼后傳輸數(shù)據(jù)數(shù)
for ebn0=0:50;%信噪比
%**************************發(fā)射機(jī)*********************************
for iii=1:nloop
%**************************數(shù)據(jù)產(chǎn)生****************************
%信源編碼
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);
%******************串并轉(zhuǎn)換***********************
paradata=reshape(channelencode,para,nd*ml);%reshape:內(nèi)建功能
%**************************16QAM調(diào)制*****************************
[ich,qch]=qammod2(paradata,para,nd,ml);
%數(shù)據(jù)映射
[ich1,qch1]=crmapping(ich,qch,fftlen,nd);
%*******************IFFT************************
x=ich1+qch1.*i;
y=ifft(x);%ifft:內(nèi)建功能
ich2=real(y);%real:內(nèi)建功能
qch2=imag(y);%imag:內(nèi)建功能
%*********插入保護(hù)間隔**********
[ich3,qch3]=giins1(ich2,qch2,fftlen,gilen,nd);
fftlen2=fftlen+gilen;
%----------Attenuation Calculation----------
spow=sum(ich3.^2+qch3.^2)/nd./para;%sum:內(nèi)建功能
attn=0.5*spow*sr/br*10.^(-ebn0/10);
attn=sqrt(attn);
%**********************瑞利衰落信道******************************
%仿真瑞利衰落信道時(shí),去除"%"
[ifade,qfade]=sefade(ich3,qch3,itau,dlvl1,n0,itnd1,now1,length(ich3),tstp,fd,flat);
itnd1=itnd1+itnd0;%更新fading counter
ich3=ifade;
qch3=qfade;
%---------------AWGN addition---------------
[ich4,qch4]=comb(ich3,qch3,attn);
%******************去除保護(hù)間隔*********
[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);
%*****************解調(diào)*******************
[demodata]=qamdemod2(ich7,qch7,para,nd,ml);
%**************并串轉(zhuǎn)換*****************
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;
%**********************輸出結(jié)果***************************
err1(ebn0+1,1)=ebn0;
err1(ebn0+1,2)=ber2;
end
semilogy(err1(:,1),err1(:,2),'+-');
hold on
% fprintf('%f\t%e\t%e\t%d\t\n',ebn0,ber1,ber2,nloop);
%************************end of file***********************************
%ofdm55.m
%16QAM調(diào)制,兩徑瑞利信道(延遲時(shí)間未超過保護(hù)間隔)下仿真程序
%**********************初始參數(shù)***************************
para=52;%并行信道數(shù)
fftlen=64;%FFT長度
noc=52;%載波數(shù)
nd=3;%每循環(huán)中OFDM符號(hào)數(shù)
ml=4;%調(diào)制水平:QAM
gilen=16;%保護(hù)間隔長度(points)
sr=250000;%OFDM symbol rate(250 ksyombol/s)
br=sr.*ml;%Bit rate per carrier
%%%%%%%%%%%%%衰落初始值%%%%%%%%%%%
tstp=1/sr/(fftlen+gilen);%判決時(shí)間
itau=[0 8];%由tstp歸一化的到達(dá)時(shí)間
dlvl1=[0 10];%由直接波歸一化的每徑能量.
n0=[6 7];%產(chǎn)生衰落的波數(shù)
itnd1=[1000 2000];%衰落計(jì)數(shù)器
now1=2;%路徑數(shù)
fd=150;%最大多普勒頻率
flat=1;%衰落模式(1->平衰落,0->幅度相位均衰落)
itnd0=nd*(fftlen+gilen)*10;%每次更新的間隔
%**************************主循環(huán)部分**************************
nloop=20;%仿真的循環(huán)數(shù)
noe1=0;%信道解碼前錯(cuò)誤數(shù)據(jù)數(shù)
nod1=0;%信道解碼前傳輸數(shù)據(jù)數(shù)哈爾濱工業(yè)大學(xué)工學(xué)碩士學(xué)位論文
noe2=0;%信道解碼后錯(cuò)誤數(shù)據(jù)數(shù)
nod2=0;%信道解碼后傳輸數(shù)據(jù)數(shù)
%**************************發(fā)射機(jī)*********************************
for ebn0=0:50;%信噪比
for iii=1:nloop
%**************************數(shù)據(jù)產(chǎn)生****************************
%信源編碼
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);
%******************串并轉(zhuǎn)換***********************
paradata=reshape(channelencode,para,nd*ml);%reshape:內(nèi)建功能
%**************************16QAM調(diào)制*****************************
[ich,qch]=qammod2(paradata,para,nd,ml);
%數(shù)據(jù)映射
[ich1,qch1]=crmapping(ich,qch,fftlen,nd);
%*******************IFFT************************
x=ich1+qch1.*i;
y=ifft(x);%ifft:內(nèi)建功能
ich2=real(y);%real:內(nèi)建功能
qch2=imag(y);%imag:內(nèi)建功能
%*********插入保護(hù)間隔**********
[ich3,qch3]=giins1(ich2,qch2,fftlen,gilen,nd);
fftlen2=fftlen+gilen;
%----------Attenuation Calculation----------
spow=sum(ich3.^2+qch3.^2)/nd./para;%sum:內(nèi)建功能
attn=0.5*spow*sr/br*10.^(-ebn0/10);
attn=sqrt(attn);
%**********************瑞利衰落信道****************************
%仿真瑞利衰落信道時(shí),去除"%"
[ifade,qfade]=sefade(ich3,qch3,itau,dlvl1,n0,itnd1,now1,length(ich3),tstp,fd,flat)
itnd1=itnd1+itnd0;%更新fading counter
ich3=ifade;
qch3=qfade;
%---------------AWGN addition---------------
[ich4,qch4]=comb(ich3,qch3,attn);
%******************去除保護(hù)間隔*********
[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);
%*****************解調(diào)*******************
[demodata]=qamdemod2(ich7,qch7,para,nd,ml);
%**************并串轉(zhuǎn)換*****************
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;
%**********************輸出結(jié)果***************************
err2(ebn0+1,1)=ebn0;
err2(ebn0+1,2)=ber2;
end
semilogy(err2(:,1),err2(:,2),'*-');
legend('AWGN信道','單徑','二徑');
% fprintf('%f\t%e\t%e\t%d\t\n',ebn0,ber1,ber2,nloop);
%************************end of file***********************************
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -