Hi,
I have a low-pass fillter in the following form:
x_k = alpha * x_{k-1} + (1-alpha) * y_k
where x_k is the average value I try to update, and y_k is the new
value that occurs at time k.
Can anyone tell me how to calculate the time constant of this filter
(as a function of alpha)?
Thanks a lot!
Jianwei
How to calculate the time constant of a filter
Started by ●July 19, 2004
Reply by ●July 19, 20042004-07-19
Stan wrote:> Hi, > > I have a low-pass fillter in the following form: > > x_k = alpha * x_{k-1} + (1-alpha) * y_k > > where x_k is the average value I try to update, and y_k is the new > value that occurs at time k. > > Can anyone tell me how to calculate the time constant of this filter > (as a function of alpha)? > > Thanks a lot! > > JianweiTo the extent that time constants mean anything in discrete time it would be -(sample time) * ln(alpha). -- Tim Wescott Wescott Design Services http://www.wescottdesign.com
Reply by ●July 19, 20042004-07-19
"Tim Wescott" <tim@wescottnospamdesign.com> wrote in message news:10fnrhgk4225g21@corp.supernews.com...> Stan wrote: > > > Hi, > > > > I have a low-pass fillter in the following form: > > > > x_k = alpha * x_{k-1} + (1-alpha) * y_k > > > > where x_k is the average value I try to update, and y_k is the new > > value that occurs at time k. > > > > Can anyone tell me how to calculate the time constant of this filter > > (as a function of alpha)? > > > > Thanks a lot! > > > > Jianwei > > To the extent that time constants mean anything in discrete time it > would be -(sample time) * ln(alpha).I think it should be -(sample time)/(ln(1-alpha)). FYI, for small alphas (e.g. <0.1), a good simple approximation is (sample time)/alpha. Also, you can find the cut-off frequency for this filter using this formula: FC = -ln(1-alpha)*(sampleRate/2*pi) (FC is -3dB cut-off frequency in Hz) Personally, I've found time constants to be just as useful with discrete time as with analog.
Reply by ●July 19, 20042004-07-19
Jon Harris wrote:> "Tim Wescott" <tim@wescottnospamdesign.com> wrote in message > news:10fnrhgk4225g21@corp.supernews.com... > >>Stan wrote: >> >> >>>Hi, >>> >>>I have a low-pass fillter in the following form: >>> >>>x_k = alpha * x_{k-1} + (1-alpha) * y_k >>> >>>where x_k is the average value I try to update, and y_k is the new >>>value that occurs at time k. >>> >>>Can anyone tell me how to calculate the time constant of this filter >>>(as a function of alpha)? >>> >>>Thanks a lot! >>> >>>Jianwei >> >>To the extent that time constants mean anything in discrete time it >>would be -(sample time) * ln(alpha). > > > I think it should be -(sample time)/(ln(1-alpha)). FYI, for small alphas (e.g. > <0.1), a good simple approximation is (sample time)/alpha. Also, you can find > the cut-off frequency for this filter using this formula: > FC = -ln(1-alpha)*(sampleRate/2*pi) (FC is -3dB cut-off frequency in Hz) > > Personally, I've found time constants to be just as useful with discrete time as > with analog. > >You're correct in that I've missed a divide, but incorrect in the 1-alpha business. His "alpha" is the z-domain pole, so the thing will decay as alpha^k, or e^(ln(alpha)*k). So in the pure-time domain it'll go as e^(ln(alpha)*k/T), and I should have said -T / ln(alpha). And yes, they are useful (I use them, in context), but it's hard to give a good mathematical definition with that sapling getting in the way. -- Tim Wescott Wescott Design Services http://www.wescottdesign.com
Reply by ●July 19, 20042004-07-19
"Tim Wescott" <tim@wescottnospamdesign.com> wrote in message news:10fo3137hg98942@corp.supernews.com...> Jon Harris wrote: > > "Tim Wescott" <tim@wescottnospamdesign.com> wrote in message > > news:10fnrhgk4225g21@corp.supernews.com... > > > >>>I have a low-pass fillter in the following form: > >>> > >>>x_k = alpha * x_{k-1} + (1-alpha) * y_k > >>> > >>>where x_k is the average value I try to update, and y_k is the new > >>>value that occurs at time k. > >>> > >>>Can anyone tell me how to calculate the time constant of this filter > >>>(as a function of alpha)? > >>> > >>To the extent that time constants mean anything in discrete time it > >>would be -(sample time) * ln(alpha). > > > > > > I think it should be -(sample time)/(ln(1-alpha)). FYI, for small alphas(e.g.> > <0.1), a good simple approximation is (sample time)/alpha. Also, you canfind> > the cut-off frequency for this filter using this formula: > > FC = -ln(1-alpha)*(sampleRate/2*pi) (FC is -3dB cut-off frequency in Hz) > > > You're correct in that I've missed a divide, but incorrect in the > 1-alpha business. His "alpha" is the z-domain pole, so the thing will > decay as alpha^k, or e^(ln(alpha)*k). So in the pure-time domain it'll > go as e^(ln(alpha)*k/T), and I should have said -T / ln(alpha).OK, I see my problem. The OP poster is defining his output as x and his input as y. The standard DSP convention is that x is for input and y is for output so I assumed that without reading carefully enough. With those definitions for x and y, Tim's second post has the correct formula: TC = -(sample time)/(ln(alpha)), or approximately TC ~= 1/(1-alpha). And the cut-off frequency will be: FC = -ln(alpha)*(sampleRate/2*pi) (FC is -3dB cut-off frequency in Hz) Between the 2 of us, it only took 3 tries to get it right! :-)> And yes, they are useful (I use them, in context), but it's hard to give > a good mathematical definition with that sapling getting in the way.Right. I often drop the sample rate and treat them in terms of number of samples. -Jon
Reply by ●February 5, 20132013-02-05
Hi, I found your thread has the equation for calculating the cut-off frequency of a low pass filter in the form of FC = -ln(alpha)*(sampleRate/2*pi) Would you mind sharing how this equation is derived? I used a low pass filter in the following format: Y/X = K[1/(1+s*tau)]. Calcuating cutoff frequency when the amplitude is 0.707, I get FC = 1/(2*pi*tau). Is your equation derived based on a different type of low pass filter? Thank you. Joyce
Reply by ●February 9, 20132013-02-09
On 2/5/2013 12:11 PM, Joyce Chen wrote:> Hi, I found your thread has the equation for calculating the cut-off > frequency of a low pass filter in the form of > FC = -ln(alpha)*(sampleRate/2*pi) > > Would you mind sharing how this equation is derived? > I used a low pass filter in the following format: Y/X = K[1/(1+s*tau)]. > Calcuating cutoff frequency when the amplitude is 0.707, I get FC = > 1/(2*pi*tau). > Is your equation derived based on a different type of low pass filter?The filter you describe is analog. Most of the filters discussed here are digital (mathematical, rather than physical). Many contributors post here. To whom is your question addressed? Jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������
Reply by ●February 16, 20132013-02-16
>On 2/5/2013 12:11 PM, Joyce Chen wrote: >> Hi, I found your thread has the equation for calculating the cut-off >> frequency of a low pass filter in the form of >> FC = -ln(alpha)*(sampleRate/2*pi) >> >> Would you mind sharing how this equation is derived? >> I used a low pass filter in the following format: Y/X = K[1/(1+s*tau)]. >> Calcuating cutoff frequency when the amplitude is 0.707, I get FC = >> 1/(2*pi*tau). >> Is your equation derived based on a different type of low pass filter? > >The filter you describe is analog. Most of the filters discussed here >are digital (mathematical, rather than physical). > >Many contributors post here. To whom is your question addressed? > >Jerry >-- >Engineering is the art of making what you want from things you can get. >����������������������������������������������������������������������� >I was trying to figure out the correlation between Fc and tau. I guesswhat I had was the correlation between Fc and tau in an analog filter. If I convert 1/(1+s*tau) to discrete transfer function using s = (1-Z^(-1))/T. Then y/x = (TZ)/(TZ+Z*tau-tau). How do I get the correlation between Fc and tau through mathmatic conversions in Z domain? If I know the equation between Fc and tau, and I already know how to calculate alpha from tau, then I can calculate alpha from Fc. My question was addressed to Tom or Jon originally since I didn't understand how the equation for FC came about, FC = -ln(alpha)*(sampleRate/2*pi). Though I appreciate your replying and any help from anyone. Thank you Joyce
Reply by ●February 17, 20132013-02-17
hi Joyce, my quoting your text is accurate, but i am changing "Z" to "z" and maybe simplifying some other ASCII math. On 2/16/13 10:30 PM, Joyce Chen wrote:>> I was trying to figure out the correlation between Fc and tau. I guess> what I had was the correlation between Fc and tau in an analog filter.might the result of that "correlation" (i might use a different term for that) be Fc = 1/(2*pi*tau) ?> If I > convert 1/(1+s*tau) to discrete transfer function using s = (1-z^(-1))/T.now that is a useful mapping, pretty much the same as Euler's forward method of discretizing a differential equation.> Then y/x = (T*z)/(T*z+z*tau-tau). How do I get the correlation between Fc > and tau through mathematic conversions in Z domain?well, you can keep the same mapping you had with the analog filter or, you can solve for the relationship again. but if you do the latter, you need to be specific about what you mean by the Fc frequency? is it the "half-power frequency" or the "-3.01 dB frequency"? just as you substitute s = j*w ("w" means "omega") to get the frequency response for the analog filter, you substitute z = e^(j*w*T) to get the frequency response of the digital filter. plug that in and chug. then find what value of w will result in a the square of the gain that is reduced to 1/2.> If I know the equation > between Fc and tau, and I already know how to calculate alpha from tau, > then I can calculate alpha from Fc.dunno alpha. can you define it? (maybe you did and i missed it.)> My question was addressed to Tom or Jon originally since I didn't > understand how the equation for Fc came about, > Fc = -ln(alpha)*(sampleRate/2*pi).i think that sampleRate = 1/T and Fc is the half-power frequency.> Though I appreciate your replying and any help from anyone.take any digital filter. plug in e^(j*w*T) for every z. then compute the magnitude-squared of the transfer function. then see what value of "w" makes the magnitude-squared take on 1/2 the value it has when w=0 (the DC value). that "w" should be 2*pi*Fc . -- r b-j rbj@audioimagination.com "Imagination is more important than knowledge."
Reply by ●February 19, 20132013-02-19
> >hi Joyce, > >my quoting your text is accurate, but i am changing "Z" to "z" and maybe >simplifying some other ASCII math. > >On 2/16/13 10:30 PM, Joyce Chen wrote: >> > > I was trying to figure out the correlation between Fc and tau. Iguess>> what I had was the correlation between Fc and tau in an analog filter. > >might the result of that "correlation" (i might use a different term for >that) be > > Fc = 1/(2*pi*tau) ? >Yes, this is equation for an analog filter.> >> If I >> convert 1/(1+s*tau) to discrete transfer function using s =(1-z^(-1))/T.> >now that is a useful mapping, pretty much the same as Euler's forward >method of discretizing a differential equation.Yes, that is what I used, Euler's forward method.> >> Then y/x = (T*z)/(T*z+z*tau-tau). How do I get the correlation betweenFc>> and tau through mathematic conversions in Z domain? > >well, you can keep the same mapping you had with the analog filter or, >you can solve for the relationship again. but if you do the latter, you >need to be specific about what you mean by the Fc frequency? is it the >"half-power frequency" or the "-3.01 dB frequency"? >By Fc frequency, I meant the frequency when the magnitude is 1/sqrt(2) of the original magnitude before the signal is being fitered.>just as you substitute s = j*w ("w" means "omega") to get the >frequency response for the analog filter, you substitute > > z = e^(j*w*T) > >to get the frequency response of the digital filter. > >plug that in and chug. then find what value of w will result in a the >square of the gain that is reduced to 1/2.After substitute z = e^(j*w*T) in the discretized equation, I got cos(WcT) = (-T^2 + 2*tau*T + 2*tau^2)/(2*(T+tau)*tau), where w = 2*pi*Fc. It is a quite complicated equation.> >> If I know the equation >> between Fc and tau, and I already know how to calculate alpha from tau, >> then I can calculate alpha from Fc. > >dunno alpha. can you define it? (maybe you did and i missed it.) >In an earlier posting by other people, they had the equation of low pass filter, where alpha is the coefficient used to multiply previous samples. x_k = alpha * x_{k-1} + (1-alpha) * y_k See the link here http://www.dsprelated.com/showmessage/5126/1.php In that posting, Tom and Jon gave the equation between Fc and alpha used in the low pass filter equation. Fc = -ln(alpha)*(sampleRate/2*pi). I was trying to see how this equation came about. In my calculation, after converting the transfer function to z domain using Euler's forward equation, I get y(n) = (tau/(T+tau))*y(n-1) + (T/(T+tau))x(n). So if alpha = (tau/(T+tau)), then 1-alpha = (T/(T=tau). So the above equation becomes y(n) = alpha*y(n-1) + (1-alpha)*x(n) Since I know the equation between tau and alpha, I just need the equation between Fc and tau. I can do that by substitute z = e^(j*w*T) as you suggested above. But the equation, the one contains cos(WcT) doesn't have any -ln() term in it. I wonder if there is some apporximation that they made in deriving the equation between Fc and alpha.>> My question was addressed to Tom or Jon originally since I didn't >> understand how the equation for Fc came about, >> Fc = -ln(alpha)*(sampleRate/2*pi). > >i think that sampleRate = 1/T and Fc is the half-power frequency. > >> Though I appreciate your replying and any help from anyone. > >take any digital filter. plug in e^(j*w*T) for every z. then compute >the magnitude-squared of the transfer function. then see what value of >"w" makes the magnitude-squared take on 1/2 the value it has when w=0 >(the DC value). that "w" should be 2*pi*Fc . > >-- > >r b-j rbj@audioimagination.com > >"Imagination is more important than knowledge." > >Thank you. Joyce






