%QPSK调制解调仿真
%Author:张宗卫
%date:2018.3.10
clc
clear all
fc=30;
fs=1000;
% fcu=200;
t=1/fs:1/fs:0.8;
L=length(t);
%四元符号产生
code4=zeros(1,L);
for i=1:L/8
code4(i)=0;
end
for i=L/8+1:L/8*2
code4(i)=3;
end
for i=L/8*2+1:L/8*3
code4(i)=1;
end
for i=L/8*3+1:L/8*4
code4(i)=2;
end
for i=L/8*4+1:L/8*5
code4(i)=1;
end
for i=L/8*5+1:L/8*6
code4(i)=0;
end
for i=L/8*6+1:L/8*7
code4(i)=2;
end
for i=L/8*7+1:L
code4(i)=3;
end
figure(1)
plot(t,code4)
title('4进制码元')
%串并转换 比特对
bIn=zeros(1,L);
bQn=zeros(1,L);
for i=1:L
switch code4(i)
case 0
bIn(i)=0;
bQn(i)=0;
case 1
bIn(i)=0;
bQn(i)=1;
case 2
bIn(i)=1;
bQn(i)=1;
case 3
bIn(i)=1;
bQn(i)=0;
end
end
figure(2)
subplot(211),plot(t,bIn),title('正交支路bIn')
subplot(212),plot(t,bQn),title('同相支路bQn')
%比特对双极性形成
aIn=zeros(1,L);
aQn=zeros(1,L);
for i=1:L
if bIn(i)==0
aIn(i)=-1;
else
aIn(i)=1;
end
if bQn(i)==0
aQn(i)=-1;
else
aQn(i)=1;
end
end
figure(3)
subplot(211),plot(t,aIn),title('双极性正交支路aIn')
subplot(212),plot(t,aQn),title('双极性同相支路aQn')
%QPSK信号调制
ISC=cos(2*pi*fc*t);
QSC=sin(2*pi*fc*t);
QPSK=aIn.*ISC+aQn.*QSC;
figure(4)
subplot(311),plot(t,ISC),title('正交支路2PSK')
subplot(312),plot(t,QSC),title('同相支路2PSK')
subplot(313),plot(t,QPSK),title('QPSK信号')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%QPSK解调
ILo=cos(2*pi*fc*t);
QLo=sin(2*pi*fc*t);
%step1 混频
RecQt=QPSK.*QLo;
RecIt=QPSK.*ILo;
figure(5)
subplot(211)
plot(t,RecQt),title('接收同相支路混频')
subplot(212)
plot(t,RecIt),title('接收正交支路混频')
%step2 过LPF
b=[0.00226675464588304,0.00136504505246622,0.00175878104612964,0.00221153432901494,0.00272748466037607,0.00330780022766749,0.00395363565442280,0.00466597851131189,0.00544450028376728,0.00628773584107796,0.00719347499703571,0.00815843398510817,0.00917825631157910,0.0102478237985242,0.0113612748511266,0.0125115706154483,0.0136904482156869,0.0148889062085348,0.0160976629650599,0.0173071380635749,0.0185071499666179,0.0196867585367558,0.0208345741081722,0.0219395410846265,0.0229913842469065,0.0239801230256774,0.0248953112618121,0.0257266964838253,0.0264657446472916,0.0271057988938512,0.0276400460627811,0.0280609918741315,0.0283640711472088,0.0285498939514168,0.0286089914329785,0.0285498939514168,0.0283640711472088,0.0280609918741315,0.0276400460627811,0.0271057988938512,0.0264657446472916,0.0257266964838253,0.0248953112618121,0.0239801230256774,0.0229913842469065,0.0219395410846265,0.0208345741081722,0.0196867585367558,0.0185071499666179,0.0173071380635749,0.0160976629650599,0.0148889062085348,0.0136904482156869,0.0125115706154483,0.0113612748511266,0.0102478237985242,0.00917825631157910,0.00815843398510817,0.00719347499703571,0.00628773584107796,0.00544450028376728,0.00466597851131189,0.00395363565442280,0.00330780022766749,0.00272748466037607,0.00221153432901494,0.00175878104612964,0.00136504505246622,0.00226675464588304];
a=1;
RecQtPassLPF=filter(b,a,RecQt);
RecItPassLPF=filter(b,a,RecIt);
RecQtPassLPF=round(2*RecQtPassLPF);
RecItPassLPF=round(2*RecItPassLPF);
figure(6)
subplot(211)
plot(t,RecQtPassLPF);title('接收同相支路混频过LPF')
subplot(212)
plot(t,RecItPassLPF);title('正交同相支路混频过LPF')
%step3 采样判决
RecbIn=zeros(1,L);
RecbQn=zeros(1,L);
for i=1:L
if RecQtPassLPF(i) ==1
RecbQn(i)=1;
else
RecbQn(i)=0;
end
if RecItPassLPF(i) ==1
RecbIn(i)=1;
else
RecbIn(i)=0;
end
end
%step4 串转并
RecCode4=zeros(1,L);
for i=1:L
if RecbIn(i)==0 && RecbQn(i)==0
RecCode4(i)=0;
elseif RecbIn(i)==0 && RecbQn(i)==1
RecCode4(i)=1;
elseif RecbIn(i)==1 && RecbQn(i)==1
RecCode4(i)=2;
else
RecCode4(i)=3;
end
end
figure(7)
subplot(211)
plot(t,RecCode4);title('解调后的4元符号序列')
subplot(212)
plot(t,code4);title('调制前的4元符号序列')