## LSM 自适应信号处理代码 原

MtrS

``````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;
``````

### MtrS

2017/06/02
0
0

weixin_36967309
2018/05/12
0
0

2017/06/20
0
0
SP++3.0 发布，欢迎大家使用

2011/02/12
4.9K
4
SP++3.0已发布，欢迎大家使用（同心协力，共创开源）

SP++ (Signal Processing in C++) 是一个关于信号处理与数值计算的开源C++程序库，该库提供了信号处理与数值计算中常用算法的C++实现。SP++中所有算法都以C++类模板方法实现，以头文件形式组...

2011/02/12
0
55

tac 与cat

tac从后往前看文件，结合grep使用

2
0

2
0
SpringBoot上传图片操作

_liucui_

6
0
DrawerLayout

2
0
python精简笔记

python精简笔记-字符串基本用法 字符串常见用法： *　encode() # 编码成bytes类型 *　find() # 查找子串 *　index() # 获取下标 *　replace() # 替换子串 *　len(string) # 返回字符串长度，...

1
0