Scilab
Scilab
Solutions provided by
Dr Kantipudi Mvv Prasad
Others
Sreyas Institute Of Engineering & Technology
2
10 Finding the Fourier Transform of a given signal and plotting
its magnitude and phase spectrum 66
3
List of Experiments
4
List of Figures
2.1 Generation Of Unit Impulse and Unit Step Signal and Se-
quences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
2.2 Generation Of Square Wave and Sawtooth Wave Signals and
Sequences . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
2.3 Generation Of Triangular and Sinusoidal Signal and Sequences 17
2.4 Generation Of Ramp and Sinc Signals and Sequences . . . . 19
5
9.1 Verifying the Gibbs phenomenon . . . . . . . . . . . . . . . 65
6
Experiment: 1
1 // E x p e r i m e n t Number : 1
2 // W r i t e a program t o p e r f o r m b a s i c o p e r a t i o n on
matrices
3 // B a s i c S i m u l a t i o n L a b o r a t o r y
4 //B . Tech I I Year I Sem
5 // S t u d d e n t Name : E n r o l e m e n t Number :
6 // C o u r s e I n s t r u c t o r : Dr . K a n t i p u d i MVV Prasad ,
7 // S r e y a s I n s t i t u t e Of E n g i n e e r i n g & T e c h n l o g y ,
Hyderabad .
8 //
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
9
10
11 // OS : Windows 1 0 . 1
12 // S c i l a b 6 . 0 . 2
13
14
15 clc ;
16 close
17 clear ;
7
18
19 // E n t e r M a t r i c e s from Keyboard
20
21 A = input ( ’ E n t e r t h e M a t r i x A : ’ ) ;
22 B = input ( ’ E n t e r t h e M a t r i x B : ’ ) ;
23
24 // D i s p l a y t h e E n t e r e d M a t r i c e s from Keyboard
25
26 disp (A , ’ The M a t r i x A i s . . . . : ’ ) ;
27
28 disp (B , ’ The M a t r i x B i s . . . . : ’ ) ;
29
30 // Find t h e s i z e o f m a t r i c e s
31
32 disp ( ’ The s i z e o f M a t r i x A i s . . . . : ’ ) ;
33
34 disp ( size ( A ) ) ;
35
36 disp ( ’ The s i z e o f M a t r i x B i s . . . . : ’ ) ;
37
38 disp ( size ( B ) ) ;
39
40 // A d d i t i o n o f two m a t r i c e s
41
42 disp ( ’ A d d i t i o n o f A and B M a t r i c e s i s . . . . . : ’ ) ;
43
44 disp ( A + B ) ;
45
46 // S u b t r a t i o n o f two m a t r i c e s
47
48 disp ( ’ S u b t r a c t i o n o f A and B M a t r i c e s i s . . . . . : ’ ) ;
49
50 disp ( A - B ) ;
51
52 // M u l t i p l i c a t i o n by a s c a l a r
53 disp ( ’ M u l t i p l i c a t i o n o f m a t r i x A w i t h a s c a l a r v a l u e
K .....: ’ );
54
8
55 K = input ( ’ E n t e r a s c a l a r v a l u e K : ’ ) ;
56
57 disp ( K * A ) ;
58
59 // M u l t i p l i c a t i o n o f two m a t r i c e s
60
61 disp ( ’ M u l t i p l i c a t i o n o f A and B M a t r i c e s is .....: ’
);
62
63 disp ( A * B ) ;
64
65
66 // M u l t i p l i c a t i o n ( Element by Element ) o f two
matrices
67
68 disp ( ’ M u l t i p l i c a t i o n ( Element by Element ) o f A and B
M a t r i c e s i s . . . . . : ’ );
69
70 disp ( A .* B ) ;
71
72 // F i n d i n g t h e Rank o f t h e m a t r i x
73
74 disp ( ’ Rank o f M a t r i x A i s : ’ ) ;
75
76 disp ( rank ( A ) ) ;
77
78 // Find t h e d e t e r m i n a n t o f t h e m a t r i x
79
80 disp ( ’ D e t e r m i n a n t o f M a t r i x A i s : ’ ) ;
81
82 disp ( det ( A ) ) ;
83
84 // Find t h e t r a c e o f t h e m a t r i x
85
86 disp ( ’ T r a c e o f M a t r i x A i s : ’ ) ;
87
88 disp ( trace ( A ) ) ;
89
9
90 // Find t h e I n v e r s e o f t h e m a t r i x
91
92 disp ( ’ I n v e r s e o f M a t r i x A i s : ’ ) ;
93
94 disp ( inv ( A ) ) ;
10
Experiment: 2
Scilab code Solution 2.1 Generation Of Unit Impulse and Unit Step Sig-
nal and Sequences
1 // E x p e r i m e n t Number : 2 . 1
2 // W r i t e a program t o g e n e r a t e u n i t i m p u l s e and u n i t
s t e p S i g n a l s and S e q u e n c e s
3 // B a s i c S i m u l a t i o n L a b o r a t o r y
4 //B . Tech I I Year I Sem
5 // S t u d d e n t Name : E n r o l e m e n t Number :
6 // C o u r s e I n s t r u c t o r : Dr . K a n t i p u d i MVV Prasad ,
7 // S r e y a s I n s t i t u t e Of E n g i n e e r i n g & T e c h n l o g y ,
Hyderabad .
8 //
11
Figure 2.1: Generation Of Unit Impulse and Unit Step Signal and Sequences
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
9
10 // OS : Windows 1 0 . 1
11 // S c i l a b 6 . 0 . 2
12
13
14 clc ;
15 close
16 clear ;
17
18 // U n i t I m p u l s e S i g n a l and S e q u e n c e
19
20 t = -4:1:4;
21 a =[ zeros (1 ,4) 1 zeros (1 ,4) ];
22 k = input ( ” E n t e r t h e A m p l i t u d e : ” ) ; // r e a d i n g
a m p l i t u d e v a l u e from k e y b o a r d
23 b = k * a ;
24
25 subplot (2 ,2 ,1) ;
26 plot (t , b ) ;
27 xlabel ( ” Time ” ) ;
28 ylabel ( ” A m p l i t u d e ” ) ;
12
29 title ( ” I m p u l s e R e s p o n s e ” ) ;
30
31 subplot (2 ,2 ,2) ;
32 plot2d3 (t , b ) ;
33 xlabel ( ” Time ” ) ;
34 ylabel ( ” A m p l i t u d e ” ) ;
35 title ( ” I m p u l s e R e s p o n s e ” ) ;
36
37 // U n i t S t e p S i g n a l and S e q u e n c e :
38
39 // D i s c r e t e S i g n a l
40
41 t =0:3;
42 y = ones (1 ,4) ;
43
44 subplot (2 ,2 ,3) ;
45 plot2d3 (t , y ) ;
46 xlabel ( ’ Time ’ ) ;
47 ylabel ( ’ A m p l i t u d e ’ ) ;
48 title ( ’ U n i t S t e p D i s c r e t e S i g n a l ’ ) ;
49
50 // C o n t i n u o u s S i g n a l
51
52 subplot (2 ,2 ,4) ;
53 plot (t , y ) ;
54 xlabel ( ’ Time ’ ) ;
55 ylabel ( ’ A m p l i t u d e ’ ) ;
56 title ( ’ U n i t S t e p C o n t i n u o u s S i g n a l ’ ) ;
57
58 // E n t e r t h e A m p l i t u d e : 8
Scilab code Solution 2.2 Generation Of Square Wave and Sawtooth Wave
Signals and Sequences
13
Figure 2.2: Generation Of Square Wave and Sawtooth Wave Signals and
Sequences
1 // E x p e r i m e n t Number : 2 . 2
2 // W r i t e a program t o g e n e r a t e s q u a r e wave and
s a w t o o t h wave S i g n a l s and S e q u e n c e s
3 // B a s i c S i m u l a t i o n L a b o r a t o r y
4 //B . Tech I I Year I Sem
5 // S t u d d e n t Name : E n r o l e m e n t Number :
6 // C o u r s e I n s t r u c t o r : Dr . K a n t i p u d i MVV Prasad ,
7 // S r e y a s I n s t i t u t e Of E n g i n e e r i n g & T e c h n l o g y ,
Hyderabad .
8 //
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
9
10 // OS : Windows 1 0 . 1
11 // S c i l a b 6 . 0 . 2
12
13
14 clc ;
15 close ;
16 clear ;
17
18
14
19 // c o n t i n u o u s s q u a r e wave S i g n a l :
20
21 a = input ( ’ E n t e r A m p l i t u d e : ’ ) ;
22 t =0:0.001:1;
23 d = a * squarewave (2* %pi *10* t ) ;
24
25 subplot (2 ,2 ,1) ;
26 plot (t , d ) ;
27 xlabel ( ”−−−−−−−−−−>Time I n d e x t ( s e c . ) ” ) ;
28 ylabel ( ”−−−−−−−−−−>A m p l i t u d e ” ) ;
29 title ( ” S q u a r e Wave S i g n a l ” ) ;
30
31 // d i s c r e t e s q u a r e wave s i g n a l
32
33 // a=i n p u t ( ’ E n t e r a m p l i t u d e ’ ) ;
34 n =0 : 0.01 :1;
35 d = a * squarewave (2* %pi *10* n ) ;
36
37 subplot (2 ,2 ,2) ;
38 plot2d3 (n , d ) ;
39 xlabel ( ”−−−−−−−−−−>Time I n d e x n” ) ;
40 ylabel ( ”−−−−−−−−−−>A m p l i t u d e ” ) ;
41 title ( ” S q u a r e Wave S i g n a l S e q u e n c e ” ) ;
42
43 // S a w t o o t h Wave S i g n a l
44
45 Fs = 20; // s a m p l e s p e r s e c o n d
46 t_total = 10; // s e c o n d s
47 n_samples = Fs * t_total ;
48 t = linspace (0 , t_total , n_samples ) ;
49 f =500; // sound f r e q u e n c y
50
51 saw_wave =2*( f *t - floor (0.5+ f * t ) ) ;
52
53 subplot (2 ,2 ,3) ;
54 plot (t , saw_wave ) ;
55 xlabel ( ”−−−−−−−−−−>Time I n d e x t ( s e c . ) ” ) ;
56 ylabel ( ”−−−−−−−−−−−>A m p l i t u d e ” ) ;
15
57 title ( ” S a w t o o t h Wave S i g n a l ” ) ;
58
59 // s a w t o o t h wave s e q u e n c e
60
61 Fs = 20; // s a m p l e s p e r s e c o n d
62 t_total = 10; // s e c o n d s
63 n_samples = Fs * t_total ;
64 n = linspace (0 , t_total , n_samples ) ;
65 f =500; // sound f r e q u e n c y
66
67 saw_wave =2*( f *n - floor (0.5+ f * n ) ) ;
68
69 subplot (2 ,2 ,4) ;
70
71 plot2d3 (n , saw_wave ) ;
72 xlabel ( ”−−−−−−−−−−>Time I n d e x ” ) ;
73 ylabel ( ”−−−−−−−−−−−>A m p l i t u d e ” ) ;
74 title ( ”Saw t o o t h Wave S i g n a l S e q u e n c e ” ) ;
75
76
77 // I n p u t P a r a m e t e r s
78 // Enter Amplitude : 7
1 // E x p e r i m e n t Number : 2 . 3
2 // W r i t e a program t o g e n e r a t e T r i a n g u l a r and
S i n u s o i d a l S i g n a l s and S e q u e n c e s
3 // B a s i c S i m u l a t i o n L a b o r a t o r y
4 //B . Tech I I Year I Sem
5 // S t u d d e n t Name : E n r o l e m e n t Number :
6 // C o u r s e I n s t r u c t o r : Dr . K a n t i p u d i MVV Prasad ,
16
Figure 2.3: Generation Of Triangular and Sinusoidal Signal and Sequences
7 // S r e y a s I n s t i t u t e Of E n g i n e e r i n g & T e c h n l o g y ,
Hyderabad .
8 //
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
9
10
11 // OS : Windows 1 0 . 1
12 // S c i l a b 6 . 0 . 2
13
14
15 clc ;
16 close ;
17 clear ;
18
19 // T r i a n g u l a r Wave S i g n a l
20
21 Fs = 20; // s a m p l e s p e r s e c o n d
22 t_total = 100; // s e c o n d s
23 n_samples = Fs * t_total ;
24 t = linspace (0 , t_total , n_samples ) ;
25 f =40; // sound f r e q u e n c y
26
17
27 tri_wave =(2/ %pi ) * asin ( sin (2* %pi * f * t ) ) ;
28
29 subplot (2 ,2 ,1) ;
30
31 plot (t , tri_wave ) ;
32 xlabel ( ’−−−−−−−−−−>Time I n d e x t ( s e c . ) ’ ) ;
33 ylabel ( ’−−−−−−−−−−−>A m p l i t u d e ’ ) ;
34 title ( ’ T r i a n g u l a r Wave S i g n a l ’ ) ;
35
36 // t r a i a n g u l a r wave s e q u e n c e
37
38 Fs = 20; // s a m p l e s p e r s e c o n d
39 t_total = 10; // s e c o n d s
40 n_samples = Fs * t_total ;
41 n = linspace (0 , t_total , n_samples ) ;
42 f =40; // sound f r e q u e n c y
43
44 tri_wave =(2/ %pi ) * asin ( sin (2* %pi * f * n ) ) ;
45
46 subplot (2 ,2 ,2) ;
47 plot2d3 (n , tri_wave ) ;
48 xlabel ( ’−−−−−−−−−−>Time I n d e x t ( s e c . ) ’ ) ;
49 ylabel ( ’−−−−−−−−−−−>A m p l i t u d e ’ ) ;
50 title ( ’ T r i a n g u l a r Wave S e q u e n c e ’ ) ;
51
52
53 // c o n t i n u o u s S i n u s o i d a l S i g n a l
54
55 a = input ( ’ E n t e r a m p l i t u d e f o r S i n u s o i d a l S i g n a l : ’ );
56 t =0:0.001:1;
57 p = a * sin (2* %pi *10* t ) ;
58
59 subplot (2 ,2 ,3) ;
60 plot (t , p ) ;
61 title ( ’ S i n u s o i d a l S i g n a l ’ ) ;
62 xlabel ( ’ t i m e ’ ) ;
63 ylabel ( ’ a m p l i t u d e ’ ) ;
64
18
Figure 2.4: Generation Of Ramp and Sinc Signals and Sequences
65 // d i s c r e t e s i n u o i d a l s i g n a l
66
67 // a=i n p u t ( ’ E n t e r magnitude ’ ) ;
68 n = 0:100;
69 x = a * sin (((2*0.05) * %pi ) * n ) ;
70
71 subplot (2 ,2 ,4) ;
72 plot2d3 (n , x ) ;
73 title ( ” S i n u s o i d a l S e q u e n c e ” ) ;
74 xlabel ( ” s a m p l e s ” ) ;
75 ylabel ( ” m a g n i t u d e ” ) ;
76
77 // A f t e r G e t t i n g T r a i n a g u l a r wave o u t p u t
, v i s t the
command window t o e n t e r I n p u t P a r a m e t e r s
78 // Enter amplitude f o r S i n u s o i d a l S i g n a l : 5
Scilab code Solution 2.4 Generation Of Ramp and Sinc Signals and Se-
quences
19
1 // E x p e r i m e n t Number : 2 . 4
2 // W r i t e a program t o g e n e r a t e ramp and s i n c S i g n a l s
and S e q u e n c e s
3 // B a s i c S i m u l a t i o n L a b o r a t o r y
4 //B . Tech I I Year I Sem
5 // S t u d d e n t Name : E n r o l e m e n t Number :
6 // C o u r s e I n s t r u c t o r : Dr . K a n t i p u d i MVV Prasad ,
7 // S r e y a s I n s t i t u t e Of E n g i n e e r i n g & T e c h n l o g y ,
Hyderabad .
8 //
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
9
10 // OS : Windows 1 0 . 1
11 // S c i l a b 6 . 0 . 2
12
13
14 clc ;
15 close
16 clear ;
17
18 // c o n t i n u o u s ramp s i g n a l
19
20 t = 0 : 0.001 : 1;
21 y = 0.5 * t ;
22
23 subplot (2 ,2 ,1) ;
24 plot ( t , y ) ;
25 xlabel ( ’−−−−−−−−−>Time I n d e x t ( s e c . ) ’ ) ;
26 ylabel ( ’−−−−−−−−−>A m p l i t u d e ’ ) ;
27 title ( ’Ramp S i g n a l ’ ) ;
28
29 // d i s c r e t e ramp s i g n a l
30
31 n = 0 : 0.1 : 1;
32 y = 0.5 * n ;
33
34 subplot (2 ,2 ,2) ;
20
35 plot2d3 (n , y ) ;
36 xlabel ( ’−−−−−−−−−−>Time I n d e x n ’ ) ;
37 ylabel ( ’−−−−−−−−−−>A m p l i t u d e ’ ) ;
38 title ( ’Ramp S i g n a l S e q u e n c e ’ ) ;
39
40 // c o n t i n u o u s s i n c s i g n a l
41
42 t = linspace ( -10 , 10) ;
43 y = sinc ( t ) ;
44
45 subplot (2 ,2 ,3) ;
46 plot (t , y ) ;
47 xlabel ( ” Time I n d e x t ( s e c . ) ” ) ;
48 ylabel ( ” A m p l i t u d e ” ) ;
49 title ( ” S i n c S i g n a l ” ) ;
50
51 // d i s c r e t e s i n c s i g n a l
52
53 n = linspace ( -10 , 10) ;
54 y = sinc ( n ) ;
55
56 subplot (2 ,2 ,4) ;
57 plot2d3 (n , y ) ;
58 xlabel ( ” Time I n d e x n” ) ;
59 ylabel ( ” A m p l i t u d e ” ) ;
60 title ( ” S i n c S i g n a l S e q u e n c e ” ) ;
21
Experiment: 3
1 // E x p e r i m e n t Number : 3 . 1
2 // W r i t e a program t o p e r f o r m A d d i t i o n , M u l t i p l i c a t i o n
, F o l d i n g , S c a l i n g and s h i f t i n g o p e r a t i o n s on
v a r i o u s S i g n a l s and S e q u e n c e s
3 // B a s i c S i m u l a t i o n L a b o r a t o r y
4 //B . Tech I I Year I Sem
5 // S t u d d e n t Name : E n r o l e m e n t Number :
6 // C o u r s e I n s t r u c t o r : Dr . K a n t i p u d i MVV Prasad ,
7 // S r e y a s I n s t i t u t e Of E n g i n e e r i n g & T e c h n l o g y ,
Hyderabad .
8 //
22
Figure 3.1: Operations on Various Signals and Sequences
23
Figure 3.3: Operations on Various Signals and Sequences
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
9
10 // OS : Windows 1 0 . 1
11 // S c i l a b 6 . 0 . 2
12
13
14 clc ;
15 close
16 clear all ;
17
18
19 // A d d i t i o n
20
21 disp ( ’ E n t e r t h e i n p u t s e q u e n c e s t o p e r f o r m A d d i t i o n
Operation ’ );
22
23 x = input ( ’ E n t e r t h e s e q u e n c e A= ’ ) ;
24 y = input ( ’ E n t e r t h e s e q u e n c e B= ’ ) ;
25
26 m = length ( x ) ;
27 n = length ( y ) ;
28
24
29 if m == n then
30
31 z = x + y ;
32
33 disp (z , ’ A d d i t i o n r e s u l t o f two e q u a l l e n g t h
s e q u e n c e s := ’ ) ;
34
35 elseif m > n then
36
37 y =[ y , zeros (1 ,m - n ) ];
38
39 z = x + y ;
40
41 disp (z , ’ A d d i t i o n r e s u l t o f two u n e q u a l l e n g t h
s e q u e n c e s := ’ ) ;
42
43 else
44
45 x =[ x , zeros (1 ,n - m ) ];
46
47 z = x + y ;
48
49 disp (z , ’ A d d i t i o n r e s u l t o f two u n e q u a l l e n g t h
s e q u e n c e s := ’ ) ;
50
51 end
52
53
54 // M u l t i p l i c a t i o n
55
56 disp ( ’ E n t e r t h e i n p u t s e q u e n c e s t o p e r f o r m
m u l i p l i c a t i o n Operation ’ );
57
58 x = input ( ’ E n t e r t h e s e q u e n c e A= ’ ) ;
59 y = input ( ’ E n t e r t h e s e q u e n c e B= ’ ) ;
60
61 m = length ( x ) ;
62 n = length ( y ) ;
25
63
64 if m == n then
65
66 z = x .* y ;
67
68 disp (z , ’ M u l t i p l i c a t i o n r e s u l t o f two e q u a l
l e n g t h s e q u e n c e s := ’ ) ;
69
70 elseif m > n then
71
72 y =[ y , zeros (1 ,m - n ) ];
73
74 z = x .* y ;
75
76 disp (z , ’ M u l t i p l i c a t i o n r e s u l t o f two u n e q u a l
l e n g t h s e q u e n c e s := ’ ) ;
77
78 else
79
80 x =[ x , zeros (1 ,n - m ) ];
81
82 z = x .* y ;
83
84 disp (z , ’ M u l t i p l i c a t i o n r e s u l t o f two u n e q u a l
l e n g t h s e q u e n c e s := ’ ) ;
85
86 end
87
88
89 // F o l d i n g O p e r a t i o n
90
91 disp ( ’ E n t e r t h e i n p u t s e q u e n c e t o p e r f o r m F o l d i n g
Operation ’ );
92
93 x1 = input ( ’ E n t e r t h e i n p u t s e q u e n c e A := ’ ) ;
94 m = length ( x1 ) ;
95 s = input ( ’ E n t e r t h e s t a r t i n g p o i n t o f o r i g i n a l
s i g n a l= ’ );
26
96 h = s + m -1;
97 n = s :1: h ;
98
99 subplot (2 ,1 ,1)
100 plot (n , x1 )
101 plot2d3 (n , x1 )
102 xlabel ( ’ n===> ’ )
103 ylabel ( ’ Ampl i t u d e ’ )
104 title ( ’ O r i g i n a l S e q u e n c e ’ )
105
106 subplot (2 ,1 ,2)
107 disp ( n ) ;
108 disp ( - n ) ;
109 plot ( -n , x1 )
110 plot2d3 ( -n , x1 )
111 xlabel ( ’ n===> ’ )
112 ylabel ( ’ Ampl i t u d e ’ )
113 title ( ’ F o l d e d S e q u e n c e ’ )
114
115 // S c a l i n g O p e r a t i o n
116
117 disp ( ’ E n t e r t h e i n p u t s e q u e n c e t o p e r f o r m S c a l i n g
Operation ’ );
118
119 x2 = input ( ’ E n t e r i n p u t S e q u e n c e := ’ ) ;
120 m = length ( x2 ) ;
121 s = input ( ’ E n t e r s t a r t i n g p o i n t o f o r i g i n a l s i g n a l
:= ’ )
122 h = s +m -1;
123 n = s :1: h ;
124 C = input ( ’ E n t e r C o m p r e s s i o n Time S c a l i n g f a c t o r : =
’ )
125
126 n = s / C :1/ C : h / C ;
127 disp ( n ) ;
128 figure ;
129
130 subplot (2 ,1 ,1)
27
131 plot ( x2 )
132 plot2d3 ( x2 )
133 xlabel ( ’ n===> ’ )
134 ylabel ( ’ Ampl i t u d e ’ )
135 title ( ’ O r i g i n a l S e q u e n c e ’ )
136
137 subplot (2 ,1 ,2)
138 plot (n , x2 )
139 plot2d3 (n , x2 )
140 xlabel ( ’ n===> ’ )
141 ylabel ( ’ Ampl i t u d e ’ )
142 title ( ’ Time S c a l i n g − Compressed S e q u e n c e ’ )
143
144 // s h i f t i n g o p e r a t i o n
145
146 disp ( ’ E n t e r t h e i n p u t s e q u e n c e t o p e r f o r m s h i f t i n g
Operation ’ );
147
148 x3 = input ( ’ E n t e r t h e i n p u t s e q u e n c e := ’ )
149 m = length ( x3 ) ;
150 lx = input ( ’ E n t e r t h e s t a r t i n g p o i n t o f o r i g i n a l
s i g n a l := ’ )
151 hx = lx + m -1;
152 n = lx :1: hx ;
153
154 d = input ( ’ E n t e r t h e d e l a y := ’ )
155
156 figure ;
157
158 subplot (2 ,1 ,1)
159 plot (n , x3 )
160 plot2d3 (n , x3 ) ;
161 xlabel ( ’ n===> ’ )
162 ylabel ( ’ Ampl i t d u e ’ )
163 title ( ’ O r i g i n a l S e q u e n c e ’ )
164
165 n = lx + d :1: hx + d ;
166
28
167 subplot (2 ,1 ,2)
168 disp ( n ) ;
169 plot (n , x3 )
170 plot2d3 (n , x3 )
171 xlabel ( ’ n===> ’ )
172 ylabel ( ’ A m p l i t u d e ’ )
173 title ( ’ D e l a y e d S e q u e n c e ’ )
174
175
176
177 // E n t e r t h e i n p u t s e q u e n c e s t o p e r f o r m A d d i t i o n
Operation
178 // E n t e r t h e s e q u e n c e A= [ 1 3 5 7 9 ]
179 // E n t e r t h e s e q u e n c e B= [ 1 3 5 ]
180 // A d d i t i o n r e s u l t o f two u n e q u a l l e n g t h s e q u e n c e s :=
181 // 2 . 6. 10. 7. 9.
182 // E n t e r t h e i n p u t s e q u e n c e s t o p e r f o r m
m u l i p l i c a t i o n Operation
183 // E n t e r t h e s e q u e n c e A= [ 1 3 5 7 9 ]
184 // E n t e r t h e s e q u e n c e B= [ 1 3 5 ]
185 // M u l t i p l i c a t i o n r e s u l t o f two u n e q u a l l e n g t h s
e q u e n c e s :=
186 // 1 . 9. 25. 0. 0.
187
188 // E n t e r t h e i n p u t s e q u e n c e t o p e r f o r m F o l d i n g
Operation
189 // E n t e r t h e i n p u t s e q u e n c e A := [1 3 5 ]
190
191 // E n t e r t h e s t a r t i n g p o i n t o f o r i g i n a l s i g n a l =1
192 // 1. 2. 3.
193 // −1. −2. −3.
194
195 // E n t e r t h e i n p u t s e q u e n c e t o p e r f o r m S c a l i n g
Operation
196 // E n t e r i n p u t S e q u e n c e := [1 3 5 7 9]
197 // E n t e r s t a r t i n g p o i n t o f o r i g i n a l s i g n a l := 1
198
199 // E n t e r C o m p r e s s i o n Time S c a l i n g f a c t o r : = 0 . 5
29
200
201 // 2. 4. 6. 8. 10.
202
203 // E n t e r t h e i n p u t s e q u e n c e t o p e r f o r m s h i f t i n g
Operation
204 // E n t e r t h e i n p u t s e q u e n c e := [ 1 3 5 ]
205 // E n t e r t h e s t a r t i n g p o i n t o f o r i g i n a l s i g n a l := 1
206 // E n t e r t h e d e l a y := 0 . 4
207 // 1.4 2.4 3.4
Scilab code Solution 3.2 To perform Energy and Average Power Opera-
tions on Various Signals and Sequences
1 // E x p e r i m e n t Number : 3 . 2
2 // W r i t e a program t o p e r f o r m Energy and A v e r a g e
power o p e r a t i o n s on v a r i o u s S i g n a l s and S e q u e n c e s
3 // B a s i c S i m u l a t i o n L a b o r a t o r y
4 //B . Tech I I Year I Sem
5 // S t u d d e n t Name : E n r o l e m e n t Number :
6 // C o u r s e I n s t r u c t o r : Dr . K a n t i p u d i MVV Prasad ,
7 // S r e y a s I n s t i t u t e Of E n g i n e e r i n g & T e c h n l o g y ,
Hyderabad .
8 //
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
9
10 // OS : Windows 1 0 . 1
11 // S c i l a b 6 . 0 . 2
12
13
14 clc ;
15 close
16 clear ;
17
18
30
19
20 // Energy and A v e r a g e power o f t h e g i v e n s e q u e n c e
21
22 p = input ( ’ E n t e r t h e s e q u e n c e = ’ ) ;
23 M = length ( p ) ;
24 disp ( ’ The l e n g t h o f t h e E n t e r e d s e q u e n c e i s = ’ )
25 disp ( M )
26 sum = 0;
27 for i = 1: M ,
28 sum = sum +( i * i ) ;
29 end ;
30 disp ( ’ Energy o f t h e g i v e n s e q u e n c e i s = ’ ) ;
31 Energy = sum
32 disp ( Energy ) ;
33 disp ( ’ A v e r a g e Power o f t h e g i v e n s e q u e n c e i s = ’ ) ;
34 Average_power = sum / M
35 disp ( Average_power )
36
37 // Energy and A v e r a g e power o f a s i g n a l
38
39 t = 0:0.01:4;
40 s = cos (2* %pi * t ) ;
41 M = length ( s ) ;
42 disp ( ’ The l e n g t h o f t h e E n t e r e d S i g n a l i s = ’ )
43 disp ( M )
44
45 sum = 0;
46 for i = 1: M ,
47 sum = sum +( i * i ) ;
48 end ;
49 disp ( ’ Energy o f t h e g i v e n s i g n a l i s = ’ ) ;
50 Energy = sum
51 disp ( Energy )
52 disp ( ’ A v e r a g e Power o f t h e g i v e n s i g n a l i s = ’ ) ;
53 Average_power = sum / M
54 disp ( Average_power )
55
56
31
57
58 // E n t e r t h e s e q u e n c e = [ 1 3 5 7 9 ]
59
60
61 // The l e n g t h o f t h e E n t e r e d s e q u e n c e i s =
62
63 // 5.
64
65 // Energy o f t h e g i v e n s e q u e n c e i s =
66
67 // 55.
68
69 // A v e r a g e Power o f t h e g i v e n s e q u e n c e i s =
70
71 // 11.
72
73 // The l e n g t h o f t h e E n t e r e d S i g n a l i s =
74
75 // 401.
76
77 // Energy o f t h e g i v e n s i g n a l i s =
78
79 // 21574201.
80
81 // A v e r a g e Power o f t h e g i v e n s i g n a l i s =
82
83 // 5 3 8 0 1 .
32
Experiment: 4
Scilab code Solution 4.1 Finding Even and Odd Parts of the Signal
1 // E x p e r i m e n t Number : 4 . 1
2 // W r i t e a program t o f i n d Even and odd p a r t s o f t h e
signal
3 // B a s i c S i m u l a t i o n L a b o r a t o r y
4 //B . Tech I I Year I Sem
5 // S t u d d e n t Name : E n r o l e m e n t Number :
6 // C o u r s e I n s t r u c t o r : Dr . K a n t i p u d i MVV Prasad ,
7 // S r e y a s I n s t i t u t e Of E n g i n e e r i n g & T e c h n l o g y ,
Hyderabad .
8 //
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
9
10 // OS : Windows 1 0 . 1
11 // S c i l a b 6 . 0 . 2
33
12
13
14 clc ;
15 close
16 clear ;
17
18 // Even and odd p a r t s o f a s i g n a l
19
20 t =0:.005:4* %pi ;
21
22 x = sin ( t ) + cos ( t ) ; // x ( t )= s i n t ( t )+c o s ( t )
23
24 subplot (2 ,2 ,1)
25 plot2d3 (t , x )
26 xlabel ( ’ t ’ ) ;
27 ylabel ( ’ a m p l i t u d e ’ )
28 title ( ’ i n p u t S i g n a l f ( t ) ’ )
29
30 y = sin ( - t ) + cos ( -t ) // y=x(− t )
31 subplot (2 ,2 ,2)
32 plot2d3 (t , y )
33 xlabel ( ’ t ’ ) ;
34 ylabel ( ’ A m p l i t u d e ’ )
35 title ( ’ I n p u t S i g n a l f ( t )=−t ’ ) ;
36
37 z=x+y
38 subplot (2 ,2 ,3) ;
39 plot2d3 (t , z /2) ;
40 xlabel ( ’ t ’ ) ;
41 ylabel ( ’ A m p l i t u d e ’ ) ;
42 title ( ’ Even P a r t o f t h e s i g n a l ’ )
43
44 p =x - y ;
45 subplot (2 ,2 ,4)
46 plot2d3 (t , p /2)
47 xlabel ( ’ t ’ ) ;
48 ylabel ( ’ A m p l i t u d e ’ ) ;
49 title ( ’ Odd P a r t o f t h e s i g n a l ’ ) ;
34
Figure 4.1: Finding Even and Odd Parts of the Signal
Scilab code Solution 4.2 Finding Even and Odd Parts of Sequence
1 // E x p e r i m e n t Number : 4 . 2
2 // W r i t e a program t o f i n d Even and odd p a r t s o f
sequence
3 // B a s i c S i m u l a t i o n L a b o r a t o r y
4 //B . Tech I I Year I Sem
5 // S t u d d e n t Name : E n r o l e m e n t Number :
6 // C o u r s e I n s t r u c t o r : Dr . K a n t i p u d i MVV Prasad ,
7 // S r e y a s I n s t i t u t e Of E n g i n e e r i n g & T e c h n l o g y ,
Hyderabad .
8 //
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
9
10 // OS : Windows 1 0 . 1
11 // S c i l a b 6 . 0 . 2
35
12
13
14 clc ;
15 close ;
16 clear ;
17
18
19 // Even and Odd p a r t o f S e q u e n c e :
20
21 x = input ( ’ E n t e r t h e s e q u e n c e : ’ );
22
23 y = -x ;
24
25 subplot (2 ,2 ,1) ;
26 plot2d3 ( x ) ;
27 xlabel ( ’ Time −−−−> ’ ) ;
28 ylabel ( ’ A m p l i t u d e −−−−> ’ ) ;
29 title ( ’ O r i g i n a l s i g n a l f ( t ) ’ ) ;
30
31 subplot (2 ,2 ,2) ;
32 plot2d3 ( y ) ;
33 xlabel ( ’ Time −−−−> ’ ) ;
34 ylabel ( ’ A m p l i t u d e −−−−> ’ ) ;
35 title ( ’ O r i g i n a l s i g n a l f (− t ) ’ ) ;
36
37 even =0.5*( x + y ) ;
38
39 subplot (2 ,2 ,3) ;
40 plot ( even ) ;
41 xlabel ( ’ Time −−−−> ’ ) ;
42 ylabel ( ’ A m p l i t u d e −−−−> ’ ) ;
43 title ( ’ Even p a r t ’ ) ;
44
45 odd = 0.5*( x - y ) ;
46
47 subplot (2 ,2 ,4) ;
48 plot2d3 ( odd ) ;
49 xlabel ( ’ Time −−−−> ’ ) ;
36
Figure 4.2: Finding Even and Odd Parts of Sequence
50 ylabel ( ’ A m p l i t u d e −−−−> ’ ) ;
51 title ( ’ Odd p a r t ’ ) ;
52
53 // E n t e r t h e s e q u e n c e : [ 1 3 2 1 ]
Scilab code Solution 4.3 Finding Real and Imaginary parts of Signal or
Sequence
1 // E x p e r i m e n t Number : 4 . 3
2 // W r i t e a program t o f i n d r e a l and i m a g i n a r y p a r t s
of s i g n a l / Sequence
3 // B a s i c S i m u l a t i o n L a b o r a t o r y
4 //B . Tech I I Year I Sem
5 // S t u d d e n t Name : E n r o l e m e n t Number :
6 // C o u r s e I n s t r u c t o r : Dr . K a n t i p u d i MVV Prasad ,
37
Figure 4.3: Finding Real and Imaginary parts of Signal or Sequence
38
7 // S r e y a s I n s t i t u t e Of E n g i n e e r i n g & T e c h n l o g y ,
Hyderabad .
8 //
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
9
10 // OS : Windows 1 0 . 1
11 // S c i l a b 6 . 0 . 2
12
13
14 clc ;
15 close
16 clear ;
17
18
19 // R e a l and I m a g i n a r y p a r t s o f e v e n and odd s i g n a l :
20
21 x = input ( ’ E n t e r t h e c o m p l e x Numbers S e q u e n c e : ’ );
22 n = -3 : 3;
23 xc = conj ( x ) ;
24 xc_folded = xc (: , $ : -1 : 1) ;
25 xc_even = 0.5 * [ x + xc_folded ];
26 xc_odd = 0.5 * [ x - xc_folded ];
27
28 subplot (2 ,1 ,1) ;
29 plot2d3 ( n , real ( xc_even ) ) ;
30 title ( ’ R e a l p a r t o f e v e n s i g n a l xc ( n ) ’ )
31 xlabel ( ’ n ’ ) ;
32 ylabel ( ’ Magnitude o f R e a l ( xc−e v e n ) ’ ) ;
33
34 subplot (2 ,1 ,2) ;
35 plot2d3 ( n , imag ( xc_even ) )
36 title ( ’ I m a g i n a r y p a r t o f e v e n s i g n a l xc ( n ) ’ )
37 xlabel ( ’ n ’ ) ;
38 ylabel ( ’ Magnitude o f Imag ( xc−e v e n ) ’ ) ;
39
40 figure ;
41
39
42 subplot (2 ,1 ,1) ;
43 plot2d3 ( n , real ( xc_odd ) ) ;
44 title ( ’ R e a l p a r t o f odd s i g n a l xc ( n ) ’ )
45 xlabel ( ’ n ’ ) ;
46 ylabel ( ’ Magnitude o f R e a l ( xc−odd ) ’ ) ;
47
48 subplot (2 ,1 ,2) ;
49 plot2d3 ( n , imag ( xc_odd ) ) ;
50 title ( ’ I m a g i n a r y p a r t o f odd s i g n a l xc ( n ) ’ )
51 xlabel ( ’ n ’ ) ;
52 ylabel ( ’ Magnitude o f Imag ( xc−odd ) ’ ) ;
53
54 // E n t e r t h e c o m p l e x Numbers S e q u e n c e : [ 3 , 2+3∗%i ,
−3+2∗%i , 4−1∗%i , −2−3∗%i , 1−2∗%i , 1 ]
40
Experiment: 5
Scilab code Solution 5.1 Convolution of any two signals and sequences
1 // E x p e r i m e n t Number : 5
2 // W r i t e a program t o p e r f o r m c o n v o l u t i o n o f any two
s i g n a l s and s e q u e n c e s .
3 // B a s i c S i m u l a t i o n L a b o r a t o r y
4 //B . Tech I I Year I Sem
5 // S t u d d e n t Name : E n r o l e m e n t Number :
6 // C o u r s e I n s t r u c t o r : Dr . K a n t i p u d i MVV Prasad ,
7 // S r e y a s I n s t i t u t e Of E n g i n e e r i n g & T e c h n l o g y ,
Hyderabad .
8 //
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
9
10 // OS : Windows 1 0 . 1
11 // S c i l a b 6 . 0 . 2
12
13
14 clc ;
15 close
41
16 clear ;
17
18 // C o n v o l u t i o n o f two S e q u e n c e s
19
20 x = input ( ’ E n t e r t h e I n p u t S e q u e n c e : ’ ) ;
21 h = input ( ’ E n t e r t h e I m p u l s e S e q u e n c e : ’ ) ;
22
23 subplot (3 ,1 ,1) ;
24 plot2d3 ( x ) ;
25 plot ( x )
26 title ( ’ I n p u t S e q u e n c e ’ )
27 xlabel ( ’ n ’ ) ;
28 ylabel ( ’ x ( n ) ’ ) ;
29
30 subplot (3 ,1 ,2) ;
31 plot2d3 ( h ) ;
32 plot ( h ) ;
33 title ( ’ I m p u l s e S e q u e n c e ’ )
34 xlabel ( ’ n ’ ) ;
35 ylabel ( ’ h ( n ) ’ ) ;
36
37
38 Y = conv (x , h ) ;
39 disp ( ’ C o n v o l u t e d o u t p u t = ’ ) ;
40 disp ( Y ) ;
41 subplot (3 ,1 ,3) ;
42 plot2d3 ( Y ) ;
43 plot ( Y ) ;
44 title ( ” L i n e a r C o n v o l u t i o n o f two S e q u e n c e s ” ) ;
45 xlabel ( ’ n ’ ) ;
46 ylabel ( ’Y( n ) ’ ) ;
47
48
49 // C o n v o l u t i o n o f two S i g n a l s
50
51 t = 1:20;
52 x = sin ( t ) ;
53 h = squarewave ( t ) ;
42
54
55 figure () ;
56 subplot (3 ,1 ,1) ;
57 plot2d3 ( x ) ;
58 plot ( x ) ;
59 title ( ’ I n p u t S i g n a l ’ )
60 xlabel ( ’ n ’ ) ;
61 ylabel ( ’ x ( n ) ’ ) ;
62
63 subplot (3 ,1 ,2) ;
64 plot2d3 ( h ) ;
65 plot ( h ) ;
66 title ( ’ I m p u l s e R e s p o n s e ’ )
67 xlabel ( ’ n ’ ) ;
68 ylabel ( ’ h ( n ) ’ ) ;
69
70 o = conv (x , h ) ;
71
72 subplot (3 ,1 ,3) ;
73 plot2d3 ( o ) ;
74 plot ( o ) ;
75 title ( ” C o n v o l u t i o n o f two S i g n a l s ” ) ;
76
77 xlabel ( ’ n ’ ) ;
78 ylabel ( ’Y( n ) ’ ) ;
79
80 // I n p u t P a r a m a t e r s
81 // Enter the Input Sequence : [ 1 2 3 ]
82 // E n t e r t h e I m p u l s e S e q u e n c e : [ −1 2 2 ]
83 // Convoluted output =
84 // −1. 0. 3. 10. 6.
43
Figure 5.1: Convolution of any two signals and sequences
44
Experiment: 6
1 // E x p e r i m e n t Number : 6 . 1
2 // W r i t e a program t o compute Auto c o r r e l a t i o n and
C r o s s c o r r e l a t i o n b e t w e e n s i g n a l s and s e q u e n c e s .
3 // B a s i c S i m u l a t i o n L a b o r a t o r y
4 //B . Tech I I Year I Sem
5 // S t u d d e n t Name : E n r o l e m e n t Number :
6 // C o u r s e I n s t r u c t o r : Dr . K a n t i p u d i MVV Prasad ,
7 // S r e y a s I n s t i t u t e Of E n g i n e e r i n g & T e c h n l o g y ,
Hyderabad .
8 //
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
9
10 // OS : Windows 1 0 . 1
11 // S c i l a b 6 . 0 . 2
12
13
45
14 clc ;
15 close
16 clear ;
17
18 // Auto c o r r e l a t i o n o f a s e q u e n c e
19
20
21 a = input ( ’ E n t e r t h e s e q u e n c e ....:: ’ );
22
23 res = xcorr ( a ) ;
24
25 disp ( res ) ;
26
27 subplot (2 ,1 ,1) ;
28 plot2d3 ( a ) ;
29 xlabel ( ’−−−−> S a m p l e s ’ ) ;
30 ylabel ( ’−−−−> A m p l i t u d e ’ ) ;
31 title ( ’ I n p u t S e q u e n c e ’ ) ;
32
33 subplot (2 ,1 ,2) ;
34 plot2d3 ( res ) ;
35 xlabel ( ’−−−−> S a m p l e s ’ ) ;
36 ylabel ( ’−−−−> A m p l i t u d e ’ ) ;
37 title ( ’ Output S e q u e n c e ’ ) ;
38
39 // Auto c o r r e l a t i o n o f a s i g n a l
40
41
42 t = 0:0.01:2;
43 a = cos (2 * %pi * t ) ;
44 res = xcorr ( a ) ;
45
46 figure () ;
47
48 subplot (2 ,1 ,1) ;
49 plot ( a ) ;
50 xlabel ( ’−−−−> S a m p l e s ’ ) ;
51 ylabel ( ’−−−−> A m p l i t u d e ’ ) ;
46
Figure 6.1: Auto correlation of signals and sequences
52 title ( ’ I n p u t S e q u e n c e ’ ) ;
53
54 subplot (2 ,1 ,2) ;
55 plot ( res ) ;
56 xlabel ( ’−−−−> S a m p l e s ’ ) ;
57 ylabel ( ’−−−−> A m p l i t u d e ’ ) ;
58 title ( ’ Output S e q u e n c e ’ ) ;
59
60 // I n p u t Arguments
61
62 // E n t e r t h e s e q u e n c e ....:: [ 1 2 5 7]
63
64 // 7. 19. 47. 79. 47. 19. 7.
1 // E x p e r i m e n t Number : 6 . 2
47
Figure 6.2: Auto correlation of signals and sequences
2 // W r i t e a program t o compute C r o s s c o r r e l a t i o n
b e t w e e n s i g n a l s and s e q u e n c e s .
3 // B a s i c S i m u l a t i o n L a b o r a t o r y
4 //B . Tech I I Year I Sem
5 // S t u d d e n t Name : E n r o l e m e n t Number :
6 // C o u r s e I n s t r u c t o r : Dr . K a n t i p u d i MVV Prasad ,
7 // S r e y a s I n s t i t u t e Of E n g i n e e r i n g & T e c h n l o g y ,
Hyderabad .
8 //
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
9
10 // OS : Windows 1 0 . 1
11 // S c i l a b 6 . 0 . 2
12
13
14 clc ;
15 close
16 clear ;
17
18 // C r o s s c o r r e l a t i o n o f a two s e q u e n c e s
19
20 a = input ( ’ E n t e r t h e f i r s t s e q u e n c e . . . . : : ’ );
48
21 b = input ( ’ E n t e r t h e s e c o n d s e q u e n c e ...:: ’ );
22
23 r = xcorr (a , b ) ;
24
25 subplot (3 ,1 ,1) ;
26 plot2d3 ( a ) ;
27 xlabel ( ’−−−−> S a m p l e s ’ ) ;
28 ylabel ( ’−−−−> A m p l i t u d e ’ ) ;
29 title ( ’ I n p u t S e q u e n c e ( 1 ) ’ ) ;
30
31 subplot (3 ,1 ,2) ;
32 plot2d3 ( b ) ;
33 xlabel ( ’−−−−> S a m p l e s ’ ) ;
34 ylabel ( ’−−−−> A m p l i t u d e ’ ) ;
35 title ( ’ I n p u t S e q u e n c e ( 2 ) ’ ) ;
36
37 subplot (3 ,1 ,3) ;
38 plot2d3 ( r ) ;
39 xlabel ( ’−−−−> S a m p l e s ’ ) ;
40 ylabel ( ’−−−−> A m p l i t u d e ’ ) ;
41 title ( ’ C r o s s c o r r e l a t i o n o f a two s e q u e n c e s ’ ) ;
42
43 // C r o s s c o r r e l a t i o n o f a two s i g n a l s
44
45
46 t = 0:0.01:2;
47 a = cos (2 * %pi * t ) ;
48 b = sin (2 * %pi * t ) ;
49 res = xcorr (a , b ) ;
50 figure () ;
51
52 subplot (3 ,1 ,1) ;
53 plot ( a ) ;
54 xlabel ( ’−−−−> S a m p l e s ’ ) ;
55 ylabel ( ’−−−−> A m p l i t u d e ’ ) ;
56 title ( ’ I n p u t s i g n a l ( 1 ) ’ ) ;
57
58 subplot (3 ,1 ,2) ;
49
Figure 6.3: Cross correlation of signals and sequences
59 plot ( b ) ;
60 xlabel ( ’−−−−> S a m p l e s ’ ) ;
61 ylabel ( ’−−−−> A m p l i t u d e ’ ) ;
62 title ( ’ I n p u t S i g n a l ( 2 ) ’ ) ;
63
64 subplot (3 ,1 ,3) ;
65 plot ( res ) ;
66 xlabel ( ’−−−−> S a m p l e s ’ ) ;
67 ylabel ( ’−−−−> A m p l i t u d e ’ ) ;
68 title ( ’ C r o s s c o r r e l a t i o n o f a two s i g n a l s ’ ) ;
69
70 // E n t e r t h e f i r s t s e q u e n c e ....:: [ 1 2 3 7]
71
72 // E n t e r t h e s e c o n d s e q u e n c e ...:: [ 1 2 5 7]
50
Figure 6.4: Cross correlation of signals and sequences
51
Experiment: 7
1 // E x p e r i m e n t Number : 7 . 1
2 // W r i t e a program t o V e r i f y l i n e a r i t y p r o p e r t y o f a
given continuous / d i s c r e t e system .
3 // B a s i c S i m u l a t i o n L a b o r a t o r y
4 //B . Tech I I Year I Sem
5 // S t u d d e n t Name : E n r o l e m e n t Number :
6 // C o u r s e I n s t r u c t o r : Dr . K a n t i p u d i MVV Prasad ,
7 // S r e y a s I n s t i t u t e Of E n g i n e e r i n g & T e c h n l o g y ,
Hyderabad .
8 //
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
9
10
52
11 // OS : Windows 1 0 . 1
12 // S c i l a b 6 . 0 . 2
13
14 clc ;
15 clear all ;
16 close ;
17
18 // E n t e r two i n p u t s e q u e n c e s and i m p u l s e s e q u e n c e
19
20 x1 = input ( ’ E n t e r t h e s a m p l e s o f x1 ’ ) ;
21
22 x2 = input ( ’ E n t e r t h e s a m p l e s o f x2 ’ ) ;
23
24 if ( length ( x1 ) ~= length ( x2 ) )
25
26 disp ( ’ E r r o r . . . ! : L e n g t h s o f two i n p u t s e q u e n c e s [ x1
and x2 ] a r e d i f f e r e n t ’ ) ; return ;
27
28 end ;
29
30 h = input ( ’ E n t e r the samples o f h ’ );
31
32 // Length o f t h e o u t p u t s e q u e n c e
33
34 N = length ( x1 ) + length ( h ) -1;
35
36 disp ( ’ l e n g t h o f t h e o u t p u t s i g n a l w i l l be ’ ) ;
37
38 disp ( N ) ;
39
40 // E n t e r s c a l i n g f a c t o r s
41
42 a1 = input ( ’ The s c a l e f a c t o r a1 i s ’ );
43 a2 = input ( ’ The s c a l e f a c t o r a2 i s ’ );
44
45 x = a1 * x1 + a2 * x2 ;
46
47 // R e s p o n s e o f x and x1
53
48
49 yo1 = conv (x , h ) ;
50
51 y1 = conv ( x1 , h ) ;
52
53 // s c a l e d r e s p o n s e o f x1
54
55 y1s = a1 * y1 ;
56
57 // R e s p o n s e o f x2
58
59 y2 = conv ( x2 , h ) ;
60
61 // S c a l e d R e s p o n s e o f x2
62
63 y2s = a2 * y2 ;
64
65 yo2 = y1s + y2s ;
66
67 disp ( ’ I n p u t s i g n a l x1 i s ’ );
68 disp ( x1 ) ;
69
70 disp ( ’ I n p u t s i g n a l x2 i s ’ );
71 disp ( x2 ) ;
72
73 disp ( ’ Output S e q u e n c e yo1 i s ’ );
74 disp ( yo1 ) ;
75
76 disp ( ’ Output S e q u e n c e yo2 i s ’ ) ;
77 disp ( yo2 ) ;
78
79 if ( yo1 == yo2 )
80
81 disp ( ’ yo1 = yo2 . Hence t h e LTI s y s t e m i s LINEAR ’ )
82
83 end ;
84
85 // E n t e r t h e s a m p l e s o f x1 [ 1 5 7 9 ]
54
86
87 // E n t e r t h e s a m p l e s o f x2 [ 4 3 2 2 ]
88
89 // E n t e r the samples of h [1 2 2 2]
90
91
92 // l e n g t h o f t h e o u t p u t s i g n a l w i l l be
93
94 // 7 .
95 // The s c a l e f a c t o r a1 i s 2
96
97 // The s c a l e f a c t o r a2 i s 3
98
99
100 // I n p u t s i g n a l x1 i s
101
102 // 1. 5. 7. 9.
103
104 // I n p u t s i g n a l x2 i s
105
106 // 4. 3. 2. 2.
107
108 // Output S e q u e n c e yo1 i s
109
110 // 14. 47. 86. 130. 126. 88. 48.
111
112 // Output S e q u e n c e yo2 i s
113
114 // 14. 47. 86. 130. 126. 88. 48.
115
116 // yo1 = yo2 . Hence t h e LTI s y s t e m i s LINEAR
55
Figure 7.1: Verifying the Time Invariance Property of a given Discrete Sys-
tem
Figure 7.2: Verifying the Time Invariance Property of a given Discrete Sys-
tem
56
Scilab code Solution 7.2 Verifying the Time Invariance Property of a given
Discrete System
1 // E x p e r i m e n t Number : 7 . 2
2 // W r i t e a program t o V e r i f y t h e Time I n v a r i a n c e o f a
g i v e n D i s c r e t e System .
3 // B a s i c S i m u l a t i o n L a b o r a t o r y
4 //B . Tech I I Year I Sem
5 // S t u d d e n t Name : E n r o l e m e n t Number :
6 // C o u r s e I n s t r u c t o r : Dr . K a n t i p u d i MVV Prasad ,
7 // S r e y a s I n s t i t u t e Of E n g i n e e r i n g & T e c h n l o g y ,
Hyderabad .
8 //
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
9
10
11 // OS : Windows 1 0 . 1
12 // S c i l a b 6 . 0 . 2
13
14 clc ;
15 clear all ;
16 close ;
17
18 // E n t e r i n g two i n p u t s e q u e n c e s
19
20 x = input ( ’ E n t e r t h e s a m p l e s o f s i g n a l x ( n ) ’ ) ;
21 h = input ( ’ E n t e r t h e s a m p l e s o f s i g n a l h ( n ) ’ ) ;
22
23 // o r i g i n a l r e s p o n s e
24
25 y = conv (x , h ) ;
26
27 disp ( ’ E n t e r a POSITIVE number f o r d e l a y ’ ) ;
28
29 d = input ( ’ D e s i r e d d e l a y o f t h e s i g n a l i s ’ );
30
31 // D e l a y e d i n p u t
57
32
33 xd = [ zeros (1 , d ) , x ];
34
35 nxd = 0 : length ( xd ) -1;
36
37 // D e l a y e d o u t p u t
38
39 yd = conv ( xd , h ) ;
40
41 nyd = 0: length ( yd ) -1;
42
43 disp ( ’ O r i g i n a l I n p u t S i g n a l x ( n ) is ’ );
44 disp ( x ) ;
45 disp ( ’ D e l a y e d I n p u t S i g n a l xd ( n ) is ’ );
46 disp ( xd ) ;
47 disp ( ’ O r i g i n a l Output S i g n a l y ( n ) is ’ );
48 disp ( y ) ;
49 disp ( ’ D e l a y e d Output S i g n a l yd ( n ) is ’ );
50 disp ( yd ) ;
51
52 xp = [ x , zeros (1 , d ) ];
53 subplot (2 ,1 ,1) ;
54 plot2d3 ( nxd , xp ) ;
55 plot ( nxd , xp ) ;
56 xgrid (2) ;
57
58 xlabel ( ’ Time I n d e x n ’ ) ;
59 ylabel ( ’ x ( n ) ’ ) ;
60 title ( ’ O r i g i n a l I n p u t S i g n a l x ( n ) ’ ) ;
61
62 subplot (2 ,1 ,2) ;
63 plot2d3 ( nxd , xd ) ;
64 plot ( nxd , xd ) ;
65 xgrid (2)
66
67 xlabel ( ’ Time I n d e x n ’ ) ;
68 ylabel ( ’ xd ( n ) ’ ) ;
69 title ( ’ D e l a y e d I n p u t S i g n a l xd ( n ) ’ ) ;
58
70
71 yp = [ y zeros (1 , d ) ];
72
73 figure ;
74
75 subplot (2 ,1 ,1) ;
76 plot2d3 ( nyd , yp ) ;
77 plot ( nyd , yp ) ;
78 xgrid (2)
79
80 xlabel ( ’ Time I n d e x n ’ ) ;
81 ylabel ( ’ y ( n ) ’ ) ;
82 title ( ’ O r i g i n a l Output S i g n a l y ( n ) ’ );
83
84 subplot (2 ,1 ,2) ;
85 plot2d3 ( nyd , yd ) ;
86 plot ( nyd , yd ) ;
87 xgrid (2)
88
89 xlabel ( ’ Time I n d e x n ’ ) ;
90 ylabel ( ’ yd ( n ) ’ ) ;
91 title ( ’ D e l a y e d Output S i g n a l yd ( n ) ’ );
92
93
94 // Enter the samples o f s i g n a l x ( n ) [ 1 2 3 8 5 6]
95
96 // E n t e r t h e s a m p l e s o f s i g n a l h ( n ) [ 2 3 5 4 4 6]
97
98
99 // E n t e r a POSITIVE number f o r d e l a y
100 // D e s i r e d d e l a y o f t h e s i g n a l i s 2
101
102
103 // O r i g i n a l Input S i g n a l x (n) i s
104
105 // 1. 2. 3. 8. 5. 6.
106
107 // D e l a y e d I n p u t S i g n a l xd ( n ) i s
59
108
109 // 0. 0. 1. 2. 3. 8. 5. 6.
110
111 // O r i g i n a l Output S i g n a l y ( n ) i s
112
113 // 2. 7. 17. 39. 61. 93. 99. 100.
92. 54. 36.
114
115 // D e l a y e d Output S i g n a l yd ( n ) i s
116
117 // 0. 0. 2. 7. 17. 39. 61. 93. 99.
100. 92. 54. 36.
60
Experiment: 8
1 // E x p e r i m e n t Number : 8
2 // W r i t e a program t o compute t h e U n i t sample , u n i t
s t e p and s i n u s o i d a l r e s p o n s e o f t h e g i v e n LTI
s y s t e m and v e r i f y i n g i t s s t a b i l i t y .
3 // B a s i c S i m u l a t i o n L a b o r a t o r y
4 //B . Tech I I Year I Sem
5 // S t u d d e n t Name : E n r o l e m e n t Number :
6 // C o u r s e I n s t r u c t o r : Dr . K a n t i p u d i MVV Prasad ,
7 // S r e y a s I n s t i t u t e Of E n g i n e e r i n g & T e c h n l o g y ,
Hyderabad .
8 //
61
Figure 8.1: Verifying Stability of a given LTI System
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
9
10 // OS : Windows 1 0 . 1
11 // S c i l a b 6 . 0 . 2
12
13 // S t a b i l i t y o f a g i v e n LTI System :
14
15 clc ;
16 clear all ;
17 close ;
18
19 n =0:0.1:20;
20
21 h = input ( ” E n t e r t h e System E q u a t i o n : ” ) ; // 0 . 2 ∗ s i n
( 0 . 3 ∗ n ) . ∗ c o s ( 0 . 2 ∗ %pi ∗n )
22
23 sum =0;
24
25 for k =1:201
26 if abs ( h ( k ) ) <10^( -6)
27 end
28 sum = sum + h ( k ) ;
62
29 end
30 disp ( ’ The summation v a l u e i s . . . . : : ’ ) ;
31 disp ( sum ) ;
32
33 if sum > 5.0983 e +008
34 disp ( ’ The System i s u n s t a b l e ’ ) ;
35 else
36 disp ( ’ The System i s s t a b l e ’ ) ;
37 end ;
38 plot2d3 (n , h ) ;
39 xgrid (2) ;
40 xlabel ( ’ n===> ’ )
41 ylabel ( ’ h ( k )===> ’ )
42 title ( ’ S t a b i l i t y ’ )
43
44 // E n t e r t h e System E q u a t i o n : 0 . 2 ∗ s i n ( 0 . 3 ∗ n ) . ∗ c o s
( 0 . 2 ∗ %pi . ∗ ( n −1) )
45
46
47 // The summation v a l u e i s ....::
48
49 // 0.5909252
50
51 // The System i s s t a b l e
63
Experiment: 9
1
2 // E x p e r i m e n t Number : 9
3 // W r i t e a program t o v e r i f y t h e Gibbs phenomenon
4 // B a s i c S i m u l a t i o n L a b o r a t o r y
5 //B . Tech I I Year I Sem
6 // S t u d d e n t Name : E n r o l e m e n t Number :
7 // C o u r s e I n s t r u c t o r : Dr . K a n t i p u d i MVV Prasad ,
8 // S r e y a s I n s t i t u t e Of E n g i n e e r i n g & T e c h n l o g y ,
Hyderabad .
9 //
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
10
11 // OS : Windows 1 0 . 1
12 // S c i l a b 6 . 0 . 2
13
14 clc ;
15 clear all ;
16 close ;
64
Figure 9.1: Verifying the Gibbs phenomenon
17
18 J = 500 // number o f p o i n t s
19 x = linspace (0 ,2* %pi , J ) ;
20 f = sign ( x ) ; // r e t u r n s a r r a y same s i z e a s x
21 kp =0.* x ; // m u l t i p l i e s e v e r y t h i n g by x s t a r t i n g w i t h
0
22 t =150
23 for k =1:2: t
24 kp = kp +(1/2) * sin ( k * x ) / k ;
25 end
26
27 plot2d3 (x , kp ) ;
28 plot (x , kp ) ;
29 xlabel ( ’ t i m e ’ ) ;
30 ylabel ( ’ A m p l i t u d e ’ ) ;
31 title ( ’ Gibbs phenomenon ’ ) ;
65
Experiment: 10
Scilab code Solution 10.1 To find the Fourier Transform of a given signal
and plotting its magnitude and phase spectrum
1 // E x p e r i m e n t Number : 10
2 // W r i t e a program t o f i n d t h e F o u r i e r T r a n s f o r m o f a
g i v e n s i g n a l and p l o t t i n g i t s m a g n i t u d e and
phase spectrum .
3 // B a s i c S i m u l a t i o n L a b o r a t o r y
4 //B . Tech I I Year I Sem
5 // S t u d d e n t Name : E n r o l e m e n t Number :
6 // C o u r s e I n s t r u c t o r : Dr . K a n t i p u d i MVV Prasad ,
7 // S r e y a s I n s t i t u t e Of E n g i n e e r i n g & T e c h n l o g y ,
Hyderabad .
66
Figure 10.1: To find the Fourier Transform of a given signal and plotting its
magnitude and phase spectrum
Figure 10.2: To find the Fourier Transform of a given signal and plotting its
magnitude and phase spectrum
67
8 //
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
9
10 // OS : Windows 1 0 . 1
11 // S c i l a b 6 . 0 . 2
12
13 clc ;
14 clear all ;
15 close ;
16
17 f =150 // ( ’ F r e q u e n c y i n h e r t z s ’ ) ;
18 Fs =2000 // ( ’ S a m p l i n f f r e q i n khz ’ )
19 Ts =1/( Fs ) ;
20 N =128 // ( ’DFT s e q u e n c e ’ ) ;
21 n =[0: N -1]* Ts ;
22 x =0.8* cos (2* %pi * f * n ) ;
23 plot (n , x ) ;
24 set ( gca () ,” g r i d ” ,[1 1]) ;
25 data_bounds =([0 -1 ; 0.05 1]) ;
26 title ( ’ C o s i n e s i g n a l f r e q u e n c y ’ ) ;
27 xlabel ( ’ Time i n n ( s e c ) ’ ) ;
28 ylabel ( ’ A m p l i t u d e ’ ) ;
29 Y = fft ( x ) ;
30 w =0: N -1;
31 figure ;
32 Xmag = abs ( Y ) ;
33 subplot (2 ,1 ,1) ;
34 plot (w , Xmag ) ;
35 set ( gca () ,” g r i d ” ,[1 1]) ;
36 title ( ’ Magnitude o f f o u r i e r t r a n s f o r m ’ ) ;
37 xlabel ( ’ F r e q u e n c y i n d e x w−−−−−−−> ’ ) ;
38 ylabel ( ’ Magnitude −−−−−> ’ ) ;
39
40 Xphase = atan ( imag ( Y ) , real ( Y ) ) ;
41
42 subplot (2 ,1 ,2) ;
43 plot (w , Xphase ) ;
68
44 set ( gca () ,” g r i d ” ,[1 1]) ;
45 title ( ’ Phase o f f o u r i e r t r a n s f o r m ’ ) ;
46 xlabel ( ’ F r e q u e n c y i n d e x w−−−−−−−> ’ ) ;
47 ylabel ( ’ Phase −−−−−> ’ ) ;
69