Anda di halaman 1dari 148

Scilab Textbook Companion for

Digital Signal Processing


by R. Babu1
Created by
Mohammad Faisal Siddiqui
B.Tech (pursuing)
Electronics Engineering
Jamia Milia Islamia
College Teacher
Dr. Sajad A. Loan, JMI, New D
Cross-Checked by
Santosh Kumar, IITB
August 10, 2013

1 Funded

by a grant from the National Mission on Education through ICT,


http://spoken-tutorial.org/NMEICT-Intro. This Textbook Companion and Scilab
codes written in it can be downloaded from the Textbook Companion Project
section at the website http://scilab.in

Book Description
Title: Digital Signal Processing
Author: R. Babu
Publisher: Scitech Publications
Edition: 4
Year: 2010
ISBN: 81-8371-081-7

Scilab numbering policy used in this document and the relation to the
above 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 particular
Example of the above book)
For example, Exa 3.51 means solved example 3.51 of this book. Sec 2.3 means
a scilab code whose theory is explained in Section 2.3 of the book.

Contents
List of Scilab Codes

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 FILTERS


139
8 MULTIRATE SIGNAL PROCESSING

141

9 STATISTICAL DIGITAL SIGNAL PROCESSING

143

11 DIGITAL SIGNAL PROCESSORS

146

List of Scilab Codes


Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa

1.1
1.2
1.3.a
1.3.b
1.4.a
1.4.d
1.5.a
1.5.c
1.5.d
1.11
1.12
1.13
1.18
1.19
1.32.a
1.37
1.38
1.45
1.57.a
1.61
1.62
1.64.a
1.64.c
2.1
2.2
2.3
2.4
2.5

Continuous Time Plot and Discrete Time Plot


Continuous Time Plot and Discrete Time Plot
Evaluate the Summations . . . . . . . . . . . .
Evaluate the Summations . . . . . . . . . . . .
Check for Energy or Power Signals . . . . . . .
Check for Energy or Power Signals . . . . . . .
Determining Periodicity of Signal . . . . . . . .
Determining Periodicity of Signal . . . . . . . .
Determining Periodicity of Signal . . . . . . . .
Stability of the System . . . . . . . . . . . . .
Convolution Sum of Two Sequences . . . . . .
Convolution of Two Signals . . . . . . . . . . .
Cross Correlation of Two Sequences . . . . . .
Determination of Input Sequence . . . . . . . .
Plot Magnitude and Phase Response . . . . . .
Sketch Magnitude and Phase Response . . . . .
Plot Magnitude and Phase Response . . . . . .
Filter to Eliminate High Frequency Component
Discrete Convolution of Sequences . . . . . . .
Fourier Transform . . . . . . . . . . . . . . . .
Fourier Transform . . . . . . . . . . . . . . . .
Frequency Response of LTI System . . . . . . .
Frequency Response of LTI System . . . . . . .
z Transform and ROC of Causal Sequence . . .
z Transform and ROC of Anticausal Sequence .
z Transform of the Sequence . . . . . . . . . .
z Transform and ROC of the Signal . . . . . .
z Transform and ROC of the Signal . . . . . .
4

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

11
13
14
14
15
15
16
18
19
21
21
22
22
23
24
24
26
27
29
29
30
31
31
34
34
35
36
36

Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa

2.6
2.7
2.8.a
2.9
2.10
2.11
2.13.a
2.13.b
2.13.c
2.13.d
2.16
2.17
2.19
2.20.a
2.22
2.23
2.34
2.35.a
2.35.b
2.38
2.40
2.41.a
2.41.b
2.41.c
2.45
2.53.a
2.53.b
2.53.c
2.53.d
2.54
2.58
3.1
3.2
3.3
3.4
3.7
3.9
3.11

Stability of the System . . . . . . . . . .


z Transform of the Signal . . . . . . . . .
z Transform of the Signal . . . . . . . . .
z Transform of the Sequence . . . . . . .
z Transform Computation . . . . . . . . .
z Transform of the Sequence . . . . . . .
z Transform of Discrete Time Signals . . .
z Transform of Discrete Time Signals . . .
z Transform of Discrete Time Signals . . .
z Transform of Discrete Time Signals . . .
Impulse Response of the System . . . . .
Pole Zero Plot of the Difference Equation
Frequency Response of the System . . . .
Inverse z Transform Computation . . . .
Inverse z Transform Computation . . . .
Causal Sequence Determination . . . . . .
Impulse Response of the System . . . . .
Pole Zero Plot of the System . . . . . . .
Unit Sample Response of the System . . .
Determine Output Response . . . . . . .
Input Sequence Computation . . . . . . .
z Transform of the Signal . . . . . . . . .
z Transform of the Signal . . . . . . . . .
z Transform of the Signal . . . . . . . . .
Pole Zero Pattern of the System . . . . .
z Transform of the Sequence . . . . . . .
z Transform of the Signal . . . . . . . . .
z Transform of the Signal . . . . . . . . .
z Transform of the Signal . . . . . . . . .
z Transform of Cosine Signal . . . . . . .
Impulse Response of the System . . . . .
DFT and IDFT . . . . . . . . . . . . . .
DFT of the Sequence . . . . . . . . . . .
8 Point DFT . . . . . . . . . . . . . . . .
IDFT of the given Sequence . . . . . . . .
Plot the Sequence . . . . . . . . . . . . .
Remaining Samples . . . . . . . . . . . .
DFT Computation . . . . . . . . . . . . .
5

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

37
37
37
38
38
39
39
40
40
41
41
42
44
44
45
45
46
47
49
50
52
53
53
54
55
55
55
56
56
56
58
59
60
62
62
63
64
65

Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa

3.13
3.14
3.15
3.16
3.17
3.18
3.20
3.21
3.23.a
3.23.b
3.23.c
3.23.d
3.23.e
3.23.f
3.24
3.25
3.26
3.27.a
3.27.b
3.30
3.32
3.36
4.3
4.4
4.6
4.8
4.9
4.10
4.11
4.12
4.13
4.14
4.15
4.16.a
4.16.b
4.17
4.18
4.19

Circular Convolution . . . . . . . . . . . . .
Circular Convolution . . . . . . . . . . . . .
Determine Sequence x3 . . . . . . . . . . .
Circular Convolution . . . . . . . . . . . . .
Circular Convolution . . . . . . . . . . . . .
Output Response . . . . . . . . . . . . . . .
Output Response . . . . . . . . . . . . . . .
Linear Convolution . . . . . . . . . . . . . .
N Point DFT Computation . . . . . . . . .
N Point DFT Computation . . . . . . . . .
N Point DFT Computation . . . . . . . . .
N Point DFT Computation . . . . . . . . .
N Point DFT Computation . . . . . . . . .
N Point DFT Computation . . . . . . . . .
DFT of the Sequence . . . . . . . . . . . .
8 Point Circular Convolution . . . . . . . .
Linear Convolution using DFT . . . . . . .
Circular Convolution Computation . . . . .
Circular Convolution Computation . . . . .
Calculate value of N . . . . . . . . . . . . .
Sketch Sequence . . . . . . . . . . . . . . .
Determine IDFT . . . . . . . . . . . . . . .
Shortest Sequence N Computation . . . . .
Twiddle Factor Exponents Calculation . . .
DFT using DIT Algorithm . . . . . . . . .
DFT using DIF Algorithm . . . . . . . . .
8 Point DFT of the Sequence . . . . . . . .
4 Point DFT of the Sequence . . . . . . . .
IDFT of the Sequence using DIT Algorithm
8 Point DFT of the Sequence . . . . . . . .
8 Point DFT of the Sequence . . . . . . . .
DFT using DIT Algorithm . . . . . . . . .
DFT using DIF Algorithm . . . . . . . . .
8 Point DFT using DIT FFT . . . . . . . .
8 Point DFT using DIT FFT . . . . . . . .
IDFT using DIF Algorithm . . . . . . . . .
IDFT using DIT Algorithm . . . . . . . . .
FFT Computation of the Sequence . . . . .
6

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

65
66
67
67
68
69
70
70
71
71
72
72
72
73
73
73
74
75
75
76
76
78
79
80
80
81
81
82
82
82
83
83
84
84
85
85
86
86

Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa

4.20
4.21
4.22
4.23
4.24
5.1
5.2
5.4
5.5
5.6
5.7
5.8
5.9
5.10
5.11
5.12
5.13
5.15
5.16
5.17
5.18
5.19
5.29
6.1
6.5
6.6
6.7
6.8
6.9.a
6.9.b
6.10
6.11
6.12
6.13.a
6.13.b
6.14.a
6.14.b
6.15

8 Point DFT by Radix 2 DIT FFT . . . . . . . . . .


DFT using DIT FFT Algorithm . . . . . . . . . . .
Compute X using DIT FFT . . . . . . . . . . . . . .
DFT using DIF FFT Algorithm . . . . . . . . . . .
8 Point DFT of the Sequence . . . . . . . . . . . . .
Order of the Filter Determination . . . . . . . . . .
Order of Low Pass Butterworth Filter . . . . . . . .
Analog Butterworth Filter Design . . . . . . . . . .
Analog Butterworth Filter Design . . . . . . . . . .
Order of Chebyshev Filter . . . . . . . . . . . . . . .
Chebyshev Filter Design . . . . . . . . . . . . . . . .
Order of Type 1 Low Pass Chebyshev Filter . . . . .
Chebyshev Filter Design . . . . . . . . . . . . . . . .
HPF Filter Design with given Specifications . . . . .
Impulse Invariant Method Filter Design . . . . . . .
Impulse Invariant Method Filter Design . . . . . . .
Impulse Invariant Method Filter Design . . . . . . .
Impulse Invariant Method Filter Design . . . . . . .
Bilinear Transformation Method Filter Design . . . .
HPF Design using Bilinear Transform . . . . . . . .
Bilinear Transformation Method Filter Design . . . .
Single Pole LPF into BPF Conversion . . . . . . . .
Pole Zero IIR Filter into Lattice Ladder Structure .
Group Delay and Phase Delay . . . . . . . . . . . .
LPF Magnitude Response . . . . . . . . . . . . . . .
HPF Magnitude Response . . . . . . . . . . . . . . .
BPF Magnitude Response . . . . . . . . . . . . . . .
BRF Magnitude Response . . . . . . . . . . . . . . .
HPF Magnitude Response using Hanning Window .
HPF Magnitude Response using Hamming Window .
Hanning Window Filter Design . . . . . . . . . . . .
LPF Filter Design using Kaiser Window . . . . . . .
BPF Filter Design using Kaiser Window . . . . . . .
Digital Differentiator using Rectangular Window . .
Digital Differentiator using Hamming Window . . .
Hilbert Transformer using Rectangular Window . . .
Hilbert Transformer using Blackman Window . . . .
Filter Coefficients obtained by Sampling . . . . . . .
7

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

86
87
87
88
88
90
90
91
92
92
93
93
94
94
95
96
96
97
97
98
99
99
100
102
104
104
106
108
110
112
114
116
118
122
124
124
126
127

Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa
Exa

6.16
6.17
6.18.a
6.18.b
6.19
6.20
6.21
6.28
6.29
7.2
7.14
8.9
8.10
9.7.a
9.7.b
9.8.a
9.8.b
11.3
11.5

Coefficients of Linear phase FIR Filter . . . . . . .


BPF Filter Design using Sampling Method . . . .
Frequency Sampling Method FIR LPF Filter . . .
Frequency Sampling Method FIR LPF Filter . . .
Filter Coefficients Determination . . . . . . . . . .
Filter Coefficients using Hamming Window . . . .
LPF Filter using Rectangular Window . . . . . . .
Filter Coefficients for Direct Form Structure . . . .
Lattice Filter Coefficients Determination . . . . . .
Subtraction Computation . . . . . . . . . . . . . .
Variance of Output due to AD Conversion Process
Two Component Decomposition . . . . . . . . . .
Two Band Polyphase Decomposition . . . . . . . .
Frequency Resolution Determination . . . . . . . .
Record Length Determination . . . . . . . . . . . .
Smallest Record Length Computation . . . . . . .
Quality Factor Computation . . . . . . . . . . . .
Program for Integer Multiplication . . . . . . . . .
Function Value Calculation . . . . . . . . . . . . .

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

128
128
129
130
131
133
135
137
138
139
139
141
142
143
144
144
145
146
146

List of Figures
1.1
1.2
1.3
1.4
1.5
1.6
1.7
1.8
1.9
1.10
1.11

Continuous Time Plot and Discrete Time Plot .


Continuous Time Plot and Discrete Time Plot .
Determining Periodicity of Signal . . . . . . . .
Determining Periodicity of Signal . . . . . . . .
Determining Periodicity of Signal . . . . . . . .
Plot Magnitude and Phase Response . . . . . .
Sketch Magnitude and Phase Response . . . . .
Plot Magnitude and Phase Response . . . . . .
Filter to Eliminate High Frequency Component
Frequency Response of LTI System . . . . . . .
Frequency Response of LTI System . . . . . . .

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

12
13
17
18
20
23
25
26
28
30
32

2.1
2.2
2.3
2.4
2.5
2.6
2.7
2.8

Pole Zero Plot of the Difference Equation


Frequency Response of the System . . .
Impulse Response of the System . . . . .
Pole Zero Plot of the System . . . . . . .
Unit Sample Response of the System . .
Determine Output Response . . . . . . .
Pole Zero Pattern of the System . . . . .
Impulse Response of the System . . . . .

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

42
43
46
48
49
51
54
57

3.1
3.2
3.3

DFT of the Sequence . . . . . . . . . . . . . . . . . . . . . .


Plot the Sequence . . . . . . . . . . . . . . . . . . . . . . . .
Sketch Sequence . . . . . . . . . . . . . . . . . . . . . . . . .

60
63
77

6.1
6.2
6.3
6.4

LPF Magnitude Response


HPF Magnitude Response
BPF Magnitude Response
BRF Magnitude Response

.
.
.
.

.
.
.
.
9

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

103
105
107
109

6.5
6.6
6.7
6.8
6.9
6.10
6.11
6.12
6.13
6.14
6.15
6.16
6.17
6.18

HPF Magnitude Response using Hanning Window .


HPF Magnitude Response using Hamming Window
Hanning Window Filter Design . . . . . . . . . . .
LPF Filter Design using Kaiser Window . . . . . .
BPF Filter Design using Kaiser Window . . . . . .
Digital Differentiator using Rectangular Window . .
Digital Differentiator using Hamming Window . . .
Hilbert Transformer using Rectangular Window . .
Hilbert Transformer using Blackman Window . . .
Frequency Sampling Method FIR LPF Filter . . . .
Frequency Sampling Method FIR LPF Filter . . . .
Filter Coefficients Determination . . . . . . . . . .
Filter Coefficients using Hamming Window . . . . .
LPF Filter using Rectangular Window . . . . . . .

10

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

111
113
115
117
119
121
123
125
126
129
131
132
134
136

Chapter 1
DISCRETE TIME SIGNALS
AND LINEAR SYSTEMS

Scilab code Exa 1.1 Continuous Time Plot and Discrete Time Plot
1
2

3
4
5
6
7
8
9
10
11
12
13
14
15

// Example 1 . 1
// S k e t c h t h e c o n t i n u o u s t i m e s i g n a l x ( t ) =2 exp (2 t )
and a l s o i t s d i s c r e t e t i m e e q u i v a l e n t s i g n a l w i t h
a sampling period T = 0.2 sec
clear all ;
clc ;
close ;
t =0:0.01:2;
x1 =2* exp ( -2* t ) ;
subplot (1 ,2 ,1) ;
plot (t , x1 ) ;
xlabel ( t ) ;
ylabel ( x ( t ) ) ;
title ( CONTINUOUS TIME PLOT ) ;
n =0:0.2:2;
x2 =2* exp ( -2* n ) ;
subplot (1 ,2 ,2) ;
11

Figure 1.1: Continuous Time Plot and Discrete Time Plot

12

Figure 1.2: Continuous Time Plot and Discrete Time Plot


16
17
18
19

plot2d3 (n , x2 ) ;
xlabel ( n ) ;
ylabel ( x ( n ) ) ;
title ( DISCRETE TIME PLOT ) ;

Scilab code Exa 1.2 Continuous Time Plot and Discrete Time Plot
1
2

// Example 1 . 2
// S k e t c h t h e c o n t i n u o u s t i m e s i g n a l x=s i n ( 7 t )+s i n
( 1 0 t ) and a l s o i t s d i s c r e t e t i m e e q u i v a l e n t
s i g n a l with a sampling p e r i o d T = 0 . 2 s e c
13

3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

clear all ;
clc ;
close ;
t =0:0.01:2;
x1 = sin (7* t ) + sin (10* t ) ;
subplot (1 ,2 ,1) ;
plot (t , x1 ) ;
xlabel ( t ) ;
ylabel ( x ( t ) ) ;
title ( CONTINUOUS TIME PLOT ) ;
n =0:0.2:2;
x2 = sin (7* n ) + sin (10* n ) ;
subplot (1 ,2 ,2) ;
plot2d3 (n , x2 ) ;
xlabel ( n ) ;
ylabel ( x ( n ) ) ;
title ( DISCRETE TIME PLOT ) ;

Scilab code Exa 1.3.a Evaluate the Summations


