4.42857

4.4 | 14 ratings Rate this file 59 Downloads (last 30 days) File Size: 2.67 KB File ID: #4038

Savitzky-Golay Smoothing and Differentiation Filter

by Jianwen Luo

 

05 Oct 2003 (Updated 06 Dec 2005)

Savitzky-Golay smoothing and differentiation filter.

| Watch this File

File Information
Description

Function:
        Savitzky-Golay Smoothing and Differentiation Filter
        The Savitzky-Golay smoothing/differentiation filter (i.e., the polynomial smoothing/differentiation filter,
        or the least-squares smoothing/differentiation filters) optimally fit a set of data points to polynomials
        of different degrees.
        See for detail in Matlab Documents (help sgolay). The sgolay function in Matlab can deal with only
        symmetrical and uniformly spaced data of even number.
        This function presented here is a general implement of the sgolay function in Matlab. The Savitzky-Golay filter
        coefficients for even number, nonsymmetrical and nonuniformly spaced data can be obtained. And the filter coefficients
        for the initial point or the end point can be obtained too.In addition, either numerical results or symbolical
        results can be obtained.
 Usage:
        fc = sgsdf(x,n,dn,x0,flag)
        x = the original data point, e.g., -5:5
        n = polynomial order, default=1
        dn = differentation order (0=smoothing), default=0
        x0 = estimation point, default=0
        flag = numerical(0) or symbolical(1), default=0
        fc = filter coefficients obtained.
 Notes:
 1. x can be arbitrary, e.g., odd number or even number,symmetrical or nonsymmetrical, uniformly spaced
           or nonuniformly spaced, etc.
 2. x0 can be arbitrary, e.g., the initial point,the end point,etc.
 3. Either numerical results or symbolical results can be obtained.
 Example:
        sgsdf([-3:3],2,0,0,0)
        sgsdf([-3:3],2,0,0,1)
        sgsdf([-3:3],2,0,-3,1)
        sgsdf([-3:3],2,1,2,1)
        sgsdf([-2:3],2,1,1/2,1)
        sgsdf([-5:2:5],2,1,0,1)
        sgsdf([-1:1 2:2:8],2,0,0,1)
 Author:
        Jianwen Luo <luojw@bme.tsinghua.edu.cn, luojw@ieee.org> 2003-10-05
        Department of Biomedical Engineering, Department of Electrical Engineering
        Tsinghua University, Beijing 100084, P. R. China
 Reference
 [1]A. Savitzky and M. J. E. Golay, "Smoothing and Differentiation of Data by Simplified Least Squares Procedures," Analytical Chemistry, vol. 36, pp. 1627-1639, 1964.
 [2]J. Steinier, Y. Termonia, and J. Deltour, "Comments on Smoothing and Differentiation of Data by Simplified Least Square Procedures,"
    Analytical Chemistry, vol. 44, pp. 1906-1909, 1972.
 [3]H. H. Madden, "Comments on Savitzky-Golay Convolution Method for Least-Squares Fit Smoothing and Differentiation of Digital Data," Analytical Chemistry, vol. 50, pp. 1383-1386, 1978.
 [4]R. A. Leach, C. A. Carter, and J. M. Harris, "Least-Squares Polynomial Filters for Initial Point and Slope Estimation," Analytical Chemistry, vol. 56, pp. 2304-2307, 1984.
 [5]P. A. Baedecker, "Comments on Least-Square Polynomial Filters for Initial Point and Slope Estimation," Analytical Chemistry, vol. 57, pp. 1477-1479, 1985.
 [6]P. A. Gorry, "General Least-Squares Smoothing and Differentiation by the Convolution (Savitzky-Golay) Method," Analytical Chemistry, vol. 62, pp. 570-573, 1990.
 See also:
        sglay, sgsdf_2d2

Acknowledgements
This submission has inspired the following:
z-transform of 1D & 2D Savitzky-Golay Smoothing and Differentiation Filter, fSGolayFilt, Savitzky-Golay smooth/differentiation filters and filter application
MATLAB release MATLAB 6.5 (R13)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (22)
10 Oct 2003 YangQuan Chen

Please also check my similar contribution

http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=3514&objectType=FILE

File Name: Savitzky-Golay Smoothing Filter
  Author: YangQuan Chen
  Summary: FIR filter design via local moving window LS fitting - A magic smooth and derivative formula
  Submitted: 2003-05-29
  Downloads: 479
 
  Description: Check more information at

http://www.csois.usu.edu/people/yqchen/dd/index.html
   

File Details
 
  File Id: 3514 Average review: 5.0
  MATLAB Release: R13 # of reviews: 1
  Size: 1 KB Subscribers: 0
  Keywords: Integer-Order Digital Differentiator, FIR,

24 Oct 2003 Grant Murphy

Love your work :-)
It saved me doing this very thing ..
I like that it can be used to generate moving extraploation filters.

