Homework Problems with Solution - Computing Techniques | ME 2016, Assignments of Computer Science

Material Type: Assignment; Professor: Ferri; Class: Computing Techniques; Subject: Mechanical Engineering; University: Georgia Institute of Technology-Main Campus; Term: Fall 2016;

Typology: Assignments

Pre 2010

Uploaded on 08/04/2009

koofers-user-okv
koofers-user-okv 🇺🇸

8 documents

1 / 11

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
ME2016, Fall 2008, Dr. Ferri
Homework Assignment 10
Due Wednesday, November 19.
Problem 1. (5 points)
This example shows the convergence of a Fourier series, and the relationship between a Fourier
series and a Fast Fourier Transform (FFT). A half-wave rectified sinewave having a frequency
of 1 rad/s and a period of 2π seconds is equal to sin(t) when sin(t) >= 0 and equal to zero when
sin(t) < 0. The Fourier series of such a signal is given by:
"+= )tcos()tcos()tcos()tsin()t(y 6
35
2
4
15
2
2
3
2
2
11
ππππ
(1.1)
A single period of the periodic signal y(t) can be generated in Matlab using the following two
lines:
» N=128; dt=2*pi/N; T=2*pi; t=0:dt:(T-dt);
» y=sin(t); I=find(y<0); y(I)=zeros(1,length(I));
Note that there are exactly N points, and that N = 128 is a power of 2 ( 2^7). Using powers of 2
for record-lengths of sampled signals is typical in digital signal processing (DSP) because of
computational efficiencies that result in the calculation of FFT’s.
(a) Plot the exact signal as well as the sum of the first two, first three, and first 4 terms in the
Fourier series (2.1) above on the same graph. Be sure to add a legend to identify all curves.
(b) Calculate the FFT of y by typing » Y = fft(y); Plot abs(Y) versus the frequency vector
w, showing the full range of frequencies. Next, make a separate plot of abs(Y) vs w,
focusing on the frequency range of 1 to 10 rad/s. On this latter plot, show the individual
points as small circles ‘o’, connected by dotted lines. Add a grid. Note that, even though Y
is complex-valued, its magnitude is given by abs(Y). Also note that the fundamental
frequency w0, is equal to 1 rad/s since w0 = 2*pi/T = 1 in this case. The 1xN frequency
vector w is given by the Matlab command
» w0 = 2*pi/T; w = w0*(0:(N-1)); % freq vector in rad/s
(c) At what frequencies does the FFT show peaks? Does this match the predictions from the
Fourier series? How do the amplitudes of those peaks compare with the Fourier-series
coefficients shown in Equation 1.1?
Solution
The solution for part (a) is shown in Figure 1.1. The Fourier series converges nicely to the exact
function.
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Homework Problems with Solution - Computing Techniques | ME 2016 and more Assignments Computer Science in PDF only on Docsity!

ME2016, Fall 2008, Dr. FerriHomework Assignment 10Due Wednesday, November 19. Problem 1. (5 points)

This example shows the convergence of a Fourier series, and the relationship between a Fourierseries and a Fast Fourier Transform (FFT). A half-wave rectified sinewave having a frequencyof 1 rad/s and a period of 2sin(t) < 0. The Fourier series of such a signal is given by:π seconds is equal to sin(t) when sin(t) >= 0 and equal to zero when

A single period of the periodic signal y(t) can be generated in Matlab using the following twolines: y(^ t) =^ π^1 +^21 sin(t) −^32 π cos(^2 t) −^152 π cos(^4 t) −^352 π cos(^6 t) −^ " (1.1)

Note that there are exactly N points, and that N = 128 is a power of 2 ( 2^7). Using powers of 2^ »»^ N=128;y=sin(t);^ dt=2pi/N;^ I=find(y<0);^ T=2pi;^ y(I)=zeros(1,length(I));^ t=0:dt:(T-dt);

for record-lengths of sampled signals is typical in digital signal processing (DSP) because ofcomputational efficiencies that result in the calculation of FFT’s.(a) Plot the exact signal as well as the sum of the first two, first three, and first 4 terms in the

(b) Calculate the FFT ofFourier series (2.1) above on the same graph. Be sure to add a legend to identify all curves.w, showing the full range of frequencies. Next, make a separate plot of y by typing » Y = fft(y); Plot abs(Y) versus the frequency vector abs(Y) vs w,