1 // Example 1 . 3 ( a )
2 //MAXIMA SCILAB TOOLBOX REQUIRED FOR THIS PROGRAM
3 // C a l c u l a t e F o l l o w i n g Summations
4 clear all ;
5 clc ;
6 close ;
7 syms n ;
8 X = symsum ( 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 window
10 disp (X , The V a l u e o f summation comes o u t t o be : ) ;

Scilab code Exa 1.3.b Evaluate the Summations


14

1 // Example 1 . 3 ( b )
2 //MAXIMA SCILAB TOOLBOX REQUIRED FOR THIS PROGRAM
3 // C a l c u l a t e F o l l o w i n g Summations
4 clear all ;
5 clc ;
6 close ;
7 syms n ;
8 X = symsum ( %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 window
10 disp (X , The V a l u e o f summation comes o u t t o be : ) ;

Scilab code Exa 1.4.a Check for Energy or Power Signals


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

// Example 1 . 4 ( a )
//MAXIMA SCILAB TOOLBOX REQUIRED FOR THIS PROGRAM
// Find Energy and Power o f Given S i g n a l s
clear all ;
clc ;
close ;
syms n N ;
x =(1/3) ^ n ;
E = symsum ( x ^2 , n ,0 , %inf ) ;
// D i s p l a y t h e r e s u l t i n command window
disp (E , Energy : ) ;
p =(1/(2* N +1) ) * symsum ( x ^2 , n ,0 , N ) ;
P = limit (p ,N , %inf ) ;
disp (P , Power : ) ;
// The Energy i s F i n i t e and Power i s 0 . T h e r e f o r e t h e
g i v e n s i g n a l i s an Energy S i g n a l

Scilab code Exa 1.4.d Check for Energy or Power Signals


1

// Example 1 . 4 ( d )
15

2
3
4
5
6
7
8
9
10
11
12
13
14
15

//MAXIMA SCILAB TOOLBOX REQUIRED FOR THIS PROGRAM


// Find Energy and Power o f Given S i g n a l s
clear all ;
clc ;
close ;
syms n N ;
x = %e ^(2* n ) ;
E = symsum ( x ^2 , n ,0 , %inf ) ;
// D i s p l a y t h e r e s u l t i n command window
disp (E , Energy : ) ;
p =(1/(2* N +1) ) * symsum ( x ^2 , n ,0 , N ) ;
P = limit (p ,N , %inf ) ;
disp (P , Power : ) ;
// The Energy andPower 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 e n s i g n a l i s an n e i t h e r Energy S i g n a l n o r
Power S i g n a l

Scilab code Exa 1.5.a Determining Periodicity of Signal


1
2
3
4
5
6
7
8
9
10
11
12
13

// Example 1 . 5 ( a )
//To D e t e r m i n e Whether Given S i g n a l i s P e r i o d i c o r
not
clear all ;
clc ;
close ;
t =0:0.01:2;
x1 = exp ( %i *6* %pi * t ) ;
subplot (1 ,2 ,1) ;
plot (t , x1 ) ;
xlabel ( t ) ;
ylabel ( x ( t ) ) ;
title ( CONTINUOUS TIME PLOT ) ;
n =0:0.2:2;
16

Figure 1.3: Determining Periodicity of Signal

17

Figure 1.4: Determining Periodicity of Signal


14 x2 = exp ( %i *6* %pi * n ) ;
15 subplot (1 ,2 ,2) ;
16 plot2d3 (n , x2 ) ;
17 xlabel ( n ) ;
18 ylabel ( x ( n ) ) ;
19 title ( DISCRETE TIME PLOT ) ;
20 // Hence Given S i g n a l i s P e r i o d i c w i t h N=1

Scilab code Exa 1.5.c Determining Periodicity of Signal


1

// Example 1 . 5 ( c )
18

2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

//To D e t e r m i n e Whether Given S i g n a l i s P e r i o d i c o r


not
clear all ;
clc ;
close ;
t =0:0.01:10;
x1 = cos (2* %pi * t /3) ;
subplot (1 ,2 ,1) ;
plot (t , x1 ) ;
xlabel ( t ) ;
ylabel ( x ( t ) ) ;
title ( CONTINUOUS TIME PLOT ) ;
n =0:0.2:10;
x2 = cos (2* %pi * n /3) ;
subplot (1 ,2 ,2) ;
plot2d3 (n , x2 ) ;
xlabel ( n ) ;
ylabel ( x ( n ) ) ;
title ( DISCRETE TIME PLOT ) ;
// Hence Given S i g n a l i s P e r i o d i c w i t h N=3

Scilab code Exa 1.5.d Determining Periodicity of Signal


1
2
3
4
5
6
7
8
9

// Example 1 . 5 ( d )
//To D e t e r m i n e Whether Given S i g n a l i s P e r i o d i c o r
not
clear all ;
clc ;
close ;
t =0:0.01:50;
x1 = cos ( %pi * t /3) + cos (3* %pi * t /4) ;
subplot (1 ,2 ,1) ;
plot (t , x1 ) ;
19

Figure 1.5: Determining Periodicity of Signal

20

10 xlabel ( t ) ;
11 ylabel ( x ( t ) ) ;
12 title ( CONTINUOUS TIME PLOT ) ;
13 n =0:0.2:50;
14 x2 = cos ( %pi * n /3) + cos (3* %pi * n /4) ;
15 subplot (1 ,2 ,2) ;
16 plot2d3 (n , x2 ) ;
17 xlabel ( n ) ;
18 ylabel ( x ( n ) ) ;
19 title ( DISCRETE TIME PLOT ) ;
20 // Hence Given S i g n a l i s P e r i o d i c w i t h N=24

Scilab code Exa 1.11 Stability of the System


1 // Example 1 . 1 1
2 //MAXIMA SCILAB TOOLBOX REQUIRED FOR THIS PROGRAM
3 // T e s t i n g S t a b i l i t y o f Given System
4 clear all ;
5 clc ;
6 close ;
7 syms n ;
8 x =(1/2) ^ n
9 X = symsum (x , n ,0 , %inf ) ;
10 // D i s p l a y t h e r e s u l t i n command window
11 disp (X , Summation 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
2
3

// Example 1 . 1 2
// 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 e s
// x ( n ) =[3 2 1 2 ] , h ( n ) =[1 2 1 2 ] ;
21

4
5
6
7
8
9
10

clear all ;
clc ;
close ;
x =[3 2 1 2];
h =[1 2 1 2];
y = convol (x , h ) ;
disp ( y ) ;

Scilab code Exa 1.13 Convolution of Two Signals


1
2
3
4
5
6
7
8
9
10

// Example 1 . 1 3
// 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 e s
// x ( n ) =[1 2 1 1 ] , h ( n ) =[1 1 1 1 ] ;
clear all ;
clc ;
close ;
x =[1 2 1 1];
h =[1 -1 1 -1];
y = convol (x , h ) ;
disp ( round ( y ) ) ;

Scilab code Exa 1.18 Cross Correlation of Two Sequences


1
2
3
4
5
6
7
8
9

// Example 1 . 1 8
// Program t o Compute C r o s s c o r r e l a t i o n
sequences
// x ( n ) =[1 2 1 1 ] , h ( n ) =[1 1 2 1 ] ;
clear all ;
clc ;
close ;
x =[1 2 1 1];
h =[1 1 2 1];
h1 =[1 2 1 1];
22

of given

Figure 1.6: Plot Magnitude and Phase Response


10 y = convol (x , h1 ) ;
11 disp ( round ( y ) ) ;

Scilab code Exa 1.19 Determination of Input Sequence


1 // Example 1 . 1 9
2 //To f i n d i n p u t x ( n )
3 // h ( n ) =[1 2 1 ] , y ( n ) =[1 5 10 11 8 4 1 ]
4 clear all ;
5 clc ;
6 close ;
7 z = %z ;
8 a = z ^6+5*( z ^(5) ) +10*( z ^(4) ) +11*( 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

Scilab code Exa 1.32.a Plot Magnitude and Phase Response


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

// Example 1 . 3 2
// Program t o P l o t Magnitude and Phase R e s p o n c e
clear all ;
clc ;
close ;
w = - %pi :0.01: %pi ;
H =1+2* cos ( w ) +2* cos (2* w ) ;
// c a l u c u l a t i o n o f Phase and Magnitude o f H
[ phase_H , m ]= phasemag ( H ) ;
Hm = abs ( H ) ;
a = gca () ;
subplot (2 ,1 ,1) ;
a . y_location = o r i g i n ;
plot2d ( w / %pi , Hm ) ;
xlabel ( F r e q u e n c y i n R a d i a n s )
ylabel ( a b s (Hm) ) ;
title ( MAGNITUDE RESPONSE ) ;
subplot (2 ,1 ,2) ;
a = gca () ;
a . x_location = o r i g i n ;
a . y_location = o r i g i n ;
plot2d ( w /(2* %pi ) , phase_H ) ;
xlabel ( F r e q u e n c y i n R a d i a n s ) ;
ylabel ( <(H) ) ;
title ( PHASE RESPONSE ) ;

Scilab code Exa 1.37 Sketch Magnitude and Phase Response

24

Figure 1.7: Sketch Magnitude and Phase Response


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

// Example 1 . 3 7
// Program t o P l o t Magnitude and Phase R e s p o n c e
// y ( n ) =1/2[ x ( n )+x ( n2) ]
clear all ;
clc ;
close ;
w =0:0.01: %pi ;
H =(1+ cos (2* w ) - %i * sin (2* w ) ) /2;
// c a l u c u l a t i o n o f Phase and Magnitude o f H
[ phase_H , m ]= phasemag ( H ) ;
Hm = abs ( H ) ;
a = gca () ;
subplot (2 ,1 ,1) ;
a . y_location = o r i g i n ;
plot2d ( w / %pi , Hm ) ;
xlabel ( F r e q u e n c y i n R a d i a n s )
ylabel ( a b s (Hm) ) ;
title ( MAGNITUDE RESPONSE ) ;
subplot (2 ,1 ,2) ;
a = gca () ;
a . x_location = o r i g i n ;
a . y_location = o r i g i n ;
plot2d ( w /(2* %pi ) , phase_H ) ;
25

Figure 1.8: Plot Magnitude and Phase Response


24
25
26

xlabel ( F r e q u e n c y i n R a d i a n s ) ;
ylabel ( <(H) ) ;
title ( PHASE RESPONSE ) ;

Scilab code Exa 1.38 Plot Magnitude and Phase Response


1
2
3
4
5
6
7
8
9
10
11
12
13

// Example 1 . 3 8
// Program t o P l o t Magnitude and Phase R e s p o n c e
// 0 . 5 d e l t a ( n )+d e l t a ( n1) +0.5 d e l t a ( n2)
clear all ;
clc ;
close ;
w = - %pi :0.01: %pi ;
H =0.5+ exp ( - %i * w ) +0.5* exp ( - %i * w ) ;
// c a l u c u l a t i o n o f Phase and Magnitude o f H
[ phase_H , m ]= phasemag ( H ) ;
Hm = abs ( H ) ;
a = gca () ;
subplot (2 ,1 ,1) ;
26

14
15
16
17
18
19
20
21
22
23
24
25
26

a . y_location = o r i g i n ;
plot2d ( w / %pi , Hm ) ;
xlabel ( F r e q u e n c y i n R a d i a n s )
ylabel ( a b s (Hm) ) ;
title ( MAGNITUDE RESPONSE ) ;
subplot (2 ,1 ,2) ;
a = gca () ;
a . x_location = o r i g i n ;
a . y_location = o r i g i n ;
plot2d ( w /(2* %pi ) , phase_H ) ;
xlabel ( F r e q u e n c y i n R a d i a n s ) ;
ylabel ( <(H) ) ;
title ( PHASE RESPONSE ) ;

Scilab code Exa 1.45 Filter to Eliminate High Frequency Component


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

// Example 1 . 4 5
//
clear all ;
clc ;
close ;
t =0:0.01:10;
x =2* cos (5* t ) + cos (300* t ) ;
x1 =2* cos (5* t ) ;
b =[0.05 0.05];
a =[1 -0.9];
y = filter (b ,a , x ) ;
subplot (2 ,1 ,1) ;
plot (t , x ) ;
xlabel ( Time i n S e c ) ;
ylabel ( A m p l i t u d e ) ;
subplot (2 ,1 ,2) ;
plot (t , y ) ;
27

Figure 1.9: Filter to Eliminate High Frequency Component

28

18
19
20

subplot (2 ,1 ,2) ;
plot (t , x1 , : ) ;
title ( x : SIGNAL WITHOUT NOISE
;
21 xlabel ( Time i n S e c ) ;
22 ylabel ( A m p l i t u d e ) ;

y : SIGNAL WITH NOISE )

Scilab code Exa 1.57.a Discrete Convolution of Sequences


1
2
3
4
5
6
7
8
9
10

// Example 1 . 5 7 ( a )
// Program t o Compute 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 n
sequences
// x ( n ) =[1 2 1 1 ] , h ( n ) =[1 0 1 1 ] ;
clear all ;
clc ;
close ;
x =[1 2 -1 1];
h =[1 0 1 1];
y = convol (x , h ) ;
disp ( round ( y ) ) ;

Scilab code Exa 1.61 Fourier Transform


1 // Example 1 . 6 1
2 //MAXIMA SCILAB TOOLBOX REQUIRED FOR THIS PROGRAM
3 // F o u r i e r t r a n s f o r m o f ( 3 ) n u ( n )
4 clear all ;
5 clc ;
6 close ;
7 syms n ;
8 x =(3) ^ n ;
9 X = symsum (x , n ,0 , %inf )
10 // D i s p l a y t h e r e s u l t i n command window

29

Figure 1.10: Frequency Response of LTI System


11

disp (X , The F o u r i e r T r a n s f o r m d o e s n o t e x i t a s x ( n )
i s n o t a b s o l u t e l y summable and a p p r o a c h e s
i n f i n i t y i . e . );

Scilab code Exa 1.62 Fourier Transform


1 // Example 1 . 6 2
2 //MAXIMA SCILAB TOOLBOX REQUIRED FOR THIS PROGRAM
3 // F o u r i e r t r a n s f o r m o f ( 0 . 8 ) | n | u ( n )
4 clear all ;
5 clc ;
6 close ;
7 syms w n ;
8 X = symsum ((0.8) ^ n * %e ^( %i * w * n ) ,n ,1 , %inf ) + symsum
9
10

((0.8) ^ n * %e ^( - %i * w * n ) ,n ,0 , %inf )
// D i s p l a y t h e r e s u l t i n command window
disp (X , The F o u r i e r T r a n s f o r m comes o u t t o be : ) ;

30

Scilab code Exa 1.64.a Frequency Response of LTI System


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

// Example 1 . 6 4 ( a )
// Program t o C a l c u l a t e P l o t Magnitude and Phase
Responce
clear all ;
clc ;
close ;
w =0:0.01: %pi ;
H =1/(1 -0.5* %e ^( - %i * w ) ) ;
// c a l u c u l a t i o n o f Phase and Magnitude o f H
[ phase_H , m ]= phasemag ( H ) ;
Hm = abs ( H ) ;
a = gca () ;
subplot (2 ,1 ,1) ;
a . y_location = o r i g i n ;
plot2d ( w / %pi , Hm ) ;
xlabel ( F r e q u e n c y i n R a d i a n s )
ylabel ( a b s (Hm) ) ;
title ( MAGNITUDE RESPONSE ) ;
subplot (2 ,1 ,2) ;
a = gca () ;
a . x_location = o r i g i n ;
a . y_location = o r i g i n ;
plot2d ( w /(2* %pi ) , phase_H ) ;
xlabel ( F r e q u e n c y i n R a d i a n s ) ;
ylabel ( <(H) ) ;
title ( PHASE RESPONSE ) ;

Scilab code Exa 1.64.c Frequency Response of LTI System


31

Figure 1.11: Frequency Response of LTI System

32

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

// Example 1 . 6 4 ( c )
// Program t o C a l c u l a t e P l o t Magnitude and Phase
Responce
clear all ;
clc ;
close ;
w =0:0.01: %pi ;
H =1/(1 -0.9* %i * %e ^( - %i * w ) ) ;
// c a l u c u l a t i o n o f Phase and Magnitude o f H
[ phase_H , m ]= phasemag ( H ) ;
Hm = abs ( H ) ;
a = gca () ;
subplot (2 ,1 ,1) ;
a . y_location = o r i g i n ;
plot2d ( w / %pi , Hm ) ;
xlabel ( F r e q u e n c y i n R a d i a n s )
ylabel ( a b s (Hm) ) ;
title ( MAGNITUDE RESPONSE ) ;
subplot (2 ,1 ,2) ;
a = gca () ;
a . x_location = o r i g i n ;
a . y_location = o r i g i n ;
plot2d ( w /(2* %pi ) , phase_H ) ;
xlabel ( F r e q u e n c y i n R a d i a n s ) ;
ylabel ( <(H) ) ;
title ( PHASE RESPONSE ) ;

33

Chapter 2
THE Z TRANSFORM

Scilab code Exa 2.1 z Transform and ROC of Causal Sequence


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

// Example 2 . 1
//Z t r a n s f o r m o f [ 1 0 3 1 2 ]
clear all ;
clc ;
close ;
function [ za ]= ztransfer ( sequence , n )
z = poly (0 , z , r )
za = sequence *(1/ z ) ^n
endfunction
x1 =[1 0 3 -1 2];
n =0: length ( x1 ) -1;
zz = ztransfer ( x1 , n ) ;
// D i s p l a y t h e r e s u l t i n command window
disp ( zz , Zt r a n s f o r m o f s e q u e n c e i s : ) ;
disp ( ROC i s t h e e n t i r e p l a n e e x c e p t z = 0 ) ;

Scilab code Exa 2.2 z Transform and ROC of Anticausal Sequence

34

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

// Example 2 . 2
//Z t r a n s f o r m o f [ 3 2 1 0 1 ]
clear all ;
clc ;
close ;
function [ za ]= ztransfer ( sequence , n )
z = poly (0 , z , r )
za = sequence *(1/ z ) ^n
endfunction
x1 =[ -3 -2 -1 0 1];
n = -( length ( x1 ) -1) :0;
zz = ztransfer ( x1 , n ) ;
// D i s p l a y t h e r e s u l t i n command window
disp ( zz , Zt r a n s f o r m o f s e q u e n c e i s : ) ;
disp ( ROC i s t h e e n t i r e p l a n e e x c e p t z = % i n f ) ;

Scilab code Exa 2.3 z Transform of the Sequence


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

// Example 2 . 3
//Z t r a n s f o r m o f [ 2 1 3 2 1 0 2 3 1]
clear all ;
clc ;
close ;
function [ za ]= ztransfer ( sequence , n )
z = poly (0 , z , r )
za = sequence *(1/ z ) ^n
endfunction
x1 =[2 -1 3 2 1 0 2 3 -1];
n = -4:4;
zz = ztransfer ( x1 , n ) ;
// D i s p l a y t h e r e s u l t i n command window
disp ( zz , Zt r a n s f o r m o f s e q u e n c e i s : ) ;
disp ( ROC i s t h e e n t i r e p l a n e e x c e p t z = 0 and z =
%inf );

35

Scilab code Exa 2.4 z Transform and ROC of the Signal


1 // Example 2 . 4
2 //MAXIMA SCILAB TOOLBOX REQUIRED FOR THIS PROGRAM
3 //Z t r a n s f o r m o f a n u ( n )
4 clear all ;
5 clc ;
6 close ;
7 syms a n z ;
8 x =a^n
9 X = symsum ( x *( z ^( - n ) ) ,n ,0 , %inf ) ;
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 a n s f o r m o f a n u ( n ) w i t h i s : ) ;
12 disp ( ROC i s t h e R e g i o n mod ( z ) > a )

Scilab code Exa 2.5 z Transform and ROC of the Signal


1 // Example 2 . 5
2 //MAXIMA SCILAB TOOLBOX REQUIRED FOR THIS PROGRAM
3 //Z t r a n s f o r m o f b n u(n 1)
4 clear all ;
5 clc ;
6 close ;
7 syms b n z ;
8 x =b^n
9 X = symsum ( x *( z ^( - n ) ) ,n ,0 , %inf ) ;
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 a n s f o r m o f b n u ( n ) w i t h i s : ) ;
12 disp ( ROC i s t h e R e g i o n mod ( z ) < b )

36

Scilab code Exa 2.6 Stability of the System


1 // Example 2 . 6
2 //MAXIMA SCILAB TOOLBOX REQUIRED FOR THIS PROGRAM
3 //Z t r a n s f o r m o f 2 n u ( n )
4 clear all ;
5 clc ;
6 close ;
7 syms n z ;
8 x =(2) ^ n
9 X = symsum ( x *( z ^( - n ) ) ,n ,0 , %inf ) ;
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 a n s f o r m o f 2 n u ( n ) i s : ) ;
12 disp ( ROC i s t h e R e g i o n mod ( z ) > 2 ) ;

Scilab code Exa 2.7 z Transform of the Signal


1
2
3
4
5
6
7
8
9
10
11
12
13
14

// Example 2 . 7
//MAXIMA SCILAB TOOLBOX REQUIRED FOR THIS PROGRAM
//Z t r a n s f o r m o f [ 3 ( 3 n ) 4(2) n ] u ( n )
clear all ;
clc ;
close ;
syms n z ;
x1 =(3) ^( n ) ;
X1 = symsum (3* x1 *( z ^( - n ) ) ,n ,0 , %inf ) ;
x2 =(4) ^( n ) ;
X2 = symsum (4* x2 *( z ^( - n ) ) ,n ,0 , %inf ) ;
X = ( X1 - X2 ) ;
// D i s p l a y t h e r e s u l t i n command window
disp (X , Zt r a n s f o r m o f [ 3 ( 3 n ) 4(2) n ] u ( n )
i s : );

Scilab code Exa 2.8.a z Transform of the Signal


37

1
2
3
4
5
6
7
8
9
10
11

// Example 2 . 8 ( a )
//MAXIMA SCILAB TOOLBOX REQUIRED FOR THIS PROGRAM
//Z t r a n s f o r m o f c o s (Won )
clc ;
syms Wo n z ;
x1 = exp ( sqrt ( -1) * Wo * n ) ;
X1 = symsum ( x1 *( z ^ - n ) ,n ,0 , %inf ) ;
x2 = exp ( - sqrt ( -1) * Wo * n ) ;
X2 = symsum ( x2 *( z ^ - n ) ,n ,0 , %inf ) ;
X =( X1 + X2 ) /2;
disp (X , X( z )= ) ;

Scilab code Exa 2.9 z Transform of the Sequence


1 // Example 2 . 9
2 //MAXIMA SCILAB TOOLBOX REQUIRED FOR THIS PROGRAM
3 //Z t r a n s f o r m o f ( 1 / 3 ) n u ( n 1)
4 clear all ;
5 clc ;
6 close ;
7 syms n z ;
8 x =(1/3) ^ n ;
9 X = (1/ z ) * symsum ( x *( z ^( - n ) ) ,n ,0 , %inf ) ;
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 a n s f o r m o f ( 1 / 3 ) n u ( n 1) i s : ) ;

