[Updated 12th March 2013]
What are RC Filtering and Exponential Averaging and how do they differ? The answer to the second part of the question is that they are the same process! If one comes from an electronics background then RC Filtering (or RC Smoothing) is the usual expression. On the other hand an approach based on time series statistics has the name Exponential Averaging, or to use the full name Exponential Weighted Moving Average. This is also variously known as EWMA or EMA.
A key advantage of the method is the simplicity of the formula for computing the next output. It takes a fraction of the previous output and one minus this fraction times the current input. Algebraically at time k the smoothed output yk is given by
As shown later this simple formula emphasises recent events, smooths out high frequency variations and reveals long term trends. Note there are two forms of the exponential averaging equation, the one above and a variant
Both are correct. See the notes at end of the article for more details. In this discussion we will only use equation (1).
The above formula is sometimes written in the more limited fashion.
How is this formula derived and what is its interpretation? A key point is how do we select . To look into this one simple way is to consider an RC low pass filter.
Now an RC low pass filter is simply a series resistor R and a parallel capacitor C as illustrated below.
The time series equation for this circuit is
The product RC has units of time and is known as the time constant ,T , for the circuit. Suppose we represent the above equation in its digital form for a time series which has data taken every h seconds. We have
This is exactly the same form as the previous equation. Comparing the two relationships for a we have
which reduces to the very simple relationship
Hence the choice of N is guided by what time constant we chose. Now equation (1) may be recognised as a low pass filter and the time constant typifies the behaviour of the filter. To see the significance of the Time Constant we need to look at the frequency characteristic of this low pass RC filter. In its general form this is
Expressing in modulus and phase form we have
where the phase angle is .
The frequency is called the nominal cut off frequency . Physically it may be shown that at this frequency the power in the signal has been reduced by one half and the amplitude is reduced by the factor . In dB terms this frequency is where the amplitude has been reduced by 3dB.
Clearly as the time constant T increases so then the cut off frequency reduces and we apply more smoothing to the data, that is we eliminate the higher frequencies.
It is important to note that the frequency response is expressed in radians/second. That is there is a factor of involved. For example choosing a time constant of 5 seconds gives an effective cut off frequency of . One popular use of RC smoothing is to simulate the action of a meter such as used in a Sound Level Meter. These are generally typified by their time constant such as 1 second for S types and 0.125 seconds for F types. For these 2 cases the effective cut off frequencies are 0.16Hz and 1.27Hz respectively.
Actually it is not the time constant we usually wish to select but those periods we wish to include. Suppose we have a signal where we wish to include features with a P second period. Now a period P is a frequency . We could then choose a time constant T given by . However we know that we have lost about 30% of the output (-3dB) at . Thus choosing a time constant which exactly corresponds to the periodicities we wish to keep is not the best scheme. It is usually better to choose a slightly higher cut off frequency, say . The time constant is then which in practical terms is similar to . This reduces the loss to around 15% at this periodicity. Hence in practical terms to retain events with a periodicity of or greater then choose a time constant of . This will include the effects of periodicities of down to about . For example if we wish to include the effects of events happening with say an 8 second period (= 0.125Hz) then choose a time constant of 0.8 seconds. This gives a cut off frequency of approximately 0.2Hz so that our 8 second period is well in the main pass band of the filter. If we were sampling the data at 20 times/second (h = 0.05) then the value of N is (0.8/0.05) = 16 and .
This gives some insight into how to set . Basically for a known sample rate it typifies the averaging period and selects which high frequency fluctuations will be ignored.
By looking at the expansion of the algorithm we can see that it favours the most recent values, and also why it is referred to as exponential weighting. We have
Substituting for yk-1 gives
Repeating this process several times leads to
Because is in the range then clearly the terms to the right become smaller and behave like a decaying exponential. That is the current output is biased towards the more recent events but the larger we choose T then the less bias.
In summary we see that the simple formula
- emphasises recent events
- smoothes out high frequency (short period) events
- reveals long term trends
Appendix 1 – Alternate forms of the equation
Caution There are two forms of the exponential averaging equation that appear in the literature. Both are correct and equivalent.
The first form as shown above is …(A1)
The alternate form is …(A2)
Note the use of in the first equation and in the second equation. In both equations and are values between zero and unity.
Earlier was defined as
Now choosing to define
Hence the alternate form of the exponential averaging equation is
In physical terms it means that the choice of form one uses depends on how one wants to think of either taking as the feed back fraction [equation (A1)] or as the fraction of the input [equation (A2)].
The first form is slightly less cumbersome in showing the RC filter relationship, and leads to a simpler understanding in filter terms.
The following two tabs change content below.
Dr Colin Mercer was formerly at the Institute of Sound and Vibration Research (ISVR), University of Southampton where he founded the Data Analysis Centre. He then went on to found Prosig in 1977. Colin retired as Chief Signal Processing Analyst at Prosig in December 2016. He is a Chartered Engineer and a Fellow of the British Computer Society.