From: Jerry Avins on
On 7/8/2010 5:14 AM, gpezzella wrote:
> Dear Jerry
>
> just yesterday I have discovery another thread
> (http://www.dsprelated.com/showmessage/13897/1.php) in this forum that talk
> about the equation that you wrote to me:
>
> --------------------------------
> Y(i) = K * X(i) + (1-K) * Y(i-1)
> --------------------------------
>
> The difference is only apparent:
>
> -----------------------------------
> Y(i) = [X(i) - Y(i-1)] * K + Y(i-1)
> -----------------------------------
>
>
> Now in that thread the author say this:
>
> Where the desired time constant is known, use the following method.
> Assuming an input step from 0.0 to +1.0, an RC LPF will change its
> output voltage towards the new input by an amount equal to:
>
> ts
> -(--) Where: ts = sample period (seconds)
> T T = time constant (seconds)
> (1) K = 1 - e K = change in o/p after 1 ts
>
>
> The value for K is then used as the coefficient in the RC LPF code.
>
>
> If the above equation is correct I should use for my case:
> 1)Ft = 50 Hz
> 2)Sample Rate = 2.48KHz
>
>
> 1
> T = ------- = 0.00318
> 2*Pi*50
>
> ts = 1/2.48 Hz = 0.0004
>
>
> 0.0004
> -(--------)
> 0.00318
> K = 1 - e = 1 - 0.88 = 0.12
>
>
>
> Is this my equation?
> ----------------------------------------
> Y(i) = [X(i) - Y(i-1)] * 0.12 + Y(i-1)
> ----------------------------------------

First, notation. Subscripts are generally unavailable in plain text, so
we substitute parentheses or brackets. Typical DSP practice makes a
virtue of necessity. Parentheses are used for continuous variables such
as time, while square brackets are are used for enumerations.

Y(i) = [X(i) - Y(i-1)] * 0.12 + Y(i-1) is incorrect. Y[i] needs to be
some (large) fraction of Y[i-1], augmented by a part of X[i]. To achieve
proper low-frequency performance, the fraction and the part must sum to
1. So Y[i] = k*Y[i-1] + (k-1)*X[i].

You calculated k=.88. On a fixed-point processor, I would change that yo
..875, so that multiplications by k and by k-1 can be simply done with
shifts. That is, k*Y[i-1] = Y[i-1]-Y[i-1]>>3, and (k-1)*X[i]=X[i]>>3.
Note that the lower bits if X[i] are discarded whather you shift or
multiply. You need to determine if that's a problem. There are ways to
deal with it, but that's another topic.

Jerry
--
Engineering is the art of making what you want from things you can get.
From: Tim Wescott on
On 07/08/2010 07:57 AM, Jerry Avins wrote:
> On 7/8/2010 5:14 AM, gpezzella wrote:
>> Dear Jerry
>>
>> just yesterday I have discovery another thread
>> (http://www.dsprelated.com/showmessage/13897/1.php) in this forum that
>> talk
>> about the equation that you wrote to me:
>>
>> --------------------------------
>> Y(i) = K * X(i) + (1-K) * Y(i-1)
>> --------------------------------
>>
>> The difference is only apparent:
>>
>> -----------------------------------
>> Y(i) = [X(i) - Y(i-1)] * K + Y(i-1)
>> -----------------------------------
>>
>>
>> Now in that thread the author say this:
>>
>> Where the desired time constant is known, use the following method.
>> Assuming an input step from 0.0 to +1.0, an RC LPF will change its
>> output voltage towards the new input by an amount equal to:
>>
>> ts
>> -(--) Where: ts = sample period (seconds)
>> T T = time constant (seconds)
>> (1) K = 1 - e K = change in o/p after 1 ts
>>
>>
>> The value for K is then used as the coefficient in the RC LPF code.
>>
>>
>> If the above equation is correct I should use for my case:
>> 1)Ft = 50 Hz
>> 2)Sample Rate = 2.48KHz
>>
>>
>> 1
>> T = ------- = 0.00318
>> 2*Pi*50
>>
>> ts = 1/2.48 Hz = 0.0004
>>
>>
>> 0.0004
>> -(--------)
>> 0.00318
>> K = 1 - e = 1 - 0.88 = 0.12
>>
>>
>>
>> Is this my equation?
>> ----------------------------------------
>> Y(i) = [X(i) - Y(i-1)] * 0.12 + Y(i-1)
>> ----------------------------------------
>
> First, notation. Subscripts are generally unavailable in plain text, so
> we substitute parentheses or brackets. Typical DSP practice makes a
> virtue of necessity. Parentheses are used for continuous variables such
> as time, while square brackets are are used for enumerations.
>
> Y(i) = [X(i) - Y(i-1)] * 0.12 + Y(i-1) is incorrect. Y[i] needs to be
> some (large) fraction of Y[i-1], augmented by a part of X[i]. To achieve
> proper low-frequency performance, the fraction and the part must sum to
> 1. So Y[i] = k*Y[i-1] + (k-1)*X[i].
>
> You calculated k=.88. On a fixed-point processor, I would change that yo
> .875, so that multiplications by k and by k-1 can be simply done with
> shifts. That is, k*Y[i-1] = Y[i-1]-Y[i-1]>>3, and (k-1)*X[i]=X[i]>>3.
> Note that the lower bits if X[i] are discarded whather you shift or
> multiply. You need to determine if that's a problem. There are ways to
> deal with it, but that's another topic.

