Digital Signal Processing - Illustration Using Python
Digital Signal Processing - Illustration Using Python
Esakkirajan
T. Veerakumar
Badri N. Subudhi
Digital
Signal
Processing
Illustration Using Python
Digital Signal Processing
S. Esakkirajan • T. Veerakumar • Badri N. Subudhi
Badri N. Subudhi
Dept of Electrical Engineering
Indian Institute of Technology Jammu
Jammu, Jammu and Kashmir, India
© The Editor(s) (if applicable) and The Author(s), under exclusive license to Springer Nature Singapore
Pte Ltd. 2024
This work is subject to copyright. All rights are solely and exclusively licensed by the Publisher, whether
the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of
illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and
transmission or information storage and retrieval, electronic adaptation, computer software, or by
similar or dissimilar methodology now known or hereafter developed.
The use of general descriptive names, registered names, trademarks, service marks, etc. in this publication
does not imply, even in the absence of a specific statement, that such names are exempt from the relevant
protective laws and regulations and therefore free for general use.
The publisher, the authors, and the editors are safe to assume that the advice and information in this
book are believed to be true and accurate at the date of publication. Neither the publisher nor the authors or
the editors give a warranty, expressed or implied, with respect to the material contained herein or for any
errors or omissions that may have been made. The publisher remains neutral with regard to jurisdictional
claims in published maps and institutional affiliations.
This Springer imprint is published by the registered company Springer Nature Singapore Pte Ltd.
The registered company address is: 152 Beach Road, #21-01/04 Gateway East, Singapore 189721,
Singapore
Motivation
v
vi Preface
Target Audience
The book comprises of 12 chapters. Chapter 1 deals with the generation and
visualization of continuous-time signals which include periodic signals,
non-stationary signals, pulse signals, and standard test signals. Chapter 2 focuses
on sampling, quantization, and reconstruction of signals. Both the time domain and
frequency domain view of sampling, the effect of undersampling, uniform and
non-uniform quantization, and different types of reconstruction like zero-order
hold, first-order hold, and sinc interpolation are discussed in this chapter.
Chapter 3 is dedicated to the generation of discrete-time signals and mathematical
operations that are performed on the discrete-time signals. In this chapter, standard
discrete-time signals like unit sample, unit step, unit ramp, exponential, and sinu-
soidal signals are generated, and mathematical operations like folding, shifting, and
scaling are performed on the generated signals. This chapter also discusses two
important signal processing operations: convolution and correlation. Different forms
of representation of discrete-time system, properties of discrete-time systems, and
responses of discrete-time systems are explained with examples in Chap. 4. One of
the important topics is signal processing which is analysis of signals and systems
using transform. Chapter 5 is devoted to transform domain analysis of signals and
systems. Different transforms discussed in this chapter include Z-transform, Fourier
transform, Short-Time Fourier transform, and Wavelet transform. Chapter 6 deals
with the design of a simple filter using pole-zero placement technique. Different
filters discussed in this chapter include moving average filter, digital resonator, notch
filter, comb filter, and all-pass filter. Chapter 7 covers the types of FIR filters and the
design of FIR filters. Three design approaches covered in this chapter include
window-based FIR filter design, frequency sampling-based FIR filter design, and
optimal FIR filter design. Chapter 8 deals with the design of IIR filter, mapping from
the analog domain to the digital domain. The types of IIR filters discussed in this
chapter include Butterworth filter, Chebyshev filter, and Elliptic filter. The mapping
techniques discussed in this chapter include the backward difference, impulse
invariant, and matched Z-transform techniques. The impact of the finite word length
effect in the FIR and IIR filters is discussed in Chap. 9. Concepts like limit cycle
vii
viii Organization of the Book
oscillation, impact of coefficient quantization, and the nature of coefficient error are
discussed in this chapter. Chapter 10 is devoted to multi-rate signal processing.
Concepts like multi-rate operators, noble identities, polyphase decomposition, filter
bank, and transmultiplexer are covered with detailed examples in this chapter.
Design of optimal and adaptive filters and their applications are discussed in
Chap. 11. This chapter discusses Wiener filter, LMS algorithm and its variants,
RLS algorithm and its applications with necessary examples. Chapter 12 is devoted
to case study which discusses the application of signal processing algorithms in
analyzing speech signal, ECG signal, and power line signal.
Acknowledgments
The authors are always thankful to the Almighty for guiding them in their persever-
ance and blessing them with achievements. The authors wish to thank Shri
L. Gopalakrishnan, Managing Trustee, PSG Institutions; Dr. K. Prakasan, Principal,
PSG College of Technology, Coimbatore; Prof. Gopal Mugeraya, Director, National
Institute of Technology, Goa; and Prof. Manoj Singh Gaur, Director, IIT Jammu for
their wholehearted cooperation and constant encouragement given in this successful
endeavor.
Dr. S. Esakkirajan would like to express his gratitude to his parents,
Mr. G. Sankaralingam, and Mrs. S. Saraswathi, wife Mrs. K. Sornalatha and sons
Azhaku Vignesh and Krishnan, for their love and encouragement. He would like to
thank his students Mr. Senthil Murugan, Mr. Vijay Bhaskar, Ms. B. Keerthiveena,
and Mr. Upendra Vishwanath for their continual support and encouragement.
Dr. T. Veerakumar would like to thank his life guru Dr. S. Esakkirajan for his
guidance, motivation, and constant support in completing this work. He also wants
to thank his parents, Mr. Thangaraj and Mrs. Muniammal, brothers Mr. Tamilselvan
and Mr. Karl Marks, and sister, Mrs. Muniponnu, for their wholehearted support.
Finally, he would like to thank his wife, Banupriya, and daughters, Harini and
Ishani, for tolerating his late coming home and their support in completing this
work on time.
Dr. Badri Narayan Subudhi would like to express his gratitude to his parents,
Mr. Ananda Chandra Subudhi and Ms. Subasini Subudhi, wife Ms. Bandanarani
Subudhi and children: Aaradhya and Anwit for their unflagging love and support
throughout life. He would also like to thank his brother Mr. Rashimi Ranjan Subudhi
and Prof. Sarat Kumar Patra for their encouragement and support during his life.
ix
Contents
Appendix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 497
Chapter 1: Generation Of Continuous-Time Signals . . . . . . . . . . . . . . 497
Answers to PreLab Questions . . . . . . . . . . . . . . . . . . . . . . . . . 497
Answers to Objective Questions . . . . . . . . . . . . . . . . . . . . . . . . 499
Chapter 2: Sampling and Quantization of Signals . . . . . . . . . . . . . . . . 500
Answers to PreLab Questions . . . . . . . . . . . . . . . . . . . . . . . . . 500
Answers to Objective Questions . . . . . . . . . . . . . . . . . . . . . . . . 501
Chapter 3: Generation and Operation on Discrete-Time Sequence . . . . 501
Answers to PreLab Questions . . . . . . . . . . . . . . . . . . . . . . . . . 501
Answers to Objective Questions . . . . . . . . . . . . . . . . . . . . . . . . 503
Chapter 4: Discrete-Time Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . 503
Answers to PreLab Questions . . . . . . . . . . . . . . . . . . . . . . . . . 503
Answers to Objective Questions . . . . . . . . . . . . . . . . . . . . . . . . 506
Chapter 5: Transforms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 506
Answers to PreLab Questions . . . . . . . . . . . . . . . . . . . . . . . . . 506
Answers to Objective Questions . . . . . . . . . . . . . . . . . . . . . . . . 508
Chapter 6: Filter Design Using Pole-Zero Placement Method . . . . . . . . 508
Answers to PreLab Questions . . . . . . . . . . . . . . . . . . . . . . . . . 508
Answers to Objective Questions . . . . . . . . . . . . . . . . . . . . . . . . 509
Chapter 7: FIR Filter Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 509
Answers to PreLab Questions . . . . . . . . . . . . . . . . . . . . . . . . . 509
Answers to Objective Questions . . . . . . . . . . . . . . . . . . . . . . . . 511
Chapter 8: Infinite Impulse Response Filter . . . . . . . . . . . . . . . . . . . . . 511
Answers to PreLab Questions . . . . . . . . . . . . . . . . . . . . . . . . . 511
Answers to Objective Questions . . . . . . . . . . . . . . . . . . . . . . . . 513
Chapter 9: Quantization Effect of Digital Filter Coefficients . . . . . . . . . 513
Answers to PreLab Questions . . . . . . . . . . . . . . . . . . . . . . . . . 513
Answer to Objective Questions . . . . . . . . . . . . . . . . . . . . . . . . 514
Chapter 10: Multirate Signal Processing . . . . . . . . . . . . . . . . . . . . . . . 515
Answers to PreLab Questions . . . . . . . . . . . . . . . . . . . . . . . . . 515
Answers to Objective Questions . . . . . . . . . . . . . . . . . . . . . . . . 517
Chapter 11: Adaptive Signal Processing . . . . . . . . . . . . . . . . . . . . . . . 517
Answers to PreLab Questions . . . . . . . . . . . . . . . . . . . . . . . . . 517
Answers to Objective Questions . . . . . . . . . . . . . . . . . . . . . . . . 518
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 519
About the Authors
Industrial Research, India, in 2011. He received the Bose-Ramagnosi Award for the
year 2010 from DST, Government of India, under India-Trento Programme for
Advanced Research (ITPAR). He was a visiting scientist at the University of Trento,
Italy, during August 2010 to February 2011. His research interests include Video
Processing, Image Processing, Medical Image Processing, Machine Learning, Pat-
tern Recognition, and Remote Sensing Image Analysis. He co-authored the textbook
titled Digital Signal Processing, published by Tata McGraw Hill. He has published
around 80 research papers in reputed journals and conferences. He is a senior
member of IEEE.
Chapter 1
Generation of Continuous-Time Signals
Learning Objectives
After completing this chapter, the reader should be able to
• Simulate and visualize periodic continuous-time signals.
• Simulate, visualize and interpret non-stationary signals.
• Simulate and visualize standard continuous-time test signals.
• Simulate and visualize continuous-time pulse signals.
© The Author(s), under exclusive license to Springer Nature Singapore Pte Ltd. 2024 1
S. Esakkirajan et al., Digital Signal Processing,
https://doi.org/10.1007/978-981-99-6752-0_1
2 1 Generation of Continuous-Time Signals
Sawtooth wave
Triangular wave
PreLab Questions
1. Give a few examples of real-world signals, which are continuous in nature.
2. Mention the built-in functions available in ‘numpy’ library in python to generate
data points of specific length to define the independent variable like time.
3. Explain the significance of a sinusoidal signal in signal processing.
4. What do you understand by the term ‘phase’ of a signal?
5. Give a few examples of multidimensional signals.
6. Cite an example where the signal or a process can be modelled as a real
exponential function.
7. Mention a few significant features of complex exponential signals.
8. Mention the salient features of the ‘sinc’ function in signal processing. Is it an
even or odd function?
9. Distinguish between stationary and non-stationary signal. Give examples of
each category of signal.
10. List a few significant properties of the Gaussian function (signal).
A signal corresponds to a physical quantity that varies with time, space, etc. Signals
are represented mathematically as a function of one or more independent variables.
The continuous-time signals are defined for a continuum of values of the indepen-
dent variable. The continuous-time signal is generally represented as x(t). Speech
signal as a function of time is an example of continuous-time signal. The signal can
1.1 Continuous-Time Signal 3
In the above equation, ‘A’ represents the amplitude of the signal, ‘f’ denotes the
frequency of the signal and ‘ϕ’ indicates the phase of the signal. To generate
sinusoidal signal, one should define three parameters: amplitude, frequency and
phase. The independent-variable is ‘time (t)’. In amplitude modulation, the ampli-
tude of the carrier is changed in accordance with the message, while the frequency
and phase are kept constant. In frequency modulation, the frequency of the carrier is
changed in accordance with the signal, while the amplitude and phase are kept
constant. In phase modulation, the phase of the carrier is changed in accordance with
the signal, while the amplitude and frequency are kept constant.
The steps involved in the generation of sinusoidal signal are summarized below:
Step 1: Defining the independent variable
The built-in function ‘np.linspace()’ is used to generate the independent
variable, which is the time axis.
Step 2: Defining the parameters of the sine wave
In this step, the three parameters of sine wave, namely, amplitude, frequency
and phase are defined.
Step 3: Generation of sinusoidal signal
In this step, the mathematical expression to generate a sine wave is given by
4 1 Generation of Continuous-Time Signals
xðt Þ = A sinð2πft þ ϕÞ
Built-In Libraries
The built-in libraries used in the program are (1) Numpy and (2) Matplotlib. The
‘numpy’ is a general purpose array-processing package. In this program, the numpy
library is used to create array (np.linspace), and it is used to perform mathematical
function (np.sin). Matplotlib is a data visualization library used to visualize the
generated sinusoidal signal. The built-in functions used in the program is given in
Table 1.1.
The python code used to generate sinusoidal waveform is shown in Fig. 1.1, and
the corresponding output is shown in Fig. 1.2.
Inference
From Fig. 1.1, the following inferences can be made with respect to python code:
1.1 Continuous-Time Signal 5
1. The libraries used in the program are (a) Numpy and (b) Matplotlib.
2. The built-in function ‘np.linspace()’ is used to generate the independent variable,
which is the time axis. In this program, 1000 data points are generated between
‘0’ and ‘1’.
From Fig. 1.2, it is possible to infer the following:
1. The phase of the signal is ‘0’; this implies that the waveform starts from the
origin.
2. The amplitude of the sine wave is 5 V. The waveform oscillates between -5
and +5.
3. The frequency of the generated waveform is 5 Hz. The number of oscillations per
second is 5.
Tasks
1. Write a python code to mark the peak of the sinusoidal signal.
2. Write a python code to compute the number of zero crossing of the sine wave.
Experiment 1.2 Sinusoidal Signal with Different Phase
In this experiment, the objective is to generate sine wave of amplitude = 1 V,
frequency = 5 Hz and four different phase angles, namely, 0°, 90°, 180° and 270°.
The python code, which does this task, is shown in Fig. 1.3, and the corresponding
output is shown in Fig. 1.4. The built-in libraries used in the program are (1) Numpy
and (2) Matplotlib.
6 1 Generation of Continuous-Time Signals
Fig. 1.3 Python code to generate sine wave with different phase angle
) = 0° ) = 90°
1 1
Amplitude (V)
Amplitude (V)
0 0
–1 –1
0.00 0.25 0.50 0.75 1.00 0.00 0.25 0.50 0.75 1.00
Time (t) Time (t)
) = 180° ) = 270°
1 1
Amplitude (V)
Amplitude (V)
0 0
–1 –1
0.00 0.25 0.50 0.75 1.00 0.00 0.25 0.50 0.75 1.00
Time (t) Time (t)
Inference
From the python code shown in Fig. 1.3, the following inferences can be made. The
phase angle is varied as 0°, 90°, 180° and 270°. The amplitude of the sine wave is
fixed as 1 V and the frequency is fixed as 5 Hz.
1.1 Continuous-Time Signal 7
From Fig. 1.4, it is possible to infer that the starting point of the waveform is
different for different phase angle. The phase parameter determines the time loca-
tions of the maxima and minima of the sinusoid.
Tasks
1. Write a python code to generate a sinusoidal signal whose phase is varying in a
random manner. Assume the phase angle ‘Φ’ to follow uniform distribution in the
range -1 to +1.
2. Write a python code to generate a sinusoidal signal, whose frequency is varying
in a random manner. Assume the frequency ‘f’ to follow uniform distribution in
the range -1 to +1.
Experiment 1.3 Generation of Three-Phase Sinusoidal Signal
The expressions for three-phase sinusoidal signals are given by
x1 ðt Þ = A sinð2πft Þ ð1:2Þ
x2 ðt Þ = A sinð2πft - 120 ° Þ ð1:3Þ
x3 ðt Þ = A sinð2πft - 240 ° Þ ð1:4Þ
The amplitude and frequency of the three waveforms are equal. The phase shift
between the signals is 120°. The python code, which generates the three-phase
sinusoidal waveforms, is shown in Fig. 1.5, and the corresponding output is
shown in Fig. 1.6.
8 1 Generation of Continuous-Time Signals
Inference
From the python code to generate the three-phase sinusoidal signal, it is possible to
observe that the amplitude of each signal is 1 V and frequency is 5 Hz. The phase
shift between the signals is 120°.
Task
1. Change the value of amplitude A1, A2 and A3 of three-phase sinusoidal signal in
the python code given in Fig. 1.5, and comment on the output waveform.
Exponential function is of two types: (1) real exponential function and (2) complex
exponential function. The real exponential function can be either an increasing
function or it could be a decreasing function. The price of petrol is an example of
exponentially increasing function. Radioactive decay is an example of exponentially
decaying function.
Complex exponential function is of interest in signal processing. Complex
exponential function is the basis function of Fourier transform. It is possible to
obtain sine wave and cosine wave from complex exponential function. It is an Eigen
function for a linear time-invariant system.
Experiment 1.4 Generation of Real Exponential Signal
The general expression for the real exponential signal is given by
1.1 Continuous-Time Signal 9
where ‘C’ and ‘α’ are real. If ‘α’ is greater than zero, it is exponentially growing
function. If ‘α’ is less than zero, it is exponentially decreasing or decaying function.
The built-in functions used in the program are given in Table 1.2.
The python code, which generates exponentially growing and decaying function
for α = 2 and α = -2, is shown in Fig. 1.7, and the corresponding output is shown in
Fig. 1.8.
Inference
In exponentially growing function, the value of the function (amplitude of the
function) increases with an increase in time. In contrast, in exponentially decaying
function, the amplitude of the function decays with respect to time.
Task
1. Write a python code to generate two real exponential functions (one growing and
another decaying) with different amplitudes, and add these two functions. Com-
ment on the observed result.
Experiment 1.5 Forward Characteristics of PN Junction Diode
The equation of current through the diode is given by
10 1 Generation of Continuous-Time Signals
VD
I D = I s eηV T - 1 ð1:6Þ
In Eq. (1.6), Is represents the reverse saturation current; VD is the voltage drop
across the diode and ID is the current through the diode; VT is the volt-equivalent of
temperature, which is 26 mV at room temperature; and η is the ideality factor, which
is material dependent. The python code, which simulates the V–I characteristics of
PN junction diode by assuming η = 1, VT = 26 mV, and Is = 1 mA is shown in
Fig. 1.9, and the corresponding output is shown in Fig. 1.10.
Inference
From the forward characteristics shown in Fig. 1.10, it is possible to observe that the
diode current increases after crossing the threshold voltage, generally termed ‘knee
voltage’. If one considers the current through the diode as a function, then the
function is an exponentially growing function.
Experiment 1.6 Radioactive Decay Function
The equation of radioactive decay is given by N(t) = N0e-λt. The python code, which
implements this equation, is shown in Fig. 1.11, and the corresponding output is
shown in Fig. 1.12.
1.1 Continuous-Time Signal 11
Fig. 1.9 Python code to plot the forward characteristics of PN junction diode
4
Forward current
0
0.0 0.2 0.4 0.6 0.8 1.0
Forward voltage
Inference
From Fig. 1.12, it is possible to observe that the radioactive decay activity can be
modelled by an exponentially decaying function.
Experiment 1.7 Complex Exponential Function
Generate two complex exponential signals x1(t) = ejΩt and x2(t) = e-jΩt. Here the
frequency of the signal is fixed as f = 5 Hz. After signal generation, extract the
magnitude and phase of the two signals, and comment on the observed output.
The built-in functions used in the python program are given in Table 1.3.
12 1 Generation of Continuous-Time Signals
350
300
Counts per second
250
200
150
100
50
0
0 10 20 30 40 50 60 70 80
Time (Hours)
ej:t e-j:t
Amplitude (V)
Amplitude (V)
1 1
0 0
–1 –1
–1 0 1 –1 0 1
Time (t) Time (t)
|e j:t| |e-j:t|
Magnitude (V)
Magnitude (V)
1.05 1.05
1.00 1.00
0.95 0.95
–1 0 1 –1 0 1
Time (t) Time (t)
)(x1(t)) )(x2(t))
Phase( ° )
Phase( ° )
100 100
0 0
–100 –100
–1 0 1 -1 0 1
Time (t) Time (t)
The python code, which performs the task mentioned above, is shown in
Fig. 1.13, and the corresponding output is shown in Fig. 1.14.
Inferences
From Figs. 1.13 and 1.14, the following inferences can be made:
1. Two complex exponential signals x1(t) = ej2πft x2(t) = e-j2πft with the frequency
value f = 5 Hz are generated. The signals x1(t) and x2(t) look alike.
2. The magnitude and phase responses of the two signals are plotted. The magnitude
of the signal x1(t) = ejΩt is given by jx1 ðt Þj = cos 2 ðΩt Þ þ sin 2 ðΩt Þ = 1.
Similarly, the magnitude of the signal x2(t) = e-jΩt is given by
j x2 ð t Þ j = cos 2 ðΩt Þ þ sin 2 ðΩt Þ = 1. Thus, the magnitudes of the two signals
are alike.
sinðΩt Þ
3. The phase of the signal x1(t) = ejΩt is expressed as ϕðx1 ðt ÞÞ = tan - 1 cosðΩt Þ .
-1
Upon simplifying the expression, we get ϕ(x1(t)) = tan (tan(Ωt)), which results
in ϕ(x1(t)) = Ωt. The phase of the signal x2(t) = e-jΩt is expressed as
sinðΩt Þ
ϕðx1 ðt ÞÞ = tan - 1 - cosðΩt Þ . Upon simplifying the expression, we get ϕ-
-1
(x1(t)) = tan (- tan (Ωt)), which results in ϕ(x1(t)) = - Ωt. The phases of
the two signals are different. This implies that the signal ej2πft and e-j2πft repre-
sents two phasors, rotating in the opposite direction.
Experiment 1.8 Generation of ‘Sine’ and ‘Cosine’ Functions from ‘Complex
Exponential Function’
This experiment aims to prove that sinusoidal signal can be generated through two
phasors rotating in the opposite direction. Mathematically it is expressed as
1.1 Continuous-Time Signal 15
Cosine wave
1
Amplitude (V)
0
–1
0.0 0.2 0.4 0.6 0.8 1.0
Time (t)
Sine wave
1
Amplitude (V)
–1
0.0 0.2 0.4 0.6 0.8 1.0
Time (t)
Fig. 1.16 Sine and cosine wave from complex exponential functions
- jΩt - jΩt
cosðΩt Þ = e þe2 and sinðΩt Þ = e -2je . The python code, which generates the
jΩt jΩt
cosine and sine wave using a rotating phasor, is shown in Fig. 1.15, and the
corresponding output is shown in Fig. 1.16.
Inference
From Fig. 1.16, it is possible to observe that there is a phase difference of 90°
between the sine and cosine waveforms.
Task
1. Add the square of the sine and cosine wave obtained in Experiment 1.8, and plot
the resultant waveform. Comment on the observed output. [Hint:
sin2(θ) + cos2(θ) = 1]
Experiment 1.9 Modulating Sinusoidal Signal with an Exponential Signal
This experiment discusses the sinusoidal signal multiplied with a growing and
decaying real exponential signal. The python code, which accomplishes this task,
is shown in Fig. 1.17, and the corresponding output is shown in Fig. 1.18.
Inference
The following inferences can be made from Fig. 1.18
1. The sinusoidal signal amplitude varies between -1 and +1.
2. Upon multiplying the sinusoidal signal with growing exponential, the amplitude
value increases; hence, the plot is shown in the range -5 to +5.
3. Upon multiplying the sinusoidal signal with decaying exponential, the amplitude
of the input sinusoidal signal decreases, which is shown between -0.5 and +0.5.
16 1 Generation of Continuous-Time Signals
A stationary signal is one whose statistical characteristics do not change with respect
to time. If the signal characteristics change with respect to time, then it is a non-
stationary signal. Example of non-stationary signal is a chirp signal whose frequency
varies with respect to time. Most of the real-world signals, like the alarm sound from
the clock or the sound of an ambulance, are non-stationary. In this section, few
stationary and non-stationary signals are generated.
Experiment 1.10 Generation of Stationary and Non-stationary Signal
This experiment deals with the generation of stationary and non-stationary signal.
The expression for stationary signal is given by
x1 ðt Þ = sinð2πft Þ ð1:7Þ
The frequency of the signal changes with respect to time; hence, it is considered
as non-stationary. The python code, which generates the two signals and the
corresponding output, is shown in Fig. 1.19, and Fig. 1.20.
Stationary signal
1
Amplitude
–1
0.0 0.2 0.4 0.6 0.8 1.0
Time (t)
Non-stationary signal
1
Amplitude
–1
0.0 0.2 0.4 0.6 0.8 1.0
Time (t)
Inference
By observing Fig. 1.20, it is possible to conclude that the frequency of the stationary
signal does not change with respect to time. On the other hand, the frequency of the
non-stationary signal increases with time increases.
Experiment 1.11 Generation of Non-stationary Sinusoidal Signal
The objective of this experiment is to append sinusoidal signals of different frequen-
cies. Signal-1 is generated with 5 Hz frequency appearing first, DC signal next and
10 Hz frequency occurs last. Signal-2 is obtained by interchanging the first and last
part of signal-1, which means high frequency occurs first and low frequency occurs
next. The python code, which performs this task, is shown in Fig. 1.21, and the
corresponding output is shown in Fig. 1.22.
Inference
The signals in Fig. 1.22 are considered as non-stationary, because the signal fre-
quency varies with respect to time. Signal-1 and Signal-2 contain the same frequency
components at different instants.
Experiment 1.12 Generation of Chirp Signal
The objective of this experiment is to generate chirp signal. The chirp signal can be
considered as a frequency swept sinusoidal signal. Four different methods of fre-
quency sweep are (1) linear, (2) quadratic, (3) logarithmic and (4) hyperbolic. In this
experiment, the frequency sweep is from 10 Hz to 1 Hz, as considered. The python
code, which generates the chirp signals, are shown in Fig. 1.23, and the
corresponding output is shown in Fig. 1.24.
1.2 Non-stationary Signal 19
import numpy as np
import matplotlib.pyplot as plt
t1=np.linspace(0,1,100)
#Defining signal frequencies
f1,f2,f3=0,5,10
#Generation of signal-1
x1=np.sin(2*np.pi*f2*t1)
#Generation of signal-2
x2=np.sin(2*np.pi*f1*t1)
x3=np.sin(2*np.pi*f3*t1)
x=np.concatenate([x1,x2,x3])
y=np.concatenate([x3,x2,x1])
#Plotting the result
t=np.linspace(0,1,300)
plt.subplot(2,1,1),plt.plot(t,x),plt.xlabel('Time(t)'),plt.ylabel('Amplitude (V)')
plt.title('Signal-1'),plt.subplot(2,1,2),plt.plot(t,y)
plt.xlabel('Time (t)'),plt.ylabel('Amplitude (V)'),plt.title('Signal-2')
plt.tight_layout()
Signal-1
1
Amplitude (V)
–1
0.0 0.2 0.4 0.6 0.8 1.0
Time (t)
Signal-2
1
Amplitude (V)
–1
0.0 0.2 0.4 0.6 0.8 1.0
Time (t)
Inference
From Fig. 1.24, it is possible to observe that the frequency varies with respect to time
in all four types of chirp signals; hence, they are considered non-stationary signals.
20 1 Generation of Continuous-Time Signals
Amplitude (V)
0 0
–1 –1
0.0 2.5 5.0 7.5 10.0 0.0 2.5 5.0 7.5 10.0
Time (t) Time (t)
Amplitude (V)
0 0
–1 –1
0.0 2.5 5.0 7.5 10.0 0.0 2.5 5.0 7.5 10.0
Time (t) Time (t)
Amplitude (V)
1 1
0 0
–1 –1
–2 –2
0.00 0.25 0.50 0.75 1.00 0.00 0.25 0.50 0.75 1.00
Time (t) Time (t)
Amplitude (V)
1 1
0 0
–1 –1
–2 –2
0.00 0.25 0.50 0.75 1.00 0.00 0.25 0.50 0.75 1.00
Time (t) Time (t)
Triangle and sawtooth waveforms are useful for exploring non-linearity in the
circuit. A triangle waveform has uniform rise and fall time, whereas in a sawtooth
waveform, the rise and fall times are markedly different.
Experiment 1.14 Generation of Sawtooth and Triangular Waveforms
The python code, which generates the sawtooth waveform of frequency 5 Hz, is
shown in Fig. 1.27, and the corresponding output is shown in Fig. 1.28.
Inference
When the width is 0.5, the sawtooth waveform turns out to be a triangular waveform.
In square waveform, the state change from -1 to +1 and from +1 to -1 occurs
instantaneously, whereas, in triangular waveform, the change of state from -1 to +1
and from +1 to -1 occurs gradually.
Amplitude (V)
1 1
0 0
–1 –1
–2 –2
0.00 0.25 0.50 0.75 1.00 0.00 0.25 0.50 0.75 1.00
Time (t) Time (t)
Amplitude (V)
1 1
0 0
–1 –1
–2 –2
0.00 0.25 0.50 0.75 1.00 0.00 0.25 0.50 0.75 1.00
Time (t) Time (t)
sin πt
xð t Þ = , -1<t<1 ð1:9Þ
πt
Sinc function
1.0
0.8
0.6
Amplitude
0.4
0.2
0.0
–0.2
Task
1. Write a python code to prove that sinc function is an even function.
Task
1. Write a python code to illustrate the fact that convolution of two rectangular pulse
signals results in a triangular pulse.
1 ðt - μÞ2
xð t Þ = p e - 2σ2 ð1:10Þ
2π σ
where ‘μ’ represents the mean and ‘σ’ represents the standard deviation. Fourier
transform of a Gaussian function results in another Gaussian function. The product
of two Gaussian functions is a Gaussian function. Gaussian window is an optimal
window for time-frequency localization. Smoothening by Gaussian function is
widely employed in image processing.
Experiment 1.17 Generation of Gaussian Function
The Gaussian function is widely used in signal processing, image processing and
communication fields. The expression for Gaussian function with the mean value ‘μ’
ðt - μ Þ2
and standard deviation ‘σ’ is given by xðt Þ = p1 e - 2σ 2 . This experiment aims to
2π σ
1.3 Non-sinusoidal Waveform 27
generate Gaussian function for different values of standard deviation, namely, 0.01,
0.5, 1 and 10. The mean value is taken as zero. The python code, which generates the
Gaussian function, is shown in Fig. 1.33, and the corresponding output is shown in
Fig. 1.34.
Inference
From Fig. 1.34, it is possible to observe the following facts:
28 1 Generation of Continuous-Time Signals
1. The Gaussian function is characterized by two parameters, which are mean and
standard deviation.
2. The mean value of the Gaussian function is zero; hence, the maximum value
occurs at the origin.
3. With an increase in the value of standard deviation, the narrower the Gaussian
function.
Task
1. Write a python code to prove that the multiplication of two Gaussian functions
results in a Gaussian function.
Experiment 1.18 Hearing a Sinusoidal Signal
Human ears can hear sound in the frequency range from 20 Hz to 20 kHz. In this
experiment, sine wave of particular frequency is heard as a tone. The sampling
frequency is chosen as 8000 Hz, and the signal frequency is chosen as 1000 Hz. The
library functions used are (1) Numpy and (2) Sounddevice. The built-in function in
sound device library (sd.play) is used to play the sound. The python code, which
generates the sinusoidal tone, is shown in Fig. 1.35. The user can hear the audio
using headphone.
Inference
From Fig. 1.35, the following inferences can be made:
1. The signal frequency is 1000 Hz, and the sampling frequency is 8000 Hz.
2. The library used to hear the audio is ‘sounddevice’ library.
3. The built-in function (sd.play) is used to hear the audio.
Task
1. Human ear can hear an audio signal whose frequency is between 20 Hz and
20 kHz. Generate 10 Hz sinusoidal waveform; try to hear the waveform. It should
not be audible. Now increase the frequency of sine wave to 100 Hz; now it should
be possible to hear the sinusoid as a single note.
Experiment 1.19 Hearing Amplitude Modulated Sinusoidal Signal
The impact of modulating the amplitude of the sinusoidal signal is observed in this
experiment. In this experiment, the amplitude of the sinusoidal signal is modulated
by both exponentially decaying and growing functions. The python code, which
1.3 Non-sinusoidal Waveform 29
performs this task is shown in Fig. 1.36. The built-in functions used in the program
are summarized in Table 1.4.
Inference
The following inferences can be made from Fig. 1.36:
1. The signal ‘x1’ refers to a sine wave modulated by an exponentially decaying
function.
2. The signal ‘x2’ refers to a sine wave modulated by an exponentially growing
function.
Experiment 1.20 Generation of Amplitude Modulated Signal
In amplitude modulation, the amplitude of the carrier signal is varied in accordance
with the message signal. The expression for amplitude modulated signal is given by
In the above expression, ‘m’ denotes the modulation index, fm represents the
frequency of the modulating signal and fc denotes frequency of the carrier signal.
The python code, which generates the amplitude modulated signal for different
modulating indices, is shown in Fig. 1.37, and the corresponding output is shown
in Fig. 1.38.
Inference
From Figs. 1.37 and 1.38, the following inferences can be drawn:
30 1 Generation of Continuous-Time Signals
#Amplitude modulation
import numpy as np
import matplotlib.pyplot as plt
t=np.linspace(0,1,1000)
fm=10 #Frequency of modulating signal
fc=100 #Frequency of carrier signal
message=np.sin(2*np.pi*fm*t)
carrier=np.sin(2*np.pi*fc*t)
m=[0.25,0.5,1,1.5] #modulation index
for i in range(len(m)):
mod_sig=(1+m[i]*message)*carrier
plt.subplot(2,2,i+1),plt.plot(t,mod_sig)
plt.xlabel('Time'),plt.ylabel('Amplitude')
plt.title('Modulated signal with m={}'.format(m[i]))
plt.tight_layout()
1. The frequency of the message signal is 10 Hz; the frequency of the carrier signal
is 100 Hz. The modulation index is varied as 0.25, 0.5, 1.0 and 1.5.
2. It is possible to observe that the amplitude of the carrier is changed in accordance
with the message signal.
1.3 Non-sinusoidal Waveform 31
3. Modulation index less than one corresponds to under modulated signal. Modu-
lation index greater than one corresponds to over modulated signal. Modulation
index equal to one corresponds to perfect modulation.
Exercises
1. Generate the following sinusoidal signal x(t) = A sin (2πft + ϕ) with the
amplitude A = 2 V, frequency f = 10 Hz and phase ϕ = 0. Let the length of
the signal be 100 samples. Store this signal in your system in a particular folder
along with the time stamp in an Excel sheet. From the Excel sheet, read the data
and the time stamp and plot the signal.
2. Write a python code to generate the sinusoidal signal of 1 V amplitude, 5 Hz
frequency and phase ϕ = 0. Mark the positive peak of the waveform. That is the
positive peak of the waveform should be marked with ‘x’ mark.
3. Write a python code to compute the number of zero crossings of sine wave of 2 V
amplitude, 5 Hz frequency and phase ϕ = 0.
4. Write a python code to generate the seven nodes ‘sa’, ‘re’, ‘ga’ and ‘ma’. Use the
sounddevice library to play the seven notes.
ðt - μÞ2
5. Generate the Gaussian function, which is given by xðt Þ = p2π
1
σ
e - 2σ2 for differ-
ent mean values μ = 0, 1, 2, 4 with the fixed standard deviation value σ = 1. Use
subplot to plot the generated Gaussian functions.
Objective Questions
1. What will the signal’s length be if the following code is executed?
A. 10
B. 50
C. 75
D. 100
2. What will be the magnitude of the variables ‘x’ and ‘y’ if the following code
segment is executed?
A. 1 and 0, respectively
B. -1 and 1, respectively
C. 0 and 1, respectively
D. 1 and -1, respectively
3. What will be the output plot if the following segment of code is executed?
32 1 Generation of Continuous-Time Signals
A. DC signal of magnitude 1
B. DC signal of magnitude 5
C. Sine wave of frequency 5 Hz
D. Cosine wave of frequency 5 Hz
4. What will be stored in the variable ‘z’ if executing the following code segment?
A. 1000
B. 2000
C. 4000
D. 8000
9. Identify the statement that is WRONG with respect to sinc function
A. Sinc function is an even function.
B. Sinc function is an odd function.
C. Fourier transform of sinc function will result in a rectangular function.
D. Sinc function can be used for signal interpolation.
10. The magnitude of the function x(t) = e-jΩt is
A. 1
B. 0
C. -1
D. Infinity
Bibliography
1. Alan V. Oppenheim, and Alan S. Willsky. “Signals and Systems”, Prentice Hall, 1996.
2. Simon Haykin, and Bary Van Veen, “Signals and Systems”, Wiley, 2005.
3. Hwei P. Hsu, “Signals and Systems”, Schaum’s outline series, McGraw Hill Education, 2017.
4. Charles L. Phillips, John M. Parr, and Eve A. Riskin, “Signals, Systems, and Transforms”,
Pearson, 2013.
5. Mark Lutz, “Learning Python”, O’Reilly Media, 2013.
Chapter 2
Sampling and Quantization of Signals
Learning Objectives
After reading this chapter, the reader is expected to
• Simulate and visualize standard discrete-time signals.
• Simulate and visualize arbitrary discrete-time signals.
• Perform different mathematical operations on discrete-time signals.
• Implement convolution and correlation operations and interpret the obtained
results.
© The Author(s), under exclusive license to Springer Nature Singapore Pte Ltd. 2024 35
S. Esakkirajan et al., Digital Signal Processing,
https://doi.org/10.1007/978-981-99-6752-0_2
36 2 Sampling and Quantization of Signals
Time-domain
view of sampling Zero order Hold
Uniform Non-uniform
quantization quantization
Frequency-domain First order Hold
view of sampling
Mid-tread
µ-law
quantizer
companding Ideal Interpolation
Mid-rise A-law
quantizer companding
PreLab Questions
1. Mention the steps involved in converting the analogue signal into a digital
signal.
2. A real-valued signal is known to be bandlimited. The maximum frequency
content in the signal is fmax. What is the guideline given by the sampling theorem
with respect to the choice of sampling frequency such that from the samples, the
signal can be reconstructed without aliasing?
3. What is the impact of sampling a bandlimited signal with too low a sampling
frequency?
4. Is it possible to reconstruct a periodic square wave of fundamental frequency
5 Hz from its samples? Explain your answer.
5. Mention the reason for aliasing to occur while sampling the signals?
6. What is the meaning of sampling the signal x(t)? What is the meaning of the
terms (a) sampling rate and (b) sampling interval?
7. A signal has a bandwidth of 5 kHz. What is the Nyquist rate of the signal?
8. Why quantization is considered as a non-linear phenomenon?
9. Why quantization is considered as irreversible phenomenon?
10. What is signal reconstruction? Mention different types of signal reconstruction
strategies.
c(t)
1.0
0.8
0.6
Ampliude
0.4
0.2
0.0
x(t) with a train of impulse can be regarded as passing the signal x(t) through a
switch. The expression for a train of impulse is given by
1
cðt Þ = δðt - nT Þ ð2:1Þ
n= -1
The function c(t) takes a value of one whenever t = nT; else, it takes a value of
zero.
Experiment 2.1 Generation of a Train of Impulse Function
The python code, which generates the train of impulse function or comb function, is
given in Fig. 2.1, and the corresponding output is shown in Fig. 2.2.
38 2 Sampling and Quantization of Signals
Inference
1. From Fig. 2.1, it is possible to observe that the variable ‘T’ (Sampling interval)
decides the distance between consecutive samples.
2. From Fig. 2.2, it is possible to confirm that the comb function c(t) takes a value of
either ‘1’ or ‘0’. Whenever c(t) = 1, the signal x(t) samples will be collected.
Experiment 2.2 Frequency Domain View of Comb Function
The time-domain expression for the comb function is given by
1
cðt Þ = δðt - nT Þ ð2:2Þ
n= -1
1
2π
C ð ΩÞ = δðΩ - kΩs Þ ð2:3Þ
T k= -1
This experiment aims to prove that Fourier transform of a train of impulse will
result in a train of impulse function. Here, two comb functions (train of impulse
function), namely, c1(t) and c2(t) are generated. In the comb function c1(t), the
spacing between consecutive impulses is 0.1 s, whereas in the comb function c2(t),
the spacing between successive impulses is 0.05 s. Upon taking Fourier transform of
these two comb functions, the corresponding magnitude spectra |C1( f )| and |C2( f )|
are obtained. In the magnitude spectrum (|C1( f )|), the spacing between successive
peaks is 1/0.1 = 10, whereas in the magnitude spectrum (|C2( f )|), the spacing
between successive peaks is 1/0.05 = 20. The python code that performs this task
is given in Fig. 2.3, and the corresponding output is shown in Fig. 2.4.
Inferences From Fig. 2.4, the following inferences can be drawn:
1. The spacing between two successive samples in the comb function c1(t) is 0.1 s.
2. The spacing between two consecutive peaks in C1( f ) is 10 Hz.
3. The spacing between two successive samples in the comb function c2(t) is 0.5 s.
4. The spacing between two consecutive peaks in C2( f ) is 20 Hz.
5. This experiment illustrates the fact that time and frequency are inversely related to
each other. That is, compression in one domain is equivalent to expansion in other
domain and vice versa.
6. The Fourier transform of a train of impulse function results in a train of impulse
function.
Task
1. Write a python code to generate a function expressed as x½m] = 1
M x
M -1 2π
ej M km , - 10 < m < 10 for M = 1 and M = 2, and comment on the observed
k=0
result.
2.1 Sampling of Signal 39
The sampling theorem gives the guideline regarding the choice of the sampling rate.
According to the sampling theorem, a continuous-time signal with frequencies no
higher than fmax (Hz) can be reconstructed exactly from its samples if the samples are
taken at a rate greater than 2fmax. That is, fs ≥ 2fmax. Violation of the sampling
theorem results in an aliasing, which can be visualized in both the time and
frequency domains.
Experiment 2.3 Illustration of Aliasing in Time Domain
In this experiment, the aliasing is visualized in time domain. The analogue signal to
be sampled is represented as x(t) = sin (2πft + ϕ). The frequency of the signal x(t) is
10 Hz, and the phase angle is zero. This signal is sampled at four different sampling
frequencies 8, 15, 50 and 100 Hz. Obviously, the first two sampling frequencies
( fs = 8 and 15 Hz) are less than the criteria specified by the sampling theorem. This
will result in aliasing. The impact of aliasing is visualized in this experiment. The
40 2 Sampling and Quantization of Signals
python code that performs this task is shown in Fig. 2.5, and the corresponding
output is shown in Fig. 2.6.
Inferences
From Fig. 2.6, the following inferences can be made:
1. The sampling frequency of 8 Hz is insufficient to capture all the information in the
signal. The frequency of the sampled signal is given by f′ = f - fs. This implies f
2.1 Sampling of Signal 41
Fs = 8 Hz Fs = 15 Hz
1
0.5
Amplitude
Amplitude
0 0.0
–0.5
–1
0.0 0.2 0.4 0.6 0.8 0.00 0.25 0.50 0.75
Time Time
Fs = 50 Hz Fs = 100 Hz
1 1
Amplitude
Amplitude
0 0
–1 –1
0.00 0.25 0.50 0.75 1.00 0.00 0.25 0.50 0.75 1.00
Time Time
import numpy as np
import matplotlib.pyplot as plt
#Step 1: To generate x1 and x2
f1=1 #Signal frequency
f2=6
fs=100
t=np.arange(0,1,1/fs)
x1=np.sin(2*np.pi*f1*t)
x2=np.sin(2*np.pi*f2*t)
#Step 2: New sampling frequency is 5 Hz
fs1=5
t1=np.arange(0,1.1,1/fs1)
x3=np.sin(2*np.pi*f1*t1)
#Step 3: Plotting the result
plt.plot(t,x1,'k--',t,x2,'k'),#plt.plot(t,x2,'k')
plt.stem(t1,x3,'r'),plt.xlabel('Time'),plt.ylabel('Amplitude')
plt.legend(['1 Hz Sine wave','6 Hz Sine wave','Sampling with 5 Hz']),
plt.title('Aliasing in Time Domain')
plt.tight_layout()
Step 2: Now, the new sampling frequency chosen is 5 Hz. That is, f′ = 5 Hz. This
sampling frequency is used to represent a 6 Hz sine wave, which is stored in the
variable ‘x3’. It is well-known that 5 Hz is insufficient to represent a sine wave of
6 Hz frequency. Because of aliasing, the new frequency will appear at 1 Hz.
Step 3: From the samples taken using f′ = 5 Hz, it is not possible to distinguish
between 1 and 6 Hz sine waves. This phenomenon is termed as ‘aliasing’. This
occurs due to spectral folding.
The python code used to illustrate this concept is shown in Fig. 2.8, and the
corresponding output is shown in Fig. 2.9.
Inferences
From Fig. 2.9, the following inferences can be made:
2.1 Sampling of Signal 43
0.25
Amplitude
0.00
–0.25
–0.50
–0.75
–1.00
0.0 0.2 0.4 0.6 0.8 1.0
Time
1. The solid line shows a sine wave of 6 Hz frequency. The dotted line represents a
sine wave of 1 Hz frequency. Since the sampling frequency is 100 Hz, both
waveforms appear as desired without ambiguity.
2. The new sampling frequency is chosen as 5 Hz. This sampling frequency is used
to represent a 6 Hz sine wave. This sampling frequency is insufficient to represent
the 6 Hz. Represent a 6 Hz sine wave; the sampling frequency should be greater
than 12 Hz. From the discrete samples, it is not possible to interpret whether the
samples are taken from a 6 Hz sine wave or a 1 Hz sine wave. This ambiguity is
termed as aliasing, which arises due to spectral folding.
Experiment 2.5 Illustration of Aliasing in Frequency Domain
The python code, which demonstrates the phenomenon of aliasing in the frequency
domain, is shown in Fig. 2.10. This experiment generates the signal x-
(t) = sin (10πt) + sin (30πt) using two different sampling rates: fs = 50 Hz and
fs = 25 Hz.
Inferences
The following inferences can be made from Fig. 2.11.
1. The frequency components present in the signal x(t) are f1 = 5 Hz and f2 = 15 Hz.
2. When the sampling rate is 50 Hz, the peak in the magnitude spectrum appears
correctly at f1 = 5 Hz and f2 = 15 Hz.
3. On the other hand, if the sampling rate is chosen as fs = 25 Hz, there is no change
with respect to f1 = 5 Hz frequency component, whereas the frequency compo-
nent f2 = 15 Hz appears as f2 = 10 Hz. Observing a 15 Hz frequency component
signal as a 10 Hz frequency component is termed as aliasing.
44 2 Sampling and Quantization of Signals
#Sampling theorem
import numpy as np
import matplotlib.pyplot as plt
from scipy.fft import fft,fftfreq
#Step 1: Generate the two signals
f1=5
f2=15
fs=[25,50]
N=256
for i in range(len(fs)):
T=1/fs[i]
t=np.linspace(0,N*T,N)
x=np.sin(2*np.pi*f1*t)+np.sin(2*np.pi*f2*t)
X=fft(x)
f_axis=fftfreq(N,T)[0:N//2]
plt.subplot(2,1,i+1)
plt.plot(f_axis,2/N*np.abs(X[0:N//2]))
plt.xlabel('$\omega$-->'),plt.ylabel('|X($\omega$)|'),
plt.title(r'Spectrum corresponding to $f_s = {} Hz$'.format(fs[i]))
plt.tight_layout()
Fig. 2.10 Python code to illustrate the concept of aliasing in frequency domain
0.5
0.0
0 2 4 6 8 10 12
w ->
Spectrum corresponding to fs = 50Hz
1.0
|X(w)|
0.5
0.0
0 5 10 15 20 25
w ->
Task
1. Change the value of the sampling frequency ( fs) in the python code given in
Fig. 2.10, and observe the changes in the output spectrum.
2.1 Sampling of Signal 45
maximum values taken by the signal x[n], then the dynamic range of the signal is
calculated by
The relationship between the input and output of a mid-tread uniform quantizer is
given by
x ½ n] 1
y½n] = Q × þ ð2:5Þ
Q 2
In the above equation, x[n] represents the input signal to be quantized and y[n]
represents the quantized signal, ‘Q’ denotes the quantization step size and the
symbol bc denotes flooring operation. The expression for quantization step size
can be computed by
Dynamic range
Q= ð2:6Þ
L
where ‘dynamic range’ represents the difference between the maximum and mini-
mum value of the signal and ‘L’ denotes the number of reconstruction levels.
The expression for the number of reconstruction levels is given by
L = 2b ð2:7Þ
In the above expression, ‘b’ is the number of bits used to represent the signal.
Experiment 2.7 Transfer Characteristics of Mid-Tread Quantizer
The aim of this experiment is to plot the transfer characteristics of mid-tread
quantizer for different bit-rate. The bit-rate (b) chosen is b = 1, 2, 4 and 8. The
python code, which performs this task, is shown in Fig. 2.13, and the corresponding
output is shown in Fig. 2.14.
Inferences
The following inferences can be drawn from Figs. 2.13 and 2.14, which are
summarized below:
1. From Fig. 2.13, it is possible to observe that the input signal is represented as the
variable ‘x’ and the quantized signal Q(x) is represented as ‘y’. The input signal
‘x’ varies from -20 to +20; hence, the dynamic range of ‘x’ is 40.
2. Figure 2.13 shows that the number of bits used to represent the input signal is
varied as 1, 2, 4 and 8. It is represented as the variable ‘b’ in the code.
2.1 Sampling of Signal 47
Q(x)
0 0
–20 –20
–20 –10 0 10 20 –20 –10 0 10 20
x x
Q(x)
0 0
–20 –20
–20 –10 0 10 20 –20 –10 0 10 20
x x
#Uniform Quantization
import numpy as np
import matplotlib.pyplot as plt
from scipy import signal
#Step 1: Generate the input signal
t=np.linspace(0,1,100)
x=signal.sawtooth(2*np.pi*5*t)
#Step 2: Parameters of the quantizer
DR=np.max(x)-np.min(x) #Dynamic range
b=[1,2,4,8] #Number of bits
for i in range(len(b)):
L=2**b[i] #Quantization level
q=DR/(L) #Quantization step size
#Step 3: To obtain the quantized signal
y=np.sign(x)*q*np.floor((abs(x)/q)+(1/2))
plt.figure(i+1)
plt.plot(t,x,'b',t,y,'r'),plt.xlabel('Time'),plt.ylabel('Amplitude')
plt.legend(['Input signal','Quantized Signal'],loc='upper right')
plt.title('Quantization with b={}'.format(b[i]))
plt.tight_layout()
Fig. 2.15 Python code to perform uniform mid-tread quantization of the signal
6. The stair tread in a ladder is the horizontal walking surface of an individual step.
From Fig. 2.14, it is possible to observe that mid-tread quantizer has a zero-
valued reconstruction level.
Tasks
1. Write a python code to plot the error signal. The error signal is the difference
between the input and quantized signals. Comment on the observed output.
2. Write a python code to illustrate the fact that quantization error follows a uniform
distribution.
Experiment 2.8 Quantization of Input Sawtooth Signal Using Mid-Tread
Quantizer
The objective of this python experiment is to perform uniform mid-tread quantiza-
tion of input sawtooth signal of 5 Hz frequency for different bit rate. The number of
bits used to represent the input signal varies as 1, 2, 4 and 8. With an increase in the
number of bits used to represent the signal, the quantized signal resembles the input
signal. The python code to verify this experiment is shown in Fig. 2.15, and its
simulation result is displayed in Fig. 2.16.
Inferences
The following are the inferences can be drawn from Fig. 2.16:
1. The input signal to be quantized is a sawtooth signal whose fundamental fre-
quency is 5 Hz.
2.1 Sampling of Signal 49
2. The input signal will be uniformly quantized by mid-tread quantizer for different
bit rates.
3. It is possible to observe that the quantized signal resembles the input signal with
an increase in bit-rate.
The relationship between the input and output of mid-rise uniform quantizer is given
by
x ½ n] 1
y ½ n] = Q × þ ð2:8Þ
Q 2
In the above equation, x[n] represents the input signal to be quantized and y[n]
represents the quantized signal, ‘Q’ denotes the quantization step size and the
symbol bc denotes flooring operation.
Experiment 2.9 Transfer Characteristics of Mid-Rise Quantizer
The aim of this experiment is to plot the transfer characteristics of mid-rise quantizer
for different bit-rate. The bit-rate (b) chosen is b = 1, 2, 4 and 8. The python code,
50 2 Sampling and Quantization of Signals
0 0
–20
–20
Q(x)
0 0
–20 –20
–20 –10 0 10 20 –20 –10 0 10 20
x x
which performs this task, is shown in Fig. 2.17, and the corresponding output is
shown in Fig. 2.18.
Inferences
From Fig. 2.18, it is possible to observe that the reconstruction level rises to the next
level at the origin; hence, it is termed as ‘mid-rise quantizer’. It is also possible to
observe that with the bit rate increase, the output follows the input. In other words,
the quantizer error is minimal with a bit rate increase.
2.1 Sampling of Signal 51
Task
In the python code given in Fig. 2.17, replace ‘np.floor()’ by ‘np.ceil()’ function, and
comment on the change in the transfer characteristics.
Experiment 2.10 Quantization of Input Sawtooth Signal Using Mid-Rise
Quantizer
The objective of this experiment is to perform uniform mid-rise quantization of the
input sawtooth signal for different bit rate. The python code, which performs this
task, is shown in Fig. 2.19, and the corresponding output is shown in Fig. 2.20.
Inference
From Fig. 2.20, it is possible to interpret that with the increase in the number of bits
used to represent the signal, the quantized signal resembles the input signal. In other
words, the error due to quantization will be minimum with the increase in the number
of bits used to represent the signal.
Experiment 2.11 Quantization of Speech Signal
The objective of this experiment is to analyse the performance of uniform mid-tread
quantizer for the speech signal. The experiment consists of two steps. Reading the
speech signal from a given location is the first step, and performing uniform
midtread-quantization of the input speech signal for different bit rates is the second
step. The python code, which does this task, is shown in Fig. 2.21, and the
corresponding output is shown in Figs. 2.22 and 2.23.
52 2 Sampling and Quantization of Signals
Inference
The following inference can be made from this experiment:
1. The input speech signal belongs to the uttered word ‘Hello’.
2. The quantized signal resembles the original speech signal with the increase in the
number of bits of the quantizer.
Experiment 2.12 Uniform Mid-Tread Quantization of Image
In this experiment, a greyscale image, whose intensity varies gradually from black to
white, is generated first. This image is subjected to uniform quantization with bit
rates 1, 2, 4 and 8. The python code, which performs this task, is shown in Fig. 2.24,
and the corresponding output is shown in Fig. 2.25.
Inferences
The following inferences can be drawn from this experiment:
1. The grey level of the input image varies gradually from black to white.
2. The input image is quantized uniformly with a bit rate of b = 1, 2, 4 and 8. When
b = 1, the number of grey levels used to represent the image is minimum. The
quantized image is different from the input image.
3. With the increase in the number of bits used to represent the pixel value, the
quantized image resembles the input image.
2.1 Sampling of Signal 53
0.2
0.0
Amplitude
–0.2
–0.4
–0.6
0.00 0.25 0.50 0.75 1.00 1.25 1.50 1.75 2.00
Time
Amplitude
–0.50
–0.25
–0.75
–0.50
–1.00
–0.75
0 1 2 0 1 2
Time Time
Amplitude
0.00
–0.25
–0.25
–0.50
–0.50
0 1 2 0 1 2
Time Time
b=1 b=2
0 0
100 100
200 200
b=4 b=8
0
Input image
0 0
50
100 100
100
150
200 200
200
250
0 50 100 150 200 250
0 100 200 0 100 200
Task
1. Generate a 256 × 256 image in which half of the pixels are white (grey level 255)
and half of the pixels are black (grey level 0). The columns 0 to 127 is white,
whereas column 128 to 256 is black. Try to quantize this image for different bit
rate and comment on the observed result.
ð1 þ μjxjÞ
x1 ðt Þ = sgnðxÞ ln ð2:9Þ
lnð1 þ μÞ
56 2 Sampling and Quantization of Signals
import numpy as np
import matplotlib.pyplot as plt
from scipy import signal
#Step 1: Generate the input signal
t1=np.linspace(0,1,100)
x=signal.sawtooth(2*np.pi*5*t1)
#Step 2: Mu law Encoding (Non-uniform encoding)
mu=255 # 8 bit Quantization
y1=np.sign(x)*((np.log(1+(mu*abs(x))))/np.log(1+mu))
plt.figure(1)
plt.plot(t1,x,'b',t1,y1,'g'),plt.xlabel('Time'),plt.ylabel('Amplitude')
plt.legend(['Input signal','Encoded'],loc='upper right')
plt.title('Degree of Compression with mu={}'.format(mu))
#Step 3: Parameters of the quantizer
DR=np.max(y1)-np.min(y1) #Dynamic range
b=[1,2,4,8] #Number of bits
for i in range(len(b)):
L=2**b[i] #Quantization level
q=DR/(L) #Quantization step size
#Step 3: To obtain the quantized signal
y2=np.sign(y1)*q*np.floor((abs(y1)/q)+(1/2))
y=np.sign(y2)*(((1+mu)**(abs(y2))-1)/mu)
plt.figure(i+2)
plt.plot(t1,y2,'r',t1,y),plt.xlabel('Time'),plt.ylabel('Amplitude')
plt.legend(['Quantized Before decoding','Non-Uniform Quantized'],loc='upper right')
plt.title('Quantization with b={} and mu={}'.format(b[i],mu))
plt.tight_layout()
In the above expression, ‘μ’ is the compression parameter, which is 255 for the
USA and Japan. During compression, the least significant bits of large amplitude
values are discarded.
Experiment 2.13 μ-Law Companding
The python code which performs μ-law companding is shown in Fig. 2.26, and the
corresponding output is shown in Figs. 2.27 and 2.28.
Inference
The input signal to be companded is a sawtooth signal. The fundamental frequency
of a sawtooth signal is 5 Hz. Figure 2.27 illustrates the signal to be encoded using
μ-law companding with μ = 255. Here the signal is basically compressed before
passing it to the uniform quantizer. Figure 2.28 shows the uniform quantizer results
for different bit-rate values. With increase in bit-rate, the quantized signal resembles
the input signal.
2.2 Non-uniform Quantization 57
0.50
0.25
Amplitude
0.00
–0.25
–0.50
–0.75
–1.00
0.0 0.2 0.4 0.6 0.8 1.0
Time
sinusoidal signal of 5 Hz frequency for different bit rate. Then, plot the error signal
for different bit-rate. The python code, which performs this task, is shown in
Fig. 2.29, and the corresponding output is shown in Fig. 2.30.
Inferences
From Fig. 2.30, the following inferences can be made:
1. The error signal is oscillatory in nature. The magnitude of the error signal varies
between positive and negative values.
2. The magnitude of the error signal decreases with increase in bit-rate of the
quantizer.
3. Error due to quantization is inevitable; hence, quantization is considered as
irreversible phenomenon.
Experiment 2.15 Probability Density Function of Quantization Error
From the previous experiment, it is possible to confirm that error is inevitable in
quantization process. The objective of this experiment is to prove that quantization
error follows a uniform distribution. The steps followed in this experiment are
displayed in Fig. 2.31.
The python code which performs the task mentioned above is shown in Fig. 2.32,
and the corresponding output is shown in Fig. 2.33.
Inferences
The following inferences can be drawn from Fig. 2.33:
2.3 Signal Reconstruction 59
Amplitude
0.0 0.0
–0.2
–0.5
0 50 100 0 50 100
Time Time
Error signal for b=4 Error signal for b=8
0.05
0.0025
Amplitude
–0.0025
–0.05
0 50 100 0 50 100
Time Time
1. The quantization error follows uniform distribution in the range (-Δ/2, Δ/2),
where ‘Δ’ is the quantization step size.
2. In this example, the value of ‘Δ’ is 0.125; hence, Δ/2 value is 0.0625.
120
100
80
P c (e)
60
40
20
0
–0.06 –0.04 –0.02 0.00 0.02 0.04 0.06
e
0 T t
1 - e - Ts
H ðsÞ = ð2:10Þ
s
Sine wave
1.00 ZOH interpolation
0.75 Sine wave samples
0.50
0.25
Amplitude
0.00
–0.25
–0.50
–0.75
–1.00
0 1 2 3 4 5 6
Time
x(t) h(t)
1
Fig. 2.38 First-order hold interpolation. (a) First-order hold interpolation. (b) Impulse response
Inference
From Fig. 2.37, it is possible to interpret that zero-order hold interpolation converts
the input signal into a piece-wise constant signal. It is possible to observe disconti-
nuity in the zero-order hold interpolated signal.
In first-order hold (FoH) interpolation, the signal samples are connected by a straight
line. This idea is illustrated in Fig. 2.38a.
The first-order hold performs linear interpolation between samples. The impulse
response of first-order hold is shown in Fig. 2.38b.
The transfer function of first-order hold is expressed as
2.3 Signal Reconstruction 63
Sine wave
1.00 FOH interpolation
0.75 Sine wave samples
0.50
0.25
Amplitude
0.00
–0.25
–0.50
–0.75
–1.00
0 1 2 3 4 5 6
Time
2
1 - e - sT
H ðsÞ = ð2:11Þ
s
Inferences
The following inference can be drawn from Fig. 2.40:
1. The zero-order hold yields a staircase approximation of the signal.
2. The first-order hold yields a linear approximation of the signal.
3. The first-order hold connects the samples with straight lines.
1
t - nT s
xð t Þ = x½n] sin c ð2:12Þ
n= -1
Ts
The sinc function is a symmetric function which is square integrable. The decay
of the sinc function is slow. The sinc function has infinite support; hence, it is termed
as ideal interpolation. The sinc interpolation produces the smoothest possible inter-
polation of the samples.
Experiment 2.18 Ideal or Sinc Interpolation of a Sinusoidal Signal
The python code, which performs the ideal interpolation of the sine waveform, is
shown in Fig. 2.41, and the corresponding output is shown in Fig. 2.42.
Inference
The sinc interpolation produces the smoothest possible interpolation of the samples.
Experiment 2.19 Comparison of Zero-Order Hold and Sinc Interpolation
The python code, which performs the zero-order hold and sinc interpolation of a
given sinusoidal signal, is shown in Fig. 2.43, and the corresponding output is in
Fig. 2.44.
Inference
By observing Fig. 2.44, it is possible to infer that sinc interpolation smooths the
successive samples in the sine wave when compared to zero-order hold interpolation
method.
Exercises
1. Write a python code to demonstrate the phenomenon of aliasing in the frequency
domain for which the signal x(t) = sin (20πt) + sin (50πt) is generated using two
different sampling rates: fs = 100 Hz and fs = 25 Hz. Plot the corresponding
spectrum and comment on the observed result.
2.3 Signal Reconstruction 65
Sinc interpolation
1.00 Ideal interpolation
0.75 Sine wave samples
0.50
0.25
Amplitude
0.00
–0.25
–0.50
–0.75
–1.00
0 1 2 3 4 5 6
Time
0.25
Amplitude
0.00
–0.25
–0.50
–0.75
–1.00
0 1 2 3 4 5 6
Time
signal, which is expressed as x′(t) = 3 cos (2πt). Plot x(t) and x′(t) on the same
graph to verify the signals inter at the sampling instants.
4. Write a python code to generate a sinusoidal signal of fundamental frequency
1300 Hz and sampling frequency fs = 8 kHz. Hear this tone. Now downsample
this signal by a factor of 2 and hear the tone. Comment on the heard tones.
5. Write a python code to generate a sinusoidal signal of 10 Hz frequency. Quantize
this signal using 4-bit uniform mid-tread quantizer. Use a subplot to plot the
input, quantized and error signals. Comment on the observed output.
Objective Questions
1. What will be the output if the following code is executed?
A. 4.5
B. 4.0
C. 4.25
D. 5.0
2. What will be the output if the following code is executed?
A. -4.0
B. -5.0
C. -4.25
D. -5.25
3. The following python code segment produces
5. A sinusoidal signal of the form x(t) = sin(2πft), where ‘f = 5 Hz’ is sampled at the
rate fs = 100 Hz to obtain the discrete-time sequence x[n]. The expression for the
signal x[n] is
π
x½n] = sin n
2
π
x½n] = sin n
4
π
x½n] = sin n
5
π
x½n] = sin n
10
H ðsÞ = 1
1
H ðsÞ =
s
1 - e - sT
H ðsÞ =
s
H ðsÞ = 1 - e - sT
9. An analogue voltage in the range 0–4 V is divided into 32 equal intervals. The
quantization step size of this uniform quantizer is
A. 0.0625
B. 0.125
C. 0.25
D. 0.5
2.3 Signal Reconstruction 69
10. If ‘Δ’ represents the quantization step size of a uniform quantizer, the expres-
sion for mean square quantization error is
Δ2
A.
2
Δ2
B.
4
Δ2
C.
8
Δ2
D.
12
11. The quantization error follows
A. Normal distribution
B. Uniform distribution
C. Chi-square distribution
D. Exponential distribution
12. The transfer function of first-order hold is
1 - e - sT
A. H ðsÞ =
s
1
B. H ðsÞ =
s
2
1 - e - sT
C. H ðsÞ =
s
- sT
D. H ðsÞ = 1 - e
13. The signal to be quantized takes the value in the range (-1,1). The dynamic
range of the signal is
A. 1
B. -1
C. 0
D. 2
14. If fs represents the sampling frequency, then the expression for Nyquist fre-
quency is
A. fs
B. fs/2
C. fs/4
D. fs/8
70 2 Sampling and Quantization of Signals
15. The quantization step size of a two-bit quantizer which accepts the input signal,
which varies from 0 to 2 V, is
A. 0.125
B. 0.25
C. 0.5
D. 0.75
Bibliography
1. Alan V. Oppenheim, and Ronald W. Schafer, “Discrete-Time Signal Processing”, Pearson, 2009.
2. Michael Roberts, and Govind Sharma, “Fundamentals of Signals and Systems”, McGraw Hill
Education, 2017.
3. John G. Proakis, and Dmitris G. Manolakis, “Digital Signal Processing: Principles, Algorithms
and Applications”, Pearson Education, 2007.
4. Barrie Jervis, Emmanuel Ifeachor, “Digital Signal Processing: A Practical Approach”,
Pearson, 2001.
5. Allen B. Downey, “Think DSP: Digital Signal Processing in Python”, O’ Reilly Media, 2016.
Chapter 3
Generation and Operation on Discrete-Time
Sequence
Learning Objectives
After completing this chapter, the reader is expected to
• Generate standard discrete-time sequences like unit sample, unit step, unit ramp
sequences, etc.
• Perform operations like folding, shifting and scaling on the discrete-time
sequence.
• Perform linear convolution and circular convolution between discrete-time
sequences.
• Perform autocorrelation and cross-correlation between discrete-time sequences.
© The Author(s), under exclusive license to Springer Nature Singapore Pte Ltd. 2024 71
S. Esakkirajan et al., Digital Signal Processing,
https://doi.org/10.1007/978-981-99-6752-0_3
72 3 Generation and Operation on Discrete-Time Sequence
Discrete-Time Sequence
PreLab Questions
1. What are the steps involved in converting the continuous-time signal into a
discrete-time signal?
2. Mention different forms of representations of discrete-time signals?
3. Mention a few standard discrete-time sequences.
4. Mention the significant features of the unit sample sequence (δ[n]).
5. State the condition for the discrete-time signal to be periodic.
6. Distinguish between energy and power signal.
7. What are the various mathematical operations that can be performed on discrete-
time signals?
8. When a discrete-time signal is said to be (a) an even signal (b) an odd signal?
Give an example for each class of signal. Also, give an example of a signal
which is neither even nor odd.
9. Give an example of an energy and power signal. Also, give an example of a
discrete-time signal which is neither energy nor power signal.
10. Explain in your own word regarding the significance of convolution operation in
signal processing.
11. What is the relationship between convolution and correlation? Mention two
applications of correlation.
3.1 Generation of Discrete-Time Signals 73
This section deals with the generation of different types of discrete-time signals like
unit sample signal, unit step signal, unit ramp signal, real and complex exponential
signals. The following section discusses about different mathematical operations that
could be performed on discrete-time signals.
Experiment 3.1 Generation of the Unit Sample Sequence
The mathematical expression of the unit sample sequence (δ[n]) is given by
1, if n = 0
δ ½ n] = ð3:1Þ
0, Otherwise
This experiment discusses the generation of unit sample sequence using ‘if’ and
‘else’ conditions in python platform. The python code to generate unit sample
sequence using ‘if’ and ‘else’ conditions is shown in Fig. 3.1, and the corresponding
output is shown in Fig. 3.2. The built-in functions used in the program are given in
Table 3.1.
Inference
It is possible to observe that unit sample sequence takes a value of ‘1’ at ‘n’ equal to
zero and zero at other instances of ‘n’.
Experiment 3.2 Generation of Unit Sample Sequence Using the Logical
Operation
This experiment deals with the logical operation used to generate unit sample
sequence, and the python code for this experiment is shown in Fig. 3.3, and the
corresponding output is shown in Fig. 3.4.
Inference
The statement (x = (n == 0)) given in Fig. 3.3 implies that the variable ‘x’ takes a
value of ‘1’ if n = 0, and it takes a value of ‘0’ for all the other values of ‘n’.
d [n]
1.0
0.8
Amplitude
0.6
0.4
0.2
0.0
–10 –9 –8 –7 –6 –5 –4 –3 –2 –1 0 1 2 3 4 5 6 7 8 9 10
n-->
Experiment 3.3 Generation of Unit Sample Sequence Using the Built-In Func-
tion from the Scipy Library
The built-in function in scipy library ‘unit_impulse’ can be used to generate unit
sample sequence. The python code, which generates unit sample sequence using the
built-in function from the scipy library, is shown in Fig. 3.5, and the corresponding
output is shown in Fig. 3.6.
3.1 Generation of Discrete-Time Signals 75
d [n]
1.0
0.8
0.6
Amplitude
0.4
0.2
0.0
–10 –9 –8 –7 –6 –5 –4 –3 –2 –1 0 1 2 3 4 5 6 7 8 9 10
n-->
Inference
From Figs. 3.5 and 3.6, it is possible to confirm that unit sample sequence can be
generated using the scipy library with the built-in command of ‘signal.unit_impulse’.
Experiment 3.4 Generation of Unit Step Sequence
The mathematical expression of the unit step sequence is written as
1, if n ≥ 0
u½n] = ð3:2Þ
0, Otherwise
In this experiment, the unit step sequence is generated using two methods. In the
first method, ‘if’ and ‘else’ conditions are used to generate unit step sequence. The
second method uses logical operation to generate unit step signal. The python code,
which generates unit step signal using two different methods, is shown in Fig. 3.7,
and the corresponding output is shown in Fig. 3.8.
76 3 Generation and Operation on Discrete-Time Sequence
d [n]
1.0
0.8
0.6
Amplitude
0.4
0.2
0.0
–5 –4 –3 –2 –1 0 1 2 3 4 5
n-->
Inference
From Fig. 3.8, it is possible to interpret that both methods yield the same result,
which is a unit step signal. The unit step signal exhibits a sudden change in state from
logic 0 to logic 1 instantaneously.
Experiment 3.5 Generation of the Unit Ramp Signal
The mathematical expression of the unit ramp sequence (r[n]) is written as
3.1 Generation of Discrete-Time Signals 77
n, if n ≥ 0
r ½ n] = ð3:3Þ
0, Otherwise
The python code, which generates unit ramp signal using two methods, is
discussed in this experiment. In method 1, ‘if’ and ‘else’ conditions generate unit
ramp signals, whereas in method 2, logical operation is used to generate unit ramp
signals. The python code, which generates unit ramp signal using the two methods,
is shown in Fig. 3.9, and the corresponding output is shown in Fig. 3.10.
Inference
From Fig. 3.10, it is possible to observe that the ramp signal generated using ‘if’ and
‘else’ condition and ‘logical operation’ are alike. Unlike step signal, the ramp signal
gradually increases from low to high value.
Task
1. Write a python code to generate unit ramp signal from unit step signal.
Experiment 3.6
From unit sample signal generates unit step signal, and from unit step signal
generates unit ramp signal.
The relationship between unit sample (δ[n]) and unit step (u[n]) sequence is given
by
78 3 Generation and Operation on Discrete-Time Sequence
n
u½ n] = δ½k ] ð3:4Þ
k= -1
and
3.1 Generation of Discrete-Time Signals 79
The relationship between the unit ramp and unit step sequence is given by
The flow chart, which depicts the objective of this experiment, is shown in
Fig. 3.11.
From the flow chart, the unit sample sequence is generated first. From unit sample
sequence, unit step sequence is obtained by repeated addition. From unit step
sequence, unit ramp sequence is derived. The python code, which performs the
above-mentioned task, is shown in Fig. 3.12, and the corresponding output is shown
in Fig. 3.13.
Inferences
From the python code shown in Fig. 3.12, it is possible to infer that unit step
sequence is obtained by repeatedly adding the unit sample sequence. The unit
ramp sequence is obtained by weighting the unit step signal by a factor of ‘n’.
From this example, it is possible to infer that any arbitrary signal x[n] can be obtained
from the unit sample sequence by scaling and shifting operations.
Task
1. Write a python code to generate a unit sample signal from the unit step signal.
Experiment 3.7 Generation of Real Exponential Sequence
The expression for a real exponential signal is given by
x½n] = αn ð3:7Þ
where α must be a real value. The aim of this experiment is to generate real
exponential sequence for four different values of ‘α’, namely, α = 0.5, α = -
0.5, α = 1.0 and α = - 1.0. The python code, which performs this task, is shown in
Fig. 3.14, and the corresponding output is shown in Fig. 3.15.
80 3 Generation and Operation on Discrete-Time Sequence
Fig. 3.12 Python code to generate test signals from unit sample sequence
α=0.5 α=–0.5
30
Amplitude
Amplitude
20 0
10 –20
0
–5 –4 –3 –2 –1 0 1 2 3 4 5 –5 –4 –3 –2 –1 0 1 2 3 4 5
n--> n-->
α=1.0 α=–1.0
1.0 1
Amplitude
Amplitude
0.5 0
0.0 –1
–5 –4 –3 –2 –1 0 1 2 3 4 5 –5 –4 –3 –2 –1 0 1 2 3 4 5
n--> n-->
Inferences
The following inference can be made from this experiment:
1. If the value of α is 0 < α < 1, then the signal x[n] decreases in magnitude. This is
evident by observing the first subplot for α = 0.5.
2. If the value of α is -1 < α < 0, then the signal x[n] alternates in sign but
decreases in magnitude. This is evident by viewing the second subplot in
Fig. 3.15 for α = - 0.5.
3. For α = 1.0, there is no oscillation and the amplitude is always one.
82 3 Generation and Operation on Discrete-Time Sequence
4. For α = - 1.0, the signal x[n] toggles. This is the highest frequency in digital
sequence.
Task
1. Obtain the real exponential sequence for α = 2 and comment on the nature of the
signal. Here the term ‘nature’ refers to whether the signal is a bounded or not.
Experiment 3.8 Generation of Complex Exponential Signal
The general form of complex exponential signal is given by
where ‘ω’ represents the angular frequency in radians. The python code to generate
complex exponential sequences for four different values of ‘ω’ such as ω =
0, π2 , π, 3π
2 is given in Fig. 3.16, and the corresponding output is shown in
Fig. 3.17.
Inferences
The following inference can be drawn from this experiment:
1. When ω = 0, the frequency is zero, the amplitude of the signal is constant and
there is no variation in the signal. This is termed as DC signal. For a DC signal,
the frequency is zero.
2. With increase in the value of ‘ω’, the oscillation exhibited by the signal increases.
At ω = π, the signal takes alternate values of +1 and -1. It is the highest
frequency in the digital signal.
Task
1. Write a python code to prove the fact that digital frequency ‘ω’ is unique in the
range 0 to 2π or from –π to π.
3.1 Generation of Discrete-Time Signals 83
w = 0° w = 90°
1.0 1
Amplitude
Amplitude
0.5 0
0.0 –1
–5 –4 –3 –2 –1 0 1 2 3 4 5 –5 –4 –3 –2 –1 0 1 2 3 4 5
n--> n-->
w = 180° w = 270°
1 1
Amplitude
Amplitude
0 0
–1 –1
–5 –4 –3 –2 –1 0 1 2 3 4 5 –5 –4 –3 –2 –1 0 1 2 3 4 5
n--> n-->
1, if n > 0
sgn½n] = 0, if n = 0 ð3:9Þ
- 1, if n < 0
The python code to generate signum function is shown in Fig. 3.18, and the
corresponding output is shown in Fig. 3.19.
84 3 Generation and Operation on Discrete-Time Sequence
Signum function
1
Amplitude
–1
–5 –4 –3 –2 –1 0 1 2 3 4 5
n-->
Inference
From Fig. 3.19, it is possible to observe that the signum function takes only three
values, which are -1, 0 and 1; whenever n < 0, the signum function takes the value
of -1. At n = 0, the signum function takes a value of ‘0’. For the positive values of
‘n’, the signum function takes the value of +1.
Task
1. Is it possible to obtain signum function from unit step function? If yes, write a
python code to generate discrete signum signal from unit step signal.
The different signal operations that come under amplitude modification are
discussed in this section.
(a) Amplitude scaling
If x[n] is the input signal, the scaling of the signal x[n] by a factor of ‘A’ is
represented as
3.2 Mathematical Operation on Discrete-Time Signals 85
import numpy as np
import matplotlib.pyplot as plt
#Step 1: Generating the input signal
n=np.arange(-10,11,1)
x=(n==0)
#Obtaining the output signals for different values of 'A'
A=[2,0.5,1] #Three different values of factor 'A'
y1=A[0]*x
y2=A[1]*x
y3=A[2]*x
#Step 2: Plotting the result
plt.subplot(2,2,1),plt.stem(n,x),plt.yticks([0,2]),plt.xlabel('n-->'),
plt.ylabel('Amplitude'),plt.title('x[n]'),plt.subplot(2,2,2),plt.stem(n,y1)
plt.yticks([0,2]),plt.xlabel('n-->'),plt.ylabel('Amplitude'),
plt.title('$y_1[n]$'),plt.subplot(2,2,3),plt.stem(n,y2)
plt.yticks([0,2]),plt.xlabel('n-->'),plt.ylabel('Amplitude'),
plt.title('$y_2[n]$'),plt.subplot(2,2,4),plt.stem(n,y3),plt.yticks([0,2]),
plt.xlabel('n-->'),plt.ylabel('Amplitude'),plt.title('$y_3[n]$')
plt.tight_layout()
x[n] Y1[n]
2 2
Amplitude
Amplitude
0 0
–10 –5 0 5 10 –10 –5 0 5 10
n--> n-->
Y2[n] Y3[n]
2 2
Amplitude
Amplitude
0 0
–10 –5 0 5 10 –10 –5 0 5 10
n--> n-->
Inference
The following inferences can be made from this experiment:
1. From Fig. 3.22, it is possible to observe that y1[n] is the amplified version of x[n],
and y2[n] is the attenuated version of x[n]. If the gain is unity, the output follows
the input, which is evident from the output y3[n].
2. This example illustrates the scaling of the amplitude axis for different values of
the factor ‘A’.
Task
1. Write a python code to illustrate the fact that amplitude scaling changes the
energy of the signal.
y ½ n] = x ½ n] ± C ð3:11Þ
#DC offset
import numpy as np
import matplotlib.pyplot as plt
#Step 1: Generation of input sinusoidal sequence
t=np.linspace(0,1,100)
x=np.sin(2*np.pi*5*t)
#Step 2: Perform DC offset
offset=[5,-5]
y1=x+offset[0]
y2=x+offset[1]
#Step 3: Ploting the input and output signals
plt.subplot(3,1,1),plt.stem(t,x),
plt.xlabel('n-->'),plt.ylabel('Amplitude'),plt.title('x[n]')
plt.subplot(3,1,2),plt.stem(t,y1)
plt.xlabel('n-->'),plt.ylabel('Amplitude'),plt.title('$y_1$[n]')
plt.subplot(3,1,3),plt.stem(t,y2)
plt.xlabel('n-->'),plt.ylabel('Amplitude'),plt.title('$y_2$[n]')
plt.tight_layout()
of ‘C’ for this experiment is to be chosen as 5. Write a python code to perform this
task and comment on the observed output.
The python code, which performs the above-mentioned task, is shown in
Fig. 3.23, and the corresponding output is shown in Fig. 3.24.
Inference
By observing Fig. 3.24, it is possible to infer that the reference for signal y1[n] is
+5 V, whereas the reference for signal y2[n] is -5 V. This is termed as DC offset.
Task
1. Does amplitude shifting affect the energy of the signal? Write a python code to
answer this question.
The amplitude of the resultant signal y[n] gets modified. For example,
consider
x[n]
Amplitude
1
0
–1
0.0 0.2 0.4 0.6 0.8 1.0
n-->
y1[n]
Amplitude
0
0.0 0.2 0.4 0.6 0.8 1.0
n-->
y 2[n]
Amplitude
–5
0.0 0.2 0.4 0.6 0.8 1.0
n-->
1
sin A cos B = f sinðA þ BÞ þ sinðA - BÞg ð3:16Þ
2
1
y ½ n] = f sin 2π ðf 1 þ f 2 Þn þ sin 2π ðf 1 - f 2 ÞnÞg ð3:17Þ
2
The amplitude of the output signal is different from the input signal x[n].
Fig. 3.25 Python code to obtain the product of the two signals
x1[n]
Amplitude
1
0
–1
0 20 40 60 80 100
n-->
x2[n]
Amplitude
1
0
–1
0 20 40 60 80 100
n-->
y [n]
Amplitude
–1
0 20 40 60 80 100
n-->
1. From Fig. 3.25, two signals of the same frequency are generated and multiplied.
2. From Fig. 3.26, it is possible to observe that x1[n] is a sine wave and x2[n] is a
cosine wave. The resultant signal y[n] is a sinusoidal signal with a frequency of
10 Hz, whereas the amplitude of the output waveform is reduced by a factor
of half.
The signal addition results in a change in the amplitude of the signal. Two
signals x1[n] and x2[n] are added together to obtain the resultant output signal y
[n], which is given by
x1[n]
Amplitude
2
0
–10 –9 –8 –7 –6 –5 –4 –3 –2 –1 0 1 2 3 4 5 6 7 8 9 10
n-->
x2[n]
Amplitude
0
–10 –9 –8 –7 –6 –5 –4 –3 –2 –1 0 1 2 3 4 5 6 7 8 9 10
n-->
y[n]
Amplitude
0
–10 –9 –8 –7 –6 –5 –4 –3 –2 –1 0 1 2 3 4 5 6 7 8 9 10
n-->
Task
1. Write a python code to illustrate the fact that ‘signal addition is a commutative
operation’.
Time scaling operations can be classified into two types, namely, (1) downsampling
and (2) upsampling.
(a) Downsampling
The downsampling of the signal x[n] by a factor of ‘M’ is represented as
#Downsampling by a factor of M
import numpy as np
import matplotlib.pyplot as plt
#Step 1: Generating the input signal
n=np.arange(-10,11,1)
x=n
M=2 #Downsampling factor
m=np.arange(n[0]/2,(n[-1]/2)+1,1)
#Step 2: Performing downsampling operation
y=x[::M]
#Step 3: Plotting the input and downsampled signal
plt.subplot(2,1,1),plt.stem(n,x),plt.xlabel('n-->'),
plt.ylabel('Amplitude'),plt.title('x[n]'),plt.xticks(n)
plt.subplot(2,1,2),plt.stem(m,y),plt.xlabel('n-->'),
plt.ylabel('Amplitude'),plt.title('y[n]'),plt.xticks(n)
plt.tight_layout()
x[n]
10
Amplitude
–10
–10 –9 –8 –7 –6 –5 –4 –3 –2 –1 0 1 2 3 4 5 6 7 8 9 10
n-->
y[n]
10
Amplitude
–10
–10 –9 –8 –7 –6 –5 –4 –3 –2 –1 0 1 2 3 4 5 6 7 8 9 10
n-->
Inferences
The following inferences can be drawn from this experiment:
1. By observing Fig. 3.30, the number of samples in the input signal x[n] is
21, whereas the number of samples in the output signal y[n] is 11.
2. Downsampling leads to a reduction in the number of samples.
3.2 Mathematical Operation on Discrete-Time Signals 93
Task
1. Write a python code to prove the fact that downsampling is an irreversible
operation. That is, it is not possible to obtain the original signal from the
downsampled signal because downsampling results in loss of signal samples.
(b) Upsampling
The upsampling of the signal x[n] by a factor of ‘L’ is represented by
n
y ½ n] = x ð3:21Þ
L
n
y½n] = x
2
The time shifting operation can be broadly classified into two types: (1) delay
operation and (2) advance operation.
(a) Delay operation
The delaying of the input signal by a factor of ‘k’ units is expressed as
94 3 Generation and Operation on Discrete-Time Sequence
#Upsampling by a factor of 2
import numpy as np
import matplotlib.pyplot as plt
#Step 1: Generating the input signal
L=2 #Upsampling factor
n=np.arange(-5,6,1)
N=len(n)
m=np.arange(-N+1,N+1,1)
x=np.ones(N)
#Step 2: Upsampling the input signal
y=np.zeros(L*N)
y[::2]=x
#Step 3: Plotting the input and output signal
plt.subplot(2,1,1),plt.stem(n,x),plt.xlabel('n-->'),plt.ylabel('Amplitude'),plt.title('x[n]'),
plt.xticks(m),plt.subplot(2,1,2),plt.stem(m,y),plt.xlabel('n-->'),
plt.ylabel('Amplitude'),plt.title('y[n]'),plt.xticks(m)
plt.tight_layout()
x[n]
1.0
Amplitude
0.5
0.0
–10 –9 –8 –7 –6 –5 –4 –3 –2 –1 0 1 2 3 4 5 6 7 8 9 10 11
n-->
y[n]
1.0
Amplitude
0.5
0.0
–10 –9 –8 –7 –6 –5 –4 –3 –2 –1 0 1 2 3 4 5 6 7 8 9 10 11
n-->
y ½ n] = x ½ n - k ] ð3:22Þ
y ½ n] = x ½ n þ k ] ð3:23Þ
The time reversal of the signal x[n] is denoted as x[-n]. This refers to flipping the
signal x[n] from left to right and right to left. It can be considered as a signal
reflection about the origin. A discrete-time signal can be reversed in time by
96 3 Generation and Operation on Discrete-Time Sequence
u[n]
Amplitude 1
0
–10 –9 –8 –7 –6 –5 –4 –3 –2 –1 0 1 2 3 4 5 6 7 8 9 10
n-->
u[n-5]
Amplitude
0
–10 –9 –8 –7 –6 –5 –4 –3 –2 –1 0 1 2 3 4 5 6 7 8 9 10
n-->
u[n+5]
Amplitude
0
–10 –9 –8 –7 –6 –5 –4 –3 –2 –1 0 1 2 3 4 5 6 7 8 9 10
n-->
changing the sign of the independent variable for all instances. Two different ways to
perform time reversal operation in python are given below.
Experiment 3.17 Time Reversal Without Built-In Function
This experiment deals with the time reversal operation using python without built-in
function. In this method, the signal x[n] is flipped from left to right using the
command" x[::-1]", the python code which performs the task of time reversal is
shown in Fig. 3.35, and the corresponding output is shown in Fig. 3.36.
Inference
Figure 3.36 clearly indicates that the left side of the input signal is moved into the
right side of the output signal and the right side of the input signal is moved into the
left side of the output signal.
Experiment 3.18 Time Reversal Using Built-In Function
This experiment tries to obtain the time reversal using a python built-in function. In
this method, the built-in function ‘np.fliplr()’ is used to perform a time reversal
operation. The python code, which performs this task, is shown in Fig. 3.37, and the
corresponding output is shown in Fig. 3.38.
Inference
This experiment confirms that the time reversal can be done using ‘np.fliplr’ built-in
function.
Task
1. Write a python code to illustrate that flipping operation does not alter the signal’s
energy.
3.3 Convolution 97
x[n]
10
Amplitude
–10
–10–9 –8 –7 –6 –5 –4 –3 –2 –1 0 1 2 3 4 5 6 7 8 9 10
n-->
y[n]
10
Amplitude
–10
–10–9 –8 –7 –6 –5 –4 –3 –2 –1 0 1 2 3 4 5 6 7 8 9 10
n-->
3.3 Convolution
x[n]
10
Amplitude
–10
–10 –9 –8 –7 –6 –5 –4 –3 –2 –1 0 1 2 3 4 5 6 7 8 9 10
n-->
y[n]
10
Amplitude
–10
–10 –9 –8 –7 –6 –5 –4 –3 –2 –1 0 1 2 3 4 5 6 7 8 9 10
n-->
In the above expression, ‘*’ denotes the convolution operation. The above
expression can be written as
1
y½n] = x½k ]h½n - k ] ð3:25Þ
k= -1
1
y½n] = h½k ]x½n - k ] ð3:26Þ
k= -1
The python code, which illustrates the above concept, is shown in Fig. 3.40, and
the corresponding output is shown in Fig. 3.41.
Inferences
The following inferences can be drawn from this experiment:
1. From Fig. 3.41, the input signal (x[n]) generated is a triangular signal.
2. The impulse response (h[n]) is unit sample signal (δ[n]).
3. The signal x[n] is convolved with unit sample signal to obtain the output signal y
[n]. It can be observed that the output signal y[n] resembles the input signal x[n].
Experiment 3.20 Convolution of the Signal x[n] with Shifted Unit Sample Signal
This experiment illustrates the fact that the signal x[n] can be shifted by convolving it
with δ[n ± k]. Convolving the signal x[n] with δ[n - k] results in delaying the signal
x[n] by a factor of ‘k’. Convolving the signal x[n] with δ[n + k] results in advancing
the signal x[n] by a factor of ‘k’. This is expressed as
The python code, which performs this task, is shown in Fig. 3.42, and the
corresponding output is shown in Fig. 3.43.
Inferences
The task performed by the python program is summarized in Fig. 3.44.
1. The input signal x[n] is applied to two systems with impulse responses
h1[n] = δ[n - k] and h2[n] = δ[n + k] to obtain the output signals y1[n] and
y2[n] respectively.
2. By comparing the input signal x[n] with the output signal y1[n], it is possible to
observe that the output signal y1[n] is a shifted version (delayed version) of the
input signal x[n].
100 3 Generation and Operation on Discrete-Time Sequence
Fig. 3.40 Convolution of the signal x[n] with unit sample signal δ[n]
x[n]
Amplitude
0
–5 –4 –3 –2 –1 0 1 2 3 4 5
n-->
h[n]
Amplitude
0
–5 –4 –3 –2 –1 0 1 2 3 4 5
n-->
y[n]
Amplitude
0
–10 –9 –8 –7 –6 –5 –4 –3 –2 –1 0 1 2 3 4 5 6 7 8 9 10
n-->
3. By comparing the input signal x[n] with the output signal y2[n], it is possible to
observe that the output signal y2[n] is a shifted version (advanced version) of the
input signal x[n].
4. This experiment illustrates the fact that signal shifting can be accomplished using
convolution operation.
3.3 Convolution 101
Fig. 3.42 Python code to perform convolution of signal x[n] with shifted unit sample signal
Task
1. Repeat the above experiment with a rectangular pulse signal instead of a
triangular one.
Experiment 3.21 Commutative Property of Convolution
The motive of this experiment is to prove the commutative property of convolution.
The commutative property of convolution is expressed as
x[n] x[n]
Amplitude
Amplitude
5 5
0 0
–5 –4 –3 –2 –1 0 1 2 3 4 5 –5 –4 –3 –2 –1 0 1 2 3 4 5
n--> n-->
h1[n] h2[n]
Amplitude
Amplitude
1 1
0 0
–5 –4 –3 –2 –1 0 1 2 3 4 5 –5 –4 –3 –2 –1 0 1 2 3 4 5
n--> n-->
y1[n] y2[n]
Amplitude
Amplitude
5 5
0 0
–10 –5 0 5 10 –10 –5 0 5 10
n--> n-->
h2[n]=δ[n + k] y2[n]
1. The input signal x[n] is a pulse signal. Similarly, the signal h[n] is a pulse signal.
The signals x[n] and h[n] are the same.
2. The signal y1[n] is obtained by convolving x[n] with h[n], whereas the signal y2[n]
is obtained by convolving h[n] with x[n]. From Fig. 3.46, the signals y1[n] and
y2[n] are the same.
3. This experiment illustrates that convolution is commutative. Also, the convolu-
tion of two pulse signals results in a triangular signal.
Task
1. In the above experiment, let L1 and L2 be the length of the signals x[n] and h
[n]. Then, the length of the convolved signal is L1 + L2 - 1. Write a python code
to illustrate that linear convolution results in stretching the length of the signal.
Experiment 3.22 Associative Property of Convolution
The associative property of convolution is expressed as
To illustrate this property, the input signal x[n] chosen is x[n] = ejπn, which
toggles between +1 and -1. The impulse response h1[n] = δ[n - k] and the impulse
3.3 Convolution 103
x[n] h[n]
1.0 1.0
Amplitude
Amplitude
0.5 0.5
0.0 0.0
–5 –4 –3 –2 –1 0 1 2 3 4 5 –5.0 –2.5 0.0 2.5 5.0
n--> n-->
Amplitude
2 2
0 0
–10 –5 0 5 10 –10 –5 0 5 10
n--> n-->
response h2[n] = δ[n + k]. The python code, which illustrates the associative
property of the convolution operation, is given in Fig. 3.47, and the corresponding
outputs are shown in Figs. 3.48 and 3.49, respectively.
Inferences
The following are the inferences from this experiment:
1. The input signal x[n] = (-1)n, -5 ≤ n ≤ 5. The impulse response h1[n] = δ[n -
5] and h2[n] = δ[n + 5], which is shown in Fig. 3.48.
2. The output y1[n] = (x[n]*h1[n])*h2[n], whereas the output y2[n] = x[n]*(h1[n]
*h2[n]). From Fig. 3.49, it is possible to observe that the output y1[n] = y2[n],
which shows that associative property of convolution is verified.
Experiment 3.23 Distributive Property of Convolution
The distributive property of convolution is expressed as
3.3 Convolution 105
x[n]
Amplitude
1
0
–1
–5 –4 –3 –2 –1 0 1 2 3 4 5
n
h1[n]
Amplitude
0
–5 –4 –3 –2 –1 0 1 2 3 4 5
n-->
h2[n]
Amplitude
0
–5 –4 –3 –2 –1 0 1 2 3 4 5
n-->
y1[n]=(x[n]*h1[n])*h2[n]
1
Amplitude
–1
–15 –10 –5 0 5 10 15
n-->
y2[n]=x[n]*(h1[n])*h2[n])
1
Amplitude
–1
–15 –10 –5 0 5 10 15
n-->
For illustration, the signal x[n] is chosen as x[n] = δ[n + 1] + 2δ[n] + δ[n - 1],
h1[n] = δ[n + 1] + δ[n] + δ[n - 1] and h2[n] = - δ[n + 1] - δ[n - 1] such that
h1[n] + h2[n] results in unit sample signal. The python code, which illustrates the
distributive of convolution, is shown in Fig. 3.50, and the corresponding outputs are
shown in Figs. 3.51 and 3.52, respectively.
106 3 Generation and Operation on Discrete-Time Sequence
Inferences
1. From Fig. 3.51, it is possible to observe that the input signal and the impulse
responses are all finite-duration signals. The input signal is expressed as x
[n] = δ[n + 1] + 2δ[n] + δ[n - 1]. The impulse responses are given by
h1[n] = δ[n + 1] + δ[n] + δ[n - 1] and h2[n] = - δ[n + 1] - δ[n - 1].
2. The sum of the impulse responses results in a unit sample signal, which is
expressed as h1[n] + h2[n] = δ[n]. Also, convolution of any input signal x[n]
with unit sample signal results in the same signal, which is expressed as x
[n] * δ[n] = x[n]. Because of this property, the output signal y1[n] is same as
the input signal x[n].
3. By observing the output signals y1[n] and y2[n], it is possible to infer
y1[n] = y2[n], which implies that the distributive property of convolution is
illustrated through this experiment.
Experiment 3.24 Convolution of a Square Wave with Lowpass Filter
Coefficient
In this experiment, a square wave of fundamental frequency 5 Hz is generated. It is
then passed through moving average filter with M = 5, 7, 9, and 11. The block
diagram of the experiment performed is shown in Fig. 3.53.
The impulse response of lowpass filter (moving average filter) is given by
M-1
1
h½n] = δ½n - k ] ð3:32Þ
M k=0
The python code which accomplishes this task is shown in Fig. 3.54, and the
corresponding output is shown in Figs. 3.55 and 3.56.
Inferences
The following inferences can be drawn from Figs. 3.55 and 3.56:
1. The input to the system is a square wave of a fundamental frequency 5 Hz.
2. The system is passed through lowpass filter to obtain a triangular waveform.
3. By observing the input and output waveform, it is possible to observe that the
system converts drastic change (square waveform) to a gradual change (sawtooth
waveform). The system basically performs lowpass filtering of the input signal.
4. The extent of smoothing is governed by the value of ‘M’. Increasing the value of
‘M’ increases the extent of smoothing the input signal.
3.3
x[n]
Amplitude
2
0
–5 –4 –3 –2 –1 0 1 2 3 4 5
n-->
h1[n]
Amplitude
0
–5 –4 –3 –2 –1 0 1 2 3 4 5
n-->
h2[n]
Amplitude
–1
–5 –4 –3 –2 –1 0 1 2 3 4 5
n-->
y1[n]=(x[n]*h1[n])*h2[n]
2
Amplitude
0
–10.0 –7.5 –5.0 –2.5 0.0 2.5 5.0 7.5 10.0
n-->
y2[n]=x[n]*(h1[n])*h2[n])
2
Amplitude
0
–10.0 –7.5 –5.0 –2.5 0.0 2.5 5.0 7.5 10.0
n-->
Task
1. In the above experiment, replace the square wave input with sine wave with a
spike signal. That is a sine wave with an abrupt change in amplitude in a few time
instants. Now pass this sine wave through the moving average filter and comment
on the observed signal.
3.3 Convolution 109
Input signal
1.00
0.75
0.50
0.25
Amplitude
0.00
–0.25
–0.50
–0.75
–1.00
0.0 0.2 0.4 0.6 0.8 1.0
Time
Amplitude
0 0
–1 –1
0.00 0.25 0.50 0.75 1.00 0.00 0.25 0.50 0.75 1.00
Time Time
Output signal for M=9 Output signal for M=11
1
0.5
Amplitude
Amplitude
0 0.0
–0.5
–1
0.00 0.25 0.50 0.75 1.00 0.00 0.25 0.50 0.75 1.00
Time Time
waveform. The python code, which performs this task, is shown in Fig. 3.57, and the
corresponding output is shown in Fig. 3.58.
Inferences
The following inferences can be made from this experiment:
1. From Fig. 3.57, it is possible to infer that the input signal is a square wave, the
impulse response of highpass filter is h[n] = {1/2, -1/2}.
2. From Fig. 3.58, it is possible to observe that the output waveform is a spike
waveform. It is due to the fact that differentiation of a constant is zero. In a square
wave, major portion is constant in magnitude; hence, differentiation of a constant
is zero. Highpass filter is a change detector; hence, it gives spike waveform as the
output for the input square waveform.
Task
1. Generate sine wave of 5 Hz frequency. Add white noise, which follows normal
distribution to this sine wave. Now pass this noisy sine wave through highpass
filter. Plot the clean sine wave, noisy sine wave and highpass filtered signal. Write
a python code to answer the query ‘Does highpass filter tend to amplify the
noise?’
3.4 Correlation 111
Input signal
Amplitude
1
0
–1
0.0 0.2 0.4 0.6 0.8 1.0
time
h[n]
Amplitude
0.5
0.0
–0.5
0.0 0.2 0.4 0.6 0.8 1.0
n-->
Output signal
Amplitude
1
0
–1
0.0 0.2 0.4 0.6 0.8 1.0
time
3.4 Correlation
Correlation is a tool to find the relative similarity between two signals. Correlation
has two variants, namely: autocorrelation and cross-correlation. Autocorrelation
involves the correlation of a signal with itself. Cross-correlation is performed
when two different signals are correlated with one another.
The expression for autocorrelation of the sequence x[n] is given by
112 3 Generation and Operation on Discrete-Time Sequence
1
r xx ðlÞ = x½n]x½n þ l] ð3:34Þ
n= -1
1
rxy ðlÞ = x½k]y½l þ k] ð3:36Þ
k= -1
4. The autocorrelation and cross-correlation are used to find the relative similarity
between the two signals.
Tasks
1. Write a python code to illustrate the fact that maximum value of autocorrelation
occurs at zero lag.
2. Write a python code to illustrate the fact that correlation can be performed in
terms of convolution. That is convolution of a signal with its folded version
results in autocorrelation.
Experiment 3.27 Autocorrelation of Sine Wave to Itself and Noisy Signal
In this experiment, sine wave of 5 Hz is generated. It is stored as the variable ‘x’. The
sine wave is then corrupted by random noise, which follows normal distribution to
obtain the signal ‘y’. The autocorrelation of clean sine wave is obtained as rxx(l ), and
the cross-correlation between the clean and noisy sine wave is obtained as rxy(l ). The
python code, which performs this task, is shown in Fig. 3.61, and the corresponding
output is shown in Fig. 3.62.
114 3 Generation and Operation on Discrete-Time Sequence
rxx(I) ryy(I)
50 50
Autocorrelation
Autocorrelation
0 0
–50
–100 –50 0 50 100 –100 –50 0 50 100
Lag Lag
rxy(I) ryx(I)
50 50
Cross correlation
Cross correlation
0 0
–50 –50
–100 –50 0 50 100 –100 –50 0 50 100
Lag Lag
Inferences
1. In Fig. 3.62, x(t) represents clean sine wave of 5 Hz frequency, and y(t) represents
noisy sine wave. The noisy sine wave is obtained by adding random noise to the
clean sine wave.
2. In Fig. 3.62, rxx(l) represents the autocorrelation of a clean sine wave. The
autocorrelation function exhibits even symmetry, with the maximum value
occurring at zero lag.
3. In Fig. 3.62, rxy(l ) represents the cross-correlation between clean and noisy sine
waves. The cross-correlation is not exhibiting even symmetry relation. Compar-
ing rxx(l ) and rxy(l), the maximum value is obtained in autocorrelation function.
Thus, the autocorrelation reveals the relative similarity between the signals.
Experiment 3.28 Delay Estimation Using Autocorrelation
In this experiment, unit step sequence (signal ×1) is generated, it is then shifted by a
factor of ‘5’ units to the right to obtain the signal ×2. The autocorrelation of the
signal ×1 to itself and the correlation between the signals ×1 and ×2 are used to
estimate the delay. The python code, which performs this function, is shown in
Fig. 3.63, and the corresponding output is shown in Fig. 3.64.
Inference
Upon displaying the result, the answer in the variable ‘td’ is ‘5’, which is a measure
of delay between the two signals x1[n] and x2[n]. Thus, autocorrelation can be used
to measure or estimate the delay between the two signals.
3.4 Correlation 115
Fig. 3.61 Python code to perform autocorrelation of clean and noisy sine wave
Exercises
1. Generate the following sequences (a) x1[n] = δ[n + 1] + δ[n - 1]
(b) x1[n] = δ[n + 1] - δ[n - 1] (c) x3[n] = δ[n] + 2δ[n - 1] + δ[n - 2] and
(d) x4[n] = δ[n] - δ[n - 1] + δ[n - 2], and plot it using a subplot, which consists
of two rows and two columns. The time index should vary from -5 to +5.
2. Write a python code to generate the finite length discrete-time signals
(a) x1[n] = u[n] - u[n - 5], (b) x2[n] = δ[n], (c) x3[n] = u[n + 5] - u[n - 5]
n, 0 ≤ n ≤ 5
and (d) x4 ½n] = in the interval -10 ≤ n ≤ 10. Use subplot to plot
0, otherwise
the generated signals.
π
3. Generate a complex exponential signal x½n] = ej4n , - 10 ≤ n ≤ 10. Perform the
following: (a) Extract the real and imaginary part of this signal. (b) Reconstruct
the signal x[n] from the real and imaginary parts using the relation x[n] = Re {x
[n]} + j Im {x[n]}.
π
4. Generate a complex exponential signal of the form x½n] = ej8n , - 10 ≤ n ≤ 10.
*
Obtain the signal y[n], which is expressed as y[n] = x[n] × x [n], and comment
on the nature of the signal y[n].
5. Write a python code to generate the following sequences:
116 3 Generation and Operation on Discrete-Time Sequence
Amplitude
Amplitude
0 0
–5
–1
0.00 0.25 0.50 0.75 1.00 0.00 0.25 0.50 0.75 1.00
Time Time
rxx(I) rxy(I)
50
Cross correlation
Autocorrelation
25
0 0
–25
Fig. 3.62 Autocorrelation and cross-correlation of clean and noisy sine wave
x1[n]
1.0
Amplitude
0.5
0.0
–20 –15 –10 –5 0 5 10 15 20
n-->
x2[n]
1.0
Amplitude
0.5
0.0
–20 –15 –10 –5 0 5 10 15 20
n-->
A. -1
B. -2
C. 0
D. 2
3. If the variable ‘x’ contains the signal of interest, then the variable ‘y’ in the
following python code returns
5. The signal generated in the variable ‘x’ after executing the following segment of
code is
A. 1J
B. 2J
C. 3J
D. 4J
7. What operation is performed on the input signal ‘x’ if the following segment of
code is executed?
10. The energy of the signal is unaltered by the following mathematical operation:
A. Downsampling of the signal by a factor of ‘M’
B. Upsampling the signal by a factor of ‘L’
C. Delaying or advancing the signal by a factor of ‘k’
D. Amplitude scaling of the signal
11. Upsampling by a factor of ‘L’ inserts
A. ‘L’ zeros between successive samples
B. ‘L – 1’ zeros between successive samples
C. ‘L + 1’ zeros between successive samples
D. ‘L + 2’ zeros between successive samples
12. If a discrete-time signal x[n] obeys the relation x[-n] = x[n], then the signal is
A. Odd signal
B. Even signal
C. Either even or odd signal
D. Neither even nor odd signal
13. Sum of elements of finite duration discrete-time odd signal is
A. Infinite
B. One
C. Zero
D. Always negative
14. The python code shown below generates the following signal in the variable ‘x’
A. u[n]
B. u[-n]
C. u[n + 5]
D. u[n – 5]
15. The product of two odd signal results in
A. Odd signal
B. Even signal
C. Either even or odd signal depending on the length of the signals
D. Neither even nor odd signal
16. Identify the statement which is FALSE
A. Autocorrelation is finding the relative similarity of the signal to itself.
B. Autocorrelation is an even function.
3.4 Correlation 121
A. 1
B. 2
C. 3
D. 4
18. Assertion: Highpass filter act as change detector
Reason: Highpass filter has the ability to detect the change in the input signal
A. Both assertion and reason are true.
B. Assertion is true, reason is false.
C. Assertion is false, reason may be true.
D. Both assertion and reason are false.
19. What will be the length of the signal ‘y’ if the following code segment is
executed?
A. 11
B. 21
C. 31
D. 41
20. What will be the impulse response (h[n]) if the following code segment is
executed?
A. h[n] = δ[n]
B. h[n] = δ[n - 1]
C. h[n] = u[n]
D. h[n] = u[n - 1]
122 3 Generation and Operation on Discrete-Time Sequence
21. Identify the statement that is WRONG with respect to ‘folding’ or ‘time
reversal’ operation
A. Folding operation does not alter the energy of the signal.
B. Folding increases the length of the signal.
C. If the folded version of the signal is equal to the signal itself, then the signal
is even signal.
D. If the folded version of the signal is equal to the signal itself, then the signal
is odd signal.
22. If x[n] is a unit step signal, then the following signal (y[n]) generated from x[n] is
A. ω = π/2 rad/sample
B. ω = π rad/sample
C. ω = π/4 rad/sample
D. ω = π/8 rad/sample
Bibliography
1. Lonnie C. Ludeman, “Fundamentals of Digital Signal Processing”, John Wiley and Sons, 1986.
2. S. Esakkirajan, T. Veerakumar and Badri N Subudhi, “Digital Signal Processing”, McGraw
Hill, 2021.
3. Sophocles Orfanidis, “Introduction to Signal Processing”, Pearson, 1995.
4. Hwei P. Hsu, “Signals and Systems”, Schaum’s outline series, McGraw Hill Education, 2017.
5. Maurice Charbit, “Digital Signal Processing with Python Programming”, Wiley-ISTE, 2017.
Chapter 4
Discrete-Time Systems
Learning Objectives
After reading this chapter, the reader is expected to
• Obtain the impulse response and step response of the discrete-time system.
• Plot the magnitude and phase response of the discrete-time system.
• Plot the pole-zero plot of the discrete-time system.
• Verifying the linearity, time-invariance, causal and stable properties of the
discrete-time system.
© The Author(s), under exclusive license to Springer Nature Singapore Pte Ltd. 2024 123
S. Esakkirajan et al., Digital Signal Processing,
https://doi.org/10.1007/978-981-99-6752-0_4
124 4 Discrete-Time Systems
Discrete-Time System
PreLab Questions
1. List different forms of representation of discrete-time system.
2. When a discrete-time system is said to be a relaxed system?
3. When a discrete-time system is said to be linear? Give a few examples of linear
system.
4. Is it always true that the cascade of two non-linear systems will result in a non-
linear system? Justify your answer.
5. Why real-time (real-world) systems are considered as causal systems?
6. ‘All memoryless systems are causal, whereas all the causal systems are not
memoryless’. Justify this statement.
7. Is it always true that a cascade of two time-variant systems will result in a time-
variant system? Justify your answer.
8. When a discrete-time system is said to be invertible? Give an example of the
invertible and non-invertible systems.
9. Is it possible to test the causality and stability of a linear time-invariant discrete-
time system from its impulse response? If so, how?
10. Distinguish between static and dynamic discrete-time systems. Cite an example
for static and dynamic discrete-time systems.
11. When is a discrete-time system said to be non-recursive, and when is it said to be
recursive? Give examples for each class of the discrete-time system.
12. The pole-zero plot of a discrete-time system exhibits a zero at z = 1; what can
you infer about this system?
13. When is a discrete-time system invertible? Give an example of a discrete-time
system, which is invertible, and an example of a non-invertible discrete-time
system.
14. Mention two advantages of state-space representation of the discrete-time
system.
4.2 Representation of DT Systems 125
Different forms of representation of DT systems include (1) block diagram, (2) dif-
ference equation, (3) transfer function, (4) pole-zero plot, (5) state-space, etc. Python
illustration with respect to different forms of representation of discrete-time system
and python examples to obtain different DT system responses, including impulse,
step, magnitude and phase responses, are discussed in this chapter.
The relationship between the input and output of a discrete-time linear time-invariant
(LTI) system is expressed in terms of linear constant coefficient difference equation
(LCCDE) as
N -1 M -1
ak y½ n - k ] = bk x ½ n - k ] ð4:1Þ
k=0 k=0
where {ak} and {bk} are the output and input coefficients respectively. The above
equation represents the fact that weighted sum of input is equal to the weighted sum
of output. Equation (4.1) can be expanded as
a0 y ½ n] þ a 1 y ½ n - 1] þ ⋯ þ a N y ½ n - N ] = b 0 x ½ n] þ b 1 x ½ n - 1] þ ⋯
þ bM x½n - M ] ð4:2Þ
If the current output is not a function of the previous output of the system, the
system is said to be a non-recursive system. The input-output relationship of a
non-recursive system is given by
1
y ½ n] = y½n - 1] þ x½n] ð4:6Þ
2
Let us consider the input to the system as a unit step signal; hence, the above
equation can be written as
1
y ½ n] = y½n - 1] þ u½n] ð4:7Þ
2
1
y½ 0] = y½ - 1] þ u½ 0 ]
2
If the initial condition is zero, y[-1] = 0 and u[0] = 1; hence, the above equation
can be written as
4.2 Representation of DT Systems 127
y½0] = 1
1
y½1] = y½ 0] þ u½ 1]
2
Substituting the value of y[0] as 1 and u[1] = 1 in the above equation, we get
1 3
y½1] = ×1 þ 1=
2 2
1 3
y½ 2] = × þ1
2 2
5
y½ 2] =
4
3 5
y½n] = 1, , ,⋯
2 4
The python code, which obtains the output of the system, is given in Fig. 4.2, and
the corresponding output is shown in Fig. 4.3.
import numpy as np
from scipy import signal
import matplotlib.pyplot as plt
n=np.arange(0,4)
x=np.ones(len(n)) #Input
#Defining the system
num=[1]
den=[1,-1/2]
#Obtaining the output
y=signal.lfilter(num,den,x)
#Displaying the result
plt.stem(y),plt.xlabel('n-->'),plt.ylabel('Amplitude'),plt.title('y[n]')
plt.tight_layout()
y[n]
1.75
1.50
1.25
Amplitude
1.00
0.75
0.50
0.25
0.00
0.0 0.5 1.0 1.5 2.0 2.5 3.0
n-->
Inference
The output of the system obtained using python example is in agreement with the
theoretical result.
Task
1. Write a python code to obtain the impulse response of a discrete-time system,
whose input and output are related as y[n] = x[n] + 2y[n - 1]. Also, try to answer
the question “whether the impulse response is absolutely summable or not”.
Experiment 4.2 Solution of Difference Equation with Initial Condition
This experiment deals with solving the difference equation with the initial condition.
The relationship between the input and output of a discrete-time system is given by
1
y½n] = y½n - 1] þ x½n] ð4:8Þ
2
n
If x½n] = 14 u½n] and y[-1] = 1.
n
Substituting x½n] = 14 u½n] in Eq. (4.8), we get
1 1 n
y½n] = y ½ n - 1] þ u½ n] ð4:9Þ
2 4
1 1 0
y½0] = y½ - 1] þ u½ 0]
2 4
1 0
Substituting y[-1] = 1 and 4 u½0] = 1 in the above equation, we get
4.2 Representation of DT Systems 129
import numpy as np
from scipy import signal
n=np.arange(0,4)
x=(1/4)**n
num=[1]
den=[1,-1/2]
y1=signal.lfiltic(num,den,y=[1.])
y=signal.lfilter(num,den,x,zi=y1)
print(y[0]) [1.5 1. 0.5625 0.296875]
Fig. 4.4 Python code to obtain the solution of difference equation. (a) Python Code (b) Result
1 3
y½0] = ×1 þ 1=
2 2
1 1 1
y½1] = y½ 0] þ u½ 1]
2 4
1 3 1
y½ 1] = × þ =1
2 2 4
1 1 2
y½2] = y½ 1] þ u½ 2]
2 4
1 1 9
y½2] = ×1 þ = = 0:5625:
2 16 16
The python code, which obtains the solution of the difference equation with a
non-zero initial condition, is given in Fig. 4.4a, and the corresponding output is
shown in Fig. 4.4b.
Inference
The built-in function ‘lfiltic’ and ‘lfilter’ is used to obtain the solution of difference
equation. The experimental result is in agreement with the theoretical result.
130 4 Discrete-Time Systems
The state-space model describes the system’s dynamics through two equations,
namely: ‘state equation’ and ‘output equation’. The state equation describes how
the input influences the state, and the output equation describes how the state and the
input directly influence the output. It is to be noted that the state-space representa-
tions of a particular system’s dynamics are not unique. The two equations are given
below
where u[k] 2 ℜm is the input, y[k] 2 ℜ p is the output and x[k] 2 ℜn is the state
vector. 'A' is the system matrix, 'B' and 'C' are the input and output matrices, and 'D' is
the feed forward matrix.
Assuming an zero initial condition (x0), the above equation can be expressed as
Substituting the expression for X(z) from Eq. (4.12) in Eq. (4.13), we get
4.2 Representation of DT Systems 131
Y ðzÞ
H ðzÞ = = CðzI - AÞ - 1 B þ D ð4:14Þ
U ðzÞ
and
-1 2 1
where A = , B= , C = [-1 2] and D = [1]. Obtain the transfer
1 0 0
function of the system using python.
The relationship between the transfer function and state-space representation is
given by
H ðzÞ = CðzI - AÞ - 1 B þ D
z 0 -1 2
zI - A = -
0 z 1 0
zþ1 -2
zI - A =
-1 z
z 2
z 2 þ z-2 z2 þ z - 2
ðzI - AÞ - 1 =
1 zþ1
z2 þ z - 2 z2 þ z - 2
H ðzÞ = CðzI - AÞ - 1 B þ D
z 2
z2 þ z - 2 z2 þ z - 2 1
H ðzÞ = ½ - 1 2] þ ½ 1]
1 zþ1 0
z2 þ z - 2 z2 þ z - 2
-z þ 2 2z 1
H ðzÞ = þ ½ 1]
z2 þ z - 2 z2 þ z - 2 0
Upon simplifying the above equation, the transfer function of the system is
given by
-z þ 2
H ðzÞ = þ1
z2 þ z - 2
z2
H ðzÞ =
z2 þ z - 2
The built-in function ‘ss2tf’ available in scipy library can be used to obtain the
transfer function of the system from the state-space representation. The python
code, which performs this task, is shown in Fig. 4.5, and the corresponding output
is shown in Fig. 4.6.
4.2 Representation of DT Systems 133
Upon executing the code shown in Fig. 4.5, the transfer function of the system
obtained is given in Fig. 4.6.
Inference
The transfer function obtained using the built-in function ‘ss2tf’ is in agreement with
the theoretical result.
Experiment 4.4 Transfer Function to State-Space
The objective of this experiment is to obtain the state-space representation of the
2
discrete-time system, whose transfer function is given by H ðzÞ = z2 þzz - 2. As per the
previous experiment, the value of the state-space model parameters should be
-1 2 1
A= , B= , C = ½ - 1 2 ] and D = [1]. The built-in function
1 0 0
‘tf2ss’ in scipy library can be used to obtain the state-space representation of
discrete-time system from the transfer function. The python code, which performs
this task, is shown in Fig. 4.7, and the corresponding output is shown in Fig. 4.8.
Inference
From Fig. 4.8, it is possible to observe that the state-space model parameters are
-1 2 1
A= , B= , C = ½ - 1 2 ] and D = [1].
1 0 0
Task
1. What will be the value of the state-space parameter ‘c’ if the numerator and the
denominator polynomial of the transfer function are same? For example,
2
þzþ1
H ðzÞ = zz2 þzþ1.
134 4 Discrete-Time Systems
Impulse response is the reaction of the discrete-time system to unit sample input
signal, whereas step response is the reaction of the system to unit step input signal.
The discrete-time system is completely characterised by its impulse response. The
meaning is, if one knows the impulse response of the system, it is possible to infer
whether the system is causal and stable from it.
Figure 4.9 depicts the input-output relationship of a discrete-time system in which
x[n] represents the input signal, h[n] represents the impulse response and y[n]
represents the output of the system. If the system is a LTI system, then the output
of the system is expressed as
In the above expression, ‘*’ indicates the convolution operation. If the input to the
system is unit sample signal, then the output of the system is given by
Convolution of any signal with unit sample signal results in the same signal;
hence, the above equation can be expressed as
Thus, the impulse response of the system is the reaction of an LTI system to unit
sample input signal.
The reaction of LTI system to unit step input signal is termed as step response of
the system. It is denoted as s[n]. The relationship between step response (s[n]) and
impulse response (h[n]) is given by
n
s½n] = h½k ] ð4:18Þ
k= -1
Fig. 4.10 Python code to obtain the impulse and step response of the system
Impulse response is the response of the system to unit sample input signal, and
step response is the response of the system to unit step input signal. The python code,
which computes the impulse and step response of the system, is shown in Fig. 4.10,
and the corresponding output is shown in Fig. 4.11.
Inferences
The following inferences can be made from this experiment:
1. From Fig. 4.11, it is possible to observe that the impulse response of the system is
unit step signal. This implies h[n] = u[n]. The impulse response of the system is
not absolutely summable; hence, this system is not stable system.
2. The step response of the system is a ramp signal. This implies s[n] = nu[n].
Task
1. In the above experiment if h[n] = δ[n], what will be the step response of the
system?
Experiment 4.6 Computation of Impulse and Step Responses of the System
from the Difference Equation
This experiment also discusses the computation of the impulse and step response
from the difference equation. Let us consider the discrete-time LTI system, whose
difference equation is given by y[n] - 0.5y[n - 1] = x[n] + x[n - 1]. The python
code, which obtains the impulse and step responses of the given discrete-time
system, is given in Fig. 4.12, and the corresponding output is shown in Fig. 4.13.
136 4 Discrete-Time Systems
0.5
0.0
0 20 40 60 80 100
n-->
Step response (s[n])
100
s[n]
50
0
0 20 40 60 80 100
n-->
Fig. 4.11 Impulse response and step response of the given system
Inferences
The following inferences can be drawn from this experiment:
1. The impulse response decays to zero. The impulse response is absolutely sum-
mable; hence, the given system is a stable system.
2. The step response settles to a finite value after a short span.
Task
1. In the above experiment, from the impulse response, will it be possible to
comment on the stability of the system? Write a python code to find whether
the impulse response is absolutely summable or not?
Experiment 4.7 Computation of Step Response from the Impulse Response
This experiment discusses the computation of step response from the impulse
response. The impulse response of the system is unit step signal. The step response
is obtained by repeatedly adding the impulse response. The python command ‘np.
cumsum’ can be used to obtain the step response of the system from impulse
response of the system. The relationship between input and output of a linear
time-invariant system is given by
It is given that the impulse response is unit step signal; hence, h[n] = u[n]. Also,
unit step response of the system implies that the input to the system is unit step
signal; hence, x[n] = u[n]. The output of the system is given by
4.2 Representation of DT Systems 137
Fig. 4.12 Python code to obtain the impulse and step response of the system
1.0
h[n]
0.5
0.0
0 20 40 60 80 100
n-->
Step response (s[n])
4
s[n]
0
0 20 40 60 80 100
n-->
y½n] = ðn þ 1Þu½n]
The python code, which obtains the step response from the impulse response, is
given in Fig. 4.14, and the corresponding output is shown in Fig. 4.15.
Inferences
The following inferences can be made from this experiment:
1. The impulse response of the system is unit step signal.
2. The step response of the system is (n + 1)u[n], which is similar to that of a ramp
signal.
3. The step response obtained using ‘np.cumsum’ command is in agreement with the
theoretical result.
Experiment 4.8 Impulse Response from Step Response
This experiment tries to obtain the impulse response from the step response. If s[n]
represents the step response of discrete-time system, then the impulse response of the
system is given by
In this experiment, the step response of the discrete-time system is chosen as unit
step signal. This implies s[n] = u[n]. Upon taking the impulse response as per
Eq. (4.21), one should obtain
h ½ n ] = u ½ n ] - u ½ n - 1] ð4:22Þ
0.5
0.0
0 2 4 6 8
n-->
Step response (s[n])
10
s[n]
0
0 2 4 6 8
n-->
The impulse response of the system is obtained as unit sample signal. The python
code, which obtains the impulse response from the step response, is shown in
Fig. 4.16, and the corresponding output is shown in Fig. 4.17.
Inferences
From this experiment the following inferences can be drawn:
1. From Fig. 4.17, the step response of the system is unit step sequence.
2. From the step response, the impulse response is derived which is unit sample
signal, which is in agreement with the theoretical result.
The pole-zero plot of a discrete-time system is plotted in the Z-plane. The position on
the complex plane is represented by rejω. The transfer function of the discrete-time
system is given by
BðzÞ
H ðzÞ = ð4:24Þ
AðzÞ
The zeros are value of ‘z’ for which B(z) = 0. In other words, zeros are the
complex frequencies that make the overall gain of the transfer function is zero. The
140 4 Discrete-Time Systems
0.5
0.0
0 20 40 60 80 100
n-->
Impulse response (h[n])
1.0
h[n]
0.5
0.0
0 20 40 60 80 100
n-->
poles are the values of ‘z’ for which A(z) = 0. The poles are the complex frequencies
that make the overall gain of the transfer function is infinite. The poles and zeros in
the Z-plane are indicated by the symbol ‘x’ and ‘o’, respectively.
Experiment 4.9 Plotting the Zeros of Non-recursive System
The objective of this experiment is to plot the zeros of the non-recursive system.
Consider two discrete-time system with the transfer function H1(z) = 1 - z-1 and
H2(z) = 1 + z-1. The built-in function ‘tf2zpk’ in scipy library is utilized to plot the Z-
plane of the two systems. The python code does this task is shown in Fig. 4.18, and
the corresponding output is shown in Fig. 4.19.
4.2 Representation of DT Systems 141
#Pole-zero plot
import numpy as np
import matplotlib.pyplot as plt
from scipy import signal
#To plot the unit circle
theta=np.linspace(0,2*np.pi,100)
#Defining system-1
num1, den1=[1,-1],[1]
z1,p1,k1=signal.tf2zpk(num1,den1)
#Defining system-2
num2,den2=[1,1],[1]
z2,p2,k2=signal.tf2zpk(num2,den2)
#To plot unit circle
plt.subplot(1,2,1),plt.plot(np.real(z1),np.imag(z1),'ko')
plt.plot(np.real(p1),np.imag(p1),'rx'),plt.plot(np.cos(theta),np.sin(theta))
plt.title('Z-plane of system-1'),plt.xlabel('$\sigma$'),plt.ylabel('$j\omega$')
plt.subplot(1,2,2), plt.plot(np.real(z2),np.imag(z2),'ko'),
plt.plot(np.real(p2),np.imag(p2),'rx'),plt.plot(np.cos(theta),np.sin(theta)),
plt.title('Z-plane of system-2'),plt.xlabel('$\sigma$'),plt.ylabel('$j\omega$')
plt.tight_layout()
Fig. 4.18 Python code to plot the Z-plane of the given system
Inferences
The following inferences can be made for discrete-time systems 1 and 2:
1. System-1 has zero at z = 1. This implies that the zero occurs at ω = 0. This zero
will block all low frequency components; hence, the system will act like a high
pass filter.
2. System-2 has zero at z = -1. This implies that the zero occurs at ω = π. The
system-2 will block all high frequency components. Thus, the system-2 will act
like a low pass filter.
Task
1. From the pole-zero plot, will it be possible to find whether systems-1 and -2 are
minimum phase system or not?
Experiment 4.10 Plot the Magnitude and Phase Responses of Non-recursive
System
The objective of this experiment is to plot the magnitude and phase responses of the
given non-recursive systems. Consider two discrete-time system with the transfer
function H1(z) = 1 - z-1 and H2(z) = 1 + z-1. The built-in function ‘freqz’ in scipy
library can be used to obtain the magnitude and phase response of the system. The
python code, which does this task, is shown in Fig. 4.20, and the corresponding
output is shown in Fig. 4.21.
142 4 Discrete-Time Systems
0.75 0.75
0.50 0.50
0.25 0.25
0.00 0.00
jw
jw
–0.25 –0.25
–0.50 –0.50
–0.75 –0.75
–1.00 –1.00
–1 0 1 –1 0 1
s s
Inferences
The following inferences are made from this experiment:
1. From the magnitude responses of system-1 and system-2, it is possible to infer
that system-1 acts like a high pass filter and system-2 acts like low pass filter.
2. From the phase responses of the two systems, it is possible to infer that both the
systems exhibit linear phase characteristics in the pass band. This means that the
phase angle varies linearly with respect to frequency. The linear phase response
implies that the system will not exhibit phase distortion. The linear phase
characteristics is an important attribute of finite impulse response filter.
Task
1. In the above experiment, what is the purpose of the command ‘np.unwrap’? What
will happen if this command is not included in the program?
Fig. 4.20 Python code to plot the magnitude and phase response of the system
0 0
Magnitude
Magnitude
–20 –20
–40 –40
0 1 2 3 0 1 2 3
w w
Phase response-System1 Phase response-System2
1.5 0.0
–0.5
Phase
Phase
1.0
0.5 –1.0
0.0 –1.5
0 1 2 3 0 1 2 3
w w
Fig. 4.22 Python code to obtain the responses of the discrete-time system
4.4 Different Representations and Response of Unit Delay Discrete-Time System 145
|H((jw)|
h[n]
0.5 20
0
0.0
0 25 20 75 100 0 1 2 3
n--> w -->
Z-plane Phase response
1 0
<H(jw)
0
jw
–1
–1
–1.0 –0.5 0.0 0.5 1.0 0 1 2 3
s w -->
Task
1. From the impulse response and the pole-zero plot, will it be possible to comment
on the stability of the system?
Consider a discrete-time system, which introduces unit delay between the input and
output signal. The different representations of unit delay system are discussed first.
(a) Block diagram representation
The block diagram, which represents unit delay system, is given in Fig. 4.24.
(b) Transfer function representation
The transfer function representation of unit delay system is given by
H ðzÞ = z - 1 ð4:25Þ
x[n] y[n]
z-1
h½ n] = Z - 1 fH ð z Þ g ð4:26Þ
Substituting the expression of H(z) from Eq. (4.25) in Eq. (4.26), we get
h½ n] = Z - 1 z - 1
In the above equation, ‘*’ represents the convolution. To obtain the step
response of the system, x[n] = u[n] and h[n] = δ[n - 1], which is obtained from
the previous result.
The above equation can be simplified by using the property of delta function
as
s ½ n ] = u ½ n - 1]
Fig. 4.25 Python code to obtain the response of unit delay system
delay) version of the input signal. The python code, which accomplishes this task, is
shown in Fig. 4.25, and the corresponding outputs are shown in Figs. 4.26 and 4.27,
respectively.
Inferences
From this experiment following inferences can be made:
1. From Fig. 4.25, it is possible to observe that the python code consists of two
sections. Section 1 obtains the responses of the unit delay system, which include
(a) impulse response, (b) step response, (c) magnitude response and (d) phase
response.
2. The section of python code simulates sinusoidal signal of 5 Hz frequency as the
input signal, and it is fed to the unit delay system to obtain the output signal. The
input is represented by the variable ‘x’, and the variable represents the output ‘y’.
148 4 Discrete-Time Systems
|H(jw)|
h[n]
0.5 1.00
0.0 0.95
0 2 4 6 8 0 1 2 3
n--> w -->
Step response Phase response
1.0 0
<H(jw)
s[n]
0.5
–2
0.0
0 2 4 6 8 0 1 2 3
n--> w -->
0.50
0.25
Amplitude
0.00
–0.25
–0.50
–0.75
–1.00
0.0 0.2 0.4 0.6 0.8 1.0
Time
3. From Fig. 4.26, the impulse response of the filter is obtained as h[n] = δ[n - 1],
which is in agreement with the theoretical result. The step response of the system
is given by s[n] = u[n - 1], which is in agreement with the theoretical result. The
magnitude response of the unit delay system is unity, which implies that the
system will not affect the magnitude of the input signal. The phase response
varies linearly with respect to frequency.
4.5 Properties of Discrete-Time System 149
4. Figure 4.27 depicts the input and output signal. The input signal is a sinusoidal
signal of 5 Hz frequency. From this figure, it is possible to observe that the output
signal is a delayed version of the input signal. The delay between the input and
output signal is one unit, which justifies the term the system is a unit delay
system.
Task
1. From the impulse response, will it be possible to comment on the stability of the
system? If so, state whether the system is stable or unstable.
The properties of discrete-time system discussed in this section include (1) linearity
property, (2) time shift property, (3) causality and (4) stability.
Fig. 4.28 Python code to test the linearity of the given discrete-time system
4.5 Properties of Discrete-Time System 151
5.0
2.5
0.0
–10 –9 –8 –7 –6 –5 –4 –3 –2 –1 0 1 2 3 4 5 6 7 8 9 10
n-->
–10
–10 –9 –8 –7 –6 –5 –4 –3 –2 –1 0 1 2 3 4 5 6 7 8 9 10
n-->
Time shift in the output
Amplitude
–10
–10 –9 –8 –7 –6 –5 –4 –3 –2 –1 0 1 2 3 4 5 6 7 8 9 10
n-->
Task
1. The relationship between the input and output of the system is given by
y[n] = x[-n]. Examine whether the system is time-variant or not.
4.5 Properties of Discrete-Time System 153
Fig. 4.32 Python code to plot the impulse response of the system
154 4 Discrete-Time Systems
h1[n] h2[n]
1.0 1.0
Amplitude
Amplitude
0.5 0.5
0.0 0.0
–10 –5 0 5 10 –10 –5 0 5 10
n--> n-->
h3[n] h4[n]
1.0 1.0
Amplitude
Amplitude
0.5 0.5
0.0 0.0
–10 –5 0 5 10 –10 –5 0 5 10
n--> n-->
3. The impulse response of system-3 is zero for n < 0; hence, discrete-time system-3
is a causal system.
4. The impulse response of system-4 is non-zero for n < 0; hence, discrete-time
system-4 is a non-causal system.
5. From the impulse response, it is possible to infer whether the discrete-time system
is causal or not.
Task
1. The relationship between the input and output of the system is expressed as y
[n] = x[-n]. Examine whether the system is causal or not?
It is to be noted that all the above-mentioned criteria are not independent criteria.
It means that one criterion implies the other.
Experiment 4.16 BIBO Stability Criterion
The aim of this experiment is to obtain the given DT system is stable or not. The
relationship between the input and output of a linear time-invariant discrete-time
system is given by y[n] = x[n] + y[n - 1]. The relationship between the input and
output of the system is given by
y ½ n] = x ½ n] þ y ½ n - 1]
Y ð zÞ = X ð zÞ þ z - 1 Y ðz Þ
Y ðzÞ 1
H ðzÞ = =
X ð zÞ 1 - z - 1
The python code, which applies the unit step input signal to the above-mentioned
system, is given in Fig. 4.34, and the corresponding output is shown in Fig. 4.35.
Inference
The following inferences can be made from this experiment:
Figure 4.36 shows that the input signal (x[n]) is a unit step signal, a bounded input
signal. By observing the output signal (y[n]) is not a bounded signal. The output
signal is a ramp signal, which is not bounded. This shows that bounded input signal
to the system does not result in bounded output signal. Hence, the system is not
BIBO stable.
Experiment 4.17 Stability Criterion Based on the Impulse Response
This experiment discusses the stability of the DT system to be checked from the
impulse response of it. Let us consider two discrete-time LTI systems with impulse
n
responses h1 ½n] = 12 u½n] and h2[n] = (2)nu[n].
For the system to be stable, the impulse response should be absolutely summable.
The impulse response of system-1 is absolutely summable; hence, it is stable. On the
other hand, the impulse response of the system-2 is not absolutely summable; hence,
it is unstable. The python code, which plots the impulse response and obtains the
absolute sum of the impulse response of the above-mentioned discrete-time LTI
systems, is given in Fig. 4.36, and the corresponding output is shown in Figs. 4.37
and 4.38.
156 4 Discrete-Time Systems
Fig. 4.34 Python code to check the BIBO criterion of discrete-time LTI system
x[n]
1.0
Amplitude
0.5
0.0
0 10 20 30 40 50
n-->
y[n]
40
Amplitude
20
0
0 10 20 30 40 50
n-->
Inferences
The following inferences can be made from this experiment:
1. From Fig. 4.37, the impulse response of system-1 is absolutely summable,
whereas the impulse response of system-2 is not absolutely summable. Hence,
system-1 is a stable system, whereas system-2 is not a stable system.
4.5 Properties of Discrete-Time System 157
Fig. 4.36 Python code to test the stability of discrete-time system based on the impulse response
Fig. 4.37 The absolute sum of impulse response of the two systems
2. From Fig. 4.38, the impulse response of system-1 (h1[n]) is converging, whereas
the impulse response of system-2 (h2[n]) is diverging. Therefore, system-1 is
stable, and system-2 is unstable.
Experiment 4.18 Stability Based on the Location of Poles of the Discrete-Time
System
This experiment discusses the verification of the stability of the DT system based on
the location of the poles of the DT system. Let us consider the transfer function of
two discrete-time LTI systems given by H 1 ðzÞ = ð1 - 0:2z - 1 Þ2ð1 - 0:4z - 1 Þ and
H 2 ðzÞ = ð1 - 2z - 1 Þ1ð1 - 4z - 1 Þ. For the discrete-time system to be stable, the poles should
lie within the unit circle. The poles of system-1 defined the transfer function H1(z)
lies within the unit circle; hence, the system is stable, whereas the poles of the
system-2 defined by the transfer function H2(z) lies outside the unit circle; hence, the
system is unstable. The python code to obtain the pole-zero plot of the above-
mentioned discrete-time systems is given in Fig. 4.39, and the corresponding output
is shown in Fig. 4.40.
158 4 Discrete-Time Systems
h1[n] h2[n]
1e14
1.0
5
0.8
4
0.6
Amplitude
Amplitude
3
0.4
2
0.2 1
0.0 0
0 20 40 0 20 40
n--> n-->
Inference
From Fig. 4.40, the poles of discrete-time system-1 lies within the unit circle; hence,
the system is stable. The poles of discrete-time system-2 lies outside the unit circle;
hence, the system is unstable.
Task
1. Comment on the stability of a discrete-time system, whose current output
depends on current and past input signal values. Write a python code to validate
your answer.
Fig. 4.39 Python code to obtain the pole-zero plot of the given discrete-time systems
Inferences
The following are the inferences:
1. Two discrete-time systems considered in this example are the following: (1) Sys-
tem-1, downsampling by a factor of 2, and (2) system-2, upsampling by a factor
of 2.
2. The input signals considered to excite the discrete-time signals are denoted as
x1[n] and x2[n]. x1[n] is a DC signal, whereas x2[n] is the highest frequency digital
signal. The output signals of system-1 for the inputs x1[n] and x2[n] are denoted as
s11[n] and s22[n], respectively.
160 4 Discrete-Time Systems
Z-plane of system-1
1
jw
–1
–1.00 –0.75 –0.50 –0.25 0.00 0.25 0.50 0.75 1.00
s
Z-plane of system-2
1
jw
System is Stable
–1
System is Unstable –1 0 1 2 3 4
s
#Invertibility of DT system
import numpy as np
import matplotlib.pyplot as plt
N=10
n=np.arange(N)
x1=np.ones(N)
x2=np.exp(1j*np.pi*n)
#System 1 output
s11=x1[::2]
s12=x2[::2]
#System 2 output
s21=np.zeros(2*len(x1))
s21[::2]=x1
s22=np.zeros(2*len(x2))
s22[::2]=x2
plt.figure(1),plt.subplot(2,2,1),plt.stem(n,x1),plt.xlabel('n-->'),plt.ylabel('Amplitude'),
plt.title('$x_1[n]$'),plt.subplot(2,2,2),plt.stem(s11),plt.xlabel('n-->'),
plt.ylabel('Amplitude'),plt.title('$s_{11}[n]$'),plt.subplot(2,2,3),plt.stem(n,x2)
plt.xlabel('n-->'),plt.ylabel('Amplitude'),plt.title('$x_2[n]$'),plt.subplot(2,2,4),
plt.stem(s12),plt.xlabel('n-->'),plt.ylabel('Amplitude'),plt.title('$s_{12}[n]$')
plt.tight_layout()
plt.figure(2),plt.subplot(2,2,1),plt.stem(n,x1),plt.xlabel('n-->'),plt.ylabel('Amplitude'),
plt.title('$x_1[n]$'),plt.subplot(2,2,2),plt.stem(s21),plt.xlabel('n-->'),
plt.ylabel('Amplitude'),plt.title('$s_{21}[n]$'),plt.subplot(2,2,3),plt.stem(n,x2)
plt.xlabel('n-->'),plt.ylabel('Amplitude'),plt.title('$x_2[n]$'),plt.subplot(2,2,4),
plt.stem(s22),plt.xlabel('n-->'),plt.ylabel('Amplitude'),plt.title('$s_{22}[n]$')
plt.tight_layout()
Fig. 4.41 Python code to examine the invertibility of the given discrete-time systems
3. The output of discrete-time system-2 for the input signals x1[n] and x2[n] is
denoted as s21[n] and s22[n], respectively.
4.5 Properties of Discrete-Time System 161
x1[n] s11[n]
1.0 1.0
Amplitude
Amplitude
0.5 0.5
0.0 0.0
0 2 4 6 8 0 1 2 3 4
n--> n-->
x2[n] s12[n]
1 1.0
Amplitude
Amplitude
0 0.5
–1 0.0
0 2 4 6 8 0 1 2 3 4
n--> n-->
4. Figure 4.42 shows the input and output signals corresponding to system-1
(downsample by a factor of 2). From Fig. 4.42, it is possible to observe that the
input signals x1[n] and x2[n] are different but the output s11[n] and s12[n] are the
same. This shows that the system produces same output for distinct inputs; hence,
the system-1 is a non-invertible system.
5. Figure 4.43 shows the input and output signals corresponding to system-2
(upsample by a factor of 2). From Fig. 4.43, it is possible to observe that the
system produces different output for distinct inputs. Hence, the system-2 is an
invertible system.
Task
1. Write a python code to prove that cascade connection of accumulator and
backward difference system results in an invertible system. System-1 is an
accumulator, whose input-output relation is given by y[n] = x[n] + y[n - 1];
system-2 is a backward system, whose difference equation is given by y[n] = x
[n] - x[n - 1].
Exercises
1. Write a python code to plot the impulse response of the discrete-time system
whose input-output relationship is given by y½n] = x½n] þ 12 y½n - 1]. From the
impulse response plot, will it be possible to comment on the stability of the
system?
2. Write a python code to obtain the state-space representation of the discrete-time
z2
system whose transfer function is given by H ðzÞ = z2 þ4z - 2.
162 4 Discrete-Time Systems
x1[n] s21[n]
1.0 1.0
Amplitude
Amplitude
0.5 0.5
0.0 0.0
0 2 4 6 8 0 5 10 15
n--> n-->
x2[n] s22[n]
1 1
Amplitude
Amplitude
0 0
–1 –1
0 2 4 6 8 0 5 10 15
n--> n-->
z-1
11. The transfer function of a discrete-time system is given by H ðzÞ = .
ðz - 12Þðzþ34Þ
The poles of the system are at
A. - 12 , þ 34
B. 12 , - 34
C. 12 , 34
D. - 12 , - 34
12. The transfer function of a discrete-time system is represented as H(z) = z-1. The
impulse response of the system is given by
A. h[n] = δ[n]
B. h[n] = δ[n - 1]
C. h[n] = δ[n - 2]
D. h[n] = δ[n - 3]
13. Among the transfer function of the discrete-time systems, identify the system
which is NOT BIBO stable system:
A. H ðzÞ = 1
1 - 14z - 1
B. H ðzÞ = 1
1 - 12z - 1
C. H ðzÞ = 1
1 - 34z - 1
D. H ðzÞ = 1
1 - z-1
Bibliography
1. Charles L. Phillips, John M. Parr, and Eve A. Riskin, “Signals, Systems, and Transforms”,
Pearson, 2013.
2. David J. Defatta, Joseph G. Lucas, and Villiam S. Hodgkiss, “Digital Signal Processing: A
System Design Approach”, Wiley India Pvt Ltd, 2009.
3. Simon Haykin, and Bary Van Veen, “Signals and Systems”, Wiley, 2005.
4. S. Esakkirajan, T. Veerakumar and Badri N Subudhi, “Digital Signal Processing”, McGraw
Hill, 2021.
5. Jose Unpingco, “Python for Signal Processing”, Springer, 2013.
Chapter 5
Transforms
Learning Objectives
After completing this chapter, the reader is expected to
• Compute the forward and inverse Z-transform.
• Analyse discrete-time system using Z-transform and discrete-time Fourier
transform.
• Compute the spectrum of continuous-time and discrete-time signals.
• Plot and infer the spectrogram of stationary and non-stationary signals.
• Plot and interpret the scalogram of non-stationary signal.
© The Author(s), under exclusive license to Springer Nature Singapore Pte Ltd. 2024 167
S. Esakkirajan et al., Digital Signal Processing,
https://doi.org/10.1007/978-981-99-6752-0_5
168 5 Transforms
Analysis of Representation of
discrete-time systems signals
Z-transform
Transform is a tool to analyse signals and systems. Signals are converted from time
or spatial domain to frequency domain using transform. Frequency domain is used to
describe the signal in terms of frequency components. Each frequency has its own
amplitude and phase. From the spectrum, it is possible to interpret the frequencies
present in the signal. Thus, the time domain and the frequency domain representation
of the signal are equivalent. It is possible to transform the signal from time domain to
frequency domain and vice versa without any loss of information. Mathematically,
transform takes the inner product of the signal with the basis function. The inner
product is one way of quantifying the similarity or the dissimilarity of two signals.
5.2 Z-Transform
1
X ðzÞ = x½n]z - n ð5:1Þ
n= -1
1
X ð zÞ = x½n]z - n ð5:2Þ
n=0
-1
X ðzÞ = x½n]z - n ð5:3Þ
n= -1
Task
1. Write a python code to obtain the Z-transform of x[n] = nu[n].
Experiment 5.2 Z-Transform of Unit Sample and Unit Step Sequences Using
lcapy Package
This experiment discusses the lcapy package, which can be used to compute the Z-
transform of unit sample and unit step sequences. The python code is shown in
Fig. 5.3.
Inferences
Upon executing the code shown in Fig. 5.3, the result obtained is 1 and 1/(1 - 1/z),
which is in agreement with the theoretical result. The python command delta defines
the unit impulse sequence, 'us' gives the unit step sequence and 'ZT' obtains the Z-
transform.
Experiment 5.3 Z-Transform of x[n] = ejnu[n] and x[n] = cos(n)
This experiment deals with the computation of Z-transform of the given input
sequences x[n] = ejnu[n] and x[n] = cos(n). The python code, which computes the
Z-transform of x[n] = ejnu[n] and x[n] = cos(n), is shown in Fig. 5.4a, and the
corresponding output is shown in Fig. 5.4b.
Inferences
1. From Fig. 5.4a, it is possible to observe that the package lcapy is used to define
the exponential function. lcapy is a Python package for linear circuit analysis.
5.2 Z-Transform 171
nanu[n] za -1
or ð1 -azaz - 1 Þ2 |z| > a
ðz - aÞ2
cos(ω0n)u[n] z - z cos ω0
2 -1
or 1 -12z--z1 coscos ω0 |z| > 1
z2 - 2z cos ω0 þ1 ω0 þ z - 2
sin(ω0n)u[n] z sin ω0 z-1
sin ω0
or 1 - 2z - 1 cos |z| > 1
z2 - 2z cos ω0 þ1 ω0 þ z - 2
[a sin ω0n]u[n]
n az sin ω0 -1
or 1 - 2azaz- 1 cossinωω0 þ0 a2 z - 2 |z| > |a|
z2 - 2az cos ω0 þa2
[a cos ω0n]u[n]
n
zðz - a cos ω0 Þ ð1 - az cos ω0 Þ
-1
|z| > |a|
z2 - 2az cos ω0 þa2 or 1 - 2az - 1 cos ω0 þa2 z - 2
2. Upon executing the commands shown in Fig. 5.4a, the result obtained is shown in
Fig. 5.4b. The result of python code is in agreement with the theoretical result.
172 5 Transforms
Fig. 5.2 Simulation result of the python code given in Fig. 5.1
n
Experiment 5.4 Z-Transform of x½n] = 12 u½n]
This experiment discusses the python code to obtain the Z-transform of x½n] =
1 n
2 u½n] and the corresponding output, which is shown in Fig. 5.5.
Inferences
1. Figure 5.5 shows that the us variable is called from the lcapy package as a unit
step sequence and multiplied by (1/2)n to get x[n].
2. The Z-transform of x[n] is obtained using ‘ZT’ python command, and the result is
displayed in Fig. 5.5. This result confirms the theoretical result.
5.3 Inverse Z-Transform 173
import lcapy
from lcapy import n
x=lcapy.exp(1j*n)
y=lcapy.cos(n)
Xz=x.ZT()
print(Xz)
Yz=y.ZT() z/(z - exp(j))
print(Yz) z*(z - cos(1))/(z**2 - 2*z*cos(1) + 1)
Fig. 5.4 Python code to Experiment 5.3. (a) Pyhton code. (b) Simulation result
Task
3 n
1. Write a python code to obtain the Z-transform of x½n] = 4 u½n].
This section discusses some of the experiments related to the inverse Z-transform.
Experiment 5.5 Inverse Z-Transform of X(z) = z-1
The python code computes the inverse Z-transform of X(z) = z-1, and the
corresponding output is shown in Fig. 5.6.
Inferences
1. From Fig. 5.6a, it is possible to infer that ‘IZT’ python command is used to obtain
the inverse Z-transform.
2. After executing the python code given in Fig. 5.6a, the result obtained is shown in
Fig. 5.6b. This result is in agreement with the theoretical result.
Task
1. Write a python code to obtain the inverse Z-transform of X(z) = z-4.
Experiment 5.6 Inverse Z-Transform of X(z) = 1/1 - z-1
The python code, which computes the inverse Z-transform of X(z) = 1/1 - z-1 and
the corresponding output, is shown in Fig. 5.7. From Fig. 5.7b, it is possible to
174 5 Transforms
Fig. 5.6 Python code to obtain the inverse z-transform of X(z) = z-1 and its result. (a) Python code.
(b) Simulation result
#Inverse Z-transform
import sympy
import lcapy
from lcapy import z
X=1/(1-z**(-1))
x=X.IZT()
print(x) Piecewise((1, n >= 0))
Fig. 5.7 Python code to obtain the inverse Z-transform of X(z) = 1/1 - z-1 and its result. (a)
Python code (b) Simulation result
observe that the result obtained using python code is in agreement with the theoret-
ical result.
Inferences
The inverse Z-transform of X(z) = 1/1 - z-1 will be u[n], and the simulation result of
the python code given in Fig. 5.7a is shown in Fig. 5.7b. This result is in agreement
with the theoretical result.
Task
1. Write a python code to compute the inverse Z-transform of X(z) = 1/1 - z-2.
Based on the nature of the signal, the Fourier family can be classified into Fourier
series or Fourier transform. Fourier series is an effective tool to analyse the periodic
signal. If the signal is aperiodic, Fourier transform can be used to analyse the signal.
Fourier transform can be viewed as the Fourier series when the period ‘T’ tends to
infinity. The Fourier transform is a generalization of the Fourier series representation
of functions. The Fourier series is limited to periodic functions, while Fourier
5.4 Family of Fourier Series and Transforms 175
transform can be used for periodic and aperiodic functions. The family of Fourier
series and transform is given in Table 5.2.
It can be interpreted as taking the inner product of the signal x(t) with the basis
function e-jΩt. This is represented as
Equations (5.4) and (5.5) are termed as ‘analysis equation’. The result of
continuous-time Fourier transform is termed as ‘spectrum’, which is illustrated in
Fig. 5.8. The equations reveal that how an arbitrary signal x(t) can be expanded as a
sum of elementary harmonic functions. The elementary harmonic functions are
termed as the basis function. The Fourier transform uses complex exponentials of
various frequencies as its basis function.
CTFT is a complex function of ‘Ω’ in the range - 1 < Ω < 1. CTFT exists if
the signal x(t) satisfies Dirichlet conditions, which are given below:
1. The signal x(t) has a finite number of discontinuities and a finite number of
maxima and minima in any finite interval.
2. The signal x(t) must be absolutely integrable, which is represented as
176 5 Transforms
1
jxðt Þjdt < 1.
-1
Inverse CTFT refers to obtaining the signal from the spectrum, which is also
called as ‘synthesis equation’. The inverse CTFT is given by
1
1
xð t Þ = X ðΩÞejΩt dΩ ð5:6Þ
2π
-1
From Eq. (5.6), it is possible to interpret that Fourier synthesis formula recon-
structs a signal using a set of scaled complex exponentials.
Analysis refers to the decomposition of the signal into its constituent components
specifying the weights of the basis functions in the expansion. Synthesis refers to the
reconstruction of the signal from the basis functions chosen to represent the signal.
The analysis and synthesis function of CTFT of the signal x(t) is illustrated in
Fig. 5.9.
(a) Forward Fourier Transform
The continuous-time Fourier transform of unit impulse signal is given by
δðΩÞ = 1 ð5:8Þ
5.4 Family of Fourier Series and Transforms 177
From Eq. (5.8), it is possible to interpret that unit impulse contains a compo-
nent at every frequency. Another way to interpret the result is to make up δ(t);
one needs infinite number of equal frequency components.
(b) Inverse Fourier transform of δ(Ω)
The inverse CTFT of δ(Ω) is given by
1
1
xð t Þ = X ðΩÞejΩt dΩ ð5:9Þ
2π
-1
1
-1 1
F fδðΩÞg = δðΩÞejΩt dΩ ð5:10Þ
2π
-1
Using the sampling property of the impulse signal, the above expression can
be simplified as
1
F - 1 f δ ð ΩÞ g = ð5:11Þ
2π
1 $ 2πδðΩÞ
import numpy as np
import matplotlib.pyplot as plt
t=np.linspace(-5,6,100)
w=np.linspace(-50,60,1000)
x=(t==0)
plt.subplot(2,2,1),plt.plot(t,x),plt.xlabel('t-->'),plt.ylabel('$\u03B4[t]$'),plt.title('Input Signal')
y1=np.zeros(len(w))
for i in range(len(t)):
y=x[i]*np.exp(-1j*w*t[i])
y1=y1+y
y2=np.zeros(len(t))
for i in range(len(w)):
y3=y1[i]*np.exp(1j*w[i]*t)
y2=y2+y3
plt.subplot(2,2,2),plt.plot(w,np.abs(y1),linewidth=3),plt.title('Magnitude response')
plt.xlabel('$Ω$-->'),plt.ylabel('|\u03B4(${Ω}$|')
plt.subplot(2,2,3),plt.plot(w,np.angle(y1),linewidth=3),plt.title('Phase response')
plt.xlabel('$Ω$-->'),plt.ylabel('$\phi({Ω})$')
plt.subplot(2,2,4),plt.plot(t,y2/np.max(y2)),plt.xlabel('t-->'),plt.ylabel('$\u03B4[t]$'),
plt.title('Reconstructed Signal')
plt.tight_layout()
Fig. 5.10 Python code to obtain the spectrum of unit impulse signal
0.5 1.00
d [t]
0.0 0.95
–5 0 5 –50 0 50
t--> Ω-->
0.00 0.5
d [t]
–0.05 0.0
–50 0 50 –5 0 5
Ω--> t-->
Task
1. Modify the above code to obtain the Fourier transform of x(t) = δ(t - 5) and
comment on the observed result.
This section focuses on obtaining the spectrum of standard test signals using CTFT.
The standard test signals include sinusoidal signal, Gaussian function and pulse
signal.
Experiment 5.8 CTFT of the Complex Exponential Signal (ejΩ0 t and e - jΩ0 t )
In this experiment, the objective is to obtain the spectrum of the signal ejΩ0 t and
e - jΩ0 t . Both the spectrum should be given an impulse corresponding to the fre-
quency ‘Ω0’. The python code which obtains the spectrum of the signals ejΩ0 t and
e - jΩ0 t is shown in Fig. 5.12 and the corresponding output is shown in Fig. 5.13. To
show the change in the spectrum between the signals ejΩ0 t and e - jΩ0 t , double-sided
spectrum is drawn instead of single-sided spectrum.
import numpy as np
import matplotlib.pyplot as plt
t=np.linspace(-50,50,1000)
w=np.linspace(-5,5,100)
yy=np.exp(1j*(np.pi/4)*t)
xx=np.exp(-1j*(np.pi/4)*t)
plt.subplot(2,2,1),plt.plot(t,yy,linewidth=2),plt.xlabel('t-->'),plt.ylabel('x$_1$(t)')
plt.title('e$^{jΩot}$')
plt.subplot(2,2,2),plt.plot(t,xx,linewidth=2),plt.xlabel('t-->'),plt.ylabel('x$_2$(t)')
plt.title('e$^{-jΩot}$')
y1=np.zeros(len(w))
y2=np.zeros(len(w))
for i in range(len(t)):
y=yy[i]*np.exp(-1j*w*t[i])
y1=y1+y
z=xx[i]*np.exp(-1j*w*t[i])
y2=y2+z
plt.subplot(2,2,3),plt.plot(w,np.abs(y1)/len(t),linewidth=2)
plt.xlabel('$Ω$-->'),plt.ylabel('|X$_1$(${Ω}$|'),plt.title('Double sided Spectrum')
plt.subplot(2,2,4),plt.plot(w,np.abs(y2),linewidth=2)
plt.xlabel('$Ω$-->'),plt.ylabel('|X$_2$(${Ω}$)|'),plt.title('Double sided Spectrum')
plt.tight_layout()
Fig. 5.12 Python code to obtain the spectrum of complex exponential signal
180 5 Transforms
ejΩot e–jΩot
1 1
x1(t)
x2(t)
0 0
–1 –1
–50 –25 0 25 50 –50 –25 0 25 50
t--> t-->
0.5 500
|X1(Ω)|
|X2(Ω)|
0.0 0
–5.0 –2.5 0.0 2.5 5.0 –5.0 –2.5 0.0 2.5 5.0
Ω--> Ω-->
Inferences
From Fig. 5.13, it is possible to observe that both the signals ejΩ0 t and e - jΩ0 t produce
single impulse at Ω = Ω0 and at Ω = - Ω0. In this case, the value of the frequency is
10 Hz; hence, it is possible to observe impulse at π=4 Hz and at - π=4 Hz, respectively,
for the signal ejΩ0 t and e - jΩ0 t .
Task
1. Obtain the CTFT of the signal xðt Þ = ejΩ0 t þ e - jΩ0 t and comment on the observed
result.
Experiment 5.9 Fourier Transform of x(t) = cos(Ωt)
According to Euler’s formula, the cos(Ωt) can be expressed as
ejΩt þ e - jΩt
cosðΩt Þ = ð5:12Þ
2
1 jΩt
cosðΩt Þ = e þ e - jΩt ð5:13Þ
2
1
FTf cosðΩt Þg = FT ejΩt þ FT e - jΩt ð5:14Þ
2
1
FTf cosðΩt Þg = f2πδðΩ - Ω0 Þ þ 2πδðΩ þ Ω0 Þg ð5:17Þ
2
Thus, the spectrum of the cosine signal has two impulses placed symmetrically at
the frequency of the cosine and its negative.
The python code, which obtains the spectrum of cosine wave, is shown in
Fig. 5.14, and the corresponding output is shown in Fig. 5.15.
Inferences
From Fig. 5.15, it is possible to observe that the Fourier transform of the cosine
signal has two impulses placed symmetrically at the frequency of the cosine and its
negative which is in agreement with the theoretical result.
182 5 Transforms
cos(Ωot)
1
x1(t)
–1
–40 –20 0 20 40
t-->
0.4
|X1(Ω)|
0.2
0.0
–4 –2 0 2 4
Ω-->
-τ 0 τ t
Task
1. Write a python code to illustrate the fact that the magnitude spectrum of sine wave
and cosine wave of same amplitude, frequency and phase are alike.
1, jt j < τ
Experiment 5.10 CTFT of the Signal xðt Þ =
0, otherwise
The given signal is a rectangular pulse. It is shown in Fig. 5.16.
The expression for the CTFT of the signal x(t) is given by
In this case, the signal exists from –τ to τ; hence, the limit of integration is
modified as
5.4 Family of Fourier Series and Transforms 183
In the limit –τ to τ, the value taken by the signal x(t) is one; hence, the above
equation can be expressed as
X ð ΩÞ = 1 × e - jΩt dt ð5:21Þ
-τ
Substituting the upper and lower limits in the above expression, we get
e - jΩτ - ejΩτ
X ð ΩÞ = ð5:23Þ
- jΩ
ejΩτ - e - jΩτ
X ð ΩÞ =
jΩ
sinðΩτÞ
X ð ΩÞ = 2
Ω
sinðΩτÞ
X ðΩÞ = 2τ = 2τ sin cðΩτÞ ð5:24Þ
Ωτ
import numpy as np
import matplotlib.pyplot as plt
t=np.linspace(-50,50,1000)
w=np.linspace(-5,5,100)
yy=(abs(t)<15)
xx=(abs(t)<2)
plt.subplot(2,2,1),plt.plot(t,yy,linewidth=1.5),plt.xlabel('t-->'),plt.ylabel('x$_1$(t)')
plt.title('Rectangular Function-1')
plt.subplot(2,2,2),plt.plot(t,xx,linewidth=1.5),plt.xlabel('t-->'),plt.ylabel('x$_2$(t)')
plt.title('Rectangular Function-2')
y1=np.zeros(len(w))
y2=np.zeros(len(w))
for i in range(len(t)):
y=yy[i]*np.exp(-1j*w*t[i])
y1=y1+y
z=xx[i]*np.exp(-1j*w*t[i])
y2=y2+z
plt.subplot(2,2,3),plt.plot(w,np.abs(y1)/len(t),linewidth=1.5)
plt.xlabel('$Ω$-->'),plt.ylabel('|X$_1$(${Ω}$)|'),plt.title('Spectrum-1')
plt.subplot(2,2,4),plt.plot(w,np.abs(y2),linewidth=1.5)
plt.xlabel('$Ω$-->'),plt.ylabel('|X$_2$(${Ω}$)|'),plt.title('Spectrum-2')
plt.tight_layout()
x2(t)
0.5 0.5
0.0 0.0
–50 –25 0 25 50 –50 –25 0 25 50
t--> t-->
Spectrum-1 Spectrum-2
40
0.2
|X1(Ω)|
|X2(Ω)|
20
0.1
0.0 0
–5.0 –2.5 0.0 2.5 5.0 –5.0 –2.5 0.0 2.5 5.0
Ω--> Ω-->
Inferences
The following inferences can be obtained by observing Fig. 5.18:
1. Two rectangular functions, rectangular function-1 and rectangular function-2, are
generated.
2. The width of rectangular function-1 is larger than the width of rectangular
function-2.
3. The spectrum of the rectangular function is observed to be a sinc function.
4. The main lobe width of spectrum-1 is narrower when compared to the main lobe
width of spectrum-2.
5. This example illustrates the fact that compression in the time domain leads to
expansion in the frequency domain and vice versa.
Task
1. Instead of rectangular pulse, obtain the magnitude spectrum of triangular pulse
signal and comment on the observed result. Triangular pulse can be obtained by
convolving two rectangular pulse signals.
1, jΩj < Ω0
Experiment 5.11 Inverse CTFT of X ðΩÞ =
0, otherwise
The expression for inverse continuous-time Fourier transform is given by
1
1
xð t Þ = X ðΩÞejΩt dΩ ð5:25Þ
2π
-1
The spectrum exists from -Ω0 to Ω0; hence, the limit of integration has to be
changed. This is represented as
Ω0
1
xð t Þ = X ðΩÞejΩt dΩ ð5:26Þ
2π
- Ω0
In the interval from -Ω0 to Ω0, the value of the spectrum is unity. This is
expressed as
Ω0
1
xðt Þ = 1 × ejΩt dΩ ð5:27Þ
2π
- Ω0
Ω0
1 ejΩt
xðt Þ = ð5:28Þ
2π jt - Ω0
1 ejΩ0 t - e - jΩ0 t
xð t Þ = ð5:29Þ
2π jt
1 ejΩ0 t - e - jΩ0 t
xð t Þ = ð5:30Þ
πt 2j
sinðΩ0 t Þ
xð t Þ = ð5:31Þ
πt
Fig. 5.19 Python code to obtain the spectrum of sinc and Gaussian function
1 ðt - μÞ2
xðt Þ = p e - 2σ2 ð5:32Þ
σ 2π
If the mean of the Gaussian function is zero, the above expression is given by
1 t2
xðt Þ = p e - 2σ2 ð5:33Þ
σ 2π
Signal-1 Signal-2
1.0 1.0
0.5 0.5
x1(t)
x2(t)
0.0 0.0
–5.0 –2.5 0.0 2.5 5.0 –5.0 –2.5 0.0 2.5 5.0
t--> t-->
|X2(Ω)|
|X1(Ω)|
50
20
0 0
–50 0 50 –50 0 50
Ω--> Ω-->
dxðt Þ 1 t2 - 2t
= p e - 2σ2 × ð5:34Þ
dt σ 2π 2σ 2
dxðt Þ 1 t2 -t
= p e - 2σ2 × 2 ð5:35Þ
dt σ 2π σ
dxðt Þ -t
= xð t Þ × 2 ð5:36Þ
dt σ
dxðt Þ 1
= - 2 txðt Þ ð5:37Þ
dt σ
dxðt Þ 1
FT = - 2 FTftxðt Þg ð5:38Þ
dt σ
dxðt Þ
FT = jΩX ðΩÞ ð5:39Þ
dt
dX ðΩÞ
FTftxðt Þg = j ð5:40Þ
dΩ
1 dX ðΩÞ
jΩX ðΩÞ = - ×j ð5:41Þ
σ2 dΩ
1 dX ðΩÞ
ΩX ðΩÞ = - × ð5:42Þ
σ2 dΩ
dX ðΩÞ
dΩ
= - σ2Ω ð5:43Þ
X ð ΩÞ
dX ðΩÞ
dΩ
= - σ2 ΩdΩ ð5:44Þ
X ð ΩÞ
Ω2
ln½X ðΩÞ] - ln½X ð0Þ] = - σ 2 ð5:45Þ
2
Since the mean value of the Gaussian signal is assumed to be zero, the above
equation can be written as
Ω2
ln½X ðΩÞ] = - σ 2 ð5:46Þ
2
Signal-1 Signal-2
1.0
0.5
x1(t)
x2(t)
0.5
0.0 0.0
–5.0 –2.5 0.0 2.5 5.0 –5.0 –2.5 0.0 2.5 5.0
t--> t-->
2.4 20
|X1(Ω)|
|X2(Ω)| 10
2.2
0
–50 0 50 –50 0 50
Ω--> Ω-->
σ 2 Ω2
X ð ΩÞ = e - 2 ð5:47Þ
Task
1. In the above experiment, Signal-1 and Signal-2 are Gaussian functions. Now
multiply Signal-1 and Signal-2 to obtain Signal-3. Obtain the spectrum of Signal-
3 and comment on the observed result.
1
X ejω = x½n]e - jωn ð5:48Þ
n= -1
In the above expression, |X(ejω)| represents the magnitude of DTFT, and Φ(ejω)
represents the phase of DTFT. The magnitude spectrum determines the relative
presence of a sinusoid in the signal x[n], whereas the phase spectrum determines
how the sinusoids line up relative to one another to form the signal x[n]. The
condition for the existence of DTFT is that the signal x[n] should be absolutely
summable. The signal x[n] is absolutely summable if it obeys the following
condition:
1
jx½n]j < 1 ð5:50Þ
n= -1
π
1
x ½ n] = X ejω ejωn dω ð5:51Þ
2π
-π
j nj < N
1,
Experiment 5.13 DTFT of x½n] =
0, otherwise
The signal x[n] represents a rectangular pulse. The DTFT of x[n] is given by
192 5 Transforms
N
X ejω = 1 × e - jωn
n= -N
aNþ1 - a - N
N
a = , jaj < 1 , the above
Using the summation formula n
a-1
n= -N 2N þ 1, a = 1
equation can be written as
e - jωðNþ1Þ - ejωN
X ejω = , e - jω < 1
e - jω - 1
e - jωN e - jω - ejωN
X ejω =
e - jω - 1
sin N þ 12 ω
X ejω = if e - jω < 1
sin ω2
This shows that Fourier transform of a rectangular pulse signal will result in a sinc
function.
Python code for the DTFT of rectangular pulse is given in Fig. 5.22, and its
corresponding output is shown in Fig. 5.23.
5.4 Family of Fourier Series and Transforms 193
x[n]
0
–4 –2 0 2 4
n-->
Magnitude response
|X(jw )|
2.5
0.0
–10.0 –7.5 –5.0 –2.5 0.0 2.5 5.0 7.5 10.0
w -->
Phase response
2.5
f (jw )
0.0
–2.5
–10.0 –7.5 –5.0 –2.5 0.0 2.5 5.0 7.5 10.0
w -->
Inferences
From Fig. 5.23, it is possible to infer that the magnitude response of a rectangular
function is a sinc function, which is in agreement with the theoretical result.
Task
1. In the above experiment, x[n] is a rectangular pulse signal. What will be the
impact of increasing the width of the signal x[n] in the magnitude and phase
responses?
The block diagram of discrete-time LTI system with the input signal x[n], impulse
response h[n] and the output signal y[n] is shown in Fig. 5.24.
The relationship between the input and output of the system if it is LTI is given by
Equation (5.53) is obtained using the fact that convolution in time domain is
equivalent to multiplication in the Fourier domain.
The frequency response of the system from Eq. (5.53) can be expressed as
Y ðejω Þ
H ejω = ð5:54Þ
X ðejω Þ
import numpy as np
import matplotlib.pyplot as plt
from scipy import signal
#Step 1: Impulse response of the two systems
h1=[0.5,0.5]
h2=[0.5,-0.5]
#Step 2: Obtaining the frequency response
w1, H1 = signal.freqz(h1,1)
w2, H2 = signal.freqz(h2,1)
angle_1 = np.unwrap(np.angle(H1))
angle_2 = np.unwrap(np.angle(H2))
#Step3 : Plotting the responses
plt.subplot(2,3,1),plt.stem(h1),plt.xlabel('n-->'),plt.ylabel('h$_1$[n]')
plt.title('Impulse response'),plt.subplot(2,3,2),plt.plot(w1, 10 * np.log10(abs(H1)))
plt.xlabel('$\omega$-->'),plt.ylabel('|X(${j\omega}$)|'),plt.title('Magnitude response')
plt.subplot(2,3,3),plt.plot(w1,(angle_1)),plt.xlabel('$\omega$--
>'),plt.ylabel('$\phi({j\omega})$')
plt.title('Phase response'),plt.subplot(2,3,4),plt.stem(h2),plt.xlabel('n-->'),
plt.ylabel('h$_2$[n]'),plt.title('Impulse response'),plt.subplot(2,3,5),
plt.plot(w1, 10 * np.log10(abs(H2))),plt.xlabel('$\omega$-->'),
plt.ylabel('|X(${j\omega}$)|'),plt.title('Magnitude response')
plt.subplot(2,3,6),plt.plot(w1,(angle_2)),plt.xlabel('$\omega$-->'),
plt.ylabel('$\phi({j\omega})$'),plt.title('Phase response')
plt.tight_layout()
Fig. 5.25 Python code to obtain the magnitude and phase response of the systems
–10
h1[n]
f (jw)
0.2 –1
–20
0.0
0 1 0 2 0 2
n--> w--> w-->
1
|X(jw)|
–10
f (jw)
h2[n]
0.0
–20
–0.5 0
0 1 0 2 0 2
n--> w--> w-->
N -1
x½n]e - j N kn , k = 0, 1, 2, . . . , N - 1
2π
X ½k ] = ð5:56Þ
n=0
N -1
X ½k ] = x½n]W kn
N ð5:57Þ
n=0
where
WN = e - jN
2π
ð5:58Þ
The signal is reconstructed by using the inverse discrete Fourier transform, which
is defined as
N -1
1 2π
x½n] = X ½k]ej N kn ð5:59Þ
N k=0
The forward transform is generally known as ‘analysis’, and the inverse transform
is called as ‘synthesis’.
Experiment 5.15 Plotting the Twiddle Factor for N = 8
The aim of this experiment is to plot the twiddle factor of DFT with the length N = 8.
The python code, which plots the twiddle factor or phase factor for N = 8, is shown
in Fig. 5.27, and the corresponding output is shown in Fig. 5.28.
Inference
From Fig. 5.28, it is possible to observe that for the choice of N = 8, the unit circle is
divided into eight equal portions.
0.50
0.25
0.00
–0.25
–0.50
–0.75
–1.00
–1.0 –0.5 0.0 0.5 1.0
1 1 1 ⋯ 1
1.ðN - 1Þ
1 W 1.1
N W 1.2
N ⋯ WN
2.ðN - 1Þ
WN = 1 W 2.1
N W 2.2
N ⋯ WN ð5:60Þ
⋮ ⋮ ⋮ ⋯ ⋮
ðN - 1Þ.1 ðN - 1Þ.2 ðN - 1Þ.ðN - 1Þ
1 WN WN ⋯ WN
1 1
W2 = ð5:61Þ
1 -1
1 1 1 1
1 -j -1 j
W4 = ð5:62Þ
1 -1 1 -1
1 j -1 -j
Fig. 5.31 Python code to obtain the DFT matrix and its result. (a) Python code. (b) Simulation
result
Fig. 5.32 Python code to compute the rank of the matrix and its result. (a) Python code. (b)
Simulation result
Inference
The signal x[n] is a DC signal, which is given by x[n] = {1, 1, 1, 1}. The DFT of the
sequence x[n] is obtained as X[k] = {4, 0, 0, 0}. The maximum energy of the
sequence x[n] is packed into one transform coefficient. This is through energy
compaction property of DFT. In Fig. 5.33, the symbol (‘@’) denotes matrix multi-
plication in python.
Experiment 5.19 Computation of Inverse DFT Through DFT Matrix
Let us consider the DFT coefficients X[k] = {4, 0, 0, 0}. The python code to compute
the inverse DFT of X[k] = {4, 0, 0, 0} is given in Fig. 5.34. After executing this code,
we get the result of {1, 1, 1, 1}, which is in agreement with the theoretical result.
Inference
The inverse DFT of X[k] = {4, 0, 0, 0} is x[n] = {1, 1, 1, 1}. The experimental result
is in agreement with the fact that DFT is invertible. This is to inform that the inverse
DFT computation is done by the forward DFT matrix, which can be seen in
Fig. 5.34.
Discrete Fourier transform is applied to discrete-time signal x[n] that are zero for
n < 0 and n ≥ N. However, the discrete-time signal x[n] must be considered a
periodic signal. Therefore, some of the DFT properties are based on modulo N or
5.4 Family of Fourier Series and Transforms 201
The python code, which verifies the linearity property of DFT, is shown in
Fig. 5.35, and the corresponding output is shown in Fig. 5.36.
Inferences
The following inferences can be made from this experiment:
202 5 Transforms
x3[n]
10
0
x1[n]
x2[n]
0.5 0 0 1 2 3 4 5 6 7
n-->
0.0 –1 X3[k]
0 2 4 6 0 2 4 6
X3[k]
n--> n--> 50
X1[k] X2[k] 0
0 1 2 3 4 5 6 7
k-->
X1[k]
X2[k]
5 5 X4[k]=a*X1[k]+b*X2[k]
X4[k]
50
0 0 0
0 2 4 6 0 2 4 6 0 1 2 3 4 5 6 7
k--> k--> k-->
1. From Fig. 5.35, the input signals chosen to prove the linearity property of DFT
are x1[n] = {1, 1, 1, 1, 1, 1, 1}, which is a DC signal, and x2[n] = {1, -1, 1, -1, -
1, 1, -1} which is an AC signal. The scaling factors chosen in this example are
a = 5, b = 10.
2. From Fig. 5.36, it is possible to observe the following facts:
(a) DFT of the DC signal x1[n] is represented as X1[k], which exhibits peak at
k = 0. DFT of the signal x2[n] shows the peak at k = 4.
(b) The DFT of ax1[n] + bx2[n] is equal to aX1[k] + bX2[k]. This implies that DFT
obeys homogeneity and additivity properties; hence, it is a linear transform.
Experiment 5.21 Verification of Circular Shift Property of DFT
The circular shift property of DFT is expressed as
DFT
x½ðn - mÞmodN ] $ e - j N km X ½k]
2π
ð5:64Þ
The python code to illustrate the circular shift property of DFT is shown in
Fig. 5.37, and the corresponding output is shown in Fig. 5.38.
Inferences
After executing the python code given in Fig. 5.37, the result of input signal x[n] is
{4, 3, 2, 1}, and the circularly shifted sequence with k = 2 is obtained as {2, 1, 4, 3}.
The DFT of the input sequence x[n] and its circularly shifted version is shown in
Fig. 5.38. From this figure, it is possible to confirm that the magnitude spectrum of
both sequences is the same, whereas the phase spectrum is different. This indicates
that ‘time shift in the time domain corresponds to phase shift in the frequency
domain’.
Experiment 5.22 Verification of the Parseval’s Relationship of DFT
According to Parseval’s relation, energy in time domain is equivalent to energy in
frequency domain.
5.4 Family of Fourier Series and Transforms 203
2.5
z[n]
0.0 0.0
0.0 0.5 1.0 1.5 2.0 2.5 3.0 0.0 0.5 1.0 1.5 2.0 2.5 3.0
n--> n-->
Magnitude response Magnitude response
10 10
|x[k]|
|z[k]|
0 0
0.0 0.5 1.0 1.5 2.0 2.5 3.0 0.0 0.5 1.0 1.5 2.0 2.5 3.0
k--> k-->
Phase response Phase response
0.5 2.5
f [k]
f [k]
0.0 0.0
–0.5 –2.5
0.0 0.5 1.0 1.5 2.0 2.5 3.0 0.0 0.5 1.0 1.5 2.0 2.5 3.0
k--> k-->
N -1 N -1
1
jx½n]j2 = j X ½ k ]j 2 ð5:65Þ
n=0
N k=0
The python code to verify the Parseval’s relation of DFT is given in Fig. 5.39, and
its simulation output is shown in Fig. 5.40.
Inference
From Fig. 5.40, it is possible to confirm that the energy in time domain and the
energy in the frequency domain are the same. Hence, converting the time domain
signal into the frequency domain using DFT always preserves energy. Therefore, the
perfect reconstruction of the original signal from the frequency components is
possible for the DFT.
Fourier transform
Discrete cosine transform was developed by Ahmed, Rao and Natarajan in the year
1974. DCT is a unitary transform, and it is not a discrete version of the cosine
functions. The DCT has better energy compaction than DFT; hence, it is widely used
in signal compression. DCT is employed in JPEG compression standard. DCT is
based on the DFT with imposed even symmetry through reflection; hence, DCT is a
real-valued transform.
The formula to compute forward discrete cosine transform is given by
N -1
ð2n þ 1Þπk
X ½k ] = αðkÞ x½n] cos ð5:66Þ
n=0
2N
where
5.5 Discrete Cosine Transform (DCT) 207
0.0
0 10 20 30 40 50
Frequency (Hz)
Spectrum of 10.5 Hz sine wave
0.75
Magnitude
0.50
0.25
0.00
0 10 20 30 40 50
Frequency (Hz)
1
, for k = 0
N
αð k Þ = ð5:67Þ
2
, Otherwise
N
N -1
ð2n þ 1Þπk
x½n] = αðk Þ X ½k] cos ð5:68Þ
k=0
2N
where
1
, for k = 0
N
αðkÞ = ð5:69Þ
2
, Otherwise
N
Inferences
The following inferences can be made from this experiment:
1. The input is real valued mulitiple sinusoidal signal, and the DCT output of the
input signal shows that most of the DCT coefficients are zero, which indicates
that the signal is highly correlated, and then the few DCT coefficients are used to
represent the signal.
5.5 Discrete Cosine Transform (DCT) 209
x[n]
x[n]
0 0
–1 –1
0 5 10 15 20 25 30 35 40 0 5 10 15 20 25 30 35 40
n--> n-->
DCT output DCT output Using in-built
2.5 2.5
x[k]
x[k]
0.0 0.0
–2.5 –2.5
0 5 10 15 20 25 30 35 40 0 5 10 15 20 25 30 35 40
k--> k-->
IDCT output IDCT output using in-built
y[n]
y[n]
0 0
–1 –1
0 5 10 15 20 25 30 35 40 0 5 10 15 20 25 30 35 40
n--> n-->
(a) Using DCT and IDCT formula (b) Using Built-in Command
Fig. 5.45 Simulation result. (a) Using DCT and IDCT formula. (b) Using built-in command
2. Inverse DCT is used to reconstruct the original signal from the DCT coefficients.
From Fig. 5.45, it is possible to observe that the reconstructed signal is exactly the
same as the original signal.
3. The same result is verified with the built-in commands ( fft.dct and fft.idct).
Task
1. Investigate whether DCT matrix entries are all real.
Experiment 5.25 Comparison Between Discrete Fourier Transform
and Discrete Cosine Transform
The objective of this experiment is to compare the performance of discrete Fourier
transform (DFT) with discrete cosine transform (DCT). This is done by taking DFT
and DCT of the sawtooth signal. After taking both DFT and DCT, the last ten
coefficients are nullified. Then, inverse DFT and inverse DCT of the modified
coefficients are taken to obtain the reconstructed signal. This is depicted in Fig. 5.46.
210 5 Transforms
The python code, which performs this task, is shown in Fig. 5.47, and the
corresponding output is shown in Fig. 5.48.
Inferences
From Fig. 5.48, it is possible to interpret that the reconstructed signal obtained using
DCT is better than DFT. DCT has better energy compaction than the DFT. This
means that DCT can pack signal energy into a few coefficients.
x[n]
0
–1
0 20 40 60 80 100
n-->
Reconstructed signal using DFT
0.5
y1[n]
0.0
–0.5
0 20 40 60 80 100
n-->
Reconstructed signal using DCT
200
y2[n]
0
–200
0 20 40 60 80 100
n-->
Non-stationary X2(τ, Ω)
STFT
signal x2(t)
where ‘w(t)’ is the window function and ‘τ’ is the centre of the window. Equation
(5.70) can be interpreted as ‘STFT provides two-dimensional representation of the
one-dimensional signal x(t)’. Narrow window provides good time resolution but
poor frequency resolution, whereas wider window provides good frequency resolu-
tion but poor time resolution. According to the Heisenberg uncertainty principle, it is
difficult to obtain both good time and frequency resolutions at the same resolution.
Experiment 5.26 STFT of Stationary and Non-stationary Signal
In this experiment, STFT of stationary and non-stationary signals are obtained, and
their results are interpreted. The stationary signal x1(t) is generated using the formula
x1(t) = sin (2πft); the non-stationary signal x2(t) is generated using the formula
x2(t) = sin (2πft2). The built-in function available in scipy library stft is used to
obtain time-frequency representation of the two signals. The block diagram of the
problem statement is given in Fig. 5.49.
212 5 Transforms
Fig. 5.50 Python code to obtain time-frequency representation of stationary and non-stationary
signals
The python code to implement the task is done in four steps. First step deals with
the generation of stationary signals, and second step deals with the generation of
non-stationary signals. Obtaining the STFT of the two signals is done in the third
step. Finally, the results are plotted in the fourth step. The python code, which
performs the abovementioned task, is given in Fig. 5.50, and the corresponding
output is shown in Fig. 5.51.
Inferences
From Fig. 5.51, the following inferences can be drawn:
1. Signal-1 and Signal-2 are stationary and non-stationary signals, respectively. For
Signal-1, the frequency does not change with respect to time; hence, it is
stationary, for Signal-2, the frequency increases with an increase in time;
hence, it is non-stationary.
2. STFT provides time-frequency representation of the signal. STFT of Signal-1 is a
horizontal line indicating that Signal-1 has one frequency component at all times.
The STFT of Signal-2 shows the gradual variation of frequency with respect to
time. With respect to time, the frequency changes, which is depicted in the
spectrogram plot.
Experiment 5.27 Impact of Choice of Window Length
In this experiment, the built-in function available in ‘matplot’ library plt.specgram is
used to analyse the impact of the choice of width of the window in STFT. The
5.6 Short-Time Fourier Transform 213
Signal-1 Signal-2
1 1
x2[t]
x1[t]
0 0
–1 –1
0.00 0.25 0.50 0.75 1.00 0.00 0.25 0.50 0.75 1.00
t--> t-->
Frequency (w -->)
40 40
20 20
0 0
0.0 0.5 1.0 0.0 0.5 1.0
Time (t-->) Time (t-->)
objective of this experiment is to verify the fact that a shorter window gives a good
time resolution and a wider window gives a good frequency resolution. To demon-
strate this fact, a non-stationary signal is generated. This signal has 5, 0 and 10 Hz
frequency components. In 0 Hz or DC, a discontinuity is introduced. The disconti-
nuity is the increase in the amplitude of the signal from 1 to 2 V. This non-stationary
signal is analysed using a spectrogram of different window widths, namely, 16, 32
and 128. The problem statement is depicted in Fig. 5.52.
The python code, which performs this task, is shown in Fig. 5.53, and the
corresponding output is shown in Fig. 5.54.
214 5 Transforms
Fig. 5.53 Python code to analyse the impact of window width in STFT
Inferences
From Fig. 5.54, the following inferences can be drawn:
1. The signal is a non-stationary signal with three frequency components 5 Hz, 0 Hz
(DC component) and 10 Hz, respectively. There is a discontinuity in the signal in
the DC component. The discontinuity refers to an abrupt change in amplitude
from 1 to 2 V.
2. The STFT of the signal is obtained for different window widths, namely, 16, 32
and 128.
3. The spectrogram corresponding to window width 16 gives good time informa-
tion. The occurrence of discontinuity at a particular instant is clearly visible in the
spectrogram with a window width of 16. But the frequency resolution is poor.
The two frequency components present in the signal, namely, 5 and 10 Hz, are not
visible in the spectrogram with a window width of 16. That is, a shorter window
gives good time resolution but poor frequency resolution.
5.6 Short-Time Fourier Transform 215
Frequency (w -->)
40
1
x(t)
0 20
–1 0
0.00 0.25 0.50 0.75 1.00 1 2
t--> Time (t-->)
Frequency (w -->)
40 40
20 20
0 0
1 2 1 2
Time (t-->) Time (t-->)
4. When the window width is 32, the frequency components present in the signal,
namely, 5 and 10 Hz, are partially visible. When the window width is 32, the
average time and frequency resolution are obtained.
5. When the window width is 128, the frequency resolution is good. From this
spectrogram, it is possible to identify 5 and 10 Hz frequency components. But it is
not possible to locate the discontinuity present in the signal. This means that time
resolution is poor.
6. In a nut shell, shorter window gives good time resolution but poor frequency
resolution, whereas a wider window gives good frequency resolution but poor
time resolution.
Task
1. Repeat this experiment by choosing different types of window functions like
Bartlett and Kaiser for specified value of ‘β’.
Experiment 5.28 Choice of Window Function in Resolving Two Close Fre-
quency Components
The objective of this experiment is to analyse the choice of window function in
resolving two close frequency components of the input signal. The input signal is the
addition of two sinusoidal signals of frequencies 5 and 8 Hz. The spectrogram of this
signal is obtained for different choices of window functions like rectangular win-
dow, Blackman window and Kaiser window. The impact of window choices in
frequency resolution is analysed in this experiment. The python code, which per-
forms this task, is shown in Fig. 5.55, and the corresponding output is shown in
Fig. 5.56.
216 5 Transforms
Inferences
The following inference can be made from this experiment:
1. From the python code, it is possible to observe that the signal consists of two
frequency components, 5 and 8 Hz, that are added to obtain the input signal
whose time-frequency representation for different windows is obtained.
2. Rectangular window is able to resolve two closely spaced frequency components.
3. Blackman window has a wider main lobe; hence, it could not resolve the
frequency components present in the signal.
4. Kaiser window successfully resolves the frequency components present in the
signal for the choice of β = 1.
5. If the main lobe width of the window is small, then good frequency resolution
could be obtained. Side lobes affect the extent to which adjacent frequency
components leak into the adjacent frequency bins.
Experiment 5.29 Comparison of FT with STFT
This experiment aims to compare Fourier transform with short-time Fourier trans-
form in analysing non-stationary signal. The non-stationary signal considered in this
example has three frequency components, namely, 5, 0 and 15 Hz. In non-stationary
5.6 Short-Time Fourier Transform 217
Frequency (w -->)
40
x(t)
0
20
–2 0
0.00 0.25 0.50 0.75 1.00 0.2 0.4 0.6
t--> Time (t-->)
Frequency (w -->)
Frequency (w -->)
40 40
20 20
0 0
0.2 0.4 0.6 0.2 0.4 0.6
Time (t-->) Time (t-->)
FT STFT FT STFT
Signal-1 Signal-2
1 1
x2(t)
x1(t)
0 0
–1 –1
0.00 0.25 0.50 0.75 1.00 0.00 0.25 0.50 0.75 1.00
t--> t-->
Spectrum-1 Spectrum-2
1 1
|X1(w)|
|X2(w)|
0 0
0 20 40 0 20 40
Frequency (w -->) Frequency (w -->)
Freq(w -->)
50 50
0 0
0 1 2 3 0 1 2 3
Time (t-->) Time (t-->)
The width of the window cannot be changed once it is fixed. This implies that STFT
provides fixed resolution. For the multi-resolution representation of the signal,
wavelet transform is employed.
1
1 t-b
W f ða, bÞ = p f ðt Þψ * dt ð5:71Þ
a a
-1
In the above equation, f(t) represents signal of interest, ψ(t) denotes ‘mother
wavelet’, b is the shifting parameter and a is the scaling parameter. The above
equation can be written as
The above equation indicates that wavelet transform is basically taking inner
product of the function f(t) with the ‘daughter wavelet’ ψ a, b(t). The daughter
wavelets are derived from the mother wavelet ψ(t) using the relation
1 t-b
ψ a,b ðt Þ = p ψ ð5:73Þ
a a
A variety of continuous wavelets filter are currently in use. They are (1) Haar,
(2) Mexican Hat, (3) Morlet, (4) Complex Morlet, (5) Gaussian, (6) Shannon and
(7) Daubechies. The wavelet family and its mathematical expression are given in
Table 5.3.
Experiment 5.30 Detection of Discontinuity in the Signal Using CWT
The objective of this experiment is to detect the discontinuity present in the signal
using continuous wavelet transform (CWT). The built-in function cwt available in
the library pywt is utilized in this experiment. The three steps followed in this
experiment are the following: Step 1: generating signal with discontinuity; Step 2:
obtaining timescale relationship using CWT, in which the wavelet chosen for this
study is Gaussian wavelet; and Step 3: plotting the signal and the corresponding
scalogram. The python code which performs this task is shown in Fig. 5.60, and the
corresponding output is shown in Fig. 5.61.
Inferences
From Fig. 5.61, the following inferences can be drawn:
1. The input signal is a smooth sinusoidal signal with a sharp discontinuity at a
particular location.
2. Upon observing the CWT result, it is possible to interpret that discontinuity
occurs at 90th sample of the sinusoidal signal, which has 200 samples of data.
3. Thus, CWT is capable of detecting the discontinuity present in the signal.
5.8 Discrete Wavelet Transform 221
Morlet ψ ðt Þ = exp - t2
cosð5t Þ ‘morl’
2
Complex ψ ðt Þ = p2 exp - t2
expðj2πCtÞ ‘cmor’
Morlet πB B
Where B is Bandwidth and C is centre frequency
Gaussian ψ(t) = C exp (-t2) ‘gaus’
wavelet where C is an order-dependent normalization
constant
p
Shannon ðπBt Þ
ψ ðt Þ = B sinπBt expðj2πCt Þ ‘shan’
wavelet Where B is Bandwidth and C is centre frequency
Task
1. Repeat the experiment for different choices of mother wavelet and comment on
the observed result.
The discrete wavelet transform decomposes the signal into approximation and detail.
The process is further iterated by decomposing the approximation with the assump-
tion that much of the signal energy is in approximation. This idea is illustrated in
Fig. 5.62.
In Fig. 5.62, L1 corresponds to first-level decomposition, where the signal is
decomposed into approximation and detail. In the second-level of decomposition
(L2), the approximation obtained in L1 is further decomposed into approximation and
detail. In the third-level of decomposition (L3), the approximation of level L2 is
222 5 Transforms
5
x(t)
0
0 25 50 75 100 125 150 175 200
t-->
CWT of the signal
Freq Scale (w -->)
30
20
10
Signal
Approximation Detail
L1
Approximation Detail
L2
Approximation Detail
L3
L1
decomposed further into approximation and detail. This is done assuming that most
of the signal energy is in approximation.
Experiment 5.31 Detection of Discontinuity in Signal Using DWT
The objective of this experiment is to compare the first-level approximation and
detail of DWT coefficient of a signal with the coefficient of the signal with discon-
tinuity. Here discontinuity refers to sudden changes in the amplitude of the signal.
The problem statement is depicted in Fig. 5.63.
From Fig. 5.63, it is possible to observe that two signals are considered in this
experiment, Signal-1 is a square wave, whereas Signal-2 is a square wave with
discontinuity. L1 in the figure represents the first-level of decomposition. Upon first-
level of decomposition, the signal is split into approximation and detail. Upon taking
an inverse discrete wavelet transform, it is possible to reconstruct the signal. The
224 5 Transforms
Fig. 5.64 Python code to compute the DWT CWT of signal with discontinuity
python code that performs this task mentioned above is shown in Fig. 5.64, and the
corresponding output is in Fig. 5.65.
Inferences
From Fig. 5.65, the following inferences are drawn:
1. Signal-1 is a square wave with 5 Hz fundamental frequency; Signal-2 is a square
wave with discontinuity.
2. The first-level decomposition of the signal gives approximation and detail coef-
ficients. For Signal-1, the approximation coefficient is similar to the signal,
whereas the detail coefficient is almost zero. For Signal-2, the discontinuity is
captured in detail coefficient.
3. Upon taking inverse DWT, the reconstructed signals are obtained, which resem-
bles the input signal. Thus, DWT is a reversible transform.
5.8 Discrete Wavelet Transform 225
Signal-1 Signal-2
1 5
x1[n]
x2[n]
0
–1 0
0 25 50 75 100 0 25 50 75 100
n--> n-->
0 y2[n]
–1 0
0 25 50 75 100 0 25 50 75 100
n--> n-->
2. The noisy signal is obtained by adding white noise, which follows normal
distribution to the input signal.
3. The noisy signal is decomposed using db2 wavelet. The level of decomposition is
three.
4. After wavelet decomposition, the detail coefficients are thresholded using soft
thresholding to minimize the impact of noise. It is generally believed that much of
the signal energy will be in low-frequency regions and noise will reside in high-
frequency regions.
5. The inverse wavelet transform of the modified wavelet coefficients is performed
to obtain the filtered signal.
6. From Fig. 5.67, it is possible to interpret that the impact of noise is less in filtered
signal when compared to noisy signal.
5.8 Discrete Wavelet Transform 227
Clean signal
x[n] 0
–1
0 10 20 30 40 50
n-->
Noisy signal
1
z[n]
0
–1
0 10 20 30 40 50
n-->
Filtered signal
1
y[n]
0 10 20 30 40 50
n-->
Tasks
1. The experiment can be repeated by the following: (a) Choose different wavelet
family other than ‘db2’. (b) The level of decomposition can be changed.
(c) Instead of soft thresholding, hard thresholding can be tried.
Exercises
1. Write a python code to obtain the Z-transform of the following sequences:
(a) x1[n] = δ[n - 5] (b) x2[n] = u[n] - u[n - 1] (c) x3[n] = nu[n]
(d) x4[n] = sin (ω0n).
2. Write a python code to compute the inverse Z-transform of (a) X1(z) = z-2
(b) X 2 ðzÞ = ð1 - 1z - 1 Þ2 .
3. Write a python code to compute the magnitude and phase responses of the
system, whose transfer function is given by H ðzÞ = 1 -1z - 1 .
4. Let the signal x[n] represent 100 samples of 5 Hz sine wave. Now increase the
length of the signal by padding 50 sample values of zeros to x[n]. Zero padding
is done at the end of 100 samples of x[n]. Let the zero padded signal be denoted
as y[n]. Write a python code to plot the spectrum of the signal x[n] and y
[n]. Comment on the observed result.
5. Obtain the DFT of the sequences x1[n] = {1, 1, 1, 1} and x2[n] = {1, -1, 1, -1}.
Plot their magnitude responses and comment on the observed result.
6. Generate a square wave of 5 Hz fundamental frequency. Write a python code to
plot the spectrum of the square wave and comment on the observed result.
7. Let x[n] represent 100 samples of 5 Hz sine wave. Let y[n] represent 100 samples
of 5 Hz cosine wave. Take Fourier transform of x[n] and y[n] to obtain X[k] and
Y[k]. Extract the magnitude and phase components of X[k] and Y[k]. Now
interchange the phase of X[k] with Y[k]. After phase interchange, take inverse
228 5 Transforms
Fourier transform to obtain x′[n] and y′[n]. Use subplot to plot the signals x[n], y
[n], x′[n] and y′[n] and comment on the observed result.
8. Generate a linear chirp signal whose frequency varies from 10 to 1 Hz in 10 s.
Plot the spectrum and spectrogram of this chirp signal and comment on the
observed result.
9. Write a python code to verify the fact that a shorter window gives good time
resolution and a wider window gives good frequency resolution in short-time
Fourier transform.
10. Generate sinusoidal signal with momentary interruption. Apply CWT to identify
the momentary interruption present in the signal.
Objective Questions
1. The region of convergence of unit sample signal (δ[n]) is
A. Entire Z-plane except z = 0
B. Entire Z-plane except z = infinity
C. Entire Z-plane
D. Entire Z-plane except z = 0 and z = infinity
2. Convolution in time domain is equivalent to
A. Addition in Z-domain
B. Subtraction in Z-domain
C. Multiplication in Z-domain
D. Division in Z-domain
3. For a discrete-time system to be stable
A. Pole should lie inside the unit circle.
B. Pole should lie outside the unit circle.
C. Pole should lie on the unit circle.
D. Pole can lie anywhere in the z-plane.
4. Z-transform of x[n] = nu[n] is
A. X ðzÞ = z
z-1
B. X ðzÞ = z
ðz - 1Þ2
2
C. X ðzÞ = z
z-1
D. X ðzÞ = z
ðz - 1Þ3
A. 0
B. 1
C. -1
D. Infinite
5.8 Discrete Wavelet Transform 229
n n
6. Let x½n] = 25 u½n] - 52 u½ - n - 1]. Let X(z) be the Z-transform of the given
signal x[n]; then, the region of convergence of its Z-transform is
A. 25 < jzj < 1
B. 52 < jzj < 1
C. 25 < jzj < 52
D. - 1 < jzj < 5
2
Bibliography
1. Ronald N. Bracewell, “Fourier Transform and its Applications”, McGraw Hill, 1978.
2. Alexander D. Poularikas, and Richard C. Dorf, “Transforms and Applications Handbook”,
Wiley, 2021.
3. Martin Vetterli, and Jelena Kovacevic, “Wavelets and Subband Coding”, CreateSpace Indepen-
dent Publishing Platform, 2013.
4. Ronald L. Allen, Duncan W. Mills, “Signal Analysis: Time, Frequency, Scale, and Structure”,
Wiley-IEEE Press, 2004.
5. B. P. Lathi, “Signals, Systems and Communication”, B.S publication, 2001.
Chapter 6
Filter Design Using Pole-Zero Placement
Method
Learning Objectives
After reading this chapter, the reader is expected to
• Design, implement and analyse first-order infinite impulse response filter.
• Design, implement and analyse the moving average filter.
• Design and analyse digital resonator.
• Design and analyse notch filter and comb filter.
• Design and analyse all-pass filter.
© The Author(s), under exclusive license to Springer Nature Singapore Pte Ltd. 2024 231
S. Esakkirajan et al., Digital Signal Processing,
https://doi.org/10.1007/978-981-99-6752-0_6
232 6 Filter Design Using Pole-Zero Placement Method
The filters discussed in this chapter include the IIR filter, moving average filter,
digital resonator, notch filter, comb filter and all-pass filter.
PreLab Questions
1. If h[n] represents the impulse response of a lowpass filter, what would be the
behaviour of the filter whose impulse response is (-1)nh[n]?
2. When a discrete-time system is said to be a minimum phase system?
3. What do you understand by the term ‘poles’ and ‘zeros’ of a system?
4. How is the stability of the discrete-time system related to (a) location of poles of
the system and (b) impulse response of the system?
5. What is the basic principle involved in the design of digital filter using pole-zero
placement method?
6. What do you understand by the term ‘delay equalizer’ or ‘phase equalizer’?
7. Mention two applications of notch filter.
8. A square wave is fed as input to M-point moving average filter. What would be
the output of M-point moving average filter?
9. The relationship between the input and output of a digital filter is given by y
[n] = αx[n] + βx[n - 1] + γx[n - 2]. Is this a finite impulse response filter (FIR)
or infinite impulse response filter (IIR)? Justify your choice.
10. What is a pole-zero plot? What information one gets by interpreting the pole-
zero plot?
This section begins with the design of a first-order IIR filter. The transfer function of
a first-order IIR filter is given by
1
H ðzÞ = ð6:1Þ
1 - p1 z - 1
If the pole lies on the unit circle ( p1 = 1), the transfer function of the filter is given
by
6.1 First-Order IIR Filter 233
1
H ðzÞ = ð6:2Þ
1 - z-1
1
H ejω = ð6:3Þ
1 - e - jω
1
H ejω = ð6:4Þ
1 - cosðωÞ þ j sinðωÞ
1
H ejω = ð6:5Þ
ð1 - cosðωÞÞ2 þ sin 2 ðωÞ
1
H ejω = ð6:6Þ
2 - 2 cosðωÞ
h½ n] = Z - 1 fH ð z Þ g ð6:7Þ
1
h½n] = Z - 1 = u½ n] ð6:8Þ
1 - z-1
The impulse response of the filter is the unit step function. The unit step
function is not absolutely summable; hence, the filter is not stable.
234 6 Filter Design Using Pole-Zero Placement Method
Fig. 6.1 Python code to obtain the characteristics of first order IIR filter
code which deals with the response of the filter for these two different types of inputs
is shown in Fig. 6.3, and the corresponding output is shown in Fig. 6.4.
Inferences
From Fig. 6.4, the following inferences can be drawn:
1. y1[n] is the output signal corresponding to the input signal x1[n]. Here x1[n] is a
DC signal. The signal x1[n] is generated from the expression x1[n] = ejωn by
substituting ω = 0. From the output signal y1[n], it is possible to interpret that the
filter amplifies x1[n], which is a DC signal.
2. y2[n] is the output signal corresponding to the input signal x2[n]. Here x2[n] is an
AC signal. The signal x2[n] is generated from the expression x2[n] = ejωn by
substituting ω = π. From the output signal y2[n], it is possible to interpret that the
filter blocks x2[n], which is a high-frequency signal.
236 6 Filter Design Using Pole-Zero Placement Method
|H(jw)_
20
h[n]
0.5
0
0.0
0 25 50 75 100 0 20 40
n--> w -->
H(jw)
0
jw
–1
–1
–1.0 –0.5 0.0 0.5 1.0 0 1 2 3
s w -->
x1[n] y1[n]
1.0
10
Amplitude
Amplitude
0.5 5
0.0 0
–5 –4 –3 –2 –1 0 1 2 3 4 5 –5 –4 –3 –2 –1 0 1 2 3 4 5
n--> n-->
x2[n] y2[n]
1 0.0
Amplitude
Amplitude
0 –0.5
–1 –1.0
–5 –4 –3 –2 –1 0 1 2 3 4 5 –5 –4 –3 –2 –1 0 1 2 3 4 5
n--> n-->
3. When the poles are at position p = 1, the filter amplifies the DC signal and blocks
the high-frequency signal. The filter behaves like a lowpass filter.
Experiment 6.3 Impact of Pole Position on the Magnitude and Impulse
Responses of First-Order IIR Filter
The objective of this experiment is to analyse the impact of pole position on the
impulse and magnitude response of first-order IIR filter whose transfer functions are
given by H 1 ðzÞ = 1 - 0:25z
1
- 1 and H 2 ðzÞ = 1þ0:25z - 1 . The python code which obtains
1
the impulse response and the magnitude response of the two filters is given in
Fig. 6.5, and the corresponding output is shown in Fig. 6.6.
Inferences
From Fig. 6.6, the following inferences can be drawn:
1. The pole of System-1 whose transfer function is given by H 1 ðzÞ = 1 - 0:25z
1
- 1 lies
Fig. 6.5 Python code to analyse the impact of pole position on the behaviour of the filter
Amplitude
|H1(jw)_
0 u 0.5
jw
–1 0.0 –2
–1 0 1 0 10 0 2
s n--> w -->
|H2(jw)_
0.5
u
jw
0 0
0.0
–1 –2
–1 0 1 0 10 0 2
s n--> w -->
The relationship between the input and output of M-point moving average filter is
given by
M-1
1
y ½ n] = x½ n - k ] ð6:9Þ
M k=0
1
y½n] = fx½n] þ x½n - 1] þ x½n - 2]g ð6:10Þ
3
From Eq. (6.10), it is possible to interpret that equal weightage is given to x[n], x
[n - 1] and x[n - 2]. This type of system is termed as ‘moving average system’. This
system performs the weighted average of three input samples x[n], x[n - 1] and x
[n - 2]; hence, it is termed as ‘moving average filter’.
Experiment 6.4 Characteristics of Moving Average Filter
This experiment tries to obtain the characteristics of a moving average filter using
python. The python code, which obtains the characteristics of three-point moving
average filter, is shown in Fig. 6.7, and the corresponding output is shown in
Fig. 6.8.
240 6 Filter Design Using Pole-Zero Placement Method
Fig. 6.7 Python code to obtain the characteristics of three-point moving average filter
|H(jw)_
0.2 –25
–50
0.0
0 25 50 75 100 0 20 40
n--> w -->
0
0
jw
–1 –2
–1.0 –0.5 0.0 0.5 1.0 0 1 2 3
s w -->
Input Signal
(Square waveform)
Inferences
From Fig. 6.8, the following inferences can be drawn:
1. The impulse response of a moving average filter is finite. If the impulse response
of the system is absolutely summable, then the discrete-time system is a stable
system. Thus, three-point moving average system is inherently stable.
2. Moving average filter is an all-zero filter.
3. From the magnitude response, it is possible to observe that three-point moving
average filter act as a lowpass filter.
4. From the phase response, it is possible to conclude that a moving average filter
exhibits linear phase characteristics in the pass band.
Task
1. Repeat the above experiment for a five-point moving average filter and six-point
moving average filter, and comment on the observed output. What change do you
observe in the pole-zero plot for M = 5 and M = 6?
Experiment 6.5 Impact of the Order of Moving Average Filter
The objective of this experiment is to observe the impact of the order of the moving
average filter with respect to the extent of filtering. This objective is shown in
Fig. 6.9. From Fig. 6.9, it is possible to interpret that the input signal to the three
moving average filters of orders 51, 71 and 91 is a square wave. The reason for
choosing square wave as input is that it exhibits sharp transition between ‘ON’ and
‘OFF’ state. The python code, which implements the task shown in Fig. 6.9, is given
in Fig. 6.10, and the corresponding output is shown in Fig. 6.11.
Inferences
The following inferences can be drawn from Fig. 6.11:
1. The input signal to the moving average filter is a square wave. The input signal
exhibits sudden transitions between states ‘0’ and ‘1’.
2. The input signal is passed through 3 moving average filters of order 51, 71 and
91.
242 6 Filter Design Using Pole-Zero Placement Method
Fig. 6.10 Python code to obtain the results of moving average filter
3. The square wave is transformed into a triangular wave for the moving average
filter of order 91. The square wave, when passed through an integrator (lowpass
filter), results in a triangular wave. The triangular wave exhibits gradual variation
between the states ‘0’ and ‘1’.
4. The extent of smoothing increases with an increase in the order of the moving
average filter.
The relationship between the input and output of M-point exponentially weighted
moving average filter is given by
6.3 M-Point Exponentially Weighted Moving Average Filter (EWMA) 243
Amplitude
0 0
–1 –1
0.00 0.25 0.50 0.75 1.00 0.00 0.25 0.50 0.75 1.00
Time Time
Amplitude
0 0
–1 –1
0.00 0.25 0.50 0.75 1.00 0.00 0.25 0.50 0.75 1.00
Time Time
M -1
y ½ n] = C αk x½n - k] ð6:11Þ
k=0
In the above expression, ‘C’ is the normalization constant, and ‘α’ is the expo-
nential weighting factor, where 0 < α < 1.
To Find the Expression for Normalization Constant (C) One way to obtain the
value of ‘C’ is that it should preserve the DC gain. If the input is a constant signal (x
[n] = K ), if the filter preserves the DC component of the signal, then the output is
also expected to be ‘K’. Substituting x[n] = K and y[n] = K in Eq. (6.11), we get
M-1
K =C αk K ð6:12Þ
k=0
M -1
K = CK αk ð6:13Þ
k=0
From the above expression, the expression for the constant ‘C’ can be written as
244 6 Filter Design Using Pole-Zero Placement Method
M -1
C αk = 1 ð6:14Þ
k=0
1
C= M-1
ð6:15Þ
αk
k=0
M-1
1 - αM
αk = ð6:16Þ
k=0
1-α
1-α
C= ð6:17Þ
1 - αM
The expression for M-point exponentially weighted moving average filter is given
by
M -1
1-α
y ½ n] = α k x½ n - k ] ð6:18Þ
1 - αM k=0
Fig. 6.12 Python code which obtains the impulse response of MA and EWMA filter
0.50
0.2
h1[n]
h3[n]
0.25
0.0 0.00
0.0 0.5 1.0 1.5 2.0 0.0 0.5 1.0 1.5 2.0
n--> n-->
h4[n]
0.1
0.2
0.0 0.0
0 1 2 3 4 0 1 2 3 4
n--> n-->
A resonator is designed to have its strongest response to match certain input signal.
Resonators find application in communication receivers, AM/FM demodulators, etc.
A digital resonator is a two-pole bandpass filter with a pair of complex-conjugate
poles near the unit circle to create a resonant peak at the desired frequency. The
digital resonator has a large magnitude response in the vicinity of the pole location. If
one pole is located at p1 = rejω, then the other pole will be at p2 = re-jω, where
0 < r < 1. The expression for the transfer function of the system is given by
1
H ðzÞ = ð6:19Þ
ð1 - p1 z - 1 Þð1 - p2 z - 1 Þ
1
H ðzÞ =
ð1 - rejω z - 1 Þð1 - re - jω z - 1 Þ
1
H ðzÞ =
1 - re - jω z - 1 - rejω z - 1 þ r 2 z - 2
1
H ðzÞ =
1 - rz - 1 ½e - jω þ ejω ] þ r2 z - 2
1
H ðzÞ = ð6:20Þ
1 - 2rz - 1 cosðωÞ þ r 2 z - 2
#Digital resonator
import numpy as np
import matplotlib.pyplot as plt
from scipy import signal
#Defining the system
r,fs=0.98,100 #Sampling frequency
fn,fc=fs/2, 5 #Cutoff frequency
w=2*np.pi*(fc/fn)
b=[1]
a=[1,-2*r*np.cos(w),r**2]
#Generating the input and obtaining the response
x=np.zeros(25) #Input to the resonator
x[0]=1
y=signal.lfilter(b,a,x) #Output of resonator
plt.subplot(3,2,1),plt.stem(x),plt.xlabel('n-->'),plt.ylabel('x[n]'),plt.title('Input signal')
plt.subplot(3,2,2),plt.stem(y),plt.xlabel('n-->'),plt.ylabel('y[n]'),plt.title('Output signal')
#Impulse response of the system
h_1=np.zeros(25)
h_1[0]=1
h=signal.lfilter(b,a,h_1)
plt.subplot(3,2,3),plt.stem(h),plt.xlabel('n-->'),plt.ylabel('y1[n]'),plt.title('Impulse response')
# Pole-zero plot
z, p, k = signal.tf2zpk(b, a)
theta = np.linspace(0, np.pi*2, 500)
circle = np.exp(1j*theta)
plt.subplot(3,2,5),plt.plot(circle.real, circle.imag, 'k--')
plt.plot(z.real, z.imag, 'ro', ms=7.5),plt.plot(p.real, p.imag, 'rx',ms=7.5)
plt.xlabel('Real part'),plt.ylabel('Imaginary part'),plt.title('Pole-zero plot'),plt.grid()
#Magnitude and phase response
w, h = signal.freqz(b,a)
plt.subplot(3,2,4),plt.plot(w, 10 * np.log10(abs(h))),plt.xlabel('$\omega$ [rad/sample]'),
plt.ylabel('$|H(e^{j\omega})|$ in [dB]'),plt.title('Magnitude response'),plt.subplot(3,2,6),
plt.plot(w,np.unwrap(np.angle(h))),plt.xlabel('$\omega$ [rad/sample]'),plt.ylabel('Degree')
plt.title('Phase response'),plt.tight_layout()
2. From the magnitude response, it is possible to observe that the system behaves
like a narrow bandpass filter.
3. From the pole-zero plot, it is possible to observe that two complex conjugate
poles occur very closer to the unit circle.
4. From the phase response, it is possible to observe that the system exhibits
non-linear phase characteristics.
248 6 Filter Design Using Pole-Zero Placement Method
y[n]
0
0 –1
0 10 20 0 10 20
n--> n-->
|H(ejw)| in [dB]
1 10
y1[n]
0
–1 0
0 10 20 0 1 2 3
n--> w>rad/sample]
Imaginary part
Task
1. Repeat the above experiment for r = 1 and comment on the observed result.
Notch filter has two complex conjugate zeros placed on the unit circle to create a null
at a desired frequency. A notch filter has the ability to reject one particular frequency.
A pair of complex conjugate zeros on the unit circle produces a null in the frequency
response, which results in the rejection of one particular frequency. Let the conjugate
zeros be represented as z1 = rejω and z2 = re-jω. If the zeros occur on the unit circle,
then r = 1. The transfer function of such a system is given by
H ð z Þ = 1 - z1 z - 1 1 - z 2 z - 1 ð6:21Þ
H ðzÞ = 1 - ejω z - 1 1 - e - jω z - 1
H ðzÞ = 1 - e - jω z - 1 - ejω z - 1 þ z - 2
H ðzÞ = 1 - z - 1 e - jω þ ejω þ z - 2
#Notch filter
import numpy as np
import matplotlib.pyplot as plt
from scipy import signal
#Step 1: Generating the input signal
f1,f2=2,5 # 1Hz and 5Hzfrequency component
n=np.arange(0,100)
x1=np.sin(2*np.pi*f1*n/100)
x2=np.sin(2*np.pi*f2*n/100)
x=x1+x2 #Input signal has 1 Hz and 5 Hz component
#Step 2: Design of notch filter
r,fs,fc=0.99,100,5 # Sampling, Cutoff frequencies
w=2*np.pi*(fc/fs)
b=[1,-2*np.cos(w),1]
a=[1]
#Step 3: Obtaining the output
y=signal.lfilter(b,a,x) #Output of resonator
plt.subplot(3,2,1),plt.stem(x),plt.xlabel('n-->'),plt.ylabel('x[n]'),plt.title('Input signal'),
plt.subplot(3,2,2),plt.stem(y),plt.xlabel('n-->'),plt.ylabel('y[n]'),plt.title('Output signal')
#Impulse response of the system
h_1=np.zeros(25)
h_1[0]=1
h=signal.lfilter(b,a,h_1)
plt.subplot(3,2,3),plt.stem(h),plt.xlabel('n-->'),plt.ylabel('y1[n]'),plt.title('Impulse response')
# Pole-zero plot
z, p, k = signal.tf2zpk(b, a)
theta = np.linspace(0, np.pi*2, 500)
circle = np.exp(1j*theta)
plt.subplot(3,2,5),plt.plot(circle.real, circle.imag, 'k--'),plt.plot(z.real, z.imag, 'ro', ms=7.5),
plt.plot(p.real, p.imag, 'rx',ms=7.5)
plt.xlabel('$\sigma$'),plt.ylabel('$j\omega$'),plt.title('Pole-zero plot'),plt.grid()
#Magnitude and phase response
w, h = signal.freqz(b,a)
plt.subplot(3,2,4),plt.plot(0.5*fs*w/np.pi, 10 * np.log10(abs(h)))
plt.xlabel('$\omega$ [rad/sample]'),plt.ylabel('$|H(j\omega)|$ in [dB]')
plt.title('Magnitude response'),plt.subplot(3,2,6),
plt.plot(0.5*fs*w/np.pi,np.unwrap(np.angle(h))),plt.xlabel('$\omega$ [rad/sample]'),
plt.ylabel('$\u2220H(j\omega)$'),plt.title('Phase response'),plt.tight_layout()
Fig. 6.17 Python code which performs notch filtering of the input signal
y[n]
–2 0.00
0 25 50 75 100 0 25 50 75 100
n--> n-->
|H(jw)| in [dB]
0 0
y1[n]
–25
–2
0 10 20 0 20 40
n--> w [rad/sample]
–1 0.0
–1.0 –0.5 0.0 0.5 1.0 0 20 40
s w [rad/sample]
2. The pole-zero plot shows two complex conjugate poles and zeros on the unit
circle. The presence of poles on the unit circle indicates that the stability of the
filter is not guaranteed.
3. The magnitude response shows that the 50 Hz notch frequency is the cut-off
frequency.
4. The phase response indicates that it is non-linear. Since the impulse response is
not symmetric, the phase response is not linear.
z-1 - a
H ðzÞ = , where jaj < 1 ð6:23Þ
1 - az - 1
e - jω - a
H ejω = ð6:24Þ
1 - ae - jω
252 6 Filter Design Using Pole-Zero Placement Method
Fig. 6.19 Python code to design notch filter using built-in function
Using Euler’s formula e-jω = cos (ω) - j sin (ω), the above expression can be
written as
cosðωÞ - j sinðωÞ - a
H ejω = ð6:25Þ
1 - a½cosðωÞ - j sinðωÞ]
Using the fact that sin2(ω) + cos2(ω) = 1, the above equation can be simplified as
6.6 All-Pass Filter 253
0.5 0
jw
0.0 –1
0 10 20 –1.0 –0.5 0.0 0.5 1.0
n--> s
–10
H(jw)
0
–20 –1
2 1 þ a2 - 2a cosðωÞ
H ejω =
1þ a2 cos 2 ðωÞ þ sin 2 ðωÞ - 2a cosðωÞ
2 1 þ a2 - 2a cosðωÞ
H ejω = =1 ð6:26Þ
1 þ a2 - 2a cosðωÞ
Thus, the magnitude response of the all-pass filter is unity. This means all-pass
filters pass all frequency components of the input signal.
Experiment 6.10 All-Pass Filter
This experiment discusses the python implementation of all-pass filter. The python
implementation of first-order all-pass filter with the value of ‘a = 0.5’ is shown in
Fig. 6.21, and the corresponding output is shown in Fig. 6.22.
Inferences
From Fig. 6.22, the following inferences can be drawn:
1. The input to the all-pass filter is a sine wave of 5 Hz frequency.
2. The output of the all-pass filter is almost the same as the input signal. Thus, all-
pass filter passes all the frequency components of the input signal.
3. The impulse response is not finite. It slowly reaches the value of zero. Hence, it is
an IIR filter.
254 6 Filter Design Using Pole-Zero Placement Method
4. The magnitude response indicates that the filter gain is one for all frequency
components.
5. From the pole-zero plot, a pole lies at 0.5, whereas a zero lies at 2. The given
system is not a minimum phase system.
6. The phase response of the system is non-linear. The phase is not varying linearly
with respect to frequency.
Task
1. Repeat the above experiment for a = 0.25 and a = 0.75, and comment on the
observed results.
6.7 Comb Filter 255
y[n]
0
–1 –1
0 20 40 0 20 40
n--> n-->
jw
0.0
–0.5 –1
0 10 20 –1 0 1 2
n--> s
Magnitude response Phase response
1.05 0.0
H(jw)
|H(jw)|
1.00
–2.5
0.95
0 1 2 3 0 1 2 3
w [rad/sample] w [rad/sample]
z-L
A comb filter is a notch filter with a number of equally spaced nulls. The block
diagram representing the comb filter is shown in Fig. 6.23.
The relationship between the input and output of the comb filter is expressed as
Y ðzÞ = X ðzÞ 1 þ z - L
Y ðz Þ
H ðzÞ = = 1 þ z-L ð6:29Þ
X ð zÞ
From the expression of the transfer function given in Eq. (6.30), it is possible to
interpret; there is a pole of multiplicity ‘L’ at the origin. The location of zeros is
obtained by equating the numerator of the transfer function to zero, which results in
z-L = - 1
e - jωL = ejð2kþ1Þπ
ð2k þ 1Þπ
ωk = ð6:31Þ
L
The zeros of the FIR filter are uniformly spaced 2π L radians apart around the unit
circle starting at ω = Lπ . For odd ‘L’, there is a zero at ω = π.
Experiment 6.11 Comb Filter
The objective of this experiment is to plot the pole-zero pattern of Comb filter for
even and odd values of L. The odd value is chosen as L = 5, and the even value is
chosen as L = 6. The python code which plots the pole-zero plot of comb filters is
shown in Fig. 6.24, and the corresponding output is shown in Fig. 6.25.
Inferences
From the pole-zero plot, which is shown in Fig. 6.25, the following inferences can
be made:
1. The zeros are uniformly spaced 2π L radians apart around the unit circle.
2. For odd values of ‘L’, there is a zero at ω = π.
3. The poles lie at the origin, which implies that the filters are inherently stable.
6.7 Comb Filter 257
0
jZ
–1
–1.00 –0.75 –0.50 –0.25 0.00 0.25 0.50 0.75 1.00
V
0
jZ
–1
–1.00 –0.75 –0.50 –0.25 0.00 0.25 0.50 0.75 1.00
V
Fig. 6.25 Pole-zero plot of comb filters for odd and even values of ‘L’
258 6 Filter Design Using Pole-Zero Placement Method
Random signal
50 Hz sinusoidal
signal
Exercises
1. Generate sinusoidal signal of 5 Hz frequency. Add random noise which follows
uniform distribution to the clean sinusoidal signal. Pass the noisy signal to the
moving average filter and comment on the observed result. The block diagram of
the problem statement is shown in Fig. 6.26.
2. Generate three tones of frequencies 500, 1000 and 1500 Hz. Append the three
tones together as one signal. Now pass this signal to a notch filter, which will
block the frequency component of a specific frequency (say 1000 Hz). Hear the
input and output signals and comment on your observation.
3. Design a notch filter to minimize 50 Hz powerline interference in ECG signal.
Read an ECG signal which is stored in ‘mat’ file format. Add 50 Hz powerline
interference to the clean ECG signal to generate noisy signal. Pass the noisy
signal to the notch filter to minimize the powerline interference. Plot the clean,
noisy and filtered signals and comment on the observed result. The problem
statement is depicted in the form of a block diagram and is shown in Fig. 6.27.
4. Generate 10 Hz square waveform. Design a comb filter to eliminate 10 Hz
frequency component in this signal and its odd harmonics.
5. Generate sine wave of frequencies 5 and 10 Hz. Add these two waveforms. Now
pass this signal through a notch filter, which should eliminate the 5 Hz frequency
component, so that the output signal contains a 10 Hz frequency component.
6.7 Comb Filter 259
Objective Questions
1. The filter which is used to reject one particular frequency is
A. Lowpass filter
B. Highpass filter
C. All-pass filter
D. Notch filter
2. The filter which can be used as a delay equalizer is
A. Lowpass filter
B. Highpass filter
C. All-pass filter
D. Notch filter
3. Cascading of lowpass and highpass filter will result in
A. Lowpass filter
B. Highpass filter
C. Band pass filter
D. All-pass filter
4. The filter which is used to minimize the impact of power line interference is
A. Lowpass filter
B. Highpass filter
C. All-pass filter
D. Notch filter
5. The impulse response of three-point moving average filter is given by
h½ n] = 3 f - δ½n] - δ½n - 1] - δ½n - 2g
1
A.
B. h½ n] = 3 f - δ½n] - δ½n - 1] þ δ½n - 2g
1
D. h½ n] = 3 f δ ½ n ] þ δ ½ n - 1 ] þ δ ½ n - 2g
1
6. The filter which has the ability to remove fundamental frequency and its
harmonics is
A. Notch filter
B. Comb filter
C. Lowpass filter
D. Highpass filter
7. The impulse response of a digital filter is given by h[n] = δ[n] + δ[n - 8]. The
filter behaves like a
A. All-pass filter
B. Highpass filter
260 6 Filter Design Using Pole-Zero Placement Method
C. Comb filter
D. Notch filter
8. Statement 1: Stable filters are always causal
Statement 2: Causal filters are always stable:
A. Both statements are wrong.
B. Both statements are true.
C. Statement 1 is true, and Statement 2 is wrong.
D. Statement 1 is wrong, and Statement 2 is true.
9. Assertion: Moving average filter attenuates quick change in the signal.
Reason: Moving average filter is a lowpass filter.
A. Both assertion and reason are wrong.
B. Assertion is true, reason is wrong.
C. Assertion is wrong, reason may be true.
D. Both assertion and reason are true.
- jω - j2ω - j3ω
10. The frequency response of lowpass filter is given by H ðejω Þ = 1þe þe4 þe .
Using frequency shift, the lowpass filter can be converted to a highpass filter.
The impulse response of the highpass filter is
A. h[n] = 0.25{δ[n] + δ[n - 1] + δ[n - 2] + δ[n - 3]}
B. h[n] = 0.25{δ[n] + δ[n - 1] - δ[n - 2] - δ[n - 3]}
C. h[n] = 0.25{-δ[n] - δ[n - 1] - δ[n - 2] - δ[n - 3]}
D. h[n] = 0.25{δ[n] - δ[n - 1] + δ[n - 2] - δ[n - 3]}
11. Statement 1: Digital resonator generates sinusoidal signal of specific frequency.
Statement 2: Digital resonator has complex conjugate pole located on the unit
circle.
A. Statement 1 is correct, and Statement 2 is wrong.
B. Statement 1 is wrong, and Statement 2 is correct.
C. Both Statements 1 and 2 are correct.
D. Both Statements 1 and 2 are wrong.
12. In the design of a simple digital filter using pole-zero placement:
Statement 1: To suppress a frequency component, locate a zero at this
frequency on the unit circle.
Statement 2: To amplify a frequency, locate a pole at this frequency inside the
unit circle.
A. Statement 1 is correct, and Statement 2 is wrong.
B. Statement 1 is wrong, and Statement 2 is correct.
C. Both Statements 1 and 2 are wrong.
D. Both Statements 1 and 2 are correct.
13. The transfer function of a linear time-invariant system is expressed as
H ðzÞ = BAððzzÞÞ.
Bibliography 261
Bibliography
Learning Objectives
After completing this chapter, the reader is expected to
• Analyse the characteristics of Type-I, Type-II, Type-III and Type-IV FIR filters.
• Design and analyse window-based finite impulse response filter.
• Design and analyse frequency sampling based finite impulse response filter.
• Design and analyse optimal finite impulse response filter.
FIR filter
© The Author(s), under exclusive license to Springer Nature Singapore Pte Ltd. 2024 263
S. Esakkirajan et al., Digital Signal Processing,
https://doi.org/10.1007/978-981-99-6752-0_7
264 7 FIR Filter Design
PreLab Questions
1. What is the difference equation relating the input and output of a finite impulse
response filter? What are the inferences that could be made from the difference
equation?
2. On what basis are FIR filters classified as Type-I, Type-II, Type-III and Type-IV
FIR filters?
3. When is a FIR filter coefficient said to exhibit (a) even symmetry and (b) odd
symmetry?
4. What is the condition for the digital filter to exhibit linear phase characteristics?
5. What is the advantage of ‘linear phase’ characteristics of digital filter?
6. What is the relationship between the group delay and the phase response of the
FIR filter?
7. What is the relationship between the order (M ) and the number of coefficients
(N ) of FIR filters?
8. Why FIR filter is considered as an ‘inherently stable’ filter?
9. List four advantages of FIR filter.
10. Mention different methods of design of FIR filter.
FIR stands for finite impulse response. The coefficients of FIR filter are either
symmetric or anti-symmetric. Due to the symmetric nature of FIR filter coefficients,
it exhibits linear phase characteristics. Because of linear phase characteristics, the
FIR filter has no phase distortion. Also, FIR filter exhibits constant group delay. In
FIR filter, the current output is a function of the current and previous inputs. This
implies that FIR filters are non-recursive filters; hence, they are inherently stable.
FIR filter is an all-zero filter, and the zeros occur in conjugate reciprocal pair.
Based on nature of symmetry and the number of coefficients, FIR filter can be
classified as Type-I, Type-II, Type-III and Type-IV. The classification is given in
Table 7.1.
Fig. 7.1 Python code to obtain the characteristics of Type-I FIR filter
2
0
jw
1
0 –1
0 10 20 –1.0 –0.5 0.0 0.5 1.0
n--> s
H(jw)
|H(jw)|
5.0
–4
2.5
0.0 –6
0 1 2 3 0 1 2 3
w --> w -->
Task
1. Write a python code to illustrate that Type-I FIR filter is versatile; (i.e.) it can be
used as a lowpass, highpass, bandpass and band reject filter.
Experiment 7.2 Characteristics of Type-II FIR Filter
Type-II FIR filter exhibits even symmetry with an even number of coefficients. The
Type-II FIR filter coefficients considered in this experiment is h[n] = {1, 2, 2, 1}.
The python code to obtain the impulse response, pole-zero plot, magnitude and
phase responses is shown in Fig. 7.3, and the corresponding output is shown in
Fig. 7.4.
Inferences
From Fig. 7.4, the following inferences can be made:
7.2 Classification of FIR Filter 267
Fig. 7.3 Python code to obtain the characteristics of Type-II FIR filter
1 0
jZ
0 –1
0 10 20 –1.0 –0.5 0.0 0.5 1.0
n--> s
–1
H(jw)
4
|H(jw)|
2 –2
0 –3
0 1 2 3 0 1 2 3
w --> w -->
Fig. 7.5 Python code to obtain the characteristics of Type-III FIR filter
1. From the impulse response, it is possible to observe that the impulse response is
of finite duration, and it exhibits even symmetry.
2. From the pole-zero plot, it is possible to observe that Type-II FIR filter is an
all-zero filter. The magnitude which is zero at ω = π indicates that Type-II FIR
filter cannot be used as a highpass filter.
3. From the magnitude response, it is possible to conclude that the filter behaves like
a lowpass filter.
4. From the phase response, it is possible to confirm that the Type-II FIR filter
exhibits linear phase characteristics in the passband.
Task
1. Generate x[n] = ejπn, 0 < n ≤ 100. Pass this signal through Type-II FIR filter
whose impulse response is h[n] = {1, 2, 2, 1}. Use subplot to plot the input and
output signals and comment on the observed result.
Experiment 7.3 Characteristics of Type-III FIR Filter
This experiment discusses the analysis of the characteristics of Type-III FIR filter
using python. The python code, which obtains the characteristics of Type-III FIR
filter, is shown in Fig. 7.5, and the corresponding output is shown in Fig. 7.6. The
7.2 Classification of FIR Filter 269
jw
0
–2 –1
0 10 20 –1.0 –0.5 0.0 0.5 1.0
n--> s
4 0
H(jw)
|H(jw)|
2 –2
–4
0
0 1 2 3 0 1 2 3
w --> w -->
impulse response chosen for Type-III FIR filter characteristics is {1, 2, 0, -2, -1},
and it satisfies both odd symmetry and the number of coefficients is odd.
Inferences
From Fig. 7.6, the following inferences can be drawn:
1. The impulse response shows odd symmetry with an odd number of coefficients.
The duration of the impulse response is finite.
2. From the pole-zero plot, it is possible to observe that the magnitude value is zero
at ω = 0 and ω = π. This implies that Type-III FIR filter cannot be used as a
lowpass and a highpass filters.
3. From the magnitude response, it is possible to observe that the filter can act as a
bandpass filter only.
4. From the phase response, it is possible to infer that the filter exhibits linear phase
characteristics in the passband.
Task
1. Write a python code to illustrate the fact that cascading of lowpass and highpass
filters will result in a bandpass filter.
Experiment 7.4 Characteristics of Type-IV FIR Filter
This experiment tries to analyse the characteristics of Type-IV FIR filter using
python. The python code, which obtains the characteristics of Type-IV FIR filter,
is shown in Fig. 7.7, and the corresponding output is shown in Fig. 7.8. The impulse
response chosen for this illustration is h[n] = {1, 2, -2, -1}. The impulse response
exhibits odd symmetry with an even number of filter coefficients.
270 7 FIR Filter Design
Fig. 7.7 Python code to obtain the characteristics of Type-IV FIR filter
jw
0 0
–2 –1
0 10 20 –2 –1 0 1
n--> s
0
|H(jw)|
2
–2
0
0 1 2 3 0 1 2 3
w --> w -->
Inferences
From Fig. 7.8, the following inferences can be made:
1. The impulse response plot reveals that Type-IV FIR filter impulse response is
anti-symmetric with an even number of coefficients.
2. From the pole-zero plot, it is possible to confirm that Type-IV FIR filter has a zero
at ω = 0; hence, it cannot be used as a lowpass filter.
3. The magnitude response resembles that of a bandpass filter.
4. The phase response plot reveals that Type-IV FIR filter exhibits linear phase
characteristics in the passband.
Experiment 7.5 Comparison of Type-I, Type-II, Type-III and Type-IV FIR
Filters with Respect to Their Location of Zeros
This experiment compares all four types of FIR filters with respect to their location
of zeros using python. The python code used to plot the pole-zero plot of Type-I,
Type-II, Type-III and Type-IV FIR filters is shown in Fig. 7.9, and the
corresponding output is shown in Fig. 7.10. In this program, the impulse responses
of four FIR filters are defined first. Then, the pole, zero and gain of each type of FIR
filter are obtained using the built-in function ‘tf2zpk’ available in ‘scipy’ package.
Then, the extracted poles and zeros are plotted. The automatic location of zeros in
Type-I, Type-II, Type-III and Type-IV FIR filters is given in Table 7.3.
Inferences
From Fig. 7.10, the following inferences can be drawn:
1. For Type-I FIR filter, there is no zero at ω = 0 and ω = π. It can be used as a
versatile filter.
2. Type-II FIR filter has a zero at ω = π. It cannot be used as a highpass filter.
3. Type-III FIR filter has zero at ω = 0 and ω = π. It cannot be used as both lowpass
and highpass filters.
4. Type-IV FIR filter has zero at ω = 0. It cannot be used as lowpass filter.
5. In general, zeros of FIR filter occur in conjugate, reciprocal pairs.
Task
1. Write a python code to illustrate the fact that all four types of FIR filters are
inherently stable filters. Hint: For a discrete-time system to be stable, the impulse
response should be absolutely summable.
The design of FIR filter starts with specification. The specification can be either in
time domain or frequency domain. In time domain, the desired impulse response is
given as specification. In frequency domain, the specification involves magnitude
and phase response. Three prominent methods to design FIR filters are (1) window-
based method, (2) frequency sampling method and (3) optimal method.
272 7 FIR Filter Design
Fig. 7.9 Python code to obtain the pole-zero plots of different types of FIR filter
The steps followed in FIR filter design using Windows are summarized below:
1. The filter design starts with the specification of the filter in terms of desired
frequency response.
2. The desired impulse response (hd[n]) is obtained from the desired frequency
response using inverse discrete-time Fourier transform.
3. Multiply the desired impulse response with the selected window function.
4. Delay the windowed impulse response by a factor of ‘τ’ to get the causal FIR filter
coefficients.
5. The process is complete if the frequency response is satisfied as per the specifi-
cation. If the frequency specifications are not satisfied, increase the filter order
and repeat the steps.
7.3 Design of FIR Filter 273
0 0
jw
jw
–2 –1
–1.0 –0.5 0.0 0.5 1.0 –1.0 –0.5 0.0 0.5 1.0
s s
0 0
jw
jw
–1 –1
–1.0 –0.5 0.0 0.5 1.0 –2 –1 0 1
s s
The expression for the impulse response of the ideal lowpass filter is given by
ωc ω
hd ½ n] = sin c c n ð7:1Þ
π π
From Eq. (7.1), it is possible to observe that the filter is neither causal nor finite in
duration. To make it finite duration, the desired impulse response is multiplied with
the window function. The mathematical expression for the impulse response multi-
plied with a rectangular window of length ‘N’ is given by
274 7 FIR Filter Design
Fig. 7.11 Python code to obtain the impulse response of the ideal filter
h[n]
0.30
0.25
0.20
Amplitude
0.15
0.10
0.05
0.00
–0.05
–20 –10 0 10 20
n-->
3. Practically realizable filters have passband and stopband ripples and a non-zero
transition band.
4. For practical filter, a delay is necessary to capture most of the signal energy in
causal time.
5. Delay in time-domain is accomplished by multiplying the spectrum with a
complex exponential. The magnitude response is multiplied by e-jωτ, which
results in the time shift of the impulse response. This is discussed in the subse-
quent section.
Task
1. In the above experiment, increase the number of coefficients of the filter to
100, observe the filter’s impulse response and comment on the observed result.
Experiment 7.7 Comparison of Ideal and Practical Lowpass Filter
The impulse response of an ideal filter is non-causal; hence, it is not physically
realizable. To design a practical filter, the impulse response of the ideal filter has to
be delayed to make it causal. Delay in the time-domain is accomplished by multi-
plying the spectrum with a complex exponential. The magnitude response is multi-
plied by e-jωτ, which results in the time shift of the impulse response.
This python illustration compares the ideal FIR filter with the practical FIR filter.
The python code, which performs the comparison, is shown in Fig. 7.13, and the
corresponding output is shown in Fig. 7.14.
276 7 FIR Filter Design
0.2
|H(e jw)|
–0.5
f (e jw)
–10
–1.0
0.0
–15
0 20 0 2 0 2
n--> w --> w -->
0.2
|H(e jw)|
I(e jw)
–50 –10
0.0
0 20 0 2 0 2
n--> w --> w -->
ωc ω
hd ½n] = sin cðn - τÞ - sin c c ðn - τÞ ð7:3Þ
π π
From Eq. (7.3), it is possible to know that the desired impulse response is a sinc
function that is not of finite duration. The desired impulse response must be
multiplied by the window function w[n] to make the finite impulse response. This
is expressed as
0.25 1
Amplitude
0.00 0
jw
–0.25 –1
0 20 40 –1 0 1
n--> s
–20
|H(ejw)|
–20
–60
0 1 2 3 0 1 2 3
w --> w -->
1. Figure 7.16 shows that the code was written to simulate the desired impulse
response, which is given in Eq. (7.3). The desired impulse response is multiplied
by the window to get the actual response. The window chosen in this illustration
is a rectangular window.
2. The ‘scipy’ library is used here to obtain the frequency response and the pole-zero
plot of the filter. The built-in function ‘tf2zpk’ is utilized to obtain the pole-zero
plot, whereas the built-in function ‘freqz’ is used here to obtain the frequency
response of the filter.
3. From the magnitude response shown in Fig. 7.16, it is possible to observe that the
filter is a highpass filter that exhibits linear phase characteristics in the passband.
4. From the pole-zero plot, it is possible to observe that the zeros of FIR filter occur
in conjugate reciprocal pair.
Task
1. In the python code given in Fig. 7.15, try to use windows like Hamming,
Hanning, Bartlett and Blackman window, and observe the changes in magnitude
and phase response.
The expression for the desired impulse response of the bandpass filter is given by
7.3 Design of FIR Filter 279
Fig. 7.17 Python code to obtain the characteristics of the bandpass filter
ωc2 ω ω ω
hd ½n] = sin cð c2 ðn - τÞÞ - c1 sin cð c1 ðn - τÞÞ ð7:5Þ
π π π π
Here ‘ωc1’ and ‘ωc2’ are pass band frequencies and ωc2 > ωc1. The desired
impulse response must be multiplied by the window function w[n] to get a finite
impulse response. This is expressed as
0.0
jw
0
–0.2 –1
0 5 10 15 –1 0 1 2 3
n--> s
–100 I(ejw) –5
0 1 2 3 0 1 2 3
w --> w -->
1. The lower cut-off frequency chosen is ωc1 = π4 which is equal to 0.785 radians/
sample, and the upper cut-off frequency chosen is ωc2 = π2 which is equal to
1.57 radians/sample. The magnitude response shows the passband between 0.785
and 1.57, and the gain drops beyond the cut-off frequency.
2. From the impulse response plot, it is possible to observe that the impulse response
is symmetric in nature.
3. From the phase response, it is possible to observe that the filter exhibits linear
phase characteristics in the passband. The linear phase is due to the symmetric
nature of the impulse response.
4. The pole-zero plot shows that the filter is an all-zero filter with the zeros occurring
in a conjugate reciprocal manner.
Task
1. In the above program, try to use windows like Hamming, Hanning, Bartlett and
Blackman, and observe the change in magnitude and phase response.
The expression for the desired impulse response of the band reject/stop filter is given
by
7.3 Design of FIR Filter 281
Fig. 7.19 Python code to obtain the characteristics of band reject filter
ωc1 ω ω ω
hd ½n] = sin cðn - τÞ þ sin c c1 ðn - τÞ - c2 sin c c2 ðn - τÞ ð7:7Þ
π π π π
Here ‘ωc1’ and ‘ωc2’ are stop band frequencies and ωc2 > ωc1. To make the
impulse response finite, the desired impulse response must be multiplied by the
window function w[n]. This is expressed as
jw
0
0.25
0.00 –1
0 5 10 15 20 –1 0 1
n--> s
–25
|H(ejw )|
f (ejw )
–10
–50
–20
–75
0 1 2 3 0 1 2 3
w --> w -->
1.57 radians/sample. The magnitude response shows that the frequency between
0.785 and 1.57 is attenuated.
2. From the impulse response plot, it is possible to observe that the impulse response
is symmetric in nature.
3. From the phase response, it is possible to observe that the filter exhibits linear
phase characteristics in the passband. The linear phase is due to symmetric nature
of the impulse response.
4. The pole-zero plot shows that the filter is an all-zero filter with the zeros occurring
in conjugate reciprocal manner.
Task
1. In the above program, try to use windows like Hamming, Hanning, Bartlett and
Blackman, and observe the change in magnitude and phase responses.
The built-in function ‘firwin’ available in ‘scipy’ library is used here to generate FIR
filter coefficients using window-based method. The input to the built-in function is
the number of coefficients of the filter, cut-off frequency and window type.
7.3 Design of FIR Filter 283
Fig. 7.21 Built-in function ‘firwin’ to obtain the characteristics of lowpass filter
0.10 1
Amplitude
jw
0.05
–1
0.00
0 5 10 15 –1.0 –0.5 0.0 0.5 1.0
n--> s
–50
f (jf)
–5
–100
0 20 40 0 20 40
Frequency (f) (Hz) Frequency (f) (Hz)
3. From the magnitude response, it is possible to observe that the gain drops after the
cut-off frequency of 5 Hz.
4. From the phase response, it is possible to confirm that linear phase characteristic
is obtained in the passband.
Experiment 7.12 Design of FIR Highpass Filter Using the Built-In Function
This experiment aims to obtain the highpass filter coefficients with a slight change in
the code which generates the lowpass filter. The keyword ‘pass-zero = false’ helps
one to obtain the highpass filter. The python code, which performs this task, is
shown in Fig. 7.23, and the corresponding output is shown in Fig. 7.24.
Inferences
The following inferences can be made from this experiment:
1. From Fig. 7.23, it is possible to observe that the keyword ‘pass_zero = False’
allows one to obtain the coefficients of the highpass filter.
2. The characteristic of highpass filter is shown in Fig. 7.24. From this figure, it is
possible to observe that beyond the cut-off frequency of 5 Hz, the gain reaches a
value of 0 dB, and the phase response is linear curve.
Experiment 7.13 Design of FIR Bandpass Filter Using the Built-In Function
The objective of this experiment is to design a bandpass filter, which will pass signal
in the frequency range 10–20 Hz. The sampling frequency chosen is 100 Hz. The
order of the filter is 50, and the window chosen is ‘Hamming window’.
7.3 Design of FIR Filter 285
0.5
0
jw
0.0 –2
0 5 10 15 20 –2 –1 0 1
n--> s
–5 –10
f (jf)
–10 –20
–15 –30
0 20 40 0 20 40
Frequency (f) (Hz) Frequency (f) (Hz)
The python code which generates the filter coefficient corresponding to the
desired bandpass filter is shown in Fig. 7.25, and the corresponding filter character-
istics are shown in Fig. 7.26.
Inferences
The following inferences can be drawn from this experiment:
1. From Fig. 7.26, it is possible to observe from the magnitude response that the
filter passes a band of frequencies from 10 to 20 Hz.
2. From the impulse response, it is possible to observe that the impulse response of
the filter is finite and symmetric.
3. The filter also exhibits linear phase characteristics in the passband. This is due to
the symmetric nature of the impulse response.
4. From the pole-zero plot, it is possible to observe that the zeros occur in conjugate
reciprocal pair.
Experiment 7.14 Design of FIR Band Reject Filter Using the Built-In Function
This experiment discusses the design of FIR band reject filter using built-in function.
The band reject filter is obtained from bandpass filter design using the key term
‘pass_zero = True’. The python code which obtains the coefficient of the band reject
filter is shown in Fig. 7.27, and the corresponding output is shown in Fig. 7.28.
7.3 Design of FIR Filter 287
0.1
0
jw
0.0
–0.1 –1
0 5 10 15 0 2 4
n--> s
–0
f (jf)
–50
–5
–100 –10
0 20 40 0 20 40
Frequency (f) (Hz) Frequency (f) (Hz)
Fig. 7.27 Python code to generate the band reject filter coefficients and its characteristics
288 7 FIR Filter Design
jw
0.2 0
0.0 –1
0 10 20 –1 0 1
n--> s
–25 –10
f (jf)
–50
–20
–75
–30
0 20 40 0 20 40
Frequency (f) (Hz) Frequency (f) (Hz)
Inferences
The following observations can be made from this experiment:
1. Figure 7.27 shows that the keyword ‘pass-zero = True’ is used here to convert the
bandpass filter to a band reject filter.
2. From the magnitude response shown in Fig. 7.28, it is possible to confirm that this
filter blocks the frequency band from 10 to 30 Hz.
In this section, the window function is visualized in both time domain and frequency
domain. Different types of window functions include rectangular, triangular, Ham-
ming, Hanning, Kaiser, etc. The main lobe width of the window function controls the
transition bandwidth, whereas the height of the side lobe controls the passband and
stopband ripples. A rectangular window has the narrowest main lobe; hence, it gives
sharpest transition. Compared to rectangular window, the Hamming and Hanning
windows are smoother. By tapering the window smoothly to zero, the sidelobes can
be reduced in amplitude, which will reduce the ripple, but the trade-off is a larger
main lobe. A linear phase response can be achieved if the window function is
symmetric. Some windows allow controlled trade-offs between sidelobe amplitude
and main lobe width. One such window is the Kaiser window.
7.3 Design of FIR Filter 289
Fig. 7.29 Python code to plot the window functions in time and frequency domain
Magnitude [dB]
–50
w[n]
0.5
–100
0.0
–20 0 20 –0.4 –0.2 0.0 0.2 0.4
n--> Normalized frequency
Bartlett window Spectrum of Bartlett window
1.0 0
Magnitude [dB]
–50
w[n]
0.5
–100
0.0
–20 0 20 –0.4 –0.2 0.0 0.2 0.4
n--> Normalized frequency
–50
w[n]
0.5
–100
0.0
–20 0 20 –0.4 –0.2 0.0 0.2 0.4
n--> Normalized frequency
–50
w[n]
0.5
–100
0.0
–20 0 20 –0.4 –0.2 0.0 0.2 0.4
n--> Normalized frequency
3. The spectrum of different windows differs with respect to main lobe width and
side lobe height.
7.4 Frequency Sampling-Based FIR Filter Design 291
The steps followed in frequency sampling method of FIR filter design are summa-
rized below:
1. The design step starts with a prescribed magnitude response.
2. The prescribed magnitude response is sampled at enough points.
3. Take the inverse Fourier transform of the samples obtained in step (2). This will
result in the filter’s impulse response.
Fig. 7.32 Python code to obtain the characteristics of four types of FIR filter using frequency
sampling method
7.5 Design of Optimal FIR filter 293
Type-I FIR filter Type-I FIR filter Type-III FIR filter Type-III FIR filter
0 0 0
|H(ejw )| in dB
|H(ejw )| in dB
0
I(ejw )
I(ejw )
–20 –20
–100 –50
–40 –40
0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3
w /p w /p w /p w /p
Type-II FIR filter Type-II FIR filter Type-IV FIR filter Type-IV FIR filter
0 0 0 0
|H(ejw )| in dB
|H(e )| in dB
I(ejw )
I(ejw )
–25 –25 –25 –50
jw
–50 –50 –50
–100
0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3
w /p w /p w /p w /p
Fig. 7.33 Magnitude and phase responses of four types of FIR filter
The optimal equiripple FIR filter design is due to Parks and McClellan. The optimal
method provides an FIR filter coefficient representing the best approximation to the
desired frequency response in a Chebyshev sense. The term optimal can be defined
in various ways. The Parks-McClellan package uses the Remez exchange algorithm
to optimize the filter design by selecting the impulse response, which minimizes the
peak ripple in the passband and stopband. The filter designed by this approach is
termed as ‘equiripple’ filter. It is also termed as ‘minimax filter’ because the
maximum ripple deviation is minimized in the optimization procedure.
Experiment 7.17 Design of Optimal FIR Filter
The built-in functions available in ‘scipy’ library like, ‘remez’ and ‘firls’ can be used
to obtain the coefficients of optimal filter using Remez exchange algorithm and the
least square approach, respectively.
The aim of this experiment is to design the lowpass, highpass, bandpass and band
reject filters using the built-in function ‘remez’ available in ‘scipy’ library. The
python code, which generates the filter coefficients and plots the magnitude
responses of these four filters, is shown in Fig. 7.34, and the corresponding output
is shown in Fig. 7.35.
Inferences
From Fig. 7.34, the following observations can be made:
1. The sampling frequency of the four filters is kept at 1000 Hz, the number of taps
of the filter of all four filters is kept as 125 and the transition width of the four
filters is kept as 25 Hz.
2. The lowpass filter cut-off frequency is kept at 100 Hz. This means that the filter
should pass all frequencies till 100 Hz and block frequency components greater
than 100 Hz.
3. The cut-off frequency of a highpass filter is fixed as 200 Hz.
4. For the bandpass and band reject filters, the lower and upper cut-off frequencies
are fixed as 100 Hz and 200 Hz, respectively.
294 7 FIR Filter Design
Fig. 7.34 Python code to obtain the filter coefficients using the built-in function ‘remez’
From Fig. 7.35, it is possible to observe that the magnitude responses of the four
filters are as per the specification.
The coefficients of FIR filters are either symmetric or anti-symmetric. FIR filter
exhibits linear phase characteristics, because of which, there is no phase distortion.
The group delay of FIR filter is constant. Since the poles of FIR filter occur at the
origin, FIR filters are inherently stable. Because of these characteristics, FIR filters
are used in many areas of signal processing like multirate signal processing, adaptive
signal processing, etc. In multirate signal processing, FIR filters are preferred to
design perfect reconstruction filter bank. In adaptive signal processing, FIR filters
are preferred in system identification, adaptive notch filter, inverse system model-
ling, echo cancellation and variety of such applications. In this section, two simple
7.6 Applications of FIR Filter 295
Gain (dB)
Gain (dB)
–50 –50
–100
–100
0 200 400 0 200 400
Frequency (Hz) Frequency (Hz)
Magnitude response of BPF Magnitude response of BRF
0 0
Gain (dB)
Gain (dB)
–50 –50
–100
–100
0 200 400 0 200 400
Frequency (Hz) Frequency (Hz)
applications are discussed. One is signal separation, and the other is signal
denoising.
Experiment 7.18 Separation of Signals Using FIR Filter
The signal x(t) is an addition of two signals x1(t) and x2(t). The frequencies of the two
signals x1(t) and x2(t) are 5 Hz and 15 Hz, respectively. The signal x(t) is now passed
through a lowpass filter whose cut-off frequency is 8 Hz, the order of the filter is
20 and the window chosen is Hanning.
The problem statement is depicted in the form of block diagram, which is shown
in Fig. 7.36.
The python code, which performs lowpass filtering of the input sine wave with
5 and 15 Hz frequency components, is shown in Fig. 7.37, and the corresponding
output is in Fig. 7.38.
Inferences
From Fig. 7.37, the following observations can be made:
296 7 FIR Filter Design
Fig. 7.37 Python code to perform lowpass filtering of the input signal
1. The input signal is the sum of two sine wave frequencies, 5 and 15 Hz.
2. Window-based FIR filter is designed with a cut-off frequency of 8 Hz, the number
of taps is 21 and the window chosen is Hanning. The sampling frequency chosen
is 100 Hz.
3. ‘The built-in function ‘firwin’, which is available in ‘scipy’ package, is used to
design the filter.
From Fig. 7.38, the following observations can be made:
1. The input signal is a mixture of 5 and 15 Hz sine wave.
2. The output signal is a lowpass filtered signal which retains a 5 Hz sine wave.
3. The spectrum of the input signal shows peaks corresponding to 5 and 15 Hz
frequency components.
7.6 Applications of FIR Filter 297
1 0.5
Amplitude
Amplitude
0 0.0
–1 –0.5
0 1 2 0 1 2
Time Time
Magnitude
0.5 0.4
0.2
0.0 0.0
0 20 40 0 20 40
Frequency Frequency
4. The spectrum of the output signal shows peak at 5 Hz, which implies that the filter
allows 5 Hz frequency component of the input signal, and it blocks the 15 Hz
frequency component of the input signal.
Experiment 7.19 Denoising of the Signal Using FIR Filter
The signal x(t) is a 5 Hz sine wave. This signal x(t) is corrupted by white noise,
which follows uniform distribution in the range [0, 1]. The noisy signal is then
passed through FIR lowpass filter. The FIR filter coefficients are generated using the
windowing technique. Plot results of the clean, noisy and filtered signals.
The python code which performs the above-mentioned task is shown in Fig. 7.39,
and the corresponding output is shown in Fig. 7.40.
Inferences
The following observations can be made from this experiment:
1. From Fig. 7.39, it is possible to observe that the built-in function ‘random.
uniform’ available in numpy library is used here to generate uniformly distributed
random noise in the interval 0 to 1.
2. The random noise is added to pure sine wave to create noisy sine wave. The noisy
sine wave is then filtered using FIR filter, obtained using the built-in function
‘firwin’ available in scipy library.
3. From Fig. 7.40, it is possible to observe that the clean sine wave has a frequency
of 5 Hz. It is then corrupted by random noise to create noisy sine wave. From the
filtered signal, it is possible to observe that the impact of noise is minimized.
298 7 FIR Filter Design
import numpy as np
import matplotlib.pyplot as plt
from scipy import signal
#Step 1: Generation of clean signal
t=np.linspace(0,1,100)
x=np.sin(2*np.pi*5*t)
n=np.random.uniform(0,1,100) #Step 2: Uniform random noise
x1=x+n #Step 3: Noisy sine wave
h=signal.firwin(21,.2,pass_zero=True)#FIR filter coefficients
y=signal.filtfilt(h,1,x1) #Step 4: Filtered signal
#Step 5: Plotting the result
plt.subplot(3,1,1),plt.plot(t,x),plt.xlabel('Time'),plt.ylabel('Amplitude'),
plt.title('Clean signal'),plt.subplot(3,1,2),plt.plot(t,x1)
plt.xlabel('Time'),plt.ylabel('Amplitude'),plt.title('Noisy signal')
plt.subplot(3,1,3),plt.plot(t,y),plt.xlabel('Time'),plt.ylabel('Amplitude'),
plt.title('Filtered signal'),plt.tight_layout()
Clean signal
Amplitude
1
0
–1
0.0 0.2 0.4 0.6 0.8 1.0
Time
Noisy signal
Amplitude
1
0
–1
0.0 0.2 0.4 0.6 0.8 1.0
Time
Filtered signal
Amplitude
1
0
0.0 0.2 0.4 0.6 0.8 1.0
Time
Exercises
1. Design a linear phase lowpass filter that satisfies the following magnitude
π
1, jωj <
response H ðe Þ =
jω 4 . For N = 5 and N = 7. Assume the window
0, otherwise
to be rectangular window. Plot the magnitude response of the filter.
7.6 Applications of FIR Filter 299
5 Blackman window -1 þ
w½n] = 0:42 þ 0:5 cos N2πn 0:08 cos 4πn
N -1
2. Design a length 7 linear phase highpass filter using windowing method with the
cut-off frequency ωc = π3 radians/sample. Assume the window to be Bartlett
window. Plot the magnitude and phase response of the filter.
3. Design a length 5 linear phase bandpass filter with lower cut-off frequency
ωc1 = 0.25π radians/sample and upper cut-off frequency ωc2 = 0.75π radians/
sample. Assume the window to be rectangular window. Plot the magnitude and
phase response of the filter.
4. Design a length 7 linear phase band reject filter with lower cut-off frequency
ωc1 = 0.15π radians/sample and upper cut-off frequency ωc2 = 0.45π radians/
sample. Assume the window to be Hamming window. Plot the magnitude and
phase response of the filter.
5. The signal x(t) is an addition of two signals x1(t) and x2(t). The frequencies of the
two signals x1(t) and x2(t) are 5 Hz and 10 Hz, respectively. The signal x(t) is
now passed through a highpass filter whose cut-off frequency is 8 Hz, the order
of the filter is 10 and the window chosen is Hamming window. Plot the input
signal and the filtered signal and comment on the observed result.
6. The time domain expression for different window functions is given in the
following Table 7.4.
Write a python code to plot the above window functions and comment on the
observed result. Assume the value of N as 31.
7. Write a python code to design a length 9 linear phase highpass filter using
windowing method with the cut-off frequency ωc = 4 radians/sample. Assume
the window to be Bartlett window. Plot the pole-zero plot of the filter, and
observe that the zeros of the filter occur in conjugate pair.
8. The impulse response of 5-tap linear phase lowpass filter is given by
h1[n] = {0.159, 0.225, 0.25, 0.225, 0.159}. Derive another filter from this
lowpass filter, whose impulse response is given by h2[n]. The relationship
between the impulse responses is given by h2[n] = (-1)nh1[n]. Plot the magni-
tude responses of the two filters and comment on the observed result.
9. Design a lowpass FIR filter using a frequency sampling technique having cut-off
frequency of π/2 radians/sample. The length of the filter is 21. Plot the magni-
tude response of the filter.
10. Design a digital FIR lowpass filter with the following specifications:
(a) Passband cut-off frequency: fp = 1 kHz. (b) Stopband cut-off frequency:
300 7 FIR Filter Design
Objective Questions
1. Assertion: FIR filter exhibits linear phase characteristics.
Reason: The coefficients of FIR filter are either symmetric or anti-symmetric:
A. Both assertion and reason are true.
B. Assertion is true; reason is false.
C. Assertion is false; reason may be true.
D. Both assertion and reason are false.
2. If ‘N’ represents the number of coefficients of the FIR filter, then the group delay
of the filter is expressed as
A. τg = N2
B. τg = N2 - 1
C. τg = N -2
1
D. τg = N
3. Identify the statement that is FALSE with respect to FIR filter
A. FIR filter is all-zero filter.
B. FIR filter is all-pole filter.
C. FIR filter is inherently stable filter.
D. Group delay of FIR filter is constant.
4. The filter which exhibits even symmetry with odd number of coefficient is
A. Type-I FIR filter
B. Type-II FIR filter
C. Type-III FIR filter
D. Type-IV FIR filter
5. The built-in function available in scipy library to design window-based FIR filter
is
A. signal.firwin()
B. signal.firwin2()
C. signal.remez()
D. signal.firls()
6. The built-in function available in scipy library to design frequency sampling-
based FIR filter is
A. signal.firwin(),
B. signal.firwin2()
C. signal.remez()
D. signal.firls()
7.6 Applications of FIR Filter 301
12. Let h[n] represent the impulse response of lowpass filter and then the impulse
response (-1)nh[n] represent
A. Lowpass filter
B. Highpass filter
C. Band pass filter
D. Band reject filter
13. Match the following
A. h = {1,2,0,2,1}
B. h = {1,2,0,-2,-1}
C. h = {1,2,0,1,2}
D. h = {1,2,0,-1,-2}
15. The impulse response of a filter is obtained using the following python code.
The filter is
Bibliography
1. Vijay Madisetti, “The Digital Signal Processing Handbook”, CRC Press, 1997.
2. Paulo S. R. Diniz, Eduardo A.B. da Silva and Sergio L. Netto, “Digital Signal Processing:
System Analysis and Design”, Cambridge University Press, 2010.
3. T.W. Parks, and C.S. Burrus, “Digital Filter Design”, John Wiley and Sons, 1987.
4. Wai-Kai Chen, “Passive, Active and Digital Filters”, CRC Press, 2006.
5. Robert J. Schilling and Sandra L. Harris, “Fundamentals of Digital Signal Processing using
MATLAB”, Cengage Learning, 2012.
Chapter 8
Infinite Impulse Response Filter
Learning Objectives
After reading this chapter, the reader is expected to:
• Design and analyse Butterworth filter.
• Design and analyse Chebyshev and inverse Chebyshev filters.
• Design and analyse elliptic filter.
• Implement different mapping techniques to convert analogue filter into an equiv-
alent digital filter.
IIR Filter
© The Author(s), under exclusive license to Springer Nature Singapore Pte Ltd. 2024 303
S. Esakkirajan et al., Digital Signal Processing,
https://doi.org/10.1007/978-981-99-6752-0_8
304 8 Infinite Impulse Response Filter
PreLab Questions
1. What is a recursive filter?
2. Examine whether IIR filter is recursive or not. Justify your answer.
3. What is a ripple in the filter’s frequency response?
4. List the different types of IIR filters based on the ripples.
5. Why the Butterworth filter is termed as ‘maximally flat frequency response’
filter?
6. Mention the techniques to convert the analogue filter transfer function into an
equivalent digital filter transfer function.
7. Which criterion is important in mapping an analogue filter into an equivalent
digital filter?
8. List the steps involved in obtaining the digital filter transfer function from the
analogue filter transfer function using the impulse invariant technique.
9. What are the drawbacks of impulse invariant technique?
10. How does the bilinear transformation technique avoid aliasing while performing
the mapping process?
11. What is frequency warping with respect to bilinear transformation technique?
Suggest a solution to overcome the frequency warping problem in bilinear
transformation technique.
12. Tabulate the difference between Butterworth filter, Chebyshev filter, inverse
Chebyshev and elliptic filter with respect to (a) ripples in passband and
stopband, (b) transition width and (c) order of the filter required to meet the
filter specification.
13. Elaborate on the steps involved in the design of a digital IIR filter.
In IIR filter, the current output is a function of the current and previous inputs and
past outputs. The relationship between the input and output of an IIR filter is given
by
From Eq. (8.1), it is possible to observe that the current output is a function of
current and previous inputs and past outputs. Thus, IIR filters are ‘recursive filters’.
In a recursive filter, the current output depends on both the input and previously
calculated outputs. The word ‘recursive’ literally means ‘running back’ and refers to
previously calculated output values that go back into calculating the current output
along with input values.
Upon taking Z-transform of the input-output relation given in Eq. (8.1), the
transfer function expression for IIR filter is given by
8.1 IIR Filter 305
M -k
k = 0 bk z
H ðzÞ = N ð8:2Þ
1þ -k
k = 1 ak z
The impulse response of the IIR filter can be obtained upon taking inverse Z-
transform of the transfer function. As the name suggests, the impulse response is not
of finite duration. The impulse response is not guaranteed to be either symmetric or
anti-symmetric; hence, it is not possible to obtain linear phase characteristics in the
IIR filter. The group delay is not constant in IIR filter. If the pole of the IIR filter lies
outside the unit circle, the filter is unstable. This implies that stability is not
guaranteed in IIR filter. The main advantage of IIR filter is that it is possible to
meet the filter specification with the minimum number of coefficients.
Experiment 8.1 Computation of Impulse Response h[n] of the Recursive Filter
The filter’s impulse response h[n] can be obtained from the input and output relation.
Let us consider the linear constant coefficient difference equation
1
y½n] þ y½n - 1] = x½n] ð8:3Þ
2
where y[n] denotes the output and x[n] represents the input of the equation. From
Eq. (8.3), it is possible to observe that the current output (y[n]) is a function of
current input (x[n]) and past output (y[n - 1]). The impulse response of this filter can
be computed by replacing y[n] as h[n] and x[n] as δ[n]. Hence, Eq. (8.3) can be
rewritten as
1
h½n] þ h½n - 1] = δ½n]
2
1
h½n] = δ½n] - h½n - 1]
2
Assume that the system is initially at rest (i.e. y[n] = 0 for n < 0) and substituting
n = 0, 1, 2, 3, . . ., in the above equation, we get
1
h½0] = δ½0] = h ½ 0 - 1] = 1 - 0 = 1
2
1 1 1 1
h½1] = δ½1] - h½1 - 1] = 0 - h½0] = - × 1 = -
2 2 2 2
1 1 1 1 1
h½2] = δ½2] - h½2 - 1] = 0 - h½1] = - × - =
2 2 2 2 4
306 8 Infinite Impulse Response Filter
Impulse response
1.0
0.8
0.6
0.4
h[n]
0.2
0.0
–0.2
–0.4
–4 –2 0 2 4 6 8 10
n-->
(a) Python code (b) Simulation result
Fig. 8.1 Python code and its result of impulse response computation. (a) Python code. (b)
Simulation result
1 1 1 1 1
h½3] = δ½3] - h½3 - 1] = 0 - h½2] = - × = -
2 2 2 4 8
1 n
h½ n] = - u½n]
2
The python code to obtain the impulse response from the input and output
coefficients mentioned in the difference equation is shown in Fig. 8.1a, and the
corresponding output is shown in Fig. 8.1b.
Inference
1. From Fig. 8.1a, it is possible to observe that the ‘scipy’ library is used for the
filtering, and ‘signal.lfilter’ is used for the computation of impulse response from
the input and output coefficients of the filter equation.
2. From Fig. 8.1b, it is possible to infer that the simulation result is in agreement
with the theoretical result.
Task
1. Write a python code to obtain the impulse response of the filter whose difference
equation is given by y½n] - 12 y½n - 1] = x½n] and comment on the observed output.
The relationship between ‘s’ domain and ‘z’ domain using the backward difference
method is given by
1 - z-1
s= ð8:4Þ
T
and
1
z= ð8:5Þ
1 - sT
This section displays the mapping of analogue filter into equivalent digital filter
using backward difference method.
Experiment 8.2 Mapping of S-Plane to Z-Plane Using Backward Difference
Method
The main objective of this experiment is to prove that stable analogue filter will be
mapped to a stable digital filter using backward difference method. The python code,
which performs the mapping from S-plane to Z-plane, is given in Fig. 8.2.
Inference
1. From Fig. 8.3a, it is possible to infer that points in the left half of S-plane
(i.e. σ ≤ 0) are mapped into inside and on the unit circle in Z-plane.
2. This confirms that the stable analogue filter can be mapped into a stable digital
filter using the backward difference mapping technique.
3. On the other hand, from Fig. 8.3b, it is evident that the points on the right side of
the S-plane (i.e. σ > 0) are mapped into outside the unit circle of the Z-plane.
Fig. 8.2 Python code for mapping S to Z plane using backward difference method. (a) σ ≤ 0. (b)
σ>0
s-plane s-plane
10
10
j:
j:
0 0
–10
–10
–10 –8 –6 –4 –2 0 2 4 6 8 10
s s
z-plane z-plane
1 1
0
jw
jw
–1 –1
–1.00 –0.75 –0.50 –0.25 0.00 0.25 0.50 0.75 1.00 –1.0 –0.5 0.0 0.5 1.0
s s
1
-------------
s^2 + 3 s + 2
import control as ss
s1 = ss.tf(1, [1,3,2]) 0.007576 z^2 - 2.22e-16 z + 2.22e-16
print(s1) ------------------------------------
yd = s1.sample(0.1, method='backward_diff') z^2 - 1.742 z + 0.7576
print(yd) dt = 0.1
Fig. 8.4 Python code and simulation result for backward difference mapping method. (a) Python
program. (b) Simulation result
1 - z-1
s=
T
1 - z-1
s=
0:1
s = 10 - 10z - 1
Substituting the above relation in the transfer function of the analogue filter, we
get
1
H ðzÞ =
ð10 - 10z - 1 Þ2 þ 3ð10 - 10z - 1 Þ þ 2
0:007576z2
H ðzÞ =
z2 - 1:742z þ 0:7576
The frequency responses of both the analogue and digital filters are computed
using python code, shown in Fig. 8.4a, and its corresponding simulation result is
shown in Fig. 8.4b. Before execution of the python code, the ‘python-control’
package must be installed using the pip command, which is given by ‘pip install
control’. The new python commands used in this python program are (1) xx.tf and
(2) yy.sample. The result of the python code given in Fig. 8.4a is shown in Fig. 8.4b.
Inference
The following inferences can be made from this experiment:
310 8 Infinite Impulse Response Filter
1. From the simulation result shown in Fig. 8.4b, it is evident that the denominator
polynomial function is exactly matched with the theoretical result.
2. The denominator polynomial corresponds to the poles of the system. Thus,
analogue filter is mapped into an equivalent digital filter, which is in agreement
with the theoretical result.
Experiment 8.4 Mapping Stable Analogue Filter to a Stable Digital Filter Using
Backward Difference Method
This experiment deals with mapping a stable analogue filter to a stable digital filter
using the backward difference method. The transfer function of a stable second-order
filter considered in this example is given by
4
H ðsÞ =
s2 þ 2:82s þ 4
This filter is converted into an equivalent digital filter H(z) using backward
difference method. The python code to verify the conversion of a second-order
stable analogue filter into a stable digital filter is given in Fig. 8.5, and the simulation
result is depicted in Fig. 8.6. This python code will work for the second-order filter
only. The simulation result of this experiment is shown in Fig. 8.6.
Inference
From Fig. 8.6b, it is possible to observe that the poles of H(s) lie left half of the S-
plane, confirming that the analogue filter is stable. Similarly, from this figure, it is
possible to know that the poles of H(z) lie inside the unit circle. Hence, the backward
difference mapping method preserves the stability criterion during mapping.
In impulse invariant technique, the digital filter is designed by sampling the impulse
response of the analogue filter. The pole at s = sp is mapped to a pole at z = esp T in
the digital filter. Impulse invariant technique performs many-to-one mapping; hence,
it suffers from an aliasing problem. Thus, impulse invariant technique is useful if the
analogue filter is band-limited. The step followed in impulse invariant technique is
given in Fig. 8.7.
The impulse response of the analogue filter is represented by h(t). It is sampled to
get h[nT]. Upon taking Z-transform of the sampled impulse response, the transfer
function of the digital filter is obtained, which is represented as H(z).
Experiment 8.5 Mapping of S-Plane to Z-Plane Using Impulse Invariant
Technique
This experiment deals with mapping the S-plane to Z-plane using impulse invariant
technique.
Case 1: Mapping the points on the j Ω axis of the S-plane
8.2 Mapping Techniques in the Design of IIR Filter 311
import numpy as np
import control as ss
from scipy import signal
import matplotlib.pyplot as plt
num=[4]
den=[1,2*np.sqrt(2),4]
T=0.1
fsam=1/T
s1=ss.tf(num,den)
print('H(s) =', s1)
a1=1
b1=-(2+den[1]*T)/(1+(den[1]*T)+den[2]*(T**2))
c1=1/(1+(den[1]*T)+den[2]*(T**2))
num1=[num[0]*c1*(T**2),0,0]
den1=[a1,b1,c1]
yd = s1.sample(T, method='backward_diff')
print('Using Built in function: H(z) =',yd)
s2=ss.tf(num1,den1,T)
print('H(z) =', s2)
ps,zs=ss.pzmap(s1)
# Pole-zero plot
plt.subplot(2,1,1),plt.plot(ps.real, ps.imag, 'kx', ms=10),plt.xlabel('$\sigma$'),
plt.ylabel('$j\Omega$'),plt.title('Pole-zero plot of H(s)'),plt.grid()
z, p, k = signal.tf2zpk(num1,den1)
theta = np.linspace(0, np.pi*2, 500)
circle = np.exp(1j*theta)
plt.subplot(2,1,2),plt.plot(circle.real, circle.imag, 'k--')
plt.plot(p.real, p.imag, 'rx', ms=7.5),plt.xlabel('$\sigma$'),
plt.ylabel('$j\omega$'),plt.title('Pole-zero plot of H(z)'),plt.grid()
plt.tight_layout(),plt.show()
Fig. 8.5 Python code for mapping analogue filter to digital filter
The python code for mapping the points on the j Ω axis onto unit circle is given in
Fig. 8.8, and its corresponding output is shown in Fig. 8.9. Figure 8.9 confirms that
the points on the j Ω axis in the S-plane are mapped onto a unit circle in the Z-plane.
Case 2: Mapping the left half of the S-plane
The python code for mapping the points in left half of S-plane are mapped into
inside the unit circle is given in Fig. 8.10, and its corresponding output is shown in
Fig. 8.11. Figure 8.11 confirms that the points in the left half of S-plane are mapped
into within the unit circle of the Z-plane.
Case 3: Mapping right half of S-plane
The points in the right half of S-plane are mapped into outside the unit circle in the
Z-plane. The python code for mapping the points in right half of S-plane are mapped
into outside the unit circle is given in Fig. 8.12, and its corresponding output is
312 8 Infinite Impulse Response Filter
j:
–1
0
jw
–1
–1.00 –0.75 –0.50 –0.25 0.00 0.25 0.50 0.75 1.00
s
Fig. 8.6 Simulation result. (a) Transfer function. (b) Pole-zero plot
Fig. 8.8 Python code for mapping points on the j Ω axis onto the unit circle
shown in Fig. 8.13. From Fig. 8.13, it is possible to infer that the points in the right
half of the S-plane are mapped outside the unit circle in the Z-plane.
Thus, a stable analogue filter can be mapped to an equivalent stable digital filter
using the impulse invariant technique.
8.2 Mapping Techniques in the Design of IIR Filter 313
S-plane
10
0
j:
–10
0
jw
–1
–1.00 –0.75 –0.50 –0.25 0.00 0.25 0.50 0.75 1.00
s
import numpy as np
import matplotlib.pyplot as plt
omega1=np.linspace(-15, 15, 30)
omega2 = np.array([1 in range(len(omega1))])
omega2=omega1
sigma1=np.linspace(-10, -0.1, 30)
sigma2 = np.array([1 in range(len(sigma1))])
sigma2 = sigma1
S=[[0 for i in range(len(sigma2))] for j in range(len(omega2))]
Z=S
T=0.9
theta = np.linspace(0, np.pi*2, 500)
circle = np.exp(1j*theta)
plt.subplot(2,1,2),plt.plot(circle.real, circle.imag, 'k'),
for j in range(len(sigma2)):
for i in range(len(omega2)):
S[i][j]=complex(sigma1[i],omega1[j])
Z[i][j]=np.exp(S[i][j]*(T))
plt.subplot(2,1,1),plt.plot(sigma1[i],omega1[j],'bx')
plt.title('S-plane'), plt.xlabel('$\sigma$'),plt.ylabel('$j\Omega$')
plt.subplot(2,1,2),plt.plot(np.real(Z[i][j]),np.imag(Z[i][j]),'rx')
plt.title('Z-plane'), plt.xlabel('$\sigma$'),plt.ylabel('$j\omega})$')
plt.tight layout()
S-plane
10
0
j:
–10
–10 –8 –6 –4 –2 0
s
Z-plane
1
0
jw
–1
–1.00 –0.75 –0.50 –0.25 0.00 0.25 0.50 0.75 1.00
s
import numpy as np
import matplotlib.pyplot as plt
omega1=np.linspace(-2, 2, 30)
omega2 = np.array([1 in range(len(omega1))])
omega2=omega1
sigma1=np.linspace(0.1, 2, 30)
sigma2 = np.array([1 in range(len(sigma1))])
sigma2 = sigma1
S=[[0 for i in range(len(sigma2))] for j in range(len(omega2))]
Z=S
T=1
theta = np.linspace(0, np.pi*2, 500)
circle = np.exp(1j*theta)
plt.subplot(2,1,2),plt.plot(circle.real, circle.imag, 'k'),
for j in range(len(sigma2)):
for i in range(len(omega2)):
S[i][j]=complex(sigma1[i],omega1[j])
Z[i][j]=np.exp(S[i][j]*(T))
plt.subplot(2,1,1),plt.plot(sigma1[i],omega1[j],'bx')
plt.title('S-plane'),plt.xlabel('$\sigma$'),plt.ylabel('$j\Omega$')
plt.subplot(2,1,2),plt.plot(np.real(Z[i][j]),np.imag(Z[i][j]),'rx')
plt.title('Z-plane'),plt.xlabel('$\sigma$'),plt.ylabel('$j\omega})$')
plt.tight_layout()
S-plane
2
0
j:
–2
0.25 0.50 0.75 1.00 1.25 1.50 1.75 2.00
s
Z-plane
5
0
jw
–5
–2 0 2 4 6
s
Inferences
The following inferences can be made from this experiment:
1. Overlapping of the symbols in Fig. 8.15 implies that impulse invariant technique
is basically a many-to-one mapping.
2. Many-to-one mapping leads to an ‘aliasing problem’ in impulse invariant
technique.
3. Hence, impulse invariant technique is suitable for the design of lowpass and
bandpass filters.
4. It is not advisable to use it in highpass and bandstop filters design.
Experiment 8.7 Conversion of Analogue Filter into a Digital Filter Using IIT
This experiment discusses the conversion of an analogue filter to a digital filter using
impulse invariant technique. Let us consider the transfer function of the analogue
0:5ðsþ3Þ
filter H ðsÞ = ðsþ1 Þðsþ4Þ to be converted into the transfer function of the digital filter
H(z) using the impulse invariant technique. Assume the sampling frequency to be
20 Hz.
316 8 Infinite Impulse Response Filter
import numpy as np
import matplotlib.pyplot as plt
T=0.5
omega1=np.linspace(-np.pi/T, np.pi/T, 15)
omega2 = np.array([1 in range(len(omega1))])
omega2=omega1
omega11=np.linspace(-3*(np.pi/T), 3*(np.pi/T), 15)
omega21 = np.array([1 in range(len(omega11))])
omega21=omega11
sigma1=np.linspace(0, 0, 15)
sigma2 = np.array([1 in range(len(sigma1))])
sigma2 = sigma1
S=[[0 for i in range(len(sigma2))] for j in range(len(omega2))]
S1=[[0 for i in range(len(sigma2))] for j in range(len(omega21))]
Z,Z1=S,S1
theta = np.linspace(0, np.pi*2, 500)
circle = np.exp(1j*theta)
plt.subplot(2,1,2),plt.plot(circle.real, circle.imag, 'k'),
for j in range(len(sigma2)):
for i in range(len(omega2)):
S[i][j]=complex(sigma1[i],omega1[j])
Z[i][j]=np.exp(S[i][j]*(T))
S1[i][j]=complex(sigma1[i],omega11[j])
Z1[i][j]=np.exp(S1[i][j]*(T))
plt.subplot(2,1,1),plt.plot(sigma1[i],omega1[j],'bx'),plt.title('S-plane')
plt.xlabel('$\sigma$'),plt.ylabel('$j\Omega$')
plt.subplot(2,1,2),plt.plot(np.real(Z[i][j]),np.imag(Z[i][j]),'rd',markersize=12)
plt.subplot(2,1,2),plt.plot(np.real(Z1[i][j]),np.imag(Z1[i][j]),'kx',markersize=6)
plt.title('Z-plane'),plt.xlabel('$\sigma$'),plt.ylabel('$j\omega})$')
plt.tight_layout()
Fig. 8.14 Python code for many-to-one mapping of impulse invariance technique
Step 1: By using partial fraction expansion, the given analogue transfer function
H(s) can be written as
A B
H ðsÞ = þ
ð s þ 1 Þ ð s þ 4Þ
S-plane
5
0
j:
–5
–0.04 –0.02 0.00 0.02 0.04
s
Z-plane
1
0
jw
–1
–1.00 –0.75 –0.50 –0.25 0.00 0.25 0.50 0.75 1.00
s
1=3 1=6
H ðsÞ = þ
ð s þ 1 Þ ð s þ 4Þ
N
Ai
H ðzÞ =
i=1
1 - esi T z - 1
2
Ai A1 A2
H ðzÞ = = þ
i=1
1 - esi T z - 1 1 - es1 T z - 1 1 - es2 T z - 1
1=3 1=6
H ðzÞ = þ
ð1 - e - 0:05 z - 1 Þ ð1 - e - 0:2 z - 1 Þ
Python code to verify the theoretical result with the simulation result is given in
Fig. 8.16, and its corresponding output is shown in Fig. 8.17. From Fig. 8.16, the
following new tool imported for the simulation, they are (1) sympy, (2) control and
(3) scipy. In addition, the following new python commands are used for this
simulation are (1) symbols—used to define the symbol (z^(-1) and ‘+’),
318 8 Infinite Impulse Response Filter
H(s) =
0.5 s + 1.5
-------------
s^2 + 5 s + 4
H(z) =
[0.333333333333333/(1 - 0.951229424500714*z^-1) '+'
0.166666666666667/(1 - 0.818730753077982*z^-1)]
(2) residue—used to obtain the residues and poles. The result of transfer function in
S domain and Z domain is displayed in Fig. 8.17.
Note: This python code converts the analogue filter into the digital filter,
which has distinct poles.
Inference
From Fig. 8.17, it is possible to observe that the simulation result is on par with the
theoretical result.
8.2 Mapping Techniques in the Design of IIR Filter 319
import control as ss
import numpy as np
import matplotlib.pyplot as plt
from sympy import symbols
from scipy import signal
z=symbols('z^-1')
num,den=[1,2],[1,6,5]
s1 = ss.tf(num, den)
print('H(s) =',s1)
T=1/20
zs,ps,ks=signal.tf2zpk(num,den)
r,p,k=signal.residue(num,den)
theta = np.linspace(0, np.pi*2, 500)
zz=np.zeros(len(theta))
plt.subplot(2,1,1),plt.plot(zz, theta, 'k--'),plt.plot(ps.real,ps.imag, 'bx',ms=10)
plt.plot(zs.real,zs.imag, 'go',ms=10),plt.xlabel('$\sigma$'),
plt.ylabel('$j\Omega$'),plt.title('Pole-zero plot H(s)')
y1=np.append((r[0]/(1-np.exp(p[0]*T)*z)),(r[1]/(1-np.exp(p[1]*T)*z)))
print('H(z) = ',y1)
z=np.exp(p*T)
theta = np.linspace(0, np.pi*2, 500)
circle = np.exp(1j*theta)
plt.subplot(2,1,2),plt.plot(circle.real, circle.imag, 'k--'),
plt.plot(z.real,z.imag, 'rx',ms=10),
plt.xlabel('$\sigma$'),plt.ylabel('$j\omega$'),plt.title('Pole-zero plot H(z)')
Fig. 8.18 Python code to map poles in S-domain to Z-domain using IIT
4
j:
2
0
–5 –4 –3 –2 –1 0
s
Pole-zero plot H(z)
1
0
jw
–1
–1.00 –0.75 –0.50 –0.25 0.00 0.25 0.50 0.75 1.00
s
2 1 - z-1
s= ð8:7Þ
T 1 þ z-1
2 ω
Ω= tan ð8:8Þ
T 2
ΩT
ω = 2 tan - 1 ð8:9Þ
2
From Eqs. (8.8) and (8.9), it is possible to infer that there exists a non-linear
relationship between analogue and digital frequency in bilinear transformation
technique, which is termed as warping.
8.2 Mapping Techniques in the Design of IIR Filter 321
import numpy as np
import matplotlib.pyplot as plt
T=[1,0.5,0.25,0.1]
omega=np.linspace(-15,15,20)
for i in range(len(T)):
domega=2*np.arctan(omega*(T[i]/2))
plt.plot(omega,domega,'-*'),plt.title('BLT Mapping')
plt.xlabel('$\Omega$ rad/sec'),plt.ylabel('$\omega$ rad/sample')
plt.legend(['$T={}$ Sec'.format(T[0]),'$T={}$ Sec'.format(T[1]),'$T={}$
Sec'.format(T[2]),'$T={}$ Sec'.format(T[3])],loc=0)
plt.tight_layout()
Fig. 8.20 Python code to display the relationship between analogue and digital frequency
BLT Mapping
3
T = 1 sec
T = 0.5 sec
2
T = 0.25 sec
T = 0.1 sec
1
w rad/sample
–1
–2
–3
–15 –10 –5 0 5 10 15
: rad/sec
import numpy as np
import matplotlib.pyplot as plt
omega1=np.linspace(-15, 15, 20)
omega2 = np.array([1 in range(len(omega1))])
omega2=omega1
#sigma1=np.linspace(0, 0, 20)# for sigma=0
#sigma1=np.linspace(-15, -0.5, 20)# for sigma < 0
sigma1=np.linspace(0.5, 5, 20)# for sigma > 0
sigma2 = np.array([1 in range(len(sigma1))])
sigma2 = sigma1
S=[[0 for i in range(len(sigma2))] for j in range(len(omega2))]
Z=S
T=0.9
theta = np.linspace(0, np.pi*2, 500)
circle = np.exp(1j*theta)
plt.subplot(2,1,2),plt.plot(circle.real, circle.imag, 'k'),
for j in range(len(sigma2)):
for i in range(len(omega2)):
S[i][j]=complex(sigma1[i],omega1[j])
Z[i][j]=(1+(S[i][j]*(T/2)))/(1-(S[i][j]*(T/2)))
plt.subplot(2,1,1),plt.plot(sigma1[i],omega1[j],'bx')
plt.title('S-plane'), plt.xlabel('$\sigma$'),plt.ylabel('$j\Omega$')
plt.subplot(2,1,2), plt.plot(np.real(Z[i][j]),np.imag(Z[i][j]),'rx')
plt.title('Z-plane'), plt.xlabel('$\sigma$'),plt.ylabel('$j\omega})$')
plt.tight_layout()
S-plane S-plane
10 10
j:
j:
0 0
–10 –10
–0.04 –0.02 0.00 0.02 0.04 –14 –12 –10 –8 –6 –4 –2 0
s s
Z-plane Z-plane
1 1
jw
jw
0 0
–1 –1
–1.00 –0.75 –0.50 –0.25 0.00 0.25 0.50 0.75 1.00 –1.00 –0.75 –0.50 –0.25 0.00 0.25 0.50 0.75 1.00
s s
as=0 bs<0
S-plane
10
j:
0
–10
1 2 3 4 5
s
Z-plane
5
jw
–5
–4 –3 –2 –1 0 1 2
s
cs>0
Fig. 8.23 Simulation result of python code given in Fig. 8.22. (a) σ = 0. (b) σ < 0. (c) σ > 0
Inferences
1. When σ = 0 indicate jΩ in the S-plane. From Fig. 8.23a, it is possible to observe
that the entire jΩ axis is mapped to points on the unit circle in the Z-plane.
2. When σ < 0 represent the left half of S-plane. All the points in the LHS of S-plane
are mapped into within the unit circle of the Z-plane.
3. When σ > 0 are the points in the RHS of the S-plane. These points are mapped
into the outside of the unit circle in the Z-plane.
4. An analogue filter is stable if the poles lie in the left half of S-plane. A digital filter
is stable if the poles lie within the unit circle. The BLT ensures that the stable
analogue filter will be mapped as a stable digital filter.
In matched Z-transform technique, the poles and zeros of the analogue filter are
mapped to Z-plane using the relation z = esT. The matched Z-transform gives the
same pole location as impulse invariant technique but a different zero location.
324 8 Infinite Impulse Response Filter
M
k = 1 ðs - zk Þ
H ðsÞ = N ð8:10Þ
k = 1 ð s - pk Þ
The transfer function of the equivalent digital filter is computed by replacing the
term (s - zk) with ð1 - ezk T z - 1 Þ. The transfer function of the equivalent digital filter
can be written as
M zk T - 1
k = 1 ð1 - e z Þ
H ðzÞ = N ð8:11Þ
k = 1 ð1 - e
p k T z - 1Þ
where T is the sampling period. The transfer function of the analogue filter consid-
ered in this example is given by
ðs þ 3Þ
H ðsÞ =
ð s þ 1 Þ ð s þ 4Þ
From the above equation, the zeros and poles are computed as z1 = -3, and
p1 = -1, p2 = -4, respectively.
Substituting the values of zeros, poles and T = 0.1 in Eq. (8.11), we get
ð1 - e - 0:3 z - 1 Þ
H ðzÞ =
ð1 - e - 0:1 z - 1 Þð1 - e - 0:4 z - 1 Þ
ð1 - 0:7408z - 1 Þ
H ðzÞ =
ð1 - 0:9048z - 1 Þð1 - 0:6703z - 1 Þ
zðz - 0:7408Þ
H ðzÞ =
ðz2 - 1:5751z þ 0:6065Þ
8.2 Mapping Techniques in the Design of IIR Filter 325
import numpy as np
from scipy import signal
import control as ss
T=0.1
z=[-3]
p =[-1, -4] # analog poles
b_s=signal.convolve([1],[1,-z[0]])
a_s=signal.convolve([1,-p[0]],[1,-p[1]])
Hs=ss.tf(b_s,a_s)
print('Transfer function H(s) =',Hs)
b_z=signal.convolve([1,0], [1, -(np.exp(z[0]*T))])
a_z = signal.convolve([1, -(np.exp(p[0]*T))], [1, -(np.exp(p[1]*T))])
Hz=ss.tf(b_z,a_z,T)
print('Transfer function H(z) =',Hz)
dt = 0.1
Python code to verify this experiment is given in Fig. 8.24, and the corresponding
simulation result is shown in Fig. 8.25.
Inferences
1. Figure 8.24 shows that the signal.convole command is used here to compute the
product of two zeros or two poles term.
2. This python code indicates that direct mapping has existed between analogue
filter poles to digital filter poles and analogue filter zeros to digital filter zeros.
3. From Fig. 8.25, it is possible to observe that the transfer function of the digital
filter is on par with the theoretical result.
326 8 Infinite Impulse Response Filter
filter and (2) band reject filter with the lower and upper cut-off frequencies of 3 and
5 rad/s, respectively, using the frequency transformation method.
Step 1: Converting the prototype filter into its equivalent bandpass filter
The prototype filter can be converted into its equivalent band pass filter by using
the frequency transformation s → ssðΩþΩ u Ωl
2
u - Ωl Þ
. In this experiment, the value of Ωu = 5
rad/s and Ωl = 3 rad/s. Hence, the s can be computed as
s2 þ 15 s2 þ 15
s→ =
sð2Þ 2s
s2 þ15
Now replacing s in the normalized lowpass filter transfer function by s → 2s ,
we get
1
H 1 ðsÞ = s2 þ15
2s þ1
2s
H 1 ðsÞ =
s2 þ 2s þ 15
import numpy as np
import matplotlib.pyplot as plt
import control as ss
num,den=[1],[1,1]
num1,den1=[2, 0],[1,2,15]
num2,den2=[1,0,15],[1,2,15]
s = ss.tf(num, den)
print(s)
s1 = ss.tf(num1, den1)
print(s1)
s2 = ss.tf(num2, den2)
print(s2)
omega1=np.linspace(0, 15, 100)
mag, phase, omega1=ss.freqresp(s, omega1)
mag1, phase1, omega1=ss.freqresp(s1, omega1)
mag2, phase2, omega1=ss.freqresp(s2, omega1)
plt.subplot(2,1,1),plt.plot(omega1,mag,'-.',omega1,mag1,'--',omega1,mag2,'-')
plt.title('Magnitude response'),plt.legend(['Prototype','BPF','BRF'],loc=0)
plt.xlabel('$\Omega$ in rad/sec'),plt.ylabel('|$H(j\Omega)$|')
plt.subplot(2,1,2),plt.plot(omega1,phase,'-.',omega1,phase1,'--',omega1,phase2,'-')
plt.title('Phase response'),plt.legend(['Prototype','BPF','BRF'],loc=0)
plt.xlabel('$\Omega$ in rad/sec'),plt.ylabel('∠$H(j\Omega)$)')
plt.tight_layout()
Fig. 8.26 Python code to obtain the magnitude and phase response
The given prototype filter can be converted into a band reject filter using the
frequency transformation s → ssð2ΩþΩ
u - Ωl Þ
u Ωl
. In this problem, the value of Ωu = 5 rad/s
and Ωl = 3 rad/s. Hence, the equivalent s is calculated as
s ð Ωu - Ω l Þ 2s
s→ = 2
s 2 þ Ωu Ωl s þ 15
1
H 2 ðsÞ =
2s
s2 þ15 þ1
s2 þ 15
H 2 ðsÞ =
s2 þ 2s þ 15
The following python code helps us to understand that the prototype filter H(s) is
converted into bandpass filter H1(s) and band reject filter H2(s). The python code is
given in Fig. 8.26, and the corresponding simulation result is shown in Fig. 8.27.
328 8 Infinite Impulse Response Filter
Magnitude response
1.0
Prototype
|H(j:)|
BPF
0.5 BRF
0.0
0 2 4 6 8 10 12 14
: in rad/sec
Phase response
1 Prototype
H(j:) BPF
0 BRF
–1
0 2 4 6 8 10 12 14
: in rad/sec
Fig. 8.27 Simulation result of the python code given in Fig. 8.26. (a) Transfer function. (b)
Frequency response
Inferences
1. The transfer function of prototype normalized lowpass filter, desired bandpass
filter and band reject filter are shown in Fig. 8.27a, which is in agreement with the
theoretical result.
2. From the magnitude response shown in Fig. 8.27b, it is possible to observe that
the filter response is in agreement with the desired result.
3. From the phase response, it is possible to observe that the phase response is
non-linear.
The squared magnitude response of Nth order Butterworth lowpass filter is given by
2 1
H N ejΩ = 2N
ð8:12Þ
Ω
1þ Ωc
where Ωc is cut-off frequency and N denotes the order of the filter. Butterworth filter
exhibits maximally flat response in both passband and stopband. Therefore, these
filters are called maximally flat filters or flat-to-flat filters. The salient features of
lowpass Butterworth filter are:
1. The magnitude response is a monotonically decreasing function of frequency.
2. The maximum gain occurs at Ω = 0.
8.4 Butterworth Filter 329
import numpy as np
import matplotlib.pyplot as plt
omega=np.linspace(0, 5, 100)
omegac=np.array([2])
N=[1,2,3,4,5]
for i in range(len(N)):
H=1/(1+(omega/omegac)**(2*N[i]))
plt.plot(omega,np.abs(H)),plt.title('Squared Magnitude Response')
plt.xlabel('$\Omega$ in rad/sec'),
plt.ylabel('|$H(j\Omega)|^2$')
plt.legend(['N = 1','N =2','N = 3','N = 4','N = 5'])
plt.tight_layout()
Fig. 8.28 Python code for squared magnitude response of Butterworth lowpass filter
3. The first (2N - 1) derivatives of an Nth order lowpass Butterworth filter are zero
at Ω = 0. Hence, Butterworth filters are termed as maximally flat magnitude
filters.
4. The high-frequency roll off of a Nth order Butterworth filter is 20N dB/decade.
0.4
0.2
0.0
0 1 2 3 4 5
: in rad/sec
Ap
10 - 10 - 1
log A
- s
10 10 -1
N= ð8:13Þ
Ωp
2 log Ωs
The symbol d.e denotes ceiling operator. Substituting the values given in the
specifications in the above equation, we get
-3
10 - 10 - 1
log - 30
10 10 - 1
N=
2 log 25
logð0:001Þ -3
N= = = d3:77e = 4
2 × ð- 0:3979Þ - 0:7958
The python code to compute the order of the Butterworth filter is given in
Fig. 8.30.
Inference
After executing the python code is given in Fig. 8.30. The result is Order of the filter
(N) = 4.0. It is in agreement with the theoretical result.
8.4 Butterworth Filter 331
Task
1. Change the value of Ap and As in the python code, given in Fig. 8.30, execute the
program and observe the result of the order of the filter.
Experiment 8.15 Transfer Function of Normalized Butterworth Filter
of Different Orders
The objective of this experiment is to obtain the transfer function of normalized
Butterworth lowpass filter with different orders of the filter. The python code to
obtain the transfer function of Butterworth filter is given in Fig. 8.31. The simulation
result is given in Fig. 8.32.
Inference
1. Using the python code given in Fig. 8.31, Nth order normalized Butterworth
lowpass filter transfer function can be obtained.
2. The simulation result of the python code given in Fig. 8.31 is shown in Fig. 8.32,
and the maximum value of the order N is chosen as 8.
3. From Fig. 8.32, it possible to see that the transfer function of the normalized
Butterworth lowpass filter from first order to eighth order.
Experiment 8.16 Design of Butterworth Filter for a Given Specifications
The aim of this experiment is to design a Butterworth filter using bilinear transfor-
mation technique (BLT) that has a passband gain of 0 to -3 dB cut-off frequency of
2 kHz, and attenuation of at least 20 dB for frequencies greater than 5 kHz. Assume
the sampling frequency to be 20 kHz and sampling period T = 1 s.
332 8 Infinite Impulse Response Filter
H(s) for N =1
1
-----
s+1
H(s) for N =2
1
-----------------
s^2 + 1.414 s + 1
H(s) for N =3
1
---------------------
s^3 + 2 s^2 + 2 s + 1
H(s) for N =4
1
-----------------------------------------
s^4 + 2.613 s^3 + 3.414 s^2 + 2.613 s + 1
H(s) for N =5
1
-----------------------------------------------------
s^5 + 3.236 s^4 + 5.236 s^3 + 5.236 s^2 + 3.236 s + 1
H(s) for N =6
1
-----------------------------------------------------------------
s^6 + 3.864 s^5 + 7.464 s^4 + 9.142 s^3 + 7.464 s^2 + 3.864 s + 1
H(s) for N =7
1
---------------------------------------------------------------------------
s^7 + 4.494 s^6 + 10.1 s^5 + 14.59 s^4 + 14.59 s^3 + 10.1 s^2 + 4.494 s + 1
H(s) for N =8
1
-----------------------------------------------------------------------------------------
s^8 + 5.126 s^7 + 13.14 s^6 + 21.85 s^5 + 25.69 s^4 + 21.85 s^3 + 13.14 s^2 + 5.126 s + 1
Fig. 8.32 Simulation result of the python code given in Fig. 8.31
fp
ωp = 2π
f samp
2
ωp = 2π = 0:2π
20
fs
ωs = 2π
f samp
5
ωs = 2π = 0:5π
20
Step 1: Prewarping
The prewarping process must be done for the bilinear transformation technique to
preserve one-to-one mapping in the frequency transformation from digital to
analogue.
The corresponding analogue frequencies Ωp and Ωs are obtained using
prewarping technique which is given by
2 ωp
Ωp = tan
T 2
0:2π
Ωp = 2 tan = 0:650
2
0:5π
Ωs = 2 tan =2
2
Ap
-
10 10 -1
log A
- s
10 10 -1
N=
Ωp
2 log Ωs
10ð10Þ - 1
3
log
10ð Þ - 1
20
10
N= 0:650
2 log 2
N = d2:0463e ≈ 3
Ωp
Ωc = 1
A
- 10p 2N
10 -1
3 - 16
Ωc = 0:650 1010 - 1
Ωc = 0:650
1
H lp ðsÞ =
BðsÞ
1
H lp ðsÞ =
ð s þ 1 Þ ð s 2 þ s þ 1Þ
Step 5: Converting normalized lowpass filter to the desired lowpass filter using
frequency transformation
1
H ðsÞ =
ð s þ 1Þ ð s 2 þ s þ 1 Þ s = Ωsc
Substituting the value of Ωc = 0.650 (from Step 3), the above expression is given
by
1
H ðsÞ = 2
s
0:650 þ1 s
0:650 þ 0:650
s
þ1
0:2751
H ðsÞ =
s3 þ 1:301s2 þ 0:8459s þ 0:2751
H ðzÞ = H ðsÞjs = 2 z - 1
T zþ1
0:2751
H ðzÞ =
s3 þ 1:301s2 þ 0:8459s þ 0:2751 -1
s = T2 zzþ1
0:2751
H ðzÞ = 3 2
-1 -1 -1
2 zzþ1 þ 1:301 2 zzþ1 þ 0:8459 2 zzþ1 þ 0:2751
import numpy as np
#import matplotlib.pyplot as plt
from scipy import signal
import control as ss
# Specifications of Filter
fsam=20000 # Sampling frequency
fp=2000 # Pass band frequency
fs=5000 # Stop abnd frequency
Ap, As, Td=3,20, 1
wp=2*np.pi*(fp/fsam) # pass band freq in radian per sample
ws=2*np.pi*(fs/fsam) # Stop band freq in radian per sample
# prewarping process
omega_p=(2/Td)*np.tan(wp/2)
omega_s=(2/Td)*np.tan(ws/2)
#Computation of order and normalized cut-off frequency
N, omega_c=signal.buttord(omega_p,omega_s,Ap,As,analog=True)
print('Order of the Filter N =', N)
print('Cut-off frequency= {:.4f} rad/s '. format(omega_c))
# Computation of H(s)
b, a=signal.butter(N,omega_c,'low', analog=True)
s1 = ss.tf(b, a)
print('Transfer function H(s)=',s1)
bz, az=signal.bilinear(b, a, Td)
z1 = ss.tf(bz,az,Td)
print('Transfer function H(z)=',z1)
Inference
1. The theoretical result is verified with the python code, which is shown in
Fig. 8.33. The built-in function signal.buttord helps to obtain the order and
cut-off frequency of the analogue filter.
2. The numerator and denominator coefficients of the analogue filter are computed
using signal.butter built-in function.
3. The analogue filter coefficients are converted into digital filter coefficients using
bilinear transformation, the built-in function used for bilinear transformation is
signal.bilinear.
4. After executing the python code, which is given in Fig. 8.33, the simulation result
is shown in Fig. 8.34. From this figure, it is possible to observe that the simulation
result is on par with the theoretical result.
Task
1. Reduce the gap between passband and stopband cut-off frequencies and observe
the order of the filter.
8.4 Butterworth Filter 337
Fig. 8.34 Simulation result of the python code is given in Fig. 8.33
import numpy as np
import matplotlib.pyplot as plt
from scipy import signal
import control as ss
# Specifications of Filter
fsam=8000 # Sampling frequency in Hz
fc=2000 # cut off frequency in Hz
N, T = 2, 1/fsam
wc1=2*np.pi*fc # Cut off frequency in rad/sec
print('Cut-off frequency (in rad/sec)=', wc1)
wc = (2/T)*np.tan(wc1*T/2) # Prewarp the analog frequency
# Design analog Butterworth filter using signal.butter function
b, a = signal.butter(N, wc, 'low', analog='True')
s1 = ss.tf(b,a)
print('Transfer function H(s)=',s1)
# Perform bilinear Transformation
bz, az = signal.bilinear(b, a, fs=fsam)
# Print numerator and denomerator coefficients of the filter
print('Numerator Coefficients:', bz),print('Denominator Coefficients:', az)
z1 = ss.tf(bz,az,T)
print('Transfer function H(z)=',z1)
# Compute frequency response of the filter using signal.freqz function
wz, hz = signal.freqz(bz, az, 512)
fig = plt.figure(figsize=(10, 8))
Mag = 20*np.log10(abs(hz)) # Calculate Magnitude in dB
Freq = wz*fsam/(2*np.pi) # Calculate frequency in Hz
# Plot Magnitude response
sub1 = plt.subplot(2, 1, 1),sub1.plot(Freq, Mag, 'r', linewidth=2),sub1.axis([1, fsam/2, -60, 5])
sub1.set_title('Magnitude Response', fontsize=15),
sub1.set_xlabel('Frequency [Hz]', fontsize=15),sub1.set_ylabel('Magnitude [dB]', fontsize=15)
sub1.grid()
# Plot phase angle
sub2 = plt.subplot(2, 1, 2)
Phase = np.unwrap(np.angle(hz))*180/np.pi # Calculate phase angle in degree from hz
sub2.plot(Freq, Phase, 'g', linewidth=2),sub2.set_ylabel('Phase (degree)', fontsize=15)
sub2.set_xlabel(r'Frequency (Hz)', fontsize=15),sub2.set_title(r'Phase response', fontsize=15)
sub2.grid(),plt.subplots_adjust(hspace=0.5),fig.tight_layout(),plt.show()
From Fig. 8.39, it is possible to observe that the transfer function of normalized
Butterworth lowpass filter is on par with the theoretical transfer function, which is
given by
1
H ðsÞ =
s2 þ 1:414s þ 1
Here, we have considered the order of the filter is (N = 2), the cut-off frequency of
lowpass and highpass filter is chosen as 2. The highest degree of the denominator
polynomial function of lowpass and highpass filters is 2, whereas the highest degree
of the denominator polynomial function of bandpass and band reject filters is 4. The
8.4 Butterworth Filter 339
import numpy as np
import matplotlib.pyplot as plt
from scipy import signal
import control as ss
N, omega_c, wn = 2, 2, [3,5] # Order, cutoff freq. of (LPF and HPF),(BPF and BSF),
omega1=np.linspace(0, 10, 100)
b, a = signal.butter(N, 1, 'low', analog=True)
b1, a1 = signal.butter(N, omega_c, 'low', analog=True)
b2, a2 = signal.butter(N, omega_c, 'high', analog=True)
b3, a3 = signal.butter(N, wn, 'bandpass', analog=True)
b4, a4 = signal.butter(N, wn, 'bandstop', analog=True)
s1 = ss.tf(b, a)
print('Normalized Butterworth filter H(s)=', s1)
mag, phase, omega1=ss.freqresp(s1, omega1)
plt.figure(1),plt.plot(omega1,np.abs(mag)),plt.xlabel('$\Omega$-->'),
plt.ylabel('$|H(j\Omega)|$'),plt.title('Magnitude response of Normalized LPF')
s2 = ss.tf(b1, a1)
print('Desired Butterworth LPF H1(s)=', s2)
mag1, phase1, omega1=ss.freqresp(s2, omega1)
plt.figure(2),plt.subplot(2,2,1),plt.plot(omega1,np.abs(mag1))
plt.xlabel('$\Omega$-->'),plt.ylabel('$|H_1(j\Omega)|$'),plt.title('Desired LPF')
s3 = ss.tf(b2, a2)
print('Desired Butterworth HPF H2(s)=', s3)
mag2, phase2, omega1=ss.freqresp(s3, omega1)
plt.subplot(2,2,2),plt.plot(omega1,np.abs(mag2)),plt.xlabel('$\Omega$-->'),
plt.ylabel('$|H_2(j\Omega)|$'),plt.title('Desired HPF')
s4 = ss.tf(b3, a3)
print('Desired Butterworth BPF H3(s)=', s4)
mag3, phase3, omega1=ss.freqresp(s4, omega1)
plt.subplot(2,2,3),plt.plot(omega1,np.abs(mag3)),plt.xlabel('$\Omega$-->'),
plt.ylabel('$|H_3(j\Omega)|$'),plt.title('Desired BPF')
s5 = ss.tf(b4, a4)
print('Desired Butterworth BSF H4(s)=', s5)
mag4, phase4, omega1=ss.freqresp(s5, omega1)
plt.subplot(2,2,4),plt.plot(omega1,np.abs(mag4)),plt.xlabel('$\Omega$-->'),
plt.ylabel('$|H_4(j\Omega)|$'),plt.title('Desired BSF')
plt.tight layout()
Fig. 8.38 Python code to convert normalized Butterworth filter to desired filters
bandpass and band reject filter contains rising and falling transition widths, each
transition width takes second-order roll-off rate; hence, the order of the filter is 4.
Inferences
1. The magnitude responses of the normalized lowpass and desired lowpass,
highpass, bandpass and bandstop filters are shown in Fig. 8.40.
2. From Fig. 8.40a, it is clearly understood that the cut-off frequency is 2 Hz.
3. From Fig. 8.40b, the cut-off frequency of lowpass and highpass filters is 2 Hz,
while bandpass and band reject filters are 3 and 5 Hz.
8.4 Butterworth Filter 341
|H2(j:)|
0.5 0.5
0.8
0.0 0.0
0.6 0.0 2.5 5.0 7.5 10.0 0.0 2.5 5.0 7.5 10.0
|H(j:)|
:--> :-->
0.4 Desired BPF Desired BSF
1.0 1.0
|H3(j:)|
|H4(j:)|
0.2
0.5 0.5
Fig. 8.40 Magnitude responses of normalized and desired Butterworth filters. (a) Normalized
lowpass filter. (b) Desired filters
4. The conclusion that can be made from this experiment is that the desired filter can
be obtained from the normalized lowpass filter using analogue frequency
transformation.
342 8 Infinite Impulse Response Filter
import numpy as np
import matplotlib.pyplot as plt
from scipy import signal
import control as ss
# Specifications of Filter
fsam=8000 # Sampling frequency in Hz
fc1,fc2=[1500,2500],[1000,3000] # cut off frequency in Hz
T = 1/fsam
wcp1=2*np.pi*fc1[0] # Pass band Cut off frequency in rad/sec
wcp2=2*np.pi*fc1[1] # Pass band Cut off frequency in rad/sec
wcs1=2*np.pi*fc2[0] # Stop band Cut off frequency in rad/sec
wcs2=2*np.pi*fc2[1] # Stop band Cut off frequency in rad/sec
pwcp1 = (2/T)*np.tan(wcp1*T/2) # Prewarp the analog frequency
pwcp2 = (2/T)*np.tan(wcp2*T/2) # Prewarp the analog frequency
pwcs1 = (2/T)*np.tan(wcs1*T/2) # Prewarp the analog frequency
pwcs2 = (2/T)*np.tan(wcs2*T/2) # Prewarp the analog frequency
N,wn=signal.buttord([pwcp1,pwcp2],[pwcs1,pwcs2],1,30,True)
print('Order of the filter (N) = ',N)
# Design analog Butterworth filter using signal.butter function
b, a = signal.butter(N, wn, 'bandpass', analog='True')
s1 = ss.tf(b,a)
print('Transfer function H(s)=',s1)
# Perform bilinear Transformation
bz, az = signal.bilinear(b, a, fs=fsam)
z1 = ss.tf(bz,az,T)
print('Transfer function H(z)=',z1)
# Compute frequency response of the filter using signal.freqz function
wz, hz = signal.freqz(bz, az, 512)
fig = plt.figure(figsize=(10, 8))
Mag = 10*np.log10(abs(hz)) # Calculate Magnitude in dB
Freq = wz*fsam/(2*np.pi) # Calculate frequency in Hz
# Plot Magnitude response
sub1 = plt.subplot(2, 1, 1)
sub1.plot(Freq, Mag, 'r', linewidth=2),sub1.axis([1, fsam/2, -60, 5])
sub1.set_title('Magnitude Response', fontsize=15),
sub1.set_xlabel('Frequency [Hz]', fontsize=15),sub1.set_ylabel('Magnitude [dB]', fontsize=15)
sub1.grid()
# Plot phase angle
sub2 = plt.subplot(2, 1, 2)
Phase = np.unwrap(np.angle(hz))*180/np.pi # Calculate phase angle in degree from hz
sub2.plot(Freq, Phase, 'g', linewidth=2),sub2.set_ylabel('Phase (degree)', fontsize=15)
sub2.set_xlabel(r'Frequency (Hz)', fontsize=15),sub2.set_title(r'Phase response', fontsize=15)
sub2.grid(),plt.subplots_adjust(hspace=0.5),fig.tight_layout(),plt.show()
The python code for this experiment is given in Fig. 8.41, and its corresponding
output is shown in Figs. 8.42 and 8.43. Figure 8.43 gives the magnitude and phase
response of the Butterworth digital bandpass filter. The libraries used in this program
are (1) numpy, (2) matplotlib, (3) scipy and (4) control. The built-in functions used in
this program are summarized in Table 8.2.
Inference
From the magnitude response shown in Fig. 8.43, it is possible to observe that the
passband of the digital filter is 1500–2500 Hz. This is in agreement with the
specification of the filter. The phase response of the filter is non-linear.
Task
1. Change the passband cut-off frequencies of the bandpass filter and see the
changes in the magnitude and phase responses.
2 1
H ejΩ = ð8:14Þ
1þ ε2 T 2N ðΩÞ
The parameter ε sets the ripple amplitude. Chebyshev filters can be classified into
two types, namely, Type I Chebyshev filters and Type II Chebyshev filters. Type I
Chebyshev filter exhibits ripple in passband, whereas Type II Chebyshev filter
exhibits ripple in stopband. Chebyshev polynomial TN(x) for different order is
given in Table 8.3.
Experiment 8.20 Plotting Chebyshev Polynomial for Different Order
This experiment tries to plot the Chebyshev polynomial functions of different order
using python. The python code is used here to plot the Chebyshev polynomial
functions of different order and the corresponding output is shown in Figs. 8.44
8.5 Chebyshev Filter 345
import numpy as np
import matplotlib.pyplot as plt
x=np.linspace(-1,1,50)
T0=np.ones(len(x)) # zeroth degree polynomial
T1=x # First degree polynomial
T2=2*x*T1-T0 # Second degree polynomial
T3=2*x*T2-T1 # Third degree polynomial
T4=2*x*T3-T2 # Fourth degree polynomial
T5=2*x*T4-T3 # Fifth degree polynomial
plt.subplot(3,2,1),plt.plot(x,T0,'k--',linewidth=3.5), plt.xlabel('x'), plt.ylabel('T_0(x)'),
plt.grid(),plt.subplot(3,2,2),plt.plot(x,T1,'k--',linewidth=3.5), plt.xlabel('x'),
plt.ylabel('T_1(x)'),plt.grid(),plt.subplot(3,2,3),plt.plot(x,T2,'k--',linewidth=3.5), plt.xlabel('x'),
plt.ylabel('T_2(x)'),plt.grid(),plt.subplot(3,2,4),plt.plot(x,T3,'k--',linewidth=3.5),
plt.xlabel('x'),plt.ylabel('T_3(x)'),plt.grid(), plt.subplot(3,2,5),plt.plot(x,T4,'k--',linewidth=3.5),
plt.xlabel('x'),plt.ylabel('T_4(x)'),plt.grid(),plt.subplot(3,2,6),plt.plot(x,T5,'k--',linewidth=3.5),
plt.xlabel('x'),plt.ylabel('T_5(x)'),plt.grid(),plt.tight_layout()
and 8.45, respectively. From Fig. 8.45, it is possible to infer that the Chebyshev
polynomial function is created based on the recursive formula, which is given by
Inference
Figure 8.45 shows that whenever N = 1, 3, 5, etc., the graph passes through the
origin. For N = 0, 2, 4, etc., the graph does not pass through the origin.
Task
1. Write a python code to plot the Chebyshev polynomial function of order 8. Men-
tion the number of zero crossings that exist in it.
346 8 Infinite Impulse Response Filter
1.05 1
T_0(x)
T_1(x)
1.00 0
0.95 –1
–1.0 –0.5 0.0 0.5 1.0 –1.0 –0.5 0.0 0.5 1.0
x x
1 1
T_2(x)
T_3(x)
0 0
–1 –1
–1.0 –0.5 0.0 0.5 1.0 –1.0 –0.5 0.0 0.5 1.0
x x
1 1
T_4(x)
0 T_5(x) 0
–1 –1
–1.0 –0.5 0.0 0.5 1.0 –1.0 –0.5 0.0 0.5 1.0
x x
fp
ωp = 2π
f samp
3
ωp = 2π = 0:4π
15
fs
ωs = 2π
f samp
5
ωs = 2π = 0:667π
15
2 ωp
Ωp = tan
T 2
2 0:4π
Ωp = tan = 1:4531
1 2
2 0:667π
Ωs = tan = 3:4633
1 2
10ð 10 Þ - 1
Ap
ε=
ε = 10ð10Þ - 1 = 10ð0:2Þ - 1
2
p p
ε = 1:5849 - 1 = 0:5849 = 0:7648
cosh - 1 10 - 10 - 1
As
1
ε2
N≥
Ωs
cosh - 1 Ωp
- 20
cosh - 1 1
ð0:7648Þ2
10 - 10 -1
N≥
cosh - 1 3:4633
1:4531
cosh - 1 1
ð0:7648Þ2
102 - 1
N≥
cosh - 1 ð2:3834Þ
cosh - 1 1
ð0:7648Þ2
ð100 - 1Þ
N≥
1:5144
cosh - 1 99
0:5849
N≥
1:5144
3:2574
N≥ = 2:1510 = 3
1:5144
From the above result, the order of the filter is computed as three (N = 3).
Step 4: Computation of the left half of the S plane poles
From the order of filter 3, 6 poles will be there in this filter. Only 3 poles will be
calculated for further process. That is, those poles must be lying left half of S-plane.
8.5 Chebyshev Filter 349
ð2k - 1Þπ 1 1
sk = σ k þ jΩk = - sin sinh sinh - 1
2N N ε
ð8:16Þ
ð2k - 1Þπ 1 1
þj cos cosh sinh - 1
2N N ε
ð2:1 - 1Þπ 1 1
s1 = σ 1 þ jΩ1 = - sin sinh sinh - 1
2×3 3 0:7648
ð2:1 - 1Þπ 1 1
þj cos cosh sinh - 1
2×3 3 0:7648
π π
s1 = - sin sinhð0:3610Þ þ j cos coshð0:3610Þ
2×3 2×3
π π
s1 = - sin ð0:3689Þ þ j cos ð1:0659Þ
6 6
s1 = - ð0:5Þð0:3689Þ þ jð0:8660Þð1:0659Þ
s1 = - 0:1845 þ j0:9231
ð2:2 - 1Þπ 1 1
s2 = σ 2 þ jΩ2 = - sin sinh sinh - 1
2×3 3 0:7648
ð2:2 - 1Þπ 1 1
þj cos cosh sinh - 1
2×3 3 0:7648
ð4 - 1Þπ 1 ð4 - 1Þπ 1
s2 = - sin sinh ð1:0831Þ þ j cos cosh ð1:0831Þ
2×3 3 2×3 3
3π 3π
s2 = - sin sinhð0:3610Þ þ j cos coshð0:3610Þ
6 6
π π
s2 = - sin ð0:3689Þ þ j cos ð1:0659Þ
2 2
π π
We know that sin 2 = 1 and cos 2 = 0, substituting this results in the above
equation, we get
s2 = - 0:3689
ð2:3 - 1Þπ 1 1
s3 = σ 3 þ jΩ3 = - sin sinh sinh - 1
2×3 3 0:7648
ð2:3 - 1Þπ 1 1
þj cos cosh sinh - 1
2×3 3 0:7648
ð6 - 1Þπ 1 ð6 - 1Þπ 1
s3 = - sin sinh ð1:0831Þ þ j cos cosh ð1:0831Þ
2×3 3 2×3 3
5π 5π
s3 = - sin sinhð0:3610Þ þ j cos coshð0:3610Þ
6 6
5π 5π
s3 = - sin ð0:3689Þ þ j cos ð1:0659Þ
6 6
s3 = - 0:1845 - j0:9231
ð- 1ÞN s1 × s2 × ⋯ × sN
H ð sÞ = K
ðs - s1 Þðs - s2 Þ⋯ðs - sN Þ
where
1
p for N is Even
K= 1 þ ε2
1 for N is odd
In this example, the order of the filter is 3; it shows that odd, hence the gain K = 1.
The transfer function is formed as
ð- 1Þ3 × s1 × s2 × s3
H ðsÞ = K
ðs - s1 Þðs - s2 Þðs - s3 Þ
0:3269
H ðsÞ =
ðs þ 0:1845 - j0:9231ÞÞðs þ 0:3689ÞÞðs þ 0:1845 þ j0:9231ÞÞ
0:3269
H ðsÞ =
ðs3 þ 0:7378s2 þ 1:0222s þ 0:3269Þ
s 0:3269
Ha =
1:4531 s 3
þ 0:7378 s 2
þ 1:0222 s
þ 0:3269
1:4531 1:4531 1:4531
s 1:003
Ha = 3
1:4531 ðs þ 1:072s2 þ 2:158s þ 1:003Þ
H ðzÞ = H a ðsÞjs = 2 1 - z - 1
T 1þz - 1
1:003
H ðzÞ =
ðs3 þ 1:072s2 þ 2:158s þ 1:003Þ -1
s = 21 - z- 1
1þz
1:003
H ðzÞ = 3 2
-z -1 -z -1 -z -1
2 11þz -1 þ 1:072 2 11þz -1 þ 2:158 2 11þz -1 þ 1:003
The python code for this experiment is given in Fig. 8.45. The built-in function
signal.cheb1ord is used here to compute the order and cut-off frequency of the filter.
The built-in function signal.cheby1 is used here to obtain the numerator and denom-
inator coefficients of filter, ss.tf is used for the computation of transfer function and
signal.bilinear helps to convert analogue filter coefficients into digital filter coeffi-
cients using BLT approach.
Inferences
1. After executing the python code given in Fig. 8.46, the simulation results are
shown in Figs. 8.47 and 8.48.
2. The order of the filter is calculated as (N = 3); the cut-off frequency is obtained as
1.4531 rad/s, which is equivalent to passband cut-off frequency, and the analogue
8.5 Chebyshev Filter 353
import numpy as np
import matplotlib.pyplot as plt
from scipy import signal
import control as ss
# Specifications of Filter
fsam=15000 # Sampling frequency
fp=3000 # Passband frequency
fs=5000 # Stopband frequency
Ap, As, Td=2,20, 1
wp=2*np.pi*(fp/fsam) # passband freq in radian per sample
ws=2*np.pi*(fs/fsam) # Stopband freq in radian per sample
# prewarping process
omega_p=(2/Td)*np.tan(wp/2)
omega_s=(2/Td)*np.tan(ws/2)
N, omega_c=signal.cheb1ord(omega_p,omega_s,Ap,As,analog=True)
print('Order of the Filter N =', N)
print('Cut-off frequency= {:.4f} rad/s'. format(omega_c))
# Computation of H(s)
b_s, a_s=signal.cheby1(N,Ap,omega_c,'low', analog=True)
s1 = ss.tf(b_s, a_s)
print('Transfer function H(s)=',s1)
bz, az=signal.bilinear(b_s, a_s, Td)
z1 = ss.tf(bz,az,Td)
print('Transfer function H(z)=',z1)
ws, hs = signal.freqz(bz, az) # Calculate Magnitude from hz in dB
Mag = 20*np.log10(abs(hs)) # Calculate phase angle in degree from hz
Phase = np.unwrap(np.arctan2(np.imag(hs), np.real(hs)))*(180/np.pi)
# Calculate frequency in Hz from wz
Freq = ws*fsam/(2*np.pi)
# Plot filter magnitude and phase responses using subplot.
fig = plt.figure(figsize=(10, 6))# Plot Magnitude response
sub1 = plt.subplot(2, 1, 1)
sub1.plot(Freq, Mag, 'r', linewidth=2)
sub1.axis([1, fsam/2, -100, 5])
sub1.set_title('Magnitude Response', fontsize=15)
sub1.set_xlabel('Frequency [Hz]', fontsize=15)
sub1.set_ylabel('Magnitude [dB]', fontsize=15)
sub1.grid()
# Plot phase angle
sub2 = plt.subplot(2, 1, 2)
sub2.plot(Freq, Phase, 'g', linewidth=2),sub2.set_ylabel('Phase (degree)', fontsize=15)
sub2.set_xlabel(r'Frequency (Hz)', fontsize=15)
sub2.set_title(r'Phase response', fontsize=15)
sub2.grid(),plt.subplots_adjust(hspace=0.5),fig.tight_layout(),plt.show()
Fig. 8.46 Python code to get transfer function of Chebyshev lowpass filter
354 8 Infinite Impulse Response Filter
and digital filters transfer functions are the same as the theoretical result, which is
shown in Fig. 8.47.
3. The frequency response of the Chebyshev Type I filter is shown in Fig. 8.48. This
figure clearly shows that the passband frequency is up to 3 kHz.
import numpy as np
import matplotlib.pyplot as plt
from scipy import signal
import control as ss
# Specifications of Filter
fsam=8000 # Sampling frequency in Hz
fc1=1500 # Stop band cut-off frequency in Hz
fc2=2500# Pass band cut-off frequency in Hz
Ap,As,T =3,40, 1/fsam
wc1=2*np.pi*fc1 # Stopband Cut off frequency in rad/sec
wc2=2*np.pi*fc2 # Passband Cut off frequency in rad/sec
#print('Cut-off frequency (in rad/sec)=', wc1)
pwc1 = (2/T)*np.tan(wc1*T/2) # Prewarp the analog frequency
pwc2 = (2/T)*np.tan(wc2*T/2) # Prewarp the analog frequency
# Design analog Butterworth filter using signal.butter function
N, Wn = signal.cheb1ord(pwc2, pwc1, Ap, As,analog=True)
print('Order of the filter (N) = ',N)
b, a = signal.cheby1(N, Ap, Wn, 'high',analog=True)
s1 = ss.tf(b,a)
print('Transfer function H(s)=',s1)
# Perform bilinear transformation
bz, az = signal.bilinear(b, a, fs=fsam)
# Print numerator and denominator coefficients of the filter
print('Numerator Coefficients:', bz)
print('Denominator Coefficients:', az)
z1 = ss.tf(bz,az,T)
print('Transfer function H(z)=',z1)
# Compute frequency response of the filter using signal.freqz function
wz, hz = signal.freqz(bz, az, 512)
fig = plt.figure(figsize=(10, 8))
Mag = 20*np.log10(abs(hz)) # Calculate Magnitude in dB
Freq = wz*fsam/(2*np.pi) # Calculate frequency in Hz
# Plot Magnitude response
sub1 = plt.subplot(2, 1, 1)
sub1.plot(Freq, Mag, 'r', linewidth=2),sub1.axis([1, fsam/2, -60, 5])
sub1.set_title('Magnitude Response', fontsize=15),sub1.set_xlabel('Frequency [Hz]', fontsize=15)
sub1.set_ylabel('Magnitude [dB]', fontsize=15),sub1.grid()
# Plot phase angle
sub2 = plt.subplot(2, 1, 2)
# Calculate phase angle in degree from hz
Phase = np.unwrap(np.angle(hz))*180/np.pi
sub2.plot(Freq, Phase, 'g', linewidth=2),sub2.set_ylabel('Phase (degree)', fontsize=15)
sub2.set_xlabel(r'Frequency (Hz)', fontsize=15),sub2.set_title(r'Phase response', fontsize=15)
sub2.grid(),plt.subplots_adjust(hspace=0.5),fig.tight_layout(),plt.show()
3 dB and stop attenuation is 40 dB. Use BLT method for transformation. The python
code for this experiment is given in Fig. 8.49, and its corresponding output is shown
in Figs. 8.50 and 8.51. Figure 8.50 gives the magnitude and phase responses of the
Chebyshev Type I digital highpass filter.
Inference
From this experiment, the following inferences can be made:
356 8 Infinite Impulse Response Filter
Magnitude Response
0
Magnitude [dB]
–10
–20
–30
–40
–50
–60
500 1000 1500 2000 2500 3000 3500 4000
Frequency [Hz]
Phase response
0
–50
Phase (degree)
–100
–150
–200
–250
–300
–350
0 500 1000 1500 2000 2500 3000 3500 4000
Frequency [Hz]
1. From the magnitude response, it is possible to observe that passband gain is high
after the frequency of 2000 Hz, and there is a ripple in the passband.
2. From the phase response, it is possible to confirm that the curve is not linear;
hence, it cannot provide the linear phase in the output.
8.5 Chebyshev Filter 357
Tasks
1. Write a python code to obtain the magnitude and phase response of Chebyshev
Type I bandpass filter with the passband frequencies of 1500–3000 Hz. Choose
the order of the filter that is 3.
2. Write a python code to obtain the magnitude and phase response of Chebyshev
Type I band reject filter with the stopband frequencies of 1500–3000 Hz. Choose
the order of the filter that is 3.
1.05
|H(j:)|
1.00
0.95
–3 –2 –1 0 1 2 3
:-->
|H1(j:)|
0
–3 –2 –1 0 1 2 3
:-->
1-|H1(j:)|
0
–3 –2 –1 0 1 2 3
:-->
1.0
0.8
1-|H1(j1/:)|
0.6
0.4
0.2
0.0
–3 –2 –1 0 1 2 3
:-->
import numpy as np
import matplotlib.pyplot as plt
from scipy import signal
import control as ss
N, rs, omega_c=3, 30, [5]
omega1=np.linspace(0, 10, 100)
b_s, a_s=signal.cheby2(N,rs,omega_c,'low', analog=True)
s1 = ss.tf(b_s, a_s)
print('H(s) = ', s1)
z1=np.roots(b_s)
print('Zeros : ', z1)
mag, phase, omega1=ss.freqresp(s1, omega1)
plt.figure,plt.plot(omega1,np.abs(mag))
plt.xlabel('$\Omega$-->'),plt.ylabel('$|H(j\Omega)|$')
plt.title('Magnitude response of Chebyshev Type II LPF')
plt.tight_layout()
The Chebyshev Type II IIR filter has an equiripple in stopband and monotonic
response in passband, which is inverse of Chebyshev Type I IIR filter; hence, it is
also called as ‘inverse Chebyshev filter’. Two-step procedures can obtain the
frequency response of this filter. In the first step, subtract the frequency response
of Chebyshev Type I filter (H(ω)) from 1, which is illustrated in Fig. 8.52. In the
second step, convert the ω by ω1 . This result will give the frequency response of
Chebyshev Type II IIR filter, which is shown in Fig. 8.53.
From Fig. 8.53, it is possible to observe that the frequency response has mono-
tonic in the passband and an equiripple in the stop band.
Using the two step procedures, the mathematical expression for the frequency
response of the Chebyshev Type II filter can be written as
1
H ðΩÞ = 1 - ð8:17Þ
1 þ ε2 T 2N ð1=ΩÞ
=Þ
1Ω
H ðΩÞ = ε2 T 2N ð8:18Þ
1þ ε2 T 2N ð1=ΩÞ
From the above expression, it is possible to understand that the Chebyshev Type
II filter has zeros as the numerator, and all the zeros lie on the imaginary axis.
8.6 Chebyshev Type II IIR Filter 359
0.8
H(s) = 0.6
|H(j:)|
0.4746 s^2 + 15.82
0.4
---------------------------------
s^3 + 4.883 s^2 + 11.81 s + 15.82 0.2
0.0
Zeros : [-0.+5.77350269j 0.-5.77350269j] 0 2 4 6 8 10
:-->
Fig. 8.55 Simulation result of the python code is given in Fig. 8.54. (a) Transfer function and
zeros. (b) Magnitude response
import numpy as np
import matplotlib.pyplot as plt
from scipy import signal
import control as ss
# Specifications of Filter
fsam=8000 # Sampling frequency in Hz
fc1,fc2=[1500,2500],[1000,3000] # cut off frequency in Hz
Ap, As, T = 2, 40, 1/fsam
wcp1=2*np.pi*fc1[0] # Pass band Cut off frequency in rad/sec
wcp2=2*np.pi*fc1[1] # Pass band Cut off frequency in rad/sec
wcs1=2*np.pi*fc2[0] # Stop band Cut off frequency in rad/sec
wcs2=2*np.pi*fc2[1] # Stop band Cut off frequency in rad/sec
pwcs1 = (2/T)*np.tan(wcp1*T/2) # Prewarp the analog frequency
pwcs2 = (2/T)*np.tan(wcp2*T/2) # Prewarp the analog frequency
pwcp1 = (2/T)*np.tan(wcs1*T/2) # Prewarp the analog frequency
pwcp2 = (2/T)*np.tan(wcs2*T/2) # Prewarp the analog frequency
N,wn=signal.cheb2ord([pwcp1,pwcp2],[pwcs1,pwcs2],Ap,As,analog=True)
print('Order of the filter (N) = ',N)
# Design analog Chebyshev Type 2 filter using signal.cheby2 function
b, a = signal.cheby2(N, As, wn, 'bandstop', analog='True')
s1 = ss.tf(b,a)
print('Transfer function H(s)=',s1)
# Perform bilinear transformation
bz, az = signal.bilinear(b, a, fs=fsam)
z1 = ss.tf(bz,az,T)
print('Transfer function H(z)=',z1)
# Compute frequency response of the filter using signal.freqz function
wz, hz = signal.freqz(bz, az, 512)
fig = plt.figure(figsize=(10, 8))
Mag = 10*np.log10(abs(hz)) # Calculate Magnitude in dB
Freq = wz*fsam/(2*np.pi) # Calculate frequency in Hz
# Plot Magnitude response
sub1 = plt.subplot(2, 1, 1)
sub1.plot(Freq, Mag, 'r', linewidth=2),sub1.axis([1, fsam/2, -60, 5])
sub1.set_title('Magnitude Response', fontsize=15),
sub1.set_xlabel('Frequency [Hz]', fontsize=15),sub1.set_ylabel('Magnitude [dB]', fontsize=15)
sub1.grid()
# Plot phase angle
sub2 = plt.subplot(2, 1, 2)
Phase = np.unwrap(np.angle(hz))*180/np.pi # Calculate phase angle in degree from hz
sub2.plot(Freq, Phase, 'g', linewidth=2),sub2.set_ylabel('Phase (degree)', fontsize=15)
sub2.set_xlabel(r'Frequency (Hz)', fontsize=15),sub2.set_title(r'Phase response', fontsize=15)
sub2.grid(),plt.subplots_adjust(hspace=0.5),fig.tight_layout(),plt.show()
Fig. 8.56 Python code for Chebyshev Type II bandstop filter design
Inferences
1. From Fig. 8.58, the magnitude response shows no ripple in the passbands and a
ripple in the stop band.
2. From the phase response, it is possible to confirm that IIR filters do not have
linear phase characteristics; hence, the phase response is not linear.
8.6 Chebyshev Type II IIR Filter 361
Task
1. Write a python code to design a Chebyshev Type II digital bandpass filter for the
following specifications: (a) Passband frequencies are from 1500 to 2500 Hz with
an attenuation of 3 dB. (b) Stopband frequencies are below 1000 Hz and above
3000 Hz with the passband ripple of 40 dB. Sampling frequency (Fs) = 8 kHz.
Use BLT method for transformation.
The elliptic filter has an equiripple in both the passband and stopband. It is also
called as ‘Cauer filter’. The elliptic filter gives minimal error between the desired and
ideal filter response for a given set of error tolerances. The elliptical filter maximizes
the rate of transition between the frequency response passband and stopband, at the
expense of equiripple in both bands. Also, it increases ringing in the step response.
The square magnitude response of ‘nth’ order elliptic filter is given by
1
jH ðjΩÞj2 = ð8:19Þ
1þ ε2 R2n ξ, Ω=Ωc
In the above expression, Rn is the nth order elliptic rational function, ‘ε’ is the
ripple factor and ‘ξ’ is the selectivity factor. The ripple factor specifies the passband
ripple, and a combination of the ripple factor and the selectivity factor specifies the
stopband ripple. As the ripple in the stopband approaches zero, the filter tends to
become Chebyshev Type I filter. As the ripple in the passband approaches zero, the
filter tends to become Chebyshev Type II filter. If both passband and stopband
ripples approach zero, then the filter tends to become a Butterworth filter. Elliptic
filter meets a standard magnitude specification with lower filter order than other filter
approximations.
Experiment 8.25 Design of an Elliptic Lowpass Filter
This experiment tries to design an elliptic lowpass filter with a passband frequency of
5 Hz. Assume the order of the filter is 3, passband ripple is 2 dB and stopband
attenuation is 30 dB. The python code to design an elliptic lowpass filter is shown in
Fig. 8.59, and its corresponding simulation result is shown in Fig. 8.60. From
Fig. 8.59, it is possible to infer that the signal.ellip built-in command is used here
to obtain the numerator and denominator coefficients. After executing the python
code given in Fig. 8.59, the transfer function of elliptic lowpass filter is shown in
Fig. 8.60a. This figure confirms that the elliptic filter has zeros, and those zeros occur
on the imaginary axis. The magnitude response of the elliptic lowpass filter is shown
in Fig. 8.60b. From this figure, it is possible to observe the equiripples in both the
passband and stopband.
8.7 Elliptic Filter 363
import numpy as np
import matplotlib.pyplot as plt
from scipy import signal
import control as ss
N, rp,rs, omega_c=3, 2, 20, [5]
omega1=np.linspace(0, 10, 100)
b_s, a_s=signal.ellip(N,rp,rs,omega_c,'low', analog=True)
s1 = ss.tf(b_s, a_s)
print('H(s) = ', s1)
z1=np.roots(b_s)
print('Zeros : ', z1)
mag, phase, omega1=ss.freqresp(s1, omega1)
plt.figure,plt.plot(omega1,np.abs(mag))
plt.xlabel('$\u03A9$-->'),plt.ylabel('$|H({j\u03A9})|$')
plt.title('Magnitude response of Elliptic LPF')
plt.tight_layout()
0.8
H(s) = 0.6
|H(j:)|
0.0
Zeros : [-0.+6.5683962j 0.-6.5683962j] 0 2 4 6 8 10
:-->
Fig. 8.60 Simulation result of the python code is given in Fig. 8.59. (a) Transfer function and
zeros. (b) Magnitude response
Inference
From the simulation result of this experiment, it is possible to observe that ripples
present in both the passband and stopband, and also it infers that the width of the
transition band is reduced.
Task
1. Write a python code to design an elliptic highpass filter with a lower cut-off
frequency of 5 Hz. Assume the order of the filter is 3, passband ripple is 2 dB and
stopband attenuation is 30 dB.
364 8 Infinite Impulse Response Filter
import numpy as np
import matplotlib.pyplot as plt
from scipy import signal
import control as ss
# Specifications of Filter
fsam=8000 # Sampling frequency in Hz
fc1,fc2=[1500,2500],[1000,3000] # cut off frequency in Hz
Ap, As, T = 2, 40, 1/fsam
wcp1=2*np.pi*fc1[0] # Pass band Cut off frequency in rad/sec
wcp2=2*np.pi*fc1[1] # Pass band Cut off frequency in rad/sec
wcs1=2*np.pi*fc2[0] # Stop band Cut off frequency in rad/sec
wcs2=2*np.pi*fc2[1] # Stop band Cut off frequency in rad/sec
pwcs1 = (2/T)*np.tan(wcp1*T/2) # Prewarp the analog frequency
pwcs2 = (2/T)*np.tan(wcp2*T/2) # Prewarp the analog frequency
pwcp1 = (2/T)*np.tan(wcs1*T/2) # Prewarp the analog frequency
pwcp2 = (2/T)*np.tan(wcs2*T/2) # Prewarp the analog frequency
N,wn=signal.ellipord([pwcp1,pwcp2],[pwcs1,pwcs2],Ap,As,analog=True)
print('Order of the filter (N) = ',N)
# Design analog Elliptic filter using signal.ellip function
b, a = signal.ellip(N, Ap, As, wn, 'bandstop', analog='True')
s1 = ss.tf(b,a)
print('Transfer function H(s)=',s1)
# Perform bilinear transformation
bz, az = signal.bilinear(b, a, fs=fsam)
z1 = ss.tf(bz,az,T)
print('Transfer function H(z)=',z1)
# Compute frequency response of the filter using signal.freqz function
wz, hz = signal.freqz(bz, az, 512)
fig = plt.figure(figsize=(10, 8))
Mag = 10*np.log10(abs(hz)) # Calculate Magnitude in dB
Freq = wz*fsam/(2*np.pi) # Calculate frequency in Hz
# Plot Magnitude response
sub1 = plt.subplot(2, 1, 1)
sub1.plot(Freq, Mag, 'r', linewidth=2),sub1.axis([1, fsam/2, -60, 5])
sub1.set_title('Magnitude Response', fontsize=15),
sub1.set_xlabel('Frequency [Hz]', fontsize=15),sub1.set_ylabel('Magnitude [dB]', fontsize=15)
sub1.grid()
# Plot phase angle
sub2 = plt.subplot(2, 1, 2)
Phase = np.unwrap(np.angle(hz))*180/np.pi # Calculate phase angle in degree from hz
sub2.plot(Freq, Phase, 'g', linewidth=2),sub2.set_ylabel('Phase (degree)', fontsize=15)
sub2.set_xlabel(r'Frequency (Hz)', fontsize=15),sub2.set_title(r'Phase response', fontsize=15)
sub2.grid(),plt.subplots_adjust(hspace=0.5),fig.tight_layout(),plt.show()
shows the magnitude and phase response of the elliptic (Cauer) digital bandstop
filter.
Inference
From this experiment, the following observations can be made:
366 8 Infinite Impulse Response Filter
Fig. 8.64 Python code to obtain the magnitude response of four analogue IIR filters
Magnitude response
0
–20
–40
Magnitude[dB]
–60
–80
Butterworth
–100
Chebyshev Type I
Chebyshev Type II
–120 Elliptic
Inferences
From Fig. 8.65, the following inferences can be made:
1. Butterworth filter exhibits maximally flat frequency response without ripples in
passband and stopband.
2. Type I Chebyshev filter exhibits ripples in only passband.
3. Type II Chebyshev filter exhibits ripples in stopband.
4. Elliptic filter exhibits ripples in both passband and stopband.
5. The roll-off rate of elliptic filter is better than Butterworth and Chebyshev filters.
Experiment 8.28 Comparing the Order of Butterworth, Chebyshev (Type I and
Type II) and Elliptic Filters for the Same Filter Specification
The objective of this experiment is to compute the order of Butterworth, Type I
Chebyshev, Type II Chebyshev and elliptic filter for the following specifications
using bilinear transformation technique (BLT). -3 dB cut-off frequency at 5 Hz, and
an attenuation of 40 dB at 10 Hz, use bilinear transformation technique. Assume the
368 8 Infinite Impulse Response Filter
5 5
5
3
3
0
Butterworth Cheby1 Cheby2 Elliptic
sampling frequency to be 1000 Hz. The python code, which computes the order of
different IIR filter, is shown in Fig. 8.66, and the corresponding output is shown in
Fig. 8.67.
Inferences
From Fig. 8.67, it is possible to observe the following facts:
1. The order of Butterworth filter to meet the given filter specification is 7.
2. The order of Chebyshev filter to meet the given filter specification is 5.
3. The order of elliptic filter to meet the given filter specification is 3.
4. The order of Butterworth filter is higher than the order of Chebyshev and elliptic
filters.
5. Elliptic filter meets the given filter specification with a minimum order.
370 8 Infinite Impulse Response Filter
Amplitude
Amplitude
Amplitude
0 0 0
–1 –1 –1
0.0 0.5 1.0 0.0 0.5 1.0 0.0 0.5 1.0
Time Time Time
Filtered signal (N=10) Filtered signal (N=20) Filtered signal (N=25)
1 1 1
Amplitude
Amplitude
Amplitude
0 0 0
–1 –1 –1
0.0 0.5 1.0 0.0 0.5 1.0 0.0 0.5 1.0
Time Time Time
Input signal
1.00
0.75
0.50
0.25
Amplitude
0.00
–0.25
–0.50
–0.75
–1.00
0.0 0.2 0.4 0.6 0.8 1.0
Time
0 0
–1 –1
0.00 0.25 0.50 0.75 1.00 0.00 0.25 0.50 0.75 1.00
0.0
0
–0.5
0.00 0.25 0.50 0.75 1.00 0.00 0.25 0.50 0.75 1.00
5. The cut-off frequency and the sampling frequency chosen are 8 and 100 Hz,
respectively.
The python code, which implements the above-mentioned task, is shown in
Fig. 8.70, and the corresponding outputs are shown in Figs. 8.71 and 8.72.
8.7 Elliptic Filter 373
Inferences
From Fig. 8.71, it is possible to observe that the input signal has three frequency
components, namely 5, 0 and 10 Hz. This
1. Input signal is passed through lowpass Butterworth, Chebyshev (Type I and Type
II) and elliptic filters.
2. Butterworth filter performs smoothing action without ripples. But the extent of
filtering is poor. Significant high-frequency components appear along with low
frequency components.
3. In Chebyshev and elliptic filters, the high-frequency components are filtered
effectively; however, the filtering action is not smooth. Ripples appear in the
filtered output signal.
Exercises
1. The transfer function of analogue filter is given by H ðsÞ = sþ10
10
. Write a python
code to obtain the transfer function of the equivalent digital filter using
(a) impulse invariant technique and (b) bilinear transformation technique.
Assume the sampling period to be 1 s.
2. A normalized first-order lowpass Butterworth filter transfer function is given by
H ðsÞ = ðsþ1
1
Þ. Write a python code to convert this filter into desired highpass
filter with a cut-off frequency of 5 rad/s. Using subplot, plot the magnitude
response of normalized filter and the desired highpass filter.
3. Write a python code to obtain the order and cut-off frequency of analogue
Butterworth filter that has -3 dB cut-off frequency of 20 rad/s and 10 dB of
attenuation at 40 rad/s. Plot the magnitude response of the filter.
4. Design an analogue bandpass filter that has the following characteristics:
(a) -3 dB upper and lower cut-off frequency of 100 Hz and 10 kHz
(b) Stopband attenuation of 30 dB at 50 Hz and 25 kHz
(c) Monotonic frequency response
Plot the magnitude response of the above-mentioned filter.
5. Write a python code to design a digital lowpass Butterworth filter for the
following specification using impulse invariant technique (a) -3 dB cut-off
frequency at 250 Hz and (b) magnitude of frequency response down at least
10 dB at 500 Hz. Assume the sample to be 1000 samples/s. Plot the magnitude
response of the filter.
6. Write a python code to design a digital filter using the bilinear transformation
technique for the following specification: (a) maximally flat frequency response
with -3 dB cut-off at 10 rad/s, (b) 30 dB of attenuation at all frequencies greater
than 20 rad/s and (c) assuming the sampling frequency to be 1000 samples/s.
Plot the magnitude response of the filter.
7. Write a python code to design a Type I Chebyshev filter using bilinear trans-
formation technique (BLT) that has a passband of 0 to -3 dB cut-off frequency
at 5 kHz and attenuation of at least 30 dB for frequencies greater than 10 kHz.
374 8 Infinite Impulse Response Filter
C. s = T
1 - z-1
D. s = T
1þz - 1
Bibliography
1. Harry Y.F. Lam, “Analog and Digital Filters: Design and Realization”, Prentice Hall, 1979.
2. Andreas Antoniou, “Digital Filters: Analysis, Design and Signal Processing Applications”,
McGraw Hill, 2018.
3. Dietrich Schlichtharle, “Digital Filters: Basics and Design”, Springer, 2011.
4. Leland B. Jackson, “Digital Filters and Signal Processing”, Springer, 1988.
5. Thomas Haslwanter, “Hands-on Signal Analysis with Python”, Springer, 2022.
Chapter 9
Quantization Effect of Digital Filter
Coefficients
Learning Objectives
After completing this chapter, the reader is expected to
• Understand and implement approximation of numbers through flooring, ceiling
and rounding operations.
• Analyse the impact of quantizing the finite impulse response filter coefficients.
• Analyse the impact of quantizing the infinite impulse response filter coefficients.
• Demonstrate limit cycle oscillation due to quantization of IIR filter coefficients.
Quantization Errors
Overflow
© The Author(s), under exclusive license to Springer Nature Singapore Pte Ltd. 2024 377
S. Esakkirajan et al., Digital Signal Processing,
https://doi.org/10.1007/978-981-99-6752-0_9
378 9 Quantization Effect of Digital Filter Coefficients
PreLab Questions
1. What is the finite word length effect in DSP?
2. List out the difference between fixed-point and floating-point number
representations.
3. What is the significance of sign-magnitude representation?
4. What are quantization and quantization errors?
5. What is rounding, and how does it the quantization process?
6. What do you mean by two’s complement truncation in quantization, and what is
the range of quantization error?
7. What is magnitude truncation, and can it suppress the limit cycle oscillation?
8. What is overflow? And mention the types of overflow.
9. What do you mean by limit cycle oscillation, and how it exists in signal
processing?
10. What do you mean by coefficient quantization, and how it affects the stability of
the result?
1. Rounding
2. Two’s complement truncation
3. Magnitude truncation
X r = Δ × roundðx=ΔÞ ð9:1Þ
where x denotes the value to be quantized, Δ represents the step size and is computed
as Δ = 2-N, N denotes the number of bits and Xr represents the quantized output
using rounding. The python code for computing quantization using the rounding
approach is given in Fig. 9.1, and its corresponding simulation result is shown in
Fig. 9.2.
Inference
1. From Fig. 9.2, it is possible to infer that the value to be quantized is ‘0.126’ and
the number of bits that can be used to represent the value is ‘2’.
2. The two bits can represent the maximum of 4 levels (0–0.25, 0.25–0.5, 0.5–0.75
and 0.75–1.0).
3. Therefore, the input ‘0.126’ is quantized, and the result is 0.25 (0.126 is greater
than 0.125).
Task
1. Enter the value to be quantized is 5.15, and 8 bits are used for the quantization.
Observe the quantized result.
The two’s complement truncation always gives the quantized value less than or
equal to the original value. Hence, the truncation error is denoted as εt = Qt(X) - X.
Then, the truncation error is ranging from -Δ ≤ εt ≤ 0. The error resulting from
quantization can be modelled as a random variable uniformly distributed over the
appropriate error range. Hence, the two’s complement truncation error can be
considered error-free calculations corrupted by additive white noise. The mean
value of the two’s complement truncation error can be obtained as μεt = - Δ2 . The
variance of the two’s complement truncation error is calculated as σ 2εt = Δ2=12.
Experiment 9.2 Perform Fixed-Point Quantization Using Two’s Complement
This experiment deals with quantizing the value using two’s complement truncation
approach. The quantization using two’s complement truncation method is denoted as
X t = Δ × bðx=ΔÞc ð9:2Þ
where bc denotes flooring operation. Xt represents the quantized result using trun-
cation method. The python code, which computes the fixed-point quantization of a
number using two’s complement truncation method, is shown in Fig. 9.3, and its
simulation result is depicted in Fig. 9.4.
9.2 Fixed-Point Quantization 381
Fig. 9.3 Python code for quantization using two’s complement truncation
Inference
From Fig. 9.4, it is possible to infer that the value to be quantized is 0.126, and the
resultant value is 0 for N = 2.
Task
1. Choose the proper value of N and execute the python code given in Fig. 9.3 to get
0.126 as the output.
Magnitude truncation gives the quantized value less than the original value for
X > 0, and the quantized result is greater than original for X < 0. Hence, the
magnitude truncation error is denoted as εmt = Qmt(X) - X.
Then, the magnitude truncation error is ranging from -Δ ≤ εmt ≤ 0 for X > 0 and
0 ≤ εmt ≤ Δ for X < 0. The mean value of the magnitude truncation error is obtained
as 0, and variance of the magnitude truncation error is calculated as σ 2εmt = Δ2=3. The
specific advantage of magnitude truncation lies in its inherent capability of limit
cycle suppression.
382 9 Quantization Effect of Digital Filter Coefficients
Δ × bðx=ΔÞc, for x ≥ 0
X mt = ð9:3Þ
Δ × dðx=ΔÞe, for x < 0
where de denotes ceiling operation. Xmt represents the quantized result using mag-
nitude truncation. The python code of this experiment is shown in Fig. 9.5, and the
simulation result is displayed in Fig. 9.6.
Inference
The following inferences can be made from this experiment:
1. Figure 9.6 shows that the value to be quantized is 0.126, and the number of bits is
chosen as 2. The result of quantization using the magnitude truncation is 0. This
simulation result is on par with the theoretical result.
2. The selection of the number of bits is essential for quantization.
3. The quantization method is crucial for the hardware implementation of the digital
systems.
9.3 Coefficient Quantization 383
Task
1. Execute the python code given in Fig. 9.5, and enter the value to be quantized as
‘0.126’ and obtain the minimum value of ‘N’, which will give the quantized result
that is the same as the input value.
The filter coefficients can be obtained using filter design approaches based on the
given set of filter specifications. These filter coefficients are represented as a system
function of the filter H(z), and they can be used in signal processing applications.
These filter coefficients may be integer or non-integer numbers. If the filter coeffi-
cient is an integer, then the finite precision format is enough to represent it in digital
computation. Otherwise, the coefficient is non-integer, then infinite precision format
is necessary to represent it for the accurate result of the applications. However, in
real-time scenario the hardware setup in the application may not be able to store the
value of filter coefficients as it is due to the limited register size or finite precision
processor. The representation of the filter coefficients from infinite precision to finite
number precision may give coefficients quantization. This coefficient quantization
can change the location of the filter poles and zeros. As a result, after implementing a
filter, it may observe that the frequency response of the filter is quite different from
that of the original design. The coefficients obtained by design methods are real or
complex. These coefficients are often stored in a finite length register for real-world
digital signal processing. The coefficients are often rounded to accommodate it in the
finite length register. This causes a rounding error, which will influence the filter
characteristics. The frequency response of the quantized filter coefficients will differ
from the desired frequency response. Sensitivity of the filter response to coefficient
quantization is dependent on the type of filter structures. Detail about this will be
discussed later in this chapter.
Experiment 9.4 Effect of Quantization Using the Rounding Approach of FIR
Filters
This experiment deals with the effect of coefficient quantization of FIR filters. Here,
the method to quantize the filter coefficients is considered as rounding method. The
FIR filter coefficients are computed by using the built in python command ‘a =
signal.firwin(n, cutoff = 0.25, window = "hamming")’. Here ‘n’ denotes the number
of the filter coefficients, ‘cutoff = 0.25’ represents cut-off frequency of the filter is
0.25π rad/sample and the ‘window = "hamming"’ indicates the window function
used for the FIR filter design. The python code for this experiment is shown in
Fig. 9.7. In this figure, ‘B = 2’ denotes the number of bits used to quantize each filter
coefficient. While increasing the value of B = 3, 4, 5, 6, . . ., the quantized filter’s
impulse and frequency response will approach the original filter’s impulse and
384 9 Quantization Effect of Digital Filter Coefficients
Fig. 9.7 Python code to analyse coefficient quantization effect of FIR filter
frequency response. The simulation result of the python code given in Fig. 9.7 is
displayed in Fig. 9.8.
Inferences
From Fig. 9.8, the following observations can be made:
1. Figure 9.8a displays the impulse response of the original FIR filter components
and its magnitude, phase and pole-zero plot.
2. Figure 9.8b shows the number of bits selected as 2 for quantizing FIR filter
coefficients and its impulse response, magnitude, phase and pole-zero plot. From
this figure, it is possible to infer that the impulse response of the quantized FIR
filter looks like a rectangular pulse, which is completely deviated from the
original impulse response (i.e.) sinc function. Magnitude and phase responses
9.3 Coefficient Quantization 385
Fig. 9.8 Simulation result of the python code is shown in Fig. 9.7. (a) Original (unquantized). (b)
Quantized with N = 2 bits. (c) Quantized with N = 4 bits. (d) Quantized with N = 16 bits
differ completely from the original magnitude and phase responses. In the pole-
zero plot, some zeros occur at the origin, whereas in the original pole-zero plot,
there is no zero at the origin; it indicates that after the filter coefficients, a lot of
coefficients become zero due to less number of bits allocated for the
representation.
3. From Fig. 9.8c, d, when the number of bits (N ) is chosen as 4 and 16, the impulse
response of the quantized FIR filter approaches the original impulse response, and
the magnitude and phase response approaches the original one.
4. From these figures, it is possible to confirm that allocating the number of bits to
represent the filter coefficients plays a significant role in DSP computations.
Experiment 9.5 Verify the Effect of Quantization Using the Two’s Complement
Truncation Approach of FIR Filters
This experiment discusses the effect of quantization using two’s complement trun-
cation method of FIR filter coefficients. The python code to perform the two’s
complement truncation-based quantization of FIR filter coefficients is shown in
Fig. 9.9. In this experiment, we have chosen the order of the FIR filter as 31, the
window function is considered ‘Hamming’, and the cut-off frequency is 0.25π
rad/samples. The finite number of bits required to represent each filter coefficient
386 9 Quantization Effect of Digital Filter Coefficients
is selected as 2, 4 and 16. The simulation result of the python code given in Fig. 9.9
is shown in Fig. 9.10.
Inferences
The following observations can be drawn from Fig. 9.10:
1. When the number of bits N = 2, the impulse response of the FIR filter is
completely deviated from the original impulse response of the FIR filter. Simi-
larly, the magnitude and phase responses differ from the original one. From the
pole-zero plot, the locations of the zeros of quantized filter are dislocated from the
original positions.
9.3 Coefficient Quantization 387
Fig. 9.10 Simulation result of the python code given in Fig. 9.9. (a) Original filter. (b) Quantized
filter with N = 2 bits. (c) Quantized filter with N = 4 bits. (d) Quantized filter with N = 16 bits
2. When the number of bits is chosen as 4, the impulse response is still not the same
as the original one. From this, 4 bits for each filter coefficient are insufficient for
the finite precision.
3. When the number of bits is considered as 16. The impulse, magnitude and phase
responses are exactly the same as the original one. This is also evident from the
pole-zero plot.
4. From this experiment, we must understand that allocating the number of bits to
represent the filter coefficients is very important for the FIR filter design. Even
though the FIR filter is stable after the quantization, the filter response is not as
expected.
Experiment 9.6 Verify the Effect of Quantization Using the Magnitude Trun-
cation Approach of FIR Filters
This experiment explores the effect of quantization using magnitude truncation of
FIR filter coefficients. The magnitude truncation is another type of quantization
approach that can represent the infinite precision to the finite precision of filter
coefficients. The python code to perform the magnitude truncation of the FIR filter
coefficients is shown in Fig. 9.11. In this experiment, we have chosen the order of
FIR filter is 31, the window function is considered ‘Hamming’ and the cut-off
frequency is 0.25π rad/samples. The finite number of bits required to represent
388 9 Quantization Effect of Digital Filter Coefficients
each filter coefficient is chosen as 2, 4 and 16. The simulation result of the python
code given in Fig. 9.11 is shown in Fig. 9.12.
Inferences
From Fig. 9.12, the following inferences can be made:
1. When the number of bits is chosen as N = 2, the impulse response of the
quantized filter has only one non-zero element, and all other elements are zero.
9.3 Coefficient Quantization 389
Fig. 9.12 Simulation result of the python code given in Fig. 9.11. (a) Original filter. (b) Quantized
filter with N = 2 bits. (c) Quantized filter with N = 4 bits. (d) Quantized filter with N = 16 bits
From the pole-zero plot, it is possible to infer that all the zeros of the FIR filters
are placed at the origin, and it confirms that improper allocation of bits will lead to
error frequency response.
2. While choosing the value N is 4, the impulse response of the quantized filter looks
like a triangular function; it is not a Gaussian function. Also, it shows that all the
zeros of the FIR filters are squeezed into only four locations.
3. If N = 16, the impulse, magnitude, and phase responses of the quantized filter are
very close to the responses of the original filter. Also, the pole-zero plot is similar
to the original one.
Experiment 9.7 Verify the Effect of Quantization Using the Rounding
Approach of Butterworth IIR Filter
This experiment discusses the quantization of Butterworth filter coefficients com-
puted using the bilinear transformation technique (BLT) that has a passband gain of
0 to -3 dB, cut-off frequency of 2 kHz and an attenuation of at least 20 dB for
frequencies greater than 5 kHz. Assume the sampling frequency to be 20 kHz.
Butterworth filter coefficients are quantized using the rounding approach. The
python code to verify the concept of this experiment is shown in Fig. 9.13. Here
the number of bits to be allocated to represent each coefficient of the IIR Butterworth
filter is chosen as 4, 8, 12 and 16. The simulation results of the python code given in
Fig. 9.13 are shown in Fig. 9.14.
390 9 Quantization Effect of Digital Filter Coefficients
import numpy as np
import matplotlib.pyplot as plt
from scipy import signal
# Specifications of Filter
fsam, fp, fs, Ap, As, Td=20000, 2000, 5000, 3, 20, 1 # Sampling frequency
wp=2*np.pi*(fp/fsam) # pass band freq in radian per sample
ws=2*np.pi*(fs/fsam) # Stop band freq in radian per sample
# prewarping process
omega_p=(2/Td)*np.tan(wp/2)
omega_s=(2/Td)*np.tan(ws/2)
#Computation of order and normalized cut-off frequency
N, omega_c=signal.buttord(omega_p,omega_s,Ap,As,analog=True)
print('Order of the Filter N =', N),print('Cut-off frequency= {:.4f} rad/s '. format(omega_c))
# Computation of H(s)
b, a=signal.butter(N,omega_c,'low', analog=True)
bz, az=signal.bilinear(b, a, Td)
n=15
n1=np.arange(0,n);
x=(n1==0)
y=signal.lfilter(bz,az,x)
W,H = signal.freqz(bz,az)
#Obtaining the pole-zero plot
z,p,k=signal.tf2zpk(bz,az)
B = 2;# Number of Bits
Q = 1/(2**(B))
Qbr=Q*np.round(bz/Q)#Rounding
Qar=Q*np.round(az/Q)#Rounding
yr=signal.lfilter(Qbr,Qar,x)
Wq,Hq = signal.freqz(Qbr,Qar)
zq,pq,kq=signal.tf2zpk(Qbr,Qar)
#Plotting the responses
plt.figure(1),plt.subplot(2,2,1),plt.stem(n1,y),plt.xlabel('n-->'),plt.ylabel('h[n]'),plt.title('h[n]')
plt.subplot(2,2,2),plt.plot((W/np.pi),20*np.log10(np.abs(H)))
plt.xlabel(r'$\omega$(x$\pi$rad/sample)'),plt.ylabel('Magnitude'),plt.title('|H($\omega$)|')
plt.subplot(2,2,3),plt.plot(np.real(z),np.imag(z),'ro'),plt.plot(np.real(p),np.imag(p),'kx')
theta=np.linspace(0,2*np.pi,100)
plt.plot(np.cos(theta),np.sin(theta))
plt.xlabel('Real part'),plt.ylabel('Imaginary part'),plt.title('Pole-zero plot')
plt.subplot(2,2,4),plt.plot((W/np.pi),np.unwrap(np.angle(H)))
plt.xlabel(r'$\omega$(x$\pi$rad/sample)'),plt.ylabel('Phase'),plt.title('$\Phi(e^{jw})$')
plt.tight_layout()
plt.figure(2),plt.subplot(2,2,1),plt.stem(n1,yr),plt.xlabel('n-->'),plt.ylabel('$h_q[n]$')
plt.title('$h_q[n]$ with N = {} bits'.format(B))
plt.subplot(2,2,2),plt.plot((Wq/np.pi),20*np.log10(np.abs(Hq)))
plt.xlabel(r'$\omega$(x$\pi$rad/sample)'),plt.ylabel('Magnitude'),plt.title('$|H_q(\omega$)|')
plt.subplot(2,2,3),plt.plot(np.real(zq),np.imag(zq),'ro'),plt.plot(np.real(pq),np.imag(pq),'kx')
theta=np.linspace(0,2*np.pi,100)
plt.plot(np.cos(theta),np.sin(theta)),plt.xlabel('Real part'),plt.ylabel('Imaginary part'),
plt.title('Pole-zero plot'),plt.subplot(2,2,4),plt.plot((Wq/np.pi),np.unwrap(np.angle(Hq)))
plt.xlabel(r'$\omega$(x$\pi$rad/sample)'),plt.ylabel('Phase'),plt.title('$\Phi_q(e^{jw})$')
plt.tight_layout()
Fig. 9.14 Simulation results of Experiment 9.7. (a) Infinite precision. (b) Finite precision (N = 2
bits). (c) Finite precision (N = 4 bits). (d) Finite precision (N = 8 bits). (e) Finite precision (N = 12
bits). (f) Finite precision (N = 16 bits)
Inferences
The following inferences can be made from Fig. 9.14:
1. When the number of bits allocated to represent each coefficient of the IIR filter is
2, the impulse response of the quantized filter becomes zero, and the pole-zero
plot, magnitude and phase responses confirm it.
2. The number of bits chosen as 4, 8 and 12, the impulse responses of the quantized
filter are not the same as the impulse response of the original filter, which reflects
in the pole-zero plot, magnitude and phase responses.
392 9 Quantization Effect of Digital Filter Coefficients
3. When the number of bits selected is 16, the impulse response of the quantized
filter is exactly the same as the impulse response of the original filter. Also, the
pole-zero plot, magnitude and phase responses are on par with the original result.
Task
Repeat the Experiment 9.7 with the filter quantization using two’s complement
truncation approach.
Experiment 9.8 Chebyshev Type I IIR Filter Coefficients Quantization Effect
Let us consider a Chebyshev Type I IIR filter designed using the bilinear transfor-
mation technique (BLT) that has a passband gain of 0 to -3 dB, cut-off frequency of
2 kHz and an attenuation of at least 20 dB for frequencies greater than 5 kHz.
Assume the sampling frequency to be 20 kHz. This experiment deals with the
quantization effect of IIR filter coefficients. The order and coefficients of Chebyshev
Type I filter are computed based on the given specifications. These filter coefficients
are quantized by either two’s complement or magnitude truncation method. The
performance of the infinite precision and finite precision is displayed. The python
code to quantize the IIR filter coefficients is given in Fig. 9.15, and the simulation
result is shown in Fig. 9.16.
When executing the python code given in Fig. 9.15, first enter the type of
quantization ‘1’ for two’s complement truncation and ‘2’ for magnitude truncation.
The simulation result is shown in Fig. 9.16.
Inference
From Fig. 9.16, it is possible to observe the quantization effect of IIR filter. The
impulse and magnitude responses are zero for the low-bit representation of filter
coefficients. When the high-bit representation of filter coefficients, the result of
impulse and magnitude responses approaches the original responses.
Task
1. Repeat Experiment 9.8 with the filter quantization using two’s complement
truncation approach.
2. Repeat Experiment 9.8 with the filter quantization using the rounding approach.
import numpy as np
import matplotlib.pyplot as plt
from scipy import signal
# Specifications of Filter
fsam, fp, fs, Ap, As, Td=20000, 2000, 5000, 3, 30, 0.9 # Sampling frequency
wp=2*np.pi*(fp/fsam) # pass band freq in radian per sample
ws=2*np.pi*(fs/fsam) # Stop band freq in radian per sample
# prewarping process
omega_p=(2/Td)*np.tan(wp/2)
omega_s=(2/Td)*np.tan(ws/2)
#Computation of order and normalized cut-off frequency
N, omega_c=signal.cheb1ord(omega_p,omega_s,Ap,As,analog=True)
print('Order of the Filter N =', N),print('Cut-off frequency= {:.4f} rad/s '. format(omega_c))
# Computation of H(s)
b, a=signal.cheby1(N, Ap, omega_c,'low', analog=True)
bz, az=signal.bilinear(b, a, Td)
n=15
n1=np.arange(0,n);
x=(n1==0)
y=signal.lfilter(bz,az,x)
W,H = signal.freqz(bz,az)
#Obtaining the pole-zero plot
z,p,k=signal.tf2zpk(bz,az)
B = 8;# Number of Bits
Q = 1/(2**(B))
QT=int(input('Enter the type of Qunatization:1-2s Complement truncation; 2-Magnitude truncation: '))
import sys
if (QT == 1):
Qbr=Q*np.floor(bz/Q)# Twos complement truncation
Qar=Q*np.floor(az/Q)# Twos complement truncation
elif (QT == 2):
Qbr=np.zeros(len(bz)) # Magnitude Truncation
Qar=np.zeros(len(az)) # Magnitude Truncation
for i in range(len(bz)):
if bz[i] > 0:
Qbr[i]=Q*np.floor(bz[i]/Q)
else: Qbr[i]=Q*np.ceil(bz[i]/Q)
for j in range(len(az)):
if az[j] > 0:
Qar[j]=Q*np.floor(az[j]/Q)
else: Qar[j]=Q*np.ceil(az[j]/Q)
else:
print('"Please select the proper quantization method"');
sys.exit()
yr=signal.lfilter(Qbr,Qar,x)
Wq,Hq = signal.freqz(Qbr,Qar)
zq,pq,kq=signal.tf2zpk(Qbr,Qar)
#Plotting the responses
plt.figure(1),plt.subplot(2,2,1),plt.stem(n1,y),plt.xlabel('n-->'),plt.ylabel('h[n]')
plt.title('h[n]')
plt.subplot(2,2,2),plt.plot((W/np.pi),20*np.log10(np.abs(H)))
plt.xlabel(r'$\omega$(x$\pi$rad/sample)'),plt.ylabel('Magnitude'),plt.title('|H($\omega$)|')
plt.subplot(2,2,3),plt.plot(np.real(z),np.imag(z),'ro')
plt.plot(np.real(p),np.imag(p),'kx')
theta=np.linspace(0,2*np.pi,100)
plt.plot(np.cos(theta),np.sin(theta))
plt.xlabel('Real part'),plt.ylabel('Imaginary part'),plt.title('Pole-zero plot')
plt.subplot(2,2,4),plt.plot((W/np.pi),np.unwrap(np.angle(H)))
plt.xlabel(r'$\omega$(x$\pi$rad/sample)'),plt.ylabel('Phase'),plt.title('$\Phi(e^{jw})$')
plt.tight_layout()
plt.figure(2)
plt.subplot(2,2,1),plt.stem(n1,yr),plt.xlabel('n-->'),plt.ylabel('$h_q[n]$')
plt.title('$h_q[n]$ with N = {} bits'.format(B))
plt.subplot(2,2,2),plt.plot((Wq/np.pi),20*np.log10(np.abs(Hq)))
plt.xlabel(r'$\omega$(x$\pi$rad/sample)'),plt.ylabel('Magnitude'),plt.title('$|H_q(\omega$)|')
plt.subplot(2,2,3),plt.plot(np.real(zq),np.imag(zq),'ro')
plt.plot(np.real(pq),np.imag(pq),'kx')
theta=np.linspace(0,2*np.pi,100)
plt.plot(np.cos(theta),np.sin(theta)),plt.xlabel('Real part'),plt.ylabel('Imaginary part'),
plt.title('Pole-zero plot'),plt.subplot(2,2,4),plt.plot((Wq/np.pi),np.unwrap(np.angle(Hq)))
plt.xlabel(r'$\omega$(x$\pi$rad/sample)'),plt.ylabel('Phase'),plt.title('$\Phi_q(e^{jw})$')
plt.tight_layout()
7 5
y ½ n] - y½n - 1] þ y½n - 2] = δ½n]
8 8
The input and output coefficients of the recursive system are quantized using the
rounding fixed-point 3-bit quantization approach. The quantized result of the recur-
sive system is written as
7 5
yq ½n] = Qr δ½n] þ y½n - 1] - y½n - 2]
8 8
The python code for this above equation is given in Fig. 9.17. From this figure, it
is possible to confirm that the number of bits used in the quantization is 3, and the
rounding quantization approach is implemented. After executing the python code
given in Fig. 9.17, the obtained result is shown in Fig. 9.18. From this figure, it is
possible to infer that the output is oscillated and confirms that the limit cycle
oscillation exists in this filter.
Inferences
From this experiment, the following inferences can be made:
1. The finite arithmetic operation in the digital implementation of a recursive system
may introduce limit cycle oscillations in the final output. This causes due to the
feedback that exists in the recursive system.
9.4 Limit Cycle Oscillations 395
Fig. 9.16 Simulation results. (a) Original filter. (b) Quantized with two’s complement. (c) Mag-
nitude truncation
396 9 Quantization Effect of Digital Filter Coefficients
import numpy as np
import matplotlib.pyplot as plt
B = 3;# Number of Bits
Q = 1/(2**(B))
N=100
x=np.zeros(N)
y1=np.zeros(N)
y=np.zeros(N)
n=np.arange(0,len(x))
x[0]=1#5/8
y1[-1], y[-1]=0,0
y1[-2], y[-2]=0,0
for i in range(len(x)):
Y=x[i]+((7/8)*y1[i-1])-(5/8)*y1[i-2]
y[i]=x[i]+((7/8)*y[i-1])-(5/8)*y[i-2]
y1[i]=(Q*np.round(Y/Q))
out=y1
plt.subplot(311),plt.stem(n,x),plt.xlabel('n-->'),plt.ylabel('x[n]'),plt.title('Input')
plt.subplot(312),plt.stem(n,y),plt.xlabel('n-->'),plt.ylabel('y[n]'),plt.title('Infinite precision Output')
plt.subplot(313),plt.stem(n,y1),plt.xlabel('n-->'),plt.ylabel('y1[n]'),plt.title('Finite arithmetic Output')
plt.tight_layout()
Input
1
x[n]
0
0 20 40 60 80 100
n-->
Infinite precision Output
1
y[n]
0
0 20 40 60 80 100
n-->
Finite arithmetic Output
1
y1[n]
0
0 20 40 60 80 100
n-->
2. After some time, the infinite precision arithmetic operation settles its output as
zero, whereas the finite precision result does not become zero.
3. Since the feedback path does not exist in the non-recursive system, the limit cycle
oscillation does not occur.
9.5 Cascade Form of a Higher Order Filters 397
Task
1. Execute the python code given in Fig. 9.17, and determine the minimum value
that will eliminate the limit cycle oscillation in Experiment 9.9 (i.e. change the
value of B (4, 5, 6, . . .)).
Exercises
1. Write a python code to convert decimal numbers to binary with fixed-point
representation.
9.5
Cascade Form of a Higher Order Filters
Fig. 9.20 Simulation result. (a) Infinite precision output. (b) Finite precision output. (c) Cascade with finite precision output
399
400 9 Quantization Effect of Digital Filter Coefficients
C. signal.butter1
D. signal.buttord1
6. The formula to quantize the input value ‘x’ and step size ‘Δ’ by rounding
approach is
A. Δ × round Δx
B. Δ × ceil Δx
C. Δ × floor Δx
D. x × round Δx
7. The formula to quantize the input value ‘x’ and step size ‘Δ’ by two’s compli-
ment truncation approach is
A. Δ × round Δx
B. Δ × ceil Δx
C. Δ × floor Δx
D. x × round Δx
8. The formula to quantize the input value ‘x’ is greater than ‘0’ and step size ‘Δ’
by magnitude truncation approach is
A. Δ × floor Δx
B. Δ × ceil Δx
C. Δ × round Δx
D. x × round Δx
9. Limit cycle oscillation does not occur in
A. Recursive system
B. IIR filter
C. Stable filter
D. FIR filter
10. The effect of quantization in a higher-order FIR filter is reduced by using
A. Parallel realization
B. Cascade realization
C. Direct form I realization
D. Lattice realization
Bibliography
1. Bernard Widrow, Istvan Kollar, “Quantization Noise: Roundoff Error in Digital Computation,
Signal Processing, Control and Communications”, Cambridge University Press, 2008.
402 9 Quantization Effect of Digital Filter Coefficients
2. N.S. Jayant, Peter Noll, “Digital Coding of Waveforms: Principles and Applications to Speech
and Video”, Prentice Hall India, 1984.
3. Lawrence R. Rabiner, and Bernard Gold, “Theory and Applications of Digital Signal
Processing”, Prentice-Hall, 1975.
4. James H. McClellan, Ronald W. Schafer, and Mark A. Yoder, “DSP First”, Prentice Hall, 1998.
5. Allen Gersho and Robert M. Gray, “Vector Quantization and Signal Compression”,
Springer, 1991.
Chapter 10
Multirate Signal Processing
Learning Objectives
After completing this chapter, the reader is expected to
• To perform sampling rate conversion using multirate operators.
• Time-domain and frequency-domain view of multirate operators.
• Demonstrate Type I and Type II polyphase decomposition.
• Signal decomposition using perfect reconstruction filter bank.
• Implementation of crosstalk free two-channel transmultiplexer.
© The Author(s), under exclusive license to Springer Nature Singapore Pte Ltd. 2024 403
S. Esakkirajan et al., Digital Signal Processing,
https://doi.org/10.1007/978-981-99-6752-0_10
404 10 Multirate Signal Processing
Downsampling Type-I
Filter bank
Upsampling Type-II
2 Channel M Channel
Filter bank Filter bank
PreLab Questions
1. Mention the need to change the sampling rate of the signal.
2. What is a sampling rate converter?
3. Mention two basic operations in sampling rate conversion or multirate signal
processing.
4. What is the need for a filter before the downsampling operation? What is the
name of the filter?
5. What is the name given to the filter after upsampling operation? What is the
purpose of this filter?
6. Write the time-domain and frequency-domain expression for downsampling by
a factor of ‘M’.
7. Write the time-domain and frequency-domain expression for upsampling by a
factor of ‘L’.
8. Mention the three significant properties of the downsampling operation.
9. Why upsampling operation is considered as a linear time-variant operation?
10. What is the condition for interchanging of upsampling by a factor of ‘L’ and
downsampling by a factor of ‘M’ operation?
11. Why is downsampling by a factor of ‘M’ followed by upsampling by a factor of
‘M’ considered an idempotent operation?
12. What is the objective of polyphase decomposition? Mention the types of
polyphase decomposition.
13. What is a filter bank? Mention two applications of the filter bank.
14. Mention the threat involved in perfect reconstruction in a two-channel filter
bank? Mention the ways to overcome this threat.
15. What is a transmultiplexer? Mention its application.
10.1 Multirate Operators 405
Multirate operators are used to change the sampling rate of the signal digitally by
either by removing (deletion) of samples or inserting zeros between successive
samples. Two basic multirate operators are (1) downsampling operator and
(2) upsampling operator. The downsampling operation is used to decrease the
sampling rate of the signal, whereas upsampling operator is used to increase the
sampling rate of the signal.
From Eq. (10.1), it is possible to interpret that the output signal consists of every
Mth element of the input signal. The transform domain expression for downsampling
by a factor of ‘M’ is given by
M -1
1 1
Y ð zÞ = X zM W kM ð10:2Þ
M k=0
0
x[n]
–1
–10 –9 –8 –7 –6 –5 –4 –3 –2 –1 0 1 2 3 4 5 6 7 8 9 10
n-->
Downsampled Signal (y[n]) by (M=2)
1.0
y[n]
0.5
0.0
–10 –9 –8 –7 –6 –5 –4 –3 –2 –1 0 1 2 3 4 5 6 7 8 9 10
n-->
X[k] Y[k]
2
Inferences
From Fig. 10.3, it is possible to infer the following:
1. The input signal is x[n] = ejπn in the range -10 to 10. The input signal toggles
between +1 and -1. This is the highest frequency in the digital signal.
2. The input signal is downsampled by a factor of 2 to obtain the output signal y[n].
From Fig. 10.4, the following fact can be inferred:
1. The input signal is the highest frequency in digital signal. The signal toggles
between -1 and 1 and vice versa.
2. The signal x[n] is downsampled by a factor of 2 to obtain the output signal y[n],
which is a DC signal.
3. Downsampling operation has the ability to convert the highest frequency digital
signal to a DC signal.
4. The number of samples in the input signal is 21, whereas the number of samples
in the output signal is 11. Thus, the downsampling operation reduces the number
of samples in the input signal by a factor of ‘M’. In this case, the value of ‘M’ is 2.
Task
1. Change the value of the M = 4 in the python code given in Fig. 10.3, and observe
the result and comment on it.
Experiment 10.2 Spectrum of Downsampled Signal
The objective of this experiment is to obtain the spectrum of the downsampled
signal, and compare it with respect to the spectrum of the input signal. To accom-
plish this task, a sine wave of 5 Hz signal is generated. This signal is represented as x
[n], and its corresponding spectrum is X[k]. The signal x[n] is downsampled by a
factor of 2 to obtain the output signal y[n], and its corresponding spectrum is Y
[k]. The objective is to compare these two spectrums. The problem statement is
illustrated in Fig. 10.5.
The python code, which performs this task, is shown in Fig. 10.6, and the
corresponding output is shown in Fig. 10.7.
Inferences
From Fig. 10.6, the following inferences can be made:
1. The python code generates the sum of sine waves of 0, 2.5, 5 Hz frequency, and it
is stored in the variable ‘x’.
2. The input sine wave is downsampled by a factor of 2, and the result is stored in
the variable ‘y’.
408 10 Multirate Signal Processing
3. Using the built-in function ‘fft’ and ‘fftfreq’ in ‘scipy’ library, the spectrum of the
input signal ‘x’ and the output signal ‘y’ is obtained and stored in the variable ‘X’
and ‘Y’, respectively.
4. The magnitude spectrum of the input and output signal is obtained using the built-
in function ‘abs’, which is available in ‘numpy’ library.
From Fig. 10.7, the following inferences can be drawn:
1. From the plot of the input signal and output signal, it is possible to observe that
the length of the output signal is lesser than the length of the input signal.
2. The magnitude spectrum of the input signal has peaks at 0, 2.5 and 5 Hz, which
shows that the frequencies of the input signal are 0, 2.5 and 5 Hz.
3. The magnitude spectrum of the output signal has peaks at 0, 5 and 10 Hz, which
shows that the frequencies of the output signal are 0, 5 and 10 Hz. That is, the
bandwidth of the downsampled spectrum increased by 2 because of the
downsampling factor chosen as 2.
4. This experiment reveals that compression in the time-domain is equivalent to
expansion in the frequency domain.
10.1 Multirate Operators 409
Amplitude
Amplitude
1 1
0 0
–1 –1
0 2 4 6 0 1 2 3
Time Time
|Y(jw)|
0.5
0.2
0.0 0.0
0 10 20 30 0 10 20 30
w --> w -->
Task
1. Change the value of the M = 4 in the python code given in Fig. 10.6, and observe
the result and comment on it.
Upsampling operation increases the sampling rate by a factor of ‘L’. The upsampling
operation by a factor of ‘L’ is shown in Fig. 10.8.
The time-domain expression for upsampling by a factor of ‘L’ is given by
n
x , n = L, 2L, . . .
y ½ n] = L ð10:3Þ
0, otherwise
From Eq. (10.3), it is possible to interpret that upsampling by a factor of ‘L’ in the
time-domain is accomplished by inserting ‘L - 1’ zeros between successive samples
of the input signal x[n]. This will increase the length of the input signal; hence,
410 10 Multirate Signal Processing
Y ð zÞ = X zL ð10:4Þ
0.5
0.0
0 1 2 3 4
n-->
Upsampled Signal (y[n]) by L=2
1.0
y[n]
0.5
0.0
0 1 2 3 4 5 6 7 8 9 10
n-->
X[k] Y[k]
L
Inferences
The following inferences can be made from this experiment:
1. From Fig. 10.11, it is possible to observe that the length of the input signal x[n] is
5, whereas the length of the output signal y[n] is 10.
2. Thus, upsampling by a factor of 2 (L ) inserts one zero (L - 1) between two
successive samples of the input signal x[n].
3. Therefore, upsampling is a ‘length stretching operation’.
Experiment 10.4 Spectrum of Upsampled Signal
The objective of this experiment is to obtain the spectrum of upsampled signal and to
compare it with the spectrum of input signal. In order to accomplish this task, the
following steps are carried out:
• Generate input signal sum of sine waves with the frequency of 0, 4 and 10 Hz.
• Pass this signal through a system that upsamples the input signal by a factor (L ) of
2 to obtain the output signal.
• Plot the spectrums of the input and output signal, and comment on the observed
result.
The pictorial representation of the problem statement is shown in Fig. 10.12.
From Fig. 10.12, X[k] represents the spectrum of the input signal, and Y[k] represents
the spectrum of the output signal.
412 10 Multirate Signal Processing
The python code, which plots the spectrum of the input and upsampled signals, is
shown in Fig. 10.13, and the corresponding output is shown in Fig. 10.14.
Inferences
From Fig. 10.14, the following inferences can be drawn:
1. From the plot of the input signal and output signal, it is possible to observe that
the length of the output signal is more than the length of the input signal.
2. The magnitude spectrum of input signal has peaks at 0, 4 and 10 Hz, which shows
that the frequencies of the input signal are 0, 4 and 10 Hz.
3. The magnitude spectrum of the output signal has peaks at 0, 2 and 5 Hz, which
shows that the frequencies of the output signal are 0, 2 and 5 Hz. That is, the
bandwidth of the upsampled spectrum is decreased by 2 because of upsampling
factor chosen as 2.
10.2 Noble Identity 413
2 2
Amplitude
Amplitude
0 0
|Y(jw)|
0.5
0.2
0.0 0.0
0 5 10 0 5 10
w --> w -->
4. This experiment reveals the fact that expansion in the time-domain is equivalent
to compression in the frequency domain.
Task
1. Change the value of the L = 4 in the python code given in Fig. 10.13, and
comment on the observed spectrum result.
Noble identities describe the way to reverse the order of multirate operators and
filtering.
Fig. 10.17 Python illustration regarding noble identity for downsampling operation
y1[n]
1.0
y1[n]
0.5
0.0
0 2 4 6 8 10
n-->
y2[n]
1.0
y2[n]
0.5
0.0
0 2 4 6 8 10
n-->
Inference
From Fig. 10.18, it is possible to observe that the output y1[n] is equal to the output
y2[n]; thus, the noble identity for the downsampling operation is verified.
Fig. 10.20 Python code to illustrate noble identity for upsampling operation
y1[n]
1.0
y1[n]
0.5
0.0
0 10 20 30 40
n-->
y2[n]
1.0
y2[n]
0.5
0.0
0 10 20 30 40
n-->
Polyphase decomposition refers to the strategy through which the multirate operators
can be used to decompose the system function H(z) into its polyphase representation.
Polyphase decomposition can be broadly classified into (1) Type I polyphase
decomposition and (2) Type II polyphase decomposition.
Experiment 10.7 Python Illustration of Type I Polyphase Decomposition
This python illustration aims to prove the Type I polyphase decomposition illus-
trated in Fig. 10.22 for the downsampling factor of M = 2. In Fig. 10.22, H(z)
represents the filter, whereas E0(z) and E1(z) represent the polyphase components of
H(z). The objective is to prove y1[n] is equal to y2[n]. The filter chosen in this
illustration is a finite impulse response filter designed using the windowing
technique.
The python code which implements the Type I polyphase decomposition is
shown in Fig. 10.23, and the corresponding output is shown in Fig. 10.24.
Inference
From Fig. 10.24, it is possible to observe that the output y1[n] is equal to the output
y2[n]. Thus, the Type I polyphase decomposition is verified.
Experiment 10.8 Type II Polyphase Decomposition
Type II polyphase decomposition deals with the upsampling operation. Upsampling
operation introduces multiple copies of the original signal spectrum, which is termed
as ‘imaging’. The Type II polyphase decomposition structure is shown in Fig. 10.25.
The python illustration of Type II polyphase decomposition is shown in
Fig. 10.26, and the corresponding output is shown in Fig. 10.27.
Inference
From Fig. 10.27, it is possible to observe that the output y1[n] is equal to y2[n]. This
implies that Type II polyphase decomposition is verified.
y1[n]
1.0
y1[n]
0.5
0.0
0.0 0.5 1.0 1.5 2.0 2.5 3.0
n-->
y2[n]
1.0
y2[n]
0.5
0.0
0.0 0.5 1.0 1.5 2.0 2.5 3.0
n-->
x[n]
R0(z) 2
x[n] y1[n] z-1
2 H(z) ≡
R1(z) 2 y2[n]
Filter bank is group of filters arranged in a specific fashion. Filter bank is used to split
the signal into different frequency bands, which are termed as ‘subband coding’.
While splitting the signal into various frequency bands, the signal characteristics are
420 10 Multirate Signal Processing
y1[n]
y1[n] 0.50
0.25
0.00
0 2 4 6 8 10 12 14
n-->
y2[n]
0.50
y2[n]
0.25
0.00
0 2 4 6 8 10 12 14
n-->
H0(z) 2 2 G0(z)
y[n]
x[n]
H1(z) 2 2 G1(z)
different in each band, and different bits can be used for coding the subband signals.
This idea is used in speech and image coding. Based on the number of paths
available for the input signal, the filter bank can be broadly classified into (1) two-
channel filter bank and (2) M-channel filter bank.
Two-channel filter bank has two sections, namely, (1) analysis section and (2) syn-
thesis section, which is depicted in Fig. 10.28. The input signal fed into the two-
channel filter bank is x[n], and the output signal received from the two-channel filter
bank is y[n]. The channel represents the medium through which the data is trans-
mitted. In Fig. 10.28, the filters in the analysis section are represented as H0(z) and
H1(z). If H0(z) represents the lowpass filter, then H1(z) represents the highpass filter.
The corresponding filters in the synthesis section are G0(z) and G1(z), respectively.
10.4 Filter Bank 421
H0(z) 1 3 5 7
2 2 G0(z)
y[n]
x[n]
9
2 4 6 G1(z) 8
H1(z) 2 2
For perfect reconstruction, the output signal y[n] has to be the delayed version of
the input signal x[n]. The different threats for perfect reconstruction are (1) aliasing
problem due to downsampling operation, (2) amplitude distortion and (3) phase
distortion. Proper choice of analysis and synthesis filters will overcome the above-
mentioned threats and achieves perfect reconstruction.
Experiment 10.9 Python Implementation of Two-Channel Filter Bank
The structure of the two-channel filter bank which is implemented in this experiment
is shown in Fig. 10.29. In Fig. 10.29, different nodes are marked as 1–8.
The input signal x[n] is a sinusoidal signal of 5 Hz frequency. The choice of
analysis and synthesis filters are H 0 ðzÞ = 12 þ 12 z - 1 , H 1 ðzÞ = 12 - 12 z - 1 ,
G0(z) = 1 + z-1 and G1(z) = - 1 + z-1. The python code which implements this
two-channel filter bank is given in Fig. 10.30, and the corresponding output is shown
in Fig. 10.31.
Inferences
1. From Fig. 10.30, it is possible to observe that the filters chosen for the analysis
section are h0 ½n] = 12 , 12 and h1 ½n] = 12 , - 12 . The filters have only two
coefficients. h0[n] act as lowpass filter, whereas h1[n] act as high pass filter.
2. The variables chosen in the python code, as shown in Fig. 10.30 like x1, x2, . . .,
x8, are in line with the nodes shown in Fig. 10.29.
3. From Fig. 10.31, it is possible to observe that the output signal follows the input
signal with one sample delay. That is, perfect reconstruction is achieved through
the proper choice of filters.
H 1 ðzÞ = H ð- zÞ ð10:7Þ
0.75
0.50
0.25
Amplitude
0.00
–0.25
–0.50
–0.75 Input
–1.00 Output
Fig. 10.31 Plot of input and output signals of a two-channel filter bank
• Instead of designing four filters (2 for analysis and 2 for synthesis). It is sufficient
to design one prototype filter H(z). All the other filters are obtained as a modified
version of the prototype filter.
• If H(z) acts as lowpass filter, then H(-z) acts as highpass filter and vice versa.
Experiment 10.10 Relationship Between Analysis and Synthesis Filters
This experiment tries to obtain the magnitude response of the analysis and synthesis
filters. The python code to obtain the magnitude response of the analysis and
synthesis filters is given in Fig. 10.32, and the corresponding output is shown in
Fig. 10.33.
Inferences
From the magnitude response, the following inferences can be drawn:
1. The analysis filter h0[n] behaves like a lowpass filter.
2. The analysis filter h1[n] behaves like a highpass filter.
3. The synthesis filter g0[n] behaves like a lowpass filter.
4. The synthesis filter g1[n] behaves like a highpass filter.
5. The filters h0[n] and h1[n] are complementary to each other.
6. The filters g0[n] and g1[n] are complementary to each other.
Experiment 10.11 Phase Responses of Analysis and Synthesis Filters
This experiment discusses the phase responses of analysis and synthesis filters of
two-channel filter bank. The python code to obtain the phase response of the analysis
and the synthesis filters are given in Fig. 10.34, and the corresponding output is
shown in Fig. 10.35.
424 10 Multirate Signal Processing
Fig. 10.32 Python code to obtain the magnitude response of analysis and synthesis filters
Inferences
1. From the phase response of the analysis and synthesis filters, it is possible to infer
that the filter exhibits linear phase characteristics in the pass band.
2. Because of linear phase characteristics, phase distortion can be avoided.
3. The filters will exhibit constant group delay.
This is a special case of two-channel filter bank in which delay is introduced instead
of filters. For example, if H0(z) = 1, H1(z) = z-1, G0(z) = z-1 and G1(z) = 1, then the
structure of two-channel filter bank is modified as in Fig. 10.36.
The relationship between the input and output in the frequency-domain is
expressed as
10.4 Filter Bank 425
|H0(ejw)| |H1(ejw)|
0 0
Magnitude(dB)
Magnitude(dB)
–10 –10
–20 –20
0 1 2 3 0 1 2 3
w [rad/sample] w [rad/sample]
|G0(ejw)| |G1(ejw)|
Magnitude(dB)
Magnitude(dB)
0 0
–10 –10
–20 –20
0 1 2 3 0 1 2 3
w [rad/sample] w [rad/sample]
Upon taking inverse Z-transform, the relationship between the input and output is
given by
y ½ n] = x ½ n - 1] ð10:11Þ
Fig. 10.34 Python code to obtain the phase response of analysis and synthesis filters
The structure of three-channel filter bank is shown in Fig. 10.39. From this figure, it
is possible to infer that there are three channels and each channel contains an analysis
and synthesis filters.
If H0(z) = 1, H1(z) = z-1 and H2(z) = z-2, G0(z) = z-2, G1(z) = z-1 and
G2(z) = 1, the structure of three-channel filter bank for this choice of filters is
given in Fig. 10.40.
The frequency-domain relationship between the input and output signal is given
by
Фh0(ejw) Фh1(ejw)
0
Degree
Degree
1
–1
0
0 1 2 3 0 1 2 3
w [rad/sample] w [rad/sample]
Фg0(ejw) Фg1(ejw)
0 0
Degree
Degree
–1 –2
0 1 2 3 0 1 2 3
w [rad/sample] w [rad/sample]
1 3 5 7
1 2 2 z-1
x[n] y[n]
2 4 6 8
z-1 2 2 1
Upon taking inverse Z-transform, the time-domain relationship between the input
and output signal is given by
y ½ n] = x ½ n - 2] ð10:13Þ
Fig. 10.37 Python code which implements filter bank without filters
2. There is two sample delay between the input and output signal, which is in
agreement with the theoretical result.
The structure of uniform tree-structured filter bank is given in Fig. 10.43. The
numbers after the block are used to understand the sequence of the process of the
input signal. The same numbers are used as variables in the python code to
understand the sequence of process.
Experiment 10.14 Tree-Structured Filter Bank
This experiment illustrates the concept of tree-structured filter bank using python.
The python code for tree-structured filter bank is shown in Fig. 10.44, and the
corresponding output is shown in Fig. 10.45.
Inference
The following inferences can be made from this experiment:
10.5 Tree-Structured Filter Bank 429
1 4 7 10
H0(z) 3 3 G0(z)
5 8 11
x[n] 2
y[n]
H1(z) 3 3 G1(z)
3 6 9 12
H2(z) 3 3 G2(z)
1 4 7 10
1 3 3 z-2
2 5 8 11
x[n] y[n]
z-1 3 3 z-1
3 6 9 12
z-2 3 3 1
import numpy as np
import matplotlib.pyplot as plt
from scipy import signal
def downsample(x,M):
y=x[::M]
return(y)
def upsample(x,L):
y=np.zeros(L*len(x))
y[::L]=x
return(y)
#Define the filters
h0,h1,h2=[1],[0,1],[0,0,1]
g0,g1,g2=[0,0,1],[0,1],[1]
#Input signal
t=np.linspace(0,1,200)
x=signal.sawtooth(2*np.pi*5*t)
x1=signal.lfilter(h0,1,x)
x2=signal.lfilter(h1,1,x)
x3=signal.lfilter(h2,1,x)
x4=downsample(x1,3)
x5=downsample(x2,3)
x6=downsample(x3,3)
x7=upsample(x4,3)
x8=upsample(x5,3)
x9=upsample(x6,3)
x10=signal.lfilter(g0,1,x7)
x11=signal.lfilter(g1,1,x8)
x12=signal.lfilter(g2,1,x9)
y=x10+x11+x12
plt.plot(t,x,t,y[0:len(t)]),plt.xlabel('Time'),plt.ylabel('Amplitude')
plt.title('Input and Output signal'),
plt.legend(['Input','Output'],loc=1), plt.tight_layout()
0.50
0.25
Amplitude
0.00
–0.25
–0.50
–0.75
–1.00
0.0 0.2 0.4 0.6 0.8 1.0
Time
Fig. 10.42 Input and output signals of three-channel filter bank without filters
5 7 13 15
H0(z) 2 2 G0(z) 18
1 3 17 19
H0(z) 2 2 G0(z)
6 8 14
H1(z) 2 2 G1(z)
16 y[n]
x[n]
20
9 11 22
H0(z) 2 2 G0(z) 25
2 4 24
H1(z) 2 2 G1(z
10 26
12 21
H1(z) 2 2 G1(z)
23
10.6 Transmultiplexer
Input-Output wavefrom
1.00 Input
Output
0.75
0.50
0.25
Amplitude
0.00
–0.25
–0.50
–0.75
–1.00
0.0 0.2 0.4 0.6 0.8 1.0
Time
1 3 6 8
x[0] 2 G0(z) H0(z) 2 v[0]
5
2 4 7 9
x[1] 2 G1(z) H1(z) 2 v[1]
#Two-channel transmultiplexer
import numpy as np
import matplotlib.pyplot as plt
from scipy import signal
def downsample(x,M):
y=x[::M]
return(y)
def upsample(x,L):
y=np.zeros(L*len(x))
y[::L]=x
return(y)
#Step 1 defining x0 and x1
f,fs,N,N1=5,100,256,128;
T=1/fs
t=np.linspace(0,N*T,N)
x0=np.sin(2*np.pi*f*t)
x1=np.cos(2*np.pi*f*t)
#Step 2: Define the filters
g0,g1,h0,h1=[0, 1, 1], [0, -1, 1], [0.5, 0.5], [0.5, -0.5];
#Step3 Tracing the structure
n1=upsample(x0,2) #At node 1
n2=upsample(x1,2) #At node 2
n3=signal.lfilter(g0,1,n1) #At node 3
n4=signal.lfilter(g1,1,n2) #At node 4
n5=n3+n4 #At node 5
n6=signal.lfilter(h0,1,n5) #At node 6
n7=signal.lfilter(h1,1,n5) #At node 7
n8=downsample(n6,2) #At node 8
n9=downsample(n7,2) #At node 9
plt.subplot(2,1,1),plt.plot(t,x0,t,n8),plt.legend(['Transmitted(x0)','Received(y0)'],loc=1)
plt.xlabel('Time'),plt.ylabel('Amplitude')
plt.subplot(2,1,2),plt.plot(t,x1,t,n9),plt.legend(['Transmitted(x1)','Received(y1)'],loc=1)
plt.xlabel('Time'),plt.ylabel('Amplitude')
plt.suptitle('Transmitted and received signals in transmultiplexer')
plt.tight_layout()
Inferences
The following inferences can be drawn from Fig. 10.48:
1. The received signals are similar to the transmitted signal without distortion; thus,
crosstalk problem is avoided. The proper choice of synthesis and analysis filter
avoids the crosstalk problem.
2. Perfect reconstruction of transmultiplexer achieves complete crosstalk cancella-
tion and is distortion-free.
10.6 Transmultiplexer 435
0.0 0.0
–0.2
–0.2
0 50000 100000 0 50000 100000
Received male voice Received female voice
0.2 0.2
0.0 0.0
–0.2
–0.2
0 50000 100000 0 50000 100000
Fig. 10.50 Transmitted and received speech signals through two-channel transmultiplexer
From Fig. 10.50, it is possible to observe that the received speech signal resem-
bles the transmitted speech signal, which confirms that the two-channel
transmultiplexer is free from cross-talk.
Exercises
1. Write a python code to simulate the comb signal whose expression is given by
M-1
1 2π
x ½ n] = ej M kn , 0 ≤ n ≤ 10
M k=0
H0(z)
1 3 5 G0(z) 7
2 2
y[n]
x[n]
9
2 4 [0,0,0…0] 6 G1(z) 8
H1(z) 2 2
Objective Questions
1. Downsampling by a factor of ‘M’ is a
A. Linear, time-invariant operation
B. Linear, time-variant operation
C. Non-linear, time-invariant operation
D. Non-linear, time-variant operation
2. The time-domain expression for downsampling by a factor of ‘M’ is given by
10.6 Transmultiplexer 439
A. y½n] = x Mn
B. y[n] = x[nM]
C. y[n] = x[n]M
1
D. y½n] = x½n]M
3. The input signal x[n] is upsampled by a factor of ‘L’; then, the result is
downsampled by the same factor ‘L’ to obtain the signal y[n]. The relationship
between y[n] and x[n] is given by
A. y[n] = x[nL]
B. y[n] = x[n]
C. y½n] = x Ln
D. y[n] = x[n]L
A. y½n] = 1, 1, 1, 1
"
B. y½n] = 1, 0, 1, 0
"
C. y½n] = 1, - 1, 1, - 1
"
D. y[n] = {0, 0, 0, 0}
5. Which of the following operation is an example of an idempotent operation
A. Upsampling followed by downsampling
B. Downsampling followed by upsampling
C. Downsampling followed by downsampling
D. Upsampling followed by upsampling
6. Which of the following is an example of an identity operation
A. Upsampling followed by downsampling
B. Downsampling followed by upsampling
C. Downsampling followed by downsampling
D. Upsampling followed by upsampling
7. Which of the following results in idempotent operation
A. Downsampling by a factor of ‘M’ followed by upsampling by a factor of ‘M’
B. Upsampling by a factor of ‘M’ followed by downsampling by the same
factor
440 10 Multirate Signal Processing
Bibliography
Learning Objectives
After reading this chapter, the reader is expected to
• Implement and analyse the Wiener filter.
• Write a python code to implement the LMS algorithm and its variants.
• Perform system identification using the LMS algorithm.
• Perform inverse system modelling using the NLMS algorithm.
• Implement adaptive line enhancer using the LMS algorithm and its variants.
• Implement the RLS algorithm.
Filter
Wiener Filter
LMS Algorithm RLS Algorithm
NLMS Algorithm
© The Author(s), under exclusive license to Springer Nature Singapore Pte Ltd. 2024 443
S. Esakkirajan et al., Digital Signal Processing,
https://doi.org/10.1007/978-981-99-6752-0_11
444 11 Adaptive Signal Processing
PreLab Questions
1. List out the valid differences between the optimal filter and the adaptive filter.
2. What is an adaptive filter? How it differs from the ordinary filter.
3. Examples of adaptive filter.
4. When are adaptive filters preferred?
5. List out the performance measures of the adaptive filter.
6. What is an LMS algorithm?
7. What do you mean by least square estimation?
8. List out the variants of LMS algorithm.
9. How the step size impacts the LMS algorithm?
10. What is the RLS algorithm, and how it differs from LMS?
Wiener filter is the mean square error (MSE) optimal stationary linear filter for signal
corrupted by additive noise. The Wiener filter computation requires the assumption
that the signal and noise are in the random process. The general block diagram of the
Wiener filter is shown in Fig. 11.1. The main objective of the Wiener filter is to
obtain the filter coefficient of the LTI filter, which can provide the final output (y[n])
as much as the minimum MSE between the output and the desired signal or target (d
[n]). In Fig. 11.1, s[n] denotes the original signal, which is a clean signal, and it is
corrupted by additive noise η[n] to give the signal x[n]. The parameters of the filter
have to be designated has to be designed in such a way that the output of the filter y
[n] should resemble the desired signal d[n] such that the error ‘e[n]’ is minimum.
The expression for the optimal Wiener filter is given by
hopt = R - 1 p ð11:1Þ
#Wiener filter
import numpy as np
from numpy.random import randn
import matplotlib.pyplot as plt
from scipy.linalg import toeplitz
from scipy import signal
#Step 1: Generation of signal s[n]
t=np.linspace(0,1,100)
s=np.sin(2*np.pi*5*t)
Ns=len(s)
#Step 2: Generation of random noise
# n=randn(len(t))*0.1
n=np.random.normal(0,.2,len(s))
#Step 3: Observed signal x[n]
x=s+n
#Step 4: Autocorrelation of observed signal
rxx=np.correlate(x,x,mode='full')
#Step 5: Cross-correlation between desired and observed signal
rsx=np.correlate(s,x,mode='full')
#Step 6: Deciding the length of the filter
Nh=11
#Step 7: Trimming the autocorrelation and cross-correlation values
rxx1=rxx[Ns-1:Ns+Nh-1]
rsx1=rsx[Ns-1:Ns+Nh-1]
#Step 8: Obtaining the autocorrelation matrix
Rx=toeplitz(rxx1)
#Step 9: Inverse of the autocorrelation matrix
Rx1=np.linalg.inv(Rx)
#Step 10: Obtaining the filter coefficient
w1=np.matmul(Rx1,rsx1)
#Step 11: Filtering the noisy signal
y=signal.lfilter(w1,1,x)
plt.subplot(3,1,1),plt.plot(t,s),plt.xlabel('t-->'),plt.ylabel('Amplitude'),
plt.title('Clean signal'),plt.subplot(3,1,2),plt.plot(t,x),plt.xlabel('t-->'),
plt.ylabel('Amplitude'),plt.title('Noisy signal'),plt.subplot(3,1,3), plt.plot(t,y)
plt.xlabel('t-->'),plt.ylabel('Amplitude'),plt.title('Filtered signal'),plt.tight_layout()
Eq. (11.1). The python code for Wiener filter is shown in Fig. 11.2. Simulation result
of the python code given in Fig. 11.2 is depicted in Fig. 11.3.
The built-in functions used in python code shown in Fig. 11.2 is summarized in
Table 11.1.
Inference
From Fig. 11.3, it can be made the following observations:
446 11 Adaptive Signal Processing
Clean signal
Amplitude
1
0
–1
0.0 0.2 0.4 0.6 0.8 1.0
t-->
Noisy signal
Amplitude
1
0
–1
0.0 0.2 0.4 0.6 0.8 1.0
t-->
Filtered signal
Amplitude
1
0
–1
0.0 0.2 0.4 0.6 0.8 1.0
t-->
Table 11.1 Built-in functions used in the python code given in Fig. 11.2
S. No. Objective Built-in function Library
1 To generate a clean sinusoidal signal of 5 Hz frequency np.sin() Numpy
2 To add white noise, which follows normal distribution to np.random.nor- Numpy
clean signal mal()
3 To perform autocorrelation np.correlate() Numpy
4 To obtain the inverse of the matrix np.linalg.inv() Scipy
5 To perform convolution signal.lfilter() Scipy
1. The input or clean signal frequency is 5 Hz, and it is a smooth sine waveform.
2. The additive noise added signal as input to the Wiener filter, and it is a distorted
signal.
3. The filtered signal is not a smooth sine waveform. However, this waveform is far
better than the noisy signal. Hence, the Wiener filter has a capability to minimize
the impact of additive noise in a signal.
Task
1. Change the value of standard deviation in random noise generation python
command ‘np.random.normal(0,.2,len(s))’ given in Fig. 11.2. Execute and
make the appropriate changes in this python code to get ‘filtered signal’ as similar
as ‘clean signal’.
Experiment 11.2 Wiener Filter Using Built-In Function
This experiment performs the Wiener filtering using built-in function in ‘scipy’
library. The built-in function is available in the ‘scipy’ library ‘wiener’ can be
used to filter out the noisy components. In this experiment, noise-free sinusoidal
signal of 5 Hz frequency is generated. The clean signal is corrupted by adding
11.1 Wiener Filter 447
#Wiener filter
import numpy as np
import matplotlib.pyplot as plt
from scipy import signal
#Step 1: Generation of clean signal
t=np.linspace(0,1,100)
s=np.sin(2*np.pi*5*t)
#Step 2: Adding noise
n=np.random.normal(0,.2,len(s))
x=s+n
#Step 3: Wiener filter
y=signal.wiener(x)
#Step 4: Plotting the results
plt.subplot(3,1,1),plt.plot(t,s),
plt.xlabel('Time'),plt.ylabel('Amplitude'),plt.title('Clean signal')
plt.subplot(3,1,2),plt.plot(t,x),plt.xlabel('Time'),plt.ylabel('Amplitude'),
plt.title('Noisy signal'),plt.subplot(3,1,3),plt.plot(t,y)
plt.xlabel('Time'),plt.ylabel('Amplitude'),plt.title('Filtered signal')
plt.tight_layout()
random noise, which follows the normal distribution with zero mean and 0.2
standard deviation. The corrupted signal is then passed through the Wiener filter to
minimize the impact of noise. The steps followed along with the built-in functions
used in the program are given in Table 11.2.
The python code which performs this task is shown in Fig. 11.4, and the
corresponding output is shown in Fig. 11.5.
Inference
From Fig. 11.5, it is possible to infer that the impact of noise is minimized after
passing the noisy signal through Wiener filter.
From Wiener-Hopf equation, the expression for the optimal Wiener filter is given by
448 11 Adaptive Signal Processing
Clean signal
Amplitude
1
0
–1
0.0 0.2 0.4 0.6 0.8 1.0
Time
Noisy signal
Amplitude
1
0
–1
0.0 0.2 0.4 0.6 0.8 1.0
Time
Filtered signal
Amplitude
1
0
–1
0.0 0.2 0.4 0.6 0.8 1.0
Time
hopt = R - 1 p ð11:2Þ
p
hopt = ð11:3Þ
R
FTfpg
FT hopt = ð11:4Þ
FTfRg
Sdx ðejω Þ
H ejω = ð11:5Þ
Sxx ðejω Þ
In Eq. (11.5), H(ejω) represents the frequency response of the Wiener filter,
Sdx(ejω) represents the cross-power spectral density estimation between desired and
observed signal and Sxx(ejω) represents the power spectral density of the observed
signal.
11.1 Wiener Filter 449
Power Spectral
Density S xx (e jZ )
Power Spectral
Density S xd (e jZ )
Wiener filter
S dx (e jZ )
H ( e jZ )
S xx (e jZ )
Impulse response
h[n]
clean signal s[n]. Upon taking inverse Fourier transform of H(ejω), the impulse
response of the Wiener filter is obtained.
The python code used to implement the Wiener filter in frequency domain is
shown in Fig. 11.7, and the corresponding output is in Fig. 11.8.
The built-in functions used in the program and its purpose are given in Table 11.3.
Inference
From Fig. 11.8, the following observations can be made:
450 11 Adaptive Signal Processing
1 0
Magnitude
Amplitude
0 0.2
–1 –20
0.0 0.2 0.4 0.6 0.8 1.0 0.1
Time 0.0 –40
Noisy signal
Amplitude
Phase
x poles
Filtered signal –500
Amplitude
jZ
1
0 –1000
–1 –1
0.0 0.2 0.4 0.6 0.8 1.0 –1 0 1 0.0 0.5 1.0
Time s w
y[n]
x[n] Adaptive filter -
e[n]
4. From the pole-zero plot, it is possible to observe that poles and zeros lie within the
unit circle; hence the filter is stable.
The adaptive filter is a non-linear filter, which updates the value of the filter
coefficients based on some specific criterion. The general block diagram of the
adaptive filter is shown in Fig. 11.9. From this figure, it is possible to observe that
452 11 Adaptive Signal Processing
the filter coefficients are updated based on the error, e[n] between the output of the
filter y[n] and reference data d[n]. Examples of adaptive filters are LMS filter and
RLS filter.
The LMS is a least mean square algorithm that works based on the stochastic
gradient descent approach to adapt the estimate based on the current error. The
estimate is called the weight or filter coefficient. The weight or filter coefficient
update equation of the LMS algorithm is given by.
where w[n + 1] represents the new weight or updated weight, w[n] denotes the old
weight, μ indicates the step size or learning rate, x[n] is the input signal or data and
the error signal e[n] = d[n] - y[n]. d[n] is the reference data or target data, and y[n] is
the actual output of the adaptive filter of the system.
Experiment 11.4 Implementation of LMS Algorithm
This experiment discusses the implementation of LMS algorithm for adaptive
filtering using python. The python code to define the LMS algorithm as a function
is shown in Fig. 11.10. This code can be called a function in the different applica-
tions of the LMS algorithm, which will be discussed in the subsequent experiments.
From Fig. 11.10, it is possible to see that the weight updation formula of the LMS
algorithm given in Eq. (11.6) exists in it.
Inference
1. From Fig. 11.10, it is possible to observe that the LMS algorithm is written as a
function, and it can be called a signal processing application whenever needed.
System w(n)
e[n]
import numpy as np
import matplotlib.pyplot as plt
from scipy import signal
N1 = 500 # Size of the Input data
N = 25 # Filter size
n_iter=[10,50,100,150]# it must be less than (N1-N)
x = np.random.randn(N1) # Input to the filter
h = signal.firwin(N, 0.25) # FIR filter to be identified
t = signal.convolve(x, h) # Target/desired signal
t = t + 0.01 * np.random.randn(len(t)) # with added noise
mu = 0.04 # LMS step size
plt.figure(),plt.title('Filter to be Identified'),plt.stem(h),plt.xlabel('n-->'),plt.ylabel('h[n]')
for i in range(0,len(n_iter)):
[w,e]=LMS_algorithmm(x,mu,N,t,n_iter[i]);
plt.figure(),plt.title('Error signal at iteration %d' % n_iter[i])
plt.stem(e),plt.xlabel('n-->'),plt.ylabel('e[n]')
plt.figure(),plt.title('Identified Filter at iteration %d' % n_iter[i])
plt.stem(w),plt.xlabel('n-->'),plt.ylabel('w[n]')
2. The inputs to the LMS function are ‘x’, ‘mu’, ‘N’ and ‘t’. ‘x’ denotes the input
data, ‘mu’ represents step size, ‘t’ denotes the reference data or target data and ‘N’
indicates the length of the adaptive filter.
3. The outputs from this LMS function are ‘w’, which denotes the adaptive filter
coefficients, and ‘e’ is an error between the estimate and target data.
Experiment 11.5 System Identification Using LMS Algorithm
This experiment deals with unknown system identification using the LMS algorithm.
Let us consider the unknown system as an FIR filter with a length of 25. In this
experiment, the output filter coefficients are obtained by using LMS algorithm with
different number of iterations. The block diagram of the system identification is
shown in Fig. 11.11. The python code to find the unknown system using the LMS
algorithm is given in Fig. 11.12, and its simulation result is shown in Fig. 11.13.
454
h[n]
w[n]
w[n]
–0.02 0.00
0.05
–0.04 –0.05
0.00
–0.06 –0.10
0 5 10 15 20 25 0 5 10 15 20 25 0 5 10 15 20 25
n--> n--> n-->
Identified Filter at iteration 50 Identified Filter at iteration 100 Identified Filter at iteration 150
0.25
0.25
0.15 0.20
0.20
0.10 0.15 0.15
0.10 0.10
w[n]
w[n]
w[n]
0.05
11
0.05 0.05
0.00
0.00 0.00
–0.05
–0.05
0 5 10 15 20 25 0 5 10 15 20 25 0 5 10 15 20 25
n--> n--> n-->
x[n] Unknown
Adaptive filter
system
- y[n]
e[n]
+ d[n]
Delay
Figure 11.12 indicates that the number of iterations is considered as 10, 50,
100 and 150, and the length of the unknown FIR filter is chosen as 25. The input
to the LMS algorithm is a random signal with a length of 500 samples. The targeted
or desired or reference data is obtained by convolving the input random signal with
the unknown FIR filter coefficients along with the random noise.
Note that the inputs to the LMS algorithm ([w,e]=LMS_algorithmm(x,mu,N,t,
n_iter[i])) are random signal (x), learning rate (mu), length of the filter (N), a
reference signal (t) and number or iteration (n_iter). Also, note that the filter
coefficients (h) are not given as input to the LMS algorithm. The outputs of the
LMS algorithm are error signal (e) and identified filter output (w).
The simulation result of the python code given in Fig. 11.12 is displayed in
Fig. 11.13.
Inference
From Fig. 11.13, it is possible to observe that the adaptive filter result approaches the
original filter coefficients while increasing the number of iterations.
Task
Increase/decrease the length of the FIR filter and fix the number of iterations is 50.
Comment on the observed result.
Experiment 11.6 Inverse System Modelling Using LMS Algorithm
This experiment discusses the inverse system modelling using LMS algorithm. The
general block diagram of inverse system modelling using adaptive filter is shown in
Fig. 11.14. From this figure, it is possible to understand that the unknown system and
the adaptive filter are connected in a cascade form, and the delayed version of the
input signal act as a reference signal. The aim of adaptive filtering in this experiment
is to obtain the inverse system of the unknown system so that y[n] and d[n] will be
similar. If y[n] and d[n] are similar, then the adaptive filter is equal to the inverse of
the unknown system.
In communication systems, inverse system modelling is used as channel equal-
ization. In such scenario, the adaptive filter is termed as ‘equalizer’. Adaptive
equalizer can combat intersymbol interference. Intersymbol interference arises
because of the spreading of a transmitted pulse due to the dispersive nature of the
channel.
456 11 Adaptive Signal Processing
import numpy as np
import matplotlib.pyplot as plt
from scipy import signal
from scipy.fft import fft
mu,W=0.04,2.2 # learning rate,Channel Capacity
filt_order,t_samples,delay,trial=7,200,4,1000
noise_var,data_var=0.001,1
for i in range(0,trial):
inp=np.zeros(filt_order)
data=np.zeros(filt_order+t_samples)
v=np.zeros(filt_order+t_samples)
w=np.zeros(filt_order)
#Generation of random data and random noise
for j in range(filt_order-1,t_samples+filt_order):
data[j]=np.fix(np.random.rand(1)+0.5)*2-1
v[j]=np.fix(np.random.rand(1)+0.5)*2*np.sqrt(noise_var)-np.sqrt(noise_var)
# Impusle response of the channel
h=np.zeros(3)
for j in range(0,3):
h[j]=(1/2)*(1+np.cos(2*np.pi/W)*(j-(3-1)))
C_out=signal.convolve(h,data) # Output from Channel
Err_square=np.zeros(len(C_out))
data=np.append(np.zeros(len(h)-1), data)
v=np.append(np.zeros(len(h)-1), v)
C_outn=C_out+v;
[w,e]=LMS_algorithmm(C_outn,mu,filt_order,data,len(C_outn)-filt_order);
e=np.append(e,np.zeros(filt_order))
Err_square=Err_square+(e**2)
mse=Err_square/trial
plt.figure,plt.subplot(2,2,1),plt.stem(h),plt.title('Impulse Resp. of Channel filter')
plt.xlabel('n-->'),plt.ylabel('h1[n]'),plt.subplot(2,2,2),plt.stem(w),
plt.title('Impulse Resp. of Inverse filter'),plt.xlabel('n-->'),plt.ylabel('h2[n]')
cas=signal.convolve(w,h);#Cascade operation
mag=fft(cas);#Frequency Response
plt.subplot(2,2,3),plt.stem(cas),plt.title('Impulse Resp. of Cascaded filter'),plt.xlabel('n-->'),
plt.ylabel('h1[n]*h2[n]'),plt.subplot(2,2,4),plt.plot(np.abs(mag)),
plt.title('Mag. Resp. of Cascaded filter'),plt.xlabel('$\omega$-->'), plt.ylabel('|H($\omega$)|'),
plt.ylim(0,10),plt.tight_layout()
1 2π
1 þ cos ð n - 2Þ , n = 1, 2, 3
h½ n] = 2 W ð11:7Þ
0, otherwise
In the above equation, ‘W’ represents the channel capacity. Higher value of ‘W’
implies that the channel is more complex.
The python code to obtain the inverse of unknown system using LMS algorithm
is given in Fig. 11.15, and its corresponding simulation result is shown in Fig. 11.16.
11.2 Adaptive Filter 457
h2[n]
0.5 0.0
0.0
0.0 0.5 1.0 1.5 2.0 0 2 4 6
n--> n-->
Impulse Resp. of Cascaded filter Mag. Resp. of Cascaded filter
1.0 10.0
7.5
h1[n]*h2[n]
|H(w)|
0.5 5.0
2.5
0.0
0.0
0 2 4 6 8 0 2 4 6 8
n--> w -->
Inference
From Fig. 11.16, it is possible to perceive the following facts
1. The impulse response of the cascaded system is an impulse. This implies that the
cascade of channel filter and its inverse system results in an identity system.
2. The Fourier transform of an impulse response will result in a flat spectrum. This is
obvious by observing the spectrum of the cascaded system.
Task
1. Increase the order of the adaptive filter and obtain the impulse response of the
inverse system.
The weight updation formula for the normalized LMS algorithm is given by
β
w½n þ 1] = wT ½n] þ e½n]x½n] ð11:8Þ
k x k2 þ c
where ‘β’ is a positive constant, which controls the convergence speed of the
algorithm. ‘c’ is a small regularization parameter; it is added with the norm of the
signal x[n] to avoid the divide by zero error.
458 11 Adaptive Signal Processing
import numpy as np
import matplotlib.pyplot as plt
from scipy import signal
from scipy.fft import fft
c,beta,W=1.5,0.25,2.2 # learning rate,Channel Capacity
filt_order,t_samples,delay,trial=7,200,4,1500
noise_var,data_var=0.001,1
for i in range(0,trial):
inp=np.zeros(filt_order)
data=np.zeros(filt_order+t_samples)
v=np.zeros(filt_order+t_samples)
w=np.zeros(filt_order)
#Generation of random data and random noise
for j in range(filt_order-1,t_samples+filt_order):
data[j]=np.fix(np.random.rand(1)+0.5)*2-1
v[j]=np.fix(np.random.rand(1)+0.5)*2*np.sqrt(noise_var)-np.sqrt(noise_var)
# Impusle response of the channel
h=np.zeros(3)
for j in range(0,3):
h[j]=(1/2)*(1+np.cos(2*np.pi/W)*(j-(3-1)))
C_out=signal.convolve(h,data) # Output from Channel
Err_square=np.zeros(len(C_out))
data=np.append(np.zeros(len(h)-1), data)
v=np.append(np.zeros(len(h)-1), v)
C_outn=C_out+v;
[w,e]=NLMS_algorithmm(C_outn,filt_order,data,beta,c,len(C_outn)-filt_order);
e=np.append(e,np.zeros(filt_order))
Err_square=Err_square+(e**2)
mse=Err_square/trial
plt.figure,plt.subplot(2,2,1),plt.stem(h),plt.title('Impulse Resp. of Channel filter')
plt.xlabel('n-->'),plt.ylabel('h1[n]'),plt.subplot(2,2,2),plt.stem(w),
plt.title('Impulse Resp. of Inverse filter'),plt.xlabel('n-->'),plt.ylabel('h2[n]')
cas=signal.convolve(w,h);#Cascade operation
mag=fft(cas);#Frequency Response
plt.subplot(2,2,3),plt.stem(cas),plt.title('Impulse Resp. of Cascaded filter')
plt.xlabel('n-->'),plt.ylabel('h1[n]*h2[n]'),plt.subplot(2,2,4),plt.plot(np.abs(mag)),
plt.title('Mag. Resp. of Cascaded filter'),plt.xlabel('$\omega$-->'),
plt.ylabel('|H($\omega$)|'),plt.ylim(0,10),plt.tight_layout()
where ‘sign’ indicates the sign of the number, ‘w[n + 1]’ represents new weight and
‘e[n]’ denotes the error signal between target and estimated signal.
460 11 Adaptive Signal Processing
h2[n]
0.0
0.5
0.0 –0.5
0.0 0.5 1.0 1.5 2.0 0 2 4 6
n--> n-->
Impulse Resp. of Cascaded filter Mag. Resp. of Cascaded filter
1.0 10.0
7.5
h1[n]*h2[n]
|H(w)|
0.5 5.0
2.5
0.0
0.0
0 2 4 6 8 0 2 4 6 8
n--> w -->
Fig. 11.19 Simulation result of the python code given in Fig. 11.18
Adaptive
Algorithm
v[n]
+ y[n]
x[n] FIR d̂ [n] +
∑ z-k ∑
s[n] + Filter
-
d[n]
import numpy as np
import matplotlib.pyplot as plt
from scipy import signal
from scipy.fft import fft
f1,f2,f3,Fs=500,2000,3500,8000 # Signal and sampling freq
T=1/Fs
t=np.arange(0,1,T)
noise=np.random.randn(len(t));
d=np.sin(2*np.pi*f1*t)+np.sin(2*np.pi*f2*t)+np.sin(2*np.pi*f3*t)+noise;
delay,N,mu=10,25,0.001 # Delay,Filter length and step size
x=np.append(np.zeros(delay),d);
[w,e]=Sign_LMS_algorithmm(x,mu,N,d,len(t)-N)
y1=signal.convolve(w,x)
mag_x=fft(x)/len(x);#Frequency Response
mag_y=fft(y1)/len(y1);#Frequency Response
plt.figure(),plt.subplot(2,2,1),plt.plot(x),plt.title('Input noisy signal')
plt.xlabel('t-->'),plt.ylabel('x(t)')
plt.subplot(2,2,2),plt.plot(y1),plt.title('Denoised signal')
plt.xlabel('t-->'),plt.ylabel('y(t)')
plt.subplot(2,2,3),plt.plot(np.abs(mag_x[0:4000])),plt.title('Spectrum of noisy signal')
plt.xlabel('$\omega$-->'),plt.ylabel('|X($\omega$)|')
plt.subplot(2,2,4),plt.plot(np.abs(mag_y[0:4000])),plt.title('Spectrum of denoised signal')
plt.xlabel('$\omega$-->'),plt.ylabel('|Y($\omega$)|')
plt.tight_layout()
Fig. 11.22 Python code for adaptive line enhancer using sign LMS
of delay is chosen as 10, and length of the adaptive FIR filter is fixed as 25. The main
objective of this experiment is to recover or enhance the original signal from the
noisy input data using sign LMS algorithm. The simulation result of the python code
462 11 Adaptive Signal Processing
0 0
x(t)
y(t)
–2
–5
0 2000 4000 6000 8000 0 2000 4000 6000 8000
t--> t-->
Spectrum of noisy signal Spectrum of denoised signal
0.4 0.4
|Y(ω)|
|X(ω)|
0.2 0.2
0.0 0.0
0 1000 2000 3000 4000 0 1000 2000 3000 4000
ω--> ω-->
Fig. 11.23 Simulation result of the adaptive line enhancer using sign LMS
given in Fig. 11.22 is shown in Fig. 11.23. From the magnitude spectrum, it is
possible to observe that the noise impact is reduced by the sign LMS algorithm.
Inference
From this experiment, the following observations can be drawn:
1. From Fig. 11.23, the magnitude response of the noisy signal indicates that the
signal has three unique frequency components and noisy components.
2. The magnitude response of denoised signal has three spikes, and the impact of the
noisy components is lesser than the input magnitude response.
Task
1. Do the suitable adjustments in the parameters used in the python code given in
Fig. 11.22 to reduce the effect of noise in the denoised or enhanced signal?
Recursive least square (RLS) is an adaptive algorithm based on the idea of least
squares. The block diagram of the adaptive filter based on RLS algorithm is shown in
Fig. 11.24. From the figure x[n] is the input to the filter, d[n] is the desired signal and
the difference between the desired signal and the output of the filter is the error signal
e[n]. Forgetting factor is used in RLS algorithm to remove or minimize the influence
of old measurements. A small forgetting factor reduces the influence of old samples
and increases the weight of new samples; as a result, a better tracking can be realized
at the cost of a higher variance of the filter coefficients. A large forgetting factor
11.3 RLS Algorithm 463
P[n 1]x[n]
Computation of gain k [ n]
O x T [n]P[n 1]x[n]
Updation of Inverse
Correlation matrix P[n] ^
O1 P[n 1] k[n]x T [n]P[n 1] `
keeps more information about the old samples and has a lower variance of the filter
coefficients, but it takes a longer time to converge.
Let us define the a priori error as e½n] = d½n] - wT ½n - 1]x½n] and the weight
updation formula for the RLS algorithm is given by
P½n - 1]x½n]e½n]
w½n] = w½n - 1] þ ð11:10Þ
λ þ xT ½n]P½n - 1]x½n]
P½n - 1]x½n]
If k ½n] = λþxT ½n]P½n - 1]x½n] represents the gain, then the above expression can be
written as
The flow chart of the sequence of steps followed in RLS algorithm is shown in
Fig. 11.25. From the flow chart, it is possible to observe that the algorithm is
iterative. Proper initialization of filter coefficients is necessary for convergence.
464 11 Adaptive Signal Processing
import numpy as np
import matplotlib.pyplot as plt
from scipy import signal
from scipy.fft import fft
f1,f2,Fs=500,2000,8000 # Signal and sampling freq
T,lamda,delta=1/Fs,1.9,0.05
t=np.arange(0,1,T)
noise=np.random.randn(len(t));
d=np.sin(2*np.pi*f1*t)+np.sin(2*np.pi*f2*t)+noise;
delay,N=10,50 # Delay,Filter length
x=np.append(np.zeros(delay),d);
[w,e]=RLS_algorithmm(x,lamda,delta,N,d,len(d)-N)
y1=signal.convolve(w,x)
mag_x=fft(x)/len(x);#Frequency Response
mag_y=fft(y1)/len(y1);#Frequency Response
plt.figure(),plt.subplot(2,2,1),plt.plot(x),plt.title('Input noisy signal')
plt.xlabel('t-->'),plt.ylabel('x(t)')
plt.subplot(2,2,2),plt.plot(y1),plt.title('Denoised signal')
plt.xlabel('t-->'),plt.ylabel('y(t)')
plt.subplot(2,2,3),plt.plot(np.abs(mag_x[0:4000])),plt.title('Spectrum of noisy signal')
plt.xlabel('$\omega$-->'),plt.ylabel('|X($\omega$)|')
plt.subplot(2,2,4),plt.plot(np.abs(mag_y[0:4000])),plt.title('Spectrum of denoised signal')
plt.xlabel('$\omega$-->'),plt.ylabel('|Y($\omega$)|')
plt.tight_layout()
Fig. 11.27 Python code for adaptive line enhancer using RLS
Inference
From Fig. 11.30, it is possible to observe that proper selection of the adaptive filter
parameters like step size or learning rate, forgetting factor and regularization plays a
major role in using the adaptive filtering algorithm for the system identification
application in signal processing.
Task
Write a python code to compare the simulation result of different adaptive algo-
rithms like LMS, NLMS, sign LMS and RLS for adaptive line enhancement
application in signal processing.
Exercises
1. Execute the python code given in Fig. 11.12 and compare the estimated filter ‘w’
with the original filter coefficients ‘h’ for different length of the filter. Also,
execute the same python code and comment on the convergence of the LMS
algorithm with different values of learning rate ‘mu’, including negative value.
2. Use the python code for the sign LMS algorithm given in Fig. 11.22 to compute
the impulse response of the inverse filter and comment on the role of learning rate.
3. Modify the sign LMS algorithm based on the equation of the sign regressor
algorithm is given by w[n + 1] = w[n] + μe[n] sign {x[n]}, and compute the
impulse response of the inverse filter and comment on the simulation result.
466 11 Adaptive Signal Processing
y(t)
0 0
–2
|Y(ω)|
|X(ω)|
0.2 0.2
0.0 0.0
0 1000 2000 3000 4000 0 1000 2000 3000 4000
ω--> ω-->
Fig. 11.28 Simulation result of the python code given in Fig. 11.27
# Python code for the comparison of adaptive algorithms for system identification
import numpy as np
import matplotlib.pyplot as plt
from scipy import signal
N1 = 1500 # Size of the Input data
N = 25 # Filter size
n=np.arange(0,N,1)
n_iter=200# it must be less than (N1-N)
x = np.random.randn(N1) # Input to the filter
h = signal.firwin(N, 0.25) # FIR filter to be identified
t = signal.convolve(x, h) # Target/desired signal
t = t + 0.01 * np.random.randn(len(t)) # with added noise
mu,mu1,beta,c,lamda,delta = 0.05,0.0005,0.05,1.5,1,0.25 # LMS step size
plt.figure(1),plt.title('Filter to be Identified')
plt.stem(h),plt.xlabel('n-->'),plt.ylabel('h[n]')
[w,e]=LMS_algorithmm(x,mu,N,t,n_iter);
[w1,e1]=NLMS_algorithmm(x,N,t,beta,c,n_iter)
[w2,e2]=Sign_LMS_algorithmm(x,mu1,N,t,n_iter)
[w3,e3]=RLS_algorithmm(x,lamda,delta,N,t,n_iter)
plt.figure(2),plt.subplot(2,2,1),plt.stem(n,w,'g'),plt.xlabel('n-->'),plt.ylabel('w[n]')
plt.title('Identified by LMS'),plt.subplot(2,2,2),plt.stem(n,w1,'k'),plt.xlabel('n-->'),
plt.ylabel('w[n]'),plt.title('Identified by NLMS'),plt.subplot(2,2,3),
plt.stem(n,w2,'r'),plt.xlabel('n-->'),plt.ylabel('w[n]'),plt.title('Identified by Sign LMS')
plt.subplot(2,2,4),plt.stem(n,w3,'b'),plt.xlabel('n-->'),plt.ylabel('w[n]')
plt.title('Identified by RLS'),plt.tight_layout()
0.2 0.2
w[n]
w[n]
0.1 0.1
Filter to be Identified
0.10
Identified by Sign LMS Identified by RLS
0.05
0.00 0.2
0.02
w[n]
w[n]
0 5 10 15 20 25 0.1
n-->
0.00
0.0
0 10 20 0 10 20
n--> n-->
Fig. 11.30 Simulation result of the python code given in Fig. 11.29
4. Modify the sign LMS algorithm based on the equation of sign-sign LMS algo-
rithm is given by w[n + 1] = w[n] + μ sign {e[n]} sign {x[n]}, and compute the
impulse response of the inverse filter and comment on the simulation result.
5. Use the python code for RLS algorithm given in Fig. 11.26 to obtain the inverse
filter coefficients and comment on the simulation result. Also, comment on the
selection of the forgetting factor and regularization parameter.
Objective Questions
1. The filter which is based on the minimum mean square error criterion, is
A. Wiener filter
B. Window-based FIR filter
C. Frequency sampling-based FIR filter
D. Savitsky Golay filter
2. If ‘R’ is the autocorrelation matrix of the observed signal and ‘p’ represents the
cross-correlation between the desired signal and the observed signal, then the
expression for the Wiener-Hopf equation is
A. wopt = R × p
B. wopt = R + p
C. wopt = R - p
D. wopt = p/R
3. The weight update expression of the standard LMS algorithm is
A. w(n + 1) = w(n) + μx[n]e[n]
B. w(n + 1) = w(n) - μx[n]e[n]
C. w(n + 1) = w(n) + μx[n]e2[n]
D. w(n + 1) = w(n) - μx[n]e2[n]
468 11 Adaptive Signal Processing
4. If μ refers to the step size and λ refers to the eigen value of the autocorrelation
matrix, then the condition for convergence of LMS algorithm is given by
A. 0 < μ < 2
λmin
B. 0 < μ < 2
λmax
C. 0 < μ < 2
λ2max
D. 0 < μ < 2
λ2min
Bibliography
Learning Objectives
After completing this chapter, the reader should be familiar with the following
• Applications of signal processing in speech signals
• ECG signal analysis
• Power line signal analysis
Speech is the easiest and most widely used way of communication between humans.
The interaction between a human and a computer is typical in the current scenario in
the communication field. Communication between humans and computers can be
made possible only with the help of hardware devices like keyboards, touch screens,
mice, etc. However, humans prefer a more natural form of interaction than hardware
devices. The speech signal is the most profound means of communication human
beings use. For the human to human interaction, voice is the most significant feature,
which helps us to recognize the speaker and extract the information from the
speaker. The speech recognition system can be used to create documents from
© The Author(s), under exclusive license to Springer Nature Singapore Pte Ltd. 2024 469
S. Esakkirajan et al., Digital Signal Processing,
https://doi.org/10.1007/978-981-99-6752-0_12
470 12 Case Study
Speaker
Modelling Speaker
Speech Feature Model
Signal Extraction Database
Pattern
Matching
Decision Decision/
Logic Output
speech, saving more time and reducing the burden on a human. In general, voice
samples contain more information, including the person’s gender and age. We can
distinguish whether the voice belongs to a male or female, child or adult, based on
the voice samples. Also, sometimes it reflects the state of mind of the speaker. The
voice recognition method uses some of the information in the voice and identifies the
speaker. Voice recognition is a technique that detects a voice sample from unique
properties that may be acoustic or phonetic.
The general block diagram of speech recognition system contains feature extrac-
tion, speaker modelling and pattern matching method to identify the speaker, which
is illustrated in Fig. 12.1. In the first stage, a speech sample is considered an input to
the system. Here the speech sample would be noise-free; to remove the noise
components in the speech signal, preprocessing method can be used. The
preprocessed speech signal is the input to the feature extraction process in the second
stage of the system. Using the feature extraction approaches, some properties of
speech, like acoustic or phonetic features, are extracted. Finally, in the third stage,
training and testing of the speech recognition model is developed, which will give
the final decision of the system (i.e.,) which speech belongs to whom.
Similarity
Similarity
Reference Model
Speaker - N
Reference
Model Speakers
(Database)
12.1.3.1 Pre-emphasis
The voice samples are passed through a highpass filter, which is mathematically
expressed as
where x[n] is the input voice samples, ‘a’ is the filter constant and it takes the value
between 0.9 to 1.0 and y[n] denotes the filtered voice samples. In this pre-emphasis
process, the input voice samples are passed through a highpass filter, and the filtered
output will emphasize the high-frequency component present in the input voice
samples.
The python code to read, normalize and display audio files is shown in Fig. 12.5,
and its simulation results are shown in Fig. 12.6.
From Fig. 12.6, it is possible to observe that the amplitude of the original audio
signal is [-20,000, 20,000], whereas in the normalized audio, the amplitude varies
from -1 to 1.
The speech signal is divided into small segments with a duration of 20–30 ms, which
are called ‘frames’. While splitting the input voice samples may be allowed to
overlap between the successive segments. Windowing can be used to avoid discon-
tinuity between consecutive segments. Also, the windowing technique smooths the
extreme samples in both starting and ending of the segments. The commonly used
windowing function is Hamming or Hanning. The process of windowing the input
sequence is mathematically written as
import numpy as np
from scipy.io import wavfile
import scipy.fftpack as fft
from scipy.signal import get_window
import IPython.display as ipd
import matplotlib.pyplot as plt
audio1 = "DSP_UV.wav"
sample_rate, audio = wavfile.read(audio1)
ipd.Audio(audio1)
audio2=audio[50000:100000]
duration = len(audio2)/sample_rate
print(f"Sample rate: {sample_rate}Hz")
print(f"Audio duration: {duration}s")
t = np.linspace(0,duration,len(audio2))
plt.figure(figsize=(15,6)),plt.plot(t,audio2),plt.xlabel("Time (s)"),plt.ylabel("Amplitude")
plt.title("Original Audio in Time domain"),plt.show()
#Normalizing to amplitude ranging between +1 and -1
normalizedAudio = audio2/np.max(np.abs(audio2))
plt.figure(figsize=(15,6)),plt.plot(t,normalizedAudio),
plt.xlabel("Time"),plt.ylabel("Amplitude")
plt.title("Normalized Audio in Time domain"),plt.show()
Fig. 12.5 Python code for read, normalize and display audio file
–20000
0.0 0.2 0.4 0.6 0.8 1.0
Time (s)
Normalized Audio in Time domain
1
Amplitude
–1
0.0 0.2 0.4 0.6 0.8 1.0
Time (s)
Fig. 12.7 Python code for framing and windowing audio signal
Hanning Window
Amplitude
1
0
0 500 1000 1500 2000
Samples
Before Windowing
Amplitude
0
–10000
0 500 1000 1500 2000
Samples
After Windowing
Amplitude
5000
0
–5000
0 500 1000 1500 2000
Samples
audio_winT = np.transpose(audio_win)
audio_fft = np.empty((int(1 + FFT_size // 2), audio_winT.shape[1]), dtype=np.complex64, order='F')
for n in range(audio_fft.shape[1]):
audio_fft[:, n] = fft.fft(audio_winT[:, n], axis=0)[:audio_fft.shape[0]]
audio_fft = np.transpose(audio_fft)
frameNo = 72
f_axis = fft.fftfreq(audio_framed[frameNo].size,1/sample_rate)[0:audio_framed[frameNo].size//2]
plt.figure
plt.plot(f_axis,2/audio_framed[frameNo].size*np.abs(audio_fft[frameNo][0:audio_framed[0].size//2]))
plt.title(f"FFT of Frame:{frameNo}")
plt.xlabel("Frequency"),plt.ylabel("Magnitude")
plt.show()
audio_power = np.square(np.abs(audio_fft))
print(audio_power.shape)
freq_min = 0
freq_high = sample_rate / 2
mel_filter_num = 10
print(f"Minimum frequency: {freq_min}"),print(f"Maximum frequency: {freq_high}")
magnitude spectrum. The output of the python code given in Fig. 12.9 is displayed in
Fig. 12.10. Frame number 72 is displayed.
476 12 Case Study
1400
1200
1000
Magnitude
800
600
400
200
0
0 5000 10000 15000 20000 25000
Frequency in (Hz)
Frequency
Y ½k ] = X ½k ] × H ½k ] ð12:3Þ
where H[k] is the magnitude spectrum of the triangular bandpass filter. The sample
triangular bandpass filter frequency responses are shown in Fig. 12.11. This figure
shows a set of triangular filters that are used to compute weighted sum of filter
spectral components so that the output of process approximates to a mel scale. Each
filter’s magnitude response is triangular in shape, and the magnitude is unity at the
centre frequency and decreases linearly to zero at the centre frequency of two
adjacent filters. The final output is the sum of its filtered spectral components.
12.1 Case Study 1: Speech Recognition Using MFCC (Mel-Frequency. . . 477
def freq_to_mel(freq):
return 2595.0 * np.log10(1.0 + freq / 700.0)
def met_to_freq(mels):
return 700.0 * (10.0**(mels / 2595.0) - 1.0)
The python code to design a mel-filter bank and normalized mel-filter bank is
shown in Fig. 12.12. The simulation result of the python code given in Fig. 12.12 is
shown in Fig. 12.13.
Figure 12.13 shows that the gain of the filters in the mel-filter bank is unity,
whereas, in the normalized mel-filter bank, the gain of the filters is different.
478 12 Case Study
The logarithmic function is used to compute cepstral components from the filtered
acoustic signal. The python code to compute the cepstral components is given in
Fig. 12.14, and its simulation result is shown in Fig. 12.15. This figure makes it
possible to understand the use of the logarithmic function for the MFCC computa-
tion. The amplitude of the filtered signal is too high; the role of the logarithmic
function is to reduce the amplitude level.
1ell
Filtered Signal
Amplitude 1.0
0.5
0.0
0 2 4 6 8
Time in (sec)
Log Power Spectrum
100
Magnitude
50
0 2 4 6 8
Frequency in (Hz)
L-1
πn 1
C ½ n] = Y ½k] cos k- ð12:4Þ
k=0
N 2
8 40
20
MFCC
6
0
4 –20
–40
2
–60
0 –80
0 2 4 6 8 10
Frames
significance, and its detection is the first stage of ECG signal processing. From the
position of the QRS complex, it is possible to obtain the positions of P and T waves.
The normal ECG signal with different intervals of wavelets is shown in Fig. 12.18.
From this figure, it is possible to know that, in particular, QRS complex as compared
to the other waves has the steepest slope, has the highest amplitude in most cases,
12.2 Case Study 2: QRS Detection in ECG Signal Using Pan-Tomkins Algorithm 481
lasts for less than 0.2 s, has a peak at R and is preceded by a P wave and succeeded
by a T wave for a normal ECG.
QRS detection consists of three major processing steps; they are (1) linear digital
filtering, (2) non-linear transformation and decision rule algorithms. Let us discuss
the Pan and Tompkins QRS detection algorithm in this case study. This algorithm
starts with the linear process, which includes a bandpass filter, a derivative operation
and moving window integration. The second step is the non-linear transformation,
which uses amplitude squaring. The final stage is a decision rule algorithm, which
includes adaptive thresholds and QRS detection. The block diagram of QRS com-
plex detection in ECG using the Pan and Tompkins algorithm is given in Fig. 12.19.
The normal ECG signals are time-varying with small amplitude ranging from 10 μV
to 5 mV. The typical amplitude of the ECG signal is 1 mV and their frequencies vary
from 0.05 to 100 Hz. The ECG signal is mainly concentrated in the 0.05–35 Hz
482 12 Case Study
range. For the ECG signal analysis, the system requires a noise-free ECG signal to
get an accurate prediction. However, ECG signals are affected by various noises and
artifacts practically. The ECG analysis system’s first step is to remove its noise by
using the filter.
The bandpass filter is used to reduce the effect of muscle noise, powerline interfer-
ence, baseline wander and T wave interference. The desirable passband frequency to
maximize the QRS energy is approximately 5–15 Hz. In this case study, the
Butterworth filter is used with order 3, and passband frequency [0.5, 15]
Hz. Instead of bandpass filter, cascaded lowpass and highpass filters may be
preferred. Filtering the ECG signal, ‘butter’ and ‘lfilter’ python commands are
used here. The python code to read the ECG data and noise removal is given in
Fig. 12.20, and its corresponding output is shown in Fig. 12.21.
From Fig. 12.21, it is possible to observe that the raw ECG signal has shifted the
amplitude to 1 mV, whereas the filtered ECG signal amplitude is between -1
and +1.
Amplitude in mV
3
1
0 500 1000 1500 2000 2500
Time-->
Filtered ECG Signal
Amplitude in mV
–1
0 500 1000 1500 2000 2500
Time-->
After bandpass filtering, the ECG signal is differentiated to provide QRS complex
slope information. ‘np.ediff1d’ python command is used here to obtain the derivative
of the filtered ECG signal. The first-order derivative equation can be written as
x ½ n - 1] - x ½ n]
y ½ n] = ð12:5Þ
2
where x[n] denotes the input signal and y[n] represents the derivative output signal.
After the derivative, the resultant signal is squared point by point. The squaring
operation can be written as
y ½ n] = x2 ½ n ] ð12:6Þ
The squaring operation makes all the data points positive and does non-linear
amplification of the derivative output emphasizing the higher frequencies.
484 12 Case Study
1
y ½ n] = fx½n - ðN - 1Þ] þ x½n - ðN - 2Þ] þ ⋯ þ x½n]g ð12:7Þ
N
where N is the number of samples in the width of the integration window. In this case
study, the length of the integration window is chosen as 15. The length of the moving
window integration (N ) is important for QRS wave detection. Generally, the value of
N should be approximately the same as the widest possible QRS complex. If the
window length (N ) is large, the integration waveform will merge the QRS complex
and T wave together. If the window length (N ) is small, some QRS complexes will
produce several peaks in the integration waveform. This may cause difficulty in the
subsequent QRS detection. The python code for the derivative process, squaring and
moving window integration is shown in Fig. 12.22, and its corresponding output is
displayed in Fig. 12.23.
The QRS wave corresponds to the rising edge of the integrated waveform. The time
duration of the rising edge is equal to the width of the QRS wave. A fiducial mark for
the temporal location of the QRS wave can be obtained from the rising edge, and the
desired waveform point is marked as peak of the R wave. The python code for the
Fig. 12.22 Python code for derivative, squaring and moving window integration
12.2 Case Study 2: QRS Detection in ECG Signal Using Pan-Tomkins Algorithm 485
Amp. in mV
0.25
0.00
–0.25
0 500 1000 1500 2000 2500
Time-->
Squared Derivative output
Amp. in mV
0.05
0.5
0.0
0 500 1000 1500 2000 2500
Time-->
peak detection of the integrated ECG measurement is given in Fig. 12.24. From this
figure, it is possible to observe that the position of the peak value results in the
variable ‘ind’ and the detected peak value can be obtained in the variable
‘detected_peaks_vals’.
486 12 Case Study
The decision rule consists of adaptive threshold selection. The thresholds are
adjusted automatically based on the noise in the ECG signal. The adaptive two
thresholds (Th1 and Th2) are calculated using the equation given below.
where NPK represents the running estimate of noise peak and SPK denotes the
running estimate of the signal peak, which are computed as
Fig. 12.25 Python code for adaptive threshold selection and QRS detection
0.4
0.2
0.0
0 500 1000 1500 2000 2500
Time-->
Filterd ECG with R peak marked
Amplitude in mV
–1
0 500 1000 1500 2000 2500
Time-->
Fig. 12.26 Simulation result of the python code given in Fig. 12.25
488 12 Case Study
Signal Processing
Simulation of PQD Analysis of PQD
Techniques
quality disturbances. The second step is to analyse different types of power quality
disturbances using time-frequency and time-scale representation.
The mathematical models of different types of power quality disturbances are
given in Table 12.2.
The generation of various power quality disturbances like voltage sag, voltage swell
and momentary interruption are simulated, and their results are plotted. The python
code which generates various power quality disturbances is shown in Fig. 12.28, and
the corresponding output is shown in Fig. 12.29.
The following observations can be drawn from Fig. 12.29:
1. The amplitude of a pure sine wave varies from -1 to +1. It is a sine wave of 50 Hz
frequency.
2. During the power quality disturbance ‘sag’, the amplitude of sine wave decreases
for a brief period of time.
3. During the power quality disturbance ‘swell’, the amplitude of sine wave
increases for a brief period of time.
4. During ‘momentary interruption’, the amplitude of sine wave approaches zero
value for a brief period of time.
5. During power quality disturbance, the characteristics of the signal (amplitude of
the signal) vary with respect to time; hence, the power quality disturbances can be
considered as a non-stationary signal.
490 12 Case Study
0 0
–1 –1
0.00 0.05 0.10 0.15 0.20 0.00 0.05 0.10 0.15 0.20
Time Time
0 0
–1
–1
0.00 0.05 0.10 0.15 0.20 0.00 0.05 0.10 0.15 0.20
Time Time
import numpy as np
import matplotlib.pyplot as plt
A,fs,f,N,ph = 1,1000,50,200,0
T = 1/fs
t = np.linspace(0,N*T,N)
#Pure sine wave
pure_sine=np.sin(2*np.pi*f*t+ ph)
#Power quality disturbance
har = np.sin(2*np.pi*f*t+ ph)+0.2*np.sin(2*np.pi*3*f*t+ ph)+0.3*np.sin(2*np.pi*5*f*t+ ph)
lamda=0.2
k=50
flicker=(1+lamda*np.sin(k*2*np.pi*f*t+ ph)) * np.sin(2*np.pi*f*t+ ph)
#Plotting the results
plt.subplot(3,1,1),plt.plot(t,pure_sine),plt.xlabel('Time'), plt.ylabel('Amplitude'),
plt.title('Pure sine wave')
plt.subplot(3,1,2),plt.plot(t,har),plt.xlabel('Time'), plt.ylabel('Amplitude'),
plt.title('Harmonics')
plt.subplot(3,1,3),plt.plot(t,flicker),plt.xlabel('Time'), plt.ylabel('Amplitude'),
plt.title('Flicker')
plt.tight_layout()
1
0
–1
0.000 0.025 0.050 0.075 0.100 0.125 0.150 0.175 0.200
Time
Harmonics
Amplitude
1
0
–1
0.000 0.025 0.050 0.075 0.100 0.125 0.150 0.175 0.200
Time
Flicker
Amplitude
1
0
–1
0.000 0.025 0.050 0.075 0.100 0.125 0.150 0.175 0.200
Time
The other power quality disturbances like ‘harmonics’ and ‘flicker’ are simulated
using python. The python code which performs this task is shown in Fig. 12.30, and
the corresponding output is shown in Fig. 12.31.
492 12 Case Study
Fig. 12.32 STFT of sinusoidal signal and sinusoidal signal with ‘sag’
12.3 Case Study 3: Power Quality Disturbance Detection 493
Amplitude
0 0
–1 –1
0.0 0.1 0.2 0.0 0.1 0.2
Time Time
Spectrogram of sine wave Spectrogram of Sag
400 400
Frequency
0 0
0.05 0.10 0.15 0.20 0.05 0.10 0.15 0.20
Time Time
From Fig. 12.33, it is possible to infer that the short-time Fourier transform of
pure sinusoidal signal shows a horizontal line at 50 Hz, which indicates that the
generated sinusoidal signal has a 50 Hz frequency component. The STFT of the sag
waveform clearly indicates the starting and ending of the sag in the sinusoidal
waveform.
The python code to obtain the time-frequency representation of a sinusoidal
signal with momentary interruption is given in Fig. 12.34, and its simulation result
is depicted in Fig. 12.35.
Figure 12.35 represents the time-frequency representation of momentary inter-
ruption in a power line signal. Momentary interruption refers to zeroing of the
amplitude of the sinusoidal signal for a brief period of time. From Fig. 12.35, it is
possible to observe that the time-frequency representation of momentary interruption
is different from the time-frequency representation of the pure sinusoidal waveform.
Thus, time-frequency representation clearly distinguishes pure sinusoidal signal
from momentary interruption.
#Time-Frequency representation of MI
import numpy as np
import matplotlib.pyplot as plt
A,fs,f,N,ph = 1,1000,50,256,0
T = 1/fs
t = np.linspace(0,N*T,N)
#Pure sine wave
pure_sine=np.sin(2*np.pi*f*t+ ph)
#Generation of sag
mi = np.sin(2*np.pi*f*t+ ph) - 0.98*np.sin(2*np.pi*f*t+ ph)*((t<0.15)&(t>0.08))
#Plotting the signal and its STFT
plt.subplot(2,2,1),plt.plot(t,pure_sine),plt.xlabel('Time'), plt.ylabel('Amplitude'),
plt.title('Pure sine wave')
plt.subplot(2,2,2),plt.plot(t,mi),plt.xlabel('Time'), plt.ylabel('Amplitude'),
plt.title('Momentary interruption')
plt.subplot(2,2,3),plt.specgram(pure_sine, Fs=fs, NFFT=16, noverlap=1,window =None)
plt.xlabel('Time'),plt.ylabel('Frequency'),plt.title('Spectrogram of sine wave')
plt.subplot(2,2,4),plt.specgram(mi, Fs=fs, NFFT=16, noverlap=1,window =None)
plt.xlabel('Time'),plt.ylabel('Frequency'),plt.title('Spectrogram of MI')
plt.tight_layout()
Amplitude
0 0
–1 –1
0.0 0.1 0.2 0.0 0.1 0.2
Time Time
Spectrogram of sine wave Spectrogram of MI
400 400
Frequency
Frequency
200 200
0 0
0.1 0.2 0.1 0.2
Time Time
Amplitude
0 0
–1 –1
0.0 0.1 0.2 0.0 0.1 0.2
Time Time
7.5 7.5
Scale
Scale
5.0 5.0
2.5 2.5
0 25 50 75 100 125 150 175 200 0 25 50 75 100 125 150 175 200
Time Time
Bibliography
1. Lawrence Rabiner and Ronald Schafer, “Theory and Applications of Digital Speech Processing”,
Pearson, 2010.
2. Rangaraj M. Rangayyan, “Biomedical Signal Analysis: A Case-Study Approach”, Wiley-
Blackwell, 2002.
3. Tompkins Willis J, “Biomedical Digital Signal Processing: C-Language Examples and Labora-
tory Experiments for the IBMR PC”, Prentice Hall India Learning Private Limited, 1998.
4. Waldemar Rebizant, Janusz Szafran, and Andrzej Wiszniewski, “Digital Signal Processing in
Power System Protection and Control”, Springer, 2011.
5. S. Esakkirajan, T. Veerakumar and Badri N Subudhi, “Digital Signal Processing”, McGraw
Hill, 2021.
Appendix
© The Author(s), under exclusive license to Springer Nature Singapore Pte Ltd. 2024 497
S. Esakkirajan et al., Digital Signal Processing,
https://doi.org/10.1007/978-981-99-6752-0
498 Appendix
the data type of the output array. The length of the array can be computed using
the command ceil((stop-start)/step).
Example: np.arange(0,1,0.1) generates array of numbers as array([0. , 0.1,
0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9]). The length of the array is 10. By default,
'np.arange' command does not allow to include the end point value.
3. Most of the real-world phenomenon like motion of pendulum, under damped
spring-mass system can be expressed as sinusoidal signal. The sinusoidal signal
is a periodic signal, which varies smoothly with respect to time. According to
Fourier series, it is possible to represent periodic signals as sum of sinusoids.
Also, sinusoidal signals are eigen functions of linear time-invariant systems.
4. The term ‘phase’ refers to position of the waveform with respect to the origin.
The phase of the signal is measured in degrees or radians.
5. Multidimensional signals require more than one independent variable to repre-
sent the signal. Examples of multidimensional signal include (a) grey scale
image, (b) colour image and (c) video. Grey scale image is represented as
f(x, y), where ‘x’ and ‘y’ are termed as spatial variable. The colour image is
represented as f(x, y, λ), where ‘λ’ represents colour information. The video
signal is basically sequence of image, which is represented as f(x, y, λ, t). The
video signal is characterized by both spatial and temporal information.
6. (a) The equation of current through the diode is given as
VD
I D = I s eηV T - 1
In the above expression, VD is the voltage across the diode and ID is the
current through the diode; VT is the volt-equivalent of temperature, which is
26 mV at room temperature, and η is the ideality factor, which is material
dependent. Thus, the current through the diode is modelled as an exponential
function. In this case, it is an exponentially growing function.
(b) The equation for radioactive decay is expressed as
A = A0 e - λt
where ‘A’ is the ending activity and A0 is the initial activity, λ = 0:693
T1 , where
2
T 12 is the half-life period of the element. Thus, the radioactive decay is modelled
as exponentially decaying function.
7. Few significant features of complex exponential function are
Appendix 499
sinðπt Þ
sin cðt Þ =
πt
The sinc function is an even function sinc(-t) = sin c(t). Few significant
features of sinc function are
(a) Sinc functions are used in the interpolation of signals
(b) Sinc and rectangular functions are dual function. Fourier transform of sinc
function results in rectangular function and vice versa.
9. A stationary signal is one whose statistical characteristics do not vary with
respect to time. Example is x(t) = A sin (2πft + ϕ). Here the frequency of the
signal does not change with respect to time. It is considered as stationary. A non-
stationary signal is one whose statistical characteristics change with respect to
time. Example of non-stationary signal includes y(t) = A sin (2πft2). Here the
frequency of the signal changes with respect to time. It is considered as
non-stationary. Chirp signal is considered as non-stationary signal.
10. The Gaussian function is characterized by two parameters, which are (a) mean
and (b) standard deviation. Few significant features of Gaussian functions are
(a) Gaussian functions are used as smoothing functions. The extent of smooth-
ing is governed by the standard deviation.
(b) Fourier transform of a Gaussian function result in another Gaussian
function.
Q. No. 1 2 3 4 5 6 7 8 9 10
Key D C A B C B B D B A
500 Appendix
1. The steps involved in converting the analogue signal into a digital signal are
(a) sampling, (b) quantization and (c) encoding. Before sampling, it is necessary
to ensure that the signal to be sampled is bandlimited. Sampling converts a
continuous-time signal into a discrete-time signal. Quantization is basically
mapping a large set of values to a smaller set of values. In quantization, the
discrete-time signal is converted to a quantized signal. In encoding, the quan-
tized signal is converted to a digital code.
2. The sampling theorem specifies the minimum sampling rate so that the sampled
signal can be reconstructed from its samples without aliasing problem. In order
to reconstruct the signal from the samples without an aliasing problem, the
sampling frequency must be greater than twice the maximum frequency content
of the signal. This is expressed as fs ≥ 2fmax, where fs represents the sampling
frequency and fmax represents the maximum frequency content of the signal.
3. Suppose the signal is a periodic and ideal interpolation is employed. In that case,
all spectral components less than fs/2 (where fs represents the sampling fre-
quency) are reconstructed perfectly, but all higher-frequency spectral compo-
nents are aliased to a frequency less than fs/2.
4. The square wave is not a bandlimited signal. It is not possible to reconstruct the
square wave from its samples.
5. Two prominent reasons for aliasing while performing sampling are
(a) undersampling and (b) signal which is not a bandlimited signal. Here
undersampling implies that the sampling rate fs < 2fmax, where fmax is the
maximum signal frequency.
6. Sampling is basically taking specific instants of the signal. The sampling rate (fs)
is the number of samples per second. Sampling interval (Ts) is the time-interval
between two consecutive samples.
7. Nyquist rate = 2B = 2 × 5 kHz = 10 kHz.
8. Quantization is mapping a large set of values to a smaller set of values. It will not
obey the superposition principle; hence, it is considered as non-linear
phenomenon.
9. Quantization maps a large set of values to a smaller set of values. It is not a one-
to-one mapping; hence, error is inevitable, and it is considered as irreversible
phenomenon. The meaning is that it is difficult to get the original signal exactly
after quantization.
10. The process of converting sampled data sequences to a continuous-time signal is
termed as signal reconstruction. Different strategies include (a) zero-order hold,
(b) first-order hold or linear interpolation and (c) ideal or sinc interpolation.
Appendix 501
Q. No. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Key B A A B D A B C B D B C D B C
x[n] y[n]
h[n]
ω
6. Discrete-time signal x[n] is periodic if it obeys the condition 2π = Nk . Here, ‘ω’
represents the angular frequency, and ‘N’ represents the fundamental period.
7. The energy and power signal descriptions are summarized in Table A.1.
8. Various mathematical operations that can be performed on DT signal include
(a) folding or time reversal; (b) shifting operation, which include delay and
advance operation; and (c) scaling operation, which could be time scaling
operation, like downsampling and upsampling, and amplitude scaling operation.
9. A DT signal is even if it obeys the condition x[-n] = x[n]. A DT signal is odd if
x[-n] = -x[n]. Example of even signal is cosine signal, whereas example of
odd signal is sinusoidal signal. Example of signal which is neither even and nor
odd includes unit step signal and unit ramp signal.
10. An energy signal has finite energy, whereas power signals have finite average
power. There are certain signals, which are neither energy nor power signal.
Example of finite energy signal is x[n] = (1/2)nu[n]. Example of power signal is
unit step signal. Example of signal which is neither energy nor power signal is
unit ramp signal.
11. Convolution is one of the most important operations in signal processing. The
three main mathematical operations involved in convolution are
(a) multiplication, (b) addition and (c) shifting operation. Convolution basically
performs filtering operation. It is represented in Fig. A.2
In Figure A.2, the input and output signals are represented as x[n] and y[n]
respectively. The impulse response of linear time-invariant system is denoted as
h[n]. The nature of filtering is decided by h[n]. If h[n] = {0.5, 0.5}, the system
behaves like a lowpass filter; on the other hand if h[n] = {0.5, -0.5}, the system
behaves like a highpass filter. The nature of filtering is decided by the impulse
response of the system. The expression for the output of the system is given by y
[n] = x[n] * h[n], where ‘*’ denotes the convolution operation.
The correlation between two signals x1[n] and x2[n] is given by
Appendix 503
Convolving the folded version of sequence x2[n] with the sequence x1[n]
results in correlation of the signal. The correlation can be broadly classified into
(a) autocorrelation and (b) cross-correlation. Autocorrelation is finding the
relative similarity of the signal with itself.
Applications of correlation are summarized below:
(a) Correlation is used to find the relative similarity between signals.
(b) Fourier transform of autocorrelation function gives the power spectral
density of the signal. This is regarded as Wiener-Khinchin theorem.
(c) Correlation can be used to estimate the pitch of the speech signal.
(d) Correlation can be used for template matching.
Q. No. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Key B B C B B C B C D C B B C D B
Q. No. 16 17 18 19 20 21 22 23 24 25
Key B B A B A D C B
system are as follows: (a) y[n] = x[-n], (b) y[n] = nx[n], (c) y[n] = Ax[n], (d) y
[n] = x[Mn] and (e) y[n] = x[n/L].
4. Cascade of two non-linear systems may result in a linear system. For example,
consider the cascade of two systems as shown below:
For system 1: The relationship between the input and output is given by v
[n] = log {x[n]}.
For system 2: The relationship between the input and output is given byy
[n] = exp {v[n]}.
It can be observed that both System-1 and System-2 are non-linear system,
whereas the cascaded system is a linear system. This implies that cascading of
two non-linear systems need not be always non-linear.
5. A discrete-time system is causal, if its current output should not depend on the
future value of the input. A real-world system cannot react to future input;
hence, they are considered as causal systems.
6. A system is memory-less if the current output of the system depends on the
current input. All the memoryless systems are causal. A causal system is
non-anticipatory. For a causal system, the current output will not depend on
the future value of the input. For a causal system, the current output depends on
the past input. If the system output depends on the past input, it is a memoryless
system. Hence, all memoryless systems are causal, whereas all causal systems
are not memoryless. For example, y[n] = Ax[n] is a memory less system, which
is also causal. Consider the system y[n] = Ax[n] + Bx[n - 1]; the system is
causal, whereas it is not memory less.
7. Consider the cascade of two discrete-time time varying system, which is
depicted below.
Q. No. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Key D D A A D D C D A A B B C D C
Chapter 5: Transforms
1
X ðzÞ = x½n]z - n
n= -1
1
-n
X ejω = x½n] rejω
n= -1
1
X ejω = x½n]e - jωn
n= -1
X k j2πf k t X *k - j2πf k t
N
xð t Þ = X 0 þ e þ e
k=1
2 2
Q. No. 1 2 3 4 5 6 7 8 9 10 11
Key C C B B B C B C D C B
1. If h[n] represents the impulse response of the lowpass filter, then the filter whose
impulse response is (-1)nh[n] will act as a highpass filter.
2. A discrete-time system with transfer functionH(z) is a minimum phase system if
the following conditions are met.
(a) All the zeros of the system are inside the unit circle centred about the origin.
(b) All the poles of the system are inside the unit circle centred about the origin.
(c) The numerator and the denominator of the transfer function (H(z)) have
equal orders of ‘z’.
3. The transfer function of a discrete-time system is given by H(z) = B(z)/A(z). The
frequencies for which the values of the denominator and numerator become zero
in a transfer function are called poles and zeros. Poles are the roots of the
denominator of a transfer function. Similarly, zeros are the roots of the numer-
ator of the transfer function. For a discrete-time system to be stable, the poles of
the system should lie within the unit circle.
4. For a discrete-time system to be stable, (a) the poles of the system should lie
within the unit circle, and (b) the impulse response should be absolutely
summable.
5. The basic principle underlying the pole-zero placement method is to locate poles
near points of the unit circle corresponding to frequencies to be emphasized and
locate zeros near the frequencies to be deemphasized. All the poles should be
placed within the unit circle for the filter to be stable. All complex zeros and
poles must occur in complex conjugate pairs for the filter coefficients to be real.
6. All-pass filters can be used as delay equalizer or phase equalizer. When an all-
pass filter is placed in cascade with a system that has an undesired phase
response, a phase equalizer is designed to compensate for the poor phase
characteristics of the system such that the cascaded system will exhibit linear
phaseresponse.
7. Notch filter is used to eliminate one particular frequency. It is used to minimize
power line interference in biomedical equipment. It can be used in radio
receivers to remove unwanted interfering frequencies.
Appendix 509
8. Moving average filter basically performs lowpass filtering of the input signal.
Lowpass filter converts drastic variation in the signal to a gradual variation.
When a square wave is fed as input to the M-point moving average filter, the
output will be a triangular wave. Square wave exhibits sharp transition between
‘ON’ and ‘OFF’ state. Triangular waveform exhibits gradual variation between
‘ON’ and ‘OFF’ state.
9. From the input-output relation, it is possible to observe that the current output is
a function of current input and previous input; hence, the given filter is finite
impulse response (FIR) filter.
10. Pole-zero plot is a two-dimensional plot with x-axis as the real part and y-axis as
the imaginary part. The pole-zero plot shows the unit circle with zeros marked as
‘0’, and poles are indicted with the symbol ‘x’. Zeros and poles near the unit
circle are expected to have a strong influence on the magnitude response of the
filter.
Q. No. 1 2 3 4 5 6 7 8 9 10 11 12 13
Key D C C D D B C A D D C D D
1. The difference equation relating the input and output of an FIR filter is given by
M
y ½ n] = bk x½ n - k ]
k=0
2. Based on symmetry and number of coefficients, the FIR filters are classified as
Type I, Type II, Type III and Type IV FIR filters
(a) Type I FIR filter: Even symmetry with odd number of coefficients
(b) Type II FIR filter: Even symmetry with even number of coefficients
(c) Type III FIR filter: Odd symmetry with odd number of coefficients
(d) Type IV FIR filter: Odd symmetry with even number of coefficients
3. An FIR filter with impulse response ‘h[n]’ is said to exhibit even symmetry if h
[n] = h[N – 1 - n], where ‘N’ is the number of coefficients of FIR filter. An FIR
filter is said to exhibit odd symmetry if h[n] = -h[N – 1 - n].
4. A digital filter exhibits linear phase characteristics if its impulse response is
either symmetric or anti-symmetric.
5. If a digital filter exhibits linear phase characteristics, then it will not introduce
phase distortion. All the frequency components of the input signal will pass
through the filter with constant delay so that there will not be any phase
distortion.
6. The relationship between group delay (τg) and the phase response (ϕ(ejω)) of the
filter is given by τg = - dω d
ðϕðejω ÞÞ.
7. Order of FIR filter (M) is the number of previous input samples necessary to
compute the current output. If ‘M’ denotes the order of the FIR filter and ‘N’
denotes the number of coefficients of FIR filter, then the relationship between
‘M’ and ‘N’ is given by N = M + 1.
8. FIR filter is an ‘all-zero’ filter with the poles occurring at the origin. For a digital
system to be stable, the pole should lie within the unit circle. Since the pole of
FIR filter occurs at the origin, the FIR filter is an inherently stable filter.
9. The advantages of FIR filter are:
(a) FIR filter exhibits linear phase characteristics; hence, there will not be phase
distortion
(b) The group delay of FIR filter is constant; hence, all the frequency compo-
nent of the input signal passes through FIR filter with equal delay.
(c) The poles of FIR filter lie at the origin; hence, FIR filter is inherently stable
filter
(d) The coefficients of FIR filter are either symmetric or anti-symmetric in
nature. Symmetricity of filter coefficient leads to linear phaseresponse of
the filter.
10. FIR filters can be designed using (a) windowing method, (b) frequency sampling
method and (c) optimal method.
Appendix 511
Q. No. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Key A C B A A B A C B D D B B B D
1. In a recursive filter, the present output depends on both the inputs and previously
calculated outputs.
2. The IIR filter is a recursive filter. The present output of the IIR filter depends on
input and past output. Hence, the IIR filter is a recursive filter.
3. Ripple is the fluctuations in the passband or stopband of the filter’s frequency
response. It is expressed in decibels.
4. Based on the ripples in the frequency response of the IIR filter, the filters are
classified as (a) Butterworth filter, (b) Chebyshev filter (Type I), (c) inverse
Chebyshev filter (Type II) and (d) elliptic filter.
5. The Butterworth filter’s magnitude response is monotonically decreased at all
frequencies, and also, there are no local maxima or minima in both the passband
and stopband. Hence, it is also called as flat-flat filters.
6. Mapping is a technique used in IIR filter design for converting analogue filter
into digital filter. The different types of mapping techniques are (a) backward
difference method, (b) impulse invariant technique (IIT), (c) bilinear transfor-
mation technique (BLT) and (d) matched Z-transformtechnique.
7. While converting an analogue filter into an equivalent digital filter, it is neces-
sary that stable analogue filter should be mapped to a stable digital filter. The
points of the analogue filter in the left half S-plane must be mapped into inside
the unit circle in the Z-plane to preserve the stability of the filter. Therefore, all
the mapping techniques must preserve the stability of the filter.
8. The steps involved in obtaining the transfer function of a digital filter using the
impulse invariant technique are summarized below:
(a) Obtain the transfer function of an analogue filter (H(s)), which has to be
converted into an equivalent digital filter (H(z)).
(b) From the analogue transfer functionH(s), get the impulse response h(t) using
the inverse Laplace transform.
(c) Apply the sampling process on impulse response h(t) to get h[nT].
(d) Take Z-transform of the sampled impulse response h[nT] to get the equiv-
alent transfer functionH(z).
512 Appendix
10. The bilinear transformation is a conformal mapping that maps the ‘jΩ’ axis of
the S-plane into the unit circle of the Z-plane only once. Therefore, it can avoid
aliasing problems.
11. The bilinear transformation technique maps the analogue frequency and digital
frequency in a non-linear fashion. The relationship between the analogue and
digital frequency is given by ω = 2 tan - 1 ΩT 2 . The non-linear relationship
between analogue and digital frequency is termed as ‘frequency warping’. To
overcome the frequency warping problem, ‘prewarping’ technique is used.
Prewarping will preserve the edge frequencies but not the exact shape of the
magnitude response.
12. Comparison of different types of IIR filter is given in Table A.2
13. The following steps are involved in the IIR filter design:
Step 1: Convert the digital filter specifications into an equivalent analogue filter
specification.
Step 2: Convert the analogue filter specifications to normalized lowpass proto-
type specifications.
Step 3: Design a normalized lowpass prototype filter by using any one of the
analogue filters: (a) Butterworth filter, (b) Chebyshev Type I filter,
(c) Chebyshev Type II filter or (d) elliptic filter.
Step 4: Use the analogue transformation technique to convert the normalized
lowpass prototype filter into the desired analogue filter.
Appendix 513
Step 5: Use the mapping technique to convert the desired analogue filter into a
desired digital one.
Q. No. 1 2 3 4 5 6 7 8 9 10
Key B D C A A A B D C B
1. The finite word length introduces an error that can affect the performance of the
DSP system. The finite word length has limited precision, and it is not sufficient
to represent the filter coefficients accurately. This causes errors between the
original filter coefficients and finite word length coefficients. The finite number
of bits is used in the arithmetic operations in DSP, which is insufficient to give
the proper result.
2. In fixed point arithmetic representation, the numbers are represented in a fixed
range with a finite number of bits of precision. The numbers beyond the fixed
range are either saturated or wrapped around. It is preferred for high speed and
low cost.
In floating-point arithmetic representation, every number is represented in two
parts (a) mantissa and (b) exponent. Floating-point representation has a higher
dynamic range and no need for scaling. It can be used to perform more complex
algorithms in it.
3. The numbers can be represented in binary format, which contains ‘0s’ and ‘1s’.
In sign-magnitude representation, most significant bit (MSB) is used to denote
the number as positive or negative. It is called as sign bit, and the remaining bits
are used to represent the number, which is called as magnitude bits.
4. Quantization is a process in which a quantity X is approximated into a quantity
Q(X). The approximated value will have a distortion between X and Q(X), called
quantization error.
5. Rounding is a method to perform quantization operation. It selects the quantized
value nearest to the original value. The error between the quantized and original
value will not exceed ±(Δ/2). Here ‘Δ’ denotes step size, which is obtained by Δ
= 2-B, and B is the number of binary bits.
514 Appendix
Q. No. 1 2 3 4 5 6 7 8 9 10
Key C A A A A A C A D B
Appendix 515
x[n] y[n]
Sampling rate converter
fs f’s
3. The two basic operations in multirate signal processing are (a) downsampling
and (b) upsampling. Downsampling reduces the sampling rate of the input
signal, whereas upsampling increases the sampling rate of the input signal.
4. Downsampling in time domain may lead to spectral overlap in the frequency
domain, which is termed as ‘aliasing’. To overcome aliasing, a lowpass filter is
used before downsampling. This filter is termed as ‘anti-aliasing filter’. This is
depicted below.
Decimation operation
Interpolation operation
516 Appendix
Q. No. 1 2 3 4 5 6 7 8 9 10 11
Key B B B B B A A B B B D
1. In optimal filtering, the input and the desired signals are available for a given
time window, and the optimal parameters of the filter are computed only once. In
adaptive filtering, the input and the desired signal are provided to the algorithm,
and the algorithm computes the parameters of the filter and is updated; hence, it
is iterative in nature. Adaptive filter does not require previous knowledge of the
signal statistics.
2. An adaptive filter is a filter with filter coefficients that are non-constants. The
filter coefficients are adjusted based on some specific criterion defined to
optimize the filter’s performance. In an ordinary filter, the filter coefficients
are constant and do not vary with respect to specific criteria.
3. Some examples of the adaptive filter include Wiener filter, least mean square
filter, RLS filter, etc.
4. The adaptive filters are generally preferred in the following contexts:
(a) The filter characteristics are necessary to be changed or adapted to specific
conditions.
(b) Spectral overlap between the signal and noise
(c) If the noise present in the signal is unknown or varies with time.
5. The performance measures of the adaptive filter are rate of convergence,
misadjustment, tracking, robustness, computational complexity, filter structure,
numerical stability and accuracy.
6. The least mean square (LMS) algorithm is an adaptive filter method that uses a
gradient-based method of steepest descent to obtain the least mean square error
between the output and the reference data. It is an iterative procedure that
corrects the weight vector (filter coefficient) in the direction of the negative of
the gradient vector, which eventually leads to the minimum mean square error.
7. The cost function of least square estimation is defined as the sum of weighted
error squares. The least square estimation is to minimize the error of the filter
output to the reference signal. In this process, statistical modelling is not
involved directly.
8. The variants of LMS algorithm include (a) normalized LMS, (b) leaky LMS,
(c) block LMS and (d) sign LMS.
518 Appendix
9. The step size parameter plays a vital role in the LMS algorithm. The larger the
step size value, the faster the adaption, increasing residual MSE. Also, it affects
the stability of the algorithm. Therefore, the step size selection cannot be
arbitrarily large.
10. The recursive least squares is an adaptive filter algorithm, which recursively
obtains the filter coefficients that minimize a least squares cost function relating
to the input. In this algorithm, input signals are considered deterministic,
whereas input signals are considered stochastic in the LMS. As a result, the
RLS algorithm converges faster than the LMS algorithm.
Q. No. 1 2 3 4 5 6
Key A D A B A C
Index
© The Author(s), under exclusive license to Springer Nature Singapore Pte Ltd. 2024 519
S. Esakkirajan et al., Digital Signal Processing,
https://doi.org/10.1007/978-981-99-6752-0
520 Index
Digital signal, 21, 36, 82, 97, 159, 378, 383, Frequency resolution, 211, 213–217, 228, 492,
407, 500, 515 507
Discrete Cosine transform (DCT), 168, Frequency response, 123, 142, 144, 167, 194,
206– 210, 472, 478–480, 507 233, 234, 248, 251, 256, 260, 266, 272,
Discrete Fourier transform (DFT), 168, 278, 293, 301, 304, 309, 328, 337, 344,
196– 204, 206, 209, 210, 227, 229, 354, 358, 362, 367, 373, 374, 383, 384,
474– 476, 478–479, 506 389, 397, 448, 451, 476, 511
Discrete-Time Fourier Transform (DTFT), 167, Frequency sampling method, 271, 291, 292,
168, 175, 191–194, 272, 506, 507 510
Discrete-time system
system properties, 123, 149–161
system representation, 123, 125–142 G
system response, 123, 125, 142–144 Gaussian function, 2, 26–33, 179, 186, 187,
Discrete wavelet transform, 168, 221–229 190, 191, 229, 389, 499
Distributive property, 104, 106, 107
Double-sided spectrum, 168, 179, 507
Downsampling, 91–93, 119, 120, 159, H
403– 408, 413–415, 417, 421, 422, 432, Hamming window, 284, 289, 299
436–440, 502, 504, 505, 515, 516 Harmonics, 175, 258, 259, 488, 489, 491, 492
Dual function, 186, 499 Highpass filter, 141, 142, 421, 438
Homogeneity property, 149, 150, 503, 516
E
Elliptic filter, 304, 362–375, 511, 512 I
Energy, 72, 86, 87, 95, 96, 117–120, 122, 200, Ideal interpolation, 59, 64, 500
202, 204, 206, 210, 221, 223, 226, 275, Impulse invariant technique (IIT), 304, 306,
482, 502, 507 310–320, 323, 373, 511, 512
Even signal, 72, 117, 120, 122, 502 Impulse response, 23, 61, 99, 128, 193, 233,
264, 305, 384, 417, 449
Infinite impulse response filter (IIR), 126,
F 231– 238, 253, 304–373, 377, 389–394,
Filter bank, 294, 403, 404, 419–433, 472, 516 401, 511–513
Finite impulse response filter Inverse transform, 196
type-I FIR filter, 264–266, 271, 273, 510 Inverse Z-transform, 145, 146, 167, 173–174,
type-II FIR filter, 266–268, 271, 273, 291, 227, 233, 305, 425, 427
510
type-III FIR filter, 268, 269, 271, 273, 291,
510 L
type-IV FIR filter, 269–271, 273, 291, 510 lcapy
Finite word length effect, 377, 378 lcapy.exp(), 170–172
FIR filter design lcapy.sin(), 173
frequency sampling based FIR filter design, Least Mean Square (LMS) algorithm, 443, 444,
291 452, 453, 455, 456, 458–462, 465, 467,
optimal FIR filter design, 293–294 468, 517, 518
window based FIR filter design, 272, 467 Linear phase, 142, 162, 194, 241, 249, 264,
First-order hold (FoH), 59, 62–64, 69 265, 268, 269, 271, 276, 278, 280, 282,
First order system, 232–239 284, 286, 288, 291, 294, 298–301, 305,
Fourier transform, 8, 23, 26, 38, 40, 67, 168, 356, 360, 366, 424, 508, 510
174, 175, 177, 181, 183, 186, 190, 204, Linear system, 3, 149, 503, 504
205, 210, 216, 218, 227, 229, 289, 448, Linear time-invariant (LTI) system, 8, 97,
449, 457, 499, 503, 506, 507 125–129, 136, 146, 231, 260, 498, 499,
Frequency, 3, 36, 82, 139, 168, 233, 271, 315, 502, 505
383, 405, 446 Low pass filter, 141, 142, 405
Index 521
384–387, 389, 391, 392, 423, 424, 426, Recursive system, 394, 401, 505
427, 450, 508, 510 RLS algorithm, 443, 444, 462–468, 518
Poles, 139, 140, 144, 154, 157, 158, 165, 228, Rounding, 377–380, 383, 389, 390, 392, 394,
232, 234, 237, 238, 246, 247, 251, 254, 400, 401, 513, 514
256–261, 266, 271, 294, 305, 310, 318,
319, 323–325, 348, 349, 375, 383, 451,
508–510, 512 S
Pole-zero plot, 123–125, 139–142, 144, 145, Sampling, 35–64, 291, 299, 307, 321, 472–474,
157, 159, 160, 162, 232, 234, 241, 247, 500, 511, 515, 516
249, 251, 254, 256, 257, 265, 266, 268, Sampling frequency, 28, 36, 39–45, 69, 250,
269, 271–273, 278, 280, 282, 283, 286, 283, 284, 293, 296, 300, 315, 331, 332,
299, 300, 312, 319, 320, 384–387, 389, 337, 342, 346, 354, 359, 362, 364, 369,
391, 392, 451, 503, 509 370, 372–374, 389, 392, 438, 460, 500,
Polyphase decomposition, 403, 404, 417–419, 515
516 Sampling rate conversion, 404, 515
Pulse signal, 1, 25–26, 101, 102, 179, 185, 192, Sampling theorem, 36, 39–45, 500
193 Sawtooth signal, 48, 51, 56, 209, 225, 227, 430
Pulse train, 36–39 Scaling operation, 91–93, 502
Python, 2–12, 14–18, 21–31, 37–52, 56, 58, Scipy
60–65, 67, 73–107, 109–118, 120, 121, signal.bilinear(), 353
123, 125, 127–129, 131–133, 135–147, signal.butter(), 331
149–153, 155–163, 170–174, 177–179, signal.buttord(), 336
181–184, 186–188, 190, 192–205, 207, signal.cheby1(), 366
208, 210–218, 220, 221, 223–228, signal.cheby1ord(), 353
234–242, 244–253, 256, 265–272, 274, signal.cheby2(), 358
275, 277–279, 281, 283–287, 289, signal.convolve(), 325
291–299, 301, 302, 306–319, 321–323, signal.ellip(), 363
325, 327–332, 336–340, 342–345, 352, signal.ellipord(), 364
353, 355–367, 369–374, 379–389, signal.filtfilt(), 298
392–394, 396–398, 400, 406–410, signal.firwin(), 300
412–428, 432–438, 440, 443–447, 449, signal.firwin2(), 300
450, 452, 453, 455, 456, 458–462, signal.freqz(), 451
464–467, 472–475, 477–480, 482–487, signal.lfilter(), 446
489–493, 495 signal.remez(), 300
Python code for time-frequency representation, signal.residue(), 318
492 signal.sawtooth(), 23
Pywavelet signal.sos2tf(), 397, 398
pywt.cwt(), 222 signal.square(), 21
pywt.dwt(), 224 signal.ss2tf(), 132
pywt.idwt(), 224 signal.stft(), 212
pywt.threshold(), 226 signal.tf2ss(), 133
pywt.wavedec(), 226 signal.tf2zpk(), 451
pywt.waverec(), 226 Scipy.fftpack
fft(), 206
fftfreq(), 206
Q ifft(), 210
Quantization, 35–64, 68–70, 377–397, 400, Shifting operation, 79, 93–95, 502
401, 500–501, 513–514 Short-time Fourier transform (STFT), 168, 205,
210–219, 228, 492, 493, 507
Sinc signal, 186
R Single sided spectrum, 179
Rectangular pulse, 25, 26, 101, 182, 185, Sinusoidal signal, 2–8, 14–18, 28, 29, 31, 32,
191–193, 384 41, 58, 61, 64, 65, 67, 68, 86, 89, 147,
Index 523
W
T Warping, 304, 320, 322, 512
Time-frequency representation, 168, 211, 212, Wavelet, 219, 220, 225, 479, 480, 493, 495
216, 218, 492–494, 507 Wavelet transform, 168, 219, 220, 493, 507
Time-invariant system, 164, 504 White noise, 110, 225, 226, 297, 379, 380, 446,
Time resolution, 211, 213–215, 228 447, 449, 451
Time reversal, 95–98, 122, 502 Wiener filter, 443–451, 467, 468, 517
Time-variant system, 124, 151–152, 162 Wiener-Hopf equation, 444, 447, 467
Transfer function, 61, 62, 68, 69, 125, 130–133, Window, 26, 211, 271, 383, 467
139–141, 145, 155, 157, 161–165, 227,
229, 232–234, 237, 238, 246, 248, 249,
251, 255, 256, 260, 302, 304, 305, 307, Z
309, 310, 312, 315–318, 324–328, 331, Zero input limit cycle oscillation, 392–397, 514
334, 337, 338, 341, 344, 351–354, 359, Zero-order hold (ZoH), 59–64, 66–68
362, 363, 373, 451, 503, 508, 511 Zero padding, 227
Transform, 167–226, 405 Zeros, 5, 37, 73, 126, 187, 232, 264, 319, 383,
Transmultiplexer, 403, 431–437, 516 405, 447
Truncation, 377–383, 385–388, 392, 395, 400, Z-plane, 139–141, 228, 237, 307, 308,
401, 514 310–312, 320, 322, 323, 374, 375, 511,
Two-channel filter bank, 404, 420–425, 438, 512
516 Z-transform, 130, 155, 167–172, 228, 255, 304,
306, 310, 323, 324, 506, 507, 511