Sunteți pe pagina 1din 11

3TP4 Lab 4

Signal Analysis Using the Discrete Fourier


Transform
Giuseppe Querques - 0749012

Part 1
2. The sound file tones2015.wav sounds like a high frequency sinusoid, with little
oscillation occurring in the waves amplitude; a singular tone. The resolution at
which a person can hear differences in waveforms is quite limited, so very few
reliable distinctions can be made using auditory senses alone.
3. The Matlab code used for this question was identical to that provided in the
laboratory documentation; the following graph was generated:

4. Approximately three or more distinct sinusoids make up this signal. This


estimation was arrived upon by on the number of peaks that appear in each low
frequency period (two distinct sinusoidal peaks noted per low-frequency amplitude
maxima, meaning there must be a secondary wave, as well as a peak offset
brought on by a tertiary wave creating further modulation ). There could be far more
than three sinusoids creating this signal, however, the absolute minimum would be
three (with unlimited additional waveforms of low amplitude being interlaced).

Furthermore, using rough extrapolations from the graph, the first sinusoid has a
frequency of (1 wavelength/0.58ms period)*1000 = 1720 Hz, the second sinusoid
was approximately twice this frequency value (3340 Hz), and the third sinusoid has
a frequency of roughly twice the second sinusoid (6880 Hz). The approximations for
the second and third sinusoidal frequencies were derived by gauging by the slope
changes between peaks, and concluding that the large upward rising slope was
approximately the same magnitude coming down from the highest peaks, but was
0.25 times in magnitude ascending the secondary peaks, and 0.5 times in
magnitude descending the secondary peaks.
These conclusions were found to be correct (albeit the frequencies were slightly
skewed due to visual estimations) in question 7, where the data used from the DFT
was used to generate the following graph, further exemplifying the accuracy of the
estimated values:

s1 = 0.4*sin(2*pi*2000*t);
s2 = 0.2*sin(2*pi*4000*t);
s3 = 0.2*sin(2*pi*6000*t);
% Plot the signal for t_plot msec
t_plot = 5;
msec_per_sec = 1000;
numSamples = t_plot*Fs/msec_per_sec;
plot(msec_per_sec*t(1:numSamples),
newSignal(1:numSamples), ...
msec_per_sec*t(1:numSamples), s1(1:numSamples), ...
msec_per_sec*t(1:numSamples), s2(1:numSamples), ...
msec_per_sec*t(1:numSamples), s3(1:numSamples))

Dark Blue: Original Signal


Green: 2000 Hz Sinusoid
Red: 4000 Hz Sinusoid
Light Blue: 6000 Hz Sinusoid

5. Using the given Matlab code from the laboratory instructions, the following graph
was generated:

6. As estimated in question 4, the signal was composed of three sinusoids. These


three sinusoids had frequencies of 2000 Hz, 4000 Hz, and 6000 Hz and magnitudes
of 0.4, 0.2, and 0.2 respectively.
7. The following Matlab code (next page) was used to generate a 5 msec duplication
of the original sine wave using a summation of three distinct sines of frequency
2000 Hz, 4000 Hz, and 6000 Hz and magnitudes of 0.4, 0.2, and 0.2 respectively. It
should be noted that a vast majority of this code was given in the laboratory
instructions; only one distinct line was added to the code for the new sine wave
summation. The code was checked using the code for signal plot and DFT plot from
question 3 and 5 respectively. As expected, the generated signal was identical to

the given original waveform. Further analysis was performed using the following
Matlab code to identify the sinusoidal frequencies in the summated sine wave.

% The following four lines were simply left in the code to duplicate the
parameters for reconstructing a 5ms waveform; L, T, and t were the same values
needed for our new 5ms sine wave summation.
[signal, Fs, bits_per_sample] = wavread('tones2015.wav');
L = length(signal);
T = 1/Fs;
t = [0:L-1]*T;
%the following code was used to
%generate the given sinusoid using a summation of three distinct sine
%waves.
newSignal = 0.4*sin(2*pi*2000*t) + 0.2*sin(2*pi*4000*t) +
0.2*sin(2*pi*6000*t);
% Plot the signal for t_plot msec
t_plot = 5;
msec_per_sec = 1000;
numSamples = t_plot*Fs/msec_per_sec;
plot(msec_per_sec*t(1:numSamples), newSignal(1:numSamples))
title('Giuseppe Querques, 0749012 - Q6. Plot of New Signal')
xlabel('time (milliseconds)')
grid('minor');

% Take the DFT


Y = fft(newSignal)/L;
f = Fs/2*linspace(0,1,L/2+1);
% Plot the single-sided magnitude spectrum.
plot(f,2*abs(Y(1:L/2+1)));
title('Giuseppe Querques, 0749012 - Q6. Single-Sided Magnitude Spectrum')
xlabel('Frequency (Hz)')
ylabel('|Y(f)|')
axis([0 Fs/2 0 .5]);
grid('minor');

Part 2
2. The given wave file has two segments of noise: High frequency static (ie.
Extraneous noise), and more distinct a medium-to-high frequency tone which varies
in pitch and volume at regular intervals. It is assumed that this second segment of
the wave file contains the information to be decoded.
3. The first step was to generate a DFT plot of the given wave file to find the
frequencies present. The following Matlab code (as derived from part one of the
laboratory report instructions) was used to do so:
[signal, Fs, bits_per_sample] = wavread('SecretMessage2015.wav');
L = length(signal);

T = 1/Fs;
t = [0:L-1]*T;
% Take the DFT
Y = fft(signal)/L;
f = Fs/2*linspace(0,1,L/2+1);
% Plot the single-sided magnitude spectrum.
plot(f,2*abs(Y(1:L/2+1)));
title('Giuseppe Querques, 0749012 - Part 2, Q3. Single-Sided Magnitude
Spectrum')
xlabel('Frequency (Hz)')
ylabel('|Y(f)|')
axis([0 Fs/2 0 .05]); %axis range limited from 0 to 0.05 for better magnitude
resolution
grid('minor');

The frequencies contained within the signal were found to be:


1000 Hz (magnitude of 0.040), 2000 Hz (magnitude of 0.031), 3000 Hz (magnitude
of 0.017), 4000 Hz (magnitude of 0.031), 5000 Hz (magnitude of 0.036), 6000 Hz
(magnitude of 0.028), and 7000 Hz (magnitude of 0.020). The noise floor present in
the signal can be ignored.

4. After performing the decoding process as detailed on the next several pages, the
secret code was found to be: BETTER TO LIGHT A SINGLE CANDLE THAN TO CURSE
THE DARKNESS.

The following Matlab code was used to split the original wave file signal into one
second blocks to be processed, reorganized, and decoded:
clc;
[signal, Fs, bits_per_sample] = wavread('SecretMessage2015.wav');
L = length(signal);
T = 1/Fs;
t = [0:L-1]*T;
freq = [0:8000]';
%this loop splits up the 59 second wave file into 59 one second segments.
%each segment is fft analyzed and sorted by peak magnitude,
%where the index of each value sorted is stored in parallel to a
%frequency storage vector. The top four magnitude peaks have
%their corresponding frequencies stored in letter identification
%vector, letterStorage.
for j=1:59
Y = fft(signal(1+(j-1)*16000:j*16000))/16000;
fftData = [2*abs(Y(1:16000/2+1))];
[fftPeaks, frequency] = sort(fftData,'descend');
letterStorage(j,1)
letterStorage(j,2)
letterStorage(j,3)
letterStorage(j,4)
end

=
=
=
=

frequency(1)-1;
frequency(2)-1;
frequency(3)-1;
frequency(4)-1;

%sort each row in ascending order of frequency, so each column corresponds to


%the Code Book values.
sortedLetters = sort(letterStorage,2);
%this block of code compares the frequencies contained within the
%sortedLetters vector to the Code Book values. The decoded segment characters
%are then placed within the secretMessage decoded block in order.
for j=1:59
if sortedLetters(j,1) == 1000 && sortedLetters(j,2) == 2000 ...
&& sortedLetters(j,3) == 3000 && sortedLetters(j,4) == 4000;
secretMessage(j) = 'A';
end
if sortedLetters(j,1) == 1000 && sortedLetters(j,2) == 2000 ...
&& sortedLetters(j,3) == 3000 && sortedLetters(j,4) == 5000;
secretMessage(j) = 'B';
end
if sortedLetters(j,1) == 1000 && sortedLetters(j,2) == 2000 ...
&& sortedLetters(j,3) == 3000 && sortedLetters(j,4) == 6000;
secretMessage(j) = 'C';

end
if sortedLetters(j,1) == 1000 && sortedLetters(j,2) == 2000 ...
&& sortedLetters(j,3) == 3000 && sortedLetters(j,4) == 7000;
secretMessage(j) = 'D';
end
if sortedLetters(j,1) == 1000 && sortedLetters(j,2) == 2000 ...
&& sortedLetters(j,3) == 4000 && sortedLetters(j,4) == 5000;
secretMessage(j) = 'E';
end
if sortedLetters(j,1) == 1000 && sortedLetters(j,2) == 2000 ...
&& sortedLetters(j,3) == 4000 && sortedLetters(j,4) == 6000;
secretMessage(j) = 'F';
end
if sortedLetters(j,1) == 1000 && sortedLetters(j,2) == 2000 ...
&& sortedLetters(j,3) == 4000 && sortedLetters(j,4) == 7000;
secretMessage(j) = 'G';
end
if sortedLetters(j,1) == 1000 && sortedLetters(j,2) == 2000 ...
&& sortedLetters(j,3) == 5000 && sortedLetters(j,4) == 6000;
secretMessage(j) = 'H';
end
if sortedLetters(j,1) == 1000 && sortedLetters(j,2) == 2000 ...
&& sortedLetters(j,3) == 5000 && sortedLetters(j,4) == 7000;
secretMessage(j) = 'I';
end
if sortedLetters(j,1) == 1000 && sortedLetters(j,2) == 2000 ...
&& sortedLetters(j,3) == 6000 && sortedLetters(j,4) == 7000;
secretMessage(j) = 'J';
end
if sortedLetters(j,1) == 1000 && sortedLetters(j,2) == 3000 ...
&& sortedLetters(j,3) == 4000 && sortedLetters(j,4) == 5000;
secretMessage(j) = 'K';
end
if sortedLetters(j,1) == 1000 && sortedLetters(j,2) == 3000 ...
&& sortedLetters(j,3) == 4000 && sortedLetters(j,4) == 6000;
secretMessage(j) = 'L';
end
if sortedLetters(j,1) == 1000 && sortedLetters(j,2) == 3000 ...
&& sortedLetters(j,3) == 4000 && sortedLetters(j,4) == 7000;
secretMessage(j) = 'M';
end
if sortedLetters(j,1) == 1000 && sortedLetters(j,2) == 3000 ...
&& sortedLetters(j,3) == 5000 && sortedLetters(j,4) == 6000;
secretMessage(j) = 'N';

end
if sortedLetters(j,1) == 1000 && sortedLetters(j,2) == 3000 ...
&& sortedLetters(j,3) == 5000 && sortedLetters(j,4) == 7000;
secretMessage(j) = 'O';
end
if sortedLetters(j,1) == 1000 && sortedLetters(j,2) == 3000 ...
&& sortedLetters(j,3) == 6000 && sortedLetters(j,4) == 7000;
secretMessage(j) = 'P';
end
if sortedLetters(j,1) == 1000 && sortedLetters(j,2) == 4000 ...
&& sortedLetters(j,3) == 5000 && sortedLetters(j,4) == 6000;
secretMessage(j) = 'Q';
end
if sortedLetters(j,1) == 1000 && sortedLetters(j,2) == 4000 ...
&& sortedLetters(j,3) == 5000 && sortedLetters(j,4) == 7000;
secretMessage(j) = 'R';
end
if sortedLetters(j,1) == 1000 && sortedLetters(j,2) == 4000 ...
&& sortedLetters(j,3) == 6000 && sortedLetters(j,4) == 7000;
secretMessage(j) = 'S';
end
if sortedLetters(j,1) == 1000 && sortedLetters(j,2) == 5000 ...
&& sortedLetters(j,3) == 6000 && sortedLetters(j,4) == 7000;
secretMessage(j) = 'T';
end
if sortedLetters(j,1) == 2000 && sortedLetters(j,2) == 3000 ...
&& sortedLetters(j,3) == 4000 && sortedLetters(j,4) == 5000;
secretMessage(j) = 'U';
end
if sortedLetters(j,1) == 2000 && sortedLetters(j,2) == 3000 ...
&& sortedLetters(j,3) == 4000 && sortedLetters(j,4) == 6000;
secretMessage(j) = 'V';
end
if sortedLetters(j,1) == 2000 && sortedLetters(j,2) == 3000 ...
&& sortedLetters(j,3) == 4000 && sortedLetters(j,4) == 7000;
secretMessage(j) = 'W';
end
if sortedLetters(j,1) == 2000 && sortedLetters(j,2) == 3000 ...
&& sortedLetters(j,3) == 5000 && sortedLetters(j,4) == 6000;
secretMessage(j) = 'X';
end
if sortedLetters(j,1) == 2000 && sortedLetters(j,2) == 3000 ...
&& sortedLetters(j,3) == 5000 && sortedLetters(j,4) == 7000;
secretMessage(j) = 'Y';

end
if sortedLetters(j,1) == 2000 && sortedLetters(j,2) == 3000 ...
&& sortedLetters(j,3) == 6000 && sortedLetters(j,4) == 6000;
secretMessage(j) = 'Z';
end
if sortedLetters(j,1) == 2000 && sortedLetters(j,2) == 4000 ...
&& sortedLetters(j,3) == 5000 && sortedLetters(j,4) == 6000;
secretMessage(j) = ' ';
end
if sortedLetters(j,1) == 2000 && sortedLetters(j,2) == 4000 ...
&& sortedLetters(j,3) == 5000 && sortedLetters(j,4) == 7000;
secretMessage(j) = '.';
end
end

S-ar putea să vă placă și