Go Down

### Topic: Question on Filters (Read 3778 times)previous topic - next topic

#### orly_andico

##### May 06, 2013, 05:25 pm
I just discovered this useful page:
http://www.schwietering.com/jayduino/filtuino/

Now I am reading encoder position and would like to smooth out spikes. But more than that, I want to get rid of long-term slow trends.

e.g. I am sampling at 1Hz rate.  I only want to see signals from 1/500Hz to 1/20 Hz.

So using the above site I built a 4th-order Butterworth bandpass filter and.... it doesn't work.

The filtered value slowly goes to infinity.  By this I assume the filters produced in the above site are IIR filters.

Questions:

1) I notice that these filters only keep a history of 10-12 past values.  How can they filter out something like 1/500 Hz?  Is that even possible?  (I'm thinking if there's a Nyquist frequency for high frequency cutoff, is there also something for low-frequency cutoff)

2) There's code floating around here for an FIR filter.. but where can I get the filter coefficients?

#### kanurys

#1
##### May 06, 2013, 05:33 pm
Maybe you could use a moving average, which acts like a tune-able low pass filter and then subtract it out. Google moving average.

#### orly_andico

#2
##### May 06, 2013, 06:57 pm
Yes I've tried that. Thing is I need to remove all frequencies below 1/500 Hz but keep the ones above. It is non-obvious how to specify the transition frequency of a moving average, which is simply a low-pass filter (convolving with a top hat function).

#### Magician

#3
##### May 06, 2013, 08:40 pm
Quote
1) I notice that these filters only keep a history of 10-12 past values.
Not correct, with IIR - infinite recursion
How can they filter out something like 1/500 Hz?  Is that even possible?  (I'm thinking if there's a Nyquist frequency for high frequency cutoff, is there also something for low-frequency cutoff)
Good question. There is limits on lower end, due float / uCPU resolution. It was noted, that arduino is capable to calculate down to 7/8 digits after comma, and when you driving as low as 1/500 Hz, you need better than that. 32-bits or even 64-bits math, which is quite complicated itself, and you 'd not wish to mix with already complex filter design.
The best practice, is keep a "window" at the upper end, decreasing sampling rate. In your case, better to reduce sampling down to 1/10 sec, so upper limit 1/20 in agreement with Shennon-Kotel'nikov theorem, than lower end 1/ 50 to sampling would much easier to calculate with lower required resolution math

2) There's code floating around here for an FIR filter.. but where can I get the filter coefficients?

http://www.exstrom.com/journal/sigproc/
http://arduino.cc/forum/index.php/topic,115139.0.html
http://www.musicdsp.org/archive.php?classid=3#195
http://www-users.cs.york.ac.uk/~fisher/mkfilter/
http://www.dsprelated.com/resources.php
http://www.dspguru.com/

IMHO, there is nothing better than FFT for band pass filtering, explained here:
http://coolarduino.wordpress.com/2012/06/28/stereo-audio-vu-meter-on-arduino/

#### MarkT

#4
##### May 06, 2013, 11:10 pm
Standard band-pass filters assume the band is narrower than the frequency of interest, I think
that's why the site isn't giving you want you need.

If you want to cut both high frequencies and low frequencies, cascade a low-pass and a high-pass
filter...
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

#### MarkT

#5
##### May 06, 2013, 11:11 pm
Quote
Not correct, with IIR - infinite recursion

IIR stands for infinite impulse response, in case anyone was confused by that statement.
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

#### orly_andico

#6
##### May 07, 2013, 10:07 am
Hmmm.

I wrote up the same functions in Processing and got better results (must be the higher precision of a PC compared to an Arduino).

I did realize that if I lower my sampling rate, I will need a less aggressive alpha to filter out the very low frequency that I want.

The challenge is that if I sample at 1/10 Hz, I won't be able to catch any errors that occur at a higher frequency than once in 10 seconds.

I guess I could decimate my data for the very-low-frequency filter...

#### Magician

#7
##### May 07, 2013, 11:17 pm
Quote
I guess I could decimate my data for the very-low-frequency filter...

No, you can't

Go Up