7
$\begingroup$

Have been using various packages SavitskyGolay.m for Savitsky-Golay polynomial smoothing but just noticed the built-in matrix kernel. I am looking for an example for smoothing of uniformly sampled temporal data using the built-in kernel.

Take the following as a simple example

data = (Sin[#] + 0.3 RandomReal[]) & /@ Range[ 0, 2 π, .01];
data // ListPlot
$\endgroup$
2

1 Answer 1

12
$\begingroup$

SavitzkyGolayMatrix produces a smoothing kernel that can be convolved with the data using ListConvolve.

Using your example and a kernel for a quadratic interpolation over the radius of 5:

data = (Sin[#] + 0.3 RandomReal[]) & /@ Range[0, 2 π, .01];

ListPlot@data
ListPlot@ListConvolve[SavitzkyGolayMatrix[{5}, 2], data]

quadratically-smoothed data

An example in 2D:

M = Table[Exp[-x^2 - y^2] + 
RandomVariate[NormalDistribution[0, 0.1]], {x, -2, 2, 0.1}, {y, -2, 2, 0.1}];

ListContourPlot[M, InterpolationOrder -> 0]
ListContourPlot[ListConvolve[SavitzkyGolayMatrix[5, 2], M], InterpolationOrder -> 0]

quadratically-smoothed 2D data

Please consider reading the detail section of ListConvolve for some common convolution settings.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.