8/11/2019 Digital Signal Processing_R. Babu
1/148
Scilab Textbook Companion for
Digital Signal Processing
by R. Babu1
Created byMohammad Faisal Siddiqui
B.Tech (pursuing)Electronics Engineering
Jamia Milia IslamiaCollege Teacher
Dr. Sajad A. Loan, JMI, New DCross-Checked by
Santosh Kumar, IITB
August 10, 2013
1Funded by a grant from the National Mission on Education through ICT,http://spoken-tutorial.org/NMEICT-Intro. This Textbook Companion and Scilabcodes written in it can be downloaded from the Textbook Companion Projectsection at the website http://scilab.in
8/11/2019 Digital Signal Processing_R. Babu
2/148
Book Description
Title: Digital Signal Processing
Author: R. Babu
Publisher: Scitech Publications
Edition: 4
Year: 2010
ISBN: 81-8371-081-7
1
8/11/2019 Digital Signal Processing_R. Babu
3/148
Scilab numbering policy used in this document and the relation to theabove book.
Exa Example (Solved example)
Eqn Equation (Particular equation of the above book)
AP Appendix to Example(Scilab Code that is an Appednix to a particularExample of the above book)
For example, Exa 3.51 means solved example 3.51 of this book. Sec 2.3 meansa scilab code whose theory is explained in Section 2.3 of the book.
2
8/11/2019 Digital Signal Processing_R. Babu
4/148
Contents
List of Scilab Codes 4
1 DISCRETE TIME SIGNALS AND LINEAR SYSTEMS 11
2 THE Z TRANSFORM 34
3 THE DISCRETE FOURIER TRANSFORM 59
4 THE FAST FOURIER TRANSFORM 79
5 INFINITE IMPULSE RESPONSE FILTERS 90
6 FINITE IMPULSE RESPONSE FILTERS 102
7 FINITE WORD LENGTH EFFECTS IN DIGITAL FIL-
TERS 139
8 MULTIRATE SIGNAL PROCESSING 141
9 STATISTICAL DIGITAL SIGNAL PROCESSING 143
11 DIGITAL SIGNAL PROCESSORS 146
3
8/11/2019 Digital Signal Processing_R. Babu
5/148
List of Scilab Codes
Exa 1.1 Continuous Time Plot and Discrete Time Plot . . . . 11Exa 1.2 Continuous Time Plot and Discrete Time Plot . . . . 13Exa 1.3.a Evaluate the Summations . . . . . . . . . . . . . . . . 14Exa 1.3.b Evaluate the Summations . . . . . . . . . . . . . . . . 14Exa 1.4.a Check for Energy or Power Signals . . . . . . . . . . . 15Exa 1.4.d Check for Energy or Power Signals . . . . . . . . . . . 15Exa 1.5.a Determining Periodicity of Signal . . . . . . . . . . . . 16Exa 1.5.c Determining Periodicity of Signal . . . . . . . . . . . . 18Exa 1.5.d Determining Periodicity of Signal . . . . . . . . . . . . 19Exa 1.11 Stability of the System . . . . . . . . . . . . . . . . . 21Exa 1.12 Convolution Sum of Two Sequences . . . . . . . . . . 21Exa 1.13 Convolution of Two Signals . . . . . . . . . . . . . . . 22Exa 1.18 Cross Correlation of Two Sequences . . . . . . . . . . 22
Exa 1.19 Determination of Input Sequence . . . . . . . . . . . . 23Exa 1.32.a Plot Magnitude and Phase Response . . . . . . . . . . 24Exa 1.37 Sketch Magnitude and Phase Response. . . . . . . . . 24Exa 1.38 Plot Magnitude and Phase Response . . . . . . . . . . 26Exa 1.45 Filter to Eliminate High Frequency Component . . . . 27Exa 1.57.a Discrete Convolution of Sequences . . . . . . . . . . . 29Exa 1.61 Fourier Transform . . . . . . . . . . . . . . . . . . . . 29Exa 1.62 Fourier Transform . . . . . . . . . . . . . . . . . . . . 30Exa 1.64.a Frequency Response of LTI System . . . . . . . . . . . 31Exa 1.64.c Frequency Response of LTI System . . . . . . . . . . . 31Exa 2.1 z Transform and ROC of Causal Sequence . . . . . . . 34
Exa 2.2 z Transform and ROC of Anticausal Sequence . . . . . 34Exa 2.3 z Transform of the Sequence . . . . . . . . . . . . . . 35Exa 2.4 z Transform and ROC of the Signal . . . . . . . . . . 36Exa 2.5 z Transform and ROC of the Signal . . . . . . . . . . 36
4
8/11/2019 Digital Signal Processing_R. Babu
6/148
Exa 2.6 Stability of the System . . . . . . . . . . . . . . . . . 37
Exa 2.7 z Transform of the Signal . . . . . . . . . . . . . . . . 37Exa 2.8.a z Transform of the Signal . . . . . . . . . . . . . . . . 37Exa 2.9 z Transform of the Sequence . . . . . . . . . . . . . . 38Exa 2.10 z Transform Computation . . . . . . . . . . . . . . . . 38Exa 2.11 z Transform of the Sequence . . . . . . . . . . . . . . 39Exa 2.13.a z Transform of Discrete Time Signals . . . . . . . . . . 39Exa 2.13.b z Transform of Discrete Time Signals. . . . . . . . . . 40Exa 2.13.c z Transform of Discrete Time Signals . . . . . . . . . . 40Exa 2.13.d z Transform of Discrete Time Signals. . . . . . . . . . 41Exa 2.16 Impulse Response of the System . . . . . . . . . . . . 41Exa 2.17 Pole Zero Plot of the Difference Equation . . . . . . . 42
Exa 2.19 Frequency Response of the System . . . . . . . . . . . 44Exa 2.20.a Inverse z Transform Computation . . . . . . . . . . . 44Exa 2.22 Inverse z Transform Computation . . . . . . . . . . . 45Exa 2.23 Causal Sequence Determination. . . . . . . . . . . . . 45Exa 2.34 Impulse Response of the System . . . . . . . . . . . . 46Exa 2.35.a Pole Zero Plot of the System . . . . . . . . . . . . . . 47Exa 2.35.b Unit Sample Response of the System . . . . . . . . . . 49Exa 2.38 Determine Output Response . . . . . . . . . . . . . . 50Exa 2.40 Input Sequence Computation . . . . . . . . . . . . . . 52Exa 2.41.a z Transform of the Signal . . . . . . . . . . . . . . . . 53
Exa 2.41.b z Transform of the Signal . . . . . . . . . . . . . . . . 53Exa 2.41.c z Transform of the Signal . . . . . . . . . . . . . . . . 54Exa 2.45 Pole Zero Pattern of the System . . . . . . . . . . . . 55Exa 2.53.a z Transform of the Sequence . . . . . . . . . . . . . . 55Exa 2.53.b z Transform of the Signal . . . . . . . . . . . . . . . . 55Exa 2.53.c z Transform of the Signal . . . . . . . . . . . . . . . . 56Exa 2.53.d z Transform of the Signal . . . . . . . . . . . . . . . . 56Exa 2.54 z Transform of Cosine Signal . . . . . . . . . . . . . . 56Exa 2.58 Impulse Response of the System . . . . . . . . . . . . 58Exa 3.1 DFT and IDFT . . . . . . . . . . . . . . . . . . . . . 59Exa 3.2 DFT of the Sequence . . . . . . . . . . . . . . . . . . 60
Exa 3.3 8 Point DFT . . . . . . . . . . . . . . . . . . . . . . . 62Exa 3.4 IDFT of the given Sequence . . . . . . . . . . . . . . . 62Exa 3.7 Plot the Sequence . . . . . . . . . . . . . . . . . . . . 63Exa 3.9 Remaining Samples . . . . . . . . . . . . . . . . . . . 64Exa 3.11 DFT Computation . . . . . . . . . . . . . . . . . . . . 65
5
8/11/2019 Digital Signal Processing_R. Babu
7/148
Exa 3.13 Circular Convolution. . . . . . . . . . . . . . . . . . . 65
Exa 3.14 Circular Convolution. . . . . . . . . . . . . . . . . . . 66Exa 3.15 Determine Sequence x3 . . . . . . . . . . . . . . . . . 67Exa 3.16 Circular Convolution. . . . . . . . . . . . . . . . . . . 67Exa 3.17 Circular Convolution. . . . . . . . . . . . . . . . . . . 68Exa 3.18 Output Response. . . . . . . . . . . . . . . . . . . . . 69Exa 3.20 Output Response. . . . . . . . . . . . . . . . . . . . . 70Exa 3.21 Linear Convolution. . . . . . . . . . . . . . . . . . . . 70Exa 3.23.a N Point DFT Computation . . . . . . . . . . . . . . . 71Exa 3.23.b N Point DFT Computation . . . . . . . . . . . . . . . 71Exa 3.23.c N Point DFT Computation . . . . . . . . . . . . . . . 72Exa 3.23.d N Point DFT Computation . . . . . . . . . . . . . . . 72
Exa 3.23.e N Point DFT Computation . . . . . . . . . . . . . . . 72Exa 3.23.f N Point DFT Computation . . . . . . . . . . . . . . . 73Exa 3.24 DFT of the Sequence . . . . . . . . . . . . . . . . . . 73Exa 3.25 8 Point Circular Convolution . . . . . . . . . . . . . . 73Exa 3.26 Linear Convolution using DFT . . . . . . . . . . . . . 74Exa 3.27.a Circular Convolution Computation . . . . . . . . . . . 75Exa 3.27.b Circular Convolution Computation . . . . . . . . . . . 75Exa 3.30 Calculate value of N . . . . . . . . . . . . . . . . . . . 76Exa 3.32 Sketch Sequence . . . . . . . . . . . . . . . . . . . . . 76Exa 3.36 Determine IDFT . . . . . . . . . . . . . . . . . . . . . 78
Exa 4.3 Shortest Sequence N Computation . . . . . . . . . . . 79Exa 4.4 Twiddle Factor Exponents Calculation . . . . . . . . . 80Exa 4.6 DFT using DIT Algorithm . . . . . . . . . . . . . . . 80Exa 4.8 DFT using DIF Algorithm . . . . . . . . . . . . . . . 81Exa 4.9 8 Point DFT of the Sequence . . . . . . . . . . . . . . 81Exa 4.10 4 Point DFT of the Sequence . . . . . . . . . . . . . . 82Exa 4.11 IDFT of the Sequence using DIT Algorithm . . . . . . 82Exa 4.12 8 Point DFT of the Sequence . . . . . . . . . . . . . . 82Exa 4.13 8 Point DFT of the Sequence . . . . . . . . . . . . . . 83Exa 4.14 DFT using DIT Algorithm . . . . . . . . . . . . . . . 83Exa 4.15 DFT using DIF Algorithm . . . . . . . . . . . . . . . 84
Exa 4.16.a 8 Point DFT using DIT FFT . . . . . . . . . . . . . . 84Exa 4.16.b 8 Point DFT using DIT FFT . . . . . . . . . . . . . . 85Exa 4.17 IDFT using DIF Algorithm . . . . . . . . . . . . . . . 85Exa 4.18 IDFT using DIT Algorithm . . . . . . . . . . . . . . . 86Exa 4.19 FFT Computation of the Sequence . . . . . . . . . . . 86
6
8/11/2019 Digital Signal Processing_R. Babu
8/148
Exa 4.20 8 Point DFT by Radix 2 DIT FFT . . . . . . . . . . . 86
Exa 4.21 DFT using DIT FFT Algorithm . . . . . . . . . . . . 87Exa 4.22 Compute X using DIT FFT . . . . . . . . . . . . . . . 87Exa 4.23 DFT using DIF FFT Algorithm . . . . . . . . . . . . 88Exa 4.24 8 Point DFT of the Sequence . . . . . . . . . . . . . . 88Exa 5.1 Order of the Filter Determination . . . . . . . . . . . 90Exa 5.2 Order of Low Pass Butterworth Filter . . . . . . . . . 90Exa 5.4 Analog Butterworth Filter Design . . . . . . . . . . . 91Exa 5.5 Analog Butterworth Filter Design . . . . . . . . . . . 92Exa 5.6 Order of Chebyshev Filter . . . . . . . . . . . . . . . . 92Exa 5.7 Chebyshev Filter Design. . . . . . . . . . . . . . . . . 93Exa 5.8 Order of Type 1 Low Pass Chebyshev Filter . . . . . . 93
Exa 5.9 Chebyshev Filter Design. . . . . . . . . . . . . . . . . 94Exa 5.10 HPF Filter Design with given Specifications . . . . . . 94Exa 5.11 Impulse Invariant Method Filter Design . . . . . . . . 95Exa 5.12 Impulse Invariant Method Filter Design . . . . . . . . 96Exa 5.13 Impulse Invariant Method Filter Design . . . . . . . . 96Exa 5.15 Impulse Invariant Method Filter Design . . . . . . . . 97Exa 5.16 Bilinear Transformation Method Filter Design. . . . . 97Exa 5.17 HPF Design using Bilinear Transform . . . . . . . . . 98Exa 5.18 Bilinear Transformation Method Filter Design. . . . . 99Exa 5.19 Single Pole LPF into BPF Conversion . . . . . . . . . 99
Exa 5.29 Pole Zero IIR Filter into Lattice Ladder Structure . . 100Exa 6.1 Group Delay and Phase Delay . . . . . . . . . . . . . 102Exa 6.5 LPF Magnitude Response . . . . . . . . . . . . . . . . 104Exa 6.6 HPF Magnitude Response . . . . . . . . . . . . . . . . 104Exa 6.7 BPF Magnitude Response . . . . . . . . . . . . . . . . 106Exa 6.8 BRF Magnitude Response. . . . . . . . . . . . . . . . 108Exa 6.9.a HPF Magnitude Response using Hanning Window . . 110Exa 6.9.b HPF Magnitude Response using Hamming Window. . 112Exa 6.10 Hanning Window Filter Design . . . . . . . . . . . . . 114Exa 6.11 LPF Filter Design using Kaiser Window . . . . . . . . 116Exa 6.12 BPF Filter Design using Kaiser Window . . . . . . . . 118
Exa 6.13.a Digital Differentiator using Rectangular Window . . . 122Exa 6.13.b Digital Differentiator using Hamming Window . . . . 124Exa 6.14.a Hilbert Transformer using Rectangular Window. . . . 124Exa 6.14.b Hilbert Transformer using Blackman Window . . . . . 126Exa 6.15 Filter Coefficients obtained by Sampling . . . . . . . . 127
7
8/11/2019 Digital Signal Processing_R. Babu
9/148
Exa 6.16 Coefficients of Linear phase FIR Filter . . . . . . . . . 128
Exa 6.17 BPF Filter Design using Sampling Method . . . . . . 128Exa 6.18.a Frequency Sampling Method FIR LPF Filter . . . . . 129Exa 6.18.b Frequency Sampling Method FIR LPF Filter . . . . . 130Exa 6.19 Filter Coefficients Determination . . . . . . . . . . . . 131Exa 6.20 Filter Coefficients using Hamming Window . . . . . . 133Exa 6.21 LPF Filter using Rectangular Window . . . . . . . . . 135Exa 6.28 Filter Coefficients for Direct Form Structure. . . . . . 137Exa 6.29 Lattice Filter Coefficients Determination. . . . . . . . 138Exa 7.2 Subtraction Computation . . . . . . . . . . . . . . . . 139Exa 7.14 Variance of Output due to AD Conversion Process . . 139Exa 8.9 Two Component Decomposition . . . . . . . . . . . . 141
Exa 8.10 Two Band Polyphase Decomposition . . . . . . . . . . 142Exa 9.7.a Frequency Resolution Determination . . . . . . . . . . 143Exa 9.7.b Record Length Determination. . . . . . . . . . . . . . 144Exa 9.8.a Smallest Record Length Computation . . . . . . . . . 144Exa 9.8.b Quality Factor Computation . . . . . . . . . . . . . . 145Exa 11.3 Program for Integer Multiplication . . . . . . . . . . . 146Exa 11.5 Function Value Calculation . . . . . . . . . . . . . . . 146
8
8/11/2019 Digital Signal Processing_R. Babu
10/148
List of Figures
1.1 Continuous Time Plot and Discrete Time Plot . . . . . . . . 121.2 Continuous Time Plot and Discrete Time Plot . . . . . . . . 131.3 Determining Periodicity of Signal . . . . . . . . . . . . . . . 171.4 Determining Periodicity of Signal . . . . . . . . . . . . . . . 181.5 Determining Periodicity of Signal . . . . . . . . . . . . . . . 201.6 Plot Magnitude and Phase Response . . . . . . . . . . . . . 231.7 Sketch Magnitude and Phase Response . . . . . . . . . . . . 251.8 Plot Magnitude and Phase Response . . . . . . . . . . . . . 261.9 Filter to Eliminate High Frequency Component . . . . . . . 281.10 Frequency Response of LTI System . . . . . . . . . . . . . . 301.11 Frequency Response of LTI System . . . . . . . . . . . . . . 32
2.1 Pole Zero Plot of the Difference Equation. . . . . . . . . . . 422.2 Frequency Response of the System . . . . . . . . . . . . . . 432.3 Impulse Response of the System . . . . . . . . . . . . . . . . 462.4 Pole Zero Plot of the System. . . . . . . . . . . . . . . . . . 482.5 Unit Sample Response of the System . . . . . . . . . . . . . 492.6 Determine Output Response . . . . . . . . . . . . . . . . . . 512.7 Pole Zero Pattern of the System . . . . . . . . . . . . . . . . 542.8 Impulse Response of the System . . . . . . . . . . . . . . . . 57
3.1 DFT of the Sequence . . . . . . . . . . . . . . . . . . . . . . 603.2 Plot the Sequence . . . . . . . . . . . . . . . . . . . . . . . . 633.3 Sketch Sequence. . . . . . . . . . . . . . . . . . . . . . . . . 77
6.1 LPF Magnitude Response . . . . . . . . . . . . . . . . . . . 1036.2 HPF Magnitude Response . . . . . . . . . . . . . . . . . . . 1056.3 BPF Magnitude Response . . . . . . . . . . . . . . . . . . . 1076.4 BRF Magnitude Response . . . . . . . . . . . . . . . . . . . 109
9
8/11/2019 Digital Signal Processing_R. Babu
11/148
6.5 HPF Magnitude Response using Hanning Window. . . . . . 111
6.6 HPF Magnitude Response using Hamming Window . . . . . 1136.7 Hanning Window Filter Design . . . . . . . . . . . . . . . . 1156.8 LPF Filter Design using Kaiser Window . . . . . . . . . . . 1176.9 BPF Filter Design using Kaiser Window . . . . . . . . . . . 1196.10 Digital Differentiator using Rectangular Window. . . . . . . 1216.11 Digital Differentiator using Hamming Window . . . . . . . . 1236.12 Hilbert Transformer using Rectangular Window . . . . . . . 1256.13 Hilbert Transformer using Blackman Window . . . . . . . . 1266.14 Frequency Sampling Method FIR LPF Filter . . . . . . . . . 1296.15 Frequency Sampling Method FIR LPF Filter . . . . . . . . . 1316.16 Filter Coefficients Determination . . . . . . . . . . . . . . . 132
6.17 Filter Coefficients using Hamming Window . . . . . . . . . . 1346.18 LPF Filter using Rectangular Window . . . . . . . . . . . . 136
10
8/11/2019 Digital Signal Processing_R. Babu
12/148
Chapter 1
DISCRETE TIME SIGNALS
AND LINEAR SYSTEMS
Scilab code Exa 1.1 Continuous Time Plot and Discrete Time Plot
1 / / E xa mp le 1 . 12 // S k et ch t he c o n ti n uo u s t im e s i g n a l x ( t ) =2e x p(2 t )
and a l s o i t s d i s c r e t e t i me e q u i v a l e n t s i g n a l w i t ha s am pl in g p e r i od T = 0 . 2 s e c
3 c l e ar a ll ;
4 clc ;
5 close ;
6 t = 0 : 0 . 0 1 : 2 ;
7 x 1 = 2 * exp ( - 2 * t ) ;
8 subplot ( 1 , 2 , 1 ) ;
9 plot ( t , x 1 ) ;
10 x l a b e l ( t ) ;
11 y l a b e l ( x ( t ) ) ;12 t i t l e (CONTINUOUS TIME PLOT ) ;13 n = 0 : 0 . 2 : 2 ;
14 x 2 = 2 * exp ( - 2 * n ) ;
15 subplot ( 1 , 2 , 2 ) ;
11
8/11/2019 Digital Signal Processing_R. Babu
13/148
Figure 1.1: Continuous Time Plot and Discrete Time Plot
12
8/11/2019 Digital Signal Processing_R. Babu
14/148
Figure 1.2: Continuous Time Plot and Discrete Time Plot
16 plot2d3 ( n , x 2 ) ;17 x l a b e l ( n ) ;18 y l a b e l ( x ( n ) ) ;19 t i t l e ( DISCRETE TIME PLOT ) ;
Scilab code Exa 1.2 Continuous Time Plot and Discrete Time Plot
1 / / E xa mp le 1 . 22 // S k et ch t he c o n ti n uo u s t im e s i g n a l x=s i n ( 7t )+si n
( 1 0t ) and a l s o i t s d i s c r e t e t i m e e q ui v a l e n ts i g n a l w i th a s am pl in g p e ri o d T = 0 . 2 s e c
13
8/11/2019 Digital Signal Processing_R. Babu
15/148
3 c l e ar a ll ;
4 clc ;5 close ;
6 t = 0 : 0 . 0 1 : 2 ;
7 x1 = sin ( 7 * t ) + sin ( 1 0 * t ) ;
8 subplot ( 1 , 2 , 1 ) ;
9 plot ( t , x 1 ) ;
10 x l a b e l ( t ) ;11 y l a b e l ( x ( t ) ) ;12 t i t l e (CONTINUOUS TIME PLOT ) ;13 n = 0 : 0 . 2 : 2 ;
14 x2 = sin ( 7 * n ) + sin ( 1 0 * n ) ;
15 subplot ( 1 , 2 , 2 ) ;16 plot2d3 ( n , x 2 ) ;
17 x l a b e l ( n ) ;18 y l a b e l ( x ( n ) ) ;19 t i t l e ( DISCRETE TIME PLOT ) ;
Scilab code Exa 1.3.a Evaluate the Summations
1 / / Example 1 . 3 ( a )2 //MAXIMA SCILAB TOOLBOX REQUIRED FOR THIS PROGRAM3 / / C a l c u l a t e F o l l o w i n g S um ma ti on s4 c l e ar a ll ;
5 clc ;
6 close ;
7 s y ms n ;
8 X = s ym su m ( sin ( 2* n ) , n ,2 , 2 ) ;
9 / / D i s p l a y t h e r e s u l t i n command window10 disp (X , The V al ue o f s um ma ti on c om es o u t t o b e : ) ;
Scilab code Exa 1.3.b Evaluate the Summations
14
8/11/2019 Digital Signal Processing_R. Babu
16/148
1 / / Exam ple 1 . 3 ( b )
2 //MAXIMA SCILAB TOOLBOX REQUIRED FOR THIS PROGRAM3 / / C a l c u l a t e F o l l o w i n g S um ma ti on s4 c l e ar a ll ;
5 clc ;
6 close ;
7 s y ms n ;
8 X = s ym su m ( %e ^ (2 * n) , n ,0 , 0) ;
9 / / D i s p l a y t h e r e s u l t i n command window10 disp (X , The V al ue o f s um ma ti on c om es o u t t o b e : ) ;
Scilab code Exa 1.4.a Check for Energy or Power Signals
1 / / Example 1 . 4 ( a )2 //MAXIMA SCILAB TOOLBOX REQUIRED FOR THIS PROGRAM3 / / Fi nd E ne rg y and Power o f G iv en S i g n a l s4 c l e ar a ll ;
5 clc ;
6 close ;
7 syms n N ;
8 x = ( 1 / 3 ) ^ n ;9 E = s ym su m ( x ^2 , n ,0 , % in f );
10 / / D i s p l a y t h e r e s u l t i n command window11 disp (E , Energy : ) ;12 p = ( 1/ (2 * N + 1) ) * s y ms um ( x ^2 , n ,0 , N ) ;
13 P = l i m i t ( p , N , % i n f ) ;
14 disp (P , Power : ) ;15 // The E nergy i s F i n i t e and P ower i s 0 . T h e re f o re t he
g iv en s i g n a l i s an Energy S i gn a l
Scilab code Exa 1.4.d Check for Energy or Power Signals
1 / / Exam ple 1 . 4 ( d )
15
8/11/2019 Digital Signal Processing_R. Babu
17/148
2 //MAXIMA SCILAB TOOLBOX REQUIRED FOR THIS PROGRAM
3 / / Fi nd E ne rg y and Power o f G iv en S i g n a l s4 c l e ar a ll ;5 clc ;
6 close ;
7 syms n N ;
8 x = % e ^ ( 2 * n ) ;
9 E = s ym su m ( x ^2 , n ,0 , % in f );
10 / / D i s p l a y t h e r e s u l t i n command window11 disp (E , Energy : ) ;12 p = ( 1/ (2 * N + 1) ) * s y ms um ( x ^2 , n ,0 , N ) ;
13 P = l i m i t ( p , N , % i n f ) ;
14 disp (P , Power : ) ;15 / / The E n er gy a nd Po we r i s i n f i n i t e . T h e r e f o r e t h e
g i v en s i g n a l i s an n e i t h e r Energy S i gn a l n o rPower S i g n a l
Scilab code Exa 1.5.a Determining Periodicity of Signal
1 / / Example 1 . 5 ( a )2 / /To D e te rm in e Whether G ive n S i g n a l i s P e r i o d i c o r
n ot3 c l e ar a ll ;
4 clc ;
5 close ;
6 t = 0 : 0 . 0 1 : 2 ;
7 x1 = exp ( % i * 6 * % p i * t ) ;
8 subplot ( 1 , 2 , 1 ) ;
9 plot ( t , x 1 ) ;10 x l a b e l ( t ) ;11 y l a b e l ( x ( t ) ) ;12 t i t l e (CONTINUOUS TIME PLOT ) ;13 n = 0 : 0 . 2 : 2 ;
16
8/11/2019 Digital Signal Processing_R. Babu
18/148
Figure 1.3: Determining Periodicity of Signal
17
8/11/2019 Digital Signal Processing_R. Babu
19/148
8/11/2019 Digital Signal Processing_R. Babu
20/148
2 / /To D e te rm in e Whether G ive n S i g n a l i s P e r i o d i c o r
n ot3 c l e ar a ll ;4 clc ;
5 close ;
6 t = 0 : 0 . 0 1 : 1 0 ;
7 x1 = cos ( 2 * % p i * t / 3 ) ;
8 subplot ( 1 , 2 , 1 ) ;
9 plot ( t , x 1 ) ;
10 x l a b e l ( t ) ;11 y l a b e l ( x ( t ) ) ;12 t i t l e (CONTINUOUS TIME PLOT ) ;
13 n = 0 : 0 . 2 : 1 0 ;14 x2 = cos ( 2 * % p i * n / 3 ) ;
15 subplot ( 1 , 2 , 2 ) ;
16 plot2d3 ( n , x 2 ) ;
17 x l a b e l ( n ) ;18 y l a b e l ( x ( n ) ) ;19 t i t l e ( DISCRETE TIME PLOT ) ;20 / / Hen ce G ive n S i g n a l i s P e r i o d i c w it h N=3
Scilab code Exa 1.5.d Determining Periodicity of Signal
1 / / Exam ple 1 . 5 ( d )2 / /To D e te rm in e Whether G ive n S i g n a l i s P e r i o d i c o r
n ot3 c l e ar a ll ;
4 clc ;
5 close ;6 t = 0 : 0 . 0 1 : 5 0 ;
7 x1 = cos ( % p i * t / 3 ) + cos ( 3 * % p i * t / 4 ) ;
8 subplot ( 1 , 2 , 1 ) ;
9 plot ( t , x 1 ) ;
19
8/11/2019 Digital Signal Processing_R. Babu
21/148
Figure 1.5: Determining Periodicity of Signal
20
8/11/2019 Digital Signal Processing_R. Babu
22/148
10 x l a b e l ( t ) ;
11 y l a b e l ( x ( t ) ) ;12 t i t l e (CONTINUOUS TIME PLOT ) ;13 n = 0 : 0 . 2 : 5 0 ;
14 x2 = cos ( % p i * n / 3 ) + cos ( 3 * % p i * n / 4 ) ;
15 subplot ( 1 , 2 , 2 ) ;
16 plot2d3 ( n , x 2 ) ;
17 x l a b e l ( n ) ;18 y l a b e l ( x ( n ) ) ;19 t i t l e ( DISCRETE TIME PLOT ) ;20 / / Hen ce G ive n S i g n a l i s P e r i o d i c w it h N=24
Scilab code Exa 1.11 Stability of the System
1 / / E x am pl e 1 . 1 12 //MAXIMA SCILAB TOOLBOX REQUIRED FOR THIS PROGRAM3 // T e st i ng S t a b i l i t y o f Given System4 c l e ar a ll ;
5 clc ;
6 close ;
7 s y ms n ;8 x = (1 /2 ) ^ n
9 X = s ym su m ( x, n ,0 , % in f ) ;
10 / / D i s p l a y t h e r e s u l t i n command window11 disp (X , S um ma ti on i s : ) ;12 disp ( Hence Summation < i n f i n i t y . Given System i s
S t a b l e ) ;
Scilab code Exa 1.12 Convolution Sum of Two Sequences
1 / / E x am pl e 1 . 1 22 / / Program t o Compute c o n v o l u t i o n o f g i v e n s e q u e n c es3 // x ( n ) =[3 2 1 2 ] , h ( n) =[1 2 1 2 ] ;
21
8/11/2019 Digital Signal Processing_R. Babu
23/148
8/11/2019 Digital Signal Processing_R. Babu
24/148
Figure 1.6: Plot Magnitude and Phase Response
10 y = convol ( x , h 1 ) ;
11 disp ( round ( y ) ) ;
Scilab code Exa 1.19 Determination of Input Sequence
1 / / E x am pl e 1 . 1 92 / /To f i n d i n pu t x ( n )3 // h ( n) =[1 2 1 ] , y ( n ) =[1 5 10 11 8 4 1 ]4 c l e ar a ll ;
5 clc ;
6 close ;
7 z = % z ;
8 a = z ^ 6 + 5 * ( z ^ ( 5 ) ) + 1 0 * ( z ^ ( 4 ) ) + 1 1 * ( z ^ ( 3 ) ) + 8 * ( z ^ ( 2 ) ) + 4 * ( z
^ ( 1 ) ) + 1 ;
9 b = z ^ 6 + 2 * z ^ ( 5 ) + 1 * z ^ ( 4 ) ;
10 x = ldiv ( a , b , 5 ) ;
11 disp (x , x ( n) = ) ;
23
8/11/2019 Digital Signal Processing_R. Babu
25/148
Scilab code Exa 1.32.a Plot Magnitude and Phase Response
1 / / E x am pl e 1 . 3 22 / / P ro gr am t o P l o t M ag n it ud e a nd P ha s e R e sp o n ce3 c l e ar a ll ;
4 clc ;
5 close ;
6 w = - % p i : 0 . 0 1 : % p i ;
7 H = 1 + 2 * cos ( w ) + 2 * cos ( 2 * w ) ;
8 // c a l u c u l a t i o n o f Pha se and Mag ni tud e o f H9 [phase_H ,m]= phasemag ( H ) ;
10 Hm = abs ( H ) ;
11 a = gca () ;
12 subplot ( 2 , 1 , 1 ) ;
13 a . y _ l o c a t i o n = o r i g i n ;14 plot2d ( w / % p i , H m ) ;
15 x l a b e l ( F r e qu e n cy i n R a d ia n s )16 y l a b e l ( abs (Hm) ) ;17 t i t l e ( MAGNITUDE RESPONSE ) ;
18 subplot ( 2 , 1 , 2 ) ;19 a = gca () ;
20 a . x _ l o c a t i o n = o r i g i n ;21 a . y _ l o c a t i o n = o r i g i n ;22 plot2d ( w / ( 2 * % p i ) , p h a s e _ H ) ;
23 x l a b e l ( F r e qu e n cy i n R a d ia n s ) ;24 y l a b e l (
8/11/2019 Digital Signal Processing_R. Babu
26/148
Figure 1.7: Sketch Magnitude and Phase Response
1 / / E x am pl e 1 . 3 72 / / P ro gr am t o P l o t M ag n it ud e a nd P ha s e R e sp o n ce3 / / y ( n ) = 1 / 2[ x ( n )+x ( n2) ]4 c l e ar a ll ;
5 clc ;
6 close ;
7 w = 0 : 0 . 0 1 : % p i ;
8 H = ( 1 + cos ( 2 * w ) - % i * sin ( 2 * w ) ) / 2 ;
9 // c a l u c u l a t i o n o f Pha se and Mag ni tud e o f H10 [phase_H ,m]= phasemag ( H ) ;
11 Hm = abs ( H ) ;
12 a = gca () ;
13 subplot ( 2 , 1 , 1 ) ;
14 a . y _ l o c a t i o n = o r i g i n ;15 plot2d ( w / % p i , H m ) ;
16 x l a b e l ( F r e qu e n cy i n R a d ia n s )17 y l a b e l ( abs (Hm) ) ;18 t i t l e ( MAGNITUDE RESPONSE ) ;19 subplot ( 2 , 1 , 2 ) ;
20 a = gca () ;
21 a . x _ l o c a t i o n = o r i g i n ;22 a . y _ l o c a t i o n = o r i g i n ;23 plot2d ( w / ( 2 * % p i ) , p h a s e _ H ) ;
25
8/11/2019 Digital Signal Processing_R. Babu
27/148
Figure 1.8: Plot Magnitude and Phase Response
24 x l a b e l ( F r e qu e n cy i n R a d ia n s ) ;25 y l a b e l (
8/11/2019 Digital Signal Processing_R. Babu
28/148
14 a . y _ l o c a t i o n = o r i g i n ;
15 plot2d ( w / % p i , H m ) ;16 x l a b e l ( F r e qu e n cy i n R a d ia n s )17 y l a b e l ( abs (Hm) ) ;18 t i t l e ( MAGNITUDE RESPONSE ) ;19 subplot ( 2 , 1 , 2 ) ;
20 a = gca () ;
21 a . x _ l o c a t i o n = o r i g i n ;22 a . y _ l o c a t i o n = o r i g i n ;23 plot2d ( w / ( 2 * % p i ) , p h a s e _ H ) ;
24 x l a b e l ( F r e qu e n cy i n R a d ia n s ) ;25 y l a b e l (
8/11/2019 Digital Signal Processing_R. Babu
29/148
Figure 1.9: Filter to Eliminate High Frequency Component
28
8/11/2019 Digital Signal Processing_R. Babu
30/148
18 subplot ( 2 , 1 , 2 ) ;
19 plot ( t , x 1 , : ) ;20 t i t l e ( x : SIGNAL WITHOUT NOISE y : SIGNAL WITH NOISE );
21 x l a b e l ( Time i n S e c ) ;22 y l a b e l ( Amplitud e ) ;
Scilab code Exa 1.57.a Discrete Convolution of Sequences
1 / / Example 1 . 5 7 ( a )2 // Program t o C ompute d i s c r e t e c o n v o l u t i o n o f g i v e ns e q u e n c e s
3 / / x ( n ) = [1 2 1 1 ] , h ( n ) =[1 0 1 1 ] ;4 c l e ar a ll ;
5 clc ;
6 close ;
7 x =[1 2 -1 1];
8 h = [1 0 1 1];
9 y = convol ( x , h ) ;
10 disp ( round ( y ) ) ;
Scilab code Exa 1.61 Fourier Transform
1 / / E x am pl e 1 . 6 12 //MAXIMA SCILAB TOOLBOX REQUIRED FOR THIS PROGRAM3 // F o u r ie r t r an s fo r m o f ( 3 ) n u ( n )4 c l e ar a ll ;
5 clc ;
6 close ;7 s y ms n ;
8 x = (3) ^ n;
9 X = s ym su m ( x, n ,0 , % in f )
10 / / D i s p l a y t h e r e s u l t i n command window
29
8/11/2019 Digital Signal Processing_R. Babu
31/148
Figure 1.10: Frequency Response of LTI System
11 disp (X , The F o u r ie r T ra ns fo rm d oe s n ot e x i t a s x ( n )i s n ot a b s o l u t e l y summable a nd a p p ro a c he s
i n f i n i t y i . e . ) ;
Scilab code Exa 1.62 Fourier Transform
1 / / E x am pl e 1 . 6 22 //MAXIMA SCILAB TOOLBOX REQUIRED FOR THIS PROGRAM3 // F o u r ie r t r an s fo r m o f ( 0 . 8 ) | n | u ( n )4 c l e ar a ll ;
5 clc ;
6 close ;
7 syms w n ;
8 X = s y ms um ( (0 . 8) ^ n * %e ^ ( %i * w * n) , n ,1 , % in f ) + s ym su m
( (0 .8 ) ^ n * %e ^ ( - %i * w * n) , n ,0 , % in f )
9 / / D i s p l a y t h e r e s u l t i n command window
10 disp (X , The F o u r i e r T ra n sf or m c om es o u t t o b e : ) ;
30
8/11/2019 Digital Signal Processing_R. Babu
32/148
8/11/2019 Digital Signal Processing_R. Babu
33/148
Figure 1.11: Frequency Response of LTI System
32
8/11/2019 Digital Signal Processing_R. Babu
34/148
1 / / E xa mp le 1 . 6 4 ( c )
2 / / Pr ogr am t o C a l c u l a t e P l o t M ag ni tu de and P ha seR e sponc e3 c l e ar a ll ;
4 clc ;
5 close ;
6 w = 0 : 0 . 0 1 : % p i ;
7 H = 1 / ( 1 - 0 . 9 * % i * % e ^ ( - % i * w ) ) ;
8 // c a l u c u l a t i o n o f Pha se and Mag ni tud e o f H9 [phase_H ,m]= phasemag ( H ) ;
10 Hm = abs ( H ) ;
11 a = gca () ;
12 subplot ( 2 , 1 , 1 ) ;13 a . y _ l o c a t i o n = o r i g i n ;14 plot2d ( w / % p i , H m ) ;
15 x l a b e l ( F r e qu e n cy i n R a d ia n s )16 y l a b e l ( abs (Hm) ) ;17 t i t l e ( MAGNITUDE RESPONSE ) ;18 subplot ( 2 , 1 , 2 ) ;
19 a = gca () ;
20 a . x _ l o c a t i o n = o r i g i n ;21 a . y _ l o c a t i o n = o r i g i n ;22 plot2d ( w / ( 2 * % p i ) , p h a s e _ H ) ;
23 x l a b e l ( F r e qu e n cy i n R a d ia n s ) ;24 y l a b e l (
8/11/2019 Digital Signal Processing_R. Babu
35/148
Chapter 2
THE Z TRANSFORM
Scilab code Exa 2.1 z Transform and ROC of Causal Sequence
1 / / E xa mp le 2 . 12 //Z tr an sf or m o f [ 1 0 3 1 2 ]3 c l e ar a ll ;
4 clc ;
5 close ;
6 function [ z a ] = z t r a n s f e r ( s e q u e n ce , n )
7 z = poly (0 , z , r )8 z a = s e q u e n c e * ( 1 / z ) ^ n
9 e n d f u n c t i o n
10 x 1 =[1 0 3 -1 2];
11 n = 0 : length ( x 1 ) - 1 ;
12 z z = z t r a n s f e r ( x 1 , n ) ;
13 / / D i s p l a y t h e r e s u l t i n command window14 disp ( z z , Zt r an s f or m o f s e qu e nc e i s : ) ;15 disp (ROC i s t he e n t i r e p la ne e xc ep t z = 0 ) ;
Scilab code Exa 2.2 z Transform and ROC of Anticausal Sequence
34
8/11/2019 Digital Signal Processing_R. Babu
36/148
1 / / E xa mp le 2 . 2
2 //Z t ra n sf or m o f [3 2 1 0 1 ]3 c l e ar a ll ;4 clc ;
5 close ;
6 function [ z a ] = z t r a n s f e r ( s e q u e n ce , n )
7 z = poly (0 , z , r )8 z a = s e q u e n c e * ( 1 / z ) ^ n
9 e n d f u n c t i o n
10 x 1 =[ -3 -2 -1 0 1] ;
11 n = - ( length ( x 1 ) - 1 ) : 0 ;
12 z z = z t r a n s f e r ( x 1 , n ) ;
13 / / D i s p l a y t h e r e s u l t i n command window14 disp ( z z , Zt r an s f or m o f s e qu e nc e i s : ) ;15 disp (ROC i s t he e n t i r e p l an e e x ce p t z = % i nf ) ;
Scilab code Exa 2.3 z Transform of the Sequence
1 / / E xa mp le 2 . 32 //Z t ra n sf or m o f [ 2 1 3 2 1 0 2 3 1]
3 c l e ar a ll ;4 clc ;
5 close ;
6 function [ z a ] = z t r a n s f e r ( s e q u e n ce , n )
7 z = poly (0 , z , r )8 z a = s e q u e n c e * ( 1 / z ) ^ n
9 e n d f u n c t i o n
10 x1 =[2 -1 3 2 1 0 2 3 -1];
11 n = - 4 : 4 ;
12 z z = z t r a n s f e r ( x 1 , n ) ;
13 / / D i s p l a y t h e r e s u l t i n command window14 disp ( z z , Zt r an s f or m o f s e qu e nc e i s : ) ;15 disp (ROC i s t he e n t i r e p la ne e xc ep t z = 0 and z =
%inf ) ;
35
8/11/2019 Digital Signal Processing_R. Babu
37/148
Scilab code Exa 2.4 z Transform and ROC of the Signal
1 / / E xa mp le 2 . 42 //MAXIMA SCILAB TOOLBOX REQUIRED FOR THIS PROGRAM3 //Z t r a ns f o r m o f a n u ( n )4 c l e ar a ll ;
5 clc ;
6 close ;
7 syms a n z ;
8 x = a^ n
9 X = s ym su m ( x *( z ^( - n )) , n ,0 , % in f ) ;
10 / / D i s p l a y t h e r e s u l t i n command window11 disp (X , Zt r an s fo r m o f a n u ( n ) w it h i s : ) ;12 disp (ROC i s t he R e gi on mod( z ) > a )
Scilab code Exa 2.5 z Transform and ROC of the Signal
1 / / E xa mp le 2 . 52 //MAXIMA SCILAB TOOLBOX REQUIRED FOR THIS PROGRAM3 //Z tr a n sf o rm o f b n u (n1)4 c l e ar a ll ;
5 clc ;
6 close ;
7 syms b n z ;
8 x = b^ n
9 X = s ym su m ( x *( z ^( - n )) , n ,0 , % in f ) ;
10 / / D i s p l a y t h e r e s u l t i n command window
11 disp (X , Zt r an s fo r m o f b n u ( n ) w it h i s : ) ;12 disp (ROC i s t he R e gi on mod( z ) < b )
36
8/11/2019 Digital Signal Processing_R. Babu
38/148
8/11/2019 Digital Signal Processing_R. Babu
39/148
1 / / Example 2 . 8 ( a )
2 //MAXIMA SCILAB TOOLBOX REQUIRED FOR THIS PROGRAM3 / /Z t r a n s f o r m o f c o s (Won )4 clc ;
5 syms Wo n z ;
6 x1 = exp ( sqrt ( - 1 ) * W o * n ) ;
7 X 1 = s y m s u m ( x 1 * ( z ^ - n ) , n , 0 , % i n f ) ;
8 x2 = exp ( - sqrt ( - 1 ) * W o * n ) ;
9 X 2 = s y m s u m ( x 2 * ( z ^ - n ) , n , 0 , % i n f ) ;
10 X = ( X 1 + X 2 ) / 2 ;
11 disp (X ,X( z )= ) ;
Scilab code Exa 2.9 z Transform of the Sequence
1 / / E xa mp le 2 . 92 //MAXIMA SCILAB TOOLBOX REQUIRED FOR THIS PROGRAM3 //Z t r a ns f or m o f ( 1 / 3 ) n u ( n1)4 c l e ar a ll ;
5 clc ;
6 close ;
7 syms n z ;8 x = (1 /3 ) ^ n ;
9 X = ( 1/ z ) * s ym su m ( x *( z ^( - n ) ) ,n ,0 , % in f ) ;
10 / / D i s p l a y t h e r e s u l t i n command window11 disp (X , Zt r an s fo r m o f ( 1 / 3) n u ( n1) i s : ) ;
Scilab code Exa 2.10 z Transform Computation
1 / / E x am pl e 2 . 1 02 //MAXIMA SCILAB TOOLBOX REQUIRED FOR THIS PROGRAM3 / /Z t r a n s f o r m o f r n . c o s (Won )4 clc ;
5 syms r Wo n z ;
38
8/11/2019 Digital Signal Processing_R. Babu
40/148
6 x 1 = ( r ^ n ) * exp ( sqrt ( - 1 ) * W o * n ) ;
7 X 1 = s y m s u m ( x 1 * ( z ^ - n ) , n , 0 , % i n f ) ;8 x 2 = ( r ^ n ) * exp ( - sqrt ( - 1 ) * W o * n ) ;
9 X 2 = s y m s u m ( x 2 * ( z ^ - n ) , n , 0 , % i n f ) ;
10 X = ( X 1 + X 2 ) / 2 ;
11 disp (X ,X( z )= ) ;
Scilab code Exa 2.11 z Transform of the Sequence
1 / / E x am pl e 2 . 1 12 //MAXIMA SCILAB TOOLBOX REQUIRED FOR THIS PROGRAM3 //Z t r a n s f o r m o f n . a n u ( n )4 c l e ar a ll ;
5 clc ;
6 close ;
7 syms a n z ;
8 x =( a) ^ n;
9 X = s ym su m ( x *( z ^( - n )) , n ,0 , % in f )
10 Y = diff ( X , z ) ;
11 / / D i s p l a y t h e r e s u l t i n command window
12 disp (Y , Zt r an s fo r m o f n . a n u ( n ) i s : ) ;
Scilab code Exa 2.13.a z Transform of Discrete Time Signals
1 / / Example 2 . 1 3 ( a )2 //MAXIMA SCILAB TOOLBOX REQUIRED FOR THIS PROGRAM3 //Z t ra n sf or m o f ( 1 / 5) n u ( n ) + 5 ( 1 / 2 ) (n ) u (n1)4 c l e ar a ll ;
5 clc ;6 close ;
7 syms n z ;
8 x 1 = ( -1 /5 ) ^n ;
9 X 1= s ym su m ( x1 * (z ^( - n )) , n ,0 , % in f ) ;
39
8/11/2019 Digital Signal Processing_R. Babu
41/148
10 x 2 = ( 1 /2 ) ^ ( - n ) ;
11 X 2 = s ym su m ( 5* x 2 *( z ^( - n )) , n ,0 , % in f ) ;12 X = ( X1 - X2 );
13 / / D i s p l a y t h e r e s u l t i n command window14 disp (X , Zt r a ns f o r m o f [ 3 ( 3 n )4(2) n ] u ( n ) i s : ) ;15 disp (ROC i s t h e R eg i on 1 /5 < mod( z ) < 2 ) ;
Scilab code Exa 2.13.b z Transform of Discrete Time Signals
1 / / Exam ple 2 . 1 3 ( b )2 //MAXIMA SCILAB TOOLBOX REQUIRED FOR THIS PROGRAM3 / /Z t r a n s fo r m4 clc ;
5 syms n z k ;
6 x 1 = 1 ;
7 X 1 = s y m s u m ( x 1 * z ^ ( - n ) , n , 0 , 0 ) ;
8 x 2 = 1 ;
9 X 2 = s y m s u m ( x 2 * z ^ ( - n ) , n , 1 , 1 ) ;
10 x 3 = 1 ;
11 X 3 = s y m s u m ( x 3 * z ^ ( - n ) , n , 2 , 2 ) ;
12 X = 0 . 5 * X 1 + X 2 - 1 / 3 * X 3 ;13 disp (X ,X( z )= ) ;
Scilab code Exa 2.13.c z Transform of Discrete Time Signals
1 / / E xa mp le 2 . 1 3 ( c )2 //MAXIMA SCILAB TOOLBOX REQUIRED FOR THIS PROGRAM3 //Z tr a ns f o r m o f u ( n2)
4 c l e ar a ll ;5 clc ;
6 close ;
7 syms n z ;
8 x =1;
40
8/11/2019 Digital Signal Processing_R. Babu
42/148
9 X = ( 1/ ( z ^ 2) ) * s y ms um ( x *( z ^( - n ) ) ,n ,0 , % in f ) ;
10 / / D i s p l a y t h e r e s u l t i n command window11 disp (X , Zt r a ns f o r m o f u ( n2) i s : ) ;
Scilab code Exa 2.13.d z Transform of Discrete Time Signals
1 / / Exam ple 2 . 1 3 ( d )2 //MAXIMA SCILAB TOOLBOX REQUIRED FOR THIS PROGRAM3 //Z t r a n s fo r m o f ( n + 0. 5 ) ( ( 1 / 3 ) n ) u ( n )
4 c l e ar a ll ;5 clc ;
6 close ;
7 syms n z ;
8 x 1 = ( 1/ 3) ^ n ;
9 X 1 1 = s ym s um ( x 1 *( z ^( - n ) ) ,n ,0 , % in f )
10 X1 = diff ( X 1 1 , z ) ;
11 x 2 = ( 1/ 3) ^ ( n) ;
12 X 2 = s ym su m ( 0. 5* x 2 * (z ^( - n )) , n ,0 , % in f ) ;
13 X = ( X1 + X2 );
14 / / D i s p l a y t h e r e s u l t i n command window
15 disp (X , Zt r an s fo r m o f ( n +0 .5 ) ( ( 1 / 3 ) n )u ( n ) i s : ) ;
Scilab code Exa 2.16 Impulse Response of the System
1 / / E x am pl e 2 . 1 62 / /To f i n d i n pu t h ( n )3 / / a = [1 2 4 1 ] , b = [1 ]4 c l e ar a ll ;
5 clc ;6 close ;
7 z = % z ;
8 a = z ^ 3 + 2 * ( z ^ ( 2 ) ) - 4 * ( z ) + 1 ;
9 b = z ^ 3 ;
41
8/11/2019 Digital Signal Processing_R. Babu
43/148
Figure 2.1: Pole Zero Plot of the Difference Equation
10 h = ldiv ( a , b , 4 ) ;
11 disp (h , h( n) = ) ;
Scilab code Exa 2.17 Pole Zero Plot of the Difference Equation
1 / / E x am pl e 2 . 1 72 / / To dra w t h e p o l ez er o p l ot3 c l e ar a ll ;
4 clc ;
5 close ;
6 z = % z
7 H 1 Z = ( ( z ) * ( z - 1 ) ) / ( ( z - 0 . 2 5 ) * ( z - 0 . 5 ) ) ;
8 xset ( window ,1);9 plzr ( H 1 Z ) ;
42
8/11/2019 Digital Signal Processing_R. Babu
44/148
Figure 2.2: Frequency Response of the System
43
8/11/2019 Digital Signal Processing_R. Babu
45/148
Scilab code Exa 2.19 Frequency Response of the System
1 / / E x am pl e 2 . 1 92 / / P ro gr am t o P l o t M ag n it ud e a nd P ha s e R e sp o n ce3 c l e ar a ll ;
4 clc ;
5 close ;
6 w = - % p i : 0 . 0 1 : % p i ;
7 H = 1 / ( 1 - 0 . 5 * ( cos ( w ) - % i * sin ( w ) ) ) ;
8 // c a l u c u l a t i o n o f Pha se and Mag ni tud e o f H9 [phase_H ,m]= phasemag ( H ) ;
10 Hm = abs ( H ) ;
11 a = gca () ;12 subplot ( 2 , 1 , 1 ) ;
13 a . y _ l o c a t i o n = o r i g i n ;14 plot2d ( w / % p i , H m ) ;
15 x l a b e l ( F r e qu e n cy i n R a d ia n s ) ;16 y l a b e l ( abs (Hm) ) ;17 t i t l e ( MAGNITUDE RESPONSE ) ;18 subplot ( 2 , 1 , 2 ) ;
19 a = gca () ;
20 a . x _ l o c a t i o n = o r i g i n ;21 a . y _ l o c a t i o n =
o r i g i n ;
22 plot2d ( w / ( 2 * % p i ) , p h a s e _ H ) ;
23 x l a b e l ( F r e qu e n cy i n R a d ia n s ) ;24 y l a b e l (
8/11/2019 Digital Signal Processing_R. Babu
46/148
6 close ;
7 z = % z ;8 a = ( z + 0 . 5 ) * ( z - 1 ) ;
9 b = z + 0 . 2 ;
10 h = ldiv ( b , a , 4 ) ;
11 disp (h , h( n) = ) ;
Scilab code Exa 2.22 Inverse z Transform Computation
1 / / E x am pl e 2 . 2 22 / /To f i n d i n pu t x ( n )3 //X( z ) =1/(2 z ( 2)+2z ( 1) +1) ;4 c l e ar a ll ;
5 clc ;
6 close ;
7 z = % z ;
8 a = ( 2 + 2 * z + z ^ 2 ) ;
9 b = z ^ 2 ;
10 h = ldiv ( b , a , 6 ) ;
11 disp (h , F i r s t s i x v a l ue s o f h ( n )= ) ;
Scilab code Exa 2.23 Causal Sequence Determination
1 / / E x am pl e 2 . 2 32 / /To f i n d i n pu t x ( n )3 //X( z ) =1/(12 z ( 1 ) ) ( 1z (1 ) ) 2 ;4 c l e ar a ll ;
5 clc ;
6 close ;7 z = % z ;
8 a = ( z - 2 ) * ( z - 1 ) ^ 2 ;
9 b = z ^ 3 ;
10 h = ldiv ( b , a , 6 ) ;
45
8/11/2019 Digital Signal Processing_R. Babu
47/148
Figure 2.3: Impulse Response of the System
11 disp (h , F i r s t s i x v a l ue s o f h ( n )= ) ;
Scilab code Exa 2.34 Impulse Response of the System
1 / / E x am pl e 2 . 3 42 //To p l o t t he i m pu l se r e s po n c e o f t he s ys te m
a n a l y i c a l l y and u si ng s c i l a b3 c l e ar a ll ;4 clc ;
5 close ;
6 n = 0 : 1 : 5 0 ;
46
8/11/2019 Digital Signal Processing_R. Babu
48/148
7 x = [ 1 , zeros ( 1 , 5 0 ) ] ;
8 b = [ 1 2 ];9 a = [1 -3 -4] ;
10 y a n a l y = 6 / 5 * 4 . ^ n - 1 / 5 * ( - 1 ) . ^ n ; // A n a l y t i c a l S o l u t i o n11 y m a t = filter ( b , a , x ) ;
12 subplot ( 3 , 1 , 1 ) ;
13 plot2d3 ( n , x ) ;
14 x l a b e l ( n ) ;15 y l a b e l ( x ( n ) ) ;16 t i t l e ( INPUT SEQUENCE (IMPULSE FUNCTION) ) ;17 subplot ( 3 , 1 , 2 ) ;
18 plot2d3 ( n , y a n a l y ) ;
19 x l a b e l ( n ) ;20 y l a b e l ( y ( n ) ) ;21 t i t l e (OUTPUT SEQUENCE y a n a l y ) ;22 subplot ( 3 , 1 , 3 ) ;
23 plot2d3 ( n , y m a t ) ;
24 x l a b e l ( n ) ;25 y l a b e l ( y ( n ) ) ;26 t i t l e (OUTPUT SEQUENCE ymat ) ;27 / /As t he A n a l t i c a l P lo t ma tc he s t he S c i l a b P lo t
h en ce i t i s t he R es pon ce o f t he s ys te m
Scilab code Exa 2.35.a Pole Zero Plot of the System
1 / / Example 2 . 3 5 ( a )2 / / To dra w t h e p o l ez er o p l ot3 c l e ar a ll ;
4 clc ;5 close ;
6 z = % z
7 H 1 Z = ( z ) / ( z ^ 2 - z - 1 ) ;
8 xset ( window ,1);
47
8/11/2019 Digital Signal Processing_R. Babu
49/148
Figure 2.4: Pole Zero Plot of the System
48
8/11/2019 Digital Signal Processing_R. Babu
50/148
Figure 2.5: Unit Sample Response of the System
9 plzr ( H 1 Z ) ;
Scilab code Exa 2.35.b Unit Sample Response of the System
1 / / Exam ple 2 . 3 5 ( b )2 //To p l o t t he r e s p on c e o f t he s ys te m a n a l y i c a l l y and
u si ng s c i l a b3 c l e ar a ll ;4 clc ;
5 close ;
6 n = 0 : 1 : 2 0 ;
49
8/11/2019 Digital Signal Processing_R. Babu
51/148
7 x = ones (1 , length ( n ) ) ;
8 b = [ 0 1 ];9 a = [1 -1 -1] ;
10 y a n a l y = 0 . 4 4 7 * ( 1 . 6 1 8 ) . ^ n - 0 . 4 4 7 * ( - 0 . 6 1 8 ) . ^ n ; //A n a l y t i c a l S o l u t i o n
11 [ y m a t , z f ] = filter ( b , a , x ) ;
12 subplot ( 3 , 1 , 1 ) ;
13 plot2d3 ( n , x ) ;
14 x l a b e l ( n ) ;15 y l a b e l ( x ( n ) ) ;16 t i t l e ( INPUT SEQUENCE (STEP FUNCTION) ) ;17 subplot ( 3 , 1 , 2 ) ;
18 plot2d3 ( n , y a n a l y ) ;19 x l a b e l ( n ) ;20 y l a b e l ( y ( n ) ) ;21 t i t l e (OUTPUT SEQUENCE y a n a l y ) ;22 subplot ( 3 , 1 , 3 ) ;
23 plot2d3 ( n , y m a t , z f ) ;
24 x l a b e l ( n ) ;25 y l a b e l ( y ( n ) ) ;26 t i t l e (OUTPUT SEQUENCE ymat ) ;27 / /As t he A n a l t i c a l P lo t ma tc he s t he S c i l a b P lo t
h en ce i t i s t he R es pon ce o f t he s ys te m
Scilab code Exa 2.38 Determine Output Response
1 / / E x am pl e 2 . 3 82 //To p l o t t he r e s p on c e o f t he s ys te m a n a l y i c a l l y and
u si ng s c i l a b3 c l e ar a ll ;4 clc ;
5 close ;
6 n = 0 : 1 : 2 0 ;
50
8/11/2019 Digital Signal Processing_R. Babu
52/148
Figure 2.6: Determine Output Response
51
8/11/2019 Digital Signal Processing_R. Babu
53/148
7 x = n ;
8 b = [0 1 1];9 a = [ 1 - 0. 7 0 .1 2 ];
10 y a n a l y = 3 8 . 8 9 * ( 0 . 4 ) . ^ n - 2 6 . 5 3 * ( 0 . 3 ) . ^ n - 1 2 . 3 6 + 4 . 7 6 * n ; //A n a l y t i c a l S o l u t i o n
11 y m a t = filter ( b , a , x ) ;
12 subplot ( 3 , 1 , 1 ) ;
13 plot2d3 ( n , x ) ;
14 x l a b e l ( n ) ;15 y l a b e l ( x ( n ) ) ;16 t i t l e ( INPUT SEQUENCE (RAMP FUNCTION) ) ;17 subplot ( 3 , 1 , 2 ) ;
18 plot2d3 ( n , y a n a l y ) ;19 x l a b e l ( n ) ;20 y l a b e l ( y ( n ) ) ;21 t i t l e (OUTPUT SEQUENCE y a n a l y ) ;22 subplot ( 3 , 1 , 3 ) ;
23 plot2d3 ( n , y m a t ) ;
24 x l a b e l ( n ) ;25 y l a b e l ( y ( n ) ) ;26 t i t l e (OUTPUT SEQUENCE ymat ) ;27 / /As t he A n a l t i c a l P lo t ma tc he s t he S c i l a b P lo t
h en ce i t i s t he R es pon ce o f t he s ys te m
Scilab code Exa 2.40 Input Sequence Computation
1 / / E x am pl e 2 . 4 02 / /To f i n d i n pu t x ( n )3 // h ( n) =1 2 3 2 , y ( n) =[1 3 7 10 10 7 2 ]4 c l e ar a ll ;
5 clc ;6 close ;
7 z = % z ;
8 a = z ^ 6 + 3 * ( z ^ ( 5 ) ) + 7 * ( z ^ ( 4 ) ) + 1 0 * ( z ^ ( 3 ) ) + 1 0 * ( z ^ ( 2 ) ) + 7 * ( z
^ ( 1 ) ) + 2 ;
52
8/11/2019 Digital Signal Processing_R. Babu
54/148
9 b = z ^ 6 + 2 * z ^ ( 5 ) + 3 * z ^ ( 4 ) + 2 * z ^ ( 3 ) ;
10 x = ldiv ( a , b , 4 ) ;11 disp (x , x ( n) = ) ;
Scilab code Exa 2.41.a z Transform of the Signal
1 / / Example 2 . 4 1 ( a )2 //MAXIMA SCILAB TOOLBOX REQUIRED FOR THIS PROGRAM3 //Z tr a ns f o r m o f n .(1 ) n u ( n )
4 c l e ar a ll ;5 clc ;
6 close ;
7 syms a n z ;
8 x =( -1) ^ n;
9 X = s ym su m ( x *( z ^( - n )) , n ,0 , % in f )
10 Y = diff ( X , z ) ;
11 / / D i s p l a y t h e r e s u l t i n command window12 disp (Y , Zt r a ns f o r m o f n .(1 ) n u ( n ) i s : ) ;
Scilab code Exa 2.41.b z Transform of the Signal
1 / / Exam ple 2 . 4 1 ( b )2 //MAXIMA SCILAB TOOLBOX REQUIRED FOR THIS PROGRAM3 //Z t r a ns f o r m o f n 2 u ( n )4 c l e ar a ll ;
5 clc ;
6 close ;
7 syms n z ;
8 x =1;9 X = s ym su m ( x *( z ^( - n )) , n ,0 , % in f )
10 Y = diff ( diff ( X , z ) , z ) ;
11 / / D i s p l a y t h e r e s u l t i n command window12 disp (Y , Zt ra ns fo rm o f n 2 u ( n) i s : ) ;
53
8/11/2019 Digital Signal Processing_R. Babu
55/148
Figure 2.7: Pole Zero Pattern of the System
Scilab code Exa 2.41.c z Transform of the Signal
1 / / E xa mp le 2 . 4 1 ( c )2 //MAXIMA SCILAB TOOLBOX REQUIRED FOR THIS PROGRAM
3 / /Z t r a ns f o r m o f (1)n . co s (%pi/3n )4 clc ;
5 syms n z ;
6 W o = % p i / 3 ;
7 x1 = exp ( sqrt ( - 1 ) * W o * n ) ;
8 X 1 = ( - 1 ) ^ n * s y m s u m ( x 1 * ( z ^ - n ) , n , 0 , % i n f ) ;
9 x2 = exp ( - sqrt ( - 1 ) * W o * n ) ;
10 X 2 = ( - 1 ) ^ n * s y m s u m ( x 2 * ( z ^ - n ) , n , 0 , % i n f ) ;
11 X = ( X 1 + X 2 ) / 2 ;
12 disp (X ,X( z )= ) ;
54
8/11/2019 Digital Signal Processing_R. Babu
56/148
Scilab code Exa 2.45 Pole Zero Pattern of the System
1 / / E x am pl e 2 . 4 52 / / To dra w t h e p o l ez er o p l ot3 c l e ar a ll ;
4 clc ;
5 close ;
6 z = % z
7 H 1 Z = ( ( z ) * ( z + 1 ) ) / ( z ^ 2 - z + 0 . 5 ) ;
8 xset ( window ,1);9 plzr ( H 1 Z ) ;
Scilab code Exa 2.53.a z Transform of the Sequence
1 / / Example 2 . 5 3 ( a )2 //Z t r a ns f o r m o f [ 3 1 2 5 7 0 1 ]3 c l e ar a ll ;
4 clc ;
5 close ;
6 function [ z a ] = z t r a n s f e r ( s e q u e n ce , n )
7 z = poly (0 , z , r )8 z a = s e q u e n c e * ( 1 / z ) ^ n
9 e n d f u n c t i o n
10 x1 =[3 1 2 5 7 0 1];
11 n = - 3 : 3 ;
12 z z = z t r a n s f e r ( x 1 , n ) ;
13 / / D i s p l a y t h e r e s u l t i n command window14 disp ( z z , Zt r an s f or m o f s e qu e nc e i s : ) ;
Scilab code Exa 2.53.b z Transform of the Signal
1 / / Exam ple 2 . 5 3 ( b )2 //MAXIMA SCILAB TOOLBOX REQUIRED FOR THIS PROGRAM
55
8/11/2019 Digital Signal Processing_R. Babu
57/148
3 //Z t r an s fo r m o f d e l t a ( n )
4 clc ;5 syms n z ;
6 x = 1 ;
7 X = s y m s u m ( x * z ^ ( - n ) , n , 0 , 0 ) ;
8 disp (X ,X( z )= ) ;
Scilab code Exa 2.53.c z Transform of the Signal
1 / / E xa mp le 2 . 5 3 ( c )2 //MAXIMA SCILAB TOOLBOX REQUIRED FOR THIS PROGRAM3 //Z t r an s fo r m o f d e l t a ( n )4 clc ;
5 syms n z k ;
6 x = 1 ;
7 X = s y m s u m ( x * z ^ ( - n ) , n , k , k ) ;
8 disp (X ,X( z )= ) ;
Scilab code Exa 2.53.d z Transform of the Signal
1 / / Exam ple 2 . 5 3 ( d )2 //MAXIMA SCILAB TOOLBOX REQUIRED FOR THIS PROGRAM3 //Z t r an s fo r m o f d e l t a ( n )4 clc ;
5 syms n z kc ;
6 x = 1 ;
7 X = s y m s u m ( x * z ^ ( - n ) , n , - k , - k ) ;
8 disp (X ,X( z )= ) ;
Scilab code Exa 2.54 z Transform of Cosine Signal
56
8/11/2019 Digital Signal Processing_R. Babu
58/148
Figure 2.8: Impulse Response of the System
1 / / E x am pl e 2 . 5 42 //MAXIMA SCILAB TOOLBOX REQUIRED FOR THIS PROGRAM3 / /Z t r a n s f o r m o f c o s (Won )4 clc ;
5 syms Wo n z ;
6 x1 = exp ( sqrt ( - 1 ) * W o * n ) ;
7 X 1 = s y m s u m ( x 1 * ( z ^ - n ) , n , 0 , % i n f ) ;
8 x2 = exp ( - sqrt ( - 1 ) * W o * n ) ;
9 X 2 = s y m s u m ( x 2 * ( z ^ - n ) , n , 0 , % i n f ) ;
10 X = ( X 1 + X 2 ) / 2 ;
11 disp (X ,X( z )= ) ;
57
8/11/2019 Digital Signal Processing_R. Babu
59/148
Scilab code Exa 2.58 Impulse Response of the System
1 / / E x am pl e 2 . 5 82 //To p l o t t he r e s p on c e o f t he s ys te m a n a l y i c a l l y and
u si ng s c i l a b3 c l e ar a ll ;
4 clc ;
5 close ;
6 n = 0 : 1 : 2 0 ;
7 x = [ 1 zeros ( 1 , 2 0 ) ] ;
8 b = [ 1 - 0. 5 ];
9 a = [ 1 -1 3 / 16 ];
10 y a n a l y = 0 . 5 * ( 0 . 7 5 ) . ^ n + 0 . 5 * ( 0 . 2 5 ) . ^ n ; / / A n a l y t i c a lS o l u t i o n
11 y m a t = filter ( b , a , x ) ;
12 subplot ( 3 , 1 , 1 ) ;
13 plot2d3 ( n , x ) ;
14 x l a b e l ( n ) ;15 y l a b e l ( x ( n ) ) ;16 t i t l e ( INPUT SEQUENCE (IMPULSE FUNCTION) ) ;17 subplot ( 3 , 1 , 2 ) ;
18 plot2d3 ( n , y a n a l y ) ;
19 x l a b e l ( n
) ;
20 y l a b e l ( y ( n ) ) ;21 t i t l e (OUTPUT SEQUENCE y a n a l y ) ;22 subplot ( 3 , 1 , 3 ) ;
23 plot2d3 ( n , y m a t ) ;
24 x l a b e l ( n ) ;25 y l a b e l ( y ( n ) ) ;26 t i t l e (OUTPUT SEQUENCE ymat ) ;27 / /As t he A n a l t i c a l P lo t ma tc he s t he S c i l a b P lo t
h en ce i t i s t he R es pon ce o f t he s ys te m
58
8/11/2019 Digital Signal Processing_R. Babu
60/148
8/11/2019 Digital Signal Processing_R. Babu
61/148
Figure 3.1: DFT of the Sequence
Scilab code Exa 3.2 DFT of the Sequence
1 / / E xa mp le 3 . 22 / / P r og ra m t o Com pu te t h e DFT o f a S e q u e n c e x [ n ] = 1 ,
0
8/11/2019 Digital Signal Processing_R. Babu
62/148
17 disp ( X 2 , X2 [ k]= ) ;
18 / / P l o t s f o r N=419 n 1 = 0 : 1 : 3 ;20 subplot ( 2 , 2 , 1 ) ;
21 a = gca () ;
22 a . y _ l o c at i o n = o r i g i n ;23 a . x _ l o c at i o n = o r i g i n ;24 plot2d3 ( n 1 , abs ( X 1 ) , 2 ) ;
25 p o ly 1 = a . c h i l dr e n ( 1 ) . c h i ld r e n ( 1) ;
26 p o l y 1 . t h i c k n e s s = 2 ;
27 xtitle (N=4 , k , | X 1 ( k )| ) ;28 subplot ( 2 , 2 , 2 ) ;
29 a = gca () ;30 a . y _ l o c at i o n = o r i g i n ;31 a . x _ l o c at i o n = o r i g i n ;32 plot2d3 ( n 1 , atan ( imag ( X 1 ) , real ( X 1 ) ) , 5 ) ;
33 p o ly 1 = a . c h i l dr e n ( 1 ) . c h i ld r e n ( 1) ;
34 p o l y 1 . t h i c k n e s s = 2 ;
35 xtitle (N=4 , k ,
8/11/2019 Digital Signal Processing_R. Babu
63/148
Scilab code Exa 3.3 8 Point DFT
1 / / E xa mp le 3 . 32 / / P r o gr am t o Com pu te t h e 8p o i n t DFT o f t h e S e qu e nc e
x [ n ] = [ 1 , 1 , 1 , 1 , 1 , 1 , 0 , 0 ]3 c l e ar a ll ;
4 clc ;
5 close ;
6 x = [ 1 ,1 , 1 , 1 ,1 , 1 , 0 ,0 ];
7 //DFT Compu tatio n8 X = fft ( x , -1) ;
9 / / D i s p l a y s e q u e n c e X [ k ] i n command w in do w10 disp (X , X[ k]= ) ;
Scilab code Exa 3.4 IDFT of the given Sequence
1 / / E xa mp le 3 . 42 / / P ro gr am t o Compute t h e IDFT o f t h e S e q u en c e X [ k]=[ 5 ,0 ,1j , 0 , 1 , 0 , 1 + j , 0 ]
3 c l e ar a ll ;
4 clc ;
5 close ;
6 j = sqrt ( - 1 ) ;
7 X = [ 5 ,0 , 1 - j ,0 , 1 , 0 ,1 +j , 0]
8 //IDFT Comput ation9 x = fft ( X , 1 ) ;
10 // Di sp l a y se q u e n c e s x [ n ] i n command w indow
11 disp (x , x [ n]= ) ;
62
8/11/2019 Digital Signal Processing_R. Babu
64/148
Figure 3.2: Plot the Sequence
Scilab code Exa 3.7 Plot the Sequence
1 / / E xa mp le 3 . 72 / / Program t o C ompute c i r c u l a r c o n v o l u t i o n o f
f o l l o w i n g s e qu e nc e s3 / / x [ n ] = [ 1 , 2 , 2 , 1 , 0 ]4 //Y[ k]= exp(j4p i k /5 ) .X[ k ]5 c l e ar a ll ;
6 clc ;
7 close ;
8 x = [ 1 , 2 , 2 , 1 , 0 ] ;
9 X = fft ( x , - 1 ) ;
10 k = 0 : 1 : 4 ;
11 j = sqrt ( - 1 ) ;
12 p i = 2 2 / 7 ;
63
8/11/2019 Digital Signal Processing_R. Babu
65/148
13 H = exp ( - j * 4 * p i * k / 5 ) ;
14 Y = H . * X ;15 //IDFT Comput ation16 y = fft ( Y , 1 ) ;
17 / / D i s p l a y s e q u e n c e y [ n ] i n command w in do w18 disp ( round ( y ) , y [ n]= ) ;19 / / P l o t s20 n = 0 : 1 : 4 ;
21 a = gca () ;
22 a . y _ l o c at i o n = o r i g i n ;23 a . x _ l o c at i o n = o r i g i n ;24 plot2d3 (n , round ( y ) , 5 ) ;
25 p o ly 1 = a . c h i l dr e n ( 1 ) . c h i ld r e n ( 1) ;26 p o l y 1 . t h i c k n e s s = 2 ;
27 xtitle ( P l o t o f s e q u e n c e y [ n ] , n , y [ n ] ) ;
Scilab code Exa 3.9 Remaining Samples
1 / / E xa mp le 3 . 92 / / Program t o r e m ai n i n g s a mp l es o f t h e s e q ue n c e
3 //X(0 ) =12,X(1)=1+j3 , X( 2 )=3+j4 , X( 3 )=1j 5 , X( 4 )=2+j2 ,X(5 )=6+j3 ,X( 6) =2j 3 , X( 7 ) =10
4 c l e ar a ll ;
5 clc ;
6 close ;
7 j = sqrt ( - 1 ) ;
8 z = 1 ;
9 X ( 0 + z ) = 1 2 , X ( 1 + z ) = - 1 + j * 3 , X ( 2 + z ) = 3 + j * 4 , X ( 3 + z ) = 1 - j * 5 , X
( 4 + z ) = - 2 + j * 2 , X ( 5 + z ) = 6 + j * 3 , X ( 6 + z ) = - 2 - j * 3 , X ( 7 + z )
=10;
10 for a = 9 :1 : 14 d o X ( a )= conj ( X ( 1 6 - a ) ) , end ;11 / / D i s p l a y t h e c o m p l e t e s e q u e n c e X [ k ] i n commandwindow
12 disp (X , X[ k]= ) ;
64
8/11/2019 Digital Signal Processing_R. Babu
66/148
Scilab code Exa 3.11 DFT Computation
1 / / E x am pl e 3 . 1 12 / / P r o gr am t o Com pu te t h e 8p o i n t DFT o f t h e
f o l l o w i n g s e qu e nc e s3 / / x 1 [ n ] = [ 1 , 0 , 0 , 0 , 0 , 1 , 1 , 1 ]4 / / x 2 [ n ] = [ 0 , 0 , 1 , 1 , 1 , 1 , 0 , 0 ]5 c l e ar a ll ;
6 clc ;
7 close ;
8 x 1 = [ 1 , 0 , 0 , 0 , 0 , 1 , 1 , 1 ] ;
9 x 2 = [ 0 , 0 , 1 , 1 , 1 , 1 , 0 , 0 ] ;
10 //DFT Compu tatio n11 X1 = fft ( x1 , -1) ;
12 X2 = fft ( x2 , -1) ;
13 / / D i s p l a y s e q u e n c e s X1 [ k ] a nd X2 [ k ] i n commandwindow
14 disp ( X 1 , X1 [ k]= ) ;15 disp ( X 2 , X2 [ k]= ) ;
Scilab code Exa 3.13 Circular Convolution
1 / / E x am pl e 3 . 1 32 / / Program t o C ompute c i r c u l a r c o n v o l u t i o n o f
f o l l o w i n g s e qu e nc e s3 //x 1 [ n] = [ 1 , 1 , 2 , 3 , 1]4 / / x 2 [ n ] = [ 1 , 2 , 3 ]
5 c l e ar a ll ;6 clc ;
7 close ;
8 x 1 = [ 1 , - 1 , - 2 , 3 , - 1 ] ;
9 x 2 = [ 1 , 2 , 3 ] ;
65
8/11/2019 Digital Signal Processing_R. Babu
67/148
10 / /Loop f o r z e r o p add in g t he s m a l l er s eq ue nc e o ut o f
t h e two11 n1 = length ( x 1 ) ;12 n2 = length ( x 2 ) ;
13 n 3 = n 2 - n 1 ;
14 if ( n 3 > = 0 ) then
15 x 1 = [ x 1 , zeros ( 1 , n 3 ) ] ;
16 else
17 x 2 = [ x 2 , zeros ( 1 , - n 3 ) ] ;
18 end
19 //DFT Compu tatio n20 X1 = fft ( x 1 , - 1 ) ;
21 X2 = fft ( x 2 , - 1 ) ;22 Y = X 1 . * X 2 ;
23 //IDFT Comput ation24 y = fft ( Y , 1 ) ;
25 / / D i s p l a y s e q u e n c e y [ n ] i n command w in do w26 disp (y , y [ n]= ) ;
Scilab code Exa 3.14 Circular Convolution
1 / / E x am pl e 3 . 1 42 / / Program t o C ompute c i r c u l a r c o n v o l u t i o n o f
f o l l o w i n g s e qu e nc e s3 / / x 1 [ n ] = [ 1 , 2 , 2 , 1 ]4 / / x 2 [ n ] = [ 1 , 2 , 3 , 1 ]5 c l e ar a ll ;
6 clc ;
7 close ;
8 x 1 = [ 1 , 2 , 2 , 1 ] ;
9 x 2 = [ 1 , 2 , 3 , 1 ] ;10 //DFT Compu tatio n11 X1 = fft ( x 1 , - 1 ) ;
12 X2 = fft ( x 2 , - 1 ) ;
13 Y = X 1 . * X 2 ;
66
8/11/2019 Digital Signal Processing_R. Babu
68/148
8/11/2019 Digital Signal Processing_R. Babu
69/148
6 clc ;
7 close ;8 x 1 = [ 1 , 1 , 2 , 1 ] ;
9 x 2 = [ 1 , 2 , 3 , 4 ] ;
10 //DFT Compu tatio n11 X1 = fft ( x 1 , - 1 ) ;
12 X2 = fft ( x 2 , - 1 ) ;
13 X 3 = X 1 . * X 2 ;
14 //IDFT Comput ation15 x3 = fft ( X 3 , 1 ) ;
16 / / D i s p l a y s e q u e n c e x 3 [ n ] i n command wi nd ow17 disp ( x 3 , x3 [ n]= ) ;
Scilab code Exa 3.17 Circular Convolution
1 / / E x am pl e 3 . 1 72 // Program to Compute y [ n ] where Y[ k]=X1 [ k ] . X2 [ k ]3 / / x 1 [ n ] = [ 0 , 1 , 2 , 3 , 4 ]4 / / x 2 [ n ] = [ 0 , 1 , 0 , 0 , 0 ]5 c l e ar a ll ;
6 clc ;7 close ;
8 x 1 = [ 0 , 1 , 2 , 3 , 4 ] ;
9 x 2 = [ 0 , 1 , 0 , 0 , 0 ] ;
10 //DFT Compu tatio n11 X1 = fft ( x 1 , - 1 ) ;
12 X2 = fft ( x 2 , - 1 ) ;
13 Y = X 1 . * X 2 ;
14 //IDFT Comput ation15 y = round ( fft ( Y , 1 ) ) ;
16 / / D i s p l a y s e q u e n c e y [ n ] i n command w in do w17 disp (y , y [ n]= ) ;
68
8/11/2019 Digital Signal Processing_R. Babu
70/148
Scilab code Exa 3.18 Output Response
1 / / E x am pl e 3 . 1 82 / / Program t o Compute o u tp ut r e s p o n c e o f f o l l o w i n g
s e q u e n c e s3 / / x [ n ] = [ 1 , 2 , 3 , 1 ]4 / / h [ n ] = [ 1 , 1 , 1 ]5 / / ( 1 ) L i n e a r C o n v o l u t i o n6 / / ( 2 ) C i r c u l a r C o n v o l u ti o n7 / / ( 3 ) C i r c u l a r C o n vo l u ti o n w it h z e r o p ad di ng8 c l e ar a ll ;
9 clc ;
10 close ;11 x = [ 1 , 2 , 3 , 1 ] ;
12 h = [ 1 , 1 , 1 ] ;
13 / / ( 1 ) L i n e a r C o n v o l u t i o n C o mp ut a ti on14 y l i n e a r = convol ( x , h ) ;
15 / / D i s p l a y L i n e a r C o n v ol u t e d S e q u en c e y [ n ] i n commandwindow
16 disp (yli near , y l i n e a r [ n ]= ) ;17 / / ( 2 ) C i r c u l a r C o n v o l u ti o n C om pu ta ti on18 / /Now z e r o p a dd i ng i n h [ n ] s e q u e n c e t o make l e n g t h
o f x [ n ] a nd h [ n ] e q u a l19 h 1 = [ h , zeros ( 1 , 1 ) ] ;20 / / Now P e r f o r m i n g C i r c u l a r C o n v o l u t i o n by DFT m et ho d21 X = fft ( x , - 1 ) ;
22 H = fft ( h 1 , - 1 ) ;
23 Y = X . * H ;
24 y c i r c u l a r = fft ( Y , 1 ) ;
25 / / D i s p l a y C i r c u l a r C o nv o lu t ed S e qu e nc e y [ n ] i ncommand window
26 disp (ycircular , y c i r c u l a r [ n ]= ) ;27 / / ( 3 ) C i r c u l a r C o n v o l u ti o n C om pu ta ti on w i th z e r o
Padding28 x 2 = [ x , zeros ( 1 , 2 ) ] ;
29 h 2 = [ h , zeros ( 1 , 3 ) ] ;
30 / / Now P e r f o r m i n g C i r c u l a r C o n v o l u t i o n by DFT m et ho d31 X2 = fft ( x 2 , - 1 ) ;
69
8/11/2019 Digital Signal Processing_R. Babu
71/148
32 H2 = fft ( h 2 , - 1 ) ;
33 Y 2 = X 2 . * H 2 ;34 y c i r c u l a r p = fft ( Y 2 , 1 ) ;
35 / / D i s p l ay C i r c u l a r C on vo lu te d S eq ue nc e w it h z e r oPadding y [ n ] in command window
36 disp (ycircularp , y c i r c u l a r p [ n ]= ) ;
Scilab code Exa 3.20 Output Response
1 / / E x am pl e 3 . 2 02 / / Program t o Compute L i n e a r C o nv o l ut i o n o f f o l l o w i n gs e q u e n c e s
3 //x [ n ] = [ 3 , 1 , 0 , 1 , 3 , 2 , 0 , 1 , 2 , 1 ]4 / / h [ n ] = [ 1 , 1 , 1 ]5 c l e ar a ll ;
6 clc ;
7 close ;
8 x = [ 3 , - 1 , 0 , 1 , 3 , 2 , 0 , 1 , 2 , 1 ] ;
9 h = [ 1 , 1 , 1 ] ;
10 / / L i n e a r C o n v o l ut i o n C om pu ta ti on
11 y = convol ( x , h ) ;12 / / D i s p l a y S e q u e n c e y [ n ] i n command w in do w13 disp (y , y [ n]= ) ;
Scilab code Exa 3.21 Linear Convolution
1 / / E x am pl e 3 . 2 12 / / Program t o Compute L i n e a r C o nv o l ut i o n o f f o l l o w i n g
s e q u e n c e s3 // x [ n ]=[ 1 ,2 ,1 ,2 ,3 ,2 ,3 ,1 ,1 ,1 ,2 ,1 ]4 / / h [ n ] = [ 1 , 2 ]5 c l e ar a ll ;
6 clc ;
70
8/11/2019 Digital Signal Processing_R. Babu
72/148
7 close ;
8 x = [ 1 , 2 , - 1 , 2 , 3 , - 2 , - 3 , - 1 , 1 , 1 , 2 , - 1 ] ;9 h = [ 1 , 2 ] ;
10 / / L i n e a r C o n v o l ut i o n C om pu ta ti on11 y = convol ( x , h ) ;
12 / / D i s p l a y S e q u e n c e y [ n ] i n command w in do w13 disp (y , y [ n]= ) ;
Scilab code Exa 3.23.a N Point DFT Computation
1 / / Example 3 . 2 3 ( a )2 //MAXIMA SCILAB TOOLBOX REQUIRED FOR THIS PROGRAM3 / /N p o i n t DFT o f d e l t a ( n )4 clc ;
5 syms n k N ;
6 x = 1 ;
7 X = s y m s u m ( x * exp ( - % i * 2 * % p i * n * k / N ) , n , 0 , 0 ) ;
8 disp (X , X( k ) = ) ;
Scilab code Exa 3.23.b N Point DFT Computation
1 / / Exam ple 3 . 2 3 ( b )2 //MAXIMA SCILAB TOOLBOX REQUIRED FOR THIS PROGRAM3 / /N p o i n t DFT o f d e l t a ( nno )4 clc ;
5 syms n k N no ;
6 x = 1 ;
7 X = s y m s u m ( x * exp ( - % i * 2 * % p i * n * k / N ) , n , - n o , - n o ) ;
8 disp (X , X( k ) = ) ;
71
8/11/2019 Digital Signal Processing_R. Babu
73/148
Scilab code Exa 3.23.c N Point DFT Computation
1 / / E xa mp le 3 . 2 3 ( c )2 //MAXIMA SCILAB TOOLBOX REQUIRED FOR THIS PROGRAM3 / /N p o i n t DFT o f a n4 clc ;
5 syms a n k N ;
6 x = a ^ n ;
7 X = s y m s u m ( x * exp ( - % i * 2 * % p i * n * k / N ) , n , 0 , N - 1 ) ;
8 disp (X , X( k ) = ) ;
Scilab code Exa 3.23.d N Point DFT Computation
1 / / Exam ple 3 . 2 3 ( d )2 //MAXIMA SCILAB TOOLBOX REQUIRED FOR THIS PROGRAM3 / /N p o i n t DFT o f x ( n ) =1 , 0
8/11/2019 Digital Signal Processing_R. Babu
74/148
Scilab code Exa 3.23.f N Point DFT Computation
1 / / E xa mp le 3 . 2 3 ( f )2 //MAXIMA SCILAB TOOLBOX REQUIRED FOR THIS PROGRAM3 / /N p o i n t DFT o f x ( n ) =1 , f o r n=e ve n and 0 , f o r n=odd4 clc ;
5 syms n k N ;
6 x = 1 ; // x (2 n ) =1 , f o r a l l n7 X = s y m s u m ( x * exp ( - % i * 4 * % p i * n * k / N ) , n , 0 , N / 2 - 1 ) ;
8 disp (X , X( k ) = ) ;
Scilab code Exa 3.24 DFT of the Sequence
1 / / E x am pl e 3 . 2 42 / / P ro gr am t o Compute t h e DFT o f t h e S e q u e nc e x [ n
]=(1 ) n , f o r N=4
3 c l e ar a ll ;4 clc ;
5 close ;
6 N = 4 ;
7 n = 0 : 1 : N - 1 ;
8 x = ( - 1 ) ^ n ;
9 //DFT Compu tatio n10 X = fft ( x , - 1 ) ;
11 / / D i s p l a y S e q u e n c e X [ k ] i n command w in do w12 disp (X , X[ k]= ) ;
Scilab code Exa 3.25 8 Point Circular Convolution
73
8/11/2019 Digital Signal Processing_R. Babu
75/148
1 / / E x am pl e 3 . 2 5
2 / / P r o gr am t o Com pu te t h e 8p o in t C i r c ul a rC o nv o l ut i on o f t h e S e qu e nc e s3 / / x 1 [ n ] = [ 1 , 1 , 1 , 1 , 0 , 0 , 0 , 0 ]4 // x2 [ n]= s i n (3 p i n / 8 )5 c l e ar a ll ;
6 clc ;
7 close ;
8 x 1 = [ 1 , 1 , 1 , 1 , 0 , 0 , 0 , 0 ] ;
9 n = 0 : 1 : 7 ;
10 p i = 2 2 / 7 ;
11 x2 = sin ( 3 * p i * n / 8 ) ;
12 //DFT Compu tatio n13 X1 = fft ( x 1 , - 1 ) ;
14 X2 = fft ( x 2 , - 1 ) ;
15 / / C i r c u l a r C o n v o l ut i o n u s i n g DFT16 Y = X 1 . * X 2 ;
17 //IDFT Comput ation18 y = fft ( Y , 1 ) ;
19 / / D i s p l a y s e q u e n c e y [ n ] i n command w in do w20 disp (y , y [ n]= ) ;
Scilab code Exa 3.26 Linear Convolution using DFT
1 / / E x am pl e 3 . 2 62 / / Pr ogr am t o Compute t h e L i n e a r C o n v o l ut i o n o f t h e
f o l l o w i n g S eq ue nc es3 //x [ n ]= [1 ,1 , 1]4 / / h [ n ] = [ 2 , 2 , 1 ]5 c l e ar a ll ;
6 clc ;7 close ;
8 x = [ 1 , - 1 , 1 ] ;
9 h = [ 2 , 2 , 1 ] ;
10 / / C o n v o l u t i o n C o m pu t a ti o n
74
8/11/2019 Digital Signal Processing_R. Babu
76/148
11 y = convol ( x , h ) ;
12 / / D i s p l a y s e q u e n c e y [ n ] i n command w in do w13 disp (y , y [ n]= ) ;
Scilab code Exa 3.27.a Circular Convolution Computation
1 / / Example 3 . 2 7 ( a )2 / / P ro gr am t o Compute t h e C o n v o l ut i o n o f t h e
f o l l o w i n g S eq ue nc es
3 / / x 1 [ n ] = [ 1 , 1 , 1 ]4 // x2 [ n ]= [2 ,1 ,2 ]5 c l e ar a ll ;
6 clc ;
7 close ;
8 x 1 = [ 1 , 1 , 1 ] ;
9 x 2 = [ 2 , - 1 , 2 ] ;
10 / / C o n v o l u t i o n C o m pu t a ti o n11 X1 = fft ( x 1 , - 1 ) ;
12 X2 = fft ( x 2 , - 1 ) ;
13 Y = X 1 . * X 2 ;
14 y = fft ( Y , 1 ) ;15 / / D i s p l a y S e q u e n c e y [ n ] i n command w in do w16 disp (y , y [ n]= ) ;
Scilab code Exa 3.27.b Circular Convolution Computation
1 / / Exam ple 3 . 2 7 ( b )2 / / P ro gr am t o Compute t h e C o n v o l ut i o n o f t h e
f o l l o w i n g S eq ue nc es3 // x1 [ n ]= [1 ,1 ,1 ,1 ,0 ]4 // x2 [ n ]= [1 ,0 , 1 , 0 , 1 ]5 c l e ar a ll ;
6 clc ;
75
8/11/2019 Digital Signal Processing_R. Babu
77/148
7 close ;
8 x 1 = [ 1 , 1 , - 1 , - 1 , 0 ] ;9 x 2 = [ 1 , 0 , - 1 , 0 , 1 ] ;
10 / / C o n v o l u t i o n C o m pu t a ti o n11 X1 = fft ( x 1 , - 1 ) ;
12 X2 = fft ( x 2 , - 1 ) ;
13 Y = X 1 . * X 2 ;
14 y = fft ( Y , 1 ) ;
15 / / D i s p l a y S e q u e n c e y [ n ] i n command w in do w16 disp (y , y [ n]= ) ;
Scilab code Exa 3.30 Calculate value of N
1 / / E x am pl e 3 . 3 02 / / Program t o C a l c u l a t e N fr om g i v e n d at a3 //fm=5000Hz4 // d f =50Hz5 // t = 0. 5 se c6 c l e ar a ll ;
7 clc ;
8 close ;9 f m = 5 0 0 0 //Hz
10 d f = 5 0 //Hz11 t = 0 . 5 // se c12 N 1 = 2 * f m / d f ;
13 N = 2 ;
14 while N < = N1 , N = N *2 , end
15 / / D i s p l a y i n g t h e v a l u e o f N i n command window16 disp (N , N= ) ;
Scilab code Exa 3.32 Sketch Sequence
76
8/11/2019 Digital Signal Processing_R. Babu
78/148
Figure 3.3: Sketch Sequence
1 / / E x am pl e 3 . 3 22 // Program t o p l o t t he r e s u l t o f t he g i ve n s eq ue nc e3 //X [ k ] = [ 1 , 2 , 2 , 1 , 0 , 2 , 1 , 2 ]4 / / y [ n ] = x [ n / 2 ] f o r n=e v en , 0 f o r n=o dd5 c l e ar a ll ;
6 clc ;
7 close ;
8 X = [ 1 , 2 , 2 , 1 , 0 , 2 , 1 , 2 ] ;
9 x = fft ( X , 1 ) ;10 y = [ x ( 1 ) , 0 , x ( 2 ) , 0 , x ( 3 ) , 0 , x ( 4 ) , 0 , x ( 5 ) , 0 , x ( 6 ) , 0 , x ( 7 ) , 0 ,
x(8) ,0];
11 Y = fft ( y , -1) ;
12 / / D i s p l a y s e q u e n c e Y [ k ] a nd i n command w in do w13 disp (Y , Y[ k]= ) ;14 / / P l o t t i n g t h e s e q ue n c e Y [ k ]15 k = 0 : 1 : 1 5 ;
16 a = gca () ;
17 a . y _ l o c at i o n = o r i g i n ;18 a . x _ l o c at i o n = o r i g i n ;19 plot2d3 ( k , Y , 2 ) ;
20 p o ly 1 = a . c h i l dr e n ( 1 ) . c h i ld r e n ( 1) ;
21 p o l y 1 . t h i c k n e s s = 2 ;
22 xtitle ( P l o t o f Y( k ) , k ,Y ( k ) ) ;
77
8/11/2019 Digital Signal Processing_R. Babu
79/148
Scilab code Exa 3.36 Determine IDFT
1 / / E x am pl e 3 . 3 62 / / P ro gr am t o Compute t h e IDFT o f t h e f o l l o w i n g
S e q u e n c e3 //X [ k ] = [ 12 , 1.5 + j2 .5 98 ,1.5 + j0 .86 6 ,0 ,1 . 5j 0
. 8 6 6 , 1.5 j 2 . 5 9 8 ]4 c l e ar a ll ;
5 clc ;6 close ;
7 j = sqrt ( - 1 ) ;
8 X = [ 1 2 , - 1 . 5 + j * 2 . 5 9 8 , - 1 . 5 + j * 0 . 8 6 6 , 0 , - 1 . 5 - j * 0 . 8 6 6 , - 1 . 5 -
j * 2 . 5 9 8 ] ;
9 //IDFT Comput ation10 x = fft ( X , 1 ) ;
11 / / D i s p l a y S e q u e n c e x [ n ] i n command w in do w12 disp ( round ( x ) , x [ n]= ) ;
78
8/11/2019 Digital Signal Processing_R. Babu
80/148
Chapter 4
THE FAST FOURIER
TRANSFORM
Scilab code Exa 4.3 Shortest Sequence N Computation
1 / / E xa mp le 4 . 32 // Program t o c a l c u l a t e s h o r t e s t s eq ue nc e N su ch t ha t
a l go r it h m B r un s // f a s t e r t han A3 c l e ar a ll ;
4 clc ;
5 close ;
6 i = 0 ;
7 N = 3 2 ; //Gi v e n8 / / C a l c u l a t i o n o f T wi dd le f a c t o r e xp o ne nt s f o r e ac h
s t a g e9 while 1==1
10 i = i + 1 ;
11 N = 2 ^ i ;
12 A = N ^ 2 ;
13 B = 5 * N * log2 ( N ) ;14 if A > B t he n b r ea k ;
15 end ;
16 end
17 disp (N ,SHORTEST SEQUENCE N = ) ;
79
8/11/2019 Digital Signal Processing_R. Babu
81/148
Scilab code Exa 4.4 Twiddle Factor Exponents Calculation
1 / / E xa mp le 4 . 42 // Program t o c a l c u l a t e T wi dd le f a c t o r e xp o ne nt s f o r
e ac h s t a g e3 c l e ar a ll ;
4 clc ;
5 close ;
6 N = 3 2 ; //Gi v e n7 / / C a l c u l a t i o n o f T wi dd le f a c t o r e xp o ne nt s f o r e ac h
s t a g e8 for m = 1 : 5
9 disp (m , S t a g e : m = ) ;10 disp ( k = ) ;11 for t = 0 : ( 2 ^ ( m - 1 ) - 1 )
12 k = N * t / 2 ^ m ;
13 disp ( k ) ;
14 end
15 end
Scilab code Exa 4.6 DFT using DIT Algorithm
1 / / E xa mp le 4 . 62 / / Pr ogr am t o f i n d t h e DFT o f a S e qu e nc e x [ n
] = [ 1 , 2 , 3 , 4 , 4 , 3 , 2 , 1 ]3 / / u s i n g DIT A l g o r i t h m .4 c l e ar a ll ;
5 clc ;
6 close ;
7 x = [ 1 ,2 , 3 , 4 ,4 , 3 , 2 ,1 ];
8 //FFT Compu tatio n
80
8/11/2019 Digital Signal Processing_R. Babu
82/148
9 X = fft ( x , -1) ;
10 disp (X , X ( z ) = ) ;
Scilab code Exa 4.8 DFT using DIF Algorithm
1 / / E xa mp le 4 . 82 / / Pr ogr am t o f i n d t h e DFT o f a S e qu e nc e x [ n
] = [ 1 , 2 , 3 , 4 , 4 , 3 , 2 , 1 ]3 / / u s i n g DIF A l g o r i t h m .4 c l e ar a ll ;
5 clc ;
6 close ;
7 x = [ 1 ,2 , 3 , 4 ,4 , 3 , 2 ,1 ];
8 //FFT Compu tatio n9 X = fft ( x , -1) ;
10 disp (X , X ( z ) = ) ;
Scilab code Exa 4.9 8 Point DFT of the Sequence
1 / / E xa mp le 4 . 92 / / Program t o f i n d t he 8p o i n t DFT o f a S e qu e nc e x [ n
] = 1 , 0
8/11/2019 Digital Signal Processing_R. Babu
83/148
Scilab code Exa 4.10 4 Point DFT of the Sequence
1 / / E x am pl e 4 . 1 02 / / P r o gr am t o Com pu te t h e 4p o i n t DFT o f a S eq ue nc e x
[ n ] = [ 0 , 1 , 2 , 3 ]3 / / u s i n g DITDIF A l g o r i t h m .4 c l e ar a ll ;
5 clc ;
6 close ;
7 x = [0 , 1 ,2 , 3] ;
8 //FFT Compu tatio n9 X = fft ( x , -1) ;
10 disp (X , X ( z ) = ) ;
Scilab code Exa 4.11 IDFT of the Sequence using DIT Algorithm
1 / / E x am pl e 4 . 1 12 / / P ro gr am t o Compute t h e IDFT o f a S e q u en c e u s i n g
DIT A l go r i t hm .3 / /X [ k ] = [ 7 , 0. 707 j 0 . 70 7 , j , 0 . 707j 0 . 7 0 7 , 1 , 0 . 7 0 7 + j 0
.7 0 7 , j ,0 . 70 7 + j 0 . 7 0 7 ]4 c l e ar a ll ;
5 clc ;
6 close ;
7 j = sqrt ( - 1 ) ;
8 X = [ 7 , - 0 .7 07 - j * 0. 70 7 , - j , 0 .7 0 7 - j * 0 . 7 07 , 1 , 0 . 7 07 + j
* 0 . 7 0 7 , j , - 0 . 7 0 7 + j * 0 . 7 0 7 ] ;
9 / / I n v e r s e FFT C o m pu t a ti o n10 x = fft ( X , 1 ) ;
11 disp (x , x ( n ) = ) ;
Scilab code Exa 4.12 8 Point DFT of the Sequence
82
8/11/2019 Digital Signal Processing_R. Babu
84/148
1 / / E x am pl e 4 . 1 2
2 / / P r o gr am t o Com pu te t h e 8p o i n t DFT o f a S e qu e nc e3 / /x [ n ] = [ 0 . 5 , 0 . 5 , 0 . 5 , 0 . 5 , 0 , 0 , 0 , 0 ] u s i n g r a di x2 DITA l gor i t hm .
4 c l e ar a ll ;
5 clc ;
6 close ;
7 x = [ 0 . 5 , 0 . 5 , 0 . 5 , 0 . 5 , 0 , 0 , 0 , 0 ] ;
8 //FFT Compu tatio n9 X = fft ( x , -1) ;
10 disp (X , X ( z ) = ) ;
Scilab code Exa 4.13 8 Point DFT of the Sequence
1 / / E x am pl e 4 . 1 32 / / P r o gr am t o Com pu te t h e 8p o i n t DFT o f a S e qu e nc e3 / /x [ n ] = [ 0 . 5 , 0 . 5 , 0 . 5 , 0 . 5 , 0 , 0 , 0 , 0 ] u s i n g r a di x2 DIF
A l gor i t hm .4 c l e ar a ll ;
5 clc ;
6 close ;7 x = [ 0 . 5 , 0 . 5 , 0 . 5 , 0 . 5 , 0 , 0 , 0 , 0 ] ;
8 //FFT Compu tatio n9 X = fft ( x , -1) ;
10 disp (X , X ( z ) = ) ;
Scilab code Exa 4.14 DFT using DIT Algorithm
1 / / E x am pl e 4 . 1 42 / / P r o gr am t o Com pu te t h e 4p o i n t DFT o f a S eq ue nc e x
[ n ]=[ 1 ,1 ,1 ,1 ]3 / / u s i n g DIT A l g o r i t h m .4 c l e ar a ll ;
83
8/11/2019 Digital Signal Processing_R. Babu
85/148
5 clc ;
6 close ;7 x = [ 1 , - 1 , 1 , - 1 ] ;
8 //FFT Compu tatio n9 X = fft ( x , -1) ;
10 disp (X , X ( z ) = ) ;
Scilab code Exa 4.15 DFT using DIF Algorithm
1 / / E x am pl e 4 . 1 52 / / P r o gr am t o Com pu te t h e 4p o i n t DFT o f a S eq ue nc e x[ n ] = [ 1 , 0 , 0 , 1 ]
3 / / u s i n g DIF A l g o r i t h m .4 c l e ar a ll ;
5 clc ;
6 close ;
7 x = [ 1 , 0 , 0 , 1 ] ;
8 //FFT Compu tatio n9 X = fft ( x , -1) ;
10 disp (X , X ( z ) = ) ;
Scilab code Exa 4.16.a 8 Point DFT using DIT FFT
1 / / Example 4 . 1 6 ( a )2 / / P ro gr am t o E v a l u a t e a nd Co mpa re t h e 8p o i n t DFT o f
t h e g i v e n S eq ue nc e3 // x1 [ n ]=1 , 3
8/11/2019 Digital Signal Processing_R. Babu
86/148
10 disp ( X 1 , X1 ( k ) = ) ;
Scilab code Exa 4.16.b 8 Point DFT using DIT FFT
1 / / Exam ple 4 . 1 6 ( b )2 / / P ro gr am t o E v a l u a t e a nd Co mpa re t h e 8p o i n t DFT o f
t h e g i v e n S eq ue nc e3 //x 2 [ n] = 1 , 0
8/11/2019 Digital Signal Processing_R. Babu
87/148
8/11/2019 Digital Signal Processing_R. Babu
88/148
8/11/2019 Digital Signal Processing_R. Babu
89/148
5 clc ;
6 close ;7 N = 8 ;
8 n = 0 : 1 : N - 1 ;
9 x = 2^ n ;
10 //FFT Compu tatio n11 X = fft ( x , -1) ;
12 disp (X , X ( z ) = ) ;
Scilab code Exa 4.23 DFT using DIF FFT Algorithm
1 / / E x am pl e 4 . 2 32 / / P r og ra m t o Compute t h e DFT o f g i v e n S e q u e nc e3 //x [ n]= co s (n p i / 2 ) , a nd N=4 u s i n g DIFFFT Alg ori thm .4 c l e ar a ll ;
5 clc ;
6 close ;
7 N = 4 ;
8 p i = 2 2 / 7 ;
9 n = 0 : 1 : N - 1 ;
10 x = cos ( n * p i / 2 ) ;11 //FFT Compu tatio n12 X = fft ( x , -1) ;
13 disp (X , X ( z ) = ) ;
Scilab code Exa 4.24 8 Point DFT of the Sequence
1 / / E x am pl e 4 . 2 4
2 / / P r o gr am t o Com pu te t h e 8p o i n t DFT o f g i v e nS e q u e n c e
3 / / x [ n ] = [ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 ] u s i n g DIF , r a d i x2,FFTA l gor i t hm .
4 c l e ar a ll ;
88
8/11/2019 Digital Signal Processing_R. Babu
90/148
5 clc ;
6 close ;7 x = [ 0 ,1 , 2 , 3 ,4 , 5 , 6 ,7 ];
8 //FFT Compu tatio n9 X = fft ( x , -1) ;
10 disp (X , X ( z ) = ) ;
89
8/11/2019 Digital Signal Processing_R. Babu
91/148
Chapter 5
INFINITE IMPULSE
RESPONSE FILTERS
Scilab code Exa 5.1 Order of the Filter Determination
1 / / E xa mp le 5 . 12 / /To Fi nd o ut t h e o r d e r o f t h e f i l t e r3 c l e ar a ll ;
4 clc ;
5 close ;
6 a p = 1 ; //db7 a s = 3 0 ; //db8 o p = 2 0 0 ; / / r a d / s e c9 o s = 6 0 0 ; / / r a d / s e c
10 N = log ( sqrt ( ( 1 0 ^ ( 0 . 1 * a s ) - 1 ) / ( 1 0 ^ ( 0 . 1 * a p ) - 1 ) ) ) / log ( o s /
o p ) ;
11 disp ( ceil ( N ) , O rd er o f t h e f i l t e r , N = ) ;
Scilab code Exa 5.2 Order of Low Pass Butterworth Filter
1 / / E xa mp le 5 . 2
90
8/11/2019 Digital Signal Processing_R. Babu
92/148
2 / /To F i nd o ut t h e o r d e r o f a Low P a s s B u tt er w or th
F i l t e r3 c l e ar a ll ;4 clc ;
5 close ;
6 a p = 3 ; //db7 a s = 4 0 ; //db8 f p = 5 0 0 ; //Hz9 f s = 1 0 0 0 ; //Hz
10 o p = 2 * % p i * f p ;
11 o s = 2 * % p i * f s ;
12 N = log ( sqrt ( ( 1 0 ^ ( 0 . 1 * a s ) - 1 ) / ( 1 0 ^ ( 0 . 1 * a p ) - 1 ) ) ) / log ( o s /
o p ) ;13 disp ( ceil ( N ) , O rd er o f t h e f i l t e r , N = ) ;
Scilab code Exa 5.4 Analog Butterworth Filter Design
1 / / E xa mp le 5 . 42 / /To D es i gn an A na lo g B u tt e rw o rt h F i l t e r3 c l e ar a ll ;
4 clc ;5 close ;
6 a p = 2 ; //db7 a s = 1 0 ; //db8 o p = 2 0 ; / / r a d / s e c9 o s = 3 0 ; / / r a d / s e c
10 N = log ( sqrt ( ( 1 0 ^ ( 0 . 1 * a s ) - 1 ) / ( 1 0 ^ ( 0 . 1 * a p ) - 1 ) ) ) / log ( o s /
o p ) ;
11 disp ( ceil ( N ) , O rd er o f t h e f i l t e r , N = ) ;12 s = % s ;
13 H S = 1 / ( ( s ^ 2 + 0 . 7 6 5 3 7 * s + 1 ) * ( s ^ 2 + 1 . 8 4 7 7 * s + 1 ) ) ; / / T r a n s f e rF u n c t i o n f o r N=414 o c = o p / ( 1 0 ^ ( 0 . 1 * a p ) - 1 ) ^ ( 1 / ( 2 * ceil ( N ) ) ) ;
15 H S 1 = horner ( H S , s / o c ) ;
16 disp ( H S 1 , N o r m a l i ze d T r a n s f e r F u n ct i o n , H( s ) = ) ;
91
8/11/2019 Digital Signal Processing_R. Babu
93/148
Scilab code Exa 5.5 Analog Butterworth Filter Design
1 / / E xa mp le 5 . 52 / /To D es i gn an A na lo g B u tt e rw o rt h F i l t e r3 c l e ar a ll ;
4 clc ;
5 close ;
6 o p = 0 . 2 * % p i ;
7 o s = 0 . 4 * % p i ;8 e 1 = 0 . 9 ;
9 l 1 = 0 . 2 ;
10 e p s i l o n = sqrt ( 1 / ( e 1 ^ 2 ) - 1 ) ;
11 l a m b d a = sqrt ( 1 / ( l 1 ^ 2 ) - 1 ) ;
12 N = log ( l a m b d a / e p s i l o n ) / log ( o s / o p ) ;
13 disp ( ceil ( N ) , O rd er o f t h e f i l t e r , N = ) ;14 s = % s ;
15 H S = 1 / ( ( s ^ 2 + 0 . 7 6 5 3 7 * s + 1 ) * ( s ^ 2 + 1 . 8 4 7 7 * s + 1 ) ) ; / / T r a n s f e rF u n c t i o n f o r N=4
16 o c = o p / e p s i l o n ^ ( 1 / ceil ( N ) ) ;
17 H S 1 = horner ( H S , s / o c ) ;
18 disp ( H S 1 , N o r m a l i ze d T r a n s f e r F u n ct i o n , H( s ) = ) ;
Scilab code Exa 5.6 Order of Chebyshev Filter
1 / / E xa mp le 5 . 62 / /To F i nd o ut t h e o r d e r o f t he F i l t e r u si ng
C h eb y s he v A p p r o x i m a t i o n3 c l e ar a ll ;4 clc ;
5 close ;
6 a p = 3 ; //db
92
8/11/2019 Digital Signal Processing_R. Babu
94/148
7 a s = 1 6 ; //db
8 f p = 1 0 0 0 ; //Hz9 f s = 2 0 0 0 ; //Hz10 o p = 2 * % p i * f p ;
11 o s = 2 * % p i * f s ;
12 N = acosh ( sqrt ( ( 1 0 ^ ( 0 . 1 * a s ) - 1 ) / ( 1 0 ^ ( 0 . 1 * a p ) - 1 ) ) ) / acosh
( o s / o p ) ;
13 disp ( ceil ( N ) , O rd er o f t h e f i l t e r , N = ) ;
Scilab code Exa 5.7 Chebyshev Filter Design
1 / / E xa mp le 5 . 72 / /To D es i gn an a n a l og C he bys hev F i l t e r w it h G iv en
S p e c i f i c a t i o n s3 c l e ar a ll ;
4 clc ;
5 close ;
6 o s = 2 ;
7 o p = 1 ;
8 a p = 3 ; //db
9 a s = 1 6 ; //db10 e 1 = 1 / sqrt ( 2 ) ;
11 l 1 = 0 . 1 ;
12 e p s i l o n = sqrt ( 1 / ( e 1 ^ 2 ) - 1 ) ;
13 l a m b d a = sqrt ( 1 / ( l 1 ^ 2 ) - 1 ) ;
14 N = acosh ( l a m b d a / e p s i l o n ) / acosh ( o s / o p ) ;
15 disp ( ceil ( N ) , O rd er o f t h e f i l t e r , N = ) ;
Scilab code Exa 5.8 Order of Type 1 Low Pass Chebyshev Filter
1 / / E xa mp le 5 . 82 / /To F i nd o ut t he o r de r o f t he p o l e s o f t he Type 1
L ow pa ss C he by sh ev F i l t e r
93
8/11/2019 Digital Signal Processing_R. Babu
95/148
3 c l e ar a ll ;
4 clc ;5 close ;
6 a p = 1 ; //dB7 a s = 4 0 ; //dB8 o p = 1 0 0 0 * % p i ;
9 o s = 2 0 0 0 * % p i ;
10 N = acosh ( sqrt ( ( 1 0 ^ ( 0 . 1 * a s ) - 1 ) / ( 1 0 ^ ( 0 . 1 * a p ) - 1 ) ) ) / acosh
( o s / o p ) ;
11 disp ( ceil ( N ) , O rd er o f t h e f i l t e r , N = ) ;
Scilab
Top Related