Summary: This development of these labs was supported by the National Science Foundation under Grant No. DUE-0511635. Any opinions, conclusions or recommendations expressed in this material are those of the authors and do not necessarily reflect the views of the National Science Foundation.
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.
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).
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;
>> Xpos=X(1:N/2+1);
>> plot(pfreq,abs(Xpos));
>> figure;
>> freq = [-(N/2-1):N/2]*Fs/N;
>> plot(freq,abs(fftshift(X)));
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.)
x=x(1:length(x)-1);.
ifft will accomplish this task.
>> xnew = real(ifft(X));
You need the real command because the inverse Fourier transform returns a vector that is complex-valued, since some changes that you make in the frequence domain could result in that. If your changes maintain complex symmetry in the frequency domain, then the imaginary components should be zero (or very close), but you still need to get rid of them if you want to use the sound command to listen to your signal.
x with the FFT and the filter definition above.
a. The low-pass filter equation above defines the filter H in the frequency domain. Because the definition assumes the filter is centered around w = 0, the vector w is defined as such.
>> load fall %load in the signal
>> x = fall;
>> X = fft(x); % get the Fourier transform (uncentered)
>> N = length(X);
>> a = 100*2*pi;
>> w = (-N/2+1:(N/2)); % centered frequency vector
>> H = a ./ (a + i*w); % centered version of H
>> plot(w*Fs/N,abs(H))
The plot will show the form of the frequency response of a system that we are used to looking at, but we need to shift it to match the form that the fft gave us for x.
>> Hshift = fftshift(H); % uncentered version of H
>> Y = X .* Hshift'; % filter the signal
' operator transposes vectors/matrices in MATLAB.
>> y = real(ifft(Y));
>> sound(x, Fs) % original sound
>> sound(y, Fs) % low-pass-filtered sound
The filter reduced the signal amplitude, which you can hear when you use the sound command but not with the soundsc which does automatic scaling. Replay the sounds with the soundsc and see what other differences there are in the filtered vs. original signals. What changes could you make to the filter to make a greater difference?
>> y = y * (max(abs(x))/max(abs(y)))
wavread to load the sound castanets44m.wav. Perform low-pass filtering with the filter defined above, starting with a = 500*2*pi, but also try different values.
x(t) using the following MATLAB command,
>> x = repmat([zeros(1, 99) 1], 1, 5);
x(t) and y(t) separately using the subplot command. These should be plotted versus the time vector. Label the axes and title each graph appropriately.
a = 2000*2*pi, but also try different values.
Fs = 8000 Hz). The mixed sound is created from bassdrum.wav, hatclosed.wav, and shake.mat.
mixedsig = shake + 10*rainstick.
mixedsig and process it to get (approximately) only the trumpet sound (shake) out? Try to do something easy but approximate first, and then if you have more time, see how good a reproduction of shake you can get. You may find it helpful to look at Fourier domain of the sounds, but you may not use rainstick.mat or shake.mat in your solution.