- #1
jasonc
- 6
- 0
I am reading some noisy data from external sensors and trying to smooth it out. I know very little about discrete filters. When looking at my data in my plotting program (kst), I applied a low-pass filter and it looked great so I tried to implement a similar filter in my own software. In the plotter program, it was described as a "zero phase low-pass filter with a butterworth amplitude response", I set order to 4 and cutoff frequency to 0.005 (as a fraction of the sample rate - my sample rate is 189 Hz so this works out to about 1Hz - my noise is roughly 6Hz).
I searched around the internet for Butterworth filter calculators and found http://www-users.cs.york.ac.uk/~fisher/mkfilter/trad.html. I entered the following parameters:
It generated the following coefficients and function (C++):
Where xv and yv are both float[5] arrays initially filled with 0's. The results are not ideal. There is a ringing at approximately 0.91 Hz. Here is what it looks like:
http://img821.imageshack.us/img821/6800/filterd.png
The block in the center is the original data with the filter turned off. The left and right portions are the filtered data. The filtered lines should be relatively flat, but instead there is a ~0.91Hz sine-shaped ringing. The ringing is constant amplitude, it does not seem to depend on the data and it does not diminish over time (at least as far as I can tell). Is something wrong with my filter design/implementation? Is Butterworth not the best type of filter to use here? Why does the plotter's built-in filter (not shown above) work so well when mine doesn't?
Thanks!
J
I searched around the internet for Butterworth filter calculators and found http://www-users.cs.york.ac.uk/~fisher/mkfilter/trad.html. I entered the following parameters:
- Type: Butterworth
- Order: 4
- Sample Rate: 189
- Corner Frequency: 1
It generated the following coefficients and function (C++):
Code:
[COLOR=#000080]#define [/COLOR]GAIN [COLOR=#000080]1.367579855e+07[/COLOR]
[COLOR=#808000]float [/COLOR][COLOR=#800080]LowPass[/COLOR][COLOR=#000000]::[/COLOR]next [COLOR=#000000]([/COLOR][COLOR=#808000]float [/COLOR][COLOR=#000000]value[/COLOR][COLOR=#000000]) [/COLOR][COLOR=#000000]{[/COLOR]
[COLOR=#800000] xv[/COLOR][COLOR=#000000][[/COLOR][COLOR=#000080]0[/COLOR][COLOR=#000000]] [/COLOR][COLOR=#000000]= [/COLOR][COLOR=#800000]xv[/COLOR][COLOR=#000000][[/COLOR][COLOR=#000080]1[/COLOR][COLOR=#000000]];[/COLOR]
[COLOR=#800000] xv[/COLOR][COLOR=#000000][[/COLOR][COLOR=#000080]1[/COLOR][COLOR=#000000]] [/COLOR][COLOR=#000000]= [/COLOR][COLOR=#800000]xv[/COLOR][COLOR=#000000][[/COLOR][COLOR=#000080]2[/COLOR][COLOR=#000000]];[/COLOR]
[COLOR=#800000] xv[/COLOR][COLOR=#000000][[/COLOR][COLOR=#000080]2[/COLOR][COLOR=#000000]] [/COLOR][COLOR=#000000]= [/COLOR][COLOR=#800000]xv[/COLOR][COLOR=#000000][[/COLOR][COLOR=#000080]3[/COLOR][COLOR=#000000]];[/COLOR]
[COLOR=#800000] xv[/COLOR][COLOR=#000000][[/COLOR][COLOR=#000080]3[/COLOR][COLOR=#000000]] [/COLOR][COLOR=#000000]= [/COLOR][COLOR=#800000]xv[/COLOR][COLOR=#000000][[/COLOR][COLOR=#000080]4[/COLOR][COLOR=#000000]];[/COLOR]
[COLOR=#800000] xv[/COLOR][COLOR=#000000][[/COLOR][COLOR=#000080]4[/COLOR][COLOR=#000000]] [/COLOR][COLOR=#000000]= [/COLOR][COLOR=#000000]value[/COLOR][COLOR=#000000]/[/COLOR]GAIN[COLOR=#000000];[/COLOR]
[COLOR=#800000] yv[/COLOR][COLOR=#000000][[/COLOR][COLOR=#000080]0[/COLOR][COLOR=#000000]] [/COLOR][COLOR=#000000]= [/COLOR][COLOR=#800000]yv[/COLOR][COLOR=#000000][[/COLOR][COLOR=#000080]1[/COLOR][COLOR=#000000]];[/COLOR]
[COLOR=#800000] yv[/COLOR][COLOR=#000000][[/COLOR][COLOR=#000080]1[/COLOR][COLOR=#000000]] [/COLOR][COLOR=#000000]= [/COLOR][COLOR=#800000]yv[/COLOR][COLOR=#000000][[/COLOR][COLOR=#000080]2[/COLOR][COLOR=#000000]];[/COLOR]
[COLOR=#800000] yv[/COLOR][COLOR=#000000][[/COLOR][COLOR=#000080]2[/COLOR][COLOR=#000000]] [/COLOR][COLOR=#000000]= [/COLOR][COLOR=#800000]yv[/COLOR][COLOR=#000000][[/COLOR][COLOR=#000080]3[/COLOR][COLOR=#000000]];[/COLOR]
[COLOR=#800000] yv[/COLOR][COLOR=#000000][[/COLOR][COLOR=#000080]3[/COLOR][COLOR=#000000]] [/COLOR][COLOR=#000000]= [/COLOR][COLOR=#800000]yv[/COLOR][COLOR=#000000][[/COLOR][COLOR=#000080]4[/COLOR][COLOR=#000000]];[/COLOR]
[COLOR=#800000] yv[/COLOR][COLOR=#000000][[/COLOR][COLOR=#000080]4[/COLOR][COLOR=#000000]] [/COLOR][COLOR=#000000]= [/COLOR][COLOR=#000000]([/COLOR][COLOR=#800000]xv[/COLOR][COLOR=#000000][[/COLOR][COLOR=#000080]0[/COLOR][COLOR=#000000]] [/COLOR][COLOR=#000000]+ [/COLOR][COLOR=#800000]xv[/COLOR][COLOR=#000000][[/COLOR][COLOR=#000080]4[/COLOR][COLOR=#000000]]) [/COLOR][COLOR=#000000]+ [/COLOR][COLOR=#000080]4 [/COLOR][COLOR=#000000]* [/COLOR][COLOR=#000000]([/COLOR][COLOR=#800000]xv[/COLOR][COLOR=#000000][[/COLOR][COLOR=#000080]1[/COLOR][COLOR=#000000]] [/COLOR][COLOR=#000000]+ [/COLOR][COLOR=#800000]xv[/COLOR][COLOR=#000000][[/COLOR][COLOR=#000080]3[/COLOR][COLOR=#000000]]) [/COLOR][COLOR=#000000]+ [/COLOR][COLOR=#000080]6 [/COLOR][COLOR=#000000]* [/COLOR][COLOR=#800000]xv[/COLOR][COLOR=#000000][[/COLOR][COLOR=#000080]2[/COLOR][COLOR=#000000]][/COLOR]
[COLOR=#000000] + [/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000]-[/COLOR][COLOR=#000080]0.9167904003[/COLOR][COLOR=#000000]*[/COLOR][COLOR=#800000]yv[/COLOR][COLOR=#000000][[/COLOR][COLOR=#000080]0[/COLOR][COLOR=#000000]]) [/COLOR][COLOR=#000000]+ [/COLOR][COLOR=#000000]([/COLOR][COLOR=#000080]3.7468029782[/COLOR][COLOR=#000000]*[/COLOR][COLOR=#800000]yv[/COLOR][COLOR=#000000][[/COLOR][COLOR=#000080]1[/COLOR][COLOR=#000000]])[/COLOR]
[COLOR=#000000] + [/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000]-[/COLOR][COLOR=#000080]5.7431439716[/COLOR][COLOR=#000000]*[/COLOR][COLOR=#800000]yv[/COLOR][COLOR=#000000][[/COLOR][COLOR=#000080]2[/COLOR][COLOR=#000000]]) [/COLOR][COLOR=#000000]+ [/COLOR][COLOR=#000000]([/COLOR][COLOR=#000080]3.9131302238[/COLOR][COLOR=#000000]*[/COLOR][COLOR=#800000]yv[/COLOR][COLOR=#000000][[/COLOR][COLOR=#000080]3[/COLOR][COLOR=#000000]]);[/COLOR]
[COLOR=#808000] return [/COLOR][COLOR=#800000]yv[/COLOR][COLOR=#000000][[/COLOR][COLOR=#000080]4[/COLOR][COLOR=#000000]];[/COLOR]
[COLOR=#000000]}[/COLOR]
Where xv and yv are both float[5] arrays initially filled with 0's. The results are not ideal. There is a ringing at approximately 0.91 Hz. Here is what it looks like:
http://img821.imageshack.us/img821/6800/filterd.png
The block in the center is the original data with the filter turned off. The left and right portions are the filtered data. The filtered lines should be relatively flat, but instead there is a ~0.91Hz sine-shaped ringing. The ringing is constant amplitude, it does not seem to depend on the data and it does not diminish over time (at least as far as I can tell). Is something wrong with my filter design/implementation? Is Butterworth not the best type of filter to use here? Why does the plotter's built-in filter (not shown above) work so well when mine doesn't?
Thanks!
J
Last edited: