clear;
%输入信号
subplot(4,1,1);
t =0:0.001:8;
d=[0 0 ;0.5 1;1 1;1.5 0;2 1;2.5 1;3 0;3.5 0;4 0;4.5 1 ;5 1 ;5.5 0 ;6 1 ;6.5 1 ;7 0 ;7.5 0];
s=pulstran(t-0.25,d,'rectpuls',0.5);plot(t,s) ;
axis([0 8 -0.5 1.5]);
text(0.25,1.2,'0') ;
text(0.75,1.2,'1') ; text(1.25,1.2,'1') ; text(1.75,1.2,'0') ;
text(2.25,1.2,'1') ;
text(2.75,1.2,'1') ; text(3.25,1.2,'0') ; text(3.75,1.2,'0') ;
text(4.25,1.2,'0') ;
text(4.75,1.2,'1') ; text(5.25,1.2,'1') ; text(5.75,1.2,'0') ;
text(6.25,1.2,'1') ;
text(6.75,1.2,'1') ; text(7.25,1.2,'0') ; text(7.75,1.2,'0') ;
% I路信号
subplot(4,1,2);
t=0:0.001:8;
a=1/sqrt(2);
d=[0 -a ;1 +a;2 -a;3 +a; 4 -a;5 +a;6 -a;7 +a];
s=pulstran(t-0.5,d,'rectpuls');plot(t,s) ;
axis([0 8 -2 2]);
text(0.5,1.5,'-0.7') ;
text(1.5,1.5,'+0.7') ;text(2.5,1.5,'-0.7') ;text(3.5,1.5,'+0.7');
text(4.5,1.5,'-0.7') ;
text(5.5,1.5,'+0.7') ;text(6.5,1.5,'-0.7') ;text(7.5,1.5,'+0.7');
% Q路信号
subplot(4,1,3);
t=0:0.001:8;
d=[0 +a;1 -a;2 -a;3 +a; 4 +a;5 -a;6 -a;7 +a];
s=pulstran(t-0.5,d,'rectpuls');
plot(t,s) ;
axis([0 8 -2 2]);
text(0.5,1.5,'+0.7') ;
text(1.5,1.5,'-0.7') ; text(2.5,1.5,'-0.7') ; text(3.5,1.5,'+0.7')
text(4.5,1.5,'+0.7') ;
text(5.5,1.5,'-0.7') ; text(6.5,1.5,'-0.7') ; text(7.5,1.5,'+0.7')
%QPSK调制信号
subplot(4,1,4);
t=0:0.001:8;
d1=[0 -a ;1 +a;2 -a;3 +a; 4 -a;5 +a;6 -a;7 +a];
s1=pulstran(t-0.5,d1,'rectpuls').*cos(2*pi*5*t) ;
d2=[0 +a;1 -a;2 -a;3 +a; 4 +a; 5 -a;6 -a;7 +a];
s2=pulstran(t-0.5,d2,'rectpuls').*sin(2*pi*5*t);
s = s1-s2;
plot(t,s) ;
axis([0 8 -2 2]);
text(0.3,1.5,'3\pi/4') ;
text(1.3,1.5, '7\pi/4') ; text(2.3,1.5,'5\pi/4') ; text(3.3,1.5,'\pi/4') ;
text(4.3,1.5, '3\pi/4') ; text(5.3,1.5, '7\pi/4') ;
text(6.3,1.5,'5\pi/4') ; text(7.3,1.5,'\pi/4') ;
%显示QPSK调制信号和加入噪声之后的信号
figure(2);
subplot(221);
plot(t,s) ;
axis([0 8 -2 2]);
title('QPSK输出信号');
%将已调制信号加入高斯白噪声
%noisegen(X,SNR)函数可以将信号设置为任意信噪比
%Y1、Y2、Y3分别为0、5、10dB信噪比的接收信号
%设置SNR为0的已调制QPSK信号Y1
[Y1,NOISE] = noisegen(s,0);
subplot(222);
t=0:0.001:8;
plot(t,Y1);
axis([0 8 -2 2]);
title('SNR为0的已调制QPSK信号Y1');
%设置SNR为5的已调制QPSK信号Y2
[Y2,NOISE] = noisegen(s,5);
figure(2);
subplot(223);
t=0:0.001:8;
plot(t,Y2);
axis([0 8 -2 2]);
title('SNR为5的已调制QPSK信号Y2');
%设置SNR为10的已调制QPSK信号Y3
[Y3,NOISE] = noisegen(s,10);
figure(2);
subplot(224);
t=0:0.001:8;
plot(t,Y3);
axis([0 8 -2 2]);
title('SNR为10的已调制QPSK信号Y3');
%下面是对不同信噪比信号进行的LMS滤波
%主要分为几个步骤:
% 1、求LMS滤波需要用到的参数
% 2、将各个不同信噪比信号和矩阵的各个参数代入LMSfilter函数
% 3、将每一个信噪比信号及其滤波之后的进行画图比对
%计算三个输入信号相关矩阵最大特征值的倒数
rho_max1 = max(eig(Y1*Y1.')); %输入信号Y1相关矩阵的最大特征值
mu_1 = rand()*(1/rho_max1); %收敛因子0<mu<1/rho
rho_max2 = max(eig(Y2*Y2.')); %输入信号Y1相关矩阵的最大特征值
mu_2 = rand()*(1/rho_max2); %收敛因子0<mu<1/rho
rho_max3 = max(eig(Y3*Y3.')); %输入信号Y1相关矩阵的最大特征值
mu_3 = rand()*(1/rho_max3); %收敛因子0<mu<1/rho
%进行LMS自适应滤波
[y1,W1,en1]= LMSfilter(Y1.',s,20,mu_1)
[y2,W2,en2]= LMSfilter(Y2.',s,20,mu_2)
[y3,W3,en3]= LMSfilter(Y3.',s,20,mu_3)
%画出QPSK信号、0dB信噪比信号、LMS自适应滤波信号
figure(3);
subplot(311);
plot(t,s);
axis([0 8 -2 2]);
title('已调制信号QPSK');
subplot(312);
plot(t,Y1);
axis([0 8 -2 2]);
title('0dB的SNR信号');
subplot(313);
plot(t,y1);
axis([0 8 -2 2]);
title('LMS自适应滤波信号');
%画出QPSK信号、5dB信噪比信号、LMS自适应滤波信号
figure(4);
subplot(311);
plot(t,s);
axis([0 8 -2 2]);
title('已调制信号QPSK');
subplot(312);
plot(t,Y2);
axis([0 8 -2 2]);
title('5dB的SNR信号');
subplot(313);
plot(t,y2);
axis([0 8 -2 2]);
title('LMS自适应滤波信号');
%画出QPSK信号、10dB信噪比信号、LMS自适应滤波信号
figure(5);
subplot(311);
plot(t,s);
axis([0 8 -2 2]);
title('已调制信号QPSK');
subplot(312);
plot(t,Y3);
axis([0 8 -2 2]);
title('10dB的SNR信号');
subplot(313);
plot(t,y3);
axis([0 8 -2 2]);
title('LMS自适应滤波信号');
%下面进行的是RLS自适应滤波