LSM 自适应信号处理代码

LSM 自适应信号处理代码
MtrS 发表于9个月前
LSM 自适应信号处理代码
• 发表于 9个月前
• 阅读 3
• 收藏 0
• 评论 0
``````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;
``````

×