📄 qpsk.m
字号:
%********************相关参数设置***************************************
ml=2;%调制电平(BPSK:ml=1, QPSK:ml=2, 16QAM:ml=4)
nd =10; % 传输的符号数
fc=5; %载波频率
qifs=199;%每个正弦波形对应的采样数为qifs+1/2
fs=qifs+1
%*******************信源与调制************************************
data1=rand(1,nd*ml)>0.5
[ich,qch]=qpskmod(data1,nd,ml)
imo = mycos(fc,qifs);
qmo = mysin(fc,qifs);
k=1;
for jj=1:nd%符号数等于nd
for jjj=1:qifs+1
iout(1,k)=ich(1,jj)*sqrt(0.5)*imo(1,jjj);
qout(1,k)=qch(1,jj)*sqrt(0.5)*qmo(1,jjj);
out(1,k)=iout(1,k)+qout(1,k);
if (jjj<=(qifs+1)/2&&jjj>=1)
indata(1,k)=ich(1,jj);
elseif (jjj>(qifs+1)/2&&jjj<=qifs+1)
indata(1,k)=qch(1,jj);
end
k=k+1;
end
end
%********************通过瑞利衰落信道************************************
%[iray,qray]=ray(1,nd*(qifs+1));%产生幅值和相位都变化的瑞利衰落信道
%iout1=iray.*iout-qray.*qout;
%qout1=qray.*iout+iray.*qout;
[mag]=ray(1,nd*(qifs+1));%产生幅值变化的瑞利衰落信道
iout1=iout.*mag;
qout1=qout.*mag;
%********************加高斯白噪声****************************************
y=wgn(1,nd*(qifs+1),0);
iout2=iout1+y;
qout2=qout1+y;
out3=iout2+qout2;
%********************接收端进行解调***************************************
k=1
for jj=1:nd%符号数等于nd
for jjj=1:qifs+1
iout3(1,k)=iout2(1,k)*imo(1,jjj);
qout3(1,k)=qout2(1,k)*qmo(1,jjj);
k=k+1;
end
end
%********************解调后的信号通过低通滤波器***************************************
%
[b,s]=butter(4,2/((qifs+1)/2)); % lowpass Butt.
iout4=filter(b,s,iout3);
qout4=filter(b,s,qout3);
%
%********************通过判决器进行判决***************************************
%
%*****************************抽样判决****************************************
k=0;
for jj=1:nd
ioutx(1,jj)= iout4(1,k+1*(qifs+1)/2);
qoutx(1,jj)=qout4(1,k+1*(qifs+1)/2);
if iout4(1,k+1*(qifs+1)/2)>0
iout5(1,jj)=1;
else
iout5(1,jj)=-1;
end
if qout4(1,k+1*(qifs+1)/2)>0
qout5(1,jj)=1;
else
qout5(1,jj)=-1;
end
k=k+qifs+1;
end
%*********************并/串转换及信号恢复**************************************
count1=0;
for jj=1:nd %nd为符号数
out1(1,1+count1)=iout5(1,jj);
out1(1,2+count1)=qout5(1,jj);
count1=count1+2;
end
k=0;
for jj=1:2*nd
if out1(1,jj)==1
out2(1,k+1:k+(qifs+1)/2)=ones(1,(qifs+1)/2);
else
out2(1,k+1:k+(qifs+1)/2)=-ones(1,(qifs+1)/2);
end
k=k+(qifs+1)/2;
end
%********************绘制相关图形***************************************
x=1:nd*(qifs+1);
x2=1:2*nd*(qifs+1)
yy=0;
%figure(1)
%psd(indata,[],fs,[]);
%title('input baseband power spectrum')
%figure(2)
%psd(out,[],fs,[]);
%title('QPSK modulated signal power spectrum')
%figure(3)
%psd(out3,[],fs,[]);
%title('AWGN channel output power spectrum')
%figure(4)
%plot(x,indata,'r');
%title('input baseband waveform');
%xlabel('t');
%figure(5)
%plot(x,out,'r',x,yy,'r');
%title('QPSK module waveform ');
%xlabel('t');
%figure(6)
%plot(x,out3,'r',x,yy,'r');
%title('AWGN output waveform ');
%xlabel('t');
figure(7)
subplot(3,1,1)
plot(x,indata,'r');
ylabel('input baseband waveform');
xlabel('t');
subplot(3,1,2);
plot(x,out,'r',x,yy,'r');
ylabel('QPSK module waveform ');
xlabel('t');
subplot(3,1,3);
plot(x,out3,'r',x,yy,'r');
ylabel('AWGN output waveform ');
xlabel('t');
figure(8);
plot(ich,qch,'*r');
axis([-1.5,1.5,-1.5,1.5]);
title('input baseband constellations ');
figure(9);
plot(iout4,qout4,'*r');
title('Ray channel constellations');
%axis([-4,4,-4,4]);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -