views:

60

answers:

2

Hi, all --

I've got code to calculate IIR filter coefficients, but they seem to lead to a really strange output. This is what the data looks like: sampled at 1 KHz with a 7 Hz excitation oscillation on top of it. I'd like to make the filter so that it filters with a cutoff frequency of 1 Hz.

Based on what I have read on the web, to calculate the cutoff frequency in fractions of PI, the equation is 2 * fc / fs, leading to a cutoff frequency of 0.002. First off, is that correct? That value gives me coefficients that lead to values that are about three orders of magnitude smaller than I would have expected. Second, when I plot the output of the filter on an array of 250 points, I expect a (mostly) flat line, but I get something that actually looks like an exponential into the negative. That can't be right...can it?

I apologize for not knowing that much about filters here. It would be nice if somebody had an answer.

Thanks -- Robert

A: 

Firstly, yes, the normalized frequency is 0.002, if fs = 1 kHz and fc = 1 Hz.

You don't say what software you used to calculate the coeffs, what the coeffs actually are, and what IIR form you are using to realise the filter. Note that filters can get tricky when fc << fs though - try a more reasonable fc first, e.g. 100 Hz, to see if that behaves acceptably - that will tell you whether your methods are sound and/or whether things are blowing up when fc gets too small.

Paul R
Paul --Thanks for the reply. The software that I initially used to calculate the coefficients was the mkfilter software at http://www-users.cs.york.ac.uk/~fisher/mkfilter. What I have in my current software (verified by mkfilter) is a C algorithm I got from Exstrom. I did try a larger fc and, sure enough, things seem to come through. Obviously, it's still got the 7 Hz oscillation on top. So if filters get weird when fs >> fc, is there another type of filter that I should be using? The application I am working toward here is a software-base lock-in amplifier.
rdherric
Paul -- ran out of room above. The coefficients that I get are monstrously small for the feedforward part of the difference equation. Like 10e-13. IIR form? I'm not sure what that means. I'm looking at a 5th-order Butterworth low-pass filter. Is that what you mean?
rdherric
@rdherric: it's hard to tell but it sounds like mkfilter may be giving bad coefficients for low fc. One common approach to problems like this is to downsample the data initially - this requires a low pass filter followed by decimation. E.g. you could downsample by a factor of 10 if you implement a low pass filter with 50 Hz cut-off and then throw away 9 out of 10 samples. This then gives you a sample rate of 100 Hz instead of 1 kHz and your 1 Hz low pass filter may then be less of a problem to implement.
Paul R
@Paul: that's exactly what I tried just after I posted the above. I downsampled the data to 10x the excitation frequency and upped the cutoff frequency. I can definitely discern a filter effect, although it still appears strange. Thanks very much for the idea and the help. I think that I'm closer to a solution now.
rdherric