Scilab Companion for Signals & Systems
Scilab Companion for Signals & Systems
Created by
Satyam Agrawal
[Link]
Instrumentation Engineering
Krishna Institute Of Engineering and Technology
College Teacher
Varun Gupta
Cross-Checked by
Chaitanya
Author: P. R. Rao
Edition: 5
Year: 2011
ISBN: 978-0-07-066927-7
1
Scilab numbering policy used in this document and the relation to 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
7 Systems 112
3
List of Scilab Codes
4
Exa 2.39 Inverse Z Transform . . . . . . . . . . . . . 39
Exa 2.40 Inverse Z Transform . . . . . . . . . . . . . 39
Exa 3.13 Complex Fourier Exponential Series . . . . . 41
Exa 3.14 Complex Fourier Exponential Series . . . . . 47
Exa 3.16 Complex Fourier Exponential Series . . . . . 48
Exa 3.17 Complex Fourier Exponential Series . . . . . 52
Exa 3.18 Trignometric Series . . . . . . . . . . . . . . 53
Exa 4.1 Magnitude and Phase Spectra . . . . . . . . 54
Exa 4.2 Magnitude and Phase Spectra . . . . . . . . 58
Exa 4.3 Magnitude and Phase Spectra . . . . . . . . 63
Exa 4.4 Energy at output . . . . . . . . . . . . . . . 64
Exa 4.5 Fourier Transform . . . . . . . . . . . . . . 64
Exa 4.6 Convolution . . . . . . . . . . . . . . . . . . 67
Exa 4.7 Energy in Signal . . . . . . . . . . . . . . . 69
Exa 4.11 Fourier Transform . . . . . . . . . . . . . . 70
Exa 4.14 Fourier Transform . . . . . . . . . . . . . . 70
Exa 4.17 Fourier Transform . . . . . . . . . . . . . . 73
Exa 5.1 DTFT . . . . . . . . . . . . . . . . . . . . . 77
Exa 5.2 DTFT and Spectra . . . . . . . . . . . . . . 78
Exa 5.3 Inverse Fourier . . . . . . . . . . . . . . . . 81
Exa 5.4 Inverse Fourier . . . . . . . . . . . . . . . . 84
Exa 5.5 Fourier series . . . . . . . . . . . . . . . . . 87
Exa 5.9.i DTFT . . . . . . . . . . . . . . . . . . . . . 90
Exa [Link] DTFT . . . . . . . . . . . . . . . . . . . . . 91
Exa [Link] DTFT . . . . . . . . . . . . . . . . . . . . . 92
Exa 5.11 Inverse Fourier . . . . . . . . . . . . . . . . 93
Exa 5.13 Circular Convolution . . . . . . . . . . . . . 94
Exa 5.14 Circular Convolution . . . . . . . . . . . . . 96
Exa 5.16 DTFT . . . . . . . . . . . . . . . . . . . . . 97
Exa 5.18 DFT coefficients . . . . . . . . . . . . . . . 98
Exa 6.1 Sampling and Reconstruction . . . . . . . . 99
Exa 6.2 Sampling and Reconstruction . . . . . . . . 100
Exa 6.3 Minimum Number of samples . . . . . . . . 104
Exa 6.4 Minimum Sampling Frequency . . . . . . . . 107
Exa 6.5 LPF output . . . . . . . . . . . . . . . . . . 107
Exa 6.6 Sampling Frequency . . . . . . . . . . . . . 108
Exa 6.8 Minimum Sampling Frequency . . . . . . . . 111
Exa 7.1 Properties of System . . . . . . . . . . . . . 112
5
Exa 7.3 System Properties . . . . . . . . . . . . . . 113
Exa 7.4 System Properties . . . . . . . . . . . . . . 114
Exa 7.5 System Properties . . . . . . . . . . . . . . 115
Exa 7.6 System Properties . . . . . . . . . . . . . . 116
Exa 7.7 Properties of System . . . . . . . . . . . . . 117
Exa 7.8 Properties of System . . . . . . . . . . . . . 118
Exa 7.9 Properties of System . . . . . . . . . . . . . 119
Exa 7.10 Output of an LTI . . . . . . . . . . . . . . . 120
Exa 7.11 Convolution . . . . . . . . . . . . . . . . . . 120
Exa 7.14 Impulse and Step response . . . . . . . . . . 122
Exa 7.15 Impulse and Step Response . . . . . . . . . 124
Exa 7.19 Convolution . . . . . . . . . . . . . . . . . . 127
Exa 7.22 Convolution . . . . . . . . . . . . . . . . . . 130
Exa 7.23 Convolution . . . . . . . . . . . . . . . . . . 133
Exa 7.24 Step Response . . . . . . . . . . . . . . . . . 135
Exa 7.25 Step response . . . . . . . . . . . . . . . . . 136
Exa 7.33 Magnitude and Phase Response . . . . . . . 138
Exa 8.1 Magnitude and Phase Responses . . . . . . 142
Exa 8.2 Transfer Function of system . . . . . . . . . 145
Exa 8.3 Magnitude and Phase Responses . . . . . . 145
Exa 8.4 system response . . . . . . . . . . . . . . . . 148
Exa 8.5 System function . . . . . . . . . . . . . . . . 150
Exa 8.8 Transfer function . . . . . . . . . . . . . . . 152
Exa 8.9 Transfer function by block diagram reduction 154
Exa 8.10 Realization Structure . . . . . . . . . . . . . 154
Exa 8.12 Transfer function Realization . . . . . . . . 155
Exa 8.13 Parallel form realization . . . . . . . . . . . 156
Exa 9.1 Convolution . . . . . . . . . . . . . . . . . . 157
Exa 9.3 Convolution . . . . . . . . . . . . . . . . . . 159
Exa 9.4 Autocorrelation . . . . . . . . . . . . . . . . 160
Exa 9.5 Autocorrelation . . . . . . . . . . . . . . . . 164
Exa 9.6 Autocorrelation . . . . . . . . . . . . . . . . 165
Exa 9.7 Autocorrelation . . . . . . . . . . . . . . . . 167
Exa 9.10 Autocorrelation Function . . . . . . . . . . . 170
Exa 9.11 PSD . . . . . . . . . . . . . . . . . . . . . . 171
Exa 10.1 Cross Correlation . . . . . . . . . . . . . . . 173
Exa 10.2 Cross Correlation Sequence . . . . . . . . . 175
Exa 10.4 Auto Correlation . . . . . . . . . . . . . . . 177
6
Exa 10.5 Auto Correlation . . . . . . . . . . . . . . . 177
Exa 10.8 Auto Correlation . . . . . . . . . . . . . . . 179
Exa 10.11 System response . . . . . . . . . . . . . . . 182
Exa 11.1 Hilbert Transform . . . . . . . . . . . . . . 183
Exa 11.2 Hilbert Transform . . . . . . . . . . . . . . 186
Exa 11.3 Hilbert Transform . . . . . . . . . . . . . . 188
Exa 11.6 Hilbert Transform . . . . . . . . . . . . . . 191
7
Chapter 1
8
Figure 1.1: Finding Fundamental Period
9
Figure 1.2: Finding Fundamental Period
10
5 clc ;
6 clear ;
7 syms t ;
8 x =3* cos (0.4* %pi * t ) +2* sin (0.66* t ) ;
9 disp (x , ’ x ( t ) ’ ) ;
10 t =0:1/50:50;
11 x =3* cos (0.4* %pi * t ) +2* sin (0.66* t ) ;
12 t =0:1/50:50;
13 plot (t , x ) ;
14 title ( ’ x ( t ) ’ ) ;
15 xlabel ( ’ Time i n s e c o n d s ’ ) ;
16 disp ( ’ p l o t t e d t h e s i g n a l and shown t h a t i t i s not
p e r i o d i c and i s i n c r e a s i n g ’ ) ;
11
Figure 1.3: Periodicity
12
Figure 1.4: Periodicity and fundamental period
13
4 // x ( t )=c o s ( 7 ∗ t )+s i n ( 4 ∗ t )
5 clc ;
6 clear ;
7 syms t ;
8 x = sin (4* t ) + cos (7* t ) ;
9 disp (x , ’ x ( t ) ’ ) ;
10 t =0:1/12:12
11 x = sin (4* t ) + cos (7* t ) ;
12 t =0:1/12:12;
13 plot (t , x ) ;
14 title ( ’ x ( t ) ’ ) ;
15 xlabel ( ’ Time i n s e c o n d s ’ ) ;
16 disp ( ’ p l o t t e d t h e s i g n a l and shown t h a t i t is
p e r i o d i c with p e r i o d o f 2 p i ’ );
14
Figure 1.5: Fundamental Period
15
Figure 1.6: Fundamental Period
15 title ( ’ x ( t ) ’ ) ;
16 xlabel ( ’ Time i n s e c o n d s ’ ) ;
17 disp ( ’ p l o t t e d t h e s i g n a l and shown t h a t i t i s not
p e r i o d i c ’ );
16
not
4 clc ;
5 clear ;
6
7 n =0:1:10;
8 x ( n +1) =2* sin (0.8* %pi * n ) ;
9 a = gca () ;
10 a . x_location = ” o r i g i n ” ;
11 a . y_location = ” o r i g i n ” ;
12 n =0:1:10;
13 plot2d3 (n ,x ,9) ;
14 title ( ’ x ( n ) ’ ) ;
15 disp ( ’ p l o t i n g t h e s i g n a l and s h o w i n g t h a t i t is
p e r i o d i c with p e r i o d o f 5 ’ );
17
Figure 1.7: Fundamental Period
18
16 end
17 a = gca () ;
18 a . x_location = ” o r i g i n ” ;
19 a . y_location = ” o r i g i n ” ;
20 t = -10:0.1:10;
21 // P l o t o f Even S i g n a l
22 plot (t , y1 ) ;
23 title ( ’ y1 ( t ) ’ ) ;
24 xlabel ( ’ Time i n s e c o n d s ’ ) ;
25 n =1;
26 for t = -1:0.01:1;
27 // F u n c t i o n f o r Odd s i g n a l
28 y2 ( n ) =0.5*( exp ( - t ) * u ( t ) - exp ( t ) * u ( - t ) ) ;
29 n = n +1;
30 end
31 figure (1) ;
32 a = gca () ;
33 a . x_location = ” o r i g i n ” ;
34 a . y_location = ” o r i g i n ” ;
35 t = -1:0.01:1;
36 // P l o t o f Odd S i g n a l
37 plot (t , y2 )
38 disp ( ’ p l o t t e d t h e s i g n a l b o t h i n e v e n and odd f o r m s ’
);
39 title ( ’ y2 ( t ) ’ ) ;
40 xlabel ( ’ Time i n s e c o n d s ’ ) ;
19
Figure 1.8: Even and odd Components
20
Figure 1.9: Even and odd Components
21
2 //P . Ramakrishna Rao
3 // d i s p l a y i n g p l o t s f o r t h e g i v e n s i g n a l s
4 clear ;
5 clc ;
6 function [ y ]= u ( t )
7 if t >=0
8 y =1
9 else y =0
10 end
11 endfunction
12 for t = -3:1:3
13 y ( t +4) = abs ( t +3) * u ( t +3) - abs ( t +1) * u ( t +1) - abs (t -1) * u (t
-1) + abs (t -3) * u (t -3) ;
14 end
15 t = -3:1:3;
16 // f o r t h e main g i v e n s i g n a l
17 a = gca () ;
18 a . x_location = ” o r i g i n ” ;
19 a . y_location = ” o r i g i n ” ;
20 plot (t , y ) ;
21 title ( ’ Main S i g n a l ) ’ ) ;
22 dy =0* y ;
23 for i =1:6
24 dy ( i ) =( y ( i +1) -y ( i ) ) /1;
25 end
26 // f o r t h e d e r i v a t i v e o f t h e g i v e n s i g n a l
27 figure (1) ;
28 a = gca () ;
29 a . x_location = ” o r i g i n ” ;
30 a . y_location = ” o r i g i n ” ;
31 plot2d2 (t , dy ) ;
32 title ( ’ D e r i v a t i v e o f S i g n a l ’ ) ;
33 dy2 =0* dy ;
34 dy2 (1) = dy (1) -0;
35 for i =1:6
36 dy2 ( i +1) =( dy ( i +1) - dy ( i ) ) /1;
37 end
38 // f o r t h e i m p u l s e r e s p o n s e r e p r e s e n t a t i o n o r s e c o n d
22
Figure 1.10: Waveforms
derivative
39 figure (2) ;
40 a = gca () ;
41 a . x_location = ” o r i g i n ” ;
42 a . y_location = ” o r i g i n ” ;
43 plot2d3 (t , dy2 , -5) ;
44 title ( ’ I m p u l s e r e s p o n s e r e p r e s e n t a t i o n ’ ) ;
23
Figure 1.11: Waveforms
24
1 // S c i l a b Code f o r Example 1 . 1 2 o f S i g n a l s and
s y s t e m s by
2 //P . Ramakrishna Rao
3 clc ;
4 clear ;
5 x = -2:1:3;
6 y =[ -1.5 ,2 ,2 ,1 , -1.5 ,2.5];
7 // P l o t o f x ( n )
8 plot2d3 (x ,y ,5) ;
9 xtitle ( ’ Time S c a l i n g x ( n ) ’ ) ;
10 a = gca () ; // g e t t h e c u r r e n t a x e s
11 a . x_location = ” o r i g i n ” ;
12 a . y_location = ” o r i g i n ” ;
13 x = -2:1:3;
14 y =[0 , -1.5 ,2 , -1.5 ,0 ,0];
15 figure (1) ;
16 // P l o t o f x ( 2 n )
17 plot2d3 (x ,y ,5) ;
18 a = gca () ; // g e t t h e c u r r e n t a x e s
19 a . x_location = ” o r i g i n ” ;
20 a . y_location = ” o r i g i n ” ;
21 xtitle ( ’ Time S c a l i n g x ( 2 n ) ’ ) ;
25
Figure 1.12: Time Scaling
26
Figure 1.13: Time Scaling
27
Figure 1.14: Plot at a particular sampling frequency
6 clc
7 A =10;
8 t =0:1/1000:1;
9 x = A * sin (2* %pi *100* t ) ;
10 q = plot2d3 (t , x ) ;
11 disp ( ’ d i s p l a y i n g a f u n c t i o n p l o t on d i s c r e t e t i m e
s c a l e t h a t has a sampling f r e q u e n c y o f 1000
samples ps ’ );
28
Chapter 2
29
2 //P . Ramakrishna Rao
3 // I n v e r s e L a p l a c e T r a n s f o r m
4 clc ;
5 clear ;
6 syms t s
7 X =( s +2) /( s ^2+8* s +25)
8 f4 = ilaplace ( X ) ;
9 disp ( f4 * ’ u ( t ) ’ ,” x ( t )=” ) ;
10 // t >=0
30
Scilab code Exa 2.4 Laplace Transform
31
1 // S c i l a b Code f o r Example 2 . 7 o f S i g n a l s and s y s t e m s
by
2 //P . Ramakrishna Rao
3 // U n i l a t e r a l L a p l a c e T r a n s f o r m u s i n g p a r t i a l
fraction
4 clear ;
5 clc ;
6 syms t s ;
7 s = %s ;
8 a1 = pfss (( s +3) /( s ^2+3* s +2) )
9 f1 = ilaplace ( a1 (1) )
10 f2 = ilaplace ( a1 (2) )
11 fy = f1 + f2
12 disp ( fy * ’ u ( t ) ’ ,” i ) f ( t )=” )
13 a2 = pfss ((2* s -1) /( s ^2+2* s +1) )
14 a2 (1) =2/( s +1)
15 a2 (2) = -3/( s +1) ^2
16 f1 = ilaplace ( a2 (1) )
17 f2 = ilaplace ( a2 (2) )
18 fz = f1 + f2
19 disp ( fz * ’ u ( t ) ’ ,” i i ) f ( t )=” )
32
Scilab code Exa 2.9 Circuit Current
33
Figure 2.1: Laplace Transform
34
8 disp (y , ”X( s )=” ) ;
9 disp ( ”Re ( s )>−3” ) ;
10 y =5/( s +3) ;
11 plzr ( y ) ;
35
Figure 2.2: Laplace Transform
36
Figure 2.3: Laplace Transform
37
Figure 2.4: Laplace Transform
6 s = %s ;
7 y = laplace ( exp ( - t ) - exp (2* t ) ,t , s ) ;
8 disp (y , ”X( s )=” ) ;
9 y =(1/( s +1) ) -(1/( s -2) ) ;
10 plzr ( y ) ;
38
3 //Z− t r a n s f o r m o f a ˆn u ( n )
4 clear ;
5 clc ;
6 close ;
7 syms a n z ;
8 x1 =1/2;
9 x2 =1/3;
10 X1 = symsum ( x1 *( z ^( - n ) ) ,n ,0 , %inf ) ;
11 X2 = symsum ( x2 *( z ^( - n ) ) ,n ,0 , %inf ) ;
12 X = X1 + X2 ;
13 // D i s p l a y t h e r e s u l t
14 disp (X , ”Z−t r a n s f o r m o f u ( n ) i s : ” ) ;
15 disp ( ’ROC i s t h e R e g i o n | z |> 1/2 ’ ) ;
39
1 // S c i l a b Code f o r Example 2 . 3 7 o f S i g n a l s and
s y s t e m s by
2 //P . Ramakrishna Rao
3 // I n v e r s e Z T r a n s f o r m :ROC 1 <| z | <2
4 clear ;
5 clc ;
6 z = %z ;
7 syms n z1 ;
8 //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
= z1
9 X =( z *( z ^2 - z +1) ) /(( z -0.5) *( z -2) *( z -1) )
10 X1 = denom ( X ) ;
11 zp = roots ( X1 ) ;
12 X1 = ( z1 *( z1 ^2 - z1 +1) ) /(( z1 -0.5) *( z1 -2) *( z1 -1) )
13 F1 = X1 *( z1 ^( n -1) ) *( z1 - zp (1) )
14 F2 = X1 *( z1 ^( n -1) ) *( z1 - zp (2) )
15 F3 = X1 *( z1 ^( n -1) ) *( z1 - zp (3) )
16 h1 = limit ( F1 , z1 , zp (1) ) ;
17 disp ( h1 * ’ u(−n −1) ’ , ’ h1 [ n ]= ’ )
18 h2 = limit ( F2 , z1 , zp (2) ) ;
19 disp (( h2 ) * ’ u ( n ) ’ , ’ h2 [ n ]= ’ )
20 h3 = limit ( F3 , z1 , zp (3) ) ;
21 disp (( h3 ) * ’ u ( n ) ’ , ’ h3 [ n ]= ’ )
22 disp (( h3 ) * ’ u ( n ) ’ +( h2 ) * ’ u ( n ) ’ -( h1 ) * ’ u(−n −1) ’ , ’ h [ n ]= ’ )
23 // // R e s u l t
24 // h [ n ]=1∗ 0 . 5 ˆ n ∗u ( n ) − 2∗ u ( n ) − 2∗ 2ˆ n ∗u(− n −
1)
40
5 clc ;
6 z = %z ;
7 syms n z1 ;
8 //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
= z1
9 X = z ^2/( z ^2+3* z +2) ;
10 X1 = denom ( X ) ;
11 zp = roots ( X1 )
12 X1 = z1 ^2/( z1 ^2+3* z1 +2) ;
13 F1 = X1 *( z1 ^( n -1) ) *( z1 - zp (1) ) ;
14 F2 = X1 *( z1 ^( n -1) ) *( z1 - zp (2) ) ;
15 h1 = limit ( F1 , z1 , zp (1) ) ;
16 disp ( h1 * ’ u ( n ) ’ , ’ h1 [ n ]= ’ )
17 h2 = limit ( F2 , z1 , zp (2) ) ;
18 disp (( h2 ) * ’ u ( n ) ’ , ’ h2 [ n ]= ’ ) ;
19 disp (( h1 ) * ’ u ( n ) ’ +( h2 ) * ’ u ( n ) ’ , ’ h [ n ]= ’ ) ;
20 // // R e s u l t
21 // h [ n ]= (2( − 2 ) ˆ n+1 − (− 1 ) ˆ n ) ∗u ( n )
41
13 F1 = X1 *( z1 ^( n ) ) *( z1 - zp (1) ) ;
14 h1 = limit ( F1 , z1 , zp (1) )
15 disp ( -( h1 ) * ’ u(−n −1) ’ , ’ h [ n ]= ’ ) ;
16 // // R e s u l t
17 // h [ n ]= (− (− 4 ) ˆ n ) ∗u(−n −1)
42
3 // I n v e r s e Z T r a n s f o r m :ROC | z | >2
4 clear ;
5 clc ;
6 z = %z ;
7 syms n z1 ;
8 //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
= z1
9 X = z ^2/(( z -0.5) *( z -1) ) ;
10 X1 = denom ( X ) ;
11 zp = roots ( X1 )
12 X1 = z1 ^2/(( z1 -0.5) *( z1 -1) ) ;
13 F1 = X1 *( z1 ^( n -1) ) *( z1 - zp (1) ) ;
14 F2 = X1 *( z1 ^( n -1) ) *( z1 - zp (2) ) ;
15 h1 = limit ( F1 , z1 , zp (1) ) ;
16 disp ( h1 * ’ u ( n ) ’ , ’ h1 [ n ]= ’ )
17 h2 = limit ( F2 , z1 , zp (2) ) ;
18 disp (( h2 ) * ’ u ( n ) ’ , ’ h2 [ n ]= ’ ) ;
19 disp ( -( h1 ) * ’ u(−n −1) ’ -( h2 ) * ’ u(−n −1) ’ , ’ h [ n ]= ’ ) ;
20 // // R e s u l t
21 // h [ n ]= ( ( 0 . 5 ) ˆ n − 2 ) ∗u(−n −1)
43
Chapter 3
44
Figure 3.1: Complex Fourier Exponential Series
45
Figure 3.2: Complex Fourier Exponential Series
46
15 x =[ x - ones (1 , length ( t_temp ) ) * %pi ];
16 else
17 x =[ x ones (1 , length ( t_temp ) ) * %pi ];
18 end
19 end
20 figure (1) ;
21 title ( ’ S i g n a l ’ ) ;
22 ylabel ( ’ x ( t ) ’ ) ;
23 xlabel ( ’ t ’ ) ;
24 plot (t ,x , ’ r ’ )
25 w0 = %pi /2;
26 for k = -10:10
27 cc ( k +11 ,:) = exp ( - %i * k * w0 * t ) ;
28 ck ( k +11) = x * cc ( k +11 ,:) ’/ length ( t ) ;
29 if abs ( ck ( k +11) ) <0.01 then
30 ck ( k +11) =0;
31 else if real ( ck ( k +11) ) <0.1 then
32 ck ( k +11) = %i * imag ( ck ( k +11) ) ;
33 end
34 end
35 if k ==0 then
36 c0 = ck ( k +11) ;
37 end
38 end
39 q = abs ( ck ) ;
40 figure (2) ;
41 title ( ’ Magnitude Spectrum ’ ) ;
42 ylabel ( ’ | cn | ’ ) ;
43 xlabel ( ’ f o ’ ) ;
44 f = -10:1:10;
45 plot2d3 (f , q )
47
Figure 3.3: Complex Fourier Exponential Series
48
Figure 3.4: Complex Fourier Exponential Series
49
Scilab code Exa 3.14 Complex Fourier Exponential Series
50
Figure 3.5: Complex Fourier Exponential Series
36 c = gca () ;
37 c . y_location = ” o r i g i n ” ;
38 c . x_location = ” o r i g i n ” ;
39 plot2d3 ( ’ gnn ’ ,k , abs ( ck ) ,9)
40 poly1 = c . children (1) . children (1) ;
41 poly1 . thickness = 3;
42 title ( ’ | ck | ’ )
43 xlabel ( ’ k ’ )
51
1 // S c i l a b Code f o r Example 3 . 1 6 o f S i g n a l s and
s y s t e m s by
2 //P . Ramakrishna Rao
3 //A=%pi o r 3 . 1 4
4 clear ;
5 clc ;
6 // T r i g n o m e t r i c F o u r i e r C o e f f i c i e n t s
7 for n =0:5
8 a ( n +1) = integrate ( ’ t ∗ c o s ( 2 ∗ %pi ∗n∗ t ) ’ , ’ t ’ ,0 ,1) ;
9 end
10 for n =0:5
11 b ( n +1) = integrate ( ’ t ∗ s i n ( 2 ∗ %pi ∗n∗ t ) ’ , ’ t ’ ,0 ,1) ;
12 end
13 disp ( %pi * a (1) ,” an ( a0 ) ” )
14 disp ( ” an ( a1−−>a5 ) ” )
15 for n =1:5
16 disp (2* a ( n +1) * %pi )
17 end
18 disp ( ” bn ( b1−−>b5 ) ” )
19 for n =1:5
20 disp (2* %pi * b ( n +1) )
21 end
22 //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 l
23 // x ( t ) =t
24 t = 0:0.01:1;
25 xt =2* %pi * t ;
26 //
27 for k =0:6
28 C ( k +1 ,:) = exp ( - sqrt ( -1) *2* %pi * t * k ) ;
29 c ( k +1) = xt * C ( k +1 ,:) ’/ length ( t ) ;
30 if ( abs ( c ( k +1) ) <=0.01)
31 c ( k +1) =0;
32 end
33 end
34 c =c ’;
35 c_conj = real ( c (:) ) - sqrt ( -1) * imag ( c (:) ) ;
36 ck = [ c_conj ( $ : -1:1) ’,c (2: $ ) ];
37 k = 0:6;
52
Figure 3.6: Complex Fourier Exponential Series
38 k = [ - k ( $ : -1:1) ,k (2: $ ) ];
39 c = gca () ;
40 c . y_location = ” o r i g i n ” ;
41 c . x_location = ” o r i g i n ” ;
42 plot2d3 ( ’ gnn ’ ,k , abs ( ck ) )
43 poly1 = c . children (1) . children (1) ;
44 poly1 . thickness = 3;
45 title ( ’ | ck | ’ )
46 xlabel ( ’ k ’ )
53
Figure 3.7: Complex Fourier Exponential Series
54
Scilab code Exa 3.17 Complex Fourier Exponential Series
55
36 figure (1) ;
37 c = gca () ;
38 c . y_location = ” o r i g i n ” ;
39 c . x_location = ” o r i g i n ” ;
40 plot2d3 ( ’ gnn ’ ,k , abs ( ck ) )
41 poly1 = c . children (1) . children (1) ;
42 poly1 . thickness = 3;
43 title ( ’ | ck | ’ )
44 xlabel ( ’ k ’ )
56
Chapter 4
57
Figure 4.1: Magnitude and Phase Spectra
58
Figure 4.2: Magnitude and Phase Spectra
59
15 end
16 end
17 Wmax = 2* %pi *1; // Analog F r e q u e n c y = 1Hz
18 K = 4;
19 k = 0:( K /1000) : K ;
20 W = k * Wmax / K ;
21 xt = xt ’;
22 XW = xt * exp ( - sqrt ( -1) *t ’* W ) * Dt ;
23 XW_Mag = real ( XW ) ;
24 W = [ - mtlb_fliplr ( W ) , W (2:1001) ]; // Omega from −
Wmax t o Wmax
25 XW_Mag = [ mtlb_fliplr ( XW_Mag ) , XW_Mag (2:1001) ];
26 [ XW_Phase , db ] = phasemag ( XW ) ;
27 XW_Phase =[ - mtlb_fliplr ( XW_Phase ) , XW_Phase (2:1001) ];
28 // P l o t t i n g t h e F u n c t i o n
29 subplot (2 ,1 ,1) ;
30 a = gca () ;
31 a . data_bounds =[ -4 ,0;4 ,2];
32 a . y_location = ” o r i g i n ” ;
33 plot (t , xt ) ;
34 xlabel ( ’ t i n s e c . ’ ) ;
35 title ( ’ C o n t i n o u s Time S i g n a l x ( t ) ’ ) ;
36 // P l o t t i n g Magnitude Reponse o f CTS
37 subplot (2 ,1 ,2) ;
38 a = gca () ;
39 a . y_location = ” o r i g i n ” ;
40 plot ( W /(2* %pi ) , XW_Mag ) ;
41 xlabel ( ’ F r e q u e n c y i n Hz ’ ) ;
42 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 X(jW) ’ ) ;
43 // P l o t t i n g Phase Reponse o f CTS
44 figure (1) ;
45 a = gca () ;
46 a . y_location = ” o r i g i n ” ;
47 a . x_location = ” o r i g i n ” ;
48 plot ( W /(2* %pi ) ,- XW_Phase * %pi /180) ;
49 xlabel ( ’ F r e q u e n c y i n Hz ’ ) ;
50 ylabel ( ’<X(jW) ’ )
51 title ( ’ Phase R e s p o n s e (CTFT) i n R a d i a n s ’ )
60
Figure 4.3: Magnitude and Phase Spectra
61
Figure 4.4: Magnitude and Phase Spectra
62
6 clc ;
7 close ;
8 // Analog S i g n a l
9 A =1; // A m p l i t u d e
10 T =1;
11 Dt = 0.005;
12 t = 0: Dt :10;
13 xt = A * exp ( - t / T ) ;
14 // 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
15 Wmax = 2* %pi *1; // Analog F r e q u e n c y = 1Hz
16 K = 4;
17 k = 0:( K /1000) : K ;
18 W = k * Wmax / K ;
19 XW = xt * exp ( - sqrt ( -1) *t ’* W ) * Dt ;
20 XW_Mag = abs ( XW ) ;
21 W = [ - mtlb_fliplr ( W ) , W (2:1001) ]; // Omega from −
Wmax t o Wmax
22 XW_Mag = [ mtlb_fliplr ( XW_Mag ) , XW_Mag (2:1001) ];
23 [ XW_Phase , db ] = phasemag ( XW ) ;
24 XW_Phase = [ - mtlb_fliplr ( XW_Phase ) , XW_Phase (2:1001)
];
25 // P l o t t i n g C o n t i n u o u s Time S i g n a l
26 a = gca () ;
27 a . y_location = ” o r i g i n ” ;
28 plot (t , xt ) ;
29 xlabel ( ’ t i n s e c . ’ ) ;
30 ylabel ( ’ x ( t ) ’ )
31 title ( ’ C o n t i n u o u s Time S i g n a l ’ )
32 figure
33 // P l o t t i n g Magnitude R e s p o n s e o f CTS
34 subplot (2 ,1 ,1) ;
35 a = gca () ;
36 a . y_location = ” o r i g i n ” ;
37 plot (W , XW_Mag ) ;
38 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’ ) ;
39 ylabel ( ’ a b s (X(jW) ) ’ )
40 title ( ’ Magnitude R e s p o n s e (CTFT) ’ )
41 // P l o t t i n g Phase Reponse o f CTS
63
Figure 4.5: Magnitude and Phase Spectra
42 subplot (2 ,1 ,2) ;
43 a = gca () ;
44 a . y_location = ” o r i g i n ” ;
45 a . x_location = ” o r i g i n ” ;
46 plot (W , XW_Phase * %pi /180) ;
47 xlabel ( ’ Frequency in
R a d i a n s / S e c o n d s −−−> W’ ) ;
48 ylabel ( ’
<X
(jW) ’ )
49 title ( ’ Phase R e s p o n s e (CTFT) i n R a d i a n s ’ )
64
Figure 4.6: Magnitude and Phase Spectra
65
Scilab code Exa 4.3 Magnitude and Phase Spectra
66
31 xlabel ( ’ F r e q u e n c y i n Hz ’ ) ;
32 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 X(jW) ’ ) ;
67
Figure 4.7: Fourier Transform
68
Figure 4.8: Fourier Transform
69
3 // x ( t )=c o s p i ∗ t , | t | > 0 . 5 , z e r o o t h e r w i s e
4 clear ;
5 clc ;
6 // F o u r i e r T r a n s f o r m
7 for f = -20:1:20;
8 X ( f +21) = integrate ( ’ c o s ( %pi ∗ t ) ∗ c o s ( 2 ∗ %pi ∗ f ∗ t ) ’ , ’ t ’
, -0.5 ,0.5) ;
9 end
10 disp (X , ’X( 0 )−−>X( 2 0 ) ’ ) ;
11 t = -0.5:0.01:0.5;
12 q = cos ( %pi * t ) ;
13 a = gca () ;
14 a . y_location = ” o r i g i n ” ;
15 a . x_location = ” o r i g i n ” ;
16 plot (t , q ) ;
17 xlabel ( ’ Time i n S e c o n d s ’ ) ;
18 title ( ’ S i g n a l x ( t ) ’ ) ;
19 figure (1) ;
20 a = gca () ;
21 a . y_location = ” o r i g i n ” ;
22 a . x_location = ” o r i g i n ” ;
23 f = -20:1:20;
24 plot (f , X ) ;
25 xlabel ( ’ F r e q u e n c y i n Hz ’ ) ;
26 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 X(jW) ’ ) ;
70
Figure 4.9: Convolution
71
5 close ;
6 disp ( ”X(w) =1/( a+jw ) ˆ2=1/( a+jw ) ∗ 1 / ( a+jw ) ” ) ;
7 disp ( ” exp (−a ∗ t ) ∗u ( t ) <−−> 1 / ( a+jw ) ” ) ;
8 disp ( ” t h e r e f o r e x ( t )=c o n v o l u t i o n ( 2 ∗ s i n c ( 2 ∗ t ) , ( s i n c t
) ˆ2 ” ) ;
9 a =2;
10 n =1;
11 for t = -10:0.1:10
12 y1 (1 , n ) =( sinc ( t ) ) ^2;
13 y2 (1 , n ) =2* sinc (2* t ) ;
14 n = n +1;
15 z = conv ( y1 , y2 ) ;
16 end
17 t = -20:0.1:20;
18 a = gca () ;
19 a . y_location = ” o r i g i n ” ;
20 a . x_location = ” o r i g i n ” ;
21 plot (t , z ) ;
22 title ( ’ C o n v o l u t i o n o f x ( t ) and y ( t ) ’ )
72
Scilab code Exa 4.11 Fourier Transform
73
Figure 4.10: Fourier Transform
74
Figure 4.11: Fourier Transform
75
10 disp ( ” G u a s s i a n p u l s e s i g n a l x ( t ) =(1/ s q r t ( 2 ) ∗ %pi ) ∗ exp
(−a ∗ t ˆ 2 ) ” ) ;
11 disp ( ”X(w)= i n t e g r a l ( exp (−a ∗ t ˆ 2 ) ∗ exp (−%i ∗w∗ t ) ) w . r . t
dt ”);
12 disp ( ” d (X(w) ) /dw=−%i ∗w/ ( 2 ∗ a ) ∗ i n t e g r a l ( exp (−a ∗ t ˆ 2 ) ∗
exp (−%i ∗w∗ t ) ) ” ) ;
13 disp ( ” d (X(w) ) /dw=−w∗X(w) /2 a ” ) ;
14 disp ( ” s o l v i n g t h i s we g e t X(w)=A∗ exp (−wˆ 2 / 4 a ) ” )
15 disp ( ”A=s q r t ( %pi / a ) ” ) ;
16 d = gca ()
17 plot (t , x ) ;
18 poly1 = d . children . children ;
19 poly1 . thickness =3;
20 poly1 . foreground =2;
21 xtitle ( ’ x ( t ) ’ , ’ t ’ )
22 A =1;
23 f=t;
24 Xf = A * exp ( -2* %pi ^2* f ^2) ;
25 figure (1) ;
26 d = gca ()
27 plot (f , Xf ) ;
28 poly1 = d . children . children ;
29 poly1 . thickness =3;
30 poly1 . foreground =2;
31 xtitle ( ’X( f ) ’ , ’ f ’ )
76
Figure 4.12: Fourier Transform
77
Figure 4.13: Fourier Transform
78
3 clear ;
4 clc ;
5 // F o u r i e r T r a n s f o r m o f x ( t )
6 n =1;
7 for t = -10:0.1:10;
8 x (1 , n ) =1/(1+ t ^2) ;
9 n = n +1;
10 end
11 a = gca () ;
12 a . y_location = ” o r i g i n ” ;
13 a . x_location = ” o r i g i n ” ;
14 t = -10:0.1:10;
15 plot (t , x ) ;
16 xlabel ( ’ Time i n S e c o n d ’ ) ;
17 title ( ’ x ( t ) ’ ) ;
18 disp ( ”By D u a l i t y Theorem F o u r i e r T r a n s f o r m o f x ( t )
i s : ”);
19 disp ( ” %pi ∗ exp ( −|w | ) ” ) ;
20 n =1;
21 for w = -10:0.1:10;
22 X (1 , n ) = %pi * exp ( - abs ( w ) ) ;
23 n = n +1;
24 end
25 figure (1) ;
26 a = gca () ;
27 a . y_location = ” o r i g i n ” ;
28 a . x_location = ” o r i g i n ” ;
29 w = -10:0.1:10;
30 plot (w , X ) ;
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 ’ ) ;
32 title ( ’X(w) ’ ) ;
79
Chapter 5
Fourier Representation of
Discrete Time Signals
80
19 XW_Mag = real ( XW ) ;
20 W = [ - mtlb_fliplr ( W ) , W (2:1001) ]; // Omega from −
Wmax t o Wmax
21 XW_Mag = [ mtlb_fliplr ( XW_Mag ) , XW_Mag (2:1001) ];
22 a = gca () ;
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 S e q u e n c e x [ n ] f o r a>0 ’ )
27 figure (1) ;
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 T r a n s f o r m X( exp (jW) ) ’ )
81
Figure 5.1: DTFT
82
Figure 5.2: DTFT
83
13 Wmax = 2* %pi ;
14 K = 4;
15 k = 0:( K /1000) : K ;
16 W = k * Wmax / K ;
17 XW = x * exp ( - sqrt ( -1) *n ’* W ) ;
18 XW_Mag = real ( XW ) ;
19 [ XW_Phase , db ] = phasemag ( XW ) ;
20 W = [ - mtlb_fliplr ( W ) , W (2:1001) ]; // Omega from −
Wmax t o Wmax
21 XW_Mag = [ mtlb_fliplr ( XW_Mag ) , XW_Mag (2:1001) ];
22 XW_Phase = [ - mtlb_fliplr ( XW_Phase ) , XW_Phase (2:1001)
];
23 a = gca () ;
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 S e q u e n c e x [ n ] ’ )
28 figure (1) ;
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 , abs ( XW_Mag ) ) ;
33 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) ) ’ )
34 figure (2) ;
35 a = gca () ;
36 a . y_location = ” o r i g i n ” ;
37 a . x_location = ” o r i g i n ” ;
38 plot2d (W , XW_Phase ) ;
39 title ( ’ Phase R e s p o n s e <(X(jW) ) ’ )
84
Figure 5.3: DTFT and Spectra
85
Figure 5.4: DTFT and Spectra
86
1 // S c i l a b Code f o r Example 5 . 3 o f S i g n a l s and s y s t e m s
by
2 //P . Ramakrishna Rao
3 clear ;
4 clc ;
5 // I n v e r s e F o u r i e r T r a n s f o r m
6 w = -20:20;
7 X =4*( cos ( w ) ) ^2;
8 a = gca () ;
9 a . y_location = ” o r i g i n ” ;
10 a . x_location = ” o r i g i n ” ;
11 plot (w , X ) ;
12 title ( ”X( e ˆ jw ) ” ) ;
13 xlabel ( ” F r e q u e n c y i n R a d i a n s / s e c ” ) ;
14 figure (1) ;
15 n = -50:50;
16 x =2* sinc ( n ) + sinc ( n +2) + sinc (n -2) ;
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 (n , x ) ;
21 title ( ” x ( n ) ” ) ;
22 xlabel ( ” Time i n s e c ” ) ;
87
Figure 5.5: Inverse Fourier
88
Figure 5.6: Inverse Fourier
89
5 clear ;
6 clc ;
7 close ;
8 N = 1;
9 N1 = -3* N :3* N ;
10 xn = [ zeros (1 ,N -1) ,1];
11 x = [1 xn xn xn xn xn xn ];
12 ak = 1/ N ;
13 XW = 2* %pi * ak * ones (1 ,2* N ) ;
14 Wo = 2* %pi / N ;
15 n = -N :N -1;
16 W = Wo * n ;
17 a = gca () ;
18 a . y_location = ” m i d d l e ” ;
19 a . x_location = ” o r i g i n ” ;
20 plot2d3 ( ’ gnn ’ ,W , XW ,2) ;
21 poly1 = a . children (1) . children (1) ;
22 poly1 . thickness = 3;
23 xlabel ( ’W’ ) ;
24 title ( ’DTFT o f P e r i o d i c I m p u l s e T r a i n ’ )
25 figure (1) ;
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 ’ ,N1 ,x ,2) ;
30 poly1 = a . children (1) . children (1) ;
31 poly1 . thickness = 3;
32 xlabel ( ’ n ’ ) ;
33 title ( ’ P e r i o d i c I m p u l s e T r a i n x ( n ) ’ )
90
Figure 5.7: Inverse Fourier
91
Figure 5.8: Inverse Fourier
92
1 // S c i l a b Code f o r Example 5 . 5 o f S i g n a l s and s y s t e m s
by
2 //P . Ramakrishna Rao
3 clear ;
4 clc ;
5 x =[1 ,2 ,3 ,2 ,1];
6 q =0;
7 for n =1:5
8 q=x(n)+q;
9 end
10 disp (q , ’ ( a ) X( e ˆ j ∗ 0 ) ’ ) ;
11 q =0;
12 for n = -2:2
13 q =(( -1) ^ n ) * x ( n +3) + q ;
14 end
15 disp (q , ’ ( c ) X( e ˆ j ∗ p i ) ’ ) ;
16 disp ( ’ ( d ) X( e ˆ j ∗ p i ) =2∗ p i ∗ x ( 0 ) ’ ) ;
17 disp (2* %pi * x (3) ) ;
18 q =0;
19 for n = -2:2
20 q =( x ( n +3) ) ^2+ q ;
21 end
22 disp ( q *2* %pi , ’ ( e ) | X( e ˆ j ∗w) | ˆ 2 ’ ) ;
93
9 x1 = a1 ^ n ;
10 x2 = a2 ^ n ;
11 w =2;
12 n =0:100;
13 z =( exp ( - %i * w * n ) ) ;
14 for n =0:33;
15 X ( n +1) = z ( n +1) * x1 (3* n +1) ;
16 q = X ( n +1) + q ;
17 end
18 disp (q , ’ Y1 ( e ˆ2 j ) a t a =0.5 ’ ) ;
19 for n =0:33;
20 X ( n +1) = z ( n +1) * x2 (3* n +1) ;
21 q = X ( n +1) + q ;
22 end
23 disp (q , ’ Y1 ( e ˆ2 j ) a t a =−0.5 ’ ) ;
94
17 end
18 disp (q , ’ Y2 ( e ˆ2 j ) a t a =0.5 ’ ) ;
19 for n =0:33;
20 X ( n +1) = z ( n +1) * x2 ( n +1) ;
21 q = X ( n +1) + q ;
22 end
23 disp (q , ’ Y2 ( e ˆ2 j ) a t a =−0.5 ’ ) ;
95
Scilab code Exa 5.11 Inverse Fourier
96
Figure 5.9: Inverse Fourier
32 xlabel ( ’ Time i n S e c o n d s ’ ) ;
33 title ( ’ x ( n ) at Wc=1 ’ ) ;
97
Figure 5.10: Inverse Fourier
98
4 clear ;
5 // F i r s t C a u s a l s e q u e n c e
6 x =[1 ,4 ,3 ,2;2 ,1 ,4 ,3;3 ,2 ,1 ,4;4 ,3 ,2 ,1]
7 // S e c o n d S e q u e n c e
8 y =[4;3;2;1]
9 // C o n o l u t i o n
10 z = x * y ;
11 disp (z , ’ C o n v o l u t i o n Of x & y i s : ’ )
99
Scilab code Exa 5.16 DTFT
100
32 disp ( ceil ( q ) , ’X( 2 )−>s e c o n d DFT c o e f f i c i e n t ’ ) ;
33 q =0;
34 w =3* %pi /2;
35 n =0:3;
36 z =( exp ( - %i * w * n ) ) ;
37 for n =0:3
38 X ( n +1) = z ( n +1) * x ( n +1) ;
39 q = X ( n +1) + q ;
40 end
41 disp (q , ’X( 3 )−> t h i r d DFT c o e f f i c i e n t ’ ) ;
101
Chapter 6
102
19 title ( ’X( f ) ’ ) ;
20 xlabel ( ’−−−&g t ; f ’ );
21 w =1;
22 n = -1;
23 for f = -275:275
24 X_delta1 ( f +276) = fs *5*[ delta (f - n * fs -75) + delta (f - n
* fs +75) ];
25 end
26 n = n +1;
27 for f = -275:275
28 X_delta2 ( f +276) = fs *5*[ delta (f - n * fs -75) + delta (f - n
* fs +75) ];
29 end
30 n = n +1;
31 for f = -275:275
32 X_delta3 ( f +276) = fs *5*[ delta (f - n * fs -75) + delta (f - n
* fs +75) ];
33 end
34 X_delta = X_delta1 + X_delta2 + X_delta3 ;
35 figure (2) ;
36 f = -275:275;
37 plot2d3 (f , X_delta , -2) ;
38 title ( ’ X d e l t a ( f ) a t f s =200 ’ ) ;
39 xlabel ( ’−−−&g t ; f ’ );
103
Figure 6.1: Sampling and Reconstruction
104
Figure 6.2: Sampling and Reconstruction
105
Sampling f r e q u e n c y
4 clc ;
5 clear
6 function [ y ]= delta ( t )
7 if t ==0
8 y =1
9 else y =0
10 end
11 endfunction
12 fs =100;
13 for f = -200:200
14 X ( f +201) =5*[ delta (f -75) + delta ( f +75) ];
15 end
16 figure (1) ;
17 f = -200:200;
18 plot2d3 (f ,X , -2) ;
19 title ( ’X( f ) ’ ) ;
20 xlabel ( ’−−−&g t ; f ’ );
21 w =1;
22 n = -2;
23 for f = -175:175
24 X_delta1 ( f +176) = fs *5*[ delta (f - n * fs -75) + delta (f - n
* fs +75) ];
25 end
26 n = n +1;
27 for f = -175:175
28 X_delta2 ( f +176) = fs *5*[ delta (f - n * fs -75) + delta (f - n
* fs +75) ];
29 end
30 n = n +1;
31 for f = -175:175
32 X_delta3 ( f +176) = fs *5*[ delta (f - n * fs -75) + delta (f - n
* fs +75) ];
33 end
34 n = n +1;
35 for f = -175:175
36 X_delta4 ( f +176) = fs *5*[ delta (f - n * fs -75) + delta (f - n
* fs +75) ];
106
37 end
38 n = n +1;
39 for f = -175:175
40 X_delta5 ( f +176) = fs *5*[ delta (f - n * fs -75) + delta (f - n
* fs +75) ];
41 end
42 X_delta = X_delta1 + X_delta2 + X_delta3 + X_delta4 + X_delta5
;
43 figure (2) ;
44 f = -175:175;
45
46 plot2d3 (f , X_delta , -2) ;
47 title ( ’ X d e l t a ( f ) a t f s =100 ’ ) ;
48 xlabel ( ’−−−&g t ; f ’ );
49 // The P r e s e n c e o f t h e 25 HZ component i n t h e
spectrum o f x d e l t a ( t )
50 // Due t o e f f e c t o f A l i a s i n g
107
Figure 6.3: Sampling and Reconstruction
108
Figure 6.4: Sampling and Reconstruction
109
11 disp ( fs , ’ Minimum S a m p l i n g F r e q u e n c y t o a v o i d
d i s t o r t i o n i s : ’ );
110
13 end
14 f = -100:100;
15 a = gca () ;
16 a . x_location = ” o r i g i n ” ;
17 a . y_location = ” o r i g i n ” ;
18 plot2d3 (f ,X , -2) ;
19 title ( ’ Spectrum o f x ( t ) ’ ) ;
20 xlabel ( ’−−&g t ; f ’ );
21 fs =150;
22 n = -1; f - n * fs
23 for f = -275:275
24 X_delta1 ( f +276) = delta (f - n * fs +100) + delta (f - n * fs
-100) +3*[ delta (f - n * fs +90) + delta (f - n * fs -90) ];
25 end
26 n = n +1;
27 for f = -275:275
28 X_delta2 ( f +276) = delta (f - n * fs +100) + delta (f - n * fs
-100) +3*[ delta (f - n * fs +90) + delta (f - n * fs -90) ];
29 end
30 n = n +1;
31 for f = -275:275
32 X_delta3 ( f +276) = delta (f - n * fs +100) + delta (f - n * fs
-100) +3*[ delta (f - n * fs +90) + delta (f - n * fs -90) ];
33 end
34 X_delta = X_delta1 + X_delta2 + X_delta3 ;
35 figure (2) ;
36 f = -275:275;
37 plot2d3 (f , X_delta , -2) ;
38 title ( ’ X d e l t a ( f ) a t f s =150 ’ ) ;
39 xlabel ( ’−−−&g t ; f ’ );
111
Figure 6.5: LPF output
112
Figure 6.6: LPF output
113
Scilab code Exa 6.6 Sampling Frequency
114
Chapter 7
Systems
115
21 q (1 , t ) = a0 + a1 * x ( t ) + a2 *( x ( t ) ) ^2;
22 end
23 disp (q , ’ T h i s i n p u t g i v e s t h e o u t p u t : ’ ) ;
24 y = b1 * y1 + b2 * y2 ;
25 disp (y , ’ For t h e s y s t e m t o be l i n e a r t h e o u t p u t
s h o u l d be : ’ ) ;
26 disp ( ’ Hence t h e s y s t e m i s n o t l i n e a r ’ ) ;
116
24 disp (q , ’ T h i s i n p u t g i v e s t h e o u t p u t : ’ ) ;
25 disp (y , ’ For t h e s y s t e m t o be l i n e a r t h e o u t p u t
s h o u l d be : ’ ) ;
26 disp ( ’ Hence t h e s y s t e m i s l i n e a r ’ ) ;
117
27 disp ( ’ For a d e l a y (T) o f 2 s e c o n d s ’ ) ;
28 disp ( ’ At t =3 s e c o n d s : ’ ) ;
29 t =3;
30 a = x (1 ,2* t -2) ;
31 b = y (1 ,t -2) ;
32 c = x (1 ,2* t -4) ;
33 disp (a , ’ x ( 2 t−T) : ’ ) ;
34 disp (b , ’ i s n o t e q u a l t o y ( 2 t−T) : ’ ) ;
35 disp (c , ’ w h i l e x ( 2 t −2∗T) : ’ ) ;
36 disp ( ’ Hence t h e s y s t e m i s Time v a r i a n t ’ ) ;
118
22 end
23 disp (q , ’ T h i s i n p u t g i v e s t h e o u t p u t : ’ ) ;
24 y = b1 * y1 + b2 * y2 ;
25 disp (y , ’ For t h e s y s t e m t o be l i n e a r t h e o u t p u t
s h o u l d be : ’ ) ;
26 disp ( ’ Hence t h e s y s t e m i s l i n e a r ’ ) ;
27 disp ( ’ For a d e l a y ( n0 ) o f 2 s e c o n d s ’ ) ;
28 disp ( ’ At n=3 s e c o n d s : ’ ) ;
29 t =3;
30 a = x (1 ,2* n -2) ;
31 b = y (1 ,n -2) ;
32 c = x (1 ,2* n -4) ;
33 disp (a , ’ x ( 2 n−n0 ) : ’ ) ;
34 disp (b , ’ i s n o t e q u a l t o y ( 2 n−n0 ) : ’ ) ;
35 disp (c , ’ w h i l e x ( 2 n−2∗n0 ) : ’ ) ;
36 disp ( ’ Hence t h e s y s t e m i s Time v a r i a n t ’ ) ;
119
16 a = x (n -2) -x (n -2 -1) ;
17 disp (a , ’ x ( n −2) : ’ ) ;
18 disp (b , ’ i s e q u a l t o y ( n−2) : ’ ) ;
19 disp ( ’ Hence t h e s y s t e m i s S h i f t i n v a r i a n t / f i x e d ’ );
120
27 disp ( ’ At n=3 s e c o n d s : ’ ) ;
28 t =3;
29 a = x (1 ,n -2) ;
30 b = y (1 ,n -2) ;
31 c =2* x (1 ,n -2) ;
32 disp (a , ’ x ( n−n0 ) : ’ ) ;
33 disp (b , ’ i s n o t e q u a l t o y ( n−n0 ) : ’ ) ;
34 disp (c , ’ w h i l e ( n−n0 ) ∗ x ( n−n0 ) : ’ ) ;
35 disp ( ’ ( i i i ) Hence t h e s y s t e m i s Time v a r i a n t ’ ) ;
121
s h o u l d be : ’ ) ;
23 disp ( ’ ( i ) Hence t h e s y s t e m i s l i n e a r ’ ) ;
122
29 disp (a , ’ e ˆ x ( n−n0 ) : ’ ) ;
30 disp (b , ’ i s e q u a l t o y ( n−n0 ) : ’ ) ;
31 disp ( ’ ( i i i ) Hence t h e s y s t e m i s Time i n v a r i a n t ’ ) ;
123
Figure 7.1: Output of an LTI
124
8 n = -2:2;
9 c = gca () ;
10 c . y_location = ” o r i g i n ” ;
11 c . x_location = ” o r i g i n ” ;
12 plot2d2 (n ,x ,2) ;
13 title ( ’ x ( t ) ’ )
14 xlabel ( ’ t ’ )
15 figure (1) ;
16 n = -2:2;
17 c = gca () ;
18 c . y_location = ” o r i g i n ” ;
19 c . x_location = ” o r i g i n ” ;
20 plot2d2 (n ,y ,5) ;
21 title ( ’ y ( t ) ’ )
22 xlabel ( ’ t ’ )
23 z = conv (x , y ) ;
24 figure (2) ;
25 n = -3:5;
26 c = gca () ;
27 c . y_location = ” o r i g i n ” ;
28 c . x_location = ” o r i g i n ” ;
29 plot (n ,z ,2) ;
30 title ( ’ C o n v o l u t e d s i g n a l z( t ) ’)
31 xlabel ( ’ t ’ )
125
Figure 7.2: Convolution
126
6 syms s t R C ;
7 Y1 =(1/( R * C ) ) /( s +1/( R * C ) ) ;
8 disp ( Y1 , ’ L a p l a c e T r a n s f o r m Of d i f f e r e n t i a l Equation
is : ’)
9 y11 = ilaplace ( Y1 ,s , t ) ;
10 disp ( y11 , ’ The I m p u l s e R e s p o n s e o f t h e System i s : ’ ) ;
11 for k =0:10;
12 y1 ( k +1) = exp ( - k ) ;
13 end
14 k =0:10;
15 plot (k , y1 ) ;
16 title ( ’ System R e s p o n s e t o i m p u l s e i n p u t ’ ) ;
17 Y2 =(1/( R * C ) ) /( s ^2+ s /( R * C ) ) ;
18 disp ( Y2 , ’ L a p l a c e T r a n s f o r m Of d i f f e r e n t i a l E q u a t i o n
is : ’)
19 y22 = ilaplace ( Y2 ,s , t ) ;
20 disp ( y22 , ’ The S t e p R e s p o n s e o f t h e System i s : ’ ) ;
21 for k =0:10;
22 y2 ( k +1) =1 - exp ( - k ) ;
23 end
24 figure (1) ;
25 k =0:10;
26 plot (k , y2 ) ;
27 title ( ’ System R e s p o n s e t o S t e p i n p u t ’ ) ;
127
Figure 7.3: Impulse and Step response
128
Figure 7.4: Impulse and Step response
129
4 clc ;
5 clear ;
6 syms s t R L ;
7 Y1 =(1/ s ) -(1/( s +( R / L ) ) ) ;
8 disp ( Y1 , ’ L a p l a c e T r a n s f o r m Of d i f f e r e n t i a l Equation
is : ’)
9 y1 = ilaplace ( Y1 ,s , t ) ;
10 disp ( y1 , ’ The S t e p R e s p o n s e o f t h e System i s : ’ ) ;
11 // Taking R/L=1;
12 for k =0:10;
13 y1 ( k +1) =1 - exp ( - k ) ;
14 end
15 k =0:10;
16 plot (k , y1 ) ;
17 title ( ’ System R e s p o n s e t o S t e p i n p u t ’ ) ;
18 Y2 =(1/( s +( R / L ) ) ) ;
19 disp ( Y2 , ’ L a p l a c e T r a n s f o r m Of d i f f e r e n t i a l E q u a t i o n
is : ’)
20 y2 = ilaplace ( Y2 ,s , t ) ;
21 disp ( y2 , ’ The I m p u l s e R e s p o n s e o f t h e System i s : ’ ) ;
22 for k =0:10;
23 y2 ( k +1) = exp ( - k ) ;
24 end
25 figure (1) ;
26 k =0:10;
27 plot (k , y2 ) ;
28 title ( ’ System R e s p o n s e t o i m p u l s e i n p u t ’ ) ;
130
Figure 7.5: Impulse and Step Response
131
Figure 7.6: Impulse and Step Response
132
s y s t e m s by
2 //P . Ramakrishna Rao
3 // C o n v o l u t i o n o f two s i g n a l s
4 clc ;
5 clear ;
6 clear x y n ;
7 x =[2 , -1 ,1 ,0 ,2];
8 y =[1 ,0 , -1 ,2];
9 n = -1:3;
10 c = gca () ;
11 c . y_location = ” o r i g i n ” ;
12 c . x_location = ” o r i g i n ” ;
13 plot2d3 (n ,x , -5) ;
14 title ( ’ x ( k ) ’ )
15 xlabel ( ’ k ’ )
16 figure (1) ;
17 n =0:3;
18 c = gca () ;
19 c . y_location = ” o r i g i n ” ;
20 c . x_location = ” o r i g i n ” ;
21 plot2d3 (n ,y , -5) ;
22 title ( ’ y ( k ) ’ )
23 xlabel ( ’ k ’ )
24 z = conv (x , y ) ;
25 figure (2) ;
26 n = -1:6;
27 c = gca () ;
28 c . y_location = ” o r i g i n ” ;
29 c . x_location = ” o r i g i n ” ;
30 plot2d3 (n ,z , -5) ;
31 title ( ’ C o n v o l u t e d s i g n a l z( t ) ’)
32 xlabel ( ’ t ’ )
133
Figure 7.7: Convolution
134
Scilab code Exa 7.22 Convolution
135
Figure 7.8: Convolution
36 c = gca () ;
37 c . y_location = ” o r i g i n ” ;
38 c . x_location = ” o r i g i n ” ;
39 plot2d3 (n ,z , -4) ;
40 title ( ’ C o n v o l u t e d s i g n a l w( t ) ’ ) ;
41 xlabel ( ’ t ’ ) ;
42 disp ( z (1) , ’ z ( 0 ) ’ ,z (4) , ’ z ( 3 ) ’ ,z (6) , ’ z ( 5 ) ’ ,z (11) , ’ z
( 1 0 ) ’ );
136
1 // S c i l a b Code f o r Example 7 . 2 3 o f S i g n a l s and
s y s t e m s by
2 //P . Ramakrishna Rao
3 // C o n v o l u t i o n o f two s i g n a l s
4 clc ;
5 clear ;
6 function [ y ]= u ( t )
7 if t >=0
8 y =1
9 else y =0
10 end
11 endfunction
12 for n =0:10;
13 x ( n +1) =(0.5) ^ n * u (n -2) ;
14 end
15 c = gca () ;
16 c . y_location = ” o r i g i n ” ;
17 c . x_location = ” o r i g i n ” ;
18 n =0:10;
19 plot2d3 (n ,x , -4) ;
20 title ( ’ x ( n ) ’ )
21 xlabel ( ’ n ’ )
22 for n =0:10;
23 y ( n +1) = u ( n ) ;
24 end
25 figure (1) ;
26 n =0:10;
27 c = gca () ;
28 c . y_location = ” o r i g i n ” ;
29 c . x_location = ” o r i g i n ” ;
30 plot2d3 (n ,y , -4) ;
31 title ( ’ y ( k ) ’ )
32 xlabel ( ’ k ’ )
33 z = conv (x , y ) ;
34 figure (2) ;
35 n =0:20;
36 c = gca () ;
37 c . y_location = ” o r i g i n ” ;
137
Figure 7.9: Convolution
38 c . x_location = ” o r i g i n ” ;
39 plot2d3 (n ,z , -4) ;
40 title ( ’ C o n v o l u t e d s i g n a l z( t ) ’)
41 xlabel ( ’ t ’ )
138
4 clc ;
5 clear ;
6 syms z n ;
7 y1 =2*(1 -0.5^ n ) ;
8 disp ( y1 * ’ u ( n ) ’ , ’ The s t e p R e s p o n s e o f t h e System i s : ’
);
9 for n =0:10;
10 q ( n +1) =2*(1 -0.5^ n ) ;
11 end
12 n =0:10;
13 plot (n , q ) ;
14 title ( ’ S t e p R e s p o n s e g ( n ) ’ );
15 xlabel ( ’ n−−> ’ ) ;
139
Figure 7.10: Step Response
140
Figure 7.11: Step response
141
3 // P l o t t i n g t h e m a g n i t u d e and p h a s e r e s p o n s e s
4 clc ;
5 clear ;
6 T =1;
7 n =1;
8 for w =0:0.1:20;
9 hmag ( n ) =2* sin ( w * T /2) ;
10 n = n +1;
11 end
12 n =1;
13 for w =0:0.1:20;
14 hphase ( n ) = %pi /2 -( w * T /2) ;
15 n = n +1;
16 end
17 // Magnitude p l o t
18 w =0:0.1:20;
19 plot (w , hmag ) ;
20 title ( ’ Magnitude P l o t ’ ) ;
21 xlabel ( ’w ’ ) ;
22 ylabel ( ’ | H( e ˆ jw ) | ’ ) ;
23 figure (1) ;
24 // Phase P l o t
25 w =0:0.1:20;
26 plot (w , hphase ) ;
27 title ( ’ Phase P l o t ’ ) ;
28 xlabel ( ’w ’ ) ;
29 ylabel ( ’ t h e t a (wT) ’ ) ;
142
Figure 7.12: Magnitude and Phase Response
143
Figure 7.13: Magnitude and Phase Response
144
Chapter 8
145
Figure 8.1: Magnitude and Phase Responses
19 title ( ’ I m p u l s e R e s p o n s e ’ ) ;
20 ylabel ( ’ A m p l i t u d e ’ ) ;
21 xlabel ( ’ t i m e i n s e c o n d s ’ ) ;
22 figure (1) ;
23 w = -5*2* %pi :0.01:5*2* %pi ;
24 plot (w , Hphs ) ;
25 title ( ’ Phase R e s p o n s e ’ ) ;
26 ylabel ( ’ t h e t a (w) ’ ) ;
27 xlabel ( ’w i n r a d i a n s / s e c o n d ’ ) ;
146
Figure 8.2: Magnitude and Phase Responses
147
Scilab code Exa 8.2 Transfer Function of system
148
Figure 8.3: Transfer Function of system
149
Scilab code Exa 8.3 Magnitude and Phase Responses
150
Figure 8.4: Magnitude and Phase Responses
151
Figure 8.5: Magnitude and Phase Responses
152
6 z = %z ;
7 syms n z1 ;
8 X =( z -1) /(( z +(1/2) ) *( z -(1/5) ) )
9 disp (X , ’ ( i ) System F u n c t i o n i s : ’ ) ;
10 X1 = denom ( X ) ;
11 zp = roots ( X1 ) ;
12 X1 = ( z1 -1) /(( z1 +(1/2) ) *( z1 -(1/5) ) ) ;
13 F1 = X1 *( z1 ^( n -1) ) *( z1 - zp (1) )
14 F2 = X1 *( z1 ^( n -1) ) *( z1 - zp (2) )
15 h1 = limit ( F1 , z1 , zp (1) )
16 h2 = limit ( F2 , z1 , zp (2) )
17 h = h1 + h2 ;
18 disp ( ’ ( i v ) U n i t s a m p l e r e s p o n s e s e q u e n c e : ’ )
19 disp ( h * ” u ( n ) ” , ’ h [ n ]= ’ ) ;
20 for n =0:10;
21 w ( n +1) =( - 5.714*(0.2) ^n - 4.285*( - 0.5^ n ) ) ;
22 end
23 n =0:10;
24 plot (n , w ) ;
25 title ( ’ ( i i i ) U n i t Sample R e s p o n s e S e q u e n c e ’ ) ;
26 disp ( ’ where z=e ˆ jw ’ ,X , ’ ( i ) T r a n s f e r F u n c t i o n i s : ’ ) ;
153
Figure 8.6: system response
154
9 disp (X , ’ ( i ) System F u n c t i o n i s : ’ ) ;
10 X1 = denom ( X ) ;
11 zp = roots ( X1 ) ;
12 X1 = z1 ^2/( z1 -0.5) ^2;
13 F1 = X1 *( z1 ^( n -1) ) *( z1 -0.5) ^2;
14 h1 = limit ( F1 , z1 , zp (1) ) ;
15 h = h1 ;
16 disp ( ’ ( i i i ) U n i t s t e p r e s p o n s e s e q u e n c e : ’ )
17 disp ( h * ” u ( n ) ” , ’ h [ n ]= ’ ) ;
18 for n =0:20;
19 w1 ( n +1) =1 -(0.5) ^ n ;
20 end
21 n =0:20;
22 plot (n , w1 ) ;
23 title ( ’ ( i i ) U n i t Sample R e s p o n s e S e q u e n c e ’ ) ;
24 disp ( ’ where z=e ˆ jw ’ ,X , ’ ( i v ) T r a n s f e r F u n c t i o n (H( e ˆ
jw ) ) i s : ’ ) ;
155
Figure 8.7: System function
156
13 disp (Z , ’ ( b ) LC Low p a s s F i l t e r : H( s ) ’ ) ;
157
8 H = s ^3/( s ^3+6* s ^2++11* s +6) ;
9 H1 = denom ( H ) ;
10 a = roots ( H1 ) ;
11 H2 =5*( s1 ^3/( s1 - a (1) ) ) *( s1 /( s1 - a (2) ) ) *( s1 /( s1 - a (3) ) ) ;
12 disp ( H2 , ’ ( i i ) C a s c a d e Form : H( s ) ’ ) ;
13 h1 = s1 ^3*( s1 - a (1) ) /(( s1 +1) *( s1 +2) *( s1 +3) ) ;
14 h2 = s1 ^3*( s1 - a (2) ) /(( s1 +1) *( s1 +2) *( s1 +3) ) ;
15 h3 = s1 ^3*( s1 - a (3) ) /(( s1 +1) *( s1 +2) *( s1 +3) ) ;
16 A = limit ( h1 , s1 , a (1) ) /( s - a (1) ) ;
17 B = limit ( h2 , s1 , a (2) ) /( s - a (2) ) ;
18 C = limit ( h3 , s1 , a (3) ) /( s - a (3) ) ;
19 Z =5*(1+ A + B + C ) ;
20 disp (Z , ’ ( i i i ) P a r a l l e l Form R e a l i z a t i o n : H( s ) ’ ) ;
158
19 w2 = limit ( F2 ,z , a (2) )
20 w = w1 + w2 ;
21 disp (w , ’ ( b ) h ( n ) )= ’ ) ;
22 z = %z ;
23 x11 = z * x1 /3
24 x12 = z * x2 /3
25 disp ( x11 , ” ( c ) P a r a l l e l r e a l i z a t i o n : H1 ( z ) ” ) ;
26 disp ( x12 , ” H2 ( z ) ” )
159
Chapter 9
160
Figure 9.1: Convolution
161
Figure 9.2: Convolution
162
8 y =1
9 else y =0
10 end
11 endfunction
12 n =1;
13 for t = -5:0.1:5
14 x ( n ) = -2* u (t -0.5) +2* u (t -1.5) ;
15 y ( n ) =( t +1) * u ( t +1) -( t +1) * u (t -2) ;
16 n = n +1;
17 end
18 z = conv (x , y ) ;
19 t = -5:0.1:5;
20 plot2d2 (t ,x ,5) ;
21 title ( ’ x ( t ) ’ ) ;
22 figure (1) ;
23 t = -5:0.1:5;
24 plot2d (t ,y ,2) ;
25 title ( ’ y ( t ) ’ ) ;
26 figure (2) ;
27 t = -10:0.1:10;
28 plot2d (t ,z ,6) ;
29 title ( ’ C o n v o l u t i o n ’ ) ;
163
Figure 9.3: Autocorrelation
164
Figure 9.4: Autocorrelation
165
Figure 9.5: Autocorrelation
166
Scilab code Exa 9.5 Autocorrelation
167
Figure 9.6: Autocorrelation
168
Figure 9.7: Autocorrelation
169
6 n =1;
7 wo =2* %pi ;
8 theta = %pi /2;
9 for t = -5:0.01:5;
10 x ( n ) = A * cos ( wo * t + theta ) ;
11 n = n +1;
12 end
13 t = -5:0.01:5;
14 plot (t , x ) ;
15 title ( ’ x ( t ) ’ ) ;
16 n =1;
17 for T = -5:0.1:5;
18 z ( n ) =( A ^2/2) * cos ( wo * T ) ;
19 n = n +1;
20 end
21 figure (1) ;
22 T = -5:0.1:5;
23 plot (T , z ) ;
24 title ( ’ Rxx (T) ’ ) ;
25 xlabel ( ’ t i n s e c o n d s ’ )
170
Figure 9.8: Autocorrelation
171
Figure 9.9: Autocorrelation
172
8 n =1;
9 for T =0:0.1: T0 ;
10 if T < T0 /2 then
11 x(n)=A;
12 else x ( n ) =0;
13 end
14 n = n +1;
15 end
16 T =0:0.1: T0 ;
17 plot2d2 (T ,x ,6) ;
18 title ( ’ x ( t ) ) ’ ) ;
19 xlabel ( ’ t i n s e c o n d s ’ ) ;
20 n =1;
21 for T =0:0.1: T0 ;
22 z ( n ) =(1/ T0 ) * integrate ( ’Aˆ2 ’ , ’ t ’ ,T , T0 /2) ;
23 n = n +1;
24 end
25 T =0:0.1: T0 ;
26 figure (1) ;
27 plot (T , z ) ;
28 title ( ’ Rxx (T) ’ ) ;
29 xlabel ( ’T i n s e c o n d s ’ ) ;
173
Figure 9.10: PSD
174
8 y =1
9 else y =0
10 end
11 endfunction
12 fo =2;
13 n =1;
14 RC =1/(2* %pi *10^3) ;
15 w =4* %pi *10^3
16 H =1/(1+ %i * w * RC ) ;
17 disp (H , ’H( f ) ’ ) ;
18 X =( abs ( H ) ) ^2;
19 for f = -5:5
20 Pxx ( n ) =25*[ delta (f - fo ) + delta ( f + fo ) ];
21 Pyy ( n ) = X * Pxx ( n ) ;
22 n = n +1;
23 end
24 disp ( Pxx , ’ Pxx= ’ ) ;
25 disp ( Pyy , ’ Pyy= ’ ) ;
26 f = -5:5;
27 plot2d3 (f , Pyy , -2) ;
28 title ( ’ Power S p e c t r a l D e n s i t y ’ ) ;
29 ylabel ( ’ Pyy ( f ) ’ ) ;
30 xlabel ( ’ f i n Hz ’ ) ;
175
Chapter 10
176
Figure 10.1: Cross Correlation
177
Figure 10.2: Cross Correlation Sequence
17 title ( ’ C r o s s −C o r r e l a t i o n s e g u e n c e o u t p u t ’ ) ;
178
Figure 10.3: Auto Correlation
7 y =[0 ,3 ,0 , -3 ,6];
8 // c o m p u t a t i o n o f c r o s s c o r r e l a t i o n s e q u e n c e ;
9 n1 = max ( size ( y ) ) -1;
10 n2 = max ( size ( x ) ) -1;
11 r = xcorr (x ,y , n1 ) ;
12 n = -4:4;
13 a = gca () ;
14 a . x_location = ” o r i g i n ” ;
15 a . y_location = ” o r i g i n ” ;
16 plot2d3 (n ,r , -9) ;
17 title ( ’ r x y c r o s s − c o r r e l a t i o n ’ ) ;
179
Scilab code Exa 10.4 Auto Correlation
180
Figure 10.4: Auto Correlation
181
13 a =0.8;
14 for n = -30:30;
15 x ( k ) = a ^( - n ) * u ( - n ) ;
16 k = k +1;
17 end
18 length ( x )
19 // c o m p u t a t i o n o f a u t o c o r r e l a t i o n s e q u e n c e ;
20 r = xcorr ( x ) ;
21 n = -60:60;
22 a = gca () ;
23 a . x_location = ” o r i g i n ” ;
24 a . y_location = ” o r i g i n ” ;
25 plot2d3 (n ,r , -4) ;
26 title ( ’ r x x a u t o − c o r r e l a t i o n ’ ) ;
182
Figure 10.5: Auto Correlation
183
Figure 10.6: System response
16 k = k +1;
17 end
18 length ( x )
19 // c o m p u t a t i o n o f a u t o c o r r e l a t i o n s e q u e n c e ;
20 r = xcorr ( x ) ;
21 n = -60:60;
22 a = gca () ;
23 a . x_location = ” o r i g i n ” ;
24 a . y_location = ” o r i g i n ” ;
25 plot2d3 (n ,r , -4) ;
26 title ( ’ r x x a u t o − c o r r e l a t i o n ’ ) ;
184
Scilab code Exa 10.11 System response
185
Chapter 11
186
Figure 11.1: Hilbert Transform
187
Figure 11.2: Hilbert Transform
188
Figure 11.3: Hilbert Transform
15 xlabel ( ’ t i m e t−−&g t ; ’ ) ;
16 figure (1) ;
17 t = -1:0.1:1;
18 plot (t , imag ( x ) ) ;
19 title ( ’ H i l b e r t T r a n s f o r m ’ ) ;
20 xlabel ( ’ t i m e t−−&g t ; ’ ) ;
189
Figure 11.4: Hilbert Transform
190
1 // S c i l a b Code f o r Example 1 1 . 2 o f S i g n a l s and
s y s t e m s by
2 //P . Ramakrishna Rao
3 // H i l b e r t T r a n s f o r m
4 clc ;
5 clear ;
6 n =1;
7 for t = -1:0.01:1
8 xr ( n ) = cos (2* %pi * t ) ;
9 n = n +1;
10 end
11 // Computing H i l b e r t b T r a n s f o r m
12 x = hilbert ( xr ) ;
13 t = -1:0.01:1;
14 plot (t , xr ) ;
15 title ( ’ Given S i g n a l x ( t ) ’ ) ;
16 xlabel ( ’ t i m e t−−> ’ ) ;
17 figure (1) ;
18 t = -1:0.01:1;
19 plot (t , imag ( x ) ) ;
20 title ( ’ H i l b e r t T r a n s f o r m ’ ) ;
21 xlabel ( ’ t i m e t−−> ’ ) ;
191
Figure 11.5: Hilbert Transform
192
Figure 11.6: Hilbert Transform
193
6 clear ;
7 n =1;
8 for t = -1:0.01:1
9 xr ( n ) = exp ( %i *2* %pi * t ) ;
10 n = n +1;
11 end
12 // Computing H i l b e r t b T r a n s f o r m
13 x1 = hilbert ( real ( xr ) ) ;
14 x2 = hilbert ( imag ( xr ) ) ;
15 x = x1 + x2 ;
16 t = -1:0.01:1;
17 plot (t , xr ) ;
18 title ( ’ Given S i g n a l x ( t ) ’ ) ;
19 xlabel ( ’ t i m e t−−> ’ ) ;
20 figure (1) ;
21 t = -1:0.01:1;
22 plot (t , imag ( x ) ) ;
23 title ( ’ H i l b e r t T r a n s f o r m ’ ) ;
24 xlabel ( ’ t i m e t−−> ’ ) ;
194
Figure 11.7: Hilbert Transform
195
Figure 11.8: Hilbert Transform
196
9 for t = -10:0.01:10;
10 if t > - T /2 & t < T /2 then
11 x(n)=A;
12 n = n +1;
13 else x ( n ) =0;
14 n = n +1;
15 end
16 end
17 t = -10:0.01:10;
18 // S i g n a l x ( t )
19 plot (t , x ) ;
20 title ( ’ Given S i g n a l x ( t ) ’ ) ;
21 xlabel ( ’ t i m e t−−> ’ ) ;
22 // Computing H i l b e r t T r a n s f o r m
23 xr = hilbert ( x ) ;
24 xr_imag = imag ( xr ) ;
25 figure (1) ;
26 t = -10:0.01:10;
27 plot (t , xr_imag ) ;
28 title ( ’ H i l b e r t t r a n s f o r m and a s s o c i a t e d s i g n a l ’ ) ;
29 xlabel ( ’ t i m e t−−> ’ ) ;
197