Scilab code Exa 2.10 z Transform Computation


1 // Example 2 . 1 0
2 //MAXIMA SCILAB TOOLBOX REQUIRED FOR THIS PROGRAM
3 //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

6
7
8
9
10
11

x1 =( r ^ n ) * exp ( sqrt ( -1) * Wo * n ) ;


X1 = symsum ( x1 *( z ^ - n ) ,n ,0 , %inf ) ;
x2 =( r ^ n ) * exp ( - sqrt ( -1) * Wo * n ) ;
X2 = symsum ( x2 *( z ^ - n ) ,n ,0 , %inf ) ;
X =( X1 + X2 ) /2;
disp (X , X( z )= ) ;

Scilab code Exa 2.11 z Transform of the Sequence


1
2
3
4
5
6
7
8
9
10
11
12

// Example 2 . 1 1
//MAXIMA SCILAB TOOLBOX
//Z t r a n s f o r m o f n . a n
clear all ;
clc ;
close ;
syms a n z ;
x =( a ) ^ n ;
X = symsum ( x *( z ^( - n ) ) ,n
Y = diff (X , z ) ;
// D i s p l a y t h e r e s u l t i n
disp (Y , Zt r a n s f o r m o f

REQUIRED FOR THIS PROGRAM


u(n)

,0 , %inf )
command window
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 PROGRAM
3 //Z t r a n s f o r m o f ( 1/5) n u ( n ) + 5 ( 1 / 2 ) (n ) u(n 1)
4 clear all ;
5 clc ;
6 close ;
7 syms n z ;
8 x1 =( -1/5) ^ n ;
9 X1 = symsum ( x1 *( z ^( - n ) ) ,n ,0 , %inf ) ;

39

10 x2 =(1/2) ^( - n ) ;
11 X2 = symsum (5* x2 *( z ^( - n ) ) ,n ,0 , %inf ) ;
12 X = ( X1 - X2 ) ;
13 // D i s p l a y t h e r e s u l t i n command window
14 disp (X , Zt r a n s f o r m o f [ 3 ( 3 n ) 4(2) n ] u ( n )
15 disp ( ROC i s t h e R e g i o n 1/5 < mod ( z ) < 2 ) ;

i s : );

Scilab code Exa 2.13.b z Transform of Discrete Time Signals


1
2
3
4
5
6
7
8
9
10
11
12
13

// Example 2 . 1 3 ( b )
//MAXIMA SCILAB TOOLBOX REQUIRED FOR THIS PROGRAM
//Z t r a n s f o r m
clc ;
syms n z k ;
x1 =1;
X1 = symsum ( x1 * z ^( - n ) ,n ,0 ,0) ;
x2 =1;
X2 = symsum ( x2 * z ^( - n ) ,n ,1 ,1) ;
x3 =1;
X3 = symsum ( x3 * z ^( - n ) ,n ,2 ,2) ;
X =0.5* X1 + X2 -1/3* X3 ;
disp (X , X( z )= ) ;

Scilab code Exa 2.13.c z Transform of Discrete Time Signals


1 // Example 2 . 1 3 ( c )
2 //MAXIMA SCILAB TOOLBOX REQUIRED FOR THIS PROGRAM
3 //Z t r a n s f o r m o f u ( n 2)
4 clear all ;
5 clc ;
6 close ;
7 syms n z ;
8 x =1;

40

9 X = (1/( z ^2) ) * symsum ( x *( z ^( - n ) ) ,n ,0 , %inf ) ;


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 a n s f o r m o f u ( n 2) i s : ) ;

Scilab code Exa 2.13.d z Transform of Discrete Time Signals


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

// Example 2 . 1 3 ( d )
//MAXIMA SCILAB TOOLBOX REQUIRED FOR THIS PROGRAM
//Z t r a n s f o r m o f ( n + 0 . 5 ) ( ( 1 / 3 ) n ) u ( n )
clear all ;
clc ;
close ;
syms n z ;
x1 =(1/3) ^ n ;
X11 = symsum ( x1 *( z ^( - n ) ) ,n ,0 , %inf )
X1 = diff ( X11 , z ) ;
x2 =(1/3) ^( n ) ;
X2 = symsum (0.5* x2 *( z ^( - n ) ) ,n ,0 , %inf ) ;
X = ( X1 + X2 ) ;
// D i s p l a y t h e r e s u l t i n command window
disp (X , Zt r a n s f o 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
2
3
4
5
6
7
8
9

// Example 2 . 1 6
//To f i n d i n p u t h ( n )
// a =[1 2 4 1 ] , b = [ 1 ]
clear all ;
clc ;
close ;
z = %z ;
a = z ^3+2*( z ^(2) ) -4*( z ) +1;
b = z ^3;
41

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 // Example 2 . 1 7
2 //To draw t h e p o l e z e r o p l o t
3 clear all ;
4 clc ;
5 close ;
6 z = %z
7 H1Z =(( z ) *( z -1) ) /(( z -0.25) *( z -0.5) ) ;
8 xset ( window ,1) ;
9 plzr ( H1Z ) ;

42

Figure 2.2: Frequency Response of the System

43

Scilab code Exa 2.19 Frequency Response of the System


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

// Example 2 . 1 9
// Program t o P l o t Magnitude and Phase R e s p o n c e
clear all ;
clc ;
close ;
w = - %pi :0.01: %pi ;
H =1/(1 -0.5*( cos ( w ) - %i * sin ( w ) ) ) ;
// c a l u c u l a t i o n o f Phase and Magnitude o f H
[ phase_H , m ]= phasemag ( H ) ;
Hm = abs ( H ) ;
a = gca () ;
subplot (2 ,1 ,1) ;
a . y_location = o r i g i n ;
plot2d ( w / %pi , Hm ) ;
xlabel ( F r e q u e n c y i n R a d i a n s ) ;
ylabel ( a b s (Hm) ) ;
title ( MAGNITUDE RESPONSE ) ;
subplot (2 ,1 ,2) ;
a = gca () ;
a . x_location = o r i g i n ;
a . y_location = o r i g i n ;
plot2d ( w /(2* %pi ) , phase_H ) ;
xlabel ( F r e q u e n c y i n R a d i a n s ) ;
ylabel ( <(H) ) ;
title ( PHASE RESPONSE ) ;

Scilab code Exa 2.20.a Inverse z Transform Computation


1 // Example 2 . 1 0 ( a )
2 //To f i n d i n p u t h ( n )
3 //X( z ) =( z + 0 . 2 ) / ( ( z + 0 . 5 ) ( z 1) ;
4 clear all ;
5 clc ;

44

6
7
8
9
10
11

close ;
z = %z ;
a =( z +0.5) *( z -1) ;
b = z +0.2;
h = ldiv (b ,a ,4) ;
disp (h , h ( n )= ) ;

Scilab code Exa 2.22 Inverse z Transform Computation


1
2
3
4
5
6
7
8
9
10
11

// Example 2 . 2 2
//To f i n d i n p u t x ( n )
//X( z ) =1/(2 z ( 2) +2 z ( 1) +1) ;
clear all ;
clc ;
close ;
z = %z ;
a =(2+2* z + z ^2) ;
b = z ^2;
h = ldiv (b ,a ,6) ;
disp (h , F i r s t s i x v a l u e s o f h ( n )= ) ;

Scilab code Exa 2.23 Causal Sequence Determination


1
2
3
4
5
6
7
8
9
10

// Example 2 . 2 3
//To f i n d i n p u t x ( n )
//X( z ) =1/(12 z ( 1) ) (1 z ( 1) ) 2 ;
clear all ;
clc ;
close ;
z = %z ;
a =( z -2) *( z -1) ^2;
b = z ^3;
h = ldiv (b ,a ,6) ;
45

Figure 2.3: Impulse Response of the System


11

disp (h , F i r s t s i x v a l u e s o f h ( n )= ) ;

Scilab code Exa 2.34 Impulse Response of the System


1
2
3
4
5
6

// Example 2 . 3 4
//To p l o t t h e i m p u l s e r e s p o n c e o f t h e s y s t e m
a n a l y i c a l l y and u s i n g s c i l a b
clear all ;
clc ;
close ;
n =0:1:50;
46

7 x =[1 , zeros (1 ,50) ];


8 b =[1 2];
9 a =[1 -3 -4];
10 yanaly =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 n
11 ymat = filter (b ,a , x ) ;
12 subplot (3 ,1 ,1) ;
13 plot2d3 (n , x ) ;
14 xlabel ( n ) ;
15 ylabel ( x ( n ) ) ;
16 title ( INPUT SEQUENCE (IMPULSE FUNCTION) ) ;
17 subplot (3 ,1 ,2) ;
18 plot2d3 (n , yanaly ) ;
19 xlabel ( n ) ;
20 ylabel ( y ( n ) ) ;
21 title ( OUTPUT SEQUENCE y a n a l y ) ;
22 subplot (3 ,1 ,3) ;
23 plot2d3 (n , ymat ) ;
24 xlabel ( n ) ;
25 ylabel ( y ( n ) ) ;
26 title ( OUTPUT SEQUENCE ymat ) ;
27 // As t h e A n a l t i c a l P l o t m a t c h e s t h e S c i l a b P l o t

hence i t

i s the Responce o f the system

Scilab code Exa 2.35.a Pole Zero Plot of the System


1 // Example 2 . 3 5 ( a )
2 //To draw t h e p o l e z e r o
3 clear all ;
4 clc ;
5 close ;
6 z = %z
7 H1Z =( z ) /( z ^2 -z -1) ;
8 xset ( window ,1) ;

plot

47

Figure 2.4: Pole Zero Plot of the System

48

Figure 2.5: Unit Sample Response of the System


9

plzr ( H1Z ) ;

Scilab code Exa 2.35.b Unit Sample Response of the System


1
2
3
4
5
6

// Example 2 . 3 5 ( b )
//To p l o t t h e r e s p o n c e o f t h e s y s t e m a n a l y i c a l l y and
using s c i l a b
clear all ;
clc ;
close ;
n =0:1:20;
49

7 x = ones (1 , length ( n ) ) ;
8 b =[0 1];
9 a =[1 -1 -1];
10 yanaly =0.447*(1.618) .^ n -0.447*( -0.618) .^ n ; //
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

Analytical Solution
[ ymat , zf ]= filter (b , a , x ) ;
subplot (3 ,1 ,1) ;
plot2d3 (n , x ) ;
xlabel ( n ) ;
ylabel ( x ( n ) ) ;
title ( INPUT SEQUENCE (STEP FUNCTION) ) ;
subplot (3 ,1 ,2) ;
plot2d3 (n , yanaly ) ;
xlabel ( n ) ;
ylabel ( y ( n ) ) ;
title ( OUTPUT SEQUENCE y a n a l y ) ;
subplot (3 ,1 ,3) ;
plot2d3 (n , ymat , zf ) ;
xlabel ( n ) ;
ylabel ( y ( n ) ) ;
title ( OUTPUT SEQUENCE ymat ) ;
// As t h e A n a l t i c a l P l o t m a t c h e s t h e S c i l a b P l o t
hence i t i s the Responce o f the system

Scilab code Exa 2.38 Determine Output Response


1
2
3
4
5
6

// Example 2 . 3 8
//To p l o t t h e r e s p o n c e o f t h e s y s t e m a n a l y i c a l l y and
using s c i l a b
clear all ;
clc ;
close ;
n =0:1:20;
50

Figure 2.6: Determine Output Response

51

7 x=n;
8 b =[0 1 1];
9 a =[1 -0.7 0.12];
10 yanaly =38.89*(0.4) .^ n -26.53*(0.3) .^ n -12.36+4.76* n ; //
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

Analytical Solution
ymat = filter (b ,a , x ) ;
subplot (3 ,1 ,1) ;
plot2d3 (n , x ) ;
xlabel ( n ) ;
ylabel ( x ( n ) ) ;
title ( INPUT SEQUENCE (RAMP FUNCTION) ) ;
subplot (3 ,1 ,2) ;
plot2d3 (n , yanaly ) ;
xlabel ( n ) ;
ylabel ( y ( n ) ) ;
title ( OUTPUT SEQUENCE y a n a l y ) ;
subplot (3 ,1 ,3) ;
plot2d3 (n , ymat ) ;
xlabel ( n ) ;
ylabel ( y ( n ) ) ;
title ( OUTPUT SEQUENCE ymat ) ;
// As t h e A n a l t i c a l P l o t m a t c h e s t h e S c i l a b P l o t
hence i t i s the Responce o f the system

Scilab code Exa 2.40 Input Sequence Computation


1 // Example 2 . 4 0
2 //To f i n d i n p u t x ( n )
3 // h ( n ) =1 2 3 2 , y ( n ) =[1 3 7 10 10 7 2 ]
4 clear all ;
5 clc ;
6 close ;
7 z = %z ;
8 a = z ^6+3*( z ^(5) ) +7*( z ^(4) ) +10*( z ^(3) ) +10*( z ^(2) ) +7*( z

^(1) ) +2;
52

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
2
3
4
5
6
7
8
9
10
11
12

// Example 2 . 4 1 ( a )
//MAXIMA SCILAB TOOLBOX REQUIRED FOR THIS PROGRAM
//Z t r a n s f o r m o f n . ( 1 ) n u ( n )
clear all ;
clc ;
close ;
syms a n z ;
x =( -1) ^ n ;
X = symsum ( x *( z ^( - n ) ) ,n ,0 , %inf )
Y = diff (X , z ) ;
// D i s p l a y t h e r e s u l t i n command window
disp (Y , Zt r a n s 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
2
3
4
5
6
7
8
9
10
11
12

// Example 2 . 4 1 ( b )
//MAXIMA SCILAB TOOLBOX REQUIRED FOR THIS PROGRAM
//Z t r a n s f o r m o f n 2 u ( n )
clear all ;
clc ;
close ;
syms n z ;
x =1;
X = symsum ( x *( z ^( - n ) ) ,n ,0 , %inf )
Y = diff ( diff (X , z ) ,z ) ;
// D i s p l a y t h e r e s u l t i n command window
disp (Y , Zt r a n s f o r m o f n 2 u ( n )
i s : );
53

Figure 2.7: Pole Zero Pattern of the System

Scilab code Exa 2.41.c z Transform of the Signal


1
2
3
4
5
6
7
8
9
10
11
12

// Example 2 . 4 1 ( c )
//MAXIMA SCILAB TOOLBOX REQUIRED FOR THIS PROGRAM
//Z t r a n s f o r m o f ( 1) n . c o s ( %pi /3 n )
clc ;
syms n z ;
Wo = %pi /3;
x1 = exp ( sqrt ( -1) * Wo * n ) ;
X1 =( -1) ^ n * symsum ( x1 *( z ^ - n ) ,n ,0 , %inf ) ;
x2 = exp ( - sqrt ( -1) * Wo * n ) ;
X2 =( -1) ^ n * symsum ( x2 *( z ^ - n ) ,n ,0 , %inf ) ;
X =( X1 + X2 ) /2;
disp (X , X( z )= ) ;

54

Scilab code Exa 2.45 Pole Zero Pattern of the System


1 // Example 2 . 4 5
2 //To draw t h e p o l e z e r o p l o t
3 clear all ;
4 clc ;
5 close ;
6 z = %z
7 H1Z =(( z ) *( z +1) ) /( z ^2 - z +0.5) ;
8 xset ( window ,1) ;
9 plzr ( H1Z ) ;

Scilab code Exa 2.53.a z Transform of the Sequence


1
2
3
4
5
6
7
8
9
10
11
12
13
14

// Example 2 . 5 3 ( a )
//Z t r a n s f o r m o f [ 3 1 2 5 7 0 1 ]
clear all ;
clc ;
close ;
function [ za ]= ztransfer ( sequence , n )
z = poly (0 , z , r )
za = sequence *(1/ z ) ^n
endfunction
x1 =[3 1 2 5 7 0 1];
n = -3:3;
zz = ztransfer ( x1 , n ) ;
// D i s p l a y t h e r e s u l t i n command window
disp ( zz , Zt r a n s f o r m o f s e q u e n c e i s : ) ;

Scilab code Exa 2.53.b z Transform of the Signal


1
2

// Example 2 . 5 3 ( b )
//MAXIMA SCILAB TOOLBOX REQUIRED FOR THIS PROGRAM
55

3 //Z t r a n s f o r m o f d e l t a ( n )
4 clc ;
5 syms n z ;
6 x =1;
7 X = symsum ( x * z ^( - n ) ,n ,0 ,0) ;
8 disp (X , X( z )= ) ;

Scilab code Exa 2.53.c z Transform of the Signal


1 // Example 2 . 5 3 ( c )
2 //MAXIMA SCILAB TOOLBOX REQUIRED FOR THIS PROGRAM
3 //Z t r a n s f o r m o f d e l t a ( n )
4 clc ;
5 syms n z k ;
6 x =1;
7 X = symsum ( x * z ^( - n ) ,n ,k , k ) ;
8 disp (X , X( z )= ) ;

Scilab code Exa 2.53.d z Transform of the Signal


1 // Example 2 . 5 3 ( d )
2 //MAXIMA SCILAB TOOLBOX REQUIRED FOR THIS PROGRAM
3 //Z t r a n s f o r m o f d e l t a ( n )
4 clc ;
5 syms n z kc ;
6 x =1;
7 X = symsum ( x * z ^( - n ) ,n , -k , - k ) ;
8 disp (X , X( z )= ) ;

Scilab code Exa 2.54 z Transform of Cosine Signal


56

Figure 2.8: Impulse Response of the System


1
2
3
4
5
6
7
8
9
10
11

// Example 2 . 5 4
//MAXIMA SCILAB TOOLBOX REQUIRED FOR THIS PROGRAM
//Z t r a n s f o r m o f c o s (Won )
clc ;
syms Wo n z ;
x1 = exp ( sqrt ( -1) * Wo * n ) ;
X1 = symsum ( x1 *( z ^ - n ) ,n ,0 , %inf ) ;
x2 = exp ( - sqrt ( -1) * Wo * n ) ;
X2 = symsum ( x2 *( z ^ - n ) ,n ,0 , %inf ) ;
X =( X1 + X2 ) /2;
disp (X , X( z )= ) ;

57

Scilab code Exa 2.58 Impulse Response of the System


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

// Example 2 . 5 8
//To p l o t t h e r e s p o n c e o f t h e s y s t e m a n a l y i c a l l y and
using s c i l a b
clear all ;
clc ;
close ;
n =0:1:20;
x =[1 zeros (1 ,20) ];
b =[1 -0.5];
a =[1 -1 3/16];
yanaly =0.5*(0.75) .^ n +0.5*(0.25) .^ n ; // A n a l y t i c a l
Solution
ymat = filter (b ,a , x ) ;
subplot (3 ,1 ,1) ;
plot2d3 (n , x ) ;
xlabel ( n ) ;
ylabel ( x ( n ) ) ;
title ( INPUT SEQUENCE (IMPULSE FUNCTION) ) ;
subplot (3 ,1 ,2) ;
plot2d3 (n , yanaly ) ;
xlabel ( n ) ;
ylabel ( y ( n ) ) ;
title ( OUTPUT SEQUENCE y a n a l y ) ;
subplot (3 ,1 ,3) ;
plot2d3 (n , ymat ) ;
xlabel ( n ) ;
ylabel ( y ( n ) ) ;
title ( OUTPUT SEQUENCE ymat ) ;
// As t h e A n a l t i c a l P l o t m a t c h e s t h e S c i l a b P l o t
hence i t i s the Responce o f the system

58

Chapter 3
THE DISCRETE FOURIER
TRANSFORM

Scilab code Exa 3.1 DFT and IDFT


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

// Example 3 . 1
// Program t o Compute t h e DFT o f a S e q u e n c e x [ n
]=[1 ,1 ,0 ,0]
// and IDFT o f a S e q u e n c e Y [ k ] = [ 1 , 0 , 1 , 0 ]
clear all ;
clc ;
close ;
x = [1 ,1 ,0 ,0];
//DFT Computation
X = fft ( x , -1) ;
Y = [1 ,0 ,1 ,0];
//IDFT Computation
y = fft ( Y , 1) ;
// D i s p l a y s e q u e n c e X [ k ] and y [ n ] i n command window
disp (X , X [ k ]= ) ;
disp (y , y [ n ]= ) ;

59

Figure 3.1: DFT of the Sequence

Scilab code Exa 3.2 DFT of the Sequence


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

// Example 3 . 2
// Program t o Compute t h e DFT o f a S e q u e n c e x [ n ] = 1 ,
0<=n<=2; and 0 o t h e r w i s e
// f o r N=4 and N=8. P l o t Magnitude and p h a s e p l o t s o f
each .
clear all ;
clc ;
close ;
//N=4
x1 = [1 ,1 ,1 ,0];
//DFT Computation
X1 = fft ( x1 , -1) ;
//N=8
x2 = [1 ,1 ,1 ,0 ,0 ,0 ,0 ,0];
//DFT Computation
X2 = fft ( x2 , -1) ;
// D i s p l a y s e q u e n c e X1 [ k ] and X2 [ k ] i n command window
disp ( X1 , X1 [ k ]= ) ;
60

17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53

disp ( X2 , X2 [ k ]= ) ;
// P l o t s f o r N=4
n1 =0:1:3;
subplot (2 ,2 ,1) ;
a = gca () ;
a . y_location = o r i g i n ;
a . x_location = o r i g i n ;
plot2d3 ( n1 , abs ( X1 ) ,2) ;
poly1 = a . children (1) . children (1) ;
poly1 . thickness =2;
xtitle ( N=4 , k , | X1 ( k ) | ) ;
subplot (2 ,2 ,2) ;
a = gca () ;
a . y_location = o r i g i n ;
a . x_location = o r i g i n ;
plot2d3 ( n1 , atan ( imag ( X1 ) , real ( X1 ) ) ,5) ;
poly1 = a . children (1) . children (1) ;
poly1 . thickness =2;
xtitle ( N=4 , k , <X1 ( k ) ) ;
// P l o t s f o r N=8
n2 =0:1:7;
subplot (2 ,2 ,3) ;
a = gca () ;
a . y_location = o r i g i n ;
a . x_location = o r i g i n ;
plot2d3 ( n2 , abs ( X2 ) ,2) ;
poly1 = a . children (1) . children (1) ;
poly1 . thickness =2;
xtitle ( N=8 , k , | X2 ( k ) | ) ;
subplot (2 ,2 ,4) ;
a = gca () ;
a . y_location = o r i g i n ;
a . x_location = o r i g i n ;
plot2d3 ( n2 , atan ( imag ( X2 ) , real ( X2 ) ) ,5) ;
poly1 = a . children (1) . children (1) ;
poly1 . thickness =2;
xtitle ( N=8 , k , <X2 ( k ) ) ;

61

Scilab code Exa 3.3 8 Point DFT


1
2
3
4
5
6
7
8
9
10

// Example 3 . 3
// Program t o Compute t h e 8 p o i n t DFT o f t h e S e q u e n c e
x [ n]=[1 ,1 ,1 ,1 ,1 ,1 ,0 ,0]
clear all ;
clc ;
close ;
x = [1 ,1 ,1 ,1 ,1 ,1 ,0 ,0];
//DFT Computation
X = fft ( x , -1) ;
// D i s p l a y s e q u e n c e X [ k ] i n command window
disp (X , X [ k ]= ) ;

Scilab code Exa 3.4 IDFT of the given Sequence


1
2
3
4
5
6
7
8
9
10
11

// Example 3 . 4
// Program t o Compute t h e IDFT o f t h e S e q u e n c e X [ k
]=[5 ,0 ,1 j ,0 ,1 ,0 ,1+ j , 0 ]
clear all ;
clc ;
close ;
j = sqrt ( -1) ;
X = [5 ,0 ,1 -j ,0 ,1 ,0 ,1+ j ,0]
//IDFT Computation
x = fft ( X , 1) ;
// D i s p l a y s e q u e n c e s x [ n ] i n command window
disp (x , x [ n ]= ) ;

