










































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Scilab code examples for performing Z-transform and frequency response analysis of digital filters. The code includes examples for Z-transform of sequences, magnitude and phase response plots, and design of digital IIR filters from analog IIR filters.
Typology: Study Guides, Projects, Research
1 / 82
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 text book companion and Scilab codes written in it can be downloaded from the ”Textbook Companion Project” Section at the website http://scilab.in/
Authors: J. G. Proakis and D. G. Manolakis
Title: Digital Signal Processing
Publisher: Prentice Hall India
Edition: 3rd
Year: 1997
Place: New Delhi
ISBN: 81-203-1129-
Scilab code Eqn 2.1.6 Unit sample sequence, also known as unit impulse sequence and delta sequence
1 // I m p l e m e n t a t i o n o f E q u a t i o n 2. 1. 6 i n C h a p t e r 2 2 // D i g i t a l S i g n a l P r o c e s s i n g by P r o a k i s , T h i r d E d i t i o n , PHI 3 // Page 45 4 5 clear ; clc ; close ; 6 L = 4; // U p p e r l i m i t 7 n = -L :L ; 8 x = [ zeros (1 , L ) ,1 , zeros (1 , L ) ]; 9 a = gca () ; 10 a. thickness = 2; 11 a. y_location = ” m i d d l e ” ; 12 plot2d3 ( ’ gnn ’ ,n , x) 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 Eqn 2.1.7 Unit step sequence
1 // I m p l e m e n t a t i o n o f E q u a t i o n 2. 1. 7 i n C h a p t e r 2 2 // D i g i t a l S i g n a l P r o c e s s i n g by P r o a k i s , T h i r d E d i t i o n , PHI 3 // Page 45 4 5 clear ; clc ; close ; 6 L = 4; // U p p e r l i m i t 7 n = -L :L ; 8 x = [ zeros (1 , L ) , ones (1 , L +1) ]; 9 a = gca () ; 10 a. thickness = 2; 11 a. y_location = ” m i d d l e ” ; 12 plot2d3 ( ’ gnn ’ ,n , x) 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 S t e p S i g n a l ’ , ’ n ’ , ’ x [ n ] ’ ) ;
Scilab code Eqn 2.1.8 Unit ramp sequence
1 // I m p l e m e n t a t i o n o f E q u a t i o n 2. 1. 8 i n C h a p t e r 2 2 // D i g i t a l S i g n a l P r o c e s s i n g by P r o a k i s , T h i r d E d i t i o n , PHI 3 // Page 45 4 5 clear ; clc ; close ; 6 L = 4; // U p p e r l i m i t 7 n = -L :L ; 8 x = [ zeros (1 , L ) ,0: L ]; 9 a = gca () ; 10 a. thickness = 2; 11 a. y_location = ” m i d d l e ” ; 12 plot2d3 ( ’ gnn ’ ,n , x) 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 Ramp S i g n a l ’ , ’ n ’ , ’ x [ n ] ’ ) ;
Scilab code Eqn 2.1.9a Exponential sequence
1 // I m p l e m e n t a t i o n o f E q u a t i o n 2. 1. 9 i n C h a p t e r 2
1 // I m p l e m e n t a t i o n o f E q u a t i o n 2. 1. 9 c i n C h a p t e r 2 2 // D i g i t a l S i g n a l P r o c e s s i n g by P r o a k i s , T h i r d E d i t i o n , PHI 3 // Page 46 4 // a < 1 5 clear ; 6 clc ; 7 close ; 8 a =0.5; 9 n = 0:10; 10 x = ( a )^ n ; 11 a = gca () ; 12 a. thickness = 2; 13 a. x_location = ” m i d d l e ” ; 14 plot2d3 ( ’ gnn ’ ,n , x) 15 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 D e c r e a s i n g S i g n a l ’ , ’ n ’ , ’ x [ n ] ’ ) ;
Scilab code Eqn 2.1.24 Even signal
1 // I m p l e m e n t a t i o n o f E q u a t i o n 2. 1. 2 4 i n C h a p t e r 2 2 // D i g i t a l S i g n a l P r o c e s s i n g by P r o a k i s , T h i r d E d i t i o n , PHI 3 // Page 51 4 5 clear ; clc ; close ; 6 n = -7:7; 7 x1 = [0 0 0 1 2 3 4]; 8 x = [ x1 ,5 , x1 ( length ( x1 ) : -1:1) ]; 9 a = gca () ; 10 a. thickness = 2; 11 a. y_location = ” m i d d l e ” ; 12 plot2d3 ( ’ gnn ’ ,n , x) 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 Even S i g n a l ’ , ’ n ’ , ’ x [ n ] ’ ) ;
Scilab code Eqn 2.1.25 Odd signal
1 // I m p l e m e n t a t i o n o f E q u a t i o n 2. 1. 2 5 i n C h a p t e r 2 2 // D i g i t a l S i g n a l P r o c e s s i n g by P r o a k i s , T h i r d E d i t i o n , PHI 3 // Page 51 4 clear ; 5 clc ; 6 close ; 7 n = -5:5; 8 x1 = [0 1 2 3 4 5]; 9 x = [ - x1 ( $ : -1:2) , x1 ]; 10 a = gca () ; 11 a. thickness = 2; 12 a. y_location = ” m i d d l e ” ; 13 a. x_location = ” m i d d l e ” 14 plot2d3 ( ’ gnn ’ ,n , x) 15 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 ODD S i g n a l ’ , ’ n ’ , ’ x [ n ] ’ ) ;
17 X4 = ztransfer_new ( x4 , n4 ) 18 x5 = [1 ,0 ,0]; // S ( n ) U n i t I m p u l s e s e q u e n c e 19 n5 = 0: length ( x5 ) -1; 20 X5 = ztransfer_new ( x5 , n5 ) 21 x6 = [0 ,0 ,0 ,1]; // S ( n−3) u n i t i m p u l s e s e q u e n c e s h i f t e d 22 n6 = 0: length ( x6 ) -1; 23 X6 = ztransfer_new ( x6 , n6 ) 24 x7 = [1 ,0 ,0 ,0]; // S ( n+3) U n i t i m p u l s e s e q u e n c e s h i f t e d 25 n7 = -3:0; 26 X7 = ztransfer_new ( x7 , n7 )
*Refer to the following for Scilab code of ztransfer new ARC 3A
Scilab code Exa 3.1.2 Z transform of x(n) = 0. 5 n.u(n)
1 // Example 3. 1. 2 2 //Z t r a n s f o r m o f x [ n ] = ( 0. 5 ) ˆn. u [ n ] 3 clear all ; 4 clc ; 5 close ; 6 syms n z ; 7 x =(0.5) ^ n 8 X = symsum ( x *( z ^( - n) ) ,n ,0 , %inf ) 9 disp (X , ” a n s=” )
Scilab code Exa 3.1.4 Z transform of x(n) = alphan
1 // Example 3. 1. 4 2 //Z t r a n s f o r m o f x [ n ] = −a l p h a ˆn. u[−n −1] 3 // a l p h a = 0. 5 4 clear all ; 5 close ; 6 clc ;
7 syms n z ; 8 x = -(0.5) ^( - n ) 9 X = symsum ( x *( z ^( n) ) ,n ,1 , %inf ) 10 disp (X , ” a n s=” )
Scilab code Exa 3.1.5 Z transform of x(n) = an.u(n) + bn.u(−n − 1)
1 // Example 3. 1. 5 2 //Z t r a n s f o r m o f x [ n ] = a ˆn. u [ n ]+ bˆn. u[−n −1] 3 // a = 0. 5 and b = 0. 6 4 clear all ; 5 close ; 6 clc ; 7 syms n z ; 8 x1 =(0.5) ^( n ) 9 X1 = symsum ( x1 *( z ^( - n ) ) ,n ,0 , %inf ) 10 x2 =(0.6) ^( - n ) 11 X2 = symsum ( x2 *( z ^( n ) ) ,n ,1 , %inf ) 12 X = ( X1 + X2 ) 13 disp (X , ” a n s=” )
Scilab code Exa 3.2.1 Z transform of x(n) = 3. 2 n.u(n) − 4. 3 n.u(n)
1 // Example 3. 2. 1 2 //Z t r a n s f o r m o f x [ n ] = 3. 2 ˆ n. u [ n ] − 4. 3 ˆ n. u [ n ] 3 clear all ; 4 close ; 5 clc ; 6 syms n z ; 7 x1 =(2) ^( n ) 8 X1 = symsum (3* x1 ( z ^( - n ) ) ,n ,0 , %inf ) 9 x2 =(3) ^( n ) 10 X2 = symsum (4 x2 *( z ^( - n ) ) ,n ,0 , %inf ) 11 X = ( X1 - X2 ) 12 disp (X , ” a n s=” )
Scilab code Exa 3.2.2 Z transform of x(n) = cos(W o.n).u(n), y(n) = sin(W o.n).u(n)
Scilab code Exa 3.2.4 Z transform of x(n) = u(n)
1 // Example 3. 2. 4 2 //Z t r a n s f o r m o f x [ n ] = u [ n ] 3 clear all ; 4 clc ; 5 close ; 6 syms n z ; 7 x =(1) ^ n 8 X = symsum ( x *( z ^( - n ) ) ,n ,0 , %inf ) 9 disp (X , ” a n s=” )
Scilab code Exa 3.2.6 Z transform of x(n) = u(−n)
1 // Example 3. 2. 6 2 //Z t r a n s f o r m o f x [ n ] = u[−n ] 3 clear all ; 4 clc ; 5 close ; 6 syms n z ; 7 x =(1) ^n 8 X = symsum ( x *( z ^( n )) ,n ,0 , %inf ) 9 disp (X , ” a n s=” )
Scilab code Exa 3.2.7 Z transform of x(n) = n.an.u(n)
1 // Example 3. 2. 7 2 //Z t r a n s f o r m o f x [ n ] = n. a ˆn. u [ n ] 3 clear all ; 4 clc ; 5 close ; 6 syms n z ; 7 x =(1) ^n ; 8 X = symsum ( x *( z ^( - n) ) ,n ,0 , %inf ) 9 disp (X , ” a n s=” ) 10 Y = diff (X , z )
Scilab code Exa 3.2.9 Convolution Property Proof
1 // Example 3. 2. 9 2 // C o n v o l u t i o n P r o p e r t y P r o o f 3 clear all ; 4 clc ; 5 close ; 6 x1 = [1 , -2 ,1]; 7 n1 = 0: length ( x1 ) -1; 8 X1 = ztransfer_new ( x1 , n1 ) 9 x2 = [1 ,1 ,1 ,1 ,1 ,1]; 10 n2 = 0: length ( x2 ) -1; 11 X2 = ztransfer_new ( x2 , n2 ) 12 X = X1 .* X
*Refer to the following for Scilab code of ztransfer new ARC 3A
Scilab code Exa 3.2.10 Correlation Property Proof
1 // Example 3. 2. 1 0 2 // C o r r e l a t i o n P r o p e r t y P r o o f 3 syms n z ; 4 x1 = (0.5) ^ n 5 X1 = symsum ( x1 *( z ^( - n ) ) ,n ,0 , %inf ) 6 X2 = symsum ( x1 *( z ^( n ) ) ,n ,0 , %inf ) 7 disp ( X1 , ”X1 =” ) 8 disp ( X2 , ”X2 =” ) 9 X = X1 * X 10 disp (X , ”X=” ) 11 // R e s u l t 12 // Which i s e q u i v a l e n t t o Rxx ( Z ) = 1 / ( 1 − 0. 5 ( z+z ˆ −1)