## Monday, December 21, 2009

### filters 2.0

I've gone on quite long enough about filters. But I think I'm finally getting it right. So it's my blog, after all, and the whole point is I can write about what I want. So I'm going to stick with filters a bit longer... I'm trying to figure this stuff out for myself.

As I noted last time, after thinking about it, I realized I could do all the filtering I needed with strictly trigonometric functions, and trigonometric functions have attractive mathematical features (particularly, their exceptional smoothness, and their tendency to average to zero). It's just a matter of selecting the function. The goal is to smooth the data (reduce high frequency components) while optionally also reducing low frequency components.

The criteria are:
1. The area of the absolute value of the function should be one.
2. The function needs to transition to zero smoothly, which is to say with a continuous slope, at the edges. This helps to reduce high frequency components.
3. If the function is to attenuate low frequency components, its average value should be zero, else the function should be strictly positive.
4. The function, after being made causal, should have a centroid at time -τ. This is to keep a constraint of constant delay compared with exponential smoothing.
5. If the function is antisymmetric, it should have a positive slope at its center with respect to real time, negative with respect to a Δt which goes into the past. This is a bit arbitrary, but tends to make the function respond positively to positive transitions in the data.

Let me clarify the last point: the process is to define a function which is zero for some t > t0. Then to shift it by ‒t0 such that for all positive (future) times the function is zero. This allows for a causal filter. We want the represent "recent" values of the data so that it responds to changes in the data in "real time" - this is why we want a causal filter. So we want the mean time of the contribution to the result to be τ. The exponential function which fulfills this requirement is exp(-Δt/τ).

So here's the functions I'll pick. In each case the function is non-zero from -τ to τ. Then it can be shifted by -τ to make it causal. This constraint is a bit different than what I've used to this point, the difference by scaling the Δt axis and then scaling the f-axis to keep the area the same.

The first one is one I considered before, with different scaled by π/2, except here I won't do any goofy differentiation. The second is very similar to the "Δt/τ cos² Δt/τ" filter I used before, but this time using only trigonometric functions, no multiplying by Δt/τ. The third is new. It's designed to be particularly good at filtering low frequencies, since it will convert not just a constant value but also a straight line to zero after convolution due to its symmetry.

I'll look at the frequency responses next time.