Description |
Contains savitzkyGolay.m and savitzkyGolayFilt.m:
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 details 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. 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).
.
.
savitzkyGolayFilt(X,N,DN,F) filters the signal X using a Savitzky-Golay
(polynomial) filter. The polynomial order, N, must be less than the
frame size, F, and F must be odd. DN specifies the differentiation
order (DN=0 is smoothing). For a DN higher than zero, you'll have to
scale the output by 1/T^DN to acquire the DNth smoothed derivative of
input X, where T is the sampling interval. The length of the input X
must be >= F. If X is a matrix, the filtering is done on the columns
of X.
Note that if the polynomial order N equals F-1, no smoothing
will occur.
savitzkyGolayFilt(X,N,DN,F,W) specifies a weighting vector W with
length F containing real, positive valued weights employed during the
least-squares minimization. If not specified, or if specified as
empty, W defaults to an identity matrix.
savitzkyGolayFilt(X,N,DN,F,[],DIM) or savitzkyGolayFilt(X,N,DN,F,W,DIM)
operates along the dimension DIM. |