Scilab Manual for DIGITAL SIGNAL PROCESSING by Prof Desai Siddhibahen Deveshbhai Others Laxmi Institute Of Technology,sarigam1 Solutions provided by Prof Desai Siddhibahen Deveshbhai Others Laxmi Institute Of Technology,sarigam April 6, 2023 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 1 Contents List of Scilab Solutions 4 1 WRITE A SCILAB PROGRAM TO GENERATE COMMON DISCRETE TIME SIGNALS. 7 2 WRITE A SCILAB PROGRAM TO OBSERVE THE EFFECTS OF LOWER SAMPLING RATE AND HIGHER SAMPLING RATE ON C.T. SIGNAL(SAMPLING THM.) 11 3 WRITE A SCILAB PROGRAM TO COMPUTE LINEARITY PROPERTY OF A GIVEN SIGNAL. 15 4 WRITE A SCILAB PROGRAM TO COMPUTE LINEAR CONVOLUTION OF TWO SEQUENCES USING BASIC EQUATION. 18 5 WRITE A SCILAB PROGRAM TO FIND AUTOCORRELATION AND CROSS CORRELATION OF THE GIVEN SEQUENCES. 22 6 WRITE A SCILAB PROGRAM TO FIND N-POINT DFT OF THE GIVEN SEQUENCE. 26 7 WRITE A SCILAB PROGRAM TO COMPUTE LINEAR CONVOLUTION OF TWO SEQUENCES USING DFT BASED APPROACH. 31 8 WRITE A SCILAB PROGRAM TO COMPUTE CIRCULAR CONVOLUTION OF TWO SEQUECNES USING BA2 SIC EQUATION. 34 9 WRITE A SCILAB PROGRAM TO COMPUTE CIRCULAR CONVOLUTION OF THE TWO SEQUENCES USING DFT BASED APPROACH. 38 10 WRITE A SCILAB PROGRAM TO COMPUTE BLOCK CONVOLUTION USING OVERLAP ADD METHOD 42 11 WRITE A SCILAB PROGRAM RO COMPUTE BLOCK CONVOLUTION USING OVERLAP SAVE METHOD. 46 12 WRITE A SCILAB PROGRAM TO FIND FFT USING DECIMATION IN TIME(DIT) METHOD. 50 13 WRITE A SCILAB PROGRAM FOR DESIGNING OF FIR FILTER FOR LOW PASS, HIGH PASS, BANDPASS AND BAND REJECT RESPONSES. 54 14 WRITE A SCILAB PROGRAM TO DESIGN DIGITAL IIR BUTTERWORTH LOW PASS FILTER. 62 15 WRITE A SCILAB PROGRAM TO DESIGN DIGITAL IIR CHEBYSHEW FILTER. 64 3 List of Experiments Solution 1.01 PROGRAM TO GENERATE COMMON DISCRETE TIME SIGNALS . . . . . . . . . . . . . . . . . . 7 Solution 2.02 PROGRAM TO OBSERVE THE EFFECTS OF LOWER SAMPLING RATE AND HIGHER SAMPLING RATE ON CONTINUOUS TIME SIGNAL 11 Solution 3.03 PROGRAM TO COMPUTE LINEARITY PROPERTY OF GIVEN SIGNAL . . . . . . . . . . . . 15 Solution 4.04 PROGRAM TO COMPUTE LINEAR CONVOLUTION OF TWO SEQUENCES USING BASIC EQUATION . . . . . . . . . . . . . . . . . . . . . 18 Solution 5.05 PROGRAM TO FIND AUTO CORRELATION AND CROSS CORRELATION OF THE GIVEN SEQUENCES Solution 6.06 PROGRAM TO FIND N POINT DFT OF THE GIVEN SEQUENCE . . . . . . . . . . . . . . . . 26 Solution 7.07 PROGRAM TO COMPUTE LINEAR CONVOLUTION OF TWO SEQUENCES USING DFT BASED APPROACH . . . . . . . . . . . . . . . . . . . . 31 Solution 8.08 PROGRAM TO COMPUTE CIRCULAR CONVOLUTION OF TWO SEQUENCES USING BASIC EQUATION . . . . . . . . . . . . . . . . . . 34 Solution 9.09 PROGRAM TO COMPUTE CIRCULAR CONVOLUTION OF THE TWO SEQUENCES USING DFT BASED APPROACH . . . . . . . . . . . . 38 Solution 10.10 PROGRAM TO COMPUTE BLOCK CONVOLUTION USING OVERLAP ADD METHOD . . . . 42 Solution 11.11 PROGRAM TO COMPUTE BLOCK CONVOLUTION USING OVERLAP SAVE METHOD . . . 46 4 22 Solution 12.12 PROGRAM TO FIND FFT USING DECIMATION IN TIME METHOD . . . . . . . . . . . . . . . . 50 Solution 13.13 PROGRAM FOR DESIGNING OF FIR FILTER FOR LOW PASS HIGH PASS BAND PASS AND BAND REJECT RESPONSES . . . . . . . . . . 54 Solution 14.14 PROGRAM TO DESIGN DIGITAL IIR BUTTERWORTH LOW PASS FILTER . . . . . . . . . . . 62 Solution 15.15 PROGRAM TO DESIGN DIGITAL IIR CHEBYSHEW FILTER . . . . . . . . . . . . . . . . . . . . . . . 64 5 List of Figures 6 Experiment: 1 WRITE A SCILAB PROGRAM TO GENERATE COMMON DISCRETE TIME SIGNALS. Scilab code Solution 1.01 PROGRAM TO GENERATE COMMON DISCRETE TIME SIGNALS 1 2 3 // VERSION : S c i l a b : 5 . 4 . 1 // OS : windows 7 // CAPTION : PROGRAM TO GENERATE COMMON DISCRETE TIME SIGNALS 4 5 clc ; 6 clear ; 7 close ; 8 9 //UNIT IMPULSE SIGNAL 10 L = input ( ’ E n t e r t h e Length= ’ ) ; //SET LIMIT 11 n = - L : L ; 7 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 x =[ zeros (1 , L ) , ones (1 ,1) , zeros (1 , L ) ]; subplot (2 ,4 ,1) ; a = gca () ; a . y_location = ” o r i g i n ” ; a . foreground = 5; a . font_color = 5; a . font_style = 5; plot2d3 (n , x ) title ( ’ U n i t I m p u l s e S i g n a l ’ ) ; xlabel ( ’ S a m p l e s n ’ ) ; ylabel ( ’ A m p l i t u d e ’ ) ; // UNIT STEP SIGNAL y =[ zeros (1 , L ) , ones (1 , L +1) ]; subplot (3 ,4 ,2) ; b = gca () ; b . y_location = ” m i d d l e ” ; b . foreground = 5; b . font_color = 5; b . font_style = 5; plot2d3 (n , y ) title ( ’ U n i t S t e p S i g n a l ’ ) ; xlabel ( ’ S a m p l e s n ’ ) ; ylabel ( ’ A m p l i t u d e ’ ) ; //UNIT RAMP SIGNAL z =[ zeros (1 , L ) ,0: L ] , subplot (2 ,4 ,3) c = gca () ; c . y_location = ” m i d d l e ” ; c . foreground = 5; c . font_color = 5; c . font_style = 5; plot2d3 (n , z ) title ( ’ U n i t Ramp S i g n a l ’ ) ; xlabel ( ’ S a m p l e s n ’ ) ; ylabel ( ’ A m p l i t u d e ’ ) ; 8 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 // EXPONENTIALLY INCREASING SEQUENCE n =0:1:10; x = exp ( n ) ; subplot (2 ,4 ,4) ; d = gca () ; d . x_location = ” o r i g i n ” ; d . y_location = ” o r i g i n ” ; d . foreground = 5; d . font_color = 5; d . font_style = 5; plot2d3 (n , x ) title ( ’ E x p o n e n t i a l l y I n c r e a s i n g S e q u e n c e ’ ) ; xlabel ( ’ S a m p l e s n ’ ) ; ylabel ( ’ A m p l i t u d e ’ ) ; // EXPONENTIALLY DECREASING SEQUENCE n =0:1:10; x = exp ( - n ) ; subplot (2 ,4 ,5) ; d = gca () ; d . x_location = ” o r i g i n ” ; d . y_location = ” o r i g i n ” ; d . foreground = 5; d . font_color = 5; d . font_style = 5; plot2d3 (n , x ) title ( ’ E x p o n e n t i a l l y D e c r e a s i n g S e q u e n c e ’ ) ; xlabel ( ’ S a m p l e s n ’ ) ; ylabel ( ’ A m p l i t u d e ’ ) ; // SINE WAVE t =0:0.04:1; x = sin (2* %pi * t ) ; subplot (2 ,4 ,6) ; a = gca () ; a . foreground = 5; a . font_color = 5; 9 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 a . font_style = 5; plot2d3 (t , x ) ; title ( ’ S i n e Wave ’ ) xlabel ( ’ S a m p l e s n ’ ) ; ylabel ( ’ A m p l i t u d e ’ ) ; // COSINE WAVE t =0:0.04:1; x = cos (2* %pi * t ) ; subplot (2 ,4 ,7) ; b = gca () ; b . foreground = 5; b . font_color = 5; b . font_style = 5; plot2d3 (t , x ) ; title ( ’ C o s i n e Wave ’ ) xlabel ( ’ S a m p l e s n ’ ) ; ylabel ( ’ A m p l i t u d e ’ ) ; //INPUT : // E n t e r t h e Length=5 10 Experiment: 2 WRITE A SCILAB PROGRAM TO OBSERVE THE EFFECTS OF LOWER SAMPLING RATE AND HIGHER SAMPLING RATE ON C.T. SIGNAL(SAMPLING THM.) Scilab code Solution 2.02 PROGRAM TO OBSERVE THE EFFECTS OF LOWER SAMPLING RATE AND HIGHER SAMPLING RATE ON CONTINUOUS TIME SIGNAL 1 2 3 // VERSION : S c i l a b : 5 . 4 . 1 // OS : windows 7 //CAPTION : PROGRAM TO OBSERVE THE EFFECTS OF LOWER SAMPLING RATE AND 11 4 // HIGHER SAMPLING RATE ON C . T . SIGNAL (SAMPLING THM .) 5 6 clc ; 7 clear ; 8 close ; 9 f = input ( ’ E n t e r c o n t i n u o u s t i m e s i g n a l 10 f r e q u e n c y= ’ ) ; // f =0.1 a = input ( ’ E n t e r c o n t i n u o u s t i m e s i g n a l a m p l i t u d e= ’ ) ; // a=1 t =0:0.01:100; x = a * sin (2* %pi * f * t ) ; subplot (2 ,2 ,1) ; b = gca () ; b . x_location = ” o r i g i n ” ; b . y_location = ” o r i g i n ” ; b . foreground = 5; b . font_color = 5; b . font_style = 5; plot (t , x ) ; title ( ’ O r i g i n a l C o n t i n u o u s t i m e S i g n a l ’ ) ; xlabel ( ’ Time t ’ ) ; ylabel ( ’ A m p l i t u d e ’ ) ; 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 // S a m p l i n g Rate =2∗max f r e q u e n c y 26 fs1 = input ( ’ E n t e r s a m p l i n g f r e q u e n c y e q u a l t o 2∗ f s = ’ ) 27 28 29 30 31 32 33 34 35 36 37 ; // f s 1 =0.2 fd = f / fs1 ; n =0:0.01:100; x1n = a * sin (2* %pi * f * n / fs1 ) ; subplot (2 ,2 ,2) ; b = gca () ; b . x_location = ” o r i g i n ” ; b . y_location = ” o r i g i n ” ; b . foreground = 5; b . font_color = 5; b . font_style = 5; plot2d3 ( ’ gnn ’ ,n , x1n ) ; 12 title ( ’ R e c o n s t r u c t e d s i g n a l w i t h s a m p l i n g f r e q u e n c y e q u a l 2∗ f s ’ ) ; 39 xlabel ( ’ Time t ’ ) ; 40 ylabel ( ’ A m p l i t u d e ’ ) ; 38 41 42 43 // S a m p l i n g Rate <2∗max f r e q u e n c y= A l i a s i n g E f f e c t 44 fs2 = input ( ’ E n t e r s a m p l i n g f r e q u e n c y l e s s t h a n 2∗ f s = ’ ) ; // f s 2 =0.1 x2n = a * sin (2* %pi * f * n / fs2 ) ; subplot (2 ,2 ,3) ; b = gca () ; b . x_location = ” o r i g i n ” ; b . y_location = ” o r i g i n ” ; b . foreground = 5; b . font_color = 5; b . font_style = 5; plot2d3 ( ’ gnn ’ ,n , x2n ) ; title ( ’ R e c o n s t r u c t e d s i g n a l w i t h s a m p l i n g f r e q u e n c y L e s s t h a n 2∗ f s =A l i a s i n g e f f e c t ’ ) ; 55 xlabel ( ’ Time t ’ ) ; 56 ylabel ( ’ A m p l i t u d e ’ ) ; 45 46 47 48 49 50 51 52 53 54 57 58 59 60 61 62 63 64 65 66 67 68 69 // S a m p l i n g Rate >2∗max f r e q u e n c y=P e r f e c t Reconstuection fs3 = input ( ’ E n t e r s a m p l i n g f r e q u e n c y G r e a t e r t h a n 2∗ f s = ’ ) ; // f s 3 =1 x3n = a * sin (2* %pi * f * n * fs3 ) ; subplot (2 ,2 ,4) ; b = gca () ; b . x_location = ” o r i g i n ” ; b . y_location = ” o r i g i n ” ; b . foreground = 5; b . font_color = 5; b . font_style = 5; plot2d3 ( ’ gnn ’ ,n , x3n ) ; title ( ’ P e r f e c t R e c o n s t r u c t e d s i g n a l w i t h s a m p l i n g f r e q u e n c y g r e a t e r t h a n 2∗ f s ’ ) ; 13 70 71 72 73 74 75 76 77 78 xlabel ( ’ Time t ’ ) ; ylabel ( ’ A m p l i t u d e ’ ) ; //INPUT : // E n t e r c o n t i n u o u s t i m e s i g n a l f r e q u e n c y =0.1 // E n t e r c o n t i n u o u s t i m e s i g n a l a m p l i t u d e =1 // E n t e r s a m p l i n g f r e q u e n c y e q u a l t o 2∗ f s =0.2 // E n t e r s a m p l i n g f r e q u e n c y l e s s t h a n 2∗ f s =0.1 // E n t e r s a m p l i n g f r e q u e n c y G r e a t e r t h a n 2∗ f s =1 14 Experiment: 3 WRITE A SCILAB PROGRAM TO COMPUTE LINEARITY PROPERTY OF A GIVEN SIGNAL. Scilab code Solution 3.03 PROGRAM TO COMPUTE LINEARITY PROPERTY OF GIVEN SIGNAL 1 2 3 4 5 6 7 8 9 10 // VERSION : S c i l a b : 5 . 4 . 1 // OS : windows 7 // CAPTION : PROGRAM TO COMPUTE LINEARITY PROPERTY OF A GIVEN SIGNAL // I n p u t S e q u e n c e : x1 ( n )=s i n ( 2 %pi0 . 1 n ) and x2 ( n )= c o s ( 2 %pi0 . 5 n ) and s y s t e m y ( n ) =0.5 x ( n ) clc ; clear ; close ; n =0:10; a =2; b =3; 15 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 x1 = sin (2* %pi *0.1* n ) ; // i n p u t s e q u e n c e 1 x2 = cos (2* %pi *0.5* n ) ; // i n p u t s e q u e n c e 2 x = a .* x1 + b .* x2 ; // h o m o g e n i t y and s u p e r p o s i t i o n −−op1 y =0.5* x ; // s y s t e m y =0.5∗ x y1 =0.5* x1 ; y2 =0.5* x2 ; yt = a .* y1 + b .* y2 ; // h o m o g e n i t y and s u p e r p o s i t i o n −−op2 d =y - yt ; // op2−op1= d i f f e r e n c e disp ( ’ Output o f System y ( n ) =0.5 x ( n ) i s : ’ ) ; if ( d ==0) disp ( ’ System i s l i n e a r ’ ) ; else disp ( ’ System i s Non− l i n e a r ’ ) ; end // I n p u t S e q u e n c e : x1 ( n )=s i n ( 2 %pi0 . 1 n ) and x2 ( n )= c o s ( 2 %pi0 . 5 n ) and s y s t e m y ( n )=s q r t ( x ( n ) ) n =0:10; a =2; b =3; x1 = sin (2* %pi *0.1* n ) ; // i n p u t s e q u e n c e 1 x2 = cos (2* %pi *0.5* n ) ; // i n p u t s e q u e n c e 2 x = a .* x1 + b .* x2 ; // h o m o g e n i t y and s u p e r p o s i t i o n −−op1 y = sqrt ( x ) ; // s y s t e m y=s q r t ( x ) y1 = sqrt ( x1 ) ; y2 = sqrt ( x2 ) ; yt = a .* y1 + b .* y2 ; // h o m o g e n i t y and s u p e r p o s i t i o n −−op2 d =y - yt ; // op2−op1= d i f f e r e n c e disp ( ’ Output o f System y ( n )=s q r t ( x ( n ) ) i s : ’ ) ; if ( d ==0) disp ( ’ System i s l i n e a r ’ ) ; else disp ( ’ System i s Non− l i n e a r ’ ) ; end //OUTPUT: // Output o f System y ( n ) =0.5 x ( n ) i s : 16 48 49 50 51 52 53 // System i s l i n e a r // Output o f System y ( n )=s q r t ( x ( n ) ) i s : // System i s Non− l i n e a r 17 Experiment: 4 WRITE A SCILAB PROGRAM TO COMPUTE LINEAR CONVOLUTION OF TWO SEQUENCES USING BASIC EQUATION. Scilab code Solution 4.04 PROGRAM TO COMPUTE LINEAR CONVOLUTION OF TWO SEQUENCES USING BASIC EQUATION 1 2 3 4 5 6 7 8 // VERSION : S c i l a b : 5 . 4 . 1 // OS : windows 7 //CAPTION : PROGRAM TO COMPUTE LINEAR CONVOLUTION OF TWO SEQUENCES USING BASIC EQUATION clc ; clear ; close ; // i n p u t s e q u e n c e s x = input ( ’ E n t e r t h e I n p u t S e q u e n c e x ( n )= ’ ) // x =[1 2 3 1] 18 9 m = length ( x ) ; 10 xl = input ( ’ E n t e r t h e l o w e r i n d e x o f I n p u t S e q u e n c e= ’ ) // 0 xh = xl +m -1; n = xl :1: xh ; subplot (3 ,1 ,1) ; a = gca () ; a . x_location = ” o r i g i n ” ; a . y_location = ” o r i g i n ” ; a . foreground = 5; a . font_color = 5; a . font_style = 5; plot2d3 ( ’ gnn ’ ,n , x ) ; title ( ’ I n p u t S e q u e n c e x [ n ] ’ ) ; xlabel ( ’ S a m p l e s n ’ ) ; ylabel ( ’ A m p l i t u d e ’ ) ; 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 h = input ( ’ E n t e r t h e I m p u l s e r e s p o n s e S e q u e n c e h ( n )= ’ ) 26 27 ; // h =[1 2 1 −1] l = length ( h ) ; hl = input ( ’ E n t e r t h e l o w e r i n d e x o f I m p u l s e r e s p o n s e S e q u e n c e= ’ ) ; //−1 hh = hl +l -1; g = hl :1: hh ; subplot (3 ,1 ,2) ; a = gca () ; a . x_location = ” o r i g i n ” ; a . y_location = ” o r i g i n ” ; a . foreground = 5; a . font_color = 5; a . font_style = 5; plot2d3 ( ’ gnn ’ ,n , h ) ; title ( ’ I m p u l s e R e s p o n s e S e q u e n c e h [ n ] ’ ) ; xlabel ( ’ S a m p l e s n ’ ) ; ylabel ( ’ A m p l i t u d e ’ ) ; 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 nx = xl + hl ; // r a n g e o f k 43 nh = xh + hh ; // r a n g e o f n 19 44 x =[ x , zeros (1 , l ) ]; 45 h =[ h , zeros (1 , m ) ]; 46 y = zeros (1 , m +l -1) // n1+n2−1= l e n g t h 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 of linear convolution for i =1: m +l -1 y ( i ) =0; for j =1: m +l -1 if (j < i +1) y ( i ) = y ( i ) + x ( j ) * h (i - j +1) ; end end end disp ( ’ L i n e a r C o n v o l u t i o n u s i n g E q u a t i o n i s y ( n ) : ’ ) disp ( y ) ; r = nx : nh ; subplot (3 ,1 ,3) ; a = gca () ; a . x_location = ” o r i g i n ” ; a . y_location = ” o r i g i n ” ; a . foreground = 5; a . font_color = 5; a . font_style = 5; plot2d3 ( ’ gnn ’ ,r , y ) ; title ( ’ Output R e s p o n s e S e q u e n c e o f L i n e a r Convolution u s i n g Equation y [ n ] ’ ); xlabel ( ’ S a m p l e s n ’ ) ; ylabel ( ’ A m p l i t u d e ’ ) ; //INPUT : // E n t e r t h e I n p u t S e q u e n c e x ( n ) =[1 2 3 1 ] // E n t e r t h e l o w e r i n d e x o f I n p u t S e q u e n c e =0 // E n t e r t h e I m p u l s e r e s p o n s e S e q u e n c e h ( n ) =[1 2 1 −1] // E n t e r t h e l o w e r i n d e x o f I m p u l s e r e s p o n s e S e q u e n c e =−1 //OUTPUT: // L i n e a r C o n v o l u t i o n u s i n g E q u a t i o n i s y ( n ) : 20 78 // 1 . 4. 8. 8. 21 3. − 2. − 1. Experiment: 5 WRITE A SCILAB PROGRAM TO FIND AUTOCORRELATION AND CROSS CORRELATION OF THE GIVEN SEQUENCES. Scilab code Solution 5.05 PROGRAM TO FIND AUTO CORRELATION AND CROSS CORRELATION OF THE GIVEN SEQUENCES 1 2 3 4 5 6 7 8 9 // VERSION : S c i l a b : 5 . 4 . 1 // OS : windows 7 //CAPTION : PROGRAM TO FIND AUTOCORRELATION AND CROSSCORRELATION OF THE GIVEN SEQUENCES clc ; clear ; close ; x = input ( ’ E n t e r t h e I n p u t S e q u e n c e= ’ ) // x =[1 2 3 1 ] m = length ( x ) ; xl = input ( ’ E n t e r t h e l o w e r i n d e x o f I n p u t S e q u e n c e= ’ ) 22 // 0 xh = xl +m -1; n = xl :1: xh ; subplot (2 ,2 ,1) ; a = gca () ; a . x_location = ” o r i g i n ” ; a . y_location = ” o r i g i n ” ; a . foreground = 5; a . font_color = 5; a . font_style = 5; plot2d3 ( ’ gnn ’ ,n , x ) ; title ( ’ I n p u t S e q u e n c e x [ n ] ’ ) ; xlabel ( ’ S a m p l e s n ’ ) ; ylabel ( ’ A m p l i t u d e ’ ) ; 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 h = input ( ’ E n t e r t h e I m p u l s e r e s p o n s e S e q u e n c e= ’ ) ; // h =[1 2 1 1 ] 25 l = length ( h ) ; 26 hl = input ( ’ E n t e r t h e l o w e r i n d e x o f i m p u l s e r e s p o n s e 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 S e q u e n c e= ’ ) ; // 0 hh = hl +l -1; g = hl :1: hh ; subplot (2 ,2 ,2) ; a = gca () ; a . x_location = ” o r i g i n ” ; a . y_location = ” o r i g i n ” ; a . foreground = 5; a . font_color = 5; a . font_style = 5; plot2d3 ( ’ gnn ’ ,g , h ) ; title ( ’ I m p u l s e R e s p o n s e S e q u e n c e h [ n ] ’ ) ; xlabel ( ’ S a m p l e s n ’ ) ; ylabel ( ’ A m p l i t u d e ’ ) ; // A u t o c o r r e l a t i o n y = xcorr (x , x ) ; disp ( ’ Auto C o r r e l a t i o n Of g i v e n S e q u e n c e y ( n )= ’ ) ; disp ( y ) ; 23 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 nx = xl + xl ; nh = xh + xh ; r = nx : nh ; subplot (2 ,2 ,3) ; a = gca () ; a . x_location = ” o r i g i n ” ; a . y_location = ” o r i g i n ” ; a . foreground = 5; a . font_color = 5; a . font_style = 5; plot2d3 ( ’ gnn ’ ,r , y ) ; title ( ’ Output o f Auto C o r r e l a t i o n o f S e q u e n c e ’ ) ; xlabel ( ’ S a m p l e s n ’ ) ; ylabel ( ’ A m p l i t u d e ’ ) ; // C r o s s c o r r e l a t i o n z = xcorr (x , h ) ; disp ( ’ C r o s s C o r r e l a t i o n o f S e q u e n c e y ( n )= ’ ) ; disp ( z ) ; subplot (2 ,2 ,4) ; a = gca () ; a . x_location = ” o r i g i n ” ; a . y_location = ” o r i g i n ” ; a . foreground = 5; a . font_color = 5; a . font_style = 5; plot2d3 ( ’ gnn ’ ,r , z ) ; title ( ’ Output o f C r o s s c o r r e l a t i o n o f S e q u e n c e ’ ) ; xlabel ( ’ S a m p l e s n ’ ) ; ylabel ( ’ A m p l i t u d e ’ ) ; //INPUT : // E n t e r t h e // E n t e r t h e // E n t e r t h e // E n t e r t h e =0 I n p u t S e q u e n c e =[1 2 3 1 ] l o w e r i n d e x o f I n p u t S e q u e n c e =0 I m p u l s e r e s p o n s e S e q u e n c e =[1 2 1 1 ] lower index of impulse response Sequence 81 24 82 83 84 85 86 87 88 89 //OUTPUT: // Auto C o r r e l a t i o n Of g i v e n S e q u e n c e y ( n )= // 1 . 5. 11. 15. 11. 5. 1. // C r o s s C o r r e l a t i o n o f S e q u e n c e y ( n )= // 1 . 3. 7. 9. 25 9. 5. 1. Experiment: 6 WRITE A SCILAB PROGRAM TO FIND N-POINT DFT OF THE GIVEN SEQUENCE. Scilab code Solution 6.06 PROGRAM TO FIND N POINT DFT OF THE GIVEN SEQUENCE 1 2 3 4 5 6 7 8 9 10 11 // VERSION : S c i l a b : 5 . 4 . 1 // OS : windows 7 // CAPTION : PROGRAM TO FIND N−POINT DFT OF THE GIVEN SEQUENCE clc ; clear ; close ; N = input ( ’ E n t e r t h e v a l u e o f N= ’ ) ; // n−p o i n t x = input ( ’ E n t e r t h e i n p u t s e q u e n c e x ( n )= ’ ) ; subplot (3 ,2 ,1) ; a = gca () ; a . foreground = 5; 26 12 a . font_color = 5; 13 a . font_style = 5; 14 plot2d3 ( x ) ; 15 title ( ’ I n p u t s e q u e n c e ’ ) ; 16 xlabel ( ’ S a m p l e s n ’ ) ; 17 ylabel ( ’ A m p l i t u d e ’ ) ; 18 19 // c a l c u l a t i o n o f DFT 20 for k =1: N 21 y ( k ) =0; 22 for n =1: N 23 y ( k ) = y ( k ) + x ( n ) .* exp ( - %i *2* %pi *( k -1) *( n -1) / N ) 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 ; A = real ( y ) ; B = imag ( y ) ; end end mag = abs ( y ) ; x1 = atan ( imag ( y ) , real ( y ) ) ; phase = x1 *(180/ %pi ) ; disp ( ’ The o u t p u t DFT s e q u e n c e i s : ’ ) ; disp ( y ) ; subplot (3 ,2 ,2) ; a = gca () ; a . foreground = 5; a . font_color = 5; a . font_style = 5; plot2d3 ( y ) ; title ( ’ Output DFT s e q u e n c e ’ ) ; xlabel ( ’ S a m p l e s n ’ ) ; ylabel ( ’ A m p l i t u d e ’ ) ; //REAL VALUE disp ( ’ The r e s u l t a n t r e a l v a l u e i s : ’ ) ; disp ( A ) ; subplot (3 ,2 ,3) ; a = gca () ; a . foreground = 5; 27 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 a . font_color = 5; a . font_style = 5; plot2d3 ( A ) ; title ( ’ R e a l V a l u e ’ ) ; xlabel ( ’ S a m p l e s n ’ ) ; ylabel ( ’ A m p l i t u d e ’ ) ; //IMAGINARY VALUE disp ( ’ The r e s u l t a n t i m a g i n a r y v a l u e i s : ’ ) ; disp ( B ) ; subplot (3 ,2 ,4) ; a = gca () ; a . foreground = 5; a . font_color = 5; a . font_style = 5; plot2d3 ( B ) ; title ( ’ I m a g i n a r y V a l u e ’ ) ; xlabel ( ’ S a m p l e s n ’ ) ; ylabel ( ’ A m p l i t u d e ’ ) ; //MAGNITUDE RESPONSE disp ( ’ The Magnitude r e s p o n s e i s : ’ ) ; disp ( mag ) ; subplot (3 ,2 ,5) ; a = gca () ; a . foreground = 5; a . font_color = 5; a . font_style = 5; plot2d3 ( mag ) ; title ( ’ Magnitude R e s p o n s e ’ ) ; xlabel ( ’ S a m p l e s n ’ ) ; ylabel ( ’ A m p l i t u d e ’ ) ; //PHASE RESPONSE disp ( ’ The Phase r e s p o n s e i s : ’ ) ; disp ( phase ) ; subplot (3 ,2 ,6) ; a = gca () ; 28 87 a . foreground = 5; 88 a . font_color = 5; 89 a . font_style = 5; 90 plot2d3 ( phase ) ; 91 title ( ’ Phase R e s p o n s e ’ ) ; 92 xlabel ( ’ S a m p l e s n ’ ) ; 93 ylabel ( ’ Phase ’ ) ; 94 95 96 97 //INPUT : 98 // E n t e r t h e v a l u e o f N=4 99 // E n t e r t h e i n p u t s e q u e n c e x ( n ) =[1 2 3 4 ] 100 101 //OUTPUT: 102 // The o u t p u t DFT s e q u e n c e i s : 103 104 // 1 0 . 105 //− 2 . + 2 . i 106 //− 2 . − 9 . 7 9 7D−16 i 107 //− 2 . − 2 . i 108 109 // The r e s u l t a n t r e a l v a l u e i s : 110 111 // 1 0 . 112 //− 2 . 113 //− 2 . 114 //− 2 . 115 116 // The r e s u l t a n t i m a g i n a r y v a l u e i s : 117 118 // 0 . 119 // 2 . 120 //− 9 . 7 9 7D−16 121 //− 2 . 122 123 // The Magnitude r e s p o n s e i s : 124 29 125 126 127 128 129 130 131 132 133 134 135 // 1 0 . // 2 . 8 2 8 4 2 7 1 // 2 . // 2 . 8 2 8 4 2 7 1 // The Phase r e s p o n s e i s : // 0 . // 1 3 5 . //− 1 8 0 . // − 1 3 5 . 30 Experiment: 7 WRITE A SCILAB PROGRAM TO COMPUTE LINEAR CONVOLUTION OF TWO SEQUENCES USING DFT BASED APPROACH. Scilab code Solution 7.07 PROGRAM TO COMPUTE LINEAR CONVOLUTION OF TWO SEQUENCES USING DFT BASED APPROACH 1 2 3 4 5 6 7 8 // VERSION : S c i l a b : 5 . 4 . 1 // OS : windows 7 //CAPTION : PROGRAM TO COMPUTE LINEAR CONVOLUTION OF TWO SEQUENCES USING DFT BASED APPROACH clc ; clear ; close ; x = input ( ’ E n t e r t h e i n p u t s e q u e n c e x ( n )= ’ ) // x =[1 2 3 1] m = length ( x ) ; 31 9 xl = input ( ’ E n t e r t h e l o w e r i n d e x o f i n p u t s e q u e n c e= ’ ) 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 // 0 xh = xl +m -1; n = xl :1: xh ; subplot (3 ,1 ,1) ; a = gca () ; a . x_location = ” o r i g i n ” ; a . y_location = ” o r i g i n ” ; a . foreground = 5; a . font_color = 5; a . font_style = 5; plot2d3 ( ’ gnn ’ ,n , x ) ; title ( ’ I n p u t S e q u e n c e x [ n ] ’ ) ; xlabel ( ’ S a m p l e s n ’ ) ; ylabel ( ’ A m p l i t u d e ’ ) ; h = input ( ’ E n t e r t h e i m p u l s e r e s p o n s e s e q u e n c e h ( n )= ’ ) ; // h =[1 2 1 −1] l = length ( h ) ; hl = input ( ’ E n t e r t h e l o w e r i n d e x o f i m p u l s e r e s p o n s e s e q u e n c e= ’ ) ; //−1 hh = hl +l -1; g = hl :1: hh ; subplot (3 ,1 ,2) ; a = gca () ; a . x_location = ” o r i g i n ” ; a . y_location = ” o r i g i n ” ; a . foreground = 5; a . font_color = 5; a . font_style = 5; plot2d3 ( ’ gnn ’ ,n , h ) ; title ( ’ I m p u l s e R e s p o n s e S e q u e n c e h [ n ] ’ ) ; xlabel ( ’ S a m p l e s n ’ ) ; ylabel ( ’ A m p l i t u d e ’ ) ; 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 nx = xl + hl ; // r a n g e o f k 42 nh = xh + hh ; // r a n g e o f n 43 p = m +l -1; 32 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 x =[ x , zeros (1 ,p - l ) ]; h =[ h , zeros (1 ,p - m ) ]; // d f t − i d f t XK = fft (x , -1) ; // DFT o f x HK = fft (h , -1) ; // DFT o f h YK = XK .* HK ; // M u l t i p l i c a t i o n o f DFT o f x and h yn = fft ( YK ,1) ; // I n v e r s e DFT f o r o b t a i n i n g yn disp ( ’ L i n e a r C o n v o l u t i o n by DFT−IDFT Method i s y ( n ) : ’ ); disp ( real ( yn ) ) ; r = nx : nh ; subplot (3 ,1 ,3) ; a = gca () ; a . x_location = ” o r i g i n ” ; a . y_location = ” o r i g i n ” ; a . foreground = 5; a . font_color = 5; a . font_style = 5; plot2d3 ( ’ gnn ’ ,r , yn ) ; title ( ’ Output R e s p o n s e S e q u e n c e o f L i n e a r C o n v o l u t i o n by DFT−IDFT Method y [ n ] ’ ) ; xlabel ( ’ S a m p l e s n ’ ) ; ylabel ( ’ A m p l i t u d e ’ ) ; //INPUT : // E n t e r t h e // E n t e r t h e // E n t e r t h e −1] 71 // E n t e r t h e =−1 72 73 74 75 76 i n p u t s e q u e n c e x ( n ) =[1 2 3 1 ] l o w e r i n d e x o f i n p u t s e q u e n c e =0 i m p u l s e r e s p o n s e s e q u e n c e h ( n ) =[1 2 1 lower index of impulse response sequence //OUTPUT: // L i n e a r C o n v o l u t i o n by DFT−IDFT Method i s y ( n ) : // 1 . 4. 8. 8. 33 3. − 2. − 1. Experiment: 8 WRITE A SCILAB PROGRAM TO COMPUTE CIRCULAR CONVOLUTION OF TWO SEQUECNES USING BASIC EQUATION. Scilab code Solution 8.08 PROGRAM TO COMPUTE CIRCULAR CONVOLUTION OF TWO SEQUENCES USING BASIC EQUATION 1 2 3 4 5 6 7 8 9 // VERSION : S c i l a b : 5 . 4 . 1 // OS : windows 7 //CAPTION : PROGRAM TO COMPUTE CIRCULAR CONVOLUTION OF TWO SEQUENCES USING BASIC EQUATION clc ; clear ; close ; x = input ( ’ E n t e r t h e i n p u t s e q u e n c e= ’ ) // x =[1 1 2 2 ] m = length ( x ) ; xl = input ( ’ E n t e r t h e l o w e r i n d e x o f i n p u t s e q u e n c e= ’ ) 34 // 0 xh = xl +m -1; n = xl :1: xh ; subplot (3 ,1 ,1) ; a = gca () ; a . x_location = ” o r i g i n ” ; a . y_location = ” o r i g i n ” ; a . foreground = 5; a . font_color = 5; a . font_style = 5; plot2d3 ( ’ gnn ’ ,n , x ) ; title ( ’ I n p u t S e q u e n c e x [ n ] ’ ) ; xlabel ( ’ S a m p l e s n ’ ) ; ylabel ( ’ A m p l i t u d e ’ ) ; 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 h = input ( ’ E n t e r t h e i m p u l s e r e s p o n s e s e q u e n c e= ’ ) ; // h =[1 2 3 4 ] 25 l = length ( h ) ; 26 hl = input ( ’ E n t e r t h e l o w e r i n d e x o f i m p u l s e r e s p o n s e 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 s e q u e n c e= ’ ) ; // 0 hh = hl +l -1; g = hl :1: hh ; subplot (3 ,1 ,2) ; a = gca () ; a . x_location = ” o r i g i n ” ; a . y_location = ” o r i g i n ” ; a . foreground = 5; a . font_color = 5; a . font_style = 5; plot2d3 ( ’ gnn ’ ,g , h ) ; title ( ’ I m p u l s e R e s p o n s e S e q u e n c e h [ n ] ’ ) ; xlabel ( ’ S a m p l e s n ’ ) ; ylabel ( ’ A m p l i t u d e ’ ) ; // f o r making l e n g t h o f b o t h s i g n a l s e q u a l N = max (m , l ) ; p =m - l ; 35 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 if (p >=0) then h =[ h , zeros (1 , p ) ]; else x =[ x , zeros (1 , - p ) ]; end for i =1: N y ( i ) =0; for j =1: N k =i - j +1; if (k <=0) k=N+k; end y(i)=y(i)+x(j)*h(k); end end disp ( ’ C i r c u l a r c o n v o l u t i o n by e q u a t i o n i s y [ n ] : ’ ) ; disp ( y ) ; nx = xl + hl ; r = nx : length ( y ) -1; subplot (3 ,1 ,3) ; a = gca () ; a . x_location = ” o r i g i n ” ; a . y_location = ” o r i g i n ” ; a . foreground = 5; a . font_color = 5; a . font_style = 5; plot2d3 ( ’ gnn ’ ,r , y ) ; title ( ’ Output R e s p o n s e S e q u e n c e o f C i r c u l a r Convolution y [ n ] u s i n g B a s i c Equation ’ ); 73 xlabel ( ’ S a m p l e s n ’ ) ; 74 ylabel ( ’ A m p l i t u d e ’ ) ; 75 76 77 78 79 80 //INPUT : // E n t e r t h e // E n t e r t h e // E n t e r t h e // E n t e r t h e =0 i n p u t s e q u e n c e =[1 1 2 2 ] l o w e r i n d e x o f i n p u t s e q u e n c e =0 i m p u l s e r e s p o n s e s e q u e n c e =[1 2 3 4 ] lower index of impulse response sequence 36 81 82 83 84 85 86 87 88 //OUTPUT: // C i r c u l a r c o n v o l u t i o n by e q u a t i o n i s y [ n ] : // 15. // 1 7 . // 1 5 . // 1 3 . 37 Experiment: 9 WRITE A SCILAB PROGRAM TO COMPUTE CIRCULAR CONVOLUTION OF THE TWO SEQUENCES USING DFT BASED APPROACH. Scilab code Solution 9.09 PROGRAM TO COMPUTE CIRCULAR CONVOLUTION OF THE TWO SEQUENCES USING DFT BASED APPROACH 1 2 3 4 5 6 7 // VERSION : S c i l a b : 5 . 4 . 1 // OS : windows 7 //CAPTION :PROGRAM TO COMPUTE CIRCULAR CONVOLUTION OF THE TWO SEQUENCES USING DFT BASED APPROACH clc ; clear ; close ; x = input ( ’ E n t e r t h e I n p u t s e q u e n c e= ’ ) // x =[1 1 2 2 ] 38 8 m = length ( x ) ; 9 xl = input ( ’ E n t e r t h e l o w e r i n d e x o f i n p u t s e q u e n c e= ’ ) // 0 xh = xl +m -1; n = xl :1: xh ; subplot (3 ,1 ,1) ; a = gca () ; a . x_location = ” o r i g i n ” ; a . y_location = ” o r i g i n ” ; a . foreground = 5; a . font_color = 5; a . font_style = 5; plot2d3 ( ’ gnn ’ ,n , x ) ; title ( ’ I n p u t S e q u e n c e x [ n ] ’ ) ; xlabel ( ’ S a m p l e s n ’ ) ; ylabel ( ’ A m p l i t u d e ’ ) ; 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 h = input ( ’ E n t e r t h e I m p u l s e r e s p o n s e s e q u e n c e= ’ ) ; // h 25 26 =[1 2 3 4 ] l = length ( h ) ; hl = input ( ’ E n t e r t h e l o w e r i n d e x o f i m p u l s e r e s p o n s e s e q u e n c e= ’ ) ; // 0 hh = hl +l -1; g = hl :1: hh ; subplot (3 ,1 ,2) ; a = gca () ; a . x_location = ” o r i g i n ” ; a . y_location = ” o r i g i n ” ; a . foreground = 5; a . font_color = 5; a . font_style = 5; plot2d3 ( ’ gnn ’ ,g , h ) ; title ( ’ I m p u l s e R e s p o n s e S e q u e n c e h [ n ] ’ ) ; xlabel ( ’ S a m p l e s n ’ ) ; ylabel ( ’ A m p l i t u d e ’ ) ; 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 // f o r making l e n g t h 42 N = max (m , l ) ; o f both s i g n a l s e q u a l 39 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 p =m - l ; if (p >=0) then h =[ h , zeros (1 , p ) ]; else x =[ x , zeros (1 , - p ) ]; end XK = fft (x , -1) ; HK = fft (h , -1) ; YK = XK .* HK ; y = ifft ( YK ) ; disp ( ’ C i r c u l a r c o n v o l u t i o n by DFT i s y ( n ) : ’ ) ; disp ( real ( y ) ) ; nx = xl + hl ; r = nx : length ( y ) -1; subplot (3 ,1 ,3) ; a = gca () ; a . x_location = ” o r i g i n ” ; a . y_location = ” o r i g i n ” ; a . foreground = 5; a . font_color = 5; a . font_style = 5; plot2d3 ( ’ gnn ’ ,r , y ) ; title ( ’ Output R e s p o n s e S e q u e n c e o f C i r c u l a r C o n v o l u t i o n y [ n ] u s i n g DFT ’ ) ; 66 xlabel ( ’ S a m p l e s n ’ ) ; 67 ylabel ( ’ A m p l i t u d e ’ ) ; 68 69 70 71 72 73 74 75 76 77 78 //INPUT : // E n t e r t h e // E n t e r t h e // E n t e r t h e // E n t e r t h e =0 I n p u t s e q u e n c e =[1 1 2 2 ] l o w e r i n d e x o f i n p u t s e q u e n c e =0 I m p u l s e r e s p o n s e s e q u e n c e =[1 2 3 4 ] lower index of impulse response sequence //OUTPUT: // C i r c u l a r c o n v o l u t i o n by DFT i s y ( n ) : // 1 5 . 17. 15. 13. 40 41 Experiment: 10 WRITE A SCILAB PROGRAM TO COMPUTE BLOCK CONVOLUTION USING OVERLAP ADD METHOD Scilab code Solution 10.10 PROGRAM TO COMPUTE BLOCK CONVOLUTION USING OVERLAP ADD METHOD 1 2 3 4 5 6 7 8 // VERSION : S c i l a b : 5 . 4 . 1 // OS : windows 7 //CAPTION : PROGRAM TO COMPUTE BLOCK CONVOLUTION USING OVERLAP ADD METHOD clc ; clear ; close ; x = input ( ’ E n t e r t h e i n p u t s e q u e n c e= ’ ) // x =[1 2 −1 2 3 −2 −3 −1 1 1 2 −1] m = length ( x ) ; 42 9 xl = input ( ’ E n t e r t h e l o w e r i n d e x o f i n p u t s e q u e n c e= ’ ) 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 // 0 xh = xl +m -1; n = xl :1: xh ; subplot (3 ,1 ,1) ; a = gca () ; a . x_location = ” o r i g i n ” ; a . y_location = ” o r i g i n ” ; a . foreground = 5; a . font_color = 5; a . font_style = 5; plot2d3 ( ’ gnn ’ ,n , x ) ; title ( ’ I n p u t S e q u e n c e x [ n ] ’ ) ; xlabel ( ’ S a m p l e s n ’ ) ; ylabel ( ’ A m p l i t u d e ’ ) ; h = input ( ’ E n t e r t h e i m p u l s e r e s p o n s e s e q u e n c e= ’ ) ; // h =[1 2 3 −1] l = length ( h ) ; hl = input ( ’ E n t e r t h e l o w e r i n d e x o f i m p u l s e r e s p o n s e s e q u e n c e= ’ ) ; // 0 hh = hl +l -1; g = hl :1: hh ; subplot (3 ,1 ,2) ; a = gca () ; a . x_location = ” o r i g i n ” ; a . y_location = ” o r i g i n ” ; a . foreground = 5; a . font_color = 5; a . font_style = 5; plot2d3 ( ’ gnn ’ ,g , h ) ; title ( ’ I m p u l s e R e s p o n s e S e q u e n c e h [ n ] ’ ) ; xlabel ( ’ S a m p l e s n ’ ) ; ylabel ( ’ A m p l i t u d e ’ ) ; 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 N = m +l -1; 42 h1 =[ h zeros (1 ,l -1) ]; 43 n3 = length ( h1 ) ; 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 y = zeros (1 , N ) ; H = fft ( h1 ) ; for i =1: l : m if i <=( m +l -1) then x1 =[ x ( i : i + n3 - l ) zeros (1 , n3 - l ) ]; else x1 =[ x ( i : m ) zeros (1 , n3 - l ) ]; end x2 = fft ( x1 ) ; x3 = x2 .* H ; x4 = round ( ifft ( x3 ) ) ; if ( i ==1) y (1: n3 ) = x4 (1: n3 ) ; else y ( i : i + n3 -1) = y ( i : i + n3 -1) + x4 (1: n3 ) ; end end disp ( ’ Output s e q u e n c e u s i n g O v e r l a p add method y ( n ) : ’ ); disp ( y (1: N ) ) ; nx = xl + hl ; r = nx : length ( y ) -1; subplot (3 ,1 ,3) ; a = gca () ; a . x_location = ” o r i g i n ” ; a . y_location = ” o r i g i n ” ; a . foreground = 5; a . font_color = 5; a . font_style = 5; plot2d3 ( ’ gnn ’ ,r , y ) ; title ( ’ Output s e q u e n c e u s i n g O v e r l a p add method y [ n ] ’ ); xlabel ( ’ S a m p l e s n ’ ) ; ylabel ( ’ A m p l i t u d e ’ ) ; //INPUT : 44 // E n t e r 2 −1] 81 // E n t e r 82 // E n t e r 83 // E n t e r =0 80 84 85 86 87 88 89 90 91 92 93 94 95 t h e i n p u t s e q u e n c e =[1 2 −1 2 3 −2 −3 −1 1 1 t h e l o w e r i n d e x o f i n p u t s e q u e n c e =0 t h e i m p u l s e r e s p o n s e s e q u e n c e =[1 2 3 −1] the lower index of impulse response sequence //OUTPUT: // Output s e q u e n c e u s i n g O v e r l a p add method y ( n ) : // column // 1 . 4. − 8. // 1 t o 12 6. 3. 5. 8. column 13 t o 15 // 3 . − 5. 2. 5. 1. 45 11. 0. − 16. Experiment: 11 WRITE A SCILAB PROGRAM RO COMPUTE BLOCK CONVOLUTION USING OVERLAP SAVE METHOD. Scilab code Solution 11.11 PROGRAM TO COMPUTE BLOCK CONVOLUTION USING OVERLAP SAVE METHOD 1 2 3 4 5 6 7 8 // VERSION : S c i l a b : 5 . 4 . 1 // OS : windows 7 //CAPTION : PROGRAM TO COMPUTE BLOCK CONVOLUTION USINF OVERLAP SAVE METHOD clc ; clear ; close ; x = input ( ’ E n t e r t h e i n p u t s e q u e n c e= ’ ) // x =[1 2 −1 2 3 −2 −3 −1 1 1 2 −1] m = length ( x ) ; 46 9 xl = input ( ’ E n t e r t h e l o w e r i n d e x o f i n p u t s e q u e n c e= ’ ) 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 // 0 xh = xl +m -1; n = xl :1: xh ; subplot (3 ,1 ,1) ; a = gca () ; a . x_location = ” o r i g i n ” ; a . y_location = ” o r i g i n ” ; a . foreground = 5; a . font_color = 5; a . font_style = 5; plot2d3 ( ’ gnn ’ ,n , x ) ; title ( ’ I n p u t S e q u e n c e x [ n ] ’ ) ; xlabel ( ’ S a m p l e s n ’ ) ; ylabel ( ’ A m p l i t u d e ’ ) ; h = input ( ’ E n t e r t h e i m p u l s e r e s p o n s e s e q u e n c e= ’ ) ; // h =[1 2 3 −1] l = length ( h ) ; hl = input ( ’ E n t e r t h e l o w e r i n d e x o f i m p u l s e r e s p o n s e s e q u e n c e= ’ ) ; // 0 hh = hl +l -1; g = hl :1: hh ; subplot (3 ,1 ,2) ; a = gca () ; a . x_location = ” o r i g i n ” ; a . y_location = ” o r i g i n ” ; a . foreground = 5; a . font_color = 5; a . font_style = 5; plot2d3 ( ’ gnn ’ ,g , h ) ; title ( ’ I m p u l s e R e s p o n s e S e q u e n c e h [ n ] ’ ) ; xlabel ( ’ S a m p l e s n ’ ) ; ylabel ( ’ A m p l i t u d e ’ ) ; 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 N = m +l -1; 42 h1 =[ h zeros (1 ,N - m ) ]; 43 n3 = length ( h1 ) ; 47 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 y = zeros (1 , N ) ; x1 =[ zeros (1 , n3 - l ) x zeros (1 , n3 ) ]; H = fft ( h1 ) ; for i =1: l : N y1 = x1 ( i : i +(2*( n3 - l ) ) ) ; y2 = fft ( y1 ) ; y3 = y2 .* H ; y4 = round ( ifft ( y3 ) ) ; y ( i :( i + n3 - l ) ) = y4 ( l : n3 ) ; end disp ( ’ Output s e q u e n c e u s i n g o v e r l a p s a v e method Y( n ) : ’ ); disp ( y (1: N ) ) ; nx = xl + hl ; r = nx : length ( y ) -1; subplot (3 ,1 ,3) ; a = gca () ; a . x_location = ” o r i g i n ” ; a . y_location = ” o r i g i n ” ; a . foreground = 5; a . font_color = 5; a . font_style = 5; plot2d3 ( ’ gnn ’ ,r , y ) ; title ( ’ Output s e q u e n c e u s i n g O v e r l a p s a v e method y [ n ] ’ ); xlabel ( ’ S a m p l e s n ’ ) ; ylabel ( ’ A m p l i t u d e ’ ) ; //INPUT : // E n t e r t h e 2 −1] 72 // E n t e r t h e 73 // E n t e r t h e 74 // E n t e r t h e =0 75 76 77 i n p u t s e q u e n c e =[1 2 −1 2 3 −2 −3 −1 1 1 l o w e r i n d e x o f i n p u t s e q u e n c e =0 i m p u l s e r e s p o n s e s e q u e n c e =[1 2 3 −1] lower index of impulse response sequence //OUTPUT: // Output s e q u e n c e u s i n g o v e r l a p s a v e method Y( n ) : 48 78 79 80 81 82 83 84 85 86 // column // 1 . 4. − 8. // // 3 . 1 t o 12 6. 3. 5. 8. 5. column 13 t o 15 − 5. 2. 1. 49 11. 0. − 16. Experiment: 12 WRITE A SCILAB PROGRAM TO FIND FFT USING DECIMATION IN TIME(DIT) METHOD. Scilab code Solution 12.12 PROGRAM TO FIND FFT USING DECIMATION IN TIME METHOD 1 2 3 4 5 6 7 // VERSION : S c i l a b : 5 . 4 . 1 // OS : windows 7 // CAPTION : PROGRAM TO FIND FFT USING DECIMATION IN TIME( DIT ) METHOD clc ; clear ; close ; x = input ( ’ E n t e r I n p u t s e q u e n c e= ’ ) ; // x =[0 1 2 3 4 5 6 7] o r x= [ 0 1 2 3 ] N = length ( x ) ; 8 9 10 s = log2 ( N ) ; // c o m p u t i n g a r r a y 11 12 // f o r s e q u e n c e s i z e 8 50 size 13 if ( N ==8) then 14 stage1 =1; 15 16 x =[ x (1) x (5) x (3) x (7) x (2) x (6) x (4) x (8) ]; // 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 stage1 for stage =1: s for index =0:(2^ stage ) :( N -1) ; // s e r i e s o f b u t t e r f l y f o r each s t a g e for n =0:( stage1 -1) ; // c r e a t e b u t t e r l f y and s a v e r e s u l t pos = n + index +1; // i n d e x o f d a t a s a m p l e pow =(2^( s - stage ) ) * n ; // p a r t o f power o f complex m u l t i p l i e r w = exp (( -1* %i ) *(2* %pi ) * pow / N ) ; // c o m p l e x multiplier a = x ( pos ) + x ( pos + stage1 ) .* w ; // 1 s t p a r t of butterfly creating operations b = x ( pos ) -x ( pos + stage1 ) .* w ; // 2 nd p a r t o f butterfly creating operation x ( pos ) = a ; // s a v i n g c o m p u t a t i o n o f 1 s t half x ( pos + stage1 ) = b ; // s a v i n g c o m p u t a t i o n of second part end end stage1 =2* stage1 ; // c o m p u t i n g n e x t s t a g e end y=x; disp ( ’FFT o f t h e g i v e n i n p u t s e q u e n c e i s y ( n )= ’ ) ; disp ( y ) ; // f o r s e q u e n c e s i z e −4 else stage1 =1; x =[ x (1) x (3) x (2) x (4) ]; // for stage =1: s 51 stage1 for index =0:(2^ stage ) :( N -1) ; // s e r i e s o f b u t t e r f l y f o r each s t a g e for n =0:( stage1 -1) ; // c r e a t e b u t t e r l f y and s a v e r e s u l t pos = n + index +1; // i n d e x o f d a t a s a m p l e pow =(2^( s - stage ) ) * n ; // p a r t o f power o f complex m u l t i p l i e r w = exp (( -1* %i ) *(2* %pi ) * pow / N ) ; // c o m p l e x multiplier a = x ( pos ) + x ( pos + stage1 ) .* w ; // 1 s t p a r t of butterfly creating operations b = x ( pos ) -x ( pos + stage1 ) .* w ; // 2 nd p a r t o f butterfly creating operation x ( pos ) = a ; // s a v i n g c o m p u t a t i o n o f 1 s t half x ( pos + stage1 ) = b ; // s a v i n g c o m p u t a t i o n of second part 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 end end stage1 =2* stage1 ; // c o m p u t i n g n e x t s t a g e end y=x; disp ( ’FFT o f t h e g i v e n i n p u t s e q u e n c e y ( n )= ’ ) ; disp ( y ) ; end //INPUT : // E n t e r I n p u t s e q u e n c e =[0 1 2 3 4 5 6 7 ] //OUTPUT: // FFT o f t h e g i v e n i n p u t s e q u e n c e i s y ( n )= // // column 1 t o 3 28. − 4. + 9.6568542 i 52 − 4. + 4. i 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 // // column 4 t o 5 − 4. + 1.6568542 i // // − 4. column 6 t o 7 − 4. − 1.6568542 i // − 4. − 4. i column 8 // − 4 . − 9 . 6 5 6 8 5 4 2 i // INPUT : // E n t e r I n p u t s e q u e n c e =[0 1 2 3 ] //OUTPUT: //FFT o f t h e g i v e n i n p u t s e q u e n c e y ( n )= // 6. − 2. + 2. i − 2. 53 − 2. − 2. i Experiment: 13 WRITE A SCILAB PROGRAM FOR DESIGNING OF FIR FILTER FOR LOW PASS, HIGH PASS, BANDPASS AND BAND REJECT RESPONSES. Scilab code Solution 13.13 PROGRAM FOR DESIGNING OF FIR FILTER FOR LOW PASS HIGH PASS BAND PASS AND BAND REJECT RESPONSES 1 2 3 4 5 // VERSION : S c i l a b : 5 . 4 . 1 // OS : windows 7 //CAPTION : PROGRAM FOR DESIGNING OF FIR LOW PASS , HIGH PASS , BAND PASS AND BAND REJECT RESPONSES // F i l t e r l e n g t h =5 , Order o f Rectangular 54 f i l t e r =4 , Window= 6 clc ; 7 clear ; 8 close ; 9 xdel ( winsid () ) ; 10 fc1 = input ( ’ E n t e r t h e a n a l o g 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 c u t o f f F r e q u e n c y i n Hz= ’ ) ; // 250 fc2 = input ( ’ E n t e r a n a l o g h i g h e r c u t o f f f r e q u e n c y i n Hz= ’ ) ; // 600 fs = input ( ’ E n t e r t h e a n a l o g s a m p l i n g F r e q u e n c y i n Hz= ’ ) ; // 2 0 0 0 M = input ( ’ E n t e r o r d e r o f f i l t e r = ’ ) ; // 4 w1 =(2* %pi ) *( fc1 / fs ) ; w2 =(2* %pi ) *( fc2 / fs ) ; // FIR LOW PASS FILTER disp ( ’ DESIGNING OF FIR LOW PASS FILTER : ’ ) ; disp ( w1 , ’ D i g i t a l C u t o f f F r e q u e n c y i n r a d i a n s . c y c l e s / samples ’ ); wc1 = w1 / %pi ; disp ( wc1 , ’ N o r m a l i z e d d i g i t a l c u t o f f f r e q u e n c y i n c y c l e s / samples ’ ); [ wft , wfm , fr ]= wfir ( ’ l p ’ ,M +1 ,[ wc1 /2 ,0] , ’ r e ’ ,[0 ,0]) ; disp ( wft , ’ I m p u l s e R e s p o n s e o f LPF FIR f i l t e r : h ( n )= ’ ) ; // p l o t t i n g m a g n i t u d e r e s p o n s e o f LPF f i l t e r subplot (2 ,4 ,1) ; a = gca () ; a . thickness =2; a . foreground = 5; a . font_color = 5; a . font_style = 5; plot (2* fr , wfm ) ; title ( ’ Magnitude R e s p o n s e o f FIR LPF ’ ) ; xlabel ( ’ N o r m a l i z e d D i g i t a l F r e q u e n c y w ’ ) ; ylabel ( ’ Magnitude | H(w) | ’ ) ; xgrid (1) subplot (2 ,4 ,2) ; a = gca () ; 55 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 a . thickness =2; a . foreground = 5; a . font_color = 5; a . font_style = 5; plot ( fr * fs , wfm ) ; title ( ’ Magnitude R e s p o n s e o f FIR LPF ’ ) ; xlabel ( ’ Analog f r e q u e n c y i n Hz f ’ ) ; ylabel ( ’ Magnitude | H(w) | ’ ) ; xgrid (1) // FIR HIGH PASS FILTER disp ( ’ DESIGNING OF FIR HIGH PASS FILTER : ’ ) disp ( w1 , ’ D i g i t a l C u t o f f F r e q u e n c y i n r a d i a n s . c y c l e s / samples ’ ); wc1 = w1 / %pi ; disp ( wc1 , ’ N o r m a l i z e d d i g i t a l c u t o f f f r e q u e n c y i n c y c l e s / samples ’ ); [ wft , wfm , fr ]= wfir ( ’ hp ’ ,M +1 ,[ wc1 /2 ,0] , ’ r e ’ ,[0 ,0]) ; disp ( wft , ’ I m p u l s e R e s p o n s e o f HPF FIR f i l t e r : h ( n )= ’ ) ; // p l o t t i n g m a g n i t u d e r e s p o n s e o f HPF f i l t e r subplot (2 ,4 ,3) ; a = gca () ; a . thickness =2; a . foreground = 5; a . font_color = 5; a . font_style = 5; plot (2* fr , wfm ) ; title ( ’ Magnitude R e s p o n s e o f FIR HPF ’ ) ; xlabel ( ’ N o r m a l i z e d D i g i t a l F r e q u e n c y w ’ ) ; ylabel ( ’ Magnitude | H(w) | ’ ) ; xgrid (1) subplot (2 ,4 ,4) ; a = gca () ; a . thickness =2; a . foreground = 5; a . font_color = 5; a . font_style = 5; 56 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 plot ( fr * fs , wfm ) ; title ( ’ Magnitude R e s p o n s e o f FIR HPF ’ ) ; xlabel ( ’ Analog f r e q u e n c y i n Hz f ’ ) ; ylabel ( ’ Magnitude | H(w) | ’ ) ; xgrid (1) // FIR BAND PASS FILTER disp ( ’ DESIGNING OF FIR BAND PASS FILTER : ’ ) disp ( w1 , ’ D i g i t a l l o w e r c u t o f f f r e q u e n c y i n r a d i a n s c y c l e s / samples ’ ); disp ( w2 , ’ D i g i t a l h i g h e r c u t o f f f r e q u e n c y i n r a d i a n s c y c l e s / samples ’ ); wc1 = w1 / %pi ; wc2 = w2 / %pi ; disp ( wc1 , ’ N o r m a l i z e d d i g i t a l l o w e r c u t o f f f r e q u e n c y i n c y c l e s / samples ’ ); disp ( wc2 , ’ N o r m a l i z e d d i g i t a l h i g h e r c u t o f f f r e q u e n c y i n c y c l e s / samples ’ ); [ wft , wfm , fr ]= wfir ( ’ bp ’ , M +1 ,[ wc1 /2 , wc2 /2] , ’ r e ’ ,[0 ,0]) ; disp ( wft , ’ I m p u l s e r e s p o n s e o f Bandpass F i l t e r FIR f i l t e r : h ( n )= ’ ) ; // p l o t t i n g t h e m a g n i t u d e R e s p o n s e o f HPF FIR f i l t e r subplot (2 ,4 ,5) ; a = gca () ; a . thickness =2; a . foreground = 5; a . font_color = 5; a . font_style = 5; plot (2* fr , wfm ) ; xlabel ( ’ N o r m a l i z e d D i g i t a l F r e q u e n c y w ’ ) ; ylabel ( ’ Magnitude | H(W) | ’ ) ; title ( ’ Magnitude R e s p o n s e o f FIR BPF ’ ) ; xgrid (1) ; subplot (2 ,4 ,6) ; a = gca () ; a . thickness =2; a . foreground = 5; 57 105 a . font_color = 5; 106 a . font_style = 5; 107 plot ( fr * fs , wfm ) ; 108 xlabel ( ’ Analog F r e q u e n c y i n Hz f ’ ) ; 109 ylabel ( ’ Magnitude | H(w) | ’ ) ; 110 title ( ’ Magnitude r e s p o n s e o f FIR BPF ’ ) ; 111 xgrid (1) ; 112 113 // FIR BAND REJECT FILTER 114 disp ( ’ DESIGNING OF FIR BAND REJECT FILTER : ’ ) 115 disp ( w1 , ’ D i g i t a l l o w e r c u t o f f f r e q u e n c y i n r a d i a n s 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 c y c l e s / samples ’ ); disp ( w2 , ’ D i g i t a l h i g h e r c u t o f f f r e q u e n c y i n r a d i a n s c y c l e s / samples ’ ); wc1 = w1 / %pi ; wc2 = w2 / %pi ; disp ( wc1 , ’ N o r m a l i z e d d i g i t a l l o w e r c u t o f f f r e q u e n c y i n c y c l e s / samples ’ ); disp ( wc2 , ’ N o r m a l i z e d d i g i t a l h i g h e r c u t o f f f r e q u e n c y i n c y c l e s / samples ’ ); [ wft , wfm , fr ]= wfir ( ’ s b ’ , M +1 ,[ wc1 /2 , wc2 /2] , ’ r e ’ ,[0 ,0]) ; disp ( wft , ’ I m p u l s e r e s p o n s e o f B a n d r e j e c t F i l t e r FIR f i l t e r : h ( n )= ’ ) ; // p l o t t i n g t h e m a g n i t u d e R e s p o n s e o f HPF FIR f i l t e r subplot (2 ,4 ,7) ; a = gca () ; a . thickness =2; a . foreground = 5; a . font_color = 5; a . font_style = 5; plot (2* fr , wfm ) ; xlabel ( ’ N o r m a l i z e d D i g i t a l F r e q u e n c y w ’ ) ; ylabel ( ’ Magnitude | H(W) | ’ ) ; title ( ’ Magnitude R e s p o n s e o f FIR BRF ’ ) ; xgrid (1) ; subplot (2 ,4 ,8) ; a = gca () ; 58 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 a . thickness =2; a . foreground = 5; a . font_color = 5; a . font_style = 5; plot ( fr * fs , wfm ) ; xlabel ( ’ Analog F r e q u e n c y i n Hz f ’ ) ; ylabel ( ’ Magnitude | H(w) | ’ ) ; title ( ’ Magnitude r e s p o n s e o f FIR BRF ’ ) ; xgrid (1) ; //INPUT : // E n t e r t h e a n a l o g c u t o f f F r e q u e n c y i n Hz=250 // E n t e r a n a l o g h i g h e r c u t o f f f r e q u e n c y i n Hz=600 // E n t e r t h e a n a l o g s a m p l i n g F r e q u e n c y i n Hz=2000 // E n t e r o r d e r o f f i l t e r =4 //OUTPUT: // DESIGNING OF FIR LOW PASS FILTER : // D i g i t a l C u t o f f F r e q u e n c y i n r a d i a n s . c y c l e s / samples // 0.7853982 // N o r m a l i z e d d i g i t a l c u t o f f f r e q u e n c y i n c y c l e s / samples // 0.25 // I m p u l s e R e s p o n s e o f LPF FIR f i l t e r : h ( n )= // 0 . 1 5 9 1 5 4 9 0.1591549 0.2250791 0.25 0.2250791 //DESIGNING OF FIR HIGH PASS FILTER : // D i g i t a l C u t o f f F r e q u e n c y i n r a d i a n s . c y c l e s / samples 59 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 // 0.7853982 // N o r m a l i z e d d i g i t a l c u t o f f f r e q u e n c y i n c y c l e s / samples // 0 . 2 5 // I m p u l s e R e s p o n s e o f HPF FIR f i l t e r : h ( n )= // − 0 . 1 5 9 1 5 4 9 0.1591549 − 0.2250791 0.75 − 0.2250791 − //DESIGNING OF FIR BAND PASS FILTER : // D i g i t a l l o w e r c u t o f f f r e q u e n c y i n r a d i a n s c y c l e s / samples // 0 . 7 8 5 3 9 8 2 // D i g i t a l h i g h e r c u t o f f f r e q u e n c y i n r a d i a n s c y c l e s / samples // 1 . 8 8 4 9 5 5 6 // N o r m a l i z e d d i g i t a l l o w e r c u t o f f f r e q u e n c y i n c y c l e s / samples // 0 . 2 5 // N o r m a l i z e d d i g i t a l h i g h e r c u t o f f f r e q u e n c y i n c y c l e s / samples // 0 . 6 // I m p u l s e r e s p o n s e o f Bandpass F i l t e r FIR f i l t e r : h ( n )= 201 60 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 //− 0 . 2 5 2 7 0 3 9 0.2527039 0.0776516 0.35 0.0776516 − //DESIGNING OF FIR BAND REJECT FILTER : // D i g i t a l l o w e r c u t o f f f r e q u e n c y i n r a d i a n s c y c l e s / samples // 0 . 7 8 5 3 9 8 2 // D i g i t a l h i g h e r c u t o f f f r e q u e n c y i n r a d i a n s c y c l e s / samples // 1 . 8 8 4 9 5 5 6 // N o r m a l i z e d d i g i t a l l o w e r c u t o f f f r e q u e n c y i n c y c l e s / samples // 0 . 2 5 // N o r m a l i z e d d i g i t a l h i g h e r c u t o f f f r e q u e n c y i n c y c l e s / samples // 0 . 6 // I m p u l s e r e s p o n s e o f B a n d r e j e c t F i l t e r FIR f i l t e r : h ( n )= // 0 . 2 5 2 7 0 3 9 − 0 . 0 7 7 6 5 1 6 0.2527039 61 0.65 − 0.0776516 Experiment: 14 WRITE A SCILAB PROGRAM TO DESIGN DIGITAL IIR BUTTERWORTH LOW PASS FILTER. Scilab code Solution 14.14 PROGRAM TO DESIGN DIGITAL IIR BUTTERWORTH LOW PASS FILTER 1 2 3 4 5 6 7 8 9 // VERSION : S c i l a b : 5 . 4 . 1 // OS : windows 7 //CAPTION : PROGRAM TO DESIGN BUTTERWORTH LOW PASS FILTER clc ; clear ; close ; xdel ( winsid () ) ; fc = input ( ’ E n t e r c u t o f f f r e q i n Hz f c= ’ ) ; // 1 0 0 0 fs = input ( ’ E n t e r s a m p l i n g f r e q i n Hz f s = ’ ) ; // 1 0 0 0 0 62 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 N = input ( ’ E n t e r o r d e r o f B u t t e r w o r t h f i l t e r N= ’ ) ; // 4 Fp =2* fc / fs ; [ Hz ]= iir (N , ’ l p ’ , ’ b u t t ’ ,[ Fp /2 ,0] ,[0 ,0]) ; [ Hw , w ]= frmag ( Hz ,256) ; subplot (2 ,1 ,1) ; a = gca () ; a . thickness =2; a . foreground = 5; a . font_color = 5; a . font_style = 5; plot (2* w , abs ( Hw ) ) ; title ( ’ Magnitude R e s p o n s e o f I I R LPF ’ ) ; xlabel ( ’ N o r m a l i z e d D i g i t a l f r e q u e n c y w ’ ) ; ylabel ( ’ Magnitude | H(w) | ’ ) ; xgrid (1) ; subplot (2 ,1 ,2) ; a = gca () ; a . thickness =2; a . foreground = 5; a . font_color = 5; a . font_style = 5; plot (2* w * fs , abs ( Hw ) ) ; title ( ’ Magnitude R e s p o n s e o f I I R LPF ’ ) ; xlabel ( ’ Analog F r e q u e n c y i n Hz f ’ ) ; ylabel ( ’ Magnitude | H(w) | ’ ) ; xgrid (1) ; //INPUT : // E n t e r c u t o f f f r e q i n Hz f c =1000 // E n t e r s a m p l i n g f r e q i n Hz f s =10000 // E n t e r o r d e r o f B u t t e r w o r t h f i l t e r N=4 63 Experiment: 15 WRITE A SCILAB PROGRAM TO DESIGN DIGITAL IIR CHEBYSHEW FILTER. Scilab code Solution 15.15 PROGRAM TO DESIGN DIGITAL IIR CHEBYSHEW FILTER 1 2 3 4 5 6 7 8 9 // VERSION : S c i l a b : 5 . 4 . 1 // OS : windows 7 //CAPTION : PROGRAM TO DESIGN DIGITAL CHEBYSHEV I I R FILTER clc ; clear ; close ; wp = input ( ’ E n t e r t h e D i g i t a l P a s s Band e d g e F r e q u e n c y = ’ ) ; // 0 . 2 ∗ %pi ws = input ( ’ E n t e r t h e D i g i t a l S t o p Band e d g e F r e q u e n c y = ’ ) ; // 0 . 6 ∗ %pi t = input ( ’ S a m p l i n g I n t e r v a l = ’ ) ; // 1 64 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 del1 = input ( ’ E n t e r t h e P a s s Band R i p p l e= ’ ) ; // 0 . 8 del2 = input ( ’ E n t e r t h e S t o p Band R i p p l e= ’ ) ; // 0 . 2 disp ( wp , ’Wp= ’ ) ; disp ( ws , ’Ws= ’ ) ; del = sqrt (((1/ del2 ) ^2) -1) ; disp ( del , ’ D e l t a= ’ ) ; epsilon = sqrt (((1/ del1 ) ^2) -1) ; disp ( epsilon , ’ E p s i l o n= ’ ) ; N =( acosh ( del / epsilon ) ) /( acosh ( ws / wp ) ) ; N = ceil ( N ) ; disp (N , ’N= ’ ) ; wc = wp /((((1/ del1 ) ^2) -1) ^(1/(2* N ) ) ) ; [ pols , gn ]= zpch1 (N , epsilon , wp ) ; hs = poly ( gn , ’ s ’ , ’ c o e f f ’ ) / real ( poly ( pols , ’ s ’ ) ) ; z = poly (0 , ’ z ’ ) ; hz = horner ( hs ,((2/ t ) *(( z -1) /( z +1) ) ) ) ; hw = frmag ( hz (2) , hz (3) ,512) ; // f r e q . r e s p o n s e f o r 512 points w =0: %pi /511: %pi ; a = gca () ; a . thickness =2; a . foreground = 5; a . font_color = 5; a . font_style = 5; plot ( w / %pi , abs ( hw ) ) ; xgrid (1) ; title ( ’ Magnitude R e s p o n s e o f D i g i t a l Chebyshew LPF IIR F i l t e r ’ ); xlabel ( ’ N o r m a l i z e d d i g i t a l F r e q u e n c y ’ ) ; ylabel ( ’ Magnitude i n db ’ ) ; //INPUT : // E n t e r t h e D i g i t a l P a s s Band e d g e F r e q u e n c y =0.2∗ %pi // E n t e r t h e D i g i t a l S t o p Band e d g e F r e q u e n c y =0.6∗ %pi // S a m p l i n g I n t e r v a l =1 // E n t e r t h e P a s s Band R i p p l e =0.8 // E n t e r t h e S t o p Band R i p p l e =0.2 65 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 //OUTPUT: //Wp= // 0 . 6 2 8 3 1 8 5 //Ws= // 1 . 8 8 4 9 5 5 6 // D e l t a= // 4 . 8 9 8 9 7 9 5 // E p s i l o n= // 0.75 //N= 2. 66