Talk About Network

Google





Electronic Equipment > Digital Signal Processing (DSP) > Re: Low pass fi...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 3 of 7 Topic 14035 of 14426
Post > Topic >>

Re: Low pass filter on a PIC

by Tim Wescott <tim@[EMAIL PROTECTED] > Oct 10, 2008 at 07:18 PM

On Fri, 10 Oct 2008 17:11:25 -0400, Jerry Avins wrote:

> Manfred wrote:
>> Hi all!
>> 
>> Tim,
>> 
>>> You want a simple first-order lowpass IIR filter.  You can implement
>>> it
>> 
>> in one line of C:
>> 
>>> output = gain * (input - output);
>> 
>> Either there is some mistake in this, or I'm doing something wrong, but
>> I'm not getting any attenuation of high frequency components with this.
> 
> It puzzled me too, but I've learned to question myself before I question
> Tim. Try the exponential averager I described. Making k small produces
> the greatest reduction of highs. You might start with k = 1/2. All
> fractions of the form (2^n - 1)/2^n, where (for 16 bit words) 1 < k < 15
> allows efficient computation.
> 
If Jerry doesn't understand it, I didn't explain it well.

Take gain = 0.1, input is constant 1, and output starts at 0.  Then you 
should get:

step    output
0       0
1       0.1
2       0.19
3       0.271
n       1 - 0.9^n

>>> A 20Hz cutoff is pretty high for a sampling rate of 50Hz -- you're not
>>> going to get much attenuation of your noise.
>> 
>> The sampling rate is 100Hz. I might lower the cutoff further. But the
>> previous implementation of this controller, done in the analog world,
>> used 20 Hz with good results. But that was a third order filter.
> 
It's still high, even for a 100Hz sampling rate -- but not nearly as bad.

> To measure entire periods, the sample rate should be 50 Hz. There is no
> assurance that alternate half cycles have the same duration.
> 

Gin up a filter with a transfer function (z + 1)/(z - d), with d close to 
1.  That'll let you update at 100Hz while rejecting the noise at 50Hz, 
yet still giving you good response at somewhat lower frequencies.

>>> Keep in mind that as you lower the filter bandwidth you'll have to
>>> back
>> 
>>> off your pro****tional and integral gains to keep the loop stable.
>> 
>> I know. That's also why I don't want to lower the cutoff frequency too
>> much.
>> 
>>> You may also find that you need to use more than 16 bits in the filter
>> to
>>> maintain enough precision
>> 
>> That would be a problem, because in the programming language I'm using,
>> I only have 16 bit integers, and no carry bit.

Then get another programming language!  If it's C, and it's remotely ANSI 
C compatible, then 'long' will be 32 bits.

> The assembly routine to filter in extended precision is rather
> straightforward. The technique we call fraction saving around here may
> allow you to limit the amount of code that needs extended precision.
> http://www.dspguru.com/comp.dsp/tricks/alg/dc_block.htm
describes a
> high-pass filter with fraction saving.
> 
>    ...

You can extend precision in most any programming language if you can 
stand the tedium -- but it's often easier to do things in assembly.


-- 

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

Do you need to implement control loops in software?
"Applied Control Theory for Embedded Systems" gives you just what it says.
See details at http://www.wescottdesign.com/actfes/actfes.html
 




 7 Posts in Topic:
Re: Low pass filter on a PIC
"Manfred" <m  2008-10-10 14:56:54 
Re: Low pass filter on a PIC
Jerry Avins <jya@[EMAI  2008-10-10 17:11:25 
Re: Low pass filter on a PIC
Tim Wescott <tim@[EMAI  2008-10-10 19:18:38 
Re: Low pass filter on a PIC
"Manfred" <m  2008-10-10 21:22:03 
Re: Low pass filter on a PIC
Jerry Avins <jya@[EMAI  2008-10-10 23:38:15 
Re: Low pass filter on a PIC
Jerry Avins <jya@[EMAI  2008-10-10 23:29:33 
Re: Low pass filter on a PIC
Tim Wescott <tim@[EMAI  2008-10-11 01:26:09 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
localhost-V2008-12-19 Thu Jan 8 21:41:38 PST 2009.