62

Figure 3.2: Plot the Sequence

Scilab code Exa 3.7 Plot the Sequence


1
2
3
4
5
6
7
8
9
10
11
12

// Example 3 . 7
// Program t o Compute c i r c u l a r c o n v o l u t i o n o f
following sequences
// x [ n ] = [ 1 , 2 , 2 , 1 , 0 ]
//Y [ k ]= exp ( j 4 p i k / 5 ) . X [ k ]
clear all ;
clc ;
close ;
x =[1 ,2 ,2 ,1 ,0];
X = fft (x , -1) ;
k =0:1:4;
j = sqrt ( -1) ;
pi =22/7;
63

13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

H = exp ( - j *4* pi * k /5) ;


Y = H .* X ;
//IDFT Computation
y = fft (Y ,1) ;
// D i s p l a y s e q u e n c e y [ n ] i n command window
disp ( round ( y ) , y [ n ]= ) ;
// P l o t s
n =0:1:4;
a = gca () ;
a . y_location = o r i g i n ;
a . x_location = o r i g i n ;
plot2d3 (n , round ( y ) ,5) ;
poly1 = a . children (1) . children (1) ;
poly1 . thickness =2;
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
2
3
4
5
6
7
8
9

10
11
12

// Example 3 . 9
// Program t o r e m a i n i n g s a m p l e s o f t h e s e q u e n c e
//X( 0 ) =12 ,X( 1 )=1+j 3 , X( 2 ) =3+j 4 , X( 3 ) =1j 5 , X( 4 )=2+j 2 ,
X( 5 ) =6+j 3 , X( 6 ) =2j 3 , X( 7 ) =10
clear all ;
clc ;
close ;
j = sqrt ( -1) ;
z =1;
X (0+ z ) =12 , 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;
for a =9:1:14 do X ( a ) = conj ( X (16 - a ) ) , end ;
// 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 command
window
disp (X , X [ k ]= ) ;

64

Scilab code Exa 3.11 DFT Computation


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

// Example 3 . 1 1
// Program t o Compute t h e 8 p o i n t DFT o f t h e
following sequences
// x1 [ n ] = [ 1 , 0 , 0 , 0 , 0 , 1 , 1 , 1 ]
// x2 [ n ] = [ 0 , 0 , 1 , 1 , 1 , 1 , 0 , 0 ]
clear all ;
clc ;
close ;
x1 =[1 ,0 ,0 ,0 ,0 ,1 ,1 ,1];
x2 =[0 ,0 ,1 ,1 ,1 ,1 ,0 ,0];
//DFT Computation
X1 = fft ( x1 , -1) ;
X2 = fft ( x2 , -1) ;
// D i s p l a y s e q u e n c e s X1 [ k ] and X2 [ k ] i n command
window
disp ( X1 , X1 [ k ]= ) ;
disp ( X2 , X2 [ k ]= ) ;

Scilab code Exa 3.13 Circular Convolution


1
2
3
4
5
6
7
8
9

// Example 3 . 1 3
// Program t o Compute c i r c u l a r c o n v o l u t i o n o f
following sequences
// x1 [ n ] = [ 1 , 1 , 2 , 3 , 1 ]
// x2 [ n ] = [ 1 , 2 , 3 ]
clear all ;
clc ;
close ;
x1 =[1 , -1 , -2 ,3 , -1];
x2 =[1 ,2 ,3];
65

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

// Loop f o r z e r o p a d d i n g t h e s m a l l e r s e q u e n c e o u t o f
t h e two
n1 = length ( x1 ) ;
n2 = length ( x2 ) ;
n3 = n2 - n1 ;
if ( n3 >=0) then
x1 =[ x1 , zeros (1 , n3 ) ];
else
x2 =[ x2 , zeros (1 , - n3 ) ];
end
//DFT Computation
X1 = fft ( x1 , -1) ;
X2 = fft ( x2 , -1) ;
Y = X1 .* X2 ;
//IDFT Computation
y = fft (Y ,1) ;
// D i s p l a y s e q u e n c e y [ n ] i n command window
disp (y , y [ n ]= ) ;

Scilab code Exa 3.14 Circular Convolution


1
2
3
4
5
6
7
8
9
10
11
12
13

// Example 3 . 1 4
// Program t o Compute c i r c u l a r c o n v o l u t i o n o f
following sequences
// x1 [ n ] = [ 1 , 2 , 2 , 1 ]
// x2 [ n ] = [ 1 , 2 , 3 , 1 ]
clear all ;
clc ;
close ;
x1 =[1 ,2 ,2 ,1];
x2 =[1 ,2 ,3 ,1];
//DFT Computation
X1 = fft ( x1 , -1) ;
X2 = fft ( x2 , -1) ;
Y = X1 .* X2 ;
66

14 //IDFT Computation
15 y = fft (Y ,1) ;
16 // D i s p l a y s e q u e n c e y [ n ]
17 disp (y , y [ n ]= ) ;

i n command window

Scilab code Exa 3.15 Determine Sequence x3


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

// Example 3 . 1 5
// Program t o Compute x3 [ n ] where X3 [ k ]=X1 [ k ] . X2 [ k ]
// x1 [ n ] = [ 1 , 2 , 3 , 4 ]
// x2 [ n ] = [ 1 , 1 , 2 , 2 ]
clear all ;
clc ;
close ;
x1 =[1 ,2 ,3 ,4];
x2 =[1 ,1 ,2 ,2];
//DFT Computation
X1 = fft ( x1 , -1) ;
X2 = fft ( x2 , -1) ;
X3 = X1 .* X2 ;
//IDFT Computation
x3 = fft ( X3 ,1) ;
// D i s p l a y s e q u e n c e x3 [ n ] i n command window
disp ( x3 , x3 [ n ]= ) ;

Scilab code Exa 3.16 Circular Convolution


// Example 3 . 1 6
// Program t o Compute c i r c u l a r c o n v o l u t i o n o f
following sequences
3 // x1 [ n ] = [ 1 , 1 , 2 , 1 ]
4 // x2 [ n ] = [ 1 , 2 , 3 , 4 ]
5 clear all ;
1
2

67

6
7
8
9
10
11
12
13
14
15
16
17

clc ;
close ;
x1 =[1 ,1 ,2 ,1];
x2 =[1 ,2 ,3 ,4];
//DFT Computation
X1 = fft ( x1 , -1) ;
X2 = fft ( x2 , -1) ;
X3 = X1 .* X2 ;
//IDFT Computation
x3 = fft ( X3 ,1) ;
// D i s p l a y s e q u e n c e x3 [ n ] i n command window
disp ( x3 , x3 [ n ]= ) ;

Scilab code Exa 3.17 Circular Convolution


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

// Example 3 . 1 7
// Program t o Compute y [ n ] where Y [ k ]=X1 [ k ] . X2 [ k ]
// x1 [ n ] = [ 0 , 1 , 2 , 3 , 4 ]
// x2 [ n ] = [ 0 , 1 , 0 , 0 , 0 ]
clear all ;
clc ;
close ;
x1 =[0 ,1 ,2 ,3 ,4];
x2 =[0 ,1 ,0 ,0 ,0];
//DFT Computation
X1 = fft ( x1 , -1) ;
X2 = fft ( x2 , -1) ;
Y = X1 .* X2 ;
//IDFT Computation
y = round ( fft (Y ,1) ) ;
// D i s p l a y s e q u e n c e y [ n ] i n command window
disp (y , y [ n ]= ) ;

68

Scilab code Exa 3.18 Output Response


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

// Example 3 . 1 8
// Program t o Compute o u t p u t r e s p o n c e o f f o l l o w i n g
sequences
// x [ n ] = [ 1 , 2 , 3 , 1 ]
// h [ n ] = [ 1 , 1 , 1 ]
// ( 1 ) L i n e a r C o n v o l u t i o n
// ( 2 ) C i r c u l a r C o n v o l u t i o n
// ( 3 ) C i r c u l a r C o n v o l u t i o n w i t h z e r o p a d d i n g
clear all ;
clc ;
close ;
x =[1 ,2 ,3 ,1];
h =[1 ,1 ,1];
// ( 1 ) L i n e a r C o n v o l u t i o n Computation
ylinear = convol (x , h ) ;
// D i s p l a y L i n e a r C o n v o l u t e d S e q u e n c e y [ n ] i n command
window
disp ( ylinear , y l i n e a r [ n ]= ) ;
// ( 2 ) C i r c u l a r C o n v o l u t i o n Computation
//Now z e r o p a d d i n g 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 ] and h [ n ] e q u a l
h1 =[ h , zeros (1 ,1) ];
//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 method
X = fft (x , -1) ;
H = fft ( h1 , -1) ;
Y = X .* H ;
ycircular = fft (Y ,1) ;
// D i s p l a y C i r c u l a r C o n v o l u t e d S e q u e n c e y [ n ] i n
command window
disp ( ycircular , y c i r c u l a r [ n ]= ) ;
// ( 3 ) C i r c u l a r C o n v o l u t i o n Computation w i t h z e r o
Padding
x2 =[ x , zeros (1 ,2) ];
h2 =[ h , zeros (1 ,3) ];
//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 method
X2 = fft ( x2 , -1) ;
69

32 H2 = fft ( h2 , -1) ;
33 Y2 = X2 .* H2 ;
34 ycircularp = fft ( Y2 ,1) ;
35 // D i s p l a y C i r c u l a r C o n v o l u t e d S e q u e n c e w i t h z e r o

Padding y [ n ] i n command window


36 disp ( ycircularp , y c i r c u l a r p [ n ]= ) ;

Scilab code Exa 3.20 Output Response


1
2
3
4
5
6
7
8
9
10
11
12
13

// Example 3 . 2 0
// Program t o Compute L i n e a r C o n v o l u t i o n o f f o l l o w i n g
sequences
// x [ n ] = [ 3 , 1 , 0 , 1 , 3 , 2 , 0 , 1 , 2 , 1 ]
// h [ n ] = [ 1 , 1 , 1 ]
clear all ;
clc ;
close ;
x =[3 , -1 ,0 ,1 ,3 ,2 ,0 ,1 ,2 ,1];
h =[1 ,1 ,1];
// L i n e a r C o n v o l u t i o n Computation
y = convol (x , h ) ;
// D i s p l a y S e q u e n c e y [ n ] i n command window
disp (y , y [ n ]= ) ;

Scilab code Exa 3.21 Linear Convolution


1
2
3
4
5
6

// Example 3 . 2 1
// Program t o Compute L i n e a r C o n v o l u t i o n o f f o l l o w i n g
sequences
// x [ n ] = [ 1 , 2 , 1 , 2 , 3 , 2 , 3 , 1 , 1 , 1 , 2 , 1 ]
// h [ n ] = [ 1 , 2 ]
clear all ;
clc ;
70

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 u t i o n Computation
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 window
13 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 PROGRAM
3 //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 = symsum ( x * exp ( - %i *2* %pi * n * k / N ) ,n ,0 ,0) ;
8 disp (X , X( k )= ) ;

