LSM 自适应信号处理代码
博客专区 > MtrS 的博客 > 博客详情
LSM 自适应信号处理代码
MtrS 发表于11个月前
LSM 自适应信号处理代码
  • 发表于 11个月前
  • 阅读 6
  • 收藏 0
  • 点赞 0
  • 评论 0

【腾讯云】买域名送云解析+SSL证书+建站!>>>   

function [yhat, c, e] = lms(x, y, mu, M, c_0)
% function [yhat, c, e] = lms(x, y, mu, M, c_0) % FIR Adaptive Filter using LMS Algorithm, % reference to "Statistical and Adaptive Signal Processing" % by Dimitris G. Manolakis, Vinay K. Ingle, and Stephen M. Kogon. McGraw-Hill Higher Education. % x = input sequence % y = desired sequence % mu = step-size % M = filter order % c_0 = initialization of coefficient vector % yhat = filtered sequence % c = FIR filter coefficient vector % e = error signal % P = squared error
if nargin ~= 5    error('The input parameters error!')    return end if M <= 0    error('The input filter order must be a postive integer!')    return end if sum(size(x)>1)>1 || sum(size(y)>1)>1 || sum(size(c_0)>1)>1    error('Input data dimension error!')    return end if length(c_0) ~= M    error('initial filter order mismatch!')    return end
x = squeeze(x); y = squeeze(y); Nx = length(x); x = reshape(x,Nx,1); Ny = length(y); y = reshape(y,Ny,1); c_0 = reshape(c_0,M,1);
if Ny > Nx    y = y(1:Nx); elseif Ny < Nx    y = [y;zeros(Nx-Ny,1)]; end
yhat = zeros(Nx,1); c = zeros(M,Nx); P = zeros(Nx,1); e = zeros(Nx,1); xm = zeros(M,1);
c(:,1) = c_0; for n = 1:Nx    if n < M         xm(1:n) = flipud(x(1:n));    else          xm = flipud(x(n+1-M:n));    end    yhat(n) = xm'*c(:,n);    e(n) = y(n)-yhat(n); %     P(n) = (abs(e(n)))^2;    c(:,n+1) = c(:,n)+2*mu*xm*e(n); end
return;
  • 打赏
  • 点赞
  • 收藏
  • 分享
共有 人打赏支持
粉丝 29
博文 475
码字总数 352174
×
MtrS
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: