声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 3438|回复: 2

[综合讨论] [转帖]RLS,Demonstration of Wiener filter,LMS filter,Steep...

[复制链接]
发表于 2006-5-7 20:43 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
  1. % Demonstration of Wiener filter,LMS filter,Steep-descent algorithm
  2. clear;
  3. clc;

  4. N = 10000; %----- the length of the observation sequence
  5. M = 2; %----- the filter length

  6. v = randn(1,N); %----- white process as the AR excitation
  7. a = poly(sign(randn(1,M)).*rand(1,M)); %----- coefficient of AR process

  8. u = filter(1,a,v); %-----the input sequence

  9. d = v; %----- the desired response

  10. rf = xcorr(u,M,'biased');
  11. rv = rf(M+1:2*M+1);

  12. R = toeplitz(rv); %----- the correlation matrix of the input

  13. pf = xcorr(d,u,M,'biased');

  14. pv = pf(M+1:2*M+1).'; %----- the cross-correlation vector between the input and the desired response

  15. %----- the optimal tap weight vector for Wiener filter-----
  16. wopt = inv(R) * pv;
  17. [V,D] = eig(R); %-----selection of a stable step size mu
  18. lambda_max = max(diag(D));
  19. mu = 0.9 * 2/lambda_max;

  20. %----- the steepest descent learning-----
  21. wsd = randn(M+1,1); %-----initial weight vector for steepest descent
  22. total_iteration_number = 100; %-----total iteration number

  23. for i=1:total_iteration_number
  24. wsd = wsd + mu * (pv - R*wsd);
  25. end

  26. %----- the LMS learning-----
  27. wlms = randn(M+1,1); %-----initial weight vector for LMS
  28. uv = zeros(M+1,1); %-----initial input vector

  29. mu = 0.1*2/lambda_max %-----step size mu for LMS

  30. for n=1:N;
  31. uv(2:M+1) = uv(1:M);
  32. uv(1) = u(n);

  33. y = wlms' * uv;
  34. e = d(n) - y;
  35. wlms = wlms + mu * uv * conj(e);
  36. end;
复制代码

回复
分享到:

使用道具 举报

 楼主| 发表于 2006-5-7 20:48 | 显示全部楼层
  1. % RLS Adaptive Noise cancellation

  2. %-----Filter Parameters-----;
  3. M = 20;
  4. delta = 1; %%%---------------diffenrence
  5. lamda = 0.99; %%%---------------diffenrence
  6. mu = 0.05;
  7. e_max = 400; %-----maximum of epochs

  8. %-----Contants-----
  9. pi = 3.14;
  10. Fs = 0.01; %-----signal frequency
  11. Fn = 0.05; %-----noise frequency

  12. %-----Initialize-----
  13. w = zeros(M,1); %%%---------------diffenrence
  14. d = zeros(M,1); %%%---------------diffenrence
  15. u = zeros(M,1); %%%---------------diffenrence
  16. P = eye(M)/delta; %%%---------------diffenrence

  17. %-----Generate desired signal and input(signal+noise)-----
  18. for t=1:M-1
  19. d(t) = sin(2*pi*Fs*t);
  20. u(t) = d(t) + 0.5*sin(2*pi*Fn*t) + 0.09*randn;
  21. end
  22. t = M;
  23. epoch = 0;

  24. while epoch<e_max %-----generate new input
  25. input = sin(2*pi*Fs*t);
  26. for i=2:M %-----shift new input into array
  27. d(M-i+2) = d(M-i+1);
  28. u(M-i+2) = u(M-i+1);
  29. end
  30. d(1) = input;
  31. u(1) = input +0.5*sin(2*pi*Fn*t)+0.09*randn; %-----add undesired freq & random noise


  32. output = w'*u; %-----compute filter output


  33. %-----RLS algorithm-----
  34. k = (P*u)/(lamda + u'*P*u); %-----compute error-----

  35. E = d(1) - w'*u;
  36. w = w + k*E;

  37. P = (P/lamda) - (k*u'*P/lamda);

  38. int(t-M+1) = u(1);
  39. out(t-M+1) = output;
  40. err(t-M+1) = E;

  41. t = t+1;
  42. epoch = epoch + 1;

  43. %-----plot noise and filtered signal-----
  44. figure(2);
  45. subplot(211),plot(t,u(1)),axis([0 e_max -2.5 2.5]),title('RLS Filter Input(Siganal + Noise)'),drawnow,hold on
  46. subplot(212),plot(t,output),axis([0 e_max -2.5 2.5]),title('RLS Filtered Signal'),drawnow,hold on
  47. end
复制代码
发表于 2008-5-15 10:04 | 显示全部楼层
学习下,谢谢:@) :victory:
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-11-18 05:34 , Processed in 0.085750 second(s), 17 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表