7

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
J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574

1 Answers1

12

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.

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
paw
  • 5,650
  • 23
  • 31