27 Oct 2003 Jianwen Luo

errata:

change the last line in this function

fc=sum(h);

to

if size(h,1)>1
    fc=sum(h);
else
    fc=h;
end

for consideration of the case when n=0

01 Nov 2003 Alpay Koc  
30 Jun 2004 Chunsheng Wu

Good!

30 Jul 2004 Jianwen Luo

See also at http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=5556&objectType=FILE

23 Sep 2004 Juha Abolmaesumi

Excellent.

24 Sep 2004 Jianwen Luo

Recently we have got our manuscript on the proprieties of Savitzky-Golay differentiation filters accepted for publication in Digital Signal Processing. The abstract is as below.

The Savitzky-Golay (SG) filters are generally used for smoothing and differentiation in many fields. The properties of the SG smoothing filters have been well studied. However, the properties of the SG differentiation filters or SG digital differentiators (SGDD, for the first order differentiation) are not developed well somehow, although they have been widely used. In the paper, the properties of the SGDD are discussed in detail. The effects of the SGDD on a noise-free single Gaussian line and a doublet are studied via simulation. The results indicate that the contrast and resolution loss of the SGDD depends on the ratio of the width of signal derivative and filter length. The linear SGDD is not preferable for preserving small details of signal derivative from this study. The cubic and quintic SGDD with the choice of optimal filter length are recommended in order to maintain the resolution of signal derivative.

An electrical copy would be sent on request via E-mail. (luojw@bme.tsinghua.edu.cn or luojw@ieee.org). Thank you.

28 Feb 2005 Jianwen Luo

Our work on the Savitzky-Golay differentiation filter has been published, as

Luo J W, Ying K, He P, Bai J. Properties of Savitzky-Golay Digital Differentiators, Digital Signal Processing, 2005, 15(2): 122-136.

The paper is available at:
http://www.cs.wright.edu/~phe/Research/Journal.html

Thank you very much for your interest.

16 Apr 2005 sigit ariatmoko  
21 Jun 2005 DON NGUYEN  
06 Jul 2005 newmouse newmouse  
24 Nov 2005 senuma senuma  
03 Dec 2005 Duane Hanselman

Posting of .exe files is not acceptable since they do not run on all MATLAB supported platforms. In addition, it is easy to hide spyware or a virus in an executable file. What happens when this exe file is run???

10 Jan 2006 Linnea Goodman

very helpful!

12 Dec 2006 aungsoe khaing  
02 Jul 2007 Olivier Planchon

A good job, I will be using it for the unsymetric case. I have a single comment. I suggest changing line 85 from :
h=inv(A'*A)*A';
to :
h=M\eye(n) ;
Note : n is size(A,2)

This comment is worth a line of justification:
line 85 is intended to solve the following equation of unknown h : M*h = I ; (M, rectangular, and I = identity). Mathlab standards commands to use the \ operator instead of the classical inv(A'*A) stuff.

Beyond correctness, the gain is in speed, precision, and robustness.

22 Jan 2008 Hyeong-yong Jeon

Thank you for sharing your codes. It's very good! Got will be blessing you. Good-Luck!

06 May 2008 Bob Marley

This algorithm can be made much more concise.
Using the author's notation:

N = length(x);
x=x(:);
a_matrix = cumprod([ones(N,1) ...
                   x*ones(1,n)],2)\eye(N);
for i = 0:n
const(i+1) = ...
              x0^(i-dn)*prod(i:-1:i-dn+1);
end
fc = sum((const'*ones(1,N)).*a_matrix)';

18 Dec 2008 Pavel Holoborodko

Alternative approach for noise-robust differentiation is described here:
http://www.holoborodko.com/pavel/?page_id=245
On the contrary to Savitzky-Golay filters it has nice property of guaranteed noise suppression.

07 Feb 2010 Roman Balabin  
22 Sep 2011 Khawaja Asim

I am new user of matlab.. I need to use Savitzky-Golay smoothing on image for surface estimation. Can someone give me tips, that are helpful in my work.. Thanks

Please login to add a comment or rating.
Updates
08 Oct 2003

The Reference and a demo have been added.

06 Dec 2005

The .exe file is replaced with a .zip file. Thank Duane for suggestion.

Tag Activity for this File
Tag Applied By Date/Time
filter design Jianwen Luo 22 Oct 2008 07:08:23
filter analysis Jianwen Luo 22 Oct 2008 07:08:23
savitzkygolay Jianwen Luo 22 Oct 2008 07:08:23
smoothing Jianwen Luo 22 Oct 2008 07:08:23
signal processing Jianwen Luo 22 Oct 2008 07:08:23
differentiation Jianwen Luo 22 Oct 2008 07:08:23
sym Josef 25 Aug 2010 08:47:55
savitzkygolay best community 22 Jun 2011 21:10:50
savitzkygolay Omar 29 Sep 2011 06:22:56

Contact us at files@mathworks.com