Savgol萨维基购耳滤波方法-MATLAB


经常用的滑动窗口滤波方法,简洁实用,欢迎拍砖。

SAVGOL function returns the coefficients of a Savitzky-Golay smoothing filter, which can then be applied using the CONVOL function. The Savitzky-Golay smoothing filter, also known as least squares or DISPO (digital smoothing polynomial), can be used to smooth a noisy signal.

The filter is defined as a weighted moving average with weighting given as a polynomial of a certain degree. The returned coefficients, when applied to a signal, perform a polynomial least-squares fit within the filter window. This polynomial is designed to preserve higher moments within the data and reduce the bias introduced by the filter. The filter can use any number of points for this weighted average.

function g = savgol2(f, nl, nr, M)

% SAVGOL SavGol smoothes the data in the vector f by means of a
%        Savitzky-Golay smoothing filter.
%        Input: f : noisy data
%        nl: number of points to the left of the reference point
%        nr: number of points to the right of the reference point
%        M : degree of the least squares polynomial
%        Output: g: smoothed data
%        W. H. Press and S. A. Teukolsky,
%        Savitzky-Golay Smoothing Filters,
%        Computers in Physics, 4 (1990), pp. 669-672.

% matrix A
A = ones (nl+nr+1, M+1);
for j = M:-1:1,
  A (:, j) = [-nl:nr]' .* A (:, j+1);
end

% filter coefficients c
[Q, R] = qr (A);
c = Q (:, M+1) / R (M+1, M+1);

% smoothing of the noisy data
% Note that there are two equivalent ways to apply the Savitzky-Golay
% filter to the vector f.  In the first case we use a for-loop whereas
% in the second case we use the faster built-in function filter.
n = length (f);
g = filter (c (nl+nr+1:-1:1), 1, f);
g (1:nl) = f (1:nl);
g (nl+1:n-nr) = g (nl+nr+1:n);
g (n-nr+1:n) = f (n-nr+1:n);

点击数: 1493   打印  添加到收藏   发布时间: 2016-11-04




上一篇:CRC8校验函数通用版VC
下一篇:清空USB FX2LP FIFO缓冲方法





» 相关内容
  MD5加密的一段代码
  滤波函数增强版
  Matlab模拟PID方法-推荐
  Matlab强制拟合函数过零方法
  清空USB FX2LP FIFO缓冲方法
  Savgol萨维基购耳滤波方法-MAT..
  CRC8校验函数通用版VC
  VS2008中修改VC使用的目标.net..
  Verilog实现clk计数器的rst边..
  Chart1控件坐标轴范围设定和恢..
  一个二维码生成页面-简洁实用
  AD7656六通道16位逐次逼近型25..
  TTL和232/485电平不分导致串口..
  .net程序中给picturebox增加滚..
  Slave FIFO时TD_init函数常用..