Scilab code Exa 3.23.b N Point DFT Computation


1 // Example 3 . 2 3 ( b )
2 //MAXIMA SCILAB TOOLBOX REQUIRED FOR THIS PROGRAM
3 //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 = symsum ( x * exp ( - %i *2* %pi * n * k / N ) ,n , - no , - no ) ;
8 disp (X , X( k )= ) ;

71

Scilab code Exa 3.23.c N Point DFT Computation


1 // Example 3 . 2 3 ( c )
2 //MAXIMA SCILAB TOOLBOX REQUIRED FOR THIS PROGRAM
3 //N p o i n t DFT o f a n
4 clc ;
5 syms a n k N ;
6 x=a^n;
7 X = symsum ( x * exp ( - %i *2* %pi * n * k / N ) ,n ,0 ,N -1) ;
8 disp (X , X( k )= ) ;

Scilab code Exa 3.23.d N Point DFT Computation


1 // Example 3 . 2 3 ( d )
2 //MAXIMA SCILAB TOOLBOX REQUIRED FOR THIS PROGRAM
3 //N p o i n t DFT o f x ( n ) =1 , 0<=n<=N/21
4 clc ;
5 syms n k N ;
6 x =1;
7 X = symsum ( x * exp ( - %i *2* %pi * n * k / N ) ,n ,0 ,( N /2) -1) ;
8 disp (X , X( k )= ) ;

Scilab code Exa 3.23.e N Point DFT Computation


1 // Example 3 . 2 3 ( e )
2 //MAXIMA SCILAB TOOLBOX REQUIRED FOR THIS PROGRAM
3 //N p o i n t DFT o f x ( n )=exp ( %i 2 %pi ko n /N) ;
4 clc ;
5 syms n k N ko ;
6 x = exp ( %i *2* %pi * ko * n / N ) ;
7 X = symsum ( x * exp ( - %i *2* %pi * n * k / N ) ,n ,0 ,( N /2) -1) ;
8 disp (X , X( k )= ) ;

72

Scilab code Exa 3.23.f N Point DFT Computation


1 // Example 3 . 2 3 ( f )
2 //MAXIMA SCILAB TOOLBOX REQUIRED FOR THIS PROGRAM
3 //N p o i n t DFT o f x ( n ) =1 , f o r n=e v e n and 0 , f o r n=odd
4 clc ;
5 syms n k N ;
6 x =1; // x ( 2 n ) =1 , f o r a l l n
7 X = symsum ( x * exp ( - %i *4* %pi * n * k / N ) ,n ,0 , N /2 -1) ;
8 disp (X , X( k )= ) ;

Scilab code Exa 3.24 DFT of the Sequence


1
2
3
4
5
6
7
8
9
10
11
12

// Example 3 . 2 4
// Program t o Compute t h e DFT o f t h e S e q u e n c e x [ n
]=( 1) n , f o r N=4
clear all ;
clc ;
close ;
N =4;
n =0:1: N -1;
x =( -1) ^ n ;
//DFT Computation
X = fft (x , -1) ;
// D i s p l a y S e q u e n c e X [ k ] i n command window
disp (X , X [ k ]= ) ;

Scilab code Exa 3.25 8 Point Circular Convolution

73

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

// Example 3 . 2 5
// Program t o Compute t h e 8 p o i n t C i r c u l a r
Convolution of the Sequences
// x1 [ n ] = [ 1 , 1 , 1 , 1 , 0 , 0 , 0 , 0 ]
// x2 [ n ]= s i n ( 3 p i n / 8 )
clear all ;
clc ;
close ;
x1 =[1 ,1 ,1 ,1 ,0 ,0 ,0 ,0];
n =0:1:7;
pi =22/7;
x2 = sin (3* pi * n /8) ;
//DFT Computation
X1 = fft ( x1 , -1) ;
X2 = fft ( x2 , -1) ;
// C i r c u l a r C o n v o l u t i o n u s i n g DFT
Y = X1 .* X2 ;
//IDFT Computation
y = fft (Y ,1) ;
// D i s p l a y s e q u e n c e y [ n ] i n command window
disp (y , y [ n ]= ) ;

Scilab code Exa 3.26 Linear Convolution using DFT


1
2
3
4
5
6
7
8
9
10

// Example 3 . 2 6
// Program t o Compute t h e L i n e a r C o n v o l u t i o n o f t h e
f o l l o w i n g Sequences
// x [ n ] = [ 1 , 1 , 1 ]
// h [ n ] = [ 2 , 2 , 1 ]
clear all ;
clc ;
close ;
x =[1 , -1 ,1];
h =[2 ,2 ,1];
// C o n v o l u t i o n Computation
74

11 y = convol (x , h ) ;
12 // D i s p l a y s e q u e n c e y [ n ]
13 disp (y , y [ n ]= ) ;

i n command window

Scilab code Exa 3.27.a Circular Convolution Computation


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

// Example 3 . 2 7 ( a )
// Program t o Compute t h e C o n v o l u t i o n o f t h e
f o l l o w i n g Sequences
// x1 [ n ] = [ 1 , 1 , 1 ]
// x2 [ n ] = [ 2 , 1 , 2 ]
clear all ;
clc ;
close ;
x1 =[1 ,1 ,1];
x2 =[2 , -1 ,2];
// C o n v o l u t i o n Computation
X1 = fft ( x1 , -1) ;
X2 = fft ( x2 , -1) ;
Y = X1 .* X2 ;
y = fft (Y ,1) ;
// D i s p l a y S e q u e n c e y [ n ] i n command window
disp (y , y [ n ]= ) ;

Scilab code Exa 3.27.b Circular Convolution Computation


1
2
3
4
5
6

// Example 3 . 2 7 ( b )
// Program t o Compute t h e C o n v o l u t i o n o f t h e
f o l l o w i n g Sequences
// x1 [ n ] = [ 1 , 1 , 1 , 1 , 0 ]
// x2 [ n ] = [ 1 , 0 , 1 , 0 , 1 ]
clear all ;
clc ;
75

7
8
9
10
11
12
13
14
15
16

close ;
x1 =[1 ,1 , -1 , -1 ,0];
x2 =[1 ,0 , -1 ,0 ,1];
// C o n v o l u t i o n Computation
X1 = fft ( x1 , -1) ;
X2 = fft ( x2 , -1) ;
Y = X1 .* X2 ;
y = fft (Y ,1) ;
// D i s p l a y S e q u e n c e y [ n ] i n command window
disp (y , y [ n ]= ) ;

Scilab code Exa 3.30 Calculate value of N


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

// Example 3 . 3 0
// Program t o C a l c u l a t e N from g i v e n d a t a
// fm =5000Hz
// d f =50Hz
// t =0.5 s e c
clear all ;
clc ;
close ;
fm =5000 // Hz
df =50
// Hz
t =0.5
// s e c
N1 =2* fm / df ;
N =2;
while N <= N1 , N = N *2 , end
// D i s p l a y i n g t h e v a l u e o f N i n command window
disp (N , N= ) ;

Scilab code Exa 3.32 Sketch Sequence


76

Figure 3.3: Sketch Sequence


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

// Example 3 . 3 2
// Program t o p l o t t h e r e s u l t o f t h e g i v e n s e q u e n c e
//X [ k ] = [ 1 , 2 , 2 , 1 , 0 , 2 , 1 , 2 ]
// y [ n ]= x [ n / 2 ] f o r n=even , 0 f o r n=odd
clear all ;
clc ;
close ;
X =[1 ,2 ,2 ,1 ,0 ,2 ,1 ,2];
x = fft ( X , 1) ;
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];
Y = fft ( y , -1) ;
// D i s p l a y s e q u e n c e Y [ k ] and i n command window
disp (Y , Y [ k ]= ) ;
// P l o t t i n g t h e s e q u e n c e Y [ k ]
k =0:1:15;
a = gca () ;
a . y_location = o r i g i n ;
a . x_location = o r i g i n ;
plot2d3 (k ,Y ,2) ;
poly1 = a . children (1) . children (1) ;
poly1 . thickness =2;
xtitle ( P l o t o f Y( k ) , k , Y( k ) ) ;
77

Scilab code Exa 3.36 Determine IDFT


1
2
3
4
5
6
7
8
9
10
11
12

// Example 3 . 3 6
// Program t o Compute t h e IDFT o f t h e f o l l o w i n g
Sequence
//X [ k ] = [ 1 2 , 1 . 5 + j 2 . 5 9 8 , 1 . 5 + j 0 . 8 6 6 , 0 , 1 . 5 j 0
.866 , 1.5 j 2 . 5 9 8 ]
clear all ;
clc ;
close ;
j = sqrt ( -1) ;
X =[12 , -1.5+ j *2.598 , -1.5+ j *0.866 ,0 , -1.5 - j *0.866 , -1.5 j *2.598];
//IDFT Computation
x = fft ( X , 1) ;
// D i s p l a y S e q u e n c e x [ n ] i n command window
disp ( round ( x ) , x [ n ]= ) ;

78

Chapter 4
THE FAST FOURIER
TRANSFORM

Scilab code Exa 4.3 Shortest Sequence N Computation


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

// Example 4 . 3
// Program t o c a l c u l a t e s h o r t e s t s e q u e n c e N s u c h t h a t
a l g o r i t h m B r u n s // f a s t e r t h a n A
clear all ;
clc ;
close ;
i =0;
N =32; // Given
// C a l c u l a t i o n o f T w i d d l e f a c t o r e x p o n e n t s f o r e a c h
stage
while 1==1
i = i +1;
N =2^ i ;
A = N ^2;
B =5* N * log2 ( N ) ;
if A > B then break ;
end ;
end
disp (N , SHORTEST SEQUENCE N = ) ;
79

Scilab code Exa 4.4 Twiddle Factor Exponents Calculation


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

// Example 4 . 4
// Program t o c a l c u l a t e T w i d d l e f a c t o r e x p o n e n t s f o r
each s t a g e
clear all ;
clc ;
close ;
N =32; // Given
// C a l c u l a t i o n o f T w i d d l e f a c t o r e x p o n e n t s f o r e a c h
stage
for m =1:5
disp (m , S t a g e : m = ) ;
disp ( k = ) ;
for t =0:(2^( m -1) -1)
k = N * t /2^ m ;
disp ( k ) ;
end
end

Scilab code Exa 4.6 DFT using DIT Algorithm


1
2
3
4
5
6
7
8

// Example 4 . 6
// Program t o f i n d t h e DFT o f a S e q u e n c e x [ n
]=[1 ,2 ,3 ,4 ,4 ,3 ,2 ,1]
// u s i n g DIT A l g o r i t h m .
clear all ;
clc ;
close ;
x = [1 ,2 ,3 ,4 ,4 ,3 ,2 ,1];
//FFT Computation
80

9 X = fft ( x , -1) ;
10 disp (X , X( z ) = ) ;

Scilab code Exa 4.8 DFT using DIF Algorithm


1
2
3
4
5
6
7
8
9
10

// Example 4 . 8
// Program t o f i n d t h e DFT o f a S e q u e n c e x [ n
]=[1 ,2 ,3 ,4 ,4 ,3 ,2 ,1]
// u s i n g DIF A l g o r i t h m .
clear all ;
clc ;
close ;
x = [1 ,2 ,3 ,4 ,4 ,3 ,2 ,1];
//FFT Computation
X = fft ( x , -1) ;
disp (X , X( z ) = ) ;

Scilab code Exa 4.9 8 Point DFT of the Sequence


1
2
3
4
5
6
7
8
9
10

// Example 4 . 9
// Program t o f i n d t h e 8 p o i n t DFT o f a S e q u e n c e x [ n
] = 1 , 0<=n<=7
// u s i n g DIT , DIF A l g o r i t h m .
clear all ;
clc ;
close ;
x = [1 ,1 ,1 ,1 ,1 ,1 ,1 ,1];
//FFT Computation
X = fft ( x , -1) ;
disp (X , X( z ) = ) ;

81

Scilab code Exa 4.10 4 Point DFT of the Sequence


1
2
3
4
5
6
7
8
9
10

// Example 4 . 1 0
// Program t o Compute t h e 4 p o i n t DFT o f a S e q u e n c e x
[n]=[0 ,1 ,2 ,3]
// u s i n g DITDIF A l g o r i t h m .
clear all ;
clc ;
close ;
x = [0 ,1 ,2 ,3];
//FFT Computation
X = fft ( x , -1) ;
disp (X , X( z ) = ) ;

Scilab code Exa 4.11 IDFT of the Sequence using DIT Algorithm
1
2
3
4
5
6
7
8
9
10
11

// Example 4 . 1 1
// Program t o Compute t h e IDFT o f a S e q u e n c e u s i n g
DIT A l g o r i t h m .
//X [ k ] = [7 , 0.707 j 0 . 7 0 7 , j , 0 . 7 0 7 j 0 . 7 0 7 , 1 , 0 . 7 0 7 + j 0
. 7 0 7 , j , 0.707+ j 0 . 7 0 7 ]
clear all ;
clc ;
close ;
j = sqrt ( -1) ;
X = [7 , -0.707 - j *0.707 , - j ,0.707 - j *0.707 ,1 ,0.707+ j
*0.707 , j , -0.707+ j *0.707];
// I n v e r s e FFT Computation
x = fft ( X , 1) ;
disp (x , x ( n ) = ) ;

Scilab code Exa 4.12 8 Point DFT of the Sequence


82

1
2
3
4
5
6
7
8
9
10

// Example 4 . 1 2
// Program t o Compute t h e 8 p o i n t DFT o f a S e q u e n c e
// x [ n ] = [ 0 . 5 , 0 . 5 , 0 . 5 , 0 . 5 , 0 , 0 , 0 , 0 ] u s i n g r a d i x 2 DIT
Algorithm .
clear all ;
clc ;
close ;
x =[0.5 ,0.5 ,0.5 ,0.5 ,0 ,0 ,0 ,0];
//FFT Computation
X = fft ( x , -1) ;
disp (X , X( z ) = ) ;

Scilab code Exa 4.13 8 Point DFT of the Sequence


1
2
3
4
5
6
7
8
9
10

// Example 4 . 1 3
// Program t o Compute t h e 8 p o i n t DFT o f a S e q u e n c e
// x [ n ] = [ 0 . 5 , 0 . 5 , 0 . 5 , 0 . 5 , 0 , 0 , 0 , 0 ] u s i n g r a d i x 2 DIF
Algorithm .
clear all ;
clc ;
close ;
x =[0.5 ,0.5 ,0.5 ,0.5 ,0 ,0 ,0 ,0];
//FFT Computation
X = fft ( x , -1) ;
disp (X , X( z ) = ) ;

Scilab code Exa 4.14 DFT using DIT Algorithm


// Example 4 . 1 4
// Program t o Compute t h e 4 p o i n t DFT o f a S e q u e n c e x
[ n ]=[1 , 1 ,1 , 1]
3 // u s i n g DIT A l g o r i t h m .
4 clear all ;

1
2

83

5 clc ;
6 close ;
7 x =[1 , -1 ,1 , -1];
8 //FFT Computation
9 X = fft ( x , -1) ;
10 disp (X , X( z ) = ) ;

Scilab code Exa 4.15 DFT using DIF Algorithm


1
2
3
4
5
6
7
8
9
10

// Example 4 . 1 5
// Program t o Compute t h e 4 p o i n t DFT o f a S e q u e n c e x
[n]=[1 ,0 ,0 ,1]
// u s i n g DIF A l g o r i t h m .
clear all ;
clc ;
close ;
x =[1 ,0 ,0 ,1];
//FFT Computation
X = fft ( x , -1) ;
disp (X , X( z ) = ) ;

Scilab code Exa 4.16.a 8 Point DFT using DIT FFT


1
2
3
4
5
6
7
8
9

// Example 4 . 1 6 ( a )
// Program t o E v a l u a t e and Compare t h e 8 p o i n t DFT o f
the given Sequence
// x1 [ n ] = 1 , 3<=n<=3 u s i n g DITFFT A l g o r i t h m .
clear all ;
clc ;
close ;
x1 =[1 ,1 ,1 ,1 ,0 ,1 ,1 ,1];
//FFT Computation
X1 = fft ( x1 , -1) ;
84

10

disp ( X1 , X1 ( k ) = ) ;

Scilab code Exa 4.16.b 8 Point DFT using DIT FFT


1
2
3
4
5
6
7
8
9
10

// Example 4 . 1 6 ( b )
// Program t o E v a l u a t e and Compare t h e 8 p o i n t DFT o f
the given Sequence
// x2 [ n ] = 1 , 0<=n<=6 u s i n g DITFFT A l g o r i t h m .
clear all ;
clc ;
close ;
x2 =[1 ,1 ,1 ,1 ,1 ,1 ,1 ,0];
//FFT Computation
X2 = fft ( x2 , -1) ;
disp ( X2 , X2 ( k ) = ) ;

Scilab code Exa 4.17 IDFT using DIF Algorithm


1
2
3
4
5
6
7
8
9
10
11

// Example 4 . 1 7
// Program t o f i n d t h e IDFT o f t h e S e q u e n c e u s i n g DIF
Algorithm .
//X [ k ]= [4 ,1 j 2 . 4 1 4 , 0 , 1 j 0 . 4 1 4 , 0 , 1 + j 0 . 4 1 4 , 0 , 1 + j 2
.414]
clear all ;
clc ;
close ;
j = sqrt ( -1) ;
X = [4 ,1 - j *2.414 ,0 ,1 - j *0.414 ,0 ,1+ j *0.414 ,0 ,1+ j
*2.414];
// I n v e r s e FFT Computation
x = fft ( X , 1) ;
disp (x , x ( n ) = ) ;
85

Scilab code Exa 4.18 IDFT using DIT Algorithm


1
2
3
4
5
6
7
8
9
10
11

// Example 4 . 1 8
// Program t o f i n d t h e IDFT o f t h e S e q u e n c e X [ k ]=
[10 , 2+ j 2 ,2,2 j 2 ]
// u s i n g DIT A l g o r i t h m .
clear all ;
clc ;
close ;
j = sqrt ( -1) ;
X = [10 , -2+ j *2 , -2 , -2 - j *2];
// I n v e r s e FFT Computation
x = fft ( X , 1) ;
disp (x , x ( n ) = ) ;

Scilab code Exa 4.19 FFT Computation of the Sequence


1
2
3
4
5
6
7
8
9

// Example 4 . 1 9
// Program t o Compute t h e FFT o f g i v e n S e q u e n c e x [ n
]=[1 ,0 ,0 ,0 ,0 ,0 ,0 ,0].
clear all ;
clc ;
close ;
x = [1 ,0 ,0 ,0 ,0 ,0 ,0 ,0];
//FFT Computation
X = fft ( x , -1) ;
disp (X , X( z ) = ) ;

Scilab code Exa 4.20 8 Point DFT by Radix 2 DIT FFT


