Greinerwk 7 Labecet 350
Greinerwk 7 Labecet 350
Name(s):
Brian Greiner
Team or Group #(if applicable):
Professor:
David Nyarko
Experiment or Assignment #: Lab07 Lab Meeting Day & Time:
4/13/12
Title of Report:
Spectral Analysis Using DFT
Summary (two sentences):
This weeks lab was an exercise with Matlabs various features that can assist in
performing discrete Fourier transforms of a signal to determine the frequency
components. We created white noise, and sinusoids, and analyzed and plotted their
spectral analysis.
________________________________________________________________________
Checklist (items included):
1. Introduction & Background 4. Results: Data, Tables, & Diagrams
2. Procedure 5. Analysis of Results
3. Troubleshooting & Testing 6. Conclusions
Key Results:
The white noise truly had component frequencies all throughout the sampling range,
while our sinusoids had very specific frequencies.
________________________________________________________________________
Key Conclusions (technical):
The fft and ifft functions in matlab greatly simplify what would be an incredible
amount of matrix math.
________________________________________________________________________
Key Conclusions (critical thinking):
The application of Fourier Transforms are numerous in the digital world.
________________________________________________________________________
Date Due:
Date Submitted:
ECET350/Lab07 2
Student(s) Signature:
Professors Signature:
Signal Processing with Labs ECET350
Objectives:
To generate digital signals such as composite sinusoidal and white noise with
Gaussian distribution.
To obtain and investigate the spectral representation of various digital signals using
DFT (Discrete Fourier Transform) by FFT function of MATLAB.
Introduction
Digital signal processing applications often require that time domain information and
frequency content of the signal be analyzed. Figure 1 shows a digitized sinusoidal signal and
its calculated signal spectrum (frequency content) defined as the signal amplitude versus its
corresponding frequency, via a digital signal processing algorithm, called DFT (Discrete-
Fourier transform).
As an example, Figure 1 illustrates the time domain representation of a 1000-Hz sinusoid
with 32 samples at a sampling rate of 8000 Hz; the second plot shows the signal spectrum
(frequency domain representation), where we can clearly observe the frequency content of
1000 Hz located at the amplitude peak in the calculated spectrum. Hence, the spectral plot
better displays the frequency information of the digital signal.
ECET350/Lab07 3
Figure 1. Example of digital signal and its amplitude spectrum
DFT and its efficient computation FFT is widely used in many applications in the area of
spectral analysis, acoustics, imaging and video, audio, instrumentation, and communication
systems.
Generation of White Noise with Gaussian Distribution
1. Generate the white noise with the Gaussian distribution using the following code:
MATLAB>>x=5*randn(1,4096); % generate 4096 noise samples
a. Make a plot of the white noise.
Plot the first 50 samples (discrete-time signal style) using the Matlab function stem().
Hint: MATLAB>>figure; subplot(2,1,1);stem(x(1:50));
b. Use fft() to compute DFT coefficients, and plot and examine the magnitude spectrum
of the signal () assuming the sampling rate is 8000 Hz. To obtain frequency
components:
MATLAB>>Ak=abs(fft(x))/length(x);
To plot the spectrum:
MATLAB>>fs=8000;
MATLAB>>k=0:1:length(x)-1; %frequency index
MATLAB>>f=k*fs/length(x); % convert it to Hz
ECET350/Lab07 4
MATLAB>>subplot(2,1,2); plot(f,Ak);
**************************************************************
MATLAB
x=5*randn(1,4096);
figure(1);
subplot(2,1,1);stem(x(1:50));
Ak=abs(fft(x))/length(x);
fs=8000;
k=0:1:length(x)-1;
f=k*fs/length(x);
subplot(2,1,2); plot(f,Ak);
Graphs showing white noise samples, 0 through 50 and the corresponding spectral
analysis.
***********************************************************************
Label and print your graph.
What frequency range should you read?
ECET350/Lab07 5
Frequencies between 0 and 4000 Hz (Nyquist cutoff)
What is the frequency resolution?
Frequency resolution 8000/4096 = 1.95Hz
c. Listen to the generated signal using the sampling rate of 8000 Hz.
MATLAB>>sound(x/max(abs(x)),8000);
Generation of the sum of digital sinusoids
2. Generate three sinusoids with the following amplitudes and phases
1
() = 5 cos[2(500)]
2
() = 5 cos[2(1200) +0.25]
3
() = 5 cos[2(1800) +0.5]
a. Make a plot of all three signals over a range of t that will exhibit approximately 0.01
second. Each signal will be sampled using a sampling rate of 8000 Hz, a step size
(sampling period) for time t is 1/8000=0.000125 second
Hint: MATLAB>> t=0:(1/8000):0.5; figure;
subplot(3,1,1);plot(t,x1); axis([0 0.01 6 6]);
MATLAB
t=0:(1/8000):0.5;
x1=5*cos(2*pi*(500)*t);
x2=5*cos(2*pi*(1200)*t+0.25*pi);
x3=5*cos(2*pi*(1800)*t+0.5*pi);
figure(1);
subplot(3,1,1);
plot(t,x1);
axis([0 0.01 -6 6]);
subplot(3,1,2);
plot(t,x2);
axis([0 0.01 -6 6]);
subplot(3,1,3);
plot(t,x3);
axis([0 0.01 -6 6]);
ECET350/Lab07 6
Verify that the phases of all three signals are correct, and verify that each one has the
correct maximum amplitude.
Calculated
1
(0) = 5
1max
= 5 Measured
1
(0) = 5
1max
= 5
Calculated
2
(0) = 3.5356
2max
= 5 Measured
2
(0) = 4.938
2max
= 3.536
Calculated
3
(0) = 0
3max
= 5 Measured
3
(0) = 5
3max
= 0
b. Create a program to generate the sum of sinusoids by adding three generated
sinusoids
() =
1
() +
2
() +
3
()
Make a plot of () over the same range of time as used in (1).
MATLAB>>figure; subplot(2,1,1);plot(t,x);
axis([0 0.01 -6 6]);
ECET350/Lab07 7
MATLAB
t=0:(1/8000):0.5;
x1=5*cos(2*pi*(500)*t);
x2=5*cos(2*pi*(1200)*t+0.25*pi);
x3=5*cos(2*pi*(1800)*t+0.5*pi);
xt=x1+x2+x3
figure(1);
subplot(2,1,1);
plot(t,xt);
axis([0 0.01 -6 6]);
What is the sampling rate?
8000Hz
c. Use fft() to compute DFT coefficients, plot and examine the spectrum of the signal
() (frequency components). To obtain frequency components:
MATLAB>>Ak=abs(fft(x))/length(x);
To plot the spectrum:
MATLAB>>fs=8000;
MATLAB>>k=0:1:length(x)-1;
%k is the frequency bin (frequency index)
MATLAB>>f=k*fs/length(x); % convert xx to Hz
MATLAB>>subplot(2,1,2);plot(f,Ak);
Matlab
t=0:(1/8000):0.5;
x1=5*cos(2*pi*(500)*t);
x2=5*cos(2*pi*(1200)*t+0.25*pi);
x3=5*cos(2*pi*(1800)*t+0.5*pi);
xt=x1+x2+x3
figure(1);
subplot(2,1,1);
plot(t,xt);
axis([0 0.01 -6 6]);
Ak=abs(fft(xt))/length(xt);
fs=8000;
k=0:1:length(xt)-1;
f=k*fs/length(xt);
subplot(2,1,2);
plot(f,Ak);
ECET350/Lab07 8
Signal from 0 to .01 seconds, and spectral analysis from 0 to 8kHz
Label and print your graph.
What frequencies are shown in the signal spectral plot?
500 Hz, 1200 Hz, 1800 Hz, 6200Hz, 6800Hz and 7500Hz
What is the maximum frequency value that you can see?
8000Hz
What is the frequency resolution based on the MATLAB program?
2Hz
d. Listen to and compare the generated signals
MATLAB>>sound(x1/max(abs(x1)), 8000);pause
MATLAB>>sound(x2/max(abs(x2)), 8000);pause
MATLAB>>sound(x3/max(abs(x3)), 8000);pause
MATLAB>>sound(x/max(abs(x)), 8000);
ECET350/Lab07 9
Matlab
sound(x1/max(abs(x1)), 8000);pause
sound(x2/max(abs(x2)), 8000);pause
sound(x3/max(abs(x3)), 8000);pause
sound(xt/max(abs(xt)), 8000);
The sum of these three signals sounds like three keys struck on a piano at the same time.
Generation of the multiplication signal of digital sinusoids
3. Generate two sinusoids with the following amplitudes and phases
1
() = 5 cos[2(500)]
2
() = 5 cos[2(1200) +0.25]
a. Make a plot of all two signals over a range of t that will exhibit approximately 0.01
second. Each signal will be sampled using the sampling rate of 8000 Hz, the step size
(sampling period) for time t is 1/8000=0.000125 second
Hint: MATLAB>> t=0:(1/8000):0.5; figure;
subplot(4,1,1);plot(t,x1); axis([0 0.01 6 6]);
Use MATLAB routines max() and mean() to detremine the maximum value and root-
mean squared value (hint: sqrt(mean(x1.*x1))
1max
= 5
1
= 3.5360
2max
= 4.9384
2
=3.5355
MATLAB CODE
t=0:(1/8000):0.5;
x1=5*cos(2*pi*(500)*t);
x2=5*cos(2*pi*(1200)*t+0.25*pi);
clf
figure(1);
subplot(4,1,1);
plot(t,x1);
axis([0 0.01 -6 6]);
subplot(4,1,2);
plot(t,x2);
axis([0 0.01 -6 6]);
sqrt(mean(x1.*x1))
sqrt(mean(x2.*x2))
max(x1)
max(x2)
ECET350/Lab07 10
Two sinusoids with Peak Amplitudes 5 and frequencies 500Hz and 1200Hz.
b. Create a program to generate the multiplication of sinusoids by using:
() =
1
().
2
().
Hint: MATLAB>>y=x1.*x2;
Make a plot of () over same range of time as used in the above
MATLAB>>figure; subplot(4,1,3);plot(t,y);
axis([0 0.01 -6 6]);
Matlab Code
y=x1.*x2;
subplot(4,1,3);
plot(t,y);
axis([0 0.01 -26 26]);
Product of signals
ECET350/Lab07 11
c. Use fft() to compute DFT coefficients, plot and examine the spectrum of the signal
() (frequency components).
To obtain frequency components:
MATLAB>> Ak=abs(fft(y))/length(y);
To plot the spectrum:
MATLAB>> fs=8000;
MATLAB>>k=0:1:length(x)-1;
%k is the frequency bin (frequency index)
MATLAB>> f=k*fs/length(y); % convert xx to Hz
MATLAB>>subplot(4,1,4);plot(f,Ak);
Label and print your graph.
MATLAB CODE
Ak=abs(fft(y))/length(y);
fs=8000;
k=0:1:length(y)-1;
f=k*fs/length(y);
subplot(4,1,4);
plot(f,Ak)
ECET350/Lab07 12
MATLAB plots showing two sinusoids, their product signal and the spectral analysis of
their product.
What frequencies having the amplitude spectral peaks are shown in the signal spectral
plot?
The spectral peaks are at
700Hz, 1700Hz, 6300Hz, and 7300Hz
What is the maximum amplitude for each amplitude spectral peak ?
The maximum amplitude at the spectral peaks are
6.174, 5.795, 5.795, 6.174 respectively
What is the frequency resolution based on the MATLAB program?
2Hz
ECET350/Lab07 13
c. Listen to and compare the generated signals
MATLAB>>pause
MATLAB>>sound(x1/max(abs(x1)), 8000);pause
MATLAB>>sound(x2/max(abs(x2)), 8000);pause
MATLAB>>sound(y/max(abs(y)), 8000);
The first frequency is low pitch, the second frequency is much higher pitch. Their product
is halfway in between in pitch.