DSPRelated.com
Forums

sync filter: Can you help me to set 3 parameter?

Started by gpezzella June 29, 2010
Dear Jerry

>I'm afraid that I'm not much help. It should be clear to you that you >don't even know enough to ask the right questions. You have to >understand the system before digging into the details
Yes it is true. I don't have enough knowledge but I would try to do it. For this I ask you to have great patience with me :-) I'm absolute newbye in DSP.
>You can sample as low as 500 Hz to save processing time.
2.48KHz Sampling Rate is obtained with the most High Prescaler. If I would go more slow I should lower Main Clock but this slow all processing time
>Then you might be able to use a single or two-section exponential
averager Now I have lost you....Have you code sample with comment that explane how to implement it? Remember that you are talking with a "child dsp developer" Giuseppe
On 7/1/2010 3:21 AM, gpezzella wrote:
> Dear Jerry > >> I'm afraid that I'm not much help. It should be clear to you that you >> don't even know enough to ask the right questions. You have to >> understand the system before digging into the details > Yes it is true. I don't have enough knowledge but I would try to do it. > For this I ask you to have great patience with me :-) > I'm absolute newbye in DSP. > >> You can sample as low as 500 Hz to save processing time. > 2.48KHz Sampling Rate is obtained with the most High Prescaler. > If I would go more slow I should lower Main Clock but this slow all > processing time > >> Then you might be able to use a single or two-section exponential > averager > Now I have lost you....Have you code sample with comment that explane how > to implement it? > Remember that you are talking with a "child dsp developer"
Are you sure that the sample rate is so intimately tied to the processor clock? If so, you can simply use every 5th sample and discard the rest. It might be that processing all the samples uses fewer clock cycles than deciding which ones to keep. If so, no harm done. An exponential averager is also called a leaky accumulator. Some notation: x[i] is input sample #i. x[i+1] is the sample after that, and so on. y[1] is output # i, and y[i-1] the output that preceded it. An exponential averager slowly forgets the past, like a capacitor and resistor in parallel whose inputs are current pulses. y[1] = k*x[i] (1-k)*y[i-1] behaves like a single RC. The value of k sets the "time constant". There are more efficient ways than simply cascading two or more of these to sharpen the cut-off, but that works. Smith's book provides details, as does the Bores site I recommended. Jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������
On 07/01/2010 12:21 AM, gpezzella wrote:
> Dear Jerry > >> I'm afraid that I'm not much help. It should be clear to you that you >> don't even know enough to ask the right questions. You have to >> understand the system before digging into the details > Yes it is true. I don't have enough knowledge but I would try to do it. > For this I ask you to have great patience with me :-) > I'm absolute newbye in DSP. > >> You can sample as low as 500 Hz to save processing time. > 2.48KHz Sampling Rate is obtained with the most High Prescaler. > If I would go more slow I should lower Main Clock but this slow all > processing time > >> Then you might be able to use a single or two-section exponential > averager > Now I have lost you....Have you code sample with comment that explane how > to implement it? > Remember that you are talking with a "child dsp developer"
There's a lot of material to cover to get up to speed for even simple DSP problems -- which leaves the education you can get from USENET posts pretty spotty. Get a copy of "Understanding Digital Signal Processing" by Rick Lyons, and start working through it. Or see if Wikibooks has anything equivalent. You'll be rewarded for your effort. -- 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
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)
----------------------------------------


Thanks

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)
----------------------------------------


Thanks

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.
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
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. �����������������������������������������������������������������������
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
------------------------------------------------------------------------------

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. &#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;