Scilab Code for Signals and Systems by Alan V. Oppenheim, Alan V. Willsky, S.Hamid Nawab 1 Created by Prof. R. Senthilkumar Institute of Road and Transport Technology rsenthil [email protected]Cross-Checked by Prof. Saravanan Vijayakumaran, IIT Bombay [email protected]18 November 2010 1 Funded by a grant from the National Mission on Education through ICT, http://spoken-tutorial.org/NMEICT-Intro.This text book companion and Scilab codes written in it can be downloaded from the website http://scilab.in
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Scilab Code forSignals and Systems
by Alan V. Oppenheim, Alan V. Willsky,S.Hamid Nawab1
Created byProf. R. Senthilkumar
Institute of Road and Transport Technologyrsenthil [email protected]
1Funded by a grant from the National Mission on Education through ICT,http://spoken-tutorial.org/NMEICT-Intro.This text book companion and Scilabcodes written in it can be downloaded from the website http://scilab.in
Book Details
Author: Alan V. Oppenheim, Alan V. Willsky, S.Hamid Nawab
1 // Example 1 . 1 : Time S h i f t i n g2 //SIGNALS & SYSTEMS, Second E d i t i o n3 //V.OPPENHEIM, S . WILLSKY, S .HAMID NAMWAB4 //PHI , 2008 E d i t i o n5 // Page 106 clear all;
7 clc;
8 close;
9 t = 0:1/100:1;
10 for i = 1: length(t)
11 x(i) = 1 ;
12 end
13 for i = length(t)+1:2* length(t)
14 x(i) = 1-t(i-length(t));
15 end
16 t1 = 0:1/100:2;
17 t2 = -1:1/100:1;
18 // t3 = 0 : 1 / 1 0 0 : 4 / 3 ;19 // t4 = 0 : 1 / l e n g t h ( t3 ) : 1 ;20 //Mid = c e i l ( l e n g t h ( t3 ) /2) ;
11
21 // f o r i = 1 : Mid22 // x3 ( i ) = 1 ;23 // end24 // f o r i = Mid+1: l e n g t h ( t3 )25 // x3 ( i ) = 1βt4 ( iβMid ) ;26 // end27 figure
28 a=gca();
29 plot2d(t1,x(1:$-1))
30 a.thickness =2;
31 xtitle( β The s i g n a l x ( t ) β )32 figure
33 a=gca();
34 plot2d(t2,x(1:$-1))
35 a.thickness =2;
36 a.y_location = β middle β;37 xtitle( β The s i g n a l x ( t +1) β )38 figure
39 a=gca();
40 plot2d(t2,x($:-1:2))
41 a.thickness =2;
42 a.y_location = β middle β;43 xtitle( β The s i g n a l x(β t +1) β )
Example 1.2 Time Scaling
1 // Example 1 . 2 : Time S c a l i n g2 //SIGNALS & SYSTEMS, Second E d i t i o n3 //V.OPPENHEIM, S . WILLSKY, S .HAMID NAMWAB4 //PHI , 2008 E d i t i o n5 // Page 116 clear all;
7 clc;
8 close;
9 t3 = 0:1/100:4/3;
10 t4 = 0:1/ length(t3):1;
11 Mid =ceil(length(t3)/2);
12 for i = 1:Mid
12
13 x3(i) = 1 ;
14 end
15 for i = Mid +1: length(t3)
16 x3(i) = 1-t4(i-Mid);
17 end
18 figure
19 a=gca();
20 plot2d(t3,x3)
21 a.thickness =2;
22 xtitle( β Time S c a l i n g x (3 t /2) β )
Example 1.3 Time Scaling and Time Shifting
1 // Example 1 . 3 : Time S c a l i n g and Time S h i f t i n g2 //SIGNALS & SYSTEMS, Second E d i t i o n3 //V.OPPENHEIM, S . WILLSKY, S .HAMID NAMWAB4 //PHI , 2008 E d i t i o n5 // Page 116 clear all;
7 clc;
8 close;
9 t3 = 0:1/100:4/3;
10 t4 = 0:1/ length(t3):1;
11 Mid =ceil(length(t3)/2);
12 for i = 1:Mid
13 x3(i) = 1 ;
14 end
15 for i = Mid +1: length(t3)
16 x3(i) = 1-t4(i-Mid);
17 end
18 t5 = -2/3:1/100:2/3;
19 figure
20 a=gca();
21 plot2d(t5,x3)
22 a.thickness =2;
23 a.y_location =β middle β;24 xtitle( β Time S c a l i n g and Time S h i f t i n g x ( ( 3 t /2) +1) β )
13
Example 1.4 Combinationation two periodic signals Aperiodic signal
1 // Example 1 . 4 : Combinat ionat i on two p e r i o d i c s i g n a l s2 // A p e r i o d i c s i g n a l3 // Page 124 clear all;
15 a.y_location = β middle β;16 a.x_location = β middle β;17 xtitle( β The s i g n a l x ( t ) = c o s t f o r t < 0 and s i n t
f o r t > 0 : A p e r i o d i c S i g n a l β )
Example 1.5 sum of two complex exponentials as a single sinusoid
1 // Example 1 . 5 : To e x p r e s s sum o f two complexe x p o n e n t i a l s
2 // as a s i n g l e s i n u s o i d3 clear all;
4 clc;
5 close;
6 t =0:1/100:2* %pi;
7 x1 = exp(sqrt(-1)*2*t);
8 x2 = exp(sqrt(-1)*3*t);
9 x = x1+x2;
10 for i = 1: length(x)
11 X(i) = sqrt((real(x(i)).^2)+(imag(x(i)).^2));
12 end
13 plot(t,X);
14
14 xtitle( β F u l l wave r e c t i f i e d s i n u s o i d β , β t ime t β , βMagnitude β );
Figure 1.1: Results of Exa 1.5
Example 1.6 Determining the fundamental period of composite discretetime signal
1 // Example 1 . 6 : Determine the fundamenta l p e r i o d o fcompos i t e
2 // d i s c r e t e t ime s i g n a l3 //x [ n ] = exp ( j (2β%pi /3) n )+exp ( j (3β%pi /4) n )4 clear all;
15
5 clc;
6 close;
7 Omega1 = 2*%pi /3; // Angular f r e q u e n c y s i g n a l 18 Omega2 = 3*%pi /4; // Angular f r e q u e n c y s i g n a l 29 N1 = (2*%pi)/Omega1; // Pe i rod o f s i g n a l 1
10 N2 = (2*%pi)/Omega2; // Per i od o f s i g n a l 211 //To f i n d r a t i o n a l p e r i o d o f s i g n a l 112 for m1 = 1:100
13 period = N1*m1;
14 if(modulo(period ,1) ==0)
15 period1 = period;
16 integer_value = m1
17 break;
18 end
19 end
20 //To f i n d r a t i o n a l p e r i o d o f s i g n a l 221 for m2 = 1:100
22 period = N2*m2;
23 if(modulo(period ,1) ==0)
24 period2 = period;
25 integer_value = m2
26 break;
27 end
28 end
29 disp(period1)
30 disp(period2)
31 //To de t e rmine the fundamenta l p e r i o d N32 N = period1*period2
Example 1.12 Classification of system:Causality property
1 // Example 1 . 1 2 : C l a s s i f i c a t i o n o f system : C a u s a l i t yp r o p e r t y
2 // Page 473 //To check whether the g i v e n d i s c r e t e system i s a
Causa l System ( or ) NonβCausa l System4 // Given d i s c r e t e system y [ n]= x[βn ]5 clear;
16
6 clc;
7 x = [2,4,6,8,10,0,0,0,1]; // Ass ign some v a l u e toinput
8 n = -length(x)/2: length(x)/2;
9 count = 0;
10 mid = ceil(length(x)/2);
11 y = zeros(1,length(x));
12 y(mid+1:$) = x($:-1:mid +1);
13 for n = -1:-1:-mid
14 y(n+1+mid) = x(-n);
15 end
16 for i = 1: length(x)
17 if (y(i)==x(i))
18 count = count +1;
19 end
20 end
21 if (count == length(x))
22 disp( β The g i v e n system i s a c a u s a l system β )23 else
24 disp( β S i n c e i t depends on f u t u r e input v a l u e β )25 disp( β The g i v e n system i s a nonβc a u s a l system β )26 end
Example 1.13 Determination of stablility of a given system
1 // Example 1 . 1 3 : De te rmina t i on o f s t a b l i l i t y o f ag i v e n system
2 // Page 493 // g i v e n system y ( t ) = t . x ( t )4 clear;
5 clc;
6 x = [1,2,3,4,0,2,1,3,5,8]; // Ass ign some input7 Maximum_Limit = 10;
8 S = 0;
9 for t = 0: Maximum_Limit -1
10 S = S+t*x(t+1);
11 end
12 if (S >Maximum_Limit)
17
13 disp( β Eventhough input i s bounded output i sunbounded β )
14 disp( β The g i v e n system i s u n s t a b l e β );15 disp( β S = β );16 S
17 else
18 disp( β The g i v e n system i s s t a b l e β );19 disp( β The v a l u e o f S = β );20 S
21 end
Example 1.13b Determination of stability of a given system
1 // Example 1 . 1 3 ( b ) : De t e rmina t i on o f s t a b i l i t y o f ag i v e n system
2 // Page 503 // g i v e n system y ( t ) = exp ( x ( t ) )4 clear;
5 clc;
6 Maximum_Limit = 10;
7 S = 0;
8 for t = 0: Maximum_Limit -1
9 x(t+1)= -2^t; // Input some bounded v a l u e10 S = S+exp(x(t+1));
11 end
12 if (S >Maximum_Limit)
13 disp( β Eventhough input i s bounded output i sunbounded β )
14 disp( β The g i v e n system i s u n s t a b l e β );15 disp( β S = β );16 S
17 else
18 disp( β The g i v e n system i s s t a b l e β );19 disp(S);
20 end
Example 1.14 Classification of a system:Time Invariance Property
18
1 // Example 1 . 1 4 : c l a s s i f i c a t i o n o f a system : TimeI n v a r i a n c e Proper ty
2 // Page 513 //To check whether the g i v e n system i s a Time
v a r i a n t ( or ) Time Inβv a r i a n t4 // The g i v e n d i s c r e t e s i g n a l i s y ( t ) = s i n ( x ( t ) )5 clear;
6 clc;
7 to = 2; // Assume the amount o f t ime s h i f t =28 T = 10; // Length o f g i v e n s i g n a l9 for t = 1:T
10 x(t) = (2*%pi/T)*t;
11 y(t) = sin(x(t));
12 end
13 // F i r s t s h i f t the input s i g n a l on ly14 Input_shift = sin(x(T-to));
15 Output_shift = y(T-to);
16 if(Input_shift == Output_shift)
17 disp( β The g i v e n d i s c r e t e system i s a Time Inβv a r i a n t system β );
18 else
19 disp( β The g i v e n d i s c r e t e system i s a Time Var iantsystem β );
20 end
19
Figure 1.2: Results of Exa 1.14
Example 1.15 Classification of a System:Time Invariance Property
1 // Example 1 . 1 5 : C l a s s i f i c a t i o n o f a System : TimeI n v a r i a n c e Proper ty
2 // Page 513 //To check whether the g i v e n system i s a Time
v a r i a n t ( or ) Time Inβv a r i a n t4 // The g i v e n d i s c r e t e s i g n a l i s y [ n ] = n . x [ n ]5 clear;
6 clc;
7 no = 2; // Assume the amount o f t ime s h i f t =28 L = 10; // Length o f g i v e n s i g n a l
20
9 for n = 1:L
10 x(n) = n;
11 y(n) = n*x(n);
12 end
13 // F i r s t s h i f t the input s i g n a l on ly14 Input_shift = x(L-no);
15 Output_shift = y(L-no);
16 if(Input_shift == Output_shift)
17 disp( β The g i v e n d i s c r e t e system i s a Time Inβv a r i a n t system β );
18 else
19 disp( β The g i v e n d i s c r e t e system i s a Time Var iantsystem β );
20 end
Example 1.16 Classification of system:Time Invariance Property
1 // Example 1 . 1 6 : C l a s s i f i c a t i o n o f system : TimeI n v a r i a n c e Proper ty
2 // Page 523 //To check whether the g i v e n system i s a Time
v a r i a n t ( or ) Time Inβv a r i a n t4 // The g i v e n d i s c r e t e s i g n a l i s y ( t ) = x (2 t )5 clear;
6 clc;
7 to = 2; // Assume the amount o f t ime s h i f t =28 T = 10; // Length o f g i v e n s i g n a l9 x = [1,2,3,4,5,6,7,8,9,10];
10 y = zeros(1,length(x));
11 for t = 1: length(x)/2
12 y(t) = x(2*t);
13 end
14 // F i r s t s h i f t the input s i g n a l on ly15 Input_shift = x(T-to);
16 Output_shift = y(T-to);
17 if(Input_shift == Output_shift)
18 disp( β The g i v e n d i s c r e t e system i s a Time Inβv a r i a n t system β );
21
19 else
20 disp( β The g i v e n d i s c r e t e system i s a Time Var iantsystem β );
21 end
Example 1.17 Classification of system:Linearity Property
1 // Example 1 . 1 7 : C l a s s i f i c a t i o n o f system : L i n e a r i t yProper ty
2 // Page 543 //To check whether the g i v e n d i s c r e t e system i s a
L i n e a r System ( or ) NonβL i n e a r System4 // Given d i s c r e t e system y ( t )= t βx ( t )5 clear;
6 clc;
7 x1 = [1,1,1,1];
8 x2 = [2,2,2,2];
9 a = 1;
10 b = 1;
11 for t = 1: length(x1)
12 x3(t) = a*x1(t)+b*x2(t);
13 end
14 for t = 1: length(x1)
15 y1(t) = t*x1(t);
16 y2(t) = t*x2(t);
17 y3(t) = t*x3(t);
18 end
19 for t = 1: length(y1)
20 z(t) = a*y1(t)+b*y2(t);
21 end
22 count = 0;
23 for n =1: length(y1)
24 if(y3(t)== z(t))
25 count = count +1;
26 end
27 end
28 if(count == length(y3))
22
29 disp( β S i n c e I t s a t i s i f i e s the s u p e r p o s i t i o np r i n c i p l e β )
30 disp( β The g i v e n system i s a L i n e a r system β )31 y3
32 z
33 else
34 disp( β S i n c e I t does not s a t i s i f y thes u p e r p o s i t i o n p r i n c i p l e β )
35 disp( β The g i v e n system i s a NonβL i n e a r system β )36 end
Example 1.18 Classsification of a system:Linearity Property
1 // Example 1 . 1 8 : C l a s s s i f i c a t i o n o f a system : L i n e a r i t yProper ty
2 // Page 543 //To check whether the g i v e n d i s c r e t e system i s a
L i n e a r System ( or ) NonβL i n e a r System4 // Given d i s c r e t e system y ( t )= ( x ( t ) Λ2)5 clear;
6 clc;
7 x1 = [1,1,1,1];
8 x2 = [2,2,2,2];
9 a = 1;
10 b = 1;
11 for t = 1: length(x1)
12 x3(t) = a*x1(t)+b*x2(t);
13 end
14 for t = 1: length(x1)
15 y1(t) = (x1(t)^2);
16 y2(t) = (x2(t)^2);
17 y3(t) = (x3(t)^2);
18 end
19 for t = 1: length(y1)
20 z(t) = a*y1(t)+b*y2(t);
21 end
22 count = 0;
23 for n =1: length(y1)
23
24 if(y3(t)== z(t))
25 count = count +1;
26 end
27 end
28 if(count == length(y3))
29 disp( β S i n c e I t s a t i s i f i e s the s u p e r p o s i t i o np r i n c i p l e β )
30 disp( β The g i v e n system i s a L i n e a r system β )31 y3
32 z
33 else
34 disp( β S i n c e I t does not s a t i s i f y thes u p e r p o s i t i o n p r i n c i p l e β )
35 disp( β The g i v e n system i s a NonβL i n e a r system β )36 end
Example 1.20 Classsification of a system:Linearity Property
1 // Example 1 . 2 0 : C l a s s s i f i c a t i o n o f a system : L i n e a r i t yProper ty
2 // Page 553 //To check whether the g i v e n d i s c r e t e system i s a
L i n e a r System ( or ) NonβL i n e a r System4 // Given d i s c r e t e system y [ n ] )= 2βx [ n ]+35 clear;
6 clc;
7 x1 = [1,1,1,1];
8 x2 = [2,2,2,2];
9 a = 1;
10 b = 1;
11 for n = 1: length(x1)
12 x3(n) = a*x1(n)+b*x2(n);
13 end
14 for n = 1: length(x1)
15 y1(n) = 2*x1(n)+3;
16 y2(n) = 2*x2(n)+3;
17 y3(n) = 2*x3(n)+3;
18 end
24
19 for n = 1: length(y1)
20 z(n) = a*y1(n)+b*y2(n);
21 end
22 count = 0;
23 for n =1: length(y1)
24 if(y3(n)== z(n))
25 count = count +1;
26 end
27 end
28 if(count == length(y3))
29 disp( β S i n c e I t s a t i s i f i e s the s u p e r p o s i t i o np r i n c i p l e β )
30 disp( β The g i v e n system i s a L i n e a r system β )31 y3
32 z
33 else
34 disp( β S i n c e I t does not s a t i s i f y thes u p e r p o s i t i o n p r i n c i p l e β )
35 disp( β The g i v e n system i s a NonβL i n e a r system β )36 end
25
Chapter 2
Linear Time Invariant Systems
2.1 Scilab Codes
Example 2.1 Linear Convolution Sum
1 // Example 2 . 1 : L i n e a r Convo lu t i on Sum2 // page 803 clear all;
4 close;
5 clc;
6 h = [0,0,1,1,1,0,0];
7 N1 = -2:4;
8 x = [0,0,0.5,2,0,0,0];
9 N2 = -2:4;
10 y = convol(x,h);
11 for i = 1: length(y)
12 if (y(i) <=0.0001)
13 y(i)=0;
14 end
15 end
16 N = -4:8;
17 figure
18 a=gca();
19 plot2d3( β gnn β ,N1 ,h)20 xtitle( β Impul se Response β , β n β , β h [ n ] β );
26
21 a.thickness = 2;
22 figure
23 a=gca();
24 plot2d3( β gnn β ,N2 ,x)25 xtitle( β Input Response β , β n β , β x [ n ] β );26 a.thickness = 2;
27 figure
28 a=gca();
29 plot2d3( β gnn β ,N,y)30 xtitle( β Output Response β , β n β , β y [ n ] β );31 a.thickness = 2;
Figure 2.1: Results of Exa 2.1
27
Figure 2.2: Results of Exa 2.1
28
Figure 2.3: Results of Exa 2.1
Example 2.3 Convolution Sum:Convolution of x[n] and Unit Impulse re-sponse h[n]
1 // Example 2 . 3 : Convo lu t i on Sum : Convo lu t i on o f x [ n ]and
2 // Unit Impul se r e s p o n s e h [ n ]3 clear;
4 close;
5 clc;
6 Max_Limit = 10;
7 h = ones(1,Max_Limit);
8 N1 = 0:Max_Limit -1;
29
9 Alpha = 0.5; // a lpha < 110 for n = 1: Max_Limit
11 x(n)= (Alpha ^(n-1))*1;
12 end
13 N2 = 0:Max_Limit -1;
14 y = convol(x,h);
15 N = 0:2* Max_Limit -2;
16 figure
17 a=gca();
18 plot2d3( β gnn β ,N1 ,h)19 xtitle( β Impul se Response Fig 2 . 5 . ( b ) β , β n β , β h [ n ] β );20 a.thickness = 2;
21 figure
22 a=gca();
23 plot2d3( β gnn β ,N2 ,x)24 xtitle( β Input Response Fig 2 . 5 . ( a ) β , β n β , β x [ n ] β );25 a.thickness = 2;
Example 2.4 Convolution Sum of finite duration sequences
1 // Example 2 . 4 : Convo lu t i on Sum o f f i n i t e d u r a t i o ns e q u e n c e s
2 clear;
3 close;
4 clc;
5 x = ones (1,5);
6 N1 =0: length(x) -1;
7 Alpha = 1.4; // a lpha > 18 for n = 1:7
9 h(n)= (Alpha ^(n-1))*1;
33
10 end
11 N2 =0: length(h) -1;
12 y = convol(x,h);
13 N = 0: length(x)+length(h) -2;
14 figure
15 a=gca();
16 plot2d3( β gnn β ,N2 ,h)17 xtitle( β Impul se Response β , β n β , β h [ n ] β );18 a.thickness = 2;
19 figure
20 a=gca();
21 plot2d3( β gnn β ,N1 ,x)22 xtitle( β Input Response β , β n β , β x [ n ] β );23 a.thickness = 2;
24 figure
25 a=gca();
26 plot2d3( β gnn β ,N,y)27 xtitle( β Output Response β , β n β , β y [ n ] β );28 a.thickness = 2;
34
Figure 2.7: Results of Exa 2.4
35
Figure 2.8: Results of Exa 2.4
36
Figure 2.9: Results of Exa 2.4
Example 2.5 Convolution Sum of input sequence x[n] = (2n).u[βn]andh[n] =u[n]
1 // Example 2 . 5 : Convo lu t i on Sum o f input s equence x [ n]=(2Λ n ) . u[βn ]
2 // and h [ n ] = u [ n ]3 clear;
4 close;
5 clc;
6 Max_Limit = 10;
7 h = ones(1,Max_Limit);
8 N2 =0: length(h) -1;
37
9 for n = 1: Max_Limit
10 x1(n)= (2^(-(n-1)))*1;
11 end
12 x = x1($:-1:1);
13 N1 = -length(x)+1:0;
14 y = convol(x,h);
15 N = -length(x)+1: length(h) -1;
16 figure
17 a=gca();
18 plot2d3( β gnn β ,N2 ,h)19 xtitle( β Impul se Response β , β n β , β h [ n ] β );20 a.thickness = 2;
21 figure
22 a=gca();
23 a.y_location = β o r i g i n β;24 plot2d3( β gnn β ,N1 ,x)25 xtitle( β Input Response Fig 2 . 1 1 ( a ) β , β n β , β x [ n ] β );26 a.thickness = 2;
27 figure
28 a=gca();
29 a.y_location =β o r i g i n β;30 plot2d3( β gnn β ,N,y)31 xtitle( β Output Response Fig 2 . 1 1 ( b ) β , β n β , β y [ n ] β );32 a.thickness = 2;
38
Figure 2.10: Results of Exa 2.5
39
Figure 2.11: Results of Exa 2.5
40
Figure 2.12: Results of Exa 2.5
Example 2.6 onvolution Integral of input x(t) = (eβat).u(t)andh(t) = u(t)
1 // Example 2 . 6 : Convo lu t i on I n t e g r a l o f i nput x ( t ) = (eΛβat ) . u ( t )
2 // and h ( t ) =u ( t )3 clear;
4 close;
5 clc;
6 Max_Limit = 10;
7 h = ones(1,Max_Limit);
8 N2 =0: length(h) -1;
9 a = 0.5; // c o n s t a n t a>0
41
10 for t = 1: Max_Limit
11 x(t)= exp(-a*(t-1));
12 end
13 N1 =0: length(x) -1;
14 y = convol(x,h) -1;
15 N = 0: length(x)+length(h) -2;
16 figure
17 a=gca();
18 plot2d(N2,h)
19 xtitle( β Impul se Response β , β t β , β h ( t ) β );20 a.thickness = 2;
21 figure
22 a=gca();
23 plot2d(N1,x)
24 xtitle( β Input Response β , β t β , β x ( t ) β );25 a.thickness = 2;
26 figure
27 a=gca();
28 plot2d(N(1: Max_Limit),y(1: Max_Limit))
29 xtitle( β Output Response β , β t β , β y ( t ) β );30 a.thickness = 2;
42
Figure 2.13: Results of Exa 2.6
43
Figure 2.14: Results of Exa 2.6
44
Figure 2.15: Results of Exa 2.6
Example 2.7 Convolution Integral of fintie duration signals
1 // Example 2 . 7 : Convo lu t i on I n t e g r a l o f f i n t i ed u r a t i o n s i g n a l s
2 // page993 clear;
4 close;
5 clc;
6 T = 10;
7 x = ones(1,T); // Input Response8 for t = 1:2*T
9 h(t) = t-1; // Impul se Response
45
10 end
11 N1 = 0: length(x) -1;
12 N2 = 0: length(h) -1;
13 y = convol(x,h);
14 N = 0: length(x)+length(h) -2;
15 figure
16 a=gca();
17 a.x_location=β o r i g i n β;18 plot2d(N2,h)
19 xtitle( β Impul se Response β , β t β , β h ( t ) β );20 a.thickness = 2;
21 figure
22 a=gca();
23 plot2d(N1,x)
24 xtitle( β Input Response β , β t β , β x ( t ) β );25 a.thickness = 2;
26 figure
27 a=gca();
28 plot2d(N,y)
29 xtitle( β Output Response β , β t β , β y ( t ) β );30 a.thickness = 2;
46
Figure 2.16: Results of Exa 2.7
47
Figure 2.17: Results of Exa 2.7
48
Figure 2.18: Results of Exa 2.7
Example 2.8 Convolution Integral of input x(t) = (e2t).u(βt)andh(t) =u(tβ 3)
1 // Example 2 . 8 : Convo lu t i on I n t e g r a l o f i nput x ( t ) =(eΛ2 t ) . u(β t ) and
2 //h ( t ) = u ( tβ3)3 clear;
4 close;
5 clc;
6 Max_Limit = 10;
7 h =[0,0,0,ones(1,Max_Limit -3)]; //h ( nβ3)8 a = 2;
21 a.x_location=β o r i g i n β;22 a.y_location=β o r i g i n β;23 plot2d(-Max_Limit +1:0,h($:-1:1))
24 xtitle( β Impul se Response β , β t β , β h ( tβT) β );25 a.thickness = 2;
26 figure
27 a=gca();
28 a.y_location = β o r i g i n β;29 plot2d(t,x)
30 xtitle( β Input Response β , β t β , β x ( t ) β );31 a.thickness = 2;
32 figure
33 a=gca();
34 a.y_location = β o r i g i n β;35 a.x_location = β o r i g i n β;36 a.data_bounds =[ -10 ,0;13 ,1];
37 plot2d(-Max_Limit +4: Max_Limit +3,y)
38 xtitle( β Output Response β , β t β , β y ( t ) β );39 a.thickness = 2;
50
Figure 2.19: Results of Exa 2.8
51
Figure 2.20: Results of Exa 2.8
52
Figure 2.21: Results of Exa 2.8
53
Chapter 3
Fourier Series Repreentation ofPeriodic Signals
3.1 Scilab Codes
Example 3.2 CTFS of a periodic signal x(t)Expression of continuous timesignal
1 // Example 3 . 2 : CTFS o f a p e r i o d i c s i g n a l x ( t )2 // E x p r e s s i o n o f c o n t i n u o u s t ime s i g n a l3 // u s i n g c o n t i n u o u s t ime f o u r i e r s e r i e s4 clear;
29 a.y_location = β o r i g i n β;30 a.x_location = β o r i g i n β;31 plot2d3( β gnn β ,[-k:k],Mag_ak ,5)32 poly1 = a.children (1).children (1);
33 poly1.thickness = 3;
34 title( β abs ( ak ) β )35 xlabel( β
k β )36 subplot (2,1,2)
37 a = gca();
38 a.y_location = β o r i g i n β;39 a.x_location = β o r i g i n β;40 plot2d3( β gnn β ,[-k:k],Phase_ak ,5)41 poly1 = a.children (1).children (1);
42 poly1.thickness = 3;
43 title( β<(ak ) β )44 xlabel( β
k β )
62
Figure 3.5: Results of Exa 3.4
Example 3.5 CTFS coefficients of a periodic signal x(t) = 1, |t| < T1, and0, T1 <|t| < T/2
1 // Example3 . 5 : CTFS c o e f f i c i e n t s o f a p e r i o d i c s i g n a l2 //x ( t ) = 1 , | t |<T1 , and 0 , T1<| t |<T/23 clear;
4 close;
5 clc;
6 T =4;
7 T1 = T/4;
8 t = -T1:T1 /100:T1;
9 Wo = 2*%pi/T;
63
10 xt =ones(1,length(t));
11 //12 for k =0:5
13 C(k+1,:) = exp(-sqrt(-1)*Wo*t.*k);
14 a(k+1) = xt*C(k+1,:) β/length(t);
15 if(abs(a(k+1)) <=0.1)
16 a(k+1)=0;
17 end
18 end
19 a =aβ;
20 a_conj = real(a(:))-sqrt(-1)*imag(a(:));
21 ak = [a_conj($: -1:1) β,a(2:$)];
22 k = 0:5;
23 k = [-k($:-1:1),k(2:$)];
24 Spectrum_ak = (1/2)*real(ak);
25 //26 figure
27 a = gca();
28 a.y_location = β o r i g i n β;29 a.x_location = β o r i g i n β;30 a.data_bounds =[-2 ,0;2,2];
31 plot2d(t,xt ,5)
32 poly1 = a.children (1).children (1);
33 poly1.thickness = 3;
34 title( β x ( t ) β )35 xlabel( β
t β )36 //37 figure
38 a = gca();
39 a.y_location = β o r i g i n β;40 a.x_location = β o r i g i n β;41 plot2d3( β gnn β ,k,Spectrum_ak ,5)42 poly1 = a.children (1).children (1);
43 poly1.thickness = 3;
44 title( β abs ( ak ) β )45 xlabel( β
64
k β )
Figure 3.6: Results of Exa 3.5
65
Figure 3.7: Results of Exa 3.5
Example 3.6 Time Shift Property of CTFS
1 // Example3 . 6 : Time S h i f t Prope r ty o f CTFS2 clear;
3 close;
4 clc;
5 T =4;
6 T1 = T/2;
7 t = 0:T1 /100:T1;
8 Wo = 2*%pi/T;
9 gt =(1/2)*ones(1,length(t));
10 a(1)=0; //k=0 , ak =0
66
11 d(1)=0;
12 for k =1:5
13 a(k+1) = (sin(%pi*k/2)/(k*%pi));
14 if(abs(a(k+1)) <=0.01)
15 a(k+1)=0;
16 end
17 d(k+1) = a(k+1)*exp(-sqrt(-1)*k*%pi /2);
18 end
19 k = 0:5
20 disp( β F o u r i e r S e r i e s C o e f f i c i e n t s o f Square Wave β )21 a
22 disp( β F o u r i e r S e r i e s C o e f f i c i e n t s o f g ( t )=x ( tβ1)β0.5β )
23 d
24 //25 figure
26 a = gca();
27 a.y_location = β o r i g i n β;28 a.x_location = β o r i g i n β;29 a.data_bounds =[-1,-2;1,4];
30 plot2d([-t($:-1:1),t(1:$)],[-gt,gt],5)
31 poly1 = a.children (1).children (1);
32 poly1.thickness = 3;
33 title( β g ( t ) β )34 xlabel( β
t β )
67
Figure 3.8: Results of Exa 3.6
Example 3.7 Derivative Property of CTFS
1 // Example3 . 7 : D e r i v a t i v e Proper ty o f CTFS2 clear;
3 clc;
4 close;
5 T =4;
6 T1 = T/2;
7 t = 0:T1 /100:T1;
8 xt = [t($:-1:1) t]/T1;
9 gt =(1/2)*ones(1,length(t));
10 e(1) = 1/2; //k =0 , e0 = 1/2
68
11 for k =1:5
12 a(k+1) = (sin(%pi*k/2)/(k*%pi));
13 if(abs(a(k+1)) <=0.01)
14 a(k+1)=0;
15 end
16 d(k+1) = a(k+1)*exp(-sqrt(-1)*k*%pi /2);
17 e(k+1) = 2*d(k+1)/(sqrt(-1)*k*%pi);
18 end
19 k = 0:5
20 disp( β F o u r i e r S e r i e s C o e f f i c i e n t s o f Square Wave β )21 a
22 disp( β F o u r i e r S e r i e s C o e f f i c i e n t s o f g ( t )=x ( tβ1)β0.5β )
23 d
24 disp( β F o u r i e r S e r i e s C o e f f i c i e n t s o f T r i a n g u l a r Waveβ )
25 e
26 // P l o t t i n g the t ime s h i f t e d squa r e waveform27 figure
28 a = gca();
29 a.y_location = β o r i g i n β;30 a.x_location = β o r i g i n β;31 a.data_bounds =[-1,-2;1,2];
32 plot2d([-t($:-1:1),t(1:$)],[-gt,gt],5)
33 poly1 = a.children (1).children (1);
34 poly1.thickness = 3;
35 title( β g ( t ) β )36 xlabel( β
t β )37 // P l o t t i n g the T r i a n g u l a r waveform38 figure
39 a = gca();
40 a.y_location = β o r i g i n β;41 a.x_location = β o r i g i n β;42 a.data_bounds =[-1 ,0;1,2];
43 plot2d([-t($:-1:1),t(1:$)],xt ,5)
44 poly1 = a.children (1).children (1);
69
45 poly1.thickness = 3;
46 title( β x ( t ) β )47 xlabel( β t β )
Figure 3.9: Results of Exa 3.7
70
Figure 3.10: Results of Exa 3.7
Example 3.8 Fourier Series Representation of Periodic Impulse Train
1 // Example3 . 8 : F o u r i e r S e r i e s R e p r e s e n t a t i o n o fP e r i o d i c Impul se Tra in
2 clear;
3 clc;
4 close;
5 T =4;
6 T1 = T/4;
7 t = [-T,0,T];
8 xt = [1,1,1]; // Genera t i on o f P e r i o d i c t r a i n o fImpu l s e s
71
9 t1 = -T1:T1/100: T1;
10 gt = ones(1,length(t1));// Genera t i on o f p e r i o d i csqua r e wave
11 t2 = [-T1 ,0,T1];
12 qt = [1,0,-1]; // D e r i v a t i v e o f p e r i o d i c squa r e wave13 Wo = 2*%pi/T;
31 a.y_location = β o r i g i n β;32 a.x_location = β o r i g i n β;33 plot2d3( β gnn β ,k,real(ak) ,5)34 poly1 = a.children (1).children (1);
35 poly1.thickness = 3;
36 title( β Real pa r t o f ( ak ) β )37 xlabel( β
k β )38 subplot (2,1,2)
39 a = gca();
40 a.y_location = β o r i g i n β;41 a.x_location = β o r i g i n β;42 plot2d3( β gnn β ,k,imag(ak) ,5)
77
43 poly1 = a.children (1).children (1);
44 poly1.thickness = 3;
45 title( β imag ina ry pa r t o f ( ak ) β )46 xlabel( β
k β )47 //48 figure
49 subplot (2,1,1)
50 a = gca();
51 a.y_location = β o r i g i n β;52 a.x_location = β o r i g i n β;53 plot2d3( β gnn β ,k,Mag_ak ,5)54 poly1 = a.children (1).children (1);
55 poly1.thickness = 3;
56 title( β abs ( ak ) β )57 xlabel( β
k β )58 subplot (2,1,2)
59 a = gca();
60 a.y_location = β o r i g i n β;61 a.x_location = β o r i g i n β;62 plot2d3( β gnn β ,k,Phase_ak ,5)63 poly1 = a.children (1).children (1);
64 poly1.thickness = 3;
65 title( β<(ak ) β )66 xlabel( β
k β )
78
Figure 3.13: Results of Exa 3.11
79
Figure 3.14: Results of Exa 3.11
Example 3.12 DTFS coefficients of periodic square wave
1 // Example3 . 1 2 : DTFS c o e f f i c i e n t s o f p e r i o d i c squa r ewave
2 clear;
3 close;
4 clc;
5 N = 10;
6 N1 = 2;
7 Wo = 2*%pi/N;
8 xn = ones(1,length(N));
9 n = -(2*N1+1) :(2*N1+1);
80
10 a(1) = (2*N1+1)/N;
11 for k =1:2* N1
12 a(k+1) = sin ((2* %pi*k*(N1+0.5))/N)/sin(%pi*k/N);
13 a(k+1) = a(k+1)/N;
14 if(abs(a(k+1)) <=0.1)
15 a(k+1) =0;
16 end
17 end
18 a =aβ;
19 a_conj =conj(a);
20 ak = [a_conj($: -1:1),a(2:$)];
21 k = -2*N1:2*N1;
22 //23 figure
24 a = gca();
25 a.y_location = β o r i g i n β;26 a.x_location = β o r i g i n β;27 plot2d3( β gnn β ,k,real(ak) ,5)28 poly1 = a.children (1).children (1);
29 poly1.thickness = 3;
30 title( β Real pa r t o f ( ak ) β )31 xlabel( β
k β )
81
Figure 3.15: Results of Exa 3.12
Example 3.13 TFS:Expression of periodic sequence using
1 // Example3 . 1 3 : DTFS2 // E x p r e s s i o n o f p e r i o d i c s equence u s i n g3 // the summation two d i f f e r e n t s equence4 clear;
12 x2 = [x2($:-1:1) x2(2:$)]; //DC sequence o f x2 [ n ]13 x = x1+x2;//sum o f x1 [ n ] & x2 [ n ]14 // Zeroth DTFS c o e f f i c i e n t o f dc s equence15 c(1) = 1;
16 // Zeroth DTFS c o e f f i c i e n t o f s qua r e waveform17 b(1) = 3/5;
18 // Zeroth DTFS c o e f f i c i e n t o f sum o f x1 [ n ] & x2 [ n ]19 a(1) = b(1)+c(1);
20 //21 Wo = 2*%pi/N;
22 for k =1:N-1
23 a(k+1) = sin ((3* %pi*k)/N)/sin(%pi*k/N);
24 a(k+1) = a(k+1)/N;
25 if(abs(a(k+1)) <=0.1)
26 a(k+1) =0;
27 end
28 end
29 a =aβ;
30 a_conj =conj(a);
31 ak = [a_conj($: -1:1),a(2:$)];
32 k = -(N-1):(N-1);
33 n = -(N-1):(N-1);
34 //35 figure
36 subplot (3,1,1)
37 a = gca();
38 a.y_location = β o r i g i n β;39 a.x_location = β o r i g i n β;40 plot2d3( β gnn β ,n,x,5)41 poly1 = a.children (1).children (1);
42 poly1.thickness = 3;
43 title( β x [ n ] β )44 xlabel( β
n β )45 subplot (3,1,2)
46 a = gca();
83
47 a.y_location = β o r i g i n β;48 a.x_location = β o r i g i n β;49 plot2d3( β gnn β ,n,x1 ,5)50 poly1 = a.children (1).children (1);
51 poly1.thickness = 3;
52 title( β x1 [ n ] β )53 xlabel( β
n β )54 subplot (3,1,3)
55 a = gca();
56 a.y_location = β o r i g i n β;57 a.x_location = β o r i g i n β;58 plot2d3( β gnn β ,n,x2 ,5)59 poly1 = a.children (1).children (1);
60 poly1.thickness = 3;
61 title( β x2 [ n ] β )62 xlabel( β
n β )
84
Figure 3.16: Results of Exa 3.13
Example 3.14 DTFS:Finding x[n] using parsevalβs relation of DTFS
1 // Example3 . 1 4 : DTFS2 // F ind ing x [ n ] u s i n g p a r s e v a l β s r e l a t i o n o f DTFS3 clear;
4 close;
5 clc;
6 N = 6;
7 n = 0:N-1;
8 a(1) = 1/3;
9 a(2)=0;
10 a(4)=0;
85
11 a(5)=0;
12 a1 = (1/6) *(( -1)^n);
13 x =0;
14 for k = 0:N-2
15 if(k==2)
16 x = x+a1;
17 else
18 x = x+a(k+1);
19 end
20 end
21 x = [x($: -1:1),x(2:$)];
22 n = -(N-1):(N-1);
23 //24 figure
25 a = gca();
26 a.y_location = β o r i g i n β;27 a.x_location = β o r i g i n β;28 plot2d3( β gnn β ,n,x,5)29 poly1 = a.children (1).children (1);
30 poly1.thickness = 3;
31 title( β x [ n ] β )32 xlabel( β
n β )
86
Figure 3.17: Results of Exa 3.14
Example 3.15 DTFS:Periodic Convolution Property
1 // Example3 . 1 5 : DTFS : P e r i o d i c Convo lu t i on Proper ty2 clear;
3 clc;
4 close;
5 x = [1,1,0,0,0,0,1];
6 X = fft(x);
7 W = X.*X;
8 w = ifft(W);
9 w = abs(w);
10 for i =1: length(x)
87
11 if (abs(w(i)) <=0.1)
12 w(i) = 0;
13 end
14 end
15 w = [w($:-1:1) w(2:$)];
16 N = length(x);
17 figure
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 β ,[-(N-1):0,1:N-1],w,5)22 poly1 = a.children (1).children (1);
23 poly1.thickness = 3;
24 title( βw [ n ] β )25 xlabel( β
n β )
88
Figure 3.18: Results of Exa 3.15
89
Chapter 4
The Continuous Time FourierTransform
4.1 Scilab Codes
Example 4.1 Continuous Time Fourier Transform of a Continuous TimeSignal x(t) = exp(βA β t)u(t), t > 0
1 // Example 4 . 1 : Cont inuous Time F o u r i e r Transform o f a2 // Cont inuous Time S i g n a l x ( t )= exp(βAβ t ) u ( t ) , t>03 clear;
4 clc;
5 close;
6 // Analog S i g n a l7 A =1; // Amplitude8 Dt = 0.005;
9 t = 0:Dt:10;
10 xt = exp(-A*t);
11 //12 // Continuousβt ime F o u r i e r Transform13 Wmax = 2*%pi*1; // Analog Frequency = 1Hz14 K = 4;
15 k = 0:(K/1000):K;
16 W = k*Wmax/K;
17 XW = xt* exp(-sqrt(-1)*tβ*W) * Dt;
90
18 XW_Mag = abs(XW);
19 W = [-mtlb_fliplr(W), W(2:1001) ]; // Omega from βWmax to Wmax
23 // P l o t t i n g Cont inuous Time S i g n a l24 figure
25 a = gca();
26 a.y_location = β o r i g i n β;27 plot(t,xt);
28 xlabel( β t i n s e c . β );29 ylabel( β x ( t ) β )30 title( β Cont inuous Time S i g n a l β )31 figure
32 // P l o t t i n g Magnitude Response o f CTS33 subplot (2,1,1);
34 a = gca();
35 a.y_location = β o r i g i n β;36 plot(W,XW_Mag);
37 xlabel( β Frequency i n Radians / Secondsβββ> Wβ );38 ylabel( β abs (X(jW) ) β )39 title( β Magnitude Response (CTFT) β )40 // P l o t t i n g Phase Reponse o f CTS41 subplot (2,1,2);
42 a = gca();
43 a.y_location = β o r i g i n β;44 a.x_location = β o r i g i n β;45 plot(W,XW_Phase*%pi /180);
46 xlabel( β Frequency i nRadians / Secondsβββ> Wβ );
47 ylabel( β<X
(jW) β )48 title( β Phase Response (CTFT) i n Radians β )
91
Figure 4.1: Results of Exa 4.1
92
Figure 4.2: Results of Exa 4.1
Example 4.2 Continuous Time Fourier Transform of a Continuous TimeSignal x(t) = exp(βA β abs(t))
1 // Example 4 . 2 : Cont inuous Time F o u r i e r Transform o f a2 // Cont inuous Time S i g n a l x ( t )= exp(βAβ abs ( t ) )3 clear;
4 clc;
5 close;
6 // Analog S i g n a l7 A =1; // Amplitude8 Dt = 0.005;
9 t = -4.5:Dt:4.5;
93
10 xt = exp(-A*abs(t));
11 //12 // Continuousβt ime F o u r i e r Transform13 Wmax = 2*%pi*1; // Analog Frequency = 1Hz14 K = 4;
15 k = 0:(K/1000):K;
16 W = k*Wmax/K;
17 XW = xt* exp(-sqrt(-1)*tβ*W) * Dt;
18 XW = real(XW);
19 W = [-mtlb_fliplr(W), W(2:1001) ]; // Omega from βWmax to Wmax
20 XW = [mtlb_fliplr(XW), XW (2:1001) ];
21 subplot (1,1,1)
22 subplot (2,1,1);
23 a = gca();
24 a.y_location = β o r i g i n β;25 plot(t,xt);
26 xlabel( β t i n s e c . β );27 ylabel( β x ( t ) β )28 title( β Cont inuous Time S i g n a l β )29 subplot (2,1,2);
30 a = gca();
31 a.y_location = β o r i g i n β;32 plot(W,XW);
33 xlabel( β Frequency i n Radians / Seconds Wβ );34 ylabel( βX(jW) β )35 title( β Continuousβt ime F o u r i e r Transform β )
94
Figure 4.3: Results of Exa 4.2
Example 4.4 Continuous Time Fourier Transform and Frequency Responseof a Square Waveform x(t) = A, fromβ T1toT1
1 // Example 4 . 42 // Cont inuous Time F o u r i e r Transform3 // and Frequency Response o f a Square Waveform4 // x ( t )= A, from βT1 to T15 clear;
6 clc;
7 close;
8 // CTS S i g n a l9 A =1; // Amplitude
95
10 Dt = 0.005;
11 T1 = 4; //Time i n s e c o n d s12 t = -T1/2:Dt:T1/2;
13 for i = 1: length(t)
14 xt(i) = A;
15 end
16 //17 // Continuousβt ime F o u r i e r Transform18 Wmax = 2*%pi*1; // Analog Frequency = 1Hz19 K = 4;
20 k = 0:(K/1000):K;
21 W = k*Wmax/K;
22 xt = xt β;
23 XW = xt* exp(-sqrt(-1)*tβ*W) * Dt;
24 XW_Mag = real(XW);
25 W = [-mtlb_fliplr(W), W(2:1001) ]; // Omega from βWmax to Wmax
31 a.y_location =β o r i g i n β;32 plot(t,xt);
33 xlabel( β t i n msec . β );34 title( β Cont iuous Time S i g n a l x ( t ) β )35 subplot (2,1,2);
36 a = gca();
37 a.y_location =β o r i g i n β;38 plot(W,XW_Mag);
39 xlabel( β Frequency i n Radians / Seconds β );40 title( β Continuousβt ime F o u r i e r Transform X(jW) β )
96
Figure 4.4: Results of Exa 4.4
Example 4.5 Inverse Continuous Time Fourier Transform X(jW ) = 1,from -T1 to T1
1 // Example 4 . 52 // I n v e r s e Cont inuous Time F o u r i e r Transform3 // X(jW)= 1 , from βT1 to T14 clear;
5 clc;
6 close;
7 // CTFT8 A =1; // Amplitude9 Dw = 0.005;
97
10 W1 = 4; //Time i n s e c o n d s11 w = -W1/2:Dw:W1/2;
12 for i = 1: length(w)
13 XW(i) = A;
14 end
15 XW = XW β;
16 //17 // I n v e r s e Continuousβt ime F o u r i e r Transform18 t = -%pi:%pi/length(w):%pi;
19 xt =(1/(2* %pi))*XW *exp(sqrt(-1)*wβ*t)*Dw;
20 xt = real(xt);
21 figure
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(t,xt);
26 xlabel( β t t imei n Seconds β );
27 title( β I n v e r s e Cont inuous Time F o u r i e r Transform x ( t) β )
98
Figure 4.5: Results of Exa 4.5
Example 4.6 Continuous Time Fourier Transform of Symmetric periodicSquare waveform
1 // Example 4 . 62 // Cont inuous Time F o u r i e r Transform o f Symmetric3 // p e r i o d i c Square waveform4 clear;
5 clc;
6 close;
7 // CTFT8 T1 = 2;
9 T = 4*T1;
99
10 Wo = 2*%pi/T;
11 W = -%pi:Wo:%pi;
12 delta = ones(1,length(W));
13 XW(1) = (2* %pi*Wo*T1/%pi);
14 mid_value = ceil(length(W)/2);
15 for k = 2: mid_value
16 XW(k) = (2* %pi*sin((k-1)*Wo*T1)/(%pi*(k-1)));
17 end
18 figure
19 a = gca();
20 a.y_location =β o r i g i n β;21 a.x_location =β o r i g i n β;22 plot2d3( β gnn β ,W(mid_value:$),XW ,2);23 poly1 = a.children (1).children (1);
28 xlabel( βW i n r a d i a n s / Seconds β );29 title( β Cont inuous Time F o u r i e r Transform o f P e r i o d i c
Square Wave β )
100
Figure 4.6: Results of Exa 4.6
Example 4.7 Continuous Time Fourier Transforms of Sinusoidal waveforms(a)sin(Wot) (b)cos(Wot)
1 // Example 4 . 72 // Cont inuous Time F o u r i e r Trans forms o f3 // S i n u s o i d a l waveforms ( a ) s i n (Wot) ( b ) co s (Wot)4 clear;
5 clc;
6 close;
7 // CTFT8 T1 = 2;
9 T = 4*T1;
101
10 Wo = 2*%pi/T;
11 W = [-Wo ,0,Wo];
12 ak = (2*%pi*Wo*T1/%pi)/sqrt(-1);
13 XW = [-ak ,0,ak];
14 ak1 = (2*%pi*Wo*T1/%pi);
15 XW1 =[ak1 ,0,ak1];
16 //17 figure
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,imag(XW) ,2);22 poly1 = a.children (1).children (1);
23 poly1.thickness = 3;
24 xlabel( β
Wβ );25 title( βCTFT o f s i n (Wot) β )26 //27 figure
28 a = gca();
29 a.y_location =β o r i g i n β;30 a.x_location =β o r i g i n β;31 plot2d3( β gnn β ,W,XW1 ,2);32 poly1 = a.children (1).children (1);
33 poly1.thickness = 3;
34 xlabel( β
Wβ );35 title( βCTFT o f co s (Wot) β )
102
Figure 4.7: Results of Exa 4.7
103
Figure 4.8: Results of Exa 4.7
Example 4.8 Continuous Time Fourier Transform of Periodic Impulse Train
1 // Example 4 . 82 // Cont inuous Time F o u r i e r Trans forms o f3 // P e r i o d i c Impul se Tra in4 clear;
5 clc;
6 close;
7 // CTFT8 T = -4:4;;
9 T1 = 1; // Sampl ing I n t e r v a l10 xt = ones(1,length(T));
104
11 ak = 1/T1;
12 XW = 2*%pi*ak*ones(1,length(T));
13 Wo = 2*%pi/T1;
14 W = Wo*T;
15 figure
16 subplot (2,1,1)
17 a = gca();
18 a.y_location =β o r i g i n β;19 a.x_location =β o r i g i n β;20 plot2d3( β gnn β ,T,xt ,2);21 poly1 = a.children (1).children (1);
22 poly1.thickness = 3;
23 xlabel( β
t β );24 title( β P e r i o d i c Impul se Tra in β )25 subplot (2,1,2)
26 a = gca();
27 a.y_location =β o r i g i n β;28 a.x_location =β o r i g i n β;29 plot2d3( β gnn β ,W,XW ,2);30 poly1 = a.children (1).children (1);
31 poly1.thickness = 3;
32 xlabel( β
t β );33 title( βCTFT o f P e r i o d i c Impul se Tra in β )
105
Figure 4.9: Results of Exa 4.8
Example 4.9 Continuous Time Fourier Transform Properties: Linearityand Time Shift Property
1 // Example 4 . 9 : Cont inuous Time F o u r i e r TransformP r o p e r t i e s :
2 // L i n e a r i t y and Time S h i f t Proper ty3 clear;
4 clc;
5 close;
6 // CTFT7 t1 = -1/2:0.1:1/2;
8 t2 = -3/2:0.1:3/2;
106
9 x1 = ones(1,length(t1));
10 x2 = ones(1,length(t2));
11 t3 = t1 +2.5;
12 t4 = t2 +2.5;
13 x1 = (1/2)*x1;
14 x = [x2(1: floor(length(x2)/3)),x1+x2(ceil(length(x2)
/3):$-floor(length(x2)/3)),x2(($-ceil(length(x2)
/3))+2:$)];
15 subplot (3,1,1)
16 a = gca();
17 a.x_location = β o r i g i n β;18 a.y_location = β o r i g i n β;19 plot(t1,x1)
20 xtitle( β x1 ( t ) β )21 subplot (3,1,2)
22 a = gca();
23 a.x_location = β o r i g i n β;24 a.y_location = β o r i g i n β;25 plot(t2,x2)
26 xtitle( β x2 ( t ) β )27 subplot (3,1,3)
28 a = gca();
29 a.x_location = β o r i g i n β;30 a.y_location = β o r i g i n β;31 plot(t4,x)
32 xtitle( β x ( t ) β )
107
Figure 4.10: Results of Exa 4.9
Example 4.12 Continuous Time Fourier Transform: Derivative property
1 // Example 4 . 1 2 : Cont inuous Time F o u r i e r Transform :2 // D e r i v a t i v e p r o p e r t y3 clear;
4 clc;
5 close;
6 // CTFT7 t = -1:0.1:1;
8 x1 = ones(1,length(t));
9 x2 = [-1,zeros(1,length(t) -2) ,-1];
10 x = t;
108
11 // d i f f e r e n t i a t i o n o f x can be e x p r e s s e d as12 // summation o f x1 and x213 subplot (3,1,1)
14 a = gca();
15 a.x_location = β o r i g i n β;16 a.y_location = β o r i g i n β;17 plot(t,x1)
18 xtitle( β x1 ( t ) β )19 subplot (3,1,2)
20 a = gca();
21 a.x_location = β o r i g i n β;22 a.y_location = β o r i g i n β;23 plot2d3( β gnn β ,t,x2)24 xtitle( β x2 ( t ) β )25 subplot (3,1,3)
26 a = gca();
27 a.x_location = β o r i g i n β;28 a.y_location = β o r i g i n β;29 plot(t,x)
30 xtitle( β x ( t ) β )
109
Figure 4.11: Results of Exa 4.12
Example 4.18 Frequency Response of Ideal Low pass Filter X(jW ) = 1,from -T1 to T1
1 // Example 4 . 1 8 : Frequency Response o f I d e a l Low pas sF i l t e r
2 // X(jW)= 1 , from βT1 to T13 clear;
4 clc;
5 close;
6 Wc = 10; // 1 rad / s e c7 W = -Wc:0.1: Wc; // Passband o f f i l t e r8 HW0 = 1; // Magnitude o f F i l t e r
110
9 HW = HW0*ones(1,length(W));
10 // I n v e r s e Continuousβt ime F o u r i e r Transform11 t = -%pi:%pi/length(W):%pi;
12 Dw = 0.1;
13 ht =(1/(2* %pi))*HW *exp(sqrt(-1)*Wβ*t)*Dw;
14 ht = real(ht);
15 figure
16 subplot (2,1,1)
17 a = gca();
18 a.y_location =β o r i g i n β;19 a.x_location =β o r i g i n β;20 plot(W,HW);
21 xtitle( β Frequency Response o f F i l t e r H(jW) β )22 subplot (2,1,2)
23 a = gca();
24 a.y_location =β o r i g i n β;25 a.x_location =β o r i g i n β;26 plot(t,ht);
27 xtitle( β Impul se Response o f F i l t e r h ( t ) β )
111
Figure 4.12: Results of Exa 4.18
Example 4.23 Multiplication Property of CTFT
1 // F igu r e 4 . 2 3 : M u l t i p l i c a t i o n Proper ty o f CTFT2 clear;
3 clc;
4 close;
5 W1 = -1:0.1:1;
6 W2 = -2:0.1:2;
7 W = -3:0.1:3;
8 // F o u r i e r Transform o f s i n c f u n c i o n i s s qua r e wave9 XW1 = (1/%pi)*ones(1,length(W1)); //CTFT o f x1 ( t )10 XW2 = (1/(2* %pi))*ones(1,length(W2));//CTFT o f x2 ( t )
112
11 XW = (1/2)*convol(XW1 ,XW2);//CTFT o f x ( t )=x1 ( t ) βx2 ( t)
12 //X( jw ) = l i n e a r c o n v o l u t i o n o f X1( jw ) and X2( jw )13 figure
14 a = gca();
15 a.y_location = β o r i g i n β;16 a.x_location = β o r i g i n β;17 plot(W,XW);
18 xlabel( β Frequency i n Radians / Secondsβββ> Wβ );19 title( β M u l t i p l i c a t i o n Proper ty X(jW) β )
Figure 4.13: Results of Exa 4.23
113
Example 4.221 // F igu r e 4 . 2 22 // P l o t t i n g Cont inuous Time F o u r i e r Transform o f3 // Impul se Response h ( t )= exp(βAβ t ) u ( t ) , t>04 clear;
5 clc;
6 close;
7 // Analog S i g n a l8 A =1; // Amplitude9 Dt = 0.005;
10 t = 0:Dt:10;
11 ht = exp(-A*t);
12 // Continuousβt ime F o u r i e r Transform13 Wmax = 2*%pi*1; // Analog Frequency = 1Hz14 K = 4;
15 k = 0:(K/1000):K;
16 W = k*Wmax/K;
17 HW = ht* exp(-sqrt(-1)*tβ*W) * Dt;
18 HW_Mag = abs(HW);
19 W = [-mtlb_fliplr(W), W(2:1001) ]; // Omega from βWmax to Wmax
24 a.y_location =β o r i g i n β;25 a.x_location =β o r i g i n β;26 plot2d3( β gnn β ,n,x);27 xtitle( β D i s c r e t e Time Sequence x [ n ] f o r a>0 β )28 subplot (2,1,2);
29 a = gca();
30 a.y_location =β o r i g i n β;31 a.x_location =β o r i g i n β;32 plot2d(W,XW_Mag);
33 title( β D i s c r e t e Time F o u r i e r Transform X( exp (jW) ) β )
122
Figure 5.3: Results of Exa 5.2
Example 5.3 Discrete Time Fourier Transform of x[n] = 1, abs(n) <= N1
1 // Example 5 . 3 : D i s c r e t e Time F o u r i e r Transform o f2 //x [ n]= 1 , abs ( n )<=N13 clear;
4 clc;
5 close;
6 // DTS S i g n a l7 N1 = 2;
8 n = -N1:N1;
9 x = ones(1,length(n));
10 // D i s c r e t eβt ime F o u r i e r Transform
123
11 Wmax = 2*%pi;
12 K = 4;
13 k = 0:(K/1000):K;
14 W = k*Wmax/K;
15 XW = x* exp(-sqrt(-1)*nβ*W);
16 XW_Mag = real(XW);
17 W = [-mtlb_fliplr(W), W(2:1001) ]; // Omega from βWmax to Wmax
23 a.y_location =β o r i g i n β;24 a.x_location =β o r i g i n β;25 plot2d3( β gnn β ,n,x);26 xtitle( β D i s c r e t e Time Sequence x [ n ] β )27 subplot (2,1,2);
28 a = gca();
29 a.y_location =β o r i g i n β;30 a.x_location =β o r i g i n β;31 plot2d(W,XW_Mag);
32 title( β D i s c r e t e Time F o u r i e r Transform X( exp (jW) ) β )
124
Figure 5.4: Results of Exa 5.3
Example 5.5 Discrete Time Fourier Transform: x[n] = cos(nWo)
1 // Example5 . 5 : D i s c r e t e Time F o u r i e r Transform : x [ n]=co s (nWo)
2 clear;
3 clc;
4 close;
5 N = 5;
6 Wo = 2*%pi/N;
7 W = [-Wo ,0,Wo];
8 XW =[%pi ,0,%pi];
9 //
125
10 figure
11 a = gca();
12 a.y_location =β o r i g i n β;13 a.x_location =β o r i g i n β;14 plot2d3( β gnn β ,W,XW ,2);15 poly1 = a.children (1).children (1);
16 poly1.thickness = 3;
17 xlabel( β
Wβ );18 title( βDTFT o f co s (nWo) β )19 disp(Wo)
126
Figure 5.5: Results of Exa 5.5
Example 5.6 Discrete Time Fourier Transform of Periodic Impulse Train
1 // Example5 . 6 : D i s c r e t e Time F o u r i e r Transform o f2 // P e r i o d i c Impul se Tra in3 clear;
4 clc;
5 close;
6 N = 5;
7 N1 = -3*N:3*N;
8 xn = [zeros(1,N-1) ,1];
9 x = [1 xn xn xn xn xn xn];
10 ak = 1/N;
127
11 XW = 2*%pi*ak*ones (1,2*N);
12 Wo = 2*%pi/N;
13 n = -N:N-1;
14 W = Wo*n;
15 figure
16 subplot (2,1,1)
17 a = gca();
18 a.y_location =β o r i g i n β;19 a.x_location =β o r i g i n β;20 plot2d3( β gnn β ,N1 ,x,2);21 poly1 = a.children (1).children (1);
22 poly1.thickness = 3;
23 xlabel( β
n β );24 title( β P e r i o d i c Impul se Tra in β )25 subplot (2,1,2)
26 a = gca();
27 a.y_location =β o r i g i n β;28 a.x_location =β o r i g i n β;29 plot2d3( β gnn β ,W,XW ,2);30 poly1 = a.children (1).children (1);
31 poly1.thickness = 3;
32 xlabel( β
Wβ );33 title( βDTFT o f P e r i o d i c Impul se Tra in β )34 disp(Wo)
128
Figure 5.6: Results of Exa 5.6
Example 5.7 Frequency Shifting Property of DTFT:Frequency Responseof Ideal Low pass Filter and HPF
1 // Example 5 . 7 : Frequency S h i f t i n g Proper ty o f DTFT:Frequency Response o f I d e a l Low pas s F i l t e r andHPF
2 clear;
3 clc;
4 close;
5 Wc = 1; // 1 rad / s e c6 W = -Wc:0.1: Wc; // Passband o f f i l t e r7 H0 = 1; // Magnitude o f F i l t e r
129
8 HlpW = H0*ones(1,length(W));
9 Whp1 = W+%pi;
10 Whp2 = -W-%pi;
11 figure
12 subplot (2,1,1)
13 a = gca();
14 a.y_location =β o r i g i n β;15 a.x_location =β o r i g i n β;16 a.data_bounds =[-%pi ,0;%pi ,2];
17 plot2d(W,HlpW);
18 xtitle( β Frequency Response o f LPF H( exp (jW) ) β )19 subplot (2,1,2)
20 a = gca();
21 a.y_location =β o r i g i n β;22 a.x_location =β o r i g i n β;23 a.data_bounds =[-2*%pi ,0;2*%pi ,2];
24 plot2d(Whp1 ,HlpW);
25 plot2d(Whp2 ,HlpW);
26 xtitle( β Frequency Response o f HPF H( exp (jW) ) β )
130
Figure 5.7: Results of Exa 5.7
Example 5.9 Time Expansion Property of DTFT
1 // Example 5 . 9 : Time Expans ion Proper ty o f DTFT2 clear;
3 close;
4 clc;
5 n = -1:11;
6 x = [0,1,2,1,2,1,2,1,2,1,2,0,0];
7 y = [1,1,1,1,1];
8 y_2_n =zeros (1,2* length(y)+1);
9 y_2_n (1:2:2* length(y)) = y;
10 y_2_n = [0 y_2_n 0];
131
11 y_2_n_1 = [0,y_2_n (1:$-1)];
12 x_r = y_2_n +2* y_2_n_1;
13 y = [0,y,zeros (1,7)];
14 figure
15 subplot (4,1,1)
16 plot2d3( β gnn β ,n,y)17 title( β y [ n ] β )18 subplot (4,1,2)
19 plot2d3( β gnn β ,n,y_2_n)20 title( β y ( 2 ) [ n ] β )21 subplot (4,1,3)
61 xtitle( β P r i n c i p a l phase β , β Frequency ( Hz ) β , β Phase ( rad )β );
62 figure
63 plot2d(f,W_phase_total ,2)
64 xtitle( β unwrapped phase β , β Frequency ( Hz ) β , β Phase ( rad )β );
65 figure
66 plot2d(f,abs(group_delay) ,2)
140
67 xtitle( β group d e l a y β , β Frequency ( Hz ) β , β Group Delay (s e c ) β );
Figure 6.1: Results of Exa 6.1
141
Figure 6.2: Results of Exa 6.1
142
Figure 6.3: Results of Exa 6.1
Example 6.3 Analog Lowpass IIR filter design Cutoff frequency Fc = 500HzPassband ripple 1-0.05 and stopband ripple = 0.05
1 // Example6 . 3 : Analog Lowpass IIR f i l t e r d e s i g n2 // C u t o f f f r e q u e n c y Fc = 500Hz3 // Passband r i p p l e 1β0.05 and stopband r i p p l e = 0 . 0 54 clear;
5 close;
6 clc;
7 hs_butt = analpf(5, β but t β ,[0.05 ,0.05] ,500);8 hs_ellip = analpf(5, β e l l i p β ,[0.05 ,0.05] ,500);9 fr =0:.1:2000;
14 // P l o t t i n g Magnitude Response o f Analog IIR F i l t e r s15 a = gca();
16 plot2d(fr,hm_butt)
17 poly1 = a.children (1).children (1);
18 poly1.foreground = 2;
19 poly1.thickness = 2;
20 poly1.line_style = 3;
21 plot2d(fr,hm_ellip)
22 poly1 = a.children (1).children (1);
23 poly1.foreground = 5;
24 poly1.thickness = 2;
25 xlabel( β Frequency ( Hz ) β )26 ylabel( β Magnitude o f f r e q u e n c y r e s p o n s e β )27 legend ([ β Butte rworth F i l t e r β ; β E l l i p t i c F i l t e r β ])
144
Figure 6.4: Results of Exa 6.3
Example 6.4 Bode Plot
1 // Example 6 . 4 : Bode P lo t2 s = %s;
3 //Open Loop T r a n s f e r Funct ion4 H = syslin( β c β ,[20000/(s^2+100*s+10000) ]);// jw
r e p l a c e d by s5 clf;
6 bode(H ,0.01 ,10000)
145
Figure 6.5: Results of Exa 6.4
Example 6.5 Bode Plot
1 // Example 6 . 5 : Bode P lo t2 s = %s;
3 //Open Loop T r a n s f e r Funct ion4 H = syslin( β c β ,[(100*(1+s))/((10+s)*(100+s))]);// jw
r e p l a c e d by s5 clf;
6 bode(H ,0.01 ,10000)
146
Figure 6.6: Results of Exa 6.5
147
Chapter 7
Sampling
7.1 Scilab Codes
Example 7.1 Sinusoidal signal
1 // Example7 . 1 : S i n u s o i d a l s i g n a l2 clear;
3 close;
4 clc;
5 Wm = 2*%pi;
6 Ws = 2*Wm;
7 t = -2:0.01:2;
8 phi = -%pi/2;
9 x = cos((Ws/2)*t+phi);
10 y = sin((Ws/2)*t);
11 subplot (2,1,1)
12 a = gca();
13 a.x_location = β o r i g i n β;14 a.y_location = β o r i g i n β;15 plot(t,x)
16 title( β c o s (Ws/2β t+phi ) β )17 subplot (2,1,2)
18 a = gca();
19 a.x_location = β o r i g i n β;20 a.y_location = β o r i g i n β;
148
21 plot(t,y)
22 title( β s i n (Ws/2β t ) β )
Figure 7.1: Results of Exa 7.1
Example 7.2 Digital Differentiator
1 // Example7 . 2 : D i g i t a l D i f f e r e n t i a t o r2 syms t n;
3 T = 0.1; // Sampl ing t ime i n s e c o n d s4 xct = sin(%pi*t/T)/(%pi*t);
5 yct = diff(xct ,t);
6 disp(yct , β yc ( t )= β );
149
7 t = n*T;
8 xdn = sin(%pi*t/T)/(%pi*t);
9 ydn = diff(xdn ,n);
10 disp(ydn , β yd [ n]= β );11 hdn = T*ydn;
12 disp(hdn , β hd [ n]= β );13 // R e s u l t14 // yc ( t ) = (10β co s ( 3 1 . 4 1 5 9 2 7β t ) / t ) β(0 .3183099β s i n
( 3 1 . 4 1 5 9 2 7β t ) /( t Λ2) )15 // yd [ n ]=(10β co s ( 3 . 1 4 1 5 9 2 7β n ) /n ) β3.183β s i n ( 3 . 1 4 1 5 9 2 7β
n ) /( n Λ2)16 //hd [ n ]=( co s ( 3 . 1 4 1 5 9 2 7β n ) /n ) β0.3183β s i n ( 3 . 1 4 1 5 9 2 7β n )
/( n Λ2)
Example 7.3 Half Sample Delay system
1 // Example7 . 3 : Ha l f Sample Delay system2 syms t n T;
3 //T = 0 . 1 ; // Sampl ing t ime i n s e c o n d s4 xct = sin(%pi*t/T)/(%pi*t);
5 t = t-T/2;
6 yct_del = sin(%pi*t/T)/(%pi*t);
7 disp(yct_del , β Output o f Ha l f Sample d e l a y systemc o n t i n u o u s = β );
8 t = n*T-T/2;
9 xdn = sin(%pi*t/T)/(%pi*t);
10 ydn_del = xdn;
11 disp(ydn_del , β Output o f Ha l f Sample d e l a y systemd i s c r e t e = β );
12 hdn = T*ydn_del;
13 disp(hdn , β Impul se Response o f d i s c r e t e t ime h a l fsample d e l a y system= β );
14 // R e s u l t15 // Output o f Ha l f Sample d e l a y system c o n t i n u o u s =16 // s i n ( 3 . 1 4 β ( tβT/2) /T) / ( 3 . 1 4 β ( tβT/2) )17 // Output o f Ha l f Sample d e l a y system d i s c r e t e =18 // s i n ( 3 . 1 4 β ( nβTβT/2) /T) / ( 3 . 1 4 β ( nβTβT/2) )
150
19 // Impul se Response o f d i s c r e t e t ime h a l f sampled e l a y system=
20 // Tβ s i n ( 3 . 1 4 β ( nβTβT/2) /T) / ( 3 . 1 4 β ( nβTβT/2) )
Example 7.4 Finding the period of the sampled signal and Sampling fre-quency
1 // Example7 . 4 : F ind ing the p e r i o d o f the sampleds i g n a l
2 // and Sampl ing f r e q u e n c y3 clear;
4 close;
5 clc;
6 Wm = 2*%pi /9;
7 N = floor (2* %pi /(2*Wm))
8 disp(N, β Pe r i od o f the d i s c r e t e s i g n a l β )9 Ws = 2*%pi/N;
10 disp(Ws, β The Sampl ing f r e q u e n c y c o r r e s p o n d i n g to thep e r i o d N β )
Example 7.5 Multirate Signal Processing:Sampling Rate Conversion (1)Down-sampling by 4 (2)Upsampling by 2 (3)Upsampling by 2 and followed bydownsampling by 9
1 // Example7 . 5 : M u l t i r a t e S i g n a l P r o c e s s i n g : Sampl ingRate Conver s i on
2 // ( 1 ) Downsampling by 43 // ( 2 ) Upsampling by 24 // ( 3 ) Upsampling by 2 and f o l l o w e d by downsampling by
95 clear;
6 close;
7 clc;
8 Wm = 2*%pi /9; //Maximum f r e q u e n c y o f s i g n a l9 Ws = 2*Wm; // Sampl ing f r e q u e n c y10 N = floor (2* %pi/Ws);// p e r i o d o f d i s c r e t e s i g n a l11 // O r i g i n a l d i s c r e t e t ime s i g n a l g e n e r a t i o n and
Magnitude r e s p o n s e
151
12 n = 0:0.01:N;
13 x = sin(Wm*n);
14 Wmax = 2*%pi/9;
15 K = 4;
16 k = 0:(K/1000):K;
17 W = k*Wmax/K;
18 XW = x* exp(-sqrt(-1)*nβ*W);
19 XW_Mag = real(XW);
20 XW_Mag = XW_Mag/max(XW_Mag);
21 W = [-mtlb_fliplr(W), W(2:1001) ]; // Omega from βWmax to Wmax
1 // Example9 . 1 32 // I n v e r s e Lapa l c e Transform3 //X1( S ) = 1/( s +1) Re ( s )> β14 //X2( S ) = 1 / ( ( s +1) ( s +2) ) Re ( s )>β15 s =%s ;
6 syms t ;
7 G1 =syslin( β c β ,(1/(s+1)));8 disp(G1,βG( s )=β)9 figure
10 plzr(G1)
11 G2 =syslin( β c β ,(1/((s+1)*(s+2))));12 disp(G2,βG( s )=β)13 figure
14 plzr(G2)
15 G3 = syslin( β c β ,(1/(s+1)) -(1/((s+1)*(s+2))));16 disp(G3,βG( s )=β)17 figure
18 plzr(G3)
160
Figure 9.2: Results of Exa 9.13
161
Figure 9.3: Results of Exa 9.13
162
Figure 9.4: Results of Exa 9.13
Example 9.14 Lapalce Transform x(t) = t.exp(βat), t > 0, x(t) = (t2)/2.exp(βat), t >0
1 // Example9 . 1 4 : Lapa l c e Transform2 //x ( t ) = t . exp(βat ) , t>03 //x ( t ) = ( t Λ2) / 2 . exp(βat ) , t>04 s =%s ;
5 syms t ;
6 a =10;
7 x1 = laplace( β t β%eΛ(β10β t ) β ,t,s);8 disp(x1)
9 x2 = laplace( β ( ( t Λ2) /2) β%eΛ(β10β t ) β ,t,s);
163
10 disp(x2)
11 // R e s u l t12 // 1 / ( ( s +10) Λ2)13 // 1 / ( ( s +10) Λ3)
1 // Example9 . 1 5 : I n v e r s e Lapa l c e Transform2 //X( S ) = (2 s Λ2+5 s +5) / ( ( s +1) Λ2) ( s +2) ) Re ( s )>β13 s =%s ;
4 syms t ;
5 [A]=pfss ((2*(s^2)+5*s+5) /(((s+1) ^2)*(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 )=β)11 // R e s u l t12 // (2β t β (%eΛβt ) )β(%eΛβt ) +(3β%eΛβ(2β t ) )
Example 9.16 Initial Value Theorem of Lapalace Transform
1 // Example9 . 1 6 : I n i t i a l Value Theorem o f Lapa laceTransform
2 syms s;
3 num =poly ([12 5 2], β s β , β c o e f f β )4 den =poly ([20 14 4 1], β s β , β c o e f f β )5 X = num/den
6 disp (X,βX( s )=β)7 SX = s*X;
8 Initial_Value =limit(SX,s,%inf);
9 disp(Initial_Value ,βx ( 0 )=β)10 // R e s u l t11 // (2β%inf Λ3+5β%inf Λ2+12β%inf ) /( %inf Λ3+4β%inf Λ2+14β
%inf +20) =2
164
Example 9.17 Analysis and Characterization of LTI System Lapalce Trans-form h(t) = exp(βt).u(t)
1 // Example9 . 1 7 : A n a l y s i s and C h a r a c t e r i z a t i o n o f LTISystem
2 // Lapa l c e Transform h ( t ) = exp(β t ) . u ( t )3 syms t s;
4 h =laplace( β%eΛ(β t ) β ,t,s);5 disp(h)
6 // R e s u l t7 // 1/( s +1)
Example 9.18 Analysis and Characterization of LTI System Lapalce Trans-form x(t) = exp(βabs(t))x(t) = exp(βt).u(t) + exp(t).u(βt)
1 // Example9 . 1 8 : A n a l y s i s and C h a r a c t e r i z a t i o n o f LTISystem
2 // Lapa l c e Transform x ( t ) = exp(βabs ( t ) )3 //x ( t ) = exp(β t ) . u ( t )+exp ( t ) . u(β t )4 syms t s;
5 y = laplace( β%eΛ(β t )β%eΛ( t ) β ,t,s);6 disp(y)
7 // R e s u l t8 // ( 1 / ( s +1) ) β(1/( sβ1) )
Example 9.19 Analysis and Characterization of LTI System Inverse La-palce Transform X(S) = (es)/(s + 1)
1 // Example9 . 1 9 : A n a l y s i s and C h a r a c t e r i z a t i o n o f LTISystem
2 // I n v e r s e Lapa l c e Transform3 //X( S ) = ( e Λ s ) /( s +1)4 syms s t ;
5 h1 = exp(-1);// I n v e r s e Lap lace Transform o f exp ( s )6 H2 =1/(s+1);
7 h2 = ilaplace(H2,s,t)
8 h = h1*h2;
9 disp(h,βh ( t )=β)
165
10 // R e s u l t11 // (1 8 0 89β (%eΛβt ) ) /49171 = 0 . 3 6 7 8 7 9 4 ( %eΛβt )
Example 9.20 Inverse Lapalce Transform X(S) = ((sβ1)/((s+1)β(sβ2)))
1 // Example9 . 2 0 : I n v e r s e Lapa l c e Transform2 //X( S ) = ( ( sβ1) / ( ( s +1) β ( sβ2) ) )3 s =%s ;
4 syms t ;
5 [A] = pfss(s/((s+1)*(s-2)));
6 [B] = pfss (1/((s+1)*(s-2)));
7 F1 = ilaplace(A(1),s,t)
8 F2 = ilaplace(A(2),s,t)
9 F3 = ilaplace(B(1),s,t)
10 F4 = ilaplace(B(2),s,t)
11 F = F1+F2-F3-F4;
12 disp(F,β f ( t )=β)13 // R e s u l t14 // f ( t )= 33333329999999β exp (2β t )
/99999970000000+6666664β%eΛβt /999999715 // i . e . f ( t ) =0.3333334β exp (2β t ) +0.6666666β%eΛ(β t )16 // Re f e r e q u a t i o n 9 . 1 2 0 . ( 1 / 3 ) =0.3333 and ( 2 / 3 ) =
0 . 6 6 6 6 6
Example 9.21 Analysis and Characterization of LTI System Lapalce Trans-form h(t) = exp(2t)u(t), Re(s) > 2
1 // Example9 . 2 1 : A n a l y s i s and C h a r a c t e r i z a t i o n o f LTISystem
2 // Lapa l c e Transform h ( t ) = exp (2 t ) u ( t ) , Re ( s )>23 syms t s;
4 X = laplace( β%eΛ(2β t ) β ,t,s);5 disp(X)
6 // R e s u l t7 // 1/( sβ2)
166
Example 9.25 LTI Systems Characterized by Linear Constant Coefficientdifferential Equation Finding Transfer function H(S) of LTI system x(t) =exp(β3t).u(t)y(t) = [exp(βt)β exp(β2t)].u(t)
1 // Example9 . 2 5 : LTI Systems C h a r a c t e r i z e d by L i n e a rConstant
2 // C o e f f i c i e n t d i f f e r e n t i a l Equat ion3 // F ind ing T r a n s f e r f u n c t i o n H( S ) o f LTI system4 //x ( t ) = exp(β3 t ) . u ( t )5 //y ( t ) = [ exp(β t )βexp(β2 t ) ] . u ( t )6 syms t s;
7 X = laplace( β%eΛ(β3β t ) β ,t,s);8 Y = laplace( β%eΛ(β t )β%eΛ(β2β t ) β ,t,s);9 H = Y/X;
10 disp(H)
11 // R e s u l t12 // ( s +3) β ( 1 / ( s +1)β1/( s +2) )
Example 9.31 Causal LTI Systems described by differential equations andRational System functions Partial Fraction H(S) = ((sβ1)/((s+1)β(sβ2)))
1 // Example9 . 3 1 : Causa l LTI Systems d e s c r i b e d byd i f f e r e n t i a l e q u a t i o n s
2 // and R a t i o n a l System f u n c t i o n s3 // P a r t i a l F r a c t i o n4 //H( S ) = ( ( sβ1) / ( ( s +1) β ( sβ2) ) )5 s =%s ;
6 syms t ;
7 [A] = pfss ((2*s^2+4*s-6)/(s^2+3*s+2));
8 disp(A,βH( S )=β)9 // R e s u l t H( S )=10 // // β 811 // βββββ12 // 1 + s13 // 614 // βββββ15 // 2 + s16 //
1 // Example9 . 3 6 : U n i l a t e r a l Lap lace Transform2 //X( S ) = ( ( s Λ2)β3) /( s +2)3 s = %s;
4 syms t;
5 [X] = pfss (((s^2) -3)/(s+2));
6 disp(X)
Example 9.37 Unilateral Laplace Transform:Solving Differential EquationY (S) = alpha/(s(s + 1)(s + 2))
1 // Example9 . 3 7 : U n i l a t e r a l Lap lace Transform : S o l v i n gD i f f e r e n t i a l Equat ion
2 //Y( S ) = a lpha /( s ( s +1) ( s +2) )3 s = %s;
4 syms t;
5 alpha = 1; // Alpha v a l u e a s s i g n e d as some c o n s t a n tone
6 [A] = pfss(alpha/(s*(s+1)*(s+2)));
7 F1 = ilaplace(A(1),s,t)
8 F2 = ilaplace(A(2),s,t)
9 F3 = ilaplace(A(3),s,t)
10 F = F1+F2+F3
11 disp(F)
12 // r e s u l t13 // (β%eΛβt ) +((%eΛβ(2β t ) ) /2) +(1/2 )
Example 9.38 Unilateral Laplace Transform:Solving Differential EquationY (S) = [beta(s+3)/((s+1)(s+2))]+[gamma/((s+2)(s+2))]+[alpha/(s(s+1)(s + 2))]
169
1 // Example9 . 3 8 : U n i l a t e r a l Lap lace Transform : S o l v i n gD i f f e r e n t i a l Equat ion
2 //Y( S ) =[ beta ( s +3) / ( ( s +1) ( s +2) ) ] + [gamma / ( ( s +2) ( s +2) )] + [ a lpha /( s ( s +1) ( s +2) ) ]
3 s = %s;
4 syms t;
5 alpha = 2; // input c o n s t a n t6 beta_B = 3; // i n t i a l c o n d i t i o n7 gamma_v = -5; // i n i t i a l c o n d i t i o n8 Y1 = 1/s;
9 Y2 = 1/(s+1);
10 Y3 = 3/(s+2);
11 Y = Y1 -Y2+Y3;
12 disp(Y)
13 y = ilaplace(Y,s,t)
14 disp(y)
15 // r e s u l t16 // ( β%eΛ(β t ) ) +3β(%eΛ(β(2β t ) ) )+1
170
Chapter 10
The Z-Transform
10.1 Scilab Codes
Example 10.1 Ztransform of x[n] = (a)n.u[n]
1 // Example10 . 1 : Zt rans fo rm o f x [ n ] = ( a ) Λn . u [ n ]2 syms n z;
3 a = 0.5;
4 x =(a)^n
5 X = symsum(x*(z^(-n)),n,0,%inf)
6 disp(X,β ans=β)7 // R e s u l t8 // 1 .0β (2Λ( β%infβ1)β zΛ(β%infβ1)β1) / ( 1 / ( 2β z )β1)9 // E q u i v a l e n t to β1/(0 .5β ( z Λβ1)β1)
Example 10.2 Ztransform of x[n] = βan.u[βnβ 1]
1 // Example 1 0 . 2 : Z t r a n s f o r m o f x [ n ] = βaΛn . u[βnβ1]2 // a = 0 . 53 clear all;
4 close;
5 clc;
6 syms n z;
7 a = 0.5;
8 x= -(0.5)^(-n)
9 X=symsum(x*(z^(n)),n,1,%inf)
171
10 disp(X,β ans=β)11 // R e s u l t12 // β1 .0β (2Λ( %inf +1)β z Λ( %inf +1)β2βz ) /(2β zβ1)13 // E q u i v a l e n t to β1ββ2βz /(2β zβ1) = 1/(1β0.5β z Λβ1)
Example 10.3 Ztransform of x[n] = 7.(1/3)n.u[n]β 6.(1/2)n.u[n]
1 // Example 1 0 . 3 : Z t r a n s f o r m o f x [ n ] = 7 . ( 1 / 3 ) Λn . u [ n] β6 . ( 1 / 2 ) Λn . u [ n ]
2 syms n z;
3 x1 =(0.33) ^(n)
4 X1=symsum (7*x1*(z^(-n)),n,0,%inf)
5 x2 =(0.5) ^(n)
6 X2=symsum (6*x2*(z^(-n)),n,0,%inf)
7 X = X1 -X2
8 disp(X,β ans=β)9 // R e s u l t
10 // β6.0β(2Λ(β%infβ1)β zΛ(β%infβ1)β1) / ( 1 / ( 2β z )β1)11 // E q u i v a l e n t to β6ββ1/(0.5β zΛβ1 β1)12 //The Region o f Convergence i s | z |>1/2
Example 10.4 Z-transform of sine signal
1 // Example10 . 4 : Zβt r a n s f o r m o f s i n e s i g n a l2 syms n z;
3 Wo =%pi/4;
4 a = (0.33)^n;
5 x1=%e^(sqrt(-1)*Wo*n);
6 X1=symsum(a*x1*(z^(-n)),n,0,%inf)
7 x2=%e^(-sqrt(-1)*Wo*n)
8 X2=symsum(a*x2*(z^(-n)),n,0,%inf)
9 X =(1/(2* sqrt(-1)))*(X1-X2)
10 disp(X,β ans=β)
Example 10.5 Z-transform of Impulse Sequence
1 // Example10 . 5 : Zβt r a n s f o r m o f Impul se Sequence
172
2 syms n z;
3 X=symsum (1*(z^(-n)),n,0,0);
4 disp(X,β ans=β)5 // R e s u l t6 // 1
Example 10.6 Ztransform of x[n] = an, 0 < n < N β 1
1 // Example 1 0 . 6 : Z t r a n s f o r m o f x [ n ] = aΛn , 0 < n < Nβ1
2 syms n z;
3 a = 0.5;
4 N =6;
5 x=(a)^(n)
6 X=symsum(x*(z^(-n)),n,0,N)
7 disp(X,β ans=β)8 // R e s u l t9 // 0 . 5 / z +0.25/ z Λ2+0.125/ z Λ3+0.0625/ z Λ4+0.03125/ z
Λ5+0.015625/ z Λ6+1.0
Example 10.7 Ztransform of x[n] = bn.u[n] + bβn.u[βnβ 1]
1 // Example 1 0 . 7 : Z t r a n s f o r m o f x [ n ] = bΛn . u [ n]+bΛβn . u[βnβ1]
2 syms n z;
3 b = 0.5;
4 x1=(b)^(n)
5 x2=(b)^(-n)
6 X1=symsum(x1*(z^(-n)),n,0,%inf)
7 X2=symsum(x2*(z^(n)),n,1,%inf)
8 X = X1+X2;
9 disp(X,β ans=β)10 // R e s u l t11 // +1.0β(2Λ(β%infβ1)β zΛ(β%infβ1)β1) / ( 1 / ( 2β z )β1)12 // E q u i v a l e n t to β1/(0.5β zΛβ1 β 1)13 // Region o f Convergence | z |>0.5
Example 10.9 Inverse Z Transform :ROC |z| > 1/3
173
1 // Example10 . 9 : I n v e r s e Z Transform :ROC | z |>1/32 z = %z;
3 syms n z1;//To f i n d out I n v e r s e z t r a n s f o r m z mustbe l i n e a r z = z1
15 disp(h, β h [ n]= β )16 // // R e s u l t17 //h [ n]= ( 1 / 4 ) Λn +(2/3) Λn
Example 10.10 Inverse Z Transform :ROC 1/4 < |z| < 1/3
1 // Example10 . 1 0 : I n v e r s e Z Transform :ROC 1/4<| z |<1/32 z = %z;
3 syms n z1;//To f i n d out I n v e r s e z t r a n s f o r m z mustbe l i n e a r z = z1
4 X =z*(3*z -(5/6))/((z -(1/4))*(z -(1/3)))
5 X1 = denom(X);
6 zp = roots(X1);
7 X1 = z1*(3*z1 -(5/6))/((z1 -(1/4))*(z1 -(1/3)))
8 F1 = X1*(z1^(n-1))*(z1-zp(1));
9 F2 = X1*(z1^(n-1))*(z1-zp(2));
10 h1 = limit(F1 ,z1,zp(1));
11 disp(h1* β u ( n ) β , β h1 [ n]= β )12 h2 = limit(F2 ,z1,zp(2));
13 disp((h2)* β u(βnβ1) β , β h2 [ n]= β )14 disp((h1)* β u ( n ) β -(h2)* β u ( nβ1) β , β h [ n]= β )15 // // R e s u l t16 // h [ n]= u ( n ) /4Λnβ2βu ( nβ1) /3Λn
174
17 // E q u i v a l e n t to h [ n ] =(1/4) Λn . u [ n ] β2β (1/3) Λn . u[βnβ1]
Example 10.11 Inverse Z Transform :ROC |z| < 1/4
1 // Example10 . 1 1 : I n v e r s e Z Transform :ROC | z |<1/42 z = %z;
3 syms n z1;//To f i n d out I n v e r s e z t r a n s f o r m z mustbe l i n e a r z = z1
13 disp((h2)* β u(βnβ1) β , β h2 [ n]= β )14 disp(-(h1)* β u(βnβ1) β -(h2)* β u(βnβ1) β , β h [ n]= β )15 // // R e s u l t16 // h [ n]= βu(βnβ1) /4Λnβ2βu(βnβ1) /3Λn17 // E q u i v a l e n t to h [ n ] =β(1/4)Λn . u[βnβ1]β2β(1/3) Λn . u[β
nβ1]
Example 10.12 Inverse z tranform:For Finite duration discrete sequence
1 // Example10 . 1 2 : I n v e r s e z t ran fo rm : For F i n i t ed u r a t i o n d i s c r e t e s equence
2 syms z;
3 X = [4*z^2 0 2 3*z^-1];
4 n = -2:1;
5 for i = 1: length(X)
6 x(i) = X(i)*(z^n(i));
7 end
8 disp(x, β x [ n]= β )
Example 10.13 Inverse z tranform ofInFinite duration discrete sequencePower Series Method (OR) Long Division Method
175
1 // Example10 . 1 3 : I n v e r s e z t ran fo rm o f I n F i n i t ed u r a t i o n d i s c r e t e s equence
2 // Power S e r i e s Method (OR) // Long D i v i s i o n Method3 z = %z;
4 a = 2;
5 X = ldiv(z,z-a,5)
Example 10.18 Ztransform-Differentiation Property x[n] = (a)n.u[n]
1 // Example10 . 1 8 : Ztrans formβD i f f e r e n t i a t i o n Proper ty2 // x [ n ] = ( a ) Λn . u [ n ]3 syms n z;
4 a = 0.5;
5 x =(a)^n
6 X = symsum(x*(z^(-n)),n,0,%inf)
7 X1 = -1/((1/(2*z)) -1) // z t r a n s f o r m o f 0 . 5 Λ n . u [n ]
8 Y = -z*diff(X,z) // D i f f e r e n t i a t i o n p r o p e r t y o f zβt r a n s f o r m
9 disp(X,β ans=β)10 disp(Y,β ans=β)11 // R e s u l t12 //X( z ) = 1.0β (2Λ( β%infβ1)β zΛ(β%infβ1)β1) / ( 1 / ( 2β z )β1)13 //Y( z ) = β1.0β(β%infβ1)β2Λ(β%infβ1)β zΛ(β%infβ1)
/ ( 1 / ( 2β z )β1)14 //Y1( z ) = 1 / ( 2β ( 1 / ( 2β z )β1)Λ2β z )15 // E q u i v a l e n t to Y1( z ) = 0 . 5β z Λβ1/((1β0.5β z Λβ1) Λ2)
Example 10.19 Z Transform : Initial Value Theorem
1 // Example10 . 1 9 : Z Transform : I n i t i a l Value Theorem2 z = %z;
3 syms n z1;//To f i n d out I n v e r s e z t r a n s f o r m z mustbe l i n e a r z = z1
15 disp(x_initial , β x [ 0 ]= β )16 // // R e s u l t17 //x [ n]= 7/3Λnβ3β2Λ(1βn )18 //x [ 0 ]= 1 ; I n i t i a l Value
Example 10.23 Inverse Z Transform H(z) =z/z-a
1 // Example10 . 2 3 : I n v e r s e Z Transform H( z ) =z /zβa2 // z = %z ;3 syms n z;
4 a = 2;
5 H = z/(z-a);
6 F = H*z^(n-1)*(z-a);
7 h = limit(F,z,a);
8 disp(h, β h [ n]= β )
Example 10.25 LTi Systems characterized by Linear Constant CoefficientDifference equations Inverse Z Transform
1 // Example10 . 2 5 : LTi Systems c h a r a c t e r i z e d by L i n e a rConstant
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 s3 // I n v e r s e Z Transform4 // z = %z ;5 syms n z;
6 H1 = z/(z -(1/2));
7 H2 = (1/3)/(z -(1/2));
8 F1 = H1*z^(n-1)*(z -(1/2));
9 F2 = H2*z^(n-1)*(z -(1/2));
10 h1 = limit(F1 ,z,1/2);
11 disp(h1, β h1 [ n]= β )
177
12 h2 = limit(F2 ,z,1/2);
13 disp(h2, β h2 [ n]= β )14 h = h1+h2;
15 disp(h, β h [ n]= β )16 // R e s u l t17 //h [ n]= [ ( 1 / 2 ) Λn ]+[2Λ(1βn ) ] / 318 //Which i s E q u i v a l e n t to h [ n ] = [ (1/2 ) Λn ] + [ ( 1 / 2 ) Λ( n
β1) ] / 3
Example 10.33 Differentiation Property of Unilateral Ztransform x[n] =(a)(n + 1).u[n + 1]
1 // Example10 . 3 3 : D i f f e r e n t i a t i o n Proper ty o fU n i l a t e r a l Zt rans f o rm
2 // x [ n ] = ( a ) Λ( n+1) . u [ n+1]3 syms n z;
4 a = 0.5;
5 x =(a)^(n+1)
6 X = symsum(x*(z^(-n)),n,-1,%inf)
7 disp(X,β ans=β)8 // R e s u l t9 //X( z )= 0.5β (2Λ( β%infβ1)β zΛ(β%infβ1)β2βz ) / ( 1 / ( 2β z )
β1)10 // E q u i v a l e n t to z /(1β0.5β z Λβ1)
28 //sum o f the s e , g i v e s the o r i g i n a l v a l u e29 // 230 // β 0 . 8 3 33 3 3 3 z + 3 z31 // βββββββββββββββββββββββββ32 // 233 // 0 . 0 8 3 3 3 33 β 0 . 5 83 3 3 3 3 z + z
Example 10.36 Output response of an LTI System
1 // Example 1 0 . 3 6 : To f i n d output r e s p o n s e o f an LTISystem
2 syms n z;
3 H = z/(z+3)
4 X = z/(z-1)
5 Y = X*H
6 F1 = Y*(z^(n-1))*(z-1);
7 y1 = limit(F1 ,z,1);
8 F2 = Y*(z^(n-1))*(z+3);
179
9 y2 = limit(F2 ,z,-3);
10 disp(y1*βu ( n ) β+y2*βu ( n ) β, β y [ n]= β )11 // R e s u l t12 //y [ n ] = u ( n ) /4β(β3) Λ( n+1)βu ( n ) /413 // E q u i v a l e n t to = ( 1 / 4 ) . u [ n ]β (3/4) (β3) Λn . u [ n ]
Example 10.37 Output response of an LTI System
1 // Example 1 0 . 3 7 : To f i n d output r e s p o n s e o f an LTISystem
2 syms n z;
3 alpha = 8; // input c o n s t a n t4 beta_b = 1; // i n i t i a l c o n d i t i o n y [β1] = 15 Y1 = -((3* beta_b*z)/(z+3))
6 Y2 = (alpha*z^2/((z+3)*(z-1)))
7 F1 = Y1*(z^(n-1))*(z+3);
8 y1 = limit(F1 ,z,-3);
9 F2 = Y2*(z^(n-1))*(z+3);
10 y2 = limit(F2 ,z,-3);
11 F3 = Y2*(z^(n-1))*(z-1);
12 y3 = limit(F3 ,z,1);
13 disp((y1+y2+y3)* β u ( n ) β , β y [ n]= β )14 // R e s u l t15 //y [ n ] = (2β(β3) Λ( n+1) ) βu ( n )
180
Chapter 11
Linear Feedback Systems
11.1 Scilab Codes
Example 11.1 Root locus Analysis of Linear Feedback Systems ContinuousTime Systems
1 // Example11 . 1 : Root l o c u s A n a l y s i s o f L i n e a r FeedbackSystems
2 // Cont inuous Time Systems3 // Re f e r f i g u r e 1 1 . 1 2 ( a ) i n Openhiem &Wi l l k sy page
8404 s = %s;
5 H = syslin( β c β ,[1/(s+1)]);6 G = syslin( β c β ,[1/(s+2)]);7 F = G*H;
8 clf;
9 evans(F,3)
181
Figure 11.1: Results of Exa 11.1
Example 11.2 Root locus Analysis of Linear Feedback Systems ContinuousTime Systems
1 // Example11 . 2 : Root l o c u s A n a l y s i s o f L i n e a r FeedbackSystems
2 // Cont inuous Time Systems3 // Re f e r f i g u r e 1 1 . 1 4 ( a ) i n Openhiem &Wi l l k sy page
8444 s = %s;
5 G = syslin( β c β ,[(s-1)/((s+1)*(s+2))]);6 clf;
7 evans(G,2)
182
Figure 11.2: Results of Exa 11.2
Example 11.3 Root locus Analysis of Linear Feedback Systems Discretetime system
1 // Example11 . 3 : Root l o c u s A n a l y s i s o f L i n e a r FeedbackSystems
2 // // D i s c r e t e t ime system3 // Re f e r f i g u r e 1 1 . 1 6 ( a ) i n Openhiem &Wi l l k sy page
8464 z = %z;
183
5 G = syslin( β d β ,[z/((z-0.5) *(z -0.25))]);6 clf;
7 evans(G,2)
Figure 11.3: Results of Exa 11.3
Example 11.5Bode Nyquist criterion for Continuous Time Systems BodePlot
1 // Example 1 1 . 5 : Nyqu i s t c r i t e r i o n f o r Cont inuous TimeSystems
2 // Bode P lo t3 s = %s;
184
4 //Open Loop T r a n s f e r Funct ion5 G = syslin( β c β ,[1/(s+1)]);6 H = syslin( β c β ,[1/(0.5*s+1)]);7 F = G*H;
8 clf;
9 bode(F ,0.01 ,100)
10 show_margins(F)
Figure 11.4: Results of Exa 11.5Bode
Example 11.5Nyquist Nyquist criterion for Continuous Time Systems NyquistPlot
185
1 // Example 1 1 . 5 : Nyqu i s t c r i t e r i o n f o r Cont inuous TimeSystems
2 // Nyqui s t P lo t3 s = %s;
4 //Open Loop T r a n s f e r Funct ion5 G = syslin( β c β ,[1/(s+1)]);6 H = syslin( β c β ,[1/(0.5*s+1)]);7 F = G*H;
8 clf;
9 nyquist(F)
10 show_margins(F, β n y q u i s t β )
Figure 11.5: Results of Exa 11.5Nyquist
186
Example 11.6 Nyquist criterion for Continuous Time Systems Nyquist Plot
1 // Example 1 1 . 6 : Nyqu i s t c r i t e r i o n f o r Cont inuous TimeSystems
2 // Nyqui s t P lo t3 s = %s;
4 //Open Loop T r a n s f e r Funct ion5 F = syslin( β c β ,[(s+1)/((s-1) *(0.5*s+1))])6 clf;
7 nyquist(F)
8 show_margins(F, β n y q u i s t β )
Figure 11.6: Results of Exa 11.6
187
Example 11.7 Nyquist Plot
1 // Example 1 1 . 72 // Nyqui s t P lo t3 s = %s;
4 T =1;
5 //Open Loop T r a n s f e r Funct ion6 G = syslin( β c β ,[-%e^(-s*T)]);7 clf;
8 nyquist(G)
9 show_margins(G, β n y q u i s t β )
Example 11.8 Nyquist criterion for Discrete Time Systems Nyquist PlotDiscrete Time System
1 // Example 1 1 . 8 : Nyqu i s t c r i t e r i o n f o r D i s c r e t e TimeSystems
2 // Nyqui s t P lo t3 // D i s c r e t e Time System4 z = %z;
5 //Open Loop T r a n s f e r Funct ion6 F = syslin( β d β ,[1/(z*(z+0.5))])7 clf;
8 nyquist(F)
9 show_margins(F, β n y q u i s t β )
188
Figure 11.7: Results of Exa 11.8
Example 11.9 Gain and Phase Margins and their associated cross over fre-quencies
1 // Example 1 1 . 9 : Gain and Phase Margins and t h e i r2 // a s s o c i a t e d c r o s s ove r f r e q u e n c i e s3 s =poly(0, β s β ); // D e f i n e s s as po lynomia l v a r i a b l e4 // Create s t r a n s f e r f u n c t i o n i n fo rward path5 F = syslin( β c β ,[(4*(1+0.5*s))/(s*(1+2*s)*(1+0.05*s
+(0.125*s)^2))])
6 B = syslin( β c β ,(1+0*s)/(1+0*s))7 OL = F*B;
8 fmin = 0.01; // Min f r e q i n Hz
189
9 fmax = 10; // Max f r e q i n Hz10 scf (1);
11 // c l f ;12 // P lo t f r e q u e n c y r e s p o n s e o f open l oop t r a n s f e r
f u n c t i o n13 bode(OL ,0.01 ,10);
14 // d i s p l a y ga in and phase margin and c r o s s ove rf r e q u e n c i e s
15 show_margins(OL);
16 [gm ,fr1] = g_margin(OL)
17 [phm ,fr2] = p_margin(OL)
18 disp(gm, β g a i n margin i n dB β )19 disp(fr1 , β g a i n c r o s s ove r f r e q u e n c y i n Hz β )20 disp(phm , β phase margin i n dB β )21 disp(fr2 , β phase c r o s s ove r f r e q u e n c y i n Hz β )
190
Figure 11.8: Results of Exa 11.9
Example 11.91 // F igu r e11 . 9 : Root l o c u s a n a l y s i s o fL i n e a r f e e d b a c k sys t ems
2 s = %s;
3 beta_b1 = 1;
4 beta_b2 = -1;
5 G1 = syslin( β c β ,[2* beta_b1/s]);6 G2 = syslin( β c β ,[2* beta_b2/s]);7 H = syslin( β c β ,[s/(s-2)]);8 F1 = G1*H;