Scilab Code for Z-Transform and Frequency Response Analysis of Digital Filters, Study Guides, Projects, Research of Computer science

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

2019/2020

Uploaded on 02/18/2020

mmk123
mmk123 🇮🇳

4 documents

1 / 82

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Scilab Code for
Digital Signal Processing
Principles, Algorithms and Applications
by J. G. Proakis & D. G. Manolakis1
Created by
Prof. R. Senthilkumar
Institute of Road and Transport Technology
Cross-Checked by
Mrs. Phani Swathi Chitta
Research Scholar, IITB
under the guidance of
Prof. Saravanan Vijayakumaran, IIT Bombay
23 August 2010
1Funded 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/
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52

Partial preview of the text

Download Scilab Code for Z-Transform and Frequency Response Analysis of Digital Filters and more Study Guides, Projects, Research Computer science in PDF only on Docsity!

Scilab Code for

Digital Signal Processing

Principles, Algorithms and Applications

by J. G. Proakis & D. G. Manolakis

Created by

Prof. R. Senthilkumar

Institute of Road and Transport Technology

rsenthil [email protected]

Cross-Checked by

Mrs. Phani Swathi Chitta

Research Scholar, IITB

under the guidance of

Prof. Saravanan Vijayakumaran, IIT Bombay

[email protected]

23 August 2010

(^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/

Book Details

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-

Contents

  • List of Scilab Codes
  • 1 Introduction
    • 1.1 Scilab Code
  • 2 Discrete Time Signals and Systems
    • 2.1 Scilab Code
    • of LTI Systems 3 The z Transformation and its Applications to the Analysis
    • 3.1 Scilab Code
  • 4 Frequency Analysis of Signal and Systems
    • 4.1 Scilab Code
    • tions 5 Discrete Fourier Transform: its Properties and Applica-
    • 5.1 Scilab Code
    • gorithms 6 Efficient Computation of DFT: Fast Fourier Transform, Al-
    • 6.1 Scilab Code
  • 7 Implementation of Discrete Time System
    • 7.1 Scilab Code
  • 8 Design of Digital Filters
    • 8.1 Scilab Code
  • 10 Multirate Digital Signal Processing
    • 10.1 Scilab Code
  • 11 Linear Predictions and Optimum Linear Filter
    • 11.1 Scilab Code
  • 12 Power Spectrum Estimation
    • 12.1 Scilab Code
  • Eqn 1.2.1 Discrete time signal List of Scilab Codes
  • Eqn 2.1.6 Unit sample sequence
  • Eqn 2.1.7 Unit step sequence
  • Eqn 2.1.8 Unit ramp sequence
  • Eqn 2.1.9a Exponential sequence
  • Eqn 2.1.9b Exponential increasing sequence
  • Eqn 2.1.9c Exponential decreasing sequence
  • Eqn 2.1.24 Even signal
  • Eqn 2.1.25 Odd signal
  • Exa 3.1.1 Direct Ztransform
  • Exa 3.1.2 Z transform
  • Exa 3.1.4 Z transform
  • Exa 3.1.5 Z transform
  • Exa 3.2.1 Z transform
  • Exa 3.2.2 Sinusoidal Signals
  • Exa 3.2.3 Time Shifting Property
  • Exa 3.2.4 Z transform
  • Exa 3.2.6 Z transform
  • Exa 3.2.7 Z transform
  • Exa 3.2.9 Convolution
  • Exa 3.2.10 Autocorrelation
  • ARC 3A Ztransfer
  • Exa 4.1.2 Fourier Transform
  • Exa 4.2.7 Continuous Time Fourier Transform
  • Exa 4.3.4 Convolution Property
  • Exa 4.4.2 Frequency Response
  • Exa 4.4.4 Frequency Response
  • Exa 5.1.2 Discrete Fourier Transform
  • Exa 5.1.3 Discrete Fourier Transform
  • Exa 5.2.1 Example 5.2.1 and 5.2.2
  • Exa 5.3.1 Linear Filtering DFT
  • Exa 5.4.1 Zero Padding
  • Exa 6.4.1 SNR DFT
  • Exa 6.4.2 SNR FFT Algorithm
  • Prb 6.8 FFT Exercise1
  • Prb 6.11 FFT Exercise2
  • Exa 7.6.3 Coeffecient Quantization NOise
  • Eqn 7.7.1 Dead Band
  • Exa 7.7.1 Round off noise variance
  • Eqn 7.7.40 SQNR
  • Exa 8.2.1 Design of Filter
  • Exa 8.2.2 Design of Filter
  • Exa 8.2.3 Remez Algorithm Based
  • Exa 8.2.4 Remez Algorithm Based
  • Exa 8.2.5 FIR Differentiator
  • Exa 8.2.6 Hilbert Transform
  • Eqn 8.2.28 Design of Filter
  • Exa 8.3.2 Analog to Digital
  • Exa 8.3.4 Analog to Digital
  • Exa 8.3.5 Analog to Digital
  • Exa 8.3.6 IIR Filter Design Butterworth Filter
  • Exa 8.3.7 IIR Filter Design
  • Exa 8.4.1 Digital IIR Butterworth Filter
  • Exa 8.4.2 IIR Filter Design Butterworth Filter
  • CF 8.5 Window Functions
  • CF 8.6 Window Functions
  • CF 8.7 Window Functions
  • Exa 10.5.1 FIR Decimation
  • Exa 10.5.2 FIR Interpolation
  • Exa 10.6.1 Sampling Rate Conversion Decimation
  • Exa 10.8.1 Signal Distortion Ratio
  • Exa 10.8.2 Signal Distortion Ratio
  • Exa 10.9.1 Sampling Rate Conversion Decimation Interpolation
  • Exa 11.6.1 Wiener Filter
  • Exa 12.1.1 Spectrum of Signal
  • Exa 12.1.2 Spectrum using DFT
  • Exa 12.5.1 Additive Noise Parameters
  • AE 4.2.7 Discrete Time Fourier Transform
  • ARC 4A sinc
  • AE 4.4.2 Frequency response
  • AE 8.2.28ADesign of Filter
  • AE 8.2.28BDesign of Filter
  • AE 8.2.28CDesign of Filter
  • AE 8.3.5 First Order Butterworth Filter
  • AE 8.3.6 IIR Butterworth Filter
  • AE 8.4.1 First Order Butterworth Filter
  • AE 8.4.2A IIR Filter Design Butterworth Filter
  • AE 8.4.2B IIR Filter Design Butterworth Filter

Chapter 2

Discrete Time Signals and

Systems

2.1 Scilab Code

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)

  • ( 0. 5 ˆ 2 ) ) 13 // i. e f o r a = 0. 5 Rxx ( Z ) = 1/(1 − a ( z+z ˆ −1)+(a ˆ 2 ) )