Savitzky-Golay Smoothing and Differentiation Filter Copyright (c) 2011, Diederick 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 details in Matlab Documents (help sgolay). The sgolay function in Matlab can deal with only 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, 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. Lastly, this function is faster than MATLAB's sgolay. Usage: [fc,df] = savitzkyGolay(x,n,dn,x0,flag) input: x = the original data point, e.g., -5:5 n = polynomial order dn = differentation order (0=smoothing), default=0 x0 = estimation point, can be a vector default=0 W = weight vector, can be empty must have same length as x0 default=identity flag = numerical(0) or symbolical(1), default=0 output: fc = filter coefficients obtained (B output of sgolay). df = differentiation filters (G output of sgolay). 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: Diederick C. Niehorster 2011-02-05 Department of Psychology, The University of Hong Kong