?? mine16.m
字號:
clear
global dt df N t f T
QAM=16
MASK=sqrt(QAM);
Ntotal=2^16; %總采樣點數
N=Ntotal/2 ; %每支路采樣點數
L=16; %每碼元的采樣點數
M=N/L; %每支路碼元數
Rb=2; %碼速率是2Mb/s
Tb=1/Rb; %碼元間隔
Ts=2/Rb; %每一支路碼元間隔
dt=Ts/L; %每一支路時域采樣間隔
df=1/(N*dt); %每一支路頻域采樣間隔
T=N*dt; %每一支路截短時間
Bs=N*df/2; %每一支路系統帶寬
Na=4; %示波器掃描寬度為4個碼元
Again=20;
alpha=1; %alpha變化參數,可方便修改
t=[-T/2+dt/2:dt:T/2]; %每一支路時域橫坐標
f=[-Bs+df/2:df:Bs]; %每一支路頻域橫坐標
ttotal=[-T/2+dt/2:dt/2:T/2];
%-----------------------------------------------設置載波
fc=5*Rb; %載波頻率
carry1=sqrt(2)*cos(2*pi*fc*t);
carry2=-sqrt(2)*sin(2*pi*fc*t);
%-----------------------------------------------升余弦
hr1=sin(pi*t/Ts)./(pi*t/Ts);
hr2=cos(alpha*pi*t/Ts)./(1-(2*alpha*t/Ts).^2);
hr=hr1.*hr2;
HR=abs(t2f(hr));
%取模是為了忽略時延
GT=sqrt(HR);
GR=GT;
%------------------------------------------------對10個信噪比
for loop1=1:10
Eb_N0(loop1)=loop1-1;
eb_n0(loop1)=10^(Eb_N0(loop1)/10);
Eb=1;
n0=Eb/eb_n0(loop1); %信道的噪聲譜密度
sita=n0*Bs; %信道中噪聲功率
%------------------------------------------------產生模擬信號
for loop2=1:5
for i=1:M
temp=rand;
desource1(i)=1+floor(MASK*temp);
temp=rand;
desource2(i)=1+floor(MASK*temp);
end
d=1;
analog=[-3*d,-d,d,3*d];
for i=1:M
AOut1(i)=analog(:,desource1(i)); %第一路模擬信號
AOut2(i)=analog(:,desource2(i)); %第二路模擬信號
end
%------------------------------------------------對信號進行抽樣
imp1=zeros(1,N);
imp2=zeros(1,N);
imp1(L/2:L:N)=AOut1/dt; %生沖激序列1
imp2(L/2:L:N)=AOut2/dt; %生沖激序列2
IMP1=t2f(imp1);
IMP2=t2f(imp2);
%------------------------------------------------經過發送濾波器合并為一路信號進行信道傳輸
message1=real(f2t(GR.*IMP1));
message2=real(f2t(GR.*IMP2));
message=[message1,message2];
sendM1=message1.*carry1;
sendM2=message2.*carry2;
sendM=sendM1+sendM2;
%------------得到接收端輸出噪聲,不同支路的噪聲信號獨立隨機產生,但是他們的分布和方差是一致的
noise1=sqrt(sita)*randn(1,N); %產生的隨機噪聲
noise2=sqrt(sita)*randn(1,N);
noiseOut1=real(f2t(t2f(noise1).*GR)); %經過接收濾波器后的隨機噪聲
noiseOut2=real(f2t(t2f(noise2).*GR));
%------------------------------------------------接收并解調
receiveM1=sendM1+noise1; %接受噪聲干擾后的信號
receiveM2=sendM2+noise2;
RECEIVEM1=t2f(receiveM1);
RECEIVEM2=t2f(receiveM2);
GETMessage1=t2f(receiveM1.*carry1).*GT; %解調
GETMessage2=t2f(receiveM2.*carry2).*GT;
getMessage1=real(f2t(GETMessage1));
getMessage2=real(f2t(GETMessage2));
getMessage=[getMessage1,getMessage2];
%y=receiveM; %得到接收端輸信號
%------------------------------------------------判決
numoferr=0;%誤比特的初始置0
for i=1:M
for j=1:MASK
metrics1(j)=abs(getMessage1(-L/2+i*L)-analog(j));
metrics2(j)=abs(getMessage2(-L/2+i*L)-analog(j));
end
[min_metric1 decis1(i)]=min(metrics1);
[min_metric2 decis2(i)]=min(metrics2);
if(decis1(i)~=desource1(i)),%出錯誤比特+1
numoferr=numoferr+1;
end
if(decis2(i)~=desource2(i)),
numoferr=numoferr+1;
end
end
end
Pe(loop1)=numoferr/(M*loop2);
%------------------------------------------------畫星座圖
if(loop1==7) %只觀察 某一分貝下星座圖
figure(1)
plot(getMessage1(L/2:L:N),getMessage2(L/2:L:N),'o')
grid on
hold on
title('16QAM星座圖');
for i=1:M
if(decis1(i)~=desource1(i)|decis2(i)~=desource2(i)),
plot(getMessage1(-L/2+L*i),getMessage2(-L/2+L*i),'rx');
plot([getMessage1(-L/2+L*i), AOut1(i)],[getMessage2(-L/2+L*i), AOut2(i)],'--r');
end
end
legend('正確判定點','錯誤判定點');
end
%------------------------------------------------模擬發送基帶信號
SumP=0;
if (loop1==10)
SENDM1=t2f(sendM1);
SumP=SumP+SENDM1.*conj(SENDM1)/T;
figure(2);
set(2,'Position',[100,50,600,600])
%設定窗口位置及大小
subplot(6,1,1);
plot(ttotal/Tb,message);
axis([-50,50,-5,5]);
legend('總發基帶信號');
subplot(6,1,2);
plot(ttotal/Tb,getMessage,'g');
axis([-50,50,-5,5]);
legend('總收基帶信號');
subplot(6,1,3);
plot(t/Tb,message1,'b');
axis([-50,50,-5,5]);
legend('第1路發送基帶信號');
subplot(6,1,4)
plot(t/Tb,getMessage1,'g');
axis([-50,50,-5,5]);
legend('第1路接收基帶信號');
subplot(6,1,5);
plot(t/Tb,message2,'b');
axis([-50,50,-5,5]);
legend('第2路發送基帶信號');
subplot(6,1,6);
plot(t/Tb,getMessage2,'g');
axis([-50,50,-5,5]);
legend('第2路接收基帶信號');
%------------------------------------------------模擬發送調制信號
figure(3)
subplot(4,1,1);
plot(t/Tb,sendM1);
title('第1、2路發送\接收調制信號','fontsize',10);
axis([-20,20,-5,5]);
hold on
%畫包絡
plot(t/Tb,message1*sqrt(2),'--g','linewidth',2);
plot(t/Tb,-message1*sqrt(2),'--g','linewidth',2);
legend('第一路發送調制信號','第一路發送基帶信號');
subplot(4,1,2);
plot(t/Tb,receiveM1);
axis([-20,20,-5,5]);
hold on
%畫包絡
plot(t/Tb,getMessage1*sqrt(2),'--g','linewidth',2);
plot(t/Tb,-getMessage1*sqrt(2),'--g','linewidth',3);
legend('第一路接收調制信號','第一路接收基帶信號');
subplot(4,1,3);
plot(t/Tb,sendM2);
axis([-20,20,-5,5]);
hold on
%畫包絡
plot(t/Tb,message2*sqrt(2),'--g','linewidth',2);
plot(t/Tb,-message2*sqrt(2),'--g','linewidth',2);
legend('第二路發送調制信號','第二路發送基帶信號');
subplot(4,1,4);
plot(t/Tb,receiveM2);
axis([-20,20,-5,5]);
hold on
%畫包絡
plot(t/Tb,getMessage2*sqrt(2),'--g','linewidth',2);
plot(t/Tb,-getMessage2*sqrt(2),'--g','linewidth',2);
legend('第二路接收調制信號','第二路接收基帶信號');
%------------------------------------------------眼圖
figure(4)
tt=[0:dt:Na*L*dt];
for ss=1:Na*L:N-Na*L
plot(tt,getMessage1(ss:ss+Na*L));
hold on
end
end
end
figure(5)
semilogy(Eb_N0,Pe);
hold on
semilogy(Eb_N0,(MASK-1)/MASK*0.5*erfc(sqrt(10.^(Eb_N0/10))),'g')
axis([0,9,1e-4,1])
title('16QAM誤碼率','fontsize',10);
xlabel('Eb/N0','fontsize',10);
ylabel('Pe','fontsize',10);
legend('16QAM實際誤碼率','16QAM理論誤碼率');
%------------------------------------------------功率普圖
P=SumP/Again;
figure(6)
plot(f/Rb,30+10*log10(P));
title('16QAM功率普','fontsize',10);
xlabel('f/Rb','fontsize',10);
ylabel('P(f)','fontsize',10);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -