% filter parameters
tic;
M=16; % number of taps
step=0.0001; % step-size parameteR
e_max=5024; % maximum #of epochs
K=120;
G=170;
Y=500;
D=1000;
% constants
pi=3.14;
% initialize
pp=zeros(1,24);
qq=zeros(1,7);
pr=zeros(1,24);
x=zeros(1,21);
w1=zeros(1,M);
w2=zeros(1,M);
r11=zeros(1,M);
r12=zeros(1,M);
r21=zeros(1,M);
r22=zeros(1,M);
ss1=zeros(1,e_max);
ss2=zeros(1,e_max);
ee1=zeros(1,e_max);
ee2=zeros(1,e_max);
dd=zeros(1,e_max);
hp=[1 0.05 0.1 0.09 0.05 0.5 0.002];
hr=[1 0.5 0.02 0.05];
h11=[1 0.5 0.01 0.9 0.005 0.02];
h22=[1 0.5 0.01 0.9 0.005 0.02];
h12=[1 0.6 0.02 0.8 0.05 0.004];
h21=[1 0.6 0.02 0.8 0.05 0.004];
%计算部分
for t=1:24
pp(t)=sin((K/D)*2*pi*(25-t)+pi/5 )+sin((G/D)*2*pi*(25-t))+sin((Y/D)*2*pi*(25-t));
pr(t)=sin((K/D)*2*pi*(25-t)+pi/5 )+sin((G/D)*2*pi*(25-t))+sin((Y/D)*2*pi*(25-t));
end
t=25;
epoch=0;
while epoch<e_max
input=sin((K/D)*2*pi*t+pi/5 )+sin((G/D)*2*pi*t)+sin((Y/D)*2*pi*t);
for i=2:7
pp(7-i+2)=pp(7-i+1);
end
pp(1)=input;
for i=1:7
qq(i)=pp(i);
end
d=dot(qq,hp);
dd(epoch+1)=d; %期望信号
for i=2:24
pr(24-i+2)=pr(24-i+1);
end
pr(1)=input;
for i=1:21
for j=1:4
x(i)=x(i)+pr(i+j-1)*hr(j);
end
end
for i=1:16
for j=1:6
r11(i)= r11(i)+x(i+j-1)*h11(j);
r22(i)=r22(i)+x(i+j-1)*h22(j);
end
for l=1:6
r12(i)=r12(i)+x(i+l-1)*h12(l);
r21(i)= r21(i)+x(i+l-1)*h21(l);
end
end
s1=dot(r11,w1)+dot(r21,w2);
s2=dot(r12,w1)+dot(r22,w2);
ss1(epoch+1)=s1;
ss2(epoch+1)=s2;
e1=d+s1;
e2=d+s2;
ee1(epoch+1)=e1;
ee2(epoch+1)=e2;
for j=1:16
w1(j)=w1(j)-2*step*(e1*r11(j)+e2*r12(j));
w2(j)=w2(j)-2*step*(e1*r21(j)+e2*r22(j));
end
for i=1:16
r11(i)=0;
r12(i)=0;
r21(i)=0;
r22(i)=0;
end
for i=1:21
x(i)=0;
end
t=t+1;
epoch=epoch+1;
end
toc;
subplot(311)
plot(dd);
axis([0 e_max -2 2]);
title('期望信号');
subplot(312)
plot(ss1);
axis([0 e_max -2 2]);
title('滤波器通路1输出信号');
subplot(313)
plot(ss2);
axis([0 e_max -2 2]);
title('滤波器通路2输出信号');
figure(2)
subplot(211)
plot(ee1);
axis([0 e_max -0.5 0.5]);
title('误差信号1');
grid on;
subplot(212)
plot(ee2);
axis([0 e_max -0.5 0.5]);
title('误差信号2');
grid on;
figure(3)
subplot(211)
plot(dd,'b-');
axis([0 e_max -2 2]);
hold on
plot(ss1,'r-');
axis([0 e_max -2 2]);
hold on
plot(ee1,'g-');
axis([0 e_max -2 2]);
subplot(212)
plot(dd,'b-');
axis([0 e_max -2 2]);
hold on
plot(ss2,'r-');
axis([0 e_max -2 2]);
hold on
plot(ee2,'g-');
axis([0 e_max -2 2]);
- 1
- 2
- 3
前往页