Anyway, if you've read part 1, hopefully you've got some really key concepts down: All a filter does is combine a signal with delayed and scaled copies of itself. Delay for a digital filter is in samples, and can be as small as a single sample, or as large as... however large you want the delay, I guess within reason. There are things called filter coefficients, which determine how different components are scaled. There are two flavours of filter - feedforward and feedback/

Last time we only looked in depth into the first order filter, say y(n) = 0.5(x(n)+x(n-1))... This is known as a first order, averaging filter, and is feedforward because it doesn't recycle the output. First order filters are the simplest types of filter, and can only really be used as simple low or high pass filters. What this means, if we say we're using a low pass filter, is we only let the low frequencies past, and kill (or attenuate) the high end frequencies. A 20Hz sine wave is unaffected, whereas a 20,000Hz signal would come out at 0 amplitude (or really close).

I'll come back to the first order filter for a bit of maths (optional and put at the end to avoid losing readers). Second order filters have up to a 2 sample delay, so as an example y(n) = x(n) + 0.5x(n-1) - 0.3x(n-2). The filter equation I just wrote has no real significance, just some random numbers. There is a useful class of second order, feedback filters, called resonators, that work as low-pass, high-pass and band-pass or band-reject filters. Band-pass means the filter lets a certain "band" of frequencies through unaffected, and kill frequencies either side. There are a few of these filters prepackaged, so you just have to calculate the coefficients based on a few things, like the frequencies you want.

There are clearly filters with bigger delays - ones that are used for reverbs etc. but I'll leave these out this time. More interestingly, it is possible to have a filter with a changing delay length. You can create a pitch shift, as seen in the Doppler effect) by having a delay length that increases or decreases. Maybe you're wondering about flange, a funky and unusual filter. A flanger is created by using a LFO (low frequency oscillator) to control the length of delay. This idea may be a bit mindblowing, but in code it's more intuitive. Code will be coming in the next installment.

For anyone who was wondering about the maths of some of this, due to the blog's lack of maths font, here is my slightly uglier solution. Knowledge of imaginary numbers and Euler's identity is needed, but if you don't have this, I'm going to explain it in much more detail another time.

If you don't understand this (and want to) I'll explain imaginary numbers and stuff at some other point! |

So, remembering to rescale by 0.5, plotting amplitude response against frequency looks something like this:

## No comments:

## Post a Comment