EE443 - Communications 1 - Lab 1 - Loren Schwappach.pdf
-
Upload
loren-schwappach -
Category
Technology
-
view
538 -
download
2
description
Transcript of EE443 - Communications 1 - Lab 1 - Loren Schwappach.pdf
CTU: EE 443 – Communications 1: Lab 1: MATLAB Project – Signal Spectrum 1
Colorado Technical University EE 443 – Communication 1
Lab 1: MATLAB Project – Signal Spectrum August 2010
Loren Schwappach
ABSTRACT: This lab report was completed as a course requirement to obtain full course credit in EE443, Communication 1 at Colorado Technical University. Given two time domain signals this lab report uses MATLAB to examine the frequency content of signals. All of the code mentioned in this lab report was saved as a MATLAB m-file for convenience, quick reproduction, and troubleshooting of the code. All of the code below can also be found at the end of the report as an attachment, as well as all figures.
If you have any questions or concerns in regards to this laboratory assignment, this laboratory report, the process used in designing the indicated circuitry, or the final conclusions and recommendations derived, please send an email to [email protected]. All computer drawn figures and pictures used in this report are of original and authentic content.
I. INTRODUCTION
MATLAB is a powerful program and is useful in the
visualization of mathematics, physics, and applied
engineering. In this lab exercise MATLAB will be used to
determine the frequency content of a composite sinusoidal
signal (to include its magnitude and power spectrum), and
the frequency content of a pulse defined by a rectangular
function (to include its magnitude, energy spectrum, and
autocorrelation).
First: Given the following signal:
(1)
Use MATLAB to plot the magnitude and power spectrum of
the signal.
Second: Given the following signal:
(2)
Use MATLAB to plot the magnitude and energy spectrum of
the signal.
Third: Given the second equation:
Use MATLAB to plot the autocorrelation of the signal.
II. PROCEDURE / RESULTS
To complete the first task the following code was used in MATLAB to produce and plot the composite sinusoidal function in the time domain:
function Lab1Prob1 = Comm1Lab2Problem1() %Function name for calling in MATLAB % Colorado Technical University % EE 443 - Communications I % Lab 1 - MATLAB Project - Signal Spectrum % By Loren K. Schwappach % Uses centeredFFT() for obtaining a two-sided spectrum %--------------------------- % Task #1 Magnitude and Power Spectrum for: y=5cos(2*pi*400*t)+5cos(2*pi*700*t) % Composite sinusodial wave f1 = 400; %frequency of the first sinusoidal wave (400Hz) a1 = 5; %amplitude of the first sinusoidal wave (5V) f2 = 700; %frequency of the second sinusoidal wave (700Hz) a2 = 5; %amplitude of the second sinusoidal wave (5V) fs = 25*f2; %sampling frequency (25*highest freq) (17.5kHz) ts = 1/fs; %sampling interval (57us) t1 = 0:ts:1-ts; %time vector (0:57us:999.943ms) y = (a1*cos(2*pi*f1*t1) + a2*cos(2*pi*f2*t1)); %composite sinusoidal wave % Plot of sinusodial wave in time domain timePlot = figure; %gives graph window a name and keeps it available plot (t1(1:176),y(1:176)); %plots sinusodial wave in time domain title('Composite Sinusodial y(t)=5cos(2*pi*400*t1)+5cos(2*pi*700*t2)'); xlabel('Time (s)'); %adds xlabel to graph ylabel('Amplitude'); %adds ylabel to graph grid; %turns on grid
CTU: EE 443 – Communications 1: Lab 1: MATLAB Project – Signal Spectrum 2
Figure 1: Composite sinusoidal wave in the time domain
y(t)=5cos(2*pi*400*t)+5cos(2*pi*700*t).
You can see form figure 1 above that this is indeed a
composite sinusoidal result of equation 1.
Next, the following code was added to plot the
sinusoidal wave’s magnitude in the frequency domain: % Plot of sinusodial wave (Magnitude) in frequency domain [YfreqDomain,YfrequencyRange] = centeredFFT(y,fs); %Uses centeredFFT function freqPlot = figure; %gives graph window a name and keeps it available stem(YfrequencyRange,abs(YfreqDomain)); %Creates stem graph for magnitude spectrum title('Magnitude of y(t) in frequency domain -> Y(f)') xlabel('Freq (Hz)'); %adds xlabel to graph ylabel('Amplitude'); %adds ylabel to graph grid; %turns on grid axis([-800,800,-1,3]); %defines axis [x(min),x(max),y(min),y(max)]
Figure 2: Composite sinusoidal wave's magnitude in the
frequency domain, Y(f).
As illustrated by figure 2 above, you should observe
that the composite sinusoidal results in two positive frequency
impulses in the frequency domain, each at their previous
individual frequencies (400Hz and 700Hz), and at half of their
original individual amplitudes (5/2=2.5) as expected.
Next, the following code was added to plot the power
spectrum for the composite sinusoidal:
% Power Spectrum of sinusodial wave
% Note: Power = ((A^2)/2T))
% The LCM of (1/400) and (1/700) is (1/280,000) so T =
(1/280,000)
Ey=((abs(YfreqDomain).*abs(YfreqDomain)))*(1/(2*(1/2800
00)));
powerPlot = figure;
stem(YfrequencyRange,Ey); %Creates stem graph for
magnitude spectrum
title('Power spectrum of Y(f)');
xlabel('Freq (Hz)'); %adds xlabel to graph
ylabel('Power (Watts)'); %adds ylabel to graph
grid; %turns on grid
axis([-800,800,-1,1000000]); %defines axis
[x(min),x(max),y(min),y(max)]
CTU: EE 443 – Communications 1: Lab 1: MATLAB Project – Signal Spectrum 3
Figure 3: Power Spectrum of Y(f).
As illustrated by figure 3 above, you should observe
that the power spectrum of the composite sinusoidal is much
higher in value than the amplitude of Y(f)’s magnitude. This
is due to the fact that the signals power is derived by squaring
Y(f)’s amplitude and dividing the result by 2*(1/T) where T is
the least common multiple of (1/400) and (1/700). Thus the
power ends up being very high since (1/T) is very small.
To complete the second task the following code was used in MATLAB to produce and plot the rectangular pulse function: % Task #2 Magnitude and Energy Spectrum for: x(t) = 2*rect(t/.002) % Note: By definition rect(t/x)=u(t+x/2)-u(t-x/2) so.. % x(t) = 2u(t+1e-3)-2u(t-1e-3) A = 2; t0 = -2e-3; tf = 2e-3; ts = (tf-t0)/1000; %(4us) fs = 1/ts; %(250kHz) t=[t0:ts:(tf-ts)]; %(-2ms:4us:2ms) x = A*rectpuls(t/2e-3); % Plot of x(t)=2*rect(t/.002) in time domain rTimePlot = figure; plot(t,x); %Creates stem graph for magnitude spectrum title('x(t)=2*rect(t/.002) in time domain'); xlabel('time (s)'); %adds xlabel to graph ylabel('Amplitude'); %adds ylabel to graph grid; %turns on grid axis([t0,tf-ts,0,2.1]); %defines axis [x(min),x(max),y(min),y(max)]
Figure 4: Rectangular pulse function x(t).
As shown by figure 4 above, the MATLAB code
correctly produces the rectangular pulse required by the
equation 2:
Next knowing that a rectangular pulse results in a sinc function the following code was added to plot the rectangular pulse’s magnitude in the frequency domain: % Plot of x(t)=2*rect(t/.002) (Magnitude) in frequency
domain
[XfreqDomain,XfrequencyRange] = centeredFFT(x,fs);
%Uses centeredFFT function
rFreqPlot = figure; %gives graph window a name and keeps it
available
plot(XfrequencyRange,abs(XfreqDomain)); %Creates stem
graph for magnitude spectrum
title('Magnitude of x(t) in frequency domain -> X(f)');
xlabel('Freq (Hz)'); %adds xlabel to graph
ylabel('Amplitude'); %adds ylabel to graph
grid; %turns on grid
axis([-10000,10000,0,1.1]); %defines axis
[x(min),x(max),y(min),y(max)]
CTU: EE 443 – Communications 1: Lab 1: MATLAB Project – Signal Spectrum 4
Figure 5: Magnitude of x(t) in the frequency domain X(f).
As produced by figure 5 above, you should observe
that the rectangular pulse function equates to a sinc function in
the frequency domain as expected. However, since the
magnitude of the function was required the sinc function never
drops below zero.
Next the following code was used to graph the energy spectrum of the rectangular pulse:
% Energy Spectrum of x(t)=2*rect(t/.002)
Ex = (abs(XfreqDomain).*abs(XfreqDomain));
rEnergyPlot = figure;
plot(XfrequencyRange,Ex); %Creates stem graph for
magnitude spectrum
title('Energy spectrum of X(f)');
xlabel('Freq (Hz)'); %adds xlabel to graph
ylabel('Amplitude'); %adds ylabel to graph
grid; %turns on grid
axis([-10000,10000,0,1.1]); %defines axis
[x(min),x(max),y(min),y(max)]
Figure 6: Energy spectrum of X(f)
As seen by figure 6 above, the energy spectrum
(energy spectral density) of the rectangular pulse is merely the
frequency domain result squared. This results in a much
smaller amplitude since the frequency domain amplitude is
already <1 (something small^2 = something even smaller).
To complete the final task the following code was used in MATLAB to plot the autocorrelation of the rectangular pulse x(t):
% Task #3 Plot the autocorrelation for the rect function in task
2.
% Uses task #2's variables and functions.
Rxx=xcorr(x); % Estimate its autocorrelation
rEnergyPlot = figure;
plot(Rxx); % Plot the autocorrelation
title('Autocorrelation function of x(t)=2*rect(t/.002)');
xlabel('lags');
ylabel('Autocorrelation');
grid;
CTU: EE 443 – Communications 1: Lab 1: MATLAB Project – Signal Spectrum 5
Figure 7: Autocorrelation of x(t).
As seen by figure 7 above, the autocorrelation of the
rectangular pulse results in a linear pyramid. The
autocorrelation function is a measure of the similarity between
x (t) and its delayed counterpart x ( ).
III. CONCLUSIONS
. MATLAB is a great utility for representing complex
concepts visually and can easily be manipulated to show
signals in various formats. This lab project was successful in
demonstrating MATLABs powerful features in a quick and
easy method, and demonstrating how MATLAB can be used
for displaying the frequency contents of signals.
REFERENCES
[1] Haykin, S., “Signals and Systems 2nd
Edition” McGraw-Hill, New York, NY, 2007.
CTU: EE 443 – Communications 1: Lab 1: MATLAB Project – Signal Spectrum 6
Figure 8: Composite sinusoidal wave in the time domain y(t)=5cos(2*pi*400*t)+5cos(2*pi*700*t).
CTU: EE 443 – Communications 1: Lab 1: MATLAB Project – Signal Spectrum 7
Figure 9: Composite sinusoidal wave's magnitude in the frequency domain, Y(f).
CTU: EE 443 – Communications 1: Lab 1: MATLAB Project – Signal Spectrum 8
Figure 10: Power Spectrum of Y(f).
CTU: EE 443 – Communications 1: Lab 1: MATLAB Project – Signal Spectrum 9
Figure 11: Rectangular pulse function x(t).
CTU: EE 443 – Communications 1: Lab 1: MATLAB Project – Signal Spectrum 10
Figure 12: Magnitude of x(t) in the frequency domain X(f).
CTU: EE 443 – Communications 1: Lab 1: MATLAB Project – Signal Spectrum 11
Figure 13: Energy spectrum of X(f)
CTU: EE 443 – Communications 1: Lab 1: MATLAB Project – Signal Spectrum 12
Figure 14: Autocorrelation of x(t).
CTU: EE 443 – Communications 1: Lab 1: MATLAB Project – Signal Spectrum 13
%MATLAB CODE
function Lab1Prob1 = Comm1Lab2Problem1() %Function name for calling in MATLAB % Colorado Technical University % EE 443 - Communications I % Lab 1 - MATLAB Project - Signal Spectrum % By Loren K. Schwappach % Uses centeredFFT() for obtaining a two-sided spectrum
%---------------------------
% Task #1 Magnitude and Power Spectrum for: y=5cos(2*pi*400*t)+5cos(2*pi*700*t) % Composite sinusodial wave f1 = 400; %frequency of the first sinusodial wave (400Hz) a1 = 5; %amplitude of the first sinusodial wave (5V) f2 = 700; %frequency of the second sinusodial wave (700Hz) a2 = 5; %amplitude of the second sinusodial wave (5V) fs = 25*f2; %sampling frequency (25*highest freq) (17.5kHz) ts = 1/fs; %sampling interval (57us) t1 = 0:ts:1-ts; %time vector (0:57us:999.943ms) y = (a1*cos(2*pi*f1*t1) + a2*cos(2*pi*f2*t1)); %composite sinusodial wave
% Plot of sinusodial wave in time domain timePlot = figure; %gives graph window a name and keeps it available plot (t1(1:176),y(1:176)); %plots sinusodial wave in time domain title('Composite Sinusodial y(t)=5cos(2*pi*400*t1)+5cos(2*pi*700*t2)'); xlabel('Time (s)'); %adds xlabel to graph ylabel('Amplitude'); %adds ylabel to graph grid; %turns on grid
% Plot of sinusodial wave (Magnitude) in frequency domain [YfreqDomain,YfrequencyRange] = centeredFFT(y,fs); %Uses centeredFFT function freqPlot = figure; %gives graph window a name and keeps it available stem(YfrequencyRange,abs(YfreqDomain)); %Creates stem graph for magnitude spectrum title('Magnitude of y(t) in frequency domain -> Y(f)') xlabel('Freq (Hz)'); %adds xlabel to graph ylabel('Amplitude'); %adds ylabel to graph grid; %turns on grid axis([-800,800,-1,3]); %defines axis [x(min),x(max),y(min),y(max)]
% Power Spectrum of sinusodial wave % Note: Power = ((A^2)/2T)) % The LCM of (1/400) and (1/700) is (1/280,000) so T = (1/280,000) Ey = ((abs(YfreqDomain).*abs(YfreqDomain)))*(1/(2*(1/280000))); powerPlot = figure; stem(YfrequencyRange,Ey); %Creates stem graph for magnitude spectrum title('Power spectrum of Y(f)'); xlabel('Freq (Hz)'); %adds xlabel to graph ylabel('Power (Watts)'); %adds ylabel to graph grid; %turns on grid axis([-800,800,-1,1000000]); %defines axis [x(min),x(max),y(min),y(max)]
%---------------------------
% Task #2 Magnitude and Energy Spectrum for: x(t) = 2*rect(t/.002) % Note: By definition rect(t/x)=u(t+x/2)-u(t-x/2) so.. % x(t) = 2u(t+1e-3)-2u(t-1e-3) A = 2; t0 = -2e-3; tf = 2e-3;
CTU: EE 443 – Communications 1: Lab 1: MATLAB Project – Signal Spectrum 14
ts = (tf-t0)/1000; %(4us) fs = 1/ts; %(250kHz) t=[t0:ts:(tf-ts)]; %(-2ms:4us:2ms) x = A*rectpuls(t/2e-3);
% Plot of x(t)=2*rect(t/.002) in time domain rTimePlot = figure; plot(t,x); %Creates stem graph for magnitude spectrum title('x(t)=2*rect(t/.002) in time domain'); xlabel('time (s)'); %adds xlabel to graph ylabel('Amplitude'); %adds ylabel to graph grid; %turns on grid axis([t0,tf-ts,0,2.1]); %defines axis [x(min),x(max),y(min),y(max)]
% Plot of x(t)=2*rect(t/.002) (Magnitude) in frequency domain [XfreqDomain,XfrequencyRange] = centeredFFT(x,fs); %Uses centeredFFT function rFreqPlot = figure; %gives graph window a name and keeps it available plot(XfrequencyRange,abs(XfreqDomain)); %Creates stem graph for magnitude spectrum title('Magnitude of x(t) in frequency domain -> X(f)'); xlabel('Freq (Hz)'); %adds xlabel to graph ylabel('Amplitude'); %adds ylabel to graph grid; %turns on grid axis([-10000,10000,0,1.1]); %defines axis [x(min),x(max),y(min),y(max)]
% Energy Spectrum of x(t)=2*rect(t/.002) Ex = (abs(XfreqDomain).*abs(XfreqDomain)); rEnergyPlot = figure; plot(XfrequencyRange,Ex); %Creates stem graph for magnitude spectrum title('Energy spectrum of X(f)'); xlabel('Freq (Hz)'); %adds xlabel to graph ylabel('Amplitude'); %adds ylabel to graph grid; %turns on grid axis([-10000,10000,0,1.1]); %defines axis [x(min),x(max),y(min),y(max)]
%---------------------------
% Task #3 Plot the autocorrelation for the rect function in task 2. % Uses task #2's variables and functions. Rxx=xcorr(x); % Estimate its autocorrelation rEnergyPlot = figure; plot(Rxx); % Plot the autocorrelation title('Autocorrelation function of x(t)=2*rect(t/.002)'); xlabel('lags'); ylabel('Autocorrelation'); grid;
%---------------------------
% end Comm1Lab1Problem1