?? lms_newton.m
字號:
%%%%%%%%% LMS_Newton 算法 《自適應濾波算法與實現》 98頁
clear all;
% the channel impulse response;
Hn =[0.8783 -0.5806 0.6537 -0.3223 0.6577 -0.0582 0.2895 -0.2710 0.1278 -0.1508 0.0238 -0.1814 0.2519 -0.0396 0.0423 -0.0152 0.1664 -0.0245 0.1463 -0.0770 0.1304 -0.0148 0.0054 -0.0381 0.0374 -0.0329 0.0313 -0.0253 0.0552 -0.0369 0.0479 -0.0073 0.0305 -0.0138 0.0152 -0.0012 0.0154 -0.0092 0.0177 -0.0161 0.0070 -0.0042 0.0051 -0.0131 0.0059 -0.0041 0.0077 -0.0034 0.0074 -0.0014 0.0025 -0.0056 0.0028 -0.0005 0.0033 -0.0000 0.0022 -0.0032 0.0012 -0.0020 0.0017 -0.0022 0.0004 -0.0011 0 0 ];
Hn=Hn(1:64);
%讀入語音; it is a column vector;
r=wavread('C:\Matlab\work\Write_In_Paper\Shi_Yan.wav');
r=r(1:10000);
% cut the former 5000 points;
% r=sin(2*pi*(1:3000)/40)';
r=r+0.2*randn(size(r));% r is the input noisy signal vector;
% the output signal vector;
output=conv(r,Hn); N=length(r);
d=output;
k=length(Hn); % k is the order of the fikter;
% the filter coeffients vector;
error=zeros(N,1);
DB_error=error;
delta=0.1; alfa=0.03; mu=0.01;
I=eye(k,k);
inv_R=delta*I;
w=zeros(k,1);
for i=k:N
x=r(i:-1:i-k+1);
e=d(i)-x'*w;
inv_R=1/(1-alfa)*(inv_R-(inv_R*(x*x')*inv_R)/((1-alfa)/alfa+x'*multiply(inv_R,x)));
w=w+2*mu*e*multiply(inv_R,x);
error(i)=error(i)+e^2;
end;
figure;
DB_error=10*log10(error);
plot(DB_error,'r'); %%%% 本圖和下圖都是 LMS_Newton算法,只是參數不同
error=zeros(N,1);
delta=0.01; alfa=0.01; mu=0.009;
I=eye(k,k);
inv_R=delta*I;
w=zeros(k,1);
for i=k:N
x=r(i:-1:i-k+1);
e=d(i)-x'*w;
inv_R=1/(1-alfa)*(inv_R-(inv_R*(x*x')*inv_R)/((1-alfa)/alfa+x'*multiply(inv_R,x)));
w=w+2*mu*e*multiply(inv_R,x);
error(i)=error(i)+e^2;
end;
hold on;
DB_error=10*log10(error);
plot(DB_error,'y');
%%%%%%%%%%%%%% 對比 LMS_Newton算法和基本LMS算法的收斂性
%%%%%% 下圖是基本LMS算法
mu=0.01;
win=zeros(1,k)'; % the filter coeffients vector;
error=zeros(1,N)';
DB_error=error;
for i=k:N
input=r(i:-1:i-k+1); % intercept the input vector;
e=output(i)-win'*input;
win=win+mu*e*input;
error(i)=error(i)+e^2;
end;
hold on;
DB_error=10*log10(error);
plot(DB_error,'b');
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -