Forums

How to compute the response to a filter ?

Started by Guillaume Dargaud May 11, 2009
Hello all,
well, it's been exactly 10 years since I last posted to this group, so my 
signal processing skills are rusty to say the least.

I've just implemented a basic IIR 2nd order low-pass butterworth filter in C 
and it's not working properly (coefs are correct). I know it's the very 
basics so I want to trace its response and compare it to standard responses 
I can find easily on the web.

What is the standard way to compute a filter response ? I have an array with 
the original signal, I filter it, I get the result. What do I do now ?

Is there an array of sample test values somewhere I can compare it to, 
before and after ?

Thanks.
-- 
Guillaume Dargaud
http://www.gdargaud.net/ 


On May 11, 7:57�am, "Guillaume Dargaud"
<use_the_form_on_my_contact_p...@www.gdargaud.net> wrote:
> Hello all, > well, it's been exactly 10 years since I last posted to this group, so my > signal processing skills are rusty to say the least. > > I've just implemented a basic IIR 2nd order low-pass butterworth filter in C > and it's not working properly (coefs are correct). I know it's the very > basics so I want to trace its response and compare it to standard responses > I can find easily on the web. > > What is the standard way to compute a filter response ? I have an array with > the original signal, I filter it, I get the result. What do I do now ? > > Is there an array of sample test values somewhere I can compare it to, > before and after ? > > Thanks. > -- > Guillaume Dargaudhttp://www.gdargaud.net/
Are you looking to do this computationally or analytically? If you are looking to test the correctness of your implementation, a good first test consists of: * Making input signals that are all zero except for a single non-zero value. Then change the amplitude and position, verify that the filter is linear and shift-invariant. For example, if you delay the input by say 4 samples, then the output should also be delayed by same amount. * Put in input signals that are sinusoids at different frequencies, see if the output is also sinusoid at same frequency (except for initial conditions). Hope this helps, I'm not exactly sure what you are looking to do. Julius
Guillaume Dargaud wrote:
> Hello all, > well, it's been exactly 10 years since I last posted to this group, so my > signal processing skills are rusty to say the least. > > I've just implemented a basic IIR 2nd order low-pass butterworth filter in C > and it's not working properly (coefs are correct). I know it's the very > basics so I want to trace its response and compare it to standard responses > I can find easily on the web. > > What is the standard way to compute a filter response ? I have an array with > the original signal, I filter it, I get the result. What do I do now ? > > Is there an array of sample test values somewhere I can compare it to, > before and after ? > > Thanks.
Why not just a series of sine waves at different frequencies, to compare to frequency response plots? If you're concerned about implementation, try at least three different amplitudes -- really small, really big, and 'this has got to be safe'. That'll test your implementation against over- and underflow. -- Tim Wescott Wescott Design Services http://www.wescottdesign.com Do you need to implement control loops in software? "Applied Control Theory for Embedded Systems" was written for you. See details at http://www.wescottdesign.com/actfes/actfes.html
On May 11, 7:57&#2013266080;am, "Guillaume Dargaud"
<use_the_form_on_my_contact_p...@www.gdargaud.net> wrote:
> Hello all, > well, it's been exactly 10 years since I last posted to this group, so my > signal processing skills are rusty to say the least. > > I've just implemented a basic IIR 2nd order low-pass butterworth filter in C > and it's not working properly (coefs are correct). I know it's the very > basics so I want to trace its response and compare it to standard responses > I can find easily on the web. > > What is the standard way to compute a filter response ? I have an array with > the original signal, I filter it, I get the result. What do I do now ? > > Is there an array of sample test values somewhere I can compare it to, > before and after ? > > Thanks. > -- > Guillaume Dargaudhttp://www.gdargaud.net/
The others made some good sugestions, but also try feeding it a simple Kronceker Delta. I.e., feed in a 1 followed by a stream of zeroes. This will give you the impulse response and then you can do an FFT of this response to get a good approximation to the frequency response. Clay
On May 11, 12:13&#2013266080;pm, c...@claysturner.com wrote:
> On May 11, 7:57&#2013266080;am, "Guillaume Dargaud" > > > > > > <use_the_form_on_my_contact_p...@www.gdargaud.net> wrote: > > Hello all, > > well, it's been exactly 10 years since I last posted to this group, so my > > signal processing skills are rusty to say the least. > > > I've just implemented a basic IIR 2nd order low-pass butterworth filter in C > > and it's not working properly (coefs are correct). I know it's the very > > basics so I want to trace its response and compare it to standard responses > > I can find easily on the web. > > > What is the standard way to compute a filter response ? I have an array with > > the original signal, I filter it, I get the result. What do I do now ? > > > Is there an array of sample test values somewhere I can compare it to, > > before and after ? > > > Thanks. > > -- > > Guillaume Dargaudhttp://www.gdargaud.net/ > > The others made some good sugestions, but also try feeding it a simple > Kronceker Delta. I.e., feed in a 1 followed by a stream of zeroes. > This will give you the impulse response and then you can do an FFT of > this response to get a good approximation to the frequency response. > > Clay- Hide quoted text - > > - Show quoted text -
After you have determined if you do in fact have a linear system, which was suggested earlier, if you are going to do this approach then you need to use an FFT that is sufficiently long that the response you are truncating is totally insignificant (I would make the FFT many times what I thought was adequate); and of course do not apply any other window than that implied by the truncation. Another way that does not require this judgement of adequate FFT size is to derive the fequency response function from the filter and plug in the complex exponentials corresponding to the frequencies you want to evaluate the response at. Dirk
Thanks for the suggestions. I've already done the sine simulations, which 
works fine in simulation but doesn't when the signal is from a real ADC, so 
I must have a bug somewhere else.
-- 
Guillaume Dargaud
http://www.gdargaud.net/


On May 12, 4:48&#2013266080;am, "Guillaume Dargaud"
<use_the_form_on_my_contact_p...@www.gdargaud.net> wrote:
> Thanks for the suggestions. I've already done the sine simulations, which > works fine in simulation but doesn't when the signal is from a real ADC, so > I must have a bug somewhere else. > -- > Guillaume Dargaudhttp://www.gdargaud.net/
Is your filter implementation fixed point or floating point? Is the simulated data and ADC'ed data scaled the same? Is your ADC output 2's complement, offset binary or something else? Are you processing one point at a time from the ADC, or using ping- pong buffers, or something else? Are you doing anything to be sure you are not losing data points while you are busy processing? Instead of filtering the signal from the ADC, try capturing the ADC data and processing it with the filter non-real-time. That will help narrow down if you have a data capture/format problem or really a filter problem. Dirk