我要加入 登录
声振论坛 返回首页

westrongmc的个人空间 http://home.vibunion.com/?190415 [收藏] [复制] [分享] [RSS]

日志

[转贴]数据平滑:RC滤波与指数平均

已有 326 次阅读2013-3-15 08:48 |个人分类:信号处理| 数据平滑, RC滤波, 指数平均, data smoothing, RC filtering


Data Smoothing : RC Filtering And Exponential Averaging

 – APRIL 28, 2003POSTED IN: SIGNAL PROCESSING

[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

y_k = {.alpha}y_{k-1} + (1 - .alpha)x_k.,.,where.,0<.alpha <1 (1)

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

y_k = {.alpha}x_k + (1 - .alpha)y_{k-1} (2)

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.

y_k = .left(.frac{N-1}{N}.right)y_{k-1} + .left(.frac{1}{N}.right)x_k

How is this formula derived and what is its interpretation? A key point is how do we select .alpha. 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

RC.left(.frac{dy}{dt}.right) + y = x

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

T.left(.frac{y_k - y_{k-1}}{h}.right) + y_k = x_k

Rearranging gives

y_k = .left(.frac{T}{T+h}.right)y_{k-1} + .left(.frac{h}{T+h}.right)x_k

or

y_k = {.alpha}y_{k-1} + (1-.alpha)x_k

This is exactly the same form as the previous equation. Comparing the two relationships for a we have

.frac{T}{T+h} = .frac{N-1}{N}

which reduces to the very simple relationship

T = (N - 1)h

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

H(.omega) = .frac{1}{1+i{.omega}RC} = .frac{1}{1+i{.omega}T}

Expressing in modulus and phase form we have

H(.omega) = {.frac{1}{.sqrt{1+.omega^2T^2}}e^{i.phi}

where the phase angle .phi$ is $tan^{-1}(-{.omega}T ).

The frequency .omega = 1/T is called the nominal cut off frequency .omega_c. 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 (1/.sqrt{2}) = 0.7071. 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 {.omega}_c 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 2.piinvolved. For example choosing a time constant of 5 seconds gives an effective cut off frequency of 1/(2.pi * 5) = 0.032Hz. 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 f_p = 1/P. We could then choose a time constant T given by T=P/(2*.pi) . However we know that we have lost about 30% of the output (-3dB) at f_p. 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 1.5f_p . The time constant is then T=P/(3*.pi) which in practical terms is similar to T = P/10. This reduces the loss to around 15% at this periodicity. Hence in practical terms to retain events with a periodicity of P or greater then choose a time constant of (P/10). This will include the effects of periodicities of down to about 0.6P. 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 .alpha = (16/17) = 0.9412.

This gives some insight into how to set .alpha. 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

y_k = (1-.alpha)x_k + {.alpha}y_{k-1}

Substituting for yk-1 gives

y_k = (1 - .alpha)x_k + .alpha.left[(1-.alpha)x_{k-1} + {.alpha}y_{k-2}.right] =(1 - .alpha)(x_k + {.alpha}x_{k-1}) + .alpha_2y_{k-2}

Repeating this process several times leads to

y_k = (1-.alpha)(x_k + {.alpha}x_{k-1} + {.alpha}^2x_{k-2}+ .dots + {.alpha}^Nx_{k-N})+{.alpha}^{N+1}y_{k-N-1}

Because .alpha is in the range 0<.alpha<1 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 y_k= {.alpha}y_{k-1} + (1-.alpha)x_k

  • 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 y_k = {.alpha}_1y_{k-1} + (1 - {.alpha}_1)x_k…(A1)

The alternate form is y_k = {.alpha}_{2}x_k + (1 - {.alpha}_2)y_{k-1} …(A2)

Note the use of {.alpha}_1 in the first equation and {.alpha}_2 in the second equation. In both equations {.alpha}_1 and {.alpha}_2 are values between zero and unity.

Earlier {.alpha}_1 was defined as

{.alpha}_1 = .big(.frac{T}{T+h}.big)

which gives

(1-{.alpha}_1)=.big(.frac{h}{T+h}.big).

Now choosing to define

{.alpha}_2 = .big(.frac{h}{T+h}.big)

gives

(1 - {.alpha}_2)=.big(.frac{T}{T+h}.big).

Hence the alternate form of the exponential averaging equation is

y_k={.alpha}_2x_k+(1-{.alpha}_2)y_{k-1}

where

{.alpha}_2 = (1-{.alpha}_1)= .big(.frac{h}{h+T}.big).

In physical terms it means that the choice of form one uses depends on how one wants to think of either taking {.alpha} 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.

Print or send:
About Dr Colin MercerDr Colin Mercer is the Technical Director of Prosig and has prime responsibility for signal processing and its applications. He was formerly at the Institute of Sound and Vibration research (ISVR), Southampton University where he founded the Data Analysis Centre. He is a Chartered Engineer and a Fellow of the British Computer Society.

评论 (0 个评论)

facelist doodle 涂鸦板

您需要登录后才可以评论 登录 | 我要加入

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-5-14 07:41 , Processed in 0.033917 second(s), 16 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部