86

1
2
3
4
5
6
7
8
9
10

// Example 4 . 2 0
// Program t o Compute t h e 8 p o i n t DFT o f g i v e n
Sequence
// x [ n ] = [ 2 , 2 , 2 , 2 , 1 , 1 , 1 , 1 ] u s i n g DIT , r a d i x 2 ,FFT
Algorithm .
clear all ;
clc ;
close ;
x = [2 ,2 ,2 ,2 ,1 ,1 ,1 ,1];
//FFT Computation
X = fft ( x , -1) ;
disp (X , X( z ) = ) ;

Scilab code Exa 4.21 DFT using DIT FFT Algorithm


1
2
3
4
5
6
7
8
9
10

// Example 4 . 2 1
// Program t o Compute t h e DFT o f g i v e n S e q u e n c e
// x [ n ] = [ 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 ] u s i n g DITFFT A l g o r i t h m
.
clear all ;
clc ;
close ;
x = [1 , -1 , -1 , -1 ,1 ,1 ,1 , -1];
//FFT Computation
X = fft ( x , -1) ;
disp (X , X( z ) = ) ;

Scilab code Exa 4.22 Compute X using DIT FFT


1
2
3
4

// Example 4 . 2 2
// Program t o Compute t h e DFT o f g i v e n S e q u e n c e
// x [ n ]=2 n and N=8 u s i n g DITFFT A l g o r i t h m .
clear all ;
87

5
6
7
8
9
10
11
12

clc ;
close ;
N =8;
n =0:1: N -1;
x =2^ n ;
//FFT Computation
X = fft ( x , -1) ;
disp (X , X( z ) = ) ;

Scilab code Exa 4.23 DFT using DIF FFT Algorithm


1
2
3
4
5
6
7
8
9
10
11
12
13

// Example 4 . 2 3
// Program t o Compute t h e DFT o f g i v e n S e q u e n c e
// x [ n ]= c o s ( n p i / 2 ) , and N=4 u s i n g DIFFFT A l g o r i t h m .
clear all ;
clc ;
close ;
N =4;
pi =22/7;
n =0:1: N -1;
x = cos ( n * pi /2) ;
//FFT Computation
X = fft ( x , -1) ;
disp (X , X( z ) = ) ;

Scilab code Exa 4.24 8 Point DFT of the Sequence


// Example 4 . 2 4
// Program t o Compute t h e 8 p o i n t DFT o f g i v e n
Sequence
3 // x [ n ] = [ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 ] u s i n g DIF , r a d i x 2 ,FFT
Algorithm .
4 clear all ;

1
2

88

5 clc ;
6 close ;
7 x = [0 ,1 ,2 ,3 ,4 ,5 ,6 ,7];
8 //FFT Computation
9 X = fft ( x , -1) ;
10 disp (X , X( z ) = ) ;

89

Chapter 5
INFINITE IMPULSE
RESPONSE FILTERS

Scilab code Exa 5.1 Order of the Filter Determination


// Example 5 . 1
//To Find o u t t h e o r d e r o f t h e f i l t e r
clear all ;
clc ;
close ;
ap =1; // db
as =30; // db
op =200; // r a d / s e c
os =600; // r a d / s e c
N = log ( sqrt ((10^(0.1* as ) -1) /(10^(0.1* ap ) -1) ) ) / log ( os /
op ) ;
11 disp ( ceil ( N ) , Order o f t h e f i l t e r , N = ) ;

1
2
3
4
5
6
7
8
9
10

Scilab code Exa 5.2 Order of Low Pass Butterworth Filter


1

// Example 5 . 2
90

2
3
4
5
6
7
8
9
10
11
12
13

//To Find o u t t h e o r d e r o f a Low P a s s B u t t e r w o r t h


Filter
clear all ;
clc ;
close ;
ap =3; // db
as =40; // db
fp =500; // Hz
fs =1000; // Hz
op =2* %pi * fp ;
os =2* %pi * fs ;
N = log ( sqrt ((10^(0.1* as ) -1) /(10^(0.1* ap ) -1) ) ) / log ( os /
op ) ;
disp ( ceil ( N ) , Order o f t h e f i l t e r , N = ) ;

Scilab code Exa 5.4 Analog Butterworth Filter Design


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

// Example 5 . 4
//To D e s i g n an Analog B u t t e r w o r t h F i l t e r
clear all ;
clc ;
close ;
ap =2; // db
as =10; // db
op =20; // r a d / s e c
os =30; // r a d / s e c
N = log ( sqrt ((10^(0.1* as ) -1) /(10^(0.1* ap ) -1) ) ) / log ( os /
op ) ;
disp ( ceil ( N ) , Order o f t h e f i l t e r , N = ) ;
s = %s ;
HS =1/(( s ^2+0.76537* s +1) *( s ^2+1.8477* s +1) ) ; // T r a n s f e r
F u n c t i o n f o r N=4
oc = op /(10^(0.1* ap ) -1) ^(1/(2* ceil ( N ) ) ) ;
HS1 = horner ( HS , s / oc ) ;
disp ( HS1 , N o r m a l i z e d T r a n s f e r F u n c t i o n , H( s ) = ) ;
91

Scilab code Exa 5.5 Analog Butterworth Filter Design


// Example 5 . 5
//To D e s i g n an Analog B u t t e r w o r t h F i l t e r
clear all ;
clc ;
close ;
op =0.2* %pi ;
os =0.4* %pi ;
e1 =0.9;
l1 =0.2;
epsilon = sqrt (1/( e1 ^2) -1) ;
lambda = sqrt (1/( l1 ^2) -1) ;
N = log ( lambda / epsilon ) / log ( os / op ) ;
disp ( ceil ( N ) , Order o f t h e f i l t e r , N = ) ;
s = %s ;
HS =1/(( s ^2+0.76537* s +1) *( s ^2+1.8477* s +1) ) ; // T r a n s f e r
F u n c t i o n f o r N=4
16 oc = op / epsilon ^(1/ ceil ( N ) ) ;
17 HS1 = horner ( HS , s / oc ) ;
18 disp ( HS1 , N o r m a l i z e d T r a n s f e r F u n c t i o n , H( s ) = ) ;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

Scilab code Exa 5.6 Order of Chebyshev Filter


1
2
3
4
5
6

// Example 5 . 6
//To Find o u t t h e o r d e r o f t h e F i l t e r u s i n g
Chebyshev A p p r o x i m a t i o n
clear all ;
clc ;
close ;
ap =3; // db
92

as =16; // db
fp =1000; // Hz
fs =2000; // Hz
op =2* %pi * fp ;
os =2* %pi * fs ;
N = acosh ( sqrt ((10^(0.1* as ) -1) /(10^(0.1* ap ) -1) ) ) / acosh
( os / op ) ;
13 disp ( ceil ( N ) , Order o f t h e f i l t e r , N = ) ;
7
8
9
10
11
12

Scilab code Exa 5.7 Chebyshev Filter Design


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

// Example 5 . 7
//To D e s i g n an a n a l o g Chebyshev F i l t e r w i t h Given
Specifications
clear all ;
clc ;
close ;
os =2;
op =1;
ap =3; // db
as =16; // db
e1 =1/ sqrt (2) ;
l1 =0.1;
epsilon = sqrt (1/( e1 ^2) -1) ;
lambda = sqrt (1/( l1 ^2) -1) ;
N = acosh ( lambda / epsilon ) / acosh ( os / op ) ;
disp ( ceil ( N ) , Order 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
2

// Example 5 . 8
//To Find o u t t h e o r d e r o f t h e p o l e s o f t h e Type 1
Lowpass Chebyshev F i l t e r
93

3
4
5
6
7
8
9
10

clear all ;
clc ;
close ;
ap =1; //dB
as =40; //dB
op =1000* %pi ;
os =2000* %pi ;
N = acosh ( sqrt ((10^(0.1* as ) -1) /(10^(0.1* ap ) -1) ) ) / acosh
( os / op ) ;
11 disp ( ceil ( N ) , Order o f t h e f i l t e r , N = ) ;

Scilab code Exa 5.9 Chebyshev Filter Design


1
2
3
4
5
6
7
8
9
10
11

// Example 5 . 9
//To D e s i g n a Chebyshev F i l t e r w i t h Given
Specifications
clear all ;
clc ;
close ;
ap =2.5; // db
as =30; // db
op =20; // r a d / s e c
os =50; // r a d / s e c
N = acosh ( sqrt ((10^(0.1* as ) -1) /(10^(0.1* ap ) -1) ) ) / acosh
( os / op ) ;
disp ( ceil ( N ) , Order o f t h e f i l t e r , N = ) ;

Scilab code Exa 5.10 HPF Filter Design with given Specifications
1 // Example 5 . 1 0
2 //To D e s i g n a H . P . F . w i t h g i v e n
3 clear all ;
4 clc ;

94

specifications

5
6
7
8
9
10
11
12
13
14
15
16

close ;
ap =3; // db
as =15; // db
op =500; // r a d / s e c
os =1000; // r a d / s e c
N = log ( sqrt ((10^(0.1* as ) -1) /(10^(0.1* ap ) -1) ) ) / log ( os /
op ) ;
disp ( ceil ( N ) , Order o f t h e f i l t e r , N = ) ;
s = %s ;
HS =1/(( s +1) *( s ^2+ s +1) ) ; // T r a n s f e r F u n c t i o n f o r N=3
oc =1000 // r a d / s e c
HS1 = horner ( HS , oc / s ) ;
disp ( HS1 , N o r m a l i z e d T r a n s f e r F u n c t i o n , H( s ) = ) ;

Scilab code Exa 5.11 Impulse Invariant Method Filter Design


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

// Example 5 . 1 1
//To D e s i g n t h e F i l t e r u s i n g I m p u l s e I n v a r i e n t
Method
clear all ;
clc ;
close ;
s = %s ;
T =1;
HS =(2) /( s ^2+3* s +2) ;
elts = pfss ( HS ) ;
disp ( elts , F a c t o r i z e d HS = ) ;
// The p o l e s comes o u t t o be a t 2 and 1
p1 = -2;
p2 = -1;
z = %z ;
HZ =(2/(1 - %e ^( p2 * T ) * z ^( -1) ) ) -(2/(1 - %e ^( p1 * T ) * z ^( -1) ) )
disp ( HZ , HZ = ) ;

95

Scilab code Exa 5.12 Impulse Invariant Method Filter Design


1
2
3
4
5
6
7
8
9
10
11
12
13

// Example 5 . 1 2
//MAXIMA SCILAB TOOLBOX REQUIRED FOR THIS PROGRAM
//To D e s i g n t h e F i l t e r u s i n g I m p u l s e I n v a r i e n t
Method
clear all ;
clc ;
close ;
s = %s ;
HS =1/( s ^2+ sqrt (2) * s +1) ;
pp = ilaplace ( HS ) ;
syms n z ;
t =1;
X = symsum ( pp *( z ^( - n ) ) ,n ,0 , %inf ) ;
disp (X , F a c t o r i z e d HS = ) ;

Scilab code Exa 5.13 Impulse Invariant Method Filter Design


1
2
3
4
5
6
7
8
9
10
11
12

// Example 5 . 1 3
//MAXIMA SCILAB TOOLBOX REQUIRED FOR THIS PROGRAM
//To D e s i g n t h e 3 r d Order B u t t e r w o r t h F i l t e r u s i n g
I m p u l s e I n v a r i e n t Method
clear all ;
clc ;
close ;
s = %s ;
HS =1/(( s +1) *( s ^2+ s +1) ) ;
pp = ilaplace ( HS ) ; // I n v e r s e L a p l a c e
syms n z ;
t =1;
X = symsum ( pp *( z ^( - n ) ) ,n ,0 , %inf ) ; //Z T r a n s f o r m
96

13

disp (X , H( z )= ) ;

Scilab code Exa 5.15 Impulse Invariant Method Filter Design


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

// Example 5 . 1 5
//To D e s i g n t h e F i l t e r u s i n g I m p u l s e I n v a r i e n t
Method
clear all ;
clc ;
close ;
s = %s ;
T =0.2;
HS =10/( s ^2+7* s +10) ;
elts = pfss ( HS ) ;
disp ( elts , F a c t o r i z e d HS = ) ;
// The p o l e s comes o u t t o be a t 5 and 2
p1 = -5;
p2 = -2;
z = %z ;
HZ = T *(( -3.33/(1 - %e ^( p1 * T ) * z ^( -1) ) ) +(3.33/(1 - %e ^( p2 * T
) * z ^( -1) ) ) )
disp ( HZ , HZ = ) ;

Scilab code Exa 5.16 Bilinear Transformation Method Filter Design


1
2
3
4
5
6
7

// Example 5 . 1 6
//To Find o u t B i l i n e a r T r a n s f o r m a t i o n o f HS=2/(( s +1)
( s +2) )
clear all ;
clc ;
close ;
s = %s ;
z = %z ;
97

8 HS =2/(( s +1) *( s +2) ) ;


9 T =1;
10 HZ = horner ( HS ,(2/ T ) *( z -1) /( z +1) ) ;
11 disp ( HZ , H( z ) = ) ;

Scilab code Exa 5.17 HPF Design using Bilinear Transform


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

// Example 5 . 1 7
//To D e s i g n an H . P . F . m o n o t o n i c i n p a s s b a n d u s i n g
B i l i n e a r Transform
clear all ;
clc ;
close ;
ap =3; // db
as =10; // db
fp =1000; // Hz
fs =350; // Hz
f =5000;
T =1/ f ;
wp =2* %pi * fp ;
ws =2* %pi * fs ;
op =2/ T * tan ( wp * T /2) ;
os =2/ T * tan ( ws * T /2) ;
N = log ( sqrt ((10^(0.1* as ) -1) /(10^(0.1* ap ) -1) ) ) / log ( op /
os ) ;
disp ( ceil ( N ) , Order o f t h e f i l t e r , N = ) ;
s = %s ;
HS =1/( s +1) // T r a n s f e r F u n c t i o n f o r N=1
oc = op // r a d / s e c
HS1 = horner ( HS , oc / s ) ;
disp ( HS1 , N o r m a l i z e d T r a n s f e r F u n c t i o n , H( s ) = ) ;
z = %z ;
HZ = horner ( HS ,(2/ T ) *( z -1) /( z +1) ) ;
disp ( HZ , H( z ) = ) ;

98

Scilab code Exa 5.18 Bilinear Transformation Method Filter Design


1
2
3
4
5
6
7
8
9
10
11

// Example 5 . 1 8
//To Find o u t B i l i n e a r T r a n s f o r m a t i o n o f H( s ) =( s
2+4.525) /( s 2+0.692 s +0.504)
clear all ;
clc ;
close ;
s = %s ;
z = %z ;
HS =( s ^2+4.525) /( s ^2+0.692* s +0.504) ;
T =1;
HZ = horner ( HS ,(2/ T ) *( z -1) /( z +1) ) ;
disp ( HZ , H( z ) = ) ;

Scilab code Exa 5.19 Single Pole LPF into BPF Conversion
1
2
3
4
5
6
7
8
9
10
11
12
13
14

// Example 5 . 1 9
//To C o n v e r t a s i n g l e P o l e LPF i n t o BPF
clear all ;
clc ;
close ;
s = %s ;
z = %z ;
HZ =(0.5*(1+ z ^( -1) ) ) /(1 -0.302* z ^( -2) ) ;
T =1;
wu =3* %pi /4;
wl = %pi /4;
wp = %pi /6;
k = tan ( wp /2) / tan (( wu - wl ) /2) ;
a = cos (( wu + wl ) /2) / cos (( wu - wl ) /2) ;

99

15

transf = -(((( k -1) /( k +1) ) *( z ^( -2) ) ) -((2* a * k /( k +1) ) *( z


^( -1) ) ) +1) /( z ^( -2) -(2* a * k /(1+ k ) * z ^( -1) ) +(( k -1) /( k
+1) ) ) ;
16 HZ1 = horner ( HZ , transf ) ;
17 disp ( HZ1 , H( z ) o f B . P . F = ) ;

Scilab code Exa 5.29 Pole Zero IIR Filter into Lattice Ladder Structure
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

// Example 5 . 2 9
// Program t o c o n v e r t g i v e n I I R p o l e z e r o F i l t e r i n t o
L a t t i c e Ladder S t r u c t u r e .
clear all ;
clc ;
close ;
U =1;
// Z e r o A d j u s t
a (3+ U ,0+ U ) =1;
a (3+ U ,1+ U ) =13/24;
a (3+ U ,2+ U ) =5/8;
a (3+ U ,3+ U ) =1/3;
a (2+ U ,0+ U ) =1; // a (m, 0 ) =1
a (2+ U ,3+ U ) =1/3;
m =3 , k =1;
a (m -1+ U , k + U ) =( a ( m +U , k + U ) -a ( m +U , m + U ) * a ( m +U ,m - k + U ) )
/(1 - a ( m +U , m + U ) * a ( m +U , m + U ) ) ;
m =3 , k =2;
a (m -1+ U , k + U ) =( a ( m +U , k + U ) -a ( m +U , m + U ) * a ( m +U ,m - k + U ) )
/(1 - a ( m +U , m + U ) * a ( m +U , m + U ) ) ;
m =2 , k =1;
a (m -1+ U , k + U ) =( a ( m +U , k + U ) -a ( m +U , m + U ) * a ( m +U ,m - k + U ) )
/(1 - a ( m +U , m + U ) * a ( m +U , m + U ) ) ;
disp ( LATTICE COEFFICIENTS ) ;
disp ( a (1+ U ,1+ U ) , k1 ) ;
disp ( a (2+ U ,2+ U ) , k2 ) ;
disp ( a (3+ U ,3+ U ) , k3 ) ;
b0 =1;
100

24
25
26
27
28
29
30
31
32
33
34
35

b1 =2;
b2 =2;
b3 =1;
c3 = b3 ;
c2 = b2 - c3 * a (3+ U ,1+ U ) ;
c1 = b1 -( c2 * a (2+ U ,1+ U ) + c3 * a (3+ U ,2+ U ) ) ;
c0 = b0 -( c1 * a (1+ U ,1+ U ) + c2 * a (2+ U ,2+ U ) + c3 * a (3+ U ,3+ U ) ) ;
disp ( LADDER COEFFICIENTS ) ;
disp ( c0 , c 0 = ) ;
disp ( c1 , c 1 = ) ;
disp ( c2 , c 2 = ) ;
disp ( c3 , c 3 = ) ;

101

Chapter 6
FINITE IMPULSE
RESPONSE FILTERS

Scilab code Exa 6.1 Group Delay and Phase Delay


