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$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.