Scilab Textbook Companion for Principles Of Linear Systems And Signals by B. P. Lathi1 Created by A. Lasya Priya B.Tech (pursuing) Electrical Engineering NIT, Surathkal College Teacher H. Girisha Navada, NIT Surathkal Cross-Checked by S.M. Giridharan, IIT Bombay August 11, 2013
1 Funded
by a grant from the National Mission on Education through ICT, http://spoken-tutorial.org/NMEICT-Intro. This Textbook Companion and Scilab codes written in it can be downloaded from the ”Textbook Companion Project” section at the website http://scilab.in
Book Description Title: Principles Of Linear Systems And Signals Author: B. P. Lathi Publisher: Oxford University Press Edition: 2 Year: 2009 ISBN: 0-19-806227-3
1
Scilab numbering policy used in this document and the relation to the above book. Exa Example (Solved example) Eqn Equation (Particular equation of the above book) AP Appendix to Example(Scilab Code that is an Appednix to a particular Example of the above book) For example, Exa 3.51 means solved example 3.51 of this book. Sec 2.3 means a scilab code whose theory is explained in Section 2.3 of the book.
2
Contents List of Scilab Codes
4
1 signals and systems
10
2 time domain analysis of continuous time systems
26
3 time domain analysis of discrete time systems
42
4 continuous time system analysis
60
5 discrete time system analysis using the z transform
78
6 continuous time signal analysis the fourier series
89
7 continuous time signal analysis the fourier transform
97
8 Sampling The bridge from continuous to discrete
111
9 fourier analysis of discrete time signals
117
10 state space analysis
134
3
List of Scilab Codes Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa
1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.10 2.5 2.6 2.7 2.8 2.9 3.1 3.8 3.9 3.10 3.11 3.13 3.14 3.16 3.17 3.18 3.19 3.20 4.1 4.2 4.3.a
power and rms value . . . . . . . . . . . . . . . time shifting . . . . . . . . . . . . . . . . . . . time scaling . . . . . . . . . . . . . . . . . . . . time reversal . . . . . . . . . . . . . . . . . . . basic signal models . . . . . . . . . . . . . . . . describing a signal in a single expression . . . . even and odd components of a signal . . . . . . input output equation . . . . . . . . . . . . . . unit impulse response for an LTIC system . . . zero state response . . . . . . . . . . . . . . . . graphical convolution . . . . . . . . . . . . . . graphical convolution . . . . . . . . . . . . . . graphical convolution . . . . . . . . . . . . . . energy and power of a signal . . . . . . . . . . iterative solution . . . . . . . . . . . . . . . . . iterative solution . . . . . . . . . . . . . . . . . total response with given initial conditions . . . iterative determination of unit impulse response convolution of discrete signals . . . . . . . . . . convolution of discrete signals . . . . . . . . . . sliding tape method of convolution . . . . . . . total response with given initial conditions . . . total response with given initial conditions . . . forced response . . . . . . . . . . . . . . . . . . forced response . . . . . . . . . . . . . . . . . . laplace transform of exponential signal . . . . . laplace transform of given fsignal . . . . . . . . laplace transform in case of different roots . . . 4
. . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . .
10 11 14 15 17 21 22 23 26 29 32 33 38 42 44 45 46 50 50 52 53 54 55 56 59 60 60 62
Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa
4.3.b 4.3.c 4.4 4.5 4.8 4.9 4.10 4.11 4.12 4.15 4.16 4.17 4.23 4.24 4.25 4.26 4.27 4.28 4.29 4.30 4.31 5.1 5.2 5.3.a 5.3.c 5.5 5.6 5.10 5.12 5.13 5.17 5.18 5.19 5.20 6.1 6.2 6.3 6.5
laplace transform in case of similar roots . . . . . . laplace transform in case of imaginary roots . . . . laplace transform of a given signal . . . . . . . . . inverse laplace transform . . . . . . . . . . . . . . time convolution property . . . . . . . . . . . . . . initial and final value . . . . . . . . . . . . . . . . second order linear differential equation . . . . . . solution to ode using laplace transform . . . . . . . response to LTIC system . . . . . . . . . . . . . . loop current in a given network . . . . . . . . . . . loop current in a given network . . . . . . . . . . . voltage and current of a given network . . . . . . . frequency response of a given system . . . . . . . . frequency response of a given system . . . . . . . . bode plots for given transfer function . . . . . . . . bode plots for given transfer function . . . . . . . . second order notch filter to suppress 60Hz hum . . bilateral inverse transform . . . . . . . . . . . . . . current for a given RC network . . . . . . . . . . . response of a noncausal sytem . . . . . . . . . . . response of a fn with given tf . . . . . . . . . . . . z transform of a given signal . . . . . . . . . . . . z transform of a given signal . . . . . . . . . . . . z transform of a given signal with different roots . z transform of a given signal with imaginary roots solution to differential equation . . . . . . . . . . . response of an LTID system using difference eq . . response of an LTID system using difference eq . . maximum sampling timeinterval . . . . . . . . . . discrete time amplifier highest frequency . . . . . . bilateral z transfrom . . . . . . . . . . . . . . . . . bilateral inverse z transform . . . . . . . . . . . . . transfer function for a causal system . . . . . . . . zero state response for a given input . . . . . . . . fourier coefficients of a periodic sequence . . . . . . fourier coefficients of a periodic sequence . . . . . . fourier spectra of a signal . . . . . . . . . . . . . . exponential fourier series . . . . . . . . . . . . . . 5
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
62 63 63 64 64 65 65 66 66 67 67 67 68 69 69 69 74 75 76 76 77 78 78 80 81 82 82 83 84 84 84 85 86 87 89 90 91 92
Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa
6.7 6.9 7.1 7.4 7.5 7.6 7.7 7.8 7.9 7.12 8.8 8.9 8.10 9.1 9.2 9.3 9.4 9.5 9.6 9.9 9.10.a 9.13 10.4 10.5 10.6 10.7 10.8 10.9 10.10 10.11 10.12 10.13
exponential fourier series for the impulse train . exponential fourier series to find the output . . fourier transform of exponential function . . . . inverse fourier transform . . . . . . . . . . . . . inverse fourier transform . . . . . . . . . . . . . fourier transform for everlasting sinusoid . . . . fourier transform of a periodic signal . . . . . . fourier transform of a unit impulse train . . . . fourier transform of unit step function . . . . . fourier transform of exponential function . . . . discrete fourier transform . . . . . . . . . . . . discrete fourier transform . . . . . . . . . . . . frequency response of a low pass filter . . . . . discrete time fourier series . . . . . . . . . . . . DTFT for periodic sampled gate function . . . discrete time fourier series . . . . . . . . . . . . discrete time fourier series . . . . . . . . . . . . DTFT for rectangular pulse . . . . . . . . . . . DTFT for rectangular pulse spectrum . . . . . DTFT of sinc function . . . . . . . . . . . . . . sketching the spectrum for a modulated signal . frequency response of LTID . . . . . . . . . . . state space descrption by transfer function . . . finding the state vector . . . . . . . . . . . . . state space descrption by transfer function . . . time domain method . . . . . . . . . . . . . . . state space descrption by transfer function . . . state equations of a given systems . . . . . . . diagonalized form of state equation . . . . . . . controllability and observability . . . . . . . . . state space description of a given description . total response using z transform . . . . . . . .
6
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
94 95 97 99 101 102 104 105 107 109 111 113 114 117 118 120 123 125 127 129 131 132 134 134 135 135 136 136 137 137 138 138
List of Figures 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 1.10
time shifting . . . . . . . . . . . . . . . . time shifting . . . . . . . . . . . . . . . . time scaling . . . . . . . . . . . . . . . . time scaling . . . . . . . . . . . . . . . . time reversal . . . . . . . . . . . . . . . . time reversal . . . . . . . . . . . . . . . . basic signal models . . . . . . . . . . . . describing a signal in a single expression even and odd components of a signal . . even and odd components of a signal . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
12 13 15 16 18 19 20 21 23 24
2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 2.10
unit impulse response unit impulse response zero state response . zero state response . graphical convolution graphical convolution graphical convolution graphical convolution graphical convolution graphical convolution
an LTIC system an LTIC system . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
27 28 30 31 34 35 36 37 39 40
3.1 3.2 3.3 3.4 3.5 3.6 3.7
energy and power of a signal . . . . . . . . . . . iterative solution . . . . . . . . . . . . . . . . . iterative solution . . . . . . . . . . . . . . . . . total response with given initial conditions . . . total response with given initial conditions . . . iterative determination of unit impulse response convolution of discrete signals . . . . . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
43 44 45 47 48 49 51
for for . . . . . . . . . . . . . . . .
7
3.8 3.9 3.10 3.11 3.12 3.13
convolution of discrete signals . . . . . . . sliding tape method of convolution . . . . total response with given initial conditions total response with given initial conditions forced response . . . . . . . . . . . . . . . forced response . . . . . . . . . . . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
52 53 54 55 57 58
4.1 4.2 4.3 4.4 4.5 4.6 4.7
laplace transform of exponential signal . . . . . frequency response of a given system . . . . . . frequency response of a given system . . . . . . frequency response of a given system . . . . . . bode plots for given transfer function . . . . . . bode plots for given transfer function . . . . . . second order notch filter to suppress 60Hz hum
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
61 68 70 71 72 73 74
5.1 5.2
z transform of a given signal . . . . . . . . . . . . . . . . . . response of an LTID system using difference eq . . . . . . .
79 83
6.1 6.2 6.3 6.4 6.5
fourier coefficients of a periodic sequence . . . fourier coefficients of a periodic sequence . . . exponential fourier series . . . . . . . . . . . . exponential fourier series for the impulse train exponential fourier series to find the output .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
90 91 93 94 96
7.1 7.2 7.3 7.4 7.5 7.6 7.7
fourier transform of exponential function inverse fourier transform . . . . . . . . . fourier transform for everlasting sinusoid fourier transform of a periodic signal . . fourier transform of a unit impulse train fourier transform of unit step function . fourier transform of exponential function
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
98 100 103 104 106 108 109
8.1 8.2 8.3
discrete fourier transform . . . . . . . . . . . . . . . . . . . . discrete fourier transform . . . . . . . . . . . . . . . . . . . . frequency response of a low pass filter . . . . . . . . . . . . .
112 113 115
9.1 9.2 9.3
discrete time fourier series . . . . . . . . . . . . . . . . . . . DTFT for periodic sampled gate function . . . . . . . . . . . discrete time fourier series . . . . . . . . . . . . . . . . . . .
118 119 120
8
. . . . . . .
. . . . . .
. . . . . . .
. . . . . .
. . . . . . .
9.4 9.5 9.6 9.7 9.8 9.9
discrete time fourier series . . . . . . . . . . . discrete time fourier series . . . . . . . . . . . DTFT for rectangular pulse . . . . . . . . . . DTFT for rectangular pulse spectrum . . . . . DTFT of sinc function . . . . . . . . . . . . . sketching the spectrum for a modulated signal
9
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
123 124 126 128 129 131
Chapter 1 signals and systems
Scilab code Exa 1.2 power and rms value 1 // s i g n a l s and s y s t e m s 2 // power and rms v a l u e o f a s i g n a l 3 clear all 4 close 5 clc 6 // p a r t a i s a p e r i o d i c f u n c t i o n w i t h p e r i o d 2∗ p i /w0 7 8 disp ( ” c o n s i d e r t h e power f o r a l m o s t i n f i n i t e r a n g e ” ) 9 10
11 12 13 14 15 16
; disp ( ’ p a r t ( a ) ’ ) disp ( ” i n t e g r a t i n g ( ( c ∗ c o s ( w0∗ t +t h e t a ) ) ˆ 2 ) f o r t h i s b i g r a n g e g i v e s c ˆ 2 / 2 a s t h e power which i s i r r e s p e c t i v e o f w0” ) ; disp ( ” rms v a l u e i s t h e s q u a r e r o o t o f power and t h e r e f p r e e q u a l t o s q r t ( c ˆ 2 / 2 ) \n\n ” ) ; // p a r t b i s t h e sum o f 2 s i n u s o i d s disp ( ’ p a r t ( b ) ’ ) disp ( ” a g a i n i n t e g r a t i n g i n t h e same way and i g n o r i n g t h e z e r o t e r m s we g e t ( c 1 ˆ2+ c 2 ˆ 2 ) /2 ” ) ; // p a r t c d e a l s w i t h a c o m p l e x s i g n a l disp ( ’ p a r t ( c ) ’ ) 10
17
disp ( ” i n t e g r a t i n g t h e e x p r e s s i o n we g e t | D| ˆ 2 a s t h e power and | D | a s t h e rms v a l u e ” ) ;
Scilab code Exa 1.3 time shifting 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
// s i g n a l s and s y s t e m s // t i m e s h i f t i n g clear all close clc t =[ -4:0.001:4]; a = gca () ; plot (t ,( exp ( -2* t ) ) .*( t >0) ) a . thickness =2; a . y_location = ” m i d d l e ” ; xtitle =( ’ t h e s i g n a l x ( t ) ’ ) // d e l a y i n g t h e f u n c t i o n by 1 s e c o n d we o b t a i n figure a = gca () ; plot (t ,( exp ( -2*( t -1) ) ) .*(( t >1) ) ) a . thickness =2; a . y_location = ” m i d d l e ” ; title =( ’ t h e s i g n a l x ( t −1) ’ ) // a d v a n c i n g t h e f u n c t i o n by 1 s e c o n d we o b t a i n figure a = gca () ; plot (t ,( exp ( -2*( t +1) ) ) .*( t > -1) ) a . thickness =2; a . y_location = ” m i d d l e ” ; xtitle =( ’ t h e s i g n a l x ( t +1) ’ )
11
Figure 1.1: time shifting
12
Figure 1.2: time shifting
13
Scilab code Exa 1.4 time scaling 1 // s i g n a l s and s y s t e m s 2 // t i m e s c a l i n g 3 clear all 4 close 5 clc 6 t =[ -4:0.1:6]; 7 a = gca () ; 8 plot (t ,2.*(( t > -1.5) &( t <=0) ) +2* exp ( - t /2) .*(( t >0) &( t 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
<=3) ) ) ; figure a . thickness =2; a . y_location = ” m i d d l e ” ; xtitle =( ’ t h e s i g n a l x ( t ) ’ ) ; // c o m p r e s s i n g t h i s g r a p h by a f a c t o r 3 a = gca () ; plot (t ,2.*(( t > -0.5) &( t <=0) ) +2* exp ( -3* t /2) .*(( t >0) &( t <=1) ) ) ; figure a . thickness =2; a . y_location = ” m i d d l e ” ; xtitle =( ’ t h e s i g n a l x ( 3 t ) ’ ) ; // e x p a n d i n g t h i s s i g n a l by a f a c t o r 2 a = gca () ; plot (t ,2.*(( t > -3) &( t <=0) ) +2* exp ( - t /4) .*(( t >0) &( t <=6) )); a . thickness =2; a . y_location = ” m i d d l e ” ; xtitle =( ’ t h e s i g n a l x ( t / 2 ) ’ ) ; // t h e c o o r d i n a t e s can b e a s i l y o b t a i n e d from t h e graphs
14
Figure 1.3: time scaling
Scilab code Exa 1.5 time reversal 1 // s i g n a l s and s y s t e m s 2 // t i m e r e v e r s a l 3 clear all 4 close 5 clc 6 t =[ -6:0.1:6];
15
Figure 1.4: time scaling
16
7 8 9 10 11 12 13 14 15 16 17 18 19
a = gca () ; plot (t , exp ( t /2) .*(( t >= -5) &( t <= -1) ) ) ; figure a . thickness =2; a . y_location = ” m i d d l e ” ; xtitle =( ’ t h e s i g n a l x ( t ) ’ ) // by r e p l a c i n g t by −t we g e t a = gca () ; plot (t , exp ( - t /2) .*(( t >=1) &( t <5) ) ) ; a . thickness =2; a . y_location = ” m i d d l e ” ; xtitle =( ’ t h e s i g n a l x(− t ) ’ ) // t h e c o o r d i n a t e s can be e a s i l y o b s e r v e d from t h e graphs
Scilab code Exa 1.6 basic signal models 1 // s i g n a l s and s y s t e m s 2 // r e p r e s e n t a t i o n o f a s i g n a l 3 clear all 4 close 5 clc 6 t =[0:0.1:5]; 7 a = gca () ; 8 plot (t , t .*(( t >=0) &( t <=2) ) - 2*( t -3) .*(( t >2) &( t <=3) ) )
; 9 a . thickness =2; 10 a . y_location = ” m i d d l e ” ; 11 xtitle =( ’ t h e s i g n a l x ( t ) ’ ) 17
Figure 1.5: time reversal
18
Figure 1.6: time reversal
19
Figure 1.7: basic signal models
20
Figure 1.8: describing a signal in a single expression 12 13
// t h i s can be w r i t t e n a s a c o m b i n a t i o n o f 2 l i n e s disp ( ” x ( t )=x1 ( t )+x2 ( t )= t u ( t ) −3( t −2)u ( t −2) +2( t −3)u ( t −3) ” ) ;
Scilab code Exa 1.7 describing a signal in a single expression 1 // s i g n a l s and s y s t e m s 2 // r e p r e s e n t a t i o n o f a s i g n a l 3 clear all 4 close 5 clc
21
6 t =[ -2:0.1:5]; 7 a = gca () ; 8 plot (t ,2.*(( t >= -1.5) &( t <0) ) +2* exp ( - t /2) .*(( t >=0) &( t
<3) ) ) ; 9 a . thickness =2; 10 a . y_location = ” m i d d l e ” ; 11 xtitle =( ’ t h e s i g n a l x ( t −1) ’ ) 12 // t h i s i s a c o b i n a t i o n o f a c o n s t a n t 13
f u n c t i o n and an
exponential function disp ( ” x ( t )=x1 ( t )+x2 ( t )= 2 u ( t + 1 . 5 ) −2(1− exp (− t / 2 ) ) u ( t ) −2exp (− t / 2 ) u ( t −3) ” ) ;
Scilab code Exa 1.8 even and odd components of a signal 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
// s i g n a l s and s y s t e m s // odd and e v e n c o mp o n e n t s clear all close clc t = 0:1/100:5; x = exp ( %i .* t ) ; y = exp ( - %i .* t ) ; even = x ./2+ y ./2; odd = x ./2 - y ./2; figure a = gca () ; plot2d (t , even ) a . x_location = ’ o r i g i n ’ xtitle =( ’ e v e n ’ ) figure a = gca () ; plot2d (t , odd ./ %i ) a . x_location = ’ o r i g i n ’ xtitle =( ’ odd ’ )
22
Figure 1.9: even and odd components of a signal
Scilab code Exa 1.10 input output equation 1 2 3 4 5 6 7 8
// s i g n a l s and s y s t e m s // f o r m a t i o n o f d i f f e r e n t i a l e q u a t i o n f o r a s e r i e s RC circuit clear all close clc r =15; c =0.2; // l e t t h e i n p u t v o l t a g e be x ( t ) 23
Figure 1.10: even and odd components of a signal
24
// l e t t h e l o o p c u r r e n t be i ( t ) // l e t c a p a c i t o r v o l t a g e be y ( t ) disp ( ” t h e l o o p e q u a t i o n 4 t h e c i r c u i t i s g i v e n by r ∗ i ( t ) +(5/D) ∗ i ( t )=x ( t ) ” ) 12 disp ( ” f i n a l form − ( 3D+1) y ( t )=x ( t ) ” ) 13 // t h e n e x t f e w p r o b l e m s a r e o f t h e same t y p e where we have t o f r a m e t h e e q a t i o n b a s e d on t h e scenario
9 10 11
25
Chapter 2 time domain analysis of continuous time systems
Scilab code Exa 2.5 unit impulse response for an LTIC system 1 2
// t i m e domain a n a l y s i s o f c o n t i n u o u s t i m e s y s t e m s // C o n v o l u t i o n I n t e g r a l o f i n p u t x ( t ) = ( eˆ− t ) . u ( t ) and g ( t ) =( e ˆ−2∗ t ) u ( t ) clear all ; close ; clc ; Max_Limit = 10; t = 0:0.001:10; for i =1: length ( t ) g ( i ) =( exp ( -2* t ( i ) ) ) ; end x = exp ( -( t ) ) ;
3 4 5 6 7 8 9 10 11 12 13 y = convol (x , g ) 14 figure
26
Figure 2.1: unit impulse response for an LTIC system
27
Figure 2.2: unit impulse response for an LTIC system
28
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
a = gca () ; plot2d (t , g ) xtitle ( ’ I m p u l s e R e s p o n s e ’ , ’ t ’ , ’ h ( t ) ’ ) ; a . thickness = 2; figure a = gca () ; plot2d (t , x ) xtitle ( ’ I n p u t R e s p o n s e ’ , ’ t ’ , ’ x ( t ) ’ ) ; a . thickness = 2; figure a = gca () ; T =0:0.001:20; plot2d (T , y ) xtitle ( ’ Output R e s p o n s e ’ , ’ t ’ , ’ y ( t ) ’ ) ; a . thickness = 2;
Scilab code Exa 2.6 zero state response 1 2 3 4 5 6 7 8 9 10 11 12
// t i m e domain a n a l y s i s o f c o n t i n u o u s t i m e s y s t e m s // C o n v o l u t i o n I n t e g r a l o f i n p u t x ( t ) = ( e ˆ−3 t ) . u ( t ) and h ( t ) =(2∗ e ˆ−2∗ t−eˆ− t ) u ( t ) clear ; close ; clc ; Max_Limit = 10; t = 0:0.001:10; for i =1: length ( t ) g ( i ) =(2* exp ( -2* t ( i ) ) - exp ( - t ( i ) ) ) ; end x = exp ( -3*( t ) ) ;
29
Figure 2.3: zero state response
30
Figure 2.4: zero state response
31
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
y = convol (x , g ) figure a = gca () ; plot2d (t , g ) xtitle ( ’ I m p u l s e R e s p o n s e ’ , ’ t ’ , ’ h ( t ) ’ ) ; a . thickness = 2; figure a = gca () ; plot2d (t , x ) xtitle ( ’ I n p u t R e s p o n s e ’ , ’ t ’ , ’ x ( t ) ’ ) ; a . thickness = 2; figure a = gca () ; T =0:0.001:20; plot2d (T , y ) xtitle ( ’ Output R e s p o n s e ’ , ’ t ’ , ’ y ( t ) ’ ) ; a . thickness = 2;
Scilab code Exa 2.7 graphical convolution 1 2
// t i m e domain a n a l y s i s o f c o n t i n u o u s t i m e s y s t e m s // C o n v o l u t i o n I n t e g r a l o f i n p u t x ( t ) = ( eˆ− t ) . u ( t ) and g ( t ) =u ( t ) clear all ; close ; clc ; Max_Limit = 10; t = -10:0.001:10; for i =1: length ( t )
3 4 5 6 7 8 9 10 g ( i ) = exp ( - t ( i ) ) ; 11 x ( i ) = exp ( -2* t ( i ) ) ; 12 end 13 14 y = convol (x , g )
32
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
figure a = gca () ; plot2d (t , g ) xtitle ( ’ I m p u l s e R e s p o n s e ’ , ’ t ’ , ’ h ( t ) ’ ) ; a . thickness = 2; figure a = gca () ; plot2d (t , x ) xtitle ( ’ I n p u t R e s p o n s e ’ , ’ t ’ , ’ x ( t ) ’ ) ; a . thickness = 2; figure a = gca () ; T = -20:0.001:20; plot2d (T , y ) xtitle ( ’ Output R e s p o n s e ’ , ’ t ’ , ’ y ( t ) ’ ) ; a . thickness = 2;
Scilab code Exa 2.8 graphical convolution 1 2 3 4 5 6 7
// t i m e domain a n a l y s i s o f c o n t i n u o u s t i m e s y s t e m s // C o n v o l u t i o n I n t e g r a l o f i n p u t x ( t ) = ( eˆ− t ) . u ( t ) and g ( t ) =u ( t ) clear all ; close ; clc ; Max_Limit = 10; t = -10:0.001:10; 33
Figure 2.5: graphical convolution
34
Figure 2.6: graphical convolution
35
Figure 2.7: graphical convolution
36
Figure 2.8: graphical convolution
37
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
for i =1: length ( t ) if t ( i ) <0 then g ( i ) = -2* exp (2* t ( i ) ) ; x ( i ) =0; else g ( i ) =2* exp ( - t ( i ) ) ; x ( i ) =1; end end y = convol (x , g ) figure a = gca () ; plot2d (t , g ) xtitle ( ’ I m p u l s e R e s p o n s e ’ , ’ t ’ , ’ h ( t ) ’ ) ; a . thickness = 2; figure a = gca () ; plot2d (t , x ) xtitle ( ’ I n p u t R e s p o n s e ’ , ’ t ’ , ’ x ( t ) ’ ) ; a . thickness = 2; figure a = gca () ; T = -20:0.001:20; plot2d (T , y ) xtitle ( ’ Output R e s p o n s e ’ , ’ t ’ , ’ y ( t ) ’ ) ; a . thickness = 2;
Scilab code Exa 2.9 graphical convolution 1
// t i m e domain a n a l y s i s o f c o n t i n u o u s t i m e s y s t e m s 38
Figure 2.9: graphical convolution
39
Figure 2.10: graphical convolution
40
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
// C o n v o l u t i o n I n t e g r a l o f i n p u t x ( t ) = ( eˆ− t ) . u ( t ) and g ( t ) =u ( t ) clear all ; close ; clc ; Max_Limit = 10; t = linspace ( -1 ,1 ,10001) ; for i =1: length ( t ) g ( i ) =1; end t1 = linspace (0 ,3 ,10001) ; for i =1: length ( t1 ) x ( i ) = t1 ( i ) /3; end y = convol (x , g ) ; figure a = gca () ; size ( t ) size ( g ) plot2d (t , g ) xtitle ( ’ I m p u l s e R e s p o n s e ’ , ’ t ’ , ’ h ( t ) ’ ) ; a . thickness = 2; figure a = gca () ; size ( x ) plot2d ( t1 , x ) xtitle ( ’ I n p u t R e s p o n s e ’ , ’ t ’ , ’ x ( t ) ’ ) ; a . thickness = 2; figure a = gca () ; T = linspace ( -1 ,4 ,20001) ; size ( y ) plot2d (T , y ) xtitle ( ’ Output R e s p o n s e ’ , ’ t ’ , ’ y ( t ) ’ ) ; a . thickness = 2;
41
Chapter 3 time domain analysis of discrete time systems
Scilab code Exa 3.1 energy and power of a signal 1 // s i g n a l s and s y s t e m s 2 // t i m e domain a n a l y s i s 3 // e n e r g y o f a s i g n a l 4 clear all ; 5 close ; 6 clc ; 7 n =0:1:5 8 figure 9 a = gca () ; 10 plot2d (n , n ) ; 11 energy = sum ( n ^2) 12 power =(1/6) * sum ( n ^2) 13 disp ( energy ) 14 disp ( power )
o f d i s c r e e t time systems
42
Figure 3.1: energy and power of a signal
43
Figure 3.2: iterative solution
Scilab code Exa 3.8 iterative solution 1 2 3 4 5 6 7 8 9 10 11 12 13
// s i g n a l s and s y s t e m s // t i m e domain a n a l y s i s o f d i s c r e e t t i m e s y s t e m s // i t e r a t i v e s o l u t i o n clear all ; close ; clc ; n =( -1:10) ’; y =[16;0; zeros ( length ( n ) -2 ,1) ]; x =[0;0; n (3: length ( n ) ) ]; for k =1: length ( n ) -1 y ( k +1) =0.5* y ( k ) + x ( k +1) ; end ; clf ; 44
Figure 3.3: iterative solution 14 15 16 17 18
size ( y ) size ( n ) plot2d3 (n , y ) ; plot (n ,y , ’ r . ’ ) disp ([ msprintf ([ n , y ]) ]) ;
Scilab code Exa 3.9 iterative solution 1 // s i g n a l s and s y s t e m s 2 // t i m e domain a n a l y s i s 3 // i t e r a t i v e s o l u t i o n 4 clear all ; 5 close ; 6 clc ;
o f d i s c r e e t time systems
45
7 8 9 10 11 12 13 14 15
n =( -2:10) ’; y =[1;2; zeros ( length ( n ) -2 ,1) ]; x =[0;0; n (3: length ( n ) ) ]; for k =1: length ( n ) -2 y ( k +2) = y ( k +1) -0.24* y ( k ) + x ( k +2) -2* x ( k +1) ; end ; clf ; plot2d3 (n , y ) ; disp ([ msprintf ([ n , y ]) ]) ;
Scilab code Exa 3.10 total response with given initial conditions 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
// s i g n a l s and s y s t e m s // t i m e domain a n a l y s i s o f d i s c r e e t t i m e s y s t e m s // t o t a l r e s p o n s e w i t h i n i t i a l c o n d i t i o n s clear all ; close ; clc ; n =( -2:10) ’; y =[25/4;0; zeros ( length ( n ) -2 ,1) ]; x =[0;0;4^ - n (3: length ( n ) ) ]; for k =1: length ( n ) -2 y ( k +2) =0.6* y ( k +1) +0.16* y ( k ) +5* x ( k +2) ; end ; clf ; a = gca () ; plot2d3 (n , y ) ; y1 =[25/4;0; zeros ( length ( n ) -2 ,1) ]; x =[0;0;4^ - n (3: length ( n ) ) ]; for k =1: length ( n ) -2 y1 ( k +2) = -6* y1 ( k +1) -9* y1 ( k ) +2* x ( k +2) +6* x ( k +1) ; end figure a = gca () ; 46
Figure 3.4: total response with given initial conditions 24 25 26 27 28 29 30 31 32 33 34
plot2d3 (n , y1 ) ;
y2 =[25/4;0; zeros ( length ( n ) -2 ,1) ]; x =[0;0;4^ - n (3: length ( n ) ) ]; for k =1: length ( n ) -2 y2 ( k +2) =1.56* y2 ( k +1) -0.81* y2 ( k ) + x ( k +1) +3* x ( k ) ; end figure a = gca () ; plot2d3 (n , y2 ) ;
47
Figure 3.5: total response with given initial conditions
48
Figure 3.6: iterative determination of unit impulse response
49
Scilab code Exa 3.11 iterative determination of unit impulse response 1 2 3 4 5 6 7 8 9 10 11 12 13
// s i g n a l s and s y s t e m s // t i m e domain a n a l y s i s o f d i s c r e e t t i m e s y s t e m s // i m p u l s e r e s p o n s e w i t h i n i t i a l c o n d i t i o n s clear all ; close ; clc ; n =(0:19) ; x =[1 zeros (1 , length ( n ) -1) ]; a =[1 -0.6 -0.16]; b =[5 0 0]; h = filter (b ,a , x ) ; clf ; plot2d3 (n , h ) ; xlabel ( ’ n ’ ) ; ylabel ( ’ h [ n ] ’ ) ;
Scilab code Exa 3.13 convolution of discrete signals 1 2 3 4 5 6 7 8 9 10 11 12
// s i g n a l s and s y s t e m s // t i m e domain a n a l y s i s o f d i s c r e e t t i m e s y s t e m s // c o n v o l u t i o n clear all ; close ; clc ; n =(0:19) ; x =0.8^ n ; g =0.3^ n ; n1 =(0:1: length ( x ) + length ( g ) -2) ; c = convol (x , g ) ; plot2d3 ( n1 , c ) ; 50
Figure 3.7: convolution of discrete signals
51
Figure 3.8: convolution of discrete signals
Scilab code Exa 3.14 convolution of discrete signals 1 2 3 4 5 6 7 8 9 10 11
// s i g n a l s and s y s t e m s // t i m e domain a n a l y s i s o f d i s c r e e t t i m e s y s t e m s // c o n v o l u t i o n clear all ; close ; clc ; n =(0:14) ; x =4^ - n ; a =[1 -0.6 -0.16]; b =[5 0 0]; y = filter (b ,a , x ) ; 52
Figure 3.9: sliding tape method of convolution 12 clf ; 13 plot2d3 (n , y ) ; xlabel ( ’ n ’ ) ; ylabel ( ’ y [ n ] ’ ) ;
Scilab code Exa 3.16 sliding tape method of convolution 1 2 3 4 5 6 7 8 9
// s i g n a l s and s y s t e m s // t i m e domain a n a l y s i s o f d i s c r e e t t i m e s y s t e m s // c o n v o l u t i o n by s l i d i n g t a p e method clear all ; close ; clc ; x =[ -2 -1 0 1 2 3 4]; g =[1 1 1 1 1 1 1 1]; n =(0:1: length ( x ) + length ( g ) -2) ; 53
Figure 3.10: total response with given initial conditions 10 c = convol (x , g ) ; 11 clf ; 12 plot2d3 (n , c ) ; xlabel ( ’ n ’ ) ; ylabel ( ’ c [ n ] ’ ) ;
Scilab code Exa 3.17 total response with given initial conditions 1 // s i g n a l s and s y s t e m s 2 // t i m e domain a n a l y s i s o f d i s c r e e t t i m e s y s t e m s 3 // c o n v o l u t i o n by s l i d i n g t a p e method 4 clear all ; 5 close ; 6 clc ; 7 n =(0:10) ’; 8 y =[4;13; zeros ( length ( n ) -2 ,1) ];
54
Figure 3.11: total response with given initial conditions 9 10 11 12 13 14 15 16
x =(3* n +5) .*( n >=0) ; for k =1: length ( n ) -2 y ( k +2) =5* y ( k +1) -6* y ( k ) + x ( k +1) -5* x ( k ) ; end clf ; plot2d3 (n , y ) ; xlabel ( ’ n ’ ) ; ylabel ( ’ y [ n ] ’ ) ; disp ( ’ n y ’ ); disp ( msprintf ( ’ %f\ t \ t%f \n ’ ,[n , y ]) ) ;
Scilab code Exa 3.18 total response with given initial conditions 1 2 3
// s i g n a l s and s y s t e m s // t i m e domain a n a l y s i s o f d i s c r e e t t i m e s y s t e m s // c o n v o l u t i o n by s l i d i n g t a p e method 55
4 5 6 7 8 9 10 11 12 13 14 15 16
clear all ; close ; clc ; n =(0:10) ’; y =[0; zeros ( length ( n ) -1 ,1) ]; x =( n +1) ^2; for k =1: length ( n ) -1 y ( k +1) = y ( k ) + x ( k ) ; end ; clf ; a = gca () ; plot2d3 (n , y ) ; xtitle ( ’ sum ’ , ’ n ’ ) plot (n ,y , ’ b . ’ )
Scilab code Exa 3.19 forced response 1 2 3 4 5 6 7 8 9 10 11 12 13
// s i g n a l s and s y s t e m s // t i m e domain a n a l y s i s o f d i s c r e e t t i m e s y s t e m s // c o n v o l u t i o n by s l i d i n g t a p e method clear all ; close ; clc ; n =(0:14) ; x =3^ n ; a =[1 -3 2]; b =[0 1 2]; y = filter (b ,a , x ) ; clf ; plot2d3 (n , y ) ; xlabel ( ’ n ’ ) ; ylabel ( ’ y [ n ] ’ ) ;
56
Figure 3.12: forced response
57
Figure 3.13: forced response
58
Scilab code Exa 3.20 forced response 1 2 3 4 5 6 7 8 9 10 11 12 13 14
// s i g n a l s and s y s t e m s // t i m e domain a n a l y s i s o f d i s c r e e t t i m e s y s t e m s // c o n v o l u t i o n by s l i d i n g t a p e method clear all ; close ; clc ; pi =3.14; n =(0:14) ; x = cos (2* n + pi /3) ; a =[1 -1 0.16]; b =[0 1 0.32]; y = filter (b ,a , x ) ; clf ; plot2d3 (n , y ) ; xlabel ( ’ n ’ ) ; ylabel ( ’ y [ n ] ’ ) ;
59
Chapter 4 continuous time system analysis
Scilab code Exa 4.1 laplace transform of exponential signal 1 2 3 4 5 6 7 8 9 10
// s i g n a l s and s y s t e m s // L a p l a c e T r a n s f o r m x ( t ) = exp (− a t ) . u ( t ) f o r t n e g a t i v e and p o s i t i v e syms t s ; a = 3; y = laplace ( ’ %eˆ(− a ∗ t ) ’ ,t , s ) ; t1 =0:0.001:10; plot2d ( t1 , exp ( - a * t1 ) ) ; disp ( y ) y1 = laplace ( ’ %e ˆ ( a∗− t ) ’ ,t , s ) ; disp ( y1 )
Scilab code Exa 4.2 laplace transform of given fsignal 1 2 3
// s i g n a l s and s y s t e m s // ( a ) l a p l a c e t r a n s f o r m x ( t ) = d e l ( t ) syms t s ; 60
Figure 4.1: laplace transform of exponential signal
61
4 5 y = laplace ( ’ 0 ’ ,t , s ) 6 disp ( y ) 7 // ( b ) L a p l a c e T r a n s f o r m x ( t ) = u ( t ) 8 9 y1 = laplace ( ’ 1 ’ ,t , s ) ; 10 disp ( y1 ) 11 // ( c ) l a p l a c e t r a n s f o r m x ( t ) = c o s ( w0∗ t ) u ( t ) 12 13 y2 = laplace ( ’ c o s ( w0∗ t ) ’ ,t , s ) ; 14 disp ( y2 )
Scilab code Exa 4.3.a laplace transform in case of different roots 1 // s i g n a l s and s y s t e m s 2 // I n v e r s e L a p a l c e T r a n s f o r m 3 // ( a ) X( S ) = ( 7 s −6) / s ˆ2−s −6 Re ( s )>−1 4 s = %s ; 5 syms t ; 6 [ A ]= pfss ((7* s -6) /(( s ^2 -s -6) ) ) ; // p a r t i a l 7 8 9 10 11
fraction of
F( s ) F1 = ilaplace ( A (1) ,s , t ) F2 = ilaplace ( A (2) ,s , t ) // F3 = i l a p l a c e (A( 3 ) , s , t ) F = F1 + F2 ; disp (F , ” f ( t )=” )
Scilab code Exa 4.3.b laplace transform in case of similar roots 1 // e x a m p l e 4 . 3 2 // ( b ) X( S ) = ( 2 ∗ s ˆ2+5) / s ˆ2−3∗ s +2 3 s = %s ; 4 syms t ;
62
Re ( s )>−1
5 [ A ]= pfss ((2* s ^2+5) /(( s ^2 -3* s +2) ) ) ; // p a r t i a l
f r a c t i o n o f F( s ) 6 F1 = ilaplace ( A (1) ,s , t ) 7 F2 = ilaplace ( A (2) ,s , t ) 8 // F3 = i l a p l a c e (A( 3 ) , s , t ) 9 F = F1 + F2 ; 10 disp (F , ” f ( t )=” )
Scilab code Exa 4.3.c laplace transform in case of imaginary roots 1 // e x a m p l e 4 . 3 2 // ( c ) X( S ) = 6 ( s +34) / s ( s ˆ2+10∗ s +34) Re ( s )>−1 3 s = %s ; 4 syms t ; 5 [ A ]= pfss ((6*( s +34) ) /( s *( s ^2+10* s +34) ) ) ; // p a r t i a l 6 7 8 9 10
f r a c t i o n o f F( s ) F1 = ilaplace ( A (1) ,s , t ) F2 = ilaplace ( A (2) ,s , t ) // F3 = i l a p l a c e (A( 3 ) , s , t ) F = F1 + F2 ; disp (F , ” f ( t )=” )
Scilab code Exa 4.4 laplace transform of a given signal 1 2 3 4 5 6 7 8
// s i g n a l s and s y s t e m s // L a p a l c e T r a n s f o r m x ( t ) = ( t −1)u ( t −1)−(t −2)u ( t −2)−u ( t −4) , 0
9 y3 = laplace ( ’ 1 ’ ,t , s ) ; 10 y = y1 *( %e ^( - s ) ) + y2 *( %e ^( -2* s ) ) + y3 *( %e ^( -4* s ) ) 11 disp ( y )
Scilab code Exa 4.5 inverse laplace transform 1 // s i g n a l s and s y s t e m s 2 // e x a m p l e 4 . 5 3 // X( S ) = s +3+5∗ exp ( −2∗ s ) / ( s +1) ∗ ( s +2) ) Re ( s )>−1 4 s1 = %s ; 5 syms t s ; 6 [ A ]= pfss (( s1 +3) /(( s1 +1) *( s1 +2) ) ) ; // p a r t i a l f r a c t i o n 7 8 9 10 11 12 13 14 15 16 17
o f F( s ) F1 = ilaplace ( A (1) ,s , t ) F2 = ilaplace ( A (2) ,s , t ) // F3 = i l a p l a c e (A( 3 ) , s , t ) Fa = F1 + F2 ; disp ( Fa , ” f 1 ( t )=” ) [ B ]= pfss ((5) /(( s1 +1) *( s1 +2) ) ) ; // p a r t i a l f r a c t i o n o f F( s ) F1 = ilaplace ( B (1) ,s , t ) F2 = ilaplace ( B (2) ,s , t ) Fb = ( F1 + F2 ) *( %e ^( -2* s ) ) ; disp ( Fb , ” f 2 ( t )=” ) disp ( Fa + Fb , ” f ( t )=” )
Scilab code Exa 4.8 time convolution property 1 // s i g n a l s and s y s t e m s 2 // Example 4 . 8 3 // L a p a l c e T r a n s f o r m f o r 4 s = %s 5 syms t ;
convolution
64
6 7 8 9 10 11 12
a =3; b =2; [ A ]= pfss (1/( s ^2 -5* s +6) ) ; // p a r t i a l f r a c t i o n o f F ( s ) F1 = ilaplace ( A (1) ,s , t ) F2 = ilaplace ( A (2) ,s , t ) // F3 = i l a p l a c e (A( 3 ) , s , t ) F = F1 + F2 ; disp (F , ” f ( t )=” )
Scilab code Exa 4.9 initial and final value 1 2 3 4 5 6 7 8 9 10 11
// I n i t i a l and f i n a l V a l u e Theorem o f L a p a l a c e Transform syms s ; num = poly ([30 20] , ’ s ’ , ’ c o e f f ’ ) den = poly ([0 5 2 1] , ’ s ’ , ’ c o e f f ’ ) X = num / den disp (X , ”X( s )=” ) SX = s * X ; Initial_Value = limit ( SX ,s , %inf ) ; final_value = limit ( SX ,s ,0) ; disp ( Initial_Value , ” x ( 0 )=” ) disp ( final_value , ” x ( i n f )=” )
Scilab code Exa 4.10 second order linear differential equation 1 2 3 4 5 6 7
// s i g n a l s and s y s t e m s // U n i l a t e r a l Laplace Transform : S o l v i n g D i f f e r e n t i a l Equation // e x a m p l e 4 . 1 0 s = %s ; syms t ; [ A ] = pfss ((2* s ^2+20* s +45) /(( s +2) *( s +3) *( s +4) ) ) ; F1 = ilaplace ( A (1) ,s , t ) 65
8 F2 = ilaplace ( A (2) ,s , t ) 9 F3 = ilaplace ( A (3) ,s , t ) 10 F = F1 + F2 + F3 11 disp ( F )
Scilab code Exa 4.11 solution to ode using laplace transform 1 2 3 4 5 6 7 8 9 10 11
// s i g n a l s and s y s t e m s // U n i l a t e r a l Laplace Transform : S o l v i n g D i f f e r e n t i a l Equation // e x a m p l e 4 . 1 1 s = %s ; syms t ; [ A ] = pfss ((2* s ) /( s ^2+2* s +5) ) ; F1 = ilaplace ( A (1) ,s , t ) // F2 = i l a p l a c e (A( 2 ) , s , t ) // F3 = i l a p l a c e (A( 3 ) , s , t ) F = F1 + F2 + F3 disp ( F )
Scilab code Exa 4.12 response to LTIC system 1 2 3 4 5 6 7 8 9 10
// s i g n a l s and s y s t e m s // U n i l a t e r a l Laplace Transform : S o l v i n g D i f f e r e n t i a l Equation // e x a m p l e 4 . 1 2 s = %s ; syms t ; [ A ] = pfss ((3* s +3) /(( s +5) *( s ^2+5* s +6) ) ) ; F1 = ilaplace ( A (1) ,s , t ) F2 = ilaplace ( A (2) ,s , t ) F3 = ilaplace ( A (3) ,s , t ) F = F1 + F2 + F3 66
11
disp ( F )
Scilab code Exa 4.15 loop current in a given network 1 2 3 4 5 6 7 8 9 10 11
// s i g n a l s and s y s t e m s // U n i l a t e r a l Laplace Transform : S o l v i n g D i f f e r e n t i a l Equation // e x a m p l e 4 . 1 5 s = %s ; syms t ; [ A ] = pfss ((10) /( s ^2+3* s +2) ) ; F1 = ilaplace ( A (1) ,s , t ) F2 = ilaplace ( A (2) ,s , t ) // F3 = i l a p l a c e (A( 3 ) , s , t ) F = F1 + F2 + F3 disp ( F )
Scilab code Exa 4.16 loop current in a given network 1 // s i g n a l s and s y s t e m s 2 // U n i l a t e r a l Laplace Transform : t r a n s f e r f u n c t i o n 3 // e x a m p l e 4 . 1 6 4 s = %s ; 5 syms t s ; 6 y1 = laplace ( ’ 24∗%eˆ( −3∗ t ) +48∗%eˆ( −4∗ t ) ’ ,t , s ) ; 7 disp ( y1 ) 8 y2 = laplace ( ’ 16∗%eˆ( −3∗ t ) −12∗%eˆ( −4∗ t ) ’ ,t , s ) ; 9 disp ( y2 )
Scilab code Exa 4.17 voltage and current of a given network 67
Figure 4.2: frequency response of a given system 1 2 3 4 5 6 7 8 9 10 11
// s i g n a l s and s y s t e m s // U n i l a t e r a l Laplace Transform : S o l v i n g D i f f e r e n t i a l Equation // e x a m p l e 4 . 1 7 s = %s ; syms t ; [ A ] = pfss ((2* s ^2+9* s +4) /(( s ) *( s ^2+3* s +1) ) ) ; F1 = ilaplace ( A (1) ,s , t ) F2 = ilaplace ( A (2) ,s , t ) F3 = ilaplace ( A (3) ,s , t ) F = F1 + F2 + F3 disp ( F )
Scilab code Exa 4.23 frequency response of a given system 68
1 s = poly (0 , ’ s ’ ) 2 h = syslin ( ’ c ’ ,( s +0.1) /( s +5) ) 3 clf () ; bode (h ,0.1 ,100) ;
Scilab code Exa 4.24 frequency response of a given system 1 2 3 4 5
s = poly (0 , ’ s ’ ) h = syslin ( ’ c ’ ,( s ^2/ s ) ) clf () ; bode (h ,0.1 ,100) ; h1 = syslin ( ’ c ’ ,(1/ s ) ) clf () ; bode ( h1 ,0.1 ,100) ;
Scilab code Exa 4.25 bode plots for given transfer function 1 s = poly (0 , ’ s ’ ) 2 h = syslin ( ’ c ’ ,((20* s ^2+2000* s ) /( s ^2+12* s +20) ) ) 3 clf () ; bode (h ,0.1 ,100) ;
Scilab code Exa 4.26 bode plots for given transfer function 1 s = poly (0 , ’ s ’ ) 2 h = syslin ( ’ c ’ ,((10* s +1000) /( s ^2+2* s +100) ) ) 3 clf () ; bode (h ,0.1 ,100) ;
69
Figure 4.3: frequency response of a given system
70
Figure 4.4: frequency response of a given system
71
Figure 4.5: bode plots for given transfer function
72
Figure 4.6: bode plots for given transfer function
73
Figure 4.7: second order notch filter to suppress 60Hz hum
Scilab code Exa 4.27 second order notch filter to suppress 60Hz hum 1 omega_0 =2* %pi *60; theta = [60 80 87]*( %pi /180) ; 2 omega = (0:0.5:1000) ’; mag = zeros (3 , length ( omega ) ) ; 3 s = poly (0 , ’ s ’ ) 4 for m =1: length ( theta ) 5 H = syslin ( ’ c ’ ,(( s ^2+ omega_0 ^2) /( s ^2+2* omega_0 * cos 6 7 end
( theta ( m ) ) * s + omega_0 ^2) ) ) ; bode (H ,10 ,100) ;
74
8 f = omega /((2* %pi ) ) plot (f , mag (1 ,:) , ’ k− ’ ,f mag (2 ,:) , ’ k 9 10
−− ’ ,f , mag (3 ,:) , ’ k −. ’ ) ; xlabel ( ’ f [ hz ] ’ ) ; ylabel ( ’ | H( j 2 / p i f ) | ’ ) ; legend ( ’ \ t h e t a =60ˆ\ c i r c ’ , ’ \ t h e t a = 8 0ˆ \ c i r c ’ , ’ \ t h e t a = 87ˆ \ c i r c ’ ,0)
Scilab code Exa 4.28 bilateral inverse transform 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
// s i g n a l s and s y s t e m s // b i l a t e r a l I n v e r s e L a p a l c e T r a n s f o r m //X( S ) = 1 / ( ( s −1) ( s +2) ) s = %s ; syms t ; [ A ]= pfss (1/(( s -1) *( s +2) ) ) // p a r t i a l f r a c t i o n o f F ( s ) F1 = ilaplace ( A (1) ,s , t ) F2 = ilaplace ( A (2) ,s , t ) F = F1 + F2 ; disp (F , ” f ( t )=” )
//X( S ) = 1 / ( ( s −1) ( s +2) ) Re ( s )> −1 ,Re ( s )< −2 s = %s ; syms t ; [ A ]= pfss (1/(( s -1) *( s +2) ) ) // p a r t i a l f r a c t i o n o f F ( s ) F1 = ilaplace ( A (1) ,s , t ) F2 = ilaplace ( A (2) ,s , t ) F = -F1 - F2 ; disp (F , ” f ( t )=” )
//X( S ) = 1 / ( ( s −1) ( s +2) ) −2< Re ( s )< 1 s = %s ; syms t ; [ A ]= pfss (1/(( s -1) *( s +2) ) ) // p a r t i a l f r a c t i o n o f F ( s ) F1 = ilaplace ( A (1) ,s , t ) 75
28 F2 = ilaplace ( A (2) ,s , t ) 29 F = - F1 + F2 ; 30 disp (F , ” f ( t )=” )
Scilab code Exa 4.29 current for a given RC network 1 2 3 4 5 6 7 8 9 10 11
// s i g n a l s and s y s t e m s // U n i l a t e r a l Laplace Transform : S o l v i n g D i f f e r e n t i a l Equation // e x a m p l e 4 . 3 0 s = %s ; syms t ; [ A ] = pfss (( - s ) /(( s -1) *( s -2) *( s +1) ) ) ; F1 = ilaplace ( A (1) ,s , t ) F2 = ilaplace ( A (2) ,s , t ) F3 = ilaplace ( A (3) ,s , t ) F = F1 + F2 + F3 disp ( F )
Scilab code Exa 4.30 response of a noncausal sytem 1 2 3 4 5 6 7 8 9 10 11
// s i g n a l s and s y s t e m s // U n i l a t e r a l Laplace Transform : S o l v i n g D i f f e r e n t i a l Equation // e x a m p l e 4 . 3 0 s = %s ; syms t ; [ A ] = pfss (( -1) /(( s -1) *( s +2) ) ) ; F1 = ilaplace ( A (1) ,s , t ) F2 = ilaplace ( A (2) ,s , t ) // F3 = i l a p l a c e (A( 3 ) , s , t ) F = F1 + F2 disp ( F ) 76
Scilab code Exa 4.31 response of a fn with given tf 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
// s i g n a l s and s y s t e m s // U n i l a t e r a l Laplace Transform : S o l v i n g D i f f e r e n t i a l Equation // e x a m p l e 4 . 1 7 s = %s ; syms t ; // Re s >−1 [ A ] = pfss (1/(( s +1) *( s +5) ) ) ; F1 = ilaplace ( A (1) ,s , t ) F2 = ilaplace ( A (2) ,s , t ) // F3 = i l a p l a c e (A( 3 ) , s , t ) F = F1 + F2 disp ( F ) //−5< Re s <−2 [ B ] = pfss ( -1/(( s +2) *( s +5) ) ) ; G1 = ilaplace ( B (1) ,s , t ) G2 = ilaplace ( B (2) ,s , t ) // F3 = i l a p l a c e (A( 3 ) , s , t ) G = G1 + G2 disp ( G )
77
Chapter 5 discrete time system analysis using the z transform
Scilab code Exa 5.1 z transform of a given signal 1 2 3 4 5 6 7 8 9 10
// s i g n a l s and s y s t e m s // Z t r a n s f o r m o f x [ n ] = ( a ) ˆn . u [ n ] syms n z ; a = 0.5; x =( a ) ^ n ; n1 =0:10; plot2d3 ( n1 , a ^ n1 ) ; xtitle ( ’ a ˆ n ’ , ’ n ’ ) ; plot ( n1 , a ^ n1 , ’ r . ’ ) X = symsum ( x *( z ^( - n ) ) ,n ,0 , %inf ) disp (X , ” a n s=” )
Scilab code Exa 5.2 z transform of a given signal 1
// e x a m p l e 5 . 2 ( c ) 78
Figure 5.1: z transform of a given signal
79
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
//Z−t r a n s f o r m o f s i n e s i g n a l syms n z ; Wo = %pi /4; a = (0.33) ^ n ; x1 = %e ^( sqrt ( -1) * Wo * n ) ; X1 = symsum ( a * x1 *( z ^( - n ) ) ,n ,0 , %inf ) x2 = %e ^( - sqrt ( -1) * Wo * n ) X2 = symsum ( a * x2 *( z ^( - n ) ) ,n ,0 , %inf ) X =(1/(2* sqrt ( -1) ) ) *( X1 + X2 ) disp (X , ” a n s=” ) // e x a m p l e 5 . 2 ( a ) //Z−t r a n s f o r m o f I m p u l s e S e q u e n c e syms n z ; X = symsum (1*( z ^( - n ) ) ,n ,0 ,0) ; disp (X , ” a n s=” ) // e x a m p l e 5 . 2 ( d ) //Z−t r a n s f o r m o f g i v e n S e q u e n c e syms n z ; X = symsum (1*( z ^( - n ) ) ,n ,0 ,4) ; disp (X , ” a n s=” ) // e x a m p l e 5 . 2 ( b ) //Z−t r a n s f o r m o f u n i t f u n c t i o n S e q u e n c e syms n z ; X = symsum (1*( z ^( - n ) ) ,n ,0 , %inf ) ; disp (X , ” a n s=” )
Scilab code Exa 5.3.a z transform of a given signal with different roots 1 // s i g n a l s and s y s t e m s 2 // I n v e r s e Z T r a n s f o r m :ROC | z | >1/3 3 z = %z ; 4 syms n z1 ; //To f i n d o u t I n v e r s e z t r a n s f o r m z must
80
5 6 7 8 9 10 11 12 13 14 15 16
be l i n e a r z = z 1 X =(8* z -19) /(( z -2) *( z -3) ) X1 = denom ( X ) ; zp = roots ( X1 ) ; X1 = (8* z1 -19) /(( z1 -2) *( z1 -3) ) F1 = X1 *( z1 ^( n -1) ) *( z1 - zp (1) ) ; F2 = X1 *( z1 ^( n -1) ) *( z1 - zp (2) ) ; h1 = limit ( F1 , z1 , zp (1) ) ; disp ( h1 , ’ h1 [ n ]= ’ ) h2 = limit ( F2 , z1 , zp (2) ) ; disp ( h2 , ’ h2 [ n ]= ’ ) h = h1 + h2 ; disp (h , ’ h [ n ]= ’ )
Scilab code Exa 5.3.c z transform of a given signal with imaginary roots 1 // s i g n a l s and s y s t e m s 2 // I n v e r s e Z T r a n s f o r m :ROC | z | >1/3 3 z = %z ; 4 syms n z1 ; //To f i n d o u t I n v e r s e z t r a n s f o r m z must 5 6 7 8 9 10 11 12 13 14 15 16
be l i n e a r z = z 1 X =(2* z *(3* z +17) ) /(( z -1) *( z ^2 -6* z +25) ) X1 = denom ( X ) ; zp = roots ( X1 ) ; X1 = 2* z1 *(3* z1 +17) /(( z1 -1) *( z1 ^2 -6* z1 +25) ) F1 = X1 *( z1 ^( n -1) ) *( z1 - zp (1) ) ; F2 = X1 *( z1 ^( n -1) ) *( z1 - zp (2) ) ; h1 = limit ( F1 , z1 , zp (1) ) ; disp ( h1 , ’ h1 [ n ]= ’ ) h2 = limit ( F2 , z1 , zp (2) ) ; disp ( h2 , ’ h2 [ n ]= ’ ) h = h1 + h2 ; disp (h , ’ h [ n ]= ’ )
81
Scilab code Exa 5.5 solution to differential equation 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
// LTi S y s t e m s c h a r a c t e r i z e d by L i n e a r C o n s t a n t // C o e f f i c i e n t D i f f e r e n c e e q u a t i o n s // I n v e r s e Z T r a n s f o r m // z = %z ; syms n z ; H1 = (26/15) /( z -(1/2) ) ; H2 = (7/3) /( z -2) ; H3 = (18/5) /( z -3) ; F1 = H1 * z ^( n ) *( z -(1/2) ) ; F2 = H2 * z ^( n ) *( z -2) ; F3 = H3 * z ^( n ) *( z -3) ; h1 = limit ( F1 ,z ,1/2) ; disp ( h1 , ’ h1 [ n ]= ’ ) h2 = limit ( F2 ,z ,2) ; disp ( h2 , ’ h2 [ n ]= ’ ) h3 = limit ( F3 ,z ,3) ; disp ( h3 , ’ h3 [ n ]= ’ ) h = h1 - h2 + h3 ; disp (h , ’ h [ n ]= ’ )
Scilab code Exa 5.6 response of an LTID system using difference eq 1 // LTi S y s t e m s c h a r a c t e r i z e d by L i n e a r C o n s t a n t 2 // C o e f f i c i e n t D i f f e r e n c e e q u a t i o n s 3 // I n v e r s e Z T r a n s f o r m 4 // z = %z ; 5 syms n z ; 6 H1 = (2/3) /( z +0.2) ; 7 H2 = (8/3) /( z +0.8) ; 8 H3 = (2) /( z +0.5) ;
82
Figure 5.2: response of an LTID system using difference eq 9 10 11 12 13 14 15 16 17 18 19
F1 = H1 * z ^( n ) *( z +0.2) ; F2 = H2 * z ^( n ) *( z +0.8) ; F3 = H3 * z ^( n ) *( z +0.5) ; h1 = limit ( F1 ,z , -0.2) ; disp ( h1 , ’ h1 [ n ]= ’ ) h2 = limit ( F2 ,z , -0.8) ; disp ( h2 , ’ h2 [ n ]= ’ ) h3 = limit ( F3 ,z , -0.5) ; disp ( h3 , ’ h3 [ n ]= ’ ) h = h1 - h2 + h3 ; disp (h , ’ h [ n ]= ’ )
Scilab code Exa 5.10 response of an LTID system using difference eq
83
1 omega = linspace ( - %pi , %pi ,106) ; 2 H = syslin ( ’ c ’ ,( s /( s -0.8) ) ) ; 3 H_omega = squeeze ( calfrq (H ,0.01 ,10) ) ; 4 size ( H_omega ) 5 subplot (2 ,1 ,1) ; plot2d ( omega , abs ( H_omega ) ) ; 6 // x l a b e l ( ’ \ omega ’ ) ; 7 // y l a b e l ( ’ | H [ e ˆ{ j \ omega } ] | ’ ) ; 8 subplot (2 ,1 ,2) ; plot2d ( omega , atan ( imag ( H_omega ) , real 9 10
( H_omega ) ) *180/ %pi ) ; // x l a b e l ( ’ \ omega ’ ) ; // y l a b e l ( ’ \ a n g l e H [ e ˆ{ j \ omega } ] [ deg ] ’ ) ;
Scilab code Exa 5.12 maximum sampling timeinterval 1 // s i g n a l s and s y s t e m s 2 //maximum s a m p l i n g i n t e r v a l 3 f =50*10^3; 4 T =0.5/ f ; 5 disp ( T ) // i n s e c o n d s
Scilab code Exa 5.13 discrete time amplifier highest frequency 1 // s i g n a l s and s y s t e m s 2 // h i g h e s t f r e q u e n c y o f a s i g n a l 3 T =25*10^ -6 4 f =0.5/ T 5 disp ( f ) // i n h e r t z
Scilab code Exa 5.17 bilateral z transfrom
84
1 2 3 4 5 6 7 8 9 10 11 12
//Z t r a n s f o r m o f x [ n ] = a ˆ n . u [ n ]+ bˆ−n . u[−n −1] syms n z ; a =0.9 b = 1.2; x1 =( a ) ^( n ) x2 =( b ) ^( - n ) // p l o t 2 d 3 ( n1 , x1+x2 ) X1 = symsum ( x1 *( z ^( - n ) ) ,n ,0 , %inf ) X2 = symsum ( x2 *( z ^( n ) ) ,n ,1 , %inf ) X = X1 + X2 ; disp (X , ” a n s=” )
Scilab code Exa 5.18 bilateral inverse z transform 1 // s i g n a l s and s y s t e m s 2 // I n v e r s e Z T r a n s f o r m :ROC | z | >2 3 z = %z ; 4 syms n z1 ; //To f i n d o u t I n v e r s e z t r a n s f o r m z must
be l i n e a r z = z 1 X = - z *( z +0.4) /(( z -0.8) *( z -2) ) X1 = denom ( X ) ; zp = roots ( X1 ) ; X1 = - z1 *( z1 +0.4) /(( z1 -0.8) *( z1 -2) ) F1 = X1 *( z1 ^( n -1) ) *( z1 - zp (1) ) ; F2 = X1 *( z1 ^( n -1) ) *( z1 - zp (2) ) ; h1 = limit ( F1 , z1 , zp (1) ) ; disp ( h1 , ’ h1 [ n ]= ’ ) h2 = limit ( F2 , z1 , zp (2) ) ; disp ( h2 , ’ h2 [ n ]= ’ ) h = h1 + h2 ; disp (h , ’ h [ n ]= ’ )
5 6 7 8 9 10 11 12 13 14 15 16 17 18 // I n v e r s e Z T r a n s f o r m :ROC 0 . 8 < | z | <2 19 z = %z ;
85
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
syms n z1 ; X = - z *( z +0.4) /(( z -0.8) *( z -2) ) X1 = denom ( X ) ; zp = roots ( X1 ) ; X1 = - z1 *( z1 +0.4) /(( z1 -0.8) *( z1 -2) ) F1 = X1 *( z1 ^( n -1) ) *( z1 - zp (1) ) ; F2 = X1 *( z1 ^( n -1) ) *( z1 - zp (2) ) ; h1 = limit ( F1 , z1 , zp (1) ) ; disp ( h1 * ’ u ( n ) ’ , ’ h1 [ n ]= ’ ) h2 = limit ( F2 , z1 , zp (2) ) ; disp (( h2 ) * ’ u(−n −1) ’ , ’ h2 [ n ]= ’ ) disp (( h1 ) * ’ u ( n ) ’ -( h2 ) * ’ u ( n−1) ’ , ’ h [ n ]= ’ ) // I n v e r s e Z T r a n s f o r m :ROC | z | < 0 . 8 z = %z ; syms n z1 ; X = - z *( z +0.4) /(( z -0.8) *( z -2) ) X1 = denom ( X ) ; zp = roots ( X1 ) ; X1 = - z1 *( z1 +0.4) /(( z1 -0.8) *( z1 -2) ) F1 = X1 *( z1 ^( n -1) ) *( z1 - zp (1) ) ; F2 = X1 *( z1 ^( n -1) ) *( z1 - zp (2) ) ; h1 = limit ( F1 , z1 , zp (1) ) ; disp ( h1 * ’ u(−n −1) ’ , ’ h1 [ n ]= ’ ) h2 = limit ( F2 , z1 , zp (2) ) ; disp (( h2 ) * ’ u(−n −1) ’ , ’ h2 [ n ]= ’ ) disp ( -( h1 ) * ’ u(−n −1) ’ -( h2 ) * ’ u(−n −1) ’ , ’ h [ n ]= ’ )
Scilab code Exa 5.19 transfer function for a causal system 1 2 3 4 5
// LTi S y s t e m s c h a r a c t e r i z e d by L i n e a r C o n s t a n t // C o e f f i c i e n t D i f f e r e n c e e q u a t i o n s // I n v e r s e Z T r a n s f o r m // z = %z ; syms n z ; 86
6 7 8 9 10 11 12 13 14 15 16 17 18 19
H1 = -z /( z -0.5) ; H2 = (8/3) * z /( z -0.8) ; H3 =( -8/3) * z /( z -2) ; F1 = H1 * z ^( n -1) *( z -0.5) ; F2 = H2 * z ^( n -1) *( z -0.8) ; F3 = H3 * z ^( n -1) *( z -2) ; h1 = limit ( F1 ,z ,0.5) ; disp ( h1 , ’ h1 [ n ]= ’ ) h2 = limit ( F2 ,z ,0.8) ; disp ( h2 , ’ h2 [ n ]= ’ ) h3 = limit ( F3 ,z ,2) ; disp ( h3 , ’ h3 [ n ]= ’ ) h = h1 + h2 + h3 ; disp (h , ’ h [ n ]= ’ )
Scilab code Exa 5.20 zero state response for a given input 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
// LTi S y s t e m s c h a r a c t e r i z e d by L i n e a r C o n s t a n t // C o e f f i c i e n t D i f f e r e n c e e q u a t i o n s // I n v e r s e Z T r a n s f o r m // z = %z ; syms n z ; H1 = ( -5/3) * z /( z -0.5) ; H2 = (8/3) * z /( z -0.8) ; H3 =5* z /( z -0.5) ; H4 = -6* z /( z -0.6) ; F1 = H1 * z ^( n -1) *( z -0.5) ; F2 = H2 * z ^( n -1) *( z -0.8) ; F3 = H3 * z ^( n -1) *( z -0.5) ; F4 = H4 * z ^( n -1) *( z -0.6) ; h1 = limit ( F1 ,z ,0.5) ; disp ( h1 , ’ h1 [ n ]= ’ ) h2 = limit ( F2 ,z ,0.8) ; disp ( h2 , ’ h2 [ n ]= ’ ) h3 = limit ( F3 ,z ,0.5) ; 87
19 disp ( h3 , ’ h3 [ n ]= ’ ) 20 h4 = limit ( F4 ,z ,0.6) ; 21 disp ( h4 , ’ h4 [ n ]= ’ ) 22 h = h1 + h2 + h3 + h4 ; 23 disp (h , ’ h [ n ]= ’ )
88
Chapter 6 continuous time signal analysis the fourier series
Scilab code Exa 6.1 fourier coefficients of a periodic sequence 1 2 3 4 5 6 7 8 9 10 11 12 13 14
n =0:10; a_n =0.504*2* ones (1 , length ( n ) ) ./(1+16* n .^2) ; a_n (1) =0.504 b_n =0.504*8* n ./(1+16* n .* n ) ; size ( n ) size ( a_n ) size ( b_n ) disp ( b_n (1) ) C_n = sqrt ( a_n .^2+( b_n ) .^2) ; theta_n (1) =0; theta_n = atan ( - b_n , a_n ) ; // n = [ 0 , n ] ; clf ; size ( n ) subplot (2 ,2 ,1) ; plot2d3 (n , a_n ) ; xtitle ( ’ a n ’ , ’ n ’ ) ; plot (n , a_n , ’ r o ’ ) ; 15 subplot (2 ,2 ,2) ; plot2d3 (n , b_n ) ; xtitle ( ’ b n ’ , ’ n ’ ) ; plot (n , b_n , ’ r . ’ ) ; 89
Figure 6.1: fourier coefficients of a periodic sequence subplot (2 ,2 ,3) ; plot2d3 (n , C_n ) ; xtitle ( ’ C n ’ , ’ n ’ ) ; plot (n , C_n , ’ r o ’ ) ; 17 subplot (2 ,2 ,4) ; plot2d3 (n , theta_n ,) ; xtitle ( ’ t h e t a n ’ , ’ n ’ ) ; plot (n , theta_n , ’ r . ’ ) 16
Scilab code Exa 6.2 fourier coefficients of a periodic sequence 1 n =0:10; 2 a_n = zeros (1 , length ( n ) ) ; 3 size ( a_n ) 4 b_n =(8/ %pi ^2* n .^2) .* sin ( n .* %pi /2) ; 5 size ( n ) 6 size ( a_n ) 7 size ( b_n )
90
Figure 6.2: fourier coefficients of a periodic sequence 8 disp ( b_n (1) ) 9 C_n = b_n 10 // t h e t a n ( 1 ) =0; 11 theta_n = atan ( - b_n , a_n ) ; 12 // n = [ 0 , n ] ; 13 clf ; 14 size ( n ) 15 subplot (2 ,2 ,1) ; plot2d3 (n , a_n ) ; xtitle ( ’ a n ’ , ’ n ’ ) ;
plot (n , a_n , ’ r o ’ ) 16 subplot (2 ,2 ,2) ; plot2d3 (n , b_n ) ; xtitle ( ’ b n ’ , ’ n ’ ) ; plot (n , b_n , ’ r . ’ ) 17 subplot (2 ,2 ,3) ; plot2d3 (n , C_n ) ; xtitle ( ’ C n ’ , ’ n ’ ) ; plot (n , C_n , ’ r o ’ ) 18 subplot (2 ,2 ,4) ; plot2d3 (n , theta_n ,) ; xtitle ( ’ t h e t a n ’ , ’ n ’ ) ; plot (n , theta_n , ’ r . ’ )
91
Scilab code Exa 6.3 fourier spectra of a signal 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
n =0:10; for n =0:10 // i f ( n%2==0) // a n =0; // e l s e if ( n ==4* n -3) a_n =2/( %pi .* n ) ; else if ( n ==4* n -1) a_n = -2/( %pi .* n ) ; end end end
b_n = zeros (1 , length ( n ) ) ; size ( n ) size ( a_n ) size ( b_n ) disp ( b_n (1) ) C_n = sqrt ( a_n .^2+( b_n ) .^2) ; theta_n (1) =0; theta_n = atan ( - b_n , a_n ) ; // n = [ 0 , n ] ; clf ; size ( n ) subplot (2 ,2 ,1) ; plot2d3 (n , a_n ) ; xtitle ( ’ a n ’ , ’ n ’ ) ; plot (n , a_n , ’ r o ’ ) ; 24 subplot (2 ,2 ,2) ; plot2d3 (n , b_n ) ; xtitle ( ’ b n ’ , ’ n ’ ) ; plot (n , b_n , ’ r . ’ ) ; 25 subplot (2 ,2 ,3) ; plot2d3 (n , C_n ) ; xtitle ( ’ C n ’ , ’ n ’ ) ; plot (n , C_n , ’ r o ’ ) ; 26 subplot (2 ,2 ,4) ; plot2d3 (n , theta_n ,) ; xtitle ( ’ t h e t a n ’ , ’ n ’ ) ; plot (n , theta_n , ’ r . ’ ) ;
92
Figure 6.3: exponential fourier series
93
Figure 6.4: exponential fourier series for the impulse train Scilab code Exa 6.5 exponential fourier series 1 n =( -10:10) ; D_n =0.504./(1+ %i *4* n ) ; 2 clf ; 3 subplot (2 ,1 ,1) ; plot2d3 (n , abs ( D_n ) ) ; 4 subplot (2 ,1 ,2) ; plot2d3 (n , atan ( imag ( D_n ) , real ( D_n ) ) )
;
Scilab code Exa 6.7 exponential fourier series for the impulse train 1 2 3 4
// s i g n a l s and s y s t e m s // f o u r i e r s e r i e s f o r t r a i n o f i m p u l s e s clear ; close ; 94
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
clc ; n = -3:1:3 x = ones (1 , length ( n ) ) D_n = ones (1 , length ( n ) ) ; C_n =[0 0 0 1 2 2 2] subplot (3 ,1 ,1) a = gca () ; a . y_location = ” o r i g i n ” ; a . x_location = ” o r i g i n ” ; plot2d3 (n , x ) subplot (3 ,1 ,2) a = gca () ; a . y_location = ” o r i g i n ” ; a . x_location = ” o r i g i n ” ; plot2d3 (n , D_n ) subplot (3 ,1 ,3) a = gca () ; a . y_location = ” o r i g i n ” ; a . x_location = ” o r i g i n ” ; plot2d3 (n , C_n ) ; plot (n , C_n , ’ r . ’ )
Scilab code Exa 6.9 exponential fourier series to find the output 1 n =( -10:10) ; D_n =2/(3.14*(1 -4.* n .^2) .*( %i *6.* n +1) ) ; 2 clf ; 3 subplot (2 ,1 ,1) ; plot2d3 (n , abs ( D_n ) ) ; 4 subplot (2 ,1 ,2) ; plot2d3 (n , atan ( imag ( D_n ) , real ( D_n ) ) )
;
95
Figure 6.5: exponential fourier series to find the output
96
Chapter 7 continuous time signal analysis the fourier transform
Scilab code Exa 7.1 fourier transform of exponential function 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
// s i g n a l s and s y s t e m s // c o n t i n u o u s t i m e s i g n a l a n a l y s i s t h e f o u r i e r transform // f o u r i e r t r a n s f o r m o f exp (−A∗ t ) clear ; clc ; A =1; // A m p l i t u d e Dt = 0.005; t = -4.5: Dt :4.5; xt = exp ( - A * abs ( t ) ) ; Wmax = 2* %pi *1; // Analog F r e q u e n c y = 1Hz K = 4; k = 0:( K /1000) : K ; W = k * Wmax / K ; XW = xt * exp ( - sqrt ( -1) *t ’* W ) * Dt ; XW = real ( XW ) ; W = [ - mtlb_fliplr ( W ) , W (2:1001) ]; // Omega from − 97
Figure 7.1: fourier transform of exponential function
98
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
Wmax t o Wmax XW = [ mtlb_fliplr ( XW ) , XW (2:1001) ]; subplot (2 ,1 ,1) ; a = gca () ; a . y_location = ” o r i g i n ” ; plot (t , xt ) ; xlabel ( ’ t i n s e c . ’ ) ; ylabel ( ’ x ( t ) ’ ) title ( ’ C o n t i n u o u s Time S i g n a l ’ ) subplot (2 ,1 ,2) ; a = gca () ; a . y_location = ” o r i g i n ” ; plot (W , XW ) ; xlabel ( ’ F r e q u e n c y i n R a d i a n s / S e c o n d s W’ ) ; ylabel ( ’X(jW) ’ ) title ( ’ C o n t i n u o u s −t i m e F o u r i e r T r a n s f o r m ’ )
Scilab code Exa 7.4 inverse fourier transform 1 2 3 4 5 6 7 8 9 10 11 12 13 14
// Example 4 . 5 // I n v e r s e C o n t i n u o u s Time F o u r i e r T r a n s f o r m // i m p u l s e f u n t i o n clear ; clc ; close ; // CTFT A =1; // A m p l i t u d e Dw = 0.005; W1 = 4; // Time i n s e c o n d s w = - W1 /2: Dw : W1 /2; for i =1: length ( w ) XW (1) =1; end 99
Figure 7.2: inverse fourier transform
100
15 16 17 18 19 20 21 22 23 24 25 26
XW = XW ’;
// I n v e r s e C o n t i n u o u s −t i m e F o u r i e r T r a n s f o r m t = -0.01:1/ length ( w ) :0.01; xt =(1/(2* %pi ) ) * XW * exp ( sqrt ( -1) *w ’* t ) * Dw ; xt = real ( xt ) ; figure a = gca () ; a . y_location = ” o r i g i n ” ; a . x_location = ” o r i g i n ” ; plot (t , xt ) ; xlabel ( ’ t time i n Seconds ’ ); 27 title ( ’ I n v e r s e C o n t i n u o u s Time F o u r i e r T r a n s f o r m x ( t ) ’)
Scilab code Exa 7.5 inverse fourier transform 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
// s i g n a l s and s y s t e m s // I n v e r s e C o n t i n u o u s Time F o u r i e r T r a n s f o r m // s h i f t e d i m p u l s e f u n c t i o n clear ; clc ; close ; w0 =1 A =1; // A m p l i t u d e Dw = 0.005; W1 = 4; // Time i n s e c o n d s w = - W1 /2: Dw : W1 /2; XW =[ zeros (1 , length ( w ) /2) 1 zeros (1 , length ( w /2) ) ]; XW = XW ’; // I n v e r s e C o n t i n u o u s −t i m e F o u r i e r T r a n s f o r m t = -0.01:1/ length ( w ) :0.01; size ( XW ) 101
18 size ( t ) 19 xt =(1/(2* %pi ) ) * XW * exp ( sqrt ( -1) *w ’.* t ) .* exp ( sqrt 20 21 22 23 24 25 26 27
( -1) .* t ) * Dw ; xt = real ( xt ) ; figure a = gca () ; a . y_location = ” o r i g i n ” ; a . x_location = ” o r i g i n ” ; plot (t , xt ) ; xlabel ( ’ t time i n Seconds ’ ); title ( ’ I n v e r s e C o n t i n u o u s Time F o u r i e r T r a n s f o r m x ( t ) ’)
Scilab code Exa 7.6 fourier transform for everlasting sinusoid 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
// s i g n a l s and s y s t e m s // C o n t i n u o u s Time F o u r i e r T r a n s f o r m s // S i n u s o i d a l w a v e f o r m s c o s ( Wot ) clear ; clc ; close ; T1 = 2; T = 4* T1 ; Wo = 2* %pi / T ; W = [ - Wo ,0 , Wo ]; ak = (2* %pi * Wo * T1 / %pi ) / sqrt ( -1) ; XW = [ - ak ,0 , ak ]; ak1 = (2* %pi * Wo * T1 / %pi ) ; XW1 =[ ak1 ,0 , ak1 ]; figure 102
Figure 7.3: fourier transform for everlasting sinusoid
103
Figure 7.4: fourier transform of a periodic signal 18 a = gca () ; 19 a . y_location = ” o r i g i n ” ; 20 a . x_location = ” o r i g i n ” ; 21 plot2d3 ( ’ gnn ’ ,W , XW1 ,2) ; 22 poly1 = a . children (1) . children (1) ; 23 poly1 . thickness = 3; 24 xlabel ( ’
W’ ) ; 25 title ( ’CTFT o f c o s ( Wot ) ’ )
Scilab code Exa 7.7 fourier transform of a periodic signal 1
// s i g n a l s and s y s t e m s 104
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
// C o n t i n u o u s Time F o u r i e r T r a n s f o r m o f Symmetric // p e r i o d i c S q u a r e waveform clear ; clc ; close ; T1 = 2; T = 4* T1 ; Wo = 2* %pi / T ; W = - %pi : Wo : %pi ; delta = ones (1 , length ( W ) ) ; XW (1) = (2* %pi * Wo * T1 / %pi ) ; mid_value = ceil ( length ( W ) /2) ; for k = 2: mid_value XW ( k ) = (2* %pi * sin (( k -1) * Wo * T1 ) /( %pi *( k -1) ) ) ; end figure a = gca () ; a . y_location = ” o r i g i n ” ; a . x_location = ” o r i g i n ” ; plot2d3 ( ’ gnn ’ ,W ( mid_value : $ ) ,XW ,2) ; poly1 = a . children (1) . children (1) ; poly1 . thickness = 3; plot2d3 ( ’ gnn ’ ,W (1: mid_value -1) , XW ( $ : -1:2) ,2) ; poly1 = a . children (1) . children (1) ; poly1 . thickness = 3; xlabel ( ’W i n r a d i a n s / S e c o n d s ’ ) ; title ( ’ C o n t i n u o u s Time F o u r i e r T r a n s f o r m o f P e r i o d i c S q u a r e Wave ’ )
Scilab code Exa 7.8 fourier transform of a unit impulse train 1
// s i g n a l s and s y s t e m s 105
Figure 7.5: fourier transform of a unit impulse train 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
// c o n t i n u o u s t i m e s i g n a l a n a l y s i s t h e f o u r i e r transform // P e r i o d i c I m p u l s e T r a i n clear ; clc ; close ; T = -4:4;; T1 = 1; // S a m p l i n g I n t e r v a l xt = ones (1 , length ( T ) ) ; ak = 1/ T1 ; XW = 2* %pi * ak * ones (1 , length ( T ) ) ; Wo = 2* %pi / T1 ; W = Wo * T ; figure subplot (2 ,1 ,1) a = gca () ; a . y_location = ” o r i g i n ” ; a . x_location = ” o r i g i n ” ;
106
19 20 21 22
plot2d3 ( ’ gnn ’ ,T , xt ,2) ; poly1 = a . children (1) . children (1) ; poly1 . thickness = 3; xlabel ( ’
23 24 25 26 27 28 29 30 31
t ’ ); title ( ’ P e r i o d i c I m p u l s e T r a i n ’ ) subplot (2 ,1 ,2) a = gca () ; a . y_location = ” o r i g i n ” ; a . x_location = ” o r i g i n ” ; plot2d3 ( ’ gnn ’ ,W , XW ,2) ; poly1 = a . children (1) . children (1) ; poly1 . thickness = 3; xlabel ( ’
32
t ’ ); title ( ’CTFT o f P e r i o d i c I m p u l s e T r a i n ’ )
Scilab code Exa 7.9 fourier transform of unit step function 1 2 3 4 5 6 7 8 9 10 11
// s i g n a l s and s y s t e m s // c o n t i n u o u s t i m e s i g n a l a n a l y s i s t h e f o u r i e r transform // f o u r i e r t r a n s f o r m o f u n i t s t e p f u n c t i o n u ( t ) clear ; clc ; A =0.000000001; // A m p l i t u d e Dt = 0.005; t = 0: Dt :4.5; xt = exp ( - A * abs ( t ) ) ; Wmax = 2* %pi *1; // Analog F r e q u e n c y = 1Hz K = 4; 107
Figure 7.6: fourier transform of unit step function 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
k = 0:( K /500) : K ; W = k * Wmax / K ; XW = xt * exp ( - sqrt ( -1) *t ’* W ) * Dt ; XW = real ( XW ) ; W = [ - mtlb_fliplr ( W ) , W (2:501) ]; // Omega from −Wmax t o Wmax XW = [ mtlb_fliplr ( XW ) , XW (2:501) ]; subplot (2 ,1 ,1) ; a = gca () ; a . y_location = ” o r i g i n ” ; plot (t , xt ) ; xlabel ( ’ t i n s e c . ’ ) ; ylabel ( ’ x ( t ) ’ ) title ( ’ C o n t i n u o u s Time S i g n a l ’ ) subplot (2 ,1 ,2) ; a = gca () ; a . y_location = ” o r i g i n ” ; plot (W , XW ) ;
108
Figure 7.7: fourier transform of exponential function 29 30 31
xlabel ( ’ F r e q u e n c y i n R a d i a n s / S e c o n d s W’ ) ; ylabel ( ’X(jW) ’ ) title ( ’ C o n t i n u o u s −t i m e F o u r i e r T r a n s f o r m ’ )
Scilab code Exa 7.12 fourier transform of exponential function 1 // s i g n a l s and s y s t e m s 2 // C o n t i n u o u s Time F o u r i e r T r a n s f o r m 3 // C o n t i n u o u s Time S i g n a l x ( t )= exp (−A∗ a b s ( t ) ) 4 clear ; 5 clc ; 6 close ; 7 8 A =1; // A m p l i t u d e
109
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
Dt = 0.005; t = -4.5: Dt :4.5; xt = exp ( - A * abs ( t ) ) ; Wmax = 2* %pi *1; // Analog F r e q u e n c y = 1Hz K = 4; k = 0:( K /1000) : K ; W = k * Wmax / K ; XW = xt * exp ( - sqrt ( -1) *t ’* W ) * Dt ; XW = real ( XW ) ; W = [ - mtlb_fliplr ( W ) , W (2:1001) ]; // Omega from − Wmax t o Wmax XW = [ mtlb_fliplr ( XW ) , XW (2:1001) ]; subplot (1 ,1 ,1) subplot (2 ,1 ,1) ; a = gca () ; a . y_location = ” o r i g i n ” ; plot (t , xt ) ; xlabel ( ’ t i n s e c . ’ ) ; ylabel ( ’ x ( t ) ’ ) title ( ’ C o n t i n u o u s Time S i g n a l ’ ) subplot (2 ,1 ,2) ; a = gca () ; a . y_location = ” o r i g i n ” ; plot (W , XW ) ; xlabel ( ’ F r e q u e n c y i n R a d i a n s / S e c o n d s W’ ) ; ylabel ( ’X(jW) ’ ) title ( ’ C o n t i n u o u s −t i m e F o u r i e r T r a n s f o r m ’ )
110
Chapter 8 Sampling The bridge from continuous to discrete
Scilab code Exa 8.8 discrete fourier transform 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
// s i g n a l s and s y s t e m s // s a m p l i n g : t h e b r i d g e from c o n t i n u o u s t o d i s c r e t e //DFT t o compute t h e f o u r i e r t r a n s f o r m o f e ˆ−2 t . u ( t ) T_0 = 4; N_0 = 256; T = T_0 / N_0 ; t = (0: T : T *( N_0 -1) ) ’; x = T * exp ( -2* t ) ; x = mtlb_i (x ,1 ,( T *( exp ( -2* T_0 ) +1) ) /2) ; X_r = fft ( x ) ; r = ( - N_0 /2: N_0 /2 -1) ’; omega_r = (( r *2) * %pi ) / T_0 ; omega = linspace ( - %pi /T , %pi /T ,4097) ; X = 1 ./( %i * omega +2) ; subplot (2 ,1 ,1) ; a = gca () ; a . y_location = ” o r i g i n ” ; 111
Figure 8.1: discrete fourier transform
112
Figure 8.2: discrete fourier transform 18 a . x_location = ” o r i g i n ” ; 19 plot ( omega , abs ( X ) ,” k ” , omega_r , fftshift ( abs ( X_r ) ) ,” ko
”); 20 xtitle ( ” m a g n i t u d e o f X( omega ) f o r t r u e FT and DFT” ) ; 21 subplot (2 ,1 ,2) ; 22 a = gca () ; 23 a . y_location = ” o r i g i n ” ; 24 a . x_location = ” o r i g i n ” ; 25 plot ( omega , atan ( imag ( X ) , real ( X ) ) ,” k ” , omega_r ,
fftshift ( atan ( imag ( X_r ) , real ( X_r ) ) ) ,” ko ” ) ; 26 xtitle ( ” a n g l e o f X( omega ) f o r t r u e FT and DFT” ) ;
Scilab code Exa 8.9 discrete fourier transform
113
// s i g n a l s and s y s t e m s // s a m p l i n g : t h e b r i d g e from c o n t i n u o u s t o d i s c r e t e //DFT t o compute t h e f o u r i e r t r a n s f o r m o f 8 r e c t ( t ) T_0 = 4; N_0 = 32; T = T_0 / N_0 ; x_n = [ ones (1 ,4) 0.5 zeros (1 ,23) 0.5 ones (1 ,3) ] ’; size ( x_n ) x_r = fft ( x_n ) ; r = ( - N_0 /2:( N_0 /2) -1) ’; omega_r = (( r *2) * %pi ) / T_0 ; size ( omega_r ) size ( omega ) omega = linspace ( - %pi /T , %pi /T ,4097) ; X = 8*( sinc ( omega /2) ) ; size ( X ) figure (1) ; subplot (2 ,1 ,1) ; plot ( omega , abs ( X ) ,” k ” ) ; plot ( omega_r , fftshift ( abs ( x_r ) ) ,” ko ” ) xtitle ( ” a n g l e o f X( omega ) f o r t r u e FT and DFT” ) ; a = gca () ; subplot (2 ,1 ,2) ; a = gca () ; a . y_location = ” o r i g i n ” ; a . x_location = ” o r i g i n ” ; plot ( omega , atan ( imag ( X ) , real ( X ) ) ,” k ” , omega_r , fftshift ( atan ( imag ( x_r ) , real ( x_r ) ) ) , ’ r . ’ ) ; 27 xtitle ( ” a n g l e o f X( omega ) f o r t r u e FT and DFT” ) ; 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
Scilab code Exa 8.10 frequency response of a low pass filter 1 2
// s i g n a l s and s y s t e m s // s a m p l i n g : t h e b r i d g e b e t w e e n c o n t i n u o u s t o 114
Figure 8.3: frequency response of a low pass filter
115
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
discrete T_0 = 4; N_0 = 32; T = T_0 / N_0 ; n = 0: N_0 -1; r = n ; x_n = [ ones (1 ,4) ,0.5 , zeros (1 ,23) ,0.5 , ones (1 ,3) ] ’; H_r = [ ones (1 ,8) ,0.5 , zeros (1 ,15) ,0.5 , ones (1 ,7) ] ’; X_r = fft ( x_n , -1) ; Y_r = H_r .*( X_r ) ; y_n = mtlb_ifft ( Y_r ) ; subplot (2 ,2 ,1) ; plot2d3 (n , x_n ) ; plot (n , x_n , ’ r . ’ ) xtitle ( ’ xn ’ , ’ n ’ ) subplot (2 ,2 ,2) ; plot2d3 (r , real ( X_r ) ) ; plot (r , real ( X_r ) , ’ r o ’ ) xtitle ( ’ Xr ’ , ’ r ’ ) subplot (2 ,2 ,3) ; plot2d3 (n , real ( y_n ) ) ; plot (n , real ( y_n ) , ’ r . ’ ) xtitle ( ’ yn ’ , ’ n ’ ) subplot (2 ,2 ,4) ; plot2d3 (r ,( X_r ) .* H_r ) ; plot (r ,( X_r ) .* H_r , ’ r o ’ ) xtitle ( ’ XrHr ’ , ’ r ’ )
116
Chapter 9 fourier analysis of discrete time signals
Scilab code Exa 9.1 discrete time fourier series 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
// s i g n a l s and s y s t e m s // f o u r i e r a n a l y s i s o f d i s c r e t e t i m e s i g n a l s // Example5 . 5 : D i s c r e t e Time F o u r i e r T r a n s f o r m : x [ n ]= s i n (nWo) clear ; clc ; close ; N = 0.1; Wo = %pi ; W = [ - Wo /10 ,0 , Wo /10]; XW =[0.5 ,0 ,0.5]; // figure a = gca () ; a . y_location = ” o r i g i n ” ; a . x_location = ” o r i g i n ” ; plot2d3 ( ’ gnn ’ ,W , XW ,2) ; 117
Figure 9.1: discrete time fourier series 17 18 19
poly1 = a . children (1) . children (1) ; poly1 . thickness = 3; xlabel ( ’
W’ ) ; 20 title ( ’DTFT o f c o s (nWo) ’ ) 21 disp ( Wo /10)
Scilab code Exa 9.2 DTFT for periodic sampled gate function 1 N_0 =32; n =(0: N_0 -1) ; 2 x_n = [ ones (1 ,5) zeros (1 ,23) ones (1 ,4) ]; 3 for r =0:31 4 X_r ( r +1) = sum ( x_n .* exp ( - sqrt ( -1) * r *2*3.14/ N_0 * n ) )
118
Figure 9.2: DTFT for periodic sampled gate function
119
Figure 9.3: discrete time fourier series /32; 5 end 6 subplot (2 ,1 ,1) ; r = n ; plot2d3 (r , real ( X_r ) ) ; 7 xlabel ( ’ r ’ ) ; ylabel ( ’ X r ’ ) ; 8 X_r = fft ( x_n ) / N_0 ; 9 subplot (2 ,1 ,2) ; 10 plot2d3 (r , phasemag ( X_r ) ) ; 11 xlabel ( ’ r ’ ) ; ylabel ( ’ p h a s e o f X r ’ ) ; 12 disp ( N_0 , ’ p e r i o d= ’ ) 13 disp (2* %pi / N_0 , ’ omega= ’ )
120
Scilab code Exa 9.3 discrete time fourier series 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
// s i g n a l s and s y s t e m s // D i s c r e t e Time F o u r i e r T r a n s f o r m o f d i s c r e t e sequence // x [ n ]= ( a ˆn ) . u [ n ] , a>0 and a<0 clear ; clc ; close ; // DTS S i g n a l a1 = 0.5; a2 = -0.5; max_limit = 10; for n = 0: max_limit -1 x1 ( n +1) = ( a1 ^ n ) ; x2 ( n +1) = ( a2 ^ n ) ; end n = 0: max_limit -1; // D i s c r e t e −t i m e F o u r i e r T r a n s f o r m Wmax = 2* %pi ; K = 4; k = 0:( K /1000) : K ; W = k * Wmax / K ; x1 = x1 ’; x2 = x2 ’; XW1 = x1 * exp ( - sqrt ( -1) *n ’* W ) ; XW2 = x2 * exp ( - sqrt ( -1) *n ’* W ) ; XW1_Mag = abs ( XW1 ) ; XW2_Mag = abs ( XW2 ) ; W = [ - mtlb_fliplr ( W ) , W (2:1001) ]; // Omega from − Wmax t o Wmax XW1_Mag = [ mtlb_fliplr ( XW1_Mag ) , XW1_Mag (2:1001) ]; XW2_Mag = [ mtlb_fliplr ( XW2_Mag ) , XW2_Mag (2:1001) ]; [ XW1_Phase , db ] = phasemag ( XW1 ) ; [ XW2_Phase , db ] = phasemag ( XW2 ) ; XW1_Phase = [ - mtlb_fliplr ( XW1_Phase ) , XW1_Phase (2:1001) ]; XW2_Phase = [ - mtlb_fliplr ( XW2_Phase ) , XW2_Phase 121
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
(2:1001) ]; // p l o t f o r a>0 figure subplot (3 ,1 ,1) ; plot2d3 ( ’ gnn ’ ,n , x1 ) ; xtitle ( ’ D i s c r e t e Time S e q u e n c e x [ n ] f o r a>0 ’ ) subplot (3 ,1 ,2) ; a = gca () ; a . y_location = ” o r i g i n ” ; a . x_location = ” o r i g i n ” ; plot2d (W , XW1_Mag ) ; title ( ’ Magnitude R e s p o n s e a b s (X(jW) ) ’ ) subplot (3 ,1 ,3) ; a = gca () ; a . y_location = ” o r i g i n ” ; a . x_location = ” o r i g i n ” ; plot2d (W , XW1_Phase ) ; title ( ’ Phase R e s p o n s e <(X(jW) ) ’ ) // p l o t f o r a<0 figure subplot (3 ,1 ,1) ; plot2d3 ( ’ gnn ’ ,n , x2 ) ; xtitle ( ’ D i s c r e t e Time S e q u e n c e x [ n ] f o r a>0 ’ ) subplot (3 ,1 ,2) ; a = gca () ; a . y_location = ” o r i g i n ” ; a . x_location = ” o r i g i n ” ; plot2d (W , XW2_Mag ) ; title ( ’ Magnitude R e s p o n s e a b s (X(jW) ) ’ ) subplot (3 ,1 ,3) ; a = gca () ; a . y_location = ” o r i g i n ” ; a . x_location = ” o r i g i n ” ; plot2d (W , XW2_Phase ) ; title ( ’ Phase R e s p o n s e <(X(jW) ) ’ )
122
Figure 9.4: discrete time fourier series
Scilab code Exa 9.4 discrete time fourier series // s i g n a l s and s y s t e m s // D i s c r e t e Time F o u r i e r T r a n s f o r m o f d i s c r e t e sequence 3 // x [ n ]= ( a ˆn ) . u[−n ] , a>0 and a<0 4 clear ; 5 clc ; 1 2
123
Figure 9.5: discrete time fourier series 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
close ; // DTS S i g n a l a = 0.5; max_limit = 10; for n = 0: max_limit -1 x1 ( n +1) = ( a ^ n ) ; end n = 0: max_limit -1; // D i s c r e t e −t i m e F o u r i e r T r a n s f o r m Wmax = 2* %pi ; K = 4; k = 0:( K /1000) : K ; W = k * Wmax / K ; x1 = x1 ’; XW1 = x1 * exp ( - sqrt ( -1) *n ’* W ) ; XW1_Mag = abs ( XW1 ) ; W = [ - mtlb_fliplr ( W ) , W (2:1001) ]; // Omega from −
124
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
Wmax t o Wmax XW1_Mag = [ mtlb_fliplr ( XW1_Mag ) , XW1_Mag (2:1001) ]; [ XW1_Phase , db ] = phasemag ( XW1 ) ; XW1_Phase = [ - mtlb_fliplr ( XW1_Phase ) , XW1_Phase (2:1001) ]; // p l o t f o r a>0 figure subplot (3 ,1 ,1) ; plot2d3 ( ’ gnn ’ ,-n , x1 ) ; xtitle ( ’ D i s c r e t e Time S e q u e n c e x [ n ] f o r a>0 ’ ) subplot (3 ,1 ,2) ; a = gca () ; a . y_location = ” o r i g i n ” ; a . x_location = ” o r i g i n ” ; plot2d (W , XW1_Mag ) ; title ( ’ Magnitude R e s p o n s e a b s (X(jW) ) ’ ) subplot (3 ,1 ,3) ; a = gca () ; a . y_location = ” o r i g i n ” ; a . x_location = ” o r i g i n ” ; plot2d (W , XW1_Phase + %pi /2) ; title ( ’ Phase R e s p o n s e <(X(jW) ) ’ )
Scilab code Exa 9.5 DTFT for rectangular pulse 1 // s i g n a l s and s y s t e m s 2 // D i s c r e t e Time F o u r i e r T r a n s f o r m 3 // x [ n ]= 1 , a b s ( n )<=N1 4 clear ; 5 clc ; 6 close ; 7 // DTS S i g n a l 8 N1 = 2;
125
Figure 9.6: DTFT for rectangular pulse
126
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
n = - N1 : N1 ; x = ones (1 , length ( n ) ) ; // D i s c r e t e −t i m e F o u r i e r T r a n s f o r m Wmax = 2* %pi ; K = 4; k = 0:( K /1000) : K ; W = k * Wmax / K ; XW = x * exp ( - sqrt ( -1) *n ’* W ) ; XW_Mag = real ( XW ) ; W = [ - mtlb_fliplr ( W ) , W (2:1001) ]; // Omega from − Wmax t o Wmax XW_Mag = [ mtlb_fliplr ( XW_Mag ) , XW_Mag (2:1001) ]; // p l o t f o r a b s ( a ) <1 figure subplot (2 ,1 ,1) ; a = gca () ; a . y_location = ” o r i g i n ” ; a . x_location = ” o r i g i n ” ; plot2d3 ( ’ gnn ’ ,n , x ) ; xtitle ( ’ D i s c r e t e Time S e q u e n c e x [ n ] ’ ) subplot (2 ,1 ,2) ; a = gca () ; a . y_location = ” o r i g i n ” ; a . x_location = ” o r i g i n ” ; plot2d (W , XW_Mag ) ; title ( ’ D i s c r e t e Time F o u r i e r T r a n s f o r m X( exp (jW) ) ’ )
Scilab code Exa 9.6 DTFT for rectangular pulse spectrum 1 2 3 4
// s i g n a l s and s y s t e m s // d i s c r e e t t i m e f o u r i e r s e r i e s //IDTFT : I m p u l s e R e s p o n s e o f I d e a l Low p a s s F i l t e r clear ; 127
Figure 9.7: DTFT for rectangular pulse spectrum 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
clc ; close ; Wc = 1; // 1 r a d / s e c W = - Wc :0.1: Wc ; // Passband o f f i l t e r H0 = 1; // Magnitude o f F i l t e r HlpW = H0 * ones (1 , length ( W ) ) ; // I n v e r s e D i s c r e t e −t i m e F o u r i e r T r a n s f o r m t = -2* %pi :2* %pi / length ( W ) :2* %pi ; ht =(1/(2* %pi ) ) * HlpW * exp ( sqrt ( -1) *W ’* t ) ; ht = real ( ht ) ; figure subplot (2 ,1 ,1) a = gca () ; a . y_location = ” o r i g i n ” ; a . x_location = ” o r i g i n ” ; a . data_bounds =[ - %pi ,0; %pi ,2]; plot2d (W , HlpW ,2) ; poly1 = a . children (1) . children (1) ;
128
Figure 9.8: DTFT of sinc function 23 24 25 26 27 28 29 30 31 32 33
poly1 . thickness = 3; xtitle ( ’ F r e q u e n c y R e s p o n s e o f LPF H( exp (jW) ) ’ ) subplot (2 ,1 ,2) a = gca () ; a . y_location = ” o r i g i n ” ; a . x_location = ” o r i g i n ” ; a . data_bounds =[ -2* %pi , -1;2* %pi ,2]; plot2d3 ( ’ gnn ’ ,t , ht ) ; poly1 = a . children (1) . children (1) ; poly1 . thickness = 3; xtitle ( ’ I m p u l s e R e s p o n s e o f LPF h ( t ) ’ )
Scilab code Exa 9.9 DTFT of sinc function
129
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
// s i g n a l s and s y s t e m s // d i s c r e e t t i m e f o u r i e r s e r i e s //IDTFT : I m p u l s e R e s p o n s e o f I d e a l Low p a s s F i l t e r clear ; clc ; close ; Wc = 1; // 1 r a d / s e c W = - Wc :0.1: Wc ; // Passband o f f i l t e r H0 = 1; // Magnitude o f F i l t e r HlpW = H0 * ones (1 , length ( W ) ) ; // I n v e r s e D i s c r e t e −t i m e F o u r i e r T r a n s f o r m t = -2* %pi :2* %pi / length ( W ) :2* %pi ; ht1 =(1/(2* %pi ) ) * HlpW * exp ( sqrt ( -1) *W ’* t ) ; size ( ht1 ) n = -21:21; size ( n ) ht = ht1 .*( %e ^ %i *2* t ) ; ht = real ( ht ) ; figure subplot (2 ,1 ,1) a = gca () ; a . y_location = ” o r i g i n ” ; a . x_location = ” o r i g i n ” ; a . data_bounds =[ - %pi ,0; %pi ,2]; plot2d (W , HlpW ,2) ; poly1 = a . children (1) . children (1) ; poly1 . thickness = 3; xtitle ( ’ F r e q u e n c y R e s p o n s e o f LPF H( exp (jW) ) ’ ) subplot (2 ,1 ,2) a = gca () ; a . y_location = ” o r i g i n ” ; a . x_location = ” o r i g i n ” ; a . data_bounds =[ -2* %pi , -1;2* %pi ,2]; size ( t ) size ( ht ) plot2d3 ( ’ gnn ’ ,t , ht ) ; poly1 = a . children (1) . children (1) ; poly1 . thickness = 3; 130
Figure 9.9: sketching the spectrum for a modulated signal 39
xtitle ( ’ I m p u l s e R e s p o n s e o f LPF h ( t ) ’ )
Scilab code Exa 9.10.a sketching the spectrum for a modulated signal 1 // s i g n a l s and s y s t e m s 2 // d i s c r e t e f o u r i e r t r a n s f o r m 3 // F r e q u e n c y S h i f t i n g P r o p e r t y o f DTFT 4 clear ; 5 clc ; 6 close ; 7 mag = 4;
131
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
W = - %pi /4:0.1: %pi /4; H1 = mag * ones (1 , length ( W ) ) ; W1 = W + %pi /2; W2 = -W - %pi /2; figure subplot (2 ,1 ,1) a = gca () ; a . y_location = ” o r i g i n ” ; a . x_location = ” o r i g i n ” ; a . data_bounds =[ - %pi ,0; %pi ,2]; plot2d (W , H1 ) ; xtitle ( ’ F r e q u e n c y R e s p o n s e o f t h e g i v e n H( exp (jW) ) ’ ) subplot (2 ,1 ,2) a = gca () ; a . y_location = ” o r i g i n ” ; a . x_location = ” o r i g i n ” ; a . data_bounds =[ -2* %pi ,0;2* %pi ,2]; plot2d ( W1 ,0.5* H1 ) ; plot2d ( W2 ,0.5* H1 ) ; xtitle ( ’ F r e q u e n c y R e s p o n s e o f m o d u l a t e d s i g n a l H1 ( exp (jW) ) ’ )
Scilab code Exa 9.13 frequency response of LTID 1 2 3 4 5 6 7 8 9 10 11
// LTi S y s t e m s c h a r a c t e r i z e d by L i n e a r C o n s t a n t // f o u r i e r a n a l y s i s o f d i s c r e t e s y s t e m s // I n v e r s e Z T r a n s f o r m // z = %z ; syms n z ; H1 = ( -5/3) /( z -0.5) ; H2 = (8/3) /( z -0.8) ; F1 = H1 * z ^( n ) *( z -0.5) ; F2 = H2 * z ^( n ) *( z -0.8) ; h1 = limit ( F1 ,z ,0.5) ; disp ( h1 , ’ h1 [ n ]= ’ ) 132
12 h2 = limit ( F2 ,z ,0.8) ; 13 disp ( h2 , ’ h2 [ n ]= ’ ) 14 h = h1 - h2 ; 15 disp (h , ’ h [ n ]= ’ )
133
Chapter 10 state space analysis
Scilab code Exa 10.4 state space descrption by transfer function 1 2 3 4 5 6 7 8 9 10 11
// s i g n a l s and s y s t e m s // s t a t e s p a c e a n a l y s i s // s t a t e s p a c e d e s c r i p t i o n clear all ; close ; clc ; s = poly (0 , ’ s ’ ) ; H =[(4/3) /(1+ s ) , -2/(3+ s ) , (2/3) /(4+ s ) ]; Sys = tf2ss ( H ) clean ( ss2tf ( Sys ) ) disp ( Sys )
Scilab code Exa 10.5 finding the state vector 1 syms t s 2 A =[ -12 2/3; -36 -1]; B =[1/3;1]; q0 =[2;1]; X =1/ s ; 3 size ( A ) 4 size ( s * eye (2 ,2) )
134
5 6 7 8 9
Q = inv ( s * eye (2 ,2) -A ) *( q0 + B * X ) ; q =[]; q (1) = ilaplace ( Q (1) ) ; q (2) = ilaplace ( Q (2) ) ; disp ( q * ’ u ( t ) ’ ,” [ q1 ( t ) ; q2 ( t ) ] ” )
Scilab code Exa 10.6 state space descrption by transfer function 1 2 3 4 5 6 7 8
A =[0 1; -2 -3]; B =[1 0;1 1]; C =[1 0;1 1;0 2]; D =[0 0;1 0; 0 1]; syms s ; H = C * inv ( s * eye (2 ,2) -A ) * B + D ; disp (H , ” t h e t r a n s f e r f u n c t i o n m a t r i x H( s )=” ) disp ( H (3 ,2) ,” t h e t r a n s f e r f u n c t i o n r e l a t i n g y3 and x2 i s H32 ( s )=” )
Scilab code Exa 10.7 time domain method 1 2 3 4 5 6 7 8 9 10 11 12 13
// s i g n a l s and s y s t e m s // s t a t e s p a c e // t i m e domain method t o f i n d t h e s t a t e v e c t o r clc ; clf ; s = poly (0 , ’ s ’ ) ; A =[ s +12 -2/3; 36 s +1]; y = roots ( det ( A ) ) t = poly (0 , ’ t ’ ) ; beta = inv ([1 y (1) ; 1 y (2) ]) *[ %e ^ - y (1) * t ; %e ^ - y (2) * t ]; disp ( beta ) size ( beta ) W = beta (1) *[1 0;0 1]+ beta (2) *[ -12 2/3; -36 -1]; 135
14 zir = W *[2;1]; 15 disp ( zir ) ; 16 zsr = W *[1/3;1]; 17 disp ( zsr ) ; 18 total = zir + zsr ; 19 disp ( total ) ;
Scilab code Exa 10.8 state space descrption by transfer function 1 2 3 4 5 6 7 8 9 10
syms t s ; F1 = ilaplace (( s +3) /(( s +1) *( s +2) ) ) F2 = ilaplace (1/(( s +1) *( s +2) ) ) F3 = ilaplace ( -2/(( s +1) *( s +2) ) ) F4 = ilaplace ( s /(( s +1) *( s +2) ) ) F =[ F1 F2 ; F3 F4 ]; disp (F , ” f ( t )=” ) A =[1 0;1 1;0 2]; B =[0 0;1 0;0 1]; h = A * F *[1 0;1 1]+ B * eye (2 ,2) ; // h e r e 1 r e p r e s e n t s d e l ( t ) 11 disp (h , ” h ( t )=” )
Scilab code Exa 10.9 state equations of a given systems 1 A =[0 1; -2 -3]; 2 B =[1;2]; 3 P =[1 1;1 -1]; 4 Ahat = P * A * inv ( P ) 5 Bhat = P * B 6 disp ( Ahat , ”Aˆ=” ) 7 disp ( Bhat , ”Bˆ=” )
136
Scilab code Exa 10.10 diagonalized form of state equation 1 A =[0 1; -2 -3]; 2 [V , lambda ]= spec ( A ) ; 3 B =[1;2]; 4 Bhat = P * B 5 disp (P , ”P=” ) 6 disp ( Bhat , ”Bˆ=” ) 7 disp ( lambda , ” lambda=” )
Scilab code Exa 10.11 controllability and observability 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
A =[1 0;1 -1]; [V , lambda ]= spec ( A ) ; B =[1;0]; C =[1 -2]; P = inv ( V ) ; Bhat = P * B Chat = C * inv ( P ) disp ( ’ ( a ) : ’ ) disp ( Bhat , ”Bˆ=” ) disp ( Chat , ”Cˆ=” ) A =[ -1 0; -2 1]; [V , lambda ]= spec ( A ) ; B =[1;1]; C =[0 1]; P = inv ( V ) ; Bhat = P * B Chat = C * inv ( P ) disp ( ’ P a r t ( b ) : ’ ) disp ( Bhat , ”Bˆ=” ) disp ( Chat , ” cˆ=” ) 137
Scilab code Exa 10.12 state space description of a given description 1 2 3 4 5 6 7 8 9 10 11
A =[0 1; -1/6 5/6]; B =[0;1]; C =[ -1 5]; D =0; sys = syslin ( ’ d ’ ,A ,B ,C , D ) ; N =25; x = ones (1 , N +1) ; n =(0: N ) ; q0 =[2;3]; [ y q ]= csim ( ’ s t e p ’ ,n , sys ) ; y = dsimul ( sys , x ) ; plot2d3 ( y )
Scilab code Exa 10.13 total response using z transform 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
// LTi S y s t e m s c h a r a c t e r i z e d by L i n e a r C o n s t a n t // I n v e r s e Z T r a n s f o r m // z = %z ; syms n z ; H1 = ( -2* z ) /( z -(1/3) ) ; H2 = (3* z ) /( z -0.5) ; H3 = (24* z ) /( z -1) ; F1 = H1 * z ^( n -1) *( z -(1/3) ) ; F2 = H2 * z ^( n -1) *( z -0.5) ; F3 = H3 * z ^( n -1) *( z -1) ; h1 = limit ( F1 ,z ,(1/3) ) ; disp ( h1 , ’ h1 [ n ]= ’ ) h2 = limit ( F2 ,z ,0.5) ; disp ( h2 , ’ h2 [ n ]= ’ ) h3 = limit ( F3 ,z ,1) ; 138
16 disp ( h3 , ’ h3 [ n ]= ’ ) 17 h = h1 + h2 + h3 ; 18 disp (h , ’ h [ n ]= ’ )
139