1 // Example 6 . 1
2 //MAXIMA SCILAB TOOLBOX REQUIRED FOR THIS PROGRAM
3 // Program t o C a l c u l a t e Group D e l a y and Phase D e l a y
4 // y ( n ) =0.25 x ( n )+x ( n1) +0.25 x ( n 2)
5 clear all ;
6 clc ;
7 close ;
8 //w=p o l y ( 0 , w ) ;
9 syms w ;
10 theeta = - w ;
11 gd = - diff ( theeta , w ) ; // Group D e l a y
12 pd = - theeta / w ; // Phase D e l a y
13 disp ( gd , GROUP DELAY = ) ;
14 disp ( pd , PHASE DELAY = ) ;

102

Figure 6.1: LPF Magnitude Response

103

Scilab code Exa 6.5 LPF Magnitude Response


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

// Example 6 . 5
// Program t o P l o t Magnitude R e s p o n c e o f i d e a l L . P . F .
w i t h wc =0.5 p i
//N=11
clear all ;
clc ;
close ;
N =11;
U =6;
for n = -5+ U :1:5+ U
if n ==6
hd ( n ) =0.5;
else
hd ( n ) =( sin ( %pi *( n - U ) /2) ) /( %pi *( n - U ) ) ;
end
end
[ hzm , fr ]= frmag ( hd ,256) ;
hzm_dB = 20* log10 ( hzm ) ./ max ( hzm ) ;
figure ;
plot (2* fr , hzm_dB ) ;
a = gca () ;
xlabel ( F r e q u e n c y w p i ) ;
ylabel ( Magnitude i n dB ) ;
title ( F r e q u e n c y R e s p o n s e o f FIR LPF w i t h N=11 ) ;
xgrid (2) ;

Scilab code Exa 6.6 HPF Magnitude Response


1
2

// Example 6 . 6
// Program t o P l o t Magnitude R e s p o n c e o f i d e a l H . P . F .
w i t h wc = 0.2 5 p i
104

Figure 6.2: HPF Magnitude Response

105

3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

//N=11
clear all ;
clc ;
close ;
N =11;
U =6;
for n = -5+ U :1:5+ U
if n ==6
hd ( n ) =0.5;
else
hd ( n ) =( sin ( %pi *( n - U ) ) - sin ( %pi *( n - U ) /4) ) /( %pi *( n - U ) ) ;
end
end
[ hzm , fr ]= frmag ( hd ,256) ;
hzm_dB = 20* log10 ( hzm ) ./ max ( hzm ) ;
figure
plot (2* fr , hzm_dB )
a = gca () ;
xlabel ( F r e q u e n c y w p i ) ;
ylabel ( Magnitude i n dB ) ;
title ( F r e q u e n c y R e s p o n s e o f FIR HPF w i t h N=11 ) ;
xgrid (2) ;

Scilab code Exa 6.7 BPF Magnitude Response


1
2
3
4
5
6
7

// Example 6 . 7
// Program t o P l o t Magnitude R e s p o n c e o f i d e a l B . P . F .
with
// wc1 = 0. 25 p i and wc2 = 0.7 5 p i
//N=11
clear all ;
clc ;
close ;
106

Figure 6.3: BPF Magnitude Response

107

8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

N =11;
U =6;
for n = -5+ U :1:5+ U
if n ==6
hd ( n ) =0.5;
else
hd ( n ) =( sin ( %pi *3*( n - U ) /4) - sin ( %pi *( n - U ) /4) ) /( %pi *( n U));
end
end
[ hzm , fr ]= frmag ( hd ,256) ;
hzm_dB = 20* log10 ( hzm ) ./ max ( hzm ) ;
figure
plot (2* fr , hzm_dB )
a = gca () ;
xlabel ( F r e q u e n c y w p i ) ;
ylabel ( Magnitude i n dB ) ;
title ( F r e q u e n c y R e s p o n s e o f FIR BPF w i t h N=11 ) ;
xgrid (2) ;

Scilab code Exa 6.8 BRF Magnitude Response


1
2
3
4
5
6
7
8
9
10

// Example 6 . 8
// Program t o P l o t Magnitude R e s p o n c e o f i d e a l B . R . F .
with
// wc1 = 0. 33 p i and wc2 = 0.6 7 p i
//N=11
clear all ;
clc ;
close ;
N =11;
U =6;
for n = -5+ U :1:5+ U
108

Figure 6.4: BRF Magnitude Response

109

11 if n ==6
12 hd ( n ) =0.5;
13 else
14 hd ( n ) =( sin ( %pi *( n - U ) ) + sin ( %pi *( n - U ) /3) - sin ( %pi *2*( n 15
16
17
18
19
20
21
22
23
24
25

U ) /3) ) /( %pi *( n - U ) ) ;
end
end
[ hzm , fr ]= frmag ( hd ,256) ;
hzm_dB = 20* log10 ( hzm ) ./ max ( hzm ) ;
figure
plot (2* fr , hzm_dB )
a = gca () ;
xlabel ( F r e q u e n c y w p i ) ;
ylabel ( Magnitude i n dB ) ;
title ( F r e q u e n c y R e s p o n s e o f FIR BRF w i t h N=11 ) ;
xgrid (2) ;

Scilab code Exa 6.9.a HPF Magnitude Response using Hanning Window
1
2
3
4
5
6
7
8
9
10
11
12
13
14

// Example 6 . 9 a
// Program t o P l o t Magnitude R e s p o n c e o f i d e a l H . P . F .
// u s i n g Hanning Window
// wc1 = 0. 25 p i
//N=11
clear all ;
clc ;
close ;
N =11;
U =6;
h_hann = window ( hn ,N ) ;
for n = -5+ U :1:5+ U
if n ==6
hd ( n ) =0.75;
110

Figure 6.5: HPF Magnitude Response using Hanning Window

111

15
16
17
18
19
20
21
22
23
24
25
26
27

else
hd ( n ) =( sin ( %pi *( n - U ) ) - sin ( %pi *( n - U ) /4) ) /( %pi *( n - U ) ) ;
end
h ( n ) = h_hann ( n ) * hd ( n ) ;
end
[ hzm , fr ]= frmag ( h ,256) ;
hzm_dB = 20* log10 ( hzm ) ./ max ( hzm ) ;
figure
plot (2* fr , hzm_dB )
a = gca () ;
xlabel ( F r e q u e n c y w p i ) ;
ylabel ( Magnitude i n dB ) ;
title ( F r e q u e n c y R e s p o n s e o f FIR HRF w i t h N=11
u s i n g Hanning Window ) ;
28 xgrid (2) ;

Scilab code Exa 6.9.b HPF Magnitude Response using Hamming Window
1
2
3
4
5
6
7
8
9
10
11
12
13
14

// Example 6 . 9 b
// Program t o P l o t Magnitude R e s p o n c e o f i d e a l H . P . F .
// u s i n g Hamming Window
// wc1 = 0. 25 p i
//N=11
clear all ;
clc ;
close ;
N =11;
U =6;
h_hamm = window ( hm ,N ) ;
for n = -5+ U :1:5+ U
if n ==6
hd ( n ) =0.75;
112

Figure 6.6: HPF Magnitude Response using Hamming Window

113

15
16
17
18
19
20
21
22
23
24
25
26
27

else
hd ( n ) =( sin ( %pi *( n - U ) ) - sin ( %pi *( n - U ) /4) ) /( %pi *( n - U ) ) ;
end
h ( n ) = h_hamm ( n ) * hd ( n ) ;
end
[ hzm , fr ]= frmag ( h ,256) ;
hzm_dB = 20* log10 ( hzm ) ./ max ( hzm ) ;
figure
plot (2* fr , hzm_dB )
a = gca () ;
xlabel ( F r e q u e n c y w p i ) ;
ylabel ( Magnitude i n dB ) ;
title ( F r e q u e n c y R e s p o n s e o f FIR HRF w i t h N=11
u s i n g Hamming Window ) ;
28 xgrid (2) ;

Scilab code Exa 6.10 Hanning Window Filter Design


1
2
3
4
5
6
7
8
9
10
11
12
13
14

// Example 6 . 1 0
// Program t o P l o t Magnitude R e s p o n c e o f g i v e n L . P . F .
with s p e c i f i c a t i o n s :
//N=7 ,w=p i /4
// U s i n g Hanning Window
clear all ;
clc ;
close ;
N =7;
alpha =3;
U =1;
h_hann = window ( hn ,N ) ;
for n =0+ U :1:6+ U
if n ==4
hd ( n ) =0.25;
114

Figure 6.7: Hanning Window Filter Design

115

15
16
17
18
19
20
21
22
23
24
25
26
27
28

else
hd ( n ) =( sin ( %pi *( n -U - alpha ) /4) ) /( %pi *( n -U - alpha ) ) ;
end
h ( n ) = hd ( n ) * h_hann ( n ) ;
end
[ hzm , fr ]= frmag ( h ,256) ;
hzm_dB = 20* log10 ( hzm ) ./ max ( hzm ) ;
figure
plot (2* fr , hzm_dB )
a = gca () ;
xlabel ( F r e q u e n c y w p i ) ;
ylabel ( Magnitude i n dB ) ;
title ( F r e q u e n c y R e s p o n s e o f g i v e n LPF w i t h N=7 ) ;
xgrid (2) ;

Scilab code Exa 6.11 LPF Filter Design using Kaiser Window
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

// Example 6 . 1 1
// Program t o P l o t Magnitude R e s p o n c e o f g i v e n L . P . F .
with s p e c i f i c a t i o n s :
//wp=20 r a d / s e c , ws=30 r a d / s e c , w s f =100 r a d / s e c
// a s =44.0dB , ap =0.1dB
// U s i n g K a i s e r Window
clear all ;
clc ;
close ;
wsf =100 // r a d / s e c
ws =30; // r a d / s e c
wp =20; // r a d / s e c
as =44.0 //dB
ap =0.1 //dB
B = ws - wp ;
wc =0.5*( ws + wp ) ;
116

Figure 6.8: LPF Filter Design using Kaiser Window

117

16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42

wc1 = wc *2* %pi / wsf ;


delta1 =10^( -0.05* as ) ;
delta2 =(10^(0.05* as ) -1) /(10^(0.05* as ) +1) ;
delta = min ( delta1 , delta2 ) ;
alphas = -20* log10 ( delta ) ;
alpha =0.5842*( alphas -21) ^0.4+0.07886*( alphas -21)
D =( alphas -7.95) /14.36;
N1 = wsf * D / B +1;
N = ceil ( N1 ) ;
U = ceil ( N /2) ;
win_l = window ( k r ,N , alpha ) ;
for n = - floor ( N /2) + U :1: floor ( N /2) + U
if n == ceil ( N /2) ;
hd ( n ) =0.5;
else
hd ( n ) =( sin ( %pi *( n - U ) /2) ) /( %pi *( n - U ) ) ;
end
h ( n ) = hd ( n ) * win_l ( n ) ;
end
[ hzm , fr ]= frmag ( h ,256) ;
hzm_dB = 20* log10 ( hzm ) ./ max ( hzm ) ;
figure
plot (2* fr , hzm_dB )
a = gca () ;
xlabel ( F r e q u e n c y w p i ) ;
ylabel ( Magnitude i n dB ) ;
title ( F r e q u e n c y R e s p o n s e o f g i v e n LPF u s i n g K a i s e r
Window ) ;
43 xgrid (2) ;
44 disp (h , F i l t e r C o e f f i c i e n t s , h ( n )= ) ;

Scilab code Exa 6.12 BPF Filter Design using Kaiser Window

118

Figure 6.9: BPF Filter Design using Kaiser Window

119

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37

// Example 6 . 1 2
// Program t o P l o t Magnitude R e s p o n c e o f g i v e n B . P . F .
with s p e c i f i c a t i o n s :
// wp1=40 p i r a d / s e c , wp2=60 p i r a d / s e c
// ws1=20 p i r a d / s e c , ws2=80 p i r a d / s e c
// a s =30dB , ap =0.5dB
//F=100 Hz
// U s i n g K a i s e r Window
clear all ;
clc ;
close ;
wsf =200* %pi ; // r a d / s e c
ws1 =20* %pi ; // r a d / s e c
ws2 =80* %pi ; // r a d / s e c
wp1 =40* %pi ; // r a d / s e c
wp2 =60* %pi ; // r a d / s e c
as =30 //dB
ap =0.5 //dB
B = min ( wp1 - ws1 , ws2 - wp2 ) ;
wc1 = wp1 - B /2;
wc2 = wp2 + B /2;
wc1 = wc1 *2* %pi / wsf ;
wc2 = wc2 *2* %pi / wsf ;
delta1 =10^( -0.05* as ) ;
delta2 =(10^(0.05* as ) -1) /(10^(0.05* as ) +1) ;
delta = min ( delta1 , delta2 ) ;
alphas = -20* log10 ( delta ) ;
alpha =0.5842*( alphas -21) ^0.4+0.07886*( alphas -21)
D =( alphas -7.95) /14.36;
N1 = wsf * D / B +1;
N = ceil ( N1 ) ;
U = ceil ( N /2) ;
win_l = window ( k r ,N , alpha ) ;
for n = - floor ( N /2) + U :1: floor ( N /2) + U
if n == ceil ( N /2) ;
hd ( n ) =0.4;
else
hd ( n ) =( sin (0.7* %pi *( n - U ) ) - sin (0.3* %pi *( n - U ) ) ) /( %pi *(
120

Figure 6.10: Digital Differentiator using Rectangular Window


n-U));
end
h ( n ) = hd ( n ) * win_l ( n ) ;
end
[ hzm , fr ]= frmag ( h ,256) ;
hzm_dB = 20* log10 ( hzm ) ./ max ( hzm ) ;
figure
plot (2* fr , hzm_dB )
a = gca () ;
xlabel ( F r e q u e n c y w p i ) ;
ylabel ( Magnitude i n dB ) ;
title ( F r e q u e n c y R e s p o n s e o f g i v e n LPF u s i n g K a i s e r
Window ) ;
49 xgrid (2) ;
50 disp (h , F i l t e r C o e f f i c i e n t s , h ( n )= ) ;

38
39
40
41
42
43
44
45
46
47
48

121

Scilab code Exa 6.13.a Digital Differentiator using Rectangular Window


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

// Example 6 . 1 3 a
// Program t o P l o t Magnitude R e s p o n c e o f i d e a l
d i f f e r e n t i a t o r with s p e c i f i c a t i o n s :
//N=8 ,w=p i
// u s i n g R e c t a n g u l a r window
clear all ;
clc ;
close ;
N =8;
alpha =7/2;
U =1;
h_Rect = window ( r e ,N ) ;
for n =0+ U :1:7+ U
hd ( n ) = -( sin ( %pi *( n -U - alpha ) ) ) /( %pi *( n -U - alpha ) *( n -U alpha ) ) ;
h ( n ) = hd ( n ) * h_Rect ( n ) ;
end
[ hzm , fr ]= frmag ( h ,256) ;
hzm_dB = 20* log10 ( hzm ) ./ max ( hzm ) ;
figure
plot (2* fr , hzm_dB )
a = gca () ;
xlabel ( F r e q u e n c y w p i ) ;
ylabel ( Magnitude i n dB ) ;
title ( F r e q u e n c y R e s p o n s e o f g i v e n i d e a l
d i f f e r e n t i a t o r u s i n g R e c t a n g u l a r Window , N=8 ) ;
xgrid (2)

122

Figure 6.11: Digital Differentiator using Hamming Window

123

Scilab code Exa 6.13.b Digital Differentiator using Hamming Window


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

// Example 6 . 1 3 b
// Program t o P l o t Magnitude R e s p o n c e o f i d e a l
d i f f e r e n t i a t o r with s p e c i f i c a t i o n s :
//N=8 ,w=p i
// u s i n g Hamming window
clear all ;
clc ;
close ;
N =8;
alpha =7/2;
U =1;
// Z e r o A d j u s t
h_hamm = window ( hm ,N ) ;
for n =0+ U :1:7+ U
hd ( n ) = -( sin ( %pi *( n -U - alpha ) ) ) /( %pi *( n -U - alpha ) *( n -U alpha ) ) ;
h ( n ) = hd ( n ) * h_hamm ( n ) ;
end
[ hzm , fr ]= frmag ( h ,256) ;
hzm_dB = 20* log10 ( hzm ) ./ max ( hzm ) ;
figure
plot (2* fr , hzm_dB )
a = gca () ;
xlabel ( F r e q u e n c y w p i ) ;
ylabel ( Magnitude i n dB ) ;
title ( F r e q u e n c y R e s p o n s e o f g i v e n i d e a l
d i f f e r e n t i a t o r u s i n g Hamming Window , N=8 ) ;
xgrid (2)

Scilab code Exa 6.14.a Hilbert Transformer using Rectangular Window


1

// Example 6 . 1 4 a
124

Figure 6.12: Hilbert Transformer using Rectangular Window


2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

// Program t o P l o t Magnitude R e s p o n c e o f i d e a l
H i l b e r t Transformer
// u s i n g R e c t a n g u l a r Window
//N=11
clear all ;
clc ;
close ;
N =11;
U =6;
h_Rect = window ( r e ,N ) ;
for n = -5+ U :1:5+ U
if n ==6
hd ( n ) =0;
else
hd ( n ) =(1 - cos ( %pi *( n - U ) ) ) /( %pi *( n - U ) ) ;
end
h ( n ) = hd ( n ) * h_Rect ( n ) ;
end
[ hzm , fr ]= frmag (h ,256) ;
125

Figure 6.13: Hilbert Transformer using Blackman Window


20 figure
21 plot (2* fr ,- hzm ) ;
22 a = gca () ;
23 xlabel ( F r e q u e n c y w p i ) ;
24 ylabel ( H( exp ( j w) ) ) ;
25 title ( F r e q u e n c y R e s p o n s e o f

H i l b e r t Transformer
w i t h N=11 u s i n g R e c t a n g u l a r Window ) ;
26 xgrid (2) ;

Scilab code Exa 6.14.b Hilbert Transformer using Blackman Window


1
2

// Example 6 . 1 4 b
// Program t o P l o t Magnitude R e s p o n c e o f i d e a l
H i l b e r t Transformer
126

3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

// u s i n g Blackman Window
//N=11
clear all ;
clc ;
close ;
N =11;
U =6;
for n = -5+ U :1:5+ U
h_balckmann ( n ) = 0.42+0.5* cos (2* %pi *( n - U ) /( N -1) )
+0.08* cos (4* %pi *( n - U ) /( N -1) ) ;
if n ==6
hd ( n ) =0;
else
hd ( n ) =(1 - cos ( %pi *( n - U ) ) ) /( %pi *( n - U ) ) ;
end
h ( n ) = hd ( n ) * h_balckmann ( n ) ;
end
[ hzm , fr ]= frmag (h ,256) ;
figure
plot (2* fr ,- hzm ) ;
a = gca () ;
xlabel ( F r e q u e n c y w p i ) ;
ylabel ( H( exp ( j w) ) ) ;
title ( F r e q u e n c y R e s p o n s e o f H i l b e r t T r a n s f o r m e r
w i t h N=11 u s i n g Blackman Window ) ;
xgrid (2) ;

