The important bit of the code in the minimal filter example is this line:
[b a] = butter(1, [0.01 0.1]);
so we need to look at it very carefully one component at a a time.
butter is short for Butterworth and refers to Stephen Butterworth (1885–1958, British physicist and engineer who developed the particular type of filter we are using here); 'butter' is just the name of the Matlab function that designs the filter.
[0.01 0.1]
are the upper and lower frequencies allowed through by the filter.
Why are these frequencies not stated in Hz? It is not obvious, but the 'butter' function doesn't know what the sample rate of the sound is, and therefore cannot work to a frequency. The 0.01 and 0.1 are multiples of the Nyquist Frequency, which you can think of (informally) as the maximum possible frequency in the signal. In our case the Nyquist frequency is 8kHz as it is half the sample rate (16kHz).
So the range of frequencies allowed through by the filter is from:
(0.01 * 8000) = 80Hz
up to:
(0.1 * 8000) = 800Hz
a range that easily allows through the low frequency (220Hz) and blocks the high frequency (1760Hz).
The final argument 1 is the order of the filter. This decides how 'picky' the filter is about frequencies outside the allowed range. The higher the order, the sharper the distinction made by the filter. You can hear the difference this makes by just changing this number and running the minimal filter script again.
The numbers on the right hand side are those we provide to the function. Those on the left are the values that are returned to us by the function and are a bit more tricky to explain.
If you look at the [b a]
values you will find that they are:
a = [1, -1.7421 ,0.75082]
b = [0.12459, 0, -0.12459]
We know that the sound is represented by a series of values, or samples, each separated by a short delay - the a and b values are multipliers that implement the filter by multiplying the sample values to create a new set of output samples.
We can draw a simple picture of what is happening. The incoming signal x is transformed in to the filtered signal y by using the a and b multipliers as shown below.
The 'b' multipliers on the left of the diagram work on the current input value, and the previous two input values of the signal. Current values become previous values as indicated in the picture by passing through the 'D' or 'delay' boxes. The 'a' multipliers work on the output sample and the delayed output samples. Because of this 'feedback' loop this sort of filter is called 'recurrent'.