Jul 15, 2010 ... by Proakis and Manolakis. 1. Created by. Hasan Ali Stationwala. B.Tech., 2nd
Year Student. Electronics and Communication Engineering,.
Scilab Codes for Digital Signal Processing by Proakis and Manolakis1 Created by Hasan Ali Stationwala B.Tech., 2nd Year Student Electronics and Communication Engineering, National Institute Of Technology, Tiruchirappalli College teacher Madhu N. Belur, IIT Bombay Reviewer Prashant Dave, IIT Bombay 15 July, 2010
1 Funded
by a grant from the National Mission on Education through ICT, http://spoken-tutorial.org/NMEICT-Intro
Book Details Authors: Proakis and Manolakis Title: Digital Signal Processing: Principle, algorithms and applications Publisher: Dorling Kindersley India Pvt. Ltd. (licensees of Prentice Education in South Asia) Edition: 4th Year: 2007 Place: New Delhi
Scilab numbering policy used in this document and the relation to the above book is as follows. Prb Problem (Unsolved problem) These are at the end of each chapter. Exa Example (Solved example) Sec Section (Particular section of the above book) For example, Prb 2.67 means Problem 2.67 of the above book. Scilab code having number Sec 2.6 means a scilab code whose theory is explained in Section 2.6 of the book. 1
Contents List of Scilab Codes
4
2 Impulse Response and Correlation 2.4 Impulse response . . . . . . . . . 2.66 Problem . . . . . . . . . . . . . . 2.67 Problem . . . . . . . . . . . . . . 2.6 Correlation . . . . . . . . . . . . 2.65 Problem . . . . . . . . . . . . . .
. . . . .
. . . . .
2 2 3 5 6 8
5 Quantization and Filter Design by 5.1 Function “quantize()” . . . . . . 5.14 Problem . . . . . . . . . . . . . . 5.4 Filter Design by placing poles and 5.43 Problem . . . . . . . . . . . . . .
placing . . . . . . . . . . zeros . . . . . .
poles and zeros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
15 15 17 18 18
8 The discrete fourier transform transform (FFT) 8.1 Function “mydft()” . . . . . . 8.2 Function “divdft()” . . . . . . 8.3 Function “r2fft()” . . . . . . . 8.36 Problem . . . . . . . . . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
(DFT) and the fast fourier . . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
9 Implementation of FIR and IIR filters 9.2 Function “direct1()”, ”lattfir()” and ”lattimpulse()” 9.2.1 Function ”direct()” . . . . . . . . . . . . . . 9.2.4 Function “lattfir()” . . . . . . . . . . . . . . 9.3 Function ”lattimpulse()” . . . . . . . . . . . . . . . 9.4 Function “lattladd()” and ”llimpulse()” . . . . . . . 2
. . . . .
. . . .
. . . . .
. . . .
. . . . .
. . . .
. . . . .
. . . .
. . . . .
. . . .
20 20 21 23 24
. . . . .
27 27 27 29 30 31
9.40 Problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
34
10 FIR and IIR Filter Design 10.2 FIR filter design by window method . . . . . . . . . . . . . . 10.3 IIR fiter design by Butterworth filter design and Bi-linear Transformation . . . . . . . . . . . . . . . . . . . . . . . . .
36 36
Solved examples from book’s appendix
45
3
40
List of Scilab Codes Sec 2.4 Prb 2.66 Prb 2.67 Sec 2.6 Prb 2.65 Sec 5.14 Prb 5.14 Prb 5.43 Sec 8.1 Sec 8.2 Sec 8.3 Prb 8.36 Prb 8.36 Sec 9.2 Sec 9.2 Sec 9.2 Sec 9.3 Sec 9.3 Prb 9.40 Sec 10.2 Sec 10.2 Sec 10.2 Sec 10.2 Sec 10.3 Sec 10.3 Sec 10.3 Sec 10.3 Exa 16
Impulse.sce . . . . . . . Impulse.sce . . . . . . . Problem 2.67 . . . . . . Correlation . . . . . . . Problem 2.65 . . . . . . quantize.sce . . . . . . . Problem 5.14 . . . . . . 5.43.sce . . . . . . . . . mydft.sce . . . . . . . . divdft.sce . . . . . . . . r2fft.sce . . . . . . . . . Problem 8.36 . . . . . . Problem 8.36 . . . . . . direct1.sce . . . . . . . lattfir.sce . . . . . . . . lattimpulse.sce . . . . . lattladd.sce . . . . . . . llimpulse.sce . . . . . . Problem . . . . . . . . . Low pass FIR filter . . . High pass FIR filter . . Bandpass FIR filter . . Bandstop FIR filter . . buttordc.sce . . . . . . buttord.sce . . . . . . . butterc.sce . . . . . . . butterd.sce . . . . . . . Example 16, page 1098 4
. . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . .
2 3 5 7 8 15 17 18 20 22 24 24 25 28 29 30 32 33 34 37 38 38 39 41 42 42 43 45
Exa Exa Exa Exa
17 18 25 25
Example Example Example Example
17, 18, 25, 29,
page page page page
no. no. no. no.
1103 1104 1114 1120
5
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
45 45 46 46
List of Figures 2.1 2.2 2.3 2.4
Problem Problem Problem Problem
2.66 2.66 2.66 2.65
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
1
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
11 12 13 14
Chapter 2 Impulse Response and Correlation 2.4
Impulse response
When unit impulse is fed as input, the output of the system is called as the impulse response of the system. It is usually denoted by h(n). This function calculates the impulse response of system described by following difference equation: y(n) = a1 y(n−1)+a2 y(n−2)+a3 y(n−3)...+b0 x(n)+b1 x(n−1)+b2 x(n−2)... (2.1) This function takes following parameters as arguments: • a-array of a1 , a2 ... (a row vector) • b-array of b0 , b1 , b2 ... (a row vector) • n-size of impulse response (a scalar) it is assumed that size of a is greater than size of b
Scilab code Sec 2.4 1 given 2
// i n p u t s
diff a , b
// f u n c t i o n
to
cala
impulse
eq .
( row
vectors )
and
3
2
%n ( s c a l a r )
response
of
4
function h=i m p u l s e ( a , b ,%n)
5 6
%a=length ( a ) ;
7 8
// zero − p a d d i n g
in
order
to
make
element
wise
summation
compatible 9 10 11 12
[ b ] = [ b , zeros ( 1 ,%n−length ( b ) ) ] ; h=[ zeros ( 1 , 1 ) ] ; h ( 1 , 1 )=b ( 1 , 1 ) ; %index =2;
13 14 15 16
17 18
// c o m p u t i n g
f i r s t
%a
terms
while %index