Scilab code Exa 6.15 Filter Coefficients obtained by Sampling


// Example 6 . 1 5
// Program t o d e t e r m i n e f i l t e r
by s a m p l i n g :
3 //N=7 ,w=p i /2
4 clear all ;
5 clc ;
1
2

127

c o e f f i c i e n t s obtained

6
7
8
9
10
11
12

close ;
N =7;
U =1;
// Z e r o A d j u s t
for n =0+ U :1: N -1+ U
h ( n ) =(1+2* cos (2* %pi *( n -U -3) /7) ) / N
end
disp (h , F i l t e r C o e f f i c i e n t s , h ( n )= )

Scilab code Exa 6.16 Coefficients of Linear phase FIR Filter


1
2
3
4
5
6
7
8
9
10
11
12

// Example 6 . 1 6
// Program t o d e t e r m i n e f i l t e r c o e f f i c i e n t s o b t a i n e d
by s a m p l i n g :
//N=15
clear all ;
clc ;
close ;
N =15;
U =1;
// Z e r o A d j u s t
for n =0:1: N -1
h ( n + U ) =(1+2* cos (2* %pi *(7 - n ) / N ) +2* cos (4* %pi *(7 - n ) / N )
+2* cos (6* %pi *(7 - n ) / N ) ) / N ;
end
disp (h , F i l t e r C o e f f i c i e n t s , h ( n )= ) ;

Scilab code Exa 6.17 BPF Filter Design using Sampling Method
// Example 6 . 1 7
// Program t o d e s i g n b a n d p a s s f i l t e r w i t h f o l l o w i n g
specifications :
3 //N=7 , f c 1 =1000Hz , f c 2 =3000Hz , F=8000Hz
4 clear all ;
5 clc ;
1
2

128

Figure 6.14: Frequency Sampling Method FIR LPF Filter


6
7
8
9
10
11
12

close ;
N =7;
U =1;
// Z e r o A d j u s t
for n =0:1: N -1
h ( n + U ) =2*( cos (2* %pi *(3 - n ) / N ) + cos (4* %pi *(3 - n ) / N ) ) / N ;
end
disp (h , F i l t e r C o e f f i c i e n t s , h ( n )= ) ;

Scilab code Exa 6.18.a Frequency Sampling Method FIR LPF Filter
1

// Example 6 . 1 8 a
129

2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

// Program t o d e s i g n L . P . F . f i l t e r w i t h f o l l o w i n g
specifications :
//N=15 , wc=p i /4
clear all ;
clc ;
close ;
N =15;
U =1;
for n =0+ U :1: N -1+ U
h ( n ) =(1+ cos (2* %pi *(7 - n ) / N ) ) / N ;
end
[ hzm , fr ]= frmag ( h ,256) ;
hzm_dB = 20* log10 ( hzm ) ./ max ( hzm ) ;
figure ;
plot (2* fr , hzm_dB ) ;
a = gca () ;
xlabel ( F r e q u e n c y w p i ) ;
ylabel ( Magnitude i n dB ) ;
title ( F r e q u e n c y R e s p o n s e o f FIR LPF w i t h N=15 ) ;
xgrid (2)

Scilab code Exa 6.18.b Frequency Sampling Method FIR LPF Filter
1
2
3
4
5
6
7
8
9

// Example 6 . 1 8 b
// Program t o d e s i g n L . P . F .
specifications :
//N=15 , wc=p i /4
clear all ;
clc ;
close ;
N =15;
U =1;
for n =0+ U :1: N -1+ U

f i l t e r with f o l l o w i n g

130

Figure 6.15: Frequency Sampling Method FIR LPF Filter


10
11
12
13
14
15
16
17
18
19
20

h ( n ) =(1+ cos (2* %pi *(7 - n ) / N ) + cos (4* %pi *(7 - n ) / N ) ) / N ;


end
[ hzm , fr ]= frmag ( h ,256) ;
hzm_dB = 20* log10 ( hzm ) ./ max ( hzm ) ;
figure ;
plot (2* fr , hzm_dB ) ;
a = gca () ;
xlabel ( F r e q u e n c y w p i ) ;
ylabel ( Magnitude i n dB ) ;
title ( F r e q u e n c y R e s p o n s e o f FIR LPF w i t h N=11 ) ;
xgrid (2)

Scilab code Exa 6.19 Filter Coefficients Determination


131

Figure 6.16: Filter Coefficients Determination

132

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

// Example 6 . 1 9
// Program t o P l o t Magnitude R e s p o n c e o f g i v e n L . P . F .
with s p e c i f i c a t i o n s :
//N=13 ,w=p i /6
clear all ;
clc ;
close ;
alpha =6;
U =1;
for n =0+ U :1:12+ U
if n ==7
hd ( n ) =0.167;
else
hd ( n ) =( sin ( %pi *( n -U - alpha ) /6) ) /( %pi *( n -U - alpha ) ) ;
end
end
[ hzm , fr ]= frmag ( hd ,256) ;
hzm_dB = 20* log10 ( hzm ) ./ max ( hzm ) ;
figure
plot (2* fr , hzm_dB )
a = gca () ;
xlabel ( F r e q u e n c y w p i ) ;
ylabel ( Magnitude i n dB ) ;
title ( F r e q u e n c y R e s p o n s e o f g i v e n LPF w i t h N=13 ) ;
xgrid (2)
disp ( hd , F i l t e r C o e f f i c i e n t s , h ( n )= ) ;

Scilab code Exa 6.20 Filter Coefficients using Hamming Window


// Example 6 . 2 0
// Program t o P l o t Magnitude R e s p o n c e o f g i v e n L . P . F .
with s p e c i f i c a t i o n s :
3 //N=13 ,w=p i /6
1
2

133

Figure 6.17: Filter Coefficients using Hamming Window

134

4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

// U s i n g Hamming Window
clear all ;
clc ;
close ;
N =13;
alpha =6;
U =1;
h_hamm = window ( hm ,N ) ;
for n =0+ U :1:12+ U
if n ==7
hd ( n ) =0.167;
else
hd ( n ) =( sin ( %pi *( n -U - alpha ) /6) ) /( %pi *( n -U - alpha ) ) ;
end
h ( n ) = hd ( n ) * h_hamm ( n ) ;
end
[ hzm , fr ]= frmag ( h ,256) ;
hzm_dB = 20* log10 ( hzm ) ./ max ( hzm ) ;
figure
plot (2* fr , hzm_dB )
a = gca () ;
xlabel ( F r e q u e n c y w p i ) ;
ylabel ( Magnitude i n dB ) ;
title ( F r e q u e n c y R e s p o n s e o f g i v e n LPF w i t h N=13 ) ;
xgrid (2)
disp (h , F i l t e r C o e f f i c i e n t s , h ( n )= ) ;
disp (h , F i l t e r C o e f f i c i e n t s , h ( n )= ) ;

Scilab code Exa 6.21 LPF Filter using Rectangular Window


1
2

// Example 6 . 2 1
// Program t o P l o t Magnitude R e s p o n c e o f g i v e n L . P . F .
with s p e c i f i c a t i o n s :
135

Figure 6.18: LPF Filter using Rectangular Window


3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

//N=7 , f c =1000Hz , F=5000Hz


clear all ;
clc ;
close ;
N =7;
U =4;
h_Rect = window ( r e ,N ) ;
for n = -3+ U :1:3+ U
if n ==4
hd ( n ) =0.4;
else
hd ( n ) =( sin (2* %pi *( n - U ) /5) ) /( %pi *( n - U ) ) ;
end
h ( n ) = hd ( n ) * h_Rect ( n ) ;
end
[ hzm , fr ]= frmag ( h ,256) ;
hzm_dB = 20* log10 ( hzm ) ./ max ( hzm ) ;
figure
plot (2* fr , hzm_dB )
136

22 a = gca () ;
23 xlabel ( F r e q u e n c y w p i ) ;
24 ylabel ( Magnitude i n dB ) ;
25 title ( F r e q u e n c y R e s p o n s e o f FIR LPF w i t h N=7 ) ;
26 xgrid (2)
27 disp (h , F i l t e r C o e f f i c i e n t s , h ( n )= ) ;

Scilab code Exa 6.28 Filter Coefficients for Direct Form Structure
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

// Example 6 . 2 8
// Program t o c a l c u l a t e FIR F i l t e r c o e f f i c i e n t s f o r
t h e d i r e c t form s t r u c t u r e
// k1 =1/2 , k2 =1/3 , k3 =1/4
clear all ;
clc ;
close ;
U =1;
k1 =1/2;
k2 =1/3;
k3 =1/4;
a (3+ U ,0+ U ) =1;
a (1+ U ,1+ U ) = k1 ;
a (2+ U ,2+ U ) = k2 ;
a (3+ U ,3+ U ) = k3 ;
m =2 , k =1;
a ( m +U , k + U ) = a (m -1+ U , k + U ) + a ( m +U , m + U ) * a (m -1+ U ,m - k + U ) ;
m =3 , k =1;
a ( m +U , k + U ) = a (m -1+ U , k + U ) + a ( m +U , m + U ) * a (m -1+ U ,m - k + U ) ;
m =3 , k =2;
a ( m +U , k + U ) = a (m -1+ U , k + U ) + a ( m +U , m + U ) * a (m -1+ U ,m - k + U ) ;
disp ( a (3+ U ,0+ U ) , a ( 3 , 0 ) ) ;
disp ( a (3+ U ,1+ U ) , a ( 3 , 1 ) ) ;
disp ( a (3+ U ,2+ U ) , a ( 3 , 2 ) ) ;
disp ( a (3+ U ,3+ U ) , a ( 3 , 3 ) ) ;

137

Scilab code Exa 6.29 Lattice Filter Coefficients Determination


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

// Example 6 . 2 9
// Program t o c a l c u l a t e g i v e n FIR F i l t e r s L a t t i c e
form c o e f f i c i e n t s .
clear all ;
clc ;
close ;
U =1;
// Z e r o A d j u s t
a (3+ U ,0+ U ) =1;
a (3+ U ,1+ U ) =2/5;
a (3+ U ,2+ U ) =3/4;
a (3+ U ,3+ U ) =1/3;
a (2+ U ,0+ U ) =1; // a (m, 0 ) =1
a (2+ U ,3+ U ) =1/3;
m =3 , k =1;
a (m -1+ U , k + U ) =( a ( m +U , k + U ) -a ( m +U , m + U ) * a ( m +U ,m - k + U ) )
/(1 - a ( m +U , m + U ) * a ( m +U , m + U ) ) ;
m =3 , k =2;
a (m -1+ U , k + U ) =( a ( m +U , k + U ) -a ( m +U , m + U ) * a ( m +U ,m - k + U ) )
/(1 - a ( m +U , m + U ) * a ( m +U , m + U ) ) ;
m =2 , k =1;
a (m -1+ U , k + U ) =( a ( m +U , k + U ) -a ( m +U , m + U ) * a ( m +U ,m - k + U ) )
/(1 - a ( m +U , m + U ) * a ( m +U , m + U ) ) ;
disp ( a (1+ U ,1+ U ) , k1 ) ;
disp ( a (2+ U ,2+ U ) , k2 ) ;
disp ( a (3+ U ,3+ U ) , k3 ) ;

138

Chapter 7
FINITE WORD LENGTH
EFFECTS IN DIGITAL
FILTERS

Scilab code Exa 7.2 Subtraction Computation


1
2
3
4
5
6
7
8
9
10
11
12
13

// Example 7 . 2
//To Compute S u b t r a c t i o n
// ( a ) 0 . 2 5 from 0 . 5
clear all ;
clc ;
close ;
a =0.5;
b =0.25;
c =a - b ;
disp (c , = ,b , ,a , PART 1 ) ;
// ( a ) 0 . 5 from 0 . 2 5
d =b - a ;
disp (d , = ,a , ,b , PART 2 ) ;

139

Scilab code Exa 7.14 Variance of Output due to AD Conversion Process


1
2
3
4
5
6
7
8
9
10
11
12
13
14

// Example 7 . 1 4
//To Compare t h e V a r i e n c e o f Output due t o A/D
Conversion process
// y ( n ) =0.8 y ( n 1)+x ( n )
clear all ;
clc ;
close ;
n =8; // B i t s
r =100; // Range
Q =2* r /(2^ n ) ; // Q u a n t i z a t i o n S t e p S i z e
Ve =( Q ^2) /12;
Vo = Ve *(1/(1 -0.8^2) ) ;
disp (Q , QUANTIZATION STEP SIZE = ) ;
disp ( Ve , VARIANCE OF ERROR SIGNAL = ) ;
disp ( Vo , VARIANCE OF OUTPUT = ) ;

140

Chapter 8
MULTIRATE SIGNAL
PROCESSING

Scilab code Exa 8.9 Two Component Decomposition


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

// Example 8 . 9
//MAXIMA SCILAB TOOLBOX REQUIRED FOR THIS PROGRAM
// D e v e l o p a two component d e c o m p o s i t i o n f o r t h e
transfer function
// and d e t e r m i n e P0 ( z ) and P1 ( z )
clear all ;
clc ;
close ;
syms z a n ;
HZ =( z ) /( z - a ) ;
hn = a ^ n ; // I n v e r s e Z T r a n s f o r m o f HZ
h2n = a ^(2* n ) ;
P0 = symsum ( h2n * z ^( - n ) ,n ,0 , %inf ) ;
h2n1 = a ^(2* n +1) ;
P1 = symsum ( h2n1 * z ^( - n ) ,n ,0 , %inf ) ;
disp ( P0 , P0 ( Z ) = ) ;
disp ( P1 , P1 ( Z ) = ) ;

141

Scilab code Exa 8.10 Two Band Polyphase Decomposition


1
2
3
4
5
6
7
8
9
10
11
12

// Example 8 . 1 0
// D e v e l o p a two band p o l y p h a s e d e c o m p o s i t i o n f o r t h e
transfer function
//H( z )=z 2+ z +2/ z 2 + 0 . 8 z +0.6
clear all ;
clc ;
close ;
z = %z ;
HZ =( z ^2+ z +2) /( z ^2+0.8* z +0.6) ;
HZa = horner ( HZ , - z ) ;
P0 =0.5*( HZ + HZa ) ;
P1 =0.5*( HZ - HZa ) ;
disp ( P1 /z , + ,P0 , H( z ) = )

142

Chapter 9
STATISTICAL DIGITAL
SIGNAL PROCESSING

Scilab code Exa 9.7.a Frequency Resolution Determination


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

// Example 9 . 7 ( a )
// Program To D e t e r m i n e F r e q u e n c y R e s o l u t i o n o f
Bartlett ,
// Welch ( 5 0% O v e r l a p ) and BlackmannTukey Methods
clear all ;
clc ;
close ;
// Data
Q =10; // Q u a l i t y F a c t o r
N =1000; // S a m p l e s
//FREQUENCY RESOLUTION CALCULATION
K=Q;
rb =0.89*(2* %pi * K / N ) ;
rw =1.28*(2* %pi *9* Q ) /(16* N ) ;
rbt =0.64*(2* %pi *2* Q ) /(3* N ) ;
// D i s p l a y t h e r e s u l t i n command window
disp ( rb , R e s o l u t i o n o f B a r t l e t t Method ) ;
disp ( rw , R e s o l u t i o n o f Welch ( 5 0% o v e r l a p ) Method ) ;
disp ( rbt , R e s o l u t i o n o f BlackmannTukey Method ) ;
143

Scilab code Exa 9.7.b Record Length Determination


// Example 9 . 7 ( b )
// Program To D e t e r m i n e Record Length o f B a r t l e t t ,
// Welch ( 5 0% O v e r l a p ) and BlackmannTukey Methods
clear all ;
clc ;
close ;
// Data
Q =10; // Q u a l i t y F a c t o r
N =1000; // S a m p l e s
//RECORD LENGTH CALCULATION
lb = N / Q ;
lw =16* N /(9* Q ) ;
lbt =3* N /(2* Q ) ;
// D i s p l a y t h e r e s u l t i n command window
disp ( lb , Record Length o f B a r t l e t t Method ) ;
disp ( lw , Record Length o f Welch ( 5 0% o v e r l a p ) Method
);
17 disp ( lbt , Record Length o f BlackmannTukey Method ) ;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

Scilab code Exa 9.8.a Smallest Record Length Computation


1
2
3
4
5
6
7

// Example 9 . 8 ( a )
// Program To D e t e r m i n e S m a l l e s t Record Length o f
B a r t l e t t Method
clear all ;
clc ;
close ;
// Data
fr =0.01; // F r e q u e n c y R e s o l u t i o n
144

8 N =2400; // S a m p l e s
9 //RECORD LENGTH CALCULATION
10 lb =0.89/ fr ;
11 // D i s p l a y t h e r e s u l t i n command window
12 disp ( lb , Record Length o f B a r t l e t t Method ) ;

Scilab code Exa 9.8.b Quality Factor Computation


1
2
3
4
5
6
7
8
9
10
11
12
13

// Example 9 . 8 ( b )
// Program To D e t e r m i n e Q u a l i t y F a c t o r o f B a r t l e t t
Method
clear all ;
clc ;
close ;
// Data
fr =0.01; // F r e q u e n c y R e s o l u t i o n
N =2400; // S a m p l e s
lb =0.89/ fr ;
//QUALITY FACTOR CALCULATION
Q = N / lb ;
// D i s p l a y t h e r e s u l t i n command window
disp (Q , Q u a l i t y F a c t o r o f B a r t l e t t Method ) ;

145

Chapter 11
DIGITAL SIGNAL
PROCESSORS

Scilab code Exa 11.3 Program for Integer Multiplication


1
2
3
4
5
6
7
8
9
10
11
12
13

// Program 1 1 . 3
// Program To C a l c u l a t e t h e v a l u e o f t h e f u n c t i o n
//Y=AB
clear all ;
clc ;
close ;
// I n p u t Data
A = input ( E n t e r I n t e g e r Number A = ) ;
B = input ( E n t e r I n t e g e r Number B = ) ;
// M u l t i p l i c a t i o n Computation
Y=A*B;
// D i s p l a y t h e r e s u l t i n command window
disp (Y , Y = AB = ) ;

Scilab code Exa 11.5 Function Value Calculation

146

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

// Program 1 1 . 5
// Program To C a l c u l a t e t h e v a l u e o f t h e f u n c t i o n
//Y=AX1+BX2+CX3
clear all ;
clc ;
close ;
// Data
A =1;
B =2;
C =3;
X1 =4;
X2 =5;
X3 =6;
// Compute t h e f u n c t i o n
Y = A * X1 + B * X2 + C * X3 ;
// D i s p l a y t h e r e s u l t i n command window
disp (Y , Y = AX1+BX2+CX3 = ) ;

147

Anda mungkin juga menyukai