clear clc
%e=0;
fs=10000;
%det=1/fs;
%f1=100;
%f2=200;
%t=0:det:2-det;
%x=randn(size(t))+cos(2*pi*f1*t)+cos(2*pi*f2*t);
x=xlsread('456.xlsx','A1:A10000');
%未知系统
[b,a]=butter(5,150*2/fs);
d=filter(b,a,x);
%自适应FIR 滤波器
N=5;
delta=0.06;
M=length(x);
y=zeros(1,M);
h=zeros(1,N);
for n=N:M
x1=x(n:-1:n-N+1);
y(n)=h*x1';
e(n)=d(n)-y(n);
h=h+delta.*e(n).*x1;
end
X=abs(fft(x,2048));
Nx=length(x); kx=0:1:(Nx/2-1)*(1);
D=abs(fft(d,2048)); Nd=length(D);
kd=0:10000/Nd:(Nd/2-1)*(10000/Nd); Y=abs(fft(y,2048));
Ny=length(Y); ky=0:10000/Ny:(Ny/2-1)*(10000/Ny);
figure(1); subplot(3,1,1)
plot(kx,X(1:Nx/2));
xlabel('Hz')
title('原始信号频谱')
subplot(3,1,2)
plot(kd,D(1:Nd/2))
title('经未知系统后信号频谱');
xlabel('Hz')
subplot(3,1,3)
plot(ky,Y(1:Ny/2))
title('经自适应FIR 滤波器后信号频谱');
xlabel('Hz')
figure(2)
plot(x)
figure(3)
plot(y)
%e=0;
fs=10000;
%det=1/fs;
%f1=100;
%f2=200;
%t=0:det:2-det;
%x=randn(size(t))+cos(2*pi*f1*t)+cos(2*pi*f2*t);
x=xlsread('456.xlsx','A1:A10000');
%未知系统
[b,a]=butter(5,150*2/fs);
d=filter(b,a,x);
%自适应FIR 滤波器
N=5;
delta=0.06;
M=length(x);
y=zeros(1,M);
h=zeros(1,N);
for n=N:M
x1=x(n:-1:n-N+1);
y(n)=h*x1';
e(n)=d(n)-y(n);
h=h+delta.*e(n).*x1;
end
X=abs(fft(x,2048));
Nx=length(x); kx=0:1:(Nx/2-1)*(1);
D=abs(fft(d,2048)); Nd=length(D);
kd=0:10000/Nd:(Nd/2-1)*(10000/Nd); Y=abs(fft(y,2048));
Ny=length(Y); ky=0:10000/Ny:(Ny/2-1)*(10000/Ny);
figure(1); subplot(3,1,1)
plot(kx,X(1:Nx/2));
xlabel('Hz')
title('原始信号频谱')
subplot(3,1,2)
plot(kd,D(1:Nd/2))
title('经未知系统后信号频谱');
xlabel('Hz')
subplot(3,1,3)
plot(ky,Y(1:Ny/2))
title('经自适应FIR 滤波器后信号频谱');
xlabel('Hz')
figure(2)
plot(x)
figure(3)
plot(y)