Matlab Session 4

You might also like

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 17

MATLAB Session 4

ES 156 Signals and Systems 2007

Harvard SEAS
Prepared by Jiajun Gu

OUTLINE
Fourier series of exponential signals Fourier series of a continuous-time rectangular signal Sinc function

Fourier series of exponential signals


Fourier series of
e jM0t

ak [ k M ]
jM0 n e Fourier series of

ak [k Nl M ], l Z

Fourier series of exponential signals II


Fourier series of
cos(M0t )

1 1 ak [k M ] [k M ] 2 2

What is Fourier series of sin( M0t )

Discrete cases?

OUTLINE
Fourier series of exponential signals Fourier series of a continuous-time rectangular signal sinc function

Fourier series of a continuous-time rectangular signal


x(t) 1.5

0.5

-0.5

-T

-T/2

-T1 0

T1

T/2

Fourier series of a continuous-time rectangular signal II


sin k0T1 ak k
a0 ?

(Example 3.5)

Plot the series: FS generation function


function ak=series_term(k,T1,T)

% to compute Fourier series a_k


% T is the period, 2*T1 is the width of the rectangular pulses % k is the input (integer). ak is the output % which is the k-th term of the Fourier series omega0=2*pi/T; if k==0 ak=2*T1/T; else ak=sin(k*2*pi/T*T1)/(k*pi); end

Plot the series: scale k-scripts


Case1: T1=1, T=20;
for k=-30:30 a(k+30+1)=series_term(k,1,20); b(k+30+1)=series_term(k,1,10); end figure;subplot(2,1,1)

Case2: T1=1, T=10;

set(gca,'fontsize',14); stem(-30:30,a,'.'); xlabel('k');ylabel('a_k') subplot(2,1,2) set(gca,'fontsize',14); stem(-30:30,b,'.'); xlabel('k');ylabel('b_k')

Plot the series: scale k


0.15 0.1

ak

0.05 0 -0.05 -30 0.3 0.2 -20 -10 0 k 10 20 30

bk

0.1 0 -0.1 -30 -20 -10 0 k 10 20 30

Plot the series: scale K0 -Scripts


figure;subplot(2,1,1) set(gca,'fontsize',14); stem((-30:30)*2*pi/20,a,'.'); xlim([-6*pi,6*pi]) % x-axis from 6pi to 6pi xlabel('k');ylabel('a_k') subplot(2,1,2) set(gca,'fontsize',14); stem((-30:30)*2*pi/10,b,'.');

xlim([-6*pi,6*pi]) % x-axis from -6pi to 6pi xlabel('k');ylabel('b_k')

Plot the series: scale


0.1

K 0

ak

-0.1

-15

-10

-5

0 k 0

10

15

0.3 0.2

bk

0.1 0 -0.1 -15 -10 -5 0 k 0 5 10 15

OUTLINE
Fourier series of exponential signals Fourier series of a continuous-time rectangular signal sinc function

Definition of sinc() function


sin t sinc(t ) t
MATLAB has a built-in function Why do we want to use sinc()? Dont need to write your own code.

sinc()

It can take vectors as input.

Using sinc() to calculate FS


sin k0T1 sin k0 (T1 / ) 0T1 2T1 ak sinc(2 kT1 / T )) k k0 (T1 / ) T
T=10;

k=-30:30; c=2/20*sinc(2*1/T.*k); figure;set(gca,'fontsize',14); stem(k*2*pi/T,c,'.'); xlim([-6*pi,6*pi]) xlabel('k\omega_0'); title('T_1=1,T=10')

Using sinc() to plot FS


T1=1,T=10 0.1 0.08 0.06 0.04 0.02 0 -0.02 -0.04 -15 -10 -5 0 k 0 5 10 15

Practice problems
Find the expression of the Fourier Series of the following signals. Plot the series.
x(t ) sin(

5 x[ n] cos( ( n 1)) 12

MATLAB question in Homework 4

You might also like