画出QPSK信号产生的信息、I路、Q路信号对比图以及接收端解调的I路,Q 路,信息恢复的对比图。
clear all;
clc;
N=20;
T=1;
fc=2
Fs=100;
bitstream=randi([0,1],1,N);
bitstream=2*bitstream-1;
I=[];Q=[];
for i=1:N
if mod(i,2)~=0
I=[I,bitstream(i)];
else
Q=[Q,bitstream(i)];
end
end
bit_data=[];
for i=1:N
bit_data=[bit_data,bitstream(i)*ones(1,T*Fs)];
end
I_data=[];
Q_data=[];
for i=1:N/2
I_data=[I_data,I(i)*ones(1,T*Fs*2)];
Q_data=[Q_data,Q(i)*ones(1,T*Fs*2)];
end
figure();
t=0:1/Fs:N*T-1/Fs;
subplot(3,1,1)
plot(t,bit_data);legend('Bitstream')
subplot(3,1,2)
plot(t,I_data);legend('Bitstream')
subplot(3,1,3)
plot(t,Q_data);legend('Bitstream')
bit_t=0:1/Fs:2*T-1/Fs;
I_carrier=[];
Q_carrier=[];
for i=1:N/2
I_carrier=[I_carrier,I(i)*cos(2*pi*fc*bit_t)];
Q_carrier=[Q_carrier,Q(i)*cos(2*pi*fc*bit_t)+pi/2];
end
QPSK_signal=I_carrier+Q_carrier;
figure();
subplot(3,1,1)
plot(t,I_carrier);legend('I signal')
subplot(3,1,2)
plot(t,Q_carrier);legend('Q signal')
subplot(3,1,3)
plot(t,QPSK_signal);legend('QPSK signal')
snr=1;
QPSK_receive=awgn(QPSK_signal,snr);
for i=1:N/2
I_output=QPSK_receive(1,(i-1)*length(bit_t)+1:i*length(bit_t)).*cos(2*pi*fc*bit_t);
if sum(I_output)>0;
I_recover(i)=1;
else
I_recover(i)=-1;
end
Q_output=QPSK_receive(1,(i-1)*length(bit_t)+1:i*length(bit_t)).*cos(2*pi*fc*bit_t+pi/2);
if sum(Q_output)>0;
Q_recover(i)=1;
else
Q_recover(i)=-1;
end
end
bit_recover=[];
for i=1:N
if mod(i,2)~=0
bit_recover=[bit_recover,I_recover((i-1)/2+1)];
else
bit_recover=[bit_recover,Q_recover(i/2)];
end
end
recover_data=[];
for i=1:N
recover_data=[recover_data,bit_recover(i)*ones(1,T*Fs)];
end
I_recover_data=[];Q_recover_data=[];
for i=1:N/2
I_recover_data=[I_recover_data,I_recover(i)*ones(1,T*Fs*2)];
Q_recover_data=[Q_recover_data,Q_recover(i)*ones(1,T*Fs*2)];
end
figure();
t=0:1/Fs:N*T-1/Fs;
subplot(3,1,2)
plot(t,I_recover_data);legend('I Bitstream')
subplot(3,1,3)
plot(t,Q_recover_data);legend('Q Bitstream')
subplot(3,1,1)
plot(t,recover_data);legend('Bitstream')
由上图所示,最后解调出来的信号图像,按照理论应该与原信号相同,但由于实际原因,可能混杂着其他的噪声信号,所以导致解调之后的图像并不能完全与原信号的图像一致。