Sunday, December 20, 2009

Filters 1.0: frequency response

Okay, so why all this interest in the rather boring subject of convolution functions for filtering? Well, a few things.

The most recent reason is having fun playing with MetriGear Vector data. Sure, I could have fun playing with PowerTap data (and I actually have a Powertap, while I don't have a Metrigear Vector). But Saris is all hush-hush with its numbers, while MetriGear is much more open: they've for example published data on their excellent blog, and when the pedals go to market, they promise to provide a much higher rate of data reporting than one gets from existing meters, typically one sample per second (or the Powertap famous sample per 1.26 seconds). Additionally the Vector will provide a lot more information.

Of particular interest to me at the moment is how to process accelerometer data. Accelerometer data tends to be noisy, both from errors in measuring the actual acceleration, and in accelerations other than those of the pedals turning in circles. So to get around this you want to filter the signals.

I filter data all the time, sometimes for work, but also for looking at data from my PowerTap. For example, normalized power and related training stress algorithms use data smoothing, which is a form of low-pass filtering. The normalized power algorithm uses a "square" filter which I don't like much, while the related "X-Power" (and algorithms I've developed myself) use exponential filtering which I substantially prefer. At other times I use Gaussian filters, which are non-causal. But I've recently started playing with the trigonometric functions I've described here.

The most informative plot of a filter is probably the frequency response. When I convolve a smoothing function with data, the spectral distribution of the result is the product of the spectral distribution of the convolution function and the spectral distribution of the data. So the spectral distribution, the Fourier Transform, of the convolution function is the "frequency response" of the filter. In discrete transforms, where the "x-axis" is a number instead of a real quantity like time or distance, a "z-transform" is also used, but I'll stick with the "real" domain of Fourier transforms.

I've been playing around with some filters so far, describing how they deal with input signals which are a perfect sine or cosine function. This is in essence the frequency response. So how do they compare?

Here's a plot of the filters I've described so far, each designed to be a band-pass filter, removing both low and high frequencies:

It can be clearly seen the last filter I described, the one not involving differentiation, is the best at removing high frequencies. Very pleasing. But not so pleasing is the analytic form of this filter. I like trigonometric and exponential functions. They're analytically attractive. They're easy to integrate. They are relatively easy to manipulate. With that "Δt/τ cos²Δt/τ" filter there was some ugly integration by parts I punted on, but even then had to simplify the indefinite integral from Wolfram. But it was pretty good.

Next time I'll look at a few more filters involving only exponential functions, and get dispense with that differentiation step completely.

No comments: