CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Low pass filter

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Guest








Low pass filter
PostPosted: Thu Sep 16, 2004 8:30 pm     Reply with quote

Hi all!
I'm currently having problem with my program to use LPF?
how to set the constant value, to get the output?
and which comes first-A/D or filtering?
thanks
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Sep 17, 2004 1:29 pm     Reply with quote

For a low-pass filter, you can use a simple R-C circuit in front
of the A/D input pin on the PIC.
http://www.gamry.com/App_Notes/ReferenceElectrodes/RC_Filter.htm
Or you can use an active filter with an OpAmp. Do a search on Google
for that.

For software filters, look in the Code Library forum on this site.
http://www.ccsinfo.com/forum/viewtopic.php?t=19509&highlight=filter
Guest
Guest







LPF
PostPosted: Sat Sep 18, 2004 1:00 pm     Reply with quote

If you want to prevent aliasing of unwanted higher frequency components into your signal, you must use the LPF BEFORE you use the ADC. Once the undesired signal is in your samples, it is impossible to get rid of it. Most people forget this, thinking that if they have satisfied the Nyquist sampling rate criteria, all their problems are solved.....

If you want to simply smooth out a signal with random electrical noise, you may be able to get away with LPF after the ADC. Grab lots of samples and average them in the micro. Averaging is just LPF.

If you have a scope, grab some data and pump it into Matlab or your favorite code to simulate LPF before/after ADC, the effects of the LPF time constants, etc. If you have filter design software, you can design and simulate some efficient IIR filters that can then be coded into the PIC. Make sure you measure the latency of the filter, too, not just the cutoff frequency. After the ADC starts grabbing samples, it takes time for the filtered data to arrive at the output of the signal procesing chain. This delay may be unacceptable for certain applications...

Have fun!
guest
Guest







PostPosted: Sun Sep 26, 2004 10:15 pm     Reply with quote

i'm doing digital filter.
could anyone help me if there's any sourcecode on that?
how to set the length, the coefficent, the pastinput etc..
and what 's parameter should we use for the calculation?
i'm doing Low pass filter
thanks buddy
Guest again
Guest







LPF
PostPosted: Sun Sep 26, 2004 11:16 pm     Reply with quote

Yikes! There are so many types of digital filters. Most people use (I believe) some type of code or filter design software. Since there are so many types of filters, the software has many inputs. For example, you may select if you want to use a filter that has feedback (IIR) or not (FIR). (IIRs are very efficient but may become unstable due to the feedback - good software will tell you if your design is stable.) You select your sampling rate, cutoff frequencies, equi-ripple filter or not, filter length, etc. At the end of this, you will get a list of coefficients for the filter taps that you can then code (I have skipped about 87 steps here). But remember that most of these tools use fairly high precision math (32-bit? 64-bit? of Wintel) for the coefficients. An IIR designed and found stable with 64-bit coefficients may not work so well with 8- or 16-bit coefficients available on a micro - and floating point multiplies eat up time.

The only real tool I have used for digital filter design comes with Matlab's Signal Processing Toolbox. And then the filters were used on WIndows CE systems or Intel CPUs, not micros. When it comes to PICs and LPFs, I usually use a pretty mundane moving-average filter or maybe something like a median filter: store several (an odd number is easiest) ADC samples, sort them, and then the output is the middle value of the sorted list. Fancy filters, or those with many taps and floating point coefficients, eat up lots of the micro resources and in that case I think a hardware filter is better; put it before the ADC.

Check the Microchip website and see if the have any LFP app. notes. And then google around for filter design software. The Matlab toolbox is great for learning about filters.

Have fun,
Bill
guest
Guest







PostPosted: Mon Sep 27, 2004 7:29 pm     Reply with quote

thanks bill for the reply.
now i do hv the sampling rate, the cutoff frequency.
how to get the coefficient value? how to get the taps (what is it actually?)
is it better for me to use FIR instead of IIR for LPF?
and how to apply all these variables to our coded?

thanks
Bill T.
Guest







LPF
PostPosted: Tue Sep 28, 2004 1:39 am     Reply with quote

Too many difficult questions, beyond the scope of this forum, not enough information, and you want it for free! (Seriously though, if you send me your specifications, and pay, I can design a filter for your application.)

Short lesson, but I may be a little rusty since its been a long time since I did the theory. Assume your ADC samples are x[1], x[2], x[3], ..., x[N] where N is time. The output of a simple moving average filter of length 4 is therefore: y[t] = (x[t - 1] + x[t - 2] + x[t - 3] + x[t - 4])/4, where t is the current output time. This is basically a shift register. Each register or "tap" holds a different ADC value for each sample in time. Very easy to code.

Another version is: y[t] = (x[t - 1] + 2*x[t - 2] + 2*x[t - 3] + x[t - 4])/6. Notice here that the two central taps have more weight than the first and last taps - they have a value of 2. This is a simple moving average filter that gives less weight to the oldest and newest samples, and more weight to the "intermediate" samples. It has a different frequency response than when all taps have equal weight. These tap weights are the coefficients I was talking about earlier, and the taps are the samples from the ADC. Notice that y[t] is a function of x[t] only - the past ADC samples, There is no feedback. It is therefore an FIR filter. Kill the input - turn off x - and y will eventually go to zero.

Then there's something like y[t] = (x[t - 1] + x[t - 2] + 1.09 * y[t - 1])/3. The output is a function of the ADC values, as well as a previous output at y[t - 1]. This is an IIR filter. IIR filters usually have many less taps than an FIR design - by up to a factor of 5, 6, 7...! Downside is that they may not be stable. I've seen FIRs with 50 or more taps and coefficients - usually implemented in ASICS, FPGAs or DSPs.

Many good books on this stuff are out there. Don't mean to discourage you, but if you have tight requirements (sample rate, low latency needed, etc.) it is a time consuming process to design numerous filters with many tradeoffs (latency, number of taps, FIR vs. IIR, etc), code them, and then see how your device or product behaves before you decide which one to use.
guest
Guest







PostPosted: Wed Sep 29, 2004 1:21 am     Reply with quote

Hi Bill..
wow..i wish i had the money to pay you Smile
thanks buddy..but still i stuck...
Guest
Guest







LPF
PostPosted: Wed Sep 29, 2004 11:43 pm     Reply with quote

What you need is out there. For example:

http://ww1.microchip.com/downloads/en/AppNotes/00852a.pdf
Mark M.
Guest







LPF
PostPosted: Thu Sep 30, 2004 10:29 am     Reply with quote

We did a lot of signal processing with PIC's, including pattern recognition, digital radio for VLF etc. They run as fast as they could ( 20 MHz and 40 MHz for PIC18). I am not trynig to boast here but those things are possible to do using PICs. Of course one has to realize limitations of the hardware.
First of all you have to know a bit more about your signal and what you want to extract. If you are looking at RF, then PIC is not the best choice. But some audio and lower frequencies are ok. I started with an excellent tutorial about DSP techinques titled "The scientist and engineer's guide to DSP" by Steven W. Smith. This book is available on line, at no cost at his web page and explains everything nicely:

http://www.dspguide.com/pdfbook.htm

Try it out, it really is a great book!

Regards
Mark M.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group