Homework Eleven

From Class Wiki
Jump to navigation Jump to search

Present an Octave (or Matlab) example using the DFT


Nick Christman


For my example of DFT, I have chosen to demonstrate digital filtering.

The process of digital filtering in Matlab is quite simple. To demonstrate this I must first obtain an original signal and I have chosen to use Audacity to create a short, four second clip of an electronic-genre music file. The artist is known as Air and the song I have chosen is "Electronic Performers." After this, I had to create a noisy signal and to accomplish this I simply super-imposed a sum of sine and cosine waves over the original signal (i.e. I literally added noise to my original signal). This is the Matlab code I used to accomplish these tasks:

close all;
clear all;

% Constants to scale noise
a = 50;         % noise amplitude a
b = 50;         % noise amplitude b
c = 50;         % noise amplitude c
n = 10000000;   % frequency scaling factor

tune = 'audio1.wav';         % location/name of .WAV file

[audio fs] = wavread(tune);  % turn .WAV file into binary format and get the sampling frequency

[N C] = size(audio);         % Get the number of rows and columns of the audio matrix

t = 0:(N-1);
noise = a*sin(fs*t/n) + b*sin(fs*t/n) + c*sin(fs*t/n);  % create some noise!
noise = [noise' zeros(N,1)];                            % reformat the noise to match the dimensions of the audio matrix
noisy = audio + noise;                                  % create the noisy signal by adding the noise to the audio matrix

Here is the original signal: Original.ogg

Here is the noisy signal: Noisy.ogg

Note: Because this is audio and not video, you will have to set your browser to download .ogg files (Tools > Options > Applicaitons tab > change action for .ogg to "Save File"

At this point, we have an original signal called audio and a noisy signal called noisy, we also have a desired frequency fs. From here, we need to run the noisy signal through an Inverse Fourier Transform and to do this, we will use the Matlab function ifft2 (because it is a two-dimensional matrix). Here is the code I used to accomplish this task and following is the graph for the Inverse Fourier Transform of the noisy function and that of the original function (the noise is so loud that the original function is hard to see):


ift1 = ifft2(audio);
ift2 = ifft2(noisy);

figure(1)
plot(f,abs(ift1))
title('Inverse Fourier Transform of Clean Audio');
ylabel('Magnitude of Original Signal');
xlabel('Frequency, Hz');
figure(2)
plot(t,abs(ift2))
title('Inverse Fourier Transform of Noisy Audio');
ylabel('Magnitude of Noisy Signal');
xlabel('Frequency, Hz');

Original nick.jpg Noisy nick.jpg

Now we have the coefficients for the FIR filter and simply need to filter the noisy signal using these coefficients (ift2).