0% found this document useful (0 votes)
222 views684 pages

978 981 15 2584 1 PDF

Uploaded by

박치현
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
222 views684 pages

978 981 15 2584 1 PDF

Uploaded by

박치현
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 684

Signals and Communication Technology

Keonwook Kim

Conceptual
Digital Signal
Processing
with MATLAB
Signals and Communication Technology

Series Editors
Emre Celebi, Department of Computer Science, University of Central Arkansas,
Conway, AR, USA
Jingdong Chen, Northwestern Polytechnical University, Xi'an, China
E. S. Gopi, Department of Electronics and Communication Engineering, National
Institute of Technology, Tiruchirappalli, Tamil Nadu, India
Amy Neustein, Linguistic Technology Systems, Fort Lee, NJ, USA
H. Vincent Poor, Department of Electrical Engineering, Princeton University,
Princeton, NJ, USA
This series is devoted to fundamentals and applications of modern methods of
signal processing and cutting-edge communication technologies. The main topics
are information and signal theory, acoustical signal processing, image processing
and multimedia systems, mobile and wireless communications, and computer and
communication networks. Volumes in the series address researchers in academia
and industrial R&D departments. The series is application-oriented. The level of
presentation of each individual volume, however, depends on the subject and can
range from practical to scientific.
**Indexing: All books in “Signals and Communication Technology” are indexed
by Scopus and zbMATH**
For general information about this book series, comments or suggestions, please
contact Mary James at [email protected] or Ramesh Nath Premnath at
[email protected].

More information about this series at http://www.springer.com/series/4748


Keonwook Kim

Conceptual Digital Signal


Processing with MATLAB

123
Keonwook Kim
Division of Electronics
and Electrical Engineering
Dongguk University
Seoul, Korea (Republic of)

ISSN 1860-4862 ISSN 1860-4870 (electronic)


Signals and Communication Technology
ISBN 978-981-15-2583-4 ISBN 978-981-15-2584-1 (eBook)
https://doi.org/10.1007/978-981-15-2584-1
© Springer Nature Singapore Pte Ltd. 2021
This work is subject to copyright. All rights are reserved 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
To my parents
To Saea, Saeyun, and my lovely wife
Gumhong Kim
To all of my family
Preface

Digital signal processing (DSP) is an extensive study area to understand the signal
and noise in the digital domain. The advanced digital technology in the 60s and 70s
started to accelerate the theoretical signal processing for the feasible engineering
over the academia. In the 80s, the research in articles were organized and consol-
idated as practical textbooks for the graduate program. There were great textbooks
such as “Discrete-Time Signal Processing” by Oppenheim and Schafer and “Digital
Filter Design” by Parks and Burrus. The decade of the 90s further enjoyed the
processor technologies along with programming environments for DSP. MATLAB
(founded in 1984) has provided a reliable and convenient computer language (also
tools) to realize and verify the mathematical algorithms. Many textbooks appreciate
the benefits of MATLAB, for instance, “Signals and Systems Using MATLAB” by
Chaparro. For DSP, books and tools are existing.
This book addresses DSP in novel approach based on reconfiguration. The
intuitions and theories along with applications are the basic philosophy of the book.
The author tries to avoid the dictionary style (bottom-up structure) and to place
theories within applications. Students often experience a loss of motivation in the
middle of a semester due to the fragmented knowledge of digital filter design. The
author believes that the great researchers in DSP did not establish solid theories
from pure mathematics. The imagination initiates the research, and the equation
finalizes the theory. This book tries to provide the theories with derivations,
illustrations, and/or applications. Once the student has a certain picture of the
procedure and intelligence, the knowledge can be extended and maintained for a
long time. MATLAB also helps to design the top-down structure for the
self-motivated learning process. The book is organized as follows.

Chapter 1
• Basics of digital filters based on the intuition,
• Simple weight and sum of recent inputs for desired output,
• Design the low, high, and band pass filter.

vii
viii Preface

Chapter 2
• Definition of frequency in continuous and discrete time domain,
• Sampling theory,
• Discrete time signal representations.
Chapter 3
• Fundamentals to find the frequency magnitude from time domain,
• Discrete-time Fourier transform (DTFT) for non-periodic signal,
• Discrete Fourier transform (DTF) for periodic signal.
Chapter 4
• Reason to have the linear time invariance property,
• Finite impulse response (FIR) filter,
• Simple FIR filter design from the specification.
Chapter 5
• Extension of DTFT and DFT to Z-transform,
• Z-transform for infinite impulse response (IIR) filter,
• Intuitive IIR filter designs.
Chapter 6
• Understanding the filter specification,
• Advanced FIR filter designs,
• Advanced IIR filter designs.
Chapter 7
• Quantization effect for fixed-point number system,
• Implementation matters for FIR and IIR filters,
• Frequency domain filter realization.
Chapter 8
• Various filter realizations in MATLAB,
• Fixed-point number for MATLAB,
• C code generation for MATLAB.
In addition to above, there are two more sections for MATALB fundamentals
and Symbolic Math Toolbox as an appendix. This book includes comprehensive
information from basic DSP theories to the real-time filter realization of digital
computers and processors. The DSP class from this book is intended to provide
one- or two-semester program at the undergraduate level. The instructor can design
the DSP class for theory or practical intensive program as follows. Also, a
two-semester class can be handled using the complete contents of this book.
Preface ix

One-semester DSP program (theory intensive)


• Chapters 1+2+3+4+5
• Chapter 6
– Specification + FIR window method + FIR types,
– IIR Butterworth method with bilinear transform.
One-semester DSP program (practical intensive)
• Chapters 1+2+3+4+5
• Chapter 6 (Specification + IIR Butterworth method with bilinear transform),
• Chapter 7 (numerical representation + filter implementation components),
• Chapter 8 (whole).
Two-semester DSP program
• First semester: Theory-intensive DSP program as shown above.
• Second semester: Chapter 5 to end.
DSP is realized by programming languages which can be chosen from the
rudimentary level such as assembly language to the advanced level, for example,
MATLAB. Unlike the low-level language, MATLAB provides a high degree of
freedom for syntax, variable, function, execution, etc. Also, the robust support for
symbolic mathematics can solve the calculus problems without using the hand
derivations. The conversion between the symbolic and numerical mathematics is
seamless in MATLAB; hence, the equation establishment is the only requirement
for DSP realization, in most of the situations. Examples in this book demonstrate
the visualization, verification, and realization of DSP algorithms based on the
MATLAB programming. The evolution of DSP is continuously happening to the
next-generation applications such as data science, deep learning, etc. The author of
this book hopes that the readers can grasp the fundamentals of DSP and employ the
understandings of DSP to real-world applications.

Seoul, Korea (Republic of) Keonwook Kim


Contents

1 Preliminary Digital Filter Design . . . . . . . . . . . . . . . . . . . . . . . . . . . 1


1.1 Discrete Time Signal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 Design the Digital Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.3 Filter Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.4 Digital Filter Definitions and Requirements . . . . . . . . . . . . . . . . . 12
1.5 What We Need for Further (Optional) . . . . . . . . . . . . . . . . . . . . . 16
1.6 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
2 Frequency and Signals in Discrete Domain . . . . . . . . . . . . . . . . . . . . 21
2.1 Continuous Sinusoid Signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
2.2 Sampling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
2.3 Signal Representation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
2.4 Frequency in Discrete Time Signal . . . . . . . . . . . . . . . . . . . . . . . 56
2.5 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
3 Fourier Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
3.1 How We Can Find the Magnitude of the Specific Frequency? . . . . 71
3.2 Signal Property and Frequency Distribution . . . . . . . . . . . . . . . . . 81
3.3 Discrete-Time Fourier Transform (DTFT) . . . . . . . . . . . . . . . . . . 83
3.4 Discrete Fourier Transform (DFT) . . . . . . . . . . . . . . . . . . . . . . . . 89
3.5 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
4 Filters in Time Domain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
4.1 Digital Filter Revisited . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
4.2 Filter Properties with LTI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
4.3 FIR and IIR Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
4.4 Frequency Response . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136

xi
xii Contents

4.5 Simple Filter Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142


4.6 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199
References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202
5 Z-Transform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203
5.1 Definition and Usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203
5.2 Filter and Z-Transform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217
5.3 Intuitive Filter Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241
5.4 Relation with Fourier Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . 262
5.5 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263
References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266
6 Filter Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 267
6.1 Filter Specifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 268
6.2 FIR Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275
6.3 IIR Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 395
6.4 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 494
References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 500
7 Implementation Matters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 503
7.1 Number Representations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 504
7.2 Filter Implementation Components . . . . . . . . . . . . . . . . . . . . . . . 516
7.3 FIR Filter Implementations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 553
7.4 IIR Filter Implementations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 558
7.5 Frequency Domain Filter Realization . . . . . . . . . . . . . . . . . . . . . . 563
7.6 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 593
References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 594
8 Filters with MATLAB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 595
8.1 Fundamental Filter Design Methods . . . . . . . . . . . . . . . . . . . . . . . 595
8.2 Advanced Filter Design Methods . . . . . . . . . . . . . . . . . . . . . . . . . 603
8.3 MATLAB Code Generation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 637
References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 643

Appendix A: MATLAB Fundamentals . . . . . . . . . . . . . . . . . . . . . . . . . . . 645


Appendix B: MATLAB Symbolic Math Toolbox . . . . . . . . . . . . . . . . . . . 661
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 673
About the Author

Dr. Keonwook Kim received the B.S. degree in Electronics Engineering from
Dongguk University, Seoul, Korea in 1995 and the M.S. and Ph.D. degrees in
Electrical and Computer Engineering from the University of Florida, Gainesville,
United States in 1997 and 2001, respectively. He is presently Professor in the
Division of Electronics and Electrical Engineering at the Dongguk University. Prior
to joining Dongguk University, he worked as Assistant Professor in the Department
of Electrical and Computer Engineering at the Florida State University from 2001
to 2003. His primary research interest is acoustic localization via using the
multi-aural architecture in order to mimic the aural system of animals which include
human.

xiii
Chapter 1
Preliminary Digital Filter Design

The general filter passes various matters to separate out unwanted things. In elec-
trical engineering, the filter is known as the device for minimizing or suppressing
the noise frequencies to obtain the better signals. The digital filter handles the input
and output in discrete time domain as well as the quantized magnitude form. This
chapter introduces the digital filter from scratch. The filter equation is derived from
the general engineering concept. We assume that the input signal to the digital filter
presents the real-time property which represents the past, present, and future tense
in the signal. The conceptual derivation performed in this chapter actually operates
filter function in the real field based on the trial and error approach. In the following
chapters, the abstract design is followed by the further delicate analyses to meet the
accurate filter performance.

1.1 Discrete Time Signal

The continuous time is t as real number and discrete time is n that is the integer
number. The () handles the continuous arguments and [] deals with discrete argu-
ments. Any functions can be continuous and discrete form with arguments. The
given signal is x[n] as shown in Fig. 1.1.
The discrete signal with integer argument has no tense as past, present, and
future unless we specify the current time. That is the sequence of signal which
shows the relative position of numbers. The higher index number shows later, and
the lower index appears earlier. The real-time signal with n index provides the
present time position n which is the variable integer number. Therefore, the n + 1,
n + 2, and etc. are the future of the signal and n−1, n−2 … are the past of them.
Based on the time schedule, we only have the data up to the n index and n + 1 data
will be gathered next. The magnitude of the data is real number and any numbers
are possible for received value. The frequency components of the signal are not
numerically analyzed yet, but we presume that the signal with rapid fluctuation
© Springer Nature Singapore Pte Ltd. 2021 1
K. Kim, Conceptual Digital Signal Processing with MATLAB,
Signals and Communication Technology,
https://doi.org/10.1007/978-981-15-2584-1_1
2 1 Preliminary Digital Filter Design

1 2 ..
.
0

Fig. 1.1 a Example of discrete time signal with absolute time index number. b The corresponding
discrete time signal with real-time representation with n. The clock shows the current time n

contains the additional high frequency components. In contrast, the signal with
gentle movement includes the dominant low frequency components. The source of
the signal can be anything such as dice toss and heart rate. Conventionally the
discrete time signal is obtained from the continuous information by regular sam-
pling. We assume that the sampling distance for time is even; hence, the actual time
difference between adjacent indexes are always identical. After every fixed time, the
number for the discrete index n will be updated to the next integer. In the digital
signal processing, the x[n] has two meanings those are whole signal sequence
(variable n) and current signal value (given n). The discrete signal can be defined as
the signal sequence as shown below.
p 
x½n ¼ cos n ð1:1Þ
2

If the sequence is used to build another discrete time signal, the input sequence is
employed as real-time signal as shown below.

1 1 1
y½n ¼ x½n þ x½n  1 þ x½n  2 ð1:2Þ
3 3 3

The y[n] function uses the current x value as x[n] and two previous values as x[n
−1] and x[n−2].
1.2 Design the Digital Filters 3

1.2 Design the Digital Filters

The real-time discrete time signal is given, and you are asked to design the filter to
reduce the noise frequencies and emphasize signal information. I believe that this is
the initial point of digital signal processing. Let’s design the filter.
The filter output y[n] is the operated results from the filter input x[n]s, and the
signal is obtained up to the n index value, as shown above Fig. 1.2. Any idea? Note
that the signal is continuously received by the system in every constant interval;
therefore, the system is willing to have the significant amount of data in short time.
It is impossible to process the whole obtained data for filtering; hence, the limited
length of data is considered to provide the filter output. The simple idea is to take
average the recent inputs for low pass filtering (smoothing). The recent N samples
are denoted as below.

x½n; x½n  1; x½n  2; . . .; x½n  N þ 1 ð1:3Þ

The current filter out y[n] is computed as below.

1
y½n ¼ fx½n þ x½n  1 þ x½n  2 þ    þ x½n  N þ 1g ð1:4Þ
N

The filter output with input data is illustrated in Fig. 1.3. The recent three data
samples are considered to create average value for output y[n]. In Fig. 1.3, the
n values (n is the variable and not the current index here) are demonstrated from

Present

Future
Gathered data

n-5 n-4 n-3 n-2 n-1 n n+1 n+2 n+3 n+4 n+5

Fig. 1.2 One example of discrete time signal with real-time representation
4 1 Preliminary Digital Filter Design

Fig. 1.3 Digital average filter with recent three data

seven to ten and the output values are noticeably smoothed comparing to the
income signal. This is the primitive low pass filter (LPF).
Example 1.1
Write the equation for digital average filter with recent three data.
Solution

1
y½n ¼ fx½n þ x½n  1 þ x½n  2g
3

The independent parameter for the LPF is operation (averaging) and length
(three). As shown in Eq. (1.4), the averaging operation can be seen as the weighted
sum for the recent incoming data. Instead of using the averaging computation, the
different weight values can be applied on the data set. First of all, let’s change the
length of the averaging in the LPF as Fig. 1.4.
Example 1.2
Write the equation for digital average filter with recent seven data.
Solution

1
y½n ¼ fx½n þ x½n  1 þ    þ x½n  5 þ x½n  6g
7

1.2 Design the Digital Filters 5

Fig. 1.4 Digital average filter with recent seven data

For the increased length (seven) of averaging operation, the filter output y
[n] delivers further smoothed outcome than the shorter version (length three).
Therefore, depending on the filtering length, smoothness of the output can be
decided proportionally. In other word, the longer length averaging passes the
narrower range frequencies from zero frequency, and the shorter length averaging
passes the wider range frequencies that demonstrates the high fluctuation in filter
output. The length of the filter is important parameter to determine the frequency
range of the output.
Example 1.3
Write the equation for y[7] digital average filter in Fig. 1.5.
Solution

1
y½7 ¼ fx½7 þ x½6 þ    þ x½2 þ x½1g
7


The other parameter to be considered is weight values in the filter. The averaging
operation multiplies the constant 1/N to each data values for limited N length and
accumulates for filter output. The averaging range, latest N data, can be seen as the
window with weight for the given time sequence, and the window slides to the next
for new output. Figure 1.5 illustrates the explained procedures in terms of window
with seven window length. We understand that the filter length controls the output
6 1 Preliminary Digital Filter Design

Fig. 1.5 Digital average filter with recent seven data

frequency range. The shape or weight of the window significantly contributes to


manipulate the frequency component of the output as well. Let’s do another
experiment.
Example 1.4
Write the equation for high pass filter in Fig. 1.6.
Solution

1
y½n ¼ fx½n þ x½n  1  x½n  2g
3


Unlike averaging filter, the filter output shows the higher variation in magnitude
than the original signal; therefore, the high frequency components are exaggerated via
the filtering process. The designed filter is high pass filter (HPF) with three window
length. The values in the window decide the characteristics of the filter which prefers
to pass the high frequency components; hence, we can think that the window shape
plays an important role. Comparing to the LPF, the HPF also uses the same window
length but the filter output is completely reverse in action. Applying the longer HPF
window derives same variation as LPF? The longer HPF length generates concen-
trated filter output to the high frequencies than the three HPF length situation as
Fig. 1.7.
1.2 Design the Digital Filters 7

Fig. 1.6 High pass filter with recent three data

Fig. 1.7 High pass filter with recent seven data


8 1 Preliminary Digital Filter Design

Example 1.5
Write the equation for high pass filter in Fig. 1.7.
Solution

1
y½n ¼ fx½n þ x½n  1 þ    þ x½n  5  x½n  6g
7


The window length controls the frequency focus of the filter output in inversely
proportional manner. The longer window creates the further concentrated output for
the specific filter type which is determined by the window shape. The relationship
between the output frequencies and window length is derived from the above
simple experiments. How we can decide the filter type from window shape? Let’s
draw the two previously used filters in Fig. 1.8.
Can you figure out the filter type by observing the filter shape? Yes, the filter
output follows the window shape; therefore, smoothness and roughness of the
window provide the filter type that specify the designated frequency you want to
pass. Other than LPF and HPF, let’s perform another example. The window shape
of this filter is certain periodic signal which shows the 6-sample period and
19-sample length. The filter output is similar to the window shape as illustrated in
Fig. 1.9. The longer length expects to emphasize the window shape on the output
based on the intuition of previous lessons.

Fig. 1.8 a Low pass filter weight. b High pass filter weight
1.2 Design the Digital Filters 9

Fig. 1.9 The filter to pass the 6-sample period signal

Example 1.6
Write the equation for digital filter in Fig. 1.9.
Solution

X
18  
2pk
y½n ¼ x½n  k cos
k¼0
6

Up to now, we have designed primitive filters for LPF, HPF, etc. This is the
fundamental of the digital filter theory. The idea and computation initiated the
filtering system and signal processing in digital domain. The design method based
on the trial and error does not lend the solid foundation for building the intended
filter. The shown intuitive methods should be formularized in engineering area for
further analysis and application. This book not only provides the mathematical
representations of the algorithms but also illustrates the physical meanings of the
system extensively in the coming sections and chapters.

1.3 Filter Architecture

The illustrated filter system provides approximate methodological principle of the


filtering. This section converts the pictured procedures into the mathematical for-
mula. Let’s consider the LPF as below.
10 1 Preliminary Digital Filter Design

1 1 1 1
y½n ¼ x½n þ x½n  1 þ x½n  2 þ    þ x½n  N þ 1 ð1:5Þ
N N N N

The recent N samples of data sequence is averaged for the low pass filtering in
terms of weighting the 1/N on each sample. Since the weight values in the window
can be various for intended filtering purpose, the window is separated and slid
sequentially in every interval as Fig. 1.10. The signal sequence x[n] starts from the
zero n value and the window will be overlapped at the zero index. As the time goes
by, overlap range will be increased and completed after N−1 sample shift; hence,
we expect to have proper averaged output from the operations.
The window function is specified as below.

1
q½0 ¼ q½1 ¼ q½2 ¼    ¼ q½ðN  1Þ ¼
N

Therefore, the first appropriate output by complete overlap is defined as;

y½N  1 ¼ q½ðN  1Þx½0 þ q½ðN  2Þx½1 þ q½ðN  3Þx½2 þ   


þ q½1x½N  2 þ q½0x½N  1

The second and third proper outputs are shown below with sliding input
sequence.

y½N ¼ q½ðN  1Þx½1 þ q½ðN  2Þx½2 þ q½ðN  3Þx½3 þ   


þ q½1x½N  1 þ q½0x½N

x[n]

... n
0 1 2 ...

q[n]
Sliding
1/N
... n
-(N-1) 0

Sum Sum
Sliding
... ... n
... ... n
Output
Output
y[n] y[n]
... n
... n

Fig. 1.10 The low pass filtering operation. The x[n] is the input sequence and the q[n] is the filter
weight window
1.3 Filter Architecture 11

y½N þ 1 ¼ q½ðN  1Þx½2 þ q½ðN  2Þx½3 þ q½ðN  3Þx½4 þ   


þ q½1x½N þ q½0x½N þ 1

Generalizing the above equation by summation as below.

X
N1
y½n ¼ x½n  k q½k ð1:6Þ
k¼0

The n is the current time in the equation and the integer value n starts from zero
to infinite. Based on the recent N input sequence, the filter output is computed by
weight q[] function. This is the nice equation to formulate the intuitive concept of
the primitive filtering. Since the input data sequence initiates from the zero-time
index to positive number, the weight window is also flipped over the vertical axis in
order to start from the zero as below.

q½0 ! h½0; q½1 ! h½1; q½2 ! h½2; . . .; q½ðN  1Þ ! h½N  1

Due to the relocation, the tense of the weight window is changed completely as
shown in Fig. 1.11. The original window function q[] represents the q[0] as present
moment and the its tails on the left as past time. Note that the q[0] is always
multiplied with the present x[] value in the filtering computations shown at
Eq. (1.6). The further to the left indicates the earlier times in weight window. In the
flipped window function h[], the further to the right is past and h[0] is present time.
Therefore, the equation with h[] is below.

y½n ¼h½ðN  1Þx½n  ðN  1Þ þ h½ðN  2Þx½n  ðN  2Þ þ   


þ h½3x½n  2 þ h½1x½n  1 þ h½0x½n

... q[n] h[n] ...


0 0

Past Future Future Past


Flipping
Present Present
Fig. 1.11 Flipping the filter weight window for h[n]
12 1 Preliminary Digital Filter Design

Fig. 1.12 Digital filter block diagram

Generalizing the above equation by summation as below.

X
N 1
y½n ¼ x½n  k h½k ð1:7Þ
k¼0

The only difference with non-flipped window filter is that there is no minus sign
in the window function. This is the digital filter equation also known as convolution
sum. The equation is the time domain filter with given input signal x[] and pro-
duces the filtered output y[]. For the specific purpose, the shape and length of h[]
have to be determined in analytical manner to improve the signal and reduce the
noise component from incoming discrete data sequence on Fig. 1.12.
The diagram for the filter is given as above. The real-time input sequence x[] is
provided to the filter system represented by h[]. The corresponding filter output is y
[].

1.4 Digital Filter Definitions and Requirements

By definition, the filter is a process to eliminate the unwanted frequencies, which


are classified as noise, from an input signal. The designed filters were explained in
terms of emphasizing the certain frequencies; however, a range of frequencies are
suppressed to intensify the information in fact. The important thing in the filter
realization is that ‘do not add any information by filtering.’ You can increase and
decrease certain frequency magnitudes but cannot create new frequencies in the
filtering process. This is the reason that the filter is explained by elimination of
frequencies.
One example of digital signal processing is shown in Fig. 1.13. The input signal
is the cosine wave with certain period and the processing output limits the input
magnitude to one. The input and output frequency distributions are illustrated as
well. The input frequency consists of single dominant component and the output
frequency presents at least three components. The additional prominent frequency
components are pointed by the circles in the Fig. 1.13. The given digital signal
processing is disqualified from the filter requirements according to the frequency
component non-creation rule. However, the reverse situation is valid as the digital
1.4 Digital Filter Definitions and Requirements 13

Fig. 1.13 An example of digital signal processing

filter. The output sequence placed at the filter input provides the output which only
includes the single frequency component. The multiple frequency components are
removed to obtain the signal frequency; therefore, the filter dose not insert any
frequencies to the output.
Example 1.7
Write the equation to add the zero frequency component over the signa x[n].
Solution

y½n ¼ x½n þ constant

Since the constant values indicate the zero frequency, the output y[n] contains
the additional zero frequency component.

Now we know that the designed filter by h[] can compute the output by
Eq. (1.7). When you have the unknown filter, how we can find the h[] and what is
the relationship with y[] from h[]? What signal figures out the h[]? Do not look at
the equation. Observe that we are dealing with discrete time signal. The primitive
and fundamental element of the discrete signal is the function that has single value
in the certain time index. Let’s see the example at Fig. 1.14.
14 1 Preliminary Digital Filter Design

q[n]
2
1
2
n
01
-1

=
q0[n] q1[n] q2[n]
2
1
+ + 2
n n n
012 012 01
-1

Fig. 1.14 An example of function decomposition

The function q[] is the linear combination (simple addition) of q0[], q1[] and
q2[]. The individual q1[] and q2[] can be represented by the shift location and
magnitude multiplication of q0[] as shown below.

Shift right by 1 Multiply by 2


q0 ½n ! ! q1 ½n

Shift right by 2 Multiply by 1


q0 ½n ! ! q2 ½n

Therefore, the manipulations and combinations of q0[] can provide the q[] and
any arbitrary functions. Based on this idea, we can think about the filter output by
analytical combinations. If the filter output of q[] is the linear combination of the
filter outputs from q0[], q1[] and q2[], then the q[] output can be decomposed into
the simpler form. Furthermore, the individual filter output of q1[] and q2[] can be
described by the shift location and magnitude multiplication of q0[] output just as
relationships of q0[], q1[] and q2[], then the filter output will be expressed by
linear combination of representative output like q0[] in this example. The gener-
ating output from individual inputs is illustrated in Fig. 1.15.
Figure 1.15 shows that the filter output can be derived from the linear combi-
nation and time shift of the primitive output. This kind of the system is called as
linear and time invariant system. The linear system denotes the filter outcome by
addition over scaled version of individual element outputs. The time invariant
system preserves the filter output shape for the time shifted input with identical time
relocation. With linear and time invariance condition, the system can be charac-
terized by very simple format that is the output of the single value in single time.
1.4 Digital Filter Definitions and Requirements 15

Fig. 1.15 The linear q0[n]


combination of shifted output
y0[n]
from decomposed input for
arbitrary input response 1 1
n Response
n
012 01234

+ +
q1[n] y1[n]
2 2

n Response
n
012 01234

q2[n]
+ +
y2[n]

2
n Response n
01 01234
-1 -1

q[n] y[n] 3
2 2
1 1 1
2
n Response
01234
n
01
-1 -1

Any other outputs can be produced by the scaled and shifted combinations of the
characterizing output. This is very important property since the characterizing
output represents the complete feature of the system described as h[] in the
equation. How we can find the h[] from the unknown linear and time invariant
system? Let’s perform Fig. 1.10 example in reverse manner as below.
As shown in Fig. 1.16, the impulse signal (one magnitude at time zero), which is
the characterizing input, sequentially scans the h[] of the system and provides the h
[] of the filter. The discovered h[] tells us the property and performance of the filter
in detail. Therefore, the user can find the system feature of the unknown and linear
16 1 Preliminary Digital Filter Design

x[n]

n
0 1 2 ...

h[n]

0 1234 n

x[n] x[n] x[n] x[n] x[n]

1 1 1 1 1

n n n n n
0 1 2 ... 0 1 2 ... 0 1 2 ... 0 1 2 ... 0 1 2 ...

h[-n]

-4 -3-2-1 0 1 2 3 4 n -4 -3-2-1 0 1 2 3 4 n -4 -3-2-1 0 1 2 3 4 n -4 -3-2-1 0 1 2 3 4 n -4 -3-2-1 0 1 2 3 4 n


y[n] y[n] y[n] y[n] y[n]

01234 n 01234 n 01234 n 01234 n 01234 n

Sliding

Fig. 1.16 Place the impulse signal to derive the h[n]

& time invariant filter by impulse signal input. Now, we understand that the h[] can
be designed and found for the specific filtering purpose. However, we have to
explore further to study the relationship between the h[] and frequency components
in coming chapters.

1.5 What We Need for Further (Optional)

If you are going to build the digital filter by using the trial and error method, the
chapter one is enough information for you. The information above shows about
window shape and filter computation intuitively. The low pass filter is realized by
the constant weight window for filter equation and the length is determined by your
trials until you obtain the satisfactory outcome. Other types of the filters can be
implemented by the derived window and numerous executions. The fundamental
concept is delivered but certain analytical approaches are missed in above.
For the engineering aspects, the systematical methodology is required for
approximate closed form solutions in filter design. The frequency is fundamental
elements of the system input/output and the signal is the limited or unlimited
combination of frequency components in general. The definition of the frequency is
introduced in the first part of this book. The digital signal processing manages the
signal in discrete time domain; however, the frequency is well understood in the
continuous time domain. The frequency for the digital signal is explained with the
sampling theory that describes the signal transformation between the continuous
and discrete time domain. The digital signal can be decomposed into the simple
1.5 What We Need for Further (Optional) 17

elements with linear and time shifting combination; therefore, the fundamental and
essential signal elements are described and defined as well.
Typically, the given signals are delivered in time domain and do not represent
the frequency information directly. To understand the signal and analyze the per-
formance, the designer needs to see the spectral distribution in the signal. The
Fourier analysis provides the mathematical tool to transform the information
between the time and frequency. The Fourier analysis computes the magnitude and
phase (or delay) of the frequencies from the periodic and non-periodic signal.
However, the Fourier analysis does not generate all-round solutions to all transform
matters. The users need to note that there are numerous limitations and conditions to
apply the analysis over the signals. The physical meaning and overall constraints of
Fourier analysis are described in this book.
The time domain filter is already introduced in this chapter. The filter equation is
primitive but essential fundamental of the signal frequency managing. Upon the
understanding of the frequency definition and Fourier analysis, the filter equation is
revisited to comprehend further based on the mathematical study. The frequency
response of the filter from the window shape and length is derived to meet the
intended filter requirements. Also, the finite window is extended to the infinite
length by recursive filter architecture and its frequency response is explored as well.
By using the frequency modulation, the low pass filter can be located in any
frequency position for designated filter specification. The simple filters based on the
frequency modulation are provided for practical filter design.
The Fourier analysis can be extended to the Z-transform to understand the signal
and system with additional perspective. The Z-transform converts the subject
between the time domain and the Z domain known as complex number plane. The
rational polynomial of complex number Z represents limited and unlimited length
signal and system with constant coefficients. The solutions to the polynomial
provide the various information such as filter type, stability, and etc. The beauty of
the Z-transform is that the transform presents powerful mathematical tool to handle
and visualize the system in simple manner. Also, the Z-transform can be adopted to
design the any type filters.
The digital filter is implemented by the digital processor (or logic) with analog to
digital converter (ADC) and digital to analog converter (DAC). Since the capability
of the processor and ADC/DAC are limited, the filter algorithm and signal repre-
sentation should be optimized in terms of computation and dimension. Numerous
concerns should be exercised to realize the digital filter in real-time processing. In
the software perspective, the algorithm can be executed quickly via using the
corresponding fast algorithms. In the other hardware viewpoint, the numbers can be
handled in the fixed- or floating-point representation that can change the execution
accuracy and speed. Therefore, the algorithm structure and format significantly
affect the filter performance in various ways.
This book extensively uses the MATLAB to understand the digital signal pro-
cessing theory throughout the chapters. In the last chapter, the comprehensive
18 1 Preliminary Digital Filter Design

digital filter design and implementation are presented via using the MATLAB from
theoretical fundamentals described by the previous chapters. The MATLAB tool-
boxes provide the effective methods to apply the complicated theory to the actual
filter system such as personal computer and embedded system. Choice for the
hardware is extensive and the MATLAB supports the full- and semi- automated
procedure in order to realize the digital signal processing system. For your infor-
mation, the basic tutorials of the MATLAB and symbolic math toolbox are orga-
nized in the appendices.
The first chapter of this book tries to inspire the readers toward the DSP world
with simple explanation. As stated above, the subsequent chapters develop the
advanced and detailed description for individual part of the theories with supportive
illustrations. From the time domain signal to frequency analysis, the major prin-
ciples are demonstrated to design the practical digital filter system. The author
challenges to visualize the underlying fundamentals of the DSP mathematics based
on the figures and illustrations for further understanding. Once the reader grasps the
idea, the theory can be realized by the MATLAB and its extensive toolboxes. The
author expects that the readers obtain the implementation-oriented DSP knowledge
from this book, hopefully.

1.6 Problems

1. Indicate the tense of signal x[.] below.


x[n]:
x[n−2]:
x[n + 3]:
2. Organize the x[.] sequence in time order from older appeared on left and newer
shown on right.
x[5], x[6], x[3], x[7], x[−2], x[9]
3. Write the simple low pass filter with recent 5 samples.
4. Write the simple high pass filter with recent 9 samples.
5. Write the simple digital filter to pass the 4-sample period signal.
6. The generalized filter equation is given below.

X
N 1
y½n ¼ x½n  k h½k
k¼0

Is it possible to realize the filter with infinite length ðN ¼ 1Þ?


7. Limiting the magnitude of the signal provides the additional frequency com-
ponents as shown below. To reverse back to input sequence, you suggest the
filter method.
1.6 Problems 19

8. According to the decomposition, what is the primitive signal? In other word,


what basic signal shape describes any other arbitrary signal by shifting and
scaling?
Chapter 2
Frequency and Signals in Discrete
Domain

Our digital system receives and produces signal which contains the information in
predictable manner. The additive noise to the signal contaminates the information in
random way; however, we assume that the DSP system in this book only considers
the discrete signal which is the sampled version of the continuous counterpart. The
signal can be represented by the combination of periodic sinusoid know as fre-
quency component. The frequency of the discrete time signal is somehow tricky to
understand directly; therefore, we borrow the frequency concept from the contin-
uous domain then apply to the discrete study. The transition between both domains
is performed by the sampling operation. The discrete time signal is further
decomposed into the primitive function that can be used for the filter characteri-
zation in Chap. 4.

2.1 Continuous Sinusoid Signals

The continuous signal is denoted by the parentheses of the function for independent
variables as xðÞ. The unit of frequency f is the cycles per second (or equivalently
Hz); therefore, the frequency represents the number of rotations within the second.
The rotation is efficiently illustrated in the complex domain with exponential power
as rejh . The r is the radius of the circle and j is the complex number. The vector
shown below Fig. 2.1 is the rejh and the function follows the circle as the radian
angle h changing.
Since the signal and frequency are the function of time, the t is placed at the
input variable as below.

xðtÞ ¼ rejXt ð2:1Þ

© Springer Nature Singapore Pte Ltd. 2021 21


K. Kim, Conceptual Digital Signal Processing with MATLAB,
Signals and Communication Technology,
https://doi.org/10.1007/978-981-15-2584-1_2
22 2 Frequency and Signals in Discrete Domain

Fig. 2.1 The rejh circular Imaginary


rotation at complex number
domain

r
θ
real

The exponential power Xt is the radian angle and, in every second, the vector
rotates for X radian. The X is known as the radian frequency that indicates the
radian per second. The conventional frequency f is related to the X as below.

X
X ¼ 2pf f ¼ ð2:2Þ
2p

Unless using the animation, the 2D polar coordinate (complex domain) barely
expresses the location variation over the time. Figure 2.2 represents the circular
rotation in 3D plot over time according to the Eq. (2.1). The figure shows all
information about the circular motion; however, it is difficult to identify the time
and radian value due to the limited viewpoint.

Fig. 2.2 The rejXt circular


rotation over time t
2.1 Continuous Sinusoid Signals 23

Prog. 2.1 MATLAB program for Fig. 2.2.


xt = @(t) t;
yt = @(t) cos(t);
zt = @(t) sin(t);
fplot3(xt,yt,zt,[0 6*pi]); %3-D plot
xL = xlim;
yL = ylim;
zL = zlim;
line([0 0], yL, [0 0],'LineWidth',1,'Color','black'); %y-axis
line(xL, [0 0], [0 0],'LineWidth',1,'Color','black'); %x-axis
line([0 0], [0 0], zL,'LineWidth',1,'Color','black'); %z-axis
...

The Cartesian coordinate solves this problem via projecting the vector onto the
real and imaginary axis. The values on each axis are located with time information
as Fig. 2.3. The projection on the real and imaginary axis are derived from the
cosine and sine function respectively.

xðtÞ ¼ rejXt ¼ rej2pft ¼ r cosð2pftÞ þ jr sinð2pftÞ ð2:3Þ

Imag.

r r
Ωτ sine
real
τ t
r
τ

cosine
r

r
t

Fig. 2.3 The projected rotation on the real (cosine) and imaginary (sine) axis
24 2 Frequency and Signals in Discrete Domain

Fig. 2.4 Graphical representation of Euler formula for cosine and sine function

The projection can figure out the cosine (real part) and sine (imaginary part)
component of the complex number. In similar manner, the conjugated complex
number (switch the imaginary part sign or change the phase sign) provides the
straightforward equations known as Euler formula as below.

ejh þ ejh ejh  ejh


cosðhÞ ¼ and sinðhÞ ¼ ð2:4Þ
2 2j

The graphical explanation is demonstrated at Fig. 2.4. The conjugated complex


number ejh is the reflection over the real axis; hence, the vector addition with the
ejh leaves the twice of the real part as 2 cosðhÞ. Divide by two on vector addition
complies with the Euler formula. The negative conjugated complex number ejh
is the reflection over the imaginary axis of the coordinates. The vector addition with
the ejh provides the twice of the imaginary part as 2j sinðhÞ. Divide by 2j on the
addition results in the above Euler formula as well.
It is important to note that the complex rotation can be transformed to the
corresponding cosine (real part) and sine (imaginary part) component by simple
linear operation with negative angle counterpart. The pair of the complex numbers
is changed to the real number. The negative frequency is used for the real valued
signal in the following chapters.
2.1 Continuous Sinusoid Signals 25

Example 2.1
Show the frequency components of r cosðXtÞ and r sinðXtÞ by Euler formula.
Solution

rejXt þ rejXt r jXt r jXt


r cosðXtÞ ¼ ¼ e þ e
2 2 2

rejXt  rejXt r r
r sinðXtÞ ¼ ¼ ejXt  ejXt
2j 2j 2j

Note that each sinusoid signal contains the positive frequency X as well as
negative frequency X component.

The conventional sinusoidal signal is represented by the cosine and sine func-
tion. The phased sinusoid can be decomposed into the non-phased cosine and sine
function as Eq. (2.5). The ReðÞ operator compute the real part value from complex
number.
   
A cosðXt þ hÞ ¼Re AejðXt þ hÞ ¼ Re Aejh ejXt
 
¼Re ðA cosðhÞ þ Aj sinðhÞÞejXt
 p 
¼Re A cosðhÞejXt þ Aej2 sinðhÞejXt
 
¼Re A cosðhÞejXt þ A sinðhÞejðXt þ 2Þ
p

 p
¼A cosðhÞ cosðXtÞ þ A sinðhÞ cos Xt þ
2
¼A cosðhÞ cosðXtÞ  A sinðhÞ sinðXtÞ ð2:5Þ

Observe the signal shift in Fig. 2.5. By adding or subtracting, the xðtÞ moves to
left or right respectively with assumption of positive s.
Note the following equivalences in trigonometry for reference.

Fig. 2.5 The time shift of signal x(t)


26 2 Frequency and Signals in Discrete Domain

Prog. 2.2 MATLAB program for Fig. 2.6.


ome = -2*pi:pi/100:2*pi;
x1 = cos(ome);
x2 = sin(ome);
str = {'-2\pi','-3\pi/2','-\pi','-\pi/2','0','\pi/2','\pi','3\pi/2','2\pi'};

figure,
subplot(221), plot(ome,x1,ome,x2), grid
xticks([-2*pi -3*pi/2 -pi -pi/2 0 pi/2 pi 3*pi/2 2*pi])
xticklabels(str);
xlim([-2*pi 2*pi])
ylim([-1.5 1.5])

subplot(222), plot(ome,x1,ome,x2,ome,-x2), grid


xticks([-2*pi -3*pi/2 -pi -pi/2 0 pi/2 pi 3*pi/2 2*pi])
xticklabels(str);
xlim([-2*pi 2*pi])
ylim([-1.5 1.5])

subplot(223), plot(ome,x1,ome,-x1), grid


xticks([-2*pi -3*pi/2 -pi -pi/2 0 pi/2 pi 3*pi/2 2*pi])
xticklabels(str);
xlim([-2*pi 2*pi])
ylim([-1.5 1.5])
xlabel('\theta')

subplot(224), plot(ome,x2,ome,-x2), grid


xticks([-2*pi -3*pi/2 -pi -pi/2 0 pi/2 pi 3*pi/2 2*pi])
xticklabels(str);
xlim([-2*pi 2*pi])
ylim([-1.5 1.5])
xlabel('\theta')

Example 2.2
What is the meaning of below equation?

A cosðXt þ hÞ ¼ A cosðhÞ cosðXtÞ  A sinðhÞ sinðXtÞ

Solution
The linear combination of weighted cosðXtÞ and sinðXtÞ provides the any arbitrary
magnitude and phase cosine function. The weights are derived from the constant
magnitude and phase. The time dependent terms present the frequency of the signal.

2.1 Continuous Sinusoid Signals 27

Fig. 2.6 The graphical illustrations for certain trigonometry equivalences

As shown in Eq. (2.5), the phased cosine function is divided into the non-phased
cosine and sine function with modified magnitude for A cosðhÞ and A sinðhÞ
respectively. Without the phase, the cosine and sine function are inherently even
and odd function that are described as below.

xe ðtÞ ¼ xe ðtÞ; xo ðtÞ ¼ xo ðtÞ ð2:6Þ

The even function is symmetric with respect to the y axis and the odd function is
symmetric with respect to the origin of the coordinates as shown in Fig. 2.7. Every
function can be decomposed into the even and odd function that can be found by
Eq. (2.7). The conventional phased sine and cosine function can be written as the
sum of the non-phased cosine (even function) and non-phased sine (odd function)
as well.

xðtÞ þ xðtÞ xðtÞ  xðtÞ


xðtÞ ¼ xe ðtÞ þ xo ðtÞ; xe ðtÞ ¼ ; xo ðtÞ ¼ ð2:7Þ
2 2
28 2 Frequency and Signals in Discrete Domain

Fig. 2.7 Even and odd


function example

Example 2.3
Find the even and odd function of xðtÞ ¼ A cosðXt þ hÞ.
Solution

xðtÞ þ xðtÞ cosðXt þ hÞ þ cosðXt þ hÞ


xe ðtÞ ¼ ¼A
2 2
ejXt ejh þ ejXt ejh þ ejXt ejh þ ejXt ejh
A
  4  
ejXt ejh þ ejh þ ejXt ejh þ ejh ejXt þ ejXt
¼A ¼ A cosðhÞ
4 2
¼A cosðhÞ cosðXtÞ

xðtÞ  xðtÞ cosðXt þ hÞ  cosðXt þ hÞ


xo ð t Þ ¼ ¼A
2 2
ejXt ejh þ ejXt ejh  ejXt ejh  ejXt ejh
A
  4  
ejXt ejh  ejh  ejXt ejh  ejh ejXt  ejXt
¼A ¼ Aj sinðhÞ
4 2
¼  A sinðhÞ sinðXtÞ

On the contrary, the multiple sinusoids can be converted to the single sinusoid
term by using the phasor. The combining the sinusoids is only applied to the
identical frequency functions; in other words, the different frequency sinusoids
cannot be merged together to the single term. The phasor indicates the static vector
of the sinusoid as below.

Aejh ¼ PhasorfA cosðXt þ hÞg ð2:8Þ

For the identical frequency, the sum of multiple sinusoids uses the phasor as
shown below.
2.1 Continuous Sinusoid Signals 29

   
A1 cosðXt þ h1 Þ þ A2 cosðXt þ h2 Þ ¼ Re A1 ejðXt þ h1 Þ þ Re A2 ejðXt þ h2 Þ
 
¼ Re A1 ejðXt þ h1 Þ þ A2 ejðXt
þ h2 Þ
 
¼ RenejXt A1 ejh1 þ o A2 e
jh2
¼ Re ejXt A3 ejh3
¼ Re A3 ejðXt þ h3 Þ ¼ A3 cosðXt þ h3 Þ

Using the phasor, we can directly compute the magnitude and phase of the
sinusoid sum as below.

PhasorfA1 cosðXt þ h1 Þg þ PhasorfA2 cosðXt þ h2 Þg


ð2:9Þ
¼ A1 ejh1 þ A2 ejh2 ¼ A3 ejh3 ! A3 cosðXt þ h3 Þ

The addition of multiple complex numbers can be illustrated by the vector


addition as shown in Fig. 2.8. The phasor in polar coordinates should be trans-
formed to the cartesian coordinates for addition and transformed back to the polar
coordinates to apply on the sinusoid form.
The complex addition of A1 ejh1 and A2 ejh2 means the new magnitude and phase
for the combined sinusoid as A3 ejh3 . Then, simply apply on the derived sinusoid like
A3 cosðXt þ h3 Þ to produce the single term. Once the sinusoid frequencies are equal,
the phasor addition simplifies the linearly combined sinusoids in uncomplicated

Fig. 2.8 Phasor addition


A1 ejh1 þ A2 ejh2 ¼ A3 ejh3
30 2 Frequency and Signals in Discrete Domain

form. Provided that the frequencies are not identical, the further simplification is not
applicable; therefore, the present equation is the last step for mathematical
maneuver as below.

If f1 6¼ f2 ; then
A1 cosð2p f1 t þ h1 Þ þ A2 cosð2p f2 t þ h2 Þ
6¼ A3 cosð2p f3 t þ h3 Þ
8 A1;2;3 ; h1;2;3 ; f1;2;3 2 R

Example 2.4
Add the sinusoid cosðXtÞ þ sinðXt þ pÞ.
Solution

 
cosðXtÞ þ sinðXt þ pÞ ¼ cosðXt Þ þ sin  Xt þ p2 þ p2
¼ cosðXtÞ þ cos Xtþ p2  
! PhasorfcosðXtÞg þ Phasor cos Xt þ p2
pffiffiffi jp=4
¼ ej0 þ ejp=2
pffiffiffi ¼ 1þ j ¼ p 2e
! 2 cos Xt þ 4

The continuous linear combination of the sinusoids can present any arbitrary
signal as shown below.

Z1
xð t Þ ¼ mðXÞ cosðXt þ hðXÞÞ dX 2 R ð2:10Þ
0

Using the Eq. (2.5), the phased cosine function can be represented by the
non-phased sinusoid functions as below.

Z1 Z1
xðtÞ ¼ mðXÞ cosðhðXÞÞ cosðXtÞ dX  mðXÞ sinðhðXÞÞ sinðXtÞ dX
0 0
ð2:11Þ
Z1 Z1
¼ aðXÞ cosðXtÞ dX  bðXÞ sinðXtÞ dX
0 0

aðXÞ ¼ mðXÞ cosðhðXÞÞ
where
bðXÞ ¼ mðXÞ sinðhðXÞÞ
2.1 Continuous Sinusoid Signals 31

The Euler formula further decomposes the equation into the analytic represen-
tation as below.
Z1 Z1
ejXt þ ejXt ejXt  ejXt
xð t Þ ¼ aðXÞ dX  bðXÞ dX
2 2j
0 0
Z1
Z1

aðXÞ jXt bðXÞ jXt aðXÞ jXt bðXÞ jXt
¼ e  e dX þ e þ e dX
2 2j 2 2j
0 0
Z1 Z1
aðXÞ þ jbðXÞ jXt aðXÞ  jbðXÞ jXt
¼ e dX þ e dX
2 2
0 0

For negative radian frequency X, the integrand of the integral should maintain
the even function for symmetrical purpose as below.

mðXÞ cosðXt þ hðXÞÞ ¼ mðXÞ cosðXt þ hðXÞÞ

The individual functions in the integrand must demonstrate the following


symmetric properties to meet the above equation condition.

mðXÞ ¼ mðXÞ

hðXÞ ¼ hðXÞ

The magnitude and phase function in the sinusoid present the even and odd
symmetric property, respectively. The corresponding aðXÞ and bðXÞ show the
below symmetric properties as well.

aðXÞ ¼ mðXÞ cosðhðXÞÞ ¼ aðXÞ ¼ mðXÞ cosðhðXÞÞ

bðXÞ ¼ mðXÞ sinðhðXÞÞ ¼ bðXÞ ¼ mðXÞ sinðhðXÞÞ

By applying the symmetric properties, the integrals are combined together as below.

Z1 Z0
aðXÞ þ jbðXÞ jXt aðXÞ  jbðXÞ jXt
xð t Þ ¼ e dX þ e dX
2 2
0 1
Z1 Z0
aðXÞ þ jbðXÞ jXt aðXÞ þ jbðXÞ jXt
¼ e dX þ e dX
2 2
0 1
Z1 Z1
aðXÞ þ jbðXÞ jXt
¼ e dX ¼ cðXÞejXt dX
2
1 1
32 2 Frequency and Signals in Discrete Domain

In short, the derived equation is organized as below.


8
Z1 < aðXÞ ¼ mðXÞ cosðhðXÞÞ
xðtÞ ¼ cðXÞejX t dX where bðXÞ ¼ mðXÞ sinðhðXÞÞ ð2:12Þ
:
1 cðXÞ ¼ aðXÞ þ2 jbðXÞ

The arbitrary signal xðtÞ can be divided into the continuous linear combination of
cðXÞejX t . Once we can find the complex magnitude cðXÞ of the analytic signal ejX t
for radian frequency X, we can represent the time domain signal xðtÞ by using the
integral as below.

Z1 Z1
xðtÞ ¼ aðXÞ cosðXtÞdX  bðXÞ sinðXtÞdX ð2:13Þ
0 0

Equivalently, the integral of phased cosine function can be used as below.


Z1
xðtÞ ¼ mðXÞ cosðXt þ hðXÞÞdX
0

Equations (2.10), (2.11), and (2.12) are synthesis equations of the Fourier
transform which tells us that infinite combination of the frequencies provides the
arbitrary time function of interest. The cðXÞ is derived by the following equation by
using the orthogonality of the sinusoid.
8 9
Z1 Z1 < Z1 =
xðtÞejX t dt ¼ cðWÞejWt dW ejX t dt
: ;
1 1 1
Z1 Z1
¼ cðWÞejðWXÞt dt dW
1 1
8 1 9
Z1 <Z =
¼ cð W Þ ejðWXÞt dt dW
: ;
1 1

Z1
where xðtÞ ¼ cðWÞejWt dW
1

The inner term of the above equation is the integral of the periodic signal ejðWXÞt
over the infinite range. The signal frequency is the ðW  XÞ radian per second and
the corresponding period T is defined as 2p=ðW  XÞ. The integral is divided into
the two cases as W 6¼ X and W ¼ X. For the non-equal case, the periodic signal
2.1 Continuous Sinusoid Signals 33

ejðWXÞt has finite period T and the integral is segmented & repeated into the
individual periods with infinite number k multiplication. The other case, which is
the equal case, the infinite period T provides the single long infinite period for the
integral range. The complex exponential function can be written as sine and cosine
function in segmented form as below.

Z1 Z1 Z 1
jðWXÞt
e dt ¼ cosððW  XÞtÞdt þ j sinððW  XÞtÞdt
1
1 1

Z
T
2 Z T
2
¼ lim k cosððW  XÞtÞdt þ j lim k sinððW  XÞtÞdt
k!1 k!1 T2
2
T

k2Z k2Z

The period T depends on the sinusoid radian frequency ðW  XÞ as below.

2p

ðW  XÞ

Figure 2.9 demonstrates the approximated equivalence between the entire range
and one period sinusoid integral. The one period integral on sinusoid denotes the
zero; therefore, the entire range integral should be zero for conventional case.

Fig. 2.9 Approximation of entire sinusoid integral with one period integral
34 2 Frequency and Signals in Discrete Domain

Prog. 2.3 MATLAB program for Fig. 2.9.


t = -6*pi:pi/100:6*pi;
t1 = pi/2:pi/100:5*pi/2;
x = cos(t);
x1 = cos(t1);

figure,
subplot(211), plot(t,x,'Color','k'), grid
hold on
stem(t,x,'Marker','none')
hold off

subplot(212), plot(t,x,'LineStyle',':','Color','k'), grid


hold on
stem(t1,x1,'Marker','none')
hold off

The one period sinusoid provides the following integral values on the frequency
conditions.
Z2
T

0 for W 6¼ X
sinððW  XÞtÞdt ¼
0 for W ¼ X
T2

Z2
T

0 for W 6¼ X
cosððW  XÞtÞdt ¼
T for W ¼ X
T2

The integral on complex exponential is arranged as below. Note that the W ¼ X


condition produces the infinite T value. Therefore, the one period of integral is valid.

Z1
ejðWXÞt dt
1

8 2 3
>
> R2
T
R2
T
>
> lim k4 cosððW  XÞtÞdt þ j sinððW  XÞtÞdt5 ¼ 0 for W 6¼ X
>
>
>
< k ! 1 T2 T2
¼ k2N
>
>
>
> R2
T
R2
T
W¼X
>
> cosððW  XÞtÞdt þ j sinððW  XÞtÞdt ¼ T for T ¼ 2p ¼ 1
>
: T
2 T
2 ðWXÞ
2.1 Continuous Sinusoid Signals 35

R1
Fig. 2.10 1 ejðWXÞt dt at
W¼X

Both case integral results are shown below.


Z1
0 for W 6¼ X
ejðWXÞt dt ¼ T ¼ 2p ¼ 1 for W ¼ X ð2:14Þ
ðWXÞ
1

The non-zero outcome T is appeared at the equal moment between W and X. The
instantaneous value at the equal situation is the infinite as shown below.
The area of the given equation over the W  X axis is 2p when the W and
X are equal. The rectangular base shown in Fig. 2.10 is approaching to the zero
because of the instant moment ðW ¼ XÞ and the height is advanced to the 2p=0 from
the integral computation. We cannot directly compute the rectangular area by mul-
tiplication due to the 0/0 condition; however, the result is 2p in mathematics
(L’Hospital’s rule) [1]. Note that this intuitive and graphical illustration is not valid for
the mathematical proof in a strict sense; therefore, the reader should refer the Dirac
delta function [2] for further information. In simple form, the result is presented below.
Z1
ejðWXÞt dt ¼ 2pdðW  XÞ ð2:15Þ
1

The dðW  XÞ is Dirac delta function (in short delta function) that only provides
the infinite output at the zero-input condition. Also, the total area of the delta
function is one. The characteristic is shown in below.

Z1
1 for t ¼ 0
dðtÞ ¼ and dðtÞdt ¼ 1 ð2:16Þ
0 for t 6¼ 0
1

With the continuous domain ðt 2 RÞ, the delta function provides the method to
specify the value on the particular position. The inevitable interference with adjacent
positions is avoided by the zero width on continuous domain. The value cannot be
built on the empty space; hence, the area of zero width is designed to be one as shown
in Eq. (2.16) and Fig. 2.10. The application of delta function is shown at Eq. (2.17).

Z1
1 for t ¼ t0
xðtÞdðt  t0 Þ ¼ and xðtÞdðt  t0 Þdt ¼ xðt0 Þ ð2:17Þ
0 for t ¼
6 t0
1
36 2 Frequency and Signals in Discrete Domain

Continuously solve the double integral problem.


8 1 9
Z1 <Z = Z1
cð W Þ ejðWXÞt dt dW ¼ cðWÞ2pdðW  XÞdW
: ;
1 1 1
ð2:18Þ
Z1
¼ 2pcðXÞ dðW  XÞdW ¼ 2pcðXÞ
1

Note that the dðW  XÞ shows the value only at the W ¼ X situation; therefore,
W and X are interchangeable. The cðWÞ is escaped from the integral by replacing
the input argument. Hence, this procedure presents the analysis equation of the
Fourier transform which presents the magnitude of the individual frequency com-
ponent as cðXÞ. The derived equation is shown below.
Z1
1
cðXÞ ¼ xðtÞejX t dt ð2:19Þ
2p
1

Once we know the frequency magnitude cðXÞ, the time domain function can be
synthesized by below.
Z1
xðtÞ ¼ cðXÞejX t dX ð2:20Þ
1

The general form of Fourier transform [3] is given as below.


8
> R1
>
< X ðX Þ ¼ xðtÞejX t dt
1
Let the X ðXÞ ¼ 2pcðXÞ R1 ð2:21Þ
>
>
: xðtÞ ¼ 2p
1
X ðXÞejX t dX
1

The pair of the Fourier transform equations provides the frequency distribution
of the continuous time signal. The analysis equation computes complex magnitude
X ðXÞ which represents the height and position of the cosine function at the radian
frequency X. From the given X ðXÞ, the synthesis equation derives the corre-
sponding time signal. Observe that the xðtÞ is generally real value continuous time
signal; hence, X ðXÞ should be distributed in certain rule as real part in even
symmetric and imaginary part in odd symmetric.
Example 2.5
Compute and draw X ðXÞ of below signal.

1 for  1  t  1
xðtÞ ¼
0 Otherwise
2.1 Continuous Sinusoid Signals 37

Solution

Z 1
1
ejX t ejX  ejX 2 sinðXÞ
X ðXÞ ¼ ejX t dt ¼ ¼ ¼
1 jX 1 jX X

Prog. 2.4 MATLAB program for Fig. 2.11.

syms t;
b = [-100:1/100:100];
x1 = heaviside(t+1) - heaviside(t-1);
y2 = 2*(sin(b+eps))./(b+eps); %Add eps to avoid NaN
figure,
subplot(211), ezplot(x1, [-2 2]), grid
axis([-2 2 -0.2 1.2]);
subplot(212), plot(b, y2), grid
axis([-100.0000 100.0000 -0.5 2.2])


The frequency component of the given time window is 2 sinðXÞ=X that is known
as the (unnormalized) sinc function [4]. The synthesis equation from Fourier
transform provides the original time window as well. Due to the requirement of

Fig. 2.11 x(t) and corresponding X ðXÞ by Fourier transform


38 2 Frequency and Signals in Discrete Domain

further understanding on Fourier transform, the inverse transform is performed with


numerical method as below.

Z1
1
xðtÞ ¼ X ðXÞejXt dX
2p
1
Z1 Z0
1 1 1 2 sinðXÞ
¼ X ð0Þ þ X ðXÞe dX þ
jXt
X ðXÞejXt dX; X ðXÞ ¼
2p 2p 2p X
0þ 1
Z1 Z1
1 1 1
¼ X ð0Þ þ X ðXÞejXt dX þ X ðXÞejXt dX
2p 2p 2p
0þ 0þ
Z1
1 1
¼ X ð0Þ þ X ðXÞðejXt þ ejXt ÞdX * X ðXÞ ¼ X ðXÞ
2p 2p

Z1
1 1
¼ X ð0Þ þ 2X ðXÞ cosðXtÞdX
2p 2p

( )
1 1X N
 X ð0Þ þ X ðXk Þ cosðXk tÞ 2pDf ¼ ~xðtÞ ð2:22Þ
2p p k¼1

In the last step of the above derivation, the numerical integration is adopted to
compute the integral part where Xk is the discrete radian frequency as 2pDf k with
Df frequency distance. Figure 2.12 illustrates the X ðXÞ ¼ 2sinðXÞ=X and inverse
transformed ~xðtÞ by numerical method for 10p  Xk  10p.

Fig. 2.12 X ðXÞ and corresponding ~xðtÞ by numerical Fourier transform for 31:4  Xk  31:4
2.1 Continuous Sinusoid Signals 39

Prog. 2.5 MATLAB program for Fig. 2.12.


delf = 0.1; % Frequency interval
delt = 0.001; % Time interval
fmax = 30/(2*pi);
tmax = 2;
ff = 0.1:delf:fmax;
tt = -tmax:delt:tmax;
out = [];
f1 = 2*pi*(-fmax:delf:fmax);
xc = 2*sin(f1+eps)./(f1+eps);

for k1 = tt % time
temp = 0;
for k2 = ff % frequency
temp = temp + sin(2*pi*k2)*cos(2*pi*k2*k1)/(2*pi*k2);
end
out = [out ((temp*2/pi)+(1/pi))*2*pi*delf];
end

figure,
subplot(211), plot(f1,xc), grid
axis([-100.0000 100.0000 -0.5 2.2])
subplot(212), plot(tt,out), grid
axis([-2 2 -0.2 1.2]);

The reconstructed x(t) presents the approximated window shape in the time
domain. The wide fluctuations and transitions are observed due to the limited fre-
quency range in the inverse Fourier transform. Figure 2.13 illustrates the X ðXÞ and
~xðtÞ by numerical method for extended frequency range. The further accurate window
shape is realized by the inverse transform with wider spectrum range. The fluctuations
and transitions are both narrow to follow the precise window shape in time domain.
Prog. 2.6 MATLAB program for Fig. 2.13. Exactly identical to Prog. 2.5 except
following.

...
fmax = 100/(2*pi);
...

Figures 2.12 and 2.13 illustrate the simulated inverse Fourier transform to obtain
the relationship between the frequency range and reconstructed shape. The wider
spectrum of the given equation provides the more accurate representation of the
original time signal. The inverse transform expects to deliver the exact time signal
40 2 Frequency and Signals in Discrete Domain

Fig. 2.13 X ðXÞ and corresponding ~xðtÞ by numerical Fourier transform for 100  Xk  100

once the infinite range and continuous frequency is applied to the integral. The
infinite distribution of the frequencies generates the designed arbitrary signal in
time domain and vice versa. Therefore, the frequency is the primitive elements of
the signal.

2.2 Sampling

The sampling is the procedure to convert the continuous signal into the discrete
version as data sequence. The discrete time signal samples the continuous signal as
real number at the specific time locations which are the integer multiple of specific
period. Therefore, the converter reads the instantaneous magnitude of the contin-
uous time signal in every constant interval and generates the data sequence for
further processing. The mathematical and graphical representation are below in
Fig. 2.14.

x½n ¼ xðnTs Þ n 2 Z; x½; xðÞ; Ts 2 R ð2:23Þ

The Ts is the sampling period and fs ¼ 1=Ts is the sampling frequency which
denotes the number of reading or sampling per second. Usually, the sampling is
specified by the sampling frequency and the higher fs describes the signal in further
detail. What is the minimum sampling frequency? Let’s consider the sinusoid signal
in Fig. 2.15.
2.2 Sampling 41

Fig. 2.14 Continuous and discrete time signal example with Ts sampling period

Fig. 2.15 Sampling the sinusoid signal with various sampling frequencies fs (or sampling period
Ts)
42 2 Frequency and Signals in Discrete Domain

Prog. 2.7 MATLAB program for Fig. 2.15.


nn0 = 0:pi/100:2*pi;
nn1 = 0:pi/10:2*pi;
nn2 = 0:pi:2*pi;
nn3 = [0 (3*pi/2+2*pi)/2];

xn0 = cos(nn0);
xn1 = cos(nn1);
xn2 = cos(nn2);
xn3 = cos(nn3);

figure,
subplot(311)
plot(nn0,xn0,'k','LineStyle','--');
hold on
stem(nn1,xn1);
hold off
subplot(312)
plot(nn0,xn0,'k','LineStyle','--');
hold on
stem(nn2,xn2);
hold off
subplot(313)
plot(nn0,xn0,'k','LineStyle','--');
hold on
stem(nn3,xn3);
hold off

The given sinusoid cosðXtÞ is sampled by the three fs in high on top, minimum
on middle, and low on bottom in Fig. 2.15. The performance of the sampling can be
defined by the representation accuracy after conversion and restoration between the
domains. For the time being, we assume that the restoration to the continuous signal
is performed by connecting the adjacent values in discrete domain with straight line.
The high sampling frequency depicts the sinusoid with fine detail; however, the low
sampling frequency cannot recover the original signal by connecting dots. The
improper sampling changes the signal frequency to the lower value; hence, the
2.2 Sampling 43

Fig. 2.16 Sampling the sinusoid signal with various sampling phase and identical sampling
frequency fs

original signal is contaminated by that frequency shift. The sampling rate in the
middle figure provides the minimum proper sampling frequency for the given
sinusoid as twice sampling reading in one signal period. The minimum rate may
cause reduced signal magnitude due to the out of phase sampling as Fig. 2.16 but
the signal frequency is preserved. The decision between the proper and improper
sampling is performed based on the frequency shift from the conversion process. In
general, the sampling is executed in marginally higher rate than the minimum
requirement.
44 2 Frequency and Signals in Discrete Domain

Prog. 2.8 MATLAB program for Fig. 2.16.


nn0 = 0:pi/100:2*pi;
nn2 = 0:pi:2*pi;
nn4 = nn2+pi/4;
nn5 = nn2+pi/2;
xn0 = cos(nn0);
xn2 = cos(nn2);
xn4 = cos(nn4);
xn5 = cos(nn5);

figure,
subplot(311)
plot(nn0,xn0,'k','LineStyle','--');
hold on
stem(nn2,xn2);
hold off
ylim([-1.5 1.5])
xlim([0 2*pi])
subplot(312)
plot(nn0,xn0,'k','LineStyle','--');
hold on
stem(nn4,xn4);
hold off
ylim([-1.5 1.5])
xlim([0 2*pi])
subplot(313)
plot(nn0,xn0,'k','LineStyle','--');
hold on
stem(nn5,xn5);
hold off
ylim([-1.5 1.5])
xlim([0 2*pi])

Let’s apply the above theory to the more typical signal, the bandlimited continuous
signal, as Eq. (2.24). The signal xðtÞ contains frequency distribution up to the Xmax
the highest frequency. As shown Fig. 2.15, the higher signal frequency requires the
higher sampling rate correspondingly. Once we select the proper sampling parameter
for Xmax , the signals in lower frequencies fit in well with the sampling condition.

ZXmax
xðtÞ ¼ mðXÞ cosðXt þ hðXÞÞdX ð2:24Þ
0
2.2 Sampling 45

Fig. 2.17 Sampling the band non-limited continuous signal with preprocessing

The general theory of sampling frequency known as Nyquist rate [5] is specified
below.

fs [ 2fmax Xmax ¼ 2pfmax ð2:25Þ

In order to satisfy the sampling condition for the highest frequency, the sampling
reading should be performed at least twice within the highest frequency signal
period. In other words, the sampling frequency must be higher than the twice of the
frequency maximum used in the bandlimited signal. This is the Nyquist sampling
rate. The lower than the Nyquist rate produces the frequency shift and causes
spectral contamination in high signal frequencies. Upon the cases such as
non-limited frequency band signal and limited sampling capability system, the
preprocessing is required to removes frequencies above Xmax . The low pass filter
tailors the frequency distribution and the sampling process does not initiate the
signal representation problems. The preprocessing is illustrated below in Fig. 2.17.
Example 2.5
Find the minimum sampling rate for following signal.
 p
xðtÞ ¼ cosð100ptÞ þ sinð200ptÞ þ cos 500pt þ þ7
4

Solution
The highest frequency of the x(t) is Xmax ¼ 500p. Therefore, fmax is 250 Hz.
According to the Nyquist rate, the minimum sampling rate is below.

fs [ 2fmax ¼ 500 Hz


46 2 Frequency and Signals in Discrete Domain

2.3 Signal Representation

The fundamental of the discrete time signal is delta function (Kronecker delta
function [6]) as Fig. 2.18. Whenever the input argument in the square bracket is
zero, the delta function provides the one; otherwise, the output is always zero.

1 n¼0
d½n ¼ ð2:26Þ
0 Otherwise

The delta function is very useful signal in order to specify the sequence location.
Let’s consider the arbitrary discrete time signal as Fig. 2.19.
The discrete time signal x½n is the finite or infinite combination of individual
values such as x½0; x½1; x½2; x½3; x½4; and etc. However, the simple linear com-
bination of the individual values cannot represent the x½n due to the missing
sequence location for each value as below.

Fig. 2.18 Delta function (Kronecker delta function)

Fig. 2.19 Discrete time signal example x[n]

Fig. 2.20 Combination of weighted and shifted delta functions for arbitrary x[n]
2.3 Signal Representation 47

X
1
x½n 6¼    þ x½0 þ x½1 þ x½2 þ x½3 þ x½4 þ    ¼ x½k ¼ Constant
k¼1

The simple sum of the discrete values is only constant value that cannot stand for
the time varying sequence x½n. The delta function supports to indicate the sequence
location as Eq. (2.27).

x½n ¼    þ x½0d½n þ x½1d½n  1 þ x½2d½n  2 þ x½3d½n  3


P
1
ð2:27Þ
þ x½4d½n  4 þ    ¼ x½kd½n  k
k¼1

The graphical illustration of Eq. (2.27) is shown in Fig. 2.20.


The multiplication with delta function presents the sequence position in n do-
main. For example, x½3d½n  3 shows the value x½3 only at the n = 3 because of
the delta function. Therefore, each value has the corresponding position specifier as
delta function to illustrate part or whole of the given function. The delta function is
very fundamental for the discrete time signal to demonstrate and decompose into
the individual values.
Example 2.6
Describe the following signal with delta function.

2 for  2  n  1
x½n ¼
0 Otherwise

Solution

x½n ¼ 2d½n þ 2 þ 2d½n þ 1 þ 2d½n þ 2d½n  1


The derived signals from the delta function are unit-step function and ramp
function as below.

1 n0
u½n ¼ ð2:28Þ
0 n\0

n n0
r½n ¼ ð2:29Þ
0 n\0

The graphical illustration of Eqs. (2.28) and (2.29) is shown in Fig. 2.21.
48 2 Frequency and Signals in Discrete Domain

Fig. 2.21 Unit-step function u[n] and ramp function r[n]

The unit-step function has the value one after the n is greater than and equal to
zero. The ramp function shows the linearly increasing output when the n is positive
and zero. The relation between those functions are organized as Eqs. (2.30) and
(2.31).
Pn Pn
d½k  u½k1
d½n !u½n !r ½n ð2:30Þ
k¼1 k¼1

u½nu½n1 r½n þ 1r½n


d½n u½n r ½n ð2:31Þ

The summation from the minus infinite to the present time n transforms the delta
function to the unit-step and ramp function in each time. The difference between
adjacent values convert the ramp function to the unit-step and delta function in
consecutive time.
From the given signal x½n, we can change the signal position by shifting,
reflecting, and scaling in sequence. The signal shift can be performed by adding or
subtracting the constant value in the sequence variable as x½n þ d . The shift
operation depicts the given function by changing the sequence variable to the n þ d;
however, the actual horizontal axis is indexed by n variable. Overall, the given
function moves to the right for the negative d and to the left for the positive d value
as shown in Fig. 2.22.

Fig. 2.22 Shifting the function in time domain


2.3 Signal Representation 49

Fig. 2.23 Signal flipping over the vertical axis

The signal can be flipped over the vertical axis by reflection which can be
performed by changing the sign of the sequence variable. For example, the signal
x½n exchanges the position between the positive and negative index values from
the x½n as Fig. 2.23.
The discrete time signal can be expanded or compressed over the horizontal axis
by multiplying the constant value on the sequence variable. As stated below, the
q value decides the shape of the signal after the operation.

q times compressed; for q [ 1; q 2 N
x½qn ¼ ð2:32Þ
1=q time expaned; for 0\q\1; q 2 Q

qn 2 Z; otherwise x½qn ¼ 0

The sequence index is scaled by q and the corresponding qn position values are
placed at the n index. For the q as natural number greater than 1, the x½qn is the
compressed version of x½n. For example, the q is equal to 2 then the
. . .x½2; x½0; x½2; x½4; . . . moves to the . . .x½1; x½0; x½1; x½2; . . ., respectively.
For the q as positive rational number less than 1, the x½qn is the expanded version
of x½n. For example, the q is equal to 1/2 then the . . .x½1; x½0; x½1; x½2; . . .
moves to the . . .x½2; x½0; x½2; x½4; . . ., correspondingly. In the expansion, the
unassigned values between the relocated signal are zero and further processing
computes the median values from the adjacent magnitudes upon the request. The
illustration of compression and expansion is given in Fig. 2.24.
The combination of shifting, reflecting, and scaling in sequence should be
executed with operation priority. The general order is the reflection, (time) scaling,
and shifting for the x½qðn  d Þ form; therefore, the sequence variable is collected
by the scaling constant and reflection sign first.

x½n ! x½n ! x½qn ! x½qðn  d Þ ð2:33Þ


Reflection Scaling Shifting

Example 2.7
Draw the x½2ðn  1Þ of given x[n].

x½n ¼ 5d½n þ 4d½n  1 þ 3d½n  2 þ 2d½n  3 þ d½n  4


50 2 Frequency and Signals in Discrete Domain

Fig. 2.24 Signal compression and expansion by time scaling

Solution
The combination is below.

x½n ! x½n ! x½2n ! x½2ðn  1Þ


Reflection Scaling Shifting

Below figure shows the above procedure.

5 5
4 4
3 3
2 2
1 1
n n
-5 -4 -3 -2 -1 0 1 2 3 4 5 -5 -4 -3 -2 -1 0 1 2 3 4 5

x[n] Reflecting x[-n]


Scaling

5 5
3 3
1 1
n n
-5 -4 -3 -2 -1 0 1 2 3 4 5 -5 -4 -3 -2 -1 0 1 2 3 4 5

x[-2(n-1)] Shi ing x[-2n]


2.3 Signal Representation 51

Fig. 2.25 Combination of reflecting and shifting in sequence

If you do not have scaling in the sequence, you may shift the function directly
without collecting the variable. The shifting direction depends on the processing
sequence as shown in Fig. 2.25. Overall, the given function moves to the left for the
positive d and to the right for the negative d in expanded form as n þ d. Observe
that the shifting, reflecting, and scaling operation replace the n with (n − d), (−n),
and (an), respectively.
Previously, we decompose the arbitrary discrete signal into the delta functions.
The sequence position is defined by the shifted delta function and magnitude is
specified by the function scale factor as below.

x½n ¼    þ x½0d½n þ x½1d½n  1 þ x½2d½n  2 þ x½3d½n  3


P
1
ð2:34Þ
þ x½4d½n  4 þ    ¼ x½kd½n  k
k¼1

The most elemental part of the discrete time signal is the delta function which
can describe the arbitrary function by linear combination of shifted versions.
Provided that the system satisfies the shifting, scaling, and linearity for the output,
we can represent the system by simple function. The required properties for the
system are time invariance and linearity as Fig. 2.26.
The time invariance is the property that the time shift in input signal provides the
identical shift in output signal without modifying any output distribution. The
linearity consists of two properties which are scalability and additivity. The scal-
ability is provided by the proportional output magnitude from the input scale in
exact manner. For instance, if you increase the input signal by two, the output is
amplified twice scale for all values. The additivity is related to the signal decom-
position. The system output from the whole input signal is equal to the sum of the
individual outputs from decomposed inputs. Usually, the additivity allows you to
separate the input signal in time domain; therefore, the individual sequence output
is accumulated for the final output. The overall time invariance and linearity
property are organized in Eqs. (2.35) and (2.36).
52 2 Frequency and Signals in Discrete Domain

Fig. 2.26 Linear and time-invariant system example

y½n ¼ Sfx½ng then y½n  d  ¼ Sfx½n  d g; 8 d 2 Z ð2:35Þ

x½n ¼ ax1 ½n þ bx2 ½n then y½n ¼ Sfx½ng


ð2:36Þ
¼ Sfax1 ½n þ bx2 ½ng ¼ aSfx1 ½ng þ bSfx2 ½ng

The linear and time invariant (LTI) system simplifies the output computation due
to the input signal property. The input is linear combination of shifted delta
functions; therefore, the output is also linear combination of shifted output from
delta function. Once we obtain the response of the delta function, the output of any
input can be computed by simple operation. Since we call the delta function as
impulse, the output of the delta function is known as impulse response. The output
computation from the impulse response is illustrated in Eq. (2.37).

h½n ¼Sfd½ng
y½n ¼Sfx½ng ¼ Sf. . . þ x½0d½n þ x½1d½n  1 þ x½2d½n  2 þ   g
¼    þ x½0Sfd½ng þ x½1Sfd½n  1g þ x½2Sfd½n  2g þ   
ð2:37Þ
¼    þ x½0h½n þ x½1h½n  1 þ x½2h½n  2 þ   
X 1
¼ x½kh½n  k ¼ y½n
k¼1

Example 2.8
From the given impulse response h[n] as below, determine the LTI system output of
shown input x[n].

h½n ¼ d½n þ d½n  1

x½n ¼ d½n  d½n  2


2.3 Signal Representation 53

Solution
Let’s decompose the input x[n] as below.

x1 ½n ¼ d½n
x½n ¼ x1 ½n þ x2 ½n where
x2 ½n ¼ d½n  2

Each x1[n] and x2[n] generates y1[n] and y2[n], respectively.

y1 ½n ¼ d½n þ d½n  1

y2 ½n ¼ d½n  2  d½n  3

The final output is the combination of individual outputs as below.

y½n ¼ y1 ½n þ y2 ½n ¼ d½n þ d½n  1  d½n  2  d½n  3


The derived equation is the convolution sum to compute filter output for the
given signal x½k. The impulse response tells us everything about the filter including
the filter frequency characteristics. The convolution sum follows the commutative
law between the impulse response and input signal; hence, the input to the impulse
response provides the identical output for the impulse to the input system as
Fig. 2.27.

X
1 X
1
y½n ¼ x½kh½n  k  ¼ h½k x½n  k
k¼1 k¼1 ð2:38Þ
¼ x½n h½n ¼ h½n x½n

The system output by convolution sum is equal to the intuitive filter equation
from Chap. 1. As described in the previous chapter, the convolution sum computes

Fig. 2.27 Commutative law


for convolution
54 2 Frequency and Signals in Discrete Domain

the present output from the recent weighted input samples likewise the input
averaging for low pass filter. Also, the filter delivers the output similar to the
impulse response profile with high likelihood. Now, we understand the convolution
sum equation and basic properties of the filter. Once the filter system guarantees the
linear and time invariant property, the user fully describes the system by reading the
impulse response. Furthermore, we can design the designated filter by carefully
deriving the impulse response for reducing or amplifying the range of the
frequencies.
Sometimes, we need to compute the power and energy of the signal to analyze
the system. The energy is the sum of all squared discrete input signal as Eq. (2.39).

X
1
Ex ¼ jx½nj2 ð2:39Þ
n¼1

The power is the average of squared discrete input signal in range as Eq. (2.40).

1 XN
Px ¼ lim jx½nj2 ð2:40Þ
N!1 2N þ 1
n¼N

If the signal is periodic and limited magnitude with infinite sequence length, then
the energy is infinite, and power is finite since the power is the average of signal
period. If the signal is aperiodic and limited magnitude with finite sequence length
(or infinite converge sequence), then the energy and power are finite values. Unless
one of the signal values is not infinite over entire infinite sequence, the power exists
with finite value. Figure 2.28 shows the conditions to exist the energy and power.
Example 2.9
Decide the energy and power existence of below signals.


2p
x1 ½n ¼ cos n
4


2p
x2 ½n ¼ tan n
8

x3 ½n ¼ 0:5n

Fig. 2.28 Signal energy and power exist condition


2.3 Signal Representation 55

x4 ½n ¼ 2n u½n

x4 ½n ¼ 1

Solution

1
X

2p 2
E x1 ¼ cos 4 n ¼ 1
n¼1

XN
3

1 2p 2 1 X 2p 2 1
Px1 ¼ lim cos 4 n ¼ 4 cos 4 n ¼ 2
N!1 2N þ 1
n¼N n¼0

For x1[n], the energy is not existed, and the power is existed.
1
X
2

Ex2 ¼ tan 2p n ¼ 1
8
n¼1

XN
2
X7
2

1 tan 2p n ¼ 1 tan 2p n ¼ 1
Px2 ¼ lim
N!1 2N þ 1 8 8 n¼0 8
n¼N

For x2[n], the energy is not existed, and the power is not existed.

X
1
Ex3 ¼ j0:5n j2 ¼ 1
n¼1

1 XN
1 X N
1 X1
Px3 ¼ lim j0:5n j2 ¼ lim 0:25n þ lim 0:25n
N!1 2N þ 1 N!1 N þ 1 N!1 N
n¼N n¼0 n¼N

1 X N
1X N
¼ lim 0:25n þ lim 4n
N!1 N þ 1 N!1 N
n¼0 n¼1

1 1  0:25N þ 1 1 4ð 1  4N Þ
¼ lim þ lim ¼1
N!1 N þ 1 1  0:25 N!1 N 14

For x3[n], the energy is not existed, and the power is not existed.

X
1 X
0 X
1
1 3
Ex4 ¼ j2n u½nj2 ¼ j 2n j 2 ¼ 0:25n ¼ ¼
n¼1 n¼1 n¼0
1  0:25 4
56 2 Frequency and Signals in Discrete Domain

1 XN
1 3
Px4 ¼ lim j2n u½nj2 ¼ lim ¼0
N!1 2N þ 1 N!1 2N þ 1 4
n¼N

For x4[n], the energy is existed, and the power is existed.

X
1
Ex5 ¼ j1j2 ¼ 1
n¼1

1 XN
2N þ 1
Px5 ¼ lim j1j2 ¼ lim ¼1
N!1 2N þ 1 N!1 2N þ 1
n¼N

For x5[n], the energy is not existed, and the power is existed.

The energy of the signal delivers finite value when the signal shows the limited
sequence length (or infinite converge sequence) and bounded magnitude value. The
power derives the finite value at the limited magnitude only over entire infinite
sequence. The LTI system cannot handle the instantaneous infinite value; therefore,
the input and output signal power should be existed for realization. The energy is
usually used for system analysis that will be shown in Chap. 4. Next step is to
discuss the frequency for the continuous and discrete time domain.

2.4 Frequency in Discrete Time Signal

The frequency is the number of rotations in second. The cyclic motion is defined in
the complex number domain with polar or Cartesian coordinates as Eq. (2.41).

xðtÞ ¼A1 ejX1 t ¼ a1 ejðX1 t þ h1 Þ


ð2:41Þ
¼a1 cosðX1 t þ h1 Þ þ ja1 sinðX1 t þ h1 Þwhere A1 ¼ a1 ejh1

In every second, the xðtÞ rotates the X1 radian or X1 =2p cycles in count
clockwise direction for the positive X1 . Strictly speaking, the X1 radian frequency
signal is A1 ejX1 t with the A1 complex magnitude that specify the amplitude and
phase (delay) of the signal. If the X1 is negative number, then the cycle is rotated in
opposite direction as clockwise. As mentioned earlier, the distinct frequencies
cannot be combined together for the single term; therefore, the multiple frequency
signals are described by the linear combination of the exponentials as Eq. (2.42).

xðtÞ ¼  
þR 1A1 e þjXt
jX1 t
A2 ejX2 t þ A3 ejX3 t þ A4 ejX4 t þ   
1 AðXÞe dX; for continuous X
ð2:42Þ
¼ P 1
1 Ak e
jXk t
; for discrete Xk
2.4 Frequency in Discrete Time Signal 57

Fig. 2.29 Continuous and discrete frequency distribution

From the Eq. (2.42) and Fig. 2.29, the frequency X1 ; X2 ; X3 ; X4 ; . . . has the
magnitude A1 ; A2 ; A3 ; A4 ; . . . respectively. The signal in discrete time domain is
expressed by the linear combination of the delta function as Eq. (2.43). The delta
function specifies the location of the sequence. In similar manner, the exponential in
the frequency equation defines the position of the frequency X; therefore, the ejXt is
the fundamental component in frequency domain. The sum or integral of all
weighted frequency components is our arbitrary signal.

x½n ¼    þ x½0d½n þ x½1d½n  1 þ x½2d½n  2 þ x½3d½n  3


P
1
ð2:43Þ
þ x½4d½n  4 þ    ¼ x½kd½n  k
k¼1

The rotation from the exponential produces the complex numbers that cannot be
realized in the actual system. In general, the complex number is projected onto the
real or imaginary axis by using the cosine or sine operation, respectively. However,
the cosine and sine are not the linear operators that represent the frequency com-
ponents in simple manner. The Euler formula is employed to project the complex
number on the axis as Eqs. (2.44) and (2.45).

A1 ejX1 t þ A 1 ejX1 t a1 ejðX1 t þ h1 Þ þ a1 ejðX1 t þ h1 Þ


x1 ð t Þ ¼ ¼
2 2 ð2:44Þ
¼a1 cosðX1 t þ h1 Þ ; where A1 ¼ a1 ejh1 and A 1 ¼ a1 ejh1
58 2 Frequency and Signals in Discrete Domain

B ejX1 t B ejX1 t jðX1 t þ h1 Þ


b1 e jðX1 t þ h1 Þ
x2 ðtÞ ¼ 1 1
¼ b1 e
2j 2j ð2:45Þ
¼ b1 sinðX1 t þ h1 Þ; where B1 ¼ b1 ejh1 and B 1 ¼ b1 ejh1

A pair of the exponential is required to make the complex rotation into the real
number. The pair should have the complex magnitudes with conjugated form
(denoted with superscript *) which exhibits the complementary phase on the
exponential. Depending on the even (cosine) or odd (sine) time function, proper
conjugated complex magnitudes are necessary on the frequency component to
obtain the real numbers in time. In other words, the given time function must
contain the positive frequency X as well as negative frequency – X in pair with
conjugated complex magnitude. Therefore, the negative frequency is introduced in
order to neutralize the complex number as shown in Fig. 2.4.
Note that period of arbitrary function does not stand for the pure frequency. The
function contains the frequency component from the period inverse in significant
amount but also the numerous side frequencies exist in neighbor. For example, the
square wave with 0.01 s period includes the 100 Hz component as well as the
integer multiple of the 100 Hz components as shown Fig. 2.30. The cosine function
with 0.01 s period only provides the 100 Hz signal. Observe also the negative
frequencies.

Fig. 2.30 Cosine x1(t) and square x2(t) wave for 0.01 s period and its frequency distribution
2.4 Frequency in Discrete Time Signal 59

The frequency from the discrete time signal presents the completely different
notation due to the sequence n instead of the time t. Let’s see the example below.

xðtÞ ¼ ejð2p10Þt and x½n ¼ ejð2p10Þn t 2 R; n 2 Z ð2:46Þ

The xðtÞ shows the 10 rotations per second. Every moment of the time can be
illustrated since the t is the real number. However, the x½n rotates the 10 cycles in
every sequence because of the integer sequence. There is no way to obtain the
values in between the adjacent sequences. It does not matter how many rotations the
function does. In fact, the minimum angular displacement between the adjacent
sequences is significant. In this case, the 2p10 is equal to the 0p, 2p, 4p, 6p, and
etc.; hence, no angular movement is observed with given parameter as shown in
Fig. 2.31.
The sampling procedure reads the continuous time data in every Ts interval to
obtain the discrete time sequence. The replacement of t with nTs derives the discrete
frequency x that is the radian frequency based on the ratio between the given
frequency f and the sampling frequency fs as shown in Eq. (2.47).

Sampling;t¼nTs
xðtÞ ¼ ejXt !x½n ¼ ejXnTs
: f f : ð2:47Þ
¼ ej2pfnTs ¼ ej2pfs n ¼ ejxn where x ¼ 2p
fs

According to the Nyquist rate, the sampling frequency should be at least twice
greater than the given frequency. Hence, the discrete frequency x is ranged up to p
as shown in Eq. (2.48). Also, note that negative frequencies are included for real
value sequence as well.

Fig. 2.31 xðtÞ ¼ ej2pt and x½n ¼ ej2pn representation for real t and integer n. Assume that t is the
integer multiple of 1/8 in this example
60 2 Frequency and Signals in Discrete Domain

fs [ 2f then f
fs \ 12 ; therefore; x ¼ 2p ffs \p ð2:48Þ

Figure 2.32 presents the three sampling cases with x as p=4, p, and 3p=2. The x
with p=4 represents that the sampling frequency is eight times greater than the
given frequency f. Therefore, the one period signal is sampled eight times in cosine
function as well as the complex circle. The sampling is dense enough to recover the
given continuous signal by connecting the neighbor dots, so it is proper sampling.
We can say the x is valid. The x with p provides that the sampling frequency is
twice greater than the given frequency f. Therefore, the one period signal is sampled
twice in cosine function as well as the complex circle. The sampling is on the edge
to recover and the x is narrowly valid.
The last case for x ¼ 3p=2 shows the ratio as f =fs ¼ 3=4 and three periods of
the signal is sampled four times. In the complex circle, after the four sampling by
3p=2 angular distance, the sampling position is placed back to the initial location as
ð3p=2Þ4 ¼ 6p. Hence, the three period 6p is read by four sampling process. The
3p=2 frequency misses some important signal information such as peaks and val-
leys, so the connecting procedure does not recover the given continuous signal as
shown in Fig. 2.33. The feasible representative frequency by the given x is the p=2
denoted by the dotted line in Fig. 2.33. Likewise, the p=2 angular space is depicted
on the complex circle sampling in Fig. 2.32. The sampling procedure changes the
frequency of sampled signal; therefore, the x is not valid. Above the p radian
frequencies cannot stand for discrete frequency x in proper manner.
Prog. 2.9 MATLAB program for Fig. 2.33.

T = 0.01;
T1 = 0.03;
fs = 10000;
fss = 1/(3*T/4);
t1 = 0:1/fs:T*4.5;
t2 = 0:1/fss:T*4.5;
x1 = cos(2*pi*t1/T);
x2 = cos(2*pi*t2/T);
x3 = cos(2*pi*t1/T1);

figure,
plot(t1,x1,'k',t1,x3,'k--'), grid
hold on
stem(t2,x2,'LineStyle','none','MarkerFaceColor','k')
hold off
2.4 Frequency in Discrete Time Signal 61

Fig. 2.32 Sampling the sinusoid with different sampling frequencies to present the radian
frequencies x as p=4; p; and 3p=2
62 2 Frequency and Signals in Discrete Domain

Fig. 2.33 Improper sampling


example with 3p/2 radian
frequency (equivalently p=2)

The effective x derived from the invalid radian frequency can be computed by
adding the integer multiple of 2p in order to obtain the less than or equal to p radian
frequency as Eq. (2.49).
8
>
> effective x
< x ¼ 2kp ! 0
For k 2 Z ð2:49Þ
>
> effective x
: x 6¼ 2kp ! 0\ minjx þ 2kpj  p

For example, the 3p=2 is added by the 2p to deliver the p=2 effective radian
frequency by absolute value. The 5p=3 is added by 2p to present absolute p=3.
The 4p=3 provides the 2p=3 effective frequency. Note that the 2p radian frequency
changes to the zero radian that illustrates the non-moving constant signal.
Figure 2.34 shows the two discrete frequencies as 5p=3 and 4p=3. The
appearance sequence is out of order in terms of circular motion but the recovery by
connecting the adjacent values generates the count clockwise cycle increased by
p=3 and 2p=3, respectively. The effective frequency is the only representative
frequency used by the discrete processing since the other frequencies are
ambiguous to illustrate from sampling procedure. Figure 2.35 shows the projected
real values of the circular motion from the two discrete frequencies as 5p=3 and
11p=3. The angular differences between the marked points are distinct for each
frequency described by the caption at Fig. 2.35; however, the location is identical to
the sampling point circles in Fig. 2.35. The direct connection between the points
represent the effective frequency p=3 derived from Eq. (2.49). Therefore, the sys-
tem designer should choose the proper sampling frequency based on the Nyquist
rate to avoid the unwanted spectral shift by effective frequency.
2.4 Frequency in Discrete Time Signal 63

Fig. 2.34 Two discrete frequencies 5p=3 and 4p=3 (effective radian frequencies p=3 and 2p=3,
respectively)

Fig. 2.35 Projected real


value of circular motion from
the three discrete frequencies
as p=3; 5p=3; and 11p=3:The
sampling points are illustrated
by circles
64 2 Frequency and Signals in Discrete Domain

Prog. 2.10 MATLAB program for Fig. 2.35.


w1 = pi/3;
w2 = 5*pi/3;
w3 = 11*pi/3;

n1 = 0:pi/100:3;

x1 = cos(w1*n1);
x2 = cos(w2*n1);
x3 = cos(w3*n1);

figure,
plot(n1,x1,n1,x2,n1,x3)
hold on
scatter ([0 1 2 3], cos(w1*[0 1 2 3]));
hold off

Figure 2.36 shows the identical situation as Fig. 2.35 for two discrete frequen-
cies as 4p=3 and 10p=3. The direct connection between the points represent the
effective frequency 2p=3.

Fig. 2.36 Projected real


value of circular motion from
the three discrete frequencies
as 2p=3, 4p=3, and 10p=3.
The sampling points are
illustrated by circles
2.4 Frequency in Discrete Time Signal 65

Prog. 2.11 MATLAB program for Fig. 2.36.


w1 = 2*pi/3;
w2 = 4*pi/3;
w3 = 10*pi/3;

n1 = 0:pi/100:3;

x1 = cos(w1*n1);
x2 = cos(w2*n1);
x3 = cos(w3*n1);

figure,
plot(n1,x1,n1,x2,n1,x3)
hold on
scatter ([0 1 2 3], cos(w1*[0 1 2 3]));
hold off

The relationship between the continuous frequency X and discrete frequency x


is given by Eq. (2.50). Simply the effective x is multiplied with fs to compute the
processing frequency X from the sampling procedure.

2p ffs ¼ Xfs ¼ x ! xeff ¼ 2p feff


fs ¼ fs
Xeff
ð2:50Þ

The effective frequency from the sampling procedure is produced by the aliasing
due to the improper sampling. Developed from Eq. (2.50), the linearly increasing
processing frequency f and fixed sampling frequency fs provides the non-linear
effective frequency feff because of the sampling procedure. If the f is less than or
equal to the fs half then the effective frequency feff is equal to the f, otherwise not
equal. The conversion plot is shown in Fig. 2.37.
Above the fs =2, the effective frequency starts to decrease linearly until zero at fs.
The triangle shape is repeated continuously and infinitely. Note that the effective
frequency is always between the zero and fs half or between the zero and p in
discrete frequency x.
Example 2.10
Based on the sampling frequency fs = 2000 Hz, compute the effective frequencies
feff from following discrete frequencies x.

p p 3p 5p
x ¼ ; ; ; p;
4 2 4 4
66 2 Frequency and Signals in Discrete Domain

Fig. 2.37 Relationship between the processing frequency f and effective frequency feff by
sampling procedure (fs)

Solution
The corresponding effective discrete frequencies xeff are below.

p p 3p 3p
xeff ¼ ; ; ; p;
4 2 4 4

Therefore, the responding effective frequencies feff are below.

feff ¼ 250; 500; 750; 1000; 750 Hz


The discrete frequency also requires the complementary negative frequency to
convert into the real number. According to the Euler formula, Eqs. (2.51) and
(2.52) are the counterpart of the continuous signal Euler formula for corresponding
sinusoid signal. Therefore, the negative frequency similarly contains the conjugated
complex magnitude as well.

A1 ejx1 n þ A 1 ejx1 n a1 ejðx1 n þ h1 Þ þ a1 ejðx1 n þ h1 Þ


x1 ½n ¼ ¼
2 2 ð2:51Þ
¼ a1 cosðx1 n þ h1 Þ; where A1 ¼ a1 ejh1 and A 1 ¼ a1 ejh1

B1 ejx1 n  B 1 ejx1 n b1 ejðx1 n þ h1 Þ  b1 ejðx1 n þ h1 Þ


x2 ½n ¼ ¼
2j 2j ð2:52Þ
¼ b1 sinðx1 n þ h1 Þ; where B1 ¼ b1 ejh1 and B 1 ¼ b1 ejh1
2.4 Frequency in Discrete Time Signal 67

Fig. 2.38 Spectral periodicity in discrete frequency x

Another characteristic on the frequency distribution for the discrete time signal is
periodicity in spectrum. Since the sequence is represented by the integer number,
the frequency is repeated every 2p interval as below.

cosðxnÞ ¼ cosððx þ 2kpÞnÞ ¼ cosðxn þ 2kpnÞ for n 2 Z ð2:53Þ

cosðXtÞ 6¼ cosððX þ 2kpÞtÞ ¼ cosðXt þ 2kptÞ for t 2 R ð2:54Þ

In Eq. (2.53), the x frequency is equal to the x þ 2kp for any integer number
k. The 2kpn does not cause the radian variation for the given sinusoid. In
Eq. (2.54), the 2kpt could be any radian value due to the real value t; therefore, no
spectrum periodicity is reserved for the continuous time signal. Figure 2.38 shows
one example of the frequency distribution for the discrete time signal.
The spectrum is repeated for every 2p interval for positive and negative fre-
quency range as well. If the discrete frequency crosses the p borders, then
spectrum between the neighbors starts to be overlapped and contaminated. The
valid discrete frequency distribution from Fig. 2.38 is also meet the Nyquist
sampling rate condition. In summary, the discrete frequency is complementary with
negative frequency, ranged from p to p, and repeated for every 2p interval.

2.5 Problems

1. The pure X frequency signal is represented by complex number as below.

xðtÞ ¼ rejXt

The size of the complex number circle r presents the magnitude of the fre-
quency. Derive the magnitude of individual frequencies of following signals
– r cosðXt þ hÞ
– r sinðXt þ hÞ
68 2 Frequency and Signals in Discrete Domain

2. Find the trigonometric identities of below equations.


 
– sin Xt þ p2
 
– cos Xt þ p2
– sinðXt  pÞ
– cos Xt  p2
3. Decompose below equation into the non-phased cosine and sine function.
– A sinðXt þ hÞ
4. Find the even and odd part of below signal.
– A sinðXt þ hÞ
5. Using the phasor, prove the equivalence of below equation.
– A cosðhÞ cosðXtÞ  A sinðhÞ sinðXtÞ ¼ A cosðXt þ hÞ
6. Equation (2.12) is derived from the following equation.

Z1 Z1
aðXÞ þ jbðXÞ jX t aðXÞ  jbðXÞ jX t
xðtÞ ¼ e dX þ e dX
2 2
0 0

To obtain the real x(t), determine the condition of aðXÞ and bðXÞ. Why?
7. Derive the following equations.
R1
– ejX t dt
1
R1
ejð100pt þ 4Þ ejX t dt
p
– 1
2p
1

8. Compute and draw X ðXÞ of below signal.



1 for 0t1
xðtÞ ¼
0 Otherwise

9. Find the minimum sampling rate for following signal.

xðtÞ ¼ cosð100ptÞ sinð200ptÞ

10. Find the value of following equations.


8
>
> d½ 0 ¼
>
> P
1
< d½n ¼
n¼1
>
> P
1
>
> nd½n  3 ¼
:
n¼1
2.5 Problems 69

8
> dð 0Þ ¼
>
> R1
>
< dðtÞdt ¼
1
>
> R1
>
>
: tdðt  3Þdt ¼
1

11. Using the unit-step function, modify the equation to extract the one period of
following signal.
 
– x1 ½n ¼ cos 2pðn3
6
Þ
   
2pðn3Þ
– x2 ½n ¼ cos 6 þ 2 cos 2p
4 n

12. Draw the x½2ðn  1Þ of given x[n].

x½n ¼ r ½n þ 2ðu½n þ 3  u½n  4Þ

13. From the given impulse response h[n] as below, determine the LTI system
output of shown input x[n].

h½n ¼ d½n  d½n  1

x½n ¼ u½n

14. Decide the energy and power existence of below signal.

x1 ½n ¼ 0:5jnj

1
x2 ½n ¼ ðu½n  1 þ u½n þ 1Þ
n

15. Based on the sampling frequency fs = 4000 Hz, compute the effective discrete
frequencies xeff from following frequencies f.

f ¼ 500; 1000; 1500; 2000; 2500; 3000; 3500; 4000 Hz

References

1. Taylor, A.E.: L’Hospital’s Rule. Am. Math. Mon. 59(1), 20–24 (1952). https://doi.org/10.1080/
00029890.1952.11988058
2. Bracewell, R.N.: The Fourier Transform and Its Applications, 3rd ed. McGraw Hill (1999)
3. Fourier, J.B.J.: The Analytical Theory of Heat. Cambridge Library Collection—Mathematics.
Cambridge University Press, Cambridge (2009)
70 2 Frequency and Signals in Discrete Domain

4. Olver, F.W.J., Standards, N.I.o., Technology, Lozier, D.W., Boisvert, R.F., Clark, C.W.: NIST
Handbook of Mathematical Functions Hardback and CD-ROM. Cambridge University Press
(2010)
5. Nyquist, H.: Certain topics in telegraph transmission theory. Trans. Am. Inst. Electri. Eng. 47
(2), 617–644 (1928). https://doi.org/10.1109/T-AIEE.1928.5055024
6. Chapter 2—Cartesian Tensors. In: Kundu, P.K., Cohen, I.M., Dowling, D.R. (eds.) Fluid
Mechanics. 5th edn, pp. 39–64. Academic Press, Boston (2012)
Chapter 3
Fourier Analysis

The convolution sum and discrete sequence implement the basic digital filter in
time domain. In previous chapter, the discrete frequency x is defined with con-
tinuous frequency X. Now, we understand the discrete time signal as well as the
discrete sinusoid signal with frequency x. The specific frequency signal can be
generated by the linear combination of sinusoids. What if we need to figure out the
frequency distribution from a given arbitrary signal? How we can derive the fre-
quency distribution from the discrete time domain? Often frequency analysis is
required since the filter is designed based on the frequency information. The Fourier
analysis is the powerful tool to transform the information between the frequency
and time. The analysis and synthesis equation find the frequency and time infor-
mation correspondingly. The Fourier analysis is further generalized by the
Z-transform to analyze and design the filter in Chap. 5.

3.1 How We Can Find the Magnitude of the Specific


Frequency?

You may easily find the magnitude of the single frequency signal. The problem is
complicated when you come up against the linearly added multiple sinusoid signal
since you have to separate as well as estimate the frequency and magnitude
simultaneously. Intuitive solution for the single sinusoid cannot be expanded for the
multiple sinusoid. The answer is the exploring the periodicity and orthogonality of
the sinusoid signal. Let’s consider following instance.

P
N1 P
N1
ð3:1Þ
2p
ej N n ¼ ejxn ¼ 0 for 8 N 2 N except N ¼ 1
n¼0 n¼0

© Springer Nature Singapore Pte Ltd. 2021 71


K. Kim, Conceptual Digital Signal Processing with MATLAB,
Signals and Communication Technology,
https://doi.org/10.1007/978-981-15-2584-1_3
72 3 Fourier Analysis

Equation (3.1) is derived from the signal periodicity with N period. You can
obtain the identical outcome by using the equivalent counterpart as
cosð2pn=N Þ þ jsinð2pn=N Þ. To find some insight of the equation, use the illus-
tration in Fig. 3.1 for N = 6.
The complex exponential in Fig. 3.1 demonstrates unit size vectors in every p=3
angular distance. The sum of the vectors indicates the origin of the coordinates;
hence, the output is equal to the zero for Eq. (3.1).
The period N is the natural number for discrete time signal; therefore, Eq. (3.1)
definition for the discrete frequency x provides a limited resolution such as
2p=2; 2p=3; 2p=4, etc. The general definition of discrete frequency x is given in
Eq. (3.2) for dense description of frequency. The multiple k rotations are performed
to find the same pattern with N sequence difference.

2pk
N ¼ x ¼ 2p ffs for k; N 2 N; ffs 2 Q; f ; fs 2 R ð3:2Þ

From the given f and fs, the period N can be calculated by finding the minimum
natural number k which produces the natural number from kfs/f. The equation is
given in Eq. (3.3).
n  o

N ¼ min k ffs 2 Nk 2 N and ffs 2 Q ð3:3Þ

The periodicity is verified by Eq. (3.4).

ejxn ¼ ej N n ¼ ej N ðn þ N Þ ¼ ej N n þ ð3:4Þ
2pk 2pk 2pk 2pk 2pk 2pk 2pk
N N ¼ ej N n ej N N ¼ ej N n

As Eq. (3.1), the k cycle summation of the unit magnitude vectors with 2pk=N
angular distance delivers the zero-output due to the symmetric vector sums over the
coordinate origin.

Fig. 3.1 The ej2pn=6 in


complex number domain Imag.

π/3
real
3.1 How We Can Find the Magnitude of the Specific Frequency? 73

Example 3.1
Find the period N of following discrete frequencies.

5p 4p
x¼ and
3 3

Solution
The calculation N from the given x is below.
5p
3 ¼ 25p
23 ¼ 6 ¼ N ! N ¼ 6
10p 2p k

3 ¼ N ! N ¼ 3
4p 2p k

The 5p=3 and 4p=3 require the five and two rotations, correspondingly, to locate
another pattern match according to the k value in above equation. ■
Figure 2.34 presents the cyclic motion of 5p=3 and 4p=3 frequency with six and
three sample period N, respectively. The inverse of the period N does not represent
the discrete frequency x. We must know the N and k as shown in Eq. (3.2) to
calculate the frequency. The general discrete sinusoid function is demonstrated in
Eq. (3.5) with discrete frequency x1 .

ejðx1 n þ h1 Þ þ ejðx1 n þ h1 Þ
x½n ¼ a1 cosðx1 n þ h1 Þ ¼ a1
2 ð3:5Þ
a1 ejh1 a1 ejh1 jx1 n
¼ 2 e jx1 n
þ 2 e

The magnitude for the given signal is a1 ejh1 =2 and its complement. In order to
find the magnitude, apply the Eq. (3.6).

P
1 P
1
X ðejx Þ ¼ x½nejxn ¼ a1 cosðx1 n þ h1 Þejxn
n¼1 n¼1
ð3:6Þ
a1 ejh1 P
1
jx1 n jxn a1 ejh1 P
1
jx1 n jxn
¼ 2 e e þ 2 e e
n¼1 n¼1

To solve Eq. (3.6), we need to understand the sum with complex exponential.
Consider below Eq. (3.7).
74 3 Fourier Analysis

8 9
>
> P jðx1 xÞn
N1
>
>
> lim k e ¼0 6 x>
for x1 ¼ >
>
>
< k ! 1 n¼0 >
=
P1 P1
ejx1 n ejxn ¼ ejðx1 xÞn ¼ k2N
>
> >
>
n¼1 n¼1
>
> P
N1 >
>
>
: ejðx1 xÞn ¼ N for x1 ¼ x >
;
( n n¼0  o
min ðx2pk x Þ 2 N j k 2 N for x1 6¼ x
¼ 2pdðx1  xÞ where N ¼ 1

ðx1 xÞ ¼ 0 ¼ 1 for x1 ¼x


2p 2p

ð3:7Þ

The real part of the ejðx1 xÞn is shown in Fig. 3.2 for 0, 2p=5 (1.2566 radian/
sample), and 6p=10 (1.8850 radian/sample). For x1 6¼ x case, the infinite length
summation for real part is represented by the product between the period sum and
nearly 1. The individual period sum is zero; hence, the overall sum is zero always.
For x1 ¼ x case, the ejðx1 xÞn is constant one for infinite length N which is 2p=0.
P1
Therefore, the ejðx1 xÞn is 2p=0 as 1 for x1 ¼ x situation.
n¼1

Fig. 3.2 The real part (cosine) of ejðx1 xÞn for ðx1  xÞ ¼ 0; 2p=5; and 6p=10
3.1 How We Can Find the Magnitude of the Specific Frequency? 75

Prog. 3.1 MATLAB program for Fig. 3.2


N = 25;
N1 = 5;
k1 = 1;
N2 = 10;
k2 = 3;

nn = 0:1:N;
nn0 = 0:1/100:N;
x1 = cos(2*pi*nn*k1/N1);
x2 = cos(2*pi*nn*k2/N2);
x3 = cos(2*pi*nn);
x01 = cos(2*pi*nn0*k1/N1);
x02 = cos(2*pi*nn0*k2/N2);
x03 = ones(1,length(nn0));

figure,
subplot(311), plot(nn0,x03,'k--'), grid
hold on
stem(nn,x3,'LineWidth',2,'Color',[0.4 0.6 0.7])
hold off
subplot(312), plot(nn0,x01,'k--'), grid
hold on
stem(nn,x1)
stem([10:1:14],cos(2*pi*k1*(10:1:14)/N1),'LineWidth',2,'Color',[0.4 0.6 0.7])
hold off
subplot(313), plot(nn0,x02,'k--'), grid
hold on
stem(nn,x2), grid
stem([10:1:19],cos(2*pi*k2*(10:1:19)/N2),'LineWidth',2,'Color',[0.4 0.6 0.7])
hold off
76 3 Fourier Analysis

Fig. 3.3 The imaginary part (sine) of ejðx1 xÞn for ðx1  xÞ ¼ 0; 2p=5; and 6p=10

The imaginary part of the ejðx1 xÞn is shown in Fig. 3.3 for 0, 2p=5
(1.2566 radian/sample), and 6p=10 (1.8850 radian/sample). The analysis is iden-
tical to the real part counterparts except x1 ¼ x case which delivers the constant
zero output.
3.1 How We Can Find the Magnitude of the Specific Frequency? 77

Prog. 3.2 MATLAB program for Fig. 3.3


N = 25;
N1 = 5;
k1 = 1;
N2 = 10;
k2 = 3;

nn = 0:1:N;
nn0 = 0:1/100:N;

y1 = sin(2*pi*nn*k1/N1);
y2 = sin(2*pi*nn*k2/N2);
y3 = sin(2*pi*nn);
y01 = sin(2*pi*nn0*k1/N1);
y02 = sin(2*pi*nn0*k2/N2);
y03 = zeros(1,length(nn0));

figure,
subplot(311), plot(nn0,y03,'k--'), grid
hold on
stem(nn,y3,'LineWidth',2,'Color',[0.4 0.6 0.7])
hold off
ylim([-1.2 1.2])
subplot(312), plot(nn0,y01,'k--'), grid
hold on
stem(nn,y1)
stem([10:1:14],sin(2*pi*k1*(10:1:14)/N1),'LineWidth',2,'Color',[0.4 0.6 0.7])
hold off
subplot(313), plot(nn0,y02,'k--'), grid
hold on
stem(nn,y2), grid
stem([10:1:19],sin(2*pi*k2*(10:1:19)/N2),'LineWidth',2,'Color',[0.4 0.6 0.7])
hold off

P
The consolidated outputs of the 1 n¼1 e
jðx1 xÞn
are demonstrated in Fig. 3.4.
jðx1 xÞn
The real and imaginary part of the e are illustrated on the complex domain
with vectors in Fig. 3.4.
78 3 Fourier Analysis

P
1
Fig. 3.4 The ejðx1 xÞn for x1 6¼ x and x1 ¼ x
n¼1

If the x1 is not equal to x then the complex exponential is periodic signal with
ðx1  xÞ radian frequency. The sum can be translated to the addition of the infinite
repetition of new periods. Since the addition of one period is zero, the whole
summation presents zero output. For the x1 ¼ x condition, the ejðx1 xÞn is ej0n that
is constant one; therefore, the summation indicates the N with infinite value.
Observe that the period of the zero-radian frequency is infinite. The summation with
complex exponential follows the property of delta function that presents the infinite
outcome on the short point. The area indicated by the given delta function is 2p as
shown in Fig. 3.4; hence, the delta function is scaled by the 2p. Therefore, the
complete solution is Eq. (3.8).

  a1 ejh1 X
1
a1 ejh1 X
1
X ejx ¼ ejx1 n ejxn þ ejx1 n ejxn
2 n¼1 2 n¼1 ð3:8Þ
a1 ejh1 a1 ejh1
¼ 2 2pdðx1  xÞ þ 2 2pdðx1 þ xÞ

The X ðejx Þ argument is ejx to imply the 2p periodicity in the spectrum due to the
sampling process. The frequency distribution for the a1 cosðx1 n þ h1 Þ is shown in
Fig. 3.5.
The other property used above computation is the orthogonality between the
P
adjacent frequencies. Except the x1 frequency, the 1 n¼1 x½ne
jxn
provides the
zero output for the given a1 cosðx1 n þ h1 Þ signal and the x1 ¼ x generates the
magnitude related output.
3.1 How We Can Find the Magnitude of the Specific Frequency? 79

Fig. 3.5 The frequency distribution of a1 cosðx1 n þ h1 Þ from the transformation

Rp
x½n ¼ 2p
1
X ðejx Þejxn dx
p
Zp
1
¼ fa1 p ejh1 dðx1  xÞ þ a1 p ejh1 dðx1 þ xÞgejxn dx
2p
p
Zp Zp
1 1
¼ a1 p e dðx1  xÞe
jh1 jxn
dx þ a1 p ejh1 dðx1 þ xÞejxn dx
2p 2p
p p
Zp Zp
a1 p ejh1 jx1 n a1 p ejh1 jx1 n
e dðx1  xÞdx þ e dðx1 þ xÞdx
2p 2p
p p
a1 p ejh1 jx1 n a1 p ejh1 jx1 n
¼ e þ e
2p 2p
a1 jðx1 n þ h1 Þ a1 jðx1 n þ h1 Þ
e þ e ¼ a1 cosðx1 n þ h1 Þ ð3:9Þ
2 2

In order to synthesis the discrete time domain signal, consider the above equa-
tions. The synthesis equation is the linear combination of complex exponential with
x radian frequency for the corresponding complex magnitude X ðejx Þ. Since the
digital frequency is ranged from p to p and the frequency is continuous domain,
the integral is applied for the given range. Scale down by 2p is required because the
analysis equation computes the magnitude with 2p multiplication. The big
assumption is that all signal can be decomposed into the infinite or finite combi-
nation of the sinusoid signal. We can find each frequency magnitudes by analysis
equation and derive the discrete time signal via synthesis equation.
80 3 Fourier Analysis

Example 3.2
Compute the frequency distribution of following signals.

x1 ½n ¼ an u½n for jaj\1

x2 ½n ¼ u½n þ N   u½n  ðN þ 1Þ

x3 ½n ¼ d½n

x 4 ½ n ¼ 3

x5 ½n ¼ cosðx1 nÞ

Solution

  X
1 X
1 X
1
X1 ejx ¼ x1 ½nejxn ¼ an u½nejxn ¼ an ejxn
n¼1 n¼1 n¼0
X1   1  
¼ ae jx n
¼ *aejx \1
n¼0
1  aejx
  X
1 X
N
X2 ejx ¼ ðu½n þ N   u½n  ðN þ 1ÞÞejxn ¼ ejxn
n¼1 n¼N

  xð2N þ 1Þ xð2N þ 1Þ xð2N þ 1Þ


!
1  ejxð2N þ 1Þ jxN e
j 2
ej 2  ej 2
¼e jxN
¼e x x x
1  ejx ej 2 ej 2  ej 2

!  
xð2N þ 1Þ xð2N þ 1Þ xð2N þ 1Þ
e j 2 e j 2 sin 2
¼ x x ¼ x 
ej 2  ej 2 sin 2

  X
1
X3 ejx ¼ d½nejxn ¼ 1
n¼1

  X
1
X4 ejx ¼ 3ejxn ¼ 6pdðxÞ
n¼1

X 1  
  1
1 X
X5 ejx ¼ cosðx1 nÞejxn ¼ ejðxx1 Þn þ ejðx þ x1 Þn
n¼1
2 n¼1

¼ pdðx  x1 Þ þ pdðx þ x1 Þ

Note that above frequency information X ðejx Þs represent the distribution over the
range between p to p. The distribution is repeated in every 2p. ■
3.2 Signal Property and Frequency Distribution 81

3.2 Signal Property and Frequency Distribution

The analysis equation finds the continuous frequency distribution X ðejx Þ of the
given discrete time signal x½n. The transfer function converts the discrete domain
x½n into the continuous domain X ðejx Þ. Certain cases such as pure sinusoid
a1 cosðx1 n þ h1 Þ could present the single frequency distribution. However, the
X ðejx Þ is the continuous function in general unless the signal is the linear combi-
nation of limited discrete frequencies with infinite length to the positive and neg-
ative sample sequence. What condition dose the X ðejx Þ make discrete distribution?
Let’s find some general situations which provide the discrete spectral distribution.
Usually the discrete frequency x denotes the radian frequency (radian/sample)
based on the p; therefore, it is difficult to make the x as integer number. Instead, the
x discretization can be performed by the specifying the spectral distance between
the adjacent discrete frequencies as fundamental frequency x0 . We assume that the
new digital frequency is only existed on the integer multiple of fundamental fre-
quency x0 . The ejx0 kn is the primitive component of the frequency distribution
denoting the spectral location at kx0 with k integer in Eq. (3.10). Also, the
dðx  kx0 Þ is the equivalent representation for spectral location as shown
Eq. (3.11) and Fig. 3.6.

x½n ¼ . . . þ a3 ej3x0 n þ a2 ej2x0 n þ a1 ejx0 n þ a0 ej0x0 n þ a1 ejx0 n


ð3:10Þ
þ a2 ej2x0 n þ a3 ej3x0 n þ . . .

Fig. 3.6 The frequency distribution of given X ðejx Þ


82 3 Fourier Analysis

Fig. 3.7 One example of discrete time signal from discrete spectral distribution (x0 is 2p=64)

X ðejx Þ ¼ . . . þ 2pa3 dðx þ 3x0 Þ þ 2pa2 dðx þ 2x0 Þ þ 2pa1 dðx þ x0 Þ


þ 2pa0 dðxÞ þ 2pa1 dðx  x0 Þ þ 2pa2 dðx  2x0 Þ ð3:11Þ
þ 2pa3 dðx  3x0 Þ þ . . .

Note that the conversion between the above x½n and X ðejx Þ is performed by the
analysis Eq. (3.6) and synthesis Eq. (3.9) equation given previously. The spectral
resolution Dx is equal to the fundamental frequency x0 since the discrete frequency
is appeared in every x0 interval in frequency domain. With this condition, what the
signal looks like? Let’s see the illustrated signal in Fig. 3.7.
Prog. 3.3 MATLAB program for Fig. 3.7

N = 128;
nn = 0:1:N;
x1 = 2*cos(2*pi*nn/32);
x2 = cos(2*pi*nn/64);
x3 = 0.5*cos(2*pi*nn/16);

figure,
subplot(211), stem(nn,[x1' x2' x3']), grid
xlim([0 128])
subplot(212), stem(nn,x1+x2+x3), grid
xlim([0 128])
3.2 Signal Property and Frequency Distribution 83

The first figure on Fig. 3.7 shows the three sinusoids with different periods. The
blue, red, and yellow plot present the 64, 32, and 16 period respectively. The sum of
the sinusoids demonstrated in the second figure indicates periodic signal with 64
sample period since the integer multiple of the 32 and 16 period is 64 period. In the
frequency viewpoint, the 64, 32, and 16 sample period is the 2p=64, 2p=32, and
2p=16 discrete frequency correspondingly. Observe that the 2p=32 and 2p=16 are
twice and quadruple of the 2p=64. Therefore, the fundamental frequency x0 is
2p=64 with 1, 2, and 4 for k values. We can derive the conclusion that the integer
multiple combinations of the fundamental frequency provide the periodic signal
with period as 2p=x0 . Also, we can state that the periodic signal with N period can
be decomposed into the fundamental frequency 2p=N and its integer multiples. If
there is any contamination by non-integer multiple of fundamental frequency, the
signal establishes new fundamental frequency based on the given frequency dis-
tribution to fulfil the integer multiple condition. The signal periodicity decides the
frequency discretization property. The non-periodic signal can be considered as the
infinite period; hence, the fundamental frequency approaches to zero for continuous
frequency distribution.
Example 3.3
Find the new period N and possible frequency components of signal x[n].

x1 ½nwith 12 sample period

x2 ½nwith 18 sample period

x ½ n ¼ x 1 ½ n þ x 2 ½ n

Solution
Least common multiple of periods presents the new period N.

LCMð12; 18Þ ¼ 36 samples

The possible frequencies are

2p
x¼ k for 0  k  18 and k 2 Z
36

3.3 Discrete-Time Fourier Transform (DTFT)

In the previous sections, the fundamentals of the Discrete-time Fourier transform


(DTFT) [1] is explained already. Equations (3.12) and (3.13) are DTFT equations
for analysis and synthesis, respectively.
84 3 Fourier Analysis

P
1
X ðejx Þ ¼ x½nejxn ð3:12Þ
n¼1

Rp
x½n ¼ 2p
1
X ðejx Þejxn dx ð3:13Þ
p

Let’s do one example to use the above equations.


Example 3.4
The below is the given discrete time signal. Find the frequency distribution.

1 for  3  n  3
x ½ n ¼
0 Otherwise

Solution
The frequency distribution of the given signal is below.

  X
1 X
3
X ejx ¼ x½nejxn ¼ ejxn
n¼1 n¼3




¼ 1 þ ejx þ ejx þ ej2x þ ej2x þ ej3x þ ej3x
¼ 1 þ 2 cosðxÞ þ 2 cosð2xÞ þ 2cosð3xÞ

The X ðejx Þ distribution is displayed in Fig. 3.9. Note that the given discrete time
signal x[n] is not periodic; hence, the X ðejx Þ is continuous according to the previous
section result.
Prog. 3.4 MATLAB program for Figs. 3.8 and 3.9

nn = -4:1:4;
w = -pi:pi/100:pi;
xn = [0 1 1 1 1 1 1 1 0];
Xw = 1+2*cos(w)+2*cos(2*w)+2*cos(3*w);

figure,
stem(nn,xn), grid
xlabel('n')
ylabel('x[n]')

figure,
plot(w,Xw), grid
xlabel('\omega')
ylabel('X(e^{j\omega})')


3.3 Discrete-Time Fourier Transform (DTFT) 85

Fig. 3.8 Given discrete time signal x[n] example

Fig. 3.9 The frequency distribution of given x[n] in Fig. 3.8


86 3 Fourier Analysis

The computed X ðejx Þ is illustrated at Fig. 3.9. Generally, the X ðejx Þ is complex
number with magnitude as well as the phase component. The negative value on
Fig. 3.9 should be translated as the positive magnitude with p phase because the −1
is equal to the 1ejp . According to the frequency property of the general discrete time
signal, the above distribution is repeated in every 2p interval as shown below.
 
X ejðx þ 2kpÞ ¼ 1 þ 2 cosðx þ 2kpÞ
þ 2 cosð2ðx þ 2kpÞÞ þ 2cosð3ðx þ 2kpÞÞ
 
¼ 1 þ 2 cosðxÞ þ 2 cosð2xÞ þ 2 cosð3xÞ ¼ X ejx k 2 Z

Using the synthesis equation, we can obtain the discrete time sequence from the
X ðejx Þ as below.
Example 3.5
The below is the given frequency distribution. Find the corresponding discrete-time
domain signal x[n].
 
X ejx ¼ 1 þ 2 cosðxÞ þ 2 cosð2xÞ þ 2cosð3xÞ

Solution

1 Zp  jx  jxn
x½n ¼ X e e dx
2p p
1 Zp
¼ f1 þ 2 cosðxÞ þ 2 cosð2xÞ þ 2 cosð3xÞgejxn dx
2p p
1 Zp
j3x
¼ e þ ej2x þ ejx þ 1 þ ejx þ ej2x þ ej3x ejxn dx
2p p
1 Zp jðn3Þx Zp Zp Zp
¼ f e dx þ ejðn2Þx dx þ ejðn1Þx dx þ ejnx dx
2p p p p p
Zp Zp Zp
jðn þ 1Þx jðn þ 2Þx jðn þ 3Þx
þ e dx þ e dx þ e dxg
p p p
¼ d½n  3 þ d½n  2 þ d½n  1 þ d½n þ d½n þ 1
þ d½ n þ 2 þ d½ n þ 3 ¼ x ½ n


The integral of the complex exponential in above indicates the discrete delta
function as shown in Eq. (3.14).
3.3 Discrete-Time Fourier Transform (DTFT) 87


Rp jðn3Þx 0 for n 6¼ 3
e dx ¼ ¼ 2pd½n  3 where n 2 Z ð3:14Þ
p 2p for n ¼ 3

If the ðn  3Þ is not equal to zero, the integral accumulates the complex vectors
on unit circle over the multiple complete turns specified by ðn  3Þ for zero output.
The integral generates non-zero output only at the one specific location that follows
the property of the discrete delta function. Therefore, the synthesis equation suc-
cessfully derives the original given sequence x[n] from the frequency distribution
X ðejx Þ.
The DTFT is the linear operator as below.

z½n ¼ ax½n þ by½n

  X
1
Z ejx ¼ fax½n þ by½ngejxn
n¼1
P1 P
1
¼a x½nejxn þ b y½nejxn ¼ aX ðejx Þ þ bY ðejx Þ ð3:15Þ
n¼1 n¼1

Also, synthesis equation is satisfying the linearity as following.


     
Z ejx ¼ aX ejx þ bY ejx

1 Zp    
z½n ¼ faX ejx þ bY ejx gejxn dx
2p p
ð3:16Þ
a Zp  jx  jxn b Zp  jx  jxn
¼ X e e dx þ Y e e dx ¼ ax½n þ by½n
2p p 2p p

The time shift can be represented in the frequency domain as below.

X
1 X
1
x½n  d ejxn ¼ x½mejxðm þ dÞ
n¼1 m þ d¼1
ð3:17Þ
X
1  
jxm jxd
¼ x½me e ¼ X ejx ejxd
m¼1

The delay in the time domain is denoted by the complex multiplication in


frequency domain. The shift in the frequency domain is illustrated as below.

Zp   Zp
1 jðxxs Þ 1  
X e e dx ¼
jxn
X eju ejðu þ xs Þn d ðu þ xs Þ
2p 2p
p p

Rp
¼ 2p
1
X ðeju Þeju n duejxs n ¼ x½nejxs n ð3:18Þ
p
88 3 Fourier Analysis

As previously mentioned, the given real sequence must generate conjugated


magnitudes for the positive and negative frequency pair.

X ðejx Þ ¼ X  ðejx Þ ð3:19Þ

The reversal in time provides the reversal in frequency as well.

P
1 P
1
x½nejxn ¼ x½mejxm ¼ X ðejx Þ ð3:20Þ
n¼1 m¼1

According to the Parseval’s theorem [2], the energy in time domain is identical
to the energy in frequency domain as below.

P
1 Rp 2
Ex ¼ jx½nj2 ¼ 2p
1
jX ðejx Þj dx ð3:21Þ
n¼1 p

Example 3.6
Apply the Parseval’s theorem on below example.

1 for  3  n  3
x ½ n ¼
0 Otherwise

Solution
The time domain energy is below.

X
1
Ex ¼ jx½nj2 ¼ 7
n¼1

The frequency domain distribution and energy are below from Example 3.4.
 
X ejx ¼ 1 þ 2 cosðxÞ þ 2 cosð2xÞ þ 2cosð3xÞ

1 Zp
Ex ¼ j1 þ 2 cosðxÞ þ 2 cosð2xÞ þ 2cosð3xÞj2 dx
2p p
( )
1 Zp Zp Zp Zp
¼ 1dx þ 4 cos2 ðxÞdx þ 4 cos2 ð2xÞdx þ 4 cos2 ð3xÞdx
2p p p p p
1
¼ f2p þ 4p þ 4p þ 4pg ¼ 7
2p

Observe that the cross terms in frequency domain energy computation are zero.
For example, shown as below.
3.3 Discrete-Time Fourier Transform (DTFT) 89

Zp Zp
1 1
cosðxÞ cosð2xÞdx ¼ 0 cosð2xÞ cosð3xÞdx ¼ 0
2p 2p
p p

Therefore, energy can be computed in either domain for your computational


convenience. ■

3.4 Discrete Fourier Transform (DFT)

Unless you use the symbolic mathematics for the computer, the continuous domain
cannot be handled by the digital computer directly. Discrete data or sampled signal
can be processed by the digital bits with binary logics specified by the computer
software. For versatile processing, the signal is managed in the time domain as well
as frequency domain with discrete information handling. We mentioned that the
sampling process provides the discrete time sequence that generates the spectrum
periodicity in every 2p interval. Also, the signal periodicity presents the discrete
frequency distribution with the 2p=N spectral distance known as fundamental
frequency. The discrete Fourier Transform (DFT) [1] is the transformation for the
discrete time and discrete frequency distribution; therefore, the conventional
computer performs the numerical operations for the transformation. The discrete
periodicity and orthogonality provide the important clue to the transformation
equations similar to the DTFT derivation. Let’s explore the DFT by defining the
discrete periodic signal as Eq. (3.22). The signal with period N contains following
periods as well.

xN ½n ¼ a1 sN ½n þ a2 sN=2 ½n þ a3 sN=3 ½n þ a4 sN=4 ½n þ    þ aN sN=N ½n
ð3:22Þ
¼ xN ½n þ mN  m 2 Z

The sN ½n is the N period sinusoid with unit magnitude and the a1 is the constant
magnitude for the sN ½n. The xN ½n only includes the N period as well as its integer
divisions such as N=2, N=3, N=4, etc. The integer division of the any given periods
can generate N period; in other words, all the sub-period signals complete its period
at N sequence location to initiate new xN ½n period. The frequency representation of
the signal is in Eq. (3.23).
2p 2p 2p 2p 2p
xN ½n ¼ a1 ej N n þ a2 ej N 2n þ a3 ej N 3n þ a4 ej N 4n þ    þ aN ej N Nn
X
N 1
2p 2p 2p ð3:23Þ
¼ X ½kej N kn where ej N Nn ¼ ej N 0n
k¼0

The signal xN ½n only has the fundamental frequency 2p=N and its integer
multiples. The X ½k is the complex magnitude for the kth harmonics. Is the xN ½n the
90 3 Fourier Analysis

real number? In order to use the Euler equation, the negative frequency is required
but not shown in Eq. (3.23). Find the condition to make the real sequence.

X
N 1
2p
x N ½ n ¼ X ½kej N kn
k¼0
2p 2p 2p
¼ X ½0ej N 0n þ X ½1ej N n þ X ½2ej N 2n þ . . .
þ X ½N  2ej N ðN2Þn þ X ½N  1ej N ðN1Þn
2p 2p

2p 2p 2p
¼ X ½0ej N 0n þ X ½1ej N n þ X ½2ej N 2n þ . . .
þ X ½N  2ej N Nn ej N 2n þ X ½N  1ej N Nn ej N n
2p 2p 2p 2p

2p 2p
¼ X ½0ej N 0n þ X ½1ej N n þ X ½2ej N 2n þ . . .
2p ð3:24Þ

þ X ½N  2ej N 2n þ X ½N  1ej N n
2p 2p

n o
¼ X ½0ej N 0n þ X ½1ej N n þ X ½N  1ej N n
2p 2p 2p

n o
þ X ½2ej N 2n þ X ½N  2ej N 2n þ   
2p 2p

(
X ½N2 e
j2pN n
N2 for even N
þ
X½  þ X½ 
2pN1 2pN1
N1
2 ej N 2 n N þ1
2 ej N 2 n for odd N

By using the angular equivalence, the north and south hemisphere of the com-
plex plane shown Fig. 3.10 is assigned to the positive and negative frequency,
respectively. The Euler formula pair transforms the complex exponentials to the
cosine functions for real number sequence shown in Eq. (3.24).
Therefore, following condition is required for real number sequence.

X ½k  ¼ X  ½N  k  ð3:25Þ

The signal with N period can be generated by the linear combination of complex
exponentials as below.

P
N1 2p
xN ½n ¼ N1 X ½kej N kn ð3:26Þ
k¼0

Fig. 3.10 Euler formula pair


imag.
relationship
ej(2π/N)2

ej(2π/N)1
Euler Pair

real

ej(2π/N)(N-1)=e-j(2π/N)1

ej(2π/N)(N-2)=e-j(2π/N)2
3.4 Discrete Fourier Transform (DFT) 91

From the given periodic sequence, how we can find the complex magnitude for
each frequency components? Use the periodicity and orthogonality like DTFT
equations.
!
X
N 1 X
N 1
1XN 1 X
N 1
1X N 1
j2p j2p
ej N kn ¼ X ½lej N ðlkÞn
2p 2p
xN ½ne N kn ¼ X ½le N ln

n¼0 n¼0
N l¼0 n¼0
N l¼0
8 9
>
> P
N1 P
N1
j N ðlk Þn
2p >
>
>
< N
1
X ½ l  e ¼ 0 for l ¼
6 k >
= X N1
l¼0 n¼0
¼ ¼ X ½ld½k  l ¼ X ½k 
>
> P
N1 P j2pðlkÞn
N1 >
>
>1
: X ½ l  e N ¼ X ½k  for l ¼ k >
; l¼0
N
l¼0 n¼0

ð3:27Þ

Therefore,

P
N1
xN ½nej N kn ¼ X ½k 
2p

n¼0

Finally, DFT analysis and synthesis equation are organized as Eqs. (3.28) and
(3.29), respectively.

P
N1
xN ½nej N kn ð3:28Þ
2p
X ½k  ¼
n¼0

P
N1 2p
xN ½n ¼ N1 X ½kej N kn ð3:29Þ
k¼0

One example of the discrete periodic signal xN[n] and corresponding frequency
distribution X[k] are illustrated below.

1n 2p 2p 2p
xN ½ n ¼ X ½0ej N 0n þ X ½1ej N n þ X ½2ej N 2n þ . . .
N o ð3:30Þ
þ X ½N  2ej N ðN2Þn þ X ½N  1ej N ðN1Þn
2p 2p

X ½k ¼ X ½0d½k  þ X ½1d½k  1 þ X ½2d½k  2 þ . . .


ð3:31Þ
þ X ½N  2d½k  ðN  2Þ þ X ½N  1d½k  ðN  1Þ

The xN[n] and X[k] present the periodic property due to the sampling and dis-
cretization in time and frequency domain, respectively. Figure 3.11 shows the one
example xN[n] and X[k] for 16 sample period N. The digital frequency k includes the
symmetric pattern distribution for real xN[n] signal.
92 3 Fourier Analysis

Fig. 3.11 Example xN[n] and X[k] for 16 sample period N

Prog. 3.5 MATLAB program for Fig. 3.11

N = 16;
rng('default')
xn = randn(1,N);
xne = [xn xn xn];
Xk = (xn);
Xke = abs([Xk Xk Xk]);
nn = -N:1:2*N-1;
kk = -N:1:2*N-1;

figure,
subplot(211), stem(nn,xne), grid
xlim([-5 20])
ylim([-5 5])
subplot(212), stem(kk,Xke), grid
xlim([-5 20])
ylim([0 15])
3.4 Discrete Fourier Transform (DFT) 93

Example 3.7
Compute the DFT of following signals with length N > 8.

x1 ½n ¼ an ðu½n  u½n  N Þ for a 2 R

x 2 ½ n ¼ u½ n  u½ n  N 

x3 ½n ¼ d½n
 
2p
x4 ½n ¼ cos 3n ðu½n  u½n  N Þ
N

Solution

X
N 1 X
N 1 N 1
X n
x1 ½nej N kn ¼ an ej N kn ¼ aej N k
2p 2p 2p
X 1 ½k  ¼
n¼0 n¼0 n¼0
 N
1  aej N k
2p

¼
1  aej N k
2p

X
N 1 X
N 1
ðu½n  u½n  N Þej N kn ¼ ej N kn
2p 2p
X 2 ½k  ¼
n¼0 n¼0
j2p jNp kN
 jNp kN p 
1e N kN
e e  ejN kN
¼ j
¼p p p
1  ej N k
2p
e N k
e N  ejN k
j k

p sinðpk Þ
¼ejN kðN1Þ  p  ¼ Nd½k
sin N k

sinðpk Þ 0 for 0\k\N
* p  ¼
sin N k N for k ¼ 0

X
N 1
d½nej N kn ¼ 1
2p
X3 ½k ¼
n¼0

N 1
X   
2p
3n ðu½n  u½n  N Þ ej N kn
2p
X4 ½k  ¼ cos
n¼0
N
N1  2p N1  
1X 1X
ej N 3n þ ej N 3n ej N kn ¼ ej N ðk3Þn þ ej N ðk þ 3Þn
2p 2p 2p 2p
¼
2 n¼0 2 n¼0
N N
¼ d½k  3 þ d½k þ 3
2 2

Note that above frequency information X ½ks represent the distribution over the
range between 0 to N−1. The distribution is repeated in every N. ■
94 3 Fourier Analysis

Relationship between the DTFT and DFT for the periodic signal is below.

  X
1 X
1
X ejx ¼ x½nejxn ¼ xN ½nejxn
n¼1 n¼1
X
1
1 X
N 1
1XN 1 X1
X ½k ej N kn ejxn ¼ ejðx N kÞn
2p 2p
¼ X ½k 
n¼1
N N k¼0 n¼1
k¼0
ð3:32Þ
1XN 1 X1
ejðx N ðk þ lN ÞÞn for l 2 Z
2p
¼ X ½k 
N k¼0 n¼1
P
N1   2p P
1  
¼ N1 X ½k2pd x  2p
N ðk þ lN Þ ¼ N X ½kd x  2p
N k
k¼0 k¼1

Zp Zp  
1   1 2p X1
2p
x½n ¼ X e jx
e jxn
dx ¼ X ½kd x  k ejxn dx
2p 2p N k¼1 N
p p

X
1 Zp  
¼
1 2p
X ½kej N kn
2p
d x  k dx ð3:33Þ
N k¼1 N
p
P
N1
j2p
¼ N1 X ½k e N kn ¼ x N ½ n
k¼0

Zp  
2p
* d x  k dx 6¼ 0 for one complete 2p equivalently N sample period
N
p

Summarize the relation between the DTFT and DFT below.

P
N1 2p P
N1  
x½n ¼ N1 X ½k ej N kn ¼ 2p
1
X ejkx0 ejx0 kn ¼ xN ½n ð3:34Þ
k¼0 k¼0

P
1  
X ðejx Þ ¼ 2p
N X ½k d x  2p
N k ð3:35Þ
k¼1

Let’s do one example as below.


Example 3.8
The given signal is periodic impulse train with 6 sample period. Compute the DFT
and DTFT of the given signal.

X
1
x 6 ½ n ¼ d6 ½ n ¼ d½n  6m
m¼1
3.4 Discrete Fourier Transform (DFT) 95

Solution

X
5
d½nej 6 kn ¼ 1
2p
X ½k  ¼
n¼0

 
  2p X 1
2p
X ejx ¼ 1d x  k
6 k¼1 6

The inverse DFT derives the original time domain signal as below.

1X 5
2p
X1
x 6 ½ n ¼ 1ejk 6 n ¼ d½n  6m
6 k¼0 m¼1

Prog. 3.6 MATLAB program for Fig. 3.12

N = 6;
xn = [1 0 0 0 0 0];
xne = [xn xn xn];
Xk = (xn);
Xke = abs([Xk Xk Xk]);
nn = -N:1:2*N-1;
kk = -N:1:2*N-1;

figure,
subplot(311), stem(nn,xne), grid
xlim([-6 11])
ylim([0 2])
ylabel('x_{6}[n]')
subplot(312), stem(kk,Xke), grid
xlim([-6 11])
ylim([0 2])
ylabel('X[k]')
subplot(313), stem(kk,Xke,'Marker','^'), grid
xlim([-6 11])
ylim([0 2])
ylabel('X(e^{j\omega})')
xcks([-1 0 1 2 3 4 5 6])
xcklabels({'...','0','\pi/3','2\pi/3','\pi','4\pi/3','5\pi/3','...'})
xckangle(90)


96 3 Fourier Analysis

Fig. 3.12 Example xN[n], X[k], and X ðejx Þ for 6 sample period N

The impulse train with six sample period is transformed to the frequency domain
by using the DFT and DTFT as shown in Fig. 3.12. The DFT frequency is the
discrete domain in spectrum with unit magnitude and the DTFT frequency is the
continuous domain in spectrum with p=3 magnitude for impulse. Note that the
DTFT can represent the any arbitrary signal but the DFT can handle the periodic
signal only. What if we have non-periodic signal and want to operate with DFT?
Let’s consider following problem.

1 for  3  n  3
x ½ n ¼ ð3:36Þ
0 Otherwise

The below is the procedure to find the frequency distribution of the given signal
Eq. (3.36). Note that the signa x[n] is illustrated at Fig. 3.8. From the previous
example, the DTFT of the given signal is below.

X ðejx Þ ¼ 1 þ 2 cosðxÞ þ 2 cosð2xÞ þ 2 cosð3xÞ ð3:37Þ

The DFT is following.

X
N 1 X
3 n 2p o n 2p o
xN ½nej N kn ¼ ej 7 kn ¼ 1 þ ej 7 k þ ej 7 k þ ej 7 2k þ ej 7 2k
2p 2p 2p 2p
X ½k  ¼
n¼0 n¼3
n 2p o   2p  2p 
þ ej 7 3k þ ej 7 3k
2p
¼ 1 þ 2 cos 2p
7 k þ 2 cos 7 2k þ 2 cos 7 3k

ð3:38Þ
3.4 Discrete Fourier Transform (DFT) 97

The inverse of the DFT is below.


6 h n 2p o n 2p o
1X
N1
1X
1 þ ej 7 k þ ej 7 k þ ej 7 2k þ ej 7 2k
2p 2p 2p
x½n ¼ X ½k ej N kn ¼
N k¼0 7 k¼0
n 2p oi 2p
þ ej 7 3k þ ej 7 3k ej 7 kn
2p

6 h n 2p o n 2p o
1X
ej 7 kn þ ej 7 kð1nÞ þ ej 7 kð1 þ nÞ þ ej 7 kð2nÞ þ ej 7 kð2 þ nÞ ð3:39Þ
2p 2p 2p
¼
7 k¼0
n 2p oi
þ ej 7 kð3nÞ þ ej 7 kð3 þ nÞ
2p

¼ d½n þ d½n  1 þ d½n þ 1 þ d½n  2


þ d½n þ 2 þ d½n  3 þ d½n þ 3

Prog. 3.7 MATLAB program for Fig. 3.13

N1 = 7;
w = 0:pi/100:2*pi;
k1 = 0:1:(N1-1);
Xw1 = 1+2*cos(w)+2*cos(2*w)+2*cos(3*w);
Xk1 = 1+2*cos(2*pi*k1/N1)+2*cos(2*pi*2*k1/N1)+2*cos(2*pi*3*k1/N1);

figure,
subplot(211), plot(w,Xw1), grid
ylabel('X(e^{j\omega})')
ylim([-2 8])
hold on
yyaxis right
stem(2*pi*k1/N1,Xk1)
ylabel('X[k]')
ylim([-2 8])
hold off
xlim([0 2*pi])
xcks(2*pi*(0:1:7)/N1)
xcklabels({'2\pi0/7','2\pi1/7','2\pi2/7','2\pi3/7','2\pi4/7','2\pi5/7','2\pi6/7','
2\pi7/7'})
xlabel('\omega')
subplot(212), stem(n1,ones(size(n1))), grid
xlabel('n')
ylabel('x[n]')
ylim([0 2])

In this problem, the signal and DFT length is seven; therefore, the seven ones are
repeated forever to show the all ones for entire sequence range. The frequency
98 3 Fourier Analysis

Fig. 3.13 DTFT and DFT of window function Eq. (3.36) and inverse DFT for x[n] for N = 7

distribution in Fig. 3.13 from the DFT delivers the single value at the
zero-frequency location that represents no fluctuation (constant) signal in time
domain. The DTFT result in Fig. 3.13 shown in solid line generates non-periodic
signal distribution which denotes the original signal Eq. (3.36) from the given
problem. The DFT samples the DTFT continuous outcome in every 2p=7 for digital
frequency distribution in terms of k. The sampling is performed improperly due to
the short DFT length; therefore, the reconstructed signal does not correspond to the
original given signal accurately.
Let’s increase the DFT length for 9 as below.

X
4
ej 9 kn
2p
X ½k  ¼
n¼4
n 2p o n 2p o n 2p o ð3:40Þ
¼1 þ ej 9 k þ ej 9 k þ ej 9 2k þ ej 9 2k þ ej 9 3k þ ej 9 3k
2p 2p 2p

  2p  2p 
9 k þ 2 cos 9 2k þ 2 cos 9 3k
¼ 1 þ 2 cos 2p
3.4 Discrete Fourier Transform (DFT) 99

The inverse of the DFT is below.

8 h n 2p o n 2p o
1XN 1
1X
1 þ ej 9 k þ ej 9 k þ ej 9 2k þ ej 9 2k
2p 2p 2p
x½n ¼ X ½kej N kn ¼
N k¼0 9 k¼0
n 2p oi 2p
þ ej 9 3k þ ej 9 3k ej 9 kn
2p

8 h n 2p o n 2p o
1X
ej 9 kn þ ej 9 kð1nÞ þ ej 9 kð1 þ nÞ þ ej 9 kð2nÞ þ ej 9 kð2 þ nÞ
2p 2p 2p
¼
9 k¼0
n 2p oi
þ ej 9 kð3nÞ þ ej 9 kð3 þ nÞ
2p

¼ d½n þ d½n  1 þ d½n þ 1 þ d½n  2


þ d½ n þ 2 þ d½ n  3 þ d½ n þ 3
ð3:41Þ

Prog. 3.8 MATLAB program for Fig. 3.14

N2 = 9;
w = 0:pi/100:2*pi;
k2 = 0:1:(N2-1);
n2 = -4:1:4;
Xw1 = 1+2*cos(w)+2*cos(2*w)+2*cos(3*w);
Xk2 = 1+2*cos(2*pi*k2/N2)+2*cos(2*pi*2*k2/N2)+2*cos(2*pi*3*k2/N2);

figure,
subplot(211), plot(w,Xw1), grid
ylabel('X(e^{j\omega})')
ylim([-2 8])
hold on
yyaxis right
stem(2*pi*k2/N2,Xk2)
ylabel('X[k]')
ylim([-2 8])
hold off
xlim([0 2*pi])
xcks(2*pi*(0:1:9)/N2)
xcklabels({'2\pi0/9','2\pi1/9','2\pi2/9','2\pi3/9','2\pi4/9','2\pi5/9','2\pi6/9','
2\pi7/9','2\pi8/9','2\pi9/9'})
xlabel('\omega')
subplot(212), stem(n2,[0 ones(size(n1)) 0]), grid
xlabel('n')
ylabel('x[n]')
ylim([0 2])
100 3 Fourier Analysis

Fig. 3.14 DTFT and DFT of window function Eq. (3.36) and inverse DFT for x[n] for N = 9

Now, we can see the certain magnitudes in other than the zero-frequency
location in Fig. 3.14. The DTF samples the DTFT outcome in every 2p=9 and the
reconstructed signal illustrates the seven ones and two zeros for one period set.
Let’s increase the DFT length further for 99.

X
4
ej99kn
2p
X ½k  ¼
n¼4
n 2p o n 2p o n 2p o ð3:42Þ
¼ 1 þ ej99k þ ej99k þ ej992k þ ej992k þ ej993k þ ej993k
2p 2p 2p

  2p  2p 
99 k þ 2 cos 99 2k þ 2 cos 99 3k
¼ 1 þ 2 cos 2p
3.4 Discrete Fourier Transform (DFT) 101

The inverse of the DFT is below.

1XN 1
2p
x ½ n ¼ X ½k ej N kn
N k¼0

1XN1
2p
x½n ¼ X ½k ej N kn
N k¼0
98 h n 2p o n 2p o
1 X
1 þ ej99k þ ej99k þ ej992k þ ej992k
2p 2p
¼
99 k¼0
n 2p oi 2p
þ ej993k þ ej993k ej99kn
2p

ð3:43Þ
98 h n 2p o n 2p o
1 X
ej99kn þ ej99kð1nÞ þ ej99kð1 þ nÞ þ ej99kð2nÞ þ ej99kð2 þ nÞ
2p 2p 2p
¼
99 k¼0
n 2p oi
þ ej99kð3nÞ þ ej99kð3 þ nÞ
2p

¼ d½n þ d½n  1 þ d½n þ 1 þ d½n  2


þ d½n þ 2 þ d½n  3 þ d½n þ 3

Prog. 3.9 MATLAB program for Fig. 3.15

N3 = 99;
w = 0:pi/100:2*pi;
k3 = 0:1:(N3-1);
n3 = -49:1:49;
Xw1 = 1+2*cos(w)+2*cos(2*w)+2*cos(3*w);
Xk3 = 1+2*cos(2*pi*k3/N3)+2*cos(2*pi*2*k3/N3)+2*cos(2*pi*3*k3/N3);

figure,
subplot(211), plot(w,Xw1), grid
ylabel('X(e^{j\omega})')
ylim([-2 8])
hold on
yyaxis right
stem(2*pi*k3/N3,Xk3,'Marker','.')
ylabel('X[k]')
ylim([-2 8])
hold off
xlim([0 2*pi])
xcks([0 pi/4 2*pi/4 3*pi/4 pi 5*pi/4 6*pi/4 7*pi/4 2*pi])
xcklabels({'0','\pi/4','2\pi/4','3\pi/4','\pi','5\pi/4','6\pi/4','7\pi/4','2\pi'})
xlabel('\omega')
subplot(212), stem(n3,[zeros(1,46) ones(size(n1)) zeros(1,46)],'Marker','.'),
grid
xlabel('n')
ylabel('x[n]')
ylim([0 2])
102 3 Fourier Analysis

Fig. 3.15 DTFT and DFT of window function Eq. (3.36) and inverse DFT for x[n] for N = 99

The DFT from 99 length precisely follows the DTFT continuous line with 2p=99
radian interval in Fig. 3.15. Only seven ones are located in the 99-length period
from the reconstruction by inverse DFT at Fig. 3.15. The further increasing in the
DFT length expects to show the accurate depiction of the spectrum; however, the
periodicity cannot be avoided unless you use the DTFT instead of DFT. For
computer processing, the longer DFT length is recommended for the non-periodic
signal. To increase the length of the non-periodic signal, zero padding is performed
by placing the zero values after the signal portion. The zero padding improves the
spectral representation by increasing the frequency resolution as shown above
problem. The resolution in radian and cyclic frequency is given as below.

Dx ¼ x0 ¼ 2p
N or Df ¼ Nfs ð3:44Þ

The equivalence location between the DFT and DTFT is subsequence.


2p 
X ½k   X N k for 0  k  N  1 ð3:45Þ

The length related matter still includes the periodic signal in DFT. The unknown
frequency signal is roughly framed by intuitive length in order to convert for the
spectrum distribution. Provided that the desired frequency dose not corresponds to
the discrete DFT frequencies, the DFT representation loses the accuracy. Let’s
consider the following signal. The below signal is the discrete cosine wave with 8
period sample.
3.4 Discrete Fourier Transform (DFT) 103

2p 
x½n ¼ cos 8 n for 0  n  7 ð3:46Þ

The DFT of the signal is below. Note that j2pðk þ 1Þn=8 term in Eq. (3.47)
presents the equal values at k = −1, 7, 15, etc. due to the circular property of
complex exponential.

X  
7
2p 1X 7
n ej 8 kn ¼ ðej 8 n þ ej 8 n Þej 8 kn
2p 2p 2p 2p
X ½k  ¼ cos
8 2 n¼0
n¼0
ð3:47Þ
P
7
j2p
¼ 12 ðe 8 ðk1Þn þe j2p
8 ðk þ 1Þn Þ ¼ 4d½k  1 þ 4d½k  7
n¼0

Prog. 3.10 MATLAB program for Fig. 3.16

syms w n;
N1 = 8; % Length
nn1 = 0:1:(N1-1);
nn1e = -N1:2*N1-1;
ww1 = 0:pi/100:2*pi;
xn1 = cos(2*pi*nn1/8);
xn1e = [xn1 xn1 xn1];
bb1 = symsum(cos(2*pi*n/8)*exp(-1j*w*n),n,0,N1-1);
cc1 = simplify(bb1,'Steps',100);
dd1 = subs(cc1,w,ww1);
ee1 = abs(eval(dd1));
Xk1 = (xn1);

figure,
subplot(211)
stem(nn1e,xn1e), grid
xlabel('n')
ylabel('x[n]')
subplot(212)
plot(ww1,ee1), grid
ylabel('|X(e^{j\omega})|')
ylim([0 10])
hold on
yyaxis right
stem(nn1*2*pi/N1,abs(Xk1))
ylabel('|X[k]|')
ylim([0 10])
hold off
xlim([0 2*pi])
xcks(2*pi*(0:1:N1-1)/N1)
xcklabels({'0','1','2','3','4','5','6','7'})
xlabel('k')
104 3 Fourier Analysis

Fig. 3.16 DFT of discrete cosine wave Eq. (3.46) for N = 8

The DFT demonstrates the values only at 1 and 7 in k positions as shown in


Fig. 3.16. The solid line in the magnitude plot represents the DTFT of the given 8
sample cosine function. The k = 1 denotes the 2p=8 radian frequency which
specifies the 8-sample period signal. Also, the k = 7 renders the 2p7=8 radian
frequency that is equivalent to the 2p=8. The time sequence of the original signal
is well expressed by the DFT since we can observe the clear division between the
desired and undesired signal in frequency domain.
Now, we increase the signal length as 9.

P
8 2p  j2pkn
X ½k  ¼ cos 8 n e
9 ð3:48Þ
n¼0

The DFT computation generates complex value results. In Fig. 3.17, certain
insignificant values are observed along with prominent outcomes due to the fre-
quency mismatch between the signal frequency and DFT frequencies. The given
signal frequency is 2p=8 located between the 1 and 2 for k value from DFT with
length 9 in Eq. (3.49) and Fig. 3.17.

9 ðk ¼ 1Þ\ 2p
8 \ 9 2ð k ¼ 2Þ ð3:49Þ
2p 2p
3.4 Discrete Fourier Transform (DFT) 105

Fig. 3.17 DFT of discrete cosine wave Eq. (3.47) for N = 9

The figure matrix in Fig. 3.18 shows the DFT magnitude for length from 10 to
15. The solid line in the magnitude plot is the DTFT result. For length 9 outcome,
the DTFT peaks present the actual signal frequencies but the DFT locates the
depature frequencies due to the insufficient frequency sampling. This phenomenon
delivers the worse frequency estimation as approaching the length 12 in terms of the
ratio between the maximum and minimum of DFT magnitude. The 12/8 (1.5) of the
k value corresponds to the 2p=8 frequency for length 12 DFT. Further increasing
the DFT length improves the frequency representation and the length 16 demon-
strates the bestperformance as shown in Fig. 3.19. Note that the length 16 is the
complete 2 period of the given cosine signal and the value 2 of the k presents the
2p=8 frequency exactly.
Prog. 3.11 MATLAB program for Fig. 3.17. Identical to Prog. 3.10 except N1
value

syms w n;
N1 = 9; % Length
...
106 3 Fourier Analysis

Fig. 3.18 DFT of discrete cosine wave Eq. (3.46) for N = 10,11,12,13,14, and 15 (Solid line
indicates the DTFT). MATLAB program is realized by modifying the N1 value from Prog. 3.10

For the periodic signal, the longer DFT length is benefit to estimate the precise
signal frequency because of the fine grain frequency resoultion by 2p=N. The
example below performs the 260 (8  32 + 4) length DFT for the cosine function
with period 8. The given case is the identically worst case as 12 length from
Fig. 3.18 since the frame is finished at the period center. The 2p=8 radian frequency
corresponds to the 32.5 of k value as below in Fig. 3.20.
3.4 Discrete Fourier Transform (DFT) 107

Fig. 3.19 DFT of discrete cosine wave Eq. (3.46) for N = 16. MATLAB program is realized by
modifying the N1 value from Prog. 3.10

260 32ðk ¼ 32Þ\ 2p


8 \ 260 33ðk ¼ 33Þ ð3:50Þ
2p 2p

Figure 3.20 shows the DFT magnitude for the 260 length signal to represent the
2p=8 radian frequency. The DTFT result is denoted by the solid line and the DTFT
peak is located at the center of the k values between 32 and 33. Compare to the DFT
with length 12, longer length DFT provides the improved prominence for the signal
representation.

Fig. 3.20 DFT of discrete cosine wave Eq. (3.46) for N = 260
108 3 Fourier Analysis

Prog. 3.12 MATLAB program for Fig. 3.20


syms w n;
N1 = 260; % Length
nn1 = 0:1:(N1-1);
ww1 = 0:pi/2048:2*pi;
xn1 = cos(2*pi*nn1/8);
bb1 = symsum(cos(2*pi*n/8)*exp(-1j*w*n),n,0,N1-1);
cc1 = simplify(bb1,'Steps',100);
dd1 = subs(cc1,w,ww1);
ee1 = abs(eval(dd1));
Xk1 = (xn1);

figure,
plot(ww1,ee1), grid
ylabel('|X(e^{j\omega})|')
ylim([0 140])
hold on
yyaxis right
stem(nn1*2*pi/N1,abs(Xk1))
ylabel('|X[k]|')
ylim([0 140])
hold off
xlim([2*pi*20/N1 2*pi*50/N1]) % From 20 ~ 50 k value
xcks(2*pi*(0:5:N1)/N1)
xcklabels({'0','5','10','15','20','25','30','35','40','45','50','55','60','65','70'});
xlabel('k')

If you cannot have the longer periodic signal, zero padding improves the visual
spectral resolution by 2p=N. The N includes signal length as well as the zero
padding length. The padded zeros are located after the signal sequence as shown in
Fig. 3.21.
The attached zeros cannot change the DTFT computations since the only
non-zero first signal portion is multiplied with complex exponential as below

P
1
X ðejx Þ ¼ x½nejxn ð3:51Þ
n¼1
3.4 Discrete Fourier Transform (DFT) 109

Fig. 3.21 Zero padding of discrete cosine wave Eq. (3.47) for N = 17

However, the DFT provides the finer resolution due to the increased overall
signal length by zero padding as Eq. (3.52). The multiplication with complex
exponential is identical to the DTFT computation but the exponential value is
changed by the N for better representation.

P
N1
x½nej N kn ð3:52Þ
2p
X ½k  ¼
n¼0

Figure 3.22 illustrates the DFT (stem plot) and DTFT (solid plot) results from
cosine function for 8 period and 12 length with various zero padding conditions.
Note that DTFT outcomes are invariant for all zero padding situations given below
and the first plot is the no zero padding case for reference. The augmented signal
size by zeros enhances the spetral representation randomly but persistently in
length-wise manner. Provided that the system knows the signal or estimation fre-
quency a priori, the designer intelligently selects the DFT parameters for precise
detection and estimation. Otherwise, the longer is better in general.
110 3 Fourier Analysis

Fig. 3.22 DFT of discrete cosine wave Eq. (3.46) for 12 sample signal length (0  n  11Þ with
various zero padding length (Solid line indicates the DTFT)
3.4 Discrete Fourier Transform (DFT) 111

Prog. 3.13 MATLAB program for Fig. 3.22. Change the padding length (N1)
syms w n;
N = 12; % Signal length
N1 = 0; % Padding size. Choose one [0 1 2 3 4 5 15 30]
nn1 = 0:1:(N-1);
ww1 = 0:pi/256:2*pi;
xn1 = cos(2*pi*nn1/8);
xn1e = [xn1 zeros(1,N1)];
N2 = length(xn1e); % Length of Signal and padding
xn2 = [xn1e xn1e xn1e];
nn2 = -N2:1:N2*2-1;
nn3 = 0:1:N2-1;
bb1 = symsum(cos(2*pi*n/8)*exp(-1j*w*n),n,0,N-1);
cc1 = simplify(bb1,'Steps',100);
dd1 = subs(cc1,w,ww1);
ee1 = abs(eval(dd1));
Xk1 = (xn1e);

figure,
subplot(211)
stem(nn2,xn2), grid
xlabel('n')
ylabel('x[n]')
xlim([-N2 N2*2-1])
ylim([-2 2])
subplot(212)
plot(ww1,ee1), grid
ylabel('|X(e^{j\omega})|')
ylim([0 7])
hold on
yyaxis right
stem(nn3*2*pi/N2,abs(Xk1))
ylabel('|X[k]|')
ylim([0 7])
hold off
xlim([0 2*pi])
xcks(2*pi*(0:3:N2-1)/N2)
xcklabels({'0','3','6','9','12','15','18','21','24','27','30','33','36','39','42'})
xlabel('k')

The DFT exhibits unique shift pattern because of the signal periodicity. Let’s
consider the DFT computation for the triangular signal with length 8. The signal x
[n] and exponential ej2pkn=8 component are decomposed in Table 3.1 for DFT
computation.
112 3 Fourier Analysis

Table 3.1 Triangular signal x[n] with length 8 and DFT exponential part
n −1 0 1 2 3 4 5 6 7 8
x[n] 0 1 2 3 4 5 4 3 2 0
ej 8 kn ej 8 k0 ej 8 k1 ej 8 k2 ej 8 k3 ej 8 k4 ej 8 k5 ej 8 k6 ej 8 k7 ej 8 k8
2p 2p 2p 2p 2p 2p 2p 2p 2p 2p 2p
ej 8 k1

P
7
x½nej 8 kn
2p
X1 ½k  ¼ ð3:53Þ
n¼0

For the time being, x½n is not a periodic signal; therefore, the 8 sample sequence
leaves the empty values beyond signal length in Table 3.1. The signal is shifted to
the right by one sample as x½n  1 and the DFT range follows the sequence span
from 1 to 8 as shown in Eq. (3.54).

P
8
x½n  1ej 8 kn ð3:54Þ
2p
X2 ½k  ¼
n¼1

In the Table 3.2, the last sample on the shifted x½n is multiplied by ej2pk8=8 that is
equivalen to the ej2pk0=8 . The last sample is relocated to the corresponding location
as zero index in Table 3.3 and the DFT range is rearranged for signal span in
Eq. (3.55).

P
7
x8 ½n  1ej 8 kn
2p
X2 ½k  ¼ ð3:55Þ
n¼0

Table 3.2 Shifted signal x[n−1] and DFT exponential part


c −1 0 1 2 3 4 5 6 7 8
x[n−1] 0 0 1 2 3 4 5 4 3 2
ej 8 kn ej 8 k0 ej 8 k1 ej 8 k2 ej 8 k3 ej 8 k4 ej 8 k5 ej 8 k6 ej 8 k7 ej 8 k8
2p 2p 2p 2p 2p 2p 2p 2p 2p 2p 2p
ej 8 k1

Table 3.3 Relocated and shifted signal x[n−1] and DFT exponential part
n −1 0 1 2 3 4 5 6 7 8
x[n−1] 0 2 1 2 3 4 5 4 3 0
ej 8 kn ej 8 k0 ej 8 k1 ej 8 k2 ej 8 k3 ej 8 k4 ej 8 k5 ej 8 k6 ej 8 k7 ej 8 k8
2p 2p 2p 2p 2p 2p 2p 2p 2p 2p 2p
ej 8 k1
3.4 Discrete Fourier Transform (DFT) 113

Fig. 3.23 Periodic signal x8[n] and x8[n−1]

In the DFT computation, the signal is processed and assumed to be periodic with
DFT length N. The edge of the signal is moved to the one end and appeared to the
other end sequentially. The given x8 ½n and x8 ½n  1 are illustrated for the wider
range of sequnce in Fig. 3.23.
The most of the DTFT properties are satisfited with DFT. The DFT is the linear
operator as below.

z½n ¼ ax½n þ by½n

P
N1
fax½n þ by½ngej N kn ¼ aX ½k þ bY ½k 
2p
Z ½k  ¼ ð3:56Þ
n¼0

Also, synthesis equation is satisfying the linearity as following.

Z ½k  ¼ aX ½k þ bY ½k 

P
N1
ð3:57Þ
2p
z½n ¼ N1 faX ½k  þ bY ½kgej N kn ¼ ax½n þ by½n
n¼0

The time shift can be represented in the frequency domain as below.

P
N1 P
N1
xN ½n  d ej N kn ¼ xN ½nej N kn ej N kd ¼ X ½k ej N kd
2p 2p 2p 2p
ð3:58Þ
n¼0 n¼0
114 3 Fourier Analysis

Table 3.4 DFT shift property by example

0 1 2 3 4 5 6 7

The explanation of the DFT shift property is presented by the example with table
method. The x½n value and corresponding complex exponential are denoted in each
column of Table 3.4. The middle rows provide the DFT of the shifted signal by 2
samples. The bottom rows deliver the shifted DFT by exponential multiplication
without relocating the signal according to the Eq. (3.58). Note that the complex
exponential equivalence is indicated by the colored circles in Table 3.4.
The shift in frequency domain is shown in Eq. (3.59). The X ½k is also the
periodic distribution with N sequence and the description for frequency shift can be
realized by the identical table method shown in Table 3.4.

P
N1 2p P
N1 2p 2p 2p
1
N X ½k  lej N kn ¼ N1 X ½kej N kn ej N ln ¼ xN ½nej N nl ð3:59Þ
n¼0 n¼0

Previously stated that the given real sequence requires the conjugated complex
numbers for the positive and negative frequency pair according to the Euler
equation for cosine function.

X ½k ¼ X  ½k or X ½k ¼ X  ½N  k  ð3:60Þ

Example 3.9
Find the number property as complex or real number for following signal’s DFT.
N = 8.

x1 ½n ¼ d½n þ 2d½n  1 þ 3d½n  2 þ 4d½n  3


þ 5d½n  4 þ 4d½n  5 þ 3d½n  6 þ 2d½n  7

x 2 ½ n ¼ x 1 ½ n  2
3.4 Discrete Fourier Transform (DFT) 115

Solution
X
7
x1 ½nej 8 kn
2p
X1 ½k  ¼
n¼0

¼ 1 þ 2ej 8 k þ 3ej 8 k2 þ 4ej 8 k3 þ 5ej 8 k4


2p 2p 2p 2p

þ 4ej 8 k5 þ 3ej 8 k6 þ 2ej 8 k7


2p 2p 2p

¼ 1 þ 2ej 8 k þ 3ej 8 k2 þ 4ej 8 k3 þ 5ej 8 k4


2p 2p 2p 2p

þ 4ej 8 kð83Þ þ 3ej 8 kð82Þ þ 2ej 8 kð81Þ


2p 2p 2p

j2p j2p j2p j2p


¼ 1 þ 2e 8k þ 3e 8 k2 þ 4e 8 k3 þ 5e 8 k4

j2p j2p j2p


þ 4e þ 3e
8 k3 þ 2e 8 k2 8k
 2p   2p 
¼ 1 þ 2 e þ e 8 þ 3 ej 8 k2 þ ej 8 k2
j2p 2p
j8k k

 2p 
þ 4 ej 8 k3 þ ej 8 k3 þ 5ej 8 k4
2p 2p

     
2p 2p 2p
¼ 1 þ 4 cos k þ 6 cos 2k þ 8 cos 3k þ 5ð1Þk 2 R
8 8 8

The X1[k] is real number because x1[n] is symmetric as below.

x 1 ½ n ¼ x 1 ½ 8  n

Note that any even symmetric distribution provides the real number on the other
domain. Using the property of delay, X2[k] is below.

DFT
xN ½n  d  $ X ½k ej N kd
2p

DFT
x2 ½n ¼ x1 ½n  2 $
       
2p 2p 2p
3k þ 5ð1Þk ej 8 k2
2p
X2 ½k ¼ 1 þ 4 cos k þ 6 cos 2k þ 8 cos
8 8 8

The X2[k] is complex number because of ej 8 k2 term which is induced by delay.■
2p

The reversal in time provides the reversal in frequency as well. See Table 3.5.

X
N 1 X
N 1 X
N 1
x½nej N kn ¼ x½N  nej N kn ¼ x½nej N ðNkÞn
2p 2p 2p

n¼0 n¼0 n¼0


ð3:61Þ
P
N1
¼ x½ne N ðk Þn
j2p
¼ X ½k ¼ X ½N  k
n¼0

According to the Parseval’s theorem, the energy in time domain is identical to


the energy in frequency domain.
116

Table 3.5 Time reversal example in time domain for DFT


n 0 1 2 3 4 5 6 7
DFTfx8 ½ng x8 ½n x8 ½0 x8 ½1 x8 ½2 x8 ½3 x8 ½4 x8 ½5 x8 ½6 x8 ½7
2p 2p 2p 2p 2p 2p 2p 2p 2p
ej 8 kn ej 8 k0 ej 8 k1 ej 8 k2 ej 8 k3 ej 8 k4 ej 8 k5 ej 8 k6 ej 8 k7
DFTfx8 ½ng x8 ½n x8 ½0 x8 ½1 x8 ½2 x8 ½3 x8 ½4 x8 ½5 x8 ½6 x8 ½7
x8 ½0 x8 ½7 x8 ½6 x8 ½5 x8 ½4 x8 ½3 x8 ½2 x8 ½1
2p 2p 2p 2p 2p 2p 2p 2p 2p
ej 8 kn ej 8 k0 ej 8 k1 ej 8 k2 ej 8 k3 ej 8 k4 ej 8 k5 ej 8 k6 ej 8 k7
DFTfx8 ½ng x8 ½n x8 ½0 x8 ½1 x8 ½2 x8 ½3 x8 ½4 x8 ½5 x8 ½6 x8 ½7
2p 2p 2p 2p 2p 2p 2p 2p 2p 2p
ej 8 kn ej 8 k8 ej 8 k8 ej 8 k7 ej 8 k6 ej 8 k5 ej 8 k4 ej 8 k3 ej 8 k2 ej 8 k1
j2p
8 ð8k Þn j2p
8 k0
e e
3 Fourier Analysis
3.4 Discrete Fourier Transform (DFT) 117

X
N 1
1XN 1
Ex ¼ jx½nj2 ¼ jX ½kj2
n¼0
N k¼0

Let’s place one example to this theorem.


Example 3.10
Apply the Parseval’s theorem on below example.
 
2p
x½n ¼ cos n for N ¼ 4
4

Solution The time domain energy is below.

X
3
Ex ¼ jx½nj2 ¼ 1 þ 0 þ 1 þ 0 ¼ 2
n¼0

The frequency domain distribution and energy are below

X
3
x½nej 4 kn ¼ 1ej 4 k0 þ 0ej 4 k1  1ej 4 k2 þ 0ej 4 k3
2p 2p 2p 2p 2p
X ½k  ¼
n¼0

¼ 1  ð1Þk ¼ 2d½k  1 þ 2d½k  3

1X 3
1
Ex ¼ jX ½kj2 ¼ ð4 þ 4Þ ¼ 2
4 k¼0 4

Therefore, energy can be computed in either domain for your computational


convenience. ■

3.5 Problems

1. Show that the even and odd function provides the pure real and imaginary
number DTFT, respectively. Use the cosine and sine function without any phase
delay.
2. Prove following relationship. What condition is required for below relationship?

1 Zp  jx  jxn 1 Zp
x ½ n ¼ X e e dx ¼ mðxÞ cosðxn þ hðxÞÞdx 2 R
2p p 2p 0
1 Zp 1 Zp
¼ aðxÞ cosðxnÞdx  bðxÞ sinðxnÞdx
2p 0 2p 0
118 3 Fourier Analysis

3. Compute the DTFT frequency distribution of following signals.


– u[n]
P1
– d½n  kM 
k¼1
– ð1Þn
4. If the given signal x[n] shows the period N = 16 samples. List the all possible
frequencies of X ðejx Þ.
5. The below is the given discrete time signal.

x½n ¼ d½n þ 2 þ 2d½n þ 1 þ 3d½n þ 2d½n  1 þ d½n  2

DTFT
– x½n ! X ðejx Þ
Inverse DTFT
– X ðejx Þ ! x½n
– Apply Parseval’s theorem to compute the energy in both domains.
6. Derive the inverse DTFT of X ðejx Þ given below.

  1 for  p2 \x\ p2
X ejx ¼
0 Otherwise
  1
X e jx
¼ Hint : Geometric series with infinite length
1  0:1ejx

7. The x[n] is obtained by the sampling of xc(t) with sampling period Ts. The DTFT
of x[n] is X ðejx Þ and the FT of xc(t) is Xc ðXÞ. Find the relation between X ðejx Þ
and Xc ðXÞ. Most of the procedures are shown below. Follow the procedures and
explain the relation in last part.
The sampled signal can be represented by following definition.

x½n ¼ xc ðnTs Þ

The continuous time signal xc(t) and its frequency distribution Xc ðXÞ are given
below by using Fourier transform.

FT
xc ðtÞ $ Xc ðXÞ

The sampling process is the multiplication between the continuous signal with
impulse train.

X
1
xs ðtÞ ¼ xc ðtÞsðtÞ where sðtÞ ¼ dðt  nTs Þ
n¼1
3.5 Problems 119

The frequency distribution of impulse train s(t) is known as below based on


Fourier series. As discussed in DFT, the periodic signal only contains the spectrum
with the integer multiple of fundamental frequency which is the inverse of the
period. The impulse train also presents the periodic signal with Ts; therefore, the
spectrum of the train denotes the integer multiple of Xs ð¼ 2pfs ¼ 2p=Ts Þ.

X
1 X
1
FT
sðt Þ ¼ dðt  nTs Þ ¼ Sk ejkXs t $
n¼1 k¼1
X1
2p
SðXÞ ¼ 2p Sk dðX  kXs Þ where Xs ¼
k¼1
Ts

Using Fourier series, find the Sk coefficient as below.

RTs RTs P
1
Sk ¼ T1s sðtÞejkXs t dt ¼ T1s dðt  nTs ÞejkXs t dt
0 0 n¼1
RTs
¼ T1s dðtÞejkXs t dt ¼ T1s
0

The frequency distribution of impulse train is demonstrated as below.

2p X 1
Sð X Þ ¼ dðX  kXs Þ
Ts k¼1

The time domain multiplication is equivalent to the convolution integral in


frequency domain according to the duality.

FT 1
xc ðtÞsðtÞ $ Xc ðXÞ  SðXÞ ¼ Xs ðXÞ
2p

The convolution integral with delta function relocates the spectrum to the delta
function locations as below.

1 X 1
Xs ðXÞ ¼ Xc ðX  kXs Þ
Ts k¼1

Directly perform the Fourier transform on x(t)s(t) as below.

R1 R1 P
1
Xs ðXÞ ¼ xs ðtÞejXt dt ¼ xc ð t Þ dðt  nTs ÞejXt dt
1 1 n¼1
P
1 R1 P
1
¼ xc ðnTs ÞejXnTs dðt  nTs Þdt ¼ xc ðnTs ÞejXnTs
n¼1 1 n¼1
  P
1
¼ X ejXTs ¼ xc ðnTs Þejxn ¼ X ðejx Þ where x ¼ XTs and x½n ¼ xc ðnTs Þ
n¼1
120 3 Fourier Analysis

  1 X 1
)X ejXTs ¼ Xc ðX  kXs Þ
Ts k¼1
 
 jx  1 X 1
x 2p
)X e ¼ Xc k
Ts k¼1 Ts Ts

Complete following drawings based on the above equations.


s(t)

... ...
t
-3Ts -2Ts -Ts 0 Ts 2Ts 3Ts

S( )

Xc( )

- c c

Xs( )

X(ejw)

w
3.5 Problems 121

8. Compute following equation.


P j2pkn
N1
e N ¼
n¼0
9. Find the DFT of following signals.
– x1 ½n ¼ d½n þ d½n  4 for N ¼ 8
– x2 ½n ¼ cosðxn Þ for x 2 R and N 2 N
– x3 ½n ¼ 2 cos 8 n for N ¼ 8
2 2p

10. In general, the given signal is non-periodic. The only numerical computation
for frequency distribution is DFT because of digital frequency k. However, the
DFT is designed for applying on the periodic signal. By using the DFT,
describe the method to find the approximated DTFT distribution for below two
situations. Explain with example. MATLAB code is recommended.
– x[n] with limited length
– x[n] with unlimited length
11. Fill out the below DFT table for x[n−4] with N = 8.

n 0 1 2 3 4 5 6 7
x[n] 1 2 3 4 5 4 3 2
x[n−3]

12. From the Problem 10, derive following.


– X ½k 
– DFTðx½n  4Þ 
– DFT x½n cos 2p 8 3n

13. The given signal is periodic impulse train with 6 sample period. Apply the
Parseval’s theorem.

X
1
x6 ½n ¼ d6 ½n ¼ d½n  6m
m ¼ 1

14. Derive the inverse DFT of X ½k  given below. DFT length is N.


8
< 1 for 0  k  L
X ½k ¼ 1 for N  L  k\L
:
0 Otherwise
Assume that L N
122 3 Fourier Analysis

15. Determine the inverse DFT of following.

DFT
xN ½n $ X ½k
DFT
$ X  ½k 

X
N 1
xN ½nej N kn
2p
X ½k  ¼
n¼0
!
X
N 1 X
N 1 X
N 1
 j2p
xN ½nej N kn ¼ xN ½nej N kðnÞ
2p 2p
X ½k  ¼ xN ½ne N kn ¼
n¼0 n¼0 n¼0
DFT
xN ½n ¼ xN ½N  n $ X ½ k  

References

1. Oppenheim, A.V., Schafer, R.W.: Discrete-time Signal Processing. Prentice Hall (1989)
2. Hazewinkel, M.: Encyclopaedia of Mathematics: Orbit—Rayleigh Equation. Springer,
Netherlands (2012)
Chapter 4
Filters in Time Domain

In the first chapter, we discussed about the filter architecture and its fundamental
theories without using the any frequency analysis. Basically, the filter generates the
output by reducing and amplifying the range of frequencies; therefore, the fre-
quency analysis on the filter is essential part of the filter design. The Chap. 3
provides powerful tools known as Fourier analysis to understand the frequency
information for periodic and aperiodic discrete signal. Now it is time to revisit the
filter computation and extend the time domain understanding to the frequency
domain knowledge. Also, the filter will be further expanded to the recursive filters
that uses the output feedback. The simple various filters such as low pass and high
pass filter will be derived from the window method as well.

4.1 Digital Filter Revisited

The discrete time signal is the real time signal that provides the signal value in
every time interval. Digital filter receives the discrete time signal for modifying the
frequency magnitude and delay for desired output. The filter utilizes the recent
signal samples by weighting and accumulating as below.

P
1
y ½ n ¼ x½kh½n  k ð4:1Þ
k¼1

Equation (4.1) is the convolution sum for discrete time signal. The graphical
explanation is shown in Fig. 4.1.
The signal x½k  is the received signal up to the present time n. The future signal
values at n + 1, n + 2, etc. are shown in Fig. 4.1 but not actually received by the

© Springer Nature Singapore Pte Ltd. 2021 123


K. Kim, Conceptual Digital Signal Processing with MATLAB,
Signals and Communication Technology,
https://doi.org/10.1007/978-981-15-2584-1_4
124 4 Filters in Time Domain

x[k] h[k]
... ... k
... ...

n-2
n-1
012

n
n+1
n+2
h[n-k]
k
n-1
n-2
n

y[n]

... k
n

Fig. 4.1 Graphical explanation of convolution sum

filter system. The filter coefficients h[k] is flipped and shifted to the n position as h
[n-k]. Note that the shift direction for the h[n−k] is reversed due to the time reversal
by –k. The multiplication is performed on the input and coefficients for the cor-
responding location in order to produce the output y[n]. The shape and length of the
filter coefficients decide the filter function such as low, high, and band pass filter.
The output shape follows the profile of the filter coefficients. The filter length
determines the frequency focus in inversely proportional manner. The Chap. 1
provided the intuitive filter design stated above. The following sections investigate
further for analytical filter design.

4.2 Filter Properties with LTI

Section 1.4 showed that the impulse response is the filter coefficient h[n] if the
system meets the linear and time invariant condition. Let’s explore the convolution
sum equation for linearity condition first. The given signal is below.

x½n ¼ ax1 ½n þ bx2 ½n ð4:2Þ

The convolution sum is performed for the output y[n].


4.2 Filter Properties with LTI 125

X
1
y ½ n ¼ x½kh½n  k 
k¼1
X1
¼ fax1 ½k þ bx2 ½kgh½n  k 
k¼1
X1 X
1
¼a x1 ½kh½n  k þ b x2 ½k h½n  k
k¼1 k¼1
ð4:3Þ
¼ ay1 ½n þ by2 ½n

X
1 X
1
where y1 ½n ¼ x1 ½k h½n  k and y2 ½n ¼ x2 ½k h½n  k
k¼1 k¼1

The linearly combined input produces the output that is equivalent to the
identically scaled individual outputs; hence, the convolution sum fulfills the lin-
earity condition. See the next condition time invariance. The delayed signal is
below.

x ½ n ¼ x 1 ½ n  d  ð4:4Þ

The convolution sum is performed for the output y[n].

X
1
y½n ¼ x½k h½n  k
k¼1
X1 X
1
¼ x1 ½k  d h½n  k  ¼ x1 ½mh½n  m  d  ð4:5Þ
k¼1 m þ d¼1
X1
¼ x1 ½mh½ðn  d Þ  m ¼ y1 ½n  d 
m¼1

X
1
where y1 ½n ¼ x1 ½k h½n  k
k¼1

The input of the delayed signal delivers the equally retarded output signal
without modifying output shape. Therefore, the convolution sum satisfies the time
invariance condition. Finally, the LTI is completed for the convolution sum.
Section 2.3 described the discrete time signal with linear combination of scaled and
shifted delta functions as shown in Eq. (4.6).
126 4 Filters in Time Domain

P
1
x ½ n ¼ x½kd½n  k ð4:6Þ
k¼1

The decomposed and combined signal is placed on the input of the convolution
sum as below.

X
1
y ½ n ¼ x½kh½n  k 
k¼1
X1 X
1 X
1 X
1
¼ x½ld½k  lh½n  k ¼ x½l d½k  lh½n  k  ð4:7Þ
k¼1 l¼1 l¼1 k¼1
X1 X
1 X1
¼ x½lh½n  l d½ k  l  ¼ x½lh½n  l
l¼1 k¼1 l¼1

Note that the impulse signal (delta function) provides the impulse response as h
[n]. The shifted impulse generates the equally shifted impulse response as below.

P
1 P
1
h½ n ¼ d½kh½n  k and h½n  l ¼ d½k  lh½n  k ð4:8Þ
k¼1 k¼1

Overall, the convolution sum output is the sum of the shifted and scaled version
of the impulse response according to the input signal x[n].
Example 4.1
From the given impulse response and x[n], compute the filter output y[n].

h½n ¼ d½n  2d½n  1 þ 3d½n  2

x½n ¼ d½n þ d½n  1 þ d½n  2

Solution
Figure 4.2 describes the convolution sum and shift & scaled impulse response for
given x[n] and h[n]. The sum of the –h[n], h[n–1], and h[n–2] are derived from the
input signal x½n ¼ d½n þ d½n  1 þ d½n  2.
4.2 Filter Properties with LTI 127

4 4

2 2

h[n]
x[n]

0 0

-2 -2

-4 -4
0 1 2 3 4 0 1 2 3 4

4 4

2 2

h[n-1]
-h[n]

0 0

-2 -2

-4 -4
0 1 2 3 4 0 1 2 3 4

4 4

2 2
h[n-2]

y[n]

0 0

-2 -2

-4 -4
0 1 2 3 4 0 1 2 3 4

Fig. 4.2 One example of convolution sum. The output y[n] is calculated by shifted and scaled h
[n]s based on the x[n]
128 4 Filters in Time Domain

Prog. 4.1 MATLAB program for Fig. 4.2


hn = [1 -2 3];
xn = [-1 1 1];
y = conv(xn,hn);
y1 = conv(hn,[-1 0 0]);
y2 = conv(hn,[0 1 0]);
y3 = conv(hn,[0 0 1]);
figure,
subplot(321), stem((0:2),xn), grid, xlim([0 4]), ylabel('x[n]'), ylim([-4 4])
subplot(322), stem((0:2),hn), grid, xlim([0 4]), ylabel('h[n]'), ylim([-4 4])
subplot(323), stem((0:4),y1), grid, xlim([0 4]), ylabel('-h[n]'), ylim([-4 4])
subplot(324), stem((0:4),y2), grid, xlim([0 4]), ylabel('h[n-1]'), ylim([-4 4])
subplot(325), stem((0:4),y3), grid, xlim([0 4]), ylabel('h[n-2]'), ylim([-4 4])
subplot(326), stem((0:4),y), grid, xlim([0 4]), ylabel('y[n]'), ylim([-4 4])


The equation for the convolution sum computes the present output y[n] by using
the entire k range as shown in Eq. (4.9). The actual summation takes place only at
the overlapped portion between the input signal and impulse response. Every shift
by n value changes the overlap area for new output.

P
1 P
1
y ½ n ¼ x½kh½n  k  ¼ h½k x½n  k ð4:9Þ
k¼1 k¼1

The x[n] range is assumed to be infinite in the given convolution sum since the
digital filter input is the real time signal. From the past, the data is arrived at the
system in every constant time interval continuously. However, the h[n] range is
finite from zero time to the positive sequence number. See below for Fig. 4.3.
Figure 4.3 shows two impulse responses with identical but shifted profile. The
first h1[k] starts from the zero index to the positive sequence number. The con-
volution sum provides the 3 overlapped sequences initiated from the present n to
the n−2. The second h2[k] starts from the −1 to the positive sequence number that
generates the 3 overlapped sequence initiated from the future n + 1 to the n−1. The
future x[n + 1] is not available to the system now. Unless the system pauses the
one-time sequence, the convolution sum cannot compute the present output y[n].
Mathematical representation for the two cases is given in Eqs. (4.10) and (4.11).

y1 ½n ¼ x½nh1 ½0 þ x½n  1h1 ½1 þ x½n  2h1 ½2


ð4:10Þ
for h1 ½n ¼ h1 ½0d½n þ h1 ½1d½n  1 þ h1 ½2d½n  2
4.2 Filter Properties with LTI 129

present
given data

x[k]
... ... k
... n-2 ...
n-1
n
n+1
n+2
h1[n-k] h1[k]
k
012
n-1
n-2
n

h2[n-k] h2[k]
k
-1 0 1
n+1
n-1
n

Fig. 4.3 Example of convolution sum with two impulse responses

y2 ½n ¼ x½n þ 1h2 ½1 þ x½nh2 ½0 þ x½n  1h2 ½1


ð4:11Þ
for h2 ½n ¼ h2 ½1d½n þ 1 þ h2 ½0d½n þ h2 ½1d½n  1

Observe that y2[n] is derived by the future input x[n + 1]. The real time system
requires the immediacy by delivering the present output y[n] from present and past
input signal. Once the system shows the non-zero h[n] values at negative time
indexes, the system cannot meet the real time condition. The system causality is
determined by the filter coefficient distribution. The causal system should follow the
below condition in Eq. (4.12).

h½ n ¼ 0 for n\0 ð4:12Þ

The non-causal system cannot provide the current output due to the future signal
accessibility. However, the delayed output method realizes the system by waiting to
receive the future data for convolution sum. After initial waiting, the filter con-
tinuously generates the output sequentially.

4.3 FIR and IIR Filters

The length of the impulse response presents significant role in the digital filter
performance as explained in Chap. 1. The filter output follows the impulse response
shape and concentrates on the shape further for longer impulse response. The
convolution sum seems to be the unlimited computation due to the infinite
130 4 Filters in Time Domain

summation range; however, actual computation takes place only at the overlapped
range between the input signal and impulse response. For the causal and N length
response, the convolution sum is given below as Eqs. (4.13) and (4.14).

P
1 P
N1
y ½ n ¼ h½kx½n  k  ¼ h½kx½n  k ð4:13Þ
k¼1 k¼0

n\0
where h½n ¼ 0 for
nN

y½n ¼ h½0x½n þ h½1x½n  1 þ h½2x½n  2 þ . . .


ð4:14Þ
þ h½N  1x½n  ðN  1Þ

The required computation for the N length response is N multiplication and N−1
accumulation for single output. We can enlarge the filter length by increasing the
N number along with increased computational requirement. The filter length is
linearly proportional to the computational load. The filter with limited length
impulse response is known as the finite impulse response (FIR) filter. For further
localization to the specific frequency, can we realize the infinite length filter? By
using the conventional convolution sum, it is impossible since the convolution sum
needs the infinite multiplications and accumulations for current output as below in
Eq. (4.15).

P
N1 n\0
y½n ¼ lim h½kx½n  k  where h½n ¼ 0 for ð4:15Þ
N!1 k¼0 nN

Let’s consider the following structure in Eq. (4.16).

y ½ n  ¼ a1 y ½ n  1  þ b 0 x ½ n  ð4:16Þ

The current output is computed by the present input x½n as well as the previous
output y½n  1. In order to represent the output in terms of input combinations, the
recursive equation is organized as below in Eq. (4.17).
4.3 FIR and IIR Filters 131

y½0 ¼ b0 x½0 let x½n ¼ y½n ¼ 0 for n\0

y½1 ¼ a1 y½0 þ b0 x½1 ¼ a1 b0 x½0 þ b0 x½1

y½2 ¼ a1 y½1 þ b0 x½2 ¼ a21 b0 x½0 þ a1 b0 x½1 þ b0 x½2

y½3 ¼ a1 y½2 þ b0 x½3 ¼ a31 b0 x½0 þ a21 b0 x½1 þ a1 b0 x½2 þ b0 x½3



P
n
y½n ¼ b0 1 x½k 
ank ð4:17Þ
k¼0

The output is the accumulated sum of exponentially weighted pervious inputs.


Before we derive the impulse response, let’s figure out the LTI compliance. The
linearity first as below.
x½n ¼ ax1 ½n þ bx2 ½n

X
n X
n
y½n ¼ b0 1 x ½ k  ¼ b0
ank 1 fax1 ½k  þ bx2 ½k g
ank
k¼0 k¼0
ð4:18Þ
Xn X
n
¼ ab0 1 x1 ½k  þ bb0
ank 1 x2 ½k 
ank ¼ ay1 ½n þ by2 ½n
k¼0 k¼0

The recursive filter successfully meets the linearity condition. The


time-invariance is next with time shifted input x½n  d .
X
n X
n
b0 1 x½ k  d  ¼ b0
ank 1 x½m ¼ 
ank
k¼0 k¼0

let m ¼ k  d and x½n ¼ 0 for n\0

P
n P
nd
ðnd Þm
 ¼ b0 anmd
1 x½m ¼ b0 a1 x½m ¼ y½n  d  ð4:19Þ
m þ d¼0 m¼0

Therefore, the time shifted input provides the relocated output with equal
amount of time delay. The given recursive filter safely satisfies the LTI condition.
Based on the LTI, we can figure out the impulse response by applying the impulse
signal to the input as below in Eqs. (4.20) and (4.21).
132 4 Filters in Time Domain

P
n
h½ n ¼ b0 1 d½ k  ¼ b0 a1
ank n
for n  0 ð4:20Þ
k¼0
 
h½n ¼ b0 d½n þ a1 d½n  1 þ a21 d½n  2 þ a31 d½n  3 þ . . . ð4:21Þ

The impulse response is the exponential function with infinite length. Depending
on the base value a1, the impulse response can be increased or decreased in
exponential fashion.
Example 4.2
Find the impulse response h[n] of following difference equations.

y1 ½n ¼ 0:75y1 ½n  1 þ x½n

y2 ½n ¼ 1:25y2 ½n  1 þ x½n

Solution
0.75 a1 less than the magnitude one represents the decreasing exponential. In
contrast, the above one magnitude 1.25 illustrates the increasing profile in Fig. 4.4.

y[n]=a 1y[n-1]+b0x[n] for a 1=0.75 b 0=1


1
h[n]

0.5

0
0 2 4 6 8 10 12 14 16 18 20

y[n]=a 1y[n-1]+b0x[n] for a 1=1.25 b 0=1


100
h[n]

50

0
0 2 4 6 8 10 12 14 16 18 20
n

Fig. 4.4 Impulse response of recursive filter with two different a1 values
4.3 FIR and IIR Filters 133

h1 ½n ¼ 0:75n for n  0

h1 ½n ¼ d½n þ 0:75d½n  1 þ 0:752 d½n  2 þ 0:753 d½n  3 þ . . .

h2 ½n ¼ 1:25n for n  0

h1 ½n ¼ d½n þ 1:25d½n  1 þ 1:252 d½n  2 þ 1:253 d½n  3 þ . . .

Prog. 4.2 MATLAB program for Fig. 4.4

a1 = 3/4;
a2 = 5/4;
b0 = 1;
n = 0:20;
y1 = b0*(a1.^n);
y2 = b0*(a2.^n);
figure;
subplot(211),stem(n,y1), grid
ylabel('h[n]');
tle('y[n]=a_1y[n-1]+b_0x[n] for a_1=0.75 b_0=1')
box off
subplot(212),stem(n,y2), grid
xlabel('n');
ylabel('h[n]');
tle('y[n]=a_1y[n-1]+b_0x[n] for a_1=1.25 b_0=1')
box off

The recursive filter effectively denotes the infinite length impulse response. The
convolution sum with finite length impulse response is known as the finite impulse
response (FIR) filter. The infinite impulse response (IIR) filter delivers the infinite
length impulse response with recursive discrete equation. Does the further recursive
filter also provide the exponential impulse response? Let’s investigate second order
recursive filter in below equations.
134 4 Filters in Time Domain

y½n ¼ ða1 þ a2 Þy½n  1  a1 a2 y½n  2 þ ða1  a2 Þx½n

y½0 ¼ ða1  a2 Þx½0 let x½n ¼ y½n ¼ 0 for n\0

y½1 ¼ ða1 þ a2 Þy½0 þ ða1  a2 Þx½1


¼ ða1 þ a2 Þða1  a2 Þx½0 þ ða1  a2 Þx½1
 
¼ a21  a22 x½0 þ ða1  a2 Þx½1

y½2 ¼ ða1 þ a2 Þy½1  a1 a2 y½0 þ ða1  a2 Þx½2


 
¼ ða1 þ a2 Þ a21  a22 x½0 þ ða1 þ a2 Þða1  a2 Þx½1
 a1 a2 ða1  a2 Þx½0 þ ða1  a2 Þx½2
   
¼ a31  a32 x½0 þ a21  a22 x½1 þ ða1  a2 Þx½2

y½3 ¼ ða1 þ a2 Þy½2  a1 a2 y½1 þ ða1  a2 Þx½3


   
¼ ða1 þ a2 Þ a31  a32 x½0 þ ða1 þ a2 Þ a21  a22 x½1
 
þ ða1 þ a2 Þða1  a2 Þx½2  a1 a2 a21  a22 x½0
 a1 a2 ða1  a2 Þx½1 þ ða1  a2 Þx½3
   
¼ a41  a42 x½0 þ a31  a32 x½1 þ ða21  a22 Þx½2 þ ða1  a2 Þx½3


n 
P 
ðn þ 1Þk ðn þ 1Þk
y ½ n ¼ a1  a2 x½ k  ð4:22Þ
k¼0

Due to the complexity, the second order recursive filter is exemplified with
specific coefficients; however, this case as well as the general cases show the
exponential relation between input and output. For conventional IIR filter shown in
Eq. (4.23), there are significant limitation to solve the recursive filter by substitution
method. The general solution for the IIR filter can be found on Chap. 5 by using the
Z-transform. The z domain provides the simple representation of exponential
solution with complex numbers. Also, the graphical interpretation of the z domain
generates the fast insight on the filter characteristics.

y½n ¼ a1 y½n  1 þ a2 y½n  2 þ a3 y½n  3 þ . . .


ð4:23Þ
þ b0 x ½ n þ b1 x ½ n  1 þ b2 x ½ n  2 þ . . .

Now, it is time to consider the filter stability. The FIR filter weights the recent
N samples of the x[n] based on the impulse response h[n] to compute the current
output y[n]. If the input x[n] values are bounded; in other words, the incoming
signal values are not infinite, the real value impulse response always generates the
bounded output. The stable filter always provides the bounded output from the
bounded input. This type of stability is known as bounded input and bounded
4.3 FIR and IIR Filters 135

Fig. 4.5 Filter length present


comparison for FIR and IIR
FIR filter length
filter
x[k]
... ... k
... ...

n-2
n-1
n
n+1
n+2
IIR filter length

... ... ...


x[k]
k
... ...

n-2
n-1
n
n+1
n+2
output (BIBO) stability. According to the limited length impulse response, FIR
filter satisfies the BIBO stability.
The IIR filter is characterized by the infinite length impulse response that con-
siders the unlimited length of the previous input signal values as shown in Fig. 4.5.
The sum of vast products between the input value and impulse response may lead to
the infinite output value even for the bounded signal. Let’s find the BIBO stability
condition for the IIR filter. The infinite length impulse response and its convolution
sum is given as Eq. (4.24).

X
N 1
y½n ¼ lim h½k x½n  k ¼ 
N!1
k¼0

where h½n ¼ 0 for n\0 and jx½nj  M\18n



X
N 1 X
N 1

  lim h½kx½n  k  lim jh½k jjx½n  k j
N!1 k¼0 N!1 k¼0

P
N1
 lim jh½kjM\1 ð4:24Þ
N!1 k¼0

Since the input is bounded up to M, the bounded output condition is derived


below.

P
1
jh½kj\1 ð4:25Þ
k¼0

If the impulse response of the IIR filter is absolute summable, the IIR filter meets
the BIBO stability condition. For general order IIR filters, the direct computation of
the impulse response and BIBO stability is not feasible in time domain. Further
managements of the IIR filter can be easily seen by Z-transform in the next chapter.
136 4 Filters in Time Domain
Example 4.3
Determine the BIBO stability of following IIR filters.

y1 ½n ¼ 0:75y1 ½n  1 þ x½n

y2 ½n ¼ 1:25y2 ½n  1 þ x½n

Solution
From the Example 4.2, we derived the below impulse responses.

h1 ½n ¼ 0:75n for n  0

h2 ½n ¼ 1:25n for n  0

X
1 X
1
1
jh1 ½k j ¼ j0:75n j ¼ ¼ 4\1
k¼0 k¼0
1  0:75

X
1 X
1
j h2 ½ k  j ¼ j1:25n j ¼ 1 * jr j [ 1 in geometric series
k¼0 k¼0

Hence, the filter for y1[n] is BIBO stable and the filter for y2[n] is not BIBO
stable.

4.4 Frequency Response

Chapter 3 provides the frequency analysis tools for periodic and aperiodic signal.
The Fourier analysis transforms the signals between the time and frequency domain
in order to investigate the spectral distribution of the given signal. The Fourier
equations are given below again in Table 4.1.
We can see the frequency profile of the given raw signal and generate the signal
with specific frequency combination. Therefore, the input and output of the filter
can be individually transformed to the frequency domain for performance

Table 4.1 Fourier transforms for discrete time signal


Discrete-time Fourier transform (DTFT) Discrete Fourier transform (DFT)
Analysis P
1 Analysis P
N1
X ðejx Þ ¼ x½nejxn X ½k  ¼ xN ½nej N kn
2p

n¼1 n¼0
Synthesis Rp Synthesis P
N1
x½n ¼ 2p X ðejx Þejxn dx
2p
1
xN ½n ¼ N1 X ½kej N kn
p k¼0
4.4 Frequency Response 137

verification. What operation is equivalent to the convolution sum in frequency


domain? Let’s see below for DTFT.

  X
1 X
1 X
1
Y ejx ¼ y½nejxn ¼ h½k x½n  kejxn
n¼1 n¼1 k¼1
X1 X
1 X
1  
¼ h½ k  x½n  kejxn ¼ h½kX ejx ejxk ð4:26Þ
k¼1 n¼1 k¼1
  X
1    
¼ X ejx h½kejxk ¼ X ejx H ejx
k¼1

The convolution sum in the time domain is represented by the simple multi-
plication in frequency domain. Due to the multiplication property, the introduced
frequency components by input can be reduced or emphasized its magnitude by the
frequency response H ðejx Þ that is the DTFT of impulse response. However, the
filter cannot create arbitrary frequencies from nothing which is equal to zero in
magnitude. Therefore, periodic signal input delivers the identical combination of
the frequency components in filter output. The DFT expects to have the same
relation for the convolution sum. See equations in below.

X
N 1 N 1 X
X 1
y½nej N kn ¼ h½lx½n  lej N kn
2p 2p
Y ½k  ¼
n¼0 n¼0 l¼1
X
1 X
N1 X
1
x½n  lej N kn ¼ h½lX ½kej N kl ð4:27Þ
2p 2p
¼ h½ l 
l¼1 n¼0 l¼1
X
1
h½lej N kl ¼ X ½kH ½k
2p
¼ X ½k 
l¼1

According to the relation in Eq. (4.27), some of the frequency components from
the input could be removed by weighting from frequency response H ½k  which is
the DFT of impulse response. Otherwise, the filter passes to the output frequencies
with modified magnitude. The frequency response shape decides the filter func-
tionality and performance. Chapter 1 described that the filter output follows the
impulse response shape; in other words, the frequency response of the filter is
applied over the input spectrum to imitate the shape in time as well as frequency
domain.
The DTFT performs the analysis over the whole range for aperiodic signal and
the spectrum is represented by the continuous variable x. Hence, the DTFT length
does not matter. You execute the DTFT over the x[n] and h[n] to obtain the X ðejx Þ
and H ðejx Þ, respectively. Then, performs the multiplication for convolution sum
counterpart in frequency domain and finally develops the convolution sum result by
applying the synthesis equation on the multiplication output.
138 4 Filters in Time Domain

DTFT Analysis
x½n

! X ðejx Þ Mul: DTFT Synthesis



! X ðejx ÞH ðejx Þ

! x½n  h½n ð4:28Þ


h½n

! H ðejx Þ
DTFT Analysis

Let’s do one example as below.


Example 4.4
Compute the filter output of below configuration with DTFT method.

1 for 0n2
x ½ n ¼ h½ n ¼
0 Otherwise

Solution

    X
1
X ejx ¼ H ejx ¼ x½nejxn ¼ 1 þ ejx þ ejx2
n¼1
      
X ejx H ejx ¼ 1 þ ejx þ ejx2 1 þ ejx þ ejx2
¼ 1 þ 2ejx þ 3ejx2 þ 2ejx3 þ ejx4

1 Zp  jx   jx  jxn
X e H e e dx
2p p
1 Zp  
¼ 1 þ 2ejx þ 3ejx2 þ 2ejx3 þ ejx4 ejxn dx
2p p
¼ d½n þ 2d½n  1 þ 3d½n  2 þ 2d½n  3 þ d½n  4 ¼ x½n  h½n


As shown above, the user did not decide the length of the DTFT for the proper
convolution sum. The DTFT convolution sum result shows the same outcome from
conventional convolution sum process. However, due to continuous variable x, the
general computer cannot process the DTFT computation without using the sym-
bolic mathematics. The DFT is more popular because of the discrete frequency.
The DFT also follows the identical process to compute the convolution sum in
frequency domain as below in Eq. (4.29).

DFT Analysis
x½n

! X ½k Mul: DFT Synthesis


! X ½kH ½k 

! x½n  h½n ð4:29Þ


h½n

! H ½k 
DFT Analysis

Let’s see the DFT convolution sum.


4.4 Frequency Response 139

Example 4.5
Compute the filter output of below configuration with DFT method in length 4 and 5.

1 for 0n2
x ½ n ¼ h½ n ¼
0 Otherwise

Solution
For N = 4,

X
3
x½nej 4 kn ¼ 1 þ ej 4 k þ ej 4 k2
2p 2p 2p
X ½k  ¼ H½k ¼
n¼0
  
X ½k H½k ¼ 1 þ ej 4 k þ ej 4 k2 1 þ ej 4 k þ ej 4 k2
2p 2p 2p 2p

¼ 1 þ 2ej 4 k þ 3ej 4 k2 þ 2ej 4 k3 þ ej 4 k4


2p 2p 2p 2p

¼ 2 þ 2ej 4 k þ 3ej 4 k2 þ 2ej 4 k3 since ej 4 k4 ¼ 1


2p 2p 2p 2p

3   2p
1X 3
1X
2 þ 2ej 4 k þ 3ej 4 k2 þ 2ej 4 k3 ej 4 kn
2p 2p 2p 2p
X ½k H ½k ej 4 kn ¼
4 k¼0 4 k¼0
¼ 2d½n þ 2d½n  1 þ 3d½n  2 þ 2d½n  3 6¼ x½n  h½n

The DFT convolution sum with N = 4 does not match with the convolution sum
result due to the improper length. The circular property of the DFT wraps the last
element ej2pk4=4 to the first location ej0 . To avoid this problem, increase the length
of the DFT for 5 as below.
For N = 5,

X
4
x½nej 5 kn ¼ 1 þ ej 5 k þ ej 5 k2
2p 2p 2p
X ½k  ¼ H½k ¼
n¼0
  
X ½k H½k ¼ 1 þ ej 5 k þ ej 5 k2 1 þ ej 5 k þ ej 5 k2
2p 2p 2p 2p

¼ 1 þ 2ej 5 k þ 3ej 5 k2 þ 2ej 5 k3 þ ej 5 k4


2p 2p 2p 2p

1X 4
2p
X ½kH ½kej 5 kn
5 k¼0
4   2p
1X
1 þ 2ej 5 k þ 3ej 5 k2 þ 2ej 5 k3 þ ej 5 k4 ej 5 kn
2p 2p 2p 2p
¼
5 k¼0
¼ d½n þ 2d½n  1 þ 3d½n  2 þ 2d½n  3 þ d½n  4 ¼ x½n  h½n


140 4 Filters in Time Domain

For the given sequences with l and m length, the convolution sum provides the
outcome with l + m–1 length. Therefore, the DFT length must cover the convo-
lution sum length as below in Eq. (4.30).

DFT Analysis  l þ m1 length


x½n : l length

! X ½k
Must have equal lengths for DFT processing Multiplication

! X ½kH ½k
h½n : m length

! H ½k  ð4:30Þ
DFT Analysis  l þ m1 length

DFT Synthesis  l þ m1 length


! x½n  h½n

With equal or bigger than to the convolution sum length, DFT processing
guarantees the identical convolution sum result over simple multiplication in fre-
quency domain. Therefore, DFT length must be chosen with data length consid-
eration. Otherwise, the above the length elements are penetrates into the first results
in circular manner known as circular convolution sum that will be explained in
Chap. 6. Another example of improper DFT length in below shows the circular
manner.
Example 4.6
Compute the filter output of below configuration with DFT method in length 3.

1 for 0n2
x ½ n ¼ h½ n ¼
0 Otherwise

Solution
For N = 3,

X
2
x½nej 3 kn ¼ 1 þ ej 3 k þ ej 3 k2
2p 2p 2p
X ½k  ¼ H½k ¼
n¼0
  
X ½kH½k ¼ 1 þ ej 3 k þ ej 3 k2 1 þ ej 3 k þ ej 3 k2
2p 2p 2p 2p

¼ 1 þ ej 3 k þ ej 3 k2 þ ej 3 k þ ej 3 k2 þ ej 3 k3


2p 2p 2p 2p 2p

þ ej 3 k2 þ ej 3 k3 þ ej 3 k4


2p 2p 2p

¼ 1 þ 2ej 3 k þ 3ej 3 k2 þ 2ej 3 k3 þ ej 3 k4


2p 2p 2p 2p

   
¼ 1 þ 2ej 3 k3 þ 2ej 3 k þ ej 3 k4 þ 3ej 3 k2
2p 2p 2p 2p

¼ 3 þ 3ej 3 k þ 3ej 3 k2
2p 2p

since ej 3 k3 ¼ 1 and ej 3 k4 ¼ ej 3 k


2p 2p 2p
4.4 Frequency Response 141

2   2p
1X 2
1X
3 þ 3ej 3 k þ 3ej 3 k2 ej 3 kn
2p 2p 2p
X ½kH ½k ej 3 kn ¼
3 k¼0 3 k¼0
¼ 3d½n þ 3d½n  1 þ 3d½n  2 6¼ x½n  h½n


Now we understand that the convolution sum in time domain can be represented
by the multiplication in the frequency domain. The DTFT or DFT of the impulse
response illustrates the filter frequency response which demonstrates the func-
tionality and performance of the filter. Also, the discrete processing with DFT
should choose the length with caution in order to avoid the wrap around in circular
manner on convolution sum processing over the DFT multiplication.
The time and frequency domain show the mutuality between domains in relation
and function. Usually the function relationship is retained in one direction and vice
versa known as duality. The convolution sum to multiplication expects to be
conserved as multiplication to convolution sum between domains. Let’s see the
multiplication in time domain based on the DTFT as below in Eq. (4.31).

X
1 X
1 Zp
jxn 1  
x½nh½ne ¼ x½n H eju ejun duejxn
n¼1 n¼1
2p
p
Zp Zp
1   X
1
jðxuÞn 1    
¼ H e ju
x½ne du ¼ H eju X ejðxuÞ du
2p n¼1
2p
p p

DTFT 1  jx   
x½nh½n $ X e  H ejx ð4:31Þ
2p

The multiplication in time domain is equivalent to the convolution integral in fre-


quency domain with scale. The identical situation can be observed in DFT as below.

X
N1 X
N1
1XN1
x½nh½nej N kn ¼ H ½lej N ln ej N kn
2p 2p 2p
x ½ n
n¼0 n¼0
N l¼0
1XN 1 X
N 1
1XN 1
x½nej N ðklÞn H ½l ¼
2p
¼ X ½k  lH ½l
N l¼0 n¼0 N l¼0

x½nh½n $
DFT 1
X ½k  H ½k  ð4:32Þ
N

The convolution sum and multiplication are the pair of the operation in duality
for time and frequency domain. One domain with the convolution sum (or integral)
corresponds to the multiplication in the other domain.
142 4 Filters in Time Domain

4.5 Simple Filter Design

Beside the intuitive filter design at Chap. 1, it is time to build the filter with
mathematical fundamentals. In previous chapters, we investigated the discrete
signal, convolution sum, frequency, transformations etc. those are the structural
materials to develop the systematical filters. Instead of using trial and error method,
the designated passing and blocking frequencies are specified in design phase to
derive the impulse response of the convolution sum filter. The method utilizes the
simple Fourier transformations and its properties to design the filter. Further
sophisticate filters can be found in Chap. 5 after the Z-transformation. Recommend
using the filter design tools such as MATLAB since the tool provides much opti-
mized results in terms of performance and computation. Otherwise the introducing
method is effective and simple to understand and realize the filter from scratch.
– Simple low pass filter first
The low pass filter (LPF) well passes the low frequency components than high
frequency section divided by the one threshold frequency value. There are multiple
parameters to specify the LPF properties in detail. For the time being, let’s consider
the LPF with single frequency value that indicates pass band upper limit. Above the
fc value, the LPF tries to block the frequency component by convolution sum
process. Figure 4.6 shows the ideal frequency response of the LPF.
We can choose the frequency domain variable in either set as continuous
(DTFT) or discrete (DFT) that is the initial point of the filter design. Let’s begin
with DTFT.
Example 4.7
Design the LPF for Table 4.2 which is the summary of the filter specifications. Use
the DTFT method. Show the impulse response from –20 to 20 as n.
Solution
The given frequency information should be changed to the discrete frequency x
based on the sampling frequency fs. The sampling frequency corresponds to the 2p;
therefore, the below equation computes the cutoff discrete frequency as p=4.

Fig. 4.6 Ideal low pass filter 1


response
f
-fc 0 fc

Table 4.2 Low pass filter Filter specifications Value


specification for the example
Filter type Low pass filter
Filter length Finite with optimization
Cutoff frequency (fc) 1000 Hz
Sampling frequency (fs) 8000 Hz
4.5 Simple Filter Design 143

Fig. 4.7 Ideal low pass filter 1


response in discrete frequency
ω
- /4 0 /4

2p
xc ¼ fc
fs

The frequency response in discrete frequency domain x is shown in Fig. 4.7.


Using the synthesis equation of DTFT, derive the impulse response as below.

1 Zp  jx  jxn
p
1 Z4 jxn
h½ n ¼ H e e dx ¼ 1e dx
2p p 2p p
4
p
1 ejxn 4 1 p p
¼ ¼ ðej4n  ej4n Þ
2p jn p 2pjn
4
 
1 jp4n jp4n sin pn
¼ ðe  e Þ ¼ 4
2pjn pn
   
sin pn sin pn 1
lim 4
¼ 0 and lim 4
¼
n!1 pn n!0 pn 4

The impulse response shows the infinite length sequence with asymptotes on
x axis toward positive and negative infinite. Also, there is one singular point in the
impulse response at zero n value and the corresponding outcome is computed by the
L’Hôpital’s rule [1] as shown in above equations. The impulse response for the
41-length sequence is illustrated in Fig. 4.8.

Note that the derived impulse response is the infinite length sequence; therefore,
we cannot employ the result directly due to the infinite computation at convolution
sum. The proper length should be decided to represent the specified LPF frequency
profile. The Parseval’s theorem [2] describes the equivalence energy relationship
between the time and frequency domain as below.

P
1 Rp 2
jh½nj2 ¼ 2p
1
jH ðejx Þj dx ð4:33Þ
n¼1 p

The energy in frequency domain is below.


144 4 Filters in Time Domain

0.25

0.2

0.15

0.1
h[n]

0.05

-0.05

-0.1
-20 -15 -10 -5 0 5 10 15 20
n

Fig. 4.8 Impulse response of the ideal low pass filter

p
Zp Z4
1  jx  2 p=2 1
H e dx ¼ 1 12 dx ¼ ¼ ð4:34Þ
2p 2p 2p 4
p p4

Therefore, the time domain energy should be identical to the value 1=4.

1 sin pn 2
P ð 4 Þ ¼ 1 ð4:35Þ
pn 4
n¼1

The energy ratio between the time and frequency domain can be numerically
computed by below equation.

Pl pn 2
sinð 4 Þ
100
n¼l
pn ð4:36Þ
0:25 ½%

As we increase the impulse response length symmetrically, the time domain is


close to the LPF distribution. The figure below depicts the energy ratio defined by
Eq. (4.36). The 15 and 83 sample length define the 95 and 99% of energy to the
frequency domain, respectively; hence, 83-length impulse response accurately
represents the specified LPF property further than the 15-sample counterpart.
4.5 Simple Filter Design 145

Prog. 4.3 MATLAB program for Figs. 4.8 and 4.9


syms n w;
nn = (-50:1:50);
f1 = exp(j*w*n);
f2 = int(f1,w,-pi/4,pi/4)/(2*pi); % Perform IDTFT for h[n]
f3 = simplify(f2);
f4 = subs(f3,n,nn+eps); % Replace symbol n with real number nn
hn = eval(f4); % Evaluate
eee = [0.25^2];
engy = 0;
for kk=0:49
engy = sum(hn(52:52+kk).^2)*2+0.25^2;
eee = [eee engy];
end
temp1 = length(eee);
inx1 = 1:temp1;
inx2 = inx1*2-1;

figure,
stem(nn,hn), grid
xlabel('n')
ylabel('h[n]')
xlim([-20 20])
figure,
stem(inx2,eee*100/0.25,':o'), grid
xlim([1 101]);
ylim([50 103]);
xlabel('h[n] length in samples');
ylabel('Energy rao between me and frequency domain [%]')

Each of the frequency distribution can be drawn by the DTFT analysis equation as
Eq. (4.37). The corresponding frequency response magnitude is illustrated in Fig. 4.10.
 
  X
1 7X
or 41
sin pn
jxn
H e jx
¼ h½ne ¼ 4
ejxn
n¼1 n¼7 or 41
pn
7X
pn
or 41
sin 4  jxn 
¼ h½ 0 þ e þ ejxn ð4:37Þ
n¼1
pn
7X
 
or 41
sin pn
¼ h½ 0 þ 2 4
cosðxnÞ
n¼1
pn
146 4 Filters in Time Domain

Energy ratio between time and frequency domain [%]


100
X: 83
95 X: 41
Y: 99.01
X: 15 Y: 97.98
90 Y: 95

85

80

75

70

65

60

55

50
10 20 30 40 50 60 70 80 90 100
h[n] length in samples

Fig. 4.9 Energy ratio between time and frequency domain for truncated LPF response

Fig. 4.10 Frequency response for 15- and 83-length LPF h[n]
4.5 Simple Filter Design 147

Prog. 4.4 MATLAB program for Fig. 4.10


syms w;

n1 = (-7:1:7);
n2 = (-41:1:41);
a1 = (sin(pi*(n1+eps)/4))./(pi*(n1+eps));
a2 = (sin(pi*(n2+eps)/4))./(pi*(n2+eps));
hw1 = sum(a1.*exp(-1i*w*n1));
hw2 = sum(a2.*exp(-1i*w*n2));
w1 = (-pi:pi/100:pi);
ohw1 = eval(subs(hw1,w,w1));
ohw2 = eval(subs(hw2,w,w1));

figure,
subplot(211), plot(w1,abs(ohw1)), grid, axis ght
ax1 = gca;
ax1.XTick = [-pi -3*pi/4 -pi/2 -pi/4 0 pi/4 pi/2 3*pi/4 pi];
ax1.XTickLabel = {'-\pi', '-3\pi/4', '-\pi/2', '-\pi/4', '0', '\pi/4', '\pi/2', '3\pi/4',
'\pi'};
subplot(212), plot(w1,abs(ohw2)), grid, axis ght
ax2 = gca;
ax2.XTick = [-pi -3*pi/4 -pi/2 -pi/4 0 pi/4 pi/2 3*pi/4 pi];
ax2.XTickLabel = {'-\pi', '-3\pi/4', '-\pi/2', '-\pi/4', '0', '\pi/4', '\pi/2', '3\pi/4',
'\pi'};

As we expected, the 83-length impulse response accurately follows the given


LPF specification. We choose the middle length 41 for the designated impulse
response shown in Fig. 4.11 with frequency response as well. Certain overshoots
on the edges and sidelobes are observed in the frequency domain and those glitches
are intrinsic problem that is the inversely proportional to the impulse response
length. Tradeoff should be exercised in terms of numerous factors such as com-
putation, memory, accuracy etc.
148 4 Filters in Time Domain

Fig. 4.11 41-length impulse response for given LPF and corresponding frequency response

Prog. 4.5 MATLAB program for Fig. 4.11

syms w;
n = (-20:1:20);
hn = sin(pi*(n+eps)/4)./(pi*(n+eps));
hw1 = sum(hn.*exp(-1i*w*n));
w1 = (-pi:pi/100:pi);
ohw1 = eval(subs(hw1,w,w1));
figure,
subplot(211), stem(n,hn), grid
xlabel('n')
ylabel('h[n]')
tle('41 length h[n]')
subplot(212), plot(w1,abs(ohw1)), grid, axis ght
ax2 = gca;
ax2.XTick = [-pi -3*pi/4 -pi/2 -pi/4 0 pi/4 pi/2 3*pi/4 pi];
ax2.XTickLabel = {'-\pi', '-3\pi/4', '-\pi/2', '-\pi/4', '0', '\pi/4', '\pi/2', '3\pi/4',
'\pi'};
tle('Frequency response of 41 length h[n] (98%)');
xlabel('Digital frequency (\omega)')
ylabel('|H(e^{j\omega})|')
4.5 Simple Filter Design 149

This is not the final design since we still have problem with the designed impulse
response. Note that the impulse response at negative index refers the future value of
the input signal x[n]. The given impulse response cannot be realized properly
because of the accessibility and causality until the filter obtains the future signals.
Equation (4.38) convolution sum shows that x[n + 20], x[n + 19],… and x[n + 1]
are the future value of x[n] at the time of n.

X
20
y ½ n ¼ h½kx½n  k ¼ h½20x½n þ 20 þ h½19x½n þ 19 þ . . .
k¼20
ð4:38Þ
þ h½0x½n þ h½1x½n  1 þ . . . þ h½20x½n  20

The solution to this problem is simple. Shift the impulse response to the right
until all h[n] values are located at the right-hand side of the plot; therefore, the
impulse response is started and placed from the zero n value and higher. As shown
in Eq. (4.39), the shift in time domain derives the phase distortion without modi-
fying the magnitude in frequency domain. We specify the frequency response in
magnitude; hence, the shifted impulse response also follows the designed
requirement in Table 4.2.

DTFT Analysis P 1
h½n  d 

! h½n  d ejxn
 n¼1
ð4:39Þ
Magnitude : jH ðejx Þj
¼ H ðejx Þejxd ¼
Phase : \H ðejx Þ  xd

The final design of the LPF is the hLPF ½n, 20 samples delayed version of the
h½n, and denoted below with frequency response in magnitude.

hLPF ½n ¼ h½n  20 ð4:40Þ


150 4 Filters in Time Domain

Prog. 4.6 MATLAB program for Fig. 4.12


syms w;
n = (-20:1:20);
hn = sin(pi*(n+eps)/4)./(pi*(n+eps));
hw1 = sum(hn.*exp(-1i*w*n));
w1 = (-pi:pi/100:pi);
ohw1 = eval(subs(hw1,w,w1));
figure,
subplot(211), stem((0:40),hn), grid
xlabel('n')
ylabel('h_{LPF}[n]')
tle('LPF')
subplot(212), plot(w1,abs(ohw1)), grid, axis ght
ax2 = gca;
ax2.XTick = [-pi -3*pi/4 -pi/2 -pi/4 0 pi/4 pi/2 3*pi/4 pi];
ax2.XTickLabel = {'-\pi', '-3\pi/4', '-\pi/2', '-\pi/4', '0', '\pi/4', '\pi/2', '3\pi/4',
'\pi'};
xlabel('\omega')
ylabel('|H_{LPF}(e^{j\omega})|')

The shifted impulse response retards the output signal with identical amount of
delay as well. The signal shift is represented by the phase in the frequency domain.
The phase modification of the impulse response provides the output relocation via
the convolution sum process. Equation (4.41) shows the 20 sample in impulse
response delay creates the 20-sample output shift to the right. Therefore, the output
is delay 20 samples by impulse response shift. The hLPF ½n is final design for the
LPF.

X
40 X
40
yLPF ½n ¼ hLPF ½kx½n  k  ¼ h½k  20x½n  k
k¼0 k¼0
ð4:41Þ
X
20
¼ h½mx½ðn  20Þ  m ¼ y½n  20
m¼20

Example 4.8
Design the LPF for Table 4.2. Use the DFT method. Show the impulse response
from 0 to 99 as n.
4.5 Simple Filter Design 151

LPF
0.3

0.2
h LPF [n]

0.1

-0.1
0 5 10 15 20 25 30 35 40
n

0.8
|HLPF (ej )|

0.6

0.4

0.2

- -3 /4 - /2 - /4 0 /4 /2 3 /4

Fig. 4.12 Final impulse response for given LPF and corresponding frequency response

Solution
DFT provides the discrete frequency domain based on the k. The method starts from
the DFT frequency domain; hence, we must define the DFT length first for expo-
nential and summation part. Based on the example statement, the DFT length is 100
for N. From the given LPF specification, the equivalent frequency for the given
k can be computed by below equation.
2p fs fs
fk ¼ k ¼ k ¼ Df k
N 2p N

The Df is the frequency resolution for the DFT configuration and defined as
fs =N. The derived Df is 80 Hz/sample from 100 N and 8000 Hz sampling fre-
quency. In order to pass the low frequencies until 1000 Hz, the magnitude one
should cover up to 12 k value because the 1000/(8000/100) is equal to the 12.5.
Note that the real signal requires the conjugated pair on the symmetrical location for
the positive and negative k index as shown in below equation and Fig. 4.13.
According to the cylindrical and periodical property of DFT, the frequency
response for the negative k can be relocated at the other end of given DFT con-
figuration as shown in Fig. 4.13.

H ½k  ¼ H  ½N  k 
152 4 Filters in Time Domain

1
X: -12 X: 12
Y: 1 Y: 1
H[k]

0.5

0
-50 -40 -30 -20 -10 0 10 20 30 40 50
k

1
X: 12 X: 88 X: 99
Y: 1 Y: 1 Y: 1
H[k]

0.5

0
0 10 20 30 40 50 60 70 80 90 100
k

Fig. 4.13 Frequency specification for LPF given by Table 4.2 using DFT

Prog. 4.7 MATLAB program for Fig. 4.13

n1 = 0:99;
n2 = -49:1:50;
hk1 = [ones(1,13) zeros(1,100-12-13) ones(1,12)];
hk2 = [zeros(1,37) ones(1,25) zeros(1,38)];
figure,
subplot(211),stem(n2,hk2), grid
xlim([-50 50]);
ylim([0 1.2]);
xlabel('k');
ylabel('H[k]')
subplot(212),stem(n1,hk1), grid
xlim([0 100]);
ylim([0 1.2]);
xlabel('k');
ylabel('H[k]')
4.5 Simple Filter Design 153

You can take either DFT configurations as −49 * 50 or 0 * 99 for k range in


LPF design. Based on the −49 * 50 k range, the DFT synthesis for the LPF
impulse response can be written as below.

1 X 1 ej10012n  ej10013n
12 2p 2p
2p
h½ n ¼ 1ej100kn ¼
1  ej100n
2p
100 k¼12 100
   
1 sin 25p n 1 sin 25p n 1
¼  p  where
100
lim  p  ¼
100
100 sin 100 n 100 n!0 sin 100 n 4

The derived impulse response shows 100 sample periodicity due to the
numerator and denominator property those represent the 8 and 200 periodicity,
respectively. The overall impulse response, numerator, and denominator are illus-
trated in Fig. 4.14. Note that the singular points at every 100 index delivers finite
value 1/4 based on the L’Hôpital’s rule [1] shown in above equation.
Prog. 4.8 MATLAB program for Fig. 4.14

n1 = 0:99;
hn1 = 0.01*sin(25*pi*(n1+eps)/100)./sin(pi*(n1+eps)/100);
y1 = sin(25*pi*n1/100);
y2 = sin(pi*n1/100);

figure,
subplot(211),stem(n1,hn1), grid
xlim([0 100]);
xlabel('n');
ylabel('h[n]')
subplot(212),
yyaxis le ;
plot(n1,0.01*y1)
yyaxis right;
plot(n1,y2), grid
xlim([0 100]);
ylim([-1 1]);
xlabel('n');


154 4 Filters in Time Domain

0.3

0.2
h[n]
0.1

-0.1
0 10 20 30 40 50 60 70 80 90 100
n

0.01 1

0.005 0.5

0 0

-0.005 -0.5

-0.01 -1
0 10 20 30 40 50 60 70 80 90 100
n

Fig. 4.14 Derived impulse response based on the DFT and its numerator and denominator plot

Likewise, the DFT range, we can observe the either impulse response config-
urations denoted Fig. 4.15 as −49 * 50 or 0 * 99 for n range in LPF design. The
shape of the impulse response is similar to the previously designed DTFT LPF with
periodicity. Does the one period of the impulse response represent final LPF
design? Let’s see further.
Prog. 4.8 MATLAB program for Fig. 4.15

n1 = 0:99;
n2 = -49:1:50;
hn1 = 0.01*sin(25*pi*(n1+eps)/100)./sin(pi*(n1+eps)/100);
hn2 = 0.01*sin(25*pi*(n2+eps)/100)./sin(pi*(n2+eps)/100);
figure,
subplot(211),stem(n2,hn2), grid
xlim([-50 50]);
ylabel('h[n]')
subplot(212),stem(n1,hn1), grid
xlim([0 100]);
xlabel('n');
ylabel('h[n]')
4.5 Simple Filter Design 155

0.3

h[n] 0.2

0.1

-0.1
-50 -40 -30 -20 -10 0 10 20 30 40 50

0.3

0.2
h[n]

0.1

-0.1
0 10 20 30 40 50 60 70 80 90 100
n

Fig. 4.15 Impulse response configuration as −49 * 50 and 0 * 99 for LPF with DFT

The convolution sum process cannot handle the infinite length impulse response;
therefore, we need to take certain range of the response. In addition, the negative
index section cannot be employed due to the accessibility and causality of future
input signal. Let’s choose the one complete period of impulse response from zero to
higher index. The convolution sum between the input signal and selected impulse
response provides the output signal. The example in Fig. 4.16 illustrates the input
signal with 100 sample period containing the even 100, 50, 25, 20, 10, and 5 sample
period signal components. The output for the selected range is presented at the
bottom subplot in Fig. 4.16. Note that the output is the part of stream outcome
156 4 Filters in Time Domain

X: 500
X: 401
4 Y: 0.25 0.3
Y: 0.2251

2 X: 500 0.2
Y: -2.657e-14

h[n]
x[n]

0 0.1

-2 0

-4 -0.1
400 420 440 460 480 500 520 540 560 580 600
n
X: 500
4 Y: 0.25 0.3

2 X: 500 0.2
Y: -2.657e-14

h[n]
x[n]

0 0.1

-2 0
X: 451 X: 550
-4 Y: 0.007075 Y: 0.01 -0.1
400 420 440 460 480 500 520 540 560 580 600
n

2 X: 500
Y: -2.152e-14
y[n]

-2

-4
400 420 440 460 480 500 520 540 560 580 600
n

Fig. 4.16 Input signal (100 sample period) with two impulse response configurations. Bottom
subplot is the output y[n] from above configurations

without any transition introduced by the incomplete overlapped convolution sum.


The transitions generally are appeared at the time edges of input signal such as start
and end time. The top of Fig. 4.16 demonstrates the input signal and the impulse
response overlapped to compute the output at 500 index as y[500]. Provided that the
future input values can be accessible, y[500] computation is illustrated in the middle
subplot in Fig. 4.16.
4.5 Simple Filter Design 157

Prog. 4.9 MATLAB program for Fig. 4.16


n1 = 400:499;
hn1 = 0.01*sin(25*pi*(n1+eps)/100)./sin(pi*(n1+eps)/100);
n3 = 451:550;
hn3 = 0.01*sin(25*pi*(n3+eps)/100)./sin(pi*(n3+eps)/100);
n2 = 0:999;
xn1 =
sin(2*pi*1*n2/100)+sin(2*pi*2*n2/100)+sin(2*pi*4*n2/100)+sin(2*pi*5*n2
/100)+sin(2*pi*10*n2/100)+sin(2*pi*20*n2/100);
yn1 = conv(xn1,hn1);

figure,
yyaxis le ;
subplot(311),plot(n2,xn1), grid
ylabel('x[n]')
hold on;
yyaxis right;
stem(n1+1,fliplr(hn1));
ylabel('h[n]')
xlim([400 600]);
xlabel('n');
hold off;

yyaxis le ;
subplot(312),plot(n2,xn1), grid
ylabel('x[n]')
hold on;
yyaxis right;
stem(n3,(hn3));
ylabel('h[n]')
xlim([400 600]);
xlabel('n');
hold off;

subplot(313),plot(0:(length(n1)+length(n2)-2),yn1), grid
xlim([400 600]);
ylim([-4 4]);
xlabel('n');
ylabel('y[n]')
158 4 Filters in Time Domain

The impulse response profiles at the top and middle of Fig. 4.16 generate the
identical output located at Fig. 4.16 bottom. The signal periodicity derives the
future from the past pattern as Eq. (4.42). Therefore, the x[501], x[502], etc. are
equivalent to the x[401], x[402], etc., respectively.

x½n ¼ x½n þ kN  where k 2 Z and N is the signal x period ð4:42Þ

The outputs from two impulse responses are only equalized for the periodic
signal with same periodic length. Otherwise, the derived impulse response cannot
be used directly for the LPF design. Certain truncation and shift are required for the
proper convolution sum process like DTFT LPF design. The complete impulse
response for given length N is illustrated with frequency response magnitude in
Fig. 4.17. Since there is no modification on the impulse response, the LPF response

Fig. 4.17 100-length impulse response for given LPF and corresponding frequency response.
Dx ¼ 2p=N
4.5 Simple Filter Design 159

Fig. 4.18 Shifted 100-length impulse response for given LPF and corresponding frequency
response. Dx ¼ 2p=N

is neat and clean in frequency domain. While the impulse response is periodic and
infinite, the frequency response is the DFT of the one period h[n]. Note that the Dx
is the radian frequency resolution as 2p=N.
If you want to use the complete impulse response, shift the main lobe to the one
period center as Eq. (4.43) and Fig. 4.18. The frequency response is identical to the
non-shifted version of the counterpart.

hLPF ½n ¼ h n  N2 ð4:43Þ
160 4 Filters in Time Domain

Prog. 4.10 MATLAB program for Figs. 4.17 and 4.18


n1 = 0:99;
n2 = -50:1:49;
hn1 = 0.01*sin(25*pi*(n1+eps)/100)./sin(pi*(n1+eps)/100);
hn2 = 0.01*sin(25*pi*(n2+eps)/100)./sin(pi*(n2+eps)/100);
n2 = shi ( (hn2));
faxis = (-pi:2*pi/100:pi-2*pi/100);

figure,
subplot(211), stem(n1,hn2), grid
xlabel('n')
ylabel('h_{LPF}[n]')
tle('Impulse response (all)')
subplot(212), stem(faxis,abs( n2)), grid
ax2 = gca;
ax2.XTick = [-pi -3*pi/4 -pi/2 -pi/4 0 pi/4 pi/2 3*pi/4 pi];
ax2.XTickLabel = {'-\pi', '-3\pi/4', '-\pi/2', '-\pi/4', '0', '\pi/4', '\pi/2', '3\pi/4',
'\pi'};
xlim([-pi pi]);
ylim([0 1.5]);
xlabel('Digital frequency (\Delta\omegak)')
ylabel('|H_{LPF}[k]|')

figure,
subplot(211), stem(n2,hn2), grid
xlabel('n')
ylabel('h[n]')
tle('Impulse response (all)')
subplot(212), stem(faxis,abs( n2)), grid
ax2 = gca;
ax2.XTick = [-pi -3*pi/4 -pi/2 -pi/4 0 pi/4 pi/2 3*pi/4 pi];
ax2.XTickLabel = {'-\pi', '-3\pi/4', '-\pi/2', '-\pi/4', '0', '\pi/4', '\pi/2', '3\pi/4',
'\pi'};
xlim([-pi pi]);
ylim([0 1.5]);
xlabel('Digital frequency (\Delta\omegak)')
ylabel('|H[k]|')
4.5 Simple Filter Design 161

The DFT property describes the time shift as the phase modification without
touching the magnitude as Eq. (4.44). Over the time axis, any relocation of the
impulse response maintains our design goal of LPF in Table 4.2.

P
DFT Analysis N1
h½n  d ej N kn
2p
h½n  d 

!
 n¼0 ð4:44Þ
j2p Magnitude : jH ½kj
¼ H ½ke N ¼ kd
Phase : \H ½k  2p N kd

The corresponding output is equally delayed by the shifted impulse response at


the convolution sum process as Eq. (4.45).

P
99
yLPF ½n ¼ hLPF ½kx½n  k  ¼ y n  N2 ð4:45Þ
k¼0

The previously shown periodic signal is used to provide the convolution sum
output in Fig. 4.19. The overlapped plot between the input signal and impulse
response illustrates the y[550] output computation. The overlapped section repre-
sents the convolution sum operation with multiplication and accumulation. We

4 0.25
X: 500
3 Y: 0.25 0.2

2
0.15
1
0.1

h[n]
x[n]

0
0.05
-1
0
-2 X: 451 X: 550
Y: 0.007075 Y: 0.01 -0.05
-3

-4 -0.1
400 420 440 460 480 500 520 540 560 580 600
n

1 X: 550
Y: -1.499e-14
y[n]

0 delay

-1

-2

-3

-4
400 420 440 460 480 500 520 540 560 580 600
n

Fig. 4.19 Input signal (100 sample period) with shifted impulse response. Bottom subplot is the
corresponding output y[n]
162 4 Filters in Time Domain

assume that the future data is not accessible to maintain the causality of the system
in this example. The x[550] and previous 99 data involves to compute the output y
[550]. Also comparing with the previous instance, the output is delayed for 50
samples due to the impulse response shift. This is one example of LPF based on the
DFT method.
Prog. 4.11 MATLAB program for Fig. 4.19

n1 = -50:1:49;
hn1 = 0.01*sin(25*pi*(n1+eps)/100)./sin(pi*(n1+eps)/100);
n2 = 0:999;
xn1 =
sin(2*pi*1*n2/100)+sin(2*pi*2*n2/100)+sin(2*pi*4*n2/100)+sin(2*pi*5*n2
/100)+sin(2*pi*10*n2/100)+sin(2*pi*20*n2/100);
yn1 = conv(xn1,hn1);
n3 = 451:550;

yyaxis le ;
subplot(211),plot(n2,xn1), grid
ylabel('x[n]')
hold on;
yyaxis right;
stem(n3,fliplr(hn1));
ylabel('h[n]')
xlim([400 600]);
xlabel('n');
hold off;
subplot(212),plot(0:(length(n1)+length(n2)-2),yn1), grid
xlim([400 600]);
ylim([-4 4]);
xlabel('n');
ylabel('y[n]')

What if we want to reduce the convolution length? How we can decrease the
impulse response size? We can choose from two methods that shrink the DFT
length and truncate the impulse response.
Example 4.9
Design the LPF for Table 4.2. Use the DFT method. Show the impulse response
from 0 to 19 as n.
Solution
Change the DFT length to design the LPF as 20 N. The computed Df is 400 Hz/
sample from 20 N and 8000 Hz sampling frequency. In order to pass the low
4.5 Simple Filter Design 163

1
H[k]

0.5

0
-10 -8 -6 -4 -2 0 2 4 6 8 10
k

1
H[k]

0.5

0
0 2 4 6 8 10 12 14 16 18 20
k

Fig. 4.20 Frequency specification for LPF given by Table 4.2 using DFT

frequencies until 1000 Hz, the magnitude one should cover up to 2 k value because
the 1000/(8000/20) is equal to the 2.5. According to the cylindrical and periodical
property of DFT, the frequency response for the negative k can be relocated at the
other end of given DFT configuration as shown in Fig. 4.20.
Based on the −9 * 10 k range, the DFT synthesis for the LPF impulse response
can be written as below.

1 X 1 ej202n  ej203n
2 2p 2p
j2p
h½ n ¼ 1e 20 kn
¼
20 k¼2 20 1  ej2p 20 n

   
1 sin 5p n 1 sin 5p n 1
¼  p  where
20
lim 20 p

20 sin 20 n 20 n!0 sin 20 n 4

The derived impulse response shows 20 sample periodicity and the singular
points at every 20 index delivers finite value 1/4 based on the L’Hôpital’s rule [1]
shown in above equation. In order to meet the causality of the system, the computed
impulse response is shifted to the right for 9 samples as shown in Fig. 4.21.

The previously used periodic signal is employed to generate the convolution sum
output in Fig. 4.22. The overlapped plot between the input signal and impulse
response illustrates the y[509] output computation. The x[509] and previous 19 data
164 4 Filters in Time Domain

0.3

h[n] 0.2

0.1

-0.1
-10 -8 -6 -4 -2 0 2 4 6 8 10
n
X: 9
0.3 Y: 0.25

0.2
h[n-9]

0.1

-0.1
0 2 4 6 8 10 12 14 16 18 20
n

Fig. 4.21 Derived impulse response and shifted impulse response for causal filter system

X: 500
Y: 0.25
4 0.25

0.2
2
0.15

X: 490 0.1
X: 509
h[n]
x[n]

0 Y: 0.05
Y: 0.0358
0.05

0
-2
-0.05

-4 -0.1
400 420 440 460 480 500 520 540 560 580 600
n

dealy X: 509
Y: -0.1063
y[n]

-2

-4
400 420 440 460 480 500 520 540 560 580 600
n

Fig. 4.22 Input signal (100 sample period) with derived impulse response. The overlapped
configuration provides for the y[509] computation. Bottom subplot is the corresponding output y[n]
4.5 Simple Filter Design 165

involves to compute the output y[509]. Also, the output is delayed for 9 samples
due to the impulse response shift. This is one example of reduced length LPF based
on the DFT method.
Prog. 4.12 MATLAB program for Fig. 4.22

n1 = -9:1:10;
hn1 = (1/20)*sin(5*pi*(n1+eps)/20)./sin(pi*(n1+eps)/20);
n2 = 0:999;
xn1 =
sin(2*pi*1*n2/100)+sin(2*pi*2*n2/100)+sin(2*pi*4*n2/100)+sin(2*pi*5*n2
/100)+sin(2*pi*10*n2/100)+sin(2*pi*20*n2/100);
yn1 = conv(xn1,hn1);
n3 = 490:509;

yyaxis le ;
subplot(211),plot(n2,xn1), grid
ylabel('x[n]')
hold on;
yyaxis right;
stem(n3,fliplr(hn1));
ylabel('h[n]')
xlim([400 600]);
xlabel('n');
hold off;
subplot(212),plot(0:(length(n1)+length(n2)-2),yn1), grid
xlim([400 600]);
ylim([-4 4]);
xlabel('n');
ylabel('y[n]')

Comparing the outputs between the 100 and 20 length DFT for LPF design, the
results are identical except the time delay as shown in Fig. 4.23. If the short impulse
response works properly, there is no need to increase the impulse response since the
length costs the computation and memory of the system. Does the both configu-
rations really provide the same output for all input signals? Let’s figure out.
166 4 Filters in Time Domain

Prog. 4.13 MATLAB program for Fig. 4.23


n1 = -9:1:10;
hn1 = (1/20)*sin(5*pi*(n1+eps)/20)./sin(pi*(n1+eps)/20);
n3 = -50:1:49;
hn3 = 0.01*sin(25*pi*(n3+eps)/100)./sin(pi*(n3+eps)/100);
n2 = 0:999;
xn1 =
sin(2*pi*1*n2/100)+sin(2*pi*2*n2/100)+sin(2*pi*4*n2/100)+sin(2*pi*5*n2
/100)+sin(2*pi*10*n2/100)+sin(2*pi*20*n2/100);
yn1 = conv(xn1,hn1);
yn2 = conv(xn1,hn3);

figure,
subplot(211),plot(0:(length(n3)+length(n2)-2),yn2), grid
xlim([400 600]);
ylim([-4 4]);
tle('LPF with 100 length (DFT method)')
ylabel('y[n]')
subplot(212),plot(0:(length(n1)+length(n2)-2),yn1), grid
xlim([400 600]);
ylim([-4 4]);
tle('LPF with 20 length (DFT method)')
xlabel('n');
ylabel('y[n]')

The frequency response of the 20-sample impulse response is illustrated in


Fig. 4.24. Below the p=4 radian frequency components are propagated through the
filter without losing the signal magnitude at all. On the other side, above the p=4
radian frequency components are completely blocked by the filter because of zero
magnitude in frequency response. No fluctuations are observed in the passing and
blocking frequency band in the frequency response. Similar to the 100-sample
impulse response shown in Fig. 4.18, the frequency response demonstrates the ideal
response for LPF except low frequency density Df . According to the above filter
outputs in Fig. 4.23, short impulse response performs the specified LPF function
well.
4.5 Simple Filter Design 167

LPF with 100 length (DFT mehtod)


4

2
y[n]

-2

-4
400 420 440 460 480 500 520 540 560 580 600

LPF with 20 length (DFT method)


4

2
y[n]

-2

-4
400 420 440 460 480 500 520 540 560 580 600
n

Fig. 4.23 LPF output with 100 and 20 length impulse response

Fig. 4.24 Shifted impulse response and corresponding frequency response in magnitude
168 4 Filters in Time Domain

Prog. 4.14 MATLAB program for Fig. 4.24


n1 = 0:1:19;
n2 = -9:1:10;
hn1 = (1/20)*sin(5*pi*(n2+eps)/20)./sin(pi*(n2+eps)/20);
n1 = shi ( (hn1));
faxis = (-pi:2*pi/20:pi-2*pi/20);

figure,
subplot(211), stem(n1,hn1), grid
xlabel('n')
ylabel('h_{LPF}[n]')
tle('Impulse response')
subplot(212), stem(faxis,abs( n1)), grid
ax2 = gca;
ax2.XTick = [-pi -3*pi/4 -pi/2 -pi/4 0 pi/4 pi/2 3*pi/4 pi];
ax2.XTickLabel = {'-\pi', '-3\pi/4', '-\pi/2', '-\pi/4', '0', '\pi/4', '\pi/2', '3\pi/4',
'\pi'};
xlim([-pi pi]);
ylim([0 1.5]);
xlabel('Digital frequency (\Delta\omegak)')
ylabel('|H_{LPF}[k]|')

If the filter performance is insensitive to the filter length, we do not need to


choose the longer filter that increases the computation time and output delay. While
the discrete frequencies provide the ideal LPF response, the intermediate frequency
response is unknown to the filter designer based on the given information.
Therefore, the continuous frequency response is required to be investigated for
further analysis. Figures 4.25 and 4.26 demonstrate the DTFT of the 20 length LPF
designed from DFT method. The continuous and discrete plot represent the DTFT
and DFT analysis, respectively. The continuous frequency response from the DTFT
denotes the ripples in the passing and blocking band in the frequency domain. The
discrete frequency response samples the ideal locations from the continuous
counterpart to pretend the perfect response of LPF.
4.5 Simple Filter Design 169

0.3

h LPF [n] 0.2

0.1

-0.1
0 2 4 6 8 10 12 14 16 18 20
n

1.5
|HLPF (ej )|

0.5 X 1.0661
Y 0.16415

0
- -3 /4 - /2 - /4 0 /4 /2 3 /4
Radian frequency ( )

Fig. 4.25 LPF impulse response and corresponding frequency response based on the DFT
(discrete) and DTFT (continuous)

1.2

1.1
|HLPF (ej )|

0.9

0.8
- /4 0 /4
Radian frequency ( )

0.2

0.15
|HLPF (ej )|

0.1

0.05

0
/4 /2 3 /4
Radian frequency ( )

Fig. 4.26 Enlarged passband and stropband of Fig. 4.25 frequency response
170 4 Filters in Time Domain

Prog. 4.15 MATLAB program for Figs. 4.25 and 4.26


syms omega real;
n1 = -9:1:10;
n2 = 0:1:19;
rfreq = linspace(-pi,pi,1000);
hn1 = (1/20)*sin(5*pi*(n1+eps)/20)./sin(pi*(n1+eps)/20);
coeff = exp(1j*omega*n1);
Hint1 = hn1.*coeff;
Homega1 = sum(Hint1);
Homega2 = subs(Homega1,omega,rfreq);
Homega3 = eval(Homega2);
n1 = shi ( (hn1));
faxis = (-pi:2*pi/20:pi-2*pi/20);

figure,
subplot(211)
stem(n2,hn1), grid
ylabel('h_{LPF}[n]')
xlabel('n');
subplot(212)
plot(rfreq,abs(Homega3))
hold on;
stem(faxis,abs( n1)), grid
ax2 = gca;
ax2.XTick = [-pi -3*pi/4 -pi/2 -pi/4 0 pi/4 pi/2 3*pi/4 pi];
ax2.XTickLabel = {'-\pi', '-3\pi/4', '-\pi/2', '-\pi/4', '0', '\pi/4', '\pi/2', '3\pi/4',
'\pi'};
xlim([-pi pi]);
ylim([0 1.5]);
xlabel('Radian frequency (\omega)')
ylabel('|H_{LPF}(\omega)|')

Let’s consider the ideal case for the length-20 LPF. The input signal x[n] with 20
sample period shown in Eq. (4.46) contains the five cosine functions and constant
value.
  
2p 4p 8p
x½n ¼ 1 þ cos n þ cos n þ cos n
20 20 20
  ð4:46Þ
10p 20p
þ cos n þ cos n
20 20
4.5 Simple Filter Design 171

Table 4.3 Input signal x[n] components from Eq. (4.46) for LPF processing
Trigonometric Period Radian Cyclic frequency Propagated?
Function frequency (fs = 8000 Hz) (Hz)
  p
cos 2p n 20 Samples 10 400 Passed
20  p
cos 4p
20 n
10 Samples 5 800 Passed
8p  2p
cos 20 n 5 Samples 5
1600 Blocked
10p  p
cos 20 n 4 Samples 2 2000 Blocked
 
cos 20p
20 n
2 Samples p 4000 Blocked

Table 4.3 illustrates individual trigonometric functions which denotes the certain
integer period. Note that the least common multiple of the all functions is 20 for
whole period of the signal. For the given design parameter of the LPF, the signal
components up to p=4 or 1000 Hz are propagated thorough the filter and the higher
than the threshold frequency should be blocked by the convolution sum process.
The discrete frequency distributions based on the 20-sample length DFT are
presented at Fig. 4.27 for the input and output of the LPF. In addition to the
constant value, the input signal retains the all frequency components described in
Table 4.3. The output signal from the LPF perfectly maintain or remove the passing
and blocking band signal in filter output. Only the zero, p=10, and p=5 radian

Fig. 4.27 20 length DFT of input x[n] and output y[n] from 20 length LPF
172 4 Filters in Time Domain

frequencies are survived from the LPF processing without changing the signal
magnitude at all. The other frequencies are completely eliminated and barely seen
in the output frequency profile. This situation is contributed to the ideal condition
that is the signal period is equal to the DFT LPF length.
Prog. 4.16 MATLAB program for Fig. 4.27

n1 = -9:1:10;
hn1 = (1/20)*sin(5*pi*(n1+eps)/20)./sin(pi*(n1+eps)/20);
n2 = 0:999;
xn1 =
cos(2*pi*1*n2/20)+cos(2*pi*2*n2/20)+cos(2*pi*4*n2/20)+cos(2*pi*5*n2/2
0)+cos(2*pi*10*n2/20)+1;
yn1 = conv(xn1,hn1);
xn2 = xn1(501:520);
yn2 = yn1(501:520);
fxn2 = shi ( (xn2));
fyn2 = shi ( (yn2));
faxis = (-pi:2*pi/20:pi-2*pi/20);

figure,
subplot(211), stem(faxis,abs(fxn2)), grid
ax2 = gca;
ax2.XTick = [-pi -3*pi/4 -pi/2 -pi/4 0 pi/4 pi/2 3*pi/4 pi];
ax2.XTickLabel = {'-\pi', '-3\pi/4', '-\pi/2', '-\pi/4', '0', '\pi/4', '\pi/2', '3\pi/4',
'\pi'};
xlim([-pi pi]);
ylim([0 22]);
ylabel('|X[k]|');
subplot(212), stem(faxis,abs(fyn2)), grid
ax2 = gca;
ax2.XTick = [-pi -3*pi/4 -pi/2 -pi/4 0 pi/4 pi/2 3*pi/4 pi];
ax2.XTickLabel = {'-\pi', '-3\pi/4', '-\pi/2', '-\pi/4', '0', '\pi/4', '\pi/2', '3\pi/4',
'\pi'};
xlim([-pi pi]);
ylim([0 22]);
ylabel('|Y[k]|')
xlabel('Digital frequency (\Delta\omegak)');
4.5 Simple Filter Design 173

In addition to the defined x[n] signal, 7p=20 radian frequency is included to the
new input signal in Eq. (4.47). The 7p=20 component presents the 40-sample
period and 1400 Hz frequency based on the 8000 Hz sampling frequency.
Therefore, the overall period of the new input signal is the 40 instead of 20 samples.
The newly inserted frequency should be eliminated by the designed LPF due to the
over the limit frequency range.
   
2p 4p 7p 8p
x½n ¼ 1 þ cos n þ cos n þ cos n þ cos n
20 20 20 20
ð4:47Þ
10p  20p 
þ cos 20 n þ cos 20 n

The designed LPF computes the output by using the derived 20 length impulse
response. While the 20 coefficients for the LPF is generated from the frequency
domain, the filter processing is performed by the convolution sum over the complete
time domain. The single frame of the infinite input signal is utilized for LPF pro-
cessing. In order to compare the frequency information between the input and output,
the frequency distribution is visualized by the 40 length DFT as shown in Fig. 4.28.
The choice of the DFT length is justified by the 7p=20ð¼ 14p=40Þ radian frequency
that is the integer multiple of the 1p=20ð¼ 2p=40Þ. Once you use the 20 length DFT,
the 7p=20 cannot be seen due to the wide stride of frequency distribution.
The filter output shows the modified frequency distribution for low pass property
in Fig. 4.29. Above the p=4 radian frequency (equivalent to the 1000 Hz), most of
the frequency components are completely removed from the LPF processing except
7p=20 ( 1.1) location that is not seen on the 20 length DFT design procedure.
The DTFT continuous distribution on Figs. 4.25 and 4.26 provides the magnitude
0.1652 at 1.079 rad frequency; therefore, we expect the output magnitude around
3.3 that is the 0.1652
20 at the 1.1 rad frequency. The designed LPF from DFT
method guarantees the designated magnitudes on the integer multiple of the fun-
damental frequency in other words Df frequency resolution. However, the inter-
mediate continuous frequencies follow the magnitude of DTFT distributions those
cannot be observed in the discrete DFT profile.

Convolu on with
x[n] 20 Length LPF y[n]
(DFT method)

40 Length DFT 40 Length DFT

X[k] Y[k]

Fig. 4.28 Block diagram to compare the LPF frequency response from given signal
174 4 Filters in Time Domain

Fig. 4.29 40 length DFT of input x[n] and output y[n] from 20 length LPF

Prog. 4.17 MATLAB program for Figs. 4.29. See Prog. 4.16 for plot decoration

n1 = -9:1:10;
hn1 = (1/20)*sin(5*pi*(n1+eps)/20)./sin(pi*(n1+eps)/20);
n2 = 0:999;
xn1 =
cos(2*pi*1*n2/20)+cos(2*pi*2*n2/20)+cos(2*pi*4*n2/20)+cos(2*pi*5*n2/2
0)+cos(2*pi*10*n2/20)+1+cos(pi*7*n2/20);
yn1 = conv(xn1,hn1);
xn2 = xn1(501:540);
yn2 = yn1(501:540);
fxn2 = shi ( (xn2));
fyn2 = shi ( (yn2));
faxis = (-pi:2*pi/40:pi-2*pi/40);

figure,
subplot(211), stem(faxis,abs(fxn2)), grid
...
subplot(212), stem(faxis,abs(fyn2)), grid
...
4.5 Simple Filter Design 175

0.3

h LPF [n] 0.2

0.1

-0.1
0 10 20 30 40 50 60 70 80 90 100
n

1.5
|HLPF (ej )|

0.5 X 0.84593
Y 0.14468

0
- -3 /4 - /2 - /4 0 /4 /2 3 /4
Radian frequency ( )

Fig. 4.30 100-length LPF impulse response and corresponding frequency response based on the
DFT (discrete) and DTFT (continuous)

The increased DFT length depicts the LPF frequency profile in dense distribu-
tion. Figures 4.30 and 4.31 demonstrate the LPF with 100 DFT length. Comparing
to the 20 length LPF, the finer grain description is observed in the discrete fre-
quency response. The continuous response from the DTFT still shows the

1.2

1.1
|HLPF (ej )|

0.9

0.8
- /4 0 /4
Radian frequency ( )

0.2

0.15
|HLPF (ej )|

0.1

0.05

0
/4 /2 3 /4
Radian frequency ( )

Fig. 4.31 Enlarged passband and stropband of Fig. 4.30 frequency response
176 4 Filters in Time Domain

fluctuations between the sampled locations in Fig. 4.31; however, the variation
height is lower than the 20 length LPF counterpart. The highest blocking band
magnitude is the 0.1459 at 0.8439 radian frequency for 100 length LPF and 0.1652
at 1.079 radian frequency for 20 length LPF. Further increasing filter length expects
to follow the design parameters closely and accurately with expense of the com-
putation time and output delay as shown in the cases with LPF with DTFT.
Prog. 4.18 MATLAB program for Figs. 4.30 and 4.31
syms omega real;
n1 = -50:1:49;
n2 = 0:1:99;
rfreq = linspace(-pi,pi,1000);
hn1 = 0.01*sin(25*pi*(n1+eps)/100)./sin(pi*(n1+eps)/100);
coeff = exp(1j*omega*n1);
Hint1 = hn1.*coeff;
Homega1 = sum(Hint1);
Homega2 = subs(Homega1,omega,rfreq);
Homega3 = eval(Homega2);
n1 = shi ( (hn1));
faxis = (-pi:2*pi/100:pi-2*pi/100);

figure,
subplot(211)
stem(n2,hn1), grid
...
subplot(212)
plot(rfreq,abs(Homega3))
hold on;
stem(faxis,abs( n1)), grid
hold off;
...
figure,
subplot(211)
plot(rfreq,abs(Homega3))
hold on;
stem(faxis,abs( n1)), grid
hold off;
...
subplot(212)
plot(rfreq,abs(Homega3))
hold on;
stem(faxis,abs( n1)), grid
hold off;
...
4.5 Simple Filter Design 177

0.25
100 Length LPF
20 Length LPF
0.2

0.15

0.1
h LPF[n]

0.05

-0.05

-0.1
-50 -40 -30 -20 -10 0 10 20 30 40 50
n

Fig. 4.32 LPF impulse response from 20 and 100 length DFT method

The method to design the LPF with DFT was utilizing the DFT length and
specifying the individual frequency requirement on each discrete frequency. If you
are using the known periodic discrete signal, this method is perfect for you.
Otherwise, the approach suffers from the unspecified frequency responses those can
be seen by DTFT analysis. The increased length LPF with DFT improves the
description resolution of the frequency response; however, the deviations from
desired output are still detected due to the discretization.
In the LPF design with DTFT, we truncate the infinite impulse response to the
limited size in order to realize the feasible system. Using the same idea, what is the
difference between the truncated and short-length LPF with DFT for the equal size?
The previous LPF design for 20 and 100 length will be used for comparison in
Fig. 4.32.
Both shows the similar time domain distribution for the overlapped range and
the energy for both LPF are identical each other due to the passband ratio that is
equal as 1000 Hz/4000 Hz. Note that the 1000 Hz and 4000 Hz is the passband
limit and sampling frequency half respectively. According to the Parseval’s theo-
rem, frequency domain energy is equal for both length filters as shown in
Eq. (4.48).
178 4 Filters in Time Domain

1XN 1
1 X 2
1 X 12
jX ½kj2 ¼ j1j2 ¼ j1j2
N k¼0 20 k¼2 100 k¼12
X
N 1 X
10 X
49
¼ jx½nj2 ¼ jh20LPF ½nj2 ¼ jh100LPF ½nj2 ¼ 0:25
n¼0 n¼9 n¼50
ð4:48Þ

Figure 4.33 demonstrates energy ratio between the time and frequency domain
due to the truncation. The frequency domain energy is ideal and constant from the
specification and time domain energy is adjusted from the truncation size. The
original size of the impulse response is 100 samples and the resized response is
changed from 1 to 99 in every odd numbers. The length 20 response contains
approximately 96% of the frequency domain energy according to the Fig. 4.33.
Note that the untrimmed 20 length LPF includes the 100% energy of the frequency
domain.
Energy ratio between time and frequency domain [%]

X: 19
100
Y: 95.62
95
X: 21
90 Y: 96.45

85

80

75

70

65

60

55

50
10 20 30 40 50 60 70 80 90 100
h[n] length in samples

Fig. 4.33 (Time domain energy)/(Frequency domain energy)


4.5 Simple Filter Design 179

Prog. 4.19 MATLAB program for Figs. 4.32 and 4.33


n1 = -9:1:10;
hn1 = (1/20)*sin(5*pi*(n1+eps)/20)./sin(pi*(n1+eps)/20);
n2 = -50:1:49;
hn2 = 0.01*sin(25*pi*(n2+eps)/100)./sin(pi*(n2+eps)/100);
n3 = 42:61;
hn3 = hn2(n3);

eee = [0.25^2];
engy = 0;
for kk=0:48
engy = sum(hn2(52:52+kk).^2)*2+0.25^2;
eee = [eee engy];
end

engy = sum(hn2(52:100).^2)*2+0.25^2+hn2(1)^2;
eee = [eee engy];
en1 = [(1:2:99) 100];

figure,
stem(n2,hn2,'*'), hold on
stem(n1,hn1), grid, hold off
...
figure,
stem(en1,eee*100/0.25,':o'), grid
...

There is subtle difference in time domain distribution for both 20 length LPF
designs. The truncated and untrimmed LPF show the proper designated LPF require-
ment that propagates the frequency components under the 1000 Hz or p=4 radian
frequency. As stated earlier, the untrimmed LPF with DFT guarantees the unit
magnitude for the specific periodic components which are represented by the stem
plot with o mark in Figs. 4.34 and 4.35. The frequency response for the truncated
LPF illustrates slight deviation from the promised magnitude at the passing and
periodic frequencies depicted by the stem plot with * mark in Figs. 4.34 and 4.35.
180 4 Filters in Time Domain

0.3
Truncated DFT
h LPF [n] 0.2 20 Length DFT

0.1

-0.1
-10 -8 -6 -4 -2 0 2 4 6 8 10
n

1.5
Truncated DFT
20 Length DFT
|HLPF (ej )|

0.5

0
- -3 /4 - /2 - /4 0 /4 /2 3 /4
Radian frequency ( )

Fig. 4.34 LPF impulse responses and corresponding frequency responses from DFT method. *
indicates truncated filter from 100 to 20 and o specifies the untrimmed filter

1.2
Truncated DFT
1.1 20 Length DFT
|HLPF (ej )|

0.9

0.8
- /4 0 /4
Radian frequency ( )

0.2
Truncated DFT
0.15 20 Length DFT
|HLPF (ej )|

0.1

0.05

0
/4 /2 3 /4
Radian frequency ( )

Fig. 4.35 Enlarged passband and stropband of Fig. 4.34 frequency response
4.5 Simple Filter Design 181

Prog. 4.20 MATLAB program for Figs. 4.34 and 4.35


syms omega real;
rfreq = linspace(-pi,pi,1000);
n1 = -9:1:10;
hn1 = (1/20)*sin(5*pi*(n1+eps)/20)./sin(pi*(n1+eps)/20);
n2 = -50:1:49;
hn2 = 0.01*sin(25*pi*(n2+eps)/100)./sin(pi*(n2+eps)/100);
n3 = 42:61;
hn3 = hn2(n3);
coeff = exp(1j*omega*n1);
Hint1 = hn1.*coeff;
Hint2 = hn3.*coeff;
Homega1 = sum(Hint1);
Homega2 = sum(Hint2);
Homega3 = subs(Homega1,omega,rfreq);
Homega4 = subs(Homega2,omega,rfreq);
Homega5 = eval(Homega3);
Homega6 = eval(Homega4);
n1 = shi ( (hn1));
n2 = shi ( (hn3));
faxis = (-pi:2*pi/20:pi-2*pi/20);
figure,
subplot(211)
stem(n1,hn3,'*'), hold on;
stem(n1,hn1), grid, hold off;
subplot(212)
plot(rfreq,abs(Homega6),rfreq,abs(Homega5)), hold on;
stem(faxis,abs( n1)),
stem(faxis,abs( n2),'*'), grid, hold off;
xlim([-pi pi]), ylim([0 1.5]);
figure,
subplot(211)
plot(rfreq,abs(Homega6),rfreq,abs(Homega5)), hold on;
stem(faxis,abs( n1)),
stem(faxis,abs( n2),'*'), grid, hold off;
xlim([-pi/4 pi/4]), ylim([0.8 1.2]);
subplot(212)
plot(rfreq,abs(Homega6),rfreq,abs(Homega5)), hold on;
stem(faxis,abs( n1)),
stem(faxis,abs( n2),'*'), grid, hold off;
xlim([pi/4 pi]), ylim([0 0.2]);
182 4 Filters in Time Domain

In Figs. 4.34 and 4.35, the continuous frequency responses for both LPF provide
the opposite performance outcome against the discrete frequency situation. The
truncated LPF delivers the less fluctuation in passing and blocking frequency band
than untrimmed LPF distribution. Originally, the truncated LPF expects to represent
the less variation in the intended band since the filter uses the increased length to
describe the given specification. Even the abbreviation of the long length LPF
maintains filter performance to the certain point with sacrifice of the designed
periodic signal gains. Overall the intermediate frequencies denoted by the contin-
uous distribution are well regulated by the truncated LPF.
We have explored the three methods to design the LPF as DTFT, untrimmed
DFT, and truncated DFT. All three methods are compared in Figs. 4.36 and 4.37
with identical length as 20 samples. Note that the truncated DFT method is originally
designed for 100 sample length. The discrete plots for the DTFT, untrimmed DFT,

0.3
Truncated DFT
0.2 20 Length DFT
20 Length DTFT
h LPF [n]

0.1

-0.1
-10 -8 -6 -4 -2 0 2 4 6 8 10
n

1.5
Truncated DFT
20 Length DFT
|HLPF (ej )|

1 20 Length DTFT

0.5

0
- -3 /4 - /2 - /4 0 /4 /2 3 /4
Radian frequency ( )

Fig. 4.36 LPF impulse responses and corresponding frequency responses from DFT and DTFT
method
4.5 Simple Filter Design 183

Prog. 4.21 MATLAB program for Figs. 4.36 and 4.37. Similar to Prog. 4.20. Repeated
parts are omitted to save the length

syms omega real;


rfreq = linspace(-pi,pi,1000);
n1 = -9:1:10;
...
hn4 = sin(pi*(n1+eps)/4)./(pi*(n1+eps));
coeff = exp(1j*omega*n1);
...
Hint3 = hn4.*coeff;
...
Homega7 = sum(Hint3);
Homega8 = subs(Homega7,omega,rfreq);
Homega9 = eval(Homega8);
...
n3 = shi ( (hn4));
faxis = (-pi:2*pi/20:pi-2*pi/20);
figure,
subplot(211)
stem(n1,hn3,'*'), hold on;
stem(n1,hn1,'o');
stem(n1,hn4,'d'), grid, hold off;
subplot(212)
plot(rfreq,abs(Homega6),rfreq,abs(Homega5),rfreq,abs(Homega9)), hold on;
stem(faxis,abs( n2),'*'),
stem(faxis,abs( n1),'o'),
stem(faxis,abs( n3),'d'), grid, hold off;
xlim([-pi pi]), ylim([0 1.5]);
figure,
subplot(211)
plot(rfreq,abs(Homega6),rfreq,abs(Homega5),rfreq,abs(Homega9)), hold on;
stem(faxis,abs( n2),'*'),
stem(faxis,abs( n1),'o'),
stem(faxis,abs( n3),'d'), grid, hold off;
xlim([-pi/4 pi/4]), ylim([0.8 1.2]);
subplot(212)
plot(rfreq,abs(Homega6),rfreq,abs(Homega5),rfreq,abs(Homega9)), hold on;
stem(faxis,abs( n2),'*'),
stem(faxis,abs( n1),'o'),
stem(faxis,abs( n3),'d'), grid, hold off;
xlim([pi/4 pi]), ylim([0 0.2]);
184 4 Filters in Time Domain

1.2
Truncated DFT
1.1 20 Length DFT
|HLPF (ej )| 20 Length DTFT

0.9

0.8
- /4 0 /4
Radian frequency ( )

0.2
Truncated DFT
0.15 20 Length DFT
|HLPF (ej )|

20 Length DTFT

0.1

0.05

0
/4 /2 3 /4
Radian frequency ( )

Fig. 4.37 Enlarged passband and stropband of Fig. 4.36 frequency response

and truncated DFT are marked with diamond, circle, and star correspondingly on the
figures. The impulse responses show the similar distributions for the three methods.
The likeness is higher between the DTFT and truncated DFT method than the
untrimmed DFT method especially for the range away from the zero. Observe that
DTFT (diamond head) and truncated DFT (star head) distribution are very close and
difficult to separate in the figure. Also, the hardly separable condition can be noticed
in the frequency domain between the DTFT and truncated DFT method those
illustrate the deviation from the designed gains on the discrete frequencies; on the
contrary, the untrimmed DFT method holds the intended gains over the frequencies.
The DTFT and truncated DFT method provide comparable performance for the
continuous frequency distribution while the truncated DFT employs the increased
length for DFT in the initial design stage. The analysis suggests that the DTFT and
truncated DFT follow the designed parameters with less variation for any given
frequencies. The untrimmed DFT shows the higher fluctuation for the compre-
hensive frequencies; however, the integer multiples of the frequency resolution main-
tain the intended gains. Therefore, if the system only controls the periodic signal, the
untrimmed DFT is the right choice for the LPF. Figure 4.38 shows the procedure to
select the design method for LPF. Though the periodic signal is provided to the system
as major input, the lengthy period disturbs to decide the untrimmed DFT method. Note
4.5 Simple Filter Design 185

Fig. 4.38 Guide for LPF design method selection from various situations

that the longer impulse response produces the higher computational burden as well as
extended delay time. The DTFT method requires to solve the symbolic mathematics
that is usually performed by hand or MATLAB symbolic math toolbox. The given
example above uses the simple description of the frequency specification but complex
shape in the frequency domain may need complicated solution for impulse response.
For the untrimmed and truncated DFT method, the computation is straightforward by
using the conventional DFT function or program. The individual and discrete frequency
specification are placed in the algorithm and the complex number result is computed by
the numerical computation.
According to the DTFT and DFT property, the even symmetric in one domain
generates the real values only in the other domain. The time or frequency either
domain can be applied for the even symmetric as Euler formula in Eq. (4.49).
2p  j2pkn j2pkn
cosðxnÞ ¼ e
jxn
þ ejxn
cos kn ¼ e N þ2e N ð4:49Þ
2 N

The frequency specification in even symmetric form provides the impulse


response in real value. Subsequently, the symmetric time window frame centered
origin is applied over the derived response function for even symmetric impulse
response that generates the frequency response in real value. Note that the fre-
quency response without complex number does not modify the input time infor-
mation; hence, no time shift is observed in the filter output. Table 4.4 shows the
186 4 Filters in Time Domain

Table 4.4 Frequency and DTFT DFT


time domain relationship for
DTFT DFT
phase and time shift x½n $ X ðe Þ jx
x½n $ X ½k 
DTFT DFT
x½n  d  $ X ðejx Þejxd x½n  d  $ X ½k ej N kd
2p

Y ðejx Þ ¼ X ðejx ÞjHðejx Þjej\H ðe Þ Y ½k  ¼ X ½k jH ½k jej\H ½k


jx

 
¼ X ðejx Þej\H ðe
jx
Þ
jH ðejx Þj ¼ X ½k ej\H ½k jH ½k j

frequency and time domain relationship for phase and time shift. The jH ðejx Þj and
jH ½kj control the individual frequency magnitude and the ej\H ðe Þ and ej\H ½k
jx

decide each frequency time shift from input signal x[n].


The even symmetric impulse response could be reduced for the compact length;
however, the configuration is still maintaining the even symmetric profile. After the
truncation, the impulse response is moved to the right until all the response portion
in the negative time index is relocated to the zero and higher location. The impulse
response positioned at the zero and higher time index assures the system causality.
Figure 4.39 illustrates the overall procedure for design the LPF based on the DTFT
and DFT method. Observe that the untrimmed DFT method does not perform the
trim procedure in Fig. 4.39.
There are number of trade-off between the implementation and performance. The
filter designer should choose the right parameters and values to maximize the system
performance. This is the end of comprehensive LPF design. The advanced methods
for LPF design will be presented after the Z-transform theory in next chapter.
The LPF is the most fundamental structure to design the filter variations such as
high pass filter (HPF), band pass filter (BPF), and band stop filter (BSF). The HPF
passes the frequency components above the threshold value known as cutoff fre-
quency. The BPF propagates the range of frequency components specified by the
lower and upper frequency limits. The BSF suppresses the range of frequency

Frequency
DTFT or Impulse Response Trim
Specifica on
DFT Truncate
Synthesis 0.3

0.2
0.3

0.2
h[n]

0.1
h[n]

0.1
0
0
-0.1
-0.1 -10 -8 -6 -4 -2 0 2 4 6 8 10
-50 -40 -30 -20 -10 0 10 20 30 40 50 n
n

Parseval DTFT or
Theorem DFT
Analysis
Note Reloca on for
Truncated DFT N Causality Shi Check
Untrimmed DFT 0.3

0.2
O.K. Performance? Not O.K.
N = Signal Period
h[n]

0.1

-0.1
0 2 4 6 8 10 12 14 16 18 20
n

Fig. 4.39 Overall design procedure for LPF based on the DTFT or DFT method
4.5 Simple Filter Design 187

LPF HPF

f
f

BSF
BPF

f f

Fig. 4.40 Various filter configurations

components with lower and upper bound. The graphical representation of the filter
structures is given in Fig. 4.40.
You can design each filter directly as explained in the LPF design procedure.
The frequency distribution is specified and transformed by DTFT or DFT to obtain
the raw impulse response. After the truncation and relocation, final impulse
response for the given requirement filter is realized for convolution sum process.
Since the procedure is identical, leave the direct method examples for HPF, BPF,
and BSF to the readers.
According to the DTFT and DFT property, we can consider the design method
that relocate and invert the frequency information. The required passing or stopping
frequency band is applied to the LPF design which can be shifted and inverted to
the desired location in frequency domain. Therefore, the LPF is the basic structure
to realize the other filter formats. Table 4.5 is the fundamental equations used for
the filter design.

Table 4.5 Fundamental DTFT and DFT properties for the filter transformation
DTFT DFT
Frequency Time Frequency Time
 
Frequency Shift X ejðxxs Þ x½nejxs n X ½k  l 2p
xN ½nej N ln
Magnitude inversion 1  X ðejx Þ d½n  x½n 1  X ½k  d½n  xN ½n
Condition X ðejx Þ 2 R and GainðX ðejx ÞÞ ¼ 1 X ½k 2 R and GainðX ½k Þ ¼ 1
188 4 Filters in Time Domain

Table 4.6 High pass filter Filter specifications Value


specification example
Filter type High pass filter
Filter length Finite with optimization
Cutoff frequency (fc) 3000 Hz
Sampling frequency (fs) 8000 Hz

You can place the LPF to any location by frequency shift and turn over the
magnitude to apply the stop band by magnitude inversion. The shift and inversion
in the frequency domain are performed in the time domain via multiplying the
computed values with derived impulse response of LPF. Since the impulse response
with complex number cannot be used for the convolution sum, the frequency shift
utilizes the cosine function instead of the complex exponential based on the Euler
relationship. For the proper magnitude inversion, the frequency response should be
real number and constant gain in the LPF; otherwise, subtraction from constant
value does not invert the frequency response. Let’s do one example for HPF as
specified in Table 4.6.
Example 4.10
Design the HPF for Table 4.6. Use the LPF from truncated DFT method for 20
sample length.
Solution
Based on the information, the cutoff frequency corresponds to the 3p=4 in discrete
frequency. The 2p repeatability with maximum p in discrete frequency domain
illustrates Fig. 4.41 frequency distribution for the given HPF. The symmetric
structure over the y axis is repeated for every 2p in order to maintain the real
number in impulse response. The circle in Fig. 4.41 demonstrates the conjugate
relationship between 3p=4 and 5p=4 for Euler formula.

Fig. 4.41 Frequency distribution for desired HPF and its angular profile
4.5 Simple Filter Design 189

Fig. 4.42 Frequency shift for LPF ! HPF

The LPF is devised as identical profile of the HPF located in the p center. In
this design, the p=2 bandwidth LPF filter is realized and shifted to the p location as
shown in Fig. 4.42. Note that the shift should provide symmetrical (conjugate)
profile to preserve the real number impulse response.
Let’s assume that the hLPF ½n is implemented by the truncated DFT method for
20 sample length. As stated earlier, the design length of the truncated DFT method
is 100 samples. The shift procedure is realized by the complex multiplication and
organized as below.

hHPF ½n ¼ hLPF ½nejpn ¼ hLPF ½nð1Þn

Figures 4.43 and 4.44 demonstrate the preliminary LPF and corresponding
shifted HPF. According to the frequency response, the designed HPF properly

0.2
h LPF [n]

-0.2

-10 -8 -6 -4 -2 0 2 4 6 8 10
n

1
|HLPF (ej )|

0.5

0
-2 - -3 /4 - /2 - /4 0 /4 /2 3 /4 2
Radian frequency ( )

Fig. 4.43 Impulse response and frequency response of baseline LPF


190 4 Filters in Time Domain

0.2
h HPF [n]

-0.2

-10 -8 -6 -4 -2 0 2 4 6 8 10
n

1
|HHPF (ej )|

0.5

0
-2 - -3 /4 - /2 - /4 0 /4 /2 3 /4 2
Radian frequency ( )

Fig. 4.44 Designed HPF from LPF transformation

propagates the signal above the 3p=4 discrete frequency with real number impulse
response. Note that the derived impulse response contains the values at the negative
index therefore the shift in time domain is required for system causality. Once the
HPF performance is acceptable for the given requirement, this computation is
concluding the design procedure.
4.5 Simple Filter Design 191

Prog. 4.22 MATLAB program for Figs. 4.43 and 4.44


syms omega real;
rfreq = linspace(-2*pi,2*pi,1000);
n2 = -50:1:49;
hn2 = 0.01*sin(25*pi*(n2+eps)/100)./sin(pi*(n2+eps)/100);
n3 = 42:61;
hn3 = hn2(n3);
n4 = -9:1:10;
hn4 = hn3.*(-1).^n4;
coeff = exp(1j*omega*n4);
Hint2 = hn3.*coeff;
Hint3 = hn4.*coeff;
Homega2 = sum(Hint2);
Homega3 = sum(Hint3);
Homega4 = subs(Homega2,omega,rfreq);
Homega5 = subs(Homega3,omega,rfreq);
Homega6 = eval(Homega4);
Homega7 = eval(Homega5);

figure,
subplot(211)
stem(n4,hn3), grid
ylim([-0.3 0.3]);
...
subplot(212)
plot(rfreq,abs(Homega6)), grid
xlim([-2*pi 2*pi]);
ylim([0 1.2]);
...
figure,
subplot(211)
stem(n4,hn4), grid
ylim([-0.3 0.3]);
...
subplot(212)
plot(rfreq,abs(Homega7)), grid
xlim([-2*pi 2*pi]);
ylim([0 1.2]);
...


192 4 Filters in Time Domain

Table 4.7 Band pass filter Filter specifications Value


specification example
Filter type Band pass filter
Filter length Finite with optimization
Lower cutoff frequency (fl) 1000 Hz
Upper cutoff frequency (fu) 3000 Hz
Sampling frequency (fs) 8000 Hz

The succeeding type of the filter is the band pass filter (BPF) which passes the
frequency range specified by the lower and upper bound. The design method is
identical to the HPF procedure except the variable frequency shift location.
Example 4.11
Design the BPF for Table 4.7. Use the LPF from truncated DFT method for 20
sample length.
Solution
Based on the information, the lower and upper cutoff frequency corresponds to the p=4
and 3p=4 respectively in discrete frequency. Upon the symmetric distribution
constraint, the BPF requirement is illustrated in Fig. 4.45 over discrete frequency domain.
The passing band contains p=2 width and the band midpoint is located at p=2.
We can consider the BPF design from the previous shift method that relocates
the LPF to the right direction. The upper subplot in Fig. 4.46 demonstrates the one
direction shift with p=2 that destroys the symmetric frequency distribution. In this
p
case, the derived impulse response includes the complex number ðhLPF ½nej2n ¼
hLPF ½njn Þ which cannot be realized in the convolution sum. Instead of unidirec-
tional shift, the bidirectional relocation shown in Fig. 4.46 conserves the symmetric
profile. Since the bidirectional movement takes place in every 2p locations, the
shifted edge cannot cross the discrete frequency boundary that is the p of the
individual 2ps.
The linear combination of each direction shift is represented by below equation.
 p p 
p 
hBPF ½n ¼ hLPF ½n ej2n þ ej2n ¼ 2hLPF ½n cos n
2

Fig. 4.45 Frequency distribution for desired BPF


4.5 Simple Filter Design 193

Fig. 4.46 Frequency shift for LPF ! BPF

Figures 4.47 and 4.48 show the fundamental LPF and the shifted LPF (BPF).
The designed BPF provides the relatively flat gains over the p=4 and 3p=4 range
which meet the initial filter requirement in Table 4.7. If you need the flatter and
shaper BPF for better frequency separation, use the longer length in LPF then apply
the frequency shift for repositioning.

0.4
h LPF [n]

0.2

-0.2

-0.4
-10 -8 -6 -4 -2 0 2 4 6 8 10
n

1
|HLPF (ej )|

0.5

0
-2 - -3 /4 - /2 - /4 0 /4 /2 3 /4 2
Radian frequency ( )

Fig. 4.47 Impulse response and frequency response of baseline LPF


194 4 Filters in Time Domain

Prog. 4.23 MATLAB program for Figs. 4.47 and 4.48


syms omega real;
rfreq = linspace(-2*pi,2*pi,1000);
n2 = -50:1:49;
hn2 = 0.01*sin(25*pi*(n2+eps)/100)./sin(pi*(n2+eps)/100);
n3 = 42:61;
hn3 = hn2(n3);
n4 = -9:1:10;
hn4 = 2*hn3.*cos(pi*n4/2);
coeff = exp(1j*omega*n4);
Hint2 = hn3.*coeff;
Hint3 = hn4.*coeff;
Homega2 = sum(Hint2);
Homega3 = sum(Hint3);
Homega4 = subs(Homega2,omega,rfreq);
Homega5 = subs(Homega3,omega,rfreq);
Homega6 = eval(Homega4);
Homega7 = eval(Homega5);

figure,
subplot(211)
stem(n4,hn3), grid
ylim([-0.4 0.6]);
...
subplot(212)
plot(rfreq,abs(Homega6)), grid
xlim([-2*pi 2*pi]);
ylim([0 1.2]);
...
figure,
subplot(211)
stem(n4,hn4), grid
ylim([-0.4 0.6]);
...
subplot(212)
plot(rfreq,abs(Homega7)), grid
xlim([-2*pi 2*pi]);
ylim([0 1.2]);
...


4.5 Simple Filter Design 195

0.4
h BPF [n]
0.2

-0.2

-0.4
-10 -8 -6 -4 -2 0 2 4 6 8 10
n

1
|HBPF (ej )|

0.5

0
-2 - -3 /4 - /2 - /4 0 /4 /2 3 /4 2
Radian frequency ( )

Fig. 4.48 Designed BPF from LPF transformation

The last type of the filter shown in this chapter is the band stop filter
(BSF) which blocks the frequency range specified by the lower and upper bound.
The design method follows the BPF procedure with additional step that inverts the
filter magnitude as low to high and high to low gain.
Example 4.12
Design the BSF for Table 4.8. Use the LPF from truncated DFT method for 20
sample length.
Solution
The above parameters are identical to the BPF design values except the lower and
upper frequency specify the blocking instead of passing range. The lower and upper
cutoff frequency corresponds to the p=4 and 3p=4 respectively in discrete fre-
quency. Similar to the flipped version of BPF, the BSF requirement is illustrated
below in discrete frequency domain as Fig. 4.49.

Table 4.8 Band stop filter Filter specifications Value


specification example
Filter type Band stop filter
Filter length Finite with optimization
Lower cutoff frequency (fl) 1000 Hz
Upper cutoff frequency (fu) 3000 Hz
Sampling frequency (fs) 8000 Hz
196 4 Filters in Time Domain

Fig. 4.49 Frequency distribution for desired BSF

... 1
...
ω
1
Subtract = ... ...
ω

... 1
...
ω

Fig. 4.50 Magnitude inversion for BPF ! BSF

The magnitude inversion in frequency domain can be described as the sub-


tracting the frequency response from the designated gain in the BPF as shown in
Fig. 4.50. The BPF gain should agree with the subtracting constant and real
number; otherwise, the inversion cannot be exercised properly.
The magnitude inversion is mathematically represented in below equation. The
subtracting with constant in frequency domain is equivalent to the deduction from
the delta function in time domain. According to the linearity in DFT, the individual
function is transformed separately for overall operation.

DFT
d½n  x½n $ 1  X ½k  for X ½k 2 R and GainðX ½k Þ ¼ 1

Figures 4.51 and 4.52 shows the fundamental BPF and the magnitude inverted
BPF (BSF). The designed BSF provides the flat low over the p=4 and 3p=4 and
gain one in the other range which meet the initial filter requirement in Table 4.8 If
you need the flatter low and shaper edge BSF for better frequency separation, use
the longer length in LPF then apply the frequency shift and magnitude inversion
sequentially.
4.5 Simple Filter Design 197

0.4
h BPF [n]
0.2

-0.2

-0.4
-10 -8 -6 -4 -2 0 2 4 6 8 10
n

1
|HBPF (ej )|

0.5

0
-2 - -3 /4 - /2 - /4 0 /4 /2 3 /4 2
Radian frequency ( )

Fig. 4.51 Impulse response and frequency response of baseline BPF

0.4
h BSF [n]

0.2

-0.2

-0.4
-10 -8 -6 -4 -2 0 2 4 6 8 10
n

1
|HBSF (ej )|

0.5

0
-2 - -3 /4 - /2 - /4 0 /4 /2 3 /4 2
Radian frequency ( )

Fig. 4.52 Designed BSF from BPF with magnitude inversion


198 4 Filters in Time Domain

Prog. 4.24 MATLAB program for Figs. 4.51 and 4.52


syms omega real;
rfreq = linspace(-2*pi,2*pi,1000);
n2 = -50:1:49;
hn2 = 0.01*sin(25*pi*(n2+eps)/100)./sin(pi*(n2+eps)/100);
n3 = 42:61;
hn3 = hn2(n3);
n4 = -9:1:10;
hn4 = 2*hn3.*cos(pi*n4/2);
temparr = zeros(size(n4));
temparr(10) = 1;
hn5 = temparr-hn4;
coeff = exp(1j*omega*n4);
Hint2 = hn4.*coeff;
Hint3 = hn5.*coeff;
Homega2 = sum(Hint2);
Homega3 = sum(Hint3);
Homega4 = subs(Homega2,omega,rfreq);
Homega5 = subs(Homega3,omega,rfreq);
Homega6 = eval(Homega4);
Homega7 = eval(Homega5);
figure,
subplot(211)
stem(n4,hn4), grid
ylim([-0.4 0.6]);
...
subplot(212)
plot(rfreq,abs(Homega6)), grid
xlim([-2*pi 2*pi]);
ylim([0 1.2]);
...
figure,
subplot(211)
stem(n4,hn5), grid
ylim([-0.4 0.6]);
...
subplot(212)
plot(rfreq,abs(Homega7)), grid
xlim([-2*pi 2*pi]);
ylim([0 1.2]);
...


4.5 Simple Filter Design 199

Time Shi for Final


Causality Low Pass Filter

Frequency Time Shi for Final


Low Pass Filter High Pass Filter
Inversion Causality High Pass Filter

Frequency Time Shi for Final


Band Pass Filter
Shi Causality Band Pass Filter

Magnitude
Inversion

Time Shi for Final


Band Stop Filter
Causality Band Stop Filter

Fig. 4.53 Transformation procedures for various filter types from LPF

Up to now, we have explored the various types of filters as LPF, HPF, BPF, and
BSF. The LPF is the building fundamental for the other filter types to specify the
designated frequency band for passing or blocking. Further mathematical pro-
cessing makes the LPF to other types as shown in Fig. 4.53. Note that the frequency
shift to the p is described as the frequency inversion in the diagram since the filter
profile is completely inverted in term of frequency distribution. At the end of design
procedure, time shift is performed for the filter causality.
In this chapter, the filter architecture (convolution sum) shown in the Chap. 1 is
extended for the further analysis. The linearity, time-invariance, and causality of the
filter are discussed for the convolution sum. The infinite length filter can be realized
by the recursive feedback that uses the recent outputs in addition to the input. The
Fourier transform simplifies the convolution sum to the multiplication in frequency
domain; therefore, impulse response in frequency domain known as frequency
response specify the filter property. Based on the understanding above, the various
types of the filter are derived and implemented in last part. The next chapter
introduces the generalized transform as Z-transform to describe, design and analysis
the comprehensive filters that includes the infinite length filter.

4.6 Problems

1. If you have the unit-step response, explain the method to obtain the impulse
response from the given information. The unit-step response is the output of the
system from the unit-step input.
200 4 Filters in Time Domain

2. If we have the individual filters as impulse response h1[n] and h2[n], derive the
overall response of the system in cascade and parallel connection as shown
below. Use the convolution sum notation * for final representation.

X
1 X
1
y ½ n ¼ x½kh½n  k  ¼ h½k x½n  k
k¼1 k¼1

¼ x½n  h½n ¼ h½n  x½n

Parallel connection

Cascade connection h1[n]

x1[n] h1[n] h2[n] y1[n] x2[n] + y2[n]

h2[n]

3. Design the digital integrator by using the first order IIR filter which use the
y[n–1] with constant coefficient. Note that the integrator performs the accu-
mulation over the all input data.
4. Design the digital differentiator by using the FIR filter. Observe that the dif-
ferentiator performs the subtraction between the current and previous input. Find
the impulse response.
5. The BIBO stability of the system can be tested by using the following equation.

X
1
jh½kj\1
k¼0

Derive the condition for unstable FIR filter.


6. In order to limit the filter output as below, what should we do? Remember this is
the filter.

jy½nj  4xmax 8n

7. Compute the filter output of below configuration with DTFT method.

x½n ¼ u½n  u½n  3

h½ n ¼ d½ n  d½ n  1
4.6 Problems 201

8. Compute the filter output of below configuration with DFT method. Use the
proper length N.

x½n ¼ u½n  u½n  3

h½ n ¼ d½ n  d½ n  1

9. Design the LPF for the below Table. Use the DTFT method. Show the impulse
response from –20 to 20 as n.

Filter specifications Value


Filter type Low pass filter
Filter length Finite with optimization
Cutoff frequency (fc) 1000 Hz
Sampling frequency (fs) 16000 Hz

10. Draw the frequency response of 95 and 99% for the frequency domain energy
from the previous problem.
11. Design the LPF for Problem 9 Table. Use the DFT method. Show the impulse
response from 0 to 99 as n.
12. Design the LPF for Problem 9 Table. Use the DFT method. Show the impulse
response from 0 to 19 as n.
13. Design the LPF for Problem 9 Table. Use the truncated DFT method for 20
sample length. Design the filter from length 100.
14. Design the HPF for the below Table. Use the LPF from truncated DFT method
for 20 sample length. Design the filter from length 100.

Filter specifications Value


Filter type High pass filter
Filter length Finite with optimization
Cutoff frequency (fc) 7000 Hz
Sampling frequency (fs) 16000 Hz
202 4 Filters in Time Domain

15. Design the BPF for the below Table. Use the LPF from truncated DFT method
for 20 sample length. Design the filter from length 100.

Filter specifications Value


Filter type Band pass filter
Filter length Finite with optimization
Lower cutoff frequency (fl) 3000 Hz
Upper cutoff frequency (fu) 5000 Hz
Sampling frequency (fs) 16000 Hz

16. Design the BSF for the below Table. Use the LPF from truncated DFT method
for 20 sample length. Design the filter from length 100.

Filter specifications Value


Filter type Band stop filter
Filter length Finite with optimization
Lower cutoff frequency (fl) 3000 Hz
Upper cutoff frequency (fu) 5000 Hz
Sampling frequency (fs) 16000 Hz

References

1. Taylor, A.E.: L’Hospital’s Rule. Am. Math. Monthly 59(1), 20–24 (1952). https://doi.org/10.
1080/00029890.1952.11988058
2. Hazewinkel, M.: Encyclopaedia of Mathematics: Orbit - Rayleigh Equation. Springer,
Netherlands (2012)
Chapter 5
Z-Transform

The fundamentals of the FIR filter design have been explored and investigated so
far. The FIR filter designer can find the dedicated methods to control the edges,
passing, and stopping band for sophisticated filter design. The essential design
procedure of further controlled filter is practically identical to the presented
approach with couple of more steps. How about the IIR filter? Upon the best
knowledge now, choose the arbitrary coefficients for recursive feedback, derive the
impulse response by hand or computer, then obtain the frequency response for filter
compliance on the requirement. The convolution sum, DTFT, and DFT barely
represent the IIR filter property directly. The Z-transform is the generalized trans-
form for the discrete time domain to describe comprehensive signals and systems.
By the Z-transform, the simple rational polynomial function denotes the IIR filter
system and pole zero plot visualizes the filter property. The Z-transform extends the
design method for the IIR as well as FIR filter.

5.1 Definition and Usage

The Z-transform provides the enhanced tool to understand the signal and system
further between time and frequency domain. To understand the meaning of the
enhancement, we need to consider the limitation of the DTFT and DFT first. Let’s
revisit the transforms for the discrete time signal as below in Table 5.1.
All transforms shown above are performed based on the periodic signal
 
ejxn or ej2pkn=N that rotates unit circle in the complex domain at xðor 2pk=N Þ rate.
The periodic signal magnitude is given by the X ðejx Þðor X ½k Þ that assumes to be the
constant value for the signal length. If we want to use the exponentially increasing or
decreasing periodic or non-periodic signal, certain linear combination of the fre-
quency components is required to represent the signal by the transformation. We can
simplify this situation by extending the primitive element of the transform as below.

© Springer Nature Singapore Pte Ltd. 2021 203


K. Kim, Conceptual Digital Signal Processing with MATLAB,
Signals and Communication Technology,
https://doi.org/10.1007/978-981-15-2584-1_5
204 5 Z-Transform

Table 5.1 Transforms for discrete time signal


Discrete-time Fourier transform (DTFT) Discrete Fourier transform (DFT)
Analysis P
1 Analysis P
N1
X ðejx Þ ¼ x½nejxn X ½k  ¼ xN ½nej N kn
2p

n¼1 n¼0
pR
Synthesis x½n ¼ 2p
1
X ðejx Þejxn dx Synthesis P
N1 2p
p xN ½n ¼ N1 X ½k ej N kn
k¼0

 
ejx ! z ¼ rejx jr 2 R and x 2 R 2 C ð5:1Þ

The power of the z represents the r n ejxn which shows the exponential variation
with periodicity inside. Plug in the new exponential part to the transform provides
the new transformation known as Z-transform [1] below. Note that the z is the
continuous complex number domain.

X
1
X ðzÞ ¼ x½nzn ð5:2Þ
n¼1

What does the Z-transform perform? Similar to the DTFT and DFT, can we
expect to obtain the magnitude and phase of the frequency component as well as the
exponential part? Let’s figure out. The signal model is periodic with exponential
part as Eq. (5.3).

x1 ½n ¼ an ejun ð5:3Þ

Place into the Z-transform as below.

X
1 X
1
X 1 ðzÞ ¼ x1 ½nzn ¼ x1 ½nr n ejxn
n¼1 n¼1
1  n
ð5:4Þ
X1 X a jðuxÞn
¼ an ejun r n ejxn ¼ e
n¼1 n¼1
r

You may remember the DTFT analysis procedure for orthogonality between the
frequency components.

X
1
ejðx1 xÞn ¼ 2pdðx1  xÞ ð5:5Þ
n¼1

The orthogonality provides the frequency selection to represent the individual


spectral complex magnitude. However, the Z-transform cannot guarantee the
orthogonality due to the time variant exponential weight with real number a=r.
Therefore, the Z-transform does not deliver the individual spectral magnitude in
anyway. In different perspectives, we may organize the Z-transform as below.
5.1 Definition and Usage 205

x2 ½n ¼ an ejun u½n ð5:6Þ


X
1 X
1 X
1  n
X 2 ðzÞ ¼ x½nzn ¼ an ejun zn ¼ aeju z1
n¼1 n¼0 n¼0 ð5:7Þ
1 z  
¼ 1
¼ for aeju z1 \1
1  ae z
ju z  aeju

By using the sum of the infinite geometric series, the given signal can be denoted
by the rational function with certain condition. The infinite length signal is reduced
to the simpler form as rational function. Since the Z-transform is the linear trans-
form as Eq. (5.8), the linear combination of time variant exponential weight peri-
odic signals can be transformed to the corresponding linear combination of rational
functions.

X
1 X
1 X
1
ðax½n þ by½nÞzn ¼ a x½nzn þ b y½nzn ð5:8Þ
n¼1 n¼1 n¼1

Instead of computing the magnitude, the Z-transform converts the infinite geo-
metric series to the straightforward rational function.

1 z  
for az1 \1 orjzj [ jaj
Z
an u ½ n  $ 1
¼ ð5:9Þ
1  az za

The condition to converge the geometric series is controlled by the z values


known as the region of convergence (ROC). The signal ratio multiplied with z1
provides the Z-transform common ratio which should be less than one in absolute
magnitude. The inequality over the absolute z value specifies the ROC and the
corresponding region is indicated by the circular fashion. Equation (5.10) shows the
mathematical definition of the ROC.

ROC of Z fx½ng ¼ fzjjX ðzÞj\1g ð5:10Þ

The ROC is defined by the signal distribution profile.


Causal signal:

xc ½n ¼ 0 for n\0 ð5:11Þ

Let xc ½n ¼ an ejxn u½n


X1 X
1 X
1
Xc ðzÞ ¼ xc ½nzn ¼ an ejxn zn ¼ ðaejx z1 Þn \1
n¼1 n¼0 n¼0
 jx 1    
ae z \1 ! aejx z1 \1
 
! jzj [ aejx  ! jzj [ jaj ð5:12Þ
206 5 Z-Transform

Anti-causal signal:

xa ½n ¼ 0 for n [ 0 ð5:13Þ

Let xa ½n ¼ bn ejxn u½n


X
1 X
0 X
1
X a ð zÞ ¼ xa ½nzn ¼ bn ejxn zn ¼ bn ejxn zn
n¼1 n¼1 n¼0
X1
¼ ðb1 ejx zÞn \1
n¼0
 1 jx   
b e z\1 ! b1 ejx jzj\1
 
! jzj\bejx  ! jzj\jbj ð5:14Þ

Non-causal signal:

xnc ½n ¼ xc ½n þ xa ½n ð5:15Þ

Let xnc ½n ¼ an ejxn u½n þ bn ejxn u½n


X
1 X
1 X
0
Xnc ðzÞ ¼ xnc ½nzn ¼ an ejxn zn þ bn ejxn zn
n¼1 n¼0 n¼1
X1 X
1
ð5:16Þ
¼ ðaejx z1 Þn þ ðb1 ejx zÞn
n¼0 n¼0
 jx 1   
ae z \1 and b1 ejx z\1 ! jaj\jzj\jbj
ROCfXnc ðzÞg ¼ ROCfXc ðzÞg \ ROCfXa ðzÞg

Finite-support signal:

xf ½n ¼ xnc ½nfu½n  N1   u½n  N2 g


ð5:17Þ
for  1\N1 \0\N2 \1

X
1 X
N2
X f ð zÞ ¼ xf ½nzn ¼ xf ½nzn
n¼1 n¼N1

¼ xf ½N1 zN1 þ . . . þ xf ½1z1 þ xf ½0z0 þ xf ½1z1 ð5:18Þ


N2
þ . . . þ xf ½N2 z
 
ROC Xf ðzÞ ¼ fzjz 6¼ 0 and z 6¼ 1g

Table 5.2 illustrates the Z-transforms for fundamental discrete signals.


5.1 Definition and Usage 207

Table 5.2 Z-transforms for fundamental discrete time signals


x½n X ðzÞ ROC
d½n 1 Whole z plane
u½n 1z1 ¼ z1
1 z jzj [ 1
an u½n 1az1 ¼ za
1 z jzj [ jaj

cosðx0 nÞu½n 1 1 1 jzj [ 1


1
þ jx 1
jx0 n
e jx0 n
þe 2 1  e 0z
jx 1  e 0z
¼ u½n
2 1  z1 cosðx0 Þ
¼
1  2z1 cosðx0 Þ þ z2

sinðx0 nÞu½n 1 1 1 jzj [ 1


1
 jx 1
jx0 n
e e jx0 n 2j 1  e 0 z
jx 1  e 0z
¼ u½n
2j z1 sinðx0 Þ
¼
1  2z1 cosðx0 Þ þ z2

Example 5.1
Find the Z-transform of following signals

x1 ½n ¼ 4d½n  3d½n  1 þ 2d½n  2  d½n  3


x2 ½n ¼ an cosðx0 nÞu½n
x3 ½n ¼ u½n

Solution

X
1
X1 ðzÞ ¼ x1 ½nzn ¼ 4  3z1 þ 2z2  z3
n¼1
ROCfX1 ðzÞg ¼ fzjz 2 C and z 6¼ 0g
X
1 X
1
X2 ðzÞ ¼ x2 ½nzn ¼ an cosðx0 nÞzn
n¼1 n¼0
X þ an ejx0 n n 1 X
1 n jx0 n
a e 1  n 1 X 1  n
¼ z ¼ aejx0 z1 þ aejx0 z1
n¼0
2 2 n¼0
2 n¼0

1
1 1 1 1  az cosðx0 Þ
¼ þ ¼
2 1  aejx0 z1 1  aejx0 z1 1  2az1 cosðx0 Þ þ a2 z2
 jx 1   
ae 0 z \1 and aejx0 z1 \1
 
! az1 \1 ! 1\az1 \1 ! z\a\z
! jzj [ jaj
ROCfX2 ðzÞg ¼ fzjz 2 C and jzj [ jajg
208 5 Z-Transform

X
1 X
1 X
0
X3 ðzÞ ¼ x3 ½nzn ¼ u½nzn ¼ zn
n¼1 n¼1 n¼1
X1
1 z1
¼ z ¼n
¼
n¼0
1  z 1  z1
ROCfX3 ðzÞg ¼ fzjz 2 C and jzj\1g


The primitive element (eigenfunction) of the DTFT, DFT, and Z-transform is the
ejx , ej2pk=N , and z ¼ rejx respectively. Therefore, the signal is indicated by the
corresponding primitive elements those are distributed over the continuous unit
circle for DTFT, discrete unit circle for DFT, and whole complex plane for
Z-transform as shown in Fig. 5.1.
The Z-transform occupies all type of the signal that contains the continuous
frequency periodic signal with subset of the discrete frequency periodic signal.
Once the Z-transform is performed, we can convert to the DTFT or DFT by
replacing the z with complex exponential as shown in Eq. (5.19).
8
<$Z
X ðzÞjz¼ejx ¼ X ðejx Þ : DTFT
x ½ n ð5:19Þ
: $X ðzÞj
Z
2p ¼ X ½k  : DFT
z¼ej N k

Basically, the Z-transform is also the transformation with the power of complex
number exponential similar to the DTFT and DFT; therefore, the Z-transform
follows the most of DTFT and DFT properties. The conventional Z-transform
properties are organized in Table 5.3.

Fig. 5.1 DTFT, DFT, and Z


in complex number domain imag Z

DFT
DTFT
1

real
5.1 Definition and Usage 209

Table 5.3 Z-transforms properties


Property Time domain x[n] z domain X(z)
Time shift x½n  d  X ðzÞzd
Time reversal x½n X ðz1 Þ
Real signal x½n 2 R X ðzÞ ¼ X  ðz Þ
Convolution x½n  h½n X ðzÞH ðzÞ
Initial value theorem x½n ¼ x½nu½n x½0 ¼ lim X ðzÞ
z!1
Final value theorem x½n ¼ x½nu½nand lim x½n ¼ x½1 x½1 ¼ limðz  1ÞX ðzÞ
n!1 z!1

Example 5.2
Find the Z-transform of following signals

x½n ¼ nu½n

Compute the following values by using the initial value and final value theorem.

x½0 ¼
x½1 ¼

Check the below condition in z domain.

x ½ n 2 R

If the new x[n] is below, check the real value condition again.

x½n ¼ jnu½n

Solution
The given function can be decomposed as below.

nu½n ¼ u½n  u½n  1


z 1 z z1
u½ n $ 1
u½n  1 $
1z 1  z1
z 1 z1 z1
u½n  u½n  1 $ 1 1
¼
1z 1z ð1  z1 Þ2
ROCfX ðzÞg ¼ fzjjzj [ 1g

By using the initial value and final value theorem, find x[0] and x½1 as below.
210 5 Z-Transform

z1
x½0 ¼ lim X ðzÞ ¼ lim ¼0
z!1 z!1 ð1  z1 Þ2
z1
x½1 ¼ limðz  1ÞX ðzÞ ¼ limðz  1Þ
z!1 z!1 ð1  z1 Þ2
z
¼ lim ¼1
z!1 ðz  1Þ

Determine the real value condition of x[n] by using the following property.

X ðzÞ ¼ X  ðz Þ
0 1  
 1
B ðz Þ  1
C ð z Þ
X  ð z  Þ ¼ @ 2 A ¼    
1  ðz Þ
 1 1  ðz Þ1 1  ðz Þ1

z1
¼ ¼ X ðzÞ
ð1  z1 Þ2

From the new given signal below, check the real value condition.

z jz1
x½n ¼ jnu½n $ X ðzÞ ¼
ð1  z1 Þ2
0 1  
jðz Þ1 j ðz Þ1
B C
X  ð z  Þ ¼ @ 2 A ¼    
1  ðz Þ
 1 1  ðz Þ1 1  ðz Þ1

jz1
¼ 6¼ X ðzÞ
ð1  z1 Þ2
)x½n 62 R


The proof of the above relationships can be easily derived by the DTFT and DFT
properties. The DTFT and DFT use the x and k for the frequency distribution over
the one-dimensional axis; however, the Z-transform delivers the information based
on the z domain which represents the two-dimensional space with r distance and x
angle. Therefore, the z1 and z indicate the r 1 ejx and rejx for z ¼ rejx ,
respectively as shown in Fig. 5.2.
The real signal property for the Z-transform is shown below.
5.1 Definition and Usage 211

Fig. 5.2 Illustration of z ¼ 0:5ejp=4 , z ¼ 0:5ejp=4 , z1 ¼ 2ejp=4

x½n 2 R ! x½n ¼ x ½n


X
1
X ð zÞ ¼ x½nzn
n¼1
( ) ð5:20Þ
X
1 X
1 X
1
 n  n   n  
x ½nz ¼ fx½nðz Þ g ¼ x½nðz Þ ¼ X ðz Þ
n¼1 n¼1 n¼1

x½n 2 R ! x½n ¼ x ½n ! X ðzÞ ¼ X  ðz Þ

Hence, the Z-transform of the real signal denotes conjugate pair between the one
location (z) and symmetric position (z*) over the real axis on the z plane. The
graphical representation of the above condition is illustrated in Fig. 5.3.
We can figure out the initial and final value of the given causal sequence in the
z domain as below.

Fig. 5.3 Conjugated pairing


for real signal condition in
z domain
212 5 Z-Transform

Initial value theorem: x[n] is causal

x½0 ¼ lim X ðzÞ ð5:21Þ


z!1

Proof

x½n ¼ x½nu½n
X
1
X ð zÞ ¼ x½nzn ¼ x½0 þ x½1z1 þ x½2z2 þ x½3z3 þ . . . þ x½1z1
n¼0
 
lim X ðzÞ ¼ lim x½0 þ x½1z1 þ x½2z2 þ x½3z3 þ . . . þ x½1z1
z!1 z!1
¼ x½0 þ x½10 þ x½20 þ x½30 þ . . . þ x½10 ¼ x½0


Final value theorem: x[n] is causal

x½1 ¼ limðz  1ÞX ðzÞ ð5:22Þ


z!1

Proof We assume that the signal asymptotically converges to the constant value
x½1 as below.

x½n ¼ x½nu½n and lim x½n ¼ x½1


n!1

And decomposed as below.

x½n ¼ x½1u½n þ w½n lim w½n ¼ 0


n!1

The example of w[n] is shown in Fig. 5.4.


In order to approach zero, the w½n common ratio (or pole) should be located
within the unit circle in the z plane.
z
X ðzÞ ¼ Z fx½1u½n þ w½ng ¼ x½1 þ W ðzÞ
z1

According to the Z-transform above, X(z) contains the (z − 1) factor in the


denominator. However, W(z) cannot include the (z − 1) factor in the denominator
because of the common ratio constraint in the w[n].

ðz  1ÞX ðzÞ ¼ x½1z þ ðz  1ÞW ðzÞ


limðz  1ÞX ðzÞ ¼ lim x½1z þ limðz  1ÞW ðzÞ
z!1 z!1 z!1
5.1 Definition and Usage 213

Fig. 5.4 Example of w[n]


with envelope

w[n]
0

The (z − 1) with W(z) cannot be cancelled out; hence, the last term goes to zero.
Finally,

limðz  1ÞX ðzÞ ¼ x½1


z!1


The inverse Z-transform can be derived from the DTFT as below.

X
1 X
1
X ðzÞ ¼ x½nzn ¼ ðx½nr n Þejxn ¼ DTFTfx½nr n g
n¼1 n¼1
n DTFT
x½nr $ X ðzÞ
Zp
1
x½nr n ¼ X ðzÞejxn dx
2p
p
Zp Zp ð5:23Þ
1 1
x½n ¼ X ðzÞr e
n jxn
dx ¼ X ðzÞz dx
n
2p 2p
p p
1
where z ¼ rejx and dx ¼ z1 dz
j
I
1
x½n ¼ X ðzÞzn1 dz
2pj

Due to the contour integral over the complex domain, the inverse Z-transform is
barely performed to compute the time domain information. By using the
Z-transform linearity, the long division and partial fraction method are employed
for the inverse Z-transform. Basically, we prefer to build following situation in
Eq. (5.24).
214 5 Z-Transform

x½n ¼ a0 r0n ejx0 n u½n þ a1 r1n ejx1 n u½n þ a2 r2n ejx2 n u½n þ . . .
Z a0 a1 a2 ð5:24Þ
$ X ðzÞ ¼ 1
þ 1
þ þ...
1  r0 e z
jx 0 1  r1 e z
jx 1 1  r2 ejx2 z1

Once we obtain the linear combination of the first-degree rational functions, the
corresponding time domain function can be simply derived by individual replace-
ment based on the Z-transform table. If the given z function is the high order
rational function, the long division and partial fraction method are required to
decompose the function for the convenient inverse transformation. The general high
order rational z function is shown in Eq. (5.25).

b0 þ b1 z1 þ b2 z2 þ . . . þ bn zn


X ðzÞ ¼ ð5:25Þ
a0 þ a1 z1 þ a2 z2 þ . . . þ am zm

The numerator and denominator are presented by the n and m degree polyno-
mial, respectively. If the numerator has the higher degree than the denominator,
long division is necessary to reduce the numerator degree. Polynomial long division
[2] is illustrated in Fig. 5.5.
The example above considers the high order polynomial with two-degree dif-
ference between the numerator and denominator. The b2 ; b1 , and b0 are provided to
remove the highest negative order at dividend; therefore, each division procedure
generates the reduced order at numerator polynomial. Once the remainder order is
less than the divisor, stop further division and organize the equation as below.

b0 þ b1 z1 þ b2 z2 þ . . . þ bn zn


X ðzÞ ¼ ¼ b2 z2 þ b1 z1 þ b0
a0 þ a1 z1 þ a2 z2 þ . . . þ am zm
ð5:26Þ
c0 þ c1 z1 þ . . . þ cn3 zðn3Þ
þ for n ¼ m þ 2
a0 þ a1 z1 þ a2 z2 þ . . . þ am zm

The rational function can be further decomposed into the linear combination of
first order rational functions as Eq. (5.27). The partial fraction method finds the
coefficients of the linearly divided rational functions as q1 , q2 , and qm . Numerous

Fig. 5.5 Example of polynomial long division for Eq. (5.25)


5.1 Definition and Usage 215

approaches are possible to solve the partial fraction method that can be found on the
various algebra books [2] and webs [3].

c0 þ c1 z1 þ . . . þ cn3 zðn3Þ


QðzÞ ¼
a0 þ a1 z1 þ a2 z2 þ . . . þ am zm
c0 þ c1 z1 þ . . . þ cn3 zðn3Þ
¼
ð1  l1 z1 Þð1  l2 z1 Þ. . .ð1  lm z1 Þ
q1 q2 qm
¼ þ þ...þ ð5:27Þ
ð1  l1 z Þ ð1  l2 z Þ
1 1 ð1  lm z1 Þ

Also, the function can be handled by the positive power of the polynomial as
below.

c0 þ c1 z1 þ . . . þ cn3 zðn3Þ


QðzÞ ¼
a0 þ a1 z1 þ a2 z2 þ . . . þ am zm
 
zm c0 zðn3Þ þ c1 zðn3Þ1 þ . . . þ cn3
¼ ðn3Þ
z ða0 zm þ a1 zm1 þ a2 zm2 þ . . . þ am Þ
 ðn3Þ 
z c0 z þ c1 zðn3Þ1 þ . . . þ cn3
¼ since n ¼ m þ 2
ða0 zm þ a1 zm1 þ a2 zm2 þ . . . þ am Þ ð5:28Þ
 ðn3Þ 
QðzÞ c0 z þ c1 zðn3Þ1 þ . . . þ cn3
¼
z ða0 zm þ a1 zm1 þ a2 zm2 þ . . . þ am Þ
q1 q2 qm
¼ þ þ...þ
ðz  l1 Þ ðz  l2 Þ ð z  lm Þ
q1 z q2 z qm z
QðzÞ ¼ þ þ...þ
ðz  l1 Þ ðz  l2 Þ ðz  lm Þ

Therefore, the final decomposed form of the rational polynomial is given below.

X ðzÞ ¼ b2 z2 þ b1 z1 þ b0 þ


q1 q2 qm ð5:29Þ
ð1l1 z1 Þ þ ð1l2 z1 Þ þ...þ ð1lm z1 Þ

The corresponding time domain representation is derived by simple substitutions


as shown in Eq. (5.30). Assume that the signal is causal.

x½n ¼ b2 d½n  2 þ b1 d½n  1 þ b0 d½n


ð5:30Þ
þ ln1 u½n þ ln2 u½n þ . . . þ lnm u½n

The damped (or non-damped) sinusoid can be illustrated by the common ratio
form as well for simple Z-transform as below. Further simplification is available
and can be found in the conventional Z-transform table [4, 5].
216 5 Z-Transform

r n ejðxn þ hÞ þ r n ejðxn þ hÞ
r n cosðxn þ hÞu½n ¼ u½ n
2
ejh  jx n ejh  jx n
¼ re u½ n þ re ð5:31Þ
2 2
Z e
jh
1 ejh 1
$ 1
þ
2 ð1  re z Þ jx 2 ð1  rejx z1 Þ

The Z-transform provides the rational function to represent the geometric series
distribution in the time domain signal. The common ratios of the geometric series
can be observed in the denominator factor forms even with the combining proce-
dure over the individual first-degree rational functions. The ROC decides the signal
time style in terms of length and direction. The conventional causal signal covers
the ROC over the outside of the biggest common ratio distance. The inverse process
of the Z-transform is performed by the long division and partial fraction method in
order to linearly decompose the high order rational function into the first-degree
rational functions. Simple replacements of the individual terms denote the corre-
sponding time domain functions.
Example 5.3
Find the inverse Z-transform of following signals. Assume that all signals are causal.
   
X1 ðzÞ ¼ 2 1  z1 1 þ 2z1 1 þ 0:5z1
3  2z1 þ z2
X 2 ðzÞ ¼
1  z1 þ z2  z3
7  26z1 þ 17z2 þ 16z3  12z4
X 3 ðzÞ ¼
1  6z1 þ 11z2  6z3

Solution
   
X1 ðzÞ ¼ 2 1  z1 1 þ 2z1 1 þ 0:5z1
z
¼ 2 þ 3z1  3z2  2z3 $ 2d½n þ 3d½n  1  3d½n  2  2d½n  3
3  2z1 þ z2 1 1 1
X2 ðzÞ ¼ ¼ þ þ
1  z1 þ z2  z3 1  z1 1  jz1 1 þ jz1
z p p
p 
$ u½n þ ej2n u½n þ ej2n u½n ¼ u½n þ 2 cos n u½n
2
7  26z1 þ 17z2 þ 16z3  12z4
X3 ðzÞ ¼
1  6z1 þ 11z2  6z3
1 2 3
¼ 1 þ 2z1 þ þ þ
1  z1 1  2z1 1  3z1
z
$ d½n þ 2d½n  1 þ u½n þ 2  2n u½n þ 3  3n u½n


5.2 Filter and Z-Transform 217

5.2 Filter and Z-Transform

The variable z in the Z-transform illustrates the two-dimensional space in the


complex number domain. Hence, the visualization of the transform requires the
three-dimensional illustration. Let’s consider the below function.

ðz þ 0:8Þðz  0:5jÞðz þ 0:5jÞ


X ðzÞ ¼ p p
ðz  0:8Þðz  0:8ej4 Þðz  0:8ej4 Þ
ð1 þ 0:8z1 Þð1  0:5jz1 Þð1 þ 0:5jz1 Þ
¼ p p ð5:32Þ
ð1  0:8z1 Þð1  0:8ej4 z1 Þð1  0:8ej4 z1 Þ

The complex number z provides the complex number output X(z) in terms of
real/imaginary or magnitude/phase. Figure 5.6 shows the 20 log10 jX ðzÞj distribution
with unit circle in white. Note that the Z-transform does not deliver the individual
spectral magnitude by itself. Therefore, the whole X(z) distribution does not contain
the significant information on spectrum.
Prog. 5.1 MATLAB program for Fig. 5.6

[X,Y] = meshgrid(-3:0.01:3,-3:0.01:3);
z = X+1j*Y;
XZ = abs((z+0.8).*(z-0.5*1j).*(z+0.5*1j)./((z-0.8).*(z-0.8*exp(1j*pi/4)).*(z-
0.8*exp(-1j*pi/4))));
ii1 = find(XZ==max(max(XZ))); % Remove first pole
XZ(ii1) = 1000; % Replace max value
ii1 = find(XZ==max(max(XZ))); % Remove second pole
XZ(ii1) = 1000; % Replace max value
ii1 = find(XZ==max(max(XZ))); % Remove third pole
XZ(ii1) = 1000; % Replace max value
XZ = XZ+0.001; % Replace min value
contourf(X,Y,20*log10(XZ)), grid;
hold on
theta = linspace(0,2*pi);
x1 = cos(theta);
y1 = sin(theta);
plot(x1,y1,'w'), axis equal,hold off; % Unit circle
c = colorbar('Ticks',[-60 60],...
'TickLabels',{'Zero','Infinite'});
xlabel('Real');
ylabel('Imaginary');
xlim([-2 2]);
ylim([-2 2]);
c.Label.String = '20log_{10}|X(z)|';
218 5 Z-Transform

Fig. 5.6 Magnitude of X(z) in decibel for Eq. (5.32)

We discussed that the Z-transform can be converted to the DTFT and DFT by
replacing the z with ejx and ej2pk=N , respectively. The DTFT and DFT is the subset
of the Z-transform as shown in Fig. 5.7. The ejx and ej2pk=N represent the complex
numbers on the unit circle expressed on Fig. 5.6 with white circle. The Z-transform
outcome on the unit circle corresponds to the DTFT and DFT result.

Fig. 5.7 Relationship


between Z-transform, DTFT,
and DFT
5.2 Filter and Z-Transform 219

The evaluation on the unit circle from the given Z-transformed function is shown
in Fig. 5.8. The corresponding DTFT and DFT of the given function is illustrated in
Fig. 5.9. The unfolded version of the unit circle output is identical to the DTFT and
DFT result.

Fig. 5.8 Magnitude of X


(z) on the unit circle for
Eq. (5.32)

Fig. 5.9 Unfolded version of


Fig. 5.8 equivalent to DTFT
(continuous) and DFT
(discrete)
220 5 Z-Transform

Prog. 5.2 MATLAB program for Figs. 5.8 and 5.9

x1 = @(w)cos(w);
y1 = @(w)sin(w);
z1 = @(w)abs(((cos(w)+1j*sin(w))+0.8).*((cos(w)+1j*sin(w))-
0.5*1j).*((cos(w)+1j*sin(w))+0.5*1j)./(((cos(w)+1j*sin(w))-
0.8).*((cos(w)+1j*sin(w))-0.8*exp(1j*pi/4)).*((cos(w)+1j*sin(w))-0.8*exp(-
1j*pi/4))));
z2 = @(w)w*0;

w1 = linspace(-pi,pi,150);
x2 = cos(w1);
y2 = sin(w1);
z3 = abs(((cos(w1)+1j*sin(w1))+0.8).*((cos(w1)+1j*sin(w1))-
0.5*1j).*((cos(w1)+1j*sin(w1))+0.5*1j)./(((cos(w1)+1j*sin(w1))-
0.8).*((cos(w1)+1j*sin(w1))-0.8*exp(1j*pi/4)).*((cos(w1)+1j*sin(w1))-
0.8*exp(-1j*pi/4))));

figure,
fp1 = fplot3(x1,y1,z1), hold on;
fp2 = fplot3(x1,y1,z2);
stem3(x2,y2,z3,'Marker','none');
sca er3([-0.8 0 0],[0 0.5 -0.5],[0 0 0],'o');
sca er3([0.8 0.8*cos(pi/4) 0.8*cos(-pi/4)],[0 0.8*sin(pi/4) 0.8*sin(-pi/4)],[0 0
0],'x'), hold off;
...
xlim([-1.5 1.5])
ylim([-1.5 1.5])

figure,
plot(w1,z3), grid, hold on;
stem(w1,z3,'Marker','none'), hold off;
...
xlim([-pi pi]);

The direct evaluation for spectrum profile requires the computational power due
to the complex number arithmetic. Rough estimation is possible by investigating
the roots of Z-transformed rational function. The roots of the numerator and
denominator polynomial is named zero and pole, respectively. The zero locations
deliver the zero output and pole positions represent the infinite output from the
z function.
5.2 Filter and Z-Transform 221

   
zeros ¼ fzz jX ðzz Þ ¼ 0g poles ¼ zp jX zp ¼ 1 ð5:33Þ

The arbitrary z function is denoted by the rational function and the factors of the
numerator and denominator polynomial provides the zeros and poles of the
z function as shown in Eq. (5.34).

b0 þ b1 z1 þ b2 z2 þ . . . þ bn zn


X ðzÞ ¼
a0 þ a1 z1 þ a2 z2 þ . . . þ am zm
ð1  r1 z1 Þð1  r2 z1 Þ. . .ð1  rn z1 Þ
¼
ð1  l1 z1 Þð1  l2 z1 Þ. . .ð1  lm z1 Þ

zeros ¼ fr1 ; r2 ; . . .; rn g
! ð5:34Þ
poles ¼ fl1 ; l2 ; . . .; lm g

The given example z function shows the following zeros and poles.

ðz þ 0:8Þðz  0:5jÞðz þ 0:5jÞ


X ðzÞ ¼ p p
ðz  0:8Þðz  0:8ej4 Þðz  0:8ej4 Þ
ð5:35Þ
zeros ¼ f0:8; 0:5j; 0:5jg : o mark on z  plane
!  p p
poles ¼ 0:8; 0:8ej4 ; 0:8ej4 : x mark on z  plane

The computed zeros and poles are presented on Fig. 5.8 by o and x mark,
individually. We can observe that the radian frequency closer to the poles produce
the high magnitude and closer to zeros generate the low magnitude in Fig. 5.8. This
geometrical relationship is caused by the Z-transform to DTFT conversion.
Equation (5.36) is the conversion for the given z function.

  ðejx þ 0:8Þðejx  0:5jÞðejx þ 0:5jÞ


X ðzÞjz¼ejx ¼ X ejx ¼ p p ð5:36Þ
ðejx  0:8Þðejx  0:8ej4 Þðejx  0:8ej4 Þ

The magnitude of each frequency x can be evaluated by the Euclidian distance


between the poles and zeros to the individual ejx positions as below.

  jx  jðejx þ 0:8Þjjðejx  0:5jÞjjðejx þ 0:5jÞj


X e  ¼ p p ð5:37Þ
jðejx  0:8Þjjðejx  0:8ej4 Þjjðejx  0:8ej4 Þj

The product of the pole distances represents the denominator value in the fre-
quency magnitude at x. In the same manner, the product of the zero distances denotes
the numerator value. The final rational number shows the frequency magnitude for
the radian frequency x. The pole-zero plots in Fig. 5.10 show the z function eval-
uation at the p=6 and 5p=6 in order to compute the frequency magnitude. The red and
222 5 Z-Transform

Fig. 5.10 Equation (5.37) evaluation at the p=6 (left) and 5p=6 (right)

Fig. 5.11 Equation (5.37)


plot with p=6 and 5p=6 maker

blue lines represent the individual denominator and numerator values respectively.
The relative pole distances to the ejp=6 are shorter than the zero’s counterparts;
therefore, the overall magnitude is high in the frequency response magnitude in
Fig. 5.11. The situation for ej5p=6 is in vice versa. Note that the symmetric locations of
poles and zeros produce the even symmetric distribution in frequency response
magnitude in Fig. 5.11.
5.2 Filter and Z-Transform 223

Prog. 5.2 MATLAB program for Fig. 5.11

w1 = linspace(-pi,pi,300);
x2 = cos(w1);
y2 = sin(w1);
z3 = abs(((cos(w1)+1j*sin(w1))+0.8).*((cos(w1)+1j*sin(w1))-
0.5*1j).*((cos(w1)+1j*sin(w1))+0.5*1j)./(((cos(w1)+1j*sin(w1))-
0.8).*((cos(w1)+1j*sin(w1))-0.8*exp(1j*pi/4)).*((cos(w1)+1j*sin(w1))-
0.8*exp(-1j*pi/4))));

figure,
plot(w1,z3), grid, hold on;
stem(w1([175 275]),z3([175 275])), hold off;
...

Example 5.4
Find the strongest frequency in the following signals.

x1 ½n ¼ 0:9n u½n


p 
x2 ½n ¼ 0:9n cos n u½n
2
x3 ½n ¼ ð0:9Þn u½n

Solution

z 1 z
x1 ½n ¼ 0:9n u½n $ X1 ðzÞ ¼ 1
¼
1  0:9z z  0:9
  ejx
X1 ejx ¼
ejx  0:9

Shortest denominator distance to the unit circle is 0 rad; hence, the strongest
frequency is zero radian.
p  1 p 1 p
x2 ½n ¼ 0:9n cos n u½n ¼ 0:9n ej2n u½n þ 0:9n ej2n u½n
2 2 2
z 1=2 1=2
$ X2 ðzÞ ¼ p þ p
1  0:9ej2 z1 1  0:9ej2 z1
z=2 z=2 a2 z þ a1 z
2
¼ þ ¼
z  0:9j z þ 0:9j ðz  0:9jÞðz þ 0:9jÞ
  2
a2 ðejx Þ þ a1 ejx
X2 ejx ¼
ðejx  0:9jÞðejx þ 0:9jÞ
224 5 Z-Transform

Shortest denominator distance to the unit circle is  p2 radian; hence, the strongest
frequency is  p2 radian.

z 1 z
x3 ½n ¼ ð0:9Þn u½n $ X3 ðzÞ ¼ ¼
1 þ 0:9z1 z þ 0:9
  ejx
X3 ejx ¼
ejx þ 0:9

Shortest denominator distance to the unit circle is p radian; hence, the strongest
frequency is p radian.

The location of poles and zeros decides the frequency property of the signal as
shown above. Let’s investigate the poles and zeros location for signal in time
domain. The conventional types of the signal are considered as below.
Finite-support and causal signal:

xfc ½n ¼ xnc ½nfu½n  u½n  N1 g for 0\N1 \1


X
1 X
N1
Xfc ðzÞ ¼ xfc ½nzn ¼ xfc ½nzn
n¼1 n¼0 ð5:38Þ
1 N2
¼ xfc ½0z þ xfc ½1z þ . . . þ xfc ½N2 z
0
 
ROC Xfc ðzÞ ¼ fzjz 6¼ 0g

Finite-support and non-causal signal:

xfnc ½n ¼ xnc ½nfu½n  N1   u½n  N2 g for  1\N1 \0\N2 \1


X
1 X
N2
Xfnc ðzÞ ¼ xfnc ½nzn ¼ xfnc ½nzn
n¼1 n¼N1
ð5:39Þ
¼ xfnc ½N1 zN1 þ . . . þ xfnc ½1z1
þ xfnc ½0z0 þ xfnc ½1z1 þ . . . þ xfnc ½N2 zN2
 
ROC Xfnc ðzÞ ¼ fzjz 6¼ 0 and z 6¼ 1g

Causal signal:

xc ½n ¼ 0 for n\0


Let xc ½n ¼ an ejxn u½n
X1 X
1 X
1
X c ð zÞ ¼ xc ½nzn ¼ an ejxn zn ¼ ðaejx z1 Þn \1 ð5:40Þ
n¼1 n¼0 n¼0
 jx 1      
ae z \1 ! aejx z 1 
\1 ! jzj [ ae jx 
! jzj [ jaj
ROCfXc ðzÞg ¼ fzjjzj [ jajg
5.2 Filter and Z-Transform 225

The typical types of signal and system shows causal property with finite or
infinite length. The finite-support signal illustrates the values in zero or positive
index for causality otherwise the signal is finite and non-causal signal. Also, the
infinite-support signal can be classified as causal and non-causal based on the signal
position. See Table 5.4.

Table 5.4 Signal types and corresponding pole locations with examples
Signal type Pole Example signal Pole-zero plot
locations
Finite-support and causal z¼0 P
9 1

signal 0:5n d½n  k  0.8


k¼0 0.6

0.4

Imaginary Part
0.2
9
0

-0.2

-0.4

-0.6

-0.8

-1

-1 -0.5 0 0.5 1
Real Part

Finite-support and z¼0 P


8 1

non-causal signal and z ¼ 1 0:5n d½n  k  0.8


k¼1 0.6

0.4
Imaginary Part

0.2
8
0

-0.2

-0.4

-0.6

-0.8

-1

-1 -0.5 0 0.5 1
Real Part

Causal signal Signal 0:5 u½n


n 1

(Infinite-support) dependent 0.8

0.6
but 0.4

z 6¼ 1
Imaginary Part

0.2

-0.2

-0.4

-0.6

-0.8

-1

-1 -0.5 0 0.5 1
Real Part

Causal signal + some Signal 0:5n u½n þ 1

values in negative index dependent 1


0:5 d½n þ 1
0.8

0.6
(Infinite-support) but 0.4

z¼1
Imaginary Part

0.2

0 2

-0.2

-0.4

-0.6

-0.8

-1

-1 -0.5 0 0.5 1
Real Part
226 5 Z-Transform

The four classes of the signal are represented for Z-transform analysis with pole
distribution. The finite-support signal provides the limited position for the poles and
free distribution for the zeros. The causal finite-support signal includes the negative
power polynomials for Z-transform as shown X1 ðzÞ in Eq. (5.41); hence, zeros are
the solution of the polynomial function and poles are arranged to the origin of the
z-plane. The non-causal finite-support signal involves the values at the negative
index; therefore, the corresponding Z-transform produces the positive and negative
power polynomial as shown X2 ðzÞ in Eq. (5.42). The zeros are allowed to move the
z-plane, but the poles are fixed to the origin and infinite.

X1 ðzÞ ¼ x1 ½0z0 þ x1 ½1z1 þ . . . þ x1 ½N zN ð5:41Þ

X2 ðzÞ ¼ x2 ½2z2 þ x2 ½1z1 þ x2 ½0z0 þ x2 ½1z1 þ . . . þ x2 ½N zN ð5:42Þ

The infinite-support causal signal as shown X3 ðzÞ in Eq. (5.43) can be simplified
by the geometric summation for rational function; therefore, the poles freely move
on the z domain except infinite value. The negative power polynomials will be
disappeared with infinite z value. If there is any signal component at the negative
index as X4 ðzÞ in Eq. (5.44), infinite z value is included as the pole position and
excluded from the ROC. The positive power polynomials will be amplified to the
infinite outcome with infinite z value.

X3 ðzÞ ¼ a0 z0 þ a1 z1 þ a2 z2 þ . . . þ a1 z1 ð5:43Þ

X4 ðzÞ ¼ a2 z2 þ a1 z1 þ a0 z0 þ a1 z1 þ a2 z2 þ . . . þ a1 z1 ð5:44Þ

If the pole is located within the unit circle, the signal magnitude is gradually
decreased. The pole on the unit circle maintains the constant signal magnitude and
the pole outside the unit circle provides the diverging signal over time. Therefore,
the absolute value of the pole determines the magnitude variation in the time
domain signal. The angle of the pole decides variation rate in time domain. The
positive real axis represents the zero frequency and negative real axis denotes
highest frequency p. The poles on the imaginary axis generate the middle frequency
p=2 based on the given sampling situation. Note that the poles and zeros should be
located with conjugated pair manner in z-plane; otherwise, the time domain signal
cannot be preserved in real value condition. Three examples of the infinite-support
causal signal are shown in Example 5.5 and Table 5.5 with pole-zero plot.
5.2 Filter and Z-Transform 227

Table 5.5 Examples of the infinite-support causal signal

Example 5.5
Draw the pole-zero plot and time domain plot of following signals.

x1 ½n ¼ 0:8n u½n


p 
x2 ½n ¼ cos n u½n
2
x3 ½n ¼ 1:2n cosðpnÞu½n
228 5 Z-Transform

Solution

z 1 z
x1 ½n ¼ 0:8n u½n $ ¼
1  0:8z1 z  0:8
zeros ¼ fz ¼ 0g poles ¼ fz ¼ 0:8g
p  1 p 1 p
x2 ½n ¼ cos n u½n ¼ ej2n u½n þ ej2n u½n
2 2 2
z 1=2 1=2
$ p þ p
1  ej2 z1 1  ej2 z1
z=2 z=2 z 2z
¼ þ ¼
z  j z þ j 2 ðz  j Þðz þ j Þ
zeros ¼ fdual z ¼ 0g poles ¼ fz ¼ jg
x3 ½n ¼ 1:2n cosðpnÞu½n ¼ 1:2n ð1Þn u½n ¼ ð1:2Þn u½n
z 1 z
$ ¼
1 þ 1:2z1 z þ 1:2
zeros ¼ fz ¼ 0g poles ¼ fz ¼ 1:2g


Like DTFT and DFT, the Z-transform also provides the convolution sum to
multiplication property between the domains as shown in Eq. (5.45).

Z
y½n ¼ x½n  h½n $ Y ðzÞ ¼ X ðzÞH ðzÞ ð5:45Þ

This relationship helps to identify the system by finding the rational equation
known as the transfer function in Eq. (5.46).

Y ðzÞ
H ðzÞ ¼ ð5:46Þ
X ðzÞ

Once you assign/obtain the proper input/output to/from the system, the transfer
function and impulse response can be computed by using the Z-transform. The
impulse response is the inverse Z-transform of the derived transfer function as
Eq. (5.47).

h½n ¼ Z1 fH ðzÞg for given ROC ð5:47Þ

The DTFT and DFT also share the above property; therefore, you can perform
the convolution sum by multiplication in the frequency domain as x and
k. However, the signal representation is limited by the transform capability. Certain
types of the signal cannot be modelled by the transform effectively; therefore, the
signal and system analysis is restricted. The degree of freedom in signal analysis is
less in the DTFT and DFT than the Z-transform’s counterpart. Let’s see the infinite
length signal below.
5.2 Filter and Z-Transform 229

x½n ¼ d½n þ rd½n  1 þ r 2 d½n  2 þ r 3 d½n  3 þ . . . ¼ r n u½n ð5:48Þ

DTFT result is below.


 
X ejx ¼ 1 þ rejx þ r 2 ej2x þ r 3 ej3x þ . . . ð5:49Þ

Z-transform is below.

X ðzÞ ¼ 1 þ rz1 þ r 2 z2 þ r 3 z3 þ . . . ð5:50Þ

Note that the DFT is not shown above because the transform is for the finite
length periodic signal. The DTFT eigenfunction is the ejx and the common ratio
for the geometric series is the rejx . When the common ratio magnitude is equal to
or greater than one, the transform cannot be represented by the rational function
according to the geometric summation. However, the Z-transform common ratio is
the rz1 and we can control the magnitude by placing the range of the complex
number in z known as region of convergence. Even, the infinite length diverging
arbitrary signal can be applied for the Z-transform to denote the signal in simple
form and further understanding. Equations (5.51) and (5.52) show the corre-
sponding rational functions.
 
X ejx ¼ 1 þ rejx þ r 2 ej2x þ r 3 ej3x þ . . .
1 ð5:51Þ
¼ only for the given jr j\1
1  rejx

X ðzÞ ¼ 1 þ rz1 þ r 2 z2 þ r 3 z3 þ . . .


1 ð5:52Þ
¼ for any r with ROC jzj [ r
1  rz1

The DFT for the finite length geometric series can be shown as below.

X ½k ¼ 1 þ rej N k þ r 2 ej N 2k þ þ r 3 ej N 3k þ . . . þ r ðN1Þ ej N ðN1Þk


2p 2p 2p 2p

ðrN ej2pk Þej N Nk


2p
2p
N j N Nk
¼ 1r e
¼  j2pk  j2pk
j2pk
1re N re N e N
QN1  j2p

m¼0 r  e
N km
ð5:53Þ
  ej N ðN1Þk
2p
¼
r  ej N k
2p

( )
Y  
j2p
ej N ðN1Þk
2p
¼ reN km

m¼0;2;3;4;5;...;N1

The finite length geometric series is organized as the polynomial over ej N k
2p

without the denominator part; hence, the DFT represents the finite length signal
230 5 Z-Transform

with period N. In conclusion, the infinite length signal can be denoted for limited
analysis in DTFT and for no analysis in DFT. The powerful Z-transform suc-
cessfully handles the any types of signal such as infinite, finite, diverging, con-
verging, and steady in property. The rational function in z domain can be easily
applied for the transfer function representation to understand the input and output
signal. Excluding the diverging in signal property, the DTFT can perform analysis
the signal efficiently. The DFT can manage the finite and periodic signal well. Note
that the DFT can approximate the DTFT output by increasing the signal length as
shown in the previous discussion. Summary of the transform capability is organized
in Fig. 5.12.
One example on the transformation is illustrated in Table 5.6 based on the given
infinite length signal for DTFT and Z-transform. The DTFT derives the time
domain signal by using the long division; however, the backward analysis is not
feasible due to the limited capability of the transform. The Z-transform performs the
forward and backward analysis well to compute the time domain and z domain
signal.
The conventional causal FIR filter can be represented by the following difference
equation. The impulse response or recent input weights are shown as h½n or bn in
the equation.

X
L X
L
y½n ¼ h½kx½n  k ¼ bk x ½ n  k 
k¼0 k¼0 ð5:54Þ
¼ b 0 x ½ n  þ b 1 x ½ n  1  þ b 2 x ½ n  2  þ . . . þ b L x ½ n  L

The general form of the filter including the IIR filter is presented below.

y½n þ a1 y½n  1 þ a2 y½n  2 þ . . . þ aM y½n  M 


ð5:55Þ
¼ b0 x ½ n þ b1 x ½ n  1 þ b2 x ½ n  2 þ . . . þ bN x ½ n  N 

Fig. 5.12 Summary of the Z-Transform (z)


transform capability
Arbitrary length and style signals

Discrete-time Fourier Transform ( )

Arbitrary length and not-diverging signals

Discrete Fourier Transform (k)

Finite length and periodic signal


5.2 Filter and Z-Transform 231

Table 5.6 Example of transformation to show the Z-trans. and DTFT comparison
DTFT Z-transform
X ðejx Þ ¼ 1e1jx X ðzÞ ¼ 1z1 1 ROC : jzj [ 1
1 + e-jw + e-2jw 1 + z-1+ z-2
1 - e-jw 1 1 – z-1 1
1 – z-1
-jw
1-e
e-jw z-1
e-jw- e-2jw z-1- z-2
e-2jw z-2
e-2jw- e-3jw z-2- z-3
........ ........
X ðejx Þ ¼ 1e1jx ¼ 1 þ ejx þ e2jx þ . . . X ðzÞ ¼ 1z1 1 ¼ 1 þ z1 þ z2 þ . . .
x½n ¼ d½n þ d½n  1 þ d½n  2 þ . . . x½n ¼ d½n þ d½n  1 þ d½n  2 þ . . .
¼ u½n ¼ u½n
x½n ¼ u½n ¼ d½n þ d½n  1 þ d½n  2 þ . . .
X ðejx Þ ¼ 1 þ ejx þ e2jx þ . . . X ðzÞ ¼ 1 þ z1 þ z2 þ . . .
6¼ 1e1jx Since jejx j ¼ 1 ¼ 1z1 1 ROC : jzj [ 1

The time delay is represented by the simple multiplication with z power in


Z-transform. Before applying the Z-transform to the conventional filter, let’s con-
sider the time shift for input x[n] and output y[n]. The causal input x[n] to the causal
system is assigned by the user as there is no values at the negative time index.
Hence the time shift to the right does not create any tails on the left-hand side for
example as shown in Eq. (5.56) and Fig. 5.13 top subplot.

Z
x½n  2 $ X ðzÞz2 ð5:56Þ

The output y[n] is the system output which possibly contains the initial values.
The causal system with causal input initiates the operation from the zero-time
index; therefore, the initial values of the output indicate the output prior to the input
assignment at negative time index. The initial values are not related to the input and
not classified to the output y[n]. Figure 5.13 and Eq. (5.57) demonstrate the y
[n] with two initial values at y[−1] and y[−2].

ytotal ½n ¼ y½2d½n þ 2 þ y½1d½n þ 1 þ y½0d½n


þ y½1d½n  1 þ y½2d½n  2 þ . . . ð5:57Þ
ytotal ½n ¼ y½2d½n þ 2 þ y½1d½n þ 1 þ y½n

The shift to the right by two samples can be denoted as below.


232 5 Z-Transform

Fig. 5.13 Shift right of y[n]


with initial values

ytotal ½n  2 ¼ y½2d½n þ y½1d½n  1 þ y½0d½n  2


þ y½1d½n  3 þ y½2d½n  4 þ . . . ð5:58Þ
ytotal ½n  2 ¼ y½2d½n þ y½1d½n  1 þ y½n  2

Since the system consider the values from the zero-time index, the shifted tails
shown in the working time index should be included to the analysis and transfor-
mation as Eq. (5.59).

Z
y½n $ Y ðzÞ
Z
y½n  1 $ y½1z0 þ Y ðzÞz1 ð5:59Þ
Z
y½n  2 $ y½2z0 þ y½1z1 þ Y ðzÞz2

Without the initial values on the output, the difference equation for the general
filter can be described as Eq. (5.60).
5.2 Filter and Z-Transform 233

y½n þ a1 y½n  1 þ a2 y½n  2 þ . . . þ aM y½n  M 


Z
¼ b0 x½n þ b1 x½n  1 þ b2 x½n  2 þ . . . þ bN x½n  N  $

Y ðzÞ þ a1 Y ðzÞz1 þ a2 Y ðzÞz2 þ . . . þ aM Y ðzÞzM


¼ b0 X ðzÞ þ b1 X ðzÞz1 þ b2 X ðzÞz2 þ . . . þ bN X ðzÞzN
 
Y ðzÞ 1 þ a1 z1 þ a2 z2 þ . . . þ aM zM
¼ X ðzÞfb0 þ b1 z1 þ b2 z2 þ . . . þ bN zN g

Y ðzÞ b0 þ b1 z1 þ b2 z2 þ . . . þ bN zN


¼ H ðzÞ ¼ ð5:60Þ
X ðzÞ 1 þ a1 z1 þ a2 z2 þ . . . þ aM zM

With the initial values on the output, the equation can be depicted as Eq. (5.61).

y½n þ a1 y½n  1 þ a2 y½n  2 þ . . . þ aM y½n  M 


Z
¼ b0 x½n þ b1 x½n  1 þ b2 x½n  2 þ . . . þ bN x½n  N  $
   
Y ðzÞ þ a1 y½1 þ Y ðzÞz1 þ a2 y½2 þ y½1z1 þ Y ðzÞz2
 
þ . . .aM y½M  þ y½ðM  1Þz1 þ . . . þ Y ðzÞzM
¼ b0 X ðzÞ þ b1 X ðzÞz1 þ b2 X ðzÞz2 þ . . . þ bN X ðzÞzN
 
Y ðzÞ 1 þ a1 z1 þ a2 z2 þ . . . þ aM zM
n o
þ y½1 a1 þ a2 z1 þ a3 z2 þ . . . þ aM zðM1Þ
n o
þ y½2 a2 þ a3 z1 þ a4 z2 þ . . . þ aM zðM2Þ þ . . . þ y½M aM
¼ X ðzÞfb0 þ b1 z1 þ b2 z2 þ . . . þ bN zN g
 
Y ðzÞ 1 þ a1 z1 þ a2 z2 þ . . . þ aM zM ¼
n o
 y½1 a1 þ a2 z1 þ a3 z2 þ . . . þ aM zðM1Þ
n o
 y½2 a2 þ a3 z1 þ a4 z2 þ . . . þ aM zðM2Þ  . . .  y½M aM
þ X ðzÞfb0 þ b1 z1 þ b2 z2 þ . . . þ bN zN g

fb0 þ b1 z1 þ b2 z2 þ . . . þ bN zN g


Y ðzÞ ¼ X ðzÞ
f1 þ a1 z1 þ a2 z2 þ . . . þ aM zM g
 
a1 þ a2 z1 þ a3 z2 þ . . . þ aM zðM1Þ
 y½1
f1 þ a1 z1 þ a2 z2 þ . . . þ aM zM g
 
a2 þ a3 z1 þ a4 z2 þ . . . þ aM zðM2Þ
 y½2  . . .
f1 þ a1 z1 þ a2 z2 þ . . . þ aM zM g
aM
 y½M 
f1 þ a1 z þ a2 z2 þ . . . þ aM zM g
1
234 5 Z-Transform

fb0 þ b1 z1 þ b2 z2 þ . . . þ bN zN g


Y ðzÞ ¼ X ðzÞ
ð1  a1 z1 Þð1  a2 z1 Þ. . .ð1  aM z1 Þ
 
a1 þ a2 z1 þ a3 z2 þ . . . þ aM zðM1Þ
 y½1
ð1  a1 z1 Þð1  a2 z1 Þ. . .ð1  aM z1 Þ
  ð5:61Þ
a2 þ a3 z1 þ a4 z2 þ . . . þ aM zðM2Þ
 y½2  . . .
ð1  a1 z1 Þð1  a2 z1 Þ. . .ð1  aM z1 Þ
aM
 y½M 
ð1  a1 z1 Þð1  a2 z1 Þ. . .ð1  aM z1 Þ

The output Y(z) is the combination of the rational functions from the X(z), y[−1],
y[−2], … and y[−M]. The first rational function is the generated by the input signal
and the other rational functions are derived from the corresponding initial values.
Since all rational functions share the denominator part, zero input response con-
verges to the constant value once the entire poles are located within the unit circle.
The transfer function defines the filter characteristics and property. The continu-
ous frequency response can be calculated by the DTFT as replacing the z with ejx .

  b0 þ b1 ejx þ b2 ej2x þ . . . þ bN ejNx


H ejx ¼ H ðzÞjz!ejx ¼ ð5:62Þ
1 þ a1 ejx þ a2 ej2x þ . . . þ aM ejMx

The discrete frequency response can be obtained by the DFT as exchanging the
z with ej2pk=N .

b0 þ b1 ej N k þ b2 ej N 2k þ . . . þ bN ej N Nk


2p 2p 2p

H ½k ¼ H ðzÞj 2p ¼ ð5:63Þ


z!ej N k 1 þ a1 ej N k þ a2 ej N 2k þ . . . þ aM ej N Mk
2p 2p 2p

The filter output in frequency and z domain is the multiplication between the
input and filter response in the corresponding domain; therefore, the output follows
the profile of the filter response. The higher magnitude in the filter response pro-
duces the amplified output in the frequency.

Y ðzÞ ¼ X ðzÞH ðzÞ


     
Y ejx ¼ X ejx H ejx ð5:64Þ
Y ½k  ¼ X ½k H ½k

Example 5.6
Derive the impulse response of following IIR filters with and without initial values.
The equations are shown previously in Chap. 4.

y½n ¼ a1 y½n  1 þ b0 x½n


y½n ¼ ða1 þ a2 Þy½n  1  a1 a2 y½n  2 þ ða1  a2 Þx½n
5.2 Filter and Z-Transform 235

Solution

y½n ¼ a1 y½n  1 þ b0 x½n with y½1 6¼ 0


Z
$ Y ðzÞ ¼ a1 y½1z0 þ a1 Y ðzÞz1 þ b0 X ðzÞ
 
Y ðzÞ 1  a1 z1 ¼ a1 y½1 þ b0 X ðzÞ
a1 y½1 b0 X ðzÞ
Y ðzÞ ¼ 1
þ
1  a1 z 1  a1 z1
a1 y½1 b0
H ðzÞ ¼ þ where X ðzÞ ¼ 1
1  a1 z1 1  a1 z1

a1 y½1an1 u½n þ b0 an1 u½n with initial value
h½n ¼
b0 an1 u½n without initial value

y½1 6¼ 0
y½n ¼ ða1 þ a2 Þy½n  1  a1 a2 y½n  2 þ ða1  a2 Þx½n with
y½2 6¼ 0
Z
$ Y ðzÞ ¼ ða1 þ a2 Þy½1z0 þ ða1 þ a2 ÞY ðzÞz1  a1 a2 y½2z0
 a1 a2 y½1z1  a1 a2 Y ðzÞz2 þ ða1  a2 ÞX ðzÞ
 
Y ðzÞ 1  ða1 þ a2 Þz1 þ a1 a2 z2
¼ ða1 þ a2 Þy½1  a1 a2 y½2  a1 a2 y½1z1 þ ða1  a2 ÞX ðzÞ
  
Y ðzÞ 1  a1 z1 1  a2 z1
¼ ða1 þ a2 Þy½1  a1 a2 y½2  a1 a2 y½1z1 þ ða1  a2 ÞX ðzÞ

ða1 þ a2 Þy½1 a1 a2 y½2


Y ðzÞ ¼ 
ð1  a1 z1 Þð1  a2 z1 Þ ð1  a1 z1 Þð1  a2 z1 Þ
a1 a2 y½1z1 ða1  a2 ÞX ðzÞ
 þ
ð1  a1 z Þð1  a2 z Þ ð1  a1 z1 Þð1  a2 z1 Þ
1 1

ða1 þ a2 Þy½1 a1 a2 y½2


H ðzÞ ¼ 
ð1  a1 z1 Þð1  a2 z1 Þ ð1  a1 z1 Þð1  a2 z1 Þ
a1 a2 y½1z1 ða1  a2 Þ
 þ where X ðzÞ ¼ 1
ð1  a1 z1 Þð1  a2 z1 Þ ð1  a1 z1 Þð1  a2 z1 Þ
ða1 þ a2 Þy½1  a1 a2 y½2 a1 a2 y½1z1
H ðzÞ ¼ 
ð1  a1 z1 Þð1  a2 z1 Þ ð1  a1 z1 Þð1  a2 z1 Þ
ða1  a2 Þ
þ
ð1  a1 z1 Þð1  a2 z1 Þ
236 5 Z-Transform

a1 a2 b1 z1 b2 z1
H ðzÞ ¼ þ þ þ
ð1  a1 z Þ ð1  a2 z Þ ð1  a1 z Þ ð1  a2 z1 Þ
1 1 1
a1 a2
þ 
ð1  a1 z1 Þ ð1  a2 z1 Þ

The corresponding impulse response is below.

h½n ¼ a1 an1 u½n þ a2 an2 u½n þ b1 an1


1 u½n  1 þ b2 a2 u½n  1
n1

þ an1 þ 1 u½n  an2 þ 1 u½n

Without the initial values, the last two terms are only survived as below.

h½n ¼ an1 þ 1 u½n  an2 þ 1 u½n

Compare the above result with Eqs. (4.17) and (4.22) which are solved by
substitution method.

The Z-transform provides the improved method to analyze the filter stability.
The stability is defined as the bounded output for the arbitrary bounded input.
Hence, the infinite length causal input with limited magnitude should generate the
bound output all the time in stable filter system. In the previous discussion, the
BIBO stability can be inspected by the impulse response with absolute summability
in square manner. In other words, the absolute summable or integrable frequency
response in square manner guarantees the BIBO stable filter according to the
Parseval’s theorem [6] as shown in Eq. (5.65).
8 1 pR jx 2
X
1 < 2p pjH ðe Þj dx\1
>
jh½nj2 \1 ! P
N1 ð5:65Þ
n¼1
>
: N1 jH ½kj2 \1
k¼0

The ROC defines the region that the Z-transform exist. If ROC includes the unit
circle in the z plane, then the values in the unit circle cannot be diverged to the
infinite value. Note that the continuous and discrete unit circle represents the DTFT
and DFT for the given signal and system, respectively. The finite values on the unit
circle provides the absolute summability and integrability in square fashion; hence,
the system deliver the stability in terms of BIBO.

Z
h½n $ H ðzÞ; unit circle 2 ROC; ) BIBO stable ð5:66Þ

The system causality can present further convenience based on the pole distri-
bution. The ROC of the causal system is the region from the outside of the farthest
pole from the z plane origin. Once the transfer function includes the all poles within
the unit circle, the causal system denotes the BIBO stability as shown in Eq. (5.67).
5.2 Filter and Z-Transform 237

Fig. 5.14 Causal signal example with all poles within the unit circle and not all poles within the
unit circle

Figure 5.14 illustrates the two situations as all poles within the unit circle and not
all poles in that boundary.

Z
h½n $ H ðzÞ; all poles 2 unit cirlce region; ) BIBO stable ð5:67Þ

Example 5.7
Analyze the difference equation that represents first order IIR filter given as below.
We need to explore the impulse response, frequency response, and BIBO stability.

y½n þ 0:8y½n  1 ¼ x½n  x½n  1

Solution
The Z-transform of the filter is shown below.
 
Y ðzÞ þ 0:8 y½1 þ Y ðzÞz1 ¼ X ðzÞ  X ðzÞz1
   
Y ðzÞ 1 þ 0:8z1 þ 0:8y½1 ¼ X ðzÞ 1  z1
   
Y ðzÞ 1 þ 0:8z1 ¼ X ðzÞ 1  z1  0:8y½1
 
X ðzÞ 1  z1 0:8y½1
Y ðzÞ ¼ 
f1 þ 0:8z1 g f1 þ 0:8z1 g
X ðzÞ X ðzÞz1 0:8y½1
¼  
f1 þ 0:8z g f1 þ 0:8z1 g f1 þ 0:8z1 g
1

The transfer function is derived by the input d[n] that provides X(z) as 1.
238 5 Z-Transform

1 0:8y½1
H ðzÞ ¼ f1 þ 0:8z
1
1 g  f1 þ 0:8z1 g  f1 þ 0:8z1 g
z

The inverse Z-transform finds the impulse response as below.

h½n ¼ ð0:8Þn u½n  ð0:8Þn1 u½n  1  0:8y½1ð0:8Þn u½n

Generally, the impulse response is the output of the impulse input with zero
initial value which can be specified as zero state condition.

h½n ¼ ð0:8Þn u½n  ð0:8Þn1 u½n  1

The zero input response is the output of the zero input with arbitrary initial value on y
[−1].

yzi ½n ¼ 0:8y½1ð0:8Þn u½n

The corresponding impulse response and zero input response are illustrated in
Figs. 5.15 and 5.16.
The frequency response is calculated by replacing the z with ejx in the transfer
function without considering the initial values as below.

1  jx
H ðejx Þ ¼ H ðzÞjz!ejx ¼ 1 þ1z
0:8z1  ¼ 1 þ1e
0:8ejx
z!ejx

The magnitude and phase of the impulse response is presented as Figs. 5.17 and 5.18.
You can figure out the BIBO stability by inspecting the impulse response as well
as pole zero plot. The impulse response develops the sequence in the power of 0.8;
hence, the system is expected to be BIBO stable. The pole zero plot shows the
BIBO stability by pole position examination. The pole is located at the −0.8 where
the unit circle area is; therefore, the system is BIBO stable as shown in Fig. 5.19.

Fig. 5.15 Impulse response


with zero initial condition
5.2 Filter and Z-Transform 239

Fig. 5.16 Zero input


response with y[− 1] = 1

Fig. 5.17 Frequency


response in magnitude

Fig. 5.18 Phase response


240 5 Z-Transform

Fig. 5.19 Pole zero plot

Prog. 5.3 MATLAB program for Figs. 5.15, 5.16, 5.17, 5.18 and 5.19

syms z w
zy = (1-z^-1)/(1+0.8*z^-1); % Given equa on in Z domain
zn = iztrans(zy); % Inverse z transform
[N, D] = numden(zy);
a = sym2poly(D);
b = sym2poly(N);
[H,T] = impz(b,a);
nn = 0:1:43;
yzi = -0.8*(-0.8).^nn; % Impulse response with ini al condi on
zw = subs(zy,z,exp(1j*w));
w1 = linspace(-pi,pi,200);
zw1 = eval(subs(zw,w,w1));

figure, % Fig. 5.15


stem(T,H), grid
...
figure, % Fig. 5.16
stem(nn,yzi), grid;
...
figure, % Fig. 5.17
plot(w1,abs(zw1)), grid
...
figure, % Fig. 5.18
plot(w1,angle(zw1)), grid
...
figure, % Fig. 5.19
zplane(b,a)
5.2 Filter and Z-Transform 241

The pole zero plot also corresponds to the frequency response. The zero is
located at the 0 rad on the unit circle and pole is placed at the −0.8 near the p
radian. Therefore, zero frequency cannot be passed, and highest frequency p is
amplified by the filter according to the pole zero position.

5.3 Intuitive Filter Design

In the previous chapter, we studied the FIR filter design based on the DTFT and
DFT. The Z-transform provides the novel power to design IIR filter which cannot
be approached by the DTFT and DFT. The proceeding section showed the example
of analyzing the difference equation filter to derive the impulse response, frequency
response, and filter stability. This section provides the designing the filter equation
from the given filter requirement in frequency domain. The intuitive method places
the poles and zeros in the z plane to meet the specification based on the pole and
zero property. The intuitive iterations optimize the response with specification in
terms of order and coefficients over the IIR filter system. Further mathematically
optimized methods will be introduced in the next chapter.
The proceeding section stated that the transfer function is the rational function
between the input and output in z domain. The frequency response evaluates the
transfer function over the unit circle. For the time being, we only consider the
magnitude of the frequency response and the phase will be discussed in the next
section. The magnitude is computed by the product over the pole and zero distances
to the corresponding frequency on the unit circle. The pole close to the unit circle
creates the amplified magnitude and the zero near by the unit circle generates the
suppressed output for the frequency. Due to the mutual relation, close solution to
place the optimized pole zero location requires the mathematical procedure that will
be investigated at the next chapter. We only utilize the fundamental knowledges
those are the unit circle evaluation, pole effect, and zero effect only.
Single pole:

y ½ n  þ a1 y ½ n  1  ¼ b 0 x ½ n 
Z
$ Y ðzÞ þ a1 Y ðzÞz1 ¼ b0 X ðzÞ ð5:68Þ
Y ðzÞ b0
H ðzÞ ¼ ¼ ; j z j [ j a1 j
X ðzÞ 1 þ a1 z1

The zero-state transfer function above represents the first order IIR filter with
pole at a1 and zero at 0. The single pole should move along with real axis on
z plane to preserve the real number coefficient condition at difference equation.
Also, the pole must be contained within the unit circle area for stability; therefore,
the pole range is above −1 and below 1 in the z domain. As the pole approaches to
242 5 Z-Transform

1, the zero-frequency component is amplified. The pole near the −1 emphasize the
p radian frequency component. With the first order IIR configuration, the LPF and
HPF are only accessible. The normalized filter is organized as Eq. (5.69).

1  j a1 j
H ðzÞ ¼ ð5:69Þ
1 þ a1 z1

Figures 5.20 and 5.21 show the pole zero plot and corresponding frequency
response for range of a1 . Approaching to the unit circle illustrates the strong
selective property in the frequency domain. Note that the FIR filter requires the
extensive orders to present rapid transition across the requirement edges. With
relatively short filter order in IIR configuration, the pole property allows us to
design the high discriminating LPF and HPF. The pole closeness to the unit circle is
proportional to the filter selectiveness. Do not place the pole on the unit circle;
otherwise, the filter stability is destroyed. The impulse response of the first order IIR
filter is given in Eq. (5.70).

Fig. 5.20 Pole zero plot and frequency response (magnitude) of Eq. (5.69) for positive pole locations

Fig. 5.21 Pole zero plot and frequency response (magnitude) of Eq. (5.69) for negative pole
locations
5.3 Intuitive Filter Design 243

h½n ¼ f1  ja1 jgða1 Þn u½n ð5:70Þ

Observe that the b0 is the f1  ja1 jg in Eq. (5.70) and the maximum gain is
limited to the one for all frequency by this modification.
Prog. 5.4 MATLAB program for Figs. 5.20 and 5.21

syms z;
w = linspace(0,pi,100);
figure(1), grid, hold on;
figure(2), grid, hold on;

for a1 = -0.1:-0.2:-0.9 % For Fig. 5.21 a1 = 0.1:0.2:0.9


b0 = 1 - abs(a1);
hz = b0./(1+a1*z^-1);
hz1 = subs(hz,z,exp(1j*w));
hz2 = eval(hz1);
figure(1), plot(w,abs(hz2));
str = sprin (' %0.3g',-a1);
text(pi/2,abs(hz2(50)),str);
figure(2), zplane(b0,[1 a1])
text(-a1,0,str,'rota on',45);
end

figure(1), hold off
figure(2), hold off
figure(1)
ax = gca;
ax.XTick = [0 pi/4 pi/2 3*pi/4 pi];
ax.XTickLabel = {'0','\pi/4','\pi/2','3\pi/4','\pi'};
xlim([0 pi]);
xlabel('\omega');
ylabel('|H(e^{j\omega})|')
figure(2)
xlim([-1.2 1.2]);
ylim([-1.0 1.0]);
244 5 Z-Transform

Dual poles:

y½n þ a1 y½n  1 þ a2 y½n  2 ¼ b0 x½n


Z
$ Y ðzÞ þ a1 Y ðzÞz1 þ a2 Y ðzÞz2 ¼ b0 X ðzÞ ð5:71Þ
Y ðzÞ b0
H ðzÞ ¼ ¼
X ðzÞ 1 þ a1 z þ a2 z2
1

The IIR filter shown above provides the second order polynomial in denominator
and the constant value in numerator. The roots of the polynomial represent the poles
that can be freely moved over the z plane. In order to include the real coefficients for
the polynomial, the pair of roots should be in the conjugated relationship as aejx
and aejx . The BIBO stability condition constrains the complex solution magnitude
within the unit circle; hence, the a absolute value should be less than 1. As the poles
approach to the ejx0 , the x0 frequency component is amplified. With given second
order IIR configuration, the LPF, HPF, and BPF are available. The normalized filter
is organized as Eqs. (5.72) and (5.73).
pffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffi
ð1  aÞ a2  2acosð2xÞ þ 1
H ðzÞ ¼ ; jzj [ jaj
ð1  aejx z1 Þð1  aejx z1 Þ
pffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffi ð5:72Þ
ð1  aÞ a2  2acosð2xÞ þ 1
¼
1  2a cosðxÞz1 þ a2 z2

y½n  2a cosðxÞy½n  1 þ a2 y½n  2


n pffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffio ð5:73Þ
¼ ð1  aÞ a2  2acosð2xÞ þ 1 x½n

Figures 5.22, 5.23, and 5.24 illustrate the pole zero plots and corresponding
frequency responses for range of a with p=2, p=4, and p=6 radian frequency.
Similar to the single pole situation, approaching to the unit circle illustrates the
strong selective property in the frequency domain as well. The normalization
process is exercised for the pole angle that usually provides the highest magnitude
in the frequency response. However, the p=4 and p=6 pole angles generate the
above the one magnitude in the low frequency range at pole away situations from
the unit circle. The mutual relation with neighbor pole provides magnitude overlap
that produce the higher response at the between pole area. Note that the mutually
closer poles cause the higher overlap as shown p=6 radian frequency in Fig. 5.24.
The impulse response of the second order IIR filter is given below.
pffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffi
ð1  aÞ a2  2acosð2xÞ þ 1
H ðzÞ ¼
ð1  aejx z1 Þð1  aejx z1 Þ
c c Z
¼ þ $ h½n ¼ can ejxn u½n ð5:74Þ
ð1  aejx z1 Þ ð1  aejx z1 Þ
þ c an ejxn u½n
¼ 2jcjan cosðxn þ ]cÞu½n
5.3 Intuitive Filter Design 245

Fig. 5.22 Pole zero plot and frequency response (magnitude) of Eq. (5.72) for p=2

Fig. 5.23 Pole zero plot and frequency response (magnitude) of Eq. (5.72) for p=4

Fig. 5.24 Pole zero plot and frequency response (magnitude) of Eq. (5.72) for p=6
246 5 Z-Transform

In Eq. (5.74), the partial fraction computes the c and its conjugate pair for
inverse Z-transform. The conjugated relation preserves the real coefficients for the
equation.
Prog. 5.5 MATLAB program for Figs. 5.22, 5.23 and 5.24

syms z;
w = linspace(0,pi,100);
an1 = pi/2; % Fig. 5.23 set an1 = pi/4 and Fig. 5.24 set an1 = pi/6
figure(1), grid, hold on;
figure(2), grid, hold on;

for a1 = 0.1:0.2:0.9
hz = (1-a1)*sqrt(a1^2-2*cos(2*an1)*a1+1)/(1-2*a1*cos(an1)*z^-
1+a1^2*z^-2);
hz1 = subs(hz,z,exp(1j*w));
hz2 = eval(hz1);
figure(1), plot(w,abs(hz2));
str = sprin (' \\alpha = %0.3g',a1);
text(pi*3/4,abs(hz2(75)),str);
[N,D] = numden(hz);
a = sym2poly(D);
b = sym2poly(N);
figure(2), zplane(b,a)
text(a1*cos(an1),a1*sin(an1),str,'rota on',0);
end

figure(1), hold off
ylim([0 1.2]);
figure(2), hold off
figure(1)
ax = gca;
ax.XTick = [0 pi/4 pi/2 3*pi/4 pi];
ax.XTickLabel = {'0','\pi/4','\pi/2','3\pi/4','\pi'};
xlim([0 pi]);
xlabel('\omega');
ylabel('|H(e^{j\omega})|')
figure(2)
xlim([-1.2 1.2]);
ylim([-1.0 1.0]);
5.3 Intuitive Filter Design 247

Single pole with zero:

y ½ n þ a1 y ½ n  1 ¼ b0 x ½ n þ b1 x ½ n  1
Z
$ Y ðzÞ þ a1 Y ðzÞz1 ¼ b0 X ðzÞ þ b1 X ðzÞz1
  ð5:75Þ
b1 1
Y ðzÞ b0 þ b1 z1 b0 1 þ b0 z
H ðzÞ ¼ ¼ ¼ ; j z j [ j a1 j
X ðzÞ 1 þ a1 z1 1 þ a1 z1

The above first order IIR filter contains the pole and zero movement over the
z plane; however, the both locations are limited to the real axis due to the real value
coefficient condition. The pole location is the a1 and zero position is the b1 =b0
with gain control by b0 . Note that the normalization is performed by assigning the
proper values at the b0 and b1 . The study shown below explores the zero-position
effect on the frequency response compare to the pole location. Observe that the
suggested examples deliver the rough idea on the pole zero location for frequency
response. Multiple poles and zeros produce the complicated mutual relation on the
response and barely obtainable frequency profile by hand. The first situation is the
approaching the zero to the pole. The pole is fixed at the 0.95 and zero is moved
toward the pole from 0.1 to 0.9 in every 0.2 stride.

Fig. 5.25 Pole zero plot and frequency response (magnitude) of Eq. (5.75)
248 5 Z-Transform

Prog. 5.6 MATLAB program for Fig. 5.25

syms z;
w = linspace(0,pi,100);
a1 = 0.95;
an1 = 0;
figure(1), grid, hold on;
figure(2), grid, hold on;

for b1 = 0.1:0.2:0.9
hz = (1-b1*z^-1)*(1-a1)/((1-a1*z^-1)*(1-b1));
hz1 = subs(hz,z,exp(1j*w));
hz2 = eval(hz1);
figure(1), plot(w,abs(hz2));
str = sprin (' %0.3g',b1);
[N,D] = numden(hz);
a = sym2poly(D);
b = sym2poly(N);
figure(2), zplane(b,a)
text(b1*cos(an1),b1*sin(an1),str,'rota on',90);
end

figure(1), hold off
legend('zero at 0.1','0.3','0.5','0.7','0.9');
figure(2), hold off
figure(1)
ax = gca;
ax.XTick = [0 pi/4 pi/2 3*pi/4 pi];
ax.XTickLabel = {'0','\pi/4','\pi/2','3\pi/4','\pi'};
xlim([0 pi]);
xlabel('\omega');
ylabel('|H(e^{j\omega})|')
figure(2)
xlim([-1.2 1.2]);
ylim([-1.0 1.0]);

The 0.95 pole provides the high selective filter in general. As the zero approa-
ches to the pole, the frequency response converges to the higher constant value for
the other frequency region. Also, the filter sharpness is slightly blurred for near
placed zero. Therefore, the distance between the pole and adjacent zero organizes
5.3 Intuitive Filter Design 249

the convergence value. The next case is a pair of poles zeroes with equidistance
moving along the real axis. The distance between the pole and zero is 0.05 with
pole closer to unit circle. As the pair advances to the origin, the filter selectiveness
is decreased, and convergence value is increased. Therefore, pole zero around the
z plane origin yields the smooth frequency response.
Prog. 5.7 MATLAB program for Fig. 5.26

w = linspace(0,pi,100);
d1 = 0.05;
figure(1), grid, hold on;
figure(2), grid, hold on;

for a1 = 0.1:0.2:0.9
hz = (1-a1*z^-1)*(1-(a1+d1))/((1-(a1+d1)*z^-1)*(1-a1));
hz1 = subs(hz,z,exp(1j*w));
hz2 = eval(hz1);
figure(1), plot(w,abs(hz2));
str = sprin (' %0.3g',a1);
text(pi/2,abs(hz2(50)),str,'rota on',45);
[N,D] = numden(hz);
a = sym2poly(D);
b = sym2poly(N);
figure(2), zplane(b,a)
text(a1,0,str,'rota on',90);
end

figure(1), hold off
figure(2), hold off
figure(1)
ax = gca;
ax.XTick = [0 pi/4 pi/2 3*pi/4 pi];
ax.XTickLabel = {'0','\pi/4','\pi/2','3\pi/4','\pi'};
xlim([0 pi]);
xlabel('\omega');
ylabel('|H(e^{j\omega})|')
figure(2)
xlim([-1.3 1.3]);
ylim([-1.0 1.0]);
250 5 Z-Transform

Fig. 5.26 Pole zero plot and frequency response (magnitude) of Eq. (5.75)

The subsequent examination in Fig. 5.27 places the zero above the unit circle
since the filter stability does not regulate the zero position. In opposite direction, the
pole and zero approach to the unit circle with identical distance and symmetrical
manner from 0.75 pole and 1.25 zero. The symmetrical configuration provides
relatively flat response and the closer pair presents further uniformity. Hence, the
symmetric pole zero pair over the unit circle is useful to construct the flat region in
the frequency domain.

Fig. 5.27 Pole zero plot and frequency response (magnitude) of Eq. (5.75)
5.3 Intuitive Filter Design 251

Prog. 5.8 MATLAB program for Fig. 5.27

w = linspace(0,pi,100);
an1 = 0;
figure(1), grid, hold on;
figure(2), grid, hold on;

for a1 = 0.75:0.05:0.95
hz = (1-(1+(1-a1))*z^-1)/(1-a1*z^-1);
hz1 = subs(hz,z,exp(1j*w));
hz2 = eval(hz1);
figure(1), plot(w,abs(hz2));
str = sprin (' %0.3g',a1);
text(pi*3/4,abs(hz2(75)),str,'rota on',45);
[N,D] = numden(hz);
a = sym2poly(D);
b = sym2poly(N);
figure(2), zplane(b,a)
text(a1*cos(an1),a1*sin(an1),str,'rota on',90);
end

figure(1), hold off
figure(2), hold off
figure(1)
ax = gca;
ax.XTick = [0 pi/4 pi/2 3*pi/4 pi];
ax.XTickLabel = {'0','\pi/4','\pi/2','3\pi/4','\pi'};
xlim([0 pi]);
xlabel('\omega');
ylabel('|H(e^{j\omega})|')
figure(2)
xlim([-1.3 1.3]);
ylim([-1.0 1.0]);

The impulse response of the given first order IIR filter is shown below. The
polynomial long division computes the l0 and c1 for inverse Z-transform.

b0 þ b1 z1 c1
H ðzÞ ¼ ¼ l0 þ
1 þ a1 z1 1 þ a1 z1 ð5:76Þ
Z
$ h½n ¼ l0 d½n þ c1 ða1 Þn u½n
252 5 Z-Transform

Dual poles with zeros:

y ½ n þ a1 y ½ n  1 þ a2 y ½ n  2 ¼ b0 x ½ n þ b1 x ½ n  1 þ b2 x ½ n  2
Z
$ Y ðzÞ þ a1 Y ðzÞz1 þ a2 Y ðzÞz2 ¼ b0 X ðzÞ þ b1 X ðzÞz1 þ b2 X ðzÞz2
Y ðzÞ b0 þ b1 z1 þ b2 z2
H ðzÞ ¼ ¼
X ðzÞ 1 þ a1 z1 þ a2 z2
ð5:77Þ

The second order IIR filter in Eq. (5.77) contains the dual pole and dual zero
movement over the z plane. Both poles and zeros can be placed any locations in the
complex domain while the pair positions maintain the conjugate relation. However,
the real axis does not limit the pole and zero positions. The single pole and zero
experiments are extended to the dual poles and zeros with selective frequencies p=2,
p=4, and p=6. Observe that the normalization is performed by dividing the magnitude
at the target frequency. The investigation shown in Fig. 5.28 explores the
zero-position effect on the frequency response compare to the pole location. The first
situation is the approaching the zero to the pole. The pole is fixed at the 0.95 and zero
is moved to the pole from 0.1 to 0.9 in every 0.2 stride for the designed frequency.

Fig. 5.28 Pole zero plot and frequency response (magnitude) of Eq. (5.77)
5.3 Intuitive Filter Design 253

Prog. 5.9 MATLAB program for Fig. 5.28

syms z;
w = linspace(0,pi,200);
a1 = 0.95;
an1 = [pi/2 pi/4 pi/6];
figure(1), grid, hold on;
figure(2), grid, hold on;
figure(3), grid, hold on;
figure(4), grid, hold on;

for kk = 1:3
for b1 = 0.1:0.2:0.9
hz = (1-b1*exp(1j*an1(kk))*z^-1)*(1-b1*exp(-1j*an1(kk))*z^-1)/((1-
a1*exp(1j*an1(kk))*z^-1)*(1-a1*exp(-1j*an1(kk))*z^-1));
hz1 = subs(hz,z,exp(1j*w));
hz2 = eval(hz1);
figure(kk), plot(w,abs(hz2)/max(abs(hz2)));
str = sprin (' %0.3g',b1);
[N,D] = numden(hz);
a = sym2poly(D);
b = sym2poly(N);
figure(4), zplane(b,a)
if kk == 1
text((b1*cos(an1(kk))),b1*sin(an1(kk)),str,'rota on',0);
end
end
end
figure(1), xlim([0 pi]), hold off
figure(2), xlim([0 pi]), hold off
figure(3), xlim([0 pi]), hold off
figure(4), hold off
254 5 Z-Transform

Fig. 5.29 Pole zero plot and frequency response (magnitude) of Eq. (5.77)

Like the single pole and zero, the zero approaching increases the frequency
response convergence to the higher constant value. Moreover, the filter sharpness is
slightly reduced for near placed zero. Hence, the distance between the pole and
adjacent zero decides the convergence value. The case in Fig. 5.29 is a pair of poles
and zeroes with equidistance moving along the selective frequency axis. The dis-
tance between the pole and zero is 0.05 with pole closer to unit circle. As the pair
advances to the origin, the filter selectiveness is decreased, and convergence value
is increased. Therefore, pole zero around the z plane origin yields the smooth
frequency response.
5.3 Intuitive Filter Design 255

Prog. 5.10 MATLAB program for Fig. 5.29

syms z;
w = linspace(0,pi,200);
a1 = 0.95;
an1 = [pi/2 pi/4 pi/6];
figure(1), grid, hold on;
figure(2), grid, hold on;
figure(3), grid, hold on;
figure(4), grid, hold on;

for kk = 1:3
for b1 = 0.1:0.2:0.9
hz = (1-b1*exp(1j*an1(kk))*z^-1)*(1-b1*exp(-1j*an1(kk))*z^-1)/((1-
(b1+0.05)*exp(1j*an1(kk))*z^-1)*(1-(b1+0.05)*exp(-1j*an1(kk))*z^-1));
hz1 = subs(hz,z,exp(1j*w));
hz2 = eval(hz1);
figure(kk), plot(w,abs(hz2)/abs(hz2(round(an1(kk)*200/pi)+1)));
str = sprin (' %0.3g',b1);
[N,D] = numden(hz);
a = sym2poly(D);
b = sym2poly(N);
figure(4), zplane(b,a)
if kk == 1
text((b1*cos(an1(kk))),b1*sin(an1(kk)),str,'rota on',0);
end
end
end
figure(1), xlim([0 pi]), hold off
figure(2), xlim([0 pi]), hold off
figure(3), xlim([0 pi]), hold off
figure(4), xlim([-1.3 1.3]), ylim([-1.0 1.0]), hold off
256 5 Z-Transform

Fig. 5.30 Pole zero plot and frequency response (magnitude) of Eq. (5.77)

The study in Fig. 5.30 locates the zero above the unit circle. In opposite
direction, the pole and zero approach to the unit circle with identical distance and
symmetrical manner from 0.75 pole and 1.25 zero. Similar to the single pole and
zero case, the symmetrical configuration provides relatively flat response and the
closer pair presents further uniformity with valley at the designated frequency.
Hence, the symmetric pole zero pair over the unit circle is useful to construct the flat
region in the frequency domain.
5.3 Intuitive Filter Design 257

Prog. 5.11 MATLAB program for Fig. 5.30

syms z;
w = linspace(0,pi,200);
b1 = 0.1;
an1 = [pi/2 pi/4 pi/6];
figure(1), grid, hold on;
figure(2), grid, hold on;
figure(3), grid, hold on;
figure(4), grid, hold on;

for kk = 1:3
for a1 = 0.75:0.05:0.95
hz = (1-(2-a1)*exp(1j*an1(kk))*z^-1)*(1-(2-a1)*exp(-
1j*an1(kk))*z^-1)/((1-a1*exp(1j*an1(kk))*z^-1)*(1-a1*exp(-1j*an1(kk))*z^-
1));
hz1 = subs(hz,z,exp(1j*w));
hz2 = eval(hz1);
figure(kk), plot(w,abs(hz2)/abs(hz2(round(an1(kk)*200/pi)+1)));
str = sprin (' %0.3g',a1);
text(pi*3/4,abs(hz2(200*3/4))/abs(hz2(round(an1(kk)*200/pi)+1)),
str,'rota on',45);
[N,D] = numden(hz);
a = sym2poly(D);
b = sym2poly(N);
figure(4), zplane(b,a)
if kk == 1
text((a1*cos(an1(kk))),a1*sin(an1(kk)),str,'rota on',0);
end
end
end

figure(1), xlim([0 pi]), hold off


figure(2), xlim([0 pi]), hold off
figure(3), xlim([0 pi]), hold off
figure(4), xlim([-1.6 1.6]), ylim([-1.3 1.3]), hold off

All of the above investigations, the p=4 and p=6 frequencies create the minor
asymmetric distribution over the given frequency because the mutual relation with
adjacent poles and zeros provides magnitude overlap that produce the higher or
lower response at the between the conjugated frequencies. The impulse response of
the given second order IIR filter is shown in Eq. (5.78). The polynomial long
division computes the l0 and c1 for inverse Z-transform.
258 5 Z-Transform

b0 þ b1 z1 þ b2 z2 c1 c1


H ðzÞ ¼ ¼ l þ þ
1 þ a1 z1 þ a2 z2 0
1  rejx z1 1  rejx z1
Z ð5:78Þ
$ h½n ¼ l0 d½n þ c1 r n ejxn u½n þ c1 r n ejxn u½n
¼ l0 d½n þ 2jc1 jr n cosðxn þ ]c1 Þ

Multi poles with zeros:

y ½ n þ a1 y ½ n  1 þ . . . þ aM y ½ n  M 
¼ b0 x ½ n þ b1 x ½ n  1 þ . . . þ bN x ½ n  N 
Z
$ Y ðzÞ þ a1 Y ðzÞz1 þ . . . þ aM Y ðzÞzM
¼ b0 X ðzÞ þ b1 X ðzÞz1 þ . . . þ bN X ðzÞzN

Y ðzÞ b0 þ b1 z1 þ . . . þ bN zN


H ðzÞ ¼ ¼
X ðzÞ 1 þ a1 z1 þ . . . þ aM zM ð5:79Þ
ð1b z1 Þð1b z1 Þ...ð1b z1 Þ
¼ ð1a11 z1 Þð1a22z1 Þ...ð1aMNz1 Þ jzj [ maxfjak jg

The arbitrary number of poles and zeros can contribute to build the designated
frequency response. The given equation in Eq. (5.79) contains the M poles and
N zeros once there is no cancelations between the poles and zeros. This investi-
gation explores whether the individual known pole-zero placements can illustrate
the overall predicted frequency or not. If the realization is true, we can design the
IIR filter by adding the poles and zeros on the specific frequency with configura-
tions shown above sections.
Example 5.8
Place the 20 zeros and 20 poles in every 2p=20 radian angles. The 7 pole-zero pairs
are located in the low frequency region in symmetric form over unit circle. The 6
pole-zero pairs are placed in the middle frequency range in medium radius and
close pairs. The rest of the pole-zero pairs are located at the high frequency section
in close poles to the unit circle and far pairs. Inspect the frequency response. Is the
overall response close to the individual response combination? Show by MATLAB
result.
Solution
With arbitrary parameter values, the transfer function is created as below.
Q3  Q  Q  
6
1  1:05ej20k z1 20k z1 20k z1
2p
j2p 10;9 j2p
k¼3 k¼4 1  0:7e k¼7 1  0:7e
H ðzÞ ¼ Q  Q  Q   jzj [ 0:95
3 6 10;9
20k z1 20k z1 20k z1
k¼3 1  0:95e k¼4 1  0:75e k¼7 1  0:95e
j2p j2p j2p

The pole zero plot and frequency response are shown in Fig. 5.31. The red lines
divide the frequencies between pole-zero configurations in the figure.
5.3 Intuitive Filter Design 259

Prog. 5.12 MATLAB program for Fig. 5.31

syms z k;
w = linspace(0,pi,100);
w1 = linspace(0,pi,10);
wd = 2*pi/20;
a1 = 0.95;
a2 = 0.7;
a3 = 0.7;
HD1 = symprod((1-a1*exp(1j*wd*k)*z^-1),k,-3,3);
HN1 = symprod((1-(2-a1)*exp(1j*wd*k)*z^-1),k,-3,3);
HD2 = symprod((1-(a2+0.05)*exp(1j*wd*k)*z^-1),k,4,6);
HN2 = symprod((1-a2*exp(1j*wd*k)*z^-1),k,4,6);
HD3 = symprod((1-(a2+0.05)*exp(1j*wd*k)*z^-1),k,-6,-4);
HN3 = symprod((1-a2*exp(1j*wd*k)*z^-1),k,-6,-4);
HD4 = symprod((1-0.95*exp(1j*wd*k)*z^-1),k,7,10);
HN4 = symprod((1-a3*exp(1j*wd*k)*z^-1),k,7,10);
HD5 = symprod((1-0.95*exp(1j*wd*k)*z^-1),k,-9,-7);
HN5 = symprod((1-a3*exp(1j*wd*k)*z^-1),k,-9,-7);
H1 = HN1*HN2*HN3*HN4*HN5/(HD1*HD2*HD3*HD4*HD5);
hz1 = subs(H1,z,exp(1j*w));
hz2 = eval(hz1);
[N,D] = numden(H1);
a = sym2poly(D);
b = sym2poly(N);

figure,
plot(w,abs(hz2)), grid
axi1 = axis;
line([2*pi*7/(20*2) 2*pi*7/(20*2)],[axi1(3) axi1(4)],'Color','r')
line([2*pi*13/(20*2) 2*pi*13/(20*2)],[axi1(3) axi1(4)],'Color','r')
xlim([0 pi]);
xlabel('\omega');
ylabel('|H(e^{j\omega})|')
figure,
zplane(b,a), grid
xlim([-1.3 1.3]);
ylim([-1.0 1.0]);
line([0 cos(2*pi*7/(20*2))],[0 sin(2*pi*7/(20*2))],'Color','r')
line([0 cos(2*pi*7/(20*2))],[0 -sin(2*pi*7/(20*2))],'Color','r')
line([0 cos(2*pi*13/(20*2))],[0 sin(2*pi*13/(20*2))],'Color','r')
line([0 cos(2*pi*13/(20*2))],[0 -sin(2*pi*13/(20*2))],'Color','r')
260 5 Z-Transform

Fig. 5.31 Pole zero plot and frequency response (magnitude) of Example 5.8

The frequency response in Fig. 5.31 shows the overall frequency distribution of
the given pole zero configuration. The red lines also represent the section division
for individual configuration. While the symmetric pole-zero pairs over the unit
circle illustrate the relatively flat frequency response as expected, the rest of the
configurations such as medium radius and close pairs and close poles to the unit
circle & far pairs barely demonstrate the individual characteristics in the response.
The peaky distribution in the high frequency range is derived from the pole zero
locations; however, the peak values are not consistent due to the mutual effect from
neighbors.

Example 5.9
Build the LPF as below. Place the 7 zeros and 7 poles in every 2p=20 radian angles
in low frequency section with close symmetric form over unit circle. Locate 13
zeros on the unit circle in every 2p=20 radian for rest of angles. Fix 13 poles on the
origin. The desired cutoff frequency of the LPF is the 0:35 p from above configu-
ration. Inspect the frequency response. Is the overall response close to the indi-
vidual response combination? Show by MATLAB result.
Solution
With arbitrary parameter values, the transfer function is created as below.
Q3  Q  
20 k z1
j2p 20k z1
10;9 j2p
k¼3 1  1:01e k¼4 1  e
H ðzÞ ¼ Q3   for jzj [ 0:99
k¼3 1  0:99e 20k z1
j2p

The pole zero plot and frequency response are shown in Fig. 5.32. The red line
ð0:35 pÞ divide the frequencies between pole-zero configurations in the figure.
5.3 Intuitive Filter Design 261

Fig. 5.32 Pole zero plot and frequency response (magnitude) of Example 5.9

Prog. 5.13 MATLAB program for Fig. 5.32

syms z k;
w = linspace(0,pi,100);
w1 = linspace(0,pi,10);
wd = 2*pi/20;
a1 = 0.99;
HD1 = symprod((1-a1*exp(1j*wd*k)*z^-1),k,-3,3);
HN1 = symprod((1-(2-a1)*exp(1j*wd*k)*z^-1),k,-3,3);
HN2 = symprod((1-exp(1j*wd*k)*z^-1),k,4,6);
HN3 = symprod((1-exp(1j*wd*k)*z^-1),k,-6,-4);
HN4 = symprod((1-exp(1j*wd*k)*z^-1),k,7,10);
HN5 = symprod((1-exp(1j*wd*k)*z^-1),k,-9,-7);
H1 = HN1*HN2*HN3*HN4*HN5/(HD1);
hz1 = subs(H1,z,exp(1j*w));
hz2 = eval(hz1);
[N,D] = numden(H1);
a = sym2poly(D);
b = sym2poly(N);

figure,
plot(w,abs(hz2)/max(abs(hz2))), grid
axi1 = axis;
line([2*pi*7/(20*2) 2*pi*7/(20*2)],[axi1(3) axi1(4)],'Color','r')
xlim([0 pi]);
xlabel('\omega');
ylabel('|H(e^{j\omega})|')
figure,
zplane(b,a), grid
xlim([-1.3 1.3]);
ylim([-1.0 1.0]);
line([0 cos(2*pi*7/(20*2))],[0 sin(2*pi*7/(20*2))],'Color','r')
line([0 cos(2*pi*7/(20*2))],[0 -sin(2*pi*7/(20*2))],'Color','r')
262 5 Z-Transform

In Fig. 5.32, the low frequency configuration is preserved, and the rest of the
frequencies are covered by the zeros on the unit circle in order to create the LPF.
The desired cutoff frequency of the LPF is the 0:35 p for passing band; however, the
magnitude of the LPF is collapsing earlier than expected in the frequency response.
The red line in the figure divides the individual pole zero configuration. The zeros
on the unit circle shows the strong convergence to the zero magnitude and the unit
magnitude is maintained by the symmetric pole zero pairs over the unit circle.
Therefore, the given pole zero configuration provides the overall LPF without
satisfying the designated specification.

Based on the Z-transform, the pole zero placement delivers the IIR filter design
method in relaxed manner. We may select the single frequency to be amplified or
reduced its magnitude over the IIR filter via approaching the pole or zero to the unit
circle in the z plane. The single frequency manipulation is well predictable by the
simple calculation in the Z-transform; however, the conventional broadband filters
such as LPF, HPF, BPF, and BSF cannot be realized by the simple Z-transform
based the method. Between the poles and zeros, the non-linear correlation to the
magnitude and phase provides design complexity to the designated IIR filter. In
addition, the Z-transform functionality limits the IIR filter design method. Note that
the DTFT and DFT directly compute the frequency magnitude and phase; hence,
the FIR filter can be designed from the approximated closed method based on the
transforms. The Z-transform represents the rational function to figure out the poles/
zeros for signal or filter property and dose not deliver the frequency information
directly. The advanced methods to design the IIR and FIR filter will be introduced
following chapter.

5.4 Relation with Fourier Analysis

Three transforms for discrete time signal are provided previously. The only DFT
can be computed by the numerical processing based on the computer and the other
transforms can be performed by the symbolic mathematics for analytic purpose.
The discrete time signal model and counterpart domain representation are denoted
by Table 5.7. The x; a, and r real value and the n, k, and N are integer value in the
equations. As the n increases the integer value, the individual magnitude frequency
terms such as X ðejx0 Þejx0 n , X ½k0 ej2pk0 n=N , and a0 r0n ejx0 n generate the periodic signals
in order to deliver the real value signal. The DTFT and DFT illustrate each fre-
quency component as the delta function signal to represent the magnitude as well as
frequency locations in the domain. The Z-transform shows the linear combination
of rational functions to indicate the poles and zeros of the signal in the z domain.
5.4 Relation with Fourier Analysis 263

Table 5.7 Three transformations with time and counterpart domain


Discrete time domain Counterpart domain
       
DTFT x½n ¼ X ejx0 ejx0 n þ X ejx1 ejx1 n X ejx ¼ 2p X ejx0 dðx  x0 Þ
 jx  jx n  jx 
þX e 2 e 2 þ... þ 2p X e 1 dðx  x1 Þ
 
þ 2p X ejx2 dðx  x2 Þ þ . . .
X ½k  ¼ NX ½k0 d½k  k0 
2p
DFT x½n ¼ X ½k0 ej N k0 n
þ X ½k1 e j2p
N k1 n j2p
þ X ½k2 eN k2 n þ... þ NX ½k1 d½k  k1 
þ NX½k2 d½k  k2  þ . . .
Z-transform x½n ¼ a0 r0n ejx0 n a0 a1
X ðzÞ ¼ þ
1  r0 ejx0 z1 1  r1 ejx1 z1
þ a1 r1n ejx1 n þ a2 r2n ejx2 n þ . . . a2
þ þ...
1  r2 ejx2 z1

In the previous discussion, we have learned that the Z-transform includes the
DTFT and DFT in mathematical viewpoint. The Z-transform can be converted to
the DTFT and DFT; however, the Z-transform itself is not the almighty transform to
design and analyze the signal and filter. The purpose of individual transform is
distinctive. The Z-transform is used to design the IIR filter. The DTFT and DFT is
utilized to design the FIR filter. The only DFT is adopted to show the frequency
information by using the numerical computer. The transforms are powerful tool to
design and analyze the signal and system. Once you use the weapon properly, the
information and filter perform what you asked for.

5.5 Problems

1. Find the Z-transform of following signals with associated ROC.


– x½n ¼ u½n  u½n  10
– x½n ¼ 2n u½n
– x½n ¼ 2n þ 1 u½n  1
– x½n ¼ 3jnj
2. Find the Z-transform of following signals with associated ROC.

x ½ n ¼ n2 u½ n
264 5 Z-Transform

Use the property below.

n2 u½n ¼ nu½n  fu½n þ u½n  1g

Note that the above property is derived from below.

X
n X
n
n2 ¼ kþ ð k  1Þ
k¼0 k¼0

Compute the following values by using the initial value and final value
theorem.

x½0 ¼
x½1 ¼

Check the below condition in z domain.

x ½ n 2 R

If the new x[n] is below, check the real value condition again.

x½n ¼ jn2 u½n

3. Find the inverse Z-transform of following signals.


– X ðzÞ ¼ 1312 z2 for jzj [ 3
– X ðzÞ ¼ 1312 z2 for jzj\3
1
– X ðzÞ ¼ 11:5z
1:5z
1 z2 for jzj [ 2
1
– X ðzÞ ¼ 11:5z
1:5z
1 z2 for 0:5\jzj\2

4. Evaluate the frequency magnitude of following signals by using Z-transform.


– x½n ¼ 0:5n u½n Compute jH ðejx Þjjx¼p
  3

– x½n ¼ 0:7n cos p3 n u½n Compute jH ðejx Þjjx¼p


3

– x½n ¼ en u½n Compute jH ðejx Þjjx¼p


2
5.5 Problems 265

5. From the given pole-zero plots, derive time domain signals and analyze the
stability.

Poles at ± zeros at 0 (dual) Pole at -0.8 zero at 0

Pole at 0 Pole at 0.5 zeros at 0

6. If the Problem 5 solutions provide the impulse response h[n] of the system,
derive the difference equations. Assume that the system is in the initial at rest
condition.
7. Design the LPF with IIR structure. Use the minimum order. Zero frequency
gain is one and p=4 frequency gain is less than 0.2. See Fig. 5.20 to determine
the order and coefficient. Derive the difference equation.
8. Design the BPF with IIR structure. Use the minimum order. p=2 frequency gain
is one and p=4 frequency gain is less than 0.2. See Fig. 5.22 to determine the
order and coefficient. Derive the difference equation.
9. Design the LPF with IIR structure. Use the minimum order. Approximately
maintain the unit magnitude up to p=6. p=4 frequency gain is  0:7 and p=2
frequency gain is  0:2. See Fig. 5.24 to determine the order and coefficient.
Derive the difference equation.
10. Design the BSF. Use the minimum order. p=2 frequency gain is zero. Derive
the difference equation. Is this IIR or FIR?
266 5 Z-Transform

References

1. Ragazzini, J.R., Zadeh, L.A.: The analysis of sampled-data systems. Transactions of the
American Institute of Electrical Engineers, Part II: Applications and Industry 71(5), 225–234
(1952). https://doi.org/10.1109/TAI.1952.6371274
2. Larson, R.: Algebra & Trigonometry. Cengage Learning (2016)
3. Wikipedia: Partial fraction decomposition (2020). https://en.wikipedia.org/w/index.php?title=
Partial_fraction_decomposition&oldid=954972624
4. Oppenheim, A.V., Schafer, R.W.: Discrete-Time Signal Processing. Prentice Hall (1989)
5. Wikipedia: Z-transform (2020). https://en.wikipedia.org/w/index.php?title=Z-
transform&oldid=963886924
6. Hazewinkel, M.: Encyclopaedia of Mathematics: Orbit—Rayleigh Equation. Springer,
Netherlands (2012)
Chapter 6
Filter Design

We designed the primitive filters based on the time and frequency domain. The
convolution sum operation is used to derive the time domain filter and DTFT (or
DFT) is utilized to figure out the FIR filter. The IIR filter is devised from the
Z-transform in the previous chapter. We already knew the simple methods to design
the basic filter structures. Are these all? Did we miss something? Why we have filter
design chapter after all? In general, the filter design is the part of system con-
struction to realize the specific purpose. The target performance is achieved by the
dedicated filter operation specified by the sophisticated numbers known as speci-
fications. The previous filter designs only follow personal intuition and ambiguous
number for filter implementation; hence, the constructed filter likely shows the
unstable performance in overall.
This chapter improves the filter design methods to satisfy the further require-
ments. We can specify the parameters for transition, ripple, order, etc. in filter shape
over frequency domain. The detailed filter requirements can increase the system
feasibility by reducing the error propagation from uncertainty. This chapter is ini-
tiated from the parameter list and meaning followed by FIR and IIR filter design
methods to meet the complex requirements. Although the extensive theories for
filter analysis and design are existed in various publications, the specification
parameters and design methods in this book are selected from MATLAB contents.
The MATLAB already contains the effective and stable design methods in the
software toolboxes for successful realization with reduced concerning on the
realization complexity. Further implementations beyond the MATLAB territory can
be found on the Chap. 7.

© Springer Nature Singapore Pte Ltd. 2021 267


K. Kim, Conceptual Digital Signal Processing with MATLAB,
Signals and Communication Technology,
https://doi.org/10.1007/978-981-15-2584-1_6
268 6 Filter Design

6.1 Filter Specifications

The digital filter requires the specifications in terms of magnitude, frequency, and
order. The magnitude in filter specifies the gain for the corresponding frequency.
Note that the gain is the ratio between the output amplitude to the input amplitude
and the filter magnitude is the function in terms of the frequency. Below is the
example to show the filter example in Fig. 6.1.

a1 ejh1 jx1 n a1 ejh1 jx1 n


x½n ¼ a1 cosðx1 n þ h1 Þ ¼ e þ e
2 2 ð6:1Þ
jh2
y½n ¼ a2 cosðx1 n þ h2 Þ ¼ a2 e2 ejx1 n þ a2 e2 ejx1 n
jh2

The input and output are the x[n] and y[n] for frequency x1 , respectively. The
given sinusoid amplitude is a1 and a2 for input and output, correspondingly. The
filter gain can be simply computed as a2/a1 in time domain once we have time
domain equation for the input and output. Using the Euler equation, we can obtain
the frequency domain representation for positive and negative x1 . The complex
scalar portion in front of the exponential frequency presents the complex amplitude
for the corresponding frequency. The absolute value of the complex number rep-
resents the absolute amplitude such as a1/2 for input and a2/2 for output as shown in
Eq. (6.2). Therefore, the filter magnitude or gain is equivalent to the time domain
result. If the modelled signal equations are not available, we can use the transfor-
mation from the discrete time domain data.
  jx    jx  a1
X e 1  ¼ X e 1  ¼
2
  jx    jx  a2
Y e 1  ¼ Y e 1  ¼
2 ð6:2Þ
jY ðejx1 Þj jY ðejx1 Þj a2
¼ ¼
jX ðejx1 Þj jX ðejx1 Þj a1

The filter selectively passes or suppresses certain frequencies in general; hence,


passing band shows unit magnitude and suppressing band exhibits the very small
magnitude in designed filter. Therefore, the filter magnitude is represented by the
small or very small values with below decimal point. To improve the readability,
the filter magnitude is described by the decibel unit instead of absolute scale. The
filter magnitude in decibel is shown in Eq. (6.3).

Fig. 6.1 Filter diagram

x[n] LTI Filter y[n]


6.1 Filter Specifications 269

1+Rp

1 0 dB Ap (dB)

1-Rp
Magnitude

0.707 -3 dB

dB
0.5 -6 dB

Rst - Ast (dB)

0 π ω

ωp
ω3dB
ω6dB
ωst
Halfpower frequency ( h) Cutoff frequency ( c)

Fig. 6.2 Filter specification with parameters for LPF

2
MagnitudedB ðx1 Þ ¼ 20 log10 jjXY ððeejx1 ÞÞjj ¼ 10 log10 jY ðejx1 Þj2
jx1 jx1
ð6:3Þ
jX ðe Þj

The beauty of the decibel scale is the compressed and magnified representation
range which indicates the huge and tiny numbers by using the relatively manage-
able numeric. For example, the output amplitude is 0.0001 times less than the input
counterpart. The filter magnitude is 0.0001, 10−4, or –80 dB. The 100,000 gain is
the 105 or 100 dB. Useful decibel numbers are organized as Table 6.1.
Also, due to the logarithm property, the multiplication in the log operator is
equivalent to the addition in outside of the operator. Every 3 dB addition or sub-
pffiffiffi
traction in magnitude demonstrates the 2 multiplication or division in amplitude
ratio respectively. Note that the amplitude square ratio presents the multiplication or
division by 2 in identical situations. The decibel conversion allows the rapid
variations to gradual changes and magnifies the extreme low values to observe the
filter performance in detail.
The filter magnitude specification indicates the desired gain in the pass- and
stop-band in the filter. Not all filters show the straight magnitude distribution and
certain type of the filters creates the magnitude fluctuation over the pass and/or stop
frequency band. Therefore, the filter specification denotes the allowed magnitude
range in passband and the maximum magnitude in stopband. The variance of the
passband gain is described by the upper (1 + Rp; in absolute) and lower limit
(1 – Rp; in absolute) as passband ripple (Ap; in decibel). Note that the passband
ripple represents the peak to peak ripple. However, since the lower is the better in
stopband magnitude, only upper limit (Rst; in absolute) identifies stopband
270

Table 6.1 Useful decibel numbers and its actual ratios


60 dB 40 dB 20 dB 6 dB 3 dB 0 dB −3 dB −6 dB −20 dB −40 dB −60 dB
jY ðejx1 Þj 1,000 100 10 1.995 1.413 1 0.708 0.501 0.1 0.01 0.001
jX ðejx1 Þj pffiffiffi pffiffiffiffiffiffiffiffi
2  2  1=2  1=2
2
jY ðejx1 Þj 1,000,000 10,000 100 3.981 1.995 1 0.501 0.251 0.01 0.0001 0.000001
2
jX ðejx1 Þj 4 2  1=2  1=4
6
Filter Design
6.1 Filter Specifications 271

attenuation (Ast; in decibel). The stopband attenuation illustrates the amount of


decreased magnitude in decibel from the passband magnitude; therefore, the
attenuation is usually represented the negative decibel. By applying the absolute on
the actual attenuation, the positive decibel presents the stopband attenuation. Below
figure displays the magnitudes for LPF specification.
The passband ripple Ap can be derived from the maximum deviation Rp and vice
versa.

AP ¼ 40 log10 ð1 þ Rp Þ ð6:4Þ
AP =2
Rp ¼ 10 20 1 ð6:5Þ

The stopband attenuation Ast can be computed from the minimum attenuation Rst
and vice versa.

Ast ¼ 20 log10 Rst ð6:6Þ


Ast
Rst ¼ 10 20 ð6:7Þ

Example 6.1
Compute the absolute magnitude of following decibel specifications.
– Passband magnitude: 0 dB
– Passband ripple: 1 dB
– Stopband attenuation: 40 dB
Solution

20 log10 Mag: ¼ 0dB; Mag: ¼ 1


AP =2 1=2
Rp ¼ 10 20  1 ¼ 10 20  1 ¼ 0:0593
Ast 40
Rst ¼ 10 20 ¼ 10 20 ¼ 0:01

The above specifications are organized in Table 6.2 to design the certain filter.
We can convert the specifications between the absolute and decibel scale by using
the above relations.

272 6 Filter Design

Table 6.2 Example of specifications


Specifications Absolute scale Decibel scale
Passband magnitude 1 0 dB
 
Maximum deviation/Passband ripple (peak to peak) 0.0593 Rp 1 dB ðAP Þ
Minimum attenuation/Stopband attenuation 0.01 ðRst Þ 40 dB ðAst Þ

Magnitude Response (dB) Magnitude Response (dB)


0
2
-10 1.5
Magnitude (dB)

-20 1

Magnitude (dB)
0.5
-30
0
-40
-0.5
-50
-1
-60 -1.5

-70 -2
0 100 200 300 400 500 600 700 800 900 0 100 200 300 400 500 600 700 800 900
Frequency (Hz) Frequency (Hz)

Magnitude Response Magnitude Response


1.08 0.07
1.06
0.06
1.04
Magnitude

Magnitude

1.02 0.05

1 0.04
0.98
0.03
0.96
0.94 0.02

0.92 0.01
0.9
0
0 100 200 300 400 500 600 700 800 900 0 100 200 300 400 500 600 700 800 900
Frequency (Hz) Frequency (Hz)

Fig. 6.3 Designed LPF based on the Table 6.2 specifications

By using the MATLAB, the designed LPF is shown at Fig. 6.3 in absolute and
decibel scale to meet the Table 6.2 requirement. Note that the frequency specifi-
cation in LPF should be ignored for the time being. Passband magnitude oscillates
between the 0.5 dB (1.0593 in absolute) and –0.5 dB (0.9441 in absolute) to meet
the 1 dB pass band ripple. The stopband attenuation demonstrates the below –
40 dB (0.01 in absolute) magnitude in Fig. 6.3.
6.1 Filter Specifications 273

Prog. 6.1 MATLAB program for Fig. 6.3.

Fpass = 370;
Fstop = 430;
Ap = 1;
Ast = 40;
Fs = 2000;

d = designfilt('lowpassfir','PassbandFrequency',Fpass,...
'StopbandFrequency',Fstop,'PassbandRipple',Ap,...
'StopbandAttenuation',Ast,'SampleRate',Fs);

hfvt = fvtool(d);

Next, the frequency values specify the frequency edges for various type filters.
The conventional units for the frequency are listed as Table 6.3 and the MATLAB
uses the cyclic and normalized frequency. The discrete frequency is used for the
mathematical and numerical computation in general. The corresponding frequencies
are indicated in Table 6.3 as well.
Example 6.2
Calculate the cyclic, discrete, normalized frequency of following situations.
– f = 4000 Hz from fs = 10,000 Hz
– x ¼ p3 from fs = 10,000 Hz
– 16 normalized frequency from fs = 10,000 Hz
Solution

f ¼ 4000 Hz from fs ¼ 10000Hz

f 4000 4p
x ¼ 2p ¼ 2p ¼
fs 10000 5

x 4
Normalized frequency ¼ ¼
p 5
p
x¼ from fs ¼ 10000Hz
3
xfs p 10000 5000
f ¼ ¼ ¼ Hz
2p 3 2p 3
274 6 Filter Design

Table 6.3 Frequency units


Frequency Unit Equivalence Remarks
type
Cyclic f in Hz 0 fs/4 fs/2 This type requires the sampling frequency for digital
frequency filter
 
Discrete x in 0 p/2 p p ¼  f2s is the maximum digital frequency (in
frequency radian/sample meaningful sense)
Normalized None 0 1/2 1 The digital frequency is divided by p; therefore, the 1
frequency is the maximum normalized frequency

x 1
Normalized frequency ¼ ¼
p 3
1
normalized frequency from fs ¼ 10000 Hz
6
p
x ¼ p Normalized frequency ¼
6
xfs p 10000 5000
f ¼ ¼ ¼ Hz
2p 6 2p 6


The particular filter type can be described by multiple frequency edges. For
example, the LPF requires the one edge to divide the low/high frequency compo-
nent and the BPF involves at least two edges to allocate the multiple frequency
bands. Also, the frequency edge can be defined by the one or two parameters due to
the unabrupt transition in the edge. The transition from high to low magnitude is
characterized by the passband frequency and stopband frequency parameter. We
may specify the edge by using the –3 dB (or –6 dB) below magnitude from the
passband magnitude. Table 6.4 summarizes the edge frequency parameters.
The overall LPF specification is illustrated in Fig. 6.2 including the magnitude
and frequency requirements. The next specification, the filter order can be identified
in time domain and z domain. The highest number of input and output delay in time
domain represents the filter order independently. Also, the highest order of the input

Table 6.4 Frequency edge specifications


Frequency edge type Explanation
Passband frequency Frequency transition location for 1  Rp
magnitude
Stopband frequency Frequency transition location for Rst magnitude
Halfpower frequency for 3 dB point Frequency location for –3 dB below from the
below the passband value desired passband magnitude
Cutoff frequency for 6 dB point below Frequency location for –6 dB below from the
the passband value desired passband magnitude
6.1 Filter Specifications 275

and output polynomials in z domain presents the filter order equivalently. For
example, below filter equation establishes the input N order and output (or feed-
back) M order. In the same manner, we can specify the system with N numerator
order and M denominator order. Note that the FIR filer order demonstrates the
arbitrary N input (numerator) order with 1 output (denominator) order due to the
feedback absence.

y½n þ a1 y½n  1 þ a2 y½n  2 þ    þ aM y½n  M 


Z
¼ b0 x ½ n þ b1 x ½ n  1 þ b2 x ½ n  2 þ    þ bN x ½ n  N  $
ð6:8Þ
Y ðzÞ þ a1 Y ðzÞz1 þ a2 Y ðzÞz2 þ    þ aM Y ðzÞzM
¼ b0 X ðzÞ þ b1 X ðzÞz1 þ b2 X ðzÞz2 þ    þ bN X ðzÞzN

Once we have the N/M order filter, the required number of parameters are
(N + 1)/(M + 1) respectively. The numerator involves the b0, b1, b2, …, bN values
and denominator needs the 1, a1, a2, …, aM values. Observe that a0 value should be
1 because of the unit gain for y[n]. Now, the digital filter specifications in terms of
magnitude, frequency, and order are explained in overall.

6.2 FIR Filters

The FIR filter contains the finite length impulse response to provide the frequency
selective filtering on the input signal. Unlike the IIR filter, the FIR filter is dedicated
to the discrete-time implementation; therefore, there is no counterpart of FIR filter
on continuous-time realization. Note that the classic IIR filters are originated from
the continuous-time IIR filters. Due to the finite length, the FIR filters demonstrate
following advantages:
– Linear phase (constant delay for whole frequency range)
– Guaranteed stability
– Finite filter transients in time domain
– High feasibility in hardware and software
The linear phase (constant delay) will be explained in the subsequent section.
The FIR filter provides the stability because the finite h[n] generates the limited
output power based on the convolution sum. The FIR filter transient is finished after
complete overlap between the input x[n] and finite h[n] in convolution sum;
therefore, the FIR filter shows the finite filter transients in time domain. According
to the convolution sum equation, the FIR realization requires the accumulations of
weighted and delayed inputs without feedback. Hence, simple multiply and accu-
mulation is the fundamental computation unit for FIR filter computation.
276 6 Filter Design

1.2 1.2
N = 30 N = 30
N = 50 N = 50
N = 100 1.15 N = 100
1 N = 300 N = 300
N = 500 N = 500
1.1

)|
)|

0.8

j
j

1.05

(e
(e

0.6

LPF
LPF

|H
0.4
|H

0.95
0.2
0.9

0
0 /4 /2 3 /4 0 /4 /2
Radian frequency ( ) Radian frequency ( )

Fig. 6.4 Simple FIR filters for various orders with cutoff frequency p=2

Previous chapter showed the basic FIR filter design by using the brick wall
specification and DTFT and DFT method. We can control the certain parameters of
the basic FIR filter such as cutoff and transition frequency by choosing the proper
filter length. However, the simple method cannot reduce the pronounced oscillating
behavior (a.k.a. Gibbs phenomenon [1]) near the band edges. Figure 6.4 presents
the simple FIR filters for order 30, 50, 100, 300, and 500 with cutoff frequency p=2:

Prog. 6.2 MATLAB program for Fig. 6.4.

b1 = fir1(30,0.5,rectwin(31));
b2 = fir1(50,0.5,rectwin(51));
b3 = fir1(100,0.5,rectwin(101));
b4 = fir1(300,0.5,rectwin(301));
b5 = fir1(500,0.5,rectwin(501));
NN = 2^13;
N1 = NN/2+1;
B1 = fft(b1,NN);
B2 = fft(b2,NN);
B3 = fft(b3,NN);
B4 = fft(b4,NN);
B5 = fft(b5,NN);
findex = linspace(0,2*pi,NN);
ff = findex(1:N1);

plot(ff,abs(B1(1:N1)),ff,abs(B2(1:N1)),ff,abs(B3(1:N1)),ff,abs(B4(1:N1)),ff,abs(
B5(1:N1))), grid
...

As we increase the order, the FIR filter demonstrates reduced overall ripple in
passband/stopband and the sharper response around the cutoff frequency. However,
6.2 FIR Filters 277

the maximum ripple in the passband and stopband are not manageable. Let’s see the
LPF in time domain for further investigation.

  1  xc  x  xc
1
HIdeal LPF ejx ¼
0
Otherwise
Zxc
1 sinðxc nÞ
hIdeal LPF ½n ¼ 1ejxn dx ¼ ð6:9Þ
2p pn
xc

1 1  nc  n  nc
hLPF ½n ¼ hIdealLPF ½nw½n where w½n ¼
0 Otherwise

DTFT   1    
$ HLPF ejx ¼ HIdealLPF ejx  W ejx
2p
Zp
1    
¼ HIdealLPF ejh W ejðxhÞ dh
2p ð6:10Þ
p
Zp  
1  
¼ W ejh HIdealLPF ejðxhÞ dh
2p
p

P
nc sinðx2 ð2nc þ 1ÞÞ
W ðejx Þ ¼ 1ejxn ¼ sinðx2 Þ
ð6:11Þ
n¼nc

The impulse response of the FIR LPF can be seen as the multiplication between
infinite length sinc function hIdeal LPF ½n and finite length window w[n] for finite
response length as shown in Eq. (6.9). The frequency domain representation can be
understood as the convolution integral between brick wall specification
HIdeal LPF ðejx Þ and frequency domain sinc function W ðejx Þ in Eq. (6.10). Figure 6.5
shows the frequency domain sinc function W ðejx Þ: The increased window size cor-
responds to the higher and narrower lobes in Eq. (6.11) and Fig. 6.5.

Fig. 6.5 DTFT of window 120


function w[n] from –nc to nc n c = 15

100 n c = 25

n c = 50

80

60
)
j

40
W(e

20

-20

-40
- - /2 0 /2
Radian frequency ( )
278 6 Filter Design

Prog. 6.3 MATLAB program for Fig. 6.5.

res = 1001;
NN1 = 30;
NN2 = 50;
NN3 = 100;
nc1 = NN1/2;
nc2 = NN2/2;
nc3 = NN3/2;
ome = linspace(-pi,pi,res);
delw = 2*pi/res;
Ww1 = sin((ome+eps)*(2*nc1+1)/2)./sin((ome+eps)/2);
Ww2 = sin((ome+eps)*(2*nc2+1)/2)./sin((ome+eps)/2);
Ww3 = sin((ome+eps)*(2*nc3+1)/2)./sin((ome+eps)/2);

figure,
plot(ome,Ww1,ome,Ww2,ome,Ww3), grid
...

The overall energy in both domains are identical according to the Parseval’s
theorem [2] as Eq. (6.12). We can approximately calculate the energy in discrete
frequency domain xk as well.

X Zp  x 2
sin 2 ð2n c þ 1Þ 
nc
1
12 ¼     dx
n¼nc
2p  sin x2 
p
  2 ð6:12Þ
kc 
1 X x
sin 2k ð2n c þ 1Þ 
     Dx
2p k¼k 
c
sin x2k 

2p
where kc 1; Dx ¼ and xk ¼ p þ kDx
2kc þ 1

The wider window contains the more energy in the frequency domain from
Eq. (6.12). Especially for the increased window size, the main lobe illustrates the
higher and narrower shape in order to present the neat response after convolution
integral in Eq. (6.10). However, the energy ratio between the main lobe and side
6.2 FIR Filters 279

lobe is almost insensitive to the window size. Note that the main lobe is specified as
the area between the first zero crossing on either direction of the origin. We can find
the main lobe edges as Eq. (6.13).
 x
 
ð2nc þ 1Þ
sin
W e ¼ jx   ¼02
sin x2
ð6:13Þ
x 2p
ð2nc þ 1Þ ¼ p xm ¼ 
2 2nc þ 1

R
xm ð þ Þ
2
1
2p jW ðejx Þj dx
Energy at main lobe xm ðÞ
ratio½nc  ¼ Energy at side lobe ¼ R ð6:14Þ
P nc xm ð þ Þ

n¼nc
12 2p
1
jW ðejx Þj2 dx
x m ð Þ

The energy ratio between the main lobe and side lobe is derived at Eq. (6.14)
and plotted in Fig. 6.6. The main lobe presents the about 9.3 times energy than the
side lobe counterpart and the ratio shows nearly constant in terms of window size.
The side lobe in the sinc function contributes to the unwanted spectral leakage
which delivers the power to the neighbor frequencies in the convolution integral
operation. The shaper main lobe provides the focused convolution integral output as
shown in Fig. 6.4. However, we cannot control the side lobe involvement by
changing the window length due to the constant energy ratio.

Fig. 6.6 W ðejx Þ energy ratio 12


between main lobe and side
X 50
lobe for various size window 10 Y 9.298
function w[n]

8
ratio[n c ]

0
20 30 40 50 60 70 80 90 100
nc
280 6 Filter Design

Prog. 6.4 MATLAB program for Fig. 6.6.

res = 1001;
NN = (30:2:200);
nc = NN/2;
ome = linspace(-pi,pi,res);
delw = 2*pi/res;
outWw = [];
zc = 2*pi./(2*nc+1);
zzc = round(zc/delw);
ssrt = ((res-1)/2+1)-zzc;
eend = ((res-1)/2+1)+zzc;
for kk = 1:length(nc)
Ww = sin((ome+eps)*(2*nc(kk)+1)/2)./sin((ome+eps)/2);
outWw = [outWw; Ww];
end
mainPower = [];
sidePower = [];
for kk = 1:length(nc)
temp1 = sum(outWw(kk,ssrt(kk):eend(kk)).^2)*delw/(2*pi);
temp2 = sum(outWw(kk,1:(ssrt(kk)-1)).^2)*delw/(2*pi);
temp3 = sum(outWw(kk,(eend(kk)+1):end).^2)*delw/(2*pi);
mainPower = [mainPower temp1];
sidePower = [sidePower temp2+temp3];
end
rratio = mainPower./sidePower;
stem(nc,rratio),grid
...

Figure 6.7 indicates the maximum ripple situation in the passband and stopband.
The convolution integral between the ideal response HIdeal LPF ðejx Þ and sinc
function W ðejx Þ is denoted as the integral over the shaded area in both cases. The

1.2 1.2
Max
1 1

0.8 0.8
)
)

j
j

0.6 0.6
(e
(e

LPF
LPF

0.4 0.4
H
H

0.2 0.2

0 0
Min
-0.2 -0.2
0 /4 /2 3 /4 0 /4 /2 3 /4
Radian frequency ( ) Radian frequency ( )

Fig. 6.7 Convolution integral between HIdeal LPF ðejx Þ & W ðejx Þ for maximum ripple situations.
Desired filter length is 51 (N) and window length is 25 (nc)
6.2 FIR Filters 281

passband maximum ripple corresponds to the area of main lobe and the side lobe
half. The stopband maximum ripple connects to the area of the side lobe half. Since
the energy ratio is constant, the maximum ripple in passband and stopband cannot
be controllable by changing the window length. The ripples can be narrower but
highest magnitude is consistent.
Prog. 6.5 MATLAB program for Fig. 6.7.

N = 50;
NN = 2^13;
N1 = NN/2+1;
N2 = N/2;
nnn = (-N2:1:N2);
b2 = sin(pi*(nnn+eps)/2)./(pi*(nnn+eps));
wwindow = [ones(1,N/2+1) zeros(1,NN-(N+1)) ones(1,N/2)];
fwin1 = real(fft(wwindow,NN))/(N+1);
fwin2 = fwin1(1:N1);
b3 = [b2 zeros(1,NN-length(b2))];
b4 = circshift(b3,-25);
B2 = fft(b4,NN);
findex = linspace(0,2*pi,NN);
ff = findex(1:N1);
amp1 = (findex <= pi/2);
[M,I] = max(abs(B2(1:N1)));
fwin3 = circshift(fwin1,I);
fwin4 = fwin3(1:N1);
minloc = max(find(ff<=1.692));
fwin5 = circshift(fwin1,minloc);
fwin6 = fwin5(1:N1);

figure,
plot(ff,real(B2(1:N1)),ff,amp1(1:N1),ff,fwin4), grid, hold on;
stem(ff,[fwin4(1:2048) zeros(1,2049)],'Marker','none','Color',[0.93 0.69
0.13]), hold off;
...
aa = text(ff(I),real(B2(I))+0.005,'\leftarrow Max');
aa.FontSize = 10;

figure,
plot(ff,real(B2(1:N1)),ff,amp1(1:N1),ff,fwin6), grid, hold on;
stem(ff,[fwin6(1:2048) zeros(1,2049)],'Marker','none','Color',[0.93 0.69
0.13]), hold off;
...
aa = text(ff(minloc),real(B2(minloc))+0.005,'\leftarrow Min');
aa.FontSize = 10;
282 6 Filter Design

The main lobe with one-half side lobe provides the maximum ripple in passband and
the one-half side lobe presents the maximum ripple in stopband. The both extreme ripple
cases are involved with the one-half side lobe with or without of main lobe presence.
Therefore, the area under the one-half side lobe determines the ripple magnitude away
from the desired response. Hence, the both ripples indicate the identical deviation from
the desired response values. Figure 6.8 shows the boxes and values for the pass-, stop-,
and transition band frequency with maximum ripple values. The passband and stopband
frequency are decided by the ripple values as the corresponding frequencies to the ripple
distance away from the desired magnitude. Each box in the passband and stopband
demonstrates the equal distance from the ideal value in magnitude. As we expected, the
maximum and minimum ripple exhibits the equal deviation from the ideal filter response.
Prog. 6.6 MATLAB program for Fig. 6.8.

N = 50;
NN = 2^13;
N1 = NN/2+1;
N2 = N/2;
nnn = (-N2:1:N2);
b2 = sin(pi*(nnn+eps)/2)./(pi*(nnn+eps));
b3 = [b2 zeros(1,NN-length(b2))];
b4 = circshift(b3,-25);
B2 = real(fft(b4,NN));
findex = linspace(0,2*pi,NN);
ff = findex(1:N1);
amp1 = (findex <= pi/2);
[M1,I1] = max(B2(1:N1));
[M2,I2] = min(B2(1:N1));

figure,
plot(ff,B2(1:N1),ff,amp1(1:N1)), grid
...
straa = sprintf('Max %1.4f',B2(I1));
aa = text(ff(I1),B2(I1)+0.005,[' \leftarrow' straa]);
aa.FontSize = 10;
strbb = sprintf('%1.4f Min',B2(I2));
bb = text(ff(I2)-0.7,B2(I2)+0.005,[strbb '\rightarrow ']);
bb.FontSize = 10;
cc = min(find(B2<(2-B2(I1))));
dd = max(find(B2(1:NN/2)>-B2(I2)));
...
ee = text(ff(cc)-0.27,0.5,'\Delta\omega \rightarrow ');
ee.FontSize = 10;
gg = text(ff(dd),0.5,'\leftarrow \Delta\omega');
gg.FontSize = 10;
6.2 FIR Filters 283

Fig. 6.8 FIR LPF with 51 1.2


sample length based on the Max 1.0897
rectangular window. 1
Dx ¼ xst  xp
0.8

)
j
0.6

(e
LPF
0.4

H
0.2

0
-0.0897 Min

-0.2
0 /4 /2 3 /4
Radian frequency ( )

Above computation for the extreme ripples are derived from the numerical
method. We can calculate the ideal ripples from Eqs. (6.15) and (6.16).
Equation (6.15) calculates the area of main lobe and one-half side. Equation (6.16)
only figures out the one-half side lobe area. The result between the numerical and
ideal are almost equal.

R
2p

sinðx2 ð2nc þ 1ÞÞ 
2nc þ 1
maxðHLPF ðe ÞÞ ¼ jx
sinðx2 Þ
dx  1:0896 ð6:15Þ
p 
nc ¼25;N¼51


2nc2pþ 1
R 
sinðx2 ð2nc þ 1ÞÞ 
minðHLPF ðe ÞÞ ¼
jx
sinðx2 Þ
dx  0:0896 ð6:16Þ
p 
nc ¼25;N¼51

Due to the equal extreme magnitudes in ripple in pass and stop band, Eqs. (6.4)–
(6.7) can be organized to compute the counterpart ripple magnitude in decibel scale.

Rp ¼ Rst
Ap =2 Ast
 1 ¼ 10 20
10 20

 Ap 
Ast ¼ 20 log10 10 40  1 ð6:17Þ
 A 
Ap ¼ 40 log10 10 20 þ 1 ð6:18Þ
st

The FIR design methods introduced in this chapter provide advanced FIR filters
to control the cutoff, transition frequency as well as ripples.
284 6 Filter Design

Linear phase FIR filters


The previous filter designs do not consider the phase information. The magnitude of
the frequency response is important to provide the selective filter function in terms of
the frequency. Based on the determined frequency magnitude by filter, the filter phase
value presents the delay location to complete the sinusoidal waveform. Note that the
sinusoid as a cosðxn þ hÞ is establish by the magnitude, frequency, and phase to
localize its position. From the given frequency x , the filter controls the magnitude
and delay by magnitude multiplication as well as phase addition, respectively. The
filter retards or advances the propagation by adding or subtracting the phase value to
the input individual sinusoid. To maintain the overall shape of the input signal, we
prefer to obtain the constant time delay over the entire frequency domain. In order to
design the constant time delay filter, let’s define the group delay [3] as Eq. (6.19). The
argument function delivers the phase angle of given complex number.
     jx 

d ðejx Þ ¼ grd H ejx ¼  dx


d
arg H e ð6:19Þ

To understand the group delay, we assume to have the arbitrary impulse


response h[n] with time delay nd ðuÞ in terms of frequency u as below.

Rp
h½n ¼ 2p
1
Aðeju Þejuðnnd ðuÞÞ du where Aðeju Þ 2 R ð6:20Þ
p

The frequency response is the DTFT of h[n] as below.


Zp
  1 X1  
H e jx
¼ n¼1
A eju ejuðnnd ðuÞÞ duejxn
2p
p
Zp X1
1  
¼ A eju ejund ðuÞ n¼1 ejðxuÞn du
2p
p
Zp
ð6:21Þ
1   jund ðuÞ
¼ A e ju
e 2pdðx  uÞdu
2p
p
Zp
   
¼ A ejx ejxnd ðxÞ dðx  uÞdu ¼ A ejx ejxnd ðxÞ
p

Apply the group delay function to the frequency response as below.


  d    d
d ejx ¼  arg H ejx ¼  ðxnd ðxÞÞ
dx dx ð6:22Þ
dnd ðxÞ
¼ nd ðxÞ þ x
dx
over x ðnd ðxÞ ¼ constantÞ
6.2 FIR Filters 285

To obtain the constant d ðejx Þ; the nd ðxÞ should be constant over the entire x
frequency domain. Therefore, the phase information xnd ðxÞ shows the linear
variation on x as shown in Eq. (6.23).

nd argðH ðejx ÞÞ ! linear phase
d ðe Þ ¼
jx
dnd ðxÞ ð6:23Þ
nd ðxÞ þ x dx argðH ðejx ÞÞ ! nonlinear

The linear phase FIR filter can be designed from the pure real or pure imaginary
frequency response. The pure real response indicates the zero or p constant phase
and the pure imaginary response specifies the p=2 or p=2 constant phase. The
constant phase shows the zero group delay. The corresponding impulse response h
[n] should be real.

H ðejx Þ 2 R ! jH ðejx Þjej0 or jH ðejx Þjejp
p p ! grdðH ðejx ÞÞ ¼ 0 ð6:24Þ
H ðejx Þ 2 j R ! jH ðejx Þjej2 or jH ðejx Þjej2

jx DTFT H ðejx Þ 2 R ! H ðejx Þ ¼ H ðejx Þ
H ðe Þ $ h½n 2 R ! ð6:25Þ
H ðejx Þ 2 j R ! H ðejx Þ ¼ H ðejx Þ

Zp Zp
  1   1  
H ejx 2 R ! h½n ¼ H ejx ejxn dx ¼ H ejx cosðxnÞdx
2p p
p 0
! even symmetric function
Zp Zp
 jx  1  jx  jxn 1  
H e 2 jR ! h½n ¼ H e e dx ¼ H ejx sinðxnÞdx
2p p
p 0
! odd symmetric function ð6:26Þ

According to the above relations, the even and odd symmetric for impulse
response h[n] provide the zero group delay FIR filter. The symmetricity and pattern
generate the four types of FIR filter with zero group delay as shown below. The
type I, II, III, and IV shows the unique symmetric patterns. After designing the zero
group delay FIR filter, the h[n] is shifted to right to observe the filter causality. The
time shift in the impulse response presents the linear phase property in frequency
domain as shown in Eq. (6.27).

DTFT
h½n  nd  $ H ðejx Þejxnd ð6:27Þ

The four types of FIR filter for zero group delay are listed as below.
Type I: Even symmetric function with even filter order (odd filter length)

hI ½n ¼ hI ½n ð6:28Þ


286 6 Filter Design

hI ½n ¼ hI ½0d½n þ hI ½1ðd½n  1 þ d½n þ 1Þ þ hI ½2ðd½n  2 þ d½n þ 2Þ


þ    þ hI ½K ðd½n  K  þ d½n þ K Þ
 jx  X1
HI e ¼ n¼1 I
h ½nejxn ð6:29Þ
¼ hI ½0 þ hI ½1ejx þ hI ½1ejx þ hI ½2ejx2 þ hI ½2ejx2 þ   
P
þ hI ½K ejxK þ hI ½K ejxK ¼ hI ½0 þ 2 Kn¼1 hI ½n cosðxnÞ

Type II: Even symmetric function with odd filter order (even filter length)

hII ½n ¼ hII ½n  1ðhII ½n ¼ hII ½n þ 1also possibleÞ ð6:30Þ

hII ½n ¼ hII ½0ðd½n þ d½n þ 1Þ þ hII ½1ðd½n  1 þ d½n þ 2Þ
þ hII ½2ðd½n  2 þ d½n þ 3Þ þ    þ hII ½K ðd½n  K  þ d½n þ ðK þ 1ÞÞ
 jx  X1
HII e ¼ n¼1 II
h ½nejxn
     
¼ hII ½0 1 þ ejx þ hII ½1 ejx þ ejx2 þ hII ½2 ejx2 þ ejx3 þ   
 
þ hII ½K  ejxK þ ejxðK þ 1Þ
x  x x x
 3x 
¼ ej 2 hII ½0 ej 2 þ ej 2 þ ej 2 hII ½1 ej 2 þ ej 2
3x

x
 5x  x
 ð2K þ 1Þx ð2K þ 1Þx

þ ej 2 hII ½2 ej 2 þ ej 2 þ    þ ej 2 hII ½K  ej 2 þ ej 2
5x

xP  
¼ 2ej 2 Kn¼0 hII ½n cos x2 ð2n þ 1Þ for hII ½n ¼ hII ½n  1
ð6:31Þ
x
XK x 
¼ 2ej 2 h II ½ n  cos ð 2n  1 Þ for hII ½n ¼ hII ½n þ 1
n¼1 2

Type III: Odd symmetric function with even filter order (odd filter length)

hIII ½n ¼ hIII ½n ðhIII ½0 ¼ 0 due to the odd symmetricityÞ ð6:32Þ

hIII ½n ¼ hIII ½1ðd½n  1  d½n þ 1Þ þ hIII ½2ðd½n  2  d½n þ 2Þ þ   
þ hIII ½K ðd½n  K   d½n þ K Þ
 jx  X1
HIII e ¼ h ½nejxn
n¼1 III
¼ hIII ½1ejx  hIII ½1ejx þ hIII ½2ejx2  hIII ½2ejx2 þ   
þ hIII ½K ejxK  hIII ½K ejxK
XK
¼ 2j n¼1 hIII ½n sinðxnÞ
ð6:33Þ
6.2 FIR Filters 287

Type IV: Odd symmetric function with odd filter order (even filter length)

hIV ½n ¼ hIV ½n  1 ðhIV ½n ¼ hIV ½n þ 1 also possibleÞ ð6:34Þ

hIV ½n ¼ hIV ½0ðd½n  d½n þ 1Þ þ hIV ½1ðd½n  1  d½n þ 2Þ
þ hIV ½2ðd½n  2  d½n þ 3Þ þ    þ hIV ½K ðd½n  K   d½n þ ðK þ 1ÞÞ
 X1

HIV e ¼
jx
n¼1 IV
h ½nejxn
     
¼ hIV ½0 1  ejx þ hIV ½1 ejx  ejx2 þ hIV ½2 ejx2  ejx3 þ   
 
þ hII ½K  ejxK  ejxðK þ 1Þ
x  x x x
 3x 
¼ ej 2 hIV ½0 ej 2  ej 2 þ ej 2 hIV ½1 ej 2  ej 2
3x

x
 5x  x
 ð2K þ 1Þx ð2K þ 1Þx

þ ej 2 hIV ½2 ej 2  ej 2 þ    þ ej 2 hII ½K  ej 2  ej 2
5x

x
X1 x 
¼ 2jej 2 h IV ½ n  sin ð2n þ 1 Þ for hIV ½n ¼ hIV ½n  1
n¼0 2
ð6:35Þ
x
X1  x 
¼ 2jej 2 h ½n sin ð2n  1Þ for hIV ½n ¼ hIV ½n þ 1
n¼1 IV 2

Table 6.5 Four types of zero group delay FIR filters (non-causal FIR filters)
Even filter order (Odd filter length) Odd filter order (Even filter length)
Even
symmetric

hI ½n ¼ hI ½n hII ½n ¼ hII ½n  1


P xP  
HI ðejx Þ ¼ hI ½0 þ 2 Kn¼1 hI ½n cosðxnÞ HII ðejx Þ ¼ 2ej 2 Kn¼0 hII ½n cos x2 ð2n þ 1Þ
Odd
symmetric

hIII ½n ¼ hIII ½n hIV ½n ¼ hIV ½n  1


P xP  
HIII ðejx Þ ¼ 2j Kn¼1 hIII ½n sinðxnÞ HIV ðejx Þ ¼ 2jej 2 Kn¼0 hIV ½n sin x2 ð2n þ 1Þ
288 6 Filter Design

Table 6.6 Variations of type II and IV


Even symmetric Odd symmetric
Odd
filter
order
(Even
filter
order)

hII ½n ¼ hII ½n þ 1 hIV ½n ¼ hIV ½n þ 1


xP   xP  
HII ðejx Þ ¼ 2ej 2 Kn¼1 hII ½n cos x2 ð2n  1Þ HIV ðejx Þ ¼ 2jej 2 Kn¼1 hIV ½n sin x2 ð2n  1Þ

Four types of zero group delay FIR filter are organized in Table 6.5 with
illustrations. The type II and IV variations are listed in Table 6.6 as well. Note that
Tables 6.5 and 6.6 filters are all zero group delay filters.
Table 6.7 shows the examples of causal linear phased FIR filters for type I, II,
III, and IV. Due to the time shift for causality, the ejxN=2 at frequency response
provides the linearity in phase; therefore, the N/2 group delay is expected for all
frequency component x.
The symmetricity and pattern of the linear phased FIR filters also deliver the
restrictions on the filter configuration. Certain frequency style cannot be realized by
the linear phase FIR filter type. Below equations analyze the frequency distribution
of the filter type. The FIR filter controls the frequency response by placing the zeros
in z domain; hence, the Z-transform is applied for analysis.

Type I: Even symmetric function with even filter order (odd filter length)

hI ½n ¼ hI ½n
hI ½n ¼ hI ½0d½n þ hI ½1ðd½n  1 þ d½n þ 1Þ þ hI ½2ðd½n  2 þ d½n þ 2Þ
þ    þ hI ½K ðd½n  K  þ d½n þ K Þ
X1
H I ðzÞ ¼ n¼1 I
h ½nzn ð6:36Þ
1 2 K
¼ hI ½0 þ hI ½1z þ hI ½1z þ hI ½2z þ hI ½2z þ    þ hI ½K z
2
þ hI ½K z K
   
¼ hI ½0 þ hI ½1 z1 þ z þ hI ½2 z2 þ z2 þ   
 K 
þ hI ½K  z þ zK
6.2 FIR Filters 289

Table 6.7 Example of causal linear phased FIR filters for all types
Even filter order N = 4 (Odd filter length L) Odd filter order N = 5 (Even filter length L)
Even symmetric

h½n ¼ h½N  nn o h½n ¼ h½N  n


PN2 PN1  
H ðejx Þ ¼ ejx 2 h N2 þ 2 n¼1 H ðejx Þ ¼ 2ejx 2 N þ1
cos x2 ð2n þ 1Þ
N
h N2 þ n cosðxnÞ
N
n¼0 h n þ
2
2

Odd symmetric

h½n ¼ h½N  n h½n ¼ h½N  n


PN2 PN1  
H ðejx Þ ¼ 2jejx 2 H ðejx Þ ¼ 2jejx 2 N þ1
sin x2 ð2n þ 1Þ
N
þ n sinðxnÞ
N
n¼0 h n þ
N
n¼1 h 2
2
2

There are no specific zeros in z domain. No restrictions mean that all filter types
are possible.

Type II: Even symmetric function with odd filter order (even filter length)

hII ½n ¼ hII ½n  1


hII ½n ¼ hII ½0ðd½n þ d½n þ 1Þ þ hII ½1ðd½n  1 þ d½n þ 2Þ
þ hII ½2ðd½n  2 þ d½n þ 3Þ þ    þ hII ½K ðd½n  K  þ d½n þ ðK þ 1ÞÞ
X1
HII ðzÞ ¼ h ½nzn
n¼1 II
   
¼ hII ½0ð1 þ zÞ þ hII ½1 z1 þ z2 þ hII ½2 z2 þ z3 þ   
    ð6:37Þ
¼ hII ½0ð1 þ zÞ þ z1 hII ½1 1 þ z3 þ z2 hII ½2 1 þ z5 þ   
 
¼ hII ½0ð1 þ zÞ þ z1 hII ½1ð1 þ zÞ 1  z þ z2
 
þ z2 hII ½2ð1 þ zÞ 1  z þ z2  z3 þ z4 þ   
 
¼ ð1 þ zÞ hII ½0 þ z1 hII ½1 1  z þ z2
 

þ z2 hII ½2 1  z þ z2  z3 þ z4 þ   


290 6 Filter Design

Due to the common factor ð1 þ zÞ in Z-transform, z = –1 should be the zero


location. The –1 position at z domain indicates the highest frequency in x domain;
therefore, the HPF is not possible.

H ð1Þ ¼ H ðejx Þjx¼p ¼ 0 ð6:38Þ

Type III: Odd symmetric function with even filter order (odd filter length)

hIII ½n ¼ hIII ½n


hIII ½n ¼ hIII ½1ðd½n  1  d½n þ 1Þ þ hIII ½2ðd½n  2  d½n þ 2Þ þ   
þ hIII ½K ðd½n  K   d½n þ K Þ
X1
HIII ðzÞ ¼ h ½nzn
n¼1 III
¼ hIII ½1z1  hIII ½1z þ hIII ½2z2  hIII ½2z2 þ   
     
¼ hIII ½1 z1  z þ hIII ½2 z2  z2 þ hIII ½3 z3  z3 þ    ð6:39Þ
     
¼ hIII ½1z1 1  z2 þ hIII ½2z2 1  z4 þ hIII ½3z3 1  z6 þ   
    
¼ hIII ½1z1 1  z2 þ hIII ½2z2 1  z2 1 þ z2
  
þ hIII ½3z3 1  z2 1 þ z2 þ z4 þ   
   
¼ 1  z2 hIII ½1z1 þ hIII ½2z2 1 þ z2
 

þ hIII ½3z3 1 þ z2 þ z4 þ   

Due to the common factor ð1  z2 Þ in Z-transform, z ¼ 1 should be the zero


locations. The 1 and –1 position at z domain indicates the lowest and highest
frequency in x domain, respectively; therefore, the LPF and HPF are not possible.

H ð1Þ ¼ H ðejx Þjx¼p ¼ 0
ð6:40Þ
H ð1Þ ¼ H ðejx Þjx¼0 ¼ 0

Type IV: Odd symmetric function with odd filter order (even filter length)

hIV ½n ¼ hIV ½n  1


hIV ½n ¼ hIV ½0ðd½n  d½n þ 1Þ þ hIV ½1ðd½n  1  d½n þ 2Þ
þ hIV ½2ðd½n  2  d½n þ 3Þ þ    þ hIV ½K ðd½n  K   d½n þ ðK þ 1ÞÞ
X1
HIV ðzÞ ¼ h ½nzn
n¼1 IV
   
¼ hIV ½0ð1  zÞ þ hIV ½1 z1  z2 þ hIV ½2 z2  z3 þ   
   
¼ hIV ½0ð1  zÞ þ hIV ½1z1 1  z3 þ hIV ½2z2 1  z5 þ   
 
¼ hIV ½0ð1  zÞ þ hIV ½1z1 ð1  zÞ 1 þ z þ z2
 
þ hIV ½2z2 ð1  zÞ 1 þ z þ z2 þ z3 þ z4 þ   
 
¼ ð1  zÞ hIV ½0 þ hIV ½1z1 1 þ z þ z2
 

þ hIV ½2z2 1 þ z þ z2 þ z3 þ z4 þ   
ð6:41Þ
6.2 FIR Filters 291

Due to the common factor ð1  zÞ in Z-transform, z ¼ 1 should be the zero


location. The 1 position at z domain indicates the lowest frequency in x domain;
therefore, the LPF is not possible. Table 6.8 summarizes the restrictions for each
linear phased FIR filter types.

H ð1Þ ¼ H ðejx Þjx¼0 ¼ 0 ð6:42Þ

Windowing methods for FIR filter


The impulse response of the ideal LPF presents the infinite length in time domain.
To realize the FIR filter, the rectangular window is applied over the ideal response.
Due to the windowing operation, the LPF frequency response shows the constant
level over- and under-shoot around the discontinuity known as Gibb’s phenomenon
[1]. The inevitable Gibb’s phenomenon can be alleviated by choosing the proper
window types since the overall frequency response is determined by the convolu-
tion integral between the ideal response and window function in frequency domain.
The window function basically emphasizes the impulse response center and
underestimates the impulse response edges in time domain. Various types of window
are presented in Tables 6.9 and 6.10. Approximate main lobe width represents the
radian distance between the first zero crossings around the window center in fre-
quency domain. Relative peak side lobe amplitude demonstrates the ratio between
the peak main lobe amplitude and peak side lobe magnitude in decibel scale. The
main lobe width corresponds to the frequency transition between the passband and
stopband. As shown in Fig. 6.7, the main lobe width denotes the radian distance
between the ripple peak in passband and stopband and generally wider than the actual
frequency transition. However, the main lobe width is proportional to the frequency
transition. The peak side lobe in frequency domain window estimates the approxi-
mate ripple magnitude in the frequency response. Exact ripple magnitude can be
calculated by the energy in the side lobes based on the distribution.

Table 6.8 Summary of restrictions for linear phased FIR filters


Filter Filter Filter Symmetry of Zero Frequency
Type Order Length L Function (Causal) Locations Response
N (Order + 1) H ðzÞ Restriction
H ðejx Þ
Type I Even Odd Even No No Restriction
h½n ¼ h½N  n Specific
Zeros
Type II Odd Even Even H ð1Þ ¼ 0 H ðejx Þjx¼p ¼ 0
h½n ¼ h½N  n
Type III Even Odd Odd H ð1Þ ¼ 0 H ðejx Þjx¼0 ¼ 0
h½n ¼ h½N  n H ðejx Þjx¼p ¼ 0
Type IV Odd Even Odd H ð 1Þ ¼ 0 H ðejx Þjx¼0 ¼ 0
h½n ¼ h½N  n
292 6 Filter Design

Table 6.9 Conventional windows


Window Type Defining Equation Approx. Relative
Main Lobe Peak Side
Width Lobe
(radian) Amp. (dB)
Rectangular [3] w½n ¼ 1 0  n  N 4p
N þ1 –13
 2n
Bartlett [3] 0  n  N2 8p
–25
w½n ¼ N 2n N N
2  N 2 nN
  
Hann [3] w½n ¼ 0:5 1  cos 2pn
N 0nN 8p
N –31
(Hanning)
 
Hamming [3] w½n ¼ 0:54  0:46 cos 2pn
N 0nN 8p
N –41
2pn  
Blackman [3] w½n ¼ 0:42  0:5 cos N þ 0:08 cos 4pnN
12p
N –57
0nN
8  2n N þ1
> N : odd ¼ N þ 1 2n 1N þ1n  2
Triangular [3] 8p
> –25
< N
2  N þ1 þ 1 nN
w½n ¼  2n1 2
>
> 1  n  N
: N : even ¼ N 2
2  2n1
N
N
2 þ 1  nN
 
Kaiser [4] 2 12
nN=2
f ðN; bÞ f ðbÞ
I0 b 1 N=2
w½n ¼ I0 ðbÞ 0nN
I0 ðÞ : zeroth-order modified Bessel function of the
first kind

Along with the conventional windows described in Table 6.9, the MATLAB
provides the further windows for various purpose. Certain main lobe width and
peak side lobe are illustrated as the function of parameters due to the complexity.
However, you can figure out the actual numbers by using the MATLAB Window
Designer based on the length and additional parameters. 64-sample length windows
are illustrated at Table 6.11 with frequency domain representation.
Below Table 6.12 summarizes window and corresponding MATLAB functions.
FIR filter design example by window method
By using the window method, design the FIR filter for given specification.
Following procedure provides the analytical and mathematical approach to realize
the designated FIR filter.
Example 6.3
Design the FIR filter for Table 6.13 specification.
Solution
The center of the passband and stopband edge is below. The center frequency is the
cutoff frequency which presents half magnitude in the frequency.

xst  xp p p 3p
xc ¼ xp þ ¼ þ ¼
2 4 8 8
Table 6.10 Further windows
Window Type Defining Equation * Main Lobe Peak Side Lobe
Width
    
Modified Bartlett-Hann [31] w½n ¼ 0:62  0:48 Nn  0:5  þ 0:38 cos 2p Nn  0:5 f ðN Þ –36
6.2 FIR Filters

0nN
(   4pn 6pn
Minimum 4-term Blackman-Harris [32] N þ
a0  a1 cos2pn Sym: f ðN Þ –92
w½n ¼  a2 cos N  a3 cos N  
4pn 6pn
a0  a1 cos N2pn
þ 1 þ a2 cos N þ 1  a3 cos N þ 1 Peri:
0nN
a0 ¼ 0:35875; a1 ¼ 0:48829; a2 ¼ 0:14128; a3 ¼ 0:01168
Bohman [32] wð xÞ ¼ ð1  jxjÞ cosðpjxjÞ þ p1 sinðpjxjÞ  1  x  1 x 2 R f ðN Þ –46
w½n ¼ wð1 þ nDxÞ0  n  N Dx ¼ N2
Chebyshev [33] Equiripple design method f ðN; rÞ Define r by
User
   
Flat top weighted [34] 2pn 4pn f ðN Þ f ðN Þ
w½n ¼ a0  a1 cos þ a2 cos
N N
   
6pn 8pn
 a3 cos þ a4 cos
N N
0nN
a0 ¼ 0:21557895; a1 ¼ 0:41663158; a2 ¼ 0:277263158
a3 ¼ 0:083578947; a4 ¼ 0:006947368
 2
Gaussian [32] an
f ðN; aÞ f ðN; aÞ
12 ðN1Þ=2 Þ Þ
w½n ¼ e  ðN1
2  n  ðN1
2
( 2pn 4pn 6pn
Nuttall-defined minimum 4-term Blackman-Harris a0  a1 cos N þ Sym: f ðN Þ f ðN Þ
w½n ¼  a2 cos N  a3 cos N  
[35] a0  a1 cos N2pn 4pn 6pn
Peri:
þ 1 þ a2 cos N þ 1  a3 cos N þ 1
0nN
a0 ¼ 0:3635819; a1 ¼ 0:4891775; a2 ¼ 0:1365995; a3 ¼ 0:0106411
(continued)
293
Table 6.10 (continued)
294

Window Type Defining Equation * Main Lobe Peak Side Lobe


Width
8  2  3
Parzen [32] >
< 1  6 jnj þ 6 jnj N1 f ðN Þ –53
N=2 N=2 0  jnj  4
w½n ¼  3
>
: 2 1  jnj N1 N1
N=2 4 \jnj  2
N1
 N1
2 n 2
Taylor [36] Smoothed edge version of Chebyshev window at time domain. f ðN; r; nÞ Define r by
User
81  r


Tukey (tapered cosine) [32] < 2 1 þ cos 2pr x2 0  x\ 2r f ðN; rÞ f ðrÞ
r
wð xÞ ¼ 1 
2  x\1  2r
r
:1 2p
2 1 þ cos r x  1 þ 2 1  2r  x  1
w½n ¼ wðnDxÞ 0  n  N Dx ¼ N1
6
Filter Design
Table 6.11 Window functions in time and frequency domain (64 length)
Window Time domain Frequency domain
Rectangular
6.2 FIR Filters

Bartlett

(continued)
295
Table 6.11 (continued)
296

Window Time domain Frequency domain


Hann (Hanning)

Hamming

Window Time domain Frequency domain


(continued)
6
Filter Design
Table 6.11 (continued)
Window Time domain Frequency domain
Blackman
6.2 FIR Filters

Triangular

(continued)
297
Table 6.11 (continued)
298

Window Time domain Frequency domain


Kaiser
b ¼ 0:5

Modified Bartlett-Hann

Window Time domain Frequency domain


(continued)
6
Filter Design
Table 6.11 (continued)
Window Time domain Frequency domain
Minimum 4-term
Blackman-Harris
6.2 FIR Filters

Bohman

Chebyshev
(continued)
299
Table 6.11 (continued)
300

Window Time domain Frequency domain


r = 60

Flat top weighted

Window Time domain Frequency domain


(continued)
6
Filter Design
Table 6.11 (continued)
Window Time domain Frequency domain
Gaussian a ¼ 2:5
6.2 FIR Filters

Nuttall-defined minimum 4-term Blackman-Harris

Parzen
(continued)
301
Table 6.11 (continued)
302

Window Time domain Frequency domain

Taylor n ¼ 4 r ¼ 30

Window Time domain Frequency domain


(continued)
6
Filter Design
Table 6.11 (continued)
Window Time domain Frequency domain
Tukey (tapered cosine) a ¼ 2:5
6.2 FIR Filters
303
304 6 Filter Design

Table 6.12 Discrete-time window summary and MATLAB functions


MATLAB window functions Function description
barthannwin Modified Bartlett-Hann window
bartlett Bartlett window
blackman Blackman window
blackmanharris Minimum four-term Blackman-Harris window
bohmanwin Bohman window
chebwin Chebyshev window
enbw Equivalent noise bandwidth
flattopwin Flat top weighted window
gausswin Gaussian window
hamming Hamming window
hann Hann (Hanning) window
kaiser Kaiser window
nuttallwin Nuttall-defined minimum 4-term Blackman-Harris window
parzenwin Parzen (de la Vallée Poussin) window
rectwin Rectangular window
taylorwin Taylor window
triang Triangular window
tukeywin Tukey (tapered cosine) window

Table 6.13 Given filter specification


Filter specifications Value
Filter type Low pass filter
Filter realization FIR with window method
Filter length N with optimization
Passband frequency (fp) 1000 Hz; xp ¼ p=4
Passband magnitude 0 dB
Passband ripple (peak to peak) 1 dB
Stopband frequency (fst) 2000 Hz; xst ¼ p=2
Stopband attenuation 40 dB
Sampling frequency (fs) 8000 Hz

The frequency transition between the passband and stopband edge is below.
p p p
Dx ¼ xst  xpa ¼  ¼
2 4 4

The main lobe width corresponds to the radian distance between the maximum
and minimum ripple; hence, the main lobe width indicates the wider distance than
the frequency transition Dx as shown in Fig. 6.9.
6.2 FIR Filters 305

1.2

0.8

)
Main Lobe Width
j
(e
LPF 0.6

0.4
H

0.2

-0.2
0 /4 /2 3 /4
Radian frequency ( )

Fig. 6.9 Relationship between main lobe width and Dx. xMainLobeWidth [ Dx

To meet the specification in wider sense, let the main lobe width considered as
frequency transition. Note that the use of the main lobe width designs the filter with
sharper transition than the specification. The rectangular window provides below
main lobe width in Table 6.9.

4p p
 N
15
N þ1 4

We assume that the filter order (N) is 16 for Type I filter. The extreme ripples in
both bands are identical in terms of deviation from the ideal response magnitude.
Also, the deviation is derived from the integral over the one-half side lobe. From
Tables 6.9 and 6.10, we can utilize the relative peak side lobe amplitude which is
usually higher than the deviation. The rectangular window shows the –13 dB for
the relative peak side lobe amplitude and we expect that the filter performance does
not meet the requirement. Realization and evaluation are below.

Z
3p=8
1 sinð3pn=8Þ
hIdeal LPF ½n ¼ 1ejxn dx ¼
2p pn
3p=8


hIdeal LPF ½n for  8  n  8
hrect ½n ¼
0 Otherwise
306 6 Filter Design

Prog. 6.7 MATLAB program for Fig. 6.10.

N = 16;
NN = 2^13;
N1 = NN/2+1;
N2 = N/2;
nnn = (-N2:1:N2);
b2 = sin(3*pi*(nnn+eps)/8)./(pi*(nnn+eps));
b3 = [b2 zeros(1,NN-length(b2))];
b4 = circshi (b3,-8);
B2 = real( (b4,NN));
findex = linspace(0,2*pi,NN);
ff = findex(1:N1);
[M1,I1] = max(B2(1:N1));
[M2,I2] = min(B2(1:N1));

figure,
plot(ff,B2(1:N1)), grid
xlim([0 pi]);
ylim([-0.2 1.2]);
...
straa = sprin ('Max %1.2f dB',40*log10(B2(I1)));
aa = text(ff(I1),B2(I1)+0.005,[' \le arrow' straa]);
aa.FontSize = 10;
strbb = sprin ('%1.2f dB Min',-20*log10(abs(B2(I2))));
bb = text(ff(I2)-0.7,B2(I2)+0.005,[strbb '\rightarrow ']);
bb.FontSize = 10;
...
line([ff(I1) ff(I1)],[-0.2 1.2],'Color','magenta');
line([ff(I2) ff(I2)],[-0.2 1.2],'Color','magenta');
hh = text(ff(I1)-0.1,0.7,'\rightarrow ');
hh.FontSize = 10;
ii = text(ff(I2),0.7,'\le arrow Main Lobe Width');
ii.FontSize = 10;

The filter response fails to satisfy the requirement for passband ripple (1 dB) and
stopband attenuation (40 dB). Choose the further low side lobe window as hanning.
Use the approximation main lobe width of hanning window to determine the filter
order (N) as below.

8p p
 N
32
N 4
6.2 FIR Filters 307

Fig. 6.10 Initial FIR filter 1.2


design with N = 16 for Max 1.68 dB

Table 6.13 specification 1

0.8

)
Main Lobe Width

j
0.6

(e
LPF
0.4

H
0.2

0
21.49 dB Min

-0.2
0 /4 /2 3 /4
Radian frequency ( )

Let the N = 32 for Type I filter. Apply the window as below.



hIdeal LPF ½nwhamm: ½n for  16  n  16
hhamm: ½n ¼
0 Otherwise

Fig. 6.11 Final FIR filter with N = 32 & hanning window for Table 6.13 specification
308 6 Filter Design

Prog. 6.8 MATLAB program for Fig. 6.11.

N = 32;
NN = 2^13;
N1 = NN/2+1;
N2 = N/2;
nnn = (-N2:1:N2);
b2 = sin(3*pi*(nnn+eps)/8)./(pi*(nnn+eps));
b2_1 = b2.*(hanning(length(b2)))';
b3 = [b2_1 zeros(1,NN-length(b2_1))];
b4 = circshi (b3,-16);
B2 = real( (b4,NN));
findex = linspace(0,2*pi,NN);
ff = findex(1:N1);
[M1,I1] = max(B2(1:N1));
[M2,I2] = min(B2(1:N1));

figure(1)
plot(ff,B2(1:N1)), grid
xlim([0 pi]), ylim([-0.2 1.2]);
straa = sprin ('Max %1.2f dB',40*log10(B2(I1)));
aa = text(ff(I1),B2(I1),[' \le arrow' straa]);
aa.FontSize = 10;
strbb = sprin ('%1.2f dB Min',-20*log10(abs(B2(I2))));
bb = text(ff(I2)-0.7,B2(I2),[strbb '\rightarrow ']);
bb.FontSize = 10;
cc = min(find(B2<(2-B2(I1))));
dd = max(find(B2(1:NN/2)>-B2(I2)));
line([ff(I1) ff(I1)],[-0.2 1.2],'Color','magenta');
line([ff(I2) ff(I2)],[-0.2 1.2],'Color','magenta');
figure,
plot(ff,20*log10(abs(B2(1:N1)))), grid
xlim([0 pi]), ylim([-140 20]);
B3 = 20*log10(abs(B2));
straa = sprin ('Max %1.2f dB',40*log10(B2(I1)));
aa = text(ff(I1)-0.63,B3(I1),[ straa '\rightarrow']);
aa.FontSize = 10;
strbb = sprin ('%1.2f dB Min',-20*log10(abs(B2(I2))));
bb = text(ff(I2),B3(I2),['\le arrow ' strbb ]);
bb.FontSize = 10;
line([ff(I1) ff(I1)],[-140 20],'Color','magenta');
line([ff(I2) ff(I2)],[-140 20],'Color','magenta');
6.2 FIR Filters 309

The FIR filter response demonstrates the 0.11 dB maximum passband ripple and
43.94 dB stopband attenuation within filter transition requirement; therefore, the
FIR filter is realized properly. The final step is the shifting right to produce the filter
causality.

h½n ¼ hhamm: ½n  16


The Window Designer from MATLAB provides the various information on the
windows. Once the window type, length and parameters are determined, we can
observe the time and frequency representation about the specific window. Also
following information are presented in Table 6.14.
The described parameters above demonstrate the window information itself.
Note that the overall filter response in frequency domain is the convolution integral
between the ideal response and window function. Hence, the area under the window
function in frequency domain is important. Based on the given values, we cannot
predict the exact ripple magnitudes; however, we can roughly estimate the per-
formance by comparing the values between various windows and parameters.
Figure 6.13 illustrates the filter transition from the given 3 dB main lobe width
(0.078125; See Fig. 6.12). Note that the main lobe width shows radian distance
between the ripple max & min and Δx is the distance between the locations
identified as xp and xst . Usually the Dx is the transition band based on the filter
specification. Once we have passband ripple as 0.11 dB, the stopband ripple can be
calculated as below example due to the equal ripple property. The calculations are
performed based on the Eqs. (6.17) and (6.18) shown again in below.

Table 6.14 MATLAB Window Designer parameters


Parameter Explanation Unit
Leakage factor Power ratio in the sidelobes to the total window Percent
power
Relative sidelobe Height difference between the main lobe peak to the Decibel
attenuation highest side lobe peak
Main lobe width Main lobe width at 3 dB below ð0:708Þ the peak Normalized
(–3 dB) Frequency
310 6 Filter Design

Fig. 6.12 MATLAB Window Designer

Fig. 6.13 FIR filter (N = 32 & hanning window) for Table 6.13 specification with 3 dB main
lobe
6.2 FIR Filters 311

Prog. 6.9 MATLAB program for Fig. 6.13.


N = 32;
NN = 2^13;
N1 = NN/2+1;
N2 = N/2;
nnn = (-N2:1:N2);
mlwT = 0.078125; % From window designer hamming L=33
mlw1 = 3*pi/8+mlwT*pi/2;
mlw0 = 3*pi/8-mlwT*pi/2;
b2 = sin(3*pi*(nnn+eps)/8)./(pi*(nnn+eps));
b2_1 = b2.*(hanning(length(b2)))';
b3 = [b2_1 zeros(1,NN-length(b2_1))];
b4 = circshi (b3,-16);
B2 = real( (b4,NN));
findex = linspace(0,2*pi,NN);
ff = findex(1:N1);
[M1,I1] = max(B2(1:N1));
[M2,I2] = min(B2(1:N1));

figure,
plot(ff,B2(1:N1)), grid, xlim([0 pi]), ylim([-0.2 1.2]);
line([mlw0 mlw0],[-0.2 1.2],'Color','green');
line([mlw1 mlw1],[-0.2 1.2],'Color','green');
hh = text(mlw0-0.1,0.5,'\rightarrow ');
ii = text(mlw1,0.5,'\le arrow Main Lobe 3dB');
line([ff(I1) ff(I1)],[-0.2 1.2],'Color','magenta');
line([ff(I2) ff(I2)],[-0.2 1.2],'Color','magenta');
hh = text(ff(I1)-0.1,0.7,'\rightarrow ');
ii = text(ff(I2),0.7,'\le arrow Main Lobe Width');
figure,
plot(ff,20*log10(abs(B2(1:N1)))), grid, xlim([0 pi]), ylim([-140 20]);
line([mlw0 mlw0],[-140 20],'Color','green');
line([mlw1 mlw1],[-140 20],'Color','green');
hh = text(mlw0-0.78,-100,'Main Lobe 3dB \rightarrow ');
ii = text(mlw1,-100,'\le arrow');
line([ff(I1) ff(I1)],[-140 20],'Color','magenta');
line([ff(I2) ff(I2)],[-140 20],'Color','magenta');
hh = text(ff(I1)-0.57,-120,'Main Lobe \rightarrow ');
ii = text(ff(I2),-120,'\le arrow');
312 6 Filter Design

Example 6.4
Calculate the passband ripple and stopband attenuation from Eqs. (6.17) and (6.18)
to verify the equal ripple property. Also compute the parameters in absolute
magnitude scale.
Solution
 0:11   Ap 
43:94dB ¼ 20 log10 10 40  1 ; Ast ¼ 20 log10 10 40  1
 43:94   Ast 
0:11dB ¼ 40 log10 10 20 þ 1 ; Ap ¼ 40 log10 10 20 þ 1

Compute the ripple magnitude.


0:11 Ap
0:0064 ¼ 10 40  1; Rp ¼ 10 40  1
43:94 Ast
0:0064 ¼ 10 20 ; Rst ¼ 10 20

Find the frequency locations around the cutoff frequency to obtain the Dx .

Dx ¼ xst  xp ¼ H 1 ð0:0064Þ  H 1 ð1  0:0064Þ at first x around xc

Kaiser window method


The Kaiser window [4] is flexible window by changing the order N as well as b
value in the algorithm. The experimentally derived equation for estimating the
parameters are given as Eqs. (6.43) and (6.44).

Dx ¼ xst  xp

Ast ¼ 20 log10 Rst


8
< 0:1102ðAst  8:7Þ Ast [ 50
b ¼ 0:5842ðAst  21Þ0:4 þ 0:07886ðAst  21Þ 21  Ast  50 ð6:43Þ
:
0 Ast \21

st 7:95
N ¼ A2:285Dx ð6:44Þ
6.2 FIR Filters 313

Table 6.15 Given filter specification


Filter specifications Value
Filter type Low pass filter
Filter realization FIR with Kaiser window
Filter length N with optimization
Passband frequency (fp) 1000 Hz; xp ¼ p=4
Passband magnitude 0 dB
Passband ripple (peak to peak) 1 dB
Stopband frequency (fst) 2000 Hz; xst ¼ p=2
Stopband attenuation 40 dB
Sampling frequency (fs) 8000 Hz

Example 6.5
Design the FIR filter for Table 6.15 specification.
Solution
The frequency transition is calculated as below.
p p p
Dx ¼ xst  xp ¼  ¼
2 4 4

The given stopband attenuation and passband ripple are below.

Ast ¼ 40dB; Ap ¼ 1dB

Since the linear phase FIR filter presents the equal maximum ripples in both
bands, the Ast and Ap are mutually related as below.
 1   Ap 
24:55dB ¼ 20 log10 1040  1 ; Ast ¼ 20 log10 10 40  1

 40   Ast 
0:17dB ¼ 40 log10 10 20 þ 1 ; Ap ¼ 40 log10 10 20 þ 1

The Ap ð1dBÞ provides the 24:55dBðAst Þ and the Ast ð40dBÞ derives the
 
0:17dB Ap : The lower Ap and higher Ast are better in filter performance; therefore,
we choose the 40dB Ast and 0:17dB Ap in order to meet the filter requirement.
Calculate b and N based on Eqs. (6.43) and (6.44).

b ¼ 0:5842ðAst  21Þ0:4 þ 0:07886ðAst  21Þ 21  Ast  50

3:3953 ¼ 0:5842ð40  21Þ0:4 þ 0:07886ð40  21Þ

Ast  7:95

2:285Dx
314 6 Filter Design

40  7:95
17:8588 ¼
2:285p=4

Select filter order N as 18 for type I FIR filter. The center of the passband and
stopband edge is below as cutoff frequency.

xst  xp p p 3p
xc ¼ xp þ ¼ þ ¼
2 4 8 8

The impulse response of the ideal LPF is below.

Z
3p=8
1 sinð3pn=8Þ
hIdeal LPF ½n ¼ 1ejxn dx ¼
2p pn
3p=8

Apply the window as below.



hIdeal LPF ½nwKaiser ½n for  9  n  9
hKaiser ½n ¼
0 Otherwise

The computed frequency response is shown in Fig. 6.14.

Fig. 6.14 FIR filter with N = 18 & Kaiser window for Table 6.15 specification
6.2 FIR Filters 315

Prog. 6.10 MATLAB program for Fig. 6.14.

N = 18;
NN = 2^13;
N1 = NN/2+1;
N2 = N/2;
nnn = (-N2:1:N2);
beta = 3.3953;
b2 = sin(3*pi*(nnn+eps)/8)./(pi*(nnn+eps));
b2_1 = b2.*(kaiser(length(b2),beta))';
b3 = [b2_1 zeros(1,NN-length(b2_1))];
b4 = circshi(b3,-N/2);
B2 = real((b4,NN));
findex = linspace(0,2*pi,NN);
ff = findex(1:N1);
[M1,I1] = max(B2(1:N1));
[M2,I2] = min(B2(1:N1));

figure,
plot(ff,B2(1:N1)), grid, xlim([0 pi]), ylim([-0.2 1.2]);
straa = sprin('Max %1.2f dB',40*log10(B2(I1)));
aa = text(ff(I1),B2(I1),[' \learrow' straa]);
aa.FontSize = 10;
strbb = sprin('%1.2f dB Min',-20*log10(abs(B2(I2))));
bb = text(ff(I2)-0.7,B2(I2),[strbb '\rightarrow ']);
bb.FontSize = 10;
line([ff(I1) ff(I1)],[-0.2 1.2],'Color','magenta');
line([ff(I2) ff(I2)],[-0.2 1.2],'Color','magenta');
hh = text(ff(I1)-0.1,0.7,'\rightarrow ');
ii = text(ff(I2),0.7,'\learrow Main Lobe Width');
figure,
plot(ff,20*log10(abs(B2(1:N1)))), grid, xlim([0 pi]), ylim([-140 20]);
B3 = 20*log10(abs(B2));
straa = sprin('Max %1.2f dB',40*log10(B2(I1)));
aa = text(ff(I1)-0.63,B3(I1),[ straa '\rightarrow']);
strbb = sprin('%1.2f dB Min',-20*log10(abs(B2(I2))));
bb = text(ff(I2),B3(I2),['\learrow ' strbb ]);
line([ff(I1) ff(I1)],[-140 20],'Color','magenta');
line([ff(I2) ff(I2)],[-140 20],'Color','magenta');
hh = text(ff(I1)-0.57,-120,'Main Lobe \rightarrow ');
ii = text(ff(I2),-120,'\learrow');
316 6 Filter Design

Calculate the ripple magnitude.


0:14 Ap
0:0081 ¼ 10 40  1; Rp ¼ 10 40  1
43:27 Ast
0:0069 ¼ 10 20 ; Rst ¼ 10 20

Find the frequency locations around the cutoff frequency to obtain the xst and xp
.
p p
xst ¼ H 1 ð0:0069Þ  ; xp ¼ H 1 ð1  0:0081Þ 
2 4
p
Dx ¼ H 1 ð0:0069Þ  H 1 ð1  0:0081Þ 
4

The computed xst and xp are illustrated as the vertical yellow lines in Fig. 6.14.
All specifications shown in Table 6.15 are satisfied with the filter design. The final
step is the shifting right to produce the filter causality.

h½n ¼ hKaiser ½n  9

Type II FIR filter


The Type I linear phase FIR filter is realized based on the real value in frequency
domain since the even symmetry function produces the frequency response in real
values. For example, the Type I filter before the causality shift is demonstrated
below for frequency response.
  XK XK
HI ejx ¼ h ½nejxn ¼ hI ½0 þ 2 n¼1 hI ½n cosðxnÞ 2 R
n¼K I

The Type II is the modified version of the Type I. The modification is made to
locate the symmetric center at the between the samples; therefore, the delay com-
ponent ejx=2 is shown in the frequency domain as below. Except the ejx=2 , the
Type II is pure real response in frequency domain.
  x
XK x 
HII ejx ¼ 2ej 2 h
n¼0 II
½ n  cos ð 2n þ 1 Þ
2
6.2 FIR Filters 317

From the Type II filter, the inverse DTFT provides the impulse response as
below
Z
1 p  jx  jxn
h½ n ¼ HII e e dx
2p p
Z XK x 
1 p x
¼ 2ej 2 h II ½ m  cos ð 2m þ 1 Þ ejxn dx
2p p m¼0 2
Z XK 2m þ 1 2m þ 1
1 p x ejx 2 þ ejx 2 jxn
¼ 2ej 2 h
m¼0 II
½ m  e dx
2p p 2
Z
XK 1 p  jx jx2m þ 1 jx2 jx2m2þ 1

¼ m¼0
h II ½ m  e 2e 2 þ e e ejxn dx
2p p
Z
XK 1 p  jxm jxðm þ 1Þ

¼ m¼0
h II ½ m  e þ e ejxn dx
2p p
XK Z
1 p jxm jxn ð6:45Þ
¼ h
m¼0 II
½ m  e e dx
2p p
X0 Z
1 p jxl jxn
þ l¼K1 II
h ½l  1  e e dx let m þ 1 ¼ l
2p p
XK Z
1 p jxðmnÞ
¼ h II ½ m  e dx
m¼0 2p p
X0 Z
1 p jxðlnÞ
þ l¼K1
h II ½l  1  e dx
2p p
XK X0
¼ h ½md½m  n þ
m¼0 II l¼K1 II
h ½l  1d½l  n
¼ hII ½nfu½n  u½n  ðK þ 1Þg
þ hII ½n  1fu½n þ ðK þ 1Þ  u½ng

where u[n] is unit-step function. The derived h[n] in Eq. (6.45) shows the even
symmetricity over the –1/2 sample location. The hII ½n and hII ½n  1 are con-
catenated mutually for even symmetricity. To implement the Type II filter, Fourier
transform is performed as below. Note that the HII ðejx Þ is multiplied with ejx=2 to
remove the –1/2 center location. For convenience purpose, the x is used for X in
Fourier transform.
318 6 Filter Design

Z1
1 x
h1=2 ðtÞ ¼ ej 2 HII ðxÞejxt dx
2p
1
Z1 XK x 
1
¼ 2 h ½m cos
m¼0 II
ð2m þ 1Þ ejxt dx
2p 2
1
Z1 XK 2m þ 1 2m þ 1
1 ejx 2 þ ejx 2
¼ 2 h ½m
m¼0 II
ejxt dx
2p 2
1
Z1 XK
1 jx2m2þ 1 jxt
¼ h ½me
m¼0 II
e dx
2p
1
Z1 X
1 K jx2m2þ 1 jxt
þ h ½me
m¼0 II
e dx
2p
1
Z1 XK
1 jx2m2þ 1 jxt
¼ h ½me
m¼0 II
e dx ð6:46Þ
2p
1
Z1 X
1 0 jx2l1
þ h ½le
l¼K II
2 jxt
e dx
2p
1

XK Z1
1
ejxð Þ dx
2m þ 1
¼ h ½ m 2 t
m¼0 II 2p
1

X0 Z1
1
ejxð 2 t Þ dx
2l1
þ h ½l
l¼K II 2p
1
XK   X  
2m þ 1 0 2l  1
¼ h
m¼0 II
½ m d t  þ h
l¼K II
½l d t 
2 2
     
2K þ 1 3 1
¼ hII ½K d t þ þ    þ hII ½1d t þ þ hII ½0d t þ
2 2 2
     
1 3 2K þ 1
þ hII ½0d t  þ hII ½1d t  þ    þ hII ½K d t 
2 2 2

The derived h1=2 ðtÞ in Eq. (6.46) shows the even symmetricity over the coor-
dinate origin. To realize the filter, compute the impulse response from the desired
frequency response as below.

Zp
1    
hð nÞ ¼ Hdesired ejx ejxn dx for Hdesired ejx 2 R
2p
p
6.2 FIR Filters 319

Even symmetricity h½n ¼ h½n is implemented by following conversion for


Type II as below.
 
1
hII ½n ¼ h n þ for n
0
2 ð6:47Þ
hII ½n ¼ hII ½n

Parseval’s theorem is applied for verifying the energy between both domains as
Eq. (6.48).

P1 2 Rp 2
n¼1 jhII ½nj  2p jHdesired ðejx Þj dx ð6:48Þ
1
p

Example 6.6
Design the FIR filter for Table 6.16 specification.
Solution
The cutoff frequency and frequency transition are calculated as below.

xst  xp p p 3p
xc ¼ xp þ ¼ þ ¼
2 4 8 8
p p p
Dx ¼ xst  xp ¼  ¼
2 4 4

Based on the rectangular window, main lobe width is below.

4p p
 N
15
N þ1 4

Choose N = 15 for Type II filter.

Table 6.16 Given filter specification


Filter specifications Value
Filter type Low pass filter
Filter realization FIR Type II without window method
Filter length N with optimization
Passband frequency (fp) 1000 Hz; xp ¼ p=4
Passband magnitude 0 dB
Stopband frequency (fst) 2000 Hz; xst ¼ p=2
Sampling frequency (fs) 8000 Hz
320 6 Filter Design

Z
3p=8
1 sinð3pn=8Þ
hIdeal LPF ½n ¼ 1ejxn dx ¼
2p pn
3p=8

sinð3pt=8Þ
Let hIdeal LPF ðtÞ ¼
pt    
15 3
h½n ¼ hIdealLPF d½n þ    þ hIdealLPF d½n  6
2 2
   
1 1
þ hIdealLPF d½n  7 þ hIdealLPF d½n  8
2 2
   
3 15
þ hIdeal LPF d½n  9 þ    þ hIdeal LPF d½n  15
2 2

The performance of the Type II filter is shown below.

Fig. 6.15 Type II FIR filter with N = 15 for Table 6.16 specification. For reference, Type I FIR
filter with N = 16 is also shown
6.2 FIR Filters 321

Prog. 6.11 MATLAB program for Fig. 6.15.

N = 15;
NN = 2^13;
N1 = NN/2+1;
findex = linspace(0,2*pi,NN);
ff = findex(1:N1);
t = -15/2:1:15/2;
n = 0:1:(length(t)-1);
ht = sin(3*pi*(t+eps)/8)./(pi*(t+eps));
B2 = abs( (ht,NN));
[PKS,LOCS]= findpeaks(B2);
M1 = PKS(1);
I1 = LOCS(1);
M2 = PKS(2);
I2 = LOCS(2);

figure,
stem(n,ht),grid
figure,
plot(ff,B2(1:N1)), grid, xlim([0 pi]), ylim([-0.2 1.2]);
straa = sprin ('Max %1.2f dB',40*log10(B2(I1)));
aa = text(ff(I1),B2(I1),[' \le arrow' straa]);
strbb = sprin ('%1.2f dB Min',-20*log10(abs(B2(I2))));
bb = text(ff(I2),B2(I2),[' \le arrow' strbb ]);
line([ff(I1) ff(I1)],[-0.2 1.2],'Color','magenta');
line([ff(I2) ff(I2)],[-0.2 1.2],'Color','magenta');
hh = text(ff(I1)-0.1,0.7,'\rightarrow ');
ii = text(ff(I2),0.7,'\le arrow Main Lobe Width');
figure,
plot(ff,20*log10(abs(B2(1:N1)))), grid, xlim([0 pi]), ylim([-140 20]);
B3 = 20*log10(abs(B2));
straa = sprin ('Max %1.2f dB',40*log10(B2(I1)));
aa = text(ff(I1)-0.63,B3(I1),[ straa '\rightarrow']);
strbb = sprin ('%1.2f dB Min',-20*log10(abs(B2(I2))));
bb = text(ff(I2),B3(I2),['\le arrow ' strbb ]);
line([ff(I1) ff(I1)],[-140 20],'Color','magenta');
line([ff(I2) ff(I2)],[-140 20],'Color','magenta');
hh = text(ff(I1)-0.57,-120,'Main Lobe \rightarrow ');
ii = text(ff(I2),-120,'\le arrow');
322 6 Filter Design

For the verification purpose, apply the Parseval’s theorem over the designed
filter.

Zp Z
3p=8
1   jx 2
H e  dx ¼ 1 12 dx ¼
1 3p 3
¼ ¼ 0:3750
2p 2p 2p 4 8
p 3p=8

X15 0:3624
jh½nj2 ¼ 0:3624 Energy ratio ¼ ¼ 0:9664
n¼0 0:3750


Both type filters are illustrated in Fig. 6.16.

Fig. 6.16 Type I & II LPF


6.2 FIR Filters 323

Prog. 6.12 MATLAB program for Fig. 6.16.

syms n w;
NN = 2^13;
N = 15;
wc = 3/8;
nn = -N/2:1:N/2;
f1 = linspace(0,2,NN);
nn1 = -(N+1)/2:1:(N+1)/2;
nd = -(N+1)/2:1/100:(N+1)/2;
reff = fir1(N,wc);
aa = exp(1j*w*n);
bb = int(aa,w,-pi*wc,pi*wc)/(2*pi);
cc = simplify(bb);
dd = subs(cc,n,nn);
dd1 = subs(cc,n,nn1+eps);
dd2 = subs(cc,n,nd+eps);
ee = eval(dd);
ee1 = eval(dd1);
ee2 = eval(dd2);
B2 = abs( (ee,NN));
B3 = abs( (reff,NN));

figure,
plot(nd,ee2), grid, hold on;
stem(nn,ee)
stem(nn1,ee1), hold off;
legend('h(t)','Type II','Type I');
tle('LPF Impulse Response')
xlabel('n')
ax2 = gca;
ax2.XTick = [-6 -4 -2 -3/2 -1 -1/2 0 1/2 1 3/2 2 4 6];
ax2.XTickLabel = {'-6','-4','-2','-3/2','-1','-1/2','0','1/2','1','3/2','2','4','6'};
ax2.XTickLabelRota on = 90;

According to the Table 6.8, Type II filter cannot be realized as the HPF because
of the fixed zero location at –1. For verification purpose, type II HPF example is
shown below.
Example 6.7
Design the FIR filter for Table 6.17 specification.
324 6 Filter Design

Table 6.17 Given filter specification


Filter specifications Value
Filter type High pass filter
Filter realization FIR Type II without window method
Filter length N with optimization
Passband frequency (fp) 1000 Hz; xp ¼ p=2
Passband magnitude 0 dB
Stopband frequency (fst) 2000 Hz; xst ¼ p=4
Sampling frequency (fs) 8000 Hz

Solution
The center of the passband and stopband edge is below.

xp  xst p p 3p
xc ¼ xst þ ¼ þ ¼
2 4 8 8

The frequency transition between the passband and stopband edge is below.
p p p
Dx ¼ xp  xst ¼  ¼
2 4 4

The main lobe width for rectangular window presents the frequency transition as
previously discussed.

4p p
 N
15
N þ1 4

Let the N = 15 for Type II filter. Realization and evaluation are below.

Z
3p=8 Zp
1 1
hIdealHPF ½n ¼ 1ejxn dx þ 1ejxn dx
2p 2p
p 3p=8

sinðpnÞ sinð3pn=8Þ
¼ 
pn pn
sinðptÞ sinð3pt=8Þ
Let hIdeal HPF ðtÞ ¼ 
pt   pt  
15 3
h½n ¼ hIdealHPF d½n þ    þ hIdealHPF d ½n  6 
2 2
     
1 1 3
þ hIdealHPF d½n  7 þ hIdealHPF d½n  8 þ hIdealHPF d½n  9
2 2 2
 
15
þ    þ hIdeal HPF d½n  15
2
6.2 FIR Filters 325

Fig. 6.17 Type II HPF with N = 15 for Table 6.17 specification. For reference, Type I HPF with
N = 16 is also shown
326 6 Filter Design

Prog. 6.13 MATLAB program for Fig. 6.17.

N = 15;
NN = 2^13;
N1 = NN/2+1;
findex = linspace(0,2*pi,NN);
ff = findex(1:N1);
t = -N/2:1:N/2;
n = 0:1:(length(t)-1);
ht = sin(pi*t)./(pi*t)-sin(3*pi*(t)/8)./(pi*(t));
B2 = abs((ht,NN));
[PKS,LOCS]= findpeaks(B2);
M2 = PKS(2);
I2 = LOCS(2);
M1 = PKS(3);
I1 = LOCS(3);
M3 = PKS(5);
I3 = LOCS(5);

figure,
stem(n,ht),grid, ylim([-0.5 0.5]);
figure,
plot(ff,B2(1:N1)), grid, xlim([0 pi]), ylim([-0.2 1.2]);
straa = sprin('Max %1.2f dB',40*log10(B2(I3)));
aa = text(ff(I3)-0.7,B2(I3),[straa '\rightarrow ' ]);
strbb = sprin('%1.2f dB Min',-20*log10(abs(B2(I2))));
bb = text(ff(I2)-0.7,B2(I2),[strbb '\rightarrow ']);
line([ff(I1) ff(I1)],[-0.2 1.2],'Color','magenta');
line([ff(I2) ff(I2)],[-0.2 1.2],'Color','magenta');
hh = text(ff(I2)-0.1,0.7,'\rightarrow ');
ii = text(ff(I1),0.7,'\learrow Main Lobe Width');
figure,
plot(ff,20*log10(abs(B2(1:N1)))), grid, xlim([0 pi]), ylim([-140 20]);
B3 = 20*log10(abs(B2));
straa = sprin('Max %1.2f dB',40*log10(B2(I3)));
aa = text(ff(I3)-0.63,B3(I3),[ straa '\rightarrow']);
strbb = sprin('%1.2f dB Min',-20*log10(abs(B2(I2))));
bb = text(ff(I2)-0.7,B3(I2),[ strbb '\rightarrow']);
line([ff(I1) ff(I1)],[-140 20],'Color','magenta');
line([ff(I2) ff(I2)],[-140 20],'Color','magenta');
hh = text(ff(I2)-0.57,-120,'Main Lobe \rightarrow ');
ii = text(ff(I1),-120,'\learrow');
6.2 FIR Filters 327

For the verification purpose, apply the Parseval’s theorem over the designed
filter.

Zp Z
3p=8 Zp
1   jx 2
H e  dx¼ 1 12 dx þ
1
12 dx
2p 2p 2p
p p 3p=8
1 5p 5
¼ 2 ¼ ¼ 0:6250
2p 8 8
X15  2
h ½n ¼ 0:5868
n¼0 TypeIIHPF
0:5868
Energy ratio ¼ ¼ 0:9389
0:6250

For Type I and N = 16, the energy ratio is below.


X15  2
h ½n ¼ 0:6124
n¼0 TypeIHPF
0:6124
Energy ratio ¼ ¼ 0:9799
0:6250


Both type filters are illustrated in Fig. 6.18.

Fig. 6.18 Type I & II HPF


328 6 Filter Design

Prog. 6.14 MATLAB program for Fig. 6.18.

NN = 2^13;
N = 15;
nn = -N/2:1:N/2;
f1 = linspace(0,2,NN);
nn1 = -(N+1)/2:1:(N+1)/2;
nd = -(N+1)/2:1/100:(N+1)/2;
ht1 = sin(pi*(nn+eps))./(pi*(nn+eps))-sin(3*pi*(nn+eps)/8)./(pi*(nn+eps));
ht2 = sin(pi*(nn1+eps))./(pi*(nn1+eps))-
sin(3*pi*(nn1+eps)/8)./(pi*(nn1+eps));
ht3 = sin(pi*(nd+eps))./(pi*(nd+eps))-sin(3*pi*(nd+eps)/8)./(pi*(nd+eps));
figure,
plot(nd,ht3), grid
hold on
stem(nn,ht1)
stem(nn1,ht2)
legend('h(t)','Type II','Type I')
hold off
tle('HPF Impulse Response')
xlabel('n')
ax2 = gca;
ax2.XTick = [-6 -4 -2 -3/2 -1 -1/2 0 1/2 1 3/2 2 4 6];
ax2.XTickLabel = {'-6','-4','-2','-3/2','-1','-1/2','0','1/2','1','3/2','2','4','6'};
ax2.XTickLabelRota on = 90;

Due to the generic property of Type II filter, the HPF cannot be realized properly
as shown above. The Type II must have the zero at the –1 location in z domain; in
other words, the filter gain at the highest frequency is zero. As demonstrated above,
the filter magnitude is rapidly decreasing around p radian frequency and highest
ripple can be observed nearby the edge. Also, the energy ratio based on the
Parseval’s theorem presents around 94% which can be compared to the Type I
energy ratio 98%. The unsuccessful representation of the spectrum component
nearby the highest frequency contributes the low energy ratio in Type II HPF filter.
However, the Type I HPF is implemented accurately for N = 16 illustrated above.
Type III FIR filter
In contrast, the Type III filter is implemented by using the pure imaginary value in
frequency domain because the odd symmetry function generates the frequency
response in imaginary values. One example is given below.
PK
HIII ðejx Þ ¼ 2j n¼1 hIII ½n sinðxnÞ 2jR
6.2 FIR Filters 329

Since the hIII ½n is real value, HIII ðejx Þ is the pure imaginary number. According
to the DTFT property, the real hIII ½n should provide the following relation.
  
 jx 
HIII ejx ¼ HIII e

Based on the pure imaginary HIII ðejx Þ; the impulse response hIII ½n can be
derived by the DTFT as Eq. (6.49).

R c2
x Rc1
x
hIII ½n ¼ 2p
1
jkejxn dx þ 1
2p jkejxn dx for k 2 R ð6:49Þ
xc1 xc2

The k is the constant for the frequency domain gain. The computed impulse
response is shown in Eq. (6.50).

Z c2
x Zxc1
1 1
jke jxn
dx þ jkejxn dx
2p 2p
xc1 xc2 ð6:50Þ
k cosðnxc1 Þ  k cosðnxc2 Þ
¼
np

Because of Type III filter property, the HPF and LPF cannot be realized prop-
erly. The Type III must have the zero at –1 and 1 location in z domain; therefore,
the filter gain at the highest and lowest frequency are zero. Let’s see following
example.
Example 6.8
Design the FIR filter for Table 6.18 specification.

Table 6.18 Given filter specification


Filter specifications Value
Filter type Band pass filter
Filter realization FIR Type III without window method
Filter length N = 16
Cutoff frequency 1 (fc1) 1000 Hz; xc1 ¼ p=4
Passband magnitude 0 dB
Cutoff frequency 2 (fc2) 3000 Hz; xc2 ¼ 3p=4
Sampling frequency (fs) 8000 Hz
330 6 Filter Design

Solution
p
Z4 Z4
3p

1 1
hIII ½n ¼ jejxn dx þ jejxn dx
2p 2p
p
3p 4
3pn  
4

cos 4  cos pn
¼ 4
np
h½n ¼ hIII ½8d½n þ    þ hIII ½0d½n  8 þ    þ hIII ½8d½n  16

Fig. 6.19 Type III BPF with N = 16 for Table 6.18 specification
6.2 FIR Filters 331

Prog. 6.15 MATLAB program for Fig. 6.19.

N = 16;
NN = 2^13;
nn = (-N/2:1:N/2)+eps;
ff = linspace(0,2*pi,NN);
wc1 = 1/4;
wc2 = 3/4;
dsr = (ff>wc1*pi & ff<wc2*pi);
hn = (cos(wc2*pi*nn)-cos(wc1*pi*nn))./(pi*nn);
Fout = abs( (hn,NN));
[PKS,LOCS]= findpeaks(Fout);
M2 = PKS(2);
I2 = LOCS(2);
M1 = PKS(1);
I1 = LOCS(1);
[NPKS,NLOCS]= findpeaks(-Fout);
NM1 = NPKS(2);
NI1 = NLOCS(2);

figure,
stem((0:N),hn), grid
figure,
plot(ff(1:NN/2+1),Fout(1:NN/2+1),ff(1:NN/2+1),dsr(1:NN/2+1)), grid, xlim([0
pi]), ylim([0 1.2]);
straa = sprin ('Max %1.2f dB',40*log10(Fout(I2)));
aa = text(ff(I2)-0.63,Fout(I2),[ straa '\rightarrow']);
strbb = sprin ('%1.2f dB Min',-20*log10(Fout(I1)));
bb = text(ff(I1)+0.1,Fout(I1),['\le arrow ' strbb ]);
dBout = 20*log10(Fout);
figure,
plot(ff(1:NN/2+1),dBout(1:NN/2+1)), grid, xlim([0 pi]), ylim([-140 20]);
line([0 pi],[dBout(NI1) dBout(NI1)],'Color',[0.93 0.69 0.13]);
line([0 pi],[dBout(I2) dBout(I2)],'Color',[0.93 0.69 0.13]);
line([0 pi],[dBout(I1) dBout(I1)],'Color',[0.93 0.69 0.13]);
straa = sprin ('Max %1.2f dB',40*log10(Fout(I2)));
aa = text(ff(I2)-0.63,dBout(I2),[ straa '\rightarrow']);
strbb = sprin ('%1.2f dB Min',-20*log10(Fout(I1)));
bb = text(ff(I1)+0.1,dBout(I1),['\le arrow ' strbb ]);

For the verification purpose, apply the Parseval’s theorem over the designed
filter.
332 6 Filter Design

Zp Zp
1   jx 2    
H e  dx¼ 1 H ejx H  ejx dx
2p 2p
p p
p
Z4 Z4
3p

1 1 1 p 1
¼ ðjÞð jÞejxn dx þ ð jÞðjÞejxn dx ¼ 2 ¼
2p 2p 2p 2 2
p
3p
4 4
X15
n¼0
jh½nj2 ¼ 0:4748
0:4748
Energy ratio ¼ ¼ 0:9496
0:5

Type IV FIR filter


The Type IV is the modified version of the Type III. The modification is made to
locate the symmetric center at the between the samples; therefore, the delay com-
ponent ejx=2 is shown in the frequency domain as below. Except the ejx=2 , the
Type IV is pure imaginary in frequency response as below.
  x
XK x 
HIV ejx ¼ 2jej 2 n¼0
h IV ½ n  sin ð 2n þ 1 Þ
2

Similar manner as Type II FIR filter, the inverse DTFT provides the impulse
response as below.
Zp
1  
h½n ¼ HIV ejx ejxn dx
2p
p
Zp XK x 
1 x
¼ 2jej 2 h ½m sin
m¼0 IV
ð2m þ 1Þ ejxn dx
2p 2
p
Zp XK 2m þ 1 2m þ 1
1 x ejx 2  ejx 2
¼ 2jej 2 h ½m
m¼0 IV
ejxn dx
2p 2j
p

XK Zp  
1 x 2m þ 1 x 2m þ 1
¼ h ½m
m¼0 IV
ej 2 ejx 2  ej 2 ejx 2 ejxn dx
2p
p

XK Zp  
1
¼ h ½m
m¼0 IV
ejxm  ejxðm þ 1Þ ejxn dx
2p
p

XK 1
Zp ð6:51Þ
¼ h ½m
m¼0 IV
ejxm ejxn dx
2p
p

X0 Zp
1
 h ½l  1
l¼K1 IV
ejxl ejxn dx let m þ 1 ¼ l
2p
p

XK Zp
1 jxðmnÞ
¼ h ½m
m¼0 IV
e dx
2p
p

X0 Zp
1
 ejxðlnÞ dx
h ½l  1
l¼K1 IV
2p
p
XK X0
¼ h ½md½m  n 
m¼0 IV
h ½l  1d½l  n
l¼K1 IV
¼ hIV ½nfu½n  u½n  ðK þ 1Þg
 hIV ½n  1fu½n þ ðK þ 1Þ  u½ng
6.2 FIR Filters 333

where u[n] is unit-step function. The derived h[n] in Eq. (6.51) shows the odd sym-
metricity over the –1/2 sample location. The hIV ½n and hIV ½n  1 are concatenated
mutually for odd symmetricity. To implement the Type IV filter, Fourier transform is
performed as below. Note that the HIV ðejx Þ is multiplied by ejx=2 to remove the –1/2
center location. For convenience purpose, the x is used for X in Fourier transform.
Z
1 1 jx
h1=2 ðtÞ ¼ e 2 HIV ðxÞejxn dx
2p 1
Z XK x 
1 1
¼  2j m¼0 hIV ½m sin ð2m þ 1Þ ejxt dx
2p 1 2
Z 1 X jx2m2þ 1 2m þ 1
1 K e  ejx 2 jxt
¼  2j m¼0 hIV ½m e dx
2p 1 2j
Z
1 1 XK 2m þ 1
¼ hIV ½mejx 2 ejxt dx
2p 1 m¼0
Z
1 1 XK 2m þ 1
 h ½mejx 2 ejxt dx
m¼0 IV
2p 1
Z
1 1 XK 2m þ 1
¼ h ½mejx 2 ejxt dx
m¼0 IV
2p 1
Z
1 1 X0
hIV ½lejx 2 ejxt dx
2l1

2p 1 l¼K
XK Z
1 1 jxð2m þ 1tÞ
¼ h ½m
m¼0 IV
e 2 dx
2p 1
X0 Z
1 1 jxð2l1tÞ
 l¼k
h IV ½l e 2 dx
2p 1
XK   X0  
2m þ 1 2l  1
¼ h
m¼0 IV
½md t   h
l¼K IV
½ld t 
2 2
     
2K þ 1 3 1
¼ hIV ½Kd t þ      hIV ½1d t þ  hIV ½0d t þ
2 2 2
     
1 3 2K þ 1
þ hIV ½0d t  þ hIV ½1d t  þ    þ hIV ½Kd t 
2 2 2
ð6:52Þ

The derived h1=2 ðtÞ in Eq. (6.52) shows the odd symmetricity over the coordi-
nate origin. To realize the filter, compute the impulse response from the desired
frequency response as below.

Zp
1    
hðnÞ ¼ Hdesired ejx ejxn dx for Hdesired ejx 2 jR
2p
p
 jx   
Hdesired e ¼ Hdesired ejx

Odd symmetricity h½n ¼ h½n is implemented by following conversion for


Type IV as below.
334 6 Filter Design

 
1
hIV ½n ¼ h n þ for n
0
2 ð6:53Þ
hIV ½n ¼ hIV ½n

Parseval’s theorem is applied for verifying the energy between both domains as
Eq. (6.54).

P1 2 Rp 
n¼1 jhIV ½nj  2p Hdesired ðejx ÞHdesired ðejx Þdx ð6:54Þ
1
p

Example 6.9
Design the FIR filter for Table 6.19 specification.
Solution
The center of the passband and stopband edge is below. The center frequency is the
cutoff frequency which presents half magnitude in the frequency.

xp  xst p p 3p
xc ¼ xst þ ¼ þ ¼
2 4 8 8

The frequency transition between the passband and stopband edge is below
p p p
Dx ¼ xp  xst ¼  ¼
2 4 4

The main lobe width for rectangular window presents the frequency transition as
previously discussed.

4p p
 N
15
N þ1 4

Let the N = 15 for Type IV filter. Realization and evaluation are below.

Table 6.19 Given filter specification


Filter specifications Value
Filter type High pass filter
Filter realization FIR Type IV without window method
Filter length N with optimization
Passband frequency (fp) 2000 Hz; xp ¼ p=2
Passband magnitude 0 dB
Stopband frequency (fst) 1000 Hz; xst ¼ p=4
Sampling frequency (fs) 8000 Hz
6.2 FIR Filters 335

Z
3p=8 Zp
1 1
hIdealHPF ½n ¼ jejxn dx þ jejxn dx
2p 2p
p 3p=8

cosðpnÞ cosð3pn=8Þ
¼ 
pn pn
cosðptÞ cosð3pt=8Þ
Let hIdeal HPF ðtÞ ¼ 
pt  pt  
15 3
h½n ¼ hIdealHPF d½n þ    þ hIdealHPF d½n  6
2 2
     
1 1 3
þ hIdealHPF d½n  7 þ hIdealHPF d½n  8 þ hIdealHPF d½n  9
2 2 2
 
15
þ    þ hIdeal HPF d½n  15
2

The performance of the Type IV filter is shown in Fig. 6.20.

Fig. 6.20 Type IV HPF with N = 15 for Table 6.19 specification. For reference, Type I HPF with
N = 16 is also shown
336 6 Filter Design

Prog. 6.16 MATLAB program for Fig. 6.20.

N = 15;
NN = 2^13;
N1 = NN/2+1;
t = -N/2:1:N/2;
n = 0:1:(length(t)-1);
ht = cos(pi*t)./(pi*t)-cos(3*pi*(t)/8)./(pi*(t));
B2 = abs((ht,NN));
findex = linspace(0,2*pi,NN);
ff = findex(1:N1);
[PKS,LOCS]= findpeaks(B2);
M2 = PKS(2);
I2 = LOCS(2);
M1 = PKS(3);
I1 = LOCS(3);
M3 = PKS(3);
I3 = LOCS(3);

figure,
stem(n,ht),grid
figure,
plot(ff,B2(1:N1)), grid, xlim([0 pi]), ylim([-0.2 1.2]);
straa = sprin('Max %1.2f dB',40*log10(B2(I3)));
aa = text(ff(I3)-0.7,B2(I3),[straa '\rightarrow ' ]);
strbb = sprin('%1.2f dB Min',-20*log10(abs(B2(I2))));
bb = text(ff(I2)-0.7,B2(I2),[strbb '\rightarrow ']);
line([ff(I1) ff(I1)],[-0.2 1.2],'Color','magenta');
line([ff(I2) ff(I2)],[-0.2 1.2],'Color','magenta');
hh = text(ff(I2)-0.1,0.7,'\rightarrow ');
ii = text(ff(I1),0.7,'\learrow Main Lobe Width');
figure,
plot(ff,20*log10(abs(B2(1:N1)))), grid, xlim([0 pi]), ylim([-140 20]);
B3 = 20*log10(abs(B2));
straa = sprin('Max %1.2f dB',40*log10(B2(I3)));
aa = text(ff(I3)-0.63,B3(I3),[ straa '\rightarrow']);
strbb = sprin('%1.2f dB Min',-20*log10(abs(B2(I2))));
bb = text(ff(I2)-0.7,B3(I2),[ strbb '\rightarrow']);
line([ff(I1) ff(I1)],[-140 20],'Color','magenta');
line([ff(I2) ff(I2)],[-140 20],'Color','magenta');
hh = text(ff(I2)-0.57,-120,'Main Lobe \rightarrow ');
ii = text(ff(I1),-120,'\learrow');
6.2 FIR Filters 337

For the verification purpose, apply the Parseval’s theorem over the designed
filter.

1 Zp   jx 2 1 Zp  jx    jx 
H e dx ¼ H e H e dx
2p p 2p p
1 3p=8
Z 1 Zp 1 5p 5
ðjÞjdx þ jðjÞdx ¼ 2 ¼ ¼ 0:6250
2p p 2p 3p=8 2p 8 8
X
15
jh½nj2 ¼ 0:6123
n¼0
0:6123
Energy ratio ¼ ¼ 0:9797
0:6250

Advanced example of FIR Type III and Type IV


Differentiator
The differentiator provides the derivative of input signal. The mathematical
derivation in strict sense is complicated to design the differentiator but we simplify
the process by assuming that the discrete n is real number.
 
Rp Rp
d
dn
1
2p X ðejx Þejxn dx ¼ 2p
1
jxX ðejx Þejxn dx n 2 R ð6:55Þ
p p

The corresponding frequency response of the differentiator is shown in


Eq. (6.56).

Hdiff ðejx Þ ¼ jx ð6:56Þ

Due to the odd symmetry in the frequency domain, the FIR Type III and IV are
possible.

Rp
hdiff ½n ¼ 2p
1
jxejxn dx ¼ cosðnpnÞ  sinpnðpn
2
Þ
ð6:57Þ
p

Let the N = 16 for Type III filter.

h½n ¼ hdiff ½8d½n þ    þ hdiff ½0d½n  8 þ    þ hdiff ½8d½n  16


338 6 Filter Design

Let the N = 15 for Type IV filter.


     
15 3 1
h½n ¼ hdiff  d½n þ    þ hdiff  d½n  6 þ hdiff  d½n  7
2 2 2
     
1 3 15
þ hdiff d½n  8 þ hdiff d½n  9 þ    þ hdiff d½n  15
2 2 2

Realization and evaluation are below.


Prog. 6.17 MATLAB program for Fig. 6.21.

syms w n;
NN = 2^13;
N1 = NN/2+1;
findex = linspace(0,2*pi,NN);
f_f = findex(1:N1);
aa = 1j*w*exp(1j*w*n);
bb = int(aa,w,-pi,pi)/(2*pi);
cc = expand(bb);
dd = simplify(cc,'Steps',100);
nn1 = -15/2:1:15/2;
nn2 = -8:1:8;
nn3 = -8:0.001:8;
ee1 = subs(dd,n,nn1);
ee2 = subs(dd,n,nn2+eps);
ee3 = subs(dd,n,nn3+eps);
ff1 = eval(ee1);
ff2 = eval(ee2);
ff3 = eval(ee3);
B1 = abs( (ff1,NN));
B2 = abs( (ff2,NN));

figure,
plot(nn3,ff3), grid, hold on
stem(nn1,ff1)
stem(nn2,ff2), hold off
figure,
plot(f_f,B1(1:N1),f_f,B2(1:N1),f_f,f_f), grid
xlim([0 pi]);
6.2 FIR Filters 339

Fig. 6.21 Type III (N = 16) and Type IV (N = 15) differentiator impulse response and frequency
response

Hilbert transform
Hilbert transform [3, 5] produces the single sideband (SSB) output in frequency
domain. Let’s divide X ðejx Þ for positive, zero, and negative frequency area as
below.
8
< Xp ðejx Þ for p
x [ 0
DTFT
x½n $ X ðe Þ ¼ X0 ðejx Þ for x ¼ 0
jx
ð6:58Þ
:
Xn ðejx Þ for  p\x\0
       
X ejx ¼ Xn ejx þ X0 ejx þ Xp ejx

The desired output in frequency domain is zero and positive frequency area only
as below.
     
Y ejx ¼ X0 ejx þ 2Xp ejx

Therefore, the positive frequency area and the magnitude inversed negative
frequency area are added over the X ðejx Þ to provide the desired output as below.
     
   
X ejx þ Xn ejx þ Xp ejx ¼ X0 ejx þ 2Xp ejx

The above process can be realized by Eq. (6.59) convolution sum with
Eq. (6.60) filter frequency response.
 
     
1 þ jHHi ejx X ejx ¼ X0 ejx þ 2Xp ejx

DTFT
$ x½n þ jhHi ½n  x½n ð6:59Þ
340 6 Filter Design

8
< j for p
x [ 0
HHi ðejx Þ ¼ 0 for x ¼ 0 ð6:60Þ
:
j for  p\x\0

Note that the Eq. (6.59) output is derived by following relation.

f1 þ jHHi ðejx ÞgX ðejx Þ


¼ Xn ðe Þ þ X0 ðe Þ þ Xp ðejx Þ þ jjXn ðejx Þ þ 0X0 ðejx Þ þ jðjÞXp ðejx Þ
jx jx

¼ X0 ðejx Þ þ 2Xp ðejx Þ

Derive the impulse response by using the DTFT with Eq. (6.60). Due to the odd
symmetry in the frequency domain, the FIR Type III and IV are possible.

Z0 Zp  
2
1 1 2 sin pn
hHi ½n ¼ je jxn
dx þ je
jxn
dx ¼ 2
2p 2p np
p 0

Below is the convolution sum for the Hilbert transform. Be careful with the time
delay caused by the causal hHi ½n filter. The x½n and jhHi ½n  x½n should be in phase
to realize the transform; therefore, we should apply the proper delay on the x½n to
synchronize the real and imaginary part of the output.

DTFT  
 
x½n þ jhHi ½n  x½n $ 1 þ jHHi ejx X ejx

We can also use the overall impulse response as below without considering the
phase mismatch problem. The below sinc function is equivalent to the delta func-
tion in Type III filter but the Type IV shows the different distribution in time
domain. Still, the below sinc function deliver the approximate constant magnitude
in frequency domain for Type IV.

sinðpnÞ DTFT  
hIII ½nor hIV ½n ¼ þ jhHi ½n $ 1 þ jHHi ejx
pn

Let the N = 16 for Type III filter.

h½n ¼ hIII ½8d½n þ    þ hIII ½0d½n  8 þ    þ hIII ½8d½n  16

Let the N = 15 for Type IV filter.


     
15 3 1
h½n ¼ hIV  d½n þ    þ hIV  d½n  6 þ hIV  d½n  7
2 2 2
     
1 3 15
þ hIV d½n  8 þ hIV d½n  9 þ    þ hIV d½n  15
2 2 2

Realization and evaluation are below.


6.2 FIR Filters 341

Prog. 6.18 MATLAB program for Fig. 6.22.

syms w n;
NN = 2^13;
N1 = NN/2+1;
findex = linspace(-pi,pi,NN);
f_f = findex(1:N1);
aa = 1j*exp(1j*w*n);
bb = (int(aa,w,-pi,0)+int(-aa,w,0,pi))/(2*pi);
cc = expand(bb);
dd = simplify(cc,'Steps',100);
nn1 = -15/2:1:15/2;
nn2 = -8:1:8;
nn3 = -8:0.001:8;
ee1 = subs(dd,n,nn1);
ee12 = subs(sin(pi*n)/(n*pi),n,nn1);
ee2 = subs(dd,n,nn2+eps);
ee3 = subs(dd,n,nn3+eps);
ff1 = eval(ee1);
ff12 = eval(ee12);
ff2 = eval(ee2);
ff3 = eval(ee3);
gg1 = ff12+1j*ff1;
gg2 = (nn2==0)+1j*ff2;
B1 = shi (abs( (gg1,NN)));
B2 = shi (abs( (gg2,NN)));
B3 = shi (abs( (ff1,NN)));
B4 = shi (abs( (ff2,NN)));
B5 = shi (abs( (ff12,NN)));

figure,
plot(nn3,ff3), grid, hold on
stem(nn1,ff1)
stem(nn2,ff2), hold off
figure,
plot(findex,B1,findex,B2), grid
xlim([-pi pi]);
figure,
plot(findex,B3,findex,B4), grid
xlim([-pi pi]);
342 6 Filter Design

Fig. 6.22 Type III (N = 16) and Type IV (N = 15) Hilbert transform impulse response and
frequency response

Remes Exchange Algorithm (Parks and McClellan)


The Remes exchange algorithm [6, 7] presents the equiripple property in passband
and stopband by changing the trigonometric problem to polynomial equation. The
optimal filter is designed by following the alternation theorem and Remes exchange
algorithm. Let’s derive the Type I FIR filter for Remes exchange algorithm. Below
is the frequency response of the non-causal FIR filter.
   
  N jxN N jxN
H ejx ¼ h e 2 þ    þ h½1ejx þ h½0 þ h½1ejx þ    þ h e 2
2 2
  X
N=2
H ejx ¼ h½0 þ 2 h½ncosðxnÞ
n¼1
ð6:61Þ

Using the Chebyshev polynomial, the cosine part can be represented by the
polynomial as shown in Eq. (6.62).
6.2 FIR Filters 343

T1 ðcosðxÞÞ ¼ cosðxÞ
T2 ðcosðxÞÞ ¼ cosð2xÞ ¼ 2 cos2 ðxÞ  1
T3 ðcosðxÞÞ ¼ cosð3xÞ ¼ 4 cos3 ðxÞ  3 cosðxÞ ð6:62Þ
...
Tn þ 1 ðcosðxÞÞ ¼ 2 cosðxÞTn ðcosðxÞÞ  Tn1 ðcosðxÞÞ

The c[n] in Eq. (6.63) is the Chebyshev polynomial coefficients.

P
N=2
H ðejx Þ ¼ c½n cosn ðxÞ ð6:63Þ
n¼0

Replacing the cosðxÞ with x completes the polynomial representation as shown


in Eq. (6.64).

P
N=2
Let cosðxÞ ¼ x; H ð xÞ ¼ c½nxn 0  x  p  1  x  1 ð6:64Þ
n¼0

Maximal error locations show the zero derivative on the position as Eq. (6.65).

dH ðxÞ
dx ¼0 N
2  1 maximal error locations ð6:65Þ

There are additional four boundaries to generate maximal error such as 0, p , and
two band edges. Overall number of maximal error locations are N=2 þ 3 as shown
in Fig. 6.23.

Two band edges

ω
π

Fig. 6.23 The optimal filter frequency response with maximal error locations for N = 32
344 6 Filter Design

The error function is defined as Eq. (6.66).

E ðejx Þ ¼ W ðejx ÞjDðejx Þ  H ðejx Þj or E ð xÞ ¼ W ð xÞ j D ð xÞ  H ð xÞ j ð6:66Þ

The W ðejx Þ is the positive weight function and Dðejx Þ is the desired real-value
function. According to the alternation theorem, the H ðejx Þ is the unique and best
Chebyshev approximation to a given desired function Dðejx Þ; provided that the
error function E ðejx Þ shows at least N=2 þ 2 maximal error locations. The maximal
error values illustrate identical magnitude with alternative sign. The unweighted
error function is shown in Eq. (6.67).

P
N=2 P
N=2
E ðejx Þ ¼ Dðejx Þ  c½n cosn ðxÞ or E ð xÞ ¼ D ð xÞ  c½nxn ð6:67Þ
n¼0 n¼0

The corresponding maximal error locations are xk or xk where k is 0, 1, 2, …,


N/2 + 1. Let the maximal error magnitude as D. Equation (6.68) presents the
maximal error locations.

  X N=2
D ejxk ¼ c½n cosn ðxk Þ þ ð1Þk D
n¼0
ð6:68Þ
X
N=2
or Dðxk Þ ¼ c½nxnk þ ð1Þk D
n¼0

Equations (6.69) and (6.70) represent the Eq. (6.68) in matrix form.
2 32 3
c½0
N
1 cosðx0 Þ cos2 ðx0 Þ  cos 2 ðx0 Þ 1
61 cosðx1 Þ cos2 ðx1 Þ 
N
cos 2 ðx1 Þ 1 76 c½1 7
6 76 7
61 cosðx2 Þ cos2 ðx2 Þ 
N
cos 2 ðx2 Þ 1 76 c½2 7
6 76 7
61 cosðx3 Þ cos2 ðx3 Þ 
N
cos 2 ðx3 Þ 1 76 .. 7
6 76 . 7
6. .. .. .. .. .. 76 7
4 .. 54 c N 5
 .   .  .  .  .
N=2 þ 1
2
Dm
N
1 cos xN=2 þ 1 cos2 xN=2 þ 1 . . . cos 2 xN=2 þ 1 ð1Þ
2 3
Dðx0 Þ
6 Dðx1 Þ 7
6 7
6 Dðx2 Þ 7
6 7
¼ 6 Dðx3 Þ 7
6 7
6 .. 7
4 5
 . 
D xN=2 þ 1
ð6:69Þ
6.2 FIR Filters 345

Fig. 6.24 Remes exchange


algorithm

2 3
1 x0 x20 
N=2
x0 1 2 3 2 3
6 7 c ½ 0 Dðx0 Þ
61 x1 x21 
N=2
x1 1 76 c½1 7 6 Dðx1 Þ 7
6 76 7 6 7
61 x2 x22 
N=2
x2 1 76 c½2 7 6 Dðx2 Þ 7
6 76 7 6 7
6 N=2 76 .. 7 ¼ 6 Dðx3 Þ 7
61 x3 x23  x3 1 76 . 7 6 7
6. .. .. .. .. .. 76 7 6 .. 7
6. 74 c N 5 4 . 5
4. . . . . . 5 2  
1 xN=2 þ 1 x2N=2 þ 1
N=2
   xN=2 þ 1 ð1ÞN=2 þ 1 D m D xN=2 þ 1

ð6:70Þ

The optimal solution is obtained by the iterative approach as shown in Fig. 6.24.
Note that Dm is the computed D value at the m-th iteration. The dm is the maximum
error value of the given configuration as shown in Eq. (6.71).
 
 X
N=2 
 
dm ¼ max DðxÞ  c½n cosn ðxÞ
x2½0;p 
n¼0
  ð6:71Þ
 X
N=2 
 
or dm ¼ max Dð xÞ  c½nxn 
x2½1;1 
n¼0
346 6 Filter Design

Example 6.10
Design the Table 6.20 FIR filter by using the Remes exchange algorithm.
Solution
From the given filter order 6, the filter response can be defined as below.

  X 3
H ejx ¼ c½n cosn ðxÞ
n¼0

  X 3
D ejxk ¼ c½n cosn ðxk Þ þ ð1Þk D
n¼0

The error function Eðejx Þ shows at least N=2 þ 2 maximal error locations; there-
fore, H ðejx Þ illustrates the 5 peak error locations. The matrix form is shown below.
2 32 3 2 3
1 cosðx0 Þ cos2 ðx0 Þ cos3 ðx0 Þ 1 c½0 Dðejx0 Þ
61 cos3 ðx1 Þ 1 7 6 7 6 jx1 7
6 cosðx1 Þ cos2 ðx1 Þ 76 c½1 7 6 Dðejx Þ 7
61 cosðx2 Þ cos2 ðx2 Þ cos3 ðx2 Þ 1 7 6 c½2 7 ¼ 6 Dðe 2 Þ 7
6 76 7 6 7
41 cosðx3 Þ cos2 ðx3 Þ cos3 ðx3 Þ 1 54 c½3 5 4 Dðejx3 Þ 5
1 cosðx4 Þ cos2 ðx4 Þ cos3 ðx4 Þ 1 Dm Dðejx4 Þ

First trial of frequency set is below.



p p 3p
x ¼ fx0 ; x1 ; x2 ; x3 ; x4 g ¼ 0; ; ; ; p
4 2 4
¼ f0; 0:7854; 1:5708; 2:3562; 3:1416g

Table 6.20 Given filter specification


Filter specifications Value
Filter type Low pass filter
Filter realization FIR Type I without window method
Filter length 7 (N = 6)
Passband frequency (fp) 1000 Hz; xp ¼ p=4
Passband magnitude 0 dB
Stopband frequency (fst) 2000 Hz; xst ¼ p=2
Sampling frequency (fs) 8000 Hz
6.2 FIR Filters 347

The corresponding Dðejx Þ is below


           

D ejx ¼ D ejx0 ; D ejx1 ; D ejx2 ; D ejx3 ; D ejx4 ¼ f1; 1; 0; 0; 0g

Place the x and Dðejx Þ on the matrix form as below.


2 32 3 2 3
1 cosð0Þ
 cos2 ð0Þ cos3 ð0Þ 1 c½0 Dð0Þ
 p
61 cosp4 cos2 p4 cos3 p4 1 7 6 7 6 7
6 76 c½1 7 6 Dp4 7
61 cos p2  cos2 p2  cos3 p2  7 6 7
1 76 c½2 7 ¼ 6 D 2  7
6
6 7
41 cos 3p cos2 3p cos3 3p 1 54 c½3 5 4 D 3p 5
4 4 4 4
1 cosðpÞ cos2 ðpÞ cos3 ðpÞ 1 D0 DðpÞ

Solution of above matrix is below.


2 3 2 3 2 31 2 3
c½0 0:1250 1 cosð0Þ
 cos2 ð0Þ cos3 ð0Þ 1 Dð0Þ
p
6 c½1 7 6 0:9142 7 6 1 cos p cos2 p4 cos3 p4 1 7 6 7
6 7 6 7 6 4 7 6 Dp4 7
6 c½2 7 ¼ 6 0:5000 7 ¼ 6 1 cos p cos2 p2  cos3 p2  1 7 6D 7
6 7 6 7 6 3p
2 7 6 27
4 c½3 5 4 0:4142 5 4 1 cos cos2 3p cos3 3p 1 5 4 D 3p 5
4 4 4 4
D0 0:1250 1 cosðpÞ cos2 ðpÞ cos3 ðpÞ 1 DðpÞ

The computed c[n] with Eq. (6.63) generates the first trial frequency response.

Fig. 6.25 Frequency


response of Remes exchange
algorithm for first trial
348 6 Filter Design

Prog. 6.19 MATLAB program for Fig. 6.25.

syms x
ww = linspace(0,pi,1000);
nf1 = [0; 1/4; 1/2; 3/4; 1];
w1 = nf1*pi;
RR1 = [ones(5,1) cos(w1) (cos(w1)).^2 (cos(w1)).^3 [1; -1; 1; -1; 1]];
DD1 = [1; 1; 0; 0; 0];
CS1 = inv(RR1)*DD1;
HW1 = CS1(1)+CS1(2)*cos(ww)+CS1(3)*cos(ww).^2+CS1(4)*cos(ww).^3;
[M1,I1] = min(HW1);
[M2,I2] = max(HW1);
cc1 = max(find(HW1>(-M1)));
cc = min(find(HW1<(2-M2)));

figure
plot(ww,HW1), grid
xlim([0 pi]);
line([0 ww(cc)],[M2 M2],'Color',[0.93 0.69 0.13]);
line([ww(cc1) pi],[M1 M1],'Color',[0.93 0.69 0.13]);
line([pi/4 pi/4],[-0.2 1.2],'Color','magenta');
line([pi/2 pi/2],[-0.2 1.2],'Color','magenta');
straa = sprin ('Max %1.4f',M2);
aa = text(ww(I2)+0.8,M2,['\le arrow ' straa]);
strbb = sprin ('%1.4f Min',M1);
bb = text(ww(I1)-1.3,M1,[strbb ' \rightarrow']);
hh = text(pi/4-0.1,0.7,'\rightarrow ');
ii = text(pi/2,0.7,'\le arrow Specifica on');

The calculated maximum error d0 for first trial is below and bigger than D0 .
 
 X3 
 
d0 ¼ max DðxÞ  c½n cos ðxÞ ¼ 0:1577 [ 0:1250 ¼ jD0 j
n
x2½0;p 
n¼0

The outcome does not meet the condition ðdm ¼ Dm Þ; therefore, next iteration is
required with new frequency set.

  X 3
dH ðejx Þ X2
H ejx ¼ c½n cosn ðxÞ ¼ ec ½n cosn ðxÞ ¼ 0
n¼0
d cosðxÞ n¼0
6.2 FIR Filters 349

The zero derivative of frequency response provides the new frequency as below.

cosðxÞ ¼ f1:3498; 0:5451g since jcosðxÞj  1

cosðxÞ ¼ 0:5451 and x ¼ 2:1472

Second trial of frequency set is below.


n p p o
x ¼ fx0 ; x1 ; x2 ; x3 ; x4 g ¼ 0; ; ; 2:1472; p
4 2
¼ f0; 0:7854; 1:5708; 2:1472; 3:1416g

The corresponding Dðejx Þ is below


           

D ejx ¼ D ejx0 ; D ejx1 ; D ejx2 ; D ejx3 ; D ejx4 ¼ f1; 1; 0; 0; 0g

Place the x and Dðejx Þ on the matrix form as below.


2 32 3 2 3
1 cosð0Þ cos2 ð0Þ cos3 ð0Þ 1 c½0 Dð0Þ
61 cos2 ð0:7854Þ cos3 ð0:7854Þ 1 7 6 7 6 7
6 cosð0:7854Þ 76 c½1 7 6 Dð0:7854Þ 7
61 cosð1:5708Þ cos2 ð1:5708Þ cos3 ð1:5708Þ 1 7 6 c½2 7 ¼ 6 Dð1:5708Þ 7
6 76 7 6 7
41 cosð2:1472Þ cos2 ð2:1472Þ cos3 ð2:1472Þ 1 54 c½3 5 4 Dð2:1472Þ 5
1 cosð3:1416Þ cos2 ð3:1416Þ cos3 ð3:1416Þ 1 D1 Dð3:1416Þ

Solution of above matrix is below.


2 31 2 3
1 cosð0Þ cos2 ð0Þ cos3 ð0Þ 1 Dð0Þ
61 1 7 6 7
6 cosð0:7854Þ cos2 ð0:7854Þ cos3 ð0:7854Þ 7 6 Dð0:7854Þ 7
61 cosð1:5708Þ cos2 ð1:5708Þ cos3 ð1:5708Þ 1 7 6 Dð1:5708Þ 7
6 7 6 7
41 cosð2:1472Þ cos2 ð2:1472Þ cos3 ð2:1472Þ 1 5 4 Dð2:1472Þ 5
1 cosð3:1416Þ cos2 ð3:1416Þ cos3 ð3:1416Þ 1 Dð3:1416Þ
2 3 2 3
c½0 0:1328
6 c½1 7 6 0:8699 7
6 7 6 7
¼6 7 6
6 c½2 7 ¼ 6 0:5000 7
7
4 c½3 5 4 0:3699 5
D1 0:1328

The computed c[n] with Eq. (6.63) generates the second trial frequency response
as shown in Fig. 6.26.
350 6 Filter Design

Prog. 6.20 MATLAB program for Fig. 6.26. Continued from Prog. 6.19.

% From Prog. 6.19


eq1 = poly2sym(CS1(4:-1:1));
eq2 = diff(eq1);
coeff1 = sym2poly(eq2);
root1 = roots(coeff1);
temp1 = acos(root1);
w2 = w1;
w2(4) = temp1(2);
RR2 = [ones(5,1) cos(w2) (cos(w2)).^2 (cos(w2)).^3 [1; -1; 1; -1; 1]];
DD2 = [1; 1; 0; 0; 0];
CS2 = inv(RR2)*DD2;
HW2 = CS2(1)+CS2(2)*cos(ww)+CS2(3)*cos(ww).^2+CS2(4)*cos(ww).^3;
[M3,I3] = min(HW2);
[M4,I4] = max(HW2);
cc2 = max(find(HW2>(-M3)));
cc3 = min(find(HW2<(2-M4)));

figure,
plot(ww,HW2), grid
xlim([0 pi]);
line([0 ww(cc3)],[M4 M4],'Color',[0.93 0.69 0.13]);
line([ww(cc2) pi],[M3 M3],'Color',[0.93 0.69 0.13]);
line([pi/4 pi/4],[-0.2 1.2],'Color','magenta');
line([pi/2 pi/2],[-0.2 1.2],'Color','magenta');
straa1 = sprin('Max %1.4f',M4);
aa1 = text(ww(I4)+0.8,M4,['\learrow ' straa1]);
strbb1 = sprin('%1.4f Min',M3);
bb1 = text(ww(I3)-1.3,M3,[strbb1 ' \rightarrow']);
hh1 = text(pi/4-0.1,0.7,'\rightarrow ');
ii1 = text(pi/2,0.7,'\learrow Specificaon');

The calculated maximum error d1 for second trial is below and equal to D1 .
 
 X3 
 
d1 ¼ max DðxÞ  c½n cos ðxÞ ¼ 0:1328 ¼ 0:1328 ¼ jD1 j
n
x2½0;p 
n¼0

The outcome satisfies the condition ðdm ¼ Dm Þ: Next step provides the impulse
response h[n] from c[n]. The frequency response from the polynomial is below.
6.2 FIR Filters 351

Fig. 6.26 Frequency


response of Remes exchange
algorithm for second trial

 
H ejx ¼ 0:1328 þ 0:8699 cosðxÞ þ 0:5 cos2 ðxÞ  0:3699 cos3 ðxÞ

Using the reverse Chebyshev polynomial, the polynomial equation converts to


the trigonometric problem as below.

cos2 ðxÞ ¼ ð1 þ cosð2xÞÞ=2


cos3 ðxÞ ¼ ð3 cosðxÞ þ cosð3xÞÞ=4

 jx  1 þ cosð2xÞ
H e ¼ 0:1328 þ 0:8699 cosðxÞ þ 0:5
2

3 cosðxÞ þ cosð3xÞ
 0:3699
4
¼ 0:3823 þ 0:5925 cosðxÞ þ 0:25 cosð2xÞ  0:0925 cosð3xÞ
  ejx þ ejx ej2x þ ej2x
H ejx ¼ 0:3823 þ 0:5925 þ 0:25
2 2
ej3x þ ej3x
 0:0925
2
hpm ½n ¼ 0:0462d½n þ 3 þ 0:125d½n þ 2 þ 0:2962d½n þ 1 þ 0:3823d½n
þ 0:2962d½n  1 þ 0:125d½n  2  0:0462d½n  3
h½n ¼ hpm ½n  3 ¼ 0:0462d½n þ 0:125d½n  1 þ 0:2962d½n  2
þ 0:3823d½n  3 þ 0:2962d½n  4 þ 0:125d½n  5  0:0462d½n  6

The final impulse response h[n] and corresponding H ðejx Þ are illustrated in
Fig. 6.27.
352 6 Filter Design

Fig. 6.27 Type I LPF designed by Remes exchange algorithm with N = 6 for Table 6.20
specification

Prog. 6.21 MATLAB program for Fig. 6.27. Continued from Prog. 6.20.

% From Prog. 6.20


ww = linspace(0,pi,1000);
nn = 0:1:6;
hh = zeros(4,1);
hh(1) = CS2(1)+CS2(3)/2;
hh(2) = CS2(2)+CS2(4)*3/4;
hh(3) = CS2(3)/2;
hh(4) = CS2(4)/4;
hhf = [flipud(hh(2:end))/2; hh(1); hh(2:end)/2];
HW3 = hh(1)+hh(2)*cos(ww)+hh(3)*cos(2*ww)-hh(4)*cos(3*ww);
[M3,I3] = min(HW2);
[M4,I4] = max(HW2);
cc2 = max(find(HW2>(-M3)));
cc3 = min(find(HW2<(2-M4)));

figure,
stem(nn,hhf), grid, ylim([-0.1 0.5]);
figure
plot(ww,HW2), grid, xlim([0 pi]);
line([0 ww(cc3)],[M4 M4],'Color',[0.93 0.69 0.13]);
line([ww(cc2) pi],[M3 M3],'Color',[0.93 0.69 0.13]);
line([pi/4 pi/4],[-0.2 1.2],'Color','magenta');
line([pi/2 pi/2],[-0.2 1.2],'Color','magenta');
straa1 = sprin('Max %1.4f',M4);
aa1 = text(ww(I4)+0.8,M4,['\learrow ' straa1]);
strbb1 = sprin('%1.4f Min',M3);
bb1 = text(ww(I3)-1.3,M3,[strbb1 ' \rightarrow']);
hh1 = text(pi/4-0.1,0.7,'\rightarrow ');
ii1 = text(pi/2,0.7,'\learrow Specificaon');
6.2 FIR Filters 353

The passband ripple Ap can be calculated from the maximum deviation Rp as


below.

AP ¼ 40 log10 ð1 þ Rp Þ

2:1661dB ¼ 40 log10 ð1 þ 0:1328Þ

The equivalent stopband attenuation can be calculated as below.

Ast ¼ 20 log10 Rst

17:5360dB ¼ 20 log10 0:1328

Frequency sampling design—Type I


The frequency sampling method [7, 8] solves the linear equations between the
impulse response and frequency domain amplitude. The equations are given by the
DFT. The impulse response length and frequency (amplitude) sampling dimension
are identical in order to derive the simple unique solution. The solution provides the
coefficients (impulse response) of the desired filter with a frequency response that
exactly passes through the sample points specified by the equations. Therefore, the
frequency sampling method is an interpolation method and not an approximation
approach.
Between the frequency sampling point, there is certain fluctuations. The fre-
quency response exactly passes through the sampling points; however, no response
constraint is exercised between the sample points. The desired frequency response
H ½k shows the symmetric property as below for real ht ½n with length L which is
N + 1 and even N.

H ½k  ¼ H  ½k

The corresponding impulse response can be derived as below.

1XL1
1 X
N=2
2p 2p
ht ½ n ¼ H ½kej L kn ¼ H ½kej L kn
L k¼0 L k¼N=2
  ð6:72Þ
2X
N=2
1 2p
¼ H ½ 0 þ H ½k cos kn
L L k¼1 L
354 6 Filter Design

The DFT analysis equation is below to figure out the frequency response for
Type I FIR filter.

X
N=2
ht ½nej L kn ;
2p
H ½k  ¼ H ½k  2 R
n¼N=2
ð6:73Þ
P
N=2 2p 
¼ ht ½ 0 þ 2 ht ½n cos L kn
n¼1

The matrix form of Eq. (6.73) is below. The exponential part matrix (DFT
matrix) is square matrix with N + 1 by N + 1 size.
2 32 3 2 3
e j L ð 2 Þ 2
2p N N
... ej L ð 2 Þ
2p N
1 ej L ð 2 Þ
2p N
... ej L ð 2 Þ 2
2p N N
ht ½N=2 H ½N=2
6 .. .. .. .. .. 76 .. 7 6 .. 7
6 76 . 7 6 . 7
6 2p . N  . . .  . 7 6 7 6 7
6 ej L ð1Þ 2  ej L ð1Þ
2p
ej L ð1Þ
2p
 ej L ð1Þ 2 7
2p N 6 ht ½1 7 6 H ½1 7
6 1 76 7 6 7
6   76 ht ½0 7 ¼ 6 H ½0 7
6 2p1 N 1 1 1 1 76 7 6 7
6 ej L ð1Þ 2 N 76
ej L ð1Þ 2 76 ht ½1 7 6 7
ej L ð1Þ ej L ð1Þ 7 6 H ½1 7
2p 2p 2p
6  1 
6 .. .. .. .. .. .. .. 76 . 7 6 . 7
4 . . . . . . . 54 .
. 5 4 .
. 5
ej L ð 2 Þ 2 ej L ð 2 Þ ej L ð 2 Þ ej 2 ð 2 Þ 2
2p N N 2p N 2p N 2p N N
 1  ht ½N=2 H ½N=2
ð6:74Þ

The solution to find the impulse response ht[n] is derived by using the inverse
matrix of exponential part as below.
2 3 2 2p N N 31 2 3
ht ½N=2 ej L ð 2 Þ 2 ... ej L ð 2 Þ
2p N
1 ej L ð 2 Þ
2p N
... ej L ð 2 Þ 2
2p N N
H ½N=2
6 .. 7 6 .. .. .. .. .. 7 6 .. 7
6 . 7 6 .  . . .  . 7 6 . 7
6 7 6 7 6 7
6 ht ½1 7 6 ej2pL ð1ÞN2  ej L ð1Þ
2p
ej L ð1Þ
2p
 ej L ð1Þ 2 7 6 H ½1 7
2p N 7 6
6 7 6 1 7
6 ht ½0 7 ¼ 6   7 6 H ½0 7
6 7 6 1 1 1 1 1 7 6 7
6 ht ½1 7 6 ej2pL ð1ÞN2 N 7
ej L ð1Þ 2 7 6 7
ej L ð1Þ ej L ð1Þ 6 H ½1 7
2p 2p 2p
6 7 6  1 
6 .. 7 6 .. .. .. .. .. .. .. 7 6 . 7
4 . 5 4 . . . . . . . 5 4 .. 5
ej L ð 2 Þ 2 ej L ð 2 Þ ej L ð 2 Þ ej 2 ð 2 Þ 2
2p N N 2p N 2p N 2p N N
ht ½N=2  1  H ½N=2
ð6:75Þ

Note that DFT matrix is unitary matrix [9] since its conjugate transpose
(Hermitian conjugate [10]) is the inverse matrix. Also, the DFT matrix represents
Vandermonde matrix [11] with the terms of a geometric progression in each row as
below.
6.2 FIR Filters 355

2 3 2 2p N N 32 3
ht ½N=2 ej L ð 2 Þ 2 ... ej L ð 2 Þ
2p N
1 ej L ð 2 Þ
2p N
... ej L ð 2 Þ 2
2p N N
H ½N=2
6 .. 7 6 .. .. .. 76 .. 7
6 . 7 6 ... .. 76 . 7
6 7 6 2p. N  . .  . 7 6 7
6 ht ½1 7 6 ej L ð1Þ 2 ej L ð1Þ 2 7 6 7
ej L ð1Þ 76 H ½1 7
2p
j2p ð1Þ 2p N
6 7 6  1 eL 
6 ht ½0 7 ¼ 1 6   7 6 H ½ 0 7
6 7 L6 1 1 1 1 1 76 7
6 ht ½1 7 6 ej2pL ð1ÞN2  ej L ð1Þ
2p
1 ej L ð1Þ
2p
 ej L ð1Þ 2 7
2p N 6 H ½1 7
6 7 6 76 7
6 .. 7 6 .. .. .. .. .. .. .. 76 .. 7
4 . 5 4 . . . . . . . 54 . 5
ej L ð 2 Þ 2 ej L ð 2 Þ 1 ej L ð 2 Þ j 2 ð2Þ2
2p N N 2p N 2p N 2p N N
h ½N=2
t   e H ½N=2
ð6:76Þ

The Euler equation compresses the exponential matrix in short form as below for
Type I.
2 32 3 2 3
1 2  2   2
2p  ht ½0 H ½0
61 L ð1Þ1
2 cos2p L ð1Þ2
2 cos2p  2 cos L ð1Þ N2  7 6 ht ½1 7 6 H ½1 7
6 N 7 6 7 6 7
61 2 cos L ð2Þ1
2p
2 cos L ð2Þ2
2p
 2 cos 2p ð 2Þ 7 6 7 6
2 76 ht ½2 7 ¼ 6 H ½2 7
7
6 L
6 .. .. .. .. 76 .. 7 6 .. 7
4. 54 5 4 5
2p. N   2p. N    2p. N  N  . .
1 2 cos L 2 1 2 cos L 2 2  2 cos L 2 2 ht ½N=2 H ½N=2
ð6:77Þ
2 3 2 32 3
ht ½0 1 2  2   2
2p  H ½0
6 7
ht ½1 6 1 2 cos2p
L ð1Þ1 L ð1Þ2
2 cos2p  2 cos L ð1Þ 2  76 H ½1 7
N 76
6 7 6 7
6 7 1 6 1 2 cos 2p
ht ½2 L ð2Þ1 L ð2Þ2
2 cos 2p  N 76
L ð2Þ 2 76 H ½2 7
2 cos 2p 7
6 7 ¼ L6
6 7
.. 6 .. .. .. .. 76 .. 7
4 5
. 4. 54 5
2p. N   2p. N    2p. N  N  .
ht ½N=2 1 2 cos L 2 1 2 cos L 2 2  2 cos L 2 2 H ½N=2
ð6:78Þ
The complete ht ½n is below

ht ½n ¼ ht ½N=2d½n þ N=2 þ    þ ht ½1d½n þ 1 þ ht ½0d½n þ ht ½1d½n  1


þ    þ ht ½N=2d½n  N=2
ð6:79Þ
To make the causal filter, perform the shift operation as below.
h½n ¼ ht ½n  N=2 ð6:80Þ
356 6 Filter Design

Table 6.21 Given filter specification


Filter specifications Value
Filter type Low pass filter
Filter realization FIR Type I without window method
Filter length 7 (N = 6)
Passband frequency (fp) 1000 Hz; xp ¼ p=4
Passband magnitude 0 dB
Stopband frequency (fst) 2000 Hz; xst ¼ p=2
Sampling frequency (fs) 8000 Hz

The frequency sampling design method is identical to the DFT method without
truncation in Sect. 4.5. The required condition is that the impulse response length is
equal to the frequency sampling length. The DFT method output illustrates the
equivalent pattern with frequency sampling design method as shown in Figs. 4.25
and 4.26.
Example 6.11
Design the Table 6.21 FIR filter by using the frequency sampling design.
Solution
According to the filter length, 2p radian frequency is divided into 7 segments as
below.
   
2p 2p
H ½k  $ H k ¼H k
L 7

First trial of frequency set is below.



2p 2p 2p
x ¼ fx0 ; x1 ; x2 ; x3 g ¼ 0; ;2 ;3
7 7 7

The corresponding H ½k  is below based on the LPF specification from


Table 6.21.
2 3 2 3
H ½ 0 1
6 H ½ 1 7 6 1 7
6 7 6 7
4 H ½ 2 5 ¼ 4 0 5
H ½ 3 0
6.2 FIR Filters 357

The DFT synthesis equation in short matrix form compute the impulse response
half as below.
2 3 2 32 3
ht ½0 1 2  2
2p  2
2p  H ½0
6 ht ½1 7 1 6 1 ð Þ1 2 cos 7 ð1Þ3 76 7
6 7 6 2 cos2p 1  2 cos  7 ð1Þ2 76 H ½1 7
4 ht ½2 5 ¼ 7 4 1
7
54 H ½2 5
7 ð2Þ1 2 cos 7 ð2Þ2
2 cos2p 2 cos 7 ð2Þ3
2p 2p

ht ½3 1 2 cos 7 ð3Þ1 2 cos 2p


2p
7 ð3Þ2 2 cos 7 ð3Þ3
2p
H ½3
2 3 2 32 3
0:4286 1 2  2  2
2p  1
6 0:3210 7 1 6 1 2 cos 7 ð1Þ3 7 617
6 7 6 7 ð1Þ1
2 cos2p 7 ð1Þ2
2 cos2p 76 7
4 0:0793 5 ¼ 7 4 1 54 0 5
7 ð2Þ1
2 cos2p 7 ð2Þ2
2 cos2p 7 ð2Þ3
2 cos2p
0:1146 1 7 ð3Þ1
2 cos 2p 7 ð3Þ2
2 cos 2p 2 cos 2p
7 ð 3 Þ3 0

The frequency response of first trial is shown in Fig. 6.28.


 Observe that the stem
plot is the design locations. The transition frequency Dx xst  xp in Fig. 6.28
occupies further range than the specification; therefore, the first trial should be
modified.

Fig. 6.28 Frequency


response of first trial by
frequency sampling design
method LPF
358 6 Filter Design

Prog. 6.22 MATLAB program for Fig. 6.28.

ww = linspace(0,pi,1000);
nn = (0:6);
RR = [1 2 2 2; ...
1 2*cos(2*pi/7) 2*cos(2*pi*2/7) 2*cos(2*pi*3/7); ...
1 2*cos(2*pi*2/7) 2*cos(2*pi*2*2/7) 2*cos(2*pi*2*3/7); ...
1 2*cos(2*pi*3/7) 2*cos(2*pi*3*2/7) 2*cos(2*pi*3*3/7)];
HH = [1; 1; 0; 0];
ht = RR*HH/7;
HW3 = ht(1)+2*ht(2)*cos(ww)+2*ht(3)*cos(2*ww)+2*ht(4)*cos(3*ww);
hn = [flipud(ht); ht(2:end)];
w0 = [0 2*pi/7 2*2*pi/7 2*3*pi/7];
mag0 = [1 1 0 0];

figure,
plot(ww,HW3), grid, xlim([0 pi]), hold on
stem(w0, mag0), hold off
[M3,I3] = min(HW3);
[M4,I4] = max(HW3);
cc2 = max(find(HW3>(-M3)));
cc3 = min(find(HW3<(2-M4)));
line([0 ww(cc3)],[M4 M4],'Color',[0.93 0.69 0.13]);
line([ww(cc2) pi],[M3 M3],'Color',[0.93 0.69 0.13]);
line([pi/4 pi/4],[-0.4 1.2],'Color','magenta');
line([pi/2 pi/2],[-0.4 1.2],'Color','magenta');
straa1 = sprin('Max %1.4f',M4);
aa1 = text(ww(I4)+0.5,M4,['\learrow ' straa1]);
strbb1 = sprin('%1.4f Min',M3);
bb1 = text(ww(I3)-1.3,M3,[strbb1 ' \rightarrow']);
hh1 = text(pi/4-0.1,0.7,'\rightarrow ');
ii1 = text(pi/2,0.7,'\learrow Specificaon');

To comply with specification, the new H ½k value is below.


2 3 2 3
H ½0 1
6 H ½1 7 6 1 7
6 7 6 7
4 H ½2 5 ¼ 4 0:05 5
H ½3 0

The corresponding impulse response is below.


6.2 FIR Filters 359

2 3 2 32 3
0:4143 1 2  2
2p  2
2p  1
6 0:3242 7 1 6 1 2 cos 2p ð1Þ1 2 cos 7 ð1Þ2 2 cos 7 ð1Þ3 7 6 7
6 7¼ 6 2p
7  76 1 7
4 0:0922 5 7 4 1 2 cos ð2Þ1 2 cos 7 ð2Þ2 2 cos 7 ð2Þ3
2p 2p 5 4 0:05 5
2p
7 
0:1235 1 2 cos 7 ð3Þ1 2 cos 7 ð3Þ2 2 cos 7 ð3Þ3
2p 2p
0

The frequency response of second trial is shown in Fig. 6.29. The transition
frequency in Fig. 6.29 is located within the specification. You may further evaluate
the LPF for better performance.
Prog. 6.23 MATLAB program for Fig. 6.29.
ww = linspace(0,pi,1000);
nn = (0:6);
RR = [1 2 2 2; ...
1 2*cos(2*pi/7) 2*cos(2*pi*2/7) 2*cos(2*pi*3/7); ...
1 2*cos(2*pi*2/7) 2*cos(2*pi*2*2/7) 2*cos(2*pi*2*3/7); ...
1 2*cos(2*pi*3/7) 2*cos(2*pi*3*2/7) 2*cos(2*pi*3*3/7)];
HH = [1; 1; -0.05; 0];
ht = RR*HH/7;
HW3 = ht(1)+2*ht(2)*cos(ww)+2*ht(3)*cos(2*ww)+2*ht(4)*cos(3*ww);
hn = [flipud(ht); ht(2:end)];
w0 = [0 2*pi/7 2*2*pi/7 2*3*pi/7];
mag0 = [1 1 -0.05 0];

figure,
plot(ww,HW3), grid, xlim([0 pi]), hold on
stem(w0, mag0), hold off
[M3,I3] = min(HW3);
[M4,I4] = max(HW3);
cc2 = max(find(HW3>(-M3)));
cc3 = min(find(HW3<(2-M4)));
line([0 ww(cc3)],[M4 M4],'Color',[0.93 0.69 0.13]);
line([ww(cc2) pi],[M3 M3],'Color',[0.93 0.69 0.13]);
line([pi/4 pi/4],[-0.4 1.2],'Color','magenta');
line([pi/2 pi/2],[-0.4 1.2],'Color','magenta');
straa1 = sprin ('Max %1.4f',M4);
aa1 = text(ww(I4)+0.5,M4,['\le arrow ' straa1]);
strbb1 = sprin ('%1.4f Min',M3);
bb1 = text(ww(I3)-1.3,M3,[strbb1 ' \rightarrow']);
hh1 = text(pi/4-0.1,0.7,'\rightarrow ');
ii1 = text(pi/2,0.7,'\le arrow Specifica on');
figure,
stem(nn,hn), grid, ylim([-0.2 0.5])

The Type I LPF with non-causality is below. The computed coefficients from the
matrix form are the one half of the impulse response.
360 6 Filter Design

Fig. 6.29 Frequency response of frequency sampling design method LPF Type I

ht ½n ¼ 0:1235d½n þ 3 þ 0:0922d½n þ 2 þ 0:3242d½n þ 1 þ 0:4143d½n


þ 0:3242d½n  1 þ 0:0922d½n  2  0:1235d½n  3

Shifting for causality finalizes the filter design.

h½n ¼ ht ½n  3 ¼ 0:1235d½n þ 0:0922d½n  1 þ 0:3242d½n  2


þ 0:4143d½n  3 þ 0:3242d½n  4 þ 0:0922d½n  5  0:1235d½n  6

The passband ripple Ap can be calculated from the maximum deviation Rp as


below.
AP ¼ 40 log10 ð1 þ Rp Þ

1:2127dB ¼ 40 log10 ð1 þ 0:0723Þ

The equivalent stopband attenuation can be calculated as below.

Ast ¼ 20 log10 Rst

11:7273dB ¼ 20 log10 0:2592

Frequency sampling design—Type II


The desired frequency response H ½k  shows the symmetric property as below for
real ht ½n with length L which is N + 1 and odd N.

H ½k  ¼ H  ½k

The corresponding impulse response can be derived as below. Note that the
Type II filter presents the zero output on p radian frequency as H½L=2 ¼ 0:
6.2 FIR Filters 361

ðL=2Þ1  
1XL1
j2p 1 X
j2p 1 L j2pLn
ht ðnÞ ¼ H ½ke L kn
¼ H ½k e L kn
þ H e L2 ; n2R
L k¼0 L k¼ðL=2Þ þ 1 L 2
   
2 X
ðL=2Þ1
1 2p 1 L jpn
¼ H ½0 þ H ½k  cos kn þ H e
L L k¼1 L L 2
   
2 X
ðL=2Þ1
1 2p L
¼ H ½0 þ H ½k  cos kn ; since H ¼ 0 *Type II
L L k¼1 L 2
ð6:81Þ

The DFT analysis equation is below to figure out the frequency response for
Type II FIR filter.

P
L=21     
H ½k  ¼ 2 L k nþ 2 ;
ht n þ 12 cos 2p 1
H ½k  2 R ð6:82Þ
n¼0

The matrix form of Eq. (6.75) is below. The cosine matrix (DFT matrix in Euler)
is square matrix with L + 1 by L + 1 size.
2  3 2  1   1    1L  32 3
ht 12 1 2 cos2p
L 21 2 cos2p
L 22 L 2 2  1
2 cos2p H ½0
6 ht 32 7 61 2 cos2p 3
L 21 2 cos2p 3
L 22 L 2 2  1
2 cos2p 3 L 76 H ½1 7
6 5  7 6 76 7
6 ht 2 7 1 6 1 2 cos 2p 5
L 2 1 2 cos 2p 5
L 2 2  L 2 21
2 cos 2p 5 L 76 H ½2 7
6 7¼ 6 76 7
6 . 7 L6. .. . 76 .. 7
4 .. 5 4 .. .        .. 54 . 5
N   N   2p N L 
ht 2 1 2 cos 2p
L 2 1 2 cos L 2 2   
2p N
2 cos L 2 2 1 H ½L=2  1
ð6:83Þ

The complete ht ½n is below.


       
N L 3 1
ht ½n ¼ ht d nþ þ    þ ht d½n þ 2 þ ht d½ n þ 1
2 2 2 2
      ð6:84Þ
1 3 N
þ ht d½n þ ht d½ n  1 þ    þ ht d½n  ðL=2  1Þ
2 2 2

To make the causal filter, perform the shift operation as below.

h½n ¼ ht ½n  L=2 ð6:85Þ

The Type II frequency sampling design method is identical to the DFT method
without truncation in Sect. 4.5 as well. The required condition is that the impulse
response length is equal to the frequency sampling length.
362 6 Filter Design

Table 6.22 Given filter specification


Filter specifications Value
Filter type Low pass filter
Filter realization FIR Type II without window method
Filter length 8 (N = 7)
Passband frequency (fp) 1000 Hz; xp ¼ p=4
Passband magnitude 0 dB
Stopband frequency (fst) 2000 Hz; xst ¼ p=2
Sampling frequency (fs) 8000 Hz

Example 6.12
Design the Table 6.22 FIR filter by using the frequency sampling design.
Solution
According to the filter length, 2p radian frequency is divided into 8 segments as
below.
   
2p 2p
H ½k  $ H k ¼H k
L 8

First trial of frequency set is below.



2p 2p 2p
x ¼ fx0 ; x1 ; x2 ; x3 g ¼ 0; ; 2 ; 3
8 8 8

The corresponding H ½k  is below based on the LPF specification from


Table 6.22.
2 3 2 3
H ½ 0 1
6 H ½ 1 7 6 1 7
6 7 6 7
4 H ½ 2 5 ¼ 4 0 5
H ½ 3 0

The DFT synthesis equation in short matrix form compute the impulse response
half as below.
2 2p 1  2p 1  2p 1  3
2 1 3 1 2 cos 2 3
8 2 1 2 cos 8 2 2 2 cos 8 2 3
ht  2  6 2p   2p   2p 3  7 H ½0
6 ht 3 7 1 6 1 2 cos 8 32 1 2 cos 8 32 2 2 cos 8 2 3 76 H ½1 7
6 25 7 ¼ 6  5   5   5  7 6 7
4 ht 5 8 6 1 2 cos 2p 2 cos 2p 2 cos 2p 7 4 H ½ 2 5
2 4 8 2 1 8 2 2 3 5
ht 72 2p   2p    8 27  H ½ 3
1 2 cos 8 72 1 2 cos 8 72 2 2 cos 2p
8 2 3

2 3 2 32 3
0:3560 1 2  2
2p  2
2p  1
6 0:2207 7 1 6 61 8 ð1Þ1
2 cos 2p 2 cos ð1Þ2 2 cos 8 ð1Þ3 7 6 17
6 7   2p
8
  776 7
4 0:0293 5 ¼ 8 6 5 05
4
41 8 ð2Þ1
2 cos 2p 2 cos 8 ð2Þ2 2 cos 2p ð 2 Þ3
  2p   8

0:1060 0
1 8 ð3Þ1
2 cos 2p 2 cos 8 ð3Þ2 2 cos 2p ð3Þ3
8

Using the following equation, compute the continuous frequency response. Or


use the DFT.
6.2 FIR Filters 363

  X 
L=21
1
  
1

H ejx ¼ 2 ht n þ cos x n þ
n¼0
2 2

The frequency response of first trial is shown in Fig.6.30. Note


 that the stem
plot is the design locations. The transition frequency Dx xst  xp in Fig. 6.30 is
located within the specification. You may further evaluate the LPF for better
performance.
Prog. 6.24 MATLAB program for Fig. 6.30.

ww = linspace(0,pi,1000);
nn = (0:7);
RR = [1 2*cos(2*pi*(1/2)/8) 2*cos(2*pi*(1/2)*2/8) 2*cos(2*pi*(1/2)*3/8); ...
1 2*cos(2*pi*(3/2)/8) 2*cos(2*pi*(3/2)*2/8) 2*cos(2*pi*(3/2)*3/8); ...
1 2*cos(2*pi*(5/2)/8) 2*cos(2*pi*(5/2)*2/8) 2*cos(2*pi*(5/2)*3/8); ...
1 2*cos(2*pi*(7/2)/8) 2*cos(2*pi*(7/2)*2/8) 2*cos(2*pi*(7/2)*3/8)];
HH = [1; 1; 0; 0];
ht = RR*HH/8;
HW3 =
2*ht(1)*cos(ww/2)+2*ht(2)*cos((3/2)*ww)+2*ht(3)*cos((5/2)*ww)+2*ht(4)*
cos((7/2)*ww);
hn = [flipud(ht); ht];
w0 = [0 2*pi/8 2*2*pi/8 2*3*pi/8];
mag0 = [1 1 0 0];

figure,
plot(ww,HW3), grid, xlim([0 pi]), hold on;
stem(w0, mag0), hold off
[M3,I3] = min(HW3);
[M4,I4] = max(HW3);
cc2 = max(find(HW3>(-M3)));
cc3 = min(find(HW3<(2-M4)));
line([0 ww(cc3)],[M4 M4],'Color',[0.93 0.69 0.13]);
line([ww(cc2) pi],[M3 M3],'Color',[0.93 0.69 0.13]);
line([pi/4 pi/4],[-0.4 1.2],'Color','magenta');
line([pi/2 pi/2],[-0.4 1.2],'Color','magenta');
straa1 = sprin ('Max %1.4f',M4);
aa1 = text(ww(I4)+0.5,M4,['\le arrow ' straa1]);
strbb1 = sprin ('%1.4f Min',M3);
bb1 = text(ww(I3)-1.3,M3,[strbb1 ' \rightarrow']);
hh1 = text(pi/4-0.1,0.7,'\rightarrow ');
ii1 = text(pi/2,0.7,'\le arrow Specifica on');
figure,
stem(nn,hn), grid, ylim([-0.2 0.5]);
364 6 Filter Design

Fig. 6.30 Frequency response of frequency sampling design method LPF Type II

The Type II LPF with causality is below.

h½n ¼ 0:1060d½n þ 0:0293d½n  1 þ 0:2207d½n  2 þ 0:3560d½n  3


þ 0:3560d½n  4 þ 0:2207d½n  5 þ 0:0293d½n  6  0:1060d½n  7

The passband ripple Ap can be calculated from the maximum deviation Rp as


below.

AP ¼ 40 log10 ð1 þ Rp Þ

1:1737dB ¼ 40 log10 ð1 þ 0:0699Þ

The equivalent stopband attenuation can be calculated as below.

Ast ¼ 20 log10 Rst

13:7692dB ¼ 20 log10 0:2049

Least squared error frequency domain design—Discrete frequency sampling


DFT
Similar to the frequency sampling design, the FIR filter uses a larger number of
sampling point than the filter order [7]. The more equations than unknowns indicate
the least square solution. The DFT analysis of given non-causal impulse response h
[n] Type I is shown in Eq. (6.86). Note that the filter length is L which is N + 1.

P
N=2 2p 
H ½ k  ¼ h½ 0 þ 2 h½ncos L kn ; 0  k  L  1 ð6:86Þ
n¼1
6.2 FIR Filters 365

The DFT synthesis for impulse response ht[n] can be performed as Eq. (6.87)
with L length.

1XL1
1 X
N=2
2p 2p
ht ½ n ¼ H ½kej L kn ¼ H ½kej L kn
L k¼0 L k¼N=2
ð6:87Þ
 
2X
N=2
1 2p
¼ H ½ 0 þ H ½k cos kn
L L k¼1 L

The matrix form of Eq. (6.87) is below.


2 32 3 2 3
e j L ð 2 Þ 2
2p N N
 ej L ð 2 Þ
2p N
1 ej L ð 2 Þ
2p N
 ej L ð 2 Þ 2
2p N N
ht ½N=2 H ½N=2
6 .. .. .. .. .. 76 .. 7 6 .. 7
6 76 . 7 6 . 7
6 2p . N  . . .  . 7 6 7 6 7
6 ej L ð1Þ 2  ej L ð1Þ
2p
ej L ð1Þ
2p
 ej L ð1Þ 2 7
2p N 6 ht ½1 7 6 H ½1 7
6 1 76 7 6 7
6   76 ht ½0 7 ¼ 6 H ½0 7
6 2p1 N 1 1 1 1 76 7 6 7
6 ej L ð1Þ 2 N 76
ej L ð1Þ 2 76 ht ½1 7 6 7
ej L ð1Þ ej L ð1Þ 7 6 H ½1 7
2p 2p 2p
6  1 
6 .. .. .. .. .. .. .. 76 . 7 6 . 7
4 . . . . . . . 54 .. 5 4 .. 5
ej L ð 2 Þ 2 ej L ð 2 Þ ej L ð 2 Þ ej L ð 2 Þ 2
2p N N 2p N 2p N 2p N N
 1  ht ½N=2 H ½N=2
ð6:88Þ

The Euler equation compresses the exponential matrix in short cosine form as
below for Type I.
2 32 3 2 3
1 2
2p  2
2p   2
2p  ht ½0 H ½0
61 2 cos L ð1Þ1 2 cos L ð1Þ2  7
2 cos L ð1Þ 2 76 h ½1 7 6 H ½1 7
N
6       6 t 7 6 7
6 N 7
61 L ð2Þ1
2 cos 2p L ð2Þ2
2 cos 2p  L ð2Þ 2 76
2 cos 2p 76 ht ½2 7 6
7 ¼ 6 H ½2 7
7
6
6 .. .. .. .. 76 .. 7 6 .. 7
4. 54 . 5 4 . 5
2p. N   2p. N    .
2p N  N 
1 2 cos L 2 1 2 cos L 2 2  2 cos L 2 2 ht ½ N=2  H ½ N=2

ð6:89Þ

Increase number of frequency sampling as M > L. Let P = M – 1. Again, it is


Type I.

X
N=2  
2p
H ½k  ¼ h½0 þ 2 h½ncos kn
n¼1
M ð6:90Þ
for 0  k  M  1 ¼ P and M [ L ¼ N þ 1

The matrix form of Eq. (6.90) is below.


366 6 Filter Design

2 3 2 3
1 2  2   2  2 3 H ½0
6 1 2 cos2p 7 ht ½0 6 7
M ð1Þ1 M ð1Þ2
2 cos2p  M ð1Þ 2 
2 cos2p H ½1
N
6 76 ht ½1 7 6 7
6 1 2 cos M ð2Þ1
2p
2 cos M ð2Þ2
2p
 2 cos M ð2Þ 2 
2p N 76 7 6 H ½2 7
6 76 ht ½2 7 6 7
6 1 2 cos 2p
M ð3Þ1 M ð3Þ2
2 cos 2p  M ð3Þ 2
2 cos 2p N 76 7¼6 H ½3 7
6 76 .. 7 6 7
6 .. 74 . 5 6 .. 7
4.  5 4 . 5
  P  2p P    P  N   ht ½N=2
M 2 ð1Þ
1 2 cos 2p 2 cos M 2 ð2Þ  2 cos 2p
M 2 2 H ½P=2
ð6:91Þ

The matrix variable representation is below.

Rh ¼ d ð6:92Þ
      p 
P N N
where R : þ1 þ1 ; h : þ 1 1; d: þ1 1
2 2 2 2

Since the R matrix is not square form and shows the overdetermined system.
Pseudoinverse [12] is used to compute the impulse response.
 1  1
RT R RT Rh ¼ RT R RT d
 1
h ¼ RT R RT d ð6:93Þ

The complete ht ½n is below.

ht ½n ¼ ht ½N=2d½n þ N=2 þ    þ ht ½1d½n þ 1 þ ht ½0d½n þ ht ½1d½n  1


þ    þ ht ½N=2d½n  N=2
ð6:94Þ

To make the causal filter, perform the shift operation as below.

h½n ¼ ht ½n  N=2 ð6:95Þ

The least square error design method provides least square solution based on the
overdetermined system which contains the further frequency sampling than the
filter length.
Example 6.13
Design the Table 6.23 FIR filter by using the least squared error frequency domain
design method.
Solution
The 2p radian frequency is divided into M = 16 segments as below.
6.2 FIR Filters 367

Table 6.23 Given filter specification


Filter specifications Value
Filter type Low pass filter
Filter realization FIR Type I without window method
Filter length 7 (N = 6)
Passband frequency (fp) 1000 Hz; xp ¼ p=4
Passband magnitude 0 dB
Stopband frequency (fst) 2000 Hz; xst ¼ p=2
Sampling frequency (fs) 8000 Hz

   
2p 2p
H ½k  $ H k ¼H k
M 16

First trial of frequency set is below.

x ¼ fx0 ; x1 ; x2 ; x3 ; x4 ; x5 ; x6 ; x7 ; x8 g

2p 2p 2p 2p 2p 2p 2p 2p
¼ 0; ; 2 ; 3 ; 4 ; 5 ; 6 ; 7 ; 8
16 16 16 16 16 16 16 16

Since the 3  2p=16 is located at transition band, we omit the frequency from the
designated set. Or, you may choose another value for the transition frequency.

x ¼ fx0 ; x1 ; x2 ; x3 ; x4 ; x5 ; x6 ; x7 g

2p 2p 2p 2p 2p 2p 2p
¼ 0; ; 2 ; 4 ; 5 ; 6 ; 7 ; 8
16 16 16 16 16 16 16

The corresponding H ½k is below


2 3 2 3
H ½ 0 1
6 H ½ 1 7 6 1 7
6 7 6 7
6 H ½ 2 7 6 1 7
6 7 6 7
6 H ½ 3 7 6 0 7
6 7 6 7
6 H ½ 4 7 ¼ 6 0 7
6 7 6 7
6 H ½ 5 7 6 0 7
6 7 6 7
4 H ½ 6 5 4 0 5
H ½ 7 0

The matrix form of Eq. (6.77) is below.


368 6 Filter Design

2 3
1 2 2 2
2p    2p 
6 1 2 cos 16 ð1Þ1 2 cos 2p 7
6 2p  16 ð1Þ2
2p
2 cos 16 ð1Þ3
2p  7
6 72 3
6 1 2 cos 16 ð2Þ1 2 cos 16 ð2Þ2 2 cos 16 ð1Þ3 7 ht ½0
6   2p  2p  7
6 76 h ½1 7
6 1 2 cos 2p16 ð4Þ1 2 cos 16 ð4Þ2
2p
2 cos 16 ð4Þ3
2p  76 t 7
6 76 7
6 1 2 cos 16 ð5Þ1 2 cos 2p ð5Þ2 2 cos 16 ð5Þ3 74 ht ½2 5
6   16  2p  7
6 1 2 cos 2p ð6Þ1 2 cos 2p ð6Þ2 2 cos 16 ð6Þ3 7 h ½3
6 2p
16  2p
16  2p  7 t
6 7
4 1 2 cos 16 ð7Þ1 2 cos 16 ð7Þ2 2 cos 16 ð7Þ3 5
2p  2p  2p 
1 2 cos 16 ð8Þ1 2 cos 16 ð8Þ2 2 cos 16 ð8Þ3
2 3 2 3
H ½0  1
6 H ½1  7 6 1 7
6 7 6 7
6 7 6 7
6 H ½2  7 6 1 7
6 7 6 7
6 H ½3  7 6 0 7
6 7 6 7
¼6 7¼6 7
6 H ½4  7 6 0 7
6 7 6 7
6 H ½5  7 6 0 7
6 7 6 7
6 7 6 7
4 H ½6  5 4 0 5
H ½7  0

Rh ¼ d

We can calculate the least square solution by below equation.


32
0:3711
 1 6 0:2914 7
h ¼ RT R RT d ¼ 6
4 0:0960 5
7

0:0399

In Fig. 6.31 frequency response, observe that the stem plot is the design loca-
tions. Unlike to the frequency sampling method, the response does not exactly
follow the design locations. In the lease square sense, the response illustrates the

Fig. 6.31 Frequency


response of first trial by least
square error design method
LPF
6.2 FIR Filters 369
 
best curve to represent the specification. The transition frequency Dx xst  xp in
Fig. 6.31 occupies further range than the specification; therefore, the first trial
should be modified.
Prog. 6.25 MATLAB program for Fig. 6.31.

ww = linspace(0,pi,1000);
nn = (0:6);
RR = [1 2 2 2; ...
1 2*cos(2*pi/16) 2*cos(2*pi*2/16) 2*cos(2*pi*3/16); ...
1 2*cos(2*pi*2/16) 2*cos(2*pi*2*2/16) 2*cos(2*pi*2*3/16); ...
1 2*cos(2*pi*4/16) 2*cos(2*pi*4*2/16) 2*cos(2*pi*4*3/16); ...
1 2*cos(2*pi*5/16) 2*cos(2*pi*5*2/16) 2*cos(2*pi*5*3/16); ...
1 2*cos(2*pi*6/16) 2*cos(2*pi*6*2/16) 2*cos(2*pi*6*3/16); ...
1 2*cos(2*pi*7/16) 2*cos(2*pi*7*2/16) 2*cos(2*pi*7*3/16); ...
1 2*cos(2*pi*8/16) 2*cos(2*pi*8*2/16) 2*cos(2*pi*8*3/16)];
HH = [1; 1; 1; 0; 0; 0; 0; 0];
ht = inv(RR'*RR)*RR'*HH;
HW3 = ht(1)+2*ht(2)*cos(ww)+2*ht(3)*cos(2*ww)+2*ht(4)*cos(3*ww);
hn = [flipud(ht); ht(2:end)];
w0 = [0 2*pi/16 2*2*pi/16 2*4*pi/16 2*5*pi/16 2*6*pi/16 2*7*pi/16
2*8*pi/16];
mag0 = [1 1 1 0 0 0 0 0];

figure,
plot(ww,HW3), grid, xlim([0 pi]), hold on;
stem(w0, mag0), hold off;
[M3,I3] = min(HW3);
[M4,I4] = max(HW3);
line([pi/4 pi/4],[-0.4 1.2],'Color','magenta');
line([pi/2 pi/2],[-0.4 1.2],'Color','magenta');
straa1 = sprin('Max %1.4f',M4);
aa1 = text(ww(I4)+0.5,M4,['\learrow ' straa1]);
strbb1 = sprin('%1.4f Min',M3);
bb1 = text(ww(I3)-1.3,M3,[strbb1 ' \rightarrow']);
hh1 = text(pi/4-0.1,0.7,'\rightarrow ');
ii1 = text(pi/2,0.7,'\learrow Specificaon');
figure,
stem(nn,hn), grid, ylim([-0.2 0.5]);
370 6 Filter Design

To comply with specification, the new H ½k value is below. We adjust certain
magnitudes to reduce the transition by trial and error.
2 3 2 3
H ½0 1
6 H ½1 7 6 1:2 7
6 7 6 7
6 H ½2 7 6 1 7
6 7 6 7
6 H ½3 7 6 0 7
6 7¼6 7
6 H ½4 7 6 0:2 7
6 7 6 7
6 H ½5 7 6 0 7
6 7 6 7
4 H ½6 5 4 0 5
H ½7 0

The corresponding impulse response is below.


2 3
0:3663
 1 6 0:3216 7
h ¼ RT R RT d ¼ 6
4 0:1239 5
7

0:0579

The frequency response of second trial is shown in Fig. 6.32. The transition
frequency in Fig. 6.32 is located within the specification. You may further evaluate
the LPF for better performance.

Fig. 6.32 Frequency response of least squared error frequency domain design method LPF Type I
6.2 FIR Filters 371

Prog. 6.26 MATLAB program for Fig. 6.32.

ww = linspace(0,pi,1000);
nn = (0:6);
RR = [1 2 2 2; ...
1 2*cos(2*pi/16) 2*cos(2*pi*2/16) 2*cos(2*pi*3/16); ...
1 2*cos(2*pi*2/16) 2*cos(2*pi*2*2/16) 2*cos(2*pi*2*3/16); ...
1 2*cos(2*pi*4/16) 2*cos(2*pi*4*2/16) 2*cos(2*pi*4*3/16); ...
1 2*cos(2*pi*5/16) 2*cos(2*pi*5*2/16) 2*cos(2*pi*5*3/16); ...
1 2*cos(2*pi*6/16) 2*cos(2*pi*6*2/16) 2*cos(2*pi*6*3/16); ...
1 2*cos(2*pi*7/16) 2*cos(2*pi*7*2/16) 2*cos(2*pi*7*3/16); ...
1 2*cos(2*pi*8/16) 2*cos(2*pi*8*2/16) 2*cos(2*pi*8*3/16)];
HH = [1; 1.2; 1; 0; -0.2; 0; 0; 0];
ht = inv(RR'*RR)*RR'*HH;
HW3 = ht(1)+2*ht(2)*cos(ww)+2*ht(3)*cos(2*ww)+2*ht(4)*cos(3*ww);
hn = [flipud(ht); ht(2:end)];
w0 = [0 2*pi/16 2*2*pi/16 2*4*pi/16 2*5*pi/16 2*6*pi/16 2*7*pi/16
2*8*pi/16];
mag0 = [1 1.2 1 0 -0.2 0 0 0];

figure,
plot(ww,HW3), grid, xlim([0 pi]), hold on;
stem(w0, mag0), hold off;
[M3,I3] = min(HW3);
[M4,I4] = max(HW3);
line([pi/4 pi/4],[-0.4 1.2],'Color','magenta');
line([pi/2 pi/2],[-0.4 1.2],'Color','magenta');
straa1 = sprin ('Max %1.4f',M4);
aa1 = text(ww(I4)+0.5,M4,['\le arrow ' straa1]);
strbb1 = sprin ('%1.4f Min',M3);
bb1 = text(ww(I3)-1.3,M3,[strbb1 ' \rightarrow']);
hh1 = text(pi/4-0.1,0.7,'\rightarrow ');
ii1 = text(pi/2,0.7,'\le arrow Specifica on');
figure,
stem(nn,hn), grid, ylim([-0.2 0.5]);

The Type I LPF with non-causality is below. The computed coefficients from the
matrix form are the one half of the impulse response.

ht ½n ¼ 0:0579d½n þ 3 þ 0:1239d½n þ 2 þ 0:3216d½n þ 1 þ 0:3663d½n


þ 0:3216d½n  1 þ 0:1239d½n  2  0:0579d½n  3
372 6 Filter Design

Shifting for causality finalizes the filter design.

h½n ¼ ht ½n  3 ¼ 0:0579d½n þ 0:1239d½n  1 þ 0:3216d½n  2


þ 0:3663d½n  3 þ 0:3216d½n  4 þ 0:1239d½n  5  0:0579d½n  6

The passband ripple Ap can be calculated from the maximum deviation Rp as below.

AP ¼ 40 log10 ð1 þ Rp Þ

2:3006dB ¼ 40 log10 ð1 þ 0:1416Þ

The equivalent stopband attenuation can be calculated as below.

Ast ¼ 20 log10 Rst

14:0011dB ¼ 20 log10 0:1995

Least squared error frequency domain design—Integral squared error


approximation criterion
The least squared error method in frequency domain from the discrete sampling
presents the least squared solution for the non-continuous frequency sampling. For
the least squared error method in continuous domain [7], the error is defined as
squared L2-norm shown in Eq. (6.96).

2 Rp 2
kEðejx Þk2 ¼ 2p
1
jH ðejx Þ  Hd ðejx Þj dx ð6:96Þ
p
   
where H ejx 2 R and Hd ejx 2 R

where Hd ðejx Þ is the desired frequency response of the filter. To minimize the error
in least squared sense, we can describe the error function in discrete time domain
according to the Parseval’s theorem as Eq. (6.97).

2 P
1
kEðejx Þk2 ¼ jh½n  hd ½nj2 ð6:97Þ
n¼1

  DTFT   DTFT
where H ejx $ h½n Hd ejx $ hd ½n

The bandlimited desired filter generates the infinite length impulse response
hd ½n and the FIR filter h½n has the finite length response. The error function can be
reorganized as Eq. (6.98). The filter length is L = N+1 with Type I and zero phase
(non-causal).
6.2 FIR Filters 373

2 P
N=2 P
1
kE ðejx Þk2 ¼ jh½n  hd ½nj2 þ 2jhd ½nj2 ð6:98Þ
n¼N=2 n¼N=2 þ 1

The Type II can be described by the simple modification from above equation.
The minimum error can be achieved by the equality between the h½n and hd ½n for
FIR interval and the overall error is demonstrated by the squared residual response
sum.

h½n ¼ hd ½n for  N=2  n  N=2 ð6:99Þ

The final filter is the shifted version of the h½n for causality. The procedure
shown above is identical to the simple filter design at Sect. 4.6. The truncated
impulse response from the DTFT is an optimal approximation in the sense that the
integral squared error is minimized in continuous frequency domain. Various type
windows can apply on the designed impulse response to control the ripples over
passband and stopband. However, the window applying does not provide the least
squared error solution for the designed filter.

  jx 2 X
1
E e  ¼ jw½nh½n  hd ½nj2
2
n¼1

P
N=2 P
1
¼ jw½nh½n  hd ½nj2 þ 2jhd ½nj2 ð6:100Þ
n¼N=2 n¼N=2 þ 1

2 P
1
min kEðejx Þk2 ¼ 2jhd ½nj2 ð6:101Þ
h½n2R&FIR n¼N=2 þ 1

By using the length limited FIR filter, the minimum achievable residual error
energy is derived in Eq. (6.101). The inequality between the desired response hd ½n
and windowed response w½nh½n represents the greater residual error energy than
the minimum value; therefore, the windowed response is the non-least squared error
design.
Example 6.14
Design the Table 6.24 FIR filter by using least squared error method in continuous
frequency domain.
Solution
The method is identical to the simple filter design at Sect. 4.5 and the extension
based on the window method can be found at FIR filters from Sect. 6.2. The simple
revisit to realize above filter is below. The center of the passband and stopband edge
is below as cutoff frequency.
374 6 Filter Design

Table 6.24 Given filter specification


Filter specifications Value
Filter type Low pass filter
Filter realization FIR Type I without window method
Filter length Optimal value from window
Passband frequency (fp) 1000 Hz; xp ¼ p=4
Passband magnitude 0 dB
Stopband frequency (fst) 2000 Hz; xst ¼ p=2
Sampling frequency (fs) 8000 Hz

xst  xp p p 3p
xc ¼ xp þ ¼ þ ¼
2 4 8 8

The frequency transition between the passband and stopband edge is below
p p p
Dx ¼ xst  xp ¼  ¼
2 4 4

The main lobe width corresponds to the radian distance between the maximum
and minimum ripple; hence, the use of the main lobe width designs the filter with
sharper transition than the specification. Below is the main lobe width for rectan-
gular window.

4p p
 N
15
N þ1 4

Let the N = 16 for Type I filter. According to the window analysis, the extreme
ripples in both bands are identical in terms of deviation from the ideal response
magnitude. Realization and evaluation are below.

Z
3p=8
1 sinð3pn=8Þ
hd ½ n ¼ 1ejxn dx ¼
2p pn
3p=8

  jx 2 X
8 X
1
E e  ¼ j h ½n   h d ½ n  j2
þ 2jhd ½nj2
2
n¼8 n¼9

hd ½n for  8  n  8
h½ n ¼
0 Otherwise
6.2 FIR Filters 375

Fig. 6.33 Frequency


response of least squared error
method LPF Type I in
continuous frequency domain

Prog. 6.27 MATLAB program for Fig. 6.33.

N = 16;
NN = 2^13;
N1 = NN/2+1;
N2 = N/2;
nnn = (-N2:1:N2);
b2 = sin(3*pi*(nnn+eps)/8)./(pi*(nnn+eps));
b3 = [b2 zeros(1,NN-length(b2))];
b4 = circshi (b3,-8);
B2 = real( (b4,NN));
findex = linspace(0,2*pi,NN);
ff = findex(1:N1);
[M1,I1] = max(B2(1:N1));
[M2,I2] = min(B2(1:N1));

figure,
plot(ff,B2(1:N1)), grid, xlim([0 pi]), ylim([-0.2 1.2]);
straa = sprin ('Max %1.2f dB',40*log10(B2(I1)));
aa = text(ff(I1),B2(I1)+0.005,[' \le arrow' straa]);
strbb = sprin ('%1.2f dB Min',-20*log10(abs(B2(I2))));
bb = text(ff(I2)-0.7,B2(I2)+0.005,[strbb '\rightarrow ']);
cc = min(find(B2<(2-B2(I1))));
dd = max(find(B2(1:NN/2)>-B2(I2)));
line([ff(I1) ff(I1)],[-0.2 1.2],'Color','magenta');
line([ff(I2) ff(I2)],[-0.2 1.2],'Color','magenta');
hh = text(ff(I1)-0.1,0.7,'\rightarrow ');
ii = text(ff(I2),0.7,'\le arrow Main Lobe Width');
376 6 Filter Design

Using the Parseval’s theorem, we can compute the residual error energy as
below.

Z
3p=8
  jx 2 X1
1 X
8
E e  ¼ 2j hd ½ n j 2 ¼ 12 dx  jh½nj2 ¼ 0:0126
2 2p
n¼9 n¼8
3p=8

Further control of the ripple can be exercised by using the window method on
the above filter realization. The final filter is given by the proper shift to preserve the
causality. The energy ratio between the desired and calculated filter can be com-
puted by using the Parseval’s theorem as well. In the equation below, the numerator
and denominator represent the calculated filter energy and desired filter energy,
respectively.

P8   P8 sinð3pn=8Þ2
R sinð3pn=8Þ2
1 p jx 2   n¼8  
2p p jH ðe Þj dx pn pn
n¼8
R p ¼ 1 Rp ¼
jx 2 jx 2
2p p jHd ðe Þj dx 2p p jHd ðe Þj dx
1 3=8
¼ 0:9664

Constrained least square design


The FIR filter can be built by applying the constraint of the upper and lower bound
on each band for the frequency response. The constrained least square design
method [13] utilizes an iterative least squares algorithm to derive an equiripple
response. Let’s observe the simplified procedure with L length filter which is N + 1
and M = N/2 with Type I FIR and zero phase (non-causal) filter.

P
M
H ðejx Þ ¼ b0 þ bn cosðnxÞ for H ðejx Þ 2 R ð6:102Þ
n¼1
8
>
>
1
b for 1  n  M
<2 n
b0 for n ¼ 0
h½n ¼ 1
>
> b for  M  n   1
: 2 n
0 Otherwise

The error is defined as squared L2-norm shown in Eq. (6.103).

2 Rp 2
kE ðejx Þk2 ¼ p1 jH ðejx Þ  Hd ðejx Þj dx ð6:103Þ
0
   
where H ejx 2 R and Hd ejx 2 R
6.2 FIR Filters 377

The equality constraints are employed on the discrete frequency band by upper
U ðejx Þ and lower Lðejx Þ bound as shown in Eq. (6.104).
   

H ejx ¼ L ejx for x 2 Sl ¼ x1 ; x2 ; . . .; xq 2 ½0; p


H ðejx Þ ¼ U ðejx Þ for x 2 Su ¼ xq þ 1 ; xq þ 2 ; . . .; xr 2 ½0; p ð6:104Þ

To minimize the squared L2-norm error subject to above constraints, we use the
Lagrangian as shown in Eq. (6.105).

  2 X q
    
L ¼ E ejx 2  li H ejxi  L ejxi
i¼1
ð6:105Þ
X
r     
þ li H ejxi  U ejxi
i¼q þ 1

By placing the derivative of L with respect to bk and li to zero, we can obtain


the desired solution with the constraint requirements.

2
@ kE ðejx Þk2 P
q P
r
li @H@b
ðe Þ
li @H@b
ðe Þ
jxi jxi
@L
@bk ¼ @bk  k
þ k
¼0 ð6:106Þ
i¼1 i¼q þ 1

for 0  k  M
   
H ejxi ¼ L ejxi for 1  i  q
   
H ejxi ¼ U ejxi for q þ 1  i  r

Based on the Kuhn–Tucker conditions, once the Lagrange multipliers are all
nonnegative, the solution from Eq. (6.106) minimize the squared L2-norm subject
to the inequality constraints.
   
H ejxi
L ejxi for 1  i  q

H ðejxi Þ  U ðejxi Þ for q þ 1  i  r ð6:107Þ

The iterative algorithm to solve above equations provides the equiripple


response. The algorithm utilizes the multiple exchange algorithm that solves
Lagrange multipliers [14] with Kuhn–Tucker conditions [15] on each iteration. The
further solution can be found on the paper [13].
Example 6.15
The design example by Table 6.25 utilizes the MATLAB function for the con-
strained least square design method.
378 6 Filter Design

Table 6.25 Given filter specification


Filter specifications Value
Filter type Low pass filter
Filter realization FIR Type I without window method
Filter length Optimal value from window
Passband frequency (fp) 1000 Hz; xp ¼ p=4
Passband magnitude 0 dB
Passband ripple (peak to peak) 1 dB
Stopband frequency (fst) 2000 Hz; xst ¼ p=2
Stopband attenuation 40 dB
Sampling frequency (fs) 8000 Hz

Solution
The center of the passband and stopband edge is below for cutoff frequency.

xst  xp p p 3p
xc ¼ xp þ ¼ þ ¼
2 4 8 8

The frequency transition is below.


p p p
Dx ¼ xst  xp ¼  ¼
2 4 4

Below is the main lobe width for rectangular window to determine the filter
order N.

4p p
 N
15
N þ1 4

Let the N = 16 for Type I filter. The maximum deviation Rp can be derived as
below.
AP =2
Rp ¼ 10 20 1
1=2
10 20  1 ¼ 0:0593

The minimum attenuation Rst can be computed as below.


Ast
Rst ¼ 10 20
40
10 20 ¼ 0:01

MATLAB code is below.


6.2 FIR Filters 379

Prog. 6.28 MATLAB program for Fig. 6.34.

N = 16; % Filter order


NN = 2^13;
N1 = NN/2+1;
N2 = N/2;
nnn = (-N2:1:N2);
f = [0 3/8 1]; % Cutoff frequency = 3/8
a = [1 0]; % Desired amplitude
up = [1.0593 0.01]; % 1+0.0593 0+0.01
lo = [0.9407 -0.01]; % 1-0.0593 0-0.01
b2 = fircls(N,f,a,up,lo); % Design the constrained least square FIR filter
b3 = [b2 zeros(1,NN-length(b2))];
b4 = circshi (b3,-8);
B2 = real( (b4,NN));
findex = linspace(0,2*pi,NN);
ff = findex(1:N1);
[M1,I1] = max(B2(1:N1));
[M2,I2] = min(B2(1:N1-10));

figure,
plot(ff,B2(1:N1)), grid, xlim([0 pi]), ylim([-0.2 1.2])
straa = sprin ('Max %1.2f dB',40*log10(B2(I1)));
aa = text(ff(I1),B2(I1)+0.005,[' \le arrow' straa]);
strbb = sprin ('%1.2f dB Min',-20*log10(abs(B2(I2))));
bb = text(ff(I2)-0.7,B2(I2)+0.005,[strbb '\rightarrow ']);
cc = min(find(B2<(2-B2(I1))));
dd = max(find(B2(1:NN/2-1000)>-B2(I2)));
figure,
LB2 = 20*log10(abs(B2));
plot(ff,LB2(1:N1)), grid, xlim([0 pi]), ylim([-100 20]);
straa = sprin ('Max %1.2f dB',40*log10(B2(I1)));
aa = text(ff(I1),LB2(I1)+1,[' \le arrow' straa]);
strbb = sprin ('%1.2f dB Min',-20*log10(abs(B2(I2))));
bb = text(ff(I2)-0.7,LB2(I2)+1,[strbb '\rightarrow ']);
ee = text(ff(cc)-0.1,-20,'\rightarrow ');
gg = text(ff(dd),-20,'\le arrow \Delta\omega');
line([ff(cc) ff(cc)],[-100 20],'Color',[0.93 0.69 0.13]);
line([ff(dd) ff(dd)],[-100 20],'Color',[0.93 0.69 0.13]);


380 6 Filter Design

Fig. 6.34 Frequency response of constrained least square design method LPF Type I

Complex and nonlinear-phase equiripple design


Via defining the complex error function, the Remez exchange algorithm [6, 7] can
be extended to compute the optimal complex Chebyshev approximation. This
generalization of the Parks-McClellan algorithm provides approximation of arbi-
trary magnitude and phase responses for the FIR filter with asymmetric spectral
distribution for positive and negative frequencies. The further information can be
found on the paper [16].
Example 6.16
The design example by Fig. 6.35 utilizes the MATLAB function for the complex
and nonlinear-phase equiripple design method.
Solution
Let the N = 16 for Type I filter. Approximately estimates transition by using the
main lobe width of rectangular window as below.
4p 4p p
¼  N ¼ 16
N þ 1 16 þ 1 4

Stopband and passband for left frequency edge are below.

p 1p 5p
xlst ¼   ¼
2 24 8
p 1p 3p
xlp ¼  þ ¼
2 24 8

Stopband and passband for right frequency edge are below.

p 1p p
xrp ¼  ¼
4 24 8
p 1 p 3p
xrst ¼ þ ¼
4 24 8
6.2 FIR Filters 381

Prog. 6.29 MATLAB program for Fig. 6.36.

N = 16; % Filter order


NN = 2^13;
N1 = NN/2+1;
N2 = N/2;
nnn = (-N2:1:N2);
f = [-1 -5/8 -3/8 1/8 3/8 1]; % f_l±Δ, f_r±Δ
b2 = cfirpm(N,f,@lowpass); % Complex and nonlinear-phase equiripple filter
b3 = [b2 zeros(1,NN-length(b2))];
b4 = circshi (b3,-8);
B2 = real( shi ( (b4,NN)));
LB2 = 20*log10(abs(B2));
findex = linspace(-pi,pi,NN);
ff = findex;
[M1,I1] = max(B2);, [M2,I2] = min(B2);

figure, plot(findex,B2), grid, xlim([-pi pi]), ylim([-0.2 1.2]);


straa = sprin ('Max %1.2f dB',40*log10(B2(I1)));
aa = text(ff(I1),B2(I1)+0.005,['\le arrow' straa]);
strbb = sprin ('%1.2f dB Min',-20*log10(abs(B2(I2))));
bb = text(ff(I2),B2(I2)+0.005,[strbb
'\rightarrow'],'HorizontalAlignment','right');
cc = min(find(B2<(2-B2(I1))));
dd = max(find(B2(1:NN/2-1000)>-B2(I2)));
line([-5*pi/8 -5*pi/8],[-0.2 1.2],'Color',[0.93 0.69 0.13]);
line([-3*pi/8 -3*pi/8],[-0.2 1.2],'Color',[0.93 0.69 0.13]);
line([pi/8 pi/8],[-0.2 1.2],'Color',[0.93 0.69 0.13]);
line([3*pi/8 3*pi/8],[-0.2 1.2],'Color',[0.93 0.69 0.13]);
line([-pi/2 -pi/2],[-0.2 1.2],'Color','magenta');
line([pi/4 pi/4],[-0.2 1.2],'Color','magenta');
figure, plot(ff,LB2), grid, xlim([-pi pi]), ylim([-120 20]);
straa = sprin ('Max %1.2f dB',40*log10(B2(I1)));
aa = text(ff(I1),LB2(I1)+1,['\le arrow' straa]);
strbb = sprin ('%1.2f dB Min',-20*log10(abs(B2(I2))));
bb = text(ff(I2),LB2(I2)+1,[strbb '\rightarrow'],'HorizontalAlignment','right');
line([-5*pi/8 -5*pi/8],[-120 20],'Color',[0.93 0.69 0.13]);
line([-3*pi/8 -3*pi/8],[-120 20],'Color',[0.93 0.69 0.13]);
line([pi/8 pi/8],[-120 20],'Color',[0.93 0.69 0.13]);
line([3*pi/8 3*pi/8],[-120 20],'Color',[0.93 0.69 0.13]);
line([-pi/2 -pi/2],[-120 20],'Color','magenta');
line([pi/4 pi/4],[-120 20],'Color','magenta');

The frequency response of designed FIR filter is illustrated in Fig. 6.36.


382 6 Filter Design

LPF
1
ω
-π/2 0 π/4

Fig. 6.35 LPF specification

Fig. 6.36 Frequency response of complex and nonlinear-phase equiripple design method LPF
Type I

We can convert the LPF to HPF by specifying the parameter in MATLAB


function as below.

Prog. 6.30 MATLAB program for Fig. 6.37. Use the Prog. 6.29.

...
b2 = cfirpm(N,f,@highpass); % Complex and nonlinear-phase equiripple filter
...

The frequency response of designed HPF filter is presented in Fig. 6.37.


Minimum phase filter design (for FIR and IIR filters)
In general, the filter is designed from the magnitude response. The magnitude
specification is decided by the multiple parameters to control the output precisely in
terms of the frequency. Once the filter is determined, the question is whether the
designed filter is unique or not to the determined magnitude response. To consider
this matter, let’s revisit the filter transfer function as below.
6.2 FIR Filters 383

Fig. 6.37 Frequency response of complex and nonlinear-phase equiripple design method HPF
Type I

H ðzÞ ¼ XY ððzzÞÞ ð6:108Þ

The frequency response of the filter is computed by the DTFT or DFT which can
be derived from the transfer function as below.
 
H ejx ¼ H ðzÞjz!ejx

H ½k ¼ H ðzÞj 2p ð6:109Þ


z!e N k

Therefore, the pole and zero locations from the transfer function play important
role to decide the filter properties. The transfer function is the rational function
based on the complex or real polynomial based on the z. Let’s consider simple
polynomial in Eq. (6.110)

1  c0 z1 ð6:110Þ

Note that the negative power is for the system causality. Due to the complex
number property, the number conjugate shows the identical magnitude.
     
1  c0 z1  ¼ ð1  c0 z1 Þ  ¼ 1  c ðz Þ1  ð6:111Þ
0

The given polynomial is evaluated over the unit circle in the complex domain to
obtain the frequency response. The conjugate of ejx is ejx .
n o n o  

  1 1 
1  c0 ðz Þ1  jx
¼ 1  c 0 ð z Þ  ¼ z z1  c0 z¼ejx ð6:112Þ
z¼e z¼ejx

The magnitude of ejx is one.


384 6 Filter Design

   
1  c0 z1  ¼ z z1  c0 z¼ejx
z¼ejx
    ð6:113Þ
¼ jzjz1  c  jx ¼ z1  c 
0 z¼e 0 z¼ejx

Using the above derivation, we can define the filter which passes the all fre-
quency component with unit gain as below.

z1 c
Hap ðzÞ ¼ 1c0 z10 ð6:114Þ

The magnitude response of the Hap ðzÞ is one as below.


   1  
Hap ðxÞ ¼  z c10  ¼1 ð6:115Þ
1c0 z z¼ejx

The derived system is named allpass filter [3, 7] since the system passes all
frequency components without modifying the magnitude. The transfer function of
the allpass filter provides the following pole and zero location.

z1 c
Hap ðzÞ ¼ 1c0 z10 and pole at z ¼ c0 & zero at z ¼ c1 ð6:116Þ
0

For general complex domain, the pole and zero in the polar coordinates can be
described as below.

z 2 C and let c0 ¼ rejh then 1


c0 ¼ re1jh ¼ 1r ejh ð6:117Þ

In the allpass filter, the zero is reflected from the pole as the conjugate reciprocal
position. In other words, the pole and zero are placed at the same angle but the
magnitude is inversed in polar coordinates. According to the system stability, the
poles should be located within the unit circle area; hence, the zeros are placed at the
outside of the unit circle. The multiple poles and zeros produce the higher order
rational function as below.
    
z1  c0 z1  c1 . . . z1  cm1
Hap ðzÞ ¼
ð1  c0 z1 Þð1  c1 z1 Þ. . .ð1  cm1 z1 Þ
ð6:118Þ
b0 þ b1 z1 þ b2 z2 þ    þ bm zm
¼
a0 þ a1 z1 þ a2 z2 þ    þ am zm

One example of the allpass filter is given below.

ðz1 0:5ejp=4 Þðz1 0:5ejp=4 Þðz1 þ 0:8Þ


Hap ðzÞ ¼ ð10:5ejp=4 z1 Þð10:5ejp=4 z1 Þð1 þ 0:8z1 Þ

The corresponding poles and zeros locations are below.


6.2 FIR Filters 385

Fig. 6.38 Pole zero plot and frequency response in magnitude for given transfer function

Poles : z ¼ 0:5ejp=4 ; z ¼ 0:5ejp=4 ; and z ¼ 0:8

zeros : z ¼ 2ejp=4 ; z ¼ 2ejp=4 ; and z ¼ 1:25

Figure 6.38 shows the poles and zeros location over the z-plane.
The allpass filter delivers the constant one magnitude in frequency response.
However, the time delay caused by the allpass filter denotes the non-constant
distribution. The group delay presents the time delay in terms of frequency x .
Below group delay equation is displayed again from Eq. (6.19).

d ðejx Þ ¼ grdðH ðejx ÞÞ ¼  dx


d
fargðH ðejx ÞÞg ð6:119Þ

The group delay of given transfer function is shown in Fig. 6.39. The distri-
bution represents the non-linear and non-constant shape.

Fig. 6.39 Group delay of


given transfer function
386 6 Filter Design

Prog. 6.31 MATLAB program for Figs. 6.38 and 6.39.

syms z
Hapznum = (z^-1 - 0.5*exp(-j*sym(pi)/4))*(z^-1 - 0.5*exp(j*sym(pi)/4))*(z^-1
+ 0.8);
Hapzden = (1 - 0.5*exp(-j*sym(pi)/4)*z^-1)*(1 - 0.5*exp(j*sym(pi)/4)*z^-
1)*(1 + 0.8*z^-1);
aa = collect(Hapzden,z);
bb = collect(Hapznum,z);
cc = bb/aa;
dd = simplifyFrac on(cc);
[num,den] = numden(dd);
ee = sym2poly(collect(num));
ff = sym2poly(collect(den));
[h,w] = freqz(ee,ff,2^13);

figure,
zplane(ee,ff);
figure,
plot(w,20*log10(abs(h))),grid, xlim([0 pi]), ylim([-120 20]);
figure,
[gd,w1] = grpdelay(ee,ff,2^13);
plot(w1,gd),grid, xlim([0 pi]), ylim([0 10]);

As shown above, the conjugate reciprocal correspondence between the pole and
zero pair provides the unit gain with arbitrary phase response. The transfer function
requires the system stability; therefore, the pole should be located within the unit
circle and the corresponding zeros is reflected to the conjugate reciprocal position
which is the circle outside. If we hope to maintain the magnitude response only then
the transfer function can be modified as Eq. (6.120).
 
H ðzÞ ¼ H0 ðzÞ z1  c0 ð6:120Þ

The transfer function above contains one zero location 1=c0 where the position is
the unit circle outside as shown in Eq. (6.121).
 
1 1 jh  1
c0 ¼ rejh wherejr j\1 hence ¼ e where  [1 ð6:121Þ

c0 r r 

By using the allpass filter, we can rewrite the transfer function as below.
6.2 FIR Filters 387

  1  c0 z1
H ðzÞ ¼ H0 ðzÞ z1  c0
1  c0 z1
ð6:122Þ
  z1  c0  
¼ H0 ðzÞ 1  c0 z1 ¼ H0 ðzÞ 1  c0 z1 Hap ðzÞ
1  c0 z1

Since the allpass filter demonstrates the unit gain, the zero reflection (conjugate
reciprocal) does not change the magnitude of given filter as below.
    
jH ðzÞj ¼ H0 ðzÞ z1  c0  ¼ H0 ðzÞð1  c0 z1 Þ ð6:123Þ

Therefore, any zeros on the system can move over the unit circle in conjugate
reciprocal fashion without modifying the magnitude response. The general form is
shown in Eq. (6.124).
 
 Y
n1  
 1 
Qm1 1  bk z1 
 k¼0 ð1  ak z1 Þ k¼0 
  ð6:124Þ
 Q  1
n1 
¼ Qm1 1 1 z  bk 
k¼0
ð1ak z Þ k¼0

Note that the jak j is less than one for any k to maintain the system stability. The
pole locations are fixed; however, the zeros can be chosen for desired magnitude
response. To understand the allpass filter property, we can derive the group delay of
the allpass filter as below.

d ðejx Þ ¼ grdðH ðejx ÞÞ ¼  dx d


fargðH ðejx ÞÞg
H ðejx Þ ¼ jH ðejx Þjej\H ðe Þ ¼ jH ðejx ÞjejargðH ðe ÞÞ
jx jx

loge H ðe Þ ¼ ln H ðe Þ
jx jx

¼ lnjH ðejx Þj þ j\H ðejx Þ ¼ lnjH ðejx Þj þ jargðH ðejx ÞÞ


where H ðejx Þ 6¼ 0 and \H ðejx Þ [ 0 8x ð6:125Þ
\H ðejx Þ ¼ Imagðln H ðejx ÞÞ
d ðejx Þ ¼  dx
d
f\H ðejx Þg n o
1 dH ðe Þ
jx
¼  dx
d
fImagðln H ðejx ÞÞg ¼ Imag H ðejx Þ dx

Using the substitution z ¼ ejx ðln z ¼ jxÞ:


n o n o
jz dH ðzÞ  z dH ðzÞ 
d ðejx Þ¼ Imag H ðzÞ dz  jx
¼ Real H ðzÞ dz  ð6:126Þ
z¼e z¼ejx

Based on the above derivation, let’s figure out the group delay of allpass filter.

z1 c 1c0 z


Hap ðzÞ ¼ 1c0 z10 ¼ zc0
ð6:127Þ
388 6 Filter Design

dHap ðzÞ c 1c z c c 1 2


¼ zc00  ðzc 0Þ2 ¼ ðzc
0 0
2 ¼ ðjczc
0 j 1
Þ2
ð6:128Þ
dz 0 0Þ 0

   
  z dHap ðzÞ  z dHap ðzÞ 
d ejx ¼ Real  jx ¼ Real  jx
Hap ðzÞ dz z¼e Hap ðzÞ dz z¼e
( ) ( )
2
zðz  c0 Þ jc0 j 1   1 jc0 j2 1 
¼ Real    ¼ Real  1  
1  c0 z ðz  c0 Þ2  jx z  c0 ðz  c0 Þ  jx
z¼e z¼e
( )
2
jc0 j 1 

¼ Real  2 
Let c0 ¼ rejh
1
1  c0 z  c0 z þ jc0 j z¼ejx

r2  1
¼ Real
1  rejh ejx  rejh ejx þ r 2

r2  1
¼ Real
1  r ðejðxhÞ þ ejðxhÞ Þ þ r 2

r2  1 1  r2
¼ Real ¼
1  2rcosðx  hÞ þ r 2 1  2rcosðx  hÞ þ r 2
ð6:129Þ

Sincejr j\1 for stable allpass filter


  2
d ðejx Þ ¼ grd Hap ðejx Þ ¼ 12rcos1r
ðxhÞ þ r2 [ 0 8x and h ð6:130Þ

The group delay of the allpass filter is always positive because of jr j\1 with
denominator condition. All possible values of the denominator are presented in
Fig. 6.40 for verification.

Fig. 6.40 Denominator of allpass filter group delay equation in Eq. (6.130)
6.2 FIR Filters 389

Prog. 6.32 MATLAB program for Fig. 6.40.


r = -1:0.01:1;
cosw = -1:0.01:1;
[X,Y] = meshgrid(r,cosw);
Z = 1-2*X.*Y+X.^2;
mesh(X,Y,Z);

The arbitrary stable transfer function is given as below with m zeros as 1=ck
located at unit circle outside.

Y
m 1  Y
m1  z1  ck

1
H ðzÞ ¼ H0 ðzÞ z  ck ¼ H 0 ðzÞ 1  ck z 1

k¼0 k¼0
1  ck z1
Y
m 1  mY
1 1
z  cq Y
m 1 
¼ H 0 ðzÞ 1  ck z1 ¼ H 0 ðzÞ 1  ck z1 Hap ðzÞ
k¼0 q¼0
1  cq z1 k¼0
   
 Y
m1  1 
   Y
m1  

H0 ðzÞ z  ck  ¼ H0 ðzÞ 1  ck z1 
 k¼0
  k¼0

! !
  Y
m1
1
 
grd H ðzÞjz¼ejx ¼ grd H0 ðzÞ 1  ck z 
k¼0
 jx
z¼e
0 ! 1
mY 1 z 1
 cq 

þ grd@  A
q¼0
1  cq z1  jx
z¼e
! ! ! !
Y
m 1
1
  X
m1 z1  cq 
¼ grd H 0 ðzÞ 1  ck z  þ grd 
k¼0
 jx q¼0
1  cq z1  jx
z¼e z¼e
! !
  Y
m 1  

grd H ðzÞjz¼ejx [ grd H 0 ðzÞ 1  ck z1 
k¼0
 jx
z¼e
ð6:131Þ
! !
z1  cq 
* grd  [ 0 8q
1  cq z1 
z¼ejx

We call the entirely reflected transfer function as minimum phase system [3]
since every zero reflection reduces the group delay by allpass filters. The reflection
indicates the zero relocations into the unit circle area.

Q
m1
Hmin ðzÞ ¼ H0 ðzÞ ð1  ck z1 Þ ð6:132Þ
k¼0
390 6 Filter Design

Above derivation provides the minimum group delay property of the minimum
phase system. The name minimum phase is originated from the following equation.
 
argðH ðejx ÞÞ ¼ argðHmin ðejx ÞÞ þ arg Hap ðejx Þ ð6:133Þ

The argðHmin ðejx ÞÞ presents the minimum phase lag property because of the
argðHap ðejx ÞÞ: Essential characteristics of the minimum phase system is the least
delayed impulse response.
Example 6.17
For the given FIR filter below, reflect the zeros in all possible situations to observe
the least delayed impulse response.

h0 ½n ¼ d½n  3d½n  4

Solution
The corresponding Z transform is below.

H0 ðzÞ ¼ 1  3z4

The pole and zero locations are below.

z4  3
H 0 ðzÞ ¼
z4
p ffiffiffi j2pk=4
z4 ¼ 3ej2pk z ¼ 4
3e k ¼ 0; 1; 2; and 3
pffiffiffi pffiffiffi
z ¼  4 3;  4 3j for zeros

z ¼ 0 for quartic poles


 pffiffiffi  pffiffiffi  pffiffiffi  pffiffiffi 
H0 ðzÞ ¼ 1  4 3z1 1 þ 4 3z1 1  4 3jz1 1 þ 4 3jz1
¼ 1  3z4

Frequency response, pole zero plot, and impulse response of the H0(z) is shown
in Fig. 6.41.
6.2 FIR Filters 391

Fig. 6.41 Frequency response, pole zero plot, impulse response of H0(z)

Prog. 6.33 MATLAB program for Fig. 6.41.

syms z
NN = 2^13;
N1 = NN/2+1;
findex = linspace(0,2*pi,NN);
f_f = findex(1:N1);
Hznum1 = (1-power(3,1/4)*z^-1)*(1+power(3,1/4)*z^-1)*(1-
1j*power(3,1/4)*z^-1)*(1+1j*power(3,1/4)*z^-1);
aa1 = collect(Hznum1,z);
bb1 = simplifyFrac on(aa1);
[num1,den1] = numden(bb1);
cc1 = sym2poly(collect(num1));
dd1 = sym2poly(collect(den1));
ee1 = cc1./dd1(1);
hf1 = abs( (ee1,NN));

figure,
subplot(2,2,[1 2]),plot(f_f,hf1(1:N1)), grid, xlim([0 pi]), ylim([0 5]);
subplot(223), zplane(cc1,dd1);
subplot(224),stem((0:4),ee1,'LineWidth',2),grid, xlim([0 4]), ylim([-4 4]);
392 6 Filter Design

Move one zero into the unit circle area in H1(z) as below.
 p ffiffiffi p ffiffiffi  p ffiffiffi  p ffiffiffi 
H1 ðzÞ ¼ z1  3 1 þ 3z1 1  3jz1 1 þ 3jz1
4 4 4 4

¼ 1:3161  0:7321z1  0:9634z2  1:2679z3 þ 2:2795z4

Frequency response, pole zero plot, and impulse response of the H1(z) is shown
in Fig. 6.42.
Prog. 6.34 MATLAB program for Fig. 6.42. Use the Prog. 6.33.

% From Prog. 6.33


...
Hznum1 = (z^-1-power(3,1/4))*(1+power(3,1/4)*z^-1)*(1-
1j*power(3,1/4)*z^-1)*(1+1j*power(3,1/4)*z^-1);
...

Move two zeros into the unit circle area in H2(z) as below.
 p ffiffiffi p ffiffiffi p ffiffiffi  p ffiffiffi 
H2 ðzÞ ¼ z1  3 z1 þ 3 1  3jz1 1 þ 3jz1
4 4 4 4

¼ 1:7321  2:0000z2 þ 1:7321z4

Fig. 6.42 Frequency response, pole zero plot, impulse response of H1(z)
6.2 FIR Filters 393

Frequency response, pole zero plot, and impulse response of the H1(z) is shown
in Fig. 6.43.
Prog. 6.35 MATLAB program for Fig. 6.43. Use the Prog. 6.33.

% From Prog. 6.33


...
Hznum1 = (z^-1-power(3,1/4))*(z^-1+power(3,1/4))*(1-1j*power(3,1/4)*z^-
1)*(1+1j*power(3,1/4)*z^-1);
...

Move all zeros into the unit circle area in Hmin(z) as below.
 p ffiffiffi  p ffiffiffi p ffiffiffi  p ffiffiffi 
Hmin ðzÞ ¼ z1  3Þ z1 þ 3 z1  3j z1 þ 3j ¼ 3 þ z4
4 4 4 4

Frequency response, pole zero plot, and impulse response of the Hmin(z) is
shown in Fig. 6.44.

Fig. 6.43 Frequency response, pole zero plot, impulse response of H2(z)
394 6 Filter Design

Fig. 6.44 Frequency response, pole zero plot, impulse response of Hmin(z)

Prog. 6.36 MATLAB program for Fig. 6.44. Use the Prog. 6.33.

% From Prog. 6.33


...
Hznum1 = (z^-1-power(3,1/4))*(z^-1+power(3,1/4))*(z^-1-
1j*power(3,1/4))*(z^-1+1j*power(3,1/4));
...

The reflection of zeros toward unit circle inside does not modify the magnitude
response of the designed filters. The group delay of the filter is reduced in the
impulse response where the larger samples are located at its left-hand end than other
sequences. If we want to design the least energy delay in the filter system, then
minimum phase filter is one solution.

The group delay discussed above is the averaged phase delay for frequency
component combinations. The phase delay is the delay for the single frequency x0
as shown in Eq. (6.134).

pðejx0 Þ ¼ phdðH ðejx0 ÞÞ ¼  argðHxð0e ÞÞ


jx0
ð6:134Þ

For example, single frequency sinusoid with envelop function is placed into the
LTI filter system. The group delay of the filter indicates the envelop delay between
6.2 FIR Filters 395

Table 6.26 Discrete-time FIR filter method summary and MATLAB functions
Filter method Function description MATLAB
functions
Windowing Apply window to truncated inverse DFT of brick wall fir1, fir2
filter specification
Multiband with Equiripple or least squares approach over the firls, firpm
transition bands frequency range
Constrained least Minimize squared integral error over entire frequency fircls,
squares range subject to maximum error constraints fircls1
Arbitrary response Arbitrary responses, including nonlinear phase and cfirpm
complex filters
Minimum phase Reflect the zeros into unit circle area polystab

the input and output signal. The phase delay specifies the single frequency sinusoid
delay between the signals. Therefore, the group delay presents the overall signal
shape delay. Table 6.26 summarizes FIR filter design methods and corresponding
MATLAB functions.

6.3 IIR Filters

The IIR filters contain the recursive input from the current and previous outputs
known as the feedback. The recursive input is represented by the rational transfer
function that is involved with the polynomial in the denominator. The direct IIR
filter design is difficult to be realized because of the circular frequency response
evaluation based on the exponential function. The IIR filter response is computed
by replacing the z variable with the exponential ejx as Eq. (6.135). The rational
value between the distance products to the poles and zeros decides the complex
result of the frequency response. The magnitude and phase are computed from the
complex value.

H ½k $ H ðejx Þjx¼2pk $ H ðzÞjz¼ejx ð6:135Þ


N

Butterworth IIR filter


The previous chapter discussed the mutual correlation between the poles and zeros
in the z plane. Since the nonlinear correlation increases the design complexity, the
Butterworth IIR filter [3, 17] initiates the design from the linear frequency domain.
The linear frequency X is the radian frequency from the continuous time signal xðtÞ
396 6 Filter Design

which can be decomposed into the infinite linear combination of eigenfunction ejXt .
The linear property of the frequency is denoted by the jX in the transfer function as
H ðjXÞ: Note that the circular property of the digital frequency x is shown by the ejx
in the transfer function as H ðejx Þ: Equation (6.136) presents the LPF model for the
linear frequency jX:

jH ðjXÞj2 ¼ H ðjXÞH  ðjXÞ ¼ H ðjXÞH ðjXÞ ¼ 1 þ1X2N ð6:136Þ


 
20 log10 jH ðjXÞj ¼ 10 log10 1
1 þ X2N
 20N log10 jXjfor X 1 ð6:137Þ

As the frequency X is increased, the denominator value becomes the dominant


factor to decrease the overall magnitude. Therefore, the frequency response rep-
resents the LPF with halfpower frequency Xh ¼ 1: The order N illustrates the
steepness of the magnitude transition. The higher N value shows the steeper
response in the filter as shown in Fig. 6.45.
Since the Eq. (6.136) represents the monotonically decreasing model, the
passband edge is defined as the halfpower frequency. Passband peak-to-peak ripple
in decibel can be calculated as Eq. (6.138).
   
Passband maximum magnitude 1
Dp ¼ 20 log10 ¼ 10 log10
Passband minimum magnitude 1=ð1 þ 1Þ
¼ 10 log10 ð1 þ 1Þ ¼ 3:0103dB for Xp ¼ Xh
ð6:138Þ

The Eq. (6.136) always denotes the one hertz halfpower frequency (also pass-
band frequency). In order to increase the design freedom, the expanding the fre-
quency axis relocates the passband frequency to any frequency by scaling as shown
in Eq. (6.139). Figure 6.46 demonstrates the LPF with 100 rad per second Xp .

1 0
0.9
-50
0.8
0.7
-100
0.6
0.5 -150
0.4 N=1
2
-200
0.3 3
4 N=1
2
0.2 5
-250 3
4
0.1 5

0 -300
-1 0 1 2 3 -1 0 1 2 3
10 10 10 10 10 10 10 10 10 10

Fig. 6.45 Frequency response of linear frequency model from Eq. (6.136)
6.3 IIR Filters 397

1 0
0.9
-20
0.8
0.7
-40
0.6
0.5 -60
0.4
-80
0.3 N=1
N=1
2
0.2 2
3
3 -100 4
4
0.1 5
5

0 -120
-1 0 1 2 3 -1 0 1 2 3
10 10 10 10 10 10 10 10 10 10

Fig. 6.46 Frequency response of Eq. (6.139) with Xp ¼ 100

jH ðjXÞj2 ¼ 1 2N
1þ X ð6:139Þ
Xp

Prog. 6.37 MATLAB program for Figs. 6.45 and 6.46.

ome = 0:0.1:1000;
omec = 100;
N = [2 4 6 8 10]';
hjo = 1./sqrt(1+ome.^N);
lhjo = 20*log10(1./sqrt(1+ome.^N));
hjoc = 1./sqrt(1+(ome/omec).^N);
lhjoc = 20*log10(1./sqrt(1+(ome/omec).^N));

figure,
semilogx(ome,hjo(1,:),ome,hjo(2,:),ome,hjo(3,:),ome,hjo(4,:),ome,hjo(5,:)),
grid
h = line([0.1 1000],[1/sqrt(2) 1/sqrt(2)],'Color',[1 0 0]);
figure,
semilogx(ome,lhjo(1,:),ome,lhjo(2,:),ome,lhjo(3,:),ome,lhjo(4,:),ome,lhjo(5,:))
, grid
figure,
semilogx(ome,hjoc(1,:),ome,hjoc(2,:),ome,hjoc(3,:),ome,hjoc(4,:),ome,hjoc(5,
:)), grid
h = line([0.1 1000],[1/sqrt(2) 1/sqrt(2)],'Color',[1 0 0]);
figure,
semilogx(ome,lhjoc(1,:),ome,lhjoc(2,:),ome,lhjoc(3,:),ome,lhjoc(4,:),ome,lhjo
c(5,:)), grid
398 6 Filter Design

The stopband is the nearest frequency after the transition due to the monotonic
property of the filter. The stopband attenuation in decibels can be computed as
Eq. (6.140).
   
Passband magnitude 1
Dst ¼ 20 log10 ¼ 20 log10
Stopband magnitude jH ðjXst Þj
0 1
0sffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffi1
B C  2N
B 1 C Xst
B
¼ 20 log10 B C @ A
r ffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffi
1 C ¼ 20 log10 1þ
Xp
ð6:140Þ
@  2N A
Xst
1þ Xp

  2N 
¼ 10 log10 1 þ XXstp

The stopband attenuation is proportional to the order selection based on the


given stopband and passband frequency. Once we have the frequency specification,
the order can be determined by Eq. (6.141).
 2N !  2N
Dst Xst Dst Xst
¼ log10 1 þ ! 10 10 ¼ 1 þ
10 Xp Xp
 2N  Dst   
Dst Xst Xst
! 10 10  1 ¼ ! log10 10 10  1 ¼ 2N log10 ð6:141Þ
Xp Xp
 D 
st
log10 10 10 1
N
 
Xst
2 log10 Xp

Designed filter from the frequency and order specification derives the magnitude
equation jH ðjXÞj2 for the filter. The stable H ðjXÞ filter requires the Laplace
transform to choose the proper poles from the combination. Let’s apply the Laplace
transform on the magnitude filter equation jH ðjXÞj2 as shown in Eq. (6.142).

jH ðsÞj2 ¼ H ðsÞH ðsÞ ¼ G 2N Let jX ! s


1þ s ð6:142Þ
jXp

Find poles (denominator solution) of Eq. (6.142) for s variable.

ðp0 Þðp1 Þðp2 Þ...ðp2N1 Þ


jH ðsÞj2 ¼ ðsp0 Þðsp1 Þðsp2 Þ...ðsp2N1 Þ
ð6:143Þ

where s ¼ r þ jX

The numerator of the above equation should be normalized by product of whole


negative poles. Note that zero s indicates the zero frequency and the zero-frequency
6.3 IIR Filters 399

gain of the Eq. (6.143) which is one. The poles of Eq. (6.142) can be found as
below.
 2N
pk pk p p p
¼ 1 ¼ ejpð2k þ 1Þ ; ¼ jej2N ð2k þ 1Þ ¼ ej2N ð2k þ 1Þ þ j2 ; k 2 Z
jXp Xp ð6:144Þ
p
ð2k þ 1Þ þ jp2
pk ¼ Xp e j2N
; k ¼ 0; 1; 2; . . .; 2N  1

On the s plane, the poles are distributed on the circle with Xp radius and equal
radian distance. According to the Laplace transform and continuous-time filter
theory, poles on the left s plane provides the stable filter.

pLi 2 left s plane
i ¼ 1; 2; . . .; N
pRi 2 right s plane

fpk g ¼ fpLi g [ fpRi g and ; ¼ fpLi g \ fpRi g

Separate the poles into the left s plane as pLi and right s plane as pRi . Observe that
there are no poles on the y axis ðjXÞ because of radian offset ejp=2 in Eq. (6.144).
     
pL0 pL1 pL2 . . . pLN1
H ðsÞ ¼        
s  pL0 s  pL1 s  pL2 . . . s  pLN1
 L  L  L   L  ð6:145Þ
p0 p1 p2 . . . pN1
¼ N
s þ a1 sN1 þ a2 sN2 þ    þ aN2 s1 þ aN1

Reconstruct the filter equation from the whole pLi as above.

ðpL0 ÞðpL1 ÞðpL2 Þ...ðpLN1 Þ ð6:146Þ


H ðjXÞ ¼ ðjXÞN þ a ðjXÞN1 þ a ðjXÞN2 þ  þ a ðjXÞ1 þ a
1 2 N2 N1

Let s ! jX

Convert back to jX by replacing with s as Eq. (6.146). The filter with rational
function is completed in the linear frequency domain jX . The circular frequency ejx
domain filter requires proper transformation from linear frequency domain filter.
The bilinear transformation converts the jX into the z domain which includes the
DTFT and DFT domain.
Bilinear transformation
The bilinear transformation [3, 7] is initiated from the z domain definition as below.
2pf X
z ¼ ejx ¼ ej fs ¼ ejfs ¼ ejXTs
ð6:147Þ
loge z ¼ jXTs
400 6 Filter Design

The logarithm function cannot directly be applied on the transformation because


rational function based on the polynomial is required for final filter equation. Using
the natural logarithm series, we can approximate the equation with first order
rational function as shown in Eq. (6.148).
(     )  
1 2 z1 1 z1 3 1 z1 5 2 z1
jX ¼ loge z ¼ þ þ þ  
Ts Ts zþ1 3 zþ1 5 zþ1 Ts z þ 1
  ð6:148Þ
1
2 1z
¼
Ts 1 þ z1

The following procedure figures out the relationship between X and x in bilinear
transformation.
8 jx  jx 9
   
2 <e 2 e 2  e 2 =
 jx
2 1  z1  2 1  ejx
jX ¼ ¼ ¼  
Ts 1 þ z1 z¼ejx Ts 1 þ ejx Ts : ejx2 ejx2 þ ejx2 ;
8  jx jx 9
> e 2 e 2 >
ð6:149Þ
> = 2j sinx 2j x
>
jx
2<
2je 2
2j
¼  jx  ¼ 2  ¼ tan
Ts >
> > Ts cos x2
:2e 2 e 2 þ2e 2 >
jx
 Ts 2
;
jx

   
X ¼ T2s tan x2 ¼ 2fs tan x2 ð6:150Þ

Equation (6.150) represents the exponential relation between the two frequency
domains by tangent function. Figure 6.47 illustrates the relationship which indicate
the p in x as the 1 in X . Therefore, the complete X frequency is covered by
limited length x frequency.

Fig. 6.47 Frequency


relationship in bilinear
transformation
6.3 IIR Filters 401

Prog. 6.38 MATLAB program for Fig. 6.47.

ome = linspace(0,pi,1000);
fs = 8000;
OM = 2*fs*tan(ome/2);
plot(ome,OM), grid
ylim([0 8000*8]);
xlim([0 pi])
ax = gca;
ax.XTick = [0 pi/4 pi/2 3*pi/4 pi];
ax.XTickLabel = {'0','\pi/4','\pi/2','3\pi/4','\pi'};
ax.YTick = [0 8000 8000*2 8000*3 8000*4 8000*5 8000*6 8000*7 8000*8];
ax.YTickLabel = {'0','f_s','2f_s','3f_s','4f_s','5f_s','6f_s','7f_s','8f_s'};
xlabel('\omega');
ylabel('\Omega')

Previous derivation for bilinear transformation performs the projection between


jX axis on s plane and unit circle on z plane. Generalization process extends to the
whole s and z plane for bilinear transformation as shown in Eq. (6.151).
 jx
e ! z ¼ rejx 2 C
jX ! s ¼ r þ jX 2 C

r ¼ erTs 
z ¼ ejXTs ¼ erTs þ jXTs ¼ erTs ejXTs ¼ rejx where ð6:151Þ
X ¼ 2fs tan x2

According to the tangent function, the X frequency is ranged from the 1 to 1


and also matched to the p to p in x frequency based on Eq. (6.150). The BIBO
stable system must include the unit circle area for ROC in z domain; therefore, the
all poles should be located within the unit circle area for causal system in z domain.
The unit circle area in the z plane is transformed to the left half of the s plane as
shown in Eq. (6.152) and Fig. 6.48.

Z plane
8f s
S plane
1
6f s
0.8
0.6 4f s
Imaginary Part

0.4
2f s
0.2
0 0
j

-0.2 -2f s
-0.4
-4f s
-0.6
-0.8 -6f s
-1
-8f s
-1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1 -3 -2.5 -2 -1.5 -1 -0.5 0
Real Part

Fig. 6.48 Color coded relation between z and s domain by bilinear transformation
402 6 Filter Design

r ¼ erTs \1 ! r\0
ð6:152Þ
re jx
2 Unit circle area ! r\0 and  1\X\1

Prog. 6.39 MATLAB program for Fig. 6.48.

fs = 1;
ts = 1/fs;
aatan = (-4:1/4:4);
of = 2*fs*aatan;
sig = -3:0.1:0;
[of1, sig1] = ndgrid((-4:1/4:4)*2*fs, -3:0.1:0);
s = sig1+1j*of1;
r = exp(sig*ts);
theta = atan(aatan)*2;
z = (r.'*exp(1j*theta))';
figure, mesh(real(s),imag(s),sig1), view(2), colormap(jet), ax = gca;
ax.YTick = [-8*fs -6*fs -4*fs -2*fs 0 2*fs 4*fs 6*fs 8*fs];
ax.YTickLabel = {'-8f_s','-6f_s','-4f_s','-2f_s','0','2f_s','4f_s','6f_s','8f_s',};
xlabel('\sigma');
ylabel('j\Omega')
tle('S plane')
figure, mesh(real(z),imag(z),sig1), view(2), colormap(jet);
xlabel('Real Part');
ylabel('Imaginary Part')
tle('Z plane')
xlim([-1.1 1.1]);
ylim([-1.1 1.1]);

The poles on the left s plane (Laplace transform) are projected on the unit circle
area in z domain (Z-transform) for stable IIR filter design. Note that we used the left
s plane poles on the Butterworth filter design in the linear frequency domain jX.
Example 6.18
Design the Table 6.27 IIR filter by using Butterworth method and bilinear
transformation.
6.3 IIR Filters 403

Table 6.27 Given filter specification


Filter specifications Value
Filter type Low pass filter
Filter realization Butterworth IIR
Filter length N with optimization
Passband frequency (fp) 1000 Hz; xp ¼ p=4
Passband magnitude 1
Passband peak-to-peak ripple in decibel ðDp Þ 3.0103 dB
Stopband frequency (fst) 2000 Hz; xst ¼ p=2
1
Stopband attenuation in decibels Dst 20 log10 0:1 ¼ 20 dB
Sampling frequency (fs) 8000 Hz

Solution
Use the bilinear transformation to find the frequency specification in X from
Eq. (6.150).
p
Xp ¼ 2fs tan ¼ 6627:4 rad=s
8
p
Xst ¼ 2fs tan ¼ 16000 rad=s
4

Apply the Eq. (6.141) to compute the filter order as below.


 20 
log10 1010  1
N
  ¼ 2:6068 ! 3
2 log10 16;000
6627:4

Create the transfer function in s domain as below.

G G
jH ðsÞj2 ¼ H ðsÞH ðsÞ ¼  2N ¼  6 where s ¼ r þ jX
1þ s
jXp 1þ s
j6627:4

Find the poles from the transfer function as below.


p p
pk ¼ 6627:4ej6ð2k þ 1Þ þ j2 for k ¼ 2; 1; 0; 1; 2; 3
p 2p 4p 5p
pk ¼ 6627:4ej0p ; 6627:4ej3 ; 6627:4ej 3 ; 6627:4ejp ; 6627:4ej 3 ; 6627:4ej 3

Select the left s plane poles as below.


2p 4p
pLi ¼ 6627:4ej 3 ; 6627:4ejp ; 6627:4ej 3
404 6 Filter Design

Compute the gain G to normalize the response at zero frequency as below.


 
2p   4p

G ¼ 6627:4ej 3 6627:4ejp 6627:4ej 3 ¼ 291091517618:824

Assemble the Butterworth equation in s domain as below.

291091517618:824
H ðsÞ ¼    
j2p
s  6627:4e 3 ðs  6627:4ejp Þ s  6627:4ej 3
4p

Apply the bilinear transformation as below.




291091517618:824 
H ðzÞ ¼     
4p   
jX  6627:4ej 3 ðjX  6627:4ejp Þ jX  6627:4ej 3 
2p

1z1
jX¼2fs
1 þ z1

The final Butterworth filter in discrete time domain is below.

0:0317 þ 0:0951z1 þ 0:0951z2 þ 0:0317z3


H ðzÞ ¼
1  1:4590z1 þ 0:9104z2  0:1978z3

Figure 6.49 shows the pole zero plot of the design filter. Three poles are located
within the unit circle and triple zeros are placed at –1 location.

Fig. 6.49 Pole zero plot of 1


designed Butterworth filter for
0.8
Table 6.27
0.6
0.4
Imaginary Part

0.2
3
0
-0.2
-0.4
-0.6
-0.8
-1

-1 -0.5 0 0.5 1
Real Part
6.3 IIR Filters 405

Prog. 6.40 MATLAB program for Figs. 6.49 and 6.50.

syms z s
pb = linspace(0,1000,501);
sb = linspace(2000,4000,2001);
aa = (16000*(1-z^(-1))-6627.4*exp(j*2*sym(pi)/3)*(1+z^(-1)))*(16000*(1-z^(-
1))-6627.4*exp(j*sym(pi))*(1+z^(-1)))*(16000*(1-z^(-1))-
6627.4*exp(j*4*sym(pi)/3)*(1+z^(-1)));
bb = simplify(aa);
cc = 291091517618.824*(1+z^-1)^3;
dd = expand(cc);
ee = collect(dd/bb);
[num, den] = numden(ee);
nnum = sym2poly(num);
nden = sym2poly(den);
nnnum = nnum/nden(1)
nnden = nden/nden(1)
zplane(nnnum,nnden)
[h,w] = freqz(nnnum,nnden,4001,8000);
hpb = freqz(nnnum,nnden,pb,8000);
hsb = freqz(nnnum,nnden,sb,8000);
figure,
plot(w,abs(h),pb,abs(hpb),'.-',sb,abs(hsb),'.-'), grid
line([0 4000],[0.1 0.1])
ylim([0 1])
figure
plot(w,db(h),pb, db(hpb),'.-',sb,db(hsb),'.-'), grid
line([0 4000],[-20 -20])
legend('Response','Passband','Stopband');

1 0
Response
0.9 Passband -50
Stopband
0.8
-100
0.7
0.6 -150

0.5 -200
0.4 -250
0.3
-300
0.2 Response
0.1 -350 Passband
Stopband

0 -400
0 500 1000 1500 2000 2500 3000 3500 4000 0 500 1000 1500 2000 2500 3000 3500 4000
Frequency (Hz) Frequency (Hz)

Fig. 6.50 Frequency response of designed Butterworth filter for Table 6.27
406 6 Filter Design

Figure 6.50 represents the frequency response of the filter. The passband and
stopband satisfy the Table 6.27 specification. Note that the horizontal line in the
figures denote the stopband attenuation requirement.

Type I Chebyshev filter


Similar to the Butterworth filter, Type I Chebyshev filter [7] uses the rational
function with special polynomial as shown in Eq. (6.153). As the e2 TN2 ðXÞ
increases exponentially, the filter magnitude decreases significantly for LPF
property.

jH ðjXÞj2 ¼ H ðjXÞH  ðjXÞ ¼ H ðjXÞH ðjXÞ ¼ 1 þ e21T 2 ðXÞ ð6:153Þ


N

The special polynomial is the first kind Chebyshev polynomial TN ðXÞ [18].
Below show the polynomials up to 7th order.

T0 ðXÞ ¼ 1
T1 ðXÞ ¼ X
T2 ðXÞ ¼ 2X2  1
T3 ðXÞ ¼ 4X3  3X
ð6:154Þ
T4 ðXÞ ¼ 8X4  8X2 þ 1
T5 ðXÞ ¼ 16X5  20X3 þ 5X
T6 ðXÞ ¼ 32X6  48X4 þ 18X2  1
T7 ðXÞ ¼ 64X7  112X5 þ 56X3  7X

The first kind Chebyshev polynomial can be derived from the recursive equation
as shown in Eq. (6.155).

TN þ 1 ðXÞ ¼ 2XTN ðXÞ  TN1 ðXÞ ð6:155Þ

The first kind Chebyshev polynomial is equivalent to the trigonometric or


hyperbolic functions for the range of X values as below.
8 1
< cosðN
 cos ð1
X ÞÞ  forjXj  1
TN ðXÞ ¼ cosh N cosh ðX Þ for X
1 ð6:156Þ
:  
ð1ÞN cosh N cosh1 ðXÞ for X   1

The TN ðXÞ presents limited magnitude one for less than one X in absolute
because of the cosine function in Eq. (6.156). Also, the TN ðXÞ shows rapid growing
magnitude for greater than one X due to the hyperbolic function.

0 for odd N
TN ð1Þ ¼ 1 and jTN ð0Þj ¼ ð6:157Þ
1 for even N
6.3 IIR Filters 407

The initial value of the TN ðXÞ depends on the order parity but the TN ð1Þ value is
fixed as one for all order. Figure 6.51 illustrates the TN ðXÞ up to 7th order.
Prog. 6.41 MATLAB program for Fig. 6.51.

x = linspace(0,2,1000);
t1 = x;
t2 = 2*x.^2-1;
t3 = 4*x.^3-3*x;
t4 = 8*x.^4-8*x.^2+1;
t5 = 16*x.^5-20*x.^3+5*x;
t6 = 32*x.^6-48*x.^4+18*x.^2-1;
t7 = 64*x.^7-112*x.^5+56*x.^3-7*x;
plot(x,t1,x,t2,x,t3,x,t4,x,t5,x,t6,x,t7), grid, xlim([0 2]), ylim([-1.5 12]);
xlabel('\Omega')
ylabel('T_N(\Omega)')
legend('N = 1','2','3','4','5','6','7');

As expected, the TN ðXÞ depicts the fluctuation with limited magnitude up to one
X and rapidly increasing after the range. The higher order demonstrates the faster
monotonic growing in Fig. 6.51. By applying the polynomial to Eq. (6.153), the
filter response can be calculated and illustrated as Fig. 6.52. The response is similar
to the Butterworth filter; however, we can observe the fluctuation in passband and
steeper decreasing in the transition band. In overall, the frequency response rep-
resents the LPF with passband frequency Xp ¼ 1: Note that the Xp and Xh are equal
in Fig. 6.52 because of unit e. The order N illustrates the steepness of the magnitude
transition. The higher N value shows the steeper response in the filter as shown in
Fig. 6.52.

Fig. 6.51 The first kind 12


Chebyshev polynomial N=1
TN ðXÞ: 10
2
3
4
5
8 6
7

0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2


408 6 Filter Design

1 0
0.9
-50
0.8
0.7
-100
0.6
0.5 -150
0.4
N=1 N=1
2 -200 2
0.3 3 3
4 4
0.2 5 -250 5
6 6
0.1 7 7
0 -300
-1 0 1 2 3 -1 0 1 2 3
10 10 10 10 10 10 10 10 10 10

Fig. 6.52 Frequency response of linear frequency model from Eq. (6.153) with e ¼ 1

Prog. 6.42 MATLAB program for Fig. 6.52.

x = linspace(0,1000,100001);
t1 = x;
t2 = 2*x.^2-1;
t3 = 4*x.^3-3*x;
t4 = 8*x.^4-8*x.^2+1;
t5 = 16*x.^5-20*x.^3+5*x;
t6 = 32*x.^6-48*x.^4+18*x.^2-1;
t7 = 64*x.^7-112*x.^5+56*x.^3-7*x;

figure,
semilogx(x,1./sqrt(1+t1.^2),x,1./sqrt(1+t2.^2),x,1./sqrt(1+t3.^2),x,1./sqrt(1+t
4.^2),x,1./sqrt(1+t5.^2),x,1./sqrt(1+t6.^2),x,1./sqrt(1+t7.^2)), grid
h = line([0.1 1000],[1/sqrt(2) 1/sqrt(2)],'LineStyle','-.');
xlim([0.1 1000]);
xlabel('\Omega')
ylabel('|H(j\Omega)|')
legend('N = 1','2','3','4','5','6','7');
figure,
semilogx(x,20*log10(1./sqrt(1+t1.^2)),x,20*log10(1./sqrt(1+t2.^2)),x,20*log1
0(1./sqrt(1+t3.^2)),x,20*log10(1./sqrt(1+t4.^2)),x,20*log10(1./sqrt(1+t5.^2)),
x,20*log10(1./sqrt(1+t6.^2)),x,20*log10(1./sqrt(1+t7.^2))), grid
legend('N = 1','2','3','4','5','6','7');
xlim([0.1 1000]);
ylim([-300 0]);
xlabel('\Omega')
ylabel('20log_{10}|H(j\Omega)|');
6.3 IIR Filters 409

From the given passband peak-to-peak ripple Dp , the e value can be determined
by Eq. (6.158).
!
1  
Dp ¼ 20 log10 pffiffiffiffiffiffiffiffiffiffiffiffi ¼ 10 log10 1 þ e2
1= 1 þ e2 ð6:158Þ
qffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffi
Dp
e¼ 10  1
10

Expanding the frequency axis relocates the passband frequency to any frequency
by scaling as shown in Eq. (6.159). Figure 6.53 demonstrates the LPF with
100 rad/s Xp and 10 dB Dp .

1 
jH ðjXÞj2 ¼
1 þ e2 TN2 X ð6:159Þ
Xp

1 0
N=1
0.9 2 -5
3
0.8 4 -10
5
0.7 6
-15
7
0.6 -20
0.5 -25
0.4 -30
N=1
0.3 -35 2
3
0.2 -40 4
5
0.1 -45 6
7
0 -50
-1 0 1 2 3 -1 0 1 2 3
10 10 10 10 10 10 10 10 10 10

Fig. 6.53 Frequency response of Eq. (6.159) with Xp ¼ 100 and Dp ¼ 10


410 6 Filter Design

Prog. 6.43 MATLAB program for Fig. 6.53.

dp = 10; %passband ripple in decibel


pa = 100; %passband for LPF
ee = sqrt(10^(dp/10)-1);
x = linspace(0,1000,100001);
t1 = ee*(x/pa);
t2 = ee*(2*(x/pa).^2-1);
t3 = ee*(4*(x/pa).^3-3*(x/pa));
t4 = ee*(8*(x/pa).^4-8*(x/pa).^2+1);
t5 = ee*(16*(x/pa).^5-20*(x/pa).^3+5*(x/pa));
t6 = ee*(32*(x/pa).^6-48*(x/pa).^4+18*(x/pa).^2-1);
t7 = ee*(64*(x/pa).^7-112*(x/pa).^5+56*(x/pa).^3-7*(x/pa));

figure,
semilogx(x,1./sqrt(1+t1.^2),x,1./sqrt(1+t2.^2),x,1./sqrt(1+t3.^2),x,1./sqrt(1+t
4.^2),x,1./sqrt(1+t5.^2),x,1./sqrt(1+t6.^2),x,1./sqrt(1+t7.^2)), grid
h = line([0.1 1000],[1/sqrt(10) 1/sqrt(10)],'LineStyle','-.');
str = '$$\frac{1}{\sqrt{10}}$$';
text(1,1/sqrt(10)+0.05,str,'Interpreter','latex')
xlim([0.1 1000]);
xlabel('\Omega')
ylabel('|H(j\Omega)|')
legend('N = 1','2','3','4','5','6','7');
figure,
semilogx(x,20*log10(1./sqrt(1+t1.^2)),x,20*log10(1./sqrt(1+t2.^2)),x,20*log1
0(1./sqrt(1+t3.^2)),x,20*log10(1./sqrt(1+t4.^2)),x,20*log10(1./sqrt(1+t5.^2)),
x,20*log10(1./sqrt(1+t6.^2)),x,20*log10(1./sqrt(1+t7.^2))), grid
h = line([0.1 1000],[-10 -10],'LineStyle','-.');
str = '-10';
text(1,-10-1,str,'Interpreter','latex')
xlim([0.1 1000]);
ylim([-50 0]);
xlabel('\Omega')
ylabel('20log_{10}|H(j\Omega)|')
legend('N = 1','2','3','4','5','6','7');
6.3 IIR Filters 411

The stopband is the nearest frequency after the transition due to the monotonic
property after passband region. From the given stopband attenuation in decibel Dst ,
the required filter order N can be calculated by using Eq. (6.160).
0 1
sffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffi
1 B 1 C
Dst ¼ 20 log10 ¼ 20 log10 B
2@ rffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffi
 A
C
jH ðjXst Þj
1= 1 þ e TN Xp
2 2 Xst

  
Xst
¼ 10 log10 1 þ e2 TN2
Xp
sffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffi
  Dst
Xst 10 10  1
TN ¼
Xp e2
sffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffi
     Dst
Xst Xst 10 10  1 Xst
TN ¼ cosh N cosh1 ¼ for [1
Xp Xp e2 Xp

ex þ ex  pffiffiffiffiffiffiffiffiffiffiffiffiffi
cosh x ¼ ; cosh1 x ¼ loge x þ x2  1 for x
1
2
qffiffiffiffiffiffiffiffiffiffi
Dst
cosh1 10 10 1
e2
N
  ð6:160Þ
cosh1 Xst
Xp

Similar to the Butterworth IIR filter, the stable H ðjXÞ filter requires the Laplace
transform to choose the proper poles from the combination. Let’s apply the Laplace
transform on the magnitude filter equation jH ðjXÞj2 as shown in Eq. (6.161).

G  Let jX ! s
jH ðsÞj2 ¼ H ðsÞH ðsÞ ¼
1 þ e2 TN2 s ð6:161Þ
jXp

Find poles (denominator solution) of Eq. (6.161) for s variable.

jH ðsÞj2 ¼ ðsp0 Þðsp1 Þðsp


G
2 Þ...ðsp2N1 Þ
ð6:162Þ

where s ¼ r þ jX

The poles of Eq. (6.161) can be found as below.


412 6 Filter Design

   
pk p 1 1
¼  sin ð2k  1Þ sinh sinh1
Xp 2N N e
   
p 1 1
þ j cos ð2k  1Þ cosh sinh1 for k ¼ 1; 2; . . .; N
2N N e ð6:163Þ
    
p 1 1
pk ¼ Xpa sin ð2k  1Þ sinh sinh1
2N N e
 p
 1  
1 1
þ jXpa cos ð2k  1Þ 2N cosh N sinh e for k ¼ 1; 2; . . .; N

Separate the poles into the left s plane as pLi and right s plane as pRi . Observe that
poles on the left s plane provides the stable filter. The left and right of the s plane
can be divided by the real value. Positive real value indicates right s plane and
negative real value specifies left s plane.

pLi 2 left s plane
i ¼ 1; 2; . . .; N
pi 2 right s plane
R

   
p 1 1
pLk ¼ Xpa sin ð2k  1Þ sinh sinh1
2N N e ð6:164Þ
    
p
þ jXpa cos ð2k  1Þ 2N cosh N1 sinh1 1e

   
p 1 1
pRk ¼ Xpa sin ð2k  1Þ sinh sinh1
2N N e
   
p 1 1
þ jXpa cos ð2k  1Þ cosh sinh1
2N N e

Reconstruct the filter equation from the whole pLi as below.

G
H ðsÞ ¼   
s s  pL2 . . .ðs  pLN Þ
pL1
ð6:165Þ
G
¼ N
s þ a1 s N1 þ a2 sN2 þ    þ aN2 s1 þ aN1

According to the Chebyshev polynomials, the output for the zero input is dif-
ferent for the even and odd order case as shown in Eq. (6.157); therefore, the
zero-frequency gain G is parity sensitive as below. Figure 6.51 also represents the
different initial values for the even and odd order number.
6.3 IIR Filters 413


1 pffiffiffiffiffiffiffiffiffiffiffiffi for odd N
G ¼ H ð s ¼ 0Þ ¼
1= 1 þ e2 for even N

G 1 pffiffiffiffiffiffiffiffiffiffiffiffi for odd N
H ðs ¼ 0Þ ¼    ¼
pL1 pL2 . . .ðpLN Þ 1= 1 þ e2 for even N
  L  L   L 
p p . . . p for odd N
G¼  1L  2L   NL  pffiffiffiffiffiffiffiffiffiffiffiffi ð6:166Þ
p1 p2 . . . pN = 1 þ e2 for even N

Convert back to jX by replacing with s as Eq. (6.167). The filter with rational
function is completed in the linear frequency domain jX.

H ðjXÞ ¼ ðjXÞN þ a ðjXÞN1 þ a ðjXÞGN2 þ  þ a 1 ð6:167Þ


1 2 N2 ðjXÞ þ aN1

The bilinear transformation provides the tool to change the linear frequency
domain into the z domain for discrete-time filter as shown in Eq. (6.168).

  
H ðzÞ ¼ ðjXÞN þ a N1
G

þ  þ aN2 ðjXÞ1 þ aN1 jX¼2f ð6:168Þ
1 ðjXÞ 1z1
1 þ z1
s

The final Type I Chebyshev filter in discrete time domain is Eq. (6.168).
Example 6.19
Design the Table 6.28 IIR filter by using Type I Chebyshev method and bilinear
transformation.

Table 6.28 Given filter specification


Filter specifications Value
Filter type Low pass filter
Filter realization Type I Chebyshev IIR filter
Filter length N with optimization
Passband frequency (fp) 1000 Hz; xp ¼ p=4
Passband magnitude 1
 
Passband peak-to-peak ripple in decibel ðDp Þ 20 log10 1=p1ffiffiffiffiffiffiffi
ffi ¼ 3:0103dB
1þ1

Stopband frequency (fst) 2000 Hz; xst ¼ p=2


1
Stopband attenuation in decibels Dst 20 log10 0:1 ¼ 20 dB
Sampling frequency (fs) 8000 Hz
414 6 Filter Design

Solution
Use the bilinear transformation to find the frequency specification in X from
Eq. (6.150).
p
Xp ¼ 2fs tan ¼ 6627:4rad=s
8
p
Xst ¼ 2fs tan ¼ 16000 rad=s
4

Compute the e value by using the Eq. (6.158).


qffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffi pffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffi
Dp
e¼ 10 10  1 ¼ 10 10  1 ¼ 1
3:0103

Estimate the proper filter order by using the Eq. (6.160).


rffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffi
 D  r
ffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffi
 ffi
1 1
10 10  1 =e 1010  1 =12
st 20
cosh 2 cosh
N
  ¼   ¼ 1:9549 ! 2; even
cosh1 XXstp cosh1 16;000
6627:4

Derive the left s plane poles from Eq. (6.164).


   
p 1 1 1
pLk ¼ Xp sin ð2k  1Þ sinh sinh
2N N e
    
p 1 1
þ jXp cos ð2k  1Þ cosh sinh1 ; k ¼ 1; 2
2N N e

pLk ¼ 2132:7 þ j5148:7; 2132:7  j5148:7

Based on the poles and gain equation Eq. (6.166), build the filter equation in
s domain as below. Note that the filter order is even.
pffiffiffi
ð2132:7  j 5148:7Þð2132:7 þ j 5148:7Þ= 2
H ðsÞ ¼
ðs þ 2132:7  j 5148:7Þðs þ 2132:7 þ j 5148:7Þ
21960983:69
¼ 2
s þ 4265:4s þ 31057520:98
6.3 IIR Filters 415

1
0.8
0.6
0.4
Imaginary Part 0.2
2
0
-0.2
-0.4
-0.6
-0.8
-1
-1 -0.5 0 0.5 1
Real Part

Fig. 6.54 Pole zero plot of designed Type I Chebyshev filter for Table 6.28

Apply the bilinear transformation as below.


pffiffiffi
ð2132:7  j 5148:7Þð2132:7 þ j 5148:7Þ= 2
H ðjXÞ ¼
ðjX þ 2132:7  j 5148:7ÞðjX þ 2132:7 þ j 5148:7Þ

21960983:69 
H ðzÞ ¼   
ðjX þ 2132:7  j5148:7ÞðjX þ 2132:7 þ j5148:7ÞjX¼2fs 1z1
1 þ z1

The final Type I Chebyshev filter in discrete time domain is below.

0:0618 þ 0:1236z1 þ 0:0618z2


H ðzÞ ¼
1  1:2662z1 þ 0:6158z2

Figure 6.54 shows the pole zero plot of the design filter. Two poles are located
within the unit circle and double zeros are placed at –1 location.
416 6 Filter Design

Prog. 6.44 MATLAB program for Figs. 6.54 and 6.55.

syms z
pb = linspace(0,1000,501);
sb = linspace(2000,4000,2001);
aa = (21960983.69*(1+z^(-1))^2)/((16000*(1-z^(-1))+(2132.7-
j*5148.7)*(1+z^(-1)))*(16000*(1-z^(-1))+(2132.7+j*5148.7)*(1+z^(-1))));
bb = simplify(aa);
[num den] = numden(bb);
cc = expand(num);
dd = simplify(den);
nnum = sym2poly(cc);
dden = sym2poly(dd);
nnnum = nnum/dden(1);
nnden = dden/dden(1);

figure,
zplane(nnnum,nnden)
[h,w] = freqz(nnnum,nnden,4001,8000);
hpb = freqz(nnnum,nnden,pb,8000);
hsb = freqz(nnnum,nnden,sb,8000);
figure,
plot(w,abs(h),pb,abs(hpb),'.-',sb,abs(hsb),'.-'), grid
line([0 4000],[0.1 0.1])
ylim([0 1])
legend('Response','Passband','Stopband')
ylabel('|H(e^{j\omega})|')
xlabel('Frequency (Hz)')
figure,
plot(w,db(h),pb, db(hpb),'.-',sb,db(hsb),'.-'), grid
line([0 4000],[-20 -20])
legend('Response','Passband','Stopband')
ylabel('20log_{10}|H(e^{j\omega})| (dB)')
xlabel('Frequency (Hz)');

Figure 6.55 represents the frequency response of the filter. The passband and
stopband satisfy the Table 6.28 specification. Note that the horizontal line in the
figures denote the stopband attenuation requirement.

Type II Chebyshev filter


Type II Chebyshev filter [7] is originated from the Type I Chebyshev filter. Type II
also uses the first kind Chebyshev polynomial TN ðXÞ [18] as Eq. (6.154).
6.3 IIR Filters 417

1 0
Response
0.9 Passband
-20
Stopband
0.8
-40
0.7

0.6 -60

0.5 -80
0.4
-100
0.3
-120
0.2
Response
0.1 -140 Passband
Stopband
0 -160
0 500 1000 1500 2000 2500 3000 3500 4000 0 500 1000 1500 2000 2500 3000 3500 4000

Frequency (Hz) Frequency (Hz)

Fig. 6.55 Frequency response of designed Type I Chebyshev filter for Table 6.28

jH ðjXÞj2 ¼ H ðjXÞH  ðjXÞ ¼ H ðjXÞH ðjXÞ ¼ 1 þ 1


1
ð6:169Þ
ðÞ
e2 T 2 1
N X

Let’s investigate the conceptual derivation procedure of the Type II Chebyshev


filter. First, H0 ðjXÞ below is the Type I Chebyshev filter illustrated at Fig. 6.56 with
e ¼ 1:
qffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffi
jH0 ðjXÞj ¼ 1
1 þ e2 T 2 ðXÞ
; Type I Chebyshev filter ð6:170Þ
N

The H0 ðjXÞ is inverted in magnitude by placing the e2 TN2 ðXÞ at numerator as


Eq. (6.171). The H1 ðjXÞ is HPF due to the inversion as shown in Fig. 6.57.
rffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffi
e2 TN2 ðXÞ
jH1 ð j XÞj ¼ 1 þ e2 TN2 ðXÞ
; Upside down inversion of jH0 ðj XÞj ð6:171Þ

The H1 ðjXÞ is flipped left right by input variable inversion as 1=X: The flipping
is performed on frequency axis over the X ¼ 1 as shown in Fig. 6.58. The inversion
and flipping operation make the filter back to the LPF again.
sffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffi
 
e2 TN2 X1
jH ðjXÞj ¼  
1 þ e2 TN2 X1
ð6:172Þ
1
¼ qffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffi ; Filp left right of jH1 ðjXÞj over X ¼ 1
1 þ e2 T 21 1
N ðXÞ
418 6 Filter Design

1
0.9
0.8
0.7
)| 0.6
0.5
|H(j

0.4
N=1
0.3 2
3
0.2 4
5
0.1 6
7
0
-1 0 1 2 3
10 10 10 10 10

Fig. 6.56 Magnitude response of Eq. (6.170)

1
0.9
0.8
0.7
0.6
)|

0.5
|H(j

0.4
N=1
0.3 2
3
0.2 4
5
0.1 6
7
0
-1 0 1 2 3
10 10 10 10 10

Fig. 6.57 Magnitude response of Eq. (6.171)

To control the ripple in the stopband, Eq. (6.172) is modified as Eq. (6.173).

jH ðjXÞj2 ¼ 1
e2 ð6:173Þ

T2
N ðXXst Þ

Figure 6.59 depicts Eq. (6.173) for two different parameter values. The
increased e value suppresses the stopband ripples further.
6.3 IIR Filters 419

1
0.9
0.8
0.7
)| 0.6
0.5
|H(j

0.4
N=1
0.3 2
3
0.2 4
5
0.1 6
7
0
-1 0 1 2 3
10 10 10 10 10

Fig. 6.58 Magnitude response of Eq. (6.172)

1 1
N=1
0.9 0.9 2
3
0.8 0.8 4
5
0.7 0.7 6
7
0.6 0.6
)|

)|

0.5 0.5
|H(j

|H(j

0.4 0.4
N=1
0.3 2 0.3
3
0.2 4 0.2
5
0.1 6 0.1
7
0 0
-1 0 1 2 3 -1 0 1 2 3
10 10 10 10 10 10 10 10 10 10

Fig. 6.59 Magnitude response of Eq. (6.173) with different parameters


420 6 Filter Design

Prog. 6.45 MATLAB program for Figs. 6.57, 6.58 and 6.59.

x = linspace(0.001,1000,100001);
t1 = x;
t2 = 2*x.^2-1;
t3 = 4*x.^3-3*x;
t4 = 8*x.^4-8*x.^2+1;
t5 = 16*x.^5-20*x.^3+5*x;
t6 = 32*x.^6-48*x.^4+18*x.^2-1;
t7 = 64*x.^7-112*x.^5+56*x.^3-7*x;

figure,
semilogx(x,sqrt(t1.^2./(1+t1.^2)),x,sqrt(t2.^2./(1+t2.^2)),x,sqrt(t3.^2./(1+t3.^
2)),x,sqrt(t4.^2./(1+t4.^2)),x,sqrt(t5.^2./(1+t5.^2)),x,sqrt(t6.^2./(1+t6.^2)),x,s
qrt(t7.^2./(1+t7.^2))), grid
h = line([0.1 1000],[1/sqrt(2) 1/sqrt(2)],'LineStyle','-.');
xlim([0.1 1000]), xlabel('\Omega'), ylabel('|H(j\Omega)|'),
legend('N = 1','2','3','4','5','6','7');
x = 1./x;
figure,
semilogx(x,sqrt(t1.^2./(1+t1.^2)),x,sqrt(t2.^2./(1+t2.^2)),x,sqrt(t3.^2./(1+t3.^
2)),x,sqrt(t4.^2./(1+t4.^2)),x,sqrt(t5.^2./(1+t5.^2)),x,sqrt(t6.^2./(1+t6.^2)),x,s
qrt(t7.^2./(1+t7.^2))), grid
h = line([0.1 1000],[1/sqrt(2) 1/sqrt(2)],'LineStyle','-.');
xlim([0.1 1000]), xlabel('\Omega'), ylabel('|H(j\Omega)|');
x = x*100;
figure,
semilogx(x,sqrt(t1.^2./(1+t1.^2)),x,sqrt(t2.^2./(1+t2.^2)),x,sqrt(t3.^2./(1+t3.^
2)),x,sqrt(t4.^2./(1+t4.^2)),x,sqrt(t5.^2./(1+t5.^2)),x,sqrt(t6.^2./(1+t6.^2)),x,s
qrt(t7.^2./(1+t7.^2))), grid
h = line([0.1 1000],[1/sqrt(2) 1/sqrt(2)],'LineStyle','-.');
xlim([0.1 1000]), xlabel('\Omega'), ylabel('|H(j\Omega)|');
figure,
semilogx(x,sqrt(t1.^2./(100+t1.^2)),x,sqrt(t2.^2./(100+t2.^2)),x,sqrt(t3.^2./(1
00+t3.^2)),x,sqrt(t4.^2./(100+t4.^2)),x,sqrt(t5.^2./(100+t5.^2)),x,sqrt(t6.^2./(
100+t6.^2)),x,sqrt(t7.^2./(100+t7.^2))), grid
h = line([0.1 1000],[1/sqrt(101) 1/sqrt(101)],'LineStyle','-.');
xlim([0.1 1000]), xlabel('\Omega'), ylabel('|H(j\Omega)|');

Previous IIR filters controls the passband ripple by adjusting the e value in the
rational function. Equation (6.172) is modified as Eq. (6.173) to manage the
passband ripple by e parameter. Note that the passband frequency is required for
Eq. (6.174).
6.3 IIR Filters 421

1 
jH ðjXÞj2 ¼
T2
N
Xst
Xp ð6:174Þ
1 þ e2
T2
N ð ÞXst
X

Figure 6.60c demonstrates the controlled passband frequency and ripple by


using the Xp and e parameter in Eq. (6.174). The stopband ripple is barely
noticeable; however, the fluctuation is observed in decibel plot in Fig. 6.60d.

1 0
0.9 -20
0.8 -40
0.7 -60

)|
0.6 -80
20log |H(j
)|

0.5 10 -100
|H(j

0.4 -120
N=1 N=1
0.3 2 -140 2
3 3
0.2 4 -160 4
5 5
0.1 6 -180 6
7 7
0 -200
-1 0 1 2 3 -1 0 1 2 3
10 10 10 10 10 10 10 10 10 10

(a) (b)
1 0
0.9 -20
0.8 -40
0.7 -60
)|

0.6 -80
20log |H(j
)|

0.5 -100
10
|H(j

0.4 -120
N=1 N=1
0.3 2 -140 2
3 3
0.2 4 -160 4
5 5
0.1 6 -180 6
7 7
0 -200
-1 0 1 2 3 -1 0 1 2 3
10 10 10 10 10 10 10 10 10 10

(c) (d)

Fig. 6.60 Equation (6.173) response in a absolute and b decibel for e ¼ 1 and Xst ¼ 100:
Equation (6.174) response in c absolute and d decibel for e ¼ 1; Xst ¼ 100; and Xp ¼ 10
422 6 Filter Design

Prog. 6.46 MATLAB program for Fig. 6.60.

q = linspace(0.001,1000,100001);
ee = 1;
x = 100./q;
t1 = x;
t2 = 2*x.^2-1;
t3 = 4*x.^3-3*x;
t4 = 8*x.^4-8*x.^2+1;
t5 = 16*x.^5-20*x.^3+5*x;
t6 = 32*x.^6-48*x.^4+18*x.^2-1;
t7 = 64*x.^7-112*x.^5+56*x.^3-7*x;
x = 100./10;
t11 = x;
t21 = 2*x.^2-1;
t31 = 4*x.^3-3*x;
t41 = 8*x.^4-8*x.^2+1;
t51 = 16*x.^5-20*x.^3+5*x;
t61 = 32*x.^6-48*x.^4+18*x.^2-1;
t71 = 64*x.^7-112*x.^5+56*x.^3-7*x;
figure,
semilogx(q,sqrt(t1.^2./(1+t1.^2)),q,sqrt(t2.^2./(1+t2.^2)),q,sqrt(t3.^2./(1+t3.
^2)),q,sqrt(t4.^2./(1+t4.^2)),q,sqrt(t5.^2./(1+t5.^2)),q,sqrt(t6.^2./(1+t6.^2)),q
,sqrt(t7.^2./(1+t7.^2))), grid
h = line([0.1 1000],[1/sqrt(2) 1/sqrt(2)],'LineStyle','-.'), xlim([0.1 1000]);
figure,
semilogx(q,20*log10(sqrt(t1.^2./(1+t1.^2))),q,20*log10(sqrt(t2.^2./(1+t2.^2))
),q,20*log10(sqrt(t3.^2./(1+t3.^2))),q,20*log10(sqrt(t4.^2./(1+t4.^2))),q,20*l
og10(sqrt(t5.^2./(1+t5.^2))),q,20*log10(sqrt(t6.^2./(1+t6.^2))),q,20*log10(sq
rt(t7.^2./(1+t7.^2)))), grid, xlim([0.1 1000]), ylim([-200 0]);
figure,
semilogx(q,sqrt(t1.^2./(ee^2*t11^2+t1.^2)),q,sqrt(t2.^2./(ee^2*t21^2+t2.^2)
),q,sqrt(t3.^2./(ee^2*t31^2+t3.^2)),q,sqrt(t4.^2./(ee^2*t41^2+t4.^2)),q,sqrt(
t5.^2./(ee^2*t51^2+t5.^2)),q,sqrt(t6.^2./(ee^2*t61^2+t6.^2)),q,sqrt(t7.^2./(
ee^2*t71^2+t7.^2))), grid
h = line([0.1 1000],[1/sqrt(2) 1/sqrt(2)],'LineStyle','-.'), xlim([0.1 1000]);
figure,
semilogx(q,20*log10(sqrt(t1.^2./(ee^2*t11^2+t1.^2))),q,20*log10(sqrt(t2.^2.
/(ee^2*t21^2+t2.^2))),q,20*log10(sqrt(t3.^2./(ee^2*t31^2+t3.^2))),q,20*log
10(sqrt(t4.^2./(ee^2*t41^2+t4.^2))),q,20*log10(sqrt(t5.^2./(ee^2*t51^2+t5.
^2))),q,20*log10(sqrt(t6.^2./(ee^2*t61^2+t6.^2))),q,20*log10(sqrt(t7.^2./(ee
^2*t71^2+t7.^2)))), grid, xlim([0.1 1000]), ylim([-200 0]);
6.3 IIR Filters 423

The passband ripple Dp determines the e parameter as shown in Eq. (6.175).


   pffiffiffiffiffiffiffiffiffiffiffiffi
Note that the H jXp  is 1= 1 þ e2 from Eq. (6.174).
!
1  
Dp ¼ 20 log10 pffiffiffiffiffiffiffiffiffiffiffiffi ¼ 10 log10 1 þ e2
1= 1 þ e2 ð6:175Þ
qffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffi
Dp
e¼ 10  110

From the given stopband attenuation in decibel Dst , the required filter order
N can be calculated by using Eq. (6.176). Observe that the TN ð1Þ is 1, according to
the Eq. (6.157).
0 1
sffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffi
1 B 1 C
Dst ¼ 20 log10 2
¼ 20 log10 B
@ rffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffi
 A
C
jH ðjXst Þj
1= 1 þ e TN Xp
2 2 Xst

qffiffiffiffiffiffiffiffiffiffi ð6:176Þ
Dst
cosh1 10 10 1
e2
N
 
cosh1 Xst
Xp

The stable H ðjXÞ filter requires the Laplace transform to choose the proper poles
from the combination. Let’s apply the Laplace transform on the magnitude filter
equation jH ðjXÞj2 as shown in Eq. (6.177).

1
jH ðsÞj2 ¼ H ðsÞH ðsÞ ¼  
Xst
TN2 Xp
1 þ e2
Þ TN2 ð ð6:177Þ
jXst
s

ð Þ 
jX
TN2 sst
¼ Let jX ! s ¼ r þ jX
TN2 ðjXsst Þ þ e2 TN2 Xst
Xp

The poles of Eq. (6.177) can be found as below.


 
TN2 Xst  
Xp 1 jXst
1 þ e 2 jXst  ¼ 0 ! 1 þ
2   TN 2
¼0
TN s e2 TN2 XXstp s
  ð6:178Þ
2 2 jXst 1
 
! 1 þ c TN ¼ 0 where c2 ¼
s e TN XXstp
2 2
424 6 Filter Design

Use the first kind Chebyshev polynomial solution for Type I Chebyshev filter as
Eq. (6.179).
   
Xst p 1 1
¼  sin ð2k  1Þ sinh sinh1
pk 2N N c
   
p 1 1 1
þ j cos ð2k  1Þ cosh sinh for k ¼ 1; 2; . . .; N
2N N c
X
pk ¼      st     
1 1
p
 sin ð2k  1Þ 2N sinh N sinh
1
c
p
þ j cos ð2k  1Þ 2N cosh N1 sinh1 1c
for k ¼ 1; 2; . . .; N
ð6:179Þ

Separate the poles into the left s plane as pLi and right s plane as pRi . Note that
poles on the left s plane provides the stable filter. The left and right of the s plane
can be divided by the real value. Positive real value indicates right s plane and
negative real value specifies left s plane.

pLi 2 left s plane
i ¼ 1; 2; . . .; N
pRi 2 right s plane

Zeros of Eq. (6.177) can be found as below.


jXst   
TN2 s ¼ 0 forjXsst   1 ð6:180Þ

Figure 6.61 demonstrates TN2 ðXÞ distribution and zeros of the function are
located between the –1 and 1. Since the vertexes of the curve touch the zero line in
Fig. 6.61, the zeros are paired with double.

Fig. 6.61 Square of the first


1.8 N=1
kind Chebyshev polynomial 2
TN2 ðXÞ 1.6 3
4
1.4 5
6
1.2 7

1
0.8
0.6
0.4
0.2
0
-0.2
-1 -0.5 0 0.5 1
6.3 IIR Filters 425

Prog. 6.47 MATLAB program for Fig. 6.61.

x = linspace(-2,2,1000);
t1 = (x).^2;
t2 = (2*x.^2-1).^2;
t3 = (4*x.^3-3*x).^2;
t4 = (8*x.^4-8*x.^2+1).^2;
t5 = (16*x.^5-20*x.^3+5*x).^2;
t6 = (32*x.^6-48*x.^4+18*x.^2-1).^2;
t7 = (64*x.^7-112*x.^5+56*x.^3-7*x).^2;
plot(x,t1,x,t2,x,t3,x,t4,x,t5,x,t6,x,t7), grid
line([-2 2],[1 1],'LineStyle','-.')
line([-2 2],[0 0],'LineStyle','-.')
xlim([-2 2]);
ylim([-1.5 12]);
xlabel('\Omega')
ylabel('T^2_N(\Omega)')
axis([-1.23 1.23 -0.25 2.0])
legend('N = 1','2','3','4','5','6','7');

The solution of the Eq. (6.180) is below.


     
cos N cos1 jXsst cos N cos1 jXsst ¼ 0 ð6:181Þ

forfs
jXst or s   jXst g

Using the trigonometric identities, the above equation is organized as below.

1 þ cosð2N cos1 ðjXsst ÞÞ


¼0
   2
cos 2N cos1 jXsst ¼ 1 ¼ cosðð2k  1ÞpÞ for k 2 Z ð6:182Þ
   
2N cos1 jXsst ¼ ð2k  1Þp; cos1 jXsst ¼ ð2k  1Þ 2N
p
 p

s ¼ cos ð2k  1Þ 2N
jXst

The zeros of Eq. (6.177) are derived as Eq. (6.183).

zk ¼ cos jXst
; k ¼ 1; 2; . . .; N ð6:183Þ
ðð2k1Þ2Np Þ
 
Collect poles pLi and zeros ðzk Þ to assemble the transfer function in s domain as
shown in Eq. (6.184).
426 6 Filter Design

Gðs  z1 Þðs  z2 Þ. . .ðs  zN Þ


H ðsÞ ¼   
s  pL1 s  pL2 . . .ðs  pLN Þ ð6:184Þ
b0 sN þ b1 sN1 þ b2 sN2 þ  þ bN2 s1 þ bN1
¼ sN þ a1 sN1 þ a2 sN2 þ  þ aN2 s1 þ aN1

The gain G of the transfer function can be computed as below. Equations (6.177)
and (6.184) produce the equal value for the zero input to calculate the gain G.

Gðz1 Þðz2 Þ. . .ðzN Þ


H ðs ¼ jX ¼ 0Þ ¼  L  L 
p1 p2 . . .ðpLN Þ

1 1
jH ðjX ¼ 0Þj2 ¼  ¼  ¼1
Xst Xst
TN2 Xp TN2 Xp
1 þ e2 1 þ e2
TN2 ðX0st Þ TN2 ð1Þ

    
Gðz1 Þðz2 Þ. . .ðzN Þ ¼ pL1 pL2 . . . pLN

ðpL1 ÞðpL2 Þ...ðpLN Þ ð6:185Þ


G¼ ðz1 Þðz2 Þ...ðzN Þ

Convert back to jX by replacing with s as Eq. (6.186). The filter with rational
function is completed in the linear frequency domain jX .

b0 ðjXÞN þ b1 ðjXÞN1 þ b2 ðjXÞN2 þ    þ bN2 ðjXÞ1 þ bN1


H ðjXÞ ¼
ðjXÞN þ a1 ðjXÞN1 þ a2 ðjXÞN2 þ    þ aN2 ðjXÞ1 þ aN1 ð6:186Þ
GðjXz1 ÞðjXz2 Þ...ðjXzN Þ
¼
ðjXpL1 ÞðjXpL2 Þ...ðjXpLN Þ

The bilinear transformation provides the tool to change the linear frequency
domain into the z domain for discrete-time filter as shown in Eq. (6.187).

ðjXÞN þ b1 ðjXÞN1 þ  þ bN2 ðjXÞ þ bN1   
H ðzÞ ¼ bð0jX N
Þ þ a ðjXÞ N1
þ  þ a ðjXÞ þ a
 ð6:187Þ
1 N2 N1 1z1
jX¼2fs
1 þ z1

The final Type II Chebyshev filter in discrete time domain is Eq. (6.187).
Example 6.20
Design the Table 6.29 IIR filter by using Type II Chebyshev method and bilinear
transformation.
Solution
Use the bilinear transformation to find the frequency specification in X from
Eq. (6.150).
6.3 IIR Filters 427

Table 6.29 Given filter specification


Filter specifications Value
Filter type Low pass filter
Filter realization Type II Chebyshev IIR filter
Filter length N with optimization
Passband frequency (fp) 1000 Hz; xp ¼ p=4
Passband magnitude 1
 
Passband peak-to-peak ripple in decibel ðDp Þ 20 log10 1=p1ffiffiffiffiffiffiffi
ffi ¼ 3:0103dB
1þ1

Stopband frequency (fst) 2000 Hz; xst ¼ p=2


1
Stopband attenuation in decibels Dst 20 log10 0:1 ¼ 20 dB
Sampling frequency (fs) 8000 Hz

p
Xp ¼ 2fs tan ¼ 6627:4 rad=s
8
p
Xst ¼ 2fs tan ¼ 16000rad=s
4

Compute the e value by using the Eq. (6.175).


qffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffi pffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffi
Dp
e¼ 10 10  1 ¼ 10 10  1 ¼ 1
3:0103

Estimate the proper filter order by using the Eq. (6.176).


rffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffi
 D  rffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffi
 ffi
cosh1 10 10  1 =e2 cosh1 1010  1 =12
st 20

N
  ¼   ¼ 1:9549 ! 2; even
cosh1 XXstp cosh1 16;000
6627:4

Derive the whole poles to find left s plane poles from Eq. (6.179).

X
pk ¼      st     
 sin ð2k  p
1Þ 2N sinh 1
N sinh1 1c p
þ j cos ð2k  1Þ 2N cosh N1 sinh1 1c

1
where k ¼ 1; 2 and c2 ¼  
e2 TN2 XXstp

pLi 2 left s plane
i ¼ 1; 2
pRi 2 right s plane
428 6 Filter Design

pk ¼ 4656:4  j5113:8; 4656:4 þ j5113:8;


 4656:4  j5113:8; 4656:4 þ j5113:8
pLk ¼ 4656:4  j5113:8; 4656:4 þ j5113:8

Calculate the zeros by using Eq. (6.183).

jXst
zk ¼  p
 ; k ¼ 1; 2; . . .; N
cos ð2k  1Þ 2N

zk ¼ j22627:41; j22627:41

Obtain the gain G from Eq. (6.185).


  
pL1 pL2 ð4656:4 þ j5113:8Þð4656:4  j5113:8Þ
G¼ ¼ ¼ 0:09343
ðz1 Þðz2 Þ ðj22627:41Þðj22627:41Þ

Follow Eq. (6.186) to build the filter equation in s domain based on the pLi , zk ,
and G.

0:09343ðs þ j22627:41Þðs  j22627:41Þ


H ðsÞ ¼
ðs þ 4656:4 þ j5113:8Þðs þ 4656:4  j5113:8Þ

0:09343s2 þ 47833766:89
H ðsÞ ¼
s2 þ 9312:8s þ 47833011:4

Apply the bilinear transformation as below.



0:09343ðjX þ j22627:41ÞðjX  j22627:41Þ 
H ðzÞ ¼  
ðjX þ 4656:4 þ j5113:8ÞðjX þ 4656:4  j5113:8ÞjX¼2fs 1z1
1 þ z1

The final Type II Chebyshev filter in discrete time domain is below.

0:15845 þ 0:10563z1 þ 0:15845z2


H ðzÞ ¼
1  0:91939z1 þ 0:34191z2

Figure 6.62 shows the pole zero plot of the design filter. Two poles are located
within the unit circle and two zeros are placed on unit circle.
6.3 IIR Filters 429

Prog. 6.48 MATLAB program for Figs. 6.62 and 6.63.

syms s z;
pb = linspace(0,1000,501);
sb = linspace(2000,4000,2001);
hs = 0.0934253837435988*(s+22627.41j)*(s-
22627.41j)/((s+4656.4+5113.8j)*(s+4656.4-5113.8j));
hz = subs(hs,s,16000*(z-1)/(z+1));
[num1,den1] = numden(hs);
num2 = collect(expand(num1));
den2 = collect(expand(den1));
num3 = sym2poly(num2);
den3 = sym2poly(den2);
num4 = num3./(den3(1));
den4 = den3./(den3(1));
[znum1,zden1] = numden(hz);
znum2 = collect(expand(znum1));
zden2 = collect(expand(zden1));
znum3 = sym2poly(znum2);
zden3 = sym2poly(zden2);
znum4 = znum3./(zden3(1));
zden4 = zden3./(zden3(1));
[h,w] = freqz(znum4,zden4,4001,8000);
hpb = freqz(znum4,zden4,pb,8000);
hsb = freqz(znum4,zden4,sb,8000);

figure,
zplane(znum4,zden4)
figure,
plot(w,abs(h),pb,abs(hpb),'.-',sb,abs(hsb),'.-'), grid
line([0 4000],[0.1 0.1])
ylim([0 1])
legend('Response','Passband','Stopband')
ylabel('|H(e^{j\omega})|')
xlabel('Frequency (Hz)')
figure
plot(w,db(h),pb, db(hpb),'.-',sb,db(hsb),'.-'), grid
line([0 4000],[-20 -20])
legend('Response','Passband','Stopband')
ylabel('20log_{10}|H(e^{j\omega})| (dB)')
xlabel('Frequency (Hz)')
430 6 Filter Design

1
0.8
0.6

Imaginary Part
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1

-1 -0.5 0 0.5 1
Real Part

Fig. 6.62 Pole zero plot of designed Type II Chebyshev filter for Table 6.29

1 10
Response Response
0.9 Passband 0 Passband
Stopband Stopband
0.8 -10
0.7 -20
0.6 -30
0.5 -40
0.4 -50
0.3 -60
0.2 -70
0.1 -80
0 -90
0 500 1000 1500 2000 2500 3000 3500 4000 0 500 1000 1500 2000 2500 3000 3500 4000
Frequency (Hz) Frequency (Hz)

Fig. 6.63 Frequency response of designed Type II Chebyshev filter for Table 6.29

Figure 6.63 represents the frequency response of the filter. The passband and
stopband satisfy the Table 6.29 specification. Note that the horizontal line in the
figures denote the stopband attenuation requirement. ∎

Elliptic filter
The elliptic filter [7] also utilizes the rational function with special polynomial as
shown in Eq. (6.188). As the e2 R2N ðn; XÞ increases exponentially, the filter mag-
nitude decreases significantly for LPF property.
6.3 IIR Filters 431

jH ðjXÞj2 ¼ H ðjXÞH  ðjXÞ ¼ H ðjXÞH ðjXÞ ¼ 1 þ e2 R12 ðn;XÞ ð6:188Þ


N


e : ripple factor
where
n : selectivity factor ðn

The special function is the elliptic rational function RN ðn; XÞ [19]. Below show
the functions up to 4th order.

R1 ðn; XÞ ¼ X

ðt þ 1ÞX2  1
R2 ðn; XÞ ¼
ðt  1ÞX2 þ 1
qffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffi
where t ¼ 1  ð1=n2 Þ
  
1  x2p X2  x2z
R3 ðn; XÞ ¼ X   
1  x2z X2  x2p
8 pffiffiffi
>
> x 2
¼ p 2n2 G
ffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffi
ffi pffiffiffiffi
>
> p
8n2 ðn2 þ 1Þ þ 12Gn2 G3  G3
<
x2z ¼ nx2
2
where
>
> qffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffi2ffi
>
p
>
:   
G ¼ 4n2 þ 4n2 n2  1 3
pffi 2 pffi
ðt þ 1Þð1 þ t Þ X4 2ð1 þ tÞð1 þ t ÞX2 þ 1
R4 ðn; XÞ ¼ pffi 2 4 pffi 2 ð6:189Þ
ðt þ 1Þð1 t Þ X 2ð1 þ tÞð1 t ÞX þ 1

qffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffi
where t ¼ 1  ð1=n2 Þ

The properties of the elliptic rational function are below.

RM ðRN ðn; nÞ; RN ðn; XÞÞ ¼ RM N ðn; XÞ

R2N ðn; XÞ  1 for jXj  1 ð6:190Þ


432 6 Filter Design

12
N=1
2
10 3
4

-2
0 0.2 0.4 0.6 0.8 1 1.2

Fig. 6.64 The elliptic rational function RN ðn; XÞ

R2N ðn; 1Þ ¼ 1 ð6:191Þ



6¼ 0 for even N
R2N ðn; 0Þ ð6:192Þ
¼ 0 for odd N

R2N ðn; XÞ ¼ R2N ðn; XÞ ð6:193Þ



RN ðn; XÞ for N even
RN ðn; XÞ ¼
RN ðn; XÞ for N odd

lim RN ðn; XÞ ¼ TN ðXÞ


n!1

The R2N ðn; XÞ presents limited magnitude one for less than one X in absolute
according to the property in Eq. (6.190). Also, the R2N ðn; XÞ shows the even
symmetricity over the X axis from Eq. (6.193). The initial value of the R2N ðn; XÞ
depends on the order parity but the R2N ðn; 1Þ value is fixed as one for all orders.
Figure 6.64 illustrates the RN ðn; XÞ up to 4th order.
6.3 IIR Filters 433

Prog. 6.49 MATLAB program for Fig. 6.64.

om = linspace(0,1.2,200);
k = 1.5;
t = sqrt(1-(1/k^2));
G = sqrt(4*k^2+(4*k^2*(k^2-1))^(2/3));
xp2 = 2*k^2*sqrt(G)/(sqrt(8*k^2*(k^2+1)+12*G*k^2-G^3)-sqrt(G^3));
xz2 = k^2/xp2;
R1 = om;
R2 = ((t+1)*om.^2-1)./((t-1)*om.^2+1);
R3 = om.*(1-xp2).*(om.^2-xz2)./((1-xz2).*(om.^2-xp2));
R4 = ((t+1)*(1+sqrt(t))^2*om.^4-2*(1+t)*(1+sqrt(t))*om.^2+1)./((t+1)*(1-
sqrt(t))^2*om.^4-2*(1+t)*(1-sqrt(t))*om.^2+1);

figure,
plot(om,R1,om,R2,om,R3,om,R4), grid
h = line([0 1.2],[1 1],'LineStyle','-.');
h = line([0 1.2],[-1 -1],'LineStyle','-.');
xlabel('\Omega')
ylabel('R_N(\xi,\Omega) where \xi=1.5')
legend('N = 1','2','3','4');

The RN ðn; XÞ presents the fluctuation with limited magnitude up to one X and
rapidly increasing after the range. The higher order illustrates the faster monotonic
growing in Fig. 6.64. By applying the function to Eq. (6.188), the filter response can
be calculated and depicted as Fig. 6.65. The response is similar to the Type I
Chebyshev filter; however, we can observe the fluctuation in stopband and steeper
decreasing in the transition band. In overall, the frequency response represents the
LPF with passband frequency Xp ¼ 1: Note that the Xp and Xh are equal in Fig. 6.65
because of unit e . The order N illustrates the steepness of the magnitude transition. The
higher N value shows the steeper response in the filter as shown in Fig. 6.65.

1 0
=1.5

N=1
0.9 2
3 -20
0.8 4
=1.5

)| =1

0.7
-40
0.6
)| =1

0.5 -60
20log10|H(j

0.4
-80
0.3
|H(j

0.2 N=1
-100 2
0.1 3
4
0 -120
-1 0 1 2 3 -1 0 1 2 3
10 10 10 10 10 10 10 10 10 10

Fig. 6.65 Frequency response of linear frequency model from Eq. (6.188) with e ¼ 1 and n ¼ 1:5
434 6 Filter Design

Prog. 6.50 MATLAB program for Fig. 6.65.


om = linspace(0.1,1000,100000);
k = 1.5; %Xi
ee = 1; %Epsilon
t = sqrt(1-(1/k^2));
G = sqrt(4*k^2+(4*k^2*(k^2-1))^(2/3));
xp2 = 2*k^2*sqrt(G)/(sqrt(8*k^2*(k^2+1)+12*G*k^2-G^3)-sqrt(G^3));
xz2 = k^2/xp2;
R1 = om;
R2 = ((t+1)*om.^2-1)./((t-1)*om.^2+1);
R3 = om.*(1-xp2).*(om.^2-xz2)./((1-xz2).*(om.^2-xp2));
R4 = ((t+1)*(1+sqrt(t))^2*om.^4-2*(1+t)*(1+sqrt(t))*om.^2+1)./((t+1)*(1-
sqrt(t))^2*om.^4-2*(1+t)*(1-sqrt(t))*om.^2+1);

figure,
semilogx(om,1./sqrt(1+ee^2*R1.^2),om,1./sqrt(1+ee^2*R2.^2),om,1./sqrt(1
+ee^2*R3.^2),om,1./sqrt(1+ee^2*R4.^2)), grid
h = line([0.1 1000],[1/sqrt(2) 1/sqrt(2)],'LineStyle','-.');
xlim([.1 1000]);
xlabel('\Omega')
ylabel('|H(j\Omega)| \epsilon=1 \xi=1.5')
legend('N = 1','2','3','4')
figure,
semilogx(om,-10*log10(1+ee^2*R1.^2),om,-10*log10(1+ee^2*R2.^2),om,-
10*log10(1+ee^2*R3.^2),om,-10*log10(1+ee^2*R4.^2)), grid
xlim([0.1 1000]);
xlabel('\Omega')
ylabel('20log_{10}|H(j\Omega)| \epsilon=1 \xi=1.5')
legend('N = 1','2','3','4')

From the given passband peak-to-peak ripple Dp , the e value can be determined
by Eq. (6.194).
!
1  
Dp ¼ 20 log10 pffiffiffiffiffiffiffiffiffiffiffiffi ¼ 10 log10 1 þ e2 where R2N ðn; 1Þ ¼ 1
1= 1 þ e2 ð6:194Þ
qffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffi
Dp
e¼ 10  1
10

Expanding the frequency axis relocates the passband frequency to any frequency
by scaling as shown in Eq. (6.195). Figure 6.66 demonstrates the LPF with
3.0103 dB Dp , 1.5 n, 66.6667 rad/s Xp , and 100 rad/s Xst .
6.3 IIR Filters 435

X
jH ðjXÞj2 ¼ 1 þ e2 R21 n;n X where n Xstp ¼ 1 ð6:195Þ
Nð Xst Þ

Prog. 6.51 MATLAB program for Fig. 6.66.

x = linspace(0.1,1000,100000);
k = 1.5; %Xi
om = x*1.5/100;
ee = 1; %Epsilon
t = sqrt(1-(1/k^2));
G = sqrt(4*k^2+(4*k^2*(k^2-1))^(2/3));
xp2 = 2*k^2*sqrt(G)/(sqrt(8*k^2*(k^2+1)+12*G*k^2-G^3)-sqrt(G^3));
xz2 = k^2/xp2;
R1 = om;
R2 = ((t+1)*om.^2-1)./((t-1)*om.^2+1);
R3 = om.*(1-xp2).*(om.^2-xz2)./((1-xz2).*(om.^2-xp2));
R4 = ((t+1)*(1+sqrt(t))^2*om.^4-2*(1+t)*(1+sqrt(t))*om.^2+1)./((t+1)*(1-
sqrt(t))^2*om.^4-2*(1+t)*(1-sqrt(t))*om.^2+1);

figure,
semilogx(x,1./sqrt(1+ee^2*R1.^2),x,1./sqrt(1+ee^2*R2.^2),x,1./sqrt(1+ee^2*
R3.^2),x,1./sqrt(1+ee^2*R4.^2)), grid
xlim([.1 1000]);
aa = axis;
h = line([0.1 1000],[1/sqrt(2) 1/sqrt(2)],'LineStyle','-.');
h = line([100/1.5 100/1.5],[aa(3) aa(4)],'LineStyle','-.');
xlabel('\Omega')
ylabel('|H(j\Omega)| \epsilon=1 \xi=1.5')
legend('N = 1','2','3','4');

figure,
semilogx(x,-10*log10(1+ee^2*R1.^2),x,-10*log10(1+ee^2*R2.^2),x,-
10*log10(1+ee^2*R3.^2),x,-10*log10(1+ee^2*R4.^2)), grid
xlim([0.1 1000]);
xlabel('\Omega')
ylabel('20log_{10}|H(j\Omega)| \epsilon=1 \xi=1.5')
h = line([100/1.5 100/1.5],[aa(3) aa(4)],'LineStyle','-.');
legend('N = 1','2','3','4')

In order to compute stopband attenuation, the discrimination factor is defined as


Eq. (6.196). The discrimination factor indicates the minimum value of the RN ðn; XÞ
magnitude for jXj
n
1:
436 6 Filter Design

1 0
0.9
-20

=1.5
0.8
=1.5

0.7 -40

)| =1
0.6 -60
)| =1

0.5 66.6667 66.6667


-80

20log |H(j
0.4

10
|H(j

0.3 -100
0.2 N=1 N=1
2 -120 2
0.1 3 3
4 4
0 -140
10
-1
100 101 10
2
10 3 10
-1
100 101 10
2
10 3

Fig. 6.66 Frequency response of Eq. (6.195) with Dp ¼ 3:0103 dB, n = 1.5, Xp = 66.6667 rad/
s, and Xst = 100 rad/s

LN ðnÞ ¼ RN ðn; nÞ ð6:196Þ

Below shows the factor up to 4th order.

L1 ðnÞ ¼ n
 qffiffiffiffiffiffiffiffiffiffiffiffiffi2
L2 ðnÞ ¼ n þ n2  1

!2
1  x2p
L3 ðnÞ ¼ n 3
n2  x2p
8 pffiffiffi
> 2n2 G
< x2p ¼ pffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffi
ffi pffiffiffiffi
8n2 ðn2 þ 1Þ þ 12Gn2 G3  G3
where qffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffi
: G ¼ 4n2 þ 4n2 n2  123
>

pffiffiffi  1  4  pffiffiffiffiffiffiffiffiffiffiffiffiffi2
L4 ð n Þ ¼ n þ n2  1 4 n þ n2  1 ð6:197Þ
6.3 IIR Filters 437

Prog. 6.52 MATLAB program for Fig. 6.67.

k = linspace(1.001,100,1000);
G = sqrt(4*k.^2+(4*k.^2.*(k.^2-1)).^(2/3));
xp2 = 2.*k.^2.*sqrt(G)./(sqrt(8.*k.^2.*(k.^2+1)+12.*G.*k.^2-G.^3)-
sqrt(G.^3));

L1 = k;
L2 = (k+sqrt(k.^2-1)).^2;
L3 = k.^3.*((1-xp2)./(k.^2-xp2)).^2;
L4 = (sqrt(k)+(k.^2-1).^(1/4)).^4.*((k+sqrt(k.^2-1)).^2);
semilogy(k,L1,k,L2,k,L3,k,L4), grid
legend('N = 1','2','3','4');
xlabel('\xi')
ylabel('L_N(\xi)')

From given e , the selective factor n and discrimination factor LN ðnÞ determine
the stopband attenuation as shown in Eq. (6.198). Also, we can compute the LN ðnÞ
to achieve the target stopband attenuation as shown in Eq. (6.199).
0 1
sffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffi
1 B
1 C
Dst ¼ 20 log10 2
¼ 20 log10 B
rffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffi
@  A
C
jH ðjXst Þj ð6:198Þ
1= 1 þ e2 R2N n; n Xstst X

   
¼ 10 log10 1 þ e2 R2N ðn; nÞ ¼ 10 log10 1 þ e2 L2N ðnÞ

10
10
N=1
2
3
8
10 4

6
10
L ( )
N

4
10

2
10

0
10
0 10 20 30 40 50 60 70 80 90 100

Fig. 6.67 Discrimination factor up to 4th order in terms of selectivity factor n


438 6 Filter Design

pffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffi
Dst
10 10  1
LN ðnÞ ¼ ð6:199Þ
e

For verification purpose, Eq. (6.200) is illustrated at Fig. 6.68 for designated
stopband attenuations. Equation (6.201) calculates the selective factor n based on
the discrimination factor L2 ðnÞ:

jH ðjXÞj2 ¼ 1 þ e2 R12 ð6:200Þ


2 ðn;nXn Þ
 qffiffiffiffiffiffiffiffiffiffiffiffiffi2 pffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffi
Dst
10 10  1
L2 ðnÞ ¼ n þ n2  1 ¼ for Dst ¼ 10; 20; 30; . . .; 100 ð6:201Þ
e

Note that the increased stopband attenuation provides the higher stopband fre-
quency because of Eqs. (6.200) and (6.201). Figure 6.68 well represents the
stopband attenuation Dst for desired value. Once the response passes the stopband
frequency, the magnitude draws the valley which asymptotically converges to the
designed stopband attenuation.

0
-10

-20
-20
)| (dB) =1

-30

-40
-40
-50

-60
-60
-70
20log |H(j

-80
10

-80
-90

-100
-100

-120
-1 0 1 2 3
10 10 10 10 10

Fig. 6.68 Frequency response of Eq. (6.200) for designated stopband attenuation Dst and
corresponding selective factor n
6.3 IIR Filters 439

Prog. 6.53 MATLAB program for Fig. 6.68.

syms ep;
dst = [10:10:100];
om = linspace(0.1,1000,10000);
ee = 1;
lne = sqrt(10.^(dst/10)-1)./ee;
l2e = (ep+sqrt(ep^2-1))^2;
out = [];
for kk = 1:10
temp = solve(l2e==lne(kk));
out = [out eval(temp)];
end
t = sqrt(1-(1./out.^2));
R2 = ((t'+1)*om.^2-1)./((t'-1)*om.^2+1);
semilogx(om,-10*log10(1+ee^2*R2.^2)),grid
ylim([-120 0])
xlabel('\Omega')
ylabel('20log_{10}|H(j\Omega)| (dB) \epsilon=1')
for kk=1:10
r2 = ((t(kk)+1)*out(kk).^2-1)./((t(kk)-1)*out(kk).^2+1);
line([out(kk) out(kk)],[-120 -10*log10(1+ee^2*r2.^2)],'LineStyle','-.');
line([out(kk) 1000],[-10*log10(1+ee^2*r2.^2) -
10*log10(1+ee^2*r2.^2)],'LineStyle','-.');
str = num2str(-dst(kk));
text(500,-dst(kk)+3,str);
end

After we determine all parameters of the elliptic filter for Eq. (6.202), the poles
and zeros of the transfer function should be derived for H ðjXÞ: The mathematical
solution for jH ðjXÞj2 with elliptic rational function is beyond this book scope.
Instead. we apply the numerical approach to find the numerator and denominator
roots of jH ðjXÞj2 for corresponding zeros and poles, respectively. Below demon-
strates the procedure to build the H ðjXÞ from jH ðjXÞj2

jH ðjXÞj2 ¼ 1 þ e2 R21 n;n X ð6:202Þ


Nð Xst Þ

Let jX ! s ¼ r þ jX
440 6 Filter Design

1
jH ðsÞj2 ¼ H ðsÞH ðsÞ ¼  
1 þ e2 R2N n; n jXsst ð6:203Þ
b0 s2N þ b1 s2N1 þ b2 s2N2 þ  þ b2N1 s1 þ b2N
¼ s2N þ a1 s2N1 þ a2 s2N2 þ  þ a2N1 s1 þ a2N

Numerically find the solutions of numerator and denominator for zeros and
poles. The factorized polynomials are reconstructed as below.

ðsz1 Þðsz2 Þ...ðsz2N1 Þðsz2N Þ


jH ðsÞj2 ¼ H ðsÞH ðsÞ ¼ Kðsp 1 Þðsp2 Þ...ðsp2N1 Þðsp2N Þ
ð6:204Þ

Separate the all poles into the left and right s plane as below. Zeros can be
chosen with various combinations. If we prefer to construct minimum phase filter,
select the all zeros from unit circle inside in z domain which corresponds to the left
s plane area.

pLi 2 s plane left
i ¼ 1; 2; . . .; N
pRi 2 s plane right

zi 2 s plane left; for i ¼ 1; 2; . . .; N

Based on the left s plane poles and zeros, the transfer function is assembled as
below. Note that G is the zero-input gain.

Gðs  z1 Þðs  z2 Þ. . .ðs  zN Þ


H ðsÞ ¼   
s  pL1 s  pL2 . . .ðs  pLN Þ
ð6:205Þ
b0 sN þ b1 sN1 þ b2 sN2 þ    þ bN2 s1 þ bN
¼ N
s þ a1 sN1 þ a2 sN2 þ    þ aN2 s1 þ aN

Convert back to jX by replacing with s as below. The filter with rational function
is completed in the linear frequency domain jX .

b0 ðjXÞN þ b1 ðjXÞN1 þ b2 ðjXÞN2 þ    þ bN2 ðjXÞ1 þ bN1


H ðjXÞ ¼
ðjXÞN þ a1 ðjXÞN1 þ a2 ðjXÞN2 þ    þ aN2 ðjXÞ1 þ aN1
ð6:206Þ
GðjX  z1 ÞðjX  z2 Þ. . .ðjX  zN Þ
¼  
jX  pL1 jX  pL2 . . .ðjX  pLN Þ
6.3 IIR Filters 441

Table 6.30 Given filter specification


Filter specifications Value
Filter type Low pass filter
Filter realization Elliptic IIR filter
Filter length N with optimization
Passband frequency (fp) 1000 Hz; xp ¼ p=4
Passband magnitude 1
 
Passband peak-to-peak ripple in decibel ðDp Þ 20 log10 1=p1ffiffiffiffiffiffiffi
ffi ¼ 3:0103dB
1þ1

Stopband frequency (fst) 2000 Hz; xst ¼ p=2


1
Stopband attenuation in decibels Dst 20 log10 0:1 ¼ 20dB
Sampling frequency (fs) 8000 Hz

The bilinear transformation provides the tool to change the linear frequency
domain into the z domain for discrete-time filter as shown in Eq. (6.207).

ðjXÞN þ b1 ðjXÞN1 þ  þ bN2 ðjXÞ þ bN1   
H ðzÞ ¼ bð0jX N
Þ þ a ðjXÞ N1
þ  þ a ðjXÞ þ a
 ð6:207Þ
1 N2 1z1
N1 jX¼2fs
1 þ z1

The final elliptic filter in discrete time domain is Eq. (6.207).


Example 6.21
Design the Table 6.30 IIR filter by using elliptic method and bilinear
transformation.
Solution
Use the bilinear transformation to find the frequency specification in X from
Eq. (6.150).
p
Xp ¼ 2fs tan ¼ 6627:4rad=s
8
p
Xst ¼ 2fs tan ¼ 16000rad=s
4

Compute the e value by using the Eq. (6.194).


qffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffi pffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffi
Dp
e¼ 10 10  1 ¼ 10 10  1 ¼ 1
3:0103
442 6 Filter Design

Let the N = 2. Dst and Xst are controlled by n.

Xst 16000 Xp
n¼ ¼ ¼ 2:4142 *n ¼1
Xp 6627:4 Xst

Using Eq. (6.198), compute Dst as below.


 
Dst ¼ 10 log10 1 þ e2 L2N ðnÞ
 qffiffiffiffiffiffiffiffiffiffiffiffiffi4 !  qffiffiffiffiffiffiffiffiffiffiffiffiffi2
¼ 10 log10 1 þ e n þ n  1
2 2
where L2 ðnÞ ¼ n þ n2  1

Place the parameter values into the above equation as below. The calculated Dst
is greater than the specification; therefore, we properly selected the order.
  pffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffi4 
10 log10 1 þ 12 2:4142 þ 2:41422  1 ¼ 26:5635 dB [ 20 dB ! O.K.

The second order elliptic rational function R2 ðn; XÞ is below.


qffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffi
ðt þ 1ÞX2  1
R2 ðn; XÞ ¼ where t ¼ 1  ð1=n2 Þ
ðt  1ÞX2 þ 1

The t value is below.


pffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffi
t¼ 1  ð1=2:41422 Þ ¼ 0:9102

Build the squared magnitude transfer function with parameters and elliptic
rational function as below.

1
jH ðsÞj2 ¼ H ðsÞH ðsÞ ¼  
1 þ e2 R22 n; n jXsst
1
¼  2
ð0:9102 þ 1ÞðnjXsst Þ 1
2

1 þ e2
ð0:91021ÞðnjXsst Þ þ 1
2

0:00221s4 þ 2157165:10916s2 þ 527558383707008


¼
s4 þ 48043766:35091s2 þ 1055116767414020
6.3 IIR Filters 443

Numerically compute the poles and zeros as below.

pk ¼ 2056:77877  j5315:28194; 2056:77877 þ j5315:28194;


 2056:77877 þ j5315:28194; 2056:77877  j5315:28194

zk ¼ 518:39561  j22097:85371; 518:39561 þ j22097:85371;


 518:39561 þ j22097:85371; 518:39561  j22097:85371

Select poles and zeros for stable and minimum phase filter. The selection means
that the filter only utilizes the poles and zeros from left s plane.

Gðs  z1 Þðs  z2 Þ. . .ðs  zN Þ


H ðsÞ ¼   
s  pL1 s  pL2 . . .ðs  pLN Þ
Gðs þ 518:39561  j22097:85371Þðs þ 518:39561 þ j22097:85371Þ
¼
ðs þ 2056:77877  j5315:28194Þðs þ 2056:77877 þ j5315:28194Þ

Find zero-input gain G as below.

1 1
H ðs ¼ 0Þ ¼ pffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffi ¼ pffiffiffi
1 þ e2 R22 ðn; 0Þ 2
 
ðt þ 1Þ02  1

wherejR2 ðn; 0Þj ¼  ¼1
ðt  1Þ02 þ 1

Gð518:39561  j22097:85371Þð518:39561 þ j22097:85371Þ 1


H ð s ¼ 0Þ ¼ ¼ pffiffiffi
ð2056:77877  j5315:28194Þð2056:77877 þ j5315:28194Þ 2

G ¼ 0:04701

The filter in s domain is below.

0:04701s2 þ 48:74022s þ 22968639:16077


H ðsÞ ¼
s2 þ 4113:55754s þ 32482561:01041
444 6 Filter Design

Convert back to jX by replacing with s.

0:04701ðjXÞ2 þ 48:74022jX þ 22968639:16077


H ðjXÞ ¼
ðjXÞ2 þ 4113:55754jX þ 32482561:01041

Apply the bilinear transformation as below.



0:04701ðjXÞ2 þ 48:74022jX þ 22968639:16077
H ðzÞ ¼   
ðjXÞ2 þ 4113:55754jX þ 32482561:01041  jX¼2fs 1z1
1 þ z1

The final elliptic filter in discrete time domain is below.

0:10100 þ 0:06172z1 þ 0:09659z2


H ðzÞ ¼
1  1:26174z1 þ 0:62847z2

Figure 6.69 shows the pole zero plot of the design filter. Two poles are located
within the unit circle and two zeros are placed nearby unit circle.

1
0.8
0.6
0.4
Imaginary Part

0.2
0
-0.2
-0.4
-0.6
-0.8
-1

-1 -0.5 0 0.5 1
Real Part

Fig. 6.69 Pole zero plot of designed elliptic filter for Table 6.30
6.3 IIR Filters 445

Prog. 6.54 MATLAB program for Figs. 6.69 and 6.70.


syms z;
pb = linspace(0,1000,501);
sb = linspace(2000,4000,2001);
hz = (0.10100+0.06172*z^(-1)+0.09659*z^(-2))/(1-1.26174*z^(-
1)+0.62847*z^(-2));
[znum1,zden1] = numden(hz);
znum2 = collect(expand(znum1));
zden2 = collect(expand(zden1));
znum3 = sym2poly(znum2);
zden3 = sym2poly(zden2);
znum4 = znum3./(zden3(1));
zden4 = zden3./(zden3(1));
[h,w] = freqz(znum4,zden4,4001,8000);
hpb = freqz(znum4,zden4,pb,8000);
hsb = freqz(znum4,zden4,sb,8000);

figure,
zplane(znum4,zden4)
figure,
plot(w,abs(h),pb,abs(hpb),'.-',sb,abs(hsb),'.-'), grid
line([0 4000],[0.1 0.1])
ylim([0 1])
legend('Response','Passband','Stopband')
ylabel('|H(e^{j\omega})|')
xlabel('Frequency (Hz)')
figure,
plot(w,db(h),pb, db(hpb),'.-',sb,db(hsb),'.-'), grid
line([0 4000],[-20 -20])
legend('Response','Passband','Stopband')
ylabel('20log_{10}|H(e^{j\omega})| (dB)')
xlabel('Frequency (Hz)')

Figure 6.70 represents the frequency response of the filter. The passband and
stopband satisfy the Table 6.30 specification. Note that the horizontal line in the
figures denote the stopband attenuation requirement.

446 6 Filter Design

1 0
Response Response
0.9 Passband Passband
Stopband -10 Stopband
0.8

20log |H(e j )| (dB)


0.7
-20
)|

0.6
j
|H(e

0.5 -30
0.4

10
-40
0.3

0.2
-50
0.1

0 -60
0 500 1000 1500 2000 2500 3000 3500 4000 0 500 1000 1500 2000 2500 3000 3500 4000

Frequency (Hz) Frequency (Hz)

Fig. 6.70 Frequency response of designed elliptic filter for Table 6.30

Parametric methods
The parametric methods design the filter based on the filter models with parameters.
Therefore, we have to estimate model as well as parameters in the design procedure.
The conventional filter models [20] are below.
Moving average (MA) model:

y½n ¼ b0 x½n þ    þ bM1 x½n  ðM  1Þ þ bM x½n  M  ð6:208Þ

Corresponding frequency response:

H ðejx Þ ¼ b0 þ    þ bM1 ejxðM1Þ þ bM ejxM ð6:209Þ

Corresponding transfer function:

H ðzÞ ¼ b0 þ    þ bM1 zðM1Þ þ bM zM ð6:210Þ

Autoregressive (AR) model:

y½n þ a1 y½n  1 þ    þ aN y½n  N  ¼ b0 x½n ð6:211Þ

Corresponding frequency response:

H ðejx Þ ¼ 1 þ a1 ejx þb0 þ aN ejxN ð6:212Þ

Corresponding transfer function:

H ðzÞ ¼ 1 þ a1 z1 þb0 þ aN zN ð6:213Þ


6.3 IIR Filters 447

Autoregressive moving average (ARMA) model:

y ½ n þ a1 y ½ n  1 þ    þ aN y ½ n  N 
ð6:214Þ
¼ b0 x½n þ    þ bM1 x½n  ðM  1Þ þ bM x½n  M 

Corresponding frequency response:


jxðM1Þ jxM
H ðejx Þ ¼ b0 þ 1þþab1M1 e þ bM e
ejx þ  þ aN ejxN
ð6:215Þ

Corresponding transfer function:


ðM1Þ M
H ðzÞ ¼ b0 þ1þþa1bzM1 z þ bM z
1 þ  þ a zN
N
ð6:216Þ

The filter model is selected by understanding the desired frequency response


profile. The MA filter model uses the zeros at z domain and the AR filter model
utilizes the poles at z domain. The ARMA filter model employs the zeros and poles
at z domain. The zeros close to the unit circle provide the valley shape distribution
and the poles nearby the unit circle generate the peaky style response in frequency
domain. Note that cluster of poles or zeros could present the flat with slight fluc-
tuation response. Once we choose the filter model, the filter order and coefficients
are estimated by the mathematical algorithm. The estimation process requires the
statistical signal processing which regards signals as stochastic processes. The
statistical signal processing is beyond this book scope; hence, following algorithms
only imitate the algorithm for understanding the basic idea only. Note that the
statistical signal processing performs the expectation, (auto)covariance, etc. oper-
ations based on the stationary white noise.
AR filter estimation (Yule-walker method style) - Approximated
Again, the following AR filter estimation algorithm is not precise as Yule-walker
method since we avoid using the techniques from statistical signal processing. The
reader can find the exact spectral estimation algorithms on the textbook [20–22].
Only grab the fundamental idea of the algorithm. Below is the conventional AR
filter model which is identical to Eq. (6.211).

y½n þ a1 y½n  1 þ    þ aN y½n  N  ¼ b0 x½n ð6:217Þ

By placing the impulse signal into the input x[n], we can find the impulse
response as below

h½n þ a1 h½n  1 þ    þ aN h½n  N  ¼ b0 d½n ð6:218Þ

Let’s design the 2nd order AR filter as below. For simplicity, we assume that the
order is estimated by another algorithm.
448 6 Filter Design

y½n þ a1 y½n  1 þ a2 y½n  2 ¼ b0 x½n ð6:219Þ

The a1 ; a2 ; and b0 are required to be estimated. The given impulse signal delivers
the impulse response as below.

h½0 þ a1 h½1 þ a2 h½2 ¼ b0 d½0 ð6:220Þ

h½1 þ a1 h½0 þ a2 h½1 ¼ b0 d½1

h½2 þ a1 h½1 þ a2 h½0 ¼ b0 d½2

h½3 þ a1 h½2 þ a2 h½1 ¼ b0 d½3

h½4 þ a1 h½3 þ a2 h½2 ¼ b0 d½4

...

The matrix representation is below for Eq. (6.220). Note that the causal filter
shows the zero h½n for negative n.
2 3
h½ 0 0 0
2 3
6 h½ 1 h½0 0 7 b0
6 72 3
6 h½ 2 h½1 h½ 0 7 1 607
6 h½ 3 h½2 h½ 1 7 6 7
6 74 a1 5 ¼ 6 0 7 ð6:221Þ
6 h½ 4 h½3 h½ 2 7 6 .. 7
6 7 a2 4 . 5
6 .. .. .. 7
4 . . . 5 0
h½L  1 h½ L  2 h½L  3

Segments the matrix as below.

ð6:222Þ

Rearrange the matrix as below.


6.3 IIR Filters 449

2 3 2 3 2 3
h½ 1 h½ 0 0 0
6 h½ 2 7 6 h½ 1 h½ 0 7 6 7
6 7 6 7  6 0 7
6 h½ 3 7 6 h½ 2 h½ 1 7 a1 6 0 7
6 7 6 7 6 7
6 h½ 4 7þ6 h½ 3 h½ 2 7 a2 ¼ 6 0 7 ð6:223Þ
6 7 6 7 6 .. 7
6 .. 7 4 .. .. 5 4 5
4 . 5 . . .
h½L  1 h½ L  2 h½L  3 0

Continuously organize the matrix as below.


2 3 2 3
h½ 0 0 h½ 1
6 h½ 1 h½0 7 6 h½ 2 7
6 7  6 7
6 h½ 2 h½1 7 6 h½ 3 7
6 7 a1 6 7
6 h½ 3 h½2 7 ¼ 6 h½ 4 7 ð6:224Þ
6 7 a2 6 7
6 .. .. 7 6 .. 7
4 . . 5 4 . 5
h½ L  2 h½ L  3 h½L  1

Let’s place the name for individual matrix and vectors as below.
2 3 2 3
h½ 0 0 h½ 1
6 h½ 1 h½ 0 7 6 h½ 2 7
6 7   6 7
6 h½ 2 h½ 1 7 6 h½ 3 7
a 6 7
R¼6
6 h½ 3 h½ 2 7; a ¼
7
1
; and l ¼ 6 h½ 4 7 ð6:225Þ
6 7 a 2 6 7
4 .. .. 5 6 .. 7
. . 4 . 5
h½ L  2 h½ L  3 h½ L  1

The solution for a is derived as shown in Eq. (6.226). The apostrophe on


variable indicates the matrix transpose.

Ra ¼ l

R0 Ra ¼ R0 l
1 1
ðR0 RÞ R0 Ra ¼ ðR0 RÞ R0 l
1
a ¼ ðR0 RÞ R0 l ð6:226Þ
450 6 Filter Design

Table 6.31 Given filter specification


Filter specifications Value
Filter type Low pass filter
Filter realization AR with Yule-walker method style
Filter length 2
Halfpower frequency (fh) 1000 Hz; xh ¼ p=4
Passband magnitude 1
Sampling frequency (fs) 8000 Hz

Once we obtain the a1 and a2, the frequency response helps to find b0 value as
below.

H ðejx Þ ¼ H ðzÞjz¼ejx ¼ 1 þ a1 ejxb0þ a2 ejx2 ð6:227Þ

Placing any known H ðejx Þ value returns the b0 as below. This example uses the
zero-frequency value.
   
b0 ¼ H ðej0 Þð1 þ a1 ej0 þ a2 ej02 Þ ¼ H ðej0 Þð1 þ a1 þ a2 Þ ð6:228Þ

We may derive the b0 value from Eq. (6.220) as below.

b0 ¼ h½ 0 ð6:229Þ

The AR filter by using the Yule-walker method requires the impulse response
from the unknown filter. The Yule-walker algorithm estimates the coefficients of
the unknown AR filter with given order. Therefore, we cannot directly design the
AR Yule-walker filter from the specification.
Example 6.22
Design the AR filter first to meet the Table 6.31 requirement and Yule-walker
algorithm follows the AR filter to estimate the coefficients. Note that the actual
Yule-walker algorithm need the unknown filter output from the white noise input
for estimation.
6.3 IIR Filters 451

Fig. 6.71 Pole zero plot of 1


designed AR filter for
0.8
Table 6.31
0.6

Imaginary Part
0.4
0.2
2
0
-0.2
-0.4
-0.6
-0.8
-1

-1 -0.5 0 0.5 1
Real Part

Solution
Figure 5.24 demonstrates the proper LPF for above specification. The pole location
0:7ejp=6 provide the best performance according to Fig. 5.24. Observe that pre-
vious IIR filter design methods cannot be used because of model mismatch as
ARMA filter model.

b0 b0
H d ðzÞ ¼ ¼
ð1  0:7e z Þð1
jp=6 1  0:7ejp=6 z1 Þ 1  1:2124z1 þ 0:49z2
pffiffiffi
At halfpower frequency p=4; the filter magnitude should be 1= 2 by controlling
b0 value as below.
    



  b0
Hd ejp=4  ¼   
1  1:2124z þ 0:49z z¼ejp=4 
1 2 
 
 b0 
¼   ¼ p1ffiffiffi ! b0 ¼ 0:2786
1  1:2124e jp=4 þ 0:49e j2p=4  2

The final AR filter for baseline model is shown in below.

Hd ðzÞ ¼ 11:2124z
0:2786
1 þ 0:49z2

Figure 6.71 shows the pole zero plot of the design AR filter. Two poles are
located at 0:7ejp=6 and two zeros are placed at origin.
452 6 Filter Design

2
1 Response Response
Passband 0
)|
Passband

-2 -3dB
j
|Hd (e

0.5

20log |H (e j )| (dB)
-4
-6
0
0 500 1000 1500 2000 2500 3000 3500 4000 -8

d
Frequency (Hz) -10

10
-12
0.3 -14
h [n]

0.2
-16
d

0.1
-18
0
-20
-0.1 0 500 1000 1500 2000 2500 3000 3500 4000
0 5 10 15 20 25
Frequency (Hz)
n

Fig. 6.72 Frequency response and impulse response of designed AR filter for Table 6.31

Prog. 6.55 MATLAB program for Figs. 6.71 and 6.72.

aangle = pi/6;
alpha = 0.7;
pb = linspace(0,1000,501);
aa = [1 -2*alpha*cos(aangle) alpha^2]
bb = abs(((exp(j*pi/4)-0.7*exp(-j*pi/6))*(exp(j*pi/4)-
0.7*exp(j*pi/6)))/sqrt(2));
[hh0, ] = impz(bb,aa);
[h0,w0] = freqz(bb,aa,1000,8000);
hpb0 = freqz(bb,aa,pb,8000);

figure,
zplane(bb,aa);
figure,
subplot(211),plot(w0,abs(h0),pb,abs(hpb0),'.-'), grid, ylim([0 1.1]);
xlabel('Frequency (Hz)')
ylabel('|H_d(e^{j\omega})|')
line([0 4000],[1/sqrt(2) 1/sqrt(2)]);
legend('Response','Passband')
subplot(212), stem( ,hh0), grid, xlim([0 25]), ylim([-0.1 0.4])
xlabel('n')
ylabel('h_d[n]')
figure
plot(w0,db(h0),pb, db(hpb0),'.-'), grid, ylim([-20 2]);
line([0 4000],[db(1/sqrt(2)) db(1/sqrt(2))]);
legend('Response','Passband')
ylabel('20log_{10}|H_d(e^{j\omega})| (dB)')
xlabel('Frequency (Hz)')
6.3 IIR Filters 453

Figure 6.72 depicts the frequency response and impulse response of the AR
filter. The passband satisfies the Table 6.31 specification. Note that the horizontal
line in the figures denote the halfpower frequency requirement. Below equation
shows the difference equation for Hd ðzÞ in time domain.

yd ½n  1:2124yd ½n  1 þ 0:49yd ½n  2 ¼ 0:2786xd ½n

By placing the delta signal for input, impulse response can be obtained as below.

hd ½n  1:2124hd ½n  1 þ 0:49hd ½n  2 ¼ 0:2786d½n

This example employs first six samples of impulse response as below.

hd ½n ¼ 0:2786d½n þ 0:3378d½n  1 þ 0:2731d½n  2


þ 0:1655d½n  3 þ 0:0669d½n  4 þ 0:0000d½n  5

Build the matrix as below.


2 3 2 3
hd ½ 0 0 hd ½ 1
6 hd ½ 1 hd ½ 0 7  6 hd ½ 2 7
6 7 a1 6 hd ½ 3 7
6 hd ½ 2 hd ½ 1 7 ¼ 6 7
4 hd ½ 3 hd ½ 2 5 a2 4 hd ½ 4 5
hd ½ 4 hd ½ 3 hd ½ 5

Actual values are as below.

2
1 Response Response
Passband 0 Passband
)|

-2 -3dB
j

0.5
|H(e

20log |H(e j )| (dB)

-4
-6
0
0 500 1000 1500 2000 2500 3000 3500 4000 -8

Frequency (Hz) -10


10

-12
0.3 -14
0.2
h[n]

-16
0.1
-18
0
-20
-0.1 0 500 1000 1500 2000 2500 3000 3500 4000
0 5 10 15 20 25
n Frequency (Hz)

Fig. 6.73 Frequency response and impulse response of designed Yule-walker filter for Table 6.31
454 6 Filter Design

2 3 2 3
0:2786 0 0:3378
6 0:3378 0:2786 7  6 7
6 7 a 6 0:2731 7
6 7 1 6 7
6 0:2731 0:3378 7 ¼ 6 0:1655 7; Ra ¼ l
6 7 a2 6 7
4 0:1655 0:2731 5 4 0:0669 5
0:0669 0:1655 0:0000

Solve the matrix for a1 and a2 as below.


1
a ¼ ðR0 RÞ R0 l
   
a 1:2124
a¼ 1 ¼
a2 0:4900
  pffiffiffi
Assume that the frequency response H ejp=4 is 1= 2 to compute b0 value.
    



 jp=4   b0  
H e ¼
1  1:2124z1 þ 0:49z2 z¼ejp=4 

 
 b0 

¼  ¼ p1ffiffiffi ! b0 ¼ 0:2786
1  1:2124e jp=4 þ 0:49e j2p=4  2

The final Yule-walker AR filter is below.

H ðzÞ ¼ 11:2124z
0:2786
1 þ 0:49z2

The corresponding time domain representation is below.

y½n  1:2124y½n  1 þ 0:49y½n  2 ¼ 0:2786x½n

Figure 6.73 represents the frequency response and impulse of the filter. The
passband satisfies the Table 6.31 specification as halfpower frequency requirement.
Note that the horizontal line in the figures denote halfpower frequency requirement.
6.3 IIR Filters 455

Prog. 6.56 MATLAB program for Fig. 6.73.

aangle = pi/6;
alpha = 0.7;
pb = linspace(0,1000,501);
aa = [1 -2*alpha*cos(aangle) alpha^2]
bb = abs(((exp(j*pi/4)-0.7*exp(-j*pi/6))*(exp(j*pi/4)-
0.7*exp(j*pi/6)))/sqrt(2));
[hh0, ] = impz(bb,aa);
hh = hh0(1:6);
R = [hh(1:end-1) [0; hh(1:end-2)]];
mu = [hh(2:end)];
acoefs = -inv(R'*R)*R'*mu
bcoef = abs((1+acoefs(1)*exp(-j*pi/4)+acoefs(2)*exp(-j*2*pi/4))/sqrt(2));
[hh1, 1] = impz(bcoef,[1; acoefs]);
[h1,w1] = freqz(bcoef,[1; acoefs],1000,8000);
hpb1 = freqz(bcoef,[1; acoefs],pb,8000);

figure,
subplot(211),plot(w1,abs(h1),pb,abs(hpb1),'.-'), grid, ylim([0 1.1]);
xlabel('Frequency (Hz)')
ylabel('|H(e^{j\omega})|')
line([0 4000],[1/sqrt(2) 1/sqrt(2)]);
legend('Response','Passband')
subplot(212), stem( 1,hh1), grid, xlim([0 25]), ylim([-0.1 0.4]);
xlabel('n')
ylabel('h[n]')
figure,
plot(w1,db(h1),pb, db(hpb1),'.-'), grid, ylim([-20 2]);
line([0 4000],[db(1/sqrt(2)) db(1/sqrt(2))]);
legend('Response','Passband')
ylabel('20log_{10}|H(e^{j\omega})| (dB)')
xlabel('Frequency (Hz)')

The impulse response in above figure also exactly follows hd[n] in Fig. 6.72.
This example exercised the AR Yule-walker method with model and order
matching condition. The derived result from the AR Yule-walker method shows the
completely identical outcome. Filter model and order mismatch situation could
generate the significant performance degradation in frequency response as well as
impulse response. Therefore, we need to be aware of matching problem from
parametric filter design method.

456 6 Filter Design

Maxflat filter
The previously described IIR filters are derived by the rational function with equal
or denominator dominant degree of numerator and denominator. Sometimes, it is
preferable to design filters having more zeros than poles to achieve an enhanced
tradeoff between performance and complexity. The maxflat filter [23] used the
unequal order of numerator and denominator on the transfer function for maximum
flat frequency response in passband and stopband. The flatness can be explained by
using the example in Table 6.32.
Four polynomials y1, y2, y3, and y4 represents the minimum value 1 at x = 0;
therefore, the polynomials pass through the identical location x = 0 and y = 1 as
shown in Fig. 6.74. The increase rate after the minimum point is vary based on the
order of the polynomial.

Table 6.32 Flatness example with polynomials


y1 ¼ x2 þ 1 y2 ¼ x4 þ 1 y3 ¼ x6 þ 1 y4 ¼ x8 þ 1
y1 jx¼0 ¼ 1 y2 jx¼0 ¼ 1 y3 jx¼0 ¼ 1 y4 jx¼0 ¼ 1

dy1 

dy2 

dy3  dy4 

dx x¼0 ¼ 0 dx x¼0 ¼ 0 dx x¼0 ¼ 0 dx x¼0 ¼ 0
  
d 2 y2  d 2 y3  d 2 y4 
dx2 x¼0 ¼ 0 dx2 x¼0 ¼ 0 dx 2 ¼0
 x¼0
d y2 
3
.. ..
dx3  ¼0 . .
x¼0
 
d 5 y3  d 7 y4 
dx5 x¼0
¼ 0 dx7 x¼0 ¼ 0
) Flatter )

3
10
x 2 +1
x 4 +1
x 6 +1
x 8 +1

2
10

1
10

0
10
-2 -1.5 -1 -0.5 0 0.5 1 1.5 2
x

Fig. 6.74 Plot of four polynomials from Table 6.32


6.3 IIR Filters 457

Prog. 6.57 MATLAB program for Fig. 6.74.

x = linspace(-2,2,10000);
y1 = x.^2+1;
y2 = x.^4+1;
y3 = x.^6+1;
y4 = x.^8+1;
plot(x,y1,x,y2,x,y3,x,y4), grid
semilogy(x,y1,x,y2,x,y3,x,y4), grid
legend('x^2+1','x^4+1','x^6+1','x^8+1')
xlabel('x');

The further flatness can be achieved by higher order of derivatives for zero
output at the specific input value. At the given example, y4 shows the maximum
flatness because up to the 7th order derivative delivers the zero output for zero
input. Figure 6.74 also presents the maximum flatness. Note that Fig. 6.74 utilizes
the logarithm scale for y axis to magnify the value around the interesting point.
For FIR low pass filter, the flatness is required at the x ¼ 0 and p . The corre-
sponding representation in mathematics is shown in Eq. (6.230).
 
H ejx 2 R
 
H ejx x¼0 ¼ 1; for unit DC gain

d k H ðejx Þ
¼ 0; k ¼ 1; 2; . . .; L1
dxk x¼0

d k H ðejx Þ
dxk x¼p
¼ 0; k ¼ 0; 1; . . .; L2 ð6:230Þ

Herrmann [24] solved the above problem for FIR filter realization. Selesnick
et al. [23] extended FIR filter realization for Butterworth IIR filter with maximum
flat response on passband and stopband. The derive procedure and corresponding
solution can be found in the papers [23, 24] and will not be presented due to the
complexity which is the out of this book scope.
Example 6.23
Using the MATLAB function, fulfill the Table 6.33 maxflat IIR filter.
Table 6.33 Given filter specification
Filter specifications Value
Filter type Low pass filter
Filter realization Maxflat IIR
Filter length Various
N = 3 for Butterworth filter (Comparison)
Halfpower frequency (fc) 1000 Hz; xh ¼ p=4
Passband magnitude 1
Sampling frequency (fs) 8000 Hz
458 6 Filter Design

Solution
Maxflat MATLAB function receives numerator/denominator order and halfpower
frequency argument. The generated numerator and denominator coefficients pro-
vide frequency response in magnitude and decibel as shown in Figs. 6.75 and 6.76.

1
0.9
0.8
0.7
0.6
)|

0.5
j
|H(e

0.4
0.3
0.2
0.1
0
0 500 1000 1500 2000 2500 3000 3500 4000
Frequency (Hz)

Fig. 6.75 Frequency response in magnitude for various order maxflat filters and Butterworth filter

0
-20
-40
20log |H(e j )| (dB)

-60
-80
-100
-120
10

-140
-160
-180
-200
0 500 1000 1500 2000 2500 3000 3500 4000
Frequency (Hz)

Fig. 6.76 Frequency response in decibel for various order maxflat filters and Butterworth filter
6.3 IIR Filters 459

Prog. 6.58 MATLAB program for Figs. 6.75 and 6.76.

m = 3;
n1 = 5;
n2 = 7;
n3 = 9;
n4 = 11;
wn = 0.25;
[b1,a1] = maxflat(n1,m,wn);
[b2,a2] = maxflat(n2,m,wn);
[b3,a3] = maxflat(n3,m,wn);
[b4,a4] = maxflat(n4,m,wn);
[b5,a5] = bu er(m,wn);
[h1,w1] = freqz(b1,a1,1000);
[h2,w2] = freqz(b2,a2,1000);
[h3,w3] = freqz(b3,a3,1000);
[h4,w4] = freqz(b4,a4,1000);
[h5,w5] = freqz(b5,a5,1000);
ww = w1/pi*4000;

figure,
plot(ww,abs(h1),ww,abs(h2),ww,abs(h3),ww,abs(h4),ww,abs(h5)), grid
h = legend('Maxflat N=5/M=3','Maxflat N=7/M=3','Maxflat
N=9/M=3','Maxflat N=11/M=3','Bu erworth N=3/M=3');
set(h,'Interpreter','latex');
xlabel('Frequency (Hz)')
ylabel('|H(e^{j\omega})|')
ylim([-0.05 1.05])
figure,
plot(ww,db(abs(h1)),ww,db(abs(h2)),ww,db(abs(h3)),ww,db(abs(h4)),ww,db(
abs(h5))), grid
h = legend('Maxflat N=5/M=3','Maxflat N=7/M=3','Maxflat
N=9/M=3','Maxflat N=11/M=3','Bu erworth N=3/M=3');
set(h,'Interpreter','latex');
xlabel('Frequency (Hz)')
ylabel('20log_{10}|H(e^{j\omega})| (dB)')
ylim([-210 10])

In figure legend above, N is numerator order and M is denominator order. As we


can see that higher order at the numerator presents the flatter response at passband
and stopband. For comparison purpose, Butterworth filter with equal orders for
numerator and denominator presents the least flatness in the filter responses. Note
that Maxflat filter is the extension of Butterworth filter to deliver the maximum
flatness at passband and stopband. ∎
460 6 Filter Design

Linear prediction filter


The filter can predict the current input by using N previous inputs as shown in
Eq. (6.231).

P
N
ex ½n ¼  ak x ½ n  k  ð6:231Þ
k¼1

The linear combination of the previous inputs predicts the current input. The
estimation error is below.

e½n ¼ x½n  ex ½n ð6:232Þ

With the estimation error, Eq. (6.231) can be organized as below. The x[n] is
filter input and e[n] is the filter output.

P
N
e½n ¼ x½n þ ak x½n  k  ð6:233Þ
k¼1

The z domain representation is below.

E ðzÞ ¼ ð1 þ a1 z1 þ a2 z2 þ    þ aN zN ÞX ðzÞ ð6:234Þ

The estimation error is the residual by removing signal pattern from x½n: The
linear combination of the previous inputs generates the best representation of x½n
based on the order N. The optimal predictor minimizes the e½n in mean square
sense for whitening the e½n: Reverse the filter configuration provides the below
transfer function.

X ðzÞ
E ðzÞ ¼ ð1 þ a1 z1 þ a2 z12 þ  þ aN zN Þ ¼ HAR ðejx Þ ð6:235Þ

The AR model from the e½n input generates the x½n output. Since the white
noise e½n has the full and flat spectrum, the output x½n and the AR filter response
are identical in frequency domain as shown in Eq. (6.236).

X ðejx Þ ¼ HAR ðejx ÞEðejx Þ  HAR ðejx Þ ð6:236Þ

The computation of linear prediction filter coefficients in Eq. (6.233) is the


estimation process of input signal x[n] based on the AR filter model. Using the
coefficients, the linear prediction filter performs the inverse filter operation on x
[n] to obtain the white noise e[n] by accurate prediction. The signal generation and
linear prediction are shown in Eq. (6.237) in transfer function form.
6.3 IIR Filters 461

Linear prediction
Generally unknown coefficients estimation
1
x[n] AR Yule-walker
e[n] ------------------------------
to estimate a1, a2, ...,aN
White noise 1+a1z +a2z-2+...+aNz-N
-1
Generated
signal

Error estimate (~x[n]) Predict by


~e[n]
~e[n]=x[n]-(~x[n]) (~x[n])=-a1x[n-1]-a2x[n-2]-...-aNx[n-N]
Approx. Predicted
White noise signal

Fig. 6.77 Overall linear prediction filter procedure. Assume order N is known

 
 1
1
N
 1 þ a1 z1 þ    þ aN zN  1
1 þ a1 z þ    þ aN z |fflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflffl{zfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflffl} ð6:237Þ
|fflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflffl{zfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflffl} Trans:func: for lin:pred:filter
Trans:func:for x½n

Therefore, the AR filter generates the x[n] from white noise e[n] and linear
prediction filter produces the white noise e[n] from x[n]. Figure 6.77 illustrates the
overall procedure of the linear prediction filter process.
We assume that the filter order N is known. If the order is required to be
estimated as well, we need to exercise the statistical process for optimal order. The
linear prediction filter [25] is the FIR filter; however, the linear prediction filter
coefficient is frequently used for AR modeling of signal as IIR filter format. The
computational procedure and method are identical to the parametric method for AR
Yule-walker filter [20–22].
We discussed that the white noise e[n] represents the full and flat spectrum. The
squared magnitude in frequency domain corresponds to the autocorrelation oper-
ation in time domain as shown in Eq. (6.238).
  2     DTFT
constant  E ejx  ¼ E ejx E ejx $ e½n  e½n
P
1 ð6:238Þ
¼ e½k e½k  n  kd½n
k¼1

If the e[n] is the random white noise with independence to adjacent data, the
autocorrelation presents the delta function which corresponds to the full and flat
spectrum. Further information about the white noise can be found at statistical
signal processing books [26, 27].
Prony
The Prony [7, 28] method designs the ARMA IIR filter from time domain response.
The difference equation from conventional ARMA model represents the nonlinear
property which is difficult to formulize the solution. The Prony method linearizes
the ARMA model in matrix description by using Z-transformation. Below is the
autoregressive moving average (ARMA) model in difference equation form.
462 6 Filter Design

y ½ n þ a1 y ½ n  1 þ    þ aN y ½ n  N 
ð6:239Þ
¼ b0 x½n þ    þ bM1 x½n  ðM  1Þ þ bM x½n  M 

The corresponding transfer function is below.

Y ðzÞ b0 þ    þ bM1 zðM1Þ þ bM zM BðzÞ


¼ ¼ ð6:240Þ
X ðzÞ 1 þ a1 z1 þ    þ aN zN AðzÞ
¼ H ðzÞ ¼ h½0 þ h½1z1 þ h½2z2 þ   

The numerator can be denoted by the product between the transfer function and
denominator part as below. Observe that the impulse response h[n] length is most
likely to be infinite due to the ARMA model.

 BðzÞ ¼ H ðzÞAðzÞ 
b0 þ    þ bM1 zðM1Þ þ bM zM ð6:241Þ
¼ ðh½0 þ h½1z1 þ h½2z2 þ   Þð1 þ a1 z1 þ    þ aN zN Þ

The above polynomial based on power of z can be represented by matrix form as


shown in Eq. (6.242).

ð6:242Þ

The dimension of above matrix is below.

½ ð L þ 1Þ 1 ¼ ½ ð L þ 1Þ ð N þ 1Þ  ½ ð N þ 1Þ 1

The partitioned matrix is presented as shown in Eq. (6.243).


  
b H1
¼ 1
ð6:243Þ
h1 H2 ay
0

The submatrix dimension is below.


    
ðM þ 1Þ 1 ðM þ 1Þ ðN þ 1Þ 1 1
¼
ðL  M Þ 1 ðL  M Þ 1 ðL  M Þ N N 1

Prony algorithm solves the following linear algebra for a and b vector.
6.3 IIR Filters 463

0 ¼ h1 þ H 2 ay

b ¼ H1a ð6:244Þ

Apply the derived a and b coefficients to the transfer function as below.


ðM1Þ M
H ðzÞ ¼ b0 þ1þþa1bzM1 z þ bM z
1 þ  þ a zN
N
ð6:245Þ

The final Prony filter in discrete time domain is Eq. (6.245). Similar to the
Yule-walker method, the Prony filter based on the ARMA model requires the
designed impulse response which satisfies the specification with unknown coeffi-
cients. The Prony algorithm estimates the coefficients of the unknown ARMA filter
with given order. Therefore, we cannot directly design the ARMA Prony filter from
the specification.
Example 6.24
Design the Table 6.34 IIR filter by using Prony method. By using the Butterworth
method, example below provides the ARMA filter first to meet the Table 6.34
requirement and Prony algorithm follows the ARMA filter to estimate the
coefficients.
Solution
In previous example, the Butterworth method presented the following ARMA IIR
filter design to meet the Table 6.34 specification.
1 2 3
þ 0:0951z þ 0:0951z þ 0:0317z
Hd ðzÞ ¼ 0:0317
11:4590z1 þ 0:9104z2 0:1978z3

The pole zero plot of the above filter is demonstrated at Fig. 6.49 and the
frequency response and impulse response are illustrated at Fig. 6.78. The passband
satisfies the Table 6.34 specification. Note that the horizontal line in the figures
denote the halfpower frequency requirement.

Table 6.34 Given filter specification


Filter specifications Value
Filter type Low pass filter
Filter realization Prony IIR
Filter length N = 3 and M = 3
Passband frequency (fp) 1000 Hz; xp ¼ p=4
Passband magnitude 1
Passband peak-to-peak ripple in decibel ðDp Þ 3.0103 dB
Stopband frequency (fst) 2000 Hz; xst ¼ p=2
1
Stopband attenuation in decibels Dst 20 log10 0:1 ¼ 20dB
Sampling frequency (fs) 8000 Hz
464 6 Filter Design

1 Response 0 -3dB
Passband
)|

Response
-10 Passband
j
|Hd(e

0.5

20log |H (e j )| (dB)
-20
0
0 500 1000 1500 2000 2500 3000 3500 4000
Frequency (Hz) -30

d
10
0.3 -40
h [n]

0.2
d

0.1 -50
0
-0.1 -60
0 5 10 15 20 25 0 500 1000 1500 2000 2500 3000 3500 4000
n Frequency (Hz)

Fig. 6.78 Frequency response and impulse response of designed Butterworth filter for Table 6.34

Prog. 6.59 MATLAB program for Fig. 6.78.

pb = linspace(0,1000,501);
sb = linspace(2000,4000,2001);
a0 = [1 -1.4590 0.9104 -0.1978];
b0 = [0.0317 0.0951 0.0951 0.0317];
[h0,w0] = freqz(b0,a0,1000,8000);
[hh0,t0] = impz(b0,a0);
hpb0 = freqz(b0,a0,pb,8000);
hsb0 = freqz(b0,a0,sb,8000);

figure,
subplot(211),plot(w0,abs(h0),pb,abs(hpb0),'.-'), grid, ylim([0 1.1]);
xlabel('Frequency (Hz)');
ylabel('|H_d(e^{j\omega})|');
line([0 4000],[1/sqrt(2) 1/sqrt(2)]);
legend('Response','Passband');
subplot(212), stem(t0,hh0), grid, xlim([0 25]), ylim([-0.1 0.4]);
xlabel('n');
ylabel('h_d[n]');
figure
plot(w0,db(h0),pb, db(hpb0),'.-'), grid, ylim([-60 2]);
line([0 4000],[db(1/sqrt(2)) db(1/sqrt(2))]);
legend('Response','Passband');
ylabel('20log_{10}|H_d(e^{j\omega})| (dB)');
xlabel('Frequency (Hz)');
6.3 IIR Filters 465

Below equation shows the difference equation for Hd ðzÞ in time domain.
yd ½n  1:4590yd ½n  1 þ 0:9104yd ½n  2  01978yd ½n  3
¼ 0:0317xd ½n þ 0:0951xd ½n  1 þ 0:0951xd ½n  2 þ 0:0317xd ½n  3

By placing the delta signal for input, impulse response can be obtained as below.
hd ½n  1:4590hd ½n  1 þ 0:9104hd ½n  2  01978hd ½n  3
¼ 0:0317d½n þ 0:0951d½n  1 þ 0:0951d½n  2 þ 0:0317d½n  3

This example employs first seven samples of impulse response as below.


hd ½n ¼ 0:0317d½n þ 0:1414d½n  1 þ 0:2725d½n  2 þ 0:3068d½n  3
þ 0:2276d½n  4 þ 0:1066d½n  5 þ 0:0090d½n  6

Build the matrix for Eq. (6.242) as below.


2 3 2 3
b0 hd ½ 0 0 0 0
6 b1 7 6 hd ½ 1 hd ½ 0 0 0 7 2 3
6 7 6 7 1
6 b2 7 6 hd ½ 2 hd ½ 1 hd ½ 0 7
0 76 7
6 7 6
6 b3 7 ¼ 6 hd ½ 3 hd ½ 2 hd ½ 1 hd ½0 7 6 a1 7
6 7 6 7 4 a2 5
6 0 7 6 hd ½ 4 hd ½ 3 hd ½ 2 hd ½1 7
6 7 6 7 a
4 0 5 4 hd ½ 5 hd ½ 4 hd ½ 3 hd ½2 5 3
0 hd ½ 6 hd ½ 5 hd ½ 4 hd ½3

Actual values are as below.

Partitioning matrix as below.


    
b H1 1
¼
0 h1 H 2 ay

The submatrices are used for a and b coefficient as below. The a coefficient
computation is below.
0 ¼ h þ H ay 1 2
2 3 2 3 2 32 3
0 0:2276 0:3068 0:2725 0:1414 a1
4 0 5 ¼ 4 0:1066 5 þ 4 0:2276 0:3068 0:2725 54 a2 5
0 0:0090 0:1066 0:2276 0:3068 a3

The b coefficient computation is below.


466 6 Filter Design

b ¼ H1a
2 3 2 32 3
b0 0:0317 0 0 0 1
6 b1 7 6 0:1414 0:0317 0 0 7 6 a1 7
6 7¼6 76 7
4 b2 5 4 0:2725 0:1414 0:0317 0 5 4 a2 5
b3 0:3068 0:2725 0:1414 0:0317 a3

Solve the matrix for a as below.


2 3 2 3 2 31 2 3
a1 1:4590 0:3068 0:2725 0:1414 0:2276
4 a2 5 ¼ 4 0:9104 5 ¼ 4 0:2276 0:3068 0:2725 5 4 0:1066 5
a3 0:1978 0:1066 0:2276 0:3068 0:0090

Solve the matrix for b as below.


2 3 2 3 2 32 3
b0 0:0317 0:0317 0 0 0 1
6 b1 7 6 0:0951 7 6 0:1414 0 7 6 7
6 7¼6 7 6 0:0317 0 76 1:4590 7
4 b2 5 4 0:0951 5 ¼ 4 0:2725 0:1414 0:0317 0 54 0:9104 5
b3 0:0317 0:3068 0:2725 0:1414 0:0317 0:1978

The final Prony ARMA filter is below.


1 2 3
þ 0:0951z þ 0:0951z þ 0:0317z
H ðzÞ ¼ 0:0317
11:4590z1 þ 0:9104z2 0:1978z3

The corresponding time domain representation is below.

y½n  1:4590y½n  1 þ 0:9104y½n  2  01978y½n  3


¼ 0:0317x½n þ 0:0951x½n  1 þ 0:0951x½n  2 þ 0:0317x½n  3

Figure 6.79 represents the frequency response and impulse of the filter. The
passband satisfies the Table 6.34 specification as halfpower frequency requirement.
Note that the horizontal line in the figures denote halfpower frequency requirement.

1 Response
0 -3dB
Response
Passband Passband
)|

-10
j

0.5
|H(e

20log |H(ej )| (dB)

-20
0
0 500 1000 1500 2000 2500 3000 3500 4000
-30
Frequency (Hz)
10

0.3 -40
0.2
h[n]

0.1 -50

0
-0.1 -60
0 5 10 15 20 25 0 500 1000 1500 2000 2500 3000 3500 4000
n Frequency (Hz)

Fig. 6.79 Frequency response and impulse response of designed Prony filter for Table 6.34
6.3 IIR Filters 467

Prog. 6.60 MATLAB program for Fig. 6.79.

pb = linspace(0,1000,501);
sb = linspace(2000,4000,2001);
a0 = [1 -1.4590 0.9104 -0.1978];
b0 = [0.0317 0.0951 0.0951 0.0317];
[hh0,t0] = impz(b0,a0);
h1 = [hh0(5:7)];
H2 = toeplitz(hh0(4:6),hh0(4:-1:2));
H1 = toeplitz(hh0(1:4),zeros(4,1));
a1 = -inv(H2)*h1;
b1 = H1*[1; a1];
[h3,w3] = freqz(b1,[1; a1],1000,8000);
[hh3,t3] = impz(b1,[1; a1]);
hpb3 = freqz(b1,[1; a1],pb,8000);
hsb3 = freqz(b1,[1; a1],sb,8000);

figure,
subplot(211),plot(w3,abs(h3),pb,abs(hpb3),'.-'), grid, ylim([0 1.1]);
xlabel('Frequency (Hz)');
ylabel('|H(e^{j\omega})|');
line([0 4000],[1/sqrt(2) 1/sqrt(2)]);
legend('Response','Passband');
subplot(212), stem(t3,hh3), grid, xlim([0 25]), ylim([-0.1 0.4]);
xlabel('n');
ylabel('h[n]');
figure,
plot(w3,db(h3),pb, db(hpb3),'.-'), grid, ylim([-60 2]);
line([0 4000],[db(1/sqrt(2)) db(1/sqrt(2))]);
legend('Response','Passband');
ylabel('20log_{10}|H(e^{j\omega})| (dB)');
xlabel('Frequency (Hz)');

The impulse response in above figure also exactly follows hd[n] in Fig. 6.78. This
example exercised the Prony ARMA filter with model and order matching condition.
The derived result from the Prony method shows the completely identical outcome.
Filter model and order mismatch situation could generate the significant perfor-
mance degradation in frequency response as well as impulse response. Therefore, we
need to be aware of matching problem from parametric filter design method.

Steiglitz-McBride algorithm
As a part of parametric methods, Steiglitz-McBride algorithm [29] finds an IIR filter
coefficients with given desired impulse response. The Steiglitz-McBride iterative
method is applied to identify an unknown linear system (or transfer function) by
468 6 Filter Design

hd[n]
δ[n] +
e[n]
-

h[n]

Fig. 6.80 Simplified system model for Stiglitz-McBride algorithm

minimizing the mean square error between the system and model output. Figure 6.80
demonstrates the simplified system model for Stiglitz-McBride algorithm.
The Steiglitz-McBride algorithm figures out the target system BðzÞ=AðzÞ by
minimizing the energy of the e[n] for equalizing model system B e ðzÞ to the
e ðzÞ= A
target. The impulse response of the individual system is defined as below.

Z e
hd ½n $ BAððzzÞÞ and h½n $ B ðzÞ
Z
ð6:246Þ
eA ðzÞ

The system error e[n] is represented as below.

e
e½n ¼ hd ½n  h½n $ E ðzÞ ¼ BAððzzÞÞ  B ðzÞ
Z
ð6:247Þ
eA ðzÞ

The system solution is presented by below equation.

e P e
h ¼ argmin je½nj2 where h ¼ fa1 ; . . .; aM ; b0 ; . . .; bN gfrom B ðzÞ ð6:248Þ
h n eA ðzÞ

e ðzÞ BðzÞ
B
Then h½n  e
h ½n and 
e
A ðzÞ AðzÞ

Due to the recursive equation, the solution by Eq. (6.248) indicates the highly
nonlinear and intractable property. The system model is modified as below to
linearize the solution.
Figure 6.81 shows the iterative method to find the optimal solution for the
Fig. 6.80 model. Below equations provide the verification of equivalence.

X I  e i ðzÞ
2
e i ðzÞ  1
2 1  A B
je½nj ¼ Hd ðzÞ   z dz
n
2pj  e i1 ðzÞ A
A e i1 ðzÞ
c
ð6:249Þ
I  2 
e i ðzÞ  A
2
e i ðzÞ 
1 BðzÞ B
¼      z1 dz
2pj AðzÞ A e i ðzÞ  A e i1 ðzÞ
c
6.3 IIR Filters 469

hd[n]
δ [n]

Prefiltering

Iteration
x[n] y[n]
Least square linear solution
~h[n] - + ~hd[n]

e[n]

Fig. 6.81 Modified system identification model for Stiglitz-McBride algorithm

H  2  2
 1

¼ 1
2pj Hd ðzÞ A i ðzÞ  B i ðzÞ e
e e 1  z dz
 ð6:250Þ
c A i1 ðzÞ

As the error norm approaches to zero, Eq. (6.249) denotes that the target and
model system are became identical. Therefore, the optimal numerator and
denominator coefficients can be derived by solving Eq. (6.252). The A e i1 ðzÞ and
e i ðzÞ are related; therefore, the iterative method should be exercised.
A
X
e
h ¼ argmin je½nj2
h n

H  2  2
 1
e e    z dz ð6:251Þ
¼ argmin c  H d ð z Þ A i ð zÞ  B i ð z Þ  e 1

h A i1 ðzÞ

H  2
¼ argmin  Hd ð zÞ A e i ðzÞ z1 dz
e i ðzÞ  B ð6:252Þ
c
h

 
H BðzÞ eB i ðzÞ2 1

¼ argmin c AðzÞ   z dz
h eA i ðzÞ

As shown in Eqs. (6.251) and (6.252), the prefiltering by 1= A e i1 ðzÞ converts the
 2
 e i ðzÞ . The prefiltering with delta
e i ðzÞ  A
equation to the linear problem as Hd ðzÞ A
function and desired response is shown below.
470 6 Filter Design

xi ½n ¼ aði1Þ1 xi ½n  1  aði1Þ2 xi ½n  2    


ð6:253Þ
aði1ÞM xi ½n  M  þ d½n

yi ½n ¼ aði1Þ1 yi ½n  1  aði1Þ2 yi ½n  2    


ð6:254Þ
aði1ÞM yi ½n  M  þ hd ½n

The left-hand side and right-hand side of the Fig. 6.81 is represented by
Eqs. (6.253) and (6.254), respectively. Note that the matrix operation below signifies
convolution sum. The matrix size is L + 1 rows and N + 1 columns (or M + 1).
2 3
xi ½0 0 0  0
6 xi ½1 x i ½ 0 0  0 72 3
6 7
6 xi ½2 x i ½ 1 x i ½ 0  0 7 bi0
6 76
6 .. .. .. .. .. 76 bi1 7
7
6 . . . . . 76
6 76 bi2 7 ¼e
h ½n ð6:255Þ
6 xi ½ N  x i ½ N  1 x i ½ N  2    x i ½ 0 76 . 7
6 74 . 7 5
6 x i ½ N þ 1 xi ½ N  x i ½ N  1    x i ½ 1 7 .
6 7
6 .. .. .. .. .. 7 biN
4 . . . . . 5
xi ½L xi ½L  1 xi ½L  2    xi ½ L  N 
2 3
yi ½ 0 0 0  0
6 y i ½ 1 y i ½ 0 0 72
 30
6 7
6 y i ½ 2 y i ½ 1 y i ½ 0 7 ai0
 0
6 76
6 .. .. .. ..7 6 ai1 7
7..
6 . . . 76
. .
6 7 6 ai2 7
7¼e
h d ½n ð6:256Þ
6 yi ½ M  yi ½M  1 yi ½M  2    7
yi ½0 7 6 .. 7
6 4 . 5
6 y i ½ M þ 1 yi ½ M  y i ½ M  1    7
y i ½ 1 7
6
6 . . . . .. 7 aiM
4 .. .. .. .. . 5
yi ½L yi ½L  1 yi ½L  2    yi ½L  M 

With zero error condition, the Eqs. (6.255) and (6.256) should be identical as
below.

e
h ½ n ¼ e
h d ½n for e½n ¼ 0 ð6:257Þ
6.3 IIR Filters 471

Equations (6.255) and (6.256) can be combined for Eq. (6.258) condition as
below.

ð6:258Þ

The first column of the matrix and first row of the column vector are partitioned
as below.
2 32 3
0  0 x i ½ 0 0  0 ai1
6 yi ½0  x i ½ 1 x i ½ 0  76 . 7
6 0 0 76 .. 7
6 . .. .. .. .. .. .. 76 7
6 .. 76 7
6 . . . . . . 76 aiM 7
6 76 7
6 y ½M  1    yi ½0 x i ½ N  x i ½ N  1    x i ½ 0 76 b 7
6 i 76 i0 7
6 76 . 7
6 .. .. .. .. .. .. .. 76 . 7
4 . . . . . . . 54 . 5
yi ½L  1    yi ½L  M  xi ½L xi ½L  1  xi ½L  N  biN
2 3
y i ½ 0
6 y i ½ 1 7
6 7
6 . 7
6 . 7
6 . 7
¼6 7
6 y ½M  7 ¼ Hc ¼ y
6 i 7
6 7
6 .. 7
4 . 5
yi ½L
ð6:259Þ

We can solve the Eq. (6.259) with linear solver such as QR solver to find
minimum norm residual solution as below.
472 6 Filter Design

c ¼ Linear SolverðH; yÞ ð6:260Þ

Repeat the procedures from Eqs. (6.253) and (6.254) for several iterations. The
iterative method converges to the optimal solution rapidly. The Prony method [7,
28] provides the good initial guess of a(i–1) coefficients for Eqs. (6.253) and (6.254).
The final Steiglitz-McBride filter in discrete time domain is Eq. (6.261).
ðN1Þ N
H ðzÞ ¼ b0 þ1  þ bN1 z þ bN z
þ a1 z1 þ  þ aM zM
ð6:261Þ

In summary, the Steiglitz-McBride algorithm tries to compute the least square


solution to minimize the error power in time domain based on the initial estimate
(usually done by Prony) of the denominator coefficient A e 1 ðzÞ: The input and output
of the unknown system are prefiltered by 1= A e 1 ðzÞ: The filtered signals are used for
e
the least square solution to derive the A 2 ðzÞ and B e 2 ðzÞ: Repeat the procedures for
converged solution.
Similar to the Yule-walker method, the Steiglitz-McBride filter based on the
ARMA model requires the designed impulse response which satisfies the specifi-
cation with unknown coefficients. The Steiglitz-McBride algorithm estimates the
coefficients of the unknown ARMA filter with given order. Therefore, we cannot
directly design the ARMA Steiglitz-McBride filter from the specification.
Example 6.25
Design the Table 6.35 IIR filter by using Steiglitz-McBride method. By using the
Butterworth method, example below provides the ARMA filter first to meet the
Table 6.35 requirement and Steiglitz-McBride algorithm follows the ARMA filter
to estimate the coefficients.
Solution
In previous example, the Butterworth method presented the following ARMA IIR
filter design to meet the Table 6.35 specification.

Table 6.35 Given filter specification


Filter specifications Value
Filter type Low pass filter
Filter realization Steiglitz-McBride IIR
Filter length N = 3 and M = 3
Passband frequency (fp) 1000 Hz; xp ¼ p=4
Passband magnitude 1
Passband peak-to-peak ripple in decibel ðDp Þ 3.0103 dB
Stopband frequency (fst) 2000 Hz; xst ¼ p=2
1
Stopband attenuation in decibels Dst 20 log10 0:1 ¼ 20 dB
Sampling frequency (fs) 8000 Hz
6.3 IIR Filters 473

1 Response
0 -3dB
Passband
)|
Response
-10
j

Passband
|Hd(e

0.5

20log |H (e j )| (dB)
-20
0
0 500 1000 1500 2000 2500 3000 3500 4000
-30

10 d
Frequency (Hz)
-40
0.3
h [n]

0.2
-50
d

0.1
0
-60
-0.1 0 500 1000 1500 2000 2500 3000 3500 4000
0 5 10 15 20 25
n Frequency (Hz)

Fig. 6.82 Frequency response and impulse response of designed Butterworth filter for
Table 6.35. See Prog. 6.59 for realization

1 2 3
þ 0:0951z þ 0:0951z þ 0:0317z
Hd ðzÞ ¼ 0:0317
11:4590z1 þ 0:9104z2 0:1978z3

The pole zero plot of the above filter is demonstrated at Fig. 6.49 and the
frequency response and impulse response are illustrated at Fig. 6.82. The passband
satisfies the Table 6.35 specification. Note that the horizontal line in the figures
denote the halfpower frequency requirement.
This example employs first seven samples (L = 6) of Eq. (6.246) impulse
response as below.

hd ½n ¼ 0:0317d½n þ 0:1414d½n  1 þ 0:2725d½n  2 þ 0:3068d½n  3


þ 0:2276d½n  4 þ 0:1066d½n  5 þ 0:0090d½n  6

Using the Prony AR filter, initial prefilter coefficient is derived as below.

a0 ¼ ½1:0000  2:3874 2:4372  1:0675T

Perform the prefiltering with a0 as below.

x1 ½n ¼ 2:3874x1 ½n  1  2:4372x1 ½n  2 þ 1:0675x1 ½n  3 þ d½n

y1 ½n ¼ 2:3874y1 ½n  1  2:4372y1 ½n  2 þ 1:0675y1 ½n  M  þ hd ½n

Create Eq. (6.259) matrix as below (L = 6).


2 32 3 2 3
0 0 0 x1 ½0 0 0 0 a11 y1 ½0
6 y1 ½0 x1 ½1 x1 ½0 0 7 6 7 6 7
6 0 0 0 76 a12 7 6 y1 ½1 7
6 y1 ½1 y1 ½0 0 x1 ½2 x1 ½1 x1 ½0 0 7 6 a13 7 6 y1 ½2 7
6 76 7 6 7
6 yi ½2 y1 ½1 y1 ½0 x1 ½3 x1 ½2 x1 ½1 x1 ½0 76 7 6 7
6 76 b10 7 ¼ 6 y1 ½3 7
6 y1 ½3 y1 ½2 y1 ½1 x1 ½4 x1 ½3 x1 ½2 x1 ½1 76 b11 7 6 y1 ½4 7
6 76 7 6 7
4 yi ½4 y1 ½3 y1 ½2 x1 ½5 x1 ½4 x1 ½3 x1 ½2 54 b12 5 4 y1 ½5 5
y1 ½5 y1 ½4 y1 ½3 x1 ½6 x1 ½5 x1 ½4 x1 ½3 b13 y1 ½6
474 6 Filter Design

Actual values are below.


2 32 3
0 0 0 1:0000 0 0 0 a11
6 0:0317 0 0 2:3874 1:0000 0 0 7 6 7
6 76 a12 7
6 0:2170 0:0317 0 3:2623 2:3874 1:0000 0 76 a13 7
76
6 7
6 0:7133 0:2170 0:0317 3:0372 3:2623 2:3874 1:0000 76 7
6 76 b10 7
6 1:5147 0:7133 0:2170 1:8486 3:0372 3:2623 2:3874 76 b11 7
76
6 7
4 2:3368 1:5147 0:7133 0:4936 1:8486 3:0372 3:2623 54 b12 5
2:7552 2:3368 1:5147 0:0848 0:4936 1:8486 3:0372 b13

2 3
0:0317
6 0:2170 7
6 7
6 0:7133 7
6 7
¼6 7
6 1:5147 7 ¼ Hc ¼ y
6 2:3368 7
6 7
4 2:7552 5
2:5084

Solve above equation with linear solver to find minimum norm residual solution
as below. In this case, the H matrix is square; hence, we can use the matrix inversion.

c ¼ Linear SolverðH; yÞ

c ¼ H 1 y

The derived coefficients are presented as below.


2 3 2 3
a11 1:4590
6 a12 7 6 0:9104 7
6 7 6 7
6 a13 7 6 0:1978 7
6 7 6 7
c¼6 7 6 7
6 b10 7 ¼ 6 0:0317 7
6 b11 7 6 0:0951 7
6 7 6 7
4 b12 5 4 0:0951 5
b13 0:0317

Organize the coefficients for denominator and numerator as below. Note that the
a10 is always one.
6.3 IIR Filters 475

a1 ¼ ½1:0000  1:4590 0:9104  0:1978T

b1 ¼ ½0:0317 0:0951 0:0951 0:0317T

If further iterations are required, execute the prefiltering with updated coefficient
a1 and follow the procedures for new a2 and b2 coefficient. Perform the iterative
procedures until the results converge to the optimal values. In this case, the a1 and
a2 provide the identical result as Hd ðzÞ: The final Steiglitz-McBride ARMA filter is
below.
1 2 3
þ 0:0951z þ 0:0951z þ 0:0317z
H ðzÞ ¼ 0:0317
11:4590z1 þ 0:9104z2 0:1978z3

The corresponding time domain representation is below.

y½n  1:4590y½n  1 þ 0:9104y½n  2  01978y½n  3


¼ 0:0317x½n þ 0:0951x½n  1 þ 0:0951x½n  2 þ 0:0317x½n  3

Figure 6.83 represents the frequency response and impulse of the filter. The
passband satisfies the Table 6.35 specification as halfpower frequency requirement.
Note that the horizontal line in the figures denote halfpower frequency requirement.

1 Response 0 -3dB
Passband
)|

Response
-10 Passband
j

0.5
|H(e

20log |H(ej )| (dB)

-20
0
0 500 1000 1500 2000 2500 3000 3500 4000
-30
Frequency (Hz)
10

0.3 -40

0.2
h[n]

0.1 -50

0
-0.1 -60
0 5 10 15 20 25 0 500 1000 1500 2000 2500 3000 3500 4000
n Frequency (Hz)

Fig. 6.83 Frequency response and impulse response of designed Steiglitz-McBride method for
Table 6.35
476 6 Filter Design

Prog. 6.61 MATLAB program for Fig. 6.83.


K = 3;, M = 3;, N = 3;, Q = 1;, L = 7;
% K: Given filter order, M: Pole order, N: Zero order, Q:Iteration number
pb = linspace(0,1000,501);
sb = linspace(2000,4000,2001);
a = [1 -1.4590 0.9104 -0.1978]; % Designed Bu erworth
b = [0.0317 0.0951 0.0951 0.0317];
[h0,t0] = impz(b,a); % Desired impulse response
h = h0(1:L);
[~,a0] = prony(h,0,K); % Ini al A(z) guess
x0 = [1; zeros(L-1,1)]; % Delta input for the system
aa = a0;
for kk = 1:Q
y = filter(1,aa,h);
x = filter(1,aa,x0);
Y1 = toeplitz(y,[y(1); zeros(L-1,1)]);
X1 = toeplitz(x,[x(1); zeros(L-1,1)]);
Y2 = Y1(1:L,1:M+1);
X2 = X1(1:L,1:N+1);
HH = [-Y2(:,2:end) X2];
coefs = HH\y;
aa = [1; coefs(1:M)];
bb = coefs(M+1:end);
end
[h00,w00] = freqz(bb,aa,1000,8000);
[hh00,t00] = impz(bb,aa);
hpb0 = freqz(bb,aa,pb,8000);
hsb0 = freqz(bb,aa,sb,8000);

figure,
subplot(211),plot(w00,abs(h00),pb,abs(hpb0),'.-'), grid, ylim([0 1.1]);
xlabel('Frequency (Hz)')
line([0 4000],[1/sqrt(2) 1/sqrt(2)]);
legend('Response','Passband')
subplot(212), stem(t00,hh00), grid, xlim([0 25]), ylim([-0.1 0.4]);
xlabel('n')
figure
plot(w00,db(h00),pb, db(hpb0),'.-'), grid, ylim([-60 2])
line([0 4000],[db(1/sqrt(2)) db(1/sqrt(2))]);
legend('Response','Passband')
xlabel('Frequency (Hz)')
6.3 IIR Filters 477

The impulse response in above figure also exactly follows hd[n] in Fig. 6.82.
This example exercised the Steiglitz-McBride ARMA filter with model and order
matching condition. The derived result from the Steiglitz-McBride method shows
the completely identical outcome. Filter model and order mismatch situation could
generate the significant performance degradation in frequency response as well as
impulse response. Therefore, we need to be aware of matching problem from
parametric filter design method.

Frequency transformation in IIR filter


The previously designed IIR filters such as Butterworth (Maxflat), Type I
Chebyshev, Type II Chebyshev, and Elliptic filter are derived for the LPF. Other
types of filter cannot be designed from the IIR filter method directly. The frequency
transformation changes the filter type from the prototype LPF. The transformation
can be performed in s (Laplace transform) or z (z transform) domain. We only
consider the z domain transformation in this book. The fundamental transformation
form is shown in Eq. (6.262).

Hd ðzÞ ¼ H ðHt ðzÞÞ ð6:262Þ

The desired type transfer function Hd(z) is obtained from the prototype LPF H
(z) with replacement transformation function Ht(z) as shown above. The transfor-
mation function Ht(z) is the allpass mapping filter which is the extension of allpass
filter shown in Eq. (6.114). To determine the transformation function, we have to
locate the frequency locations of the selected feature as shown in Fig. 6.84.
Halfpower frequencies are chosen for the feature.
Table 6.36 demonstrates the conventional transformation functions with feature
frequencies indicated by Fig. 6.84. The z in the prototype filter is replaced with
Ht(z) for preferred filter type. The further derivation and extension of the trans-
formation functions can be found on reference [30].
After the transformation, the new type filter shows the below rational polynomial
function. The order of numerator and denominator could be increased because of
the transformation function order.

b0 þ b1 z1 þ b2 z2 þ    þ bN zN


H d ðzÞ ¼
1 þ a1 z1 þ a2 z2 þ    þ aM zM ð6:263Þ
b0 ð1d1 ejl1 z1 Þð1d2 ejl2 z1 Þ...ð1dN ejlN z1 Þ
¼ ð1c1 ejc1 z1 Þð1c2 ejc2 z1 Þ...ð1cM ejcM z1 Þ
478 6 Filter Design

ωorg To HPF ωtar

-π π -π π

ωorg To BPF
ωtar1 ωtar2

-π π -π π

ωorg To BSF
ωtar1 ωtar2

-π π -π π

Fig. 6.84 Spectral distribution and feature frequencies of frequency transformation example

Table 6.36 Transformation functions and parameters


Transform property Transform function Ht(z) Parameters
   
LPF ! HPF 1
 1aþþazz 1 cosð1ðxorg þ xtar ÞÞ
a ¼  cos 21 x x
ð2ð org tar ÞÞ
 
LPF ! BPF abð1 þ aÞz1 þ z2
 1b xbw ¼ jxtar2  xtar1 j
1
ð1 þ aÞz þ az 2
sinð1ðxorg xbw ÞÞ
a ¼ sin 12 x þ x
ð2ð org bw ÞÞ
cosð12ðxtar1 þ xtar2 ÞÞ
b¼ cosð12xbw Þ
 
LPF ! BSF abð1 þ aÞz1 þ z2 xbw ¼ jxtar2  xtar1 j
1bð1 þ aÞz1 þ az2
cosð1ðxorg þ xbw ÞÞ
a ¼ cos 21 x x
ð2ð org bw ÞÞ
cosð12ðxtar1 þ xtar2 ÞÞ
b¼ cosð12xbw Þ
6.3 IIR Filters 479

The transformation could provide the filter instability by placing the poles at unit
circle outside. Using the allpass filter property in Eq. (6.122), poles are relocated
into the unit circle area. Also, the zeros are moved into the unit circle inside for
minimum phase filter as shown in Eq. (6.264).

1  r1 ejh1 z1 1  r1 ejh1 z1 z1  r0 ejh0 z1  r1 ejh1


H ð zÞ ¼ ¼
1  r0 ejh0 z1 1  r0 ejh0 z1 z1  r0 ejh0 z1  r1 ejh1
z1  r1 ejh1 z1  r0 ejh0 1  r1 ejh1 z1 z1  r1 ejh1
¼ 1 ¼ Hap1 ðzÞHap2 ðzÞ ð6:264Þ
z  r0 ejh0 1  r0 ejh0 z1 z1  r1 ejh1 z1  r0 ejh0
   
 1 ejh1 z1  z1 r1 ejh1 
)1r
1r ejh0 z1
 ¼ z1 r ejh0 wherejr0 j [ 1 andjr1 j [ 1
0 0

The new rational function is derived as below with gain adjustment parameter
w. Note that, even with identical poles and zeros, the filter magnitude presents
various distributions with identical shape.

b0 þ b1 z1 þ b2 z2 þ    þ bN zN


H d ðzÞ ¼
1 þ a1 z1 þ a2 z2 þ    þ aM zM ð6:265Þ
P&Z relocations wðb0 þ b1 z1 þ b2 z2 þ  þ bN zN Þ
! 1 þ a1 z1 þ a2 z2 þ  þ aM zM ¼ Hdsta ðzÞ

Once the transformation and pole & zero relocations are performed, the filter
gain should be adjusted to obtain identical amplitude at the reference point such as
zero frequency. Derive the w parameter based on Eq. (6.266).
   
Hd ðej0 Þ2 ¼ Hdsta ðej0 Þ2 ð6:266Þ

Example 6.26
In previous example, the Butterworth method presented the following ARMA IIR
LPF to meet 1000 Hz halfpower frequency based on the 8000 Hz sampling
frequency.

0:0317 þ 0:0951z1 þ 0:0951z2 þ 0:0317z3


H ðzÞ ¼
1  1:4590z1 þ 0:9104z2  0:1978z3

The corresponding pole zero plot is below.


Based on the given LPF, design the following filters.
480 6 Filter Design

1. HPF with 3000 Hz halfpower frequency.


2. BPF with passband between 1000 Hz and 3000 Hz as halfpower frequency.
3. BSF with stopband between 1000 Hz and 3000 Hz as halfpower frequency.
Solution
Transformation is performed as below for HPF with 3000 Hz halfpower frequency.
The feature frequencies from protype and target filter are shown as well.

3 
0:0317 þ 0:0951z1 2
0 þ 0:0951z0 þ 0:0317z0 
HHPF0 ðzÞ ¼ 3 
1  1:4590z1 2
0 þ 0:9104z0  0:1978z0 z0 ¼ðz1 Þ

p 3p
where xorg ¼ ; xtar ¼ ; and a ¼ 0
4 4

The derived HPF is below.

0:1603 þ 0:4808z1  0:4808z2 þ 0:1603z3


HHPF0 ðzÞ ¼
1 þ 4:6026z1 þ 7:3761z2 þ 5:0556z3

The pole zero plot of the above transfer function indicates the unstable filter due
to the poles located at unit circle outside as shown in Fig. 6.86. By reflecting the
poles into the unit circle, the filter demonstrates the stable property as shown in
Fig. 6.86.

Fig. 6.85 Pole zero plot of 1


Butterworth LPF
0.8
0.6
Imaginary Part

0.4
0.2
3
0
-0.2
-0.4
-0.6
-0.8
-1
-1 -0.5 0 0.5 1
Real Part
6.3 IIR Filters 481

1
1 0.8
0.6

Imaginary Part
Imaginary Part

0.5 0.4
0.2
3 3
0 0
-0.2
-0.5 -0.4
-0.6
-1
-0.8
-1
-2.5 -2 -1.5 -1 -0.5 0 0.5 1 -1 -0.5 0 0.5 1
Real Part Real Part

Fig. 6.86 Pole zero plot of HPF from transformation (left) and reflection (right)

The transformed and reflected filter is shown in below.

0:0317 þ 0:0951z1  0:0951z2 þ 0:0317z3


HHPF1 ðzÞ ¼
1 þ 1:4590z1 þ 0:9104z2 þ 0:1978z3

The frequency response of above transfer function is shown in Fig. 6.87.

HPF
Response
1 Passband

0.8
)|

0.6
j
|H(e

0.4

0.2

0
0 500 1000 1500 2000 2500 3000 3500 4000
Frequency (Hz)

Fig. 6.87 Frequency response of transformed and reflected HPF


482 6 Filter Design

Prog. 6.62 MATLAB program for Fig. 6.85 * Fig. 6.87.

syms s z;
pb0 = linspace(0,1000,501);
pb1 = linspace(3000,4000,501);
a = [1 -1.4590 0.9104 -0.1978]; % Designed Bu erworth
b = [0.0317 0.0951 0.0951 0.0317];
figure, zplane(b,a);
worg = sym('pi')/4;
wtar = 3*sym('pi')/4;
alp = -(cos((1/2)*(worg+wtar))/cos((1/2)*(worg-wtar)));
z1 = -(alp+z^-1)/(1+alp*z^-1);
nums = poly2sym(b,s);
dens = poly2sym(a,s);
Hs = nums/dens;
Hz = (subs(Hs,s,z1));
[numz, denz] = numden(Hz);
b0 = sym2poly(numz);
a0 = sym2poly(denz);
figure, zplane(b0,a0);
b1 = polystab(b0)*norm(b0)/norm(polystab(b0)); % Relocate zero for min
phase
a1 = polystab(a0)*norm(a0)/norm(polystab(a0)); % Relocate pole for
stability
figure, zplane(b1,a1);
[h0,w0] = freqz(b,a,1000,8000);
[h1,w1] = freqz(b1,a1,1000,8000);
hpb0 = freqz(b,a,pb0,8000);
hpb1 = freqz(b1,a1,pb1,8000);

figure,
plot(w1,abs(h1),pb1,abs(hpb1),'.-'), grid, ylim([0 1.1])
xlabel('Frequency (Hz)')
ylabel('|H(e^{j\omega})|')
line([0 4000],[1/sqrt(2) 1/sqrt(2)]);
legend('Response','Passband')
tle('HPF')
Transformation is performed as below for BPF with passband between 1000 Hz
and 3000 Hz as halfpower frequency. The feature frequencies from protype and
target filter are shown as well.

3 
0:0317 þ 0:0951z1 2
0 þ 0:0951z0 þ 0:0317z0 
HBPF0 ðzÞ ¼ 3   ffi 
1  1:4590z1 2
0 þ 0:9104z0  0:1978z0 z0 ¼
p
1 2 p ffi
þ z2
1 þ ð1 2Þz2
6.3 IIR Filters 483

50 1
40 0.8
30 0.6
Imaginary Part

Imaginary Part
20 0.4
10 0.2
33 3 3
0 0
-10 -0.2
-20 -0.4
-30 -0.6
-40 -0.8
-50 -1
-60 -40 -20 0 20 40 60 -1 -0.5 0 0.5 1
Real Part Real Part

Fig. 6.88 Pole zero plot of BPF from transformation (left) and reflection (right)

p p 3p pffiffiffi
where xorg ¼ ; xtar1 ¼ ; xtar2 ¼ ; a ¼ 1  2; and b ¼ 0
4 4 4

The derived BPF is below.

0:2085  0:6253z2  0:6253z4  0:2085z3


HBPF0 ðzÞ ¼
1:0000  4169:8z2 þ 1:8571z4  12503z6

The pole zero plot of the above transfer function indicates the unstable filter due to
the poles located at unit circle outside as shown in Fig. 6.88. By reflecting the poles
into the unit circle, the filter demonstrates the stable property as shown in Fig. 6.88.
The zeros reflections do not change any zero locations since all zeros are on unit circle.
The transformed and reflected filter is shown in below.

0:1667 þ 5:3541 108 z1 0:5002z2


7 3
1:0708 10 z þ 0:5002z þ 5:3540 10 z 0:1667z 4 8 5 6
HBPF1 ðzÞ ¼ 1:00001:5543 1015 z1 1:4854 104 z2 þ 7:2164 1016 z3
þ 3:3351 101 z4 þ 9:6223 1019 z5 7:9981 105 z6

The frequency response of above transfer function is shown in Fig. 6.89.

Fig. 6.89 Frequency BPF


response of transformed and
Response
reflected BPF 1 Passband

0.8
)|

0.6
j
|H(e

0.4

0.2

0
0 500 1000 1500 2000 2500 3000 3500 4000
Frequency (Hz)
484 6 Filter Design

Prog. 6.63 MATLAB program for Figs. 6.88 and 6.89.

syms s z;
pb0 = linspace(0,1000,501);
pb1 = linspace(1000,3000,501);
a = [1 -1.4590 0.9104 -0.1978]; % Designed Bu erworth
b = [0.0317 0.0951 0.0951 0.0317];
worg = sym('pi')/4;
wtar1 = sym('pi')/4;
wtar2 = 3*sym('pi')/4;
wbw = abs(wtar2-wtar1);
alp = (sin((1/2)*(worg-wbw))/sin((1/2)*(worg+wbw)));
bet = cos((1/2)*(wtar1+wtar2))/cos((1/2)*wbw);
z1 = -(alp-bet*(1+alp)*z^-1+z^-2)/(1-bet*(1+alp)*z^-1+alp*z^-2);
nums = poly2sym(b,s);
dens = poly2sym(a,s);
Hs = nums/dens;
Hz = (subs(Hs,s,z1));
[numz, denz] = numden(Hz);
b0 = sym2poly(numz);
a0 = sym2poly(denz);
figure, zplane(b0,a0);
b1 = polystab(b0)*norm(b0)/norm(polystab(b0)); % Relocate zero for min
phase
a1 = polystab(a0)*norm(a0)/norm(polystab(a0)); % Relocate pole for
stability
figure, zplane(b1,a1);
[h0,w0] = freqz(b,a,1000,8000);
[h1,w1] = freqz(b1,a1,1000,8000);
hpb0 = freqz(b,a,pb0,8000);
hpb1 = freqz(b1,a1,pb1,8000);

figure,
plot(w1,abs(h1),pb1,abs(hpb1),'.-'), grid, ylim([0 1.1])
xlabel('Frequency (Hz)')
ylabel('|H(e^{j\omega})|')
line([0 4000],[1/sqrt(2) 1/sqrt(2)]);
legend('Response','Passband')
tle('BPF')

Transformation is performed as below for BSF with stopband between 1000 Hz


and 3000 Hz as halfpower frequency. The feature frequencies from protype and
target filter are shown as well.
6.3 IIR Filters 485


3 
0:0317 þ 0:0951z1 2
0 þ 0:0951z0 þ 0:0317z0 
HBSF0 ðzÞ ¼
1  1:4590z1 2 3   pffi21 þ z2 
0 þ 0:9104z0  0:1978z0 z0 ¼ pffi
1 þ ð 21Þz2

p p 3p pffiffiffi
where xorg ¼ ; xtar1 ¼ ; xtar2 ¼ ; a ¼ 2  1; and b ¼ 0
4 4 4

The derived BSF is below.

2:0845 103 þ 6:2534 103 z2 þ 6:2534 103 z4 þ 2:0845 103 z6
HBSF0 ðzÞ ¼
1:0000 þ 4:1698 103 z2 þ 1:8571z4 þ 1:2503 104 z6

The pole zero plot of the above transfer function indicates the unstable filter due
to the poles located at unit circle outside as shown in Fig. 6.90. By reflecting the
poles into the unit circle, the filter demonstrates the stable property as shown in
Fig. 6.90. The zeros reflections do not change any zero locations since all zeros are
on unit circle.
The transformed and reflected filter is shown in below.

1:6672 101 þ 3:7334 1016 z1 þ 5:0015 101 z2


2:5183 1016 z3 þ 5:0015 101 z4 6:2516 1016 z5 þ 1:6671 101 z6
HBSF1 ðzÞ ¼ 1:0000 þ 1:7764 1015 z1 þ 1:4854 104 z2
7:7716 1016 z3 þ 3:3351 101 z4 1:4908 1019 z5 þ 7:9981 105 z6

The frequency response of above transfer function is shown in Fig. 6.91.

1 3
60
0.8
40 0.6
Imaginary Part

Imaginary Part

0.4
20
3 0.2
3 0
0
-0.2
-20
-0.4
-40 -0.6
-0.8
-60 -1 3

-80 -60 -40 -20 0 20 40 60 80 -1 -0.5 0 0.5 1


Real Part Real Part

Fig. 6.90 Pole zero plot of BSF from transformation (left) and reflection (right)
486 6 Filter Design

Prog. 6.64 MATLAB program for Figs. 6.90 and 6.91.

syms s z;
pb0 = linspace(0,1000,501);
pb1 = linspace(0,1000,501);
pb2 = linspace(3000,4000,501);
a = [1 -1.4590 0.9104 -0.1978]; % Designed Bu erworth
b = [0.0317 0.0951 0.0951 0.0317];
worg = sym('pi')/4;
wtar1 = sym('pi')/4;
wtar2 = 3*sym('pi')/4;
wbw = abs(wtar2-wtar1);
alp = (cos((1/2)*(worg+wbw))/cos((1/2)*(worg-wbw)));
bet = cos((1/2)*(wtar1+wtar2))/cos((1/2)*wbw);
z1 = (alp-bet*(1+alp)*z^-1+z^-2)/(1-bet*(1+alp)*z^-1+alp*z^-2);
nums = poly2sym(b,s);
dens = poly2sym(a,s);
Hs = nums/dens;
Hz = (subs(Hs,s,z1));
[numz, denz] = numden(Hz);
b0 = sym2poly(numz);
a0 = sym2poly(denz);
figure, zplane(b0,a0);
b1 = polystab(b0)*norm(b0)/norm(polystab(b0)); % Relocate zero for min
phase
a1 = polystab(a0)*norm(a0)/norm(polystab(a0)); % Relocate pole for
stability
figure, zplane(b1,a1);
[h0,w0] = freqz(b,a,1000,8000);
[h1,w1] = freqz(b1,a1,1000,8000);
hpb0 = freqz(b,a,pb0,8000);
hpb1 = freqz(b1,a1,pb1,8000);
hpb2 = freqz(b1,a1,pb2,8000);

figure,
plot(w1,abs(h1),pb1,abs(hpb1),'.-',pb2,abs(hpb2),'.-'), grid, ylim([0 1.1]);
xlabel('Frequency (Hz)');
ylabel('|H(e^{j\omega})|');
line([0 4000],[1/sqrt(2) 1/sqrt(2)]);
legend('Response','Passband','Passband');
tle('BSF');
6.3 IIR Filters 487

BSF
Response
1 Passband
Passband

0.8

)|
0.6
j
|H(e

0.4

0.2

0
0 500 1000 1500 2000 2500 3000 3500 4000
Frequency (Hz)

Fig. 6.91 Frequency response of transformed and reflected BSF

Following figures consolidate the prototype and transformed filter responses as


summary (Figure 6.92).

LPF HPF
Response Response
1 Passband 1 Passband

0.8 0.8
)|
)|

0.6 0.6
j
j
|H(e

|H(e

0.4 0.4

0.2 0.2

0 0
0 500 1000 1500 2000 2500 3000 3500 4000 0 500 1000 1500 2000 2500 3000 3500 4000

Frequency (Hz) Frequency (Hz)

BPF BSF
Response Response
1 Passband 1 Passband
Passband

0.8 0.8
)|

)|

0.6 0.6
j

j
|H(e

|H(e

0.4 0.4

0.2 0.2

0 0
0 500 1000 1500 2000 2500 3000 3500 4000 0 500 1000 1500 2000 2500 3000 3500 4000

Frequency (Hz) Frequency (Hz)

Fig. 6.92 Spectral distribution of frequency transformation example. LPF is prototype filter
488 6 Filter Design

Note that the Yule-walker, linear prediction, Prony, and Steiglitz-McBride filter
are the parametric methods which follow the impulse response of the unknown
filter. Therefore, no direct filter design is feasible from the given specification.
However, once the IIR filter is designed from the parametric method, the trans-
formation can be applied for the target filter type as shown in previous examples.
Impulse invariance
The classic s ðor jXÞ domain filter design for continuous time is transformed to
z domain by using bilinear transformation. The bilinear transformation converts the
complete X frequency range to the 2p x frequency range by wrapping the left-side
of s plane into the unit circle of z plane. The bilinear transformation is derived from
the frequency domain viewpoint. Time domain also provides the method to
transform the continuous to discrete time filter. The impulse invariance method [3,
7] samples the designed impulse response of continuous time filter with constant
period for discrete time IIR filter. The mathematical representation is below.

hd ½n ¼ Ts hc ðnTs Þ ð6:267Þ

Ts is sampling period and hc(t) is the impulse response of continuous time filter.
The direct sampling in time domain does not give the rational function for IIR filter.
The transfer function in s domain filter is required to derive the IIR filter in z do-
main. The partial fraction of the Laplace domain transfer function is below.

P
M
H c ðsÞ ¼ Gk
ssk ð6:268Þ
k¼1

The time domain impulse response is below.

P
M
hc ð t Þ ¼ G k es k t ð6:269Þ
k¼1

Sampling the response is below.

P
M P
M
n
Ts hc ðnTs Þ ¼ Ts Gk esk nTs ¼ Ts G k ð es k T s Þ ð6:270Þ
k¼1 k¼1

Build the H(z) based on the common ratio esk Ts as below.


M
P
1 P P
M
H ðzÞ ¼ Ts Gk ðe sk Ts n
Þ zn ¼ Ts Gk
1esk Ts z1
ð6:271Þ
n¼0 k¼1 k¼1
6.3 IIR Filters 489

The Fourier transform of the sampled impulse response is the repeated Hc ðjXÞ in
every sampling frequency fs as below.

X
1  
2p
FT ðhc ðnTs ÞÞ ¼ Hc jX þ j k
k¼1
Ts

Z1
where Hc ðjXÞ ¼ hc ðtÞejXt dt ð6:272Þ
1

According to Eq. (2.53), the sampling process provides the spectral duplication
in every 2p distance which represents the sampling frequency fs in cyclic frequency.
Figure 6.93 shows the spectral profile of LPF Hc ðjXÞ and sampled time filter in
cyclic frequency domain. In general, the continuous time filter cannot be ban-
dlimited; hence, the sampled time filter presents aliasing side effect due to the tails
from the consecutive spectral distributions. Beyond the fs/2 frequency, the
jFT ðhc ðnTs ÞÞj in Fig. 6.93 indicates the overlapping which may causes the per-
formance degradation in IIR filter in discrete time domain.

Fig. 6.93 Spectral


distribution of continuous
time filter and sampled time
filter
490 6 Filter Design

Prog. 6.65 MATLAB program for Fig. 6.93.

p = poly([6627.4*exp(j*2*pi/3) -6627.4 6627.4*exp(-j*2*pi/3)]); %


Bu erworth poles
w5 = -12000*2*pi:0.1:12000*2*pi;
h5 = freqs(291091517618.824,p,w5);
ofset = 8000*2*pi;

figure,
subplot(211), plot(w5/(2*pi),abs(h5)),grid
xlim([-12000 12000]);
x cks([-12000 -8000 -4000 0 4000 8000 12000]);
x cklabels({'-3f_s/2','-f_s','-f_s/2','0','f_s/2','f_s','3f_s/2'});
xlabel('Frequency (Hz)');
ylabel('|H_c(j\Omega)|');
subplot(212), plot(w5/(2*pi),abs(h5),(w5+ofset)/(2*pi),abs(h5),(w5-
ofset)/(2*pi),abs(h5)),grid
xlim([-12000 12000]);
x cks([-12000 -8000 -4000 0 4000 8000 12000]);
x cklabels({'-3f_s/2','-f_s','-f_s/2','0','f_s/2','f_s','3f_s/2'});
xlabel('Frequency (Hz)');
ylabel('|FT(h_c(nT_s))|');

The sampling frequency fs (or period Ts) cannot be used to control the aliasing in
impulse invariance method since the s domain and z domain poles are mutually
related. The pole locations in z domain are esk Ts in Eq. (6.271); therefore, the Ts
variation should trigger the sk modification to maintain the desired filter specifi-
cation. The impulse invariance method is proper to apply for the bandlimited filters
only. Otherwise, the designed filter suffers from the significant distortion in fre-
quency response.
Example 6.27
The Butterworth filter (fp = 1000 Hz, fst = 2000 Hz, and fs = 8000 Hz) before the
bilinear transformation with left s plane poles and the appropriate gain is shown
below.
6.3 IIR Filters 491

291091517618:824
H c ðsÞ ¼    
j2p
s  6627:4e ðs  6627:4ejp Þ s  6627:4ej 3
4p
3

Compare the impulse invariance with bilinear transformation.


Solution
Derive the partial fraction of the transfer function as below.

3826:3ej 6
5p 5p
6627:4 3826:3j 6
Hc ðsÞ ¼  þ þ 
s  6627:4ej 3
2p
ðs  6627:4e Þ
jp
s  6627:4ej 3
4p

The corresponding impulse response hc(t) is below.

j2p j4p
hc ðtÞ ¼ 3826:3ej 6 e6627:4e 3 t þ 6627:4eð6627:4Þt þ 3826:3j 6 e6627:4e 3 t
5p 5p

 
ð3313:7Þt 5p
¼ 7652:6e cos 5739:5t  þ 6627:4eð6627:4Þt
6

Apply the impulse invariance method on partial fraction Hc(s) as below.

3826:3ej 6
5p 5p
6627:4 3826:3j 6
Himp ðzÞ ¼  2p  þ   þ  4p 
1  e 8000 z1
6627:4 j 6627:4 6627:4 j
1  e 8000 e 3 z1 1  e 8000 e 3 z1
9:09495 1013 þ 1256:78z1 þ 727:066z2
¼
1  1:4326z1 þ 0:8717z2  0:1907z3

For reference, the transfer function from bilinear transformation method is


below.

0:0317 þ 0:0951z1 þ 0:0951z2 þ 0:0317z3


Hbil ðzÞ ¼
1  1:4590z1 þ 0:9104z2  0:1978z3
492 6 Filter Design

Prog. 6.66 MATLAB program for Fig. 6.94.

Ts = 1/8000;
= 0:Ts/100:22/8000;
p = poly([6627.4*exp(j*2*pi/3) -6627.4 6627.4*exp(-j*2*pi/3)]); %
Bu erworth poles
[r1,p1,k1] = residue(291091517618.824,p); % Par al frac on
[num,den] = residue(r1,exp(p1*Ts),[]);
[h0,w0] = freqz(num,den,1000,8000);
[h1,t1] = impz(num,den);
h2 = r1.*exp( .*p1);
b0 = [0.0317 0.095 0.0951 0.0317]; % Bu erworth
a0 = [1 -1.4590 0.9104 -0.1978];
[h4,w4] = freqz(b0,a0,1000,8000);
w5 = -12000*2*pi:0.1:12000*2*pi;
h5 = freqs(291091517618.824,p,w5);
ofset = 8000*2*pi;
figure,
subplot(211), plot(w0,abs(h0)*Ts), grid, hold on
xlabel('Frequency (Hz)')
ylabel('|H(e^{j\omega})|')
plot(w4, abs(h4)), hold off, ylim([0 1.1]);
line([0 4000],[1/sqrt(2) 1/sqrt(2)]);
line([0 4000],[0.1 0.1]);
legend('Impulse Inv.','Bilinear')
subplot(212), stem(t1*Ts,h1*Ts), grid, xlim([0 22/8000]), hold on
ylabel('T_sh_c(t) & h_d[n]')
plot( ,sum(h2)*Ts), hold off
xlabel('t (second)')
legend('Impulse Inv.','T_sh_c(t)')
figure,
subplot(211), plot(w5/(2*pi),db(abs(h5))),grid, xlim([-12000 12000])
x cks([-12000 -8000 -4000 0 4000 8000 12000]);
x cklabels({'-12000','-8000','-4000','0','4000','8000','12000'});
xlabel('Frequency (Hz)')
ylabel('20log_{10}(|H_c(j\Omega)|)')
subplot(212), plot(w5/(2*pi),db(abs(h5)),(w5+ofset)/(2*pi),db(abs(h5)),(w5-
ofset)/(2*pi),db(abs(h5))),grid, xlim([-12000 12000])
x cks([-12000 -8000 -4000 0 4000 8000 12000]);
x cklabels({'-12000','-8000','-4000','0','4000','8000','12000'});
xlabel('Frequency (Hz)')
ylabel('20log_{10}(|FT(h_c(nT_s))|)')
6.3 IIR Filters 493

Fig. 6.94 Spectral distribution of continuous time LPF and sampled time LPF on left.
Designed LPF frequency and impulse response by impulse invariance and bilinear transformation
method on right

Figure 6.94 demonstrates the jHc ðjXÞj and jFT ðhc ðnTs ÞÞj for designed LPF from
Butterworth. Also, the figure shows the frequency response from impulse invari-
ance and bilinear transformation method. The impulse invariance method samples
the continuous time filter in every Ts interval on the figure as well. According to the
frequency response, the impulse invariance method does not meet the LPF
requirement from Table 6.27 (fp = 1000 Hz, fst = 2000 Hz, and Dst = 20 dB).

Because of the frequency aliasing distorting by neighbor distributions, the
impulse invariance presents the higher magnitude in the frequency response. By
tightening the LPF requirement, the impulse invariance provides the adequate
performance in the design LPF. The impulse invariance method could require the
multiple iterations to verify the filter performance. On the other hand, the bilinear
transformation reflects the complete left-hand area of s domain into the unit circle
area of z domain; hence, one trial of closed-form expression finds the optimal
solution in general. Table 6.37 summarizes the IIR filter design methods and cor-
responding MATLAB functions.
494 6 Filter Design

Table 6.37 Discrete-time IIR filter method summary and MATLAB functions
Filter method Function description MATLAB
functions
Analog Complete design butter, cheby1,
prototyping functions cheby2, ellip
(Based on the classical lowpass prototype Lowpass Butterworth maxflat
filter in s domain, obtain a digital filter by filters with more zeros
filter discretization.)
Order estimation buttord,
functions cheb1ord,
cheb2ord,
ellipord
Frequency iirlp2hp, iirlp2bp,
transformation iirlp2bs
functions
Filter discretization bilinear,
functions impinvar
Parametric modeling (Derive modelled Time-domain aryule(yulewalk),
digital filter which follows a prescribed time modeling functions lpc, prony, stmcb
domain response.)
Minimum phase Reflect the poles and polystab
zeros into unit circle
area

6.4 Problems

1. Compute the absolute magnitude of following decibel specifications.


– Passband magnitude: 0 dB
– Passband ripple: 0.1 dB
– Stopband attenuation: 80 dB
2. Calculate the cyclic, discrete, normalized frequency of following situations.
– f = 2000 Hz from fs= 10,000 Hz
– x ¼ p4 from fs= 10,000 Hz
– 34 normalized frequency from fs= 10,000 Hz
3. Design the FIR filter for following specification.

Filter specifications Value


Filter type Low pass filter
Filter realization FIR with hanning window
Filter length N with optimization
Passband frequency (fp) 2000 Hz; xp ¼ p=2
(continued)
6.4 Problems 495

(continued)
Filter specifications Value
Passband magnitude 0 dB
Passband ripple (peak to peak) 1 dB
Stopband frequency (fst) 3000 Hz; xst ¼ 3p=4
Stopband attenuation 40 dB
Sampling frequency (fs) 8000 Hz

4. Design the Problem 3 FIR filter with Kaiser window.


5. Design the FIR filter for following specification.

Filter specifications Value


Filter type Low pass filter
Filter realization FIR Type II without window method
Filter length N with optimization
Passband frequency (fp) 2000 Hz; xp ¼ p=2
Passband magnitude 0 dB
Stopband frequency (fst) 3000 Hz; xst ¼ 3p=4
Sampling frequency (fs) 8000 Hz

6. Design the FIR filter for following specification.

Filter specifications Value


Filter type Band pass filter
Filter realization FIR Type III without window method
Filter length N = 16
Cutoff frequency 1 (fc1) 4000/3 Hz; xc1 ¼ p=3
Passband magnitude 0 dB
Cutoff frequency 2 (fc2) 8000/3 Hz; xc2 ¼ 2p=3
Sampling frequency (fs) 8000 Hz
496 6 Filter Design

7. Design the FIR filter for following specification.

Filter specifications Value


Filter type High pass filter
Filter realization FIR Type IV without window method
Filter length N with optimization
Passband frequency (fp) 3000 Hz; xp ¼ 3p=4
Passband magnitude 0 dB
Stopband frequency (fst) 2000 Hz; xst ¼ p=2
Sampling frequency (fs) 8000 Hz

8. Design the following FIR filter by using the Remes exchange algorithm.

Filter specifications Value


Filter type Low pass filter
Filter realization FIR Type I without windowing method
Filter length 7 (N = 6)
Passband frequency (fp) 2000 Hz; xp ¼ p=2
Passband magnitude 0 dB
Stopband frequency (fst) 3000 Hz; xst ¼ 3p=4
Sampling frequency (fs) 8000 Hz

9. Design the FIR filter by using the frequency sampling method based on the
Problem 8 specification.
10. Design the FIR filter by using the least squared error frequency domain method
based on the Problem 8 specification.
11. Design the following FIR filter by using the constrained least square method.
MATLAB realization only.

Filter specifications Value


Filter type Low pass filter
Filter realization FIR Type I without window method
Filter length Optimal value from window
Passband frequency (fp) 2000 Hz; xp ¼ p=2
Passband magnitude 0 dB
Passband ripple (peak to peak) 1 dB
(continued)
6.4 Problems 497

(continued)
Filter specifications Value
Stopband frequency (fst) 3000 Hz; xst ¼ 3p=4
Stopband attenuation 40 dB
Sampling frequency (fs) 8000 Hz

12. Design the following FIR filter by using the complex and nonlinear-phase
equiripple method. MATLAB realization only.

13. For the given filter below, design the minimum phase FIR filter.

h½n ¼ d½n þ 4d½n  4

14. Design the following IIR filter by using Butterworth method and bilinear
transformation.

Filter specifications Value


Filter type Low pass filter
Filter realization Butterworth IIR
Filter length N with optimization
Passband frequency (fp) 2000 Hz; xp ¼ p=2
Passband magnitude 1
Passband peak-to-peak ripple in decibel ðDp Þ 3.0103 dB
Stopband frequency (fst) 3000 Hz; xst ¼ 3p=4
1
Stopband attenuation in decibels Dst 20 log10 0:1 ¼ 20 dB
Sampling frequency (fs) 8000 Hz

15. Design the following IIR filter by using Type I Chebyshev method and bilinear
transformation.
498 6 Filter Design

Filter specifications Value


Filter type Low pass filter
Filter realization Type I Chebyshev IIR filter
Filter length N with optimization
Passband frequency (fp) 2000 Hz; xp ¼ p=2
Passband magnitude 1
 
Passband peak-to-peak ripple in decibel ðDp Þ 20 log10 1=p1ffiffiffiffiffiffiffi
ffi ¼ 3:0103 dB
1þ1

Stopband frequency (fst) 3000 Hz; xst ¼ 3p=4


1
Stopband attenuation in decibels Dst 20 log10 0:1 ¼ 20 dB
Sampling frequency (fs) 8000 Hz

16. Design the following IIR filter by using Type II Chebyshev method and bilinear
transformation.

Filter specifications Value


Filter type Low pass filter
Filter realization Type II Chebyshev IIR filter
Filter length N with optimization
Passband frequency (fp) 2000 Hz; xp ¼ p=2
Passband magnitude 1
 
Passband peak-to-peak ripple in decibel ðDp Þ 20 log10 1=p1ffiffiffiffiffiffiffi
ffi ¼ 3:0103 dB
1þ1

Stopband frequency (fst) 3000 Hz; xst ¼ 3p=4


1
Stopband attenuation in decibels Dst 20 log10 0:1 ¼ 20 dB
Sampling frequency (fs) 8000 Hz

17. Design the following IIR filter by using elliptic method and bilinear transfor-
mation.

Filter specifications Value


Filter type Low pass filter
Filter realization Elliptic IIR filter
Filter length N with optimization
Passband frequency (fp) 2000 Hz; xp ¼ p=2
Passband magnitude 1
 
Passband peak-to-peak ripple in decibel ðDp Þ 20 log10 1=p1ffiffiffiffiffiffiffi
ffi ¼ 3:0103 dB
1þ1
(continued)
6.4 Problems 499

(continued)
Filter specifications Value
Stopband frequency (fst) 3000 Hz; xst ¼ 3p=4
1
Stopband attenuation in decibels Dst 20 log10 0:1 ¼ 20 dB
Sampling frequency (fs) 8000 Hz

18. Design the AR filter based on the Yule-walker algorithm which estimates the
coefficients of the unknown AR filter Hd(z) with given 2nd order.

0:25
H d ðzÞ ¼
1  1:2z1 þ 0:45

19. Design the following IIR filter by using maxflat method. MATLAB realization
only with maxflat function.

Filter specifications Value


Filter type Low pass filter
Filter realization Maxflat IIR
Filter length Numerator order = 9
Denominator order = 3
Halfpower frequency (fh) 2000 Hz; xh ¼ p=2
Passband magnitude 1
Sampling frequency (fs) 8000 Hz

20. Design the ARMA filter based on the Prony algorithm which estimates the
coefficients of the unknown ARMA filter Hd(z) with given 2nd order.

0:10100 þ 0:06172z1 þ 0:09659z2


H d ðzÞ ¼
1  1:26174z1 þ 0:62847z2

21. Design the ARMA filter based on the Steiglitz-McBride method which esti-
mates the coefficients of the unknown ARMA filter Hd(z) with given 2nd order.

0:10100 þ 0:06172z1 þ 0:09659z2


H d ðzÞ ¼
1  1:26174z1 þ 0:62847z2
500 6 Filter Design

22. The Elliptic method presented the following ARMA IIR LPF to meet 1000 Hz
halfpower frequency based on the 8000 Hz sampling frequency.

0:10100 þ 0:06172z1 þ 0:09659z2


H ðzÞ ¼
1  1:26174z1 þ 0:62847z2

Based on the given LPF, design the following filters by using the transformation
functions
– HPF with 3000 Hz halfpower frequency.
– BPF with passband between 1000 Hz and 3000 Hz as halfpower frequency.
– BSF with stopband between 1000 Hz and 3000 Hz as halfpower frequency.
23. The Type I Chebyshev IIR filter (fp = 1000 Hz, fst = 2000 Hz, and
fs = 8000 Hz) before the bilinear transformation with left s plane poles and the
appropriate gain is shown below.

21960983:69
Hc ðsÞ ¼
s2 þ 4265:4s þ 31057520:98

Compare the impulse invariance with bilinear transformation.

References

1. Hewitt, E., Hewitt, R.E.: The Gibbs-Wilbraham phenomenon: An episode in fourier analysis.
Arch. Hist. Exact Sci. 21(2), 129–160 (1979). https://doi.org/10.1007/BF00330404
2. Hazewinkel, M.: Encyclopaedia of Mathematics: Orbit—Rayleigh Equation. Springer,
Netherlands (2012)
3. Oppenheim, A.V., Schafer, R.W.: Discrete-Time Signal Processing. Prentice Hall, (1989)
4. Kaise, J.F.: Nonrecursive digital filter design using the I0-Sinh window function. In: IEEE
International Symposium on Circuits and Systems, San Francisco, California, USA, 22–25
April 1974. IEEE
5. Marple, S.L.: Computing the discrete-time ‘analytic’ signal via FFT. In: Conference Record
of the Thirty-First Asilomar Conference on Signals, Systems and Computers (Cat.
No.97CB36136), 2–5 November 1997, vol.1322, pp. 1322–1325 (1997)
6. Rabiner, L.R., McClellan, J.H., Parks, T.W.: FIR digital filter design techniques using
weighted Chebyshev approximation. Proc. IEEE 63(4), 595–610 (1975). https://doi.org/10.
1109/PROC.1975.9794
7. Parks, T.W., Burrus, C.S.: Digital Filter Design. Wiley, (1987)
8. Jackson, L.B.: Digital Filters and Signal Processing, 3rd edn. Kluwer Academic Publishers,
Boston (1996)
9. Wikipedia: Unitary matrix (2020). https://en.wikipedia.org/w/index.php?title=Unitary_
matrix&oldid=961644790
10. Wikipedia: Conjugate transpose (2020). https://en.wikipedia.org/w/index.php?title=
Conjugate_transpose&oldid=961399224
11. Wikipedia: Vandermonde matrix (2020). https://en.wikipedia.org/w/index.php?title=
Vandermonde_matrix&oldid=965588394
References 501

12. Wikipedia: Moore–Penrose inverse (2020). https://en.wikipedia.org/w/index.php?title=Moore


%E2%80%93Penrose_inverse&oldid=961651512
13. Selesnick, I.W., Lang, M., Burrus, C.S.: Constrained least square design of FIR filters without
specified transition bands. IEEE Trans. Signal Process. 44(8), 1879–1892 (1996). https://doi.
org/10.1109/78.533710
14. Wikipedia: Lagrange multiplier (2020). https://en.wikipedia.org/w/index.php?title=Lagrange_
multiplier&oldid=964661260
15. Wikipedia: Karush–Kuhn–Tucker conditions (2020). https://en.wikipedia.org/w/index.php?
title=Karush%E2%80%93Kuhn%E2%80%93Tucker_conditions&oldid=966216684
16. Karam, L.J., McClellan, J.H.: Complex Chebyshev approximation for FIR filter design. IEEE
Trans. Circuits Syst. II: Analog. Digit. Signal Process. 42(3), 207–216 (1995). https://doi.org/
10.1109/82.372870
17. Butterworth, S.: On the theory of filter amplifiers. Exp. Wirel. Wirel. Eng. 7, 536–541 (1930)
18. Wikipedia: Chebyshev polynomials. https://en.wikipedia.org/w/index.php?title=Chebyshev_
polynomials&oldid=962339092 (2020)
19. Wikipedia: Elliptic rational functions (2020). https://en.wikipedia.org/w/index.php?title=
Elliptic_rational_functions&oldid=946797692
20. Stoica, P., Moses, R.L.: Introduction to Spectral Analysis. Prentice Hall (1997)
21. Yule, G.U.: On a method of investigating periodicities in disturbed series, with special
reference to Wolfer’s sunspot numbers. Philos. Trans. R. Soc. Lond. Ser. A (Containing
Papers of a Mathematical or Physical Character) 226, 267–298 (1927)
22. Walker, G.T.: On periodicity in series of related terms. Proc. R. Soc. Lond. Ser.
A (Containing Papers of a Mathematical and Physical Character) 131(818), 518–532
(1931). https://doi.org/10.1098/rspa.1931.0069
23. Selesnick, I.W., Burrus, C.S.: Generalized digital Butterworth filter design. In: 1996 IEEE
International Conference on Acoustics, Speech, and Signal Processing Conference
Proceedings, 9–9 May 1996, vol. 1363, pp. 1367–1370 (1996)
24. Herrmann, O.: On the approximation problem in nonrecursive digital filter design. IEEE
Trans. Circuit Theory 18(3), 411–413 (1971). https://doi.org/10.1109/TCT.1971.1083275
25. Makhoul, J.: Linear prediction: a tutorial review. Proc. IEEE 63(4), 561–580 (1975). https://
doi.org/10.1109/PROC.1975.9792
26. Papoulis, A.: Probability, Random Variables, and Stochastic Processes. McGraw-Hill (1991)
27. Kay, S.M.: Fundamentals of Statistical Signal Processing. Estimation Theory, vol. 1. Prentice
Hall (1993)
28. Hauer, J.F., Demeure, C.J., Scharf, L.L.: Initial results in Prony analysis of power system
response signals. IEEE Trans. Power Syst. 5(1), 80–89 (1990). https://doi.org/10.1109/59.
49090
29. Steiglitz, K., McBride, L.: A technique for the identification of linear systems. IEEE Trans.
Autom. Control. 10(4), 461–464 (1965). https://doi.org/10.1109/TAC.1965.1098181
30. Constantinides, A.G.: Spectral transformations for digital filters. Proc. Inst. Electr. Eng. 117
(8), 1585–1590 (1970). https://doi.org/10.1049/piee.1970.0281
31. Yeong Ho, H., Pearce, J.A.: A new window and comparison to standard windows. IEEE
Trans. Acoust. Speech Signal Process. 37(2), 298–301 (1989). https://doi.org/10.1109/29.
21693
32. Harris, F.J.: On the use of windows for harmonic analysis with the discrete Fourier transform.
Proc. IEEE 66(1), 51–83 (1978). https://doi.org/10.1109/PROC.1978.10837
33. Elliott, D.F.: Handbook of Digital Signal Processing. Academic, New York (1987)
34. D’Antona, G., Ferrero, A.: Digital Signal Processing for Measurement Systems: Theory and
Applications. Springer, US (2006)
35. Nuttall, A.: Some windows with very good sidelobe behavior. IEEE Trans. Acoust. Speech
Signal Process. 29(1), 84–91 (1981). https://doi.org/10.1109/TASSP.1981.1163506
36. Brookner, E.: Practical Phased-array Antenna Systems. Artech House (1991)
Chapter 7
Implementation Matters

The previously explained filter design provided the proper type, method, and order
of the filter to meet the desired specification. Once we derived the transfer function
as Eq. (7.1), everything seems to be finalized.
ðN1Þ N
HðzÞ ¼ b0 þ1  þ bN1 z þ bN z
þ a1 z1 þ  þ aM zM
ð7:1Þ

From the transfer function above, we find the difference equation for time
domain realization. The filter output y½n is computed by the combination of
weighted inputs and outputs as shown in Eq. (7.2). The computation is performed
by the digital processors based on the binary number system.

y½n ¼ b0 x½n þ    þ bM x½n  M   a1 y½n  1     aN y½n  N  ð7:2Þ

Unfortunately, the computation is impossible to deliver due to the infinite pre-


cision of the real numbers. Note that the inputs, outputs, and coefficients are real
numbers. The time in the filter is discretized by the sampling process. In the same
manner, the inputs, outputs, and coefficients are required to be discretized for
storing and processing the values within the digital processor. The discretization
process for the magnitude is named as the quantization. Because of the limited
precision, the quantization process loses the information; therefore, we expect the
performance degradation of the filter. The various filter realization methods
demonstrate the distinctive sensitivity to the quantization error. The random nature
of the quantization error involves the statistical analysis which will be introduced in
rudimentary level.

© Springer Nature Singapore Pte Ltd. 2021 503


K. Kim, Conceptual Digital Signal Processing with MATLAB,
Signals and Communication Technology,
https://doi.org/10.1007/978-981-15-2584-1_7
504 7 Implementation Matters

7.1 Number Representations

– Binary numbers
In conventional computers and processors, the binary number is used for digital
arithmetic. The information is represented by the simple high (1) or low (0) of the
electrical voltage; therefore, the individual digit of the binary number contains the
one or zero only. According to the translation, the binary number can be converted
to the various conventional number systems. Frequently, the integer number is
utilized for the corresponding binary number. Equation (7.3) shows the B + 1 bit
binary number. Note that the digit in the binary number is known as a bit.

bB bB1 . . . b2 b1 b0 ð7:3Þ

The leftmost bB and rightmost b0 bit denotes the most significant bit (MSB) and
least significant bit (LSB), respectively. For integer conversion, we assume that the
binary point is placed after LSB. The weighted sum from sequential power of two
presents the unsigned integer value as below.

P
B
Unsigned integer ¼ bk 2k ð7:4Þ
k¼0

2’s complement method is employed for the signed integer from binary number.
The MSB signifies the negative number with highest weight as shown below. The
sum of all lower bits below the MSB is less than the single MSB weight; hence, the
MSB serves as the sign bit.

P
B1
Signed integer ¼ bB 2B þ bk 2k ð7:5Þ
k¼0

The unsigned and signed inter range are given as below. Observe that overall
integer range is identical for unsigned and signed representation with different
coverage.

0  Unsigned integer  2B þ 1  1
ð7:6Þ
2B  Signed integer  2B  1

Because of the limited size arithmetic in binary number, the overflow contam-
inates the computation result significantly. The binary addition and subtraction do
not break the arithmetic rules in the binary system. However, the carry-out from or
to the MSB ruins the decimal representation. Figure 7.1 is the binary arithmetic
diagram for 3-bit size. Note that unsigned integer is ranged from 0 to 7 and signed
integer is covered from −4 to 3.
7.1 Number Representations 505

ow
erfl y
Ov ndar
u
bo
0002 (010) 0002 (010)
1112 (710) Subtract 0012 (110) 1112 (-110) 0012 (110)

Subtract
Add

Add
1102 (610) Unsigned 0102 (210) 1102 (-210) Signed 0102 (210)

0112 (310) 0112 (310)


1012 (510) 1012 (-310)
1002 (410) 1002 (-410)
bo
u
Ov ndar
erfl y
ow

Fig. 7.1 Binary number arithmetic for 3-bit size and 2’s complement

The circular property of the binary number generates the abrupt representation in
decimal number. The impact of overflow is significant in signal description;
therefore, the overflow should be avoided or minimized within the possible limits.
– Floating point numbers
The real number can be represented by the floating-point number which uses the
power of the base with signed significand. The exponent and signed significand will
be represented by the binary number. The power base is implicitly specified in the
floating-point number system. Figure 7.2 is the example of floating-point number
with 10 base.
The floating-point number increases the dynamic range of the signal represen-
tation by storing the significand and exponent. The digital signal processing is
performed by the conventional computer or special processor; therefore, the signal
should be denoted by the binary number for execution. By converting the signifi-
cand and exponent to the binary number, we can use the very large or small
magnitude numbers in the system. Equation (7.7) is the small-scale example for
floating-point number by 8 bits.

b7 b6 b5 b4 b3 b2 b1 b0
|{z} |fflfflfflfflffl{zfflfflfflfflffl} |fflfflffl{zfflfflffl}
s e f ð7:7Þ
Floating point number10 ðFP#10Þ ¼ ð1Þs ð1:f  2e7 Þ10

The f mantissa and e exponent are represented by the unsigned binary number.
Note that the subscript 10 presents the decimal conversion. The biased exponent

Fig. 7.2 Floating-point Sign Mantissa Base


number example

-3.141592×10-3
Significand Exponent
506 7 Implementation Matters

shifts the numeric range to cover the signed number. To demonstrate the proper
significand, the binary point is located at the left of f MSB. Also, we assume that the
implicit 1 is comprised at the binary point left as shown below.

1:b2 b1 b0 ! 1 þ b2 21 þ b1 22 þ b0 23 ð7:8Þ

Below is the range of significand and exponent based on the above


configuration.

1  j1:f j  1:8750
ð7:9Þ
7  e  7  8

Therefore, the overall range of floating-point number absolute is below.

1  27  0:078  jFP#10j  1:8750  28 ¼ 480 ð7:10Þ

From the given 8-bit floating-point number, above range is divided into the 128
positive numbers and the corresponding identical negative numbers. Figure 7.3
depicts the 128 positive numbers for the floating-point number. Observe that the
vertical grids show the floating-point number positions.

0.5

0
0 50 100 150 200 250 300 350 400 450 500

0.5

0
0 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1

0.5

0
100 150 200 250 300 350 400 450 500
Floating-point # value

Fig. 7.3 128 positive numbers for the floating-point number with 8-bit configuration on Eq. (7.7)
7.1 Number Representations 507

Prog. 7.1 MATLAB program for Fig. 7.3.


ff = 0:1:7;
ee = -7:1:8;
fract = 1+ff*2^-3;
out = [];
for kk=1:length(ee)
out = [out fract.*2^ee(kk)];
end
figure
subplot(311), h = stem(out,ones(size(out)));, grid
h.Marker = 'none';
subplot(312), h = stem(out,ones(size(out)));, grid
h.Marker = 'none';
xlim([0 0.1])
subplot(313), h = stem(out,ones(size(out)));, grid
h.Marker = 'none';
xlim([100 500]);
xlabel('Floa ng-point # value');

Due to the exponent, the floating-point number shows the non-constant reso-
lution between adjacent numbers. The overall plot demonstrates the dense popu-
lation nearby the zero and coarse distribution around high. The other subplots
magnify the low and high zone to verify the observation.
The problems of the above configuration are zero and special numbers notations.
With the implicit 1 at the significant, no methods can be applied to define the zero.
The second subplot in Fig. 7.3 demonstrates the significant white region which
provides the descriptive void around zero. Also, the conventional computation
requires the infinity and not-a-number (NaN; 0/0) representation to describe the
unexpected results. The following bit reservation manages the special numbers.
The zero, infinity, and NaN are defined by the 8-bit floating point number as
shown in Table 7.1. The zero exponent denormalizes the significand to present the
values around zero. Note that the denormalization includes the exponent as the
second least (−6 not −7) value as shown in Eq. (7.11).
(  
ð1Þs  1:f  2e7 10 for 1  e  14 ðnormalizedÞ
FP#10 ¼   : ð7:11Þ
ð1Þs  0:f  26 10 for e ¼ 0 ðdenormalizedÞ

Table 7.1 Floating-point s e f Decimal # Remark


number bit configurations for
special numbers 02 00002 0002 0 Denormalized
12 00002 0002 −0 Denormalized
02 11112 0002 1
12 11112 0002 1
02 11112 6¼ 0002 NaN
12 11112 6¼ 0002 NaN
508 7 Implementation Matters

Following is the range of significand and exponent based on the above configuration.

1  j1:f j  1:8750 for e 6¼ 0 ðnormalizedÞ


0  j0:f j  0:8750 for e ¼ 0 ðdenormalizedÞ ð7:12Þ
6  e  7  7 exclude e ¼ 0 and 15

Therefore, overall range of floating-point number absolute is shown in Eq. (7.13).

0  jFP#10j  1:8750  27 ¼ 240 ð7:13Þ

The denormalized and normalized floating-point representation are depicted in


Fig. 7.4 with stems.

Prog. 7.2 MATLAB program for Fig. 7.4.


ff = 0:1:7;
ee = -6:1:7;
ee1 = -7:1:7;
fract1 = 1+ff*2^-3;
fract2 = ff*2^-3;
out1 = [];
out2 = [];
out1 = [out1 fract2.*2^-6];
for kk=1:length(ee)
out1 = [out1 fract1.*2^ee(kk)];
end
for qq=1:length(ee1)
out2 = [out2 fract1.*2^ee1(qq)];
end

figure,
subplot(311), h = stem(out1,ones(size(out1)));, grid
h.Marker = 'none';
ylabel('Denormalized')
subplot(312), h = stem(out1,ones(size(out1)));, grid
h.Marker = 'none';
x cks([0 1/128 1/64 1/32 1/16])
x cklabels({'0','1/128','1/64','1/32','1/16'})
xlim([0 1/16])
ylabel('Denormalized')
subplot(313), h = stem(out2,ones(size(out2)));, grid
h.Marker = 'none';
x cks([0 1/128 1/64 1/32 1/16])
x cklabels({'0','1/128','1/64','1/32','1/16'})
xlim([0 1/16])
ylabel('Normalized only')
xlabel('Floa ng-point # value')
7.1 Number Representations 509

Denormalized 1

0.5

0
0 50 100 150 200 250

1
Denormalized

0.5

0
0 1/128 1/64 1/32 1/16

1
Normalized only

0.5

0
0 1/128 1/64 1/32 1/16
Floating-point # value

Fig. 7.4 128 positive numbers for floating-point number with 8-bit length from denormalized and
normalized configuration

With denormalization, the dynamic range is decreased by the reduced exponent


limit as shown in Fig. 7.4. However, the denormalization stuffs the blank around
the zero (shown in third subplot of Fig. 7.4) with consistent floating-point numbers
(shown in second subplot of Fig. 7.4). Note that the infinities and NaN are not
presented in above figure. From the given configuration, the floating-point number
specifications can be derived as Table 7.2.
IEEE Standard 754 [1] specifies the general floating-point numbers in single
precision and double precision as Eq. (7.14). Note that MATLAB uses the double
precision floating-point number as default.

b31 b30 b29 . . .b24 b23 b22 b21 . . .b1 b0 : single precision ð32 bitsÞ
|{z} |fflfflfflfflfflfflfflfflfflfflffl{zfflfflfflfflfflfflfflfflfflfflffl} |fflfflfflfflfflfflfflfflffl{zfflfflfflfflfflfflfflfflffl}
s e:8 bits f :23 bits
ð7:14Þ
b63 b62 b61 . . .b53 b52 b51 b50 . . .b1 b0 : double precisionð64 bitsÞ
|{z} |fflfflfflfflfflfflfflfflfflfflffl{zfflfflfflfflfflfflfflfflfflfflffl} |fflfflfflfflfflfflfflfflffl{zfflfflfflfflfflfflfflfflffl}
s e:11 bits f :52 bits

The corresponding decimal number is derived as Eq. (7.15).


510 7 Implementation Matters

Table 7.2 8-bit floating-point number specifications


Specification Binary Decimal number MATLAB
b7 b6 b5 b4 b3 b2 b1 b0
|{z} |fflfflfflfflffl{zfflfflfflfflffl} |fflfflffl{zfflfflffl} ð1Þs ð1:f  2e7 Þ10
 
s e f ð1Þs  0:f  26 10
Smallest positive 000010002 1  26  0:0156 realmin
normalized
floating-point
number
Largest positive 011101112 ð1 þ 21 þ 22 þ 23 Þ realmax
floating-point 27 ¼ 240
number
Floating-point 001110012 ð1 þ 23 Þ  20  1 ¼ 0:1250 eps
relative accuracy
(Distance from 1.0
to the next larger
number)
Smallest positive 000000012 23  26 ¼ 29  0:0020 None
denormalized
floating-point
number

(  
ð1Þs  1:f  2e127 10 for 1  e  254 ðnormalizedÞ
FP#10single ¼   : ð7:15Þ
ð1Þs  0:f  2126 10 for e ¼ 0 ðdenormalizedÞ
(  
ð1Þs  1:f  2e1023 10 for 1  e  2046 ðnormalizedÞ
FP#10double ¼   :
ð1Þs  0:f  21022 10 for e ¼ 0 ðdenormalizedÞ

From the given configuration, IEEE 754 single and double precision
floating-point number specifications can be derived as Table 7.3.
In the filter design and realization, we have to consider the quantization effects
generated from the finite length variable and arithmetic for infinite precision
number. The single or double precision floating-point number shown above indi-
cates the high dynamic range with high resolution around zero; therefore, the
floating-point number is adequately accurate for the processing. With floating-point

Table 7.3 The single and double precision floating-point number specifications
Specification Decimal # for Decimal # for
single double
Smallest positive normalized floating-point  1:1755  1038  2:2251  10308
number
Largest positive floating-point number  3:4028  1038  1:7977  10308
7
Floating-point relative accuracy  1:1921  10  2:2204  1016
(Distance from 1.0 to the next larger number)
7.1 Number Representations 511

number, we can assume that the quantization problems are ignored and restricted to
the fixed-point number. Note that the floating-point number arithmetic requires the
expensive hardware and/or software to process the number in real time.
– Fixed point numbers
The fixed-point number fixes the binary point at the specific point to represent the
corresponding decimal number. Equation (7.5) described binary to integer con-
version assumed that the binary point is located at the right of LSB. For the
effectiveness of the fixed-point number arithmetic, following configuration is used.
The reason will be explained in later section.

b0 :b1 b2 . . .bB þ 1 bB ð7:16Þ

The B + 1 bit configuration places the binary point at the MSB right. The
decimal number from the configuration is the signed fraction number based on the
2’s complement. The conversion equation is below.

P
B
Fraction number ¼ b0 þ bk 2k ð7:17Þ
k¼1

The range of the fraction number is below.

1  Fraction number  1  2B ð7:18Þ

The smallest difference between numbers is below.

D ¼ 2B ð7:19Þ

Unlike the floating-point number, the fixed-point number demonstrates the


constant distance D between the adjacent numbers. The fixed-point number pro-
vides the simple arithmetic computations which can be built from the inexpensive
processor and uncomplicated algorithm. The computation methods for the
fixed-point number will be introduced in later section.
– Signal quantization
Previously, the signal x[n] is sampled from the x(t) with period T. The time is
discretized but the x[n] magnitude is still real value which cannot be represented by
finite length variable. The signal quantization process converts the real magnitude
to the finite precision value such as fixed-point number. The below presents the
quantization process for fixed-point number with B + 1 bits. Note that the QB
presents the quantization process.

^x ¼ QB ðxÞwhere x 2 R ð7:20Þ

The quantized values can be derived from the following equation.


512 7 Implementation Matters

 
P
B
^x ¼ Xm b0 þ bk 2 k
where Xm ¼ maxjx½nj ð7:21Þ
k¼1 n

The minimum difference between the quantized numbers is below.

DQB ¼ Xm 2B ð7:22Þ

The fraction number by fixed-point binary produces the less than one magnitude;
hence, the quantized value ^x cannot be increased further than the signal maximum
Xm. The selected approximation policy finds proper binary value to represent the
given value x[n]. The rounding makes a real value x to the nearest discrete ^x value.
A real value x which is located at the exact middle location is approximated to the
higher (right) and nearest discrete ^x value. The truncation in 2’s complement (in
abbreviated form, truncation) transfers a real value x to the nearest discrete ^x value
toward negative infinity direction. Note that the truncation is identical to the floor
function. For example, one random real x value has the two adjacent ^x values at left
and right of the x. The round chooses the nearest distance ^x from two adjacent
values and the truncation selects the ^x in the left direction from the two. The transfer
equation for round and truncation is below. Note that the b c denotes floor function.
 
x 1
QB ðxÞ ¼ DQB þ for rounding ð7:23Þ
DQB 2
j k
x
QB ðxÞ ¼ DQB DQB for truncation ð7:24Þ

The binary representation can be calculated by following equations.


j k

b0 b1 . . .bB þ 1 bB ¼ x


DQB þ 1
2 for rounding ð7:25Þ
2
j k

b0 b1 . . .bB þ 1 bB ¼ x


DQB for truncation ð7:26Þ
2

The example binary conversion is presented below based on the maximum


magnitude Xm as 2 and assigned bits B as 2 in Fig. 7.5.
The quantization error is defined as below.

e ¼ ^x  x ¼ QB ðxÞ  x ð7:27Þ

The error range for both approximations are below.


DQB DQB
 2 \e  2 for rounding ð7:28Þ

DQB \e  0 for truncation ð7:29Þ


7.1 Number Representations 513

011 2
Rounding
Truncation
010 2

001 2

000 2
b 0 b -1 b -2

111 2

110 2

101 2

100 2
-2.0 -1.5 -1.0 -0.5 0 0.5 1.0 1.5 2.0

x with X m=2, B=2, & Q2


=0.5

Fig. 7.5 Binary conversion example for rounding and truncation with 2 Xm and 2 B

The overall error distance is DQB for both methods with individual initial and
final error range.
– Simple statistical analysis
The quantization error e is the continuous unpredictable random value. We describe the
e as the random variable E whose possible values e are the random process (quanti-
zation in this case) outcomes. Often the random variable is analyzed by the distribution,
mean, variance, etc. The expected value lE can be calculated by the probability
density function fE ðeÞ or arithmetic mean. The C indicates the probability density
function range. We assume that the signal is initiated from zero time [0].
 
R P
N1
E½E ¼ lE ¼ C efE ðeÞde ¼ lim
1
N e½ k  ð7:30Þ
N!1 k¼0

The variance also can be computed by the fE ðeÞ probability density function or
second moment [2] as below.
h i  N1 
P
VarðEÞ ¼ r2E ¼ E ðE  lE Þ2 ¼ lim N1 ðe½k   lE Þ2
N!1 ð7:31Þ
R k¼0
¼ E½E 2   E½E 2 ¼ E½E 2   l2E ¼ C e2 fE ðeÞde  l2E

The signal power of e[n] is defined as below.


514 7 Implementation Matters

P
N1
Pe ¼ N1 e2 ½k  E½E 2  ð7:32Þ
k¼0

The variance of random variable E is below.

P
N1 P
N1
r2E  N1 ðe½k   lE Þ2  N1 e2 ½k  l2E ð7:33Þ
k¼0 k¼0

Observe that the dividing factor N is replaced with N−1 for unbiased estimation
of variance. The given signal power and variance show the following relationship.

Pe ¼ r2E for lE ¼ 0 ð7:34Þ

The signal-to-noise ratio (SNR) in decibel is defined as the ratio between the
signal power and noise power as below.

r2

Psignal
SNR ¼ 10 log10 Pnoise ¼ 10 log10 signal
r2noise
for l ¼ 0 ð7:35Þ

For zero mean noise and signal, the SNR can be calculated from the variance ratio as
above. Once we know the statistical information, the SNR can be derived by the esti-
mated the variances. Following example computes the SNR in rounding quantization.
Example 7.1
Calculate the SNR in round quantization. Assume that the probability density
function is uniform as shown in Fig. 7.6.
Solution
The minimum distance between the quantization level is given below.

DQB ¼ Xm 2B

The quantization error range and corresponding probability density function are
below. Assume that we have uniform distribution.
DQB DQB
fE ðeÞ ¼ D1QB for  2 \e  2

Note that the total area under the probability density function should be one as
below due to the function property.

Z DQB
2

DQB
fE ðeÞde ¼ 1
 2

The expected value (mean) of the quantization error is below.


7.1 Number Representations 515

1/ QB
f E(e)

- QB /2 0 - QB /2
e

Fig. 7.6 Example probability function for rounding

R DQB R DQB
lE ¼ 2
DQB efE ðeÞde ¼ D
1
QB
2
DQB ede ¼ 0
 2  2

The variance of the quantization error is below.


R DQB R DQB R DQB
r2noise ¼ D
2
e2 fE ðeÞde ¼ 2
D e2 D1QB de ¼ D2QB 0
2
e2 de
 QB
2  QB
2
h 3 iDQB
2 D2QB Xm2 22B
¼ D2QB e
3 0 ¼ 12 ¼ 12

Let the maximum signal magnitude is N times signal standard deviation rsignal .below.
Xm ¼ Nrsignal

The corresponding signal variance is below.


X2
r2signal ¼ Nm2

The SNR is below.


!    
r2signal Xm2 =N 2 12
SNR ¼10 log10 ¼ 10 log10 ¼ 10 log10
r2noise Xm2 22B =12 N 2 22B
¼10 log10 ð12Þ  20 log10 ðNÞ þ 20B log10 ð2Þ
¼10:7918  20 log10 ðNÞ þ 6:0206B
516 7 Implementation Matters

According to the SNR equation above, adding the additional bits to the quan-
tization increases the 6 dB. Also, as we expand the maximum signal limit Xm by
N times of signal standard deviation, the SNR decreases in logarithm fashion. For
instance, 16-bit quantization level (B = 15) with three times limit (N = 3) presents
91.5584 dB SNR. ∎

7.2 Filter Implementation Components

– Fundamental blocks
The filter realization can be decomposed into three fundamental blocks in time
domain. Below is the conventional filter equation.

y½n ¼ b0 x½n þ    þ bM x½n  M   a1 y½n  1     aN y½n  N  ð7:36Þ

For current filter output y[n], the filter performs the multiplication, addition, and
delay operations with proper order and coefficients. The filter design procedure
determined parameters such as filter type, order, and coefficients in advance. The
basic three blocks multiplication, addition, and delay are illustrated as below in
Fig. 7.7.
Each single line represents the one signal state and propagation through box,
arrow, or circle changes the signal state. The multiplication multiplies the signal
with constant a1. The addition adds the more than two signal inputs toward the
circle to create single output. The delay retards the signal time by one sample via
using the memory element. The certain combination of the above three blocks
provides the filter realization in a specific method.
– Fixed point number computations
According to the basic filter blocks, the filter implementation requires the multi-
plication and addition as the arithmetic. The binary fractions show the special
properties and requirement to perform the arithmetic. Let’s assume that we have
B + 1 bit binary fraction number as below.

a1
+ z-1

Multiplication Addition Delay

Fig. 7.7 Fundamental filter blocks for time domain realization


7.2 Filter Implementation Components 517

b0 :b1 b2 . . .bB þ 1 bB ð7:37Þ

The x1 and x2 are the random binary fraction number with possible range as
below.

1  x1  1  2B and  1  x2  1  2B ð7:38Þ

The feasible range of x1 + x2 is below.

2  x1 þ x2  2  2B þ 1 ð7:39Þ

To avoid the overflow, addition outcome should be stored in the B + 2 bit


memory as below. Note that additional bit is appended at the left of MSB.

b1 b0 :b1 b2 . . .bB þ 1 bB ð7:40Þ

The corresponding decimal fraction number can be computed by weighted sum


as below.

P
B
x1 þ x2 ¼ 2b1 þ b0 þ bk 2k ð7:41Þ
k¼1

For general situation, the accumulated range for N number addition is below.
PN
N  k¼1 xk  N  N2B ð7:42Þ

The required extra bits to avoid overflow is below. Observe that the de is the
ceiling function which provides the least integer greater than or equal to the
argument.

D ¼ dlog2 N e ð7:43Þ

Place the D number of bit on the MSB left. The below bit configuration guar-
antees the proper value representation by N number additions.

bD . . .b1 b0 :b1 b2 . . .bB þ 1 bB ð7:44Þ

One example of binary addition for 2’s complement is below.

0:1102 ! 0:75010 1:0012 ! 0:87510


þ 0:1012 ! 0:62510 þ 1:1112 ! 0:12510
01:0112 ! 1:37510 11:0002 ! 1:00010

The unified bit format for input and output causes overflow problem in addition
operation. See the below example.
518 7 Implementation Matters

0:1102 ! 0:75010 1:0012 ! 0:87510


þ 0:1012 ! 0:62510 þ 1:1102 ! 0:25010
1:0112 ! 0:62510 0:1112 ! 0:875010

The carry-out from the MSB addition is abandoned for limited size output;
therefore, the output sign is inverted due to the missing information. The impact of
the overflow is substantial because of the circulation in decimal representation.
With limited length memory, we cannot completely prevent the overflow from the
addition. However, the saturation addition decreases the overflow influence by
maintaining the numeric boundary. Once the result is bigger or lower than the upper
or lower boundary, the output is the edge value. The output is still incorrect, but the
impact is lessened by minimizing error distance. See below for example.

0:1102 ! 0:75010 1:0012 ! 0:87510


þ 0:1012 ! 0:62510 þ 1:1102 ! 0:25010
1:0112 ! 0:62510 0:1112 ! 0:875010
! 0:1112 ! 0:87510 ! 1:0002 ! 1:00010

Followed by overflow detection algorithm, the addition algorithm decides the


positive ð0:1112 Þ or negative ð1:0002 Þ edge value as final output in overflow sit-
uation. Figure 7.8 shows the non-saturation and saturation arithmetic with 4-bit
binary signed integer. If the arithmetic decimal output is out of the 4-bit range, the
final output is translated or modified to the proper value based on the saturation
policy.
With the number x1 and x2, the range of multiplication is below. The product
range cannot be increased further than one because of the individual x1 and x2
magnitude.

0  j x1 x2 j  1 ð7:45Þ

Except zero, the minimum magnitude of the individual and product is below.

minjx1 j ¼ 2B for x1 6¼ 0


ð7:46Þ
minjx1 x2 j ¼ 22B for x1 x2 6¼ 0

The product generates the 2B + 2 bit output as below. Two bits above the binary
point indicate the redundant sign bits; hence, the redundancy removal establishes
the final output as below.

b1 b0 :b1 b2 . . .b2B þ 1 b2B ! b0 :b1 b2 . . .b2B þ 1 b2B ð7:47Þ


7.2 Filter Implementation Components 519

Non-saturation output 10

-5

-10
-16 -14 -12 -10 -8 -6 -4 -2 0 2 4 6 8 10 12 14

10
Saturation output

-5

-10
-16 -14 -12 -10 -8 -6 -4 -2 0 2 4 6 8 10 12 14
Decimal output

Fig. 7.8 Non-saturation and saturation arithmetic with 4-bit binary signed integer

The range of product outcome is below.

1  b0 :b1 b2 . . .b2B þ 1 b2B  1  22B ð7:48Þ

The conversion equation to the decimal fraction is below.

P
2B
x1 x2 ¼ b0 þ bk 2k ð7:49Þ
k¼1

One example of binary multiplication for 2’s complement is below.

0:1102 ! 0:75010 1:0012 ! 0:87510


0:1012 ! 0:62510 1:1112 ! 0:12510
0:0001102 1:1110012
0:000002 1:110012
0:01102 1:10012
0:0002 0:1112
00:0111102 ! 0:4687510 10:0001112 ! 0:10937510
520 7 Implementation Matters

With 2B + 2 bit configuration, most product outputs are properly symbolized


except one. The positive one from the product of negative ones cannot be repre-
sented. The situation is the only overflow experienced from the fixed-point number
multiplication in binary fraction form. On the other hand, the shorter bit length for
the product causes the problem known as underflow. The reduced bit length loose
the output resolution; therefore, the outputs are appraised to the nearest value
according to the approximation rule. For example, 2B bits below binary point is
converted to the B bits as shown subsequently.

b1 b0 :b1 b2 . . .b2B þ 1 b2B ! b0 :b1 b2 . . .bB þ 1 bB ð7:50Þ

DQ2B ¼ 22B ! DQB ¼ 2B for Xm ¼ 1

The corresponding precision is decreased to the 2B from 22B ; hence, the
values in the 2B interval should be approximated to the left or right. Below figure
presents the b0 :b1 b2 b3 and b0 :b1 quantization positions. If the 3 bits below
binary point is the product output, then mapping to the 1 bit below configuration
requires the three approximations in every interval as shown in Fig. 7.9.
The discrete values around zero are quantized to the one bit below the binary
point number as below. Note that a value x which is located at the exact middle
location is approximated to the higher ^x value in rounding method on Table 7.4.
To avoid the underflow problem, the multiplication requires significant bit
length. For instance, M times multiplications with B + 1 bit length multiplicand and
b 0.b -1
b 0.b -1 b -2 b -3

-1 -0.5 0 0.5 1

Fig. 7.9 b0.b−1b−2b−3 and b0.b−1 quantization positions


7.2 Filter Implementation Components 521

Table 7.4 Conversion from b0.b−1b−2b−3 to b0.b−1


B=3 Fraction Round Truncate B=3 Fraction Round Truncate
0.0012 0.12510 0.02 0.02 1.1112 −0.12510 0.02 1.12
0.0102 0.25010 0.12 0.02 1.1102 −0.25010 0.02 1.12
0.0112 0.37510 0.12 0.02 1.1012 −0.37510 1.12 1.12

Fig. 7.10 Signal flow of


multiplication and a1
quantization x[n] QB QB(a1x[n])

multiplier involve M  ðB þ 1Þ bit length to keep the product correctly. Normally


the linear increasement of the memory size is not feasible; therefore, the product is
placed in the shrunk memory size. The underflow can be seen as the quantization
problem which is mapping the higher resolution information to the lower precision
dimension. The statistical analysis is identical to the quantization problem.
Figure 7.10 depicts the signal multiplication with constant a1 followed by the
quantization with B + 1 bits. We assume that x[n] and a1 are binary fraction number
with B + 1 bits individually. The noise variance from the quantization is approx-
imated below. Observe that the binary fraction a1x[n] has the maximum magnitude
Xm as 1.
2B
r2noise ¼ 212 ð7:51Þ

While the above quantization error presents the discrete probability distribution,
we can approximate to the continuous probability density function based on the
dense distribution of 2B + 2 bit quantization levels. Overall 2−2B factor is identical
with minor constant variation. Further assignment of bits to the quantization process
reduces the noise variance as well as the power.
– Coefficient quantization
One famous example of coefficient quantization error is Wilkinson’s polynomial
[3–5]. Below Wilkinson example demonstrates the 20 order FIR filter with linearly
increasing zero locations. The other FIR filter H2(z) shows the identical transfer
function as H1(z) except error in z−1 degree. The error is negligible; however, the
impact is substantial as shown in Fig. 7.11 for zero plot in z-plane.

Q
20
H1 ðzÞ ¼ ð1  kz1 Þ ð7:52Þ
k¼1

Q
20
H2 ðzÞ ¼ ð1  kz1 Þ  223 z1 ð7:53Þ
k¼1
522 7 Implementation Matters

Zeros of H 1(z)
4

2
Imaginary

-2

-4
0 5 10 15 20 25
Real

Zeros of H 2(z)
4

2
Imaginary

-2

-4
0 5 10 15 20 25
Real

Fig. 7.11 Zeros of Eqs. (7.52) and (7.53)

Prog. 7.3 MATLAB program for Fig. 7.11.


syms z k

y1 = symprod(1 - k*z^-1, k, 1, 20);


y2 = expand(y1) - 2^-23*z^-1;
y3 = collect(y2);
y4 = solve(y3);
y5 = solve(y1);
double(y4);

figure,
subplot(211), sca er(real(y5),imag(y5)),grid
axis([ 0 25 -4 4]);
tle('Zeros of H_1(z)')
xlabel('Real')
ylabel('Imaginary')
subplot(212), sca er(real(y4),imag(y4)), grid
axis([ 0 25 -4 4]);
tle('Zeros of H_2(z)')
xlabel('Real')
ylabel('Imaginary')
7.2 Filter Implementation Components 523

Around the 10 real zero location in above figure, the zeros start to diverge and
converge to the elliptical shape; therefore, the filter property is expected to be
deviated from the design specification. Usually, the higher order polynomial is
vulnerable to the tiny quantization errors which generate ill-condition state as
significant property modification. Let’s analyze the sensitivity of individual zero
location with respect to filter coefficients. Rewrite the filter equation as below.
Q
20 Q
20 P
20
H1 ðzÞ ¼ ð1  kz1 Þ ¼ ð1  zk z1 Þ ¼ 1 þ bk zk ð7:54Þ
k¼1 k¼1 k¼1

where zk ¼ k

The sensitivity of zero zj to coefficient bk is defined and written as below. Used


chain rule.

@zj @zj @H1 ðzÞ ð@H1 ðzÞ=@bk Þz¼zj
@bk ¼ @H1 ðzÞ z¼z @bk z¼z ¼ ð@H1 ðzÞ=@zj Þ
ð7:55Þ
j j z¼zj

The numerator and denominator partial derivatives are derived as below.



@H1 ðzÞ
@bk ¼ zk
j
z¼zj
ð7:56Þ

20 
Q 
@H1 ðzÞ
@zj z¼z ¼ z20
j zj  zi ð7:57Þ
j i¼1;i6¼j
Y
20
where H1 ðzÞ ¼ z20 ðz  zk Þ
k¼1

The derived sensitivity is below.


@zj zk zj20k
@bk ¼ Q20j ¼  Q20 ð7:58Þ
z20
j i¼1;i6¼j
ðzj zi Þ i¼1;i6¼j
ðzj zi Þ

The jth zero location error can be described by the coefficient errors as below.
P
20
@zj
Dzj ¼ @bk Dbk
ð7:59Þ
k¼1

In the Wilkinson’s polynomial example, we modify the z−1 order coefficient only.
@z
Dzj ¼ @b1j Db1 ð7:60Þ

The sensitivity with respect to b1 coefficient is below.


@zj zj201
@b1 ¼  Q20 ð7:61Þ
i¼1;i6¼j
ðzj zi Þ
524 7 Implementation Matters

The zero location z10 (10 in z-plane) sensitivity to b1 is below.


201
@z10 z10
¼  Q20 ¼  Q20 1019 19
10
@b1 ¼  9!10! ð7:62Þ
ðz zi Þ
i¼1;i6¼10 10 i¼1;i6¼10
ð10zi Þ

The deviation of z10 is below. Note that b1 error is −2−23.


Dz10 ¼ @z
19
10 23
@b1 Db1 ¼  9!10! ð2
10
Þ ¼ 0:9053 ð7:63Þ

The individual zero sensitivity to b1 error is below according to the above


equation. Also, logarithm sensitivity base ten is illustrated below to magnify the
visual dynamic range.
Prog. 7.4 MATLAB program for Fig. 7.12.

syms z k
kk = 1:20;
sensi = zeros(1,20);
sensi(1) = 1^19/(factorial(0)*factorial(19));
sensi(2) = 2^19/(factorial(1)*factorial(18));
sensi(3) = 3^19/(factorial(2)*factorial(17));
sensi(4) = 4^19/(factorial(3)*factorial(16));
sensi(5) = 5^19/(factorial(4)*factorial(15));
sensi(6) = 6^19/(factorial(5)*factorial(14));
sensi(7) = 7^19/(factorial(6)*factorial(13));
sensi(8) = 8^19/(factorial(7)*factorial(12));
sensi(9) = 9^19/(factorial(8)*factorial(11));
sensi(10) = 10^19/(factorial(9)*factorial(10));
sensi(11) = 11^19/(factorial(10)*factorial(9));
sensi(12) = 12^19/(factorial(11)*factorial(8));
sensi(13) = 13^19/(factorial(12)*factorial(7));
sensi(14) = 14^19/(factorial(13)*factorial(6));
sensi(15) = 15^19/(factorial(14)*factorial(5));
sensi(16) = 16^19/(factorial(15)*factorial(4));
sensi(17) = 17^19/(factorial(16)*factorial(3));
sensi(18) = 17^19/(factorial(17)*factorial(2));
sensi(19) = 19^19/(factorial(18)*factorial(1));
sensi(20) = 20^19/(factorial(19)*factorial(0));

figure,
subplot(211),bar(kk,(sensi)), grid
ylabel('|¡Óz_j/¡Ób_1|')
xlabel('j')
subplot(212),bar(kk,log10(sensi)), grid
ylabel('log_{10}(|¡Óz_j/¡Ób_1|)')
xlabel('j')
7.2 Filter Implementation Components 525

10 9
3

2
| zj / b1|

0
0 2 4 6 8 10 12 14 16 18 20
j

10
log10(| zj / b1|)

-10

-20
0 2 4 6 8 10 12 14 16 18 20
j

Fig. 7.12 The individual zero sensitivity to b1 error in absolute and logarithm scale

The high sensitivity can be observed from the 10 zero location to the 20 which is
corresponding to the previous zero location plot due to the b1 coefficient error. The
general root sensitivity to the coefficient is below.

@zj zNk
@bk ¼  QN j
ð7:64Þ
i¼1;i6¼j
ðzj zi Þ

The above equation can be applied for the numerator (zeros) or denominator
(poles) to derive the sensitivity with respect to the individual coefficients. To reduce
the sensitivity, following rules can be developed from the above equation.
– Reduced order N
– Small root magnitude zj
– Not clustered roots.
526 7 Implementation Matters

Once we designed the optimal filter, the orders (N and M) and roots (poles and
zeros) of the filter cannot be changed. In the filter implementation stage, the fol-
lowing direct form transfer function is realized by modified form to minimize
sensitivity over the coefficient quantization errors.
ðM1Þ M
HðzÞ ¼ b0 þ1þþa1bzM1 z þ bM z
1 þ  þ a zN
N
where M  N ð7:65Þ

Rewrite the transfer function in terms of poles and zeros as below.

b0 ð1z1 z1 Þð1z2 z1 Þ...ð1zM z1 Þ


HðzÞ ¼ ð1p1 z1 Þð1p2 z1 Þ...ð1pN z1 Þ
ð7:66Þ

The sensitivity of individual numerator and denominator is below.

@pj pNk
@ak ¼  QN j
ð7:67Þ
i¼1;i6¼j
ðpj pi Þ

@zj zMk
@bk ¼  QM j ð7:68Þ
b0
i¼1;i6¼j
ðzj zi Þ

Without modifying the pole and zero positions, the H(z) can be decomposed into
the reduced order functions in cascade connection as below.

HðzÞ ¼ Hs1 ðzÞHs2 ðzÞ. . .HsNs ðzÞ ð7:69Þ

The second order is the minimum order for individual sections to maintain the
real coefficients. In general, the poles and zeros could be complex number but the
filter coefficients are real number. The fundamental second order function is known
as second-order section (SOS). The cascade connection with SOS is below
(Fig. 7.13).

Q
Ns
b0k þ b1k z1 þ b2k z2
N þ 1
HðzÞ ¼ 1 þ a1k z1 þ a2k z2 where Ns ¼ 2
ð7:70Þ
k¼1

The poles and zeros should be spread out to minimize the sensitivity in the SOS.
Provided that the poles and zeros are complex number, the pole and zero distri-
bution is automatic in the SOS. The real poles and zeros are assigned carefully not

x[n] Hs1(z) Hs2(z) HsNs(z) y[n]

Fig. 7.13 Cascade connection


7.2 Filter Implementation Components 527

Fig. 7.14 Parallel connection


Hp1(z)

Hp2(z)
x[n] + y[n]

HpNp(z)

to close each other. The rule of thumb for pairing pole and zero are given by
Leland B. Jackson [6] as below.
– Poles closest to the unit circle $ zeros nearest to the poles
– Poles next closest to the unit circle $ residual zeros nearest to the poles
– And so on until entire the poles and zeros have been paired for SOS
– Order the SOS from least-peaked to most-peaked in gain (arrange the sections
with poles closest to the unit circle last in the cascade).
Also, the direct form H(z) can be decomposed into the partial fractions in parallel
connection as below. The addition of each sections produces the final output of the
filter.

HðzÞ ¼ Hp1 ðzÞ þ Hp2 ðzÞ þ    þ HpNp ðzÞ ð7:71Þ

The parallel connection with the sections is below. The denominator roots of the
section present the overall poles in the filter; however, the numerator roots of the
section are not related to the overall zeros in Fig. 7.14.

P
Np
c0k þ c1k z1
N þ 1
HðzÞ ¼ 1 þ a1k z1 þ a2k z2 where Np ¼ 2
ð7:72Þ
k¼1

The zeros in the direct form require to compute common denominator and
corresponding expanded numerators. Therefore, all coefficients in the sections
affects every zero. This situation is not recommended due to the high sensitivity of
zero locations with respect to the coefficient quantization error. The parallel real-
ization is not prevalent. The cascade implementation shows the further robustness
to the quantization error in fixed-point realization. However, the parallel realization
still presents considerably less sensitive to coefficient quantization error than the
corresponding direct form since the individual sections are not extremely sensitive.
Below is the general sensitivity order for each realization. We assume that the
below filter is implemented with the high order.
528 7 Implementation Matters

SensitivityDirect  SensitivityParallel [ SensitivityCascade ð7:73Þ

The SOS in the cascade realization contains the two poles and two zero in each
section. The pole locations are important to specify the pass frequency band;
therefore, the poles should be placed at the precise positions. The quadratic
equation in the denominator is characterized by the quantized coefficients with
binary fraction numbers. The roots of the equation demonstrate the limited numbers
and pole distributions due to the constrained numeric system. Let’s investigate
below transfer function. The two pole locations are rejh and rejh .

HðzÞ ¼ ð1rejh z1 Þð11rejh z1 Þ ¼ 12r cos hz11 þ r2 z2 ð7:74Þ

The coefficients of the denominator are 2r cos h and r 2 . The coefficients are
represented by the binary fraction number with 3 bit below binary point as below.

b0 :b1 b2 b3 where B ¼ 3 ð7:75Þ

The r 2 distribution is below in binary form.

r 2 ¼ f0:0002 0:0012 0:0102 0:0112 0:1002 0:1012 0:1102 0:1112 g

The corresponding decimal numbers are below.

r 2 ¼ f0 0:125 0:25 0:375 0:5 0:625 0:75 0:875g

The r cos h distribution is below in binary form.

r cos h ¼ f1:0002 1:0012 1:0102 1:0112 1:1002 1:1012 1:1102 1:1112 . . .


0:0002 0:0012 0:0102 0:0112 0:1002 0:1012 0:1102 0:1112 g

The corresponding decimal numbers are below.

r cos h ¼ f1  0:875  0:75  0:625  0:5  0:375  0:25  0:125. . .


0 0:125 0:25 0:375 0:5 0:625 0:75 0:875g

Note that the 2r cos h magnitude is beyond the binary fraction range with given
r cos h distribution. As long as the overall product (shown below) is less than one
magnitude, the filter is working properly. The multiplication by two is performed by
the shift operation.

2r cos hz1 ! j2r cos hy½n  1j\1 ð7:76Þ


7.2 Filter Implementation Components 529

The poles of the given function can be found by the intersections between the
real r cos h values and radius r circles in complex domain. Observe that the poles
are designed to be rejh and rejh in the transfer function. The r cos h is the real value
of the re jh . Below figure shows the real r cos h values, radius r circles, and cor-
responding intersections.
Figure 7.16 demonstrates the pure pole locations with unit circle. With given
binary fraction numbers, the pole distribution displays the sparse population around
the 1 in complex number domain.
Prog. 7.5 MATLAB program for Figs. 7.15 and 7.16.
B = 3;
N = 1000;
theta = linspace(0,2*pi,N);
ggrid = linspace(-1,1,N);
r2 = linspace(0,1-2^(-B),2^B);
r3 = sqrt(r2);
rcos = linspace(-1,1-2^(-B),2^(B+1));
rrad1 = r3'*exp(1j*theta);
rrad2 = 1*exp(1j*theta);
yy1 = rcos'*ones(1,N)+1j*ones(2^(B+1),1)*ggrid;
final = [];
for kk1 = 1:length(r2)
for kk2 = 1:length(rcos)
if ((rcos(kk2)).^2 > r2(kk1))
con nue
end
y1 = sqrt(r2(kk1)-(rcos(kk2)).^2);
y2 = -sqrt(r2(kk1)-(rcos(kk2)).^2);

final = [final [rcos(kk2); y1] [rcos(kk2); y2]];


end
end

figure,
sca er(final(1,:),final(2,:)), grid, hold on;
plot(rrad2','Color','c'), hold off;
axis equal
figure,
plot(rrad1','Color',[0 0.4470 0.7410]), grid, hold on;
axis equal
plot(rrad2','Color','c')
plot(yy1','Color',[0 0.4470 0.7410]);
sca er(final(1,:),final(2,:)), grid, hold off;
530 7 Implementation Matters

Unit circle
Imaginary

-1
-1 0 1
Real

Fig. 7.15 Possible pole locations for Eq. (7.74) with b0.b−1b−2b−3 coefficients

1
Unit circle
Imaginary

-1
-1 0 1
Real

Fig. 7.16 Possible pole locations for Eq. (7.74) based on b0.b−1b−2b−3 coefficients without grid
7.2 Filter Implementation Components 531

With 5 bits below binary point, the increasement of bit assignment significantly
improves the pole distribution widely. However, the 1 vicinity still indicates the
depletion.
Prog. 7.6 MATLAB program for Fig. 7.17.
B = 5;
N = 1000;
theta = linspace(0,2*pi,N);
rrad2 = 1*exp(1j*theta);
a1 = linspace(-1,1-2^(-B),2^(B+1));
a2 = linspace(-1,1-2^(-B),2^(B+1));
[A1,A2] = meshgrid(a1,a2);
LLE = length(a1);
final = [];
for kk1 = 1:LLE
for kk2 = 1:LLE
temp1 = roots([1 A1(kk1,kk2)*2 A2(kk1,kk2)]);
rr = sqrt(temp1.*conj(temp1));
for kk3 = 1:2
if (rr(kk3)>=1)
con nue
end
final = [final temp1(kk3)];
end
end
end

figure,
sca er(real(final),imag(final)), grid, hold on
plot(rrad2','Color','c'), hold off
axis equal
axis([-1.1860 1.1860 -1.0 1.0]);
y cks([-1 0 1]);
y cklabels({'-1','0','1'});
x cks([-1 0 1]);
x cklabels({'-1','0','1'});
xlabel('Real');
ylabel('Imaginary');

The above figures present the rare pole distribution on the real axis. The negative
2
r places the poles on the real axis and the situation is not shown here. For
verification purpose, below shows the real pole derivation. The denominator is
rewritten below.
532 7 Implementation Matters

Unit circle
Imaginary

-1
-1 0 1
Real

Fig. 7.17 Possible pole locations for Eq. (7.74) based on b0.b−1b−2b−3b−4b−5 coefficients without
grid

1  2r cos hz1 þ r 2 z2 ¼ z2 ðz2  2r cos hz þ r 2 Þ ð7:77Þ

Discriminant of the quadratic equation is below.

D ¼ 4r 2 cos2 h  4r 2 ¼ 4r 2 ðcos2 h  1Þ ¼ 4r 2 sin2 h ð7:78Þ

Therefore, the negative r 2 provides the real poles.



D  0 for r 2
0
ð7:79Þ
D
0 for r 2 \0

For even pole distribution, we prefer to sample the real and imaginary axis. The
pole location rejh can be considered as the r cos h and r sin h in real and imaginary
axis respectively. The uniform pole distribution in Cartesian coordinate can be
realized by an alternative SOS structure known coupled form as below.
7.2 Filter Implementation Components 533

r sin hz1
Hcoupled ðzÞ ¼
ð1  ðr cos h þ jr sin hÞz1 Þð1  ðr cos h  jr sin hÞz1 Þ
ð7:80Þ
r sin hz1
¼
1  2r cos hz1 þ r 2 ðcos2 h þ sin2 hÞz2

The pole re jh is denoted by the ðr cos h jr sin hÞ in the coupled form. The
individual real and imaginary component are sample by binary fraction numbers as
below.

r cos h ¼ f1:0002 1:0012 1:0102 1:0112 1:1002 1:1012 1:1102 1:1112 . . .


0:0002 0:0012 0:0102 0:0112 0:1002 0:1012 0:1102 0:1112 g

r cos h ¼ f1  0:875  0:75  0:625  0:5  0:375  0:25  0:125. . .


0 0:125 0:25 0:375 0:5 0:625 0:75 0:875g

r sin h ¼ f1:0002 1:0012 1:0102 1:0112 1:1002 1:1012 1:1102 1:1112 . . .


0:0002 0:0012 0:0102 0:0112 0:1002 0:1012 0:1102 0:1112 g

r sin h ¼ f1  0:875  0:75  0:625  0:5  0:375  0:25  0:125. . .


0 0:125 0:25 0:375 0:5 0:625 0:75 0:875g

Certain combination of above assignment ruins the filter stability by placing the
poles outside of unit circle. We only preserve the poles which is the less than one
radius from the coordinate origin as below.
 
r 2 cos2 h þ sin2 h \1 ð7:81Þ

The poles of the coupled form can be derived by the intersections between the
real r cos h values and the imaginary r sin h values in complex domain. Below
figure shows the real r cos h values, the imaginary r sin h values, and corresponding
intersections.
Subsequent figure demonstrates the pure pole locations with unit circle. With
given binary fraction numbers, the pole distribution demonstrates the uniform
population for entire unit circle area in complex domain.
With 5 bits below binary point, the increasement of bit assignment significantly
improves the pole distribution widely and evenly. Unlike the SOS case, no
prominent spots of pole population are observed around the 1 vicinity as shown
below.
534 7 Implementation Matters

Prog. 7.7 MATLAB program for Figs. 7.18, 7.19 and 7.20.
B = 3; % For Fig.7.18&19 B = 3 and For Fig.7.20 B=5
N = 1000;
theta = linspace(0,2*pi,N);
xgrid = linspace(-1.1860,1.1860,N);
ygrid = linspace(-1,1,N);
rsin = linspace(-1,1-2^(-B),2^(B+1));
rcos = linspace(-1,1-2^(-B),2^(B+1));
rrad2 = 1*exp(1j*theta);
yy1 = rcos'*ones(1,N)+1j*ones(2^(B+1),1)*ygrid;
xx1 = 1j*rsin'*ones(1,N)+ones(2^(B+1),1)*xgrid;
final = [];
for kk1 = 1:length(rcos)
for kk2 = 1:length(rsin)
rr = sqrt(rcos(kk1)^2+rsin(kk2)^2);
if (rr>=1)
con nue
end
final = [final [rcos(kk1); rsin(kk2)]];
end
end

figure,
sca er(final(1,:),final(2,:)), grid, hold on
plot(rrad2','Color','c'), hold off
axis equal
figure,
plot(xx1','Color',[0 0.4470 0.7410]), grid, hold on
axis equal
plot(rrad2','Color','c')
plot(yy1','Color',[0 0.4470 0.7410]);
sca er(final(1,:),final(2,:)), grid, hold off

The disadvantage of the coupled form is the slight increment of the computa-
tional requirement.
– Overflow and scaling
The filter output computation requires the multiplications and additions. With
fixed-point number, the careful scaling should be involved to avoid the overflow in
7.2 Filter Implementation Components 535

Unit circle
Imaginary

-1
-1 0 1
Real

Fig. 7.18 Possible pole locations for Eq. (7.80) with b0.b−1b−2b−3 coefficients

1
Unit circle
Imaginary

-1
-1 0 1
Real

Fig. 7.19 Possible pole locations for Eq. (7.80) based on b0.b−1b−2b−3 coefficients without grid
536 7 Implementation Matters

Unit circle
Imaginary

-1
-1 0 1
Real

Fig. 7.20 Possible pole locations for Eq. (7.80) based on b0.b−1b−2b−3b−4b−5 coefficients without
grid

any arithmetic computation. Note that we use the binary fraction numbers as
fixed-point representation. For scaling problem, see below SOS.
1 2
HðzÞ ¼ b10þþab11zz1 þþab22zz2 ð7:82Þ

The corresponding time domain realization is below.

y½n ¼ b0 x½n þ b1 x½n  1 þ b2 x½n  2  a1 y½n  1  a2 y½n  2 ð7:83Þ

Each signal x[n]s, y[n]s, coefficients and products in the right-hand side of
Eq. (7.83) shows less than unity magnitude due to the binary fraction number
system. Therefore, the corresponding summation for left-hand side produces the
five times of the binary fraction dynamic range as below.

5  y½n\5 ð7:84Þ

The above overflowed range is the outcome of the given instantaneous time
n based on the less than unity assumptions. If the overflow is allowed for outputs,
the maximum output ymax can be derived from below equations.
7.2 Filter Implementation Components 537

ztrans
h½ n $ H ð z Þ
P 1 P 1
jy½nj ¼ h½k x½n  k  jh½k jjx½n  kj
k¼0 k¼0
ð7:85Þ
P
1 P1
 jh½kjxmax ¼ xmax jh½kj ¼ ymax  1
k¼0 k¼0

where xmax ¼ maxjx½nj8n ymax ¼ maxjy½nj8n

The maximum output is the multiplication between maximum input and absolute
sum of impulse response. The quantized input is described by the binary fraction
number; therefore, the input magnitude is less than one automatically. The absolute
sum of the impulse response h[n] is known as L1-norm of the impulse response. If
the L1-norm is less than one, the overall product for the ymax is less than one which
can be stored as the binary fraction number.

P
1
jh½kj  1 ! ymax  1 ð7:86Þ
k¼0
(
X
1
1 ^ ^
jh½k j ¼ [ 1 ! h½n ¼ sh½n ! ymax ¼ 1 ð7:87Þ
^ ^
k¼0
s x½n ¼ sx½n ! y max ¼ 1

If the L1-norm is greater than one, we can scale down the impulse response or
input signal by factor of the s (=1/L1-norm) in order to generate the proper dynamic
range output.

^ P
1 ^ P
1
^ P
1
y ½ n ¼ h½k x½n  k ¼ h½kx ½n  k ¼ sh½kx½n  k  ð7:88Þ
k¼0 k¼0 k¼0

In the SOS realization, the scale factor s is computed from the impulse response
h[n] and the factor is applied over the numerator of the transfer function as below.
^ 1 2
H ðzÞ ¼ sH ðzÞ ¼ s b10þþab11zz1 þþab22zz2 ð7:89Þ

The time domain realization with scaling is below.


^
y½n ¼sb0 x½n þ sb1 x½n  1 þ sb2 x½n  2  a1 y½n  1  a2 y½n  2
^ ^ ^
¼b0 x½n þ b1 x½n  1 þ b2 x½n  2 ð7:90Þ
^
 a1 y½n  1  a2 y½n  2  y max ¼ 1

^
The scaled output y ½n is guaranteed to stay within the acceptable dynamic range
of binary fraction number. In the given SOS, four additions are performed to deliver
538 7 Implementation Matters

Fig. 7.21 Example of Overflow


intermediate overflow with
binary representation on right 0.500 0.1002
1.250 1.0102
0.750 0.1102
+ -0.375 + 1.1012
0.875 0.1112

O.K.

the output. Certain intermediate summation could produce the overflow output;
^
however, the final output y ½n is not contaminated by the overflow due to the
modular property of binary number. Below example illustrates the three-number
addition which induces the intermediate overflow in Fig. 7.21.
The first addition generates the overflow by changing the output sign. The
second summation reduces magnitude to override the overflow. The multiple
additions with several overflows can yield the proper output as long as the final
value is placed within the binary fraction range. Be careful not to use the saturation
addition which changes the arithmetic distance. With saturation addition, single
overflow pollutes the final output. See below example in Fig. 7.22.
The L1-norm prevents the overflow from filter output computation; however, the
scaling factor L1-norm significantly reduces the dynamic range or filter gain. The
output SNR can be improved by allowing low probability overflow. The L2-norm
shown below provides the decreased scale factor which may lead the overflow with
low probability.
rffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffi
P
1
s ¼ l2 ¼ ðh½k Þ2 ð7:91Þ
k

With the narrowband signal ejx0 n , the output is the modified magnitude and
shifted phase of the signal based on the DTFT of impulse response as below.

X
1 X
1 X
1
y ½ n ¼ h½kx½n  k  ¼ h½k ejx0 ðnkÞ ¼ ejx0 n h½k ejx0 k
k¼0 k¼0 k¼0 ð7:92Þ
   
¼ H ejx0 ejðx0 n þ ]Hðe ÞÞ
jx0
jx0 n jx0
¼e H e

Fig. 7.22 Example of Saturation


intermediate saturation with
binary representation on right 0.500 0.1002
0.875 0.1112
0.750 0.1102
+ -0.375 + 1.1012
0.500 0.1002

Incorrect
7.2 Filter Implementation Components 539

The scaling factor L1 -norm is the maximum magnitude of the frequency


response as below. The scaling by the L1 -norm presents the less than unity
magnitude for any narrowband signal; however, the broadband signal could initiate
the overflow.

L1 ¼ maxjH ðejx Þj ð7:93Þ


x

Below equation demonstrates the magnitude comparison between norms. The


L1 -norm is the most commonly used scaling factor in practice.

L1  norm
L1  norm
L2  norm ð7:94Þ

In summary, we can choose the one of the norms for the scale factor as below.
8 P1
>
> jh½nj ¼ L1  P1
> n¼0
< jxn
1 max j H ð e jx
Þ j ¼ L where H ðe jx
Þ ¼ n¼0 h½ne
¼ 1 ð7:95Þ
> x H ðzÞjz!ejxn
s
> qffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffi
: P1 jh½nj2 ¼ L
>
n¼0 2

For the FIR filter scaling, below is the transfer function.

H ðzÞ ¼ b0 þ b1 z1 þ    þ bN1 zðN1Þ þ bN zN ð7:96Þ

The time domain realization is below.

y½n ¼ b0 x½n þ b1 x½n  1 þ   


ð7:97Þ
þ bN1 x½n  ðN  1Þ þ bN x½n  N 

The scaled output can be described by the below equation.


^
y ½n ¼ sb0 x½n þ sb1 x½n  1 þ    þ sbN1 x½n  ðN  1Þ þ sbN x½n  N 
^ ^ ^ ^ ð7:98Þ
¼ b0 x½n þ b1 x½n  1 þ    þ bN1 x½n  ðN  1Þ þ bN x½n  N 

The scaling factor can be chosen from any norm given below.
8 PN
>
> k¼0 jbk j ¼ L1 P
1 < maxjH ðejx Þj ¼ L1 where H ðejx Þ ¼ N bk ejxk
¼ qxffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffi k¼0 ð7:99Þ
s >
> PN
: 2
k¼0 jbk j ¼ L2

The high order filter can be decomposed into the reduced order systems such as
SOS with cascade connection. Each SOS should produce the appropriate dynamic
range output to avoid the overflow. The individual SOS scaling factor controls the
discrete output range independently. Below is the L SOS cascade system.
540 7 Implementation Matters

HðzÞ ¼ GH1 ðzÞH2 ðzÞ. . .HL ðzÞ ð7:100Þ

The G is the global gain of the cascade SOS system to improve the computa-
tional efficiency. Uniform distribution of the global gain G assists to prevent the
peaky SOS gain which amplifies unwanted errors from the previous SOS stage.
Rewritten transfer function is below.

HðzÞ ¼ G1=L H1 ðzÞG1=L H2 ðzÞ. . .G1=L HL ðzÞ ð7:101Þ

The norm of the stage is derived in the cumulative manner from the initial input
x[n] to the given stage output as below. The output range is manipulated by the
scaling factor which is the inverse of the norm. Note that the norm function can be
L1 ; L1 ; or L2 which regulates output SNR and overflow policy. In this chapter, we
compute the norm value numerically with heuristic length. We could use the
Cauchy residue theorem [7] or partial fraction expansion [8] for better represen-
tation of impulse response by analytic inverse z transform derivation. The L1 norm
requires the frequency response instead of the impulse response. The * operation
indicates the convolution sum.

1
s1 ¼
normðG1=L h1 ½nÞ

1
s2 ¼
normðG1=L h 1 ½n G
1=L h ½nÞ
2

1
sL ¼ normðG1=L h1 ½n G1=L h2 ½n ... G1=L hL ½nÞ ð7:102Þ

Figure 7.23 shows the SOS connection and corresponding scale factor scope.
The scale factor is applied in current stage and voided in previous stages to leave
the latest scale factor only. The subsequent figure illustrates the scale factored SOS
connection as well in Figs. 7.24 and 7.25.

sL
...

s3
s2
s1

x[n]
G1/LH1(z)
y1[n]
G1/LH2(z)
y2[n]
G1/LH3(z)
y3[n] ... G1/LHL(z)
yL[n]

x[n]
s1G1/LH1(z)
y1[n]
s2G1/LH2(z)/s1
y2[n]
s3G1/LH3(z)/s2
y3[n] ... sLG1/LHL(z)/sL-1
yL[n]

Fig. 7.23 SOS connection and corresponding scale factor scope


7.2 Filter Implementation Components 541

Overall
1.25

0.75
|H(e j )|

0.50

0.25

0
0 /4 /2 3 /4
Radian frequency ( )

Fig. 7.24 Frequency response of given filter above

0.8

0.6

0.4
Imaginary Part

0.2
4
0

-0.2

-0.4

-0.6

-0.8

-1

-1 -0.5 0 0.5 1
Real Part

Fig. 7.25 Pole zero plot of given filter above


542 7 Implementation Matters

The mathematical representation of the scaled SOS system is below.


  1=L
1=L

H ðzÞ ¼ s1 G1=L H1 ðzÞ s2 G s1H2 ðzÞ s3 G s2H3 ðzÞ . . .


1=L
ð7:103Þ
sL G HL ðzÞ
sL1

^ ^ ^ ^
¼ H 1 ðzÞH 2 ðzÞH 3 ðzÞ. . .H L ðzÞ

The scale factor is applied on the numerator of the transfer function as below.

^ ^ ^ ^
1 2
sk b0k þ b1k z þ b2k z b 0k þ b 1k z1 þ b 2k z2 ð7:104Þ
H k ðzÞ ¼ sk1 1 þ a1k z1 þ a2k z2 ¼ 1 þ a1k z1 þ a2k z2

The corresponding time domain realization is below.


^ ^ ^
yk ½n ¼ b0k xk ½n þ b1k xk ½n  1 þ b2k xk ½n  2 ð7:105Þ
a1k yk ½n  1  a2k yk ½n  2

Example 7.2
Shows the overall scaling procedure for cascade system. The designed filter indi-
cates the LPF with 0:5p cutoff frequency in 4th order system. The design method is
Butterworth.

0:0940 þ 0:3759z1 þ 0:5639z2 þ 0:3759z3 þ 0:0940z4


HðzÞ ¼
1 þ 0:4860z2 þ 0:0177z4

The frequency response is below.


Solution
The SOS implementation is below with global gain.

1 þ 2z2 þ z2 1 þ 2z2 þ z2


HðzÞ ¼ 0:0940
1 þ 0:0396z2 1 þ 0:4465z2

The corresponding pole zero plot is below.


Distribute the global gain into individual stage as below.

1 þ 2z2 þ z2 1 þ 2z2 þ z2


HðzÞ ¼ 0:3066 0:3066 ¼ H1 ðzÞH2 ðzÞ
1 þ 0:0396z2 1 þ 0:4465z2
7.2 Filter Implementation Components 543

The scale factor for cumulative stage is below. Choose one of the norms for
factor.
8 P1
>
> k¼0 jh1 ½k j ¼ L1  1:2515
1 < maxjH1 ðejx Þj ¼ L1 ¼ 1:1796
¼ qffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffi
x
s1 >
: P1 ðh1 ½kÞ2 ¼ L2  0:7465
>
k¼0

8 P1
>
> k¼0 jh½k j ¼ L1  1:6469
1 < maxjH ðejx Þj ¼ L1 ¼ 1:0000
¼ qffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffi
x
s2 >
: P1 ðh½kÞ2 ¼ L2  0:7071
>
k¼0

Observe that the h½n and H ðejx Þ for the s2 is the overall impulse and frequency
response, respectively. The scaled SOS is derived as below.
^ ^ ^
^ 1 þ 2z1 þ z2 b01 þ b11 z1 þ b21 z2
H 1 ðzÞ ¼ 0:3066s1 ¼
1 þ 0:0396z2 1 þ a11 z1 þ a21 z2
^ ^ ^
^ s2 1 þ 2z1 þ z2 b02 þ b12 z1 þ b22 z2
H 2 ðzÞ ¼ 0:3066 ¼
s1 1 þ 0:4465z2 1 þ a12 z1 þ a22 z2

The cascade connection for LPF is shown below in Fig. 7.26. The H1(z) contains
the pole pair close to the origin; therefore, the frequency response expects the less
peaky response.
For individual scaling factor, the frequency responses to y1[n] and y2[n] from
input x[n] are shown in Fig. 7.27. The jH1 ðejx ÞjjH2 ðejx Þj is equivalent to the
absolute magnitude of the overall response. The scaling factor only modifies the
height of the individual response without altering the shape. The L1 demonstrates
the most conservative scaling which prevents the overflow with confidence.
However, the L2 shows the most liberal scaling which improve the output SNR with
sacrificing the overflow.

Fig. 7.26 Cascade


connection for SOS Input x[n] y1[n] y2[n]
H1(z) H2(z)
544 7 Implementation Matters

Prog. 7.8 MATLAB program for Figs. 7.24, 7.25, and 7.27.
[b,a] = bu er(4,0.5);
[z,p,k] = 2zp(b,a);
[h0,w0] = freqz(b,a,2^10);
[sos0,g0] = 2sos(b,a);
bb = sqrt(g0)*sos0(1,1:3);
aa = sos0(1,4:6);
bbb = conv(bb*sqrt(g0),sos0(2,1:3));
aaa = conv(aa,sos0(2,4:6));
[h1,w1] = freqz(bb,aa,2^10);
[h2,w2] = freqz(bbb,aaa,2^10);
[hn1,n1] = impz(bb,aa,2^10);
[hn2,n2] = impz(bbb,aaa,2^10);
s1_1 = 1/norm(hn1,1); bb1_1 = s1_1*bb;
s1_2 = 1/norm(hn2,1); bbb1_2 = s1_2*bbb;
sinf_1 = 1/max(abs(h1)); bbinf_1 = sinf_1*bb;
sinf_2 = 1/max(abs(h2)); bbbinf_2 = sinf_2*bbb;
s2_1 = 1/norm(hn1,2); bb2_1 = s2_1*bb;
s2_2 = 1/norm(hn2,2); bbb2_2 = s2_2*bbb;
[h3,w3] = freqz(bb1_1,aa,2^10);
[h4,w4] = freqz(bbb1_2,aaa,2^10);
[h5,w5] = freqz(bbinf_1,aa,2^10);
[h6,w6] = freqz(bbbinf_2,aaa,2^10);
[h7,w7] = freqz(bb2_1,aa,2^10);
[h8,w8] = freqz(bbb2_2,aaa,2^10);

figure,
zplane(z,p);
figure,
plot(w1/pi,abs(h0)), grid
x cks([0 1/4 1/2 3/4 1]), ylim([0 1.25])
figure,
subplot(221), plot(w2/pi,abs(h1),w3/pi,abs(h2)), grid
x cks([0 1/4 1/2 3/4 1]), ylim([0 1.75])
subplot(222), plot(w2/pi,abs(h3),w3/pi,abs(h4)), grid
x cks([0 1/4 1/2 3/4 1]), ylim([0 1.75])
legend('|H_1(e^{j\omega})|','|H_1(e^{j\omega})||H_2(e^{j\omega})|')
subplot(223), plot(w2/pi,abs(h5),w3/pi,abs(h6)), grid
x cks([0 1/4 1/2 3/4 1]), ylim([0 1.75])
subplot(224),plot(w2/pi,abs(h7),w3/pi,abs(h8)), grid
x cks([0 1/4 1/2 3/4 1]), ylim([0 1.75])

The L1 presents the moderate scaling that provides the balance between the
output SNR and overflow possibility. ∎
7.2 Filter Implementation Components 545

Without scaling With L 1 scaling


1.75 1.75
1.50 1.50 |H 1(e j )|
1.25 1.25 |H 1(e j )||H2(e j )|
Magnitude

1 1
0.75 0.75
0.50 0.50
0.25 0.25
0 0
0 /4 /2 3 /4 0 /4 /2 3 /4

With L Scaling With L 2 Scaling


1.75 1.75
1.50 1.50
1.25 1.25
Magnitude

1 1
0.75 0.75
0.50 0.50
0.25 0.25
0 0
0 /4 /2 3 /4 0 /4 /2 3 /4
Radian frequency ( ) Radian frequency ( )

Fig. 7.27 Individual frequency response with or without scaling for jH1 ðejx Þj and
jH1 ðejx ÞjjH2 ðejx Þj

Example 7.3
The overflow likelihood for each scaling method can be investigated by simple
MATLAB experiment as below. The random signal with zero mean and uniform
distribution is provide to the system input of Example 7.2. The input is ranged from
−1 to 1 to avoid the overflow and shown below as histogram.
Solution
The subsequent histograms represent the outputs of the LPF SOS for each scaling
method. The histogram bin size for overflow range is exaggerated for better rep-
resentation. The blue and brown bin signifies the y1[n] and y2[n] output,
respectively.
546 7 Implementation Matters

Prog. 7.9 MATLAB program for Figs. 7.28 and 7.29.


rng('default')
xn = rand(2^16,1)*2-1;
nxn = xn./max(abs(xn));
% … Insert the Prog. 7.8 here for below variables
out0_1 = filter(bb, aa, nxn);
out0_2 = filter(bbb, aaa, out0_1);
out1_1 = filter(bb1_1, aa, nxn);
out1_2 = filter(bbb1_2, aaa, out1_1);
ou nf_1 = filter(bbinf_1, aa, nxn);
ou nf_2 = filter(bbbinf_2, aaa, ou nf_1);
out2_1 = filter(bb2_1, aa, nxn);
out2_2 = filter(bbb2_2, aaa, out2_1);

figure,
edges = [-1.5 -1:1/16:1 1.5];
histogram(nxn,edges,'Normaliza on','probability'), grid;
set(gca,'YScale','log'), ylim([10^-4 1])
figure,
subplot(221), h1 = histogram(out0_1,edges,'Normaliza on','probability'),
grid; hold on
h1 = histogram(out0_2,edges,'Normaliza on','probability');
set(gca,'YScale','log'), ylim([10^-4 1])
subplot(222),h1 = histogram(out1_1,edges,'Normaliza on','probability'),
grid; hold on
h1 = histogram(out1_2,edges,'Normaliza on','probability');
set(gca,'YScale','log'), ylim([10^-4 1])
subplot(223),h1 = histogram(ou nf_1,edges,'Normaliza on','probability'),
grid; hold on
h1 = histogram(ou nf_2,edges,'Normaliza on','probability');
legend('y_1[n]','y_2[n]')
set(gca,'YScale','log'), ylim([10^-4 1])
subplot(224),h1 = histogram(out2_1,edges,'Normaliza on','probability'),
grid; hold on
h1 = histogram(out2_2,edges,'Normaliza on','probability');
set(gca,'YScale','log'), ylim([10^-4 1])

As expected, L1 shows the least and L2 illustrates the most overflow probability.
The L1 is middle and less than the unscaled in terms of overflow likelihood. We
can select the scaling method based on the requirement of the overflow and
dynamic range. Fundamentally, the scaling does not change the system stability;
however, fixed point number scaling could induce the pole relocations due to the
sensitivity. After design and scaling, the procedure to check the response and
stability is recommended. ∎
7.2 Filter Implementation Components 547

100

10-1
Probability

10-2

10-3

10-4
-1.5 -1 -0.5 0 0.5 1 1.5
Input

Fig. 7.28 Input signal probability histogram to investigate the overflow

10 0 10 0
Probability

Probability

-2 -2
10 10

10 -4 10 -4
-1 0 1 -1 0 1
Output without scaling Output with L1 scaling

0 0
10 10
y 1[n]
y 2[n]
Probability

Probability

-2 -2
10 10

-4 -4
10 10
-1 0 1 -1 0 1
Output with L scaling Output with L2 scaling

Fig. 7.29 Probability histograms of SOS output y1[n] and y2[n] with random input shown in
Fig. 7.28
548 7 Implementation Matters

– Overall quantization error sources in filters


The quantization can be classified as two different categories as below. The first
category quantization takes place at the signal acquisition stage along with sam-
pling process. The quantization is known as analog to digital conversion. The
analog signal which is real number in time and magnitude is discretized into the
integer domain. The second category quantization happens at the multiplication
stage which requires the double length space to store the product with full precision.
If the hardware cannot support the sufficient storage, the multiplication outcome is
truncated for further processing. Usually the LSBs are abandoned. The noise
variance of two categories are shown below. Note that the data is kept at B + 1 bit
storage.
1. Input signal quantization from real number to binary fraction number
Xm2 22B
r2noise ¼ 12
ð7:106Þ

2. Large bit binary fraction number to reduced size binary fraction number
2B
r2noise ¼ 212 ð7:107Þ

The digital filter accepts the quantized signal x[n] and produces the corre-
sponding output y[n]. The only quantization related to the digital filter is the second
category quantization from multiplication. The first category quantization is con-
cerned at the front-end of the digital filter system. Note that we previously analyzed
the SNR for the input signal quantization due to the conversion between the real
number to the integer number (binary fraction number). After the analog to digital
conversion, the information is processed as quantized and sampled form in the
digital filter. We need to investigate the quantization from the multiplication as the
SNR in the filter output. Let’s see the below example.

y½n ¼ b0 x½n þ b1 x½n  1 þ b2 x½n  2 ð7:108Þ

The input signal x[n] and individual coefficient bk are quantized by the B + 1 bit
binary fraction number. The current output y[n] is produced by the sum of three
products which generate the 2B + 2 bit binary fraction. If the given FIR filter is
properly scaled, the output y[n] can be represented by the 2B + 2 bit number with
perfect precision. For any size FIR filter, the output can be described by the
manageable length arithmetic operations. However, the IIR filter requires the further
size to realize the system without the quantization problem. See below example.

y½n ¼ b0 x½n þ a1 y½n  1 ð7:109Þ

Each product presents the 2B + 2 bit outcome and sum of them delivers the
current output y[n]. Unlike FIR filter, the IIR filter contains the recursive loop
7.2 Filter Implementation Components 549

which uses the current output as the input to the next output. Therefore, the output
size should be increased by B + 1 bits for every iterations; otherwise, the output
loses information precision. The IIR filter cannot be implemented with the perfect
precision due to the recursive property.
The proper quantization is required for FIR and IIR filters because of hardware
limitation. Below equation shows the SOS with quantizer for each product com-
putation. The 2B + 2 bit product outcome is converted to the B + 1 bit result by
quantizer. Note that the summation for output y[n] is carefully scaled by the scaling
factor to reduce the overflow probability.

y½n ¼ QB ðb0 x½nÞ þ QB ðb1 x½n  1Þ þ QB ðb2 x½n  2Þ


ð7:110Þ
QB ða1 y½n  1Þ  QB ða2 y½n  2Þ

The quantization for the product can be considered as the additive error which is
the difference between the real product and quantized product. Subsequent equation
demonstrates the quantization with induced error.

y½n ¼ ðb0 x½n þ e0 ½nÞ þ ðb1 x½n  1 þ e1 ½nÞ þ ðb2 x½n  2 þ e2 ½nÞ
ð7:111Þ
ða1 y½n  1  e3 ½nÞ  ða2 y½n  2  e4 ½nÞ

According to the previous derivation, the variance for the individual quantized
error is shown below.
2B
r2ek ¼ 212 k ¼ 0; 1; . . .; 4 ð7:112Þ

The quantization error can be represented by single noise source as long as all
the noise sources ek[n] are independent of the input and each other.

y½n ¼ b0 x½n þ b1 x½n  1 þ b2 x½n  2  a1 y½n  1  a2 y½n  2 þ e½n


ð7:113Þ
where e½n ¼ e0 ½n þ e1 ½n þ e2 ½n þ e3 ½n þ e4 ½n

The overall quantization noise variance is the addition of individual variances


based on the independence condition. The total variance is shown below.
2B
r2e ¼ 5 212 ð7:114Þ

The y[n] is the weighted combination of input x[n]s, output y[n]s, and noise e[n];
therefore, the generated noise can be regarded as another input to the filter. The
filter output is named as r[n] for pure noise input e[n]. Since there is no input, the
difference equation can be organized as below.

r ½n ¼ a1 r ½n  1  a2 r ½n  2 þ e½n ð7:115Þ

The output noise variance r2r is proportional to the absolute squared sum of the
impulse response which is derived from noise source only. The higher impulse
550 7 Implementation Matters

response energy increases the output noise variance. Also, higher filter order
amplifies the output noise variance as below.

P
1 2B P
1
r2r ¼ r2e jhe2r ½nj2 ¼ 5 212 jhe2r ½nj2 ð7:116Þ
n¼0 n¼0

For general filter, the transfer function is described as below. The filter type
decides the numerator and denominator order.

b0 þ    þ bM1 zðM1Þ þ bM zM BðzÞ


HðzÞ ¼ ¼ ð7:117Þ
1 þ a1 z1 þ    þ aN zN AðzÞ

The output noise variance requires the impulse response from the quantization
noise without input signal. The denominator of the transfer function is utilized to
compute the impulse response as below. Observe that the numerator contributes to
the input signal only.
ztrans 1
he2r ½n $ AðzÞ
ð7:118Þ

The given transfer function provides the below output noise variance due to the
quantization. The assigned bit size B is only positive factor for the output noise
variance; in other words, the increased bit size reduces the noise variance.

2B P
1
r2r ¼ ðM þ 1 þ N Þ 212 jhe2r ½nj2 ð7:119Þ
n¼0

For FIR filter, there is no recursive output loop; hence, the output noise variance
is presented as below.
2B
r2r ¼ ðM þ 1Þ 212 ð7:120Þ

One method to improve the output noise variance is employing the double length
accumulator (multiplier and adder) and applying the quantization at the final
step. The 2B + 2 bit products are processed without length modification to
cumulate. The accumulated output is quantized at the last step as shown in below.
Hence, there is single quantization procedure in any type and order filter.

y½n ¼ QB ðb0 x½n þ    þ bM x½n  M   a1 y½n  1  . . .aN y½n  N Þ ð7:121Þ

The single quantization step is equivalent to the single noise source as below.

y½n ¼ b0 x½n þ    þ bM x½n  M   a1 y½n  1


ð7:122Þ
. . .  aN y ½ n  N  þ e ½ n
7.2 Filter Implementation Components 551

The noise variance is given below for the rounding approximation with uniform
distribution.
2B
r2e ¼ 212 ð7:123Þ

Based on the single quantization noise, the output noise variance is derived as
below.

2B P
1 ztrans 1
r2r ¼ 212 jhe2r ½nj2 where he2r ½n $ AðzÞ ð7:124Þ
n¼0

Compare to the multi-quantization noise performance, the single quantization


with double length accumulator significantly improves the output noise variance in
the order of filter length.
Example 7.4
Analyze the quantization noise performance. The designed filter indicates the LPF
with 0:5p cutoff frequency in 4th order system. The design method is Butterworth.
1 2 3
þ 0:0940z4
HðzÞ ¼ 0:0940 þ 0:3759z1 þ 0:4860z
þ 0:5639z þ 0:3759z
2 þ 0:0177z4

¼ BðzÞ
AðzÞ

Solution
The corresponding SOS for the given LPF is below. Note that the G is the global
gain.

1 þ 2z2 þ z2 1 þ 2z2 þ z2 B1 ðzÞ B2 ðzÞ


HðzÞ ¼ 0:0940 ¼G
1 þ 0:0396z2 1 þ 0:4465z2 A1 ðzÞ A2 ðzÞ

In order to compute the output noise variance, the impulse response for transfer
function denominator is specified as below. Any scaling factors do not affect the
impulse response since the scaling is applied over the numerator only.

ztrans 1
he2r ½n $
AðzÞ
ztrans 1
he2r1 ½n $ A1 ðzÞ

ztrans 1
he2r2 ½n $
A2 ðzÞ

The he2r ½n is the denominator impulse response for overall LPF. The he2r1 ½n
and he2r2 ½n is the first and second section of denominator SOS impulse response,
respectively. The output noise variance for multiple quantization is calculated as
552 7 Implementation Matters

below. The integer scaling factor in the variance is equivalent to the number of
multiplications on the filter difference equation. Observe that the quadruple scaling
in the r2r1 and r2r2 can be further reduced by use of particular coefficient such as 1 or
2. The selected bit length is 15 for B.

22B X
1
230
r2r ¼ 7 jhe2r ½nj2 ¼ 7 1:2959 ¼ 7:0403  1010
12 n¼0 12

2B P
1 30
r2r1 ¼ 4 212 jhe2r1 ½nj2 ¼ 4 212 1:0016 ¼ 3:1093  1010
n¼0

22B X
1
230
r2r2 ¼ 4 jhe2r2 ½nj2 ¼ 4 1:2490 ¼ 3:8774  1010
12 n¼0 12

The output noise variance for single quantization system is derived as below.
The integer scaling is not required; therefore, the variance is significantly lower
than the multi quantization counterpart.

22B X
1
230
r2r ¼ jhe2r ½nj2 ¼ 1:2959 ¼ 1:0058  1010
12 n¼0 12

2B P
1 30
r2r1 ¼ 212 jhe2r1 ½nj2 ¼ 212 1:0016 ¼ 7:7732  1011
n¼0

22B X
1
230
r2r2 ¼ jhe2r2 ½nj2 ¼ 1:2490 ¼ 9:6935  1011
12 n¼0 12

The output SNR from the quantization can be calculated by the previously
derived output noise variance as below. The r2signal is the output signal variance
which can be computed by various methods. We assume that the r2signal is given.
r2

 
SNR ¼ 10 log10 signal
r2noise
¼ 10 log10 r2signal  10 log10 r2noise

The calculated SNRs are given as below in Table 7.5.

Table 7.5 SNR of given H(z) for both quantization scenarios


Multi quantizations Single quantization

SNRr 10 log10 r2signal þ 91:5241 dB 10 log10 r2signal þ 99:9751 dB



SNRr1 10 log10 r2signal þ 95:0734 dB 10 log10 r2signal þ 101:094 dB



SNRr2 10 log10 r2signal þ 94:1146 dB 10 log10 r2signal þ 100:135 dB


7.2 Filter Implementation Components 553

The single quantization system demonstrates the higher SNR values than the
multi quantization system’s SNR as we expected. The cascade SOS system presents
the increased SNR than the single overall filter system in the individual section.
Therefore, we recommend the single quantization SOS cascade filter system with
double length accumulator.

7.3 FIR Filter Implementations

– FIR realization structures


The FIR filter produces the output y[n] by summing the weighted recent N + 1
inputs. The mathematical representation is below. Note that the bk and h[k] are
equivalent mutually for the FIR filter.

y½n ¼ b0 x½n þ b1 x½n  1 þ b2 x½n  2 þ    þ bN x½n  N  ð7:125Þ

The corresponding block diagram is illustrated in Fig. 7.30 and known as direct
form or transversal structure. The signal follows the arrow line for multiplication,
addition, and delay. The signal is separated by the delay block in time; in other
words, the signal is propagated though the delay block in every synchronized
discrete time. For example, the signal before the delay block is the x[n] and after the
block is the x[n − 1]. The signals over the any wires, additions, and multiplications
indicate the certain times to yield the current output y[n].
The MATLAB provides the convolution sum by the conv function. The FIR
filter realization by using the computer language requires the following steps.
1. Initialize the program by defining below constant and empty variables.
– N + 1 length memory initialized by bk
– N + 1 length memory initialized by zero for delay components.
2. Shift right the delay component
– Shift right one memory element at a time from right-end to the left-bound
– The oldest (rightest) data is removed by the shift right operation

x[n] ...
z-1 z-1 z-1 z-1
b0 b1 b2 b3 bN-1 bN

... y[n]
+ + + + +

Fig. 7.30 Block diagram for FIR filter in direct form or transversal structure
554 7 Implementation Matters

– The established blank space by the shift operation is stuffed by the new data
x[n].
3. Accumulate the products for output y[n]
P
– y½n ¼ Nk¼0 bk x½n  k
4. Repeat the step 2 and 3 for all input data.
Below block diagram indicates the execution sequence for step 2 and 3. Further
algorithm exploration can reduce the execution complexity; however, overall
computational procedure is maintained as shown in Fig. 7.31.
The reversal operations in the block diagram provides the equivalent filter. The
procedure is known as transposition [6] and described as following.
– Reverse direction of each signal flow
– Reverse direction of each multiplication and interconnection
– Change junctions to additions and vice versa
– Interchange the input and output signals
– Flipping the diagram horizontally (optional).
The direct form FIR filter is converted to the transposed direct (or transversal)
FIR filter as below. Without the horizontal flipping, the input is located on the right
as below in Fig. 7.32.
To follow the conventional structure, below figure shows the flipped transposed
FIR filter. The computational complexity is identical due to the equal number of
additions, multiplications, and delays between the direct and transposed FIR fil-
ter as shown in Fig. 7.33.

New x[n] x[n-1] x[n-2] x[n-3] x[n-N+1] x[n-N] Data


data in Latest Previous ... ... ... Oldest drop

x[n] x[n-1] x[n-2] x[n-3] x[n-N+1] x[n-N]

× × × × × ×

b0 b1 b2 b3 bN-1 bN

+ y[n]

Fig. 7.31 Block diagram for FIR filter realization by computer language
7.3 FIR Filter Implementations 555

y[n]
+ z-1 + z-1 + z-1 + ... + z-1

b0 b1 b2 b3 bN-1 bN

... x[n]

Fig. 7.32 Block diagram for FIR filter realization in transposed direct form

y[n]
z-1 + ... + z-1 + z-1 + z-1 +
bN bN-1 b3 b2 b1 b0

x[n] ...

Fig. 7.33 Block diagram for FIR filter realization in flipped transposed direct form

The computational procedure of the transposed FIR filter is illustrated below as


block diagram. The direct form performs the computation by shifting and accu-
mulating in the divided stage. The transposed FIR filter executes the shifting and
accumulating simultaneously as below in Fig. 7.34.
The circle in the above figure denotes the kth fundamental computational unit
which assigns to the subsequent memory u[n − k] with sum of previous memory u
[n − k+1] value and bN−k weighted recent value x[n]. The computational unit is
realized from right-end to the left-bound. The transposed FIR filter implementation
by using the computer language requires the following steps.
1. Initialize the program by defining below constant and empty variables.
– N + 1 length memory initialized by bk
– N length memory initialized by zero for delay components
2. Execute following sequence

x[n]

bN bN-1 bN-2 bN-3 ... b1 b0

× × × × ... × ×

u[n] + u[n-1] + u[n-2] + u[n-3] ... + u[n-N+1] +


y[n]

Fig. 7.34 Computational procedure of the transposed FIR filter


556 7 Implementation Matters

– y ½ n ¼ u½ n  N þ 1 þ b0 x ½ n
– u½n  k ¼ u½n  k þ 1 þ bNk x½n
for k ¼ N  1; N  2; . . .2; 1
– u ½ n  ¼ bN x ½ n 
3. Repeat the step 2 for all input data.
According to the previous analysis, we should stay away from the high order
filter design because of numerical ill-condition generated by high sensitivity. Let’s
revisit the sensitivity analysis. The given FIR filter with N order is below.

HðzÞ ¼ b0 þ    þ bN1 zðN1Þ þ bN zN ð7:126Þ

Rewrite the transfer function in terms of zeros as below.

HðzÞ ¼ b0 ð1  z1 z1 Þð1  z2 z1 Þ. . .ð1  zN z1 Þ ð7:127Þ

The derived sensitivity of the FIR filter is below.

@zj zNk
@bk ¼  QN j
ð7:128Þ
b0 i¼1;i6¼j
ðzj zi Þ

The filter order and zero locations determine the sensitivity of FIR filter. In fact,
the direct form is generally utilized for FIR filter realization because the zeros are
likely to be spread evenly for linear phase FIR filter. In addition, the zero-location
variation does not produce the filter instability in FIR filter. As long as the fre-
quency response follows the desired specification with tolerable range, the direct
form realization is feasible choice. The frequency response of the FIR filter can
present the impact of the coefficient quantization error for worst situation. Below is
the definition of coefficient quantization error. Note that the bk and h[k] are equal for
FIR filter.

QB ðh½kÞ ¼ h½k þ he ½k where k ¼ 0; 1; . . .; N ð7:129Þ

The frequency response of the FIR filter is given below.

^ P
N P
N
H ðejx Þ ¼ QB ðh½nÞejxn ¼ ðh½n þ he ½nÞejxn
n¼0 n¼0
ð7:130Þ
P
N
¼ H ðe Þ þ He ðe Þ where He ðejx Þ ¼
jx jx
he ½nejxn
n¼0

The range of the frequency response error is derived by using the inequality
relation as below.
7.3 FIR Filter Implementations 557

 jx  XN
H e e  jhe ½nj ejxn  ðN þ 1Þ2ðB þ 1Þ ð7:131Þ
n¼0

Example 7.5
For below configurations, find maximum frequency response error in magnitude
from coefficient quantization. Also calculate the corresponding pass band ripple Ap
and stop band attenuation Ast
– FIR filter with 31 length (N = 30) and 16-bit quantization
– FIR filter with 31 length (N = 30) and 8-bit quantization
Solution
The type I FIR filter with 31 length (N = 30) and 16-bit quantization (B = 15)
presents the 0.00047302 maximum frequency response error in magnitude. The
corresponding pass band ripple Ap and stop band attenuation Ast are below. Note
that the Rp and Rst are established to the maximum frequency response error from
the quantization.

AP ¼ 40 log10 ð1 þ Rp Þ ¼ 40 log10 ð1 þ 0:00047302Þ ¼ 0:0082 dB


Ast ¼ 20 log10 Rst ¼ 20 log10 ð0:00047302Þ ¼ 66:5024 dB

The identical filter with 31 length (N = 30) and 8-bit quantization (B = 7) pre-
sents the 0.1211 maximum frequency response error in magnitude. The corre-
sponding pass band ripple Ap and stop band attenuation Ast is below.

AP ¼ 40 log10 ð1 þ Rp Þ ¼ 40 log10 ð1 þ 0:1211Þ ¼ 1:9858 dB


Ast ¼ 20 log10 Rst ¼ 20 log10 ð0:1211Þ ¼ 18:3376 dB


The derived maximum frequency response error from the quantization is very
conservative limit because of the rare possibility to hit the maximum error for all
coefficient quantizations. By comparing the two situations above, sufficiently long
bit assignment for quantization exponentially improves the filter performance in
term of ripple. The filter length is the linear factor in the maximum error function as
Eq. (7.131); hence, the direct form can be used for the filter realization. The
increased filter length could be counterbalanced by the higher precision quantiza-
tion for acceptable magnitude ripples. The FIR filter with very rough quantization
or high-order system based on the closely spaced zeros can be considered to realize
smaller sets of zeros with cascade structure as shown below.

HðzÞ ¼ H1 ðzÞH2 ðzÞ


ð7:132Þ
¼ ðb01 þ b11 z1 þ b21 z2 Þðb02 þ b12 z1 þ b22 z2 Þ
558 7 Implementation Matters

The above example consists of two second order FIR filters in cascaded structure
to deliver fourth order overall. The FIR filter with linear phase or unit circle zeros
provide the further exploration on the realization structure. Numerous variations
which are not shown here can be found under the topic of FIR filter realizations.

7.4 IIR Filter Implementations

– IIR realization structures


The general transfer function for the IIR filter is shown again in below. The IIR
filter includes the feedforward as well as feedback component simultaneously. The
feedforward uses the input signal x[n] with delays and the feedback utilizes the
output signal y[n] with delays.
ðN1Þ N
HðzÞ ¼ b0 þ1  þ bN1 z þ bN z
þ a1 z1 þ  þ aM zM ¼ BðzÞ
AðzÞ
ð7:133Þ

The given transfer function can be considered as the cascade connection between
the B(z) and 1/A(z). Therefore, the feedforward realization is followed by the
feedback implementation as below. This realization is called direct form I which is
the fundamental structure as shown in Fig. 7.35.

Fig. 7.35 Block diagram for x[n] b0 y[n]


IIR filter realization in direct + +
form I -
-1
z z-1
b1 a1
+ +

z-1 z-1
b2 a2
+ +
...

...

...

...

bN-1 aM-1
+ +

z-1 z-1
bN aM
7.4 IIR Filter Implementations 559

The IIR filter in direct form I realization by using the computer language requires
the following steps.
1. Initialize the program by defining below constant and empty variables.
– N + 1 length memory initialized by bk
– M length memory initialized by ak
– N + 1 length memory initialized by zero for feedforward delays
– M length memory initialized by zero for feedback delays
2. Shift right the feedforward delays
– Shift right one memory element at a time from right-end to the left-bound
– The oldest (rightest) data is removed by the shift right operation
– The established blank space by the shift operation is stuffed by the new data
x[n]
3. Accumulate the products for output y[n]
P P
– y½n ¼ Nk¼0 bk x½n  k  M k¼1 ak y½n  k 

4. Shift right the feedback delays


– Shift right one memory element at a time from right-end to the left-bound
– The oldest (rightest) data is removed by the shift right operation
– The established blank space by the shift operation is stuffed by the new data
y[n]
5. Repeat the step 2, 3, and 4 for all input data
Below block diagram indicates the execution sequence for step 2, 3, and 4.
Further algorithm exploration can reduce the execution complexity; however,
overall computational procedure is maintained as shown in Fig. 7.36.
The given transfer function also can be considered as the cascade connection
between the 1/A(z) and B(z) in reverse order of the direct form I. Therefore, the
feedback realization is followed by the feedforward implementation as below
Fig. 7.37a. The realization includes the double delay lines which represent the
identical signal flow. Merging the delay lines presents simplified structure as the
direct form II. The direct form II is shown in Fig. 7.37b and also known as the
canonic form which uses the minimum number of delay elements in the realization.
Using the transposition property, the direct form II filter is converted to the
transposed direct form II (or canonic form) IIR filter as Fig. 7.37c. Transposition
reduces the adder number; however, the hardware benefit is limited if the system
does not support the three-port adder. Note that the order of numerator and
denominator is equal for simple illustration.
The IIR filter in direct form II realization by using the computer language
requires the following steps. Assume that M is equal to N here.
560 7 Implementation Matters

New x[n] x[n-1] x[n-2] x[n-3] ...


...
x[n-N+1]
...
x[n-N] Data
data in Latest Previous ... Oldest drop

x[n] x[n-1] x[n-2] x[n-3] ... x[n-N+1] x[n-N]

× × × × ... × ×

b0 b1 b2 b3 ... bN-1 bN

+ y[n]

-
a1 a2 a3 a4 ... a M-1 aM

× × × × ... × ×

y[n-1] y[n-2] y[n-3] y[n-4] ... y[n-M+1] y[n-M]

New
outcome
y[n-1] y[n-2] y[n-3] y[n-4] ... y[n-M+1]
...
y[n-M] Data
y[n] in Latest Previous ... ... Oldest drop

Fig. 7.36 Block diagram for IIR filter direct form I realization by computer language

1. Initialize the program by defining below constant and empty variables.


– N + 1 length memory initialized by bk
– M length memory initialized by ak
– N + 1 (or M + 1) length memory initialized by zero for delays
2. Accumulate the products for u[n] and y[n]
P
– u½ n ¼ x ½ n  Mk¼1 ak u½n  k 
P
– y½n ¼ Nk¼0 bk u½n  k
3. Shift right the delay components
– Shift right one memory element at a time from right-end to the left-bound
– The oldest (rightest) data is removed by the shift right operation
– The established blank space u[n] by the shift operation leave empty. The
space will be written by the accumulated products at step 2.
7.4 IIR Filter Implementations 561

x[n] b0 y[n] x[n] b0 y[n] x[n] b0 y[n]


+ + + + +
- -
z-1 z-1 z-1 z-1
a1 b1 a1 b1 b1 - a1
+ + + + +

z-1 z-1 z-1 z-1


a2 b2 a2 b2 a2
+-
b2
+ + + +

...

...
...

...

...

...

...

...

...
...

aM-1 bN-1 aM-1 bN-1 bN-1 - aM-1


+ + + + +

z-1 z-1 z-1 z-1


aM bN aM bN bN - aM
+
(a) (b) (c)

Fig. 7.37 Block diagram for IIR filter realization in direct form I with reverse order (a), direct
form II (b), and transposed direct form II (c)

4. Repeat the step 2 and 3 for all input data


Below block diagram below indicates the execution sequence for step 2 and 3.
Further algorithm exploration can reduce the execution complexity; however,
overall computational procedure is maintained as shown in Fig. 7.38.
The IIR filter in transposed direct form II realization by using the computer
language requires the following steps. Assume that M is equal to N here. The circle
in the below figure denotes the kth fundamental computational unit for memory u
[n − k]. The computational unit is executed from right-end to the left-bound.
1. Initialize the program by defining below constant and empty variables.
– N + 1 length memory initialized by bk
– M length memory initialized by ak
– M (or N) length memory initialized by zero for delays
2. Execute following sequence
– y ½ n  ¼ u ½ n  M þ 1  þ b0 x ½ n 
– u½n  k ¼ u½n  k þ 1 þ bNk x½n  aMk y½n
for k ¼ M  1; M  2; . . .2; 1 or k ¼ N  1; N  2; . . .2; 1
– u ½ n  ¼ bN x ½ n   a M y ½ n 
3. Repeat the step 2 for all input data
Previously we investigated the IIR filter sensitivity which presents the significant
performance degradation in direct form realization. The cascade SOS structure is
recommended to minimize the side effect from the quantization. The rule of thumb
for pairing and sequencing was suggested earlier. The SOS structure can use the
direct form II with or without the transposition as below Figs. 7.39 and 7.40.
562 7 Implementation Matters

a1 a2 a3 aM-1 aM

x[n]

u[n] u[n-1] u[n-2] u[n-3] u[n-M+1] u[n-M]

b0 b1 b2 b3 bN-1 bN

y[n]

u[n] u[n-1] u[n-2] u[n-3] ... u[n-M+1] u[n-M]


Data
drop

Fig. 7.38 Block diagram for IIR filter direct form II realization by computer language. Assume
that M is equal to N

x[n]

bM bM-1 bM-2 bM-3 ... b1 b0

× × × × ... × ×

+ u[n] + u[n-1] + u[n-2] + u[n-3] ... + u[n-M+1] +


y[n]

- - - - -
× × × × ... ×

aN aN-1 aN-2 aN-3 ... a1

Fig. 7.39 Computational procedure of the transposed direct form II IIR filter

The SOSs are ordered from least-peaked to most-peaked in gain; therefore, the
SOS with poles closest to the unit circle is located last in the cascade. In fact, the
most-peaked to least-peaked ordering also shows the comparative performance as
well. Both consistent orderings are used in the practical realization. The SOSs with
7.4 IIR Filter Implementations 563

x[n]
+
b01
+ +
b02
+ ... +
b0L
+
y[n]
- - -
z-1 z-1 z-1

+
a11 b11
+ +
a12 b12
+ ... +
a1L b1L
+

z-1 z-1 z-1


a21 b21 a22 b22 a2L b2L

y[n]
x[n] b01
+
b02
+ ... b0L
+

z-1 z-1 z-1


b11
+
- a11 b12
+
- a12
... b1L
+
- a1L

z-1 z-1 z-1


a21 a22 a2L
+- +- +-
b21 b22 b2L

Fig. 7.40 Block diagram for transposed direct form II IIR filter realization in cascade SOS
structure with (below) and without (above) transposition

parallel connection are another reasonable choice for the realization in terms of
various performance aspects; however, the cascade implementation is more likely
used because of zero controllability in coefficient quantization process.
The recursive property of the quantized IIR filter demonstrates the nonlinear
characteristic known as limit cycle. The output could persist to fluctuate forever
whilst the input stays zero. The limit cycle process is complicated and tricky to
understand; hence, we will not try to discuss the limit cycle in detail here. Once we
have the unexpected output from the zero input, the possible solutions are below.
– Increase the quantization length
– Use the quantization after the double length accumulation
– Use the saturation overflow
The further information can be found on the papers [9, 10]. The FIR filter cannot
provide the limit cycle behavior because of the non-recursive routines in the
computation. If the system cannot tolerate the limit cycle, then use the FIR filter.

7.5 Frequency Domain Filter Realization

The time domain filter is realized by the difference equation or convolution sum.
The difference equation can apply on the FIR and IIR filter; however, the convo-
lution sum is only valid for the FIR filter. Observe that the difference equation is
564 7 Implementation Matters

equivalent to the convolution sum for the FIR filter with delayed inputs. Another
implementation choice we can think of is the frequency domain realization by using
the following relation.

DFT
y½n ¼ x½n h½n $ Y ½k ¼ X ½kH ½k ð7:134Þ

The convolution sum is identical to the simple multiplication on the discrete


frequency domain. The benefits of the frequency domain filtering are complexity
and simplicity. We can specify the filter requirement directly on H[k] and realize the
filtering by the multiplication. However, the cost of the benefit is the transformation
known as DFT. The filter involves the DFT twice from and to between two
domains. On the certain condition, the frequency domain filtering is attractive
method in terms of complexity. The fast DFT algorithm and realization condition
will be introduced in the following sections.
– Fast DFT algorithm
The DFT requires the significant computation for analysis and synthesis transfor-
mation. Below revisits the DFT equations. The complex number by exponential
part is presented by the cosine and sine function; therefore, the complex number
arithmetic increases the complexity.

P
N1 2p
X ½k  ¼ x½nej N kn
n¼0
ð7:135Þ
1
P
N1 2p
x½n ¼ N X ½kej N kn
k¼0

Note that the complex exponential demonstrates the periodicity property. The kn
product in the exponential can be adjusted to the smaller value to improve the
computation efficiency as below.
2p 2p 2p 2p
ej N kn ¼ ej N kðn þ N Þ ¼ ej N kðn þ 2N Þ ¼ ej N ðk þ N Þn ¼ . . . ð7:136Þ

The equivalent matrix representation is shown below for the DFT.


2 3 2 32 x½0 3
X ½0 1 1  1 1
6 7 6 6 7
6 X ½1 7 6 1 ej N ðN1Þ 7 76 x½1 7
2p 2p 2p
ej N 1  ej N ðN2Þ
6 7 6 7 6 7
6 .. 7 6 .. .. .. .. .. 7 6 .. 7
6 . 7¼6. . . . . 766 . 7
6 7 6 7 7
6 7 54 x½N  2 7
6
4 X ½N  2 5 4 1
2p 2p
j2p
ej N ðN2Þ1  ej N ðN2ÞðN2Þ e N ð N2 Þ ð N1 Þ
5
2p 2p
j2p
X ½N  1 1 ej N ðN1Þ1  ej N ðN1ÞðN2Þ e N ðN1ÞðN1Þ
x½N  1
ð7:137Þ
7.5 Frequency Domain Filter Realization 565

2 3 2 32 3
x ½ 0 1 1  1 1 X ½ 0
6 x ½ 1 7 6 1
2p
ej N 1 
2p
ej N ðN2Þ ej N ðN1Þ 76
2p
X ½ 1 7
6 7 76 7
6 .. 7 16 .. .. .. .. .. 76 .. 7
6 . 7 ¼ N6
6. . . . . 76 . 7
6 7 41 56 7
4 x ½ N  2 5 2p
ej N ðN2Þ1
2p
   ej N ðN2ÞðN2Þ j2p
eN ð N2 Þð N1Þ 4 X ½ N  2 5
2p 2p 2p
x ½ N  1 1 ej N ðN1Þ1    ej N ðN1ÞðN2Þ ej N ðN1ÞðN1Þ X ½ N  1
ð7:138Þ

For given problem size N, the DFT involves the N2 complex multiplications and
N(N − 1) complex additions. The algorithm complexity is evaluated by the number
of multiplications; hence, the DFT complexity is order of N2. The decomposition in
time or frequency considerably reduces the DFT complexity. The following is the
decimation-in-time fast Fourier transform (FFT) algorithm [9] which is the fast
version of the DFT. The FFT needs the power of two data length to perform the
algorithm. The length N in the below DFT is 2L.
2p 2p
X ½k ¼ x½0 þ x½1ej N k1 þ x½2ej N k2 þ   
2p 2p ð7:139Þ
þ x½N  2ej N kðN2Þ þ x½N  1ej N kðN1Þ

Divide into the even and odd data part as below.


2p 2p 2p 2p
¼ x½0 þ x½2ej N k2 þ x½4ej N k4 þ x½6ej N k6 þ    þ x½N  2ej N kðN2Þ
j2p j2p j2p j2p 2p
þ x½1e N k1 þ x½3e N k3 þ x½5e N k5 þ x½7e N k7 þ    þ x½N  1ej N kðN1Þ
2p 2p 2p 2p ðN2Þ
¼ x½0 þ x½2ejN=2k1 þ x½4ejN=2k2 þ x½6ejN=2k3    þ x½N  2ejN=2k 2

2p 2p 2p
þ ej N k x½1 þ ej N k x½3ejN=2k1 þ ej N k x½5ejN=2k2 þ ej N k x½7ejN=2k3 þ   
2p 2p 2p 2p

2p ðN2Þ
þ ej N k x½N  1ejN=2k
2p
2

ð7:140Þ

Organize into the below equation that represents the two distinct N/2-point DFTs
with even and odd data. The exponential weighting is required over the odd data
sequence.

P Þ
ðN=21 2p P Þ
ðN=21 2p
x½2qejN=2kq þ ej N k x½2q þ 1ejN=2kq
2p
X ½k  ¼
q¼0 q¼0 ð7:141Þ
2p
¼ F ½k  þ ej N k G½k 

The F[k] represents the DFT with even data sequence and G[k] denotes the DFT
with weighted odd data sequence. In the same manner as above, the F[k] and G
[k] can be further decomposed into the even DFT and odd DFT as below. Observe
that the f[q] and g[q] is the compressed version of the even and odd of x[n],
respectively.
566 7 Implementation Matters


ðN=21
2p
F ½k  ¼ f ½qejN=2kq
q¼0
ð7:142Þ

ðN=41
2p
jN=4 kr 2p
jN=2 k

ðN=41
2p
jN=4 kr
¼ f ½2r e þe f ½2r þ 1e
r¼0 r¼0


ðN=21
2p
G ½k  ¼ g½qejN=2kq
q¼0
ð7:143Þ

ðN=41
2p
jN=4 kr 2p
jN=2 k

ðN=41
2p
jN=4 kr
¼ g½2r e þe g½2r þ 1e
r¼0 r¼0

Further decomposition is performed until the data length reaches the minimum
as 2. The DFT with length 2 is below.

C ½k ¼ c½0ej 2 k0 þ c½1ej 2 k1 ¼ c½0 þ c½1ð1Þk


2p 2p
ð7:144Þ

After the 2-point DFT, the proper weighting and summation provide the next
size DFT output. The cascade even odd DFTs result in the N-point DFT with
reduced computation. The actual DFT is executed at the first DFT stage (2-point)
and later stages perform the simple complex weighting and adding for next com-
putational stage. The linear algebra analysis for the FFT is shown below. Note that
the WN represents the complex exponential as below

WN ¼ ej2p=N

The length for analysis is 8 which is 23.


2 3 2 3 2 0 32 3
x½0 X ½0 W8 W80 W80 W80 W80 W80 W80 W80 x½0
6 x½1 7 6 7 6
X ½1 7 6 W80 W81 W82 W83 W84 W85 W86 W87 7 6 7
6 7 6 76 x½1 7
6 7 6 7 6 0 7 6 7
6 x½2 7 6 X ½2 7 6W W82 W84 W86 W80 W82 W84 W86 76 x½2 7
6 7 6 7 6 8 76 7
6 x½3 7 6 7
X ½3 7 6 0
W83 W86 W81 W84 W87 W82 W85 7 6 7
6 7 6 6 W8 76 x½3 7
DFT8 6 7¼6 7¼6 0 7 6 7
6 x½4 7 6 X ½4 7 6 W8 W84 W80 W84 W80 W84 W80 W84 7 6 x½4 7
6 7 6 7 6 76 7
6 x½5 7 6 X ½5 7 6 0 W85 W82 W87 W84 W81 W86 W83 7 6 7
6 7 6 7 6 W8 76 x½5 7
6 7 6 7 6 0 7 6 7
4 x½6 5 4 X ½6 5 4 W8 W86 W84 W82 W80 W86 W84 W82 54 x½6 5
x½7 X ½7 W80 W87 W86 W85 W84 W83 W82 W81 x½7
ð7:145Þ
7.5 Frequency Domain Filter Realization 567

The matrix is divided into the even and odd data as below.
2 3 2 0 3 2 3
X ½0 W8 W80 W80 W80 W80 W80 W80 W80
6 X ½1 7 6 W 0 W82 W84 W86 7 6 W1 W83 W85 W87 7
6 7 6 8 7 6 8 7
6 7 6 72 3 6 2 72 3
6 X ½2 7 6 W80 W84 W80 W84 7 x½0 6 W8 W86 W82 W86 7 x½1
6 7 6 7 6 7
6 X ½3 7 6 W 0 W86 W84 W82 7 6 7 6 W3 W81 W87 W85 7 6 x½3 7
6 7 6 8 76 x½2 7 6 76 7
6 7¼6 7 6 7 þ 6 84 7 6 7
6 X ½4 7 6 W80 W80 W80 W80 7 4 x½4 5 6 W8 W84 W84 W84 7 4 x½5 5
6 7 6 7 6 7
6 X ½5 7 6 W 0 W82 W84 67 x½6 6 W5 W87 W81 37
6 7 6 8 W8 7 6 8 W8 7 x½7
6 7 6 7 6 6 7
4 X ½6 5 4 W80 W84 W80 W84 5 4 W8 W82 W86 W82 5
X ½7 W80 W86 W84 W82 W87 W85 W83 W81
ð7:146Þ

Further division is performed for data output as below.


2 3 2 32 3 2 32 3
X ½0 W80 W80 W80 W80 x½0 W80 W80 W80 W80 x½1
6 7 6 W0 W82 W84 W86 7 6 7 6 W1 W83 W85 W87 7 6 x½3 7
6 X ½1 7 6 8 76 x½2 7 6 8 76 7
6 7¼6 0 7 6 7þ6 2 7 6 7
4 X ½2 5 4 W8 W84 W80 W84 54 x½4 5 4 W8 W86 W82 W86 54 x½5 5
X ½3 W80 W86 W84 W82 x½6 W83 W81 W87 W85 x½7
ð7:147Þ
2 3 2 0 32 3 2 4 32 3
X ½4 W8 W80 W80 W80 x½0 W8 W84 W84 W84 x½1
6 X ½5 7 6 W 0 W82 W84 6 76 7 6
W8 76 x½2 7 6 W85 W87 W81 W83 7 6 7
6 7 6 8 76 x½3 7
6 7¼6 76 7þ6 27 6 7
4 X ½6 5 4 W80 W84 W80 W84 54 x½4 5 4 W86 W82 W86 W8 54 x½5 5
X ½7 W80 W86 W84 W82 x½6 W87 W85 W83 W81 x½7
ð7:148Þ

Extract the common factor as below by using the complex exponential periodicity.
2 3 2 32 3 2 0 32 3
X ½4  W80 W80 W80 W80 x½0 W8 W80 W80 W80 x½1
6 X ½5  7 6 W 0 W82 W84 W86 7 6 7 6 W1 W83 W85 W87 7 6 7
6 7 6 8 76 x½2 7 6 8 76 x½3 7
6 7¼6 76 7 þ W84 6 2 76 7
4 X ½6 5 4 W80 W84 W80 W84 54 x½4 5 4 W8 W86 W82 W86 54 x½5 5
X ½7  W80 W86 W84 W82 x½6 W83 W81 W87 W85 x½7
ð7:149Þ

Derive the common factors for corresponding row as below.

2 3 2 3
X ½0  W80 W80 W80 W80 2 x½0 3
6 7 6
6
76 7
6 X ½1 7 6 W80 W82 W84 W86 7
76 x½2 7
6 7¼6 76 7
6 7 4 76 x½4 7
4 X ½2  5 6
4 W8
0
W84 W80 W8 5 4 5
X ½3  W80 W86 W84 W82 x½6
2 32 32 3 ð7:150Þ
W80 0 0 0 W80 W80 W80 W80 x½1
6 76 0 76 7
6 0 W81 0 7 6 W82 W84 W86 76 7
6 0 76 W8 76 x½3 7
þ6 76 0 76 7
6 0 0 W82 0 56
7 W84 W80 4 76 x½5 7
4 4 W8 W8 54 5
3
0 0 0 W8 W80 W86 W84 W82 x½7
568 7 Implementation Matters

2 3 2 3
X ½4 W80 W80 W80 W80 2 x½0 3
6 7 6 76 7
6 X ½5 7 6 W 0 W 2 W 4 W86 7
6 7 6 8 76 x½ 2  7
76 7
8 8
6 7¼6 6 x½ 4  7
6 X ½6 7 6 W 0 W 4 W 0 W84 74 5
4 5 4 8 8 8 5
X ½7 W80 W86 W84 W82 x½ 6 
2 0 32 0 32 3 ð7:151Þ
W8 0 0 0 W8 W80 W80 W80 x½1
6 76 0 76 7
6 0 W1 0 0 7 6W W82 W84 W86 76 7
6 8 76 8 76 x½3 7
þ W84 6 76 0 76 7
6 0 0 W82 0 7 6 W84 W80 4 76 x½5 7
4 54 W8 W8 54 5
0 0 0 W83 W80 W86 W84 W82 x½7

Combining and simplifying the factors for consistency as below.


2 3 2 3
X ½0 W40 W40 W40 W40 2 x½0 3
6 7 6 76 7
6 X ½1 7 6 W40 W41 W42 W43 776 x½2 7
6 7¼6 76 7
6 7 6 2 76 x½4 7
4 X ½2 5 6 0
4 W4 W4
2
W4 W4 54
0
5
X ½3 W40 W43 W42 W41 x½6
2 0 32 0 32 3 ð7:152Þ
W8 0 0 0 W4 W40 W40 W40 x½ 1 
6 76 0 76 7
6 0 W 1
0 0 7 6 1
W42 3 76 x½3 7
6 8 76 W4 W4 W4 76 7
þ6 76 0 76 7
6 0 0 W82 0 7 6 2
W40 W42 76 7
4 54 W4 W4 54 x½5 5
0 0 0 W83 W40 W43 W42 W41 x½ 7 
2 3 2 3
X ½4 W40 2 x½0 3
W40 W40 W40
6 7 6 7
6 X ½5 7 6 W 0 W 1 W 2 W 3 76 7
6 7 6 4 4 76 x½2 7
6 7¼6 0
4 4
7 6 7
6 X ½6 7 6 W W 2 W 0 W 2 76 x½4 7
4 5 4 4 4 4 4 54 5
X ½7 0 3 2 1 x½6
W4 W4 W4 W4
2 4 32 0 32 3 ð7:153Þ
W8 0 0 0 W4 W40 W40 W40 x½ 1 
6 76 0 76 7
6 0 W5 0 0 76 1 2 3 76 x½3 7
6 8 76 W4 W4 W4 W4 76 7
þ6 76 76 7
6 0 0 W86 0 7 6 0 2 0
W42 76 7
4 54 W4 W4 W4 54 x½5 5
0 0 0 W87 W40 W43 W42 W41 x½ 7 

The square matrix with full of complex exponential indicates the DFT with 4-point
as below. Therefore, the 8-point DFT is performed by 4-point DFT as below.
2 3 2 3 2 3 2 3
X ½0 x½0 W80 0 0 0 x½1
6 7 6 7 6 0 W81 0 7 6 x½3 7
6 X ½1 7 6 x½2 7 6 0 7 6 7
6 7 ¼ DFT4 6 7þ6 7DFT4 6 7 ð7:154Þ
4 X ½2 5 4 x½4 5 4 0 0 W82 0 5 4 x½5 5
X ½3 x½6 0 0 0 W83 x½7

2 3 2 3 2 4 3 2 3
X ½4 x½0 W8 0 0 0 x½1
6 X ½5 7 6 x½2 7 6 0 W85 0 7 6 x½3 7
6 7 6 7 6 0 7 6 7
6 7 ¼ DFT4 6 7þ6 7DFT4 6 7 ð7:155Þ
4 X ½6 5 4 x½4 5 4 0 0 W86 0 5 4 x½5 5
X ½7 x½6 0 0 0 W87 x½7
7.5 Frequency Domain Filter Realization 569

Exercise the same above procedure to the 4-point DFT.


2 3 2 3 2 0 32 3
x ½ 0 F ½ 0 W4 W40 W40 W40 x½0
6 x ½ 2 7 6 F ½ 1 7 6 W 0
W41 W42 W43 7
76 x½2 7
DFT4 4 5 ¼4 5 ¼6 4 x½4 5
4 ð7:156Þ
x ½ 4 F ½ 2 4 W40 W42 W40 W42 5
x ½ 6 F ½ 3 W40 W43 W42 W41 x½6

The matrix is divided into the even and odd data asbelow.
2 3 2 0 3 2 0 3
F ½ 0 W4 W40   W4 W40  
6 F ½ 1 7 6 W40 W42 7 x½0 6 W 1 W 3 7 x ½ 2
4 F ½ 2 5 ¼ 6 7
4 W 0 W 0 5 x½4 þ 6 4 4 7
4 W 2 W 2 5 x ½ 6 ð7:157Þ
4 4 4 4
0 2
F ½ 3 W4 W4 W43 W41

Further division is performed for data output as below.


       
F ½0 W40 W40 x½0 W40 W40 x½2
¼ þ ð7:158Þ
F ½1 W40 W42 x½4 W41 W43 x½6
   0     
F ½2 W4 W40 x ½ 0 W42 W42 x ½ 2
¼ þ ð7:159Þ
F ½3 W40 W42 x ½ 4 W43 W41 x ½ 6

Extract the common factor as below by using the complex exponential periodicity.
   0     
F ½ 2 W4 W40 x½0 W40 W40 x ½ 2
¼ þ W42 ð7:160Þ
F ½ 3 W40 W42 x½4 W41 W43 x ½ 6

Derive the common factors for corresponding row as below.


        
F ½ 0 W40 W40 x ½ 0 W40 0 W40 W40 x ½ 2
¼ þ ð7:161Þ
F ½ 1 W40 W42 x ½ 4 0 W41 W40 W42 x ½ 6
   0      
F ½2 W4 W40 x ½ 0 W40 0 W40 W40 x ½ 2
¼ þ W42 ð7:162Þ
F ½3 W40 W42 x ½ 4 0 W41 W40 W42 x ½ 6

Combining and simplifying the factors for consistency as below.


        
F ½ 0 W20 W20 x ½ 0 W40 0 W20 W20 x ½ 2
¼ þ ð7:163Þ
F ½ 1 W20 W21 x ½ 4 0 W41 W20 W21 x ½ 6
   0      
F ½ 2 W2 W20 x ½ 0 W42 0 W20 W20 x½2
¼ þ ð7:164Þ
F ½ 3 W20 W21 x ½ 4 0 W43 W20 W21 x½6

The square matrix with full of complex exponential indicates the DFT with
2-point as below. Therefore, the 4-point DFT is performed by 2-point DFT as
below.
570 7 Implementation Matters

       
F ½0 x ½ 0 W40 0 x½2
¼ DFT2 þ DFT2 ð7:165Þ
F ½1 x ½ 4 0 W41 x½6
     2   
F ½2 x ½ 0 W4 0 x½2
¼ DFT2 þ DFT2 ð7:166Þ
F ½3 x ½ 4 0 W43 x½6

For odd data, same procedure is performed as below.


2 3 2 3 2 0 32 3
x ½ 1 G½0 W4 W40 W40 W40 x ½ 1
6 x ½ 3 7 6 G½1 7 6 W40 W41 W42 W43 76 x ½ 3 7
DFT4 6 7
4 x ½ 5 5 ¼ 4 5 ¼6
4
76
2 54
7 ð7:167Þ
G½2 W40 W42 W40 W4 x ½ 5 5
x ½ 7 G½3 W40 W43 W42 W41 x ½ 7

Also, the 4-point DFT is performed by 2-point DFT as below.


       
G½0 x ½ 1 W40 0 x ½ 3
¼ DFT2 þ DFT2 ð7:168Þ
G½1 x ½ 5 0 W41 x ½ 7
     2   
G½2 x½1 W4 0 x ½ 3
¼ DFT2 þ DFT2 ð7:169Þ
G½3 x½5 0 W43 x ½ 7

The 2-point DFT is simple computation as below and no further decomposition


is required.
       
x ½ 1 W20 W20 x ½ 1 1 1 x½1
DFT2 ¼ ¼ ð7:170Þ
x ½ 5 W20 W21 x ½ 5 1 1 x½5
    
x ½ 3 1 1 x ½ 3
DFT2 ¼ ð7:171Þ
x ½ 7 1 1 x ½ 7
    
x ½ 0 1 1 x ½ 0
DFT2 ¼ ð7:172Þ
x ½ 4 1 1 x ½ 4
    
x ½ 2 1 1 x ½ 2
DFT2 ¼ ð7:173Þ
x ½ 6 1 1 x ½ 6

The 8-point DFT is calculated by 2- and 4-point DFT with weighting and
adding. The signal flow graph convention presents the constant multiplication by
arrow and the signal addition by junction. The 8-point FFT is shown below in flow
graph on Fig. 7.41.
The first stage in the left indicates the 2-point DFT. The second and third stage
specify the 4- and 8-point DFT. Each stage requires the N multiplications and
N additions. The number of stages is log2N; therefore, the total number of multi-
plications is Nlog2N that represents the FFT complexity order. The primitive pattern
7.5 Frequency Domain Filter Realization 571

Fig. 7.41 Signal flow graph for 8-point FFT

in the FFT flow graph is the butterfly computation. By exploring the butterfly, we
can reduce the computation further. The two complex weights in the butterfly
always show the p radian difference as ejp which is the −1. The extended butterfly
demonstrated below decreased the complex multiplications by using the consistent
phase difference as shown in Fig. 7.42.
The FFT flow graph with extended butterfly structure is illustrated below. The
number of multiplication in the graph approximates to the (N/2)log2N which is half
of the basic FFT structure. The overall complexity of the below FFT structure is still
Nlog2N because the constant factor does not modify the algorithm complexity as
shown in Fig. 7.43.

Fig. 7.42 Equivalence


butterfly structures of FFT
flow graph =
-1
572 7 Implementation Matters

x[0] X[0]

x[4] X[1]
-1

x[2] X[2]
-1

x[6] X[3]
-1 -1

x[1] X[4]
-1

x[5] X[5]
-1 -1

x[3] X[6]
-1 -1

x[7] X[7]
-1 -1 -1

Fig. 7.43 8-point FFT flow graph with extended butterfly structure

Table 7.6 Bit-reversed order for 8-point FFT


Index Binary Bit-rev FFT in Index Binary Bit-rev FFT in
0 0002 0002 0 4 1002 0012 1
1 0012 1002 4 5 1012 1012 5
2 0102 0102 2 6 1102 0112 3
3 0112 1102 6 7 1112 1112 7

The FFT algorithm requires the shuffling the input sequence to obtain the output
sequence in order. The bit-reversed order turns left and right of the binary index to
provide the proper sequencing for FFT input. Table 7.6 shows the bit-reversed
order for 8-point FFT.
The above decimation-in-time FFT is derived by dividing the time data into the
even and odd sequence. Alternative approach for FFT can be suggested by
decomposing the frequency output into the even and odd sequence. The frequency
decomposed method is known as decimation-in-frequency FFT [9]. Below matrix
analysis shows the derivation procedure for decimation-in-frequency FFT with
8-point data. Start from the 8-point DFT as below.
7.5 Frequency Domain Filter Realization 573

2 3 2 3
x ½ 0 X ½0
6 x ½ 1 7 6 X ½1 7
6 7 6 7
6 x ½ 2 7 6 X ½2 7
6 7 6 X ½3 7
6 x ½ 3 7 6 7
DFT8 6 7 ¼ 6 X ½4 7
6 x ½ 4 7 6 7
6 7 6 7
6 x ½ 5 7 6 X ½5 7
4 5 4 5
x ½ 6 X ½6
x ½ 7 2 ½07
X 3
W8 W80 W80 W80 W80 W80 W80 W80 2 x½0
3
6 W0 W87 7
6 80 W81 W82 W83 W84 W85 W86 766
x½1 7
7
6W W82 W84 W86 W80 W82 W84 W86 7 6 x½2 7
6 80 7 6 7
6W W83 W86 W81 W84 W87 W82 W85 7 6 x½3 7
¼66 W0
8 7 6 7
6 8 W84 W80 W84 W80 W84 W80 W84 7
76 x½4 7
6 W0 6 7
6 8 W85 W82 W87 W84 W81 W86 W83 7
76 x½5 7
4 W0 4 5
8 W86 W84 W82 W80 W86 W84 W82 5 x½6
W80 W87 W86 W85 W84 W83 W82 W81 x½7
ð7:174Þ

The matrix is divided into the even and odd frequency output as below.
2 3
x½0
2 3 2 0 366
x½1 7
7
X ½ 0 W8 W80 W80 W80 W80 W80 W80 W80 6 x½2 7
6 7
6 X ½ 2 7 66 W0 W82 W84 W86 W80 W82 W84 W86 7
7 6 x½3 7
4 X ½4 5 ¼ 4 80 6 7 ð7:175Þ
W8 W84 W80 W84 W80 W84 W80 W84 56 x½4 7
6 7
X ½ 6 W80 W86 W84 W82 W80 W86 W84 W82 6 x½5 7
4 5
x½6
x½7
2 3
x½0
2 3 2 0 366
x½1 7
7
X ½ 1 W8 W81 W82 W83 W84 W85 W86 W87 6 x½2 7
6 X ½ 3 7 6 W 0 6 7
6 7 6 8 W83 W86 W81 W84 W87 W82 W85 7
76 x½3 7
4 X ½ 5 5 ¼ 4 W 0 6 7 ð7:176Þ
W85 W82 W87 W84 W81 W86 W83 56 x½4 7
8 6 7
X ½ 7 W80 W87 W86 W85 W84 W83 W82 W81 6 x½5 7
4 5
x½6
x½7
574 7 Implementation Matters

Further division is performed as below.


2 3 2 0 32 3 2 0 32 3
X ½ 0 W8 W80 W80 W80 x½0 W8 W80 W80 W80 x ½ 4
6 X ½ 2 7 6 W80 W82 W84 W86 7
76 x½1 7 6 W80 W82 W84 W86 76
76 x½5 7
7
4 X ½ 4 5 ¼ 6
4 W0 4 5þ6
8 W84 W80 W84 5 x½2 4 W80 W84 W80 W84 54 x½6 5

X ½ 6 W80 W86 W84 W82 x½3 W80 W86 W84 W82 x ½ 7


ð7:177Þ
2 3 2 3
3 2 3 2 32 3
X ½ 1 W80 W81 W82 W8 x½0 W84 W85 W86 W87 x ½ 4
6 X ½ 3 7 6 W 0 W81 7 x½1 7 6 W85 76 7
6 7 6 8 W83 W86 764 5þ6
W84 W87 W82 76 x½5 7
4 X ½ 5 5 ¼ 4 W 0 W85 W82 W87 5 x½2 4 W4 W81 W86 W83 54 x½6 5
8 8
X ½ 7 W80 W87 W86 W85 x½3 W84 W83 W82 W81 x ½ 7
ð7:178Þ

Extract common factors from matrix and columns by using the complex expo-
nential periodicity as below.
2 3 2 32 0 32 3
X ½1 W80 W80 W80 W80 W8 0 0 0 x½0
6 X ½3 7 6 W0 W82 W84 6 76
W81 0 7 6 x½1 7
6 7 6 8 W 8 76 0 0 76 7
6 7¼6 0 76 76 7
4 X ½5 5 4 W8 W84 W80 W84 54 0 0 W82 0 54 x½2 5
X ½7 W80 W86 W84 W82 0 0 0 W83 x½3
2 32 0 32 3 ð7:179Þ
W80 W80 W80 W80 W8 0 0 0 x½4
6 W0 W82 W84 W86 7 6 0 W81 0 76 x½5 7
76
6 76 0 7
þ W84 6 80 76 76 7
4 W8 W84 W80 W84 54 0 0 W82 0 54 x½6 5
W80 W86 W84 W82 0 0 0 W83 x½7

Simplify the matrix for consistency.


2 3 2 0 32 3 2 0 32 3
X ½ 0 W4 W40 W40 W40 x½0 W4 W40 W40 W40 x ½ 4
6 X ½ 2 7 6 W 0
W41 W42 W43 7
76 x½1 7 6 W40 W41 W42 W43 76
76 x½5 7
7
4 X ½ 4 5 ¼ 6
4 W0
4
4 5þ6
4 W42 W40 W42 5 x½2 4 W40 W42 W40 W42 54 x½6 5
X ½ 6 W40 W43 W42 W41 x½3 W40 W43 W42 W41 x ½ 7
ð7:180Þ
2 3 2 32 0 32 3
X ½1 W40 W40 W40 W40 W8 0 0 0 x½0
6 X ½3 7 6 W0 W41 W42 W43 7 6 1
0 7 6 7
6 7 6 4 76 0 W 8 0 76 x½1 7
6 7¼6 0 27 6 76 7
4 X ½5 5 4 W4 W42 W40 W4 5 4 0 0 W8 2
0 5 4 x½2 5
X ½7 W40 W43 W42 W41 0 0 0 W83 x½3
2 0 0 32 32 3 ð7:181Þ
W4 W40 W40 W4 W84
0 0 0 x½4
6 W0 W41 W42 3 76 5
0 76 x½5 7
7 6
6 W 4 76 0 W 8 0 7
þ 6 40 7 6 76 7
4 W4 W42 W40 W42 54 0 0 W86 0 54 x½6 5
W40 W43 W42 W41 0 0 0 W87 x½7

Combine the diagonal square matrix with column vector.


7.5 Frequency Domain Filter Realization 575

2 3 2 0 32 3 2 0 32 4 3
X ½1 W4 W40 W40 W40 W80 x½0 W4 W40 W40 W40 W 8 x ½ 4
6 X ½3 7 6 W 0 W41 W42 W43 7 6 W81 x½1 7 6 W0 W41 W42 W43 76 5 7
6 7 6 4 76 7þ6 4 76 W86 x½5 7
4 X ½5 5 ¼ 4 W 0 W42 W40 W42 54 W82 x½2 5 4 W40 W42 W40 W42 54
W 8 x ½ 6 5
4
X ½7 W40 W43 W42 W41 W83 x½3 W40 W43 W42 W41 W87 x½7
ð7:182Þ

Using the DFT linearity, merge the data sequence.


2 3 2 3 2 3 2 3
X ½0 x ½ 0 x ½ 4 x½0 þ x½4
6 X ½2 7 6 x ½ 1 7 6 x ½ 5 7 6 x½1 þ x½5 7
4 X ½4 5 ¼ DFT4 4 5 þ DFT4 6 7
4 x½6 5 ¼ DFT4 4 5 ð7:183Þ
x ½ 2 x½2 þ x½6
X ½6 x ½ 3 x ½ 7 x½3 þ x½7
2 3 2 0 3 2 4 3
X ½ 1 W 8 x ½ 0 W8 x½4
6 X ½ 3 7 6 1 7 6 5 7
6 7 ¼ DFT4 6 W82 x½1 7 þ DFT4 6 W86 x½5 7
4 X ½ 5 5 4 W x ½ 2 5 4 W x½6 5
8 8
X2½7 W833x½3 2 W87 x½7 3 ð7:184Þ
W80 x½0 þ W84 x½4 W80 ðx½0  x½4Þ
6 W x ½ 1 þ W x ½ 5 7
1 5 6 1 7
¼ DFT4 6 8 8 7 ¼ DFT4 6 W82 ðx½1  x½5Þ 7
4 W x ½ 2 þ W x ½ 6 5
2 6 4 W ðx½2  x½6Þ 5
8 8 8
W83 x½3 þ W87 x½7 W83 ðx½3  x½7Þ

Now, we have 4-point DFT to obtain the 8-point DFT. Apply the identical
analysis to the reduced size DFT as below.
2 3 2 3 2 0 32 3
x½0 þ x½4 X ½0 W4 W40 W40 W40 x ½ 0 þ x ½ 4
6 x½1 þ x½5 7 6 X ½2 7 6 W40 W41 W42 W43 7
76 x ½ 1 þ x ½ 5 7
DFT4 4 5¼4 5 ¼6
4 4 5
x½2 þ x½6 X ½4 W40 W42 W40 W42 5 x ½ 2 þ x ½ 6
x½3 þ x½7 X ½6 W40 W43 W42 W41 x ½ 3 þ x ½ 7
ð7:185Þ

The even frequency sequence can be calculated by the 2-point DFT as below.
     
X ½ 0 x ½ 0 þ x ½ 4 x ½ 2 þ x ½ 6
¼ DFT2 þ DFT2
X ½ 4  x ½ 1 þ x ½ 5 x½3 þ x½7
ð7:186Þ
x½0 þ x½4 þ x½2 þ x½6
¼ DFT2
x½1 þ x½5 þ x½3 þ x½7
576 7 Implementation Matters

  " # " #
X ½2 W40 ðx½0 þ x½4Þ W42 ðx½2 þ x½6Þ
¼ DFT2 þ DFT2
X ½6 W41 ðx½1 þ x½5Þ W43 ðx½3 þ x½7Þ
" #
W40 ðx½0 þ x½4Þ þ W42 ðx½2 þ x½6Þ
¼ DFT2
W41 ðx½1 þ x½5Þ þ W43 ðx½3 þ x½7Þ
" #
W40 ððx½0 þ x½4Þ  ðx½2 þ x½6ÞÞ
¼ DFT2 ð7:187Þ
W41 ððx½1 þ x½5Þ  ðx½3 þ x½7ÞÞ

The odd frequency sequence can be calculated by the 2-point DFT as below.
2 3 2 3 2 32 0 3
W80 ðx½0  x½4Þ X ½ 1 W40 W40 W40 W40 W8 ðx½0  x½4Þ
6 W81 ðx½1  x½5Þ 7 6 X ½ 3 7 6 W0 W41 W42 3 76
W4 76 W81 ðx½1  x½5Þ 7
6 7 6 7 6 4 7
DFT4 6 7¼6 7¼6 0 76 7
4 W82 ðx½2  x½6Þ 5 4 X ½ 5 5 4 W4 W42 W40 W42 54 W82 ðx½2  x½6Þ 5
W83 ðx½3  x½7Þ X ½ 7 W40 W43 W42 W41 W83 ðx½3  x½7Þ
ð7:188Þ
     
X ½1 W80 ðx½0  x½4Þ W82 ðx½2  x½6Þ
¼ DFT2 1 þ DFT2 3
X ½5 W
 80 ð x ½ 1   x ½ 5 Þ W 8 ðx½3   x½7Þ
2 ð7:189Þ
W 8 ð x ½ 0  x ½ 4 Þ þ W 8 ð x ½ 2  x ½ 6 Þ
¼ DFT2
W81 ðx½1  x½5Þ þ W83 ðx½3  x½7Þ
     2 2 
X ½ 3 W40 W80 ðx½0  x½4Þ W 4 W 8 ð x ½ 2  x ½ 6 Þ
¼ DFT2 1 1 þ DFT2
X ½ 7  W40 W80 ðx½1  x½5Þ W43 W83 ðx½3  x½7Þ
2 2
W4 W8 ðx½0  x½4Þ þ W4 W8 ðx½2  x½6Þ
¼ DFT2 1 1 3 3 ð7:190Þ
W
 40W  8 ð0x½1  x½5Þ þ W4 W 8 ðx½3  x½7Þ 
W4 W8 ðx½0  x½4Þ  W82 ðx½2  x½6Þ
¼ DFT2
W41 W81 ðx½1  x½5Þ  W83 ðx½3  x½7Þ

The individual 2-point DFT is the last computation stage which is calculated as
below.
" # " #
X ½0 x½0 þ x½4 þ x½2 þ x½6
¼ DFT2
X ½4 x½1 þ x½5 þ x½3 þ x½7
" #" # ð7:191Þ
1 1 x½0 þ x½4 þ x½2 þ x½6
¼
1 1 x½1 þ x½5 þ x½3 þ x½7
" # " #
X ½2 W40 ððx½0 þ x½4Þ  ðx½2 þ x½6ÞÞ
¼ DFT2
X ½6 W41 ððx½1 þ x½5Þ  ðx½3 þ x½7ÞÞ
" #" 0 # ð7:192Þ
1 1 W4 ððx½0 þ x½4Þ  ðx½2 þ x½6ÞÞ
¼
1 1 W41 ððx½1 þ x½5Þ  ðx½3 þ x½7ÞÞ
7.5 Frequency Domain Filter Realization 577

" # " #
X ½1 W80 ðx½0  x½4Þ þ W82 ðx½2  x½6Þ
¼ DFT2
X ½5 W81 ðx½1  x½5Þ þ W83 ðx½3  x½7Þ
" #" 0 # ð7:192Þ
1 1 W8 ðx½0  x½4Þ þ W82 ðx½2  x½6Þ
¼
1 1 W81 ðx½1  x½5Þ þ W83 ðx½3  x½7Þ
" # " #
X ½ 3 W40 W80 ðx½0  x½4Þ  W82 ðx½2  x½6Þ
¼ DFT2  
X ½ 7 W41 W81 ðx½1  x½5Þ  W83 ðx½3  x½7Þ
" #" 0  0 # ð7:194Þ
1 1 W4 W8 ðx½0  x½4Þ  W82 ðx½2  x½6Þ
¼  
1 1 W41 W81 ðx½1  x½5Þ  W83 ðx½3  x½7Þ

The decimation-in-frequency FFT flow graph is illustrated below in Fig. 7.44.


The number of multiplication in the graph approximates to the (N/2)log2N which
indicates Nlog2N overall complexity .
The decimation-in-frequency FFT accepts the sequence in order and generates
output in bit-reversed order. Proper relocation is required to obtain the sequential
frequency information.
– FFT based filter (block convolution)
The filter realization in frequency domain exploits the benefit of FFT algorithm
due to the reduced complexity. The complexity for the convolution sum is pro-
portional to the N2 in which the filter length and data length are both N. Below
equation revisits the convolution sum.

P
N1 P
N1
y ½ n ¼ h½kx½n  k ¼ x½k h½n  k for 0  n  2N  2 ð7:195Þ
k¼0 k¼0

Fig. 7.44 8-point FFT flow graph for decimation-in-frequency


578 7 Implementation Matters

The filter with convolution sum is only applied for the FIR filter because the IIR
filter presents the infinite length for impulse response h[n]. With infinite length h[n],
the convolution sum cannot be calculated unless the h[n] is truncated. Observe that
the truncated IIR filter is the FIR filter fundamentally. The IIR filter is realized by
the difference equation with recursive inputs. For complexity analysis, the matrix
representation for convolution sum is shown below.
2 3 2 32 3
y½0 h½ 0 0 0  0 0 x ½ 0
6 y½1 7 6 h½ 1 h½ 0 0  0 0 76 x ½ 1 7
6 7 6 76 7
6 y½2 7 6 h½ 2 h½ 1 h½ 0  0 0 76 x ½ 2 7
6 7 6 76 7
6 .. 7 ¼ 6 .. .. .. .. .. .. 76 .. 7
6 . 7 6 . . . . . . 76 . 7
6 7 6 76 7
4 y½2N  3 5 4 0 0 0  h½N  1 h½N  2 54 x½N  2 5
y½2N  2 0 0 0  0 h½ N  1 x ½ N  1
ð7:196Þ

As the problem size linearly increases in convolution sum, the computational


requirement rises in quadratic sense. The FFT complexity denotes the
Nlog2N complexity; therefore, the filer realization based on FFT presents substantial
performance advantage for increased problem size. Note that the 1024 N indicate
1048576 for N2 and 10240 for Nlog2N.
In Chap. 4, we discussed the frequency domain filter by using the DFT. In the
same manner, the FFT length should be limited to the power of two and greater than
or equal to N + L − 1 as below. With this condition, the multiplication of the FFT
processed signal is equivalent to the convolution sum output according to the DFT
properties. Note that the FFT length should be consistent for entire processing.

FFT with N þ L1length


x½n : N length ! X ½k  Multiplication
h½n : L length ! H ½k  g ! X ½kH ½k
FFT with N þ L1length

Inverse FFT with N þ L1 length


! x½n h½n ð7:197Þ

The inverse FFT can be realized by the forward FFT algorithm by using the
following relation. Simply conjugating the input and output of the FFT with con-
stant weighting provides the inverse FFT operation.

P
N1 2p
X ½k  ¼ x½nej N kn ¼ DFTN ðx½nÞ ¼ FFTN ðx½nÞ for N ¼ 2L
n¼0
N1 
P
N1 2p P j2pkn ð7:198Þ
x½n ¼ N1 X ½kej N kn ¼ N1 X ½ke N
k¼0 n¼0
¼ N1 ðDFTN ðX ½kÞÞ
7.5 Frequency Domain Filter Realization 579

In general, the data for the filter shows the infinite length with real-time pro-
cessing requirement. The continuous sampling of analog signal creates the current
data x[n] for unlimited time span. The data obtaining policy determines the latency
performance of the filter output. Possible policies are below.
– Sample-based processing: Immediate processing with current data
– Frame-based processing: Every N-length data is processed
– Entirety-based processing: Complete data is processed once.
Along with the data obtaining policies, the filter can be realized in time or
frequency domain as below.
– Time-domain filter: Use the difference equation (FIR and IIR)
– Frequency-domain filter: Use the FFT and multiplication (FIR only).
Table 7.7 organizes the data obtaining policies and filter realization methods
with pros and cons.
We cannot wait for the data end to obtain the complete data set toward single
convolution sum because of the substantial latency. The offline processing allows to
use the single convolution sum for complete filter output. In general, the data with
fixed size is processed with h[n] for partial convolution sum. The sample-based and
frame-based processing execute the convolution sum with one and N (>1) data
length, respectively. The corresponding output also presents the identical size with
given input data length. Note that the augmented output length from convolution is
generated by the transition.
The realization method can select the time domain or frequency domain to
implement the filter. The time domain filter employs the difference equation as
below. The constant coefficient as and bs are derived by the filter design methods.

y½n ¼ b0 x½n þ    þ bM x½n  M   a1 y½n  1     aN y½n  N  ð7:199Þ

The FIR filter only contains the coefficient bs with previous and current input
data. The FIR difference equation is equivalent to the convolution sum in which the
h[n] indicates the constant coefficient bs. The IIR filter includes the coefficient as
and bs with previous and current input output data. The sample-based and
frame-based filter in time domain well connect the fragmented outputs into con-
tinuous structure. The final states from previous filter computation are maintained
toward the initial states for current computation in order to remove the transition.
Therefore, the post-processing to consolidate the segmented outputs is not
necessary.
The frequency domain filter only selects the frame-based realization. Unlike time
domain filter, there is no way to deliver the final states to initial states between the
frame output computations. Hence, in every filter computation with given N-length
data, we assume that the initial states are zeros. The frame outputs are required to be
interwoven for continuous streamed output due to the zero initial states. The block
convolution unites the framed outputs into an appropriate way as single convolution
output. The block convolution is not dedicated for the frequency domain filter. The
580 7 Implementation Matters

Table 7.7 Data obtaining policies and filter realization methods


Policy Time domain realization Frequency domain realization
Sample ! Obtain current x[n] Not possible
based ! Perform difference equation
! Get current y[n]
! Shift input buffer for previous inputs
! Shift output buffer for previous
outputs (IIR only)
" Repeat
Good: Very low latency, No
post-processing
Bad: High complexity
Frame ! Obtain current data frame N-length ! Computing H[k] with N length
based ! Perform difference equation for (Execute once)
N times ! Obtain current data frame N length
! Get current output frame ! Perform FFT on data frame with
! Maintain last input states (x[n-1], x N length
[n-2], etc.) for next frame processing ! Calculate X[k]H[k]
! Maintain last output states (y[n-1], y ! Compute IFFT on X[k]H[k] to get filter
[n-2], etc.) for next frame processing output
(IIR only) ! Assemble with previous output frame
" Repeat as post-processing
" Repeat from obtain data
Good: Minor latency, No Good: Minor latency, Low complexity
post-processing
Bad: High complexity, Input and output Bad: Input and output frame,
frame Post-processing, 2L length
Entirety ! Obtain complete data Procedure is identical to the frame-based
based ! Perform difference equation for all frequency domain realization except the
data longer data length and post-processing
! Get complete output
Good: High latency, No Good: High latency, Low complexity, No
post-processing post-processing
Bad: High complexity, Input and output Bad: Input and output frame with long
frame with long length length, 2L length

block convolution can apply for the any filter realizations in which the input is
framed without the state transfer.
The overlap-add method [9] adds the overlap samples between consecutive
frame outputs. For example, N-length input xm[n] and L-length h[n] provide the
convolution output with N + L − 1 length. Overlap and add the L − 1 samples
between the adjacent frames over the end to end. The figure below demonstrates the
overall procedure for overlap-add method where the N is 12 and L is 5. The
convolution sum equation is shown below for mth frame.
7.5 Frequency Domain Filter Realization 581

X
1 X
n
y m ½ n ¼ xm ½kh½n  k ¼ xm ½k h½n  k ð7:200Þ
k¼0 k¼nL þ 1

Based on the given parameters, the h[n − k] escapes from and enters into the
first and second frame, correspondingly at n = 12. The discrete time 12, 13, 14, and
15 provide the partial convolution outputs and the sum of two convolutions is
identical to the unframed convolution as shown in the figure below. Therefore, the
last L − 1 elements of preceding and the first L-1 elements of subsequent output
frame are overlapped and added to complete the transition convolution output as
shown in Fig. 7.45.
The FFT reduces the complexity of the convolution sum at overlap-add method.
The FFT length is chosen carefully to avoid the output corruption. Fundamentally,
the convolution sum realized by the FFT shows the circular property; therefore, the
output edges are connected and rounded for inappropriate FFT length. The FFT
length is greater than or equal to the convolution length as well as power of two.
The above example requires the 16 FFT length because of N + L − 1 convolution
length.
The above figure presents the given random data x[n] and framed data x1[n]
& x2[n]. The corresponding outputs are displayed below by locating the L − 1

Σ y[11] h[n-k] Σ y1[11] h[n-k] for x1[k]


x[k] 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 n=11 0 1 2 3 4 5 6 7 8 9 10 11 x1[k]
x2[k] 12 13 14 15 16 17 18 19 20 21 22 23

Σ y2[11] h[n-k] for x2[k]

Σ y[12] h[n-k] + Σ y1[12] h[n-k] for x1[k]


x[k] 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 n=12 0 1 2 3 4 5 6 7 8 9 10 11 x1[k]
x2[k] 12 13 14 15 16 17 18 19 20 21 22 23

Σ y2[12] h[n-k] for x2[k]

Σ y[13] h[n-k] + Σ y1[13] h[n-k] for x1[k]


x[k] 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 n=13 0 1 2 3 4 5 6 7 8 9 10 11 x1[k]
x2[k] 12 13 14 15 16 17 18 19 20 21 22 23

Σ y2[13] h[n-k] for x2[k]

Σ y[14] h[n-k] + Σ y1[14] h[n-k] for x1[k]


x[k] 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 n=14 0 1 2 3 4 5 6 7 8 9 10 11 x1[k]
x2[k] 12 13 14 15 16 17 18 19 20 21 22 23

Σ y2[14] h[n-k] for x2[k]

Σ y[15] h[n-k] + Σ y1[15] h[n-k] for x1[k]


x[k] 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 n=15 0 1 2 3 4 5 6 7 8 9 10 11 x1[k]
x2[k] 12 13 14 15 16 17 18 19 20 21 22 23

Σ y2[15] h[n-k] for x2[k]

Σ y[16] h[n-k] Σ y1[16] h[n-k] for x1[k]


x[k] 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 n=16 0 1 2 3 4 5 6 7 8 9 10 11 x1[k]
x2[k] 12 13 14 15 16 17 18 19 20 21 22 23

Σ y2[16] h[n-k] for x2[k]

Fig. 7.45 Overlap-add method where the N is 12 and L is 5. Left is continuous convolution and
right is block convolution (overlap-add method)
582 7 Implementation Matters

samples overlapped. Note that the outputs are computed by using the FFT method.
The overlapped outputs are added for final output as y[n] in the figure. For com-
parison purpose, the time domain convolution outputs are overlaid with overlap-add
output. The indistinguishable difference is observed between the outputs.

Prog. 7.10 MATLAB program for Figs. 7.46 and 7.47.

rng('default');
N = 24; % Whole data length
H = 5; % h[n] length
FN = N/2 + H - 1; % FFT length (assume that N is divided into two frames)
n = 0:N-1; % Time sequence for whole data
n1 = 0:N/2-1; % Time sequence for x1[n]
n2 = N/2:N-1; % Time sequence for x2[n]
no1 = 0:FN-1; % Time sequence for y1[n]
no2 = FN-(H-1):N+H-1-1; % Time sequence for y2[n]
noo = 0:N+H-2; % Time sequence for y[n]
hn = ones(1,H); % h[n]
HK = (hn,FN); % H[k]
x = randi([-5,5],1,N); % x[n]
x1 = x(1:N/2); % x1[n]
x2 = x(N/2+1:N); % x2[n]
X1K = (x1,FN); % X1[k]
X2K = (x2,FN); % X2[k]
y1 = real(i (X1K.*HK)); % y1[n]
y2 = real(i (X2K.*HK)); % y2[n]
yo = [y1(1:N/2) y1(N/2+1)+y2(1) ... % y[n] from overlap-add
y1(N/2+2)+y2(2) y1(N/2+3)+y2(3) ...
y1(N/2+4)+y2(4) y2(5:end)];
yc = conv(hn,x); % y[n] from convolu on sum

figure,
subplot(311),stem(n,x), grid, xlim([0 N-1]), ylabel('x[n]')
subplot(312),stem(n1,x1), grid, xlim([0 N-1]), ylabel('x_1[n]')
subplot(313),stem(n2,x2), grid, xlim([0 N-1]), ylabel('x_2[n]')
figure,
subplot(311), stem(no1,y1), grid, xlim([0 N+H-2]), ylim([-5 20])
ylabel('y_1[n]')
subplot(312), stem(no2,y2), grid, xlim([0 N+H-2]), ylim([-5 20])
ylabel('y_2[n]')
subplot(313), stem(noo,yo), grid, hold on, h = stem(noo,yc);
h.Marker = '*'; hold off
legend('Overlap-add','Convolu on'), xlim([0 N+H-2]), ylim([-5 20])
ylabel('y[n]')
7.5 Frequency Domain Filter Realization 583

x[n]
0

-5
0 5 10 15 20
5
x1[n]

-5
0 5 10 15 20
5
x2[n]

-5
0 5 10 15 20
n

Fig. 7.46 Given random data x[n] and framed data x1[n] and x2[n] for overlap-add method

20
y1[n]

10

0 5 10 15 20 25
20
y2[n]

10

0 5 10 15 20 25
20
Overlap-add
Convolution
10
y[n]

0 5 10 15 20 25

Fig. 7.47 Individual block convolution output of x1[n] and x2[n] and continuous convolution and
overlap-added block convolution output
584 7 Implementation Matters

One disadvantage of the overlap-add method is the extra operation to merge the
framed outputs. We can remove the add operations by overlapping the framed data.
The overlap-save method [9] overlaps the L − 1 length data for efficient output
transition where the N-length input frame xm[n] and L-length h[n] provide the
convolution output with N + L−1 length. The figure below demonstrates the overall
procedure for overlap-save method with 12 N and 5 L. The h[n − k] enters into the
second frame while the h[n − k] still holds the first frame entirely due to the
overlapped data at n = 12. The discrete time 12, 13, 14, and 15 provide the com-
plete outputs from the first frame convolution and the second frame convolution
prepares the output by increasing the overlapping area. As soon as the complete
overlapping is initiated, the second frame convolution delivers the output whereas
the first frame convolution outputs are discarded. Therefore, the first L − 1 ele-
ments of subsequent data frame are attached over the preceding data frame end to
generate the uninterrupted outputs. In the framed output, the first and last L − 1
elements are abandoned, and the middle N elements are taken for final output. Note
that the convolution length of the overlap-save method is N + (L − 1) + (L − 1).
No inter-frame operations are necessary for final output as shown in Fig. 7.48.
The conventional convolution length for the above example is 20 because of
overlapped data. With given configuration, the FFT length should be 32. The first
and last L − 1 outputs are not in use; therefore, the last L − 1 outputs are allowed
to intrude into the first L − 1 positions by circular convolution property. The above
example requires the 16 FFT length because of 16 data length as N.
The above figure presents the given random data x[n] and framed data x1[n] &
x2[n]. The last or first 4 (L − 1) data samples are duplicated and overlapped in the
framed data. The corresponding outputs are displayed below by locating the L − 1
samples overlapped. Note that the outputs are computed by using the 16-point FFT
method. The last 4 output elements of first frame are adopted as the final output and
the first 4 output elements of second frame are discarded. For comparison purpose,
the time domain convolution outputs are overlaid with overlap-save output. The
very first 4 outputs are not equal to the time domain convolution as a result of
circular convolution with N period. From the second frame, all outputs are identical
to the time domain convolution outputs. Shifting with zero padding saves the lost 4
outputs.
7.5 Frequency Domain Filter Realization 585

Prog. 7.11 MATLAB program for Figs. 7.49 and 7.50.


rng('default');
N = 28; % Whole data length (frame length 12 + overlap 4)
H = 5; % h[n] length
FN = 16; % FFT length (frame length 12 + h[n] length 5 - 1 -> power of two)
n = 0:N-1; % Time sequence for whole data
n1 = 0:15; % Time sequence for x1[n] 0 ~ 12+4-1
n2 = 12:27; % Time sequence for x2[n] 12 ~ N-1
no1 = 0:FN-1; % Time sequence for y1[n] 0 ~ FFT length - 1
no2 = FN-4:N+H-6; % Time sequence for y2[n] (same length as y1[n]
with 4 overlap)
noo = 0:27; % Time sequence for y[n]
hn = ones(1,H); % h[n]
HK = (hn,FN); % H[k]
x = randi([-5,5],1,N); % x[n]
x1 = x(1:16); % x1[n] with 4 overlap
x2 = x(13:end); % x2[n] with 4 overlap
X1K = (x1,FN); % X1[k]
X2K = (x2,FN); % X2[k]
y1 = real(i (X1K.*HK)); % y1[n]
y2 = real(i (X2K.*HK)); % y2[n]
yo = [y1 y2(5:end)]; % y[n] from overlap-save
yc = conv(hn,x); % y[n] from convolu on sum

figure,
subplot(311),stem(n,x), grid, xlim([0 N-1]), ylabel('x[n]')
subplot(312),stem(n1,x1), grid, xlim([0 N-1]), ylabel('x_1[n]')
subplot(313),stem(n2,x2), grid, xlim([0 N-1]), ylabel('x_2[n]')
figure,
subplot(311), stem(no1,y1), grid, xlim([0 27]), ylim([-5 20])
ylabel('y_1[n]')
subplot(312), stem(no2,y2), grid, xlim([0 27]), ylim([-5 20])
ylabel('y_2[n]')
subplot(313), stem(noo,yo), grid, hold on
h = stem(noo,yc(1:28));
h.Marker = '*'; hold off
legend('Overlap-save','Convolu on')
xlim([0 27]); ylim([-5 20]); ylabel('y[n]')

The block convolution permits to use the FFT for convolution sum. The clever
arrangement for data or output overcomes the initial state disruption between the
framed convolution sum. Since the filter with FFT reduces the complexity, the
increased segment size provides the better performance in terms of computation.
However, the high N generates the extra latency in filter processing.
586 7 Implementation Matters

Σ y[11] h[n-k] Σ y1[11] h[n-k] for x1[k]


x[k] 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 n=11 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 x1[k]
x2[k] 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27

Σ y2[11] h[n-k] for x2[k]

Σ y[12] h[n-k] Σ y1[12] h[n-k] for x1[k]


x[k] 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 n=12 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 x1[k]
x2[k] 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27

Σ y2[12] h[n-k] for x2[k]

Σ y[13] h[n-k] Σ y1[13] h[n-k] for x1[k]


x[k] 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 n=13 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 x1[k]
x2[k] 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27

Σ y2[13] h[n-k] for x2[k]

Σ y[14] h[n-k] Σ y1[14] h[n-k] for x1[k]


x[k] 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 n=14 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 x1[k]
x2[k] 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27

Σ y2[14] h[n-k] for x2[k]

Σ y[15] h[n-k] Σ y1[15] h[n-k] for x1[k]


x[k] 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 n=15 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 x1[k]
x2[k] 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27

Σ y2[15] h[n-k] for x2[k]

Σ y[16] h[n-k] Σ y1[16] h[n-k] for x1[k]


x[k] 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 n=16 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 x1[k]
x2[k] 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27

Σ y2[16] h[n-k] for x2[k]

Fig. 7.48 Overlap-save method where the N is 12 and L is 5. Left is continuous convolution and
right is block convolution (overlap-save method)

5
x[n]

-5
0 5 10 15 20 25
5
x1[n]

-5
0 5 10 15 20 25
5
x2[n]

-5
0 5 10 15 20 25
n

Fig. 7.49 Given random data x[n] and framed data x1[n] and x2[n] for overlap-save method
7.5 Frequency Domain Filter Realization 587

20

y1[n]
10

0 5 10 15 20 25
20
y2[n]

10

0 5 10 15 20 25
20
Overlap-save
Convolution
10
y[n]

0 5 10 15 20 25

Fig. 7.50 Individual block convolution output of x1[n] and x2[n] and continuous convolution and
overlap-saved block convolution output

– Quantization effect
In previous sections, we discussed the implementation matters on time domain filter
such as sampling, quantization, and scaling. With floating-point number, we assume
that the problems are ignored and restricted to the fixed-point number. The DFT and
FFT also experiences the similar troubles for realization except the sampling. The
complex weight and sum with fixed-point number require the quantization and
scaling for proper transform output. The filter in frequency domain extensively uses
the FFT algorithm; hence, the FFT analysis over the quantization and scaling is
essential to understand the filter performance. Below shows the DFT in matrix form
again for quick reference.
2 3 2 32 x½0 3
X ½0 1 1  1 1
6 7 6 6 7
ej N ðN1Þ 7
2p 2p 2p
6 X ½1 7 6 1 ej N 1  ej N ðN2Þ 76 x½1 7
6 7 6 7 6 7
6 .. 7 6 .. .. .. .. .. 76 .. 7
6 . 7¼6. . . . . 766 . 7
6 7 6 7 7
6 7 54 x½N  2 7
6
4 X ½N  2 5 4 1
2p 2p
j2p
ej N ðN2Þ1  ej N ðN2ÞðN2Þ e N ðN2 Þð N1 Þ
5
j2p
N ðN1Þ1
2p
j2p
X ½N  1 1 e  ej N ðN1ÞðN2Þ e N ðN1ÞðN1Þ
x½N  1
ð7:201Þ

For single output X [1], the weighted sum is presented as below according to the
DFT matrix.
588 7 Implementation Matters

2p 2p
X ½1 ¼ x½0 þ x½1ej N 1 þ x½2ej N 2 þ   
2p 2p
ð7:202Þ
þ x½N  2ej N ðN2Þ þ x½N  1ej N ðN1Þ

The complex weight can be represented as below with complex input x. The
below example is one of the product in X [1] at n = 1.
    
2p 2p 2p
x½1ej N 1 ¼ Reðx½1Þ cos  1  Imagðx½1Þ sin  1
N N
    
2p 2p
þ j Reðx½1Þ sin  1 þ Imagðx½1Þ cos  1 for x½1 2 C
N N
ð7:203Þ

Since the multiplication doubles the bit size, the quantization truncates the
product output for B + 1 bit size. The complex number product executes the
multiplication in four instances; therefore, the four quantizations are performed for
single complex weighting as below.
2p

QB x½1ej N 1
      
2p 2p
¼ QB Reðx½1Þ cos  1  QB Imagðx½1Þ sin  1
N N
   2p    2p 
þ j QB Reðx½1Þ sin  N 1 þ QB Imagðx½1Þ cos  N 1
ð7:204Þ

The quantization can be described by the random noise addition as below. We


assume that the random noise follows the uniform distribution in probability density
function.

   
j2p 2p
QB x½1e N1 ¼ Reðx½1Þ cos  1 þ e1 ½1; 1
N
   
2p
 Imagðx½1Þ sin  1 þ e2 ½1; 1
N
    ð7:205Þ
2p
þ j Reðx½1Þ sin  1 þ e3 ½1; 1
N
   
2p
þ Imagðx½1Þ cos  1 þ e4 ½1; 1
N

The random noise function e1,2,3,4[n, k] uses the parameter n and k for time and
frequency sample respectively. The individual noise variance is given below for the
approximation with uniform distribution according to the previous section result.
We assume the zero-mean condition.
7.5 Frequency Domain Filter Realization 589

   2
22B
Var e1;2;3;4 ½1; 1 ¼ E e1;2;3;4 ½1; 1 ¼ ð7:206Þ
12

The squared magnitude of the complex error e [1, 1] is below.

je½1; 1j2 ¼ ðe1 ½1; 1  e2 ½1; 1Þ2 þ ðe3 ½1; 1 þ e4 ½1; 1Þ2 ð7:207Þ

Using the uncorrelated and independent condition, the expected value of the
e [1, 1] squared magnitude can be represented as below.

22B 22B
E je½1; 1j2 ¼ 4 ¼ ð7:208Þ
12 3

The expected value of output error squared magnitude for the given k = 1 is below.
Note that the error is uncorrelated and independent for sample to sample in time.

XN 1
22B
E jR½1j2 ¼ E je½n; 1j2 ¼ N ð7:209Þ
n¼0
3

For any k value, we can obtain the general output as below. The N times in the
output error squared magnitude average can be decreased by the number of unit
2p
product ej N 0 ; however, the overall the average is proportional to N.
X
N1 2p

QB ðX ½kÞ ¼ QB x½nej N kn
n¼0

N1
X      !
2p 2p
¼ QB Reðx½nÞ cos  kn  QB Imagðx½nÞ sin  kn
n¼0
N N
N1
X      !
2p 2p
þj QB Reðx½nÞ sin  kn þ QB Imagðx½nÞ cos  kn
n¼0
N N
!
X
N1
QB ðReðX ½kÞÞ ¼ ReðX ½kÞ þ ðe1 ½n; k   e2 ½n; kÞ
n¼0
!
X
N 1
QB ðImagðX ½kÞÞ ¼ ImagðX ½kÞ þ ðe3 ½n; k þ e4 ½n; kÞ
n¼0

N1
P
2B
E jR½kj2 ¼ E je½n; k j2 ¼ N 2 3
n¼0

ð7:210Þ

where

je½n; kj2 ¼ ðe1 ½n; k   e2 ½n; k Þ2 þ ðe3 ½n; k þ e4 ½n; k Þ2
590 7 Implementation Matters

The double-length accumulator improves the quantization noise performance.


The individual noise sources from the complex weight are converted into the single
source by using the double-length accumulator. The four products in the complex
weight are accumulated along with time sequence then quantized as below.
N1 
P j2p
QB ðX ½kÞ ¼ QB x½ke N kn

N1  n¼0 N1 


P   P  2p 
¼ QB Reðx½nÞ cos  2pN kn  Q B Imag ðx ½n  Þ sin  N kn
 n¼0  N1
n¼0 
P
N1  2p  P  2p 
þ j QB Reðx½nÞ sin  N kn þ QB Imagðx½nÞ cos  N kn
n¼0 n¼0
QB ðReðX ½k ÞÞ ¼ ReðX ½k Þ þ ðe1 ½k  e2 ½kÞ
QB ðImagðX ½kÞÞ ¼ ImagðX ½k Þ þ ðe3 ½k þ e4 ½kÞ
ð7:211Þ

The uncorrelated and independent condition provides the following average


magnitude squared of the output error.

E jR½k j2 ¼ E ðe1 ½k  e2 ½kÞ2 þ ðe3 ½k þ e4 ½kÞ2


2B 2B
ð7:212Þ
¼ 4 212 ¼ 2 3

The FFT employs the complex exponential periodicity for reduced complexity.
With length limitation, the extended butterfly decreases the computational stage as
well as burden in FFT algorithms. Below is the one extended butterfly which
performs one complex weighting and negating with two input and two output ports
as shown in Fig. 7.51.
From the FFT output, the one X[k] value is connected to the two butterflies in
the previous stage. The two butterflies are joined to the four butterflies in the
preceding stage as shown in below FFT signal flow as shown in Fig. 7.52.
The power of two pattern involves the butterfly numbers in each stage from the
output such as one, two, four, eight, etc. The total number of butterflies can be
calculated by using the binary number representation. The 8-point FFT requires the
three stages as log28 and MSB stands for the output stage.

Fig. 7.51 Extended butterfly


structure for FFT

-1
7.5 Frequency Domain Filter Realization 591

x[0] X[0]

x[4] X[1]
-1

x[2] X[2]
-1

x[6] X[3]
-1 -1

x[1] X[4]
-1

x[5] X[5]
-1 -1

x[3] X[6]
-1 -1

x[7] X[7]
-1 -1 -1

Fig. 7.52 8-point FFT flow graph with extended butterfly structure

 
01112 ¼ 10002  12 ¼ 23  1 10 ¼ 7

The seven butterflies are engaged for the given 8-point FFT output at kth fre-
quency. For general N-point FFT, the number of butterflies for each output is
below.

|{z} 1    |{z}
0 |{z} 1 |{z} 1 ¼ |{z}
1 |{z} 0    |{z}
1 |{z} 0 |{z} 0 1 ¼ N  1 where L
0 |{z}
2L 2L1 22 21 20 2L 2L1 22 21 20
¼ log2 N
ð7:213Þ

The complex weighting in each butterfly provides four multiplications to deliver


the following variance with zero mean condition.
2B 2B
r2B ¼ 4 212 ¼ 2 3 ð7:214Þ

The overall output noise at individual output port is equivalent to the propagated
noise sum. With the uncorrelated noise source condition, the mean-squared mag-
nitude of the output noise is calculated by the product of individual variance over
the weight counts on the signal propagation path as below.

2B
E jR½kj2 ¼ ðN  1Þr2B ¼ ðN  1Þ 2 3 ð7:215Þ

The mean-squared magnitude of the output noise could be further reduced by


considering the unit weight on the FFT input stage as below.
592 7 Implementation Matters


    2B
E jR½k j2 ¼ N  N2  1 r2B ¼ N2  1 2 3 ð7:216Þ

The cascade connection between FFT stages does not promote the double-length
accumulator benefit on output noise figures. To obtain the perfect precision for FFT
output, every stage increases the storage size by B + 1 bits; otherwise, the quan-
tization error is inevitable. In general, the butterfly outputs are stored in the B + 1
bit variables by quantization for next stage processing.
The proper pre-scaling over DFT input prevents the output overflow. The DFT
and FFT provide the identical computational result; therefore, the pre-scaling policy
is equal to both transforms. The fixed-point number by B + 1 bit binary fraction are
ranged as below.

1  x½n  1  2B ð7:217Þ

The corresponding DFT range is indicated as below.

P
N1
2p
jX ½k j  jx½nj ej N kn \N ð7:218Þ
n¼0

The input is divided by N to maintain the output range below the binary fraction
limits as below.

jx½nj\ N1 ! jX ½kj\1 ð7:219Þ

The increased DFT length N produces the following results for signal and noise
power.
(

nrange
#) Decrease signal power
N ") 2B ð7:220Þ
E jR½k j2 ¼ N 2 3 ") Increase noise power

The SNR from fixed-point DFT is deteriorate by the extended DFT length.
Oppenheim and Schafer [9] derived the SNR for fixed-point DFT as below.

EðjX ½k j2 Þ
EðjR½k j2 Þ
¼ N 2 212B ð7:221Þ

The signal power is derived by the signal probability distribution function and
DFT equation. The derivation assumed that the DFT is performed on the B + 1 bit
fixed-point number. The SNR equation represents that the SNR decreases as N2
sense. To maintain the constant SNR, the doubled N should be counterbalanced by
the added one bit on quantization. The DFT with double-length accumulator pre-
sents the identical SNR as above since both N factors in signal and noise power are
removed by double-length accumulator. Alternative scaling procedure for FFT
shows the better performance in SNR by adapting 1/2 attenuator at each FFT stage
7.5 Frequency Domain Filter Realization 593

rather than a large scaling at input stage. We can find the detail procedures and
results from the Oppenheim and Schafer [9]. Also, Oppenheim and Schafer ana-
lyzed the coefficient quantization in the FFT. The SNR from the coefficient
quantization by B + 1 bits is below.

EðjX ½kj2 Þ 6
EðjR½k j2 Þ
/ log N22B ð7:222Þ
2

The major consequence is that the SNR decreases very gently with N which is
inversely proportional to log2N; therefore, doubling N produces only a slight
decrease in the SNR. Further analysis can be found on the reference [6, 9].

7.6 Problems

1. Calculate the SNR in round quantization. Assume that the probability density
function is uniform as shown below.

2/ QB
f E (e)

- QB
/2 0 - QB
/2
e

2. Shows the overall scaling procedure for cascade system. The designed filter
indicates the LPF with p/3 cutoff frequency in 4th order system. The design
method is Butterworth.

0:0261 þ 0:1043z1 þ 0:1565z2 þ 0:1043z3 þ 0:0261z4


HðzÞ ¼
1  1:3066z1 þ 1:0305z2  0:3624z3 þ 0:0558z4

3. The random signal with zero mean and uniform distribution is provide to the
system input of Problem 2. The input is ranged from −1 to 1 to avoid the
overflow. Investigate the overflow likelihood for each scaling method by simple
MATLAB experiment.
594 7 Implementation Matters

4. Analyze the quantization noise performance. The designed filter indicates the
LPF with p/3 cutoff frequency in 4th order system. The design method is
Butterworth.

0:0261 þ 0:1043z1 þ 0:1565z2 þ 0:1043z3 þ 0:0261z4


HðzÞ ¼
1  1:3066z1 þ 1:0305z2  0:3624z3 þ 0:0558z4

5. For below configurations, find maximum frequency response error in magnitude


from coefficient quantization. Also calculate the corresponding pass band ripple
Ap and stop band attenuation Ast.
– FIR filter with 30 length (N = 29) and 8-bit quantization
– FIR filter with 60 length (N = 59) and 9-bit quantization.

References

1. IEEE Standard for Floating-Point Arithmetic. IEEE Std 754-2019 (Revision of IEEE
754-2008), 1−84 (2019). https://doi.org/10.1109/ieeestd.2019.8766229
2. Wikipedia: Moment (mathematics) (2020). https://en.wikipedia.org/w/index.php?title=
Moment_(mathematics)&oldid=959967484
3. Wilkinson, J.H.: The evaluation of the zeros of ill-conditioned polynomials. Part I.
Numerische Mathematik 1(1), 150–166 (1959). https://doi.org/10.1007/BF01386381
4. Wilkinson, J.H.: Rounding Errors in Algebraic Processes By J.H. Wilkinson. Prentice-Hall,
(1963)
5. Wikipedia: Wilkinson’s polynomial (2020). https://en.wikipedia.org/w/index.php?title=
Wilkinson%27s_polynomial&oldid=954862605
6. Jackson, L.B.: Digital Filters and Signal Processing, 3rd edn. Kluwer Academic Publishers,
Boston (1996)
7. Wikipedia: Residue theorem (2020). https://en.wikipedia.org/w/index.php?title=Residue_
theorem&oldid=959312933
8. Wikipedia: Partial fraction decomposition (2020). https://en.wikipedia.org/w/index.php?title=
Partial_fraction_decomposition&oldid=954972624
9. Oppenheim, A.V., Schafer, R.W.: Discrete-Time Signal Processing. Prentice Hall (1989)
10. Parks, T.W., Burrus, C.S.: Digital Filter Design. Wiley (1987)
Chapter 8
Filters with MATLAB

The previous chapters have provided the knowledges on the digital filter design,
analysis, and realization based on the digital signal understanding. The MATLAB
assists the all procedures by computing, deriving, and visualizing the mathematics
and algorithms. The robust and strong functions and toolboxes in the MATLAB are
essential instruments for novice students as well as professional engineers.
The MATLAB usage shown in proceeding chapters are focused on the theory
understanding and verification. This chapter extends the MATLAB programming
for practical problems such as optimization, fixed-point number, etc. This chapter
also introduces the system objects which are designed for dynamic iterative com-
putations that process large streams of data in segments. The MATLAB coder for
non-MATLAB environment will be explored for rapid deployment system.
The MATLAB is very extensive technical language for various applications. This
chapter delivers quick introductions only and further information can be found on
MATLAB support documents at MathWorks webpages. Note that this chapter
provides in-text examples without numbering. The problem section is not generated
explicitly in the chapter end.

8.1 Fundamental Filter Design Methods

The MATLAB provides two programming approaches as textual and graphical


environment. We have used the textual environment as script-based programming
by using the command or editor window. The MATLAB also gives the graphical
environment known as Simulink. The intuitive blocks and wiring present the
convenient programming style in Simulink. The flexible and extensive supports
from the Simulink expand the graphical blocks to the script programming and
beyond. Further information on Simulink can be found at MathWorks webpage [1].
The MATLAB contains the numerous toolboxes which collect the discrete
functions for individual application area. By adding the specific toolboxes, we can
© Springer Nature Singapore Pte Ltd. 2021 595
K. Kim, Conceptual Digital Signal Processing with MATLAB,
Signals and Communication Technology,
https://doi.org/10.1007/978-981-15-2584-1_8
596 8 Filters with MATLAB

perform the technical computing for the application with reduced efforts on pro-
gramming. The discrete function in MATLAB is the realization of mathematical
algorithm. The fundamental mathematical algorithms from the conventional study
areas are continuously appended and updated for toolboxes biannually.
The MATLAB also provides apps for the window-based interactive application to
design and analysis the technical computing task. The below diagram shows the
overall MATLAB configuration for programming environments as Fig. 8.1.
The digital filter design, analysis, and realization can be executed in any
MATLAB programming level. In this book, we exclude the Simulink environment
which should be investigated by dedicated chapters due to the comprehensiveness.
Below present the filter related programming levels.
– Primitive MATLAB programming for mathematical algorithm
– Toolbox function
– MATLAB apps.
The mathematical algorithm programming utilizes the MATLAB primitive
functions to solve the equations in numerical or symbolical way. The established
equations are realized by the MATLAB in step by step. For example, the least
squared error frequency domain FIR filter design (integral squared error approxi-
mation criterion) requires the following procedure. The theoretical background can
be found at Chap. 6. See Fig. 8.2.
The MATLAB realization is demonstrated in below. The inverse DTFT is
performed by the symbolic math and converted to the numerical computation by
using the subs and eval function. The frequency domain analysis is prepared by the
DFT (FFT) with symmetric impulse response in order to obtain the real DFT
outcome. The advantage of the primitive MATLAB programming is the flexible
and profound understanding on the mathematical algorithm. The disadvantage of
the method is requirement of extra verification steps to prove the written MATLAB
program.

Fig. 8.1 MATLAB MATLAB


configuration for Script-based Simulink
programming environments
Toolbox
Apps

Discrete functions

Mathematics
8.1 Fundamental Filter Design Methods 597

Design Analysis
Frequency Truncate & Frequency
Inverse
Specifica on domain shi the domain
DTFT
requirement response anaysis

No O.K. Yes

Fig. 8.2 Example of MATLAB algorithm (least squared error frequency domain FIR filter design)

Prog. 8.1 Least squared error frequency domain FIR filter design.

syms w n % Declare symbols


wc = 3*pi/8; % The center of the pass band (pi/4) and stop band (pi/2) edge
N = 16; % FIR filter length = N+1
NN = 2^13; % DFT(FFT) length
N1 = NN/2+1; % DFT(FFT) half posion
N2 = N/2;
nnn = (-N2:1:N2); % Impulse response posions

hd0 = int(exp(1j*w*n),-wc,wc)/(2*pi); % Inverse DTFT of frequency response


hd1 = simplify(hd0); % Simplify the symbolic math
b1 = subs(hd1,n,nnn+eps); % Place values onto the symbolic math
b2 = eval(b1); % Compute the symbolic math
b3 = [b2 zeros(1,NN-length(b2))]; % Extend the impulse response to the
DFT(FFT) length
b4 = circshi(b3,-8); % Circular shi for real DFT(FFT) value
B2 = real((b4,NN)); % Frequency analysis

findex = linspace(0,2*pi,NN);
ff = findex(1:N1);

figure(1)
subplot(211), stem(nnn,b2), grid
subplot(212),plot(ff,B2(1:N1)), grid
...

The program output is illustrated below in Fig. 8.3. Note that the decoration
code is not shown above but the grid and labels are displayed at below figure. Once
the response is acceptable, we can use the h[n] as the filter coefficients; otherwise,
the specification is modified to meet the requirement.
The IIR filter is also designed and analyzed by primitive MATLAB program-
ming as below. The symbolic math is employed in the Butterworth model and
bilinear transform stage. When the filter coefficient values are determined, the
598 8 Filters with MATLAB

0.4

0.3
h LPF [n]

0.2

0.1

-8 -6 -4 -2 0 2 4 6 8
n

1
H LPF ( )

0.5

0 /4 /2 3 /4
Radian frequency ( )

Fig. 8.3 Output of Prog. 8.1

analysis stage is executed by the numerical computation. The code realization of the
below diagram is omitted due to the replication from Chap. 6. See Fig. 8.4.
The toolbox functions serve the extensive tasks on filter design, analysis, and
realization stage. Tables 8.1, 8.2, 8.3, and 8.4 organize the dedicated filter related
functions in part. The detail and further information on the function can be obtained
from the MATLAB support documents [2].
Below example shows the FIR filter design and analysis based on the
least-square approximation with hamming window. Observe that the fir1 function
uses the normalized frequency. The individual function performs the filter design

Design Analysis
Bu erworth Frequency
Bilinear Pole & zero
Specifica on model in domain
transform analysis
s-domain anaysis

No O.K. Yes

Fig. 8.4 Example of MATLAB algorithm (Butterworth IIR filter design)


8.1 Fundamental Filter Design Methods 599

Table 8.1 MATLAB functions for IIR filter design


Function name Function task
butter Butterworth filter design
cheby1 Chebyshev Type I filter design
cheby2 Chebyshev Type II filter design
ellip Elliptic filter design
yulewalk Recursive digital filter design
maxflat Generalized digital Butterworth filter design
lpc Linear prediction filter coefficients
prony Prony method for filter design
stmcb Compute linear model using Steiglitz-McBride iteration
invfreqz Identify discrete-time filter parameters from frequency response data

Table 8.2 MATLAB functions for FIR filter design


Function Function task
name
fir1 Window-based FIR filter design with least-squares approximation
fir2 Frequency sampling-based FIR filter design
firls Least-squares linear-phase FIR filter design
firpm Parks-McClellan optimal FIR filter design
fircls Constrained-least-squares FIR multiband filter design
fircls1 Constrained-least-squares linear-phase FIR lowpass and highpass filter
design
cfirpm Complex and nonlinear-phase equiripple FIR filter design

Table 8.3 MATLAB functions for filter analysis in frequency domain


Function name Function task
freqz Frequency response of digital filter
fvtool Open filter visualization tool
grpdelay Average filter delay (group delay)
phasedelay Phase delay of digital filter
phasez Phase response of digital filter
unwrap Correct phase angles to produce smoother phase plots
zerophase Zero-phase response of digital filter
zplane Zero-pole plot for discrete-time systems
600 8 Filters with MATLAB

and analysis automatically. Instead of freqz, the fvtool function provides the
interactive menu to select the various analysis tasks.
Prog. 8.2 FIR filter design and analysis based on the least-square approximation
with hamming window.

wc = 3*pi/8; % The center of the pass band (pi/4) and stop band (pi/2) edge
N = 16; % FIR filter length = N+1
b = fir1(N,wc/pi); % Filter design
freqz(b,1); % Filter analysis

The freqz function presents the magnitude and phase response in frequency domain
for the given filter as below. The plot decoration is given by default. After the filter
design, the filter execution with input data stream is performed by realization functions
listed at Table 8.5. The coefficients as and bs with input data are placed into the
function arguments and the returned outcome presents the filter output. The filter type
(FIR or IIR) selects the usable functions for filter execution in Table 8.5.
Apps in the MATLAB are interactive applications written to perform specific
computing tasks. The app is a self-contained program with a user interface that auto-
mates a task. All the operations required to complete the task are performed within the
app. The Apps tab of the MATLAB Toolstrip shows the currently installed apps.
Below table consolidates the filter design and analysis related apps in Table 8.6.
The filter designer app is launched by clicking the app icon in the tab or typing the
filterDesigner in the command window. We specify the response type, design method,
and design specifications for desired filter. The derived filter coefficients can be ana-
lyzed and verified by the filter designer app in numerous performance factors. The
finalized filter design is converted to the specific structure as well as exported to the
MATLAB workspace. Below figure shows the filter designer app window in Fig. 8.6.
The filter builder app is launched by clicking the app icon in the tab or typing the
filterBuilder in the command window. The filter builder app provides a graphical
interface to the object-oriented filter design method to find the best algorithm for the
desired response. The designed filter can be operated as the system object which
delivers the flexibility and expandability for dynamic systems. Similar to the filter
designer, we specify the various parameters such as response type, design method, and
design specifications for desired filter. The derived filter coefficients can be analyzed
and verified by clicking the view filter response button in the app. The finalized filter
design is converted to the specific structure as well as exported to the MATLAB
workspace. Below figure shows the filter builder app window in Fig. 8.7.

Table 8.4 MATLAB Function name Function task


functions for filter analysis in
time domain impz Impulse response of digital filter
impzlength Impulse response length
stepz Step response of digital filter
8.1 Fundamental Filter Design Methods 601

Magnitude (dB) 50

-50

-100
0 0.2 0.4 0.6 0.8 1
Normalized Frequency ( rad/sample)
0
Phase (degrees)

-500

-1000
0 0.2 0.4 0.6 0.8 1
Normalized Frequency ( rad/sample)

Fig. 8.5 Output of Prog. 8.2

Table 8.5 MATLAB functions for filter realization


Function name Function task
conv Convolution and polynomial multiplication. FIR only
filter 1-D digital filter. FIR and IIR
filtfilt Zero-phase digital filtering. FIR and IIR
fftfilt FFT-based FIR filtering using overlap-add method. FIR only

Table 8.6 MATLAB apps for filter design and analysis


Apps name Function task
filter designer Design filters starting with algorithm selection
filter builder Design filters starting with frequency and magnitude specifications
window designer Design and analyze spectral windows
602 8 Filters with MATLAB

Fig. 8.6 Filter designer app

The window designer app is launched by clicking the app icon in the tab or
typing the windowDesigner in the command window. The window designer app
enables us to design and analyze spectral windows by investigating how the
behavior of a window changes as a function of its length and other parameters. The
length and shape of window determine the spectral estimation and FIR filter per-
formance. We specify the various parameters such as window type, length, and
sampling for desired spectral performance. The corresponding spectral window
analyzes and verifies the performance with parametric outputs for instance leakage
factor, relative sidelobe attenuation, and mainlobe width. The finalized window
design is exported to the MATLAB workspace. Below figure shows the window
designer app screenshot in Fig. 8.8.
Obviously, the MATLAB lends the customizing capability on the functions and
apps. We can create any functions and apps for our purpose and share with other
MATLAB and non-MATLAB users. The stand-alone application can be written for
most computing environments. By mounting the designated hardware, the designed
filter can perform the real-time processing with streaming input and output data.
The conventional computer can support the digital filter system over audio data
streaming with relaxed latency requirement. The previous chapters have used the
MATLAB to derive and verify the theoretical and mathematical equations for
8.1 Fundamental Filter Design Methods 603

Fig. 8.7 Filter builder app

digital signal processing. The MATLAB expandability and adaptability reach


beyond the typical computer system by using the extended concept and toolbox
usage. Next sections will introduce some further usability of MATLAB.

8.2 Advanced Filter Design Methods

The MATLAB functions perform the digital filter design, analysis, and realization.
The digital filter system prefers to use the frame-based iterative processing because
of latency, memory, and complexity. The function-based programming is difficult
to handle the iterative processing since the programming requires the explicit trace
of data positions and retention of internal states. The frequent parameter modifi-
cations within the filter design and analysis stage increase the programming
604 8 Filters with MATLAB

Fig. 8.8 Window designer app

complexity exponentially. The explicit and fragmented programming prevent the


smooth conversion to other language for filter realization. The object-oriented
programming paradigm is required for encapsulation to hide data and bind together
with functions. The encapsulated object can provide the standardized code gener-
ation for optimized and verified performance.
The MATLAB introduced the system object as a dedicated MATLAB object.
System objects are designed for implementing and simulating dynamic systems
with inputs that change over time. The dynamic system generates the output signals
which depends on the current input values as well as the previous output values.
The system object stores the previous output values as internal states for next
computational iteration. The state delivery between the consecutive iterations allow
us to use the framed processing in segmented data. The framed processing with
system object gives simplified programming method that use loops efficiently.
The example MATLAB code below demonstrates FIR LPF based on the
functions. The frame size is 1024 samples with 100 frames for whole random data
stream. The 160 order FIR filter performs low pass filtering with 0:2p cutoff
8.2 Advanced Filter Design Methods 605

frequency. The while loop executes the iterative processing with explicit trace of
data positions. The internal state handover is performed by the state variable within
the input and output arguments of filter function. Without the internal state delivery,
the filter output ends are corrupted by the transition. The periodogram [3] function
displays the spectral power distribution with window size as frame size. The framed
output sequence is cumulated on the self-resizing array. The function-based pro-
gramming shows the transparent environment where you must specify the detail
information obviously.
Prog. 8.3 FIR LPF realization from MATLAB functions for frame-based pro-
cessing.

frameSize = 1024; % Frame size


N = frameSize*100; % Data size
numFrame = N/frameSize; % Number of frames

L = 160; % FIR order


wc = 0.2; % Cutoff frequency (normalized)
index = 1;

input = randn(1,N); % Generate full input data


b = fir1(L,wc); % FIR filter coefficients
states = zeros(1,length(b)-1); % Internal states
output = []; % Output buffer

while index <= (N - frameSize + 1)


x = input(index:index + frameSize - 1); % Framed data
[y,states] = filter(b,1,x,states); % Filtered data
output = [output y]; % Output buffer
index = index + frameSize; % Data posi on index
end

figure,
subplot(211), periodogram(input,[],frameSize) % Plot input spectral power
subplot(212), periodogram(output,[],frameSize) % Plot output spectral power

The MATLAB program produces the below plot for input and output spectral
distribution. The random signal demonstrates the wide and flat frequency distri-
bution. The filter output shown in second subplot depicts the concentrated spectral
distribution toward the low frequencies as we expected in Fig. 8.9.
606 8 Filters with MATLAB

Periodogram Power Spectral Density Estimate


0
Input power (dB)

-10

-20

-30

-40

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

0
Output power (dB)

-50

-100
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalized Frequency ( rad/sample)

Fig. 8.9 Output of Prog. 8.3

The system object-based programming is shown below to realize the identical


task as the previous code job. For the time being, we skip the detail explanation
about the system object. In overall, the program is neat by suppressing arguments
and states. Various reserved system objects provide the extensive filter design,
analysis and realization.
8.2 Advanced Filter Design Methods 607

Prog. 8.4 FIR LPF realization from MATLAB system object for frame-based
processing.
frameSize = 1024; % Frame size
N = frameSize*100; % Data size
L = 160; % FIR order
wc = 0.2; % Cutoff frequency (normalized)

sr = dsp.SignalSource(randn(N,1),frameSize); % Input generator


sink1 = dsp.SignalSink; % Output buffer
sink2 = dsp.SignalSink; % Input buffer

fir = dsp.FIRFilter(fir1(L,wc)); % Filter system object

while ~isDone(sr)
input = sr(); % Generate framed input
filteredOutput = fir(input); % Filtered data
sink1(filteredOutput); % Output buffer
sink2(input); % Input buffer
end

figure,
subplot(211), periodogram(sink2.Buffer,[],frameSize)
subplot(212), periodogram(sink1.Buffer,[],frameSize)

Similar to the previous program, the system object-based code produces


Fig. 8.10 for input and output spectral distribution. The figures are not perfectly
matched mutually because of the random number generation; however, the overall
distributions are closely comparable to the previous figure.
The system object-based filter design requires the specification, design, anal-
ysis, and realization stage. The specification stage selects the filter type, param-
eters, algorithm, and customization to generate the specification object. The
design stage creates the filter system object based on the specification object. The
analysis stage presents the time and frequency domain information about the
system object filter as well as the realization cost. The realization stage imple-
ments the designed filter in the iterative loop for frame-based processing. If the
measured performance does not meet the requirements, the procedure returns to
the specification stage to adjust the various parameters and methods. The overall
diagram is illustrated as Fig. 8.11.
The specification stage defines the filter response by placing the proper suffix
after fdesign prefix. The possible responses for the fdesign object are organized in
608 8 Filters with MATLAB

Periodogram Power Spectral Density Estimate


0
Input power (dB)

-10

-20

-30

-40
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

0
Output power (dB)

-20

-40

-60

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1


Normalized Frequency ( rad/sample)

Fig. 8.10 Output of Prog. 8.4

Not OK

Select and specify


Design filter Analyze filter OK Realize filter
filter parameters

Fig. 8.11 Overall procedures for MATLAB filter design from system object method

Table 8.7. Suitable toolboxes are necessary for the responses. The specification
stage is the first stage for the system object filter design because the response
defines the following stage parameters and variables.
The following stages are investigated by applying the design example based on
the given parameters from the subsequent table in Table 8.8.
The lowpass response creates the specification object ‘dfilter’ by fdesign.lowpass
command as below. The set function returns the possible specifications for lowpass
filter response. Choose one of the specifications for filter design. The specification
8.2 Advanced Filter Design Methods 609

Table 8.7 List of responses (suffix) for the fdesign object


Filter designer Filter designer response Signal processing DSP system
response name function toolbox required? toolbox required?
arbmag Arbitrary magnitude filters Yes
bandpass Bandpass filters Yes
bandstop Bandstop filters Yes
differentiator Differentiators Yes
highpass Highpass filters Yes
hilbert Hilbert transformers Yes
lowpass Lowpass filters Yes
arbgrpdelay Arbitrary group delay Yes Yes
filters
arbmagnphase Arbitrary magnitude and Yes Yes
phase filters
audioweighting Audio weighting filters Yes Yes
ciccomp CIC compensators Yes Yes
comb Comb filters Yes Yes
decimator Decimators Yes Yes
fracdelay Fractional delay filters Yes Yes
halfband Halfband filters Yes Yes
interpolator Interpolators Yes Yes
isinclp Inverse-sinc lowpass filters Yes Yes
notch Notching filters Yes Yes
nyquist Nyquist filters Yes Yes
parameq Parametric equalizer filters Yes Yes
peak Peaking filters Yes Yes
polysrc Polynomial sample-rate Yes Yes
converters
octave Octave-band and Yes Yes
fractional-octave-band
filters
rsrc Rational factor sample-rate Yes Yes
converters

definition can be found by help or doc command with fdesign.lowpass. Without


selecting the specification, the first entry will be chosen by default. Note that the
command executions are performed in the command window.
610 8 Filters with MATLAB

Table 8.8 Given filter Filter specifications Value


specification
Filter type Low pass filter
Filter realization IIR with Butterworth
Filter length Optimization
Passband frequency (fp) 1000 Hz;xp ¼ p=4
Pass magnitude 0 dB
Pass band ripple (peak to peak)Dp 1 dB
Stopband frequency (fst) 2000 Hz;xst ¼ p=2
Stop band attenuation in decibels Dst 40 dB
Sampling frequency (fs) 8000 Hz

Prog. 8.5 Specification object creation for LPF.

>> dfilter = fdesign.lowpass; % Response is lowpass


>> set(dfilter,'Specifica on')

ans =

18×1 cell array

{'Fp,Fst,Ap,Ast'}
{'N,F3dB' }
{'Nb,Na,F3dB' }
{'N,F3dB,Ap' }
{'N,F3dB,Ap,Ast'}
{'N,F3dB,Ast' }
{'N,F3dB,Fst' }
{'N,Fc' }
{'N,Fc,Ap,Ast' }
{'N,Fp,Ap' }
{'N,Fp,Ap,Ast' }
{'N,Fp,F3dB' }
{'N,Fp,Fst' }
{'N,Fp,Fst,Ap' }
{'N,Fp,Fst,Ast' }
{'N,Fst,Ap,Ast' }
{'N,Fst,Ast' }
{'Nb,Na,Fp,Fst' }

>>
8.2 Advanced Filter Design Methods 611

The MATLAB provides the auto-completion and auto-listing by tab keystroke. For
example, the set function argument is completed by ‘S<tab> and listed by ‘N<tab> as
shown below. Navigate the specifications by arrow keys as shown in Fig. 8.12.
The set function decides the specification by additional argument as below. The
designmentods function presents the possible design methods for the given response
and specification. The below example shows the window method as the candidate.
Prog. 8.6 Filter design method selection example.

>> set(dfilter,'Specifica on','N,Fc') % Set specifica on


>> designmethods(dfilter,'Systemobject',true) % Find available algorithms

Design Methods that support System objects for class fdesign.lowpass (N,Fc):

window

>>

The specification change provides the distinct subset of the design methods.
After the specification selection, we can assign the actual values for the specifi-
cation object by using the setspecs function. The specification frequencies and
ripples are derived from the design example table.

Fig. 8.12 Auto-completion and auto-listing example in command window


612 8 Filters with MATLAB

Prog. 8.7 Assign specification values.


>> set(dfilter,'Specifica on','Fp,Fst,Ap,Ast') % Set specifica on
>> setspecs(dfilter,0.25,0.5,1,40) % Specifica on
>> designmethods(dfilter,'Systemobject',true) % Find available algorithms

Design Methods that support System objects for class fdesign.lowpass


(Fp,Fst,Ap,Ast):

bu er
cheby1
cheby2
ellip
equiripple
ifir
kaiserwin
mul stage

>>

The further information about the specification object with the filter design
method can be obtained by help function as below.
Prog. 8.8 Specification object help.

>> help(dfilter,'bu er')


DESIGN Design a Bu erworth IIR filter.
HD = DESIGN(D, 'bu er') designs a Bu erworth filter specified by the
FDESIGN object D, and returns the DFILT/MFILT object HD.
...
% Example #1 - Compare passband and stopband MatchExactly.
h = fdesign.lowpass('Fp,Fst,Ap,Ast', .1, .3, 1, 60);
Hd = design(h, 'bu er', 'MatchExactly', 'passband');
Hd(2) = design(h, 'bu er', 'MatchExactly', 'stopband');

% Compare the passband edges in FVTool.


fvtool(Hd);
axis([.09 .11 -2 0]);

>>
8.2 Advanced Filter Design Methods 613

The design function with specification object and additional arguments defines
the filter system object as below. The filter is built by the Butterworth method with
direct form II SOS structure. The design function displays the detail filter properties
as return. By calling the filter system object, we can perform the filter operation for
the desired specification.
Prog. 8.9 The design function example for specification object.

>> filt = design(dfilter,'buer','filterstructure','df2sos','Systemobject',true)

filt =

dsp.BiquadFilter with properes:

Structure: 'Direct form II'


SOSMatrixSource: 'Property'
SOSMatrix: [13×6 double]
ScaleValues: [14×1 double]
InialCondions: 0
OpmizeUnityScaleValues: true

Show all properes

>>

The analysis stage evaluates the filter system object over various aspects. The
measure function provides the frequency, magnitude, and ripple performance. The
cost function presents the computation and memory requirement. The info function
exhibits the filter structure, stability, and phase linearity.
614 8 Filters with MATLAB

Prog. 8.10 Analysis of filter system object.


>> measure(filt)

ans =
Sample Rate : N/A (normalized frequency)
Passband Edge : 0.25
3-dB Point : 0.27666
6-dB Point : 0.29956
Stopband Edge : 0.5
Passband Ripple : 0.98666 dB
Stopband A en. : 40 dB
Transi on Width : 0.25

>> cost(filt)

ans =
struct with fields:

NumCoefficients: 12
NumStates: 6
Mul plica onsPerInputSample: 12
Addi onsPerInputSample: 12

>> info(filt)

ans =
6×59 char array

'Discrete-Time IIR Filter (real) '


'------------------------------- '
'Filter Structure : Direct-Form II, Second-Order Sec ons '
'Number of Sec ons : 3 '
'Stable : Yes '
'Linear Phase : No '

>> fvtool(filt)

The fvtool with filter system object shows the extensive analysis on the filter.
Figure 8.13 illustrates the magnitude response with given specifications as auto-
mated and dotted lines. The ribbon menu on the figure can choose the phase, group
delay, phase delay, impulse response, step response, pole/zero, coefficients, filter
information, and etc. plots.
After the analysis satisfies the specification, the realization stage implements the
system object filter in the loop for frame-based processing. Below code realizes the
LPF system with random input data. The filter system object is located within the
loop for 1024 samples per frame processing. The filter system object is created by
the fdesign and following functions. The code is written in the MATLB editor.
8.2 Advanced Filter Design Methods 615

Magnitude Response (dB)

-20

-40
Magnitude (dB)

-60

-80

-100

-120

-140

-160

-180
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
Normalized Frequency ( rad/sample)

Fig. 8.13 Magnitude response from fvtool function with filter system object

Prog. 8.11 Filter realization with system object for Table 8.6 specification.

frameSize = 1024; % Frame size


N = frameSize*100; % Data size

sr = dsp.SignalSource(randn(N,1),frameSize); % Input generator


sink1 = dsp.SignalSink; % Output buffer
sink2 = dsp.SignalSink; % Input buffer

dfilter = fdesign.lowpass; % Response is lowpass


set(dfilter,'Specificaon','Fp,Fst,Ap,Ast') % Set specificaon
setspecs(dfilter,0.25,0.5,1,40) % Specificaon
filt = design(dfilter,'buer','filterstructure','df2sos','Systemobject',true)

while ~isDone(sr)
input = sr(); % Generate framed input
filteredOutput = filt(input); % Filtered data
sink1(filteredOutput); % Output buffer
sink2(input); % Input buffer
end

figure,
subplot(211), periodogram(sink2.Buffer,[],frameSize)
subplot(212), periodogram(sink1.Buffer,[],frameSize)
616 8 Filters with MATLAB

The spectral power distributions are illustrated below in Fig. 8.14 for the input
and output of the filter. The random white noise is represented by the wide and flat
frequency distribution. The filter output shown in second subplot depicts the con-
centrated spectral distribution toward the low frequencies as we expected. The
spectral power starts to decrease from p=4 and the decline slope is mild to meet the
given specifications.
The MATLAB provides many system objects in toolboxes. Tables 8.9, 8.10,
8.11, 8.12, and 8.13 organize and categorize the partial system objects for filter
related subjects. Further list and information can be found on MathWorks web-
page [2].
Below program represents the filtering task from mp3 signal to the audio device.
The input data is obtained from the mp3 file reading by the system object dsp.
AudioFileReader. The frame size is defined at the file reading system object and
automatically applied to the data filtering and audio playing. The output data is
played over the default audio device by the system object audioDeviceWriter. The
sampling rate is delivered from the file reading system object. The LPF is published
by the system object dsp.LowpassFilter which provides simple procedure with less

Periodogram Power Spectral Density Estimate


10
Input power (dB)

-10

-20

-30
0 0.2 0.4 0.6 0.8 1

50
Output power (dB)

-50

-100
0 0.2 0.4 0.6 0.8 1
Normalized Frequency ( rad/sample)

Fig. 8.14 Output of Prog. 8.11


8.2 Advanced Filter Design Methods 617

Table 8.9 Signal generation system objects


dsp.SignalSource Import variable from workspace
dsp.SineWave Generate discrete sine wave

Table 8.10 Signal input and output system objects


audioDeviceReader Record from sound card
audioDeviceWriter Play to sound card
dsp.AudioFileReader Stream from audio file
dsp.AudioFileWriter Stream to audio file

Table 8.11 Scope and data logging system objects


dsp.TimeScope Time domain signal display and measurement
dsp.SpectrumAnalyzer Display frequency spectrum of time-domain signals
dsp.SignalSink Log simulation data in buffer

Table 8.12 Filter system objects


dsp.Differentiator Direct form FIR fullband differentiator filter
dsp.FIRFilter Static or time-varying FIR filter
dsp.HighpassFilter FIR or IIR highpass filter
dsp.LowpassFilter FIR or IIR lowpass filter
dsp.AllpassFilter Single section or cascaded allpass filter
dsp.BiquadFilter IIR filter using biquadratic structures
dsp.IIRFilter Infinite impulse response (IIR) filter

Table 8.13 Transform dsp.FFT Discrete Fourier transform


system objects
dsp.IFFT Inverse discrete Fourier transform (IDFT)

freedom on design method. The complete parameter list for the given system
objects can be found by the MATLAB documents and help [1, 2]. Note that the
auto-completion and auto-list are available for system object arguments. The iter-
ative loop by while statement executes the frame-based data flow and filtering. By
selecting the input variable for adw object, you can hear the raw or filtered audio.
618 8 Filters with MATLAB

Prog. 8.12 Filtering task from mp3 file to the audio device.
frame = 1024; % Samples per frame

afr = dsp.AudioFileReader('speech_d .mp3','SamplesPerFrame',frame);


% Read data from file
adw = audioDeviceWriter('SampleRate', afr.SampleRate);
% Write data to audio device
L1 = dsp.LowpassFilter('SampleRate',afr.SampleRate,...
'FilterType','FIR','PassbandFrequency',afr.SampleRate/8,...
'StopbandFrequency',afr.SampleRate/4,'PassbandRipple',1,...
'StopbandA enua on',60);
% LPF with 1/4 wpa and 1/2 wst

while ~isDone(afr)
audio = afr(); % Get data
out = L1(audio); % Filtering
adw(out); % Filtered data to audio device
%adw(audio); % Raw data to audio device
end

release(afr);
release(adw);

Fixed-Point Designer
The MATLAB stores and processes numeric variables as double-precision
floating-point values by default. Additional data types are text, integer and
single-precision floating-point values. The powerful PC processors support the
double-precision algorithm for low latency and high throughput processing by
using the complex hardware architecture. Therefore, the MATLAB algorithms are
executed rapidly on the PC environment. The MATLAB algorithms extends the
application areas beyond the desktop computers in order to be the highly deploy-
able language of technical computing.
The hardware complexity is proportional to the data length and type compli-
cation. The reduced data length or fixed-point data type requires the less compli-
cated hardware than the counterpart for double-precision floating-point data
processing. The conventional embedded hardware is optimized for the fixed-point
and single-precision algorithms to meet the cost and power budget. The MATLAB
provides the fixed-point designer [4] for extensive tool to analyze and simulate the
data type conversion in the MATLAB algorithms. The fixed-point designer allows
8.2 Advanced Filter Design Methods 619

the automatic conversion from double-precision algorithms to single precision or


fixed point. The fixed-point designer recommends the optimal data types, length,
and scaling. Also, we can customize the detail data attributes for instance rounding,
overflow, and etc. The simulation presents the algorithm output variation from the
data conversions to understand the algorithm sensitivity. The fixed-point designer
provides apps that lead the data conversion process and enable to compare
fixed-point results with floating-point baselines.
The fixed-point designer is the large toolbox and this section only shows the
brief introduction. A fixed-point data type is defined by the word length, the binary
point position with signed or unsigned property. The binary point position is
interpreted by the scaled fixed-point values. A binary representation of a general-
ized fixed-point number is shown in Fig. 8.15.
In above, the word length is wl and fraction length is 4. The fixed-point designer
performs the automatic conversion process based on the function or app. Below
example shows the representation conversion by using the fixed-point designer
function. The fi function creates the fixed-point numeric object from the
double-precision floating-point number with word length and (un)signed property.
The undefined fraction length provides the best-precision fraction length by
MATLAB. In the first case, the equal word and fraction length indicate that the
binary point is located at the left of MSB. By placing the bin suffix, the fixed-point
numeric object shows the full binary representation. The second case for integer
number demonstrates the 16 word length and 9 fraction length. The sum of two
vectors creates the new fixed-point numeric object with expanded word and fraction
length to embed the output. The MATLAB automatically adjust and traces the
lengths and properties of the objects to preserve the proper numeric information.

word length

bwl-1 bwl-2 ... b5 b4 b3 b2 b1 b0

MSB binary point LSB


fraction length

Fig. 8.15 Binary representation of a generalized fixed-point number


620 8 Filters with MATLAB

Prog. 8.13 Representation conversion by using the fixed-point designer function.


>> a = [1/4 1/8 1/16 1/32] % Double precision floang-point number
a=
0.2500 0.1250 0.0625 0.0313
>> b = fi(a,1,16) % Convert to signed 16 bits number (word length is 16
bits) and fracon length is determined by MATLAB automacally
b=
0.2500 0.1250 0.0625 0.0313
DataTypeMode: Fixed-point: binary point scaling
Signedness: Signed
WordLength: 16
FraconLength: 16
>> b.bin % Show us the binary representaon of the number
ans =
'0100000000000000 0010000000000000 0001000000000000
0000100000000000'
>> c = [4 8 16 32] % Double precision floang-point number
c=
4 8 16 32
>> d = fi(c,1,16) % Convert to signed 16 bits number (word length is 16
bits) and fracon length is determined by MATLAB automacally
d=
4 8 16 32
DataTypeMode: Fixed-point: binary point scaling
Signedness: Signed
WordLength: 16
FraconLength: 9
>> d.bin % Show us the binary representaon of the number
ans =
'0000100000000000 0001000000000000 0010000000000000
0100000000000000'
>> e = b+d
e=
4.2500 8.1250 16.0625 32.0313
DataTypeMode: Fixed-point: binary point scaling
Signedness: Signed
WordLength: 24
FraconLength: 16
>> e.bin
ans =
'000001000100000000000000 000010000010000000000000
000100000001000000000000 001000000000100000000000'
>>
8.2 Advanced Filter Design Methods 621

If we want to declare the fixed-point numeric object, we can use the numerictype
function. For the automatic conversion process, we prepare the target function as
below with myfilter.m file name. The function includes the persistent variable to
perform the filter design process once. The second execution of the function skips
the dsp.FIRFilter system object by the if statement.
Prog. 8.14 Target function for automatic conversion process in fixed-point
designer.

func on [y] = myfilter(x)


%#codegen
% For code genera on, you should put the codegen hashtag in above
persistent d1 % Sta c variable for func on
if isempty(d1) % If it is not defined, the func on compute filter
coefficient
d1 = dsp.FIRFilter('CoefficientsDataType','Custom','Numerator',...
fir1(51,0.1),'FullPrecisionOverride',false,...
'ProductDataType','Full precision','AccumulatorDataType',...
'Custom','OutputDataType','Custom'); % Actucal filter
end
y = d1(x); % Filter execu on
end

The test code for myfilter function is below. We name the file as BAfilter.m. The
tic and toc function measure the execution time between the functions. The soundsc
function plays the vector as sound.
Prog. 8.15 Test code for automatic conversion process of Prog. 8.14.

clear all
clc

data = load('mtlb.mat'); % Load sound


x = data.mtlb;
Fs = data.Fs;
Q = length(x);

c
y = myfilter(x); % Filter algorithm
toc

soundsc(double(y),Fs);
622 8 Filters with MATLAB

When you execute the BAfilter.m program, you can hear the low frequency
MATLAB pronunciation with execution time in seconds. For automatic fixed-point
conversion, execute the fixed-point converter in APPS ribbon tab as Fig. 8.16. Be
careful that the target function and file should be located at the English named
directory in all levels; otherwise, the conversion process will be failed.
Select the myfilter.m file for conversion and click the next button located at the
lower right corner. In the next stage as below, you select test code and click the
autodefine input type button. Click the next again in Fig. 8.17.
In the analyze tab, activate the log data for histogram and click the analyze
button Fig. 8.18.
The MATLAB suggests the optimal fixed-point configuration for each variables
and computations. The numerictype function contains the three arguments as signed
property, word length, and fraction length in Fig. 8.19.
Once you click the proposed type, you can observe the histogram for coverage.
If you accept the suggestion, click convert tab in Fig. 8.20.
Activate the log inputs and outputs for comparison plots in the test tab and click
the test for final test in Fig. 8.21.
You can see the difference between the floating-point and fixed-point configu-
rations for input and output as Figs. 8.22 and 8.23.
Click the next for finalizing the process as Fig. 8.24.

Fig. 8.16 Select the target function for conversion


8.2 Advanced Filter Design Methods 623

Fig. 8.17 Select the test code for conversion

Fig. 8.18 Activate the log data for histogram and click the analyze button
624 8 Filters with MATLAB

Fig. 8.19 Check the MATLAB suggestions for optimal fixed-point configurations

Fig. 8.20 Click the proposed type and observe the histogram for coverage
8.2 Advanced Filter Design Methods 625

Fig. 8.21 Activate the log inputs and outputs for comparison plots and click the test

myfilter > float : x


5

-5
0 500 1000 1500 2000 2500 3000 3500 4000 4500
myfilter > fixed : x
5

-5
0 500 1000 1500 2000 2500 3000 3500 4000 4500
-4 error
10
2

0 500 1000 1500 2000 2500 3000 3500 4000 4500

Fig. 8.22 Observe the difference between the floating-point and fixed-point configurations for
input
626 8 Filters with MATLAB

myfilter > float : y


2

-2
0 500 1000 1500 2000 2500 3000 3500 4000 4500
myfilter > fixed : y
2

-2
0 500 1000 1500 2000 2500 3000 3500 4000 4500
-4 error
10
5

-5
0 500 1000 1500 2000 2500 3000 3500 4000 4500

Fig. 8.23 Observe the difference between the floating-point and fixed-point configurations for
ouput

We can find the overall configuration and profile by opening the conversion
report located at your_directory/codegen/myfilter/fixpt as myfilter_report.html or by
clicking the Reports at finish workflow window in Fig. 8.25.
FIR Filter Using Fixed-Point Numbers
Frequently, the system is designed with analog-to-digital converter (ADC) and
digital-to-analog converter (DAC) for real-time processing. Along with fixed-point
processor, the complete arithmetic can be implemented by using the fixed-point
operations. In this situation, we carefully manipulate the word and fraction length.
Below is the system with 12-bit ADC and DAC for processing the audio signal in
Fig. 8.26.
To simulate the 12-bit ADC, let's load audio signal as below.
8.2 Advanced Filter Design Methods 627

Fig. 8.24 Finalizing the process

Fig. 8.25 Overall configuration and profile for fixed-point conversion


628 8 Filters with MATLAB

Fixed-point
Microprocessor
ADC 12-bit DAC 12-bit
16-bit coefficients
40-bit ALU

Fig. 8.26 System configuration for real-time FIR filter with ADC/DAC and fixed-point
microprocessor

Prog. 8.16 Load audio signal.

data = load('mtlb.mat'); % Load sound


x = data.mtlb;
L = length(x);
whos x
>>
Name Size Bytes Class A ributes

x 4001x1 32008 double

The loaded x variable is a floating-point number with double precision. Change


the variable to 12-bit integer as below.
Prog. 8.17 Change the variable to 12-bit integer.

tx = fi(x,1,12);
tx.get
% Now you can see that the variable has the 12-bit WL and 9-bit FL as
below
ans =
struct with fields:
...
WordLength: 12
Frac onLength: 9
...
ix = fi(tx.int,1,12,0); % Change the 12-bit numbers to integer
ix.WordLength % Check word length
ans =
12
ix.Frac onLength % Check frac on length
ans =
0
8.2 Advanced Filter Design Methods 629

The MATLAB function computes the FIR Type I LPF impulse response as
below. The cutoff frequency is p=4.
Prog. 8.18 Design and analysis the FIR filter.

N = 60; % FIR order


NN = 2^12; % Frequency samples
nn = 0:1:N; % Impulse response index
LPFhn = fir1(N,0.25); % Type I FIR filter
[H,W] = freqz(LPFhn,1,NN); % Frequency analysis
figure,
subplot(211), stem(nn,LPFhn), grid
subplot(212), plot(W,20*log10(abs(H))), grid

The impulse response and frequency response are given as Fig. 8.27.
The FIR filter coefficients can be converted to the 16-bit integer number as
below.

0.3

0.2
h LPF [n]

0.1

-0.1
0 10 20 30 40 50 60
n

0
Magnitude(dB)

-50

-100
0 /4 /2 3 /4

Fig. 8.27 Impulse and frequency response of Prog. 8.18


630 8 Filters with MATLAB

Prog. 8.19 FIR filter coefficient conversion to 16-bit integer number.


tLPFhn = fi(LPFhn,1,16); % Convert to fixed-point 16-bit #
iLPFhn = fi(tLPFhn.int,1,16,0); % Convert to 16-bit integer
iLPFhn.WordLength % Check word length
ans =
16
iLPFhn.Frac onLength % Check frac on length
ans =
0
[H1,W1] = freqz(double(iLPFhn),1,NN); % Frequency analysis
figure,
subplot(211), stem(nn,iLPFhn), grid
subplot(212), plot(W1,20*log10(abs(H1))), grid

Designed LPF has all integer numbers which is greater than the original coef-
ficient values. The 16-bit integer impulse response and corresponding frequency
response are shown in Fig. 8.28.

20000
(Integer) hLPF [n]

15000

10000

5000

0 10 20 30 40 50 60
n

100
(Integer) Magnitude(dB)

50

-50
0 /4 /2 3 /4

Fig. 8.28 Output of Prog. 8.19


8.2 Advanced Filter Design Methods 631

The gain of the integer LPF is significantly higher than the original LPF;
therefore, the filter output is required to be scale down afterward. Perform the filter
operation as below.
Prog. 8.20 Perform the integer filter operation.

iy = filter(iLPFhn,1,ix); % Perform filter opera on


iy.get
ans =
struct with fields:
...
Signedness: 'Signed'
WordLength: 34
Frac onLength: 0
...
nn2 = 0:1:(L-1);
figure,
stem(nn2(end-100:end),[ix(end-100:end) iy(end-100:end)]),grid
% Plot last 100

The input and output of the filter are illustrated in Fig. 8.29. The output magnitude is
significantly higher than the input amplitude because of the integer FIR coefficients. We
need to compute the integer filter gain from the coefficients for scale down.

2500
Integer Input
2000 Integer Output

1500

1000

500

-500

-1000

-1500

-2000

-2500
3900 3910 3920 3930 3940 3950 3960 3970 3980 3990 4000
n

Fig. 8.29 Output of Prog. 8.20


632 8 Filters with MATLAB

The FIR filter gain is below.

P
L1
Gain ¼ jh½kj ð8:1Þ
k¼0

Instead of direct scaling, the bit shift is performed based on the gain as below.
The number of bit shift is represented by the power of two factor for binary number
system. Note that the b c is floor function.

Bit Shift ¼ blog2 ðGainÞc ð8:2Þ

Below code creates the new fixed-point variable yout with WL word length and
FL fraction length. The binary values are assigned from the integer filter output to
new fixed-point variable. Both variable sizes are identical, but the binary point
locations are distinct. Therefore, the binary representations are identical, but the
decimal representations are different as factor of bit shift. Note that we cannot
change the word and fraction length of the existing fixed-point variables.
Prog. 8.21 Apply filter gain to adjust output magnitude.

GAIN = sum(abs(iLPFhn)); % Gain computa on


WL = iy.WordLength; % New word length
FL = iy.Frac onLength + floor(log2(double(GAIN))); % New frac on length
% log2(gain) represents the gain by factor of 2
yout = fi(size(iy),1,WL,FL); % New fixed-point variable
yout.bin = iy.bin; % Binary copy
figure,
stem(nn2(end-100:end),[ix(end-100:end) yout(end-100:end)]), grid

Display the input and scaled output as Fig. 8.30.


Observe that the scale of the input and output is comparable now. However, the
output word length is still 34 bits. Change to 12-bit for DAC.
8.2 Advanced Filter Design Methods 633

100
Integer Input
50 Scaled Integer Output

-50

-100

-150

-200

-250

-300

-350
3900 3920 3940 3960 3980 4000
n

Fig. 8.30 Output of Prog. 8.21

Prog. 8.22 Change the output size to 12-bit integer.

yfinal = fi(yout,1,12); % Convert to 12-bit integer number


yfinal.WordLength
ans =
12
yfinal.Frac onLength
ans =
0
figure,
stem(nn2(end-100:end),[ix(end-100:end) yfinal(end-100:end)]),grid

The output is modified to the 12-bit integer. Verify output by graph in


Fig. 8.31.
Let's hear the filtered sound.
Prog. 8.23 Listen the filtered sound.

soundsc(double(yfinal),data.Fs); % Play sound


634 8 Filters with MATLAB

100
Integer Input
50 Scaled 12-bit Integer Output

-50

-100

-150

-200

-250

-300

-350
3900 3920 3940 3960 3980 4000
n

Fig. 8.31 Output of Prog. 8.22

The above integer FIR filter with integer data can apply for processing the filter
system based on the binary fraction numbers. The procedure is identical as below.
1. ADC input ! 12-bit binary fraction number
2. FIR filter coefficient ! compute L1  norm ! Scaling ! 16-bit binary
fraction number
3. FIR filtering (full precision)
4. Filter output ! 12-bit binary fraction number.
We can select the different scaling policy such as L1-, L∞-, and L2-norm to avoid
the output overflow. In this example, the L∞-norm is utilized. The subsequent
MATLAB program realizes the equivalent filtering task with binary fraction rep-
resentation. Note that the fraction length in the fixed-point number should be one bit
less than the word length because of the sign bit in MSB location. The FIR filter
computation is the arithmetic of consecutive multiplications and additions. The full
precision filter operation indicates that the MATLAB automatically adjusts the data
width for processing and storing without losing any information. We can manip-
ulate the precision by modifying the properties of the fixed-point objects. The
ProductMode and SumMode property can be specified as FullPrecision, KeepLSB,
KeepMSB, or SpecifyPrecision. The further information is beyond the book scope
and can be found at the MathWorks documentations [5]. Remember that the
auto-completion and auto-listing by tab keystroke are convenient tool to input the
object property.
8.2 Advanced Filter Design Methods 635

Prog. 8.24 Filter operation based on the binary fraction numbers. (ADC/
DAC ! 12 bits and h[n] ! 16 bits).
data = load('mtlb.mat'); % Load sound
x = data.mtlb; % Extract data
L = length(x); % Data length
N = 60; % Filter order
NN = 2^12; % Frequency sampling
nn = 0:1:N; % Filter me index
n = 0:1:L-1; % Data me index
WW = linspace(0,2*pi,NN); % FFT frequency index

tx = fi(x,1,12); % 12-bit ADC


bx = fi(size(tx),1,12,11); % 12-bit for binary fracon #
bx.bin = tx.bin;

LPFhn = fir1(N,0.25); % LPF FIR h[n]

l1 = sum(abs(LPFhn)); % L1-norm
l2 = sqrt(sum(LPFhn.^2)); % L2-norm
[H,W] = freqz(LPFhn,1,NN);
Linf = max(abs(H)); % Linf-norm (selected)

bLPFhn = fi(LPFhn/Linf,1,16,15); % h[n] with binary fracon #


[H1,W1] = freqz(double(bLPFhn),1,NN);

by = filter(bLPFhn,1,bx); % Filtering
yfinal = fi(by,1,12,11); % Convert to 12-bit binary fracon #

figure,
subplot(311), plot(n,bx), grid
subplot(312), plot(W1,20*log10(abs(H1))), grid
subplot(313), plot(n,yfinal(1:L)), grid

xxx = (double(bx),NN);
yyy = (double(yfinal),NN);

pxxx = 10*log10(xxx.*conj(xxx)/(2*pi*NN)); % Spectral density


pyyy = 10*log10(yyy.*conj(yyy)/(2*pi*NN)); % Spectral density

figure,
subplot(211), plot(WW(1:NN/2+1),pxxx(1:NN/2+1)), grid
subplot(212), plot(WW(1:NN/2+1),pyyy(1:NN/2+1)), grid
636 8 Filters with MATLAB

Fig. 8.32 Output of Prog. 8.24. Part 1

Figure 8.32 shows the input, frequency response, and output of the FIR filter
system with binary fraction numbers. The cutoff frequency is p=4 and the L∞-norm
is applied for scaling. The range of the input and output is placed within the binary
fraction number. No overflow signs are observed.
To verify the filter processing, Fig. 8.33 demonstrates the power spectral density
for input and output. The output spectral power distribution presents the substan-
tially reduced magnitude from p=4; hence, the filter removes the high frequency
components efficiently.
The conventional programing with embedded processor requires to represent the
all data and coefficient as integer number for binary fraction processing. The
intrinsic functions from the processor manufactures support fraction mode arith-
metic with various properties such as saturation, output width, and etc. The typical
standard arithmetic operators (+, *, etc.) cannot use the given hardware fully. The
filter for binary fraction numbers should be built with integer number and intrinsic
functions. The dedicated compiler is essential as well.
8.3 MATLAB Code Generation 637

Input
0
Pwr./Freq. (dB/Radian)

-50

-100
0 /4 /2 3 /4

Ouput
0
Pwr./Freq. (dB/Radian)

-50

-100
0 /4 /2 3 /4

Fig. 8.33 Output of Prog. 8.24. Part 2

8.3 MATLAB Code Generation

All of the filter designs and executions have been performed on the MATLAB
environment. Even the mathematical derivation procedures are realized in the
MATLAB symbolic math. The designed filters are required to be executed in the
various testbeds and targets for deployment. Conventional deployment method is
the rewriting the MATLAB program manually as the C and C++ code for a variety
of hardware platforms. The code conversion process is tedious and time-consuming
task with multiple verifications for accuracy. The overall procedure is illustrated as
Fig. 8.34.

MATLAB Code
Target Test and
Requirements Code Conversion to
Deployment Verification
Development C and C++
++

Feedback

Fig. 8.34 Overall procedure for MATLAB code deployment on target system
638 8 Filters with MATLAB

The MATLAB provides the MATLAB coder [6] to generate C and C++ code
from MATLAB program. The generated code can be integrated with the existing
projects as source code or libraries in readable and portable format. The mathe-
matically complicated algorithms are developed in MATLAB environment and the
interface programs are written by the C and C++ code. As the part of combining
procedure, the MATLAB coder generates the C and C++ code. We can also
compile the generated code as a MEX-function to use in the MATLAB environ-
ment for verification and acceleration. The MEX stands for ‘MATLAB executable.’
The MEX subroutines can be called by the command line as if they are MATLAB
functions. The MATLAB codes beyond the MATLAB environment are extremely
extensive and fast-growing area in MATLAB world. However, this section only
provides the code generation for MEX-function to execute the algorithm fast.
Further information can be found at MATLAB documentations.
The code generation only supports the MATLAB functions not a general script.
We have to separate the algorithms into the individual functions. Before we perform
the code generation, check the compiler as below.
Prog. 8.25 Check compiler for MEX-function generation by using MATLAB
coder.

>> mex -setup


Error using mex
No supported compiler or SDK was found. You can install the freely available
MinGW-w64 C/C++
compiler; see Install MinGW-w64 Compiler. For more op ons, visit
h p://www.mathworks.com/support/compilers.

If we have any compatible compiler, the MATLAB returns the compiler name,
otherwise we have to install the software. The above is the error message with no
available compiler. The open-source compiler for MATLAB is MinGW64. Install
the compiler by following procedure.
HOME ribbon tab ! Add-Ons ! Get Add-Ons ! Search ‘gcc’ ! Choose
and install ‘MATLAB Support for MinGW-w64 C/C++ Compiler’.
Now, you have proper environment. Below is the example filter function.
8.3 MATLAB Code Generation 639

Prog. 8.26 Example filter for MEX-function.


func on [y] = myfilter1(x)
%#codegen
% For code genera on, you should put the codegen hashtag in above
persistent d1 % Sta c variable for func on
if isempty(d1) % If it is not defined, the func on compute filter coefficient
d1 = dsp.FIRFilter('Numerator',fir1(50,0.1)); % Actual filter
end
y = d1(x); % Filter execu on
end

In the filter function, the filter coefficient is computed once due to the static
variable and conditional statement. Not all MATLAB intrinsic functions are
compatible to the code generation. Visit the website [7] for compatibility. Potential
our filter selections for code generation are below.
dsp.FIRFilter, dsp.IIRFilter, dsp.HighpassFilter, dsp.LowpassFilter.
See the manual [8] for further information on the above functions. Check the
suitability by typing the following instruction in the command window.
Prog. 8.27 Check suitability for code generation.

coder.screener('myfilter1')

If there are no problems, you can see the below window as Fig. 8.35.
Ready to generate and compile the c code for the function.
Prog. 8.28 Generate and compile the c code for the myfilter1.m function.

codegen myfilter1 -args {randn(4001,1)}

Fig. 8.35 Check readiness for code generation


640 8 Filters with MATLAB

The last argument specifies the input argument for my filter function. Note that
the argument size must correspond with caller argument size. The 4001 is the size
of MATLB sound.
Prog. 8.29 Test code for MATLAB function.

data = load('mtlb.mat'); % Load sound


x = data.mtlb;
Fs = data.Fs;

c
y = myfilter1(x); % Filter algorithm (Change this for compiled version)
toc

figure,
subplot(211), spectrogram(x,128,120,128,Fs)
tle('Input')
subplot(212), spectrogram(y,128,120,128,Fs)
tle('Output')

Figure 8.36 shows the spectrogram [3] of the input and output signal. The
spectrogram is the frequency plot in terms of time. The input spectrogram illustrates
the wide frequency distribution and the filtered output spectrogram presents the low
frequency centric configuration according to the LPF property. The sampling fre-
quency is 7418 Hz and the cutoff frequency is the 370.9 Hz (0.1 normalized fre-
quency). Around the cutoff frequency, the magnitude is significantly decreasing on
the output spectrogram. The filter is working properly.
The tic & toc function measures the execution time in second. Execute the above
code and check the execution time. The example execution time is below. Note that
above code is pure MATLAB code and the execution time is statistical.
Prog. 8.30 Execution time of the MATLAB function from Prog. 8.29.

Elapsed me is 0.265705 seconds.


>>

Change the filter function with MEX-function as below.


8.3 MATLAB Code Generation 641

Input
500

Power/frequency (dB/Hz)
400 -50
Time (ms)

300
-100
200

100
-150
0 0.5 1 1.5 2 2.5 3 3.5
Frequency (kHz)
Output
500

Power/frequency (dB/Hz)
400 -50
Time (ms)

300
-100
200

100
-150
0 0.5 1 1.5 2 2.5 3 3.5
Frequency (kHz)

Fig. 8.36 Output of Prog. 8.30

Prog. 8.31 Change Prog. 8.29 for MEX-function execution.

...
c
y = myfilter1_mex(x); % Filter algorithm (Change this for compiled version)
toc
...

The execution time with MEX-function is shown below. The execution time
varies with trials due to the resource assignments of operating system.
Prog. 8.32 Execution time of the MEX-function from Prog. 8.31.

Elapsed me is 0.001380 seconds.


>>
642 8 Filters with MATLAB

The speedup from the code generation and compiling can be computed by
following equation.

Speedup ¼ Execution time with MATLAB code


Execution time with MEX code
ð8:3Þ

With given execution times, the speedup from the MEX is the 192.54 which
indicates that the MEX code is 192.54 times faster than the MATLAB intrinsic
code. The MEX-function can be applied for the system object as well. For the 1024
sample size frame, we have to regenerate the MEX function with new argument size
as below.
Prog. 8.33 Re-generate and re-compile the c code for new argument size.

codegen myfilter1 -args {randn(1024,1)}

The system object code for the identical task is below. Observe that the audio
data is substituted with the longer length version. The frame size is 1024 samples.
Prog. 8.34 Identical task as Prog. 8.29 with system object and frame-based pro-
cessing.

FrameSize = 1024; % Frame size

reader = dsp.AudioFileReader('handel.ogg','SamplesPerFrame',FrameSize);
% Audio file reader object
P = audioDeviceWriter(reader.SampleRate); % Audio device writer object

me = 0; % Execu on me ini aliza on

while ~isDone(reader)
x = reader();
c;
y = myfilter1(x); % Filter algorithm (Change this for compiled version)
me = me + toc;
P(y);
end

me

me =
0.2069
>>
8.3 MATLAB Code Generation 643

The execution time is accumulated for multiple frame times because of the
frame-based executions. The audio device uses the default device. We can modify
the device by setting the object properties. Remember to use the auto-completion
and auto-listing by applying the tab key.
Prog. 8.35 Modify Prog. 8.34 for MEX-function execution.

...
while ~isDone(reader)
...
y = myfilter1_mex(x); % Filter algorithm (Change this for compiled version)
me = me + toc;
...
end

me

me =
0.0203
>>

The execution time of the MEX function can be obtained by changing the filter
function as above. The speedup of the MEX based on the system object is 10.2. The
reduced performance results from the segmented execution which requires the
overhead to initialize and finalize the executions. Overall, the MEX-function pro-
vides the significant speedup. The explicit code generation and system integration
can be found at the MATLAB documentation [6].

References

1. MathWorks: MATLAB Homepage (2020). https://www.mathworks.com/products/matlab.html


2. MathWorks: MATLAB Help Center (2020). https://www.mathworks.com/help/
3. Stoica, P., Moses, R.L.: Introduction to Spectral Analysis. Prentice Hall (1997)
4. MathWorks: Fixed-Point Designer (2020). https://www.mathworks.com/help/fixedpoint/index.
html
5. MathWorks: fimath ProductMode and SumMode (2020). https://www.mathworks.com/help/
fixedpoint/ug/using-fimath-productmode-and-summode.html
6. MathWorks: MATLAB Coder (2020). https://www.mathworks.com/help/coder/index.html
7. MathWorks: Functions and Objects Supported for C/C++ Code Generation (2020). https://
www.mathworks.com/help/simulink/ug/functions-and-objects-supported-for-cc-code-
generation.html
8. MathWorks: Fixed-Point Filters (2020). https://www.mathworks.com/help/dsp/fixed-point-
filters.html?s_tid=CRUX_lftnav
Appendix A
MATLAB Fundamentals

The MATLAB provides the extensive tutorials for all its products in various format.
This appendix briefly introduces the MATLAB fundamentals based on the
MATLAB Primer. You can observe the primitive MATLAB capabilities in short.
Once you click the MATLAB icon, you will get the following screen as Fig A.1.
We can observe the four window spaces as below.
– Current Folder: Your working directory and files.
– Command Window: Enter commands for immediate execution.
– Workspace: Variables and data.
– Editor-Untitled: Once click the New button, the editor window provides the
script space for programming.
Most of the icon buttons and ribbon menus are intuitive and self-explanatory for
its functions. We can execute the MATLAB commands by
– Type the command in command window and put the <enter> key
– Write the program in the editor window and put the <ctrl>+<enter> key
The script program also can be executed by clicking the run button. One big
advantage of the MATLAB programming is the worry-free variables. If we need the
variables, just create and use them. Below example creates the a and b variable with
initial values in command window. As soon as we type the ‘a=1’ and <enter>, the
a variable is created with initial value one. When we compute the value without the
assignment, the output value is allocated at the temporary variable ans. See the ‘a+b’
command in below. All created variables can be seen in the workspace window.

© Springer Nature Singapore Pte Ltd. 2021 645


K. Kim, Conceptual Digital Signal Processing with MATLAB,
Signals and Communication Technology,
https://doi.org/10.1007/978-981-15-2584-1
646 Appendix A: MATLAB Fundamentals

Fig. A.1 MATLAB screen

Prog. A.1 Variable creation and initialization

>> a = 1
a=
1
>> b = 2
b=
2
>> a+b
ans =
3
>>

To clear the command window, type the clc. The second MATLAB advantage is
the strong supports for the linear algebra operations based on the matrix and array.
Just like variable, we can create the matrix and array as below.
Appendix A: MATLAB Fundamentals 647

Prog. A.2 Creation, initialization, and arithmetic of matrix variables

>> a = [1 2 3]
a=
1 2 3
>> b = [4, 5, 6]
b=
4 5 6
>> c = [7; 8; 9]
c=
7
8
9
>> d = [1 2 3; 4 5 6; 7 8 9]
d=
1 2 3
4 5 6
7 8 9
>> e = d*a
Error using *
Incorrect dimensions for matrix mulplicaon. Check that the number of
columns in the first matrix matches the number of rows
in the second matrix. To perform elementwise mulplicaon, use '.*'.
>> e = a*d
e=
30 36 42
>>

The most arithmetic operators in MATLAB perform the linear algebra opera-
tions which require to match the dimensions between the matrices. Table A.1
shows the arithmetic operator list. The addition and subtraction are working for the
constant, matrix, and element-wise operation.
Other operators for logic and relation are listed below as Table A.2.
The matrix can be generated by the MATLAB functions. The part of functions is
shown below in Table A.3.
Below example demonstrates the matrix generation from the function. The first
command rng(‘default’) places the random number generator setting to their default
values so that they produce the same random numbers.
648 Appendix A: MATLAB Fundamentals

Table A.1 Arithmetic operator list of MATLAB


Symbol Role
+ Addition
− Subtraction
* Matrix multiplication
/ Matrix right division
\ Matrix left division
^ Matrix power
‘ Complex conjugate transpose
.* Element-wise multiplication
./ Element-wise right division
.\ Element-wise left division
.^ Element-wise power
.’ Transpose

Table A.2 Logical and relational operator list of MATLAB


Symbol Role
¼= Equal to
*= Not equal to
> Greater than
>= Greater than or equal to
< Less than
<= Less than or equal to
& Logical AND
| Logical OR
&& Logical AND (with short-circuiting)
|| Logical OR (with short-circuiting)
* Logical NOT

Table A.3 Special matrix generation functions


Function Role
zeros Create array of all zeros
ones Create array of all ones
rand Uniformly distributed random numbers
eye Identity matrix
Appendix A: MATLAB Fundamentals 649

Prog. A.3 Matrix generation example from function

>> rng('default')
>> aa = rand(3,3)
aa =
0.8147 0.9134 0.2785
0.9058 0.6324 0.5469
0.1270 0.0975 0.9575
>> bb = ones(3,2)
bb =
1 1
1 1
1 1
>>

The matrix is also produced by the concatenation which joins the arrays to make
larger ones. See below example.

Prog. A.4 Matrix generation example by concatenation

>> rng('default')
>> bb = randi(10,2,3)
bb =
9 2 7
10 10 1
>> cc = [bb bb]
cc =
9 2 7 9 2 7
10 10 1 10 10 1
>> dd = [bb, bb]
dd =
9 2 7 9 2 7
10 10 1 10 10 1
>> ee = [bb; bb]
ee =
9 2 7
10 10 1
9 2 7
10 10 1
>>
650 Appendix A: MATLAB Fundamentals

Use the indexing, we can access or modify selected elements of an array. The
most general method is to indicate row and column number which starts from one.
A single column-wise numbering can specify the matrix position as well. The
matrix element can be modified by assigning the specific value to the element.

Prog. A.5 Matrix indexing and modification

>> bb = randi(100,4,4)
bb =
23 54 11 82
92 100 97 87
16 8 1 9
83 45 78 40
>> bb(2,4)
ans =
87
>> bb(14)
ans =
87
>> bb(2,4)=0
bb =
23 54 11 82
92 100 97 0
16 8 1 9
83 45 78 40
>> bb(2,1:3)
ans =
92 100 97
>> bb(:,2)
ans =
54
100
8
45
>> bb(end,:)
ans =
83 45 78 40
>> cc = 0:5:30
cc =
0 5 10 15 20 25 30
>> dd = 1:10
dd =
1 2 3 4 5 6 7 8 9 10
>>
Appendix A: MATLAB Fundamentals 651

The colon operator allows to refer the multiple elements in the matrix as the
start:end form. The colon alone indicates all of the elements in that dimension. The
end indicator denotes the last row or column number. The general colon operator
creates an equally spaced vector using the form start:step:end. Missing the step
value indicates the default step value of one.
MATLAB provides a large number of functions which perform various tasks.
The input and output argument format can be found by using the help or doc
function as below. Note that doc function opens the new window for information.

Prog. A.6 MATLAB help

>> help max


max Largest component.
...
[Y,I] = max(X) returns the indices of the maximum values in vector I.
If the values along the first non-singleton dimension contain more
than one maximal element, the index of the first one is returned.
...
Example:
X = [2 8 4; 7 3 9]
max(X,[],1)
max(X,[],2)
max(X,5)
...
>>

One example of function usage is to find the minimum, negative, and zero
locations of the given function below.

y ¼ x2  1 for  10  x  10

Find the x values which satisfy the following conditions.



min x2  1
x
x  1\0
2

x2  1 ¼ 0

The MATLAB numerically computes the values based on the discretized input
values for the given range. The continuous input is divided into the discrete input
with 0.1 step by using the colon operator. The output is calculated by the
element-wise operation. The min and find function perform the designated tasks.
Note that the fine-grain results can be derived from the reduced step size for input.
652 Appendix A: MATLAB Fundamentals

In general, the function supports the various argument styles. See help for further
information. Below example is written by the script editor.

Prog. A.7 Numerically solve the equation

x = -10:0.1:10; % Input values


y = x.^2-1; % Output equaon

[k1,I1] = min(y) % Find the min value at k1 and locaon I1


[k2] = find(y<0) % Find the locaons for negave output
y(k2) % Corresponding negave values
[k3] = find(y==0) % Find the zero locaons
y(k3) % Verify the zero outputs

k1 =
-1
I1 =
101
k2 =
92 93 94 95 96 97 98 99 100 101
102 103 104 105 106 107 108 109 110
ans =
Columns 1 through 13
-0.1900 -0.3600 -0.5100 -0.6400 -0.7500 -0.8400 -
0.9100 -0.9600 -0.9900 -1.0000 -0.9900 -0.9600 -0.9100
Columns 14 through 19
-0.8400 -0.7500 -0.6400 -0.5100 -0.3600 -0.1900
k3 =
91 111
ans =
0 0

The third advantage of the MATLAB is the powerful visualization tools. The
impressive 2-D and 3-D plots are available with various decoration functions to
display extensive information. Labeling, legend, range, and etc. are specified by the
MATLAB functions. Using the TeX markup, Geek letters and special characters
can be added to the plot. Some of the list are arranged below in Table A.4.
Appendix A: MATLAB Fundamentals 653

Table A.4 Special text markup for special characters


Char. sequence Symbol Char. sequence Symbol
^{ } Superscript \delta d
_{ } Subscript \epsilon 
\bf Bold font \theta h
\it Italic font \pi p
\alpha a \omega x
\beta b \Omega X
\gamma c \rightarrow !

Below example shows the line and stem plots.

Prog. A.8 2-D plot example

x = 0:pi/100:2*pi; % Input
y1 = sin(x); % sine funcon
y2 = cos(x); % cosine funcon

figure,
plot(x,y1,x,y2), grid % Line plot for sine and cosine
tle(‘Example 1’) % Title
legend('sin(\omega)','cos(\omega)'); % Legend with special char
xcks([0 pi/2 pi 3*pi/2 2*pi]) % Tick posion
xcklabels({'0','\pi/2','\pi','3\pi/2','2\pi'}) % Tick label
xlim([0 2*pi]) % x display range
ylim([-1.5 1.5]) % y display range
xlabel('\omega') % x label
ylabel('Magnitude') % y label

figure,
subplot(211), stem(x,y1), grid % Subplot with stem
tle(‘Example 2’)
ylabel('sin(\omega)')
xcks([0 pi/2 pi 3*pi/2 2*pi])
xcklabels({'0','\pi/2','\pi','3\pi/2','2\pi'})
xlim([0 2*pi])
subplot(212), stem(x,y2), grid
ylabel('cos(\omega)')
xcks([0 pi/2 pi 3*pi/2 2*pi])
xcklabels({'0','\pi/2','\pi','3\pi/2','2\pi'})
xlim([0 2*pi])
xlabel('\omega')
654 Appendix A: MATLAB Fundamentals

Example 1
1.5
sin( )
cos( )
1

0.5
Magnitude

-0.5

-1

-1.5
0 /2 3 /2 2

Fig. A.2 Output of Prog. A.8. Part 1

The simple sine and cosine plots are displayed for 2p range as below (Fig A.2).
The subplot function allows us to place the more than one plot in the single
figure as Fig A.3.
The MATLAB also gives the versatile 3-D plot features. Below example pre-
sents the 3-D Gaussian plot according to the following equation.

z ¼ f ðx; yÞ ¼ eððxx0 Þ þ ðyy0 ÞÞ


Appendix A: MATLAB Fundamentals 655

Example 2
1

0.5
sin( )

-0.5

-1
0 /2 3 /2 2

0.5
cos( )

-0.5

-1
0 /2 3 /2 2

Fig. A.3 Output of Prog. A.8. Part 2

Prog. A.9 3-D plot example

[X,Y] = meshgrid(-2:0.1:2); % Cartesian grid


Z = exp(-(X.^2+Y.^2)); % 2-D Gaussian funcon Z = f(X,Y)

figure,
surf(X,Y,Z) % 3D surface plot
tle('3-D Normal Distribuon') % Title
xcks([-2 -1 0 1 2]) % Tick posion
xcklabels({'-2','-1','x_0','1','2'}) % Tick label
xlabel('x') % x axis label
ycks([-2 -1 0 1 2]) % Tick posion
ycklabels({'-2','-1','y_0','1','2'}) % Tick label
ylabel('y') % y axis label
zlabel('e^{-((x-x_0)^2+(y-y_0)^2)}') % z axis label
colormap('gray') % Color bar color configuraon
colorbar % Color bar
656 Appendix A: MATLAB Fundamentals

3-D Normal Distribution


1

0.9

1
0.8

0.8 0.7
+(y-y ) )
2
0

0.6 0.6
2
e -((x-x 0 )

0.4 0.5

0.4
0.2
0.3
0
2 0.2
1 2
y0 1 0.1
x0
-1
-1
y -2 -2
x

Fig. A.4 Output of Prog. A.9

Prior to create the 3-D plot, we must generate the input coordinates for the 3-D
equation. The meshgrid function returns 2-D grid coordinates based on the coor-
dinates contained in input vector(s). The X and Y are the square grid coordinates
with single input grid size. The element-wise operation completes the equation
calculation followed by the 3-D plot function. Below figure shows the 3-D surface
plot. We can change the viewpoint by clicking the rotate 3D button and dragging
the figure (Fig A.4).
We can create the MATLAB function by generating the new script for function
as shown in Fig A.5.
The created editor includes the function format as below. Decide function name,
write function code, and update the comment. Finally save the function as the
function name with m extension.

Prog. A.10 Created new function format

funcon [outputArg1,outputArg2] = untled2(inputArg1,inputArg2)


%UNTITLED2 Summary of this funcon goes here
% Detailed explanaon goes here
outputArg1 = inputArg1;
outputArg2 = inputArg2;
end
Appendix A: MATLAB Fundamentals 657

Fig. A.5 New script for function

The simple sum function is written for example as below.

Prog. A.11 Function example

funcon [z] = Mysum(x,y)


% Compute the sum of two variables or arrays
% z = x+y
% Example
% x = [1 2 3];
% y = [3 5 7];
% z = Mysum(x,y)
% Created by Keonwook Kim
% Jan. 23rd 2019
z = x+y;
end

Save the function as Mysum.m in the working directory. The help function with
Mysum replies the comment in the function as shown below. Execute the comment
example for verification.
658 Appendix A: MATLAB Fundamentals

Prog. A.12 Function help and execution

>> help Mysum


Compute the sum of two variables or arrays
z = x+y
Example
x = [1 2 3];
y = [3 5 7];
z = Mysum(x,y)
Created by Keonwook Kim
Jan. 23rd 2019
>> x = [1 2 3];
y = [3 5 7];
z = Mysum(x,y)
z=
4 7 10
>>

We can execute the part of MATLAB program code as section. Sometime, this
kind of execution is required for debugging. The double percent sign (%%) divides
the program into the sections as shown in Fig A.6. By moving the cursor, the
selected section is highlighted by yellow color as shown below. Typing the <ctrl>
+<enter> executes the chosen section. MATLAB provides the advanced debugging
tools and the section run is the part of them.
In command window, the command history is recalled by clicking the <up> key
and the history is narrowed by typing the character letters as shown in Fig A.7. The
quick access to the history makes the multiple executions easy for various purpose.
Followings are the frequently used commands.
clear all: Clear all variables
clc: Clear the command window
clf: Clear the current figure
close all: Close all figure windows
lookfor ‘keyword’: Search all MATLAB files for keyword
Further information about the MATLAB and toolboxes can be referred from the
MathWorks documentations.
Appendix A: MATLAB Fundamentals 659

Fig. A.6 Section division

Fig. A.7 Recall command history


Appendix B
MATLAB Symbolic Math Toolbox

Symbolic math performs exact computation with variables which have no given
value as symbols. Symbolic math toolbox provides functions for solving and
manipulating symbolic math equations. The toolbox delivers functions in subjects
such as calculus, linear algebra, differential equations, equation simplification, and
equation manipulation. The computations can be realized either analytically or
using variable-precision arithmetic. The MATLAB live script editor presents the
optimal environment to create and run the symbolic math code. We can share the
symbolic work with other users as live scripts or convert them to HTML or PDF for
publication. We can generate the new live script by selecting the New ! Live
Script in the menu as below Fig B.1.
The live script is divided into the text and code area. The text area (white)
describes the background, algorithm, explanation, analysis, etc. with plain text. The
code area (gray) locates the MATLAB code for algorithm execution.
The MATLAB outcome is embedded at the live script immediate right or below
according to your choice as shown in Fig B.2.

© Springer Nature Singapore Pte Ltd. 2021 661


K. Kim, Conceptual Digital Signal Processing with MATLAB,
Signals and Communication Technology,
https://doi.org/10.1007/978-981-15-2584-1
662 Appendix B: MATLAB Symbolic Math Toolbox

Fig. B.1 Generate live script

The buttons under the LIVE EDITOR ribbon menu specify the file, text, code,
and execution related information. The buttons are intuitive and self-explanatory.
Example live script code is below. Note that the below is not the symbolic math
code. Execute the code by clicking <ctrl>+<enter>.
Appendix B: MATLAB Symbolic Math Toolbox 663

Prog. B.1 Example of live script code for MATLAB programming

Title
Heading
Normal
% Code
x = 0:pi/100:2*pi; % Input
y1 = sin(x); % sine func on
y2 = cos(x); % cosine func on
plot(x,y1,x,y2), grid % Line plot for sine and cosine
tle('Example 1') % Title
legend('sin(\omega)','cos(\omega)'); % Legend with special char
x cks([0 pi/2 pi 3*pi/2 2*pi]) % Tick posi on
x cklabels({'0','\pi/2','\pi','3\pi/2','2\pi'}) % Tick label
xlim([0 2*pi]) % x display range
ylim([-1.5 1.5]) % y display range
xlabel('\omega') % x label
ylabel('Magnitude') % y label

Most type of MATLAB code can be executed in the live script. The graphic
environment of live script gives the powerful presentation for the symbolic math
code which use the mathematical symbols and characters frequently. Now, we will
explore the symbolic math toolbox with live script editor. Below example shows
the symbolic math example.
664 Appendix B: MATLAB Symbolic Math Toolbox

Fig. B.2 Live editor ribbon menu

Prog. B.2 Example of live script code for symbolic math

Create symbolic variables


clear all
syms a % Symbolic variable declara on
a = sym(pi) % Symbolic pi
a=π
sin(a) % Symbolic sin(pi) result
ans = 0
sin(pi) % Numeric sin(pi) result
ans = 1.2246e-16
A = sym('b',[1 10]) % Mul symbolic variable declara on
A=
syms f(x,y) % Symbolic func on declara on
f(x,y)=x^2*y % Define func on
f(x, y) =
f(3,2)
ans = 18
B = sym('C%d%d',[3 3]) % Declare the 3X3 matrix
B=

inv(B) % Square matrix inversion


ans =
Appendix B: MATLAB Symbolic Math Toolbox 665

The symbolic math on MATLAB requires to declare the symbolic variable


before use. The sym creates numbered symbolic variables or symbolic variables.
The syms command is shorthand for the sym syntax. The above code demonstrates
the various situations for symbolic variable declarations. The sinðpÞ computation
with numeric and symbolic p results in the different outcome due to the precision
limitation. We can define the multi-variable function by using the symbolic rep-
resentation.

Prog. B.3 Symbolic computation example

Perform symbolic calculus


clear all
syms x y
f1 = sin(x)^2+cos(y)^2
f1 =
diff(f1) % Differenate
ans =
diff(f1,y) % Differenate over y
ans =
int(f1) % Integral (indefinite)
ans =

int(f1,y) % Integral (indefinite) over y


ans =

int(f1,-2,2) % Integral (definite) over x from -2 to 2


ans =

The above code performs the symbolic computations for simple calculus. The
symbolic math toolbox supports extensive calculus functions such as differentia-
tion, integral, vector operations, series, limits, transformation, and etc.
666 Appendix B: MATLAB Symbolic Math Toolbox

Prog. B.4 Solving the polynomials

Solve equations
clear all
syms x y z
z1 = x^3-6*x^2
z1 =
z2 = 6-11*x
z2 =
solve(z1==z2)
ans =

solve(z1-z2==0)
ans =

z3 = 6*x^2 - 6*x^2*y + x*y^2 - x*y + y^3 - y^2


z3 =
solve(z3==0,y)
ans =

[x,y,z] = solve(z == 4*x, x == y, z == x^2 + y^2)


x=

y=

z=
Appendix B: MATLAB Symbolic Math Toolbox 667

We can solve the multi or single variable polynomials as above. The symbolic math
toolbox provides the equation solvers for polynomials and differential equations.

Prog. B.5 Manipulation of polynomials

Manipulation of polynomials
syms x y
f1 = (x^2- 1)*(x^4 + x^3 + x^2 + x + 1)*(x^4 - x^3 + x^2 - x + 1)
f1 =
expand(f1) % Expand polynomial
ans =
f2 = x^3 + 6*x^2 + 11*x + 6
f2 =
factor(f2) % Factor polynomial
ans =
f3 = x^5 + x^4 + x^3 + x^2 + x
f3 =
horner(f3) % Nested representaon for polynomial
ans =
f4 = 2*x^2 - 3*x + 1
f4 =
aa = subs(f4,1/3) % Substute the x with 1/3
aa =

eval(aa) % Compute the value


ans = 0.2222
f5 = x^2*y + 5*x*sqrt(y)
f5 =
subs(f5,x,3) % Substute the x with 3
ans =

Manipulations for polynomial can be performed as shown above. The toolbox


presents the extensive simplification methods for instance expand, decomposition, fac-
torization, and etc. If we do not need a particular form of expressions, use simplify
function to shorten mathematical expressions. The simplify works universally; otherwise,
we apply the specific manipulations on the equation to derive the specific form.
668 Appendix B: MATLAB Symbolic Math Toolbox

Prog. B.6 FIR filter design by using symbolic math

Symbolic math example


clear all
syms w n
f1 = int(exp(1j*w*n),w,-pi/4,pi/4)/(2*pi)
% Inverse DTFT (1 for -pi/4 ~ pi/4) h[n]
f1 =

f2 = simplify(f1) % Simplify the equaon h[n]


f2 =

f3 = subs(f2,n,(-20:20)+eps);
% Substute n with -20:20 with eps to avoid the 0/0
f4 = eval(f3); % Compute the substuon
f4(21) % Approximated h[0]
ans = 0.2500
temp = limit(f2,n,0) % Verify real h[0]
temp =

stem((-20:20),f4), grid % Stem plot


xlabel('n')
ylabel('h[n]')

The above code performs the inverse DTFT to design the LPF with cutoff
frequency p=4. The corresponding impulse response is displayed as stem plot. Note
that the simplify function makes the equation in simple form. The substitution is
executed to replace the n symbolic variable with range of integer values. In zero
Appendix B: MATLAB Symbolic Math Toolbox 669

replacement condition, the equation represents the NaN (Not-a-Number) outcome.


To avoid the NaN output, the integer values are added with very small value eps
(2.220410−16) which is the distance from 1.0 to the next larger double-precision
number. The zero input result is verified with the limit function which computes the
output for infinitesimal approach to given input value.

Prog. B.7 Plot in symbolic math

Plot the symbolic math


syms x y
f1 = x^3 - 6*x^2 + 11*x - 6
f1 =
fplot(f1,[-5 10]) % 2D plot of symbolic funcon
xlabel('x')
ylabel('y')
tle(texlabel(f1)) % Title the TeX format equaon
grid on

f2 = x^2 + y^2
f2 =
fsurf(f2) % Surface plot of symbolic funcon (auto range)
xlabel('x')
ylabel('y')
tle(texlabel(f2))
grid on
670 Appendix B: MATLAB Symbolic Math Toolbox

Again, there is no given value to the symbolic variables. This condition is also
true for drawing the plot in symbolic math. We only assign the symbolic function to
the designated plot functions to illustrate the plot as shown above.

Prog. B.8 Assumptions on variables

Assumptions
clear all
syms n x
f1 = sin(2*n*pi) % Given funcon1
f1 =
simplify(f1) % Simplify funcon1
ans =
assume(n,'integer') % Assume that n is integer
simplify(f1) % Re-simplify funcon1
ans = 0
f2 = x^4==1 % Given funcon2
f2 =
solve(f2,x) % Solve funcon2
ans =

assume(x,'real') % Assume that x is real


solve(f2,x) % Re-solve funcon2
ans =

assumeAlso(x>0) % Assume again x is real and posive


solve(f2,x) % Re-solve funcon2
ans = 1
assumpons % Show all assumpons
ans =
assume([x n],'clear') % Clear assumpons on x and n
assumpons % Show all assumpons again
ans =
Empty sym: 1-by-0
Appendix B: MATLAB Symbolic Math Toolbox 671

When the symbolic variables are declared, there is no assigned conditions.


Therefore, the variable could be any value and number set. We can apply certain
conditions on the variables to specify the output range. See above code for example.
Index

Symbols Block convolution, 577, 581


( ), 1 Bohman window, 304
[ ], 1 Bounded Input and Bounded Output (BIBO)
2’s complement, 504 stability, 135
,1 Brick wall specification, 276
Butterworth IIR filter, 395
A
Absolute summability, 236 C
Additivity, 51 Canonic form, 559
Aliasing, 65, 489 Cascade connection, 526
Allpass filter, 384, 479 Cauchy residue theorem, 540
Alternation theorem, 344 Causality, 129, 149
App, 596 Causal system, 129
Arguments, 1 Ceiling function, 517
Arithmetic mean, 513 Chebyshev approximation, 344
Auto-completion, 611 Chebyshev polynomial, 343
Autocorrelation, 461 Chebyshev window, 304
Auto-listing, 611 Coefficient quantization, 521
Autoregressive (AR) model, 446 Commutative law, 53
Autoregressive Moving Average (ARMA) Complex and nonlinear-phase equiripple
model, 447 design, 380
Complex Chebyshev approximation, 380
B Compressed, 49
Band Pass Filter (BPF), 186, 192 Conjugate transpose (Hermitian conjugate),
Band Pass Filter (BPF) - FIR type III, 329 354
Band Stop Filter (BSF), 186, 195 Constrained least square design, 376
Bartlett window, 304 Continuous frequency distriution, 83
Base, 505 Convolution sum, 12, 53, 123
BIBO stability, 236 Convolution sum in frequency domain, 138
BIBO stability condition, 135 Convolution sum to multiplication property,
Bilinear transformation, 399, 413, 426, 444, 228
493 Coupled form for SOS structure, 532
Binary number, 504 Cutoff frequency, 274
Bit-reversed order, 572, 577 Cyclic frequency, 274
Blackman window, 304

© Springer Nature Singapore Pte Ltd. 2021 673


K. Kim, Conceptual Digital Signal Processing with MATLAB,
Signals and Communication Technology,
https://doi.org/10.1007/978-981-15-2584-1
674 Index

D FIR filter transformations, 187


Decibel unit, 268 FIR realization structures, 553
Decimation-in-frequency FFT, 572 First kind Chebyshev polynomial, 406, 416,
Decimation-in-time Fast Fourier transform 424
(FFT), 565 Fixed-point designer, 618
Delta function, 35 Fixed-point number, 511, 619
Denormalize, 507 Fixed-point number computation, 511
DFT for non-periodic signal, 98 Flat top weighted window, 304
DFT length, 105 Flipped transposed FIR filter, 554
DFT length for convolution sum, 141 Floating-point number, 505
DFT method - filter design, 150 Floor function, 512
DFT method without truncation, 356 Flow graph, 570, 577
Differentiator, 337 Fourier transform, 32, 36
Dirac delta function, 35 Fourier transform for discrete time signal, 136
Direct form, 554 Four types of FIR filter with zero group delay,
Direct form I, 558 285
Direct form II, 559 Fraction length, 619
Discrete delta function, 87 Fraction number, 512
Discrete Fourier Transform (DFT), 89 Frame-based processing, 579
Discrete frequency x, 59, 273 Frequency, 2
Discrete-Time Fourier Transform (DTFT), 83 Frequency aliasing, 493
Discrimination factor, 438 Frequency discretization, 83
Double precision, 509 Frequency edge specifications, 274
DTFT method - filter design, 142 Frequency inversion, 199
Duality, 141 Frequency resolution, 102
Dual poles, 244 Frequency response, 234
Dual poles with zeros, 252 Frequency sampling design - type I, 353
Frequency sampling design - type II, 360
E Frequency sampling method, 353
Effective frequency, 65 Frequency shift, 192, 199
Effective radian frequency, 62 Frequency shift - DFT, 114
Elliptic filter, 430 Frequency shift - DTFT, 87
Elliptic rational function, 431 Frequency transformation in IIR filter, 477
Energy, 54 Fundamental frequency, 81, 89
Energy ratio between the main lobe and side
lobe, 279 G
Entirety-based processing, 579 Gaussian window, 304
Equivalent filter, 554 Geometric series, 205
Euler formula, 24, 57, 66, 90 Gibbs phenomenon, 276
Even (odd) function, 27 Group delay, 284, 385
Expanded, 49
Expected value, 513 H
Exponent, 505 Halfpower frequency, 274
Hamming window, 304
F Hann (Hanning) window, 304
Filter, 12 High Pass Filter (HPF), 7, 186, 188
Filtering length, 5 High Pass Filter (HPF) - FIR type IV, 334
Filter order, 274 Hilbert transform, 339
Final value theorem, 212
Finite Impulse Response (FIR) filter, 130 I
FIR filter advantages, 275 IEEE standard 754, 509
FIR filter gain, 632 Ill-condition, 523, 556
Index 675

IIR filter method summary, 494 Minimum attenuation, 271


Impulse invariance, 500 Minimum group delay, 390
Impulse response, 52, 228 Minimum phase filter, 443, 479
Impulse train, 96 Minimum phase filter design, 382
Infinite Impulse Response (IIR) filter, 133 Minimum phase system, 389
Initial values, 232 Modified Bartlett-Hann window, 293
Initial value theorem, 212 Most Significant Bit (MSB), 504
Invalid radian frequency, 62 Moving Average (MA) model, 446
Inverse Z-transform, 213 Multiplication, 234
Multiplication for convolution sum, 137
K Multiplication property, 137
Kaiser window, 304, 312 Multi poles with zeros, 258
Kronecker delta function, 46
Kuhn–Tucker conditions, 377 N
Negative frequency, 24
L Normalized frequency, 273
L∞-norm, 539 Not-A-Number (NaN), 507
L1-norm, 537 Nuttall-defined minimum 4-term
L2-norm, 538 Blackman-Harris window, 304
Lagrangian, 377 Nyquist sampling rate, 45, 59
Laplace transform, 399, 411, 423
Leakage factor, 309 O
Least Significant Bit (LSB), 504 Object-oriented programming, 604
Least squared error frequency domain design— Orthogonality, 32, 71, 91
discrete frequency sampling DFT, 364 Overlap-add method, 584
Least squared error frequency domain design— Overlap-save method, 586
integral squared error approximation
criterion, 372 P
L’Hospital’s rule, 35 Parallel connection, 527
Limit cycle, 563 Parametric methods, 446
Linear and Time Invariant (LTI), 52, 124 Parks-McClellan algorithm, 380
Linear and time invariant system, 14 Parseval’s theorem, 143, 177, 236, 278, 319,
Linearity, 51 322, 327, 331, 334, 337, 372, 376
Linearity - DFT, 113 Parseval’s theorem - DFT, 115
Linearity - DTFT, 87 Parseval’s theorem - DTFT, 88
Linear phase, 275, 284 Partial fraction, 216, 527
Linear prediction filter, 461 Partial fraction expansion, 540
Low Pass Filter (LPF), 142 Parzen window, 304
LPF design method selection, 185 Passband frequency, 274
LPF design procedure, 187 Passband magnitude, 271
Passband ripple, 269
M Peak-to-peak ripple, 396
Magnitude, 268 Period, 72
Magnitude inversion, 188, 197 Periodicity in spectrum, 67
Main lobe, 279 Phase delay, 395
Main lobe width, 291, 305 Phasor, 28
Mantissa, 505 Pole, 220
MATLAB coder, 638 Pole-zero plot, 221
Maxflat filter, 459 Polynomial long division, 214
Maximum deviation, 271 Positive (negative) frequency, 67
Minimum 4-term Blackman-Harris window, Power, 56
293 Prefiltering, 473
676 Index

Pre-scaling, 592 Sensitivity, 523


Primitive low pass filter, 4 Shifting, 48
Probability density function, 513 Shift pattern for DFT, 111
Prony, 461, 473 Shift property - DFT, 114
Pseudoinverse, 366 Signal periodicity, 83
Signal power, 513
Q Signal-to-Noise Ratio (SNR), 514
QR solver, 471 Signal types and pole locations, 225
Quantization, 511, 548 Sign bit, 504
Quantization effect, 587 Signed fraction number, 511
Quantization error sources, 548 Signed integer, 504
Significand, 505
R Simulink, 595
Radian frequency, 22, 62 Sinc function, 37
Ramp function, 47 Single pole, 244
Random process, 513 Single pole with zero, 247
Random variable, 513 Single precision, 509
Real sequence - DFT, 114 Single quantization noise, 551
Real signal property, 210 Single Sideband (SSB) output, 339
Real-time signal, 1 Speedup, 642
Rectangular window, 291 Stability, 275
Recursive filter, 132 Statistical signal processing, 447
Reflecting, 49 Steiglitz-McBride algorithm, 468
Region of Convergence (ROC), 205 Stopband, 398
Relatioinship between DTFT and DFT, 94 Stopband attenuation, 271
Relatioinship between Z-transform, DTFT, and Stopband frequency, 274
DFT, 218 Substitution method, 134
Relative peak side lobe amplitude, 291 Symmetricity for impulse response, 284
Relative sidelobe attenuation, 309 System object, 604
Remes exchange algorithm, 345
Remes exchange algorithm (Parks and T
McClellan), 342 Taylor window, 304
Restrictions for linear phased FIR filters, 288, Tense, 1
291 Three transformations, 263
Reversal operations, 554 Time delay - Z-transform, 231
Rounding, 512 Time invariance, 51
Rule of thumb for pairing poles and zeros, 527 Time reversal - DFT, 116
Time reversal - DTFT, 88
S Time shift, 25
Sample-based processing, 579 Time shift - DFT, 113
Sampling, 40 Time shift - DTFT, 87
Sampling frequency, 40 Toolbox, 595
Sampling period, 41 Transfer function, 230, 236
Saturation addition, 518 Transformation procedure from LPF, 199
Saturation arithmetic, 518 Transform capability, 230
Scalability, 51 Transposed direct, 554
Scaling, 48 Transposed direct form II, 559
Second moment, 513 Transposition, 554
Second-Order Section (SOS), 526 Transversal, 553
Selective factor, 438 Transversal structure, 553
Index 677

Triangular window, 304 Variance, 513


Truncated impulse response from DTFT, 373 Visual spectral resolution, 108
Truncated LPF, 182
Truncation, 512 W
Tukey (tapered cosine) window, 293 Weight values, 4
Type I, 285 White noise, 461
Type I Chebyshev filter, 406 Wilkinson’s polynomial, 521
Type II, 285 Window Designer from MATLAB, 309
Type II Chebyshev filter, 416 Windowing methods, 291
Type II FIR filter, 316 Window shape, 8
Type II HPF, 323 Word length, 619
Type III, 285
Type III and type IV FIR filter, 334 Y
Type III FIR filter, 328 Yule-walker method - approximated, 447
Type IV, 285
Type IV FIR filter, 332 Z
Z, 204
U Z domain transformation, 477
Unbiased estimation, 514 Zero, 221
Underflow, 520 Zero group delay FIR filter, 285
Unit of frequency, 21 Zero padding, 102, 108
Unit-step function, 47 Zero reflection, 389
Untrimmed LPF, 182 Z-transform, 203
Z-transform properties, 208
V Z-transforms for fundamentals, 206
Vandermonde matrix, 354

You might also like