Moving Average and Savitzki-Golay Smoothing Filter
Moving Average and Savitzki-Golay Smoothing Filter
net/publication/228407245
CITATIONS READS
105 10,335
4 authors, including:
V. Pérez-Herranz
Polytechnic University of Valencia
151 PUBLICATIONS 3,600 CITATIONS
SEE PROFILE
All content following this page was uploaded by J. L. Guiñón on 17 May 2014.
Abstract - All measurement processes cause certain The Saviztky-Golay filter is based on the least squares
amount of random variations in the signal; this polynomial fitting across a moving window within the data
phenomenon is called noise. The procedure to reduce or in the time domain [5]. Typically, a long polynomial, and a
smooth the noise of a measured signal is commonly moderate order polynomial allows a high level of smoothing
known as filtering. In this paper we present the use of without attenuation of data features. By contrast, the
Mathcad software for the implementation and analysis of Saviztky-Golay filtering method is better than averaging
the moving average and Savitzky-Golay filters. The because it tends to preserve features of the data such as peak
moving average filter is the simplest digital filter to height and width, which are usually attenuated by the
understand and use. As its name suggests, this filter moving average filter.
operates by averaging a number of points in a recursive Different mathematical algorithms, generally based on
fashion. In spite of its simplicity, the moving average Excel macro and Matlab, have been developed to implement
filter is effective for time domain encoded signals. The the moving average and Saviztky-Golay filters [2, 6-8].
Saviztky-Golay filter is based on the least squares Among the different symbolic solvers, Mathcad is one of the
polynomial fitting across a moving window within the most widely used. The ease with which Mathcad lets the user
data in the time domain. Generally, a high order type equations and text, nearly exactly as we would write
polynomial (n=4) allows a high level of smoothing them down paper, and its capability of generating complex
without attenuation of data features. By contrast, the graphs, make Mathcad be a powerful and flexible tool to
Saviztky-Golay filtering method is better than averaging develop a variety of instructional designed programs to
because it tends to preserve data features such as peak promote knowledge.
height and width, which are usually attenuated by the The use of Mathcad in the curriculum of chemical
moving average filter. By means of the Mathcad engineering has been discussed in previous papers [9-12]. In
software, moving average and Savitzky-Golay filters this manuscript we report the use of the Mathcad software
were successfully applied to the smoothing of for the implementation and analysis of the moving average
photochemical and electrochemical reactor data. and Savitzky-Golay filters. Finally, Mathcad was
successfully implemented to the smoothing of photochemical
Index Terms - Mathcad, Computer Applications, Moving and electrochemical reactor data.
Average, Savitzki-Golay, Filters, Noise.
FUNDAMENTALS
INTRODUCTION
As its name suggests, the moving average filter
All measurement processes cause certain amount of random operates by averaging a number of points from the input
variations in the signal; this phenomenon is called noise. The signal to generate each point in the output signal. This
procedure to reduce or smooth the noise of a measured signal procedure is repeated so that a moving window of M points
is commonly known as filtering. There are many different is used to calculate the average of the data set. The algorithm
filter designs, but the most common ones are based on takes the mathematical expression:
averaging.
The moving average filter is the simplest digital filter to M−1
∑ ( si+ j) 0.5
− ( M−1)
j=
2 ( M − 1) ( M + 1)
ySi := if i > ∧ i< N−
M 2 2
noisei 0
0 otherwise
(2)
where sm+k is the input signal, gm is the output signal. 0 0.1 0.2 0.3
Here nL is the number of points used to the left of a data ti
point m, while nR is the number used to the right. The
Saviztky-Golay coefficients, ck+nL , are given by: Figure 1.- Top: Random noise. Bottom: Simulation of a
signal with two Gaussian features and noisy baseline.
cM+n
( T
:= ( A) ⋅A ) − 1 ⋅( (A)T ) 0 , M+n
L L (4)
where: 4
M := −n L .. n R
(5)
m := n L .. N − n R si
(6) 2
j := 0 .. n (7) ( ytS25 ) i
j
AM+n , j := M
L (8)
0
0 0.1 0.2 0.3
RESULTS AND DISCUSSION
ti
Figure 1 shows the random noise and the input signal formed 4
by two Gaussians, a major one centred at 0.20 s, while the
minor one is centred at 0.24 s. Figure 2 shows the output
signals obtained with 25-point moving average filters si
symmetrical and directional respectively. Both filters 2
produce a sharp noise reduction, however, the directional ( yt25 ) i
filter with the points on only one side, causes a relative shift
between the input and output signals. The effect of the
number of points on the average is shown in Figure 3. 0
Clearly, as the number of points in the filter increases, noise
signal becomes lower; however, there are significant 0 0.1 0.2 0.3
distortions of the signal by the smoothing filter, which ti
increases with increasing filter bandwidth. This phenomenon
is expected as it inevitably involves averaging part of the Figure 2.- Effect of the 25-point moving average filter. Top:
baseline with the rising portion of the minor peak, leading to Symmetrical filter. Bottom: Directional filter.
its disappearance. Figure 4 shows the linear variation in the
yi
2
200 g25m
S/N
0
100
0 0.1 0.2 0.3
ti , tm
0 Observamos que el filtrado de SG, por ejemplo de 25 puntos conserva la amplitud
0 2 4 6 8 Figure 5.- Top: Effect of 25-point Saviztky-Golay filter on
0.5 the noisy signal (si). Bottom: Comparison of the signal
M
without noise (yi) and the filtered signal (g25).
Figure 4.- Plot of signal-to-noise ratio vs square-root of the Moving average and Savitzky-Golay filters were
number of points in the average. successfully applied to the smoothing of photochemical and
electrochemical reactor data. Figure 6 (top) shows the noisy
The coefficients of Saviztky-Golay filters for orders signal (energy vs wavelength, λ) obtained in a
n=2 and n=4, with several choices of nL and nR are shown in photochemical reactor equipped with a hydrogen or xenon
Table I. The central column is the coefficient applied to the lamp. The effect of the 25-point Savitzky-Golay (n=2) and
data sm for obtaining the smoothed gm. Coefficients to the 25-point moving average filters is shown in Figure 6
left are applied to earlier data and to the right to later data. (bottom). Savitzky-Golay filter produces very little distortion
The coefficient values always add the unity. Note that the in the signal in comparison to the moving average filter.
coefficients always have a central positive lobe and with
smaller outlying corrections of both positive and negative.
Figure 5 illustrates the effect of a 25 point Saviztky-
Golay filter (order 2) on the same input signal as shown in
Figure 1. Clearly, the baseline noise amplitude is reduced by
n nL=nR
CM+nL: Savitzky-Golay Coefficients
ACKNOWLEDGMENT
Energy
Figure 7 shows the potential-time response to applying [5] Savitzky, A., Golay, M.J.E. “Smoothing and differentiation of data by
simplified least squares procedures” Analytical Chemistry, 36(2),
a pulse of current in an electrochemical reactor. In this case, p.1627, (1964).
the use of 201-point Savitzky-Golay (n=1) filter, is not so [6] Borchers, H.W. “Savitzky-Golay smoothing an R implementation” in
excellent as the above example; however, it suffices enough http://tostoy.newcastle.edu.au/R/help/04/02/0385.html
to retrieve the signal with little noise.
[7] Press, W.H., Flannery, B.P., Teukolsky, S.A., Vetterling, W.T.
“Numerical recipes in C: The Art of Scientific Computing”
Cambridge Univesity Press, Cambridge, (1992).