Actually, if it's a DSP chip (and on some newer 'regular' chips) there's
no extra cost for a multiply, and particularly on a DSP chip a shift may
be slower than a multiply (because most DSP chips give you single-cycle
multiply-and-accumulate, but few give you single-cycle
shift-and-accumulate).

--

Tim Wescott
Wescott Design Services
http://www.wescottdesign.com

Do you need to implement control loops in software?
"Applied Control Theory for Embedded Systems" was written for you.
See details at http://www.wescottdesign.com/actfes/actfes.html
From: Jerry Avins on
On 7/8/2010 11:48 AM, Tim Wescott wrote:
> On 07/08/2010 07:57 AM, Jerry Avins wrote:

...

>> You calculated k=.88. On a fixed-point processor, I would change that yo
>> .875, so that multiplications by k and by k-1 can be simply done with
>> shifts. That is, k*Y[i-1] = Y[i-1]-Y[i-1]>>3, and (k-1)*X[i]=X[i]>>3.
>> Note that the lower bits if X[i] are discarded whather you shift or
>> multiply. You need to determine if that's a problem. There are ways to
>> deal with it, but that's another topic.
>
> Actually, if it's a DSP chip (and on some newer 'regular' chips) there's
> no extra cost for a multiply, and particularly on a DSP chip a shift may
> be slower than a multiply (because most DSP chips give you single-cycle
> multiply-and-accumulate, but few give you single-cycle
> shift-and-accumulate).

I should have pointed that out. I remember the OP writing that his
resources are very limited, and I switched into Z-80 mode.

Jerry
--
Engineering is the art of making what you want from things you can get.
�����������������������������������������������������������������������
From: gpezzella on
Ok I will use this notation from now

I previous post (7/1/2010 3:21 AM) you wrote me the follow equation:
<a> "y[1] = k*x[i] + (1-k)*y[i-1] that behaves like a single RC".

In the day 7/8/2010 I discovery another thread that use:
<b> "Y[i] = K * X[i] + [1-K] * Y[i-1]"
which is coincident to yours:
<c> "Y[i] = [ X[i] - Y[i-1] ] * K + Y[i-1]"

Today instead you write that:
<d> "Y[i] = k*Y[i-1] + (k-1)*X[i]" is the correct equation

Question 1: Which is the good one between a,b,c,d?
Question 2: After chhose the correct equation, is the follow method correct
for calculate K coefficient?
--------------------------------------------------------------------------------
ts
-(--) Where: ts = sample period (seconds)
T T = time constant (seconds)
(1) K = 1 - e K = change in o/p after 1 ts


The value for K is then used as the coefficient in the RC LPF code.

If the above equation is correct I should use for my case:
1)Ft = 50 Hz
2)Sample Rate = 2.48KHz


1
T = ------- = 0.00318
2*Pi*50

ts = 1/2.48 Hz = 0.0004


0.0004
-(--------)
0.00318
K = 1 - e = 1 - 0.88 = 0.12
------------------------------------------------------------------------------

From: Jerry Avins on
On 7/9/2010 5:42 AM, gpezzella wrote:
> Ok I will use this notation from now
>
> I previous post (7/1/2010 3:21 AM) you wrote me the follow equation:
> <a> "y[1] = k*x[i] + (1-k)*y[i-1] that behaves like a single RC".
>
> In the day 7/8/2010 I discovery another thread that use:
> <b> "Y[i] = K * X[i] + [1-K] * Y[i-1]"
> which is coincident to yours:
> <c> "Y[i] = [ X[i] - Y[i-1] ] * K + Y[i-1]"
>
> Today instead you write that:
> <d> "Y[i] = k*Y[i-1] + (k-1)*X[i]" is the correct equation
>
> Question 1: Which is the good one between a,b,c,d?

They are all good. Where I initially have the coefficients as k and 1-k,
your other gave them as 1-k and k. Because k is an arbitrary constant,
the two notations are equivalent. After your response, I switched to
your notation.

> Question 2: After choose the correct equation, is the follow method correct
> for calculate K coefficient?
> --------------------------------------------------------------------------------
> ts
> -(--) Where: ts = sample period (seconds)
> T T = time constant (seconds)
> (1) K = 1 - e K = change in o/p after 1 ts
>
>
> The value for K is then used as the coefficient in the RC LPF code.
>
> If the above equation is correct I should use for my case:
> 1)Ft = 50 Hz
> 2)Sample Rate = 2.48KHz
>
>
> 1
> T = ------- = 0.00318
> 2*Pi*50
>
> ts = 1/2.48 Hz = 0.0004
>
>
> 0.0004
> -(--------)
> 0.00318
> K = 1 - e = 1 - 0.88 = 0.12
> ------------------------------------------------------------------------------

Yes. (I would have written the last line either as e^(-.0004/.00318) or
exp(-.0004/.00318).)

Jerry
--
Engineering is the art of making what you want from things you can get.
�����������������������������������������������������������������������