SavitzkyGolay Manual

An Example Notebook

Arnd Roth
Abteilung Zellphysiologie
Max-Planck-Institut fuer Medizinische Forschung
Postfach 10 38 20, D-69028 Heidelberg, Germany
roth@sunny.mpimf-heidelberg.mpg.de

This loads the package.

<<Statistics`SavitzkyGolay`

?SavitzkyGolay

?SavitzkyGolayCoefficients

We use rational arithmetic in order to avoid numerical difficulties associated with inverting a badly conditioned matrix.

SavitzkyGolayCoefficients[4, 4, 2]

?SavitzkyGolayFilter

Of course, N[] should be applied to the coefficient list before it is used for filtering data. This is shown in the following example.

Example

Suppose this represents a function we want to measure:

epsp[t_] := If[t > 50.,
               -65. -E^(-(t - 50.) / 10.) +
                    E^(-(t - 50.) / 100.),
               -65.]

epspPlot =
Plot[epsp[t], {t, 0, 300}, PlotRange -> {-66, -63}]

Add some Gaussian noise to simulate the process of measurement.

<<Statistics`NormalDistribution`

measurement =
Table[epsp[t] + Random[NormalDistribution[0, 0.3]],
      {t, 1, 300}];

measurementPlot =
ListPlot[measurement, PlotRange -> {-66, -63},
         PlotJoined -> True,
         PlotStyle -> {GrayLevel[0.5]}]

Compute the filter coefficients. The number of filter coefficients (41 = 20 + 20 + 1) is chosen such that the rising phase of the epsp[t] function is not significantly distorted.

c = SavitzkyGolayCoefficients[20, 20, 4]

c = N[c]

ListPlot[Transpose[{Range[-20, 20], c}],
         AxesLabel -> {"n", "c[n]"}]

Apply this filter to the 'measured' data.

filterOutput = SavitzkyGolayFilter[measurement, c];

This is what the filter output function looks like. It is zero padded in the beginning and the end just to compensate for the reduction in the number of data points due to the filtering.

filterOutputPlot =
ListPlot[Join[Table[0, {20}],
              filterOutput,
              Table[0, {20}]],
         PlotRange -> {-66, -63}]

Show[measurementPlot, epspPlot, filterOutputPlot]