Lab 4
Lab 4
This lab investigates the effect of high-pass, low-pass, band-pass, and band-stop (notch)
filters on audio. When filters are applied to audio signals, certain frequencies of sound are
attenuated. Music professionals use more complicated filters and equalizers to change the
balance of instruments or to eliminate an unwanted sound. We will apply simpler filters to
music using MATLAB.
4.1 Preparation
Download the following files from the Ufuture website and save it into your MATLAB file
directory:
• timeDomainPlot.m
• frequencyDomainPlot.m
• lab_annoying.wav
• lab_bandpass.wav.
If you want to experiment with filters on your own music, convert the song(s) to WAV format
and clip them to 30 seconds or less. (Longer songs can work, up to a limit, but will take too
long for the purposes of this lab).
Launch MATLAB and change your current directory to the folder containing the m-files and
the music files. Type the following lines into the command prompt:
global player
global stopped
timeDomainPlot('lab_bandpass.wav')
Output (graph):
1
You should hear music playing and see a time-domain plot of the sound’s amplitude.
Now view the frequency-domain plot for the same music clip:
frequencyDomainPlot('lab_bandpass.wav')
Output (graph):
4.2 Syntax
2
Possible filter types are ‘low’, ‘high’, ‘bandpass, and ‘stop’. If you’re using a low-
pass or high-pass filter, w_cutoff is a scalar; if you’re using a bandpass or stop-band filter,
w_cutoff is a two-element array in the form [w1 w2].
Note: To stop a song early, hit the ‘Stop’ button on the lower-left corner of the plot. If you
close the plot in any other way, you must kill the script from the command prompt with CTRL+C,
and pause the audio with pause(player). Also, if you do not have the global variables
player and stopped declared, the ‘Stop’ button won’t work.
Run the frequencyDomainPlot script for the music clip ‘lab_annoying.wav’. Note the
sound and the frequency range. Use a low-pass filter to completely eliminate the annoying
high-pitched sound. (This will take a few iterations of guess-and-check.) What value of
w_cutoff did you use?
Example:
frequencyDomainPlot('lab_annoying.wav', 'low', 500);
Output (graph):
3
4.4 High-pass filters
Run the frequencyDomainPlot script for the music clip ‘lab_annoying.wav’, with a
high-pass filter using the same w_cutoff. What happens?
Example:
frequencyDomainPlot('lab_annoying.wav', 'high', 1000);
Output (graph):
4
4.6 Notch/band-stop filters
Run the frequencyDomainPlot script for the music clip ‘lab_bandpass.wav’, using a
band-stop filter to remove the midrange instrument. What values for w_cutoff work well?
Example:
frequencyDomainPlot('lab_bandpass.wav', 'stop', [200 1500]);
Output (graph):