📄 lms2.m
字号:
% RLS Adaptive Noise cancellation
%-----Filter Parameters-----;
M = 20;
delta = 1; %%%---------------diffenrence
lamda = 0.99; %%%---------------diffenrence
mu = 0.05;
e_max = 400; %-----maximum of epochs
%-----Contants-----
pi = 3.14;
Fs = 0.01; %-----signal frequency
Fn = 0.05; %-----noise frequency
%-----Initialize-----
w = zeros(M,1); %%%---------------diffenrence
d = zeros(M,1); %%%---------------diffenrence
u = zeros(M,1); %%%---------------diffenrence
P = eye(M)/delta; %%%---------------diffenrence
%-----Generate desired signal and input(signal+noise)-----
for t=1:M-1
d(t) = sin(2*pi*Fs*t);
u(t) = d(t) + 0.5*sin(2*pi*Fn*t) + 0.09*randn;
end
t = M;
epoch = 0;
while epoch<e_max %-----generate new input
input = sin(2*pi*Fs*t);
for i=2:M %-----shift new input into array
d(M-i+2) = d(M-i+1);
u(M-i+2) = u(M-i+1);
end
d(1) = input;
u(1) = input +0.5*sin(2*pi*Fn*t)+0.09*randn; %-----add undesired freq & random noise
output = w'*u; %-----compute filter output
%-----RLS algorithm-----
k = (P*u)/(lamda + u'*P*u); %-----compute error-----
E = d(1) - w'*u;
w = w + k*E;
P = (P/lamda) - (k*u'*P/lamda);
int(t-M+1) = u(1);
out(t-M+1) = output;
err(t-M+1) = E;
t = t+1;
epoch = epoch + 1;
%-----plot noise and filtered signal-----
figure(2);
subplot(211),plot(t,u(1)),axis([0 e_max -2.5 2.5]),title('RLS Filter Input(Siganal + Noise)'),drawnow,hold on
subplot(212),plot(t,output),axis([0 e_max -2.5 2.5]),title('RLS Filtered Signal'),drawnow,hold on
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -