Docsity

Computing Techniques - Lecture Notes | ME 2016, Study notes of Computer Science

Toggle sidebar
bg1
ME2016, Dr. Ferri
Example showing Fourier series applied to a unit-amplitude square wave of period T =
2 and fundamental frequency 0 = 1 rad/s.
» t=0:0.001:20;
» Y=[];
» for n=1:2:51; y=sin(n*t)/n; Y=[Y; y]; end
» Y = 4*Y/pi;
» plot(t,Y(1,:))
0 2 4 6 8 10 12 14 16 18 20
-1.5
-1
-0.5
0
0.5
1
1.5
Now, add the first 3 rows of Y to get the 1st plus 3rd plus 5th harmonic. (Note that when
the Matlab “sum” command is applied to a matrix, it gives a row-vector that is the sum of
the rows of the matrix. Also recall that Y(1:3,:) gives the first 3 rows of the matrix Y.)
» plot(t,sum(Y(1:3,:)))
0 2 4 6 8 10 12 14 16 18 20
-1.5
-1
-0.5
0
0.5
1
1.5
pf3

Partial preview of the text

Download Computing Techniques - Lecture Notes | ME 2016 and more Study notes Computer Science in PDF only on Docsity!

ME2016, Dr. Ferri Example showing Fourier series applied to a unit-amplitude square wave of period T = 2  and fundamental frequency  0 = 1 rad/s. » t=0:0.001:20; » Y=[]; » for n=1:2:51; y=sin(nt)/n; Y=[Y; y]; end » Y = 4Y/pi; » plot(t,Y(1,:)) 0 2 4 6 8 10 12 14 16 18 20 -1.

-0. 0

1

Now, add the first 3 rows of Y to get the 1st^ plus 3rd^ plus 5th^ harmonic. (Note that when the Matlab “sum” command is applied to a matrix, it gives a row-vector that is the sum of the rows of the matrix. Also recall that Y(1:3,:) gives the first 3 rows of the matrix Y.) » plot(t,sum(Y(1:3,:))) -1.

-0. 0

1

Now, let’s add the first 6 rows, giving the sum of odd harmonic numbers 1 through 11: » plot(t,sum(Y(1:6,:))) 0 2 4 6 8 10 12 14 16 18 20 -1.

-0. 0

1

Now, let’s add some more harmonics: » plot(t,sum(Y(1:12,:))) -1.

-0. 0

1