1.
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 thefrequency content of signals. All of the code mentioned in this lab report was saved as a MATLAB m-file for convenience, quickreproduction, and troubleshooting of the code. All of the code below can also be found at the end of the report as anattachment, as well as all figures. If you have any questions or concerns in regards to this laboratory assignment, this laboratory report, the processused in designing the indicated circuitry, or the final conclusions and recommendations derived, please send an email toLSchwappach@yahoo.com. All computer drawn figures and pictures used in this report are of original and authentic content. function Lab1Prob1 = Comm1Lab2Problem1() %Function name for calling in MATLAB I. INTRODUCTION % Colorado Technical University % EE 443 - Communications I MATLAB is a powerful program and is useful in the % Lab 1 - MATLAB Project - Signal Spectrumvisualization of mathematics, physics, and applied % By Loren K. Schwappachengineering. In this lab exercise MATLAB will be used to % Uses centeredFFT() for obtaining a two-sided spectrumdetermine the frequency content of a composite sinusoidalsignal (to include its magnitude and power spectrum), and %---------------------------the frequency content of a pulse defined by a rectangularfunction (to include its magnitude, energy spectrum, and % Task #1 Magnitude and Power Spectrum for:autocorrelation). y=5cos(2*pi*400*t)+5cos(2*pi*700*t) % Composite sinusodial wave First: Given the following signal: f1 = 400; %frequency of the first sinusoidal wave (400Hz) (1) a1 = 5; %amplitude of the first sinusoidal wave (5V)Use MATLAB to plot the magnitude and power spectrum of f2 = 700; %frequency of the second sinusoidal wave (700Hz)the signal. a2 = 5; %amplitude of the second sinusoidal wave (5V) fs = 25*f2; %sampling frequency (25*highest freq) (17.5kHz) Second: Given the following signal: ts = 1/fs; %sampling interval (57us) t1 = 0:ts:1-ts; %time vector (0:57us:999.943ms) (2) y = (a1*cos(2*pi*f1*t1) + a2*cos(2*pi*f2*t1)); %compositeUse MATLAB to plot the magnitude and energy spectrum of sinusoidal wavethe signal. % Plot of sinusodial wave in time domain Third: Given the second equation: timePlot = figure; %gives graph window a name and keeps itUse MATLAB to plot the autocorrelation of the signal. 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 II. PROCEDURE / RESULTS ylabel(Amplitude); %adds ylabel to graph To complete the first task the following code was grid; %turns on gridused in MATLAB to produce and plot the compositesinusoidal function in the time domain:
2.
CTU: EE 443 – Communications 1: Lab 1: MATLAB Project – Signal Spectrum 2Figure 1: Composite sinusoidal wave in the time domain Figure 2: Composite sinusoidal waves magnitude in they(t)=5cos(2*pi*400*t)+5cos(2*pi*700*t). frequency domain, Y(f). You can see form figure 1 above that this is indeed a As illustrated by figure 2 above, you should observecomposite sinusoidal result of equation 1. that the composite sinusoidal results in two positive frequency impulses in the frequency domain, each at their previous Next, the following code was added to plot the individual frequencies (400Hz and 700Hz), and at half of their original individual amplitudes (5/2=2.5) as expected.sinusoidal wave’s magnitude in the frequency domain: Next, the following code was added to plot the power% Plot of sinusodial wave (Magnitude) in frequency domain spectrum for the composite sinusoidal:[YfreqDomain,YfrequencyRange] = centeredFFT(y,fs); %UsescenteredFFT function % Power Spectrum of sinusodial wavefreqPlot = figure; %gives graph window a name and keeps it % Note: Power = ((A^2)/2T))available % The LCM of (1/400) and (1/700) is (1/280,000) so T =stem(YfrequencyRange,abs(YfreqDomain)); %Creates stem (1/280,000)graph for magnitude spectrum Ey=((abs(YfreqDomain).*abs(YfreqDomain)))*(1/(2*(1/2800title(Magnitude of y(t) in frequency domain -> Y(f)) 00)));xlabel(Freq (Hz)); %adds xlabel to graph powerPlot = figure;ylabel(Amplitude); %adds ylabel to graph stem(YfrequencyRange,Ey); %Creates stem graph forgrid; %turns on grid magnitude spectrumaxis([-800,800,-1,3]); %defines axis title(Power spectrum of Y(f));[x(min),x(max),y(min),y(max)] 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)]
3.
CTU: EE 443 – Communications 1: Lab 1: MATLAB Project – Signal Spectrum 3Figure 3: Power Spectrum of Y(f). Figure 4: Rectangular pulse function x(t). As illustrated by figure 3 above, you should observe As shown by figure 4 above, the MATLAB codethat the power spectrum of the composite sinusoidal is much correctly produces the rectangular pulse required by thehigher in value than the amplitude of Y(f)’s magnitude. This equation 2:is due to the fact that the signals power is derived by squaringY(f)’s amplitude and dividing the result by 2*(1/T) where T is Next knowing that a rectangular pulse results in athe least common multiple of (1/400) and (1/700). Thus the sinc function the following code was added to plot thepower ends up being very high since (1/T) is very small. rectangular pulse’s magnitude in the frequency domain: To complete the second task the following code was % Plot of x(t)=2*rect(t/.002) (Magnitude) in frequencyused in MATLAB to produce and plot the rectangular pulse domainfunction: [XfreqDomain,XfrequencyRange] = centeredFFT(x,fs); %Uses centeredFFT function% Task #2 Magnitude and Energy Spectrum for: x(t) = rFreqPlot = figure; %gives graph window a name and keeps it2*rect(t/.002) available% Note: By definition rect(t/x)=u(t+x/2)-u(t-x/2) so.. plot(XfrequencyRange,abs(XfreqDomain)); %Creates stem% x(t) = 2u(t+1e-3)-2u(t-1e-3) graph for magnitude spectrumA = 2; title(Magnitude of x(t) in frequency domain -> X(f));t0 = -2e-3; xlabel(Freq (Hz)); %adds xlabel to graphtf = 2e-3; ylabel(Amplitude); %adds ylabel to graphts = (tf-t0)/1000; %(4us) grid; %turns on grid axis([-10000,10000,0,1.1]); %defines axisfs = 1/ts; %(250kHz) [x(min),x(max),y(min),y(max)]t=[t0:ts:(tf-ts)]; %(-2ms:4us:2ms)x = A*rectpuls(t/2e-3);% Plot of x(t)=2*rect(t/.002) in time domainrTimePlot = figure;plot(t,x); %Creates stem graph for magnitude spectrumtitle(x(t)=2*rect(t/.002) in time domain);xlabel(time (s)); %adds xlabel to graphylabel(Amplitude); %adds ylabel to graphgrid; %turns on gridaxis([t0,tf-ts,0,2.1]); %defines axis[x(min),x(max),y(min),y(max)]
4.
CTU: EE 443 – Communications 1: Lab 1: MATLAB Project – Signal Spectrum 4Figure 5: Magnitude of x(t) in the frequency domain X(f). Figure 6: Energy spectrum of X(f) As produced by figure 5 above, you should observe As seen by figure 6 above, the energy spectrumthat the rectangular pulse function equates to a sinc function in (energy spectral density) of the rectangular pulse is merely thethe frequency domain as expected. However, since the frequency domain result squared. This results in a muchmagnitude of the function was required the sinc function never smaller amplitude since the frequency domain amplitude isdrops below zero. already <1 (something small^2 = something even smaller). Next the following code was used to graph the To complete the final task the following code wasenergy spectrum of the rectangular pulse: used in MATLAB to plot the autocorrelation of the rectangular pulse x(t):% Energy Spectrum of x(t)=2*rect(t/.002)Ex = (abs(XfreqDomain).*abs(XfreqDomain)); % Task #3 Plot the autocorrelation for the rect function in taskrEnergyPlot = figure; 2.plot(XfrequencyRange,Ex); %Creates stem graph for % Uses task #2s variables and functions.magnitude spectrum Rxx=xcorr(x); % Estimate its autocorrelationtitle(Energy spectrum of X(f)); rEnergyPlot = figure;xlabel(Freq (Hz)); %adds xlabel to graph plot(Rxx); % Plot the autocorrelationylabel(Amplitude); %adds ylabel to graph title(Autocorrelation function of x(t)=2*rect(t/.002));grid; %turns on grid xlabel(lags);axis([-10000,10000,0,1.1]); %defines axis ylabel(Autocorrelation);[x(min),x(max),y(min),y(max)] grid;
5.
CTU: EE 443 – Communications 1: Lab 1: MATLAB Project – Signal Spectrum 5Figure 7: Autocorrelation of x(t). As seen by figure 7 above, the autocorrelation of therectangular pulse results in a linear pyramid. Theautocorrelation function is a measure of the similarity betweenx (t) and its delayed counterpart x ( ). III. CONCLUSIONS. MATLAB is a great utility for representing complexconcepts visually and can easily be manipulated to showsignals in various formats. This lab project was successful indemonstrating MATLABs powerful features in a quick andeasy method, and demonstrating how MATLAB can be usedfor displaying the frequency contents of signals. REFERENCES nd[1] Haykin, S., “Signals and Systems 2 Edition” McGraw- Hill, New York, NY, 2007.
6.
CTU: EE 443 – Communications 1: Lab 1: MATLAB Project – Signal Spectrum 6Figure 8: Composite sinusoidal wave in the time domain y(t)=5cos(2*pi*400*t)+5cos(2*pi*700*t).
7.
CTU: EE 443 – Communications 1: Lab 1: MATLAB Project – Signal Spectrum 7Figure 9: Composite sinusoidal waves magnitude in the frequency domain, Y(f).
8.
CTU: EE 443 – Communications 1: Lab 1: MATLAB Project – Signal Spectrum 8Figure 10: Power Spectrum of Y(f).
9.
CTU: EE 443 – Communications 1: Lab 1: MATLAB Project – Signal Spectrum 9Figure 11: Rectangular pulse function x(t).
10.
CTU: EE 443 – Communications 1: Lab 1: MATLAB Project – Signal Spectrum 10Figure 12: Magnitude of x(t) in the frequency domain X(f).
11.
CTU: EE 443 – Communications 1: Lab 1: MATLAB Project – Signal Spectrum 11Figure 13: Energy spectrum of X(f)
12.
CTU: EE 443 – Communications 1: Lab 1: MATLAB Project – Signal Spectrum 12Figure 14: Autocorrelation of x(t).
13.
CTU: EE 443 – Communications 1: Lab 1: MATLAB Project – Signal Spectrum 13%MATLAB CODEfunction 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 wavef1 = 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 domaintimePlot = figure; %gives graph window a name and keeps it availableplot (t1(1:176),y(1:176)); %plots sinusodial wave in time domaintitle(Composite Sinusodial y(t)=5cos(2*pi*400*t1)+5cos(2*pi*700*t2));xlabel(Time (s)); %adds xlabel to graphylabel(Amplitude); %adds ylabel to graphgrid; %turns on grid% Plot of sinusodial wave (Magnitude) in frequency domain[YfreqDomain,YfrequencyRange] = centeredFFT(y,fs); %Uses centeredFFT functionfreqPlot = figure; %gives graph window a name and keeps it availablestem(YfrequencyRange,abs(YfreqDomain)); %Creates stem graph for magnitude spectrumtitle(Magnitude of y(t) in frequency domain -> Y(f))xlabel(Freq (Hz)); %adds xlabel to graphylabel(Amplitude); %adds ylabel to graphgrid; %turns on gridaxis([-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 spectrumtitle(Power spectrum of Y(f));xlabel(Freq (Hz)); %adds xlabel to graphylabel(Power (Watts)); %adds ylabel to graphgrid; %turns on gridaxis([-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;
14.
CTU: EE 443 – Communications 1: Lab 1: MATLAB Project – Signal Spectrum 14ts = (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 domainrTimePlot = figure;plot(t,x); %Creates stem graph for magnitude spectrumtitle(x(t)=2*rect(t/.002) in time domain);xlabel(time (s)); %adds xlabel to graphylabel(Amplitude); %adds ylabel to graphgrid; %turns on gridaxis([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 functionrFreqPlot = figure; %gives graph window a name and keeps it availableplot(XfrequencyRange,abs(XfreqDomain)); %Creates stem graph for magnitude spectrumtitle(Magnitude of x(t) in frequency domain -> X(f));xlabel(Freq (Hz)); %adds xlabel to graphylabel(Amplitude); %adds ylabel to graphgrid; %turns on gridaxis([-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 spectrumtitle(Energy spectrum of X(f));xlabel(Freq (Hz)); %adds xlabel to graphylabel(Amplitude); %adds ylabel to graphgrid; %turns on gridaxis([-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 #2s variables and functions.Rxx=xcorr(x); % Estimate its autocorrelationrEnergyPlot = figure;plot(Rxx); % Plot the autocorrelationtitle(Autocorrelation function of x(t)=2*rect(t/.002));xlabel(lags);ylabel(Autocorrelation);grid;%---------------------------% end Comm1Lab1Problem1
Be the first to comment