In the previous section, we have seen some basic filters and their applications. In this section, we shall cover some basic approaches to filter design using MATLAB.
We can use the MATLAB command "butter" to design a Butterworth low-pass filter, with the following format:
[b, a] = butter(order, wn, function) The input arguments to butter can be explained next:
- order: order of the filte. A larger order leads to a better filtering effect. However, the required computing time is also proportional to the order since the the length of the parameters a and b is equal to order+1。
- wn: normalized cutoff frequency within the range of 0 and 1. When the sample frequency is fs, the maximum allowable frequency in frequency-domain processing is fs/2. Therefore the normalized cutoff frequency wn is equal to the real cutoff frequency divided by fs/2.
- function: a string representing the filter function, which could be 'low' or 'high', representing low-pass and high-pass, respectively.
In the next example, we use the command "butter" to design a Butterworth low-pass filter.
In the above example, we have designed a Butterworth filter with a cutoff frequency of 1000 Hz. The plot is the magnitude frequency response of the filter.When the order of the filter is bigger, the filtering effect is better at the cost of longer computation time. On the other hand, a smaller order leads to a shorter computation time and less desirable filtering effect. The following example demonstrates the magnitude frequency response as a function of the order of the Butterworth filter.
As it is obvious in the above example, when the order is increased from 1 to 8, the magnitude frequency response is becoming sharper at the cutoff frequency of 1000 Hz.We can apply the above filter to a clip of a pop song to see if the high-frequency components can be removed. See the next example.
We can hear the original and the output clips:The playback of the output signal demonstrates that the high-frequency components are eliminated from the original signal.
- Original signal x[n]:example/wubai_solicitude_orig.wav
- Output signal y[n]:example/wubai_solicitude_1000.wav
If we set up the cutoff frequency to 100 Hz, then the output signal is almost inaudible unless we have a speaker with a subwoofer. See the next example.
Obviously, after the low-pass filter at a cutoff frequency of 100 Hz, most of the sounds are removed except for those from the bass drum.
- Original signal x[n]:example/wubai_solicitude_orig.wav
- Output signal y[n]:example/wubai_solicitude_100.wav
If you cannot identify the sounds of the bass drum, you can hear the playback of the following clips one by one. (If you use CoolEdit for playback, the progress bar can help you identify where the sounds of the bass drum are.)
In fact, by supplying appropriates input parameters, we can use the command "butter" to design four types of filters, including low-pass, high-pass, band-pass, band-stop filters. The following example plots typical frequency responses of these filters.
- Original signal:example/wubai_solicitude_orig.wav
- Cutoff frequency = 1000 Hz:example/wubai_solicitude_1000.wav
- Cutoff frequency = 500 Hz:example/wubai_solicitude_500.wav
- Cutoff frequency = 400 Hz:example/wubai_solicitude_400.wav
- Cutoff frequency = 300 Hz:example/wubai_solicitude_300.wav
- Cutoff frequency = 200 Hz:example/wubai_solicitude_200.wav
- Cutoff frequency = 100 Hz:example/wubai_solicitude_100.wav
Audio Signal Processing and Recognition (音訊處理與辨識)