







































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!








































(^1) Funded by a grant from the National Mission on Education through ICT,
http://spoken-tutorial.org/NMEICT-Intro. This Scilab Manual and Scilab codes written in it can be downloaded from the โMigrated Labsโ section at the website http://scilab.in
Scilab code Solution 1.1 Unit Sample Sequence
1 // C a p t i o n : U n i t Sample S e q u e n c e 2 clear ; 3 clc ; 4 close ; 5 L = 4; // U p p e r l i m i t 6 n = -L : L; 7 x = [ zeros (1 , L ) ,1 , zeros (1 , L ) ]; 8 b = gca () ; 9 b. y_location = โ m i d d l e โ ; 10 plot2d3 ( โ gnn โ ,n , x ) 11 a = gce () ; 12 a. children (1). thickness =4; 13 xtitle ( โ G r a p h i c a l R e p r e s e n t a t i o n o f U n i t Sample S e q u e n c e โ , โ n โ , โ x [ n ] โ ) ;
Scilab code Solution 1.2 Unit Step Sequence
1 // C a p t i o n : U n i t S t e p S e q u e n c e
Scilab code Solution 1.4 Exponentially Decreasing Signal
1 // C a p t i o n : E x p o n e n t i a l l y D e c r e a s i n g S i g n a l 2 clear ; 3 clc ; 4 close ; 5 a =0.5; 6 n = 0:10; 7 x = ( a ) ^n ; 8 a = gca () ; 9 a. x_location = โ o r i g i n โ ; 10 a. y_location = โ o r i g i n โ ; 11 plot2d3 ( โ gnn โ ,n , x ) 12 a. thickness = 2; 13 xtitle ( โ G r a p h i c a l R e p r e s e n t a t i o n o f E x p o n e n t i a l l y D e c r e a s i n g S i g n a l โ , โ n โ , โ x [ n ] โ ) ;
Scilab code Solution 1.5 Exponentially Increasing Signal
1 // C a p t i o n : E x p o n e n t i a l l y I n c r e a s i n g S i g n a l 2 clear ; 3 clc ; 4 close ; 5 a =1.5; 6 n =1:10; 7 x = ( a ) ^n ; 8 a = gca () ; 9 a. thickness = 2; 10 plot2d3 ( โ gnn โ ,n , x ) 11 xtitle ( โ G r a p h i c a l R e p r e s e n t a t i o n o f E x p o n e n t i a l l y I n c r e a s i n g S i g n a l โ , โ n โ , โ x [ n ] โ ) ;
Scilab code Solution 2.1 Program for Linear Convolution
1 // C a p t i o n : Program f o r L i n e a r C o n v o l u t i o n 2 clc ; 3 clear all ; 4 close ; 5 x = input ( โ e n t e r x s e q โ ) ; 6 h = input ( โ e n t e r h s e q โ ) ; 7 m = length ( x ) ; 8 n = length ( h ) ; 9 // Method 1 U s i n g D i r e c t C o n v o l u t i o n Sum Formula 10 for i = 1: n +m - 11 conv_sum = 0; 12 for j = 1: i 13 if ((( i - j +1) <= n ) &( j <= m ) ) 14 conv_sum = conv_sum + x ( j ) * h (i - j +1) ; 15 end ; 16 y ( i ) = conv_sum ; 17 end ; 18 end ; 19 disp (y โ, โ C o n v o l u t i o n Sum u s i n g D i r e c t Formula Method
Scilab code Solution 2.2 Program to find the Cicrcular Convolution
1 // C a p t i o n : Program t o f i n d t h e C i c r c u l a r C o n v o l u t i o n o f g i v e n 2 // d i s c r e t e s e q u e n c e s u s i n g M a t r i x method 3 4 clear ; 5 clc ; 6 x1 = [2 ,1 ,2 ,1]; // F i r s t s e q u e n c e 7 x2 = [1 ,2 ,3 ,4]; // Se c o n d s e q u e n c e 8 m = length ( x1 ) ; // l e n g t h o f f i r s t s e q u e n c e 9 n = length ( x2 ) ; // l e n g t h o f s e c o n d s e q u e n c e 10 //To make l e n g t h o f x1 and x2 a r e Equal 11 if ( m >n ) 12 for i = n +1: m 13 x2 ( i ) = 0; 14 end 15 elseif (n > m ) 16 for i = m +1: n 17 x1 ( i) = 0; 18 end 19 end 20 N = length ( x1 ) ; 21 x3 = zeros (1 , N ) ; // x3 = C i r c u l a r c o n v o l u t i o n r e s u l t 22 a (1) = x2 (1) ; 23 for j = 2: N 24 a ( j ) = x2 (N - j +2) ; 25 end 26 for i =1: N 27 x3 (1) = x3 (1) + x1 (i ) * a ( i ) ; 28 end 29 X (1 ,:) = a ; 30 // C a l c u l a t i o n o f c i r c u l a r c o n v o l u t i o n 31 for k = 2: N
32 for j =2: N 33 x2 ( j) = a (j -1) ; 34 end 35 x2 (1) = a ( N ) ; 36 X (k ,:) = x2 ; 37 for i = 1: N 38 a ( i ) = x2 ( i ) ; 39 x3 ( k) = x3 ( k ) + x1 ( i ) * a ( i ) ; 40 end 41 end 42 disp (X , โ C i r c u l a r C o n v o l u t i o n M a t r i x x2 [ n ]= โ ) 43 disp ( x3 , โ C i r c u l a r C o n v o l u t i o n R e s u l t x3 [ n ] = โ ) 44 // R e s u l t 45 // C i r c u l a r C o n v o l u t i o n M a t r i x x2 [ n ]= 46 // 47 // 1. 4. 3. 2. 48 // 2. 1. 4. 3. 49 // 3. 2. 1. 4. 50 // 4. 3. 2. 1. 51 // 52 // C i r c u l a r C o n v o l u t i o n R e s u l t x3 [ n ] = 53 // 54 // 1 4. 1 6. 1 4. 1 6.
20 // R e s u l t 21 // DFT o f x1 [ n ] i s X1 ( k )= 22 // 23 // 6. 0 2. 0 24 // 25 // DFT o f x1 [ n ] i s X2 ( k )= 26 // 27 // 1 0. โ 2. + 2. i โ 2. โ 2. โ 2. i 28 // 29 // DFT o f x3 [ n ] i s X3 ( k )= 30 // 31 // 6 0. 0 โ 4. 0 32 // 33 // C i r c u l a r C o n v o l u t i o n R e s u l t x3 [ n ]= 34 // 35 // 1 4. 1 6. 1 4. 1 6.
Scilab code Solution 4.1 Performing Linear Convolution using Circular Convolution
1 // C a p t i o n : P e r f o r m i n g L i n e a r C o n v o l u t i o n u s i n g C i r c u l a r C o n v o l u t i o n 2 3 clear ; 4 clc ; 5 close ; 6 h = [1 ,2 ,3]; // I m p u l s e R e s p o n s e o f LTI System 7 x = [1 ,2 ,2 ,1]; // I n p u t R e s p o n s e o f LTI System 8 N1 = length ( x ) ; 9 N2 = length ( h ) ; 10 N = N1 + N2 - 11 disp (N , โ Length o f Output R e s p o n s e y ( n ) โ ) 12 // Padding z e r o s t o Make Length o f โ h โ and โ x โ 13 // Equal t o l e n g t h o f o u t p u t r e s p o n s e โ y โ 14 h1 = [h , zeros (1 ,N - N2 ) ]; 15 x1 = [x , zeros (1 ,N - N1 ) ]; 16 // Computing FFT 17 H = fft (h1 , -1) ;
Scilab code Solution 5.5 Performing FFT and IFFT of a discrete sequence
1 // C a p t i o n : P e r f o r m i n g FFT and IFFT o f a d i s c r e t e s e q u e n c e 2 clear ; 3 clc ; 4 close ; 5 L = 4; // Length o f t h e S e q u e n c e 6 N = 4; // N โp o i n t DFT 7 x = [1 ,2 ,3 ,4]; 8 // Computing DFT 9 X = fft (x , -1) ; 10 disp (X , โFFT o f x [ n ] i s X( k )= โ ) 11 x = abs ( fft (X ,1) ) 12 disp (x , โ IFFT o f X( k ) i s x [ n ]= โ ) 13 // P l o t t i n g t h e s p e c t r u m o f D i s c r e t e S e q u e n c e 14 subplot (2 ,1 ,1) 15 a = gca () ; 16 a. data_bounds =[0 ,0;5 ,10]; 17 plot2d3 ( โ gnn โ ,0: length ( x ) -1 , x ) 18 b = gce () ;
19 b. children (1). thickness =3; 20 xtitle ( โ G r a p h i c a l R e p r e s e n t a t i o n o f D i s c r e t e S e q u e n c e โ , โ n โ , โ x [ n ] โ ) ; 21 subplot (2 ,1 ,2) 22 a = gce () ; 23 a. data_bounds =[0 ,0;5 ,10]; 24 plot2d3 ( โ gnn โ ,0: length ( X ) -1 , abs ( X ) ) 25 b = gce () ; 26 b. children (1). thickness =3; 27 xtitle ( โ G r a p h i c a l R e p r e s e n t a t i o n o f D i s c r e t e Spectrum โ , โ k โ , โX( k ) โ ) ; 28 // R e s u l t 29 //FFT o f x [ n ] i s X( k )= 30 // 31 // 1 0. โ 2. + 2. i โ 2. โ 2. โ 2. i 32 // 33 // IFFT o f X( k ) i s x [ n ]= 34 // 35 // 1. 2. 3. 4.
18 ylabel ( โ h ( t ) โ ) 19 title ( โ I m p u l s e R e p s o n s e o f I s t Order L i n e a r C o n s t a n t C o e f f. D i f f e r e n t i a l Equ. โ ) 20 // 21 // [ 2 ]. F i n d i n g F r e q u e n c y r e s p o n s e u s i n g 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 22 Wmax = 2* %pi *1; // Analog F r e q u e n c y = 1Hz 23 K = 4; 24 k = 0:( K /1000) : K ; 25 W = k * Wmax / K ; 26 HW = ht * exp ( - sqrt ( -1) t โ W ) * Dt ; 27 HW_Mag = abs ( HW ) ; 28 W = [ - mtlb_fliplr (W ) , W (2:1001) ]; // Omega from โ Wmax t o Wmax 29 HW_Mag = [ mtlb_fliplr ( HW_Mag ) , HW_Mag (2:1001) ]; 30 [ HW_Phase , db ] = phasemag ( HW ) ; 31 HW_Phase = [ - mtlb_fliplr ( HW_Phase ) , HW_Phase (2:1001) ]; 32 figure (2) 33 // P l o t t i n g Magnitude R e s p o n s e 34 subplot (2 ,1 ,1) ; 35 a = gca () ; 36 a. y_location = โ o r i g i n โ ; 37 plot (W , HW_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 (H(jW) ) โ ) 40 title ( โ Magnitude R e s p o n s e โ ) 41 // P l o t t i n g Phase Reponse 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 , HW_Phase * %pi /180) ; 47 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โ ) ; 48 ylabel ( โ <H (jW) โ )
49 title ( โ Phase R e s p o n s e i n R a d i a n s โ )