focusing on the frequency range of 1 to 10 rad/s. On this latter plot, show the individualpoints as small circles ‘o’, connected by dotted lines. Add a grid. Note that, even though Yis complex-valued, its magnitude is given byfrequency w0, is equal to 1 rad/s since w0 = 2*pi/T = 1 in this case. The 1xN frequencyvector w is given by the Matlab command abs(Y). Also note that the fundamental

(c) At what frequencies does the FFT show peaks? Does this match the predictions from theFourier series? How do the amplitudes of those peaks compare with the Fourier-seriescoefficients shown in Equation 1.1?^ »^ w0^ =^ 2pi/T;^ w^ =^ w0(0:(N-1));^ %^ freq^ vector^ in^ rad/s

Solution The solution for part (a) is shown in Figure 1.1. The Fourier series converges nicely to the exactfunction.

The amplitude spectrum of the signal is shown in Figure 1.2. You can see that the amplitudespectrum is “reflected” about the Nyquist frequency,A close-up of the amplitude spectrum is shown in Figure 1.3. The plot shows peaks at the “0th- ωNyquist = N*ω0/2 = 64 rad/s.

harmonic,” (that is, the constant term), the 1st harmonic, the 2nd, 4th, 6th, etc.YY 01 = 40.735. Based on a= 0.00 – 32.0 i. Based on a 0 = 1/π 1 , we should have Y= 0, b 1 =0.5, we should have Y 0 = Na 0 = 128/ 1 =(N/2)(aπ = 40.744 1 -ib 1 ) = -32 i

YYAnd so onWe see that there is excellent agreement between the FFT coefficients, and the Fourier series 23 = -13.589. Based on a= -1.159e-015 -4.863e-016i. Based on a 2 = -2/3π, b 2 =0, we should have Y 3 =0, b 3 = 0, we should have Y 2 =(N/2)*(a 2 -ib 32 ) = -= 0. 13.

coefficients.» Y(2) =» Y(3) = -13.5894 + 0.0000i, Y(127) = -13.5894 - 0.0000i (complex conjugates)Since Y(2) corresponds to Y -0.0000 -32.0000i, Y(128) = 1 , it should be imaginary since a -0.0000 +32.0000i (complex conjugates) 1 = 0, b 1 = 1/

Since Y(3) corresponds to Y 2 , it should be real since a 2 = -2/3π, b 2 = 0

-0.2^00 1 2 3 4 5 6

0.20.

0.60.

1.2 1

Time (sec)

y

Problem 2, Convergence of Fourier Series 2 terms3 terms4 termsExact

Figure 1.

Matlab N=128;y=sin(t); dt=2pi/N; I=find(y<0); T=2pi; y(I)=zeros(1,length(I)); t=0:dt:(T-dt);

yea0y2=a0+b1sin(t);y3=y2+a2cos(2t); == y;1/pi; % exactb1=1/2; function a2=-2/(3pi); a4=-2/(15*pi);

y4=y3+a4cos(4t);figure(1)plot(t,y2,'--',t,y3,'-.',t,y4,':',t,ye);xlabel('Time ; (sec)'); ylabel('y');

legend('2title('Problem%Y=fft(y); 1.b terms','3 2, Convergence terms','4 terms','Exact');of Fourier Series');

w0figure(2);plot(w,abs(Y))xlabel('Frequency, = 2pi/T; w = w0(0:(N-1)); (rad/s)') % freq vector in rad/s

ylabel('abs(Y)')I=find(w<=10);figure(3);plot(w(I),abs(Y(I)),'o--')

xlabel('Frequency,ylabel('abs(Y)')grid (rad/s)')

Problem 2. (5 points) Consider the signal y = sin(t), having frequency 1 rad/s. The following lines of code determinethe signal and its FFT, and generates the 2x1 plot below. Note the use of the Matlab commandstem:

T=2pi;N=128; dt=T/N; t=(0:(N-1))dt;y=sin(t); Y=fft(y);w0=2pi/T; w=(0:(N-1))w0;subplot(2,1,1);

plot(t,y,’o-‘); xlabel('t (sec)'); ylabel('y');subplot(2,1,2);I = find(w<10);stem(w(I),abs(Y(I)),'o-'); xlabel('w (rad/s)'); ylabel('abs(FFT)');

-0.5-1^00 1 2 3 4 5 6 0.5^1 t (sec)

y (^204000 1 2 3 4 5 6 7 8 ) 6080

(a) Repeat the exercise above for T = 4exercise for T = 20abs(FFT)π; i.e., 10 complete periods of the sinusoid. Include these two plots with yourπ; i.e., 2 complete periods of the sinusoid. Next repeat thew (rad/s)

(b) Let’s see what happens if we do not consider an integer number of periods of the signal. Generatehomework. What is the fundamental frequency, w0, in each case? What do you observe about theFFT spectrum? What is the peak amplitude of the FFT amplitude spectrum, and where does itoccur? How does the amplitude and frequency of the peak compare with the theoretical prediction?Be specific.

(c) Keeping T = 40plots for T = 3the peak of the FFT amplitude spectrum.= 128, 64, 32, and 16. In each case, calculate the Nyquist frequency. At what value of N should the1 rad/s signal experience aliasing? How does aliasing manifest itself in the time-plot and in the FFTππ, T = 19, plot the signal and its amplitude spectrum (using the code above) for the case of Nπ, T=19.5π. What do you observe about the shape, height, and location of

Solution It is seen that the magnitude, and the placement of the peak in the magnitude FFT is correct. The Fourieramplitude spectrum?

series corresponds to a single nonzero coefficient, bshould be Nby(t). However, in Figure 2.1, the peak occurs in the 3the 11 th point, Y 1 /2 = 64. Only a single FFT point is nonzero, since there is only one frequency present in 10. In each case, the index (subscript on Y) corresponds to 1 rad/s, k 1 = 1. Therefore, the FFT magnitude at rd point, Y 2 , and in Figure 2.2, the peak occurs inω 0 = 1 rad/s. ω = 1 rad/s

t (sec)

y (^2000 1 2 3 4 5 6 7 8 9 )

We see that the FFT now shows that the frequency content of the signal has been “spread” over manyabs(FFT)^ Figure 2.3 T = 3w (rad/s) π

frequencies. There is a maximum nearphenomenon can be seen in Figure 2.4, which plots 2 periods of the signal. The FFT analysis assumesthat the signal’s period is equal to T = 3“kink” at t = 3necessary to form this complicated signal.π. In terms of a Fourier series, many frequencies components (many harmonics) are ωπ = 1 rad/s, but it is not equal to N*bsec, therefore, the signal is not a pure sinusoid. Instead, it has a 1 /2 = 64. The reason for this

-0.8-0.6-1 0 2 4 6 8 10 12 14 16 18 20 -0.4-0.20.2^0

0.40.60.8^1 Time (sec)

y

Figure 2.4 Two periods of the signal having T = 3π

-0.5-1^00 10 20 30 40 50
0.5^1

t (sec)

y (^2000 1 2 3 4 5 6 7 8 9 )

abs(FFT) Figure 2.5 T = 19w (rad/s) π

t (sec)

y

(^2000 1 2 3 4 5 6 7 8 9 )

abs(FFT) Figure 2.6 T = 19.5w (rad/s) π

-0.5-1^00 20 40 60 80 100 120
0.5^1

t (sec)

y (^102000) 0.5 1 1.5 2 2.5 3 3.

Figure 2.8 T = 40abs(FFT) π, ω 0 = 2π/T = 0.05 rad/s,w (rad/s) Ν = 64, ωNyquist = N*ω 0 /2 = 1.6 rad/s

-0.5-1^00 20 40 60 80 100 120
0.5^1

t (sec)

y (^10050) 0.2 0.4 0.6 0.8 1 1.2 1.4 1.

Figure 2.9 T = 40abs(FFT) π, ω 0 = 2π/T = 0.05 rad/s,w (rad/s) Ν = 32, ωNyquist = N*ω 0 /2 = 0.8 rad/s

-0.5-1^00 20 40 60 80 100
0.5^1

t (sec)

y

(^0240) 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.

Figure 2.10 T = 40abs(FFT) π, ω 0 = 2π/T = 0.05 rad/s,w (rad/s) Ν = 16, ωNyquist = N*ω 0 /2 = 0.4 rad/s