|
|
View previous topic :: View next topic |
Author |
Message |
Guest
|
Low pass filter |
Posted: Thu Sep 16, 2004 8:30 pm |
|
|
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
|
|
|
Guest Guest
|
LPF |
Posted: Sat Sep 18, 2004 1:00 pm |
|
|
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
|
|
Posted: Sun Sep 26, 2004 10:15 pm |
|
|
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 |
Posted: Sun Sep 26, 2004 11:16 pm |
|
|
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
|
|
Posted: Mon Sep 27, 2004 7:29 pm |
|
|
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 |
Posted: Tue Sep 28, 2004 1:39 am |
|
|
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
|
|
Posted: Wed Sep 29, 2004 1:21 am |
|
|
Hi Bill..
wow..i wish i had the money to pay you
thanks buddy..but still i stuck... |
|
|
Guest Guest
|
|
|
Mark M. Guest
|
LPF |
Posted: Thu Sep 30, 2004 10:29 am |
|
|
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. |
|
|
|
|
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
|