<< Chapter < Page | Chapter >> Page > |
In this lab, we will look at the effect of filtering signals using a frequency domain implementation of an LTI system, i.e., multiplying the Fourier transform of the input signal with the frequency response of the system. In particular, we will filter sound signals, and investigate both low-pass and high-pass filters. Recall that a low-pass filter filters out high frequencies, allowing only the low frequencies to pass through. A high-pass filter does the opposite.
help<command>
, online help for a command.fft
, Fast Fourier Transform.ifft
, Inverse Fourier Transform.sound
, plays sound unscaled (clips input to [-1,1]).soundsc
, plays sound scaled (scales input to [-1,1]).wavread
, reads in WAV file. The sampling rate of the WAV file can also be retrieved, for example,
[x, Fs] = wavread('filename.wav')
, where
x
is the sound vector and
Fs
is the sampling rate.All of the sounds for this lab can be downloaded from the Sound Resources page.
When working in MATLAB, the continuous-time Fourier transform cannot be done by the computer exactly, but a digital approximation is done instead. The approximation uses the discrete Fourier transform (more on that in EE 341).
There are a couple important differences between the discrete Fourier transforms on the computer and the continuous Fourier transforms you are working with in class: finite frequency range and discrete frequency samples. The frequency range is related to the sampling frequency of the signal. In the example below, where we find the Fourier transform of the "fall" signal, the sampling frequency is
Fs=8000
, so the frequency range is [-4000,4000] Hz (or 2*pi times that for w in radians). The frequency resolution depends on the length of the signal (which is also the length of the frequency representation).
The MATLAB command for finding the Fourier transform of a signal is
fft
(for Fast Fourier Transform (FFT)). In this class, we only need the default version.
>>load fall %load in the signal>>x = fall;>>X = fft(x);
The
fft
command in MATLAB returns an uncentered result. To view the frequency content in the same way as we are used to seeing it in class, you need to plot only the first half of the result (positive frequencies only) OR use the MATLAB command
fftshift
which toggles between centered and uncentered versions of the frequency domain. The code below will allow you to view the frequency content both ways.
>>N = length(x);>>pfreq = [0:N/2]*Fs/N; % index of positive frequencies in fft>>Xpos=X(1:N/2+1); % subset of fft values at positive frequencies>>plot(pfreq,abs(Xpos)); % plot magnitude of fft at positive frequencies>>figure;>>freq = [-(N/2-1):N/2]*Fs/N; % index of positive AND negative freqs>>plot(freq,abs(fftshift(X))); % fftshift actually SWAPS halves of X here. See help.
% Convince yourself of why it does this to match up with freq!
Note that we are using
abs
in the plot to view the magnitude since the Fourier transform of the signal is complex valued. (Type
X(2)
to see this. Note that X(1) is the DC term, so this will be real valued.)
Notification Switch
Would you like to follow the 'Continuous time linear systems laboratory (ee 235)' conversation and receive update notifications?