978 981 15 2584 1 PDF
978 981 15 2584 1 PDF
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].
123
Keonwook Kim
Division of Electronics
and Electrical Engineering
Dongguk University
Seoul, Korea (Republic of)
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
xi
xii Contents
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.
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
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.
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
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
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
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
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
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 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
The second and third proper outputs are shown below with sliding input
sequence.
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
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.
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.
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
[].
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
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
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.
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
+ +
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
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]
Sliding
& 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.
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
X
N 1
y½n ¼ x½n k h½k
k¼0
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.
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.
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.
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.
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.
Example 2.1
Show the frequency components of r cosðXtÞ and r sinðXtÞ by Euler formula.
Solution
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.
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])
Example 2.2
What is the meaning of below equation?
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
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.
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.
Example 2.3
Find the even and odd function of xðtÞ ¼ A cosðXt þ hÞ.
Solution
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.
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Þ ¼ 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.
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
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
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
2p
T¼
ð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
figure,
subplot(211), plot(t,x,'Color','k'), grid
hold on
stem(t,x,'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
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
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
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 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
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
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
0þ
Z1
1 1
¼ X ð0Þ þ 2X ðXÞ cosðXtÞdX
2p 2p
0þ
( )
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
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.
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
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
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.
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
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.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).
Solution
∎
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
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
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.
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.
Example 2.7
Draw the x½2ðn 1Þ of given x[n].
Solution
The combination is below.
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
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
∎
2.3 Signal Representation 51
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.
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
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].
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
∎
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
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
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
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.
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).
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
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.
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).
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.
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
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)
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.
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 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
∎
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.
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.
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
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
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
> 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
13. From the given impulse response h[n] as below, determine the LTI system
output of shown input x[n].
x½n ¼ u½n
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.
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.
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
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Þ
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.
π/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
ð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
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
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
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.
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Þ
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
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.
Fig. 3.7 One example of discrete time signal from discrete spectral distribution (x0 is 2p=64)
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].
x ½ n ¼ x 1 ½ n þ x 2 ½ n
Solution
Least common multiple of periods presents the new period N.
2p
x¼ k for 0 k 18 and k 2 Z
36
■
P
1
X ðejx Þ ¼ x½nejxn ð3:12Þ
n¼1
Rp
x½n ¼ 2p
1
X ðejx Þejxn dx ð3:13Þ
p
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
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.
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
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
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
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
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
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
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
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
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.
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
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
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
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
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
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
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
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
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
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
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 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
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
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
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
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
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.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
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.
P
N1
fax½n þ by½ngej N kn ¼ aX ½k þ bY ½k
2p
Z ½k ¼ ð3:56Þ
n¼0
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
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
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.
Example 3.9
Find the number property as complex or real number for following signal’s DFT.
N = 8.
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
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
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
X
N 1
1XN 1
Ex ¼ jx½nj2 ¼ jX ½kj2
n¼0
N k¼0
X
3
Ex ¼ jx½nj2 ¼ 1 þ 0 þ 1 þ 0 ¼ 2
n¼0
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
1X 3
1
Ex ¼ jX ½kj2 ¼ ð4 þ 4Þ ¼ 2
4 k¼0 4
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
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
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
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
2p X 1
Sð X Þ ¼ dðX kXs Þ
Ts k¼1
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
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
... ...
t
-3Ts -2Ts -Ts 0 Ts 2Ts 3Ts
S( )
Xc( )
- c c
Xs( )
X(ejw)
w
3.5 Problems 121
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]
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
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.
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
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
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.
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
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Þ
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].
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
■
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).
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
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).
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.
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
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
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
P
n
y½n ¼ b0 1 x½k
ank ð4:17Þ
k¼0
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
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.
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.
0.5
0
0 2 4 6 8 10 12 14 16 18 20
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
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
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.
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
n-2
n-1
n
n+1
n+2
IIR filter length
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
P
N1
lim jh½kjM\1 ð4:24Þ
N!1 k¼0
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.
Solution
From the Example 4.2, we derived the below impulse responses.
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.
■
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
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
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
! H ðejx Þ
DTFT Analysis
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
! H ½k
DFT Analysis
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
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
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).
! 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
! 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 þ 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
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
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
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.
2p
xc ¼ fc
fs
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
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
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 ½%
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
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
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'};
Fig. 4.11 41-length impulse response for given LPF and corresponding frequency response
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.
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
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
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
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.
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
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
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
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]')
2
y[n]
-2
-4
400 420 440 460 480 500 520 540 560 580 600
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
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]|')
0.3
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
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)
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
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
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
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
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
¼ 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
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
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
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
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.
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 ( )
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 ( )
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
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
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
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 ( )
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 ( )
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.
... 1
...
ω
1
Subtract = ... ...
ω
... 1
...
ω
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 ( )
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 ( )
■
4.5 Simple Filter Design 199
Magnitude
Inversion
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
Parallel connection
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
jy½nj 4xmax 8n
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.
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.
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.
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.
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.
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.
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.
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).
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
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
Anti-causal signal:
Non-causal signal:
Finite-support signal:
X
1 X
N2
X f ð zÞ ¼ xf ½nzn ¼ xf ½nzn
n¼1 n¼N1
Example 5.1
Find the Z-transform of following signals
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.
DFT
DTFT
1
real
5.1 Definition and Usage 209
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 ¼
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.
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
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.
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
Proof We assume that the signal asymptotically converges to the constant value
x½1 as below.
w[n]
0
The (z − 1) with W(z) cannot be cancelled out; hence, the last term goes to zero.
Finally,
∎
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).
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.
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
approaches are possible to solve the partial fraction method that can be found on the
various algebra books [2] and webs [3].
Also, the function can be handled by the positive power of the polynomial as
below.
Therefore, the final decomposed form of the rational polynomial is given below.
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
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
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.
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.
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).
The given example z function shows the following zeros and poles.
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.
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)
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
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.
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:
Causal signal:
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
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
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
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
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.
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.
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
Example 5.5
Draw the pole-zero plot and time domain plot of following signals.
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).
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
Z-transform is below.
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
The DFT for the finite length geometric series can be shown as below.
( )
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.
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
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].
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
With the initial values on the output, the equation can be depicted as Eq. (5.61).
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 .
The discrete frequency response can be obtained by the DFT as exchanging the
z with ej2pk=N .
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.
Example 5.6
Derive the impulse response of following IIR filters with and without initial values.
The equations are shown previously in Chap. 4.
Solution
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 Þ
Without the initial values, the last two terms are only survived as below.
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.
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
Generally, the impulse response is the output of the impulse input with zero
initial value which can be specified as zero state condition.
The zero input response is the output of the zero input with arbitrary initial value on y
[−1].
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.
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));
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.
∎
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
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;
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:
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
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
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
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
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
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
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
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
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
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
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
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
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
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.
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
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
x ½ n ¼ n2 u½ n
264 5 Z-Transform
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 ¼
x ½ n 2 R
If the new x[n] is below, check the real value condition again.
5. From the given pole-zero plots, derive time domain signals and analyze the
stability.
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.
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.
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
1+Rp
1 0 dB Ap (dB)
1-Rp
Magnitude
0.707 -3 dB
dB
0.5 -6 dB
0 π ω
ωp
ω3dB
ω6dB
ωst
Halfpower frequency ( h) Cutoff frequency ( c)
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
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.
Example 6.1
Compute the absolute magnitude of following decibel specifications.
– Passband magnitude: 0 dB
– Passband ripple: 1 dB
– Stopband attenuation: 40 dB
Solution
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
-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
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)
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
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 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
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
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.
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.
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:
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.
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
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.
8
ratio[n c ]
0
20 30 40 50 60 70 80 90 100
nc
280 6 Filter Design
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
)
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
Rp
h½n ¼ 2p
1
Aðeju Þejuðnnd ðuÞÞ du where Aðeju Þ 2 R ð6:20Þ
p
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)
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
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
Odd symmetric
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)
Type III: Odd symmetric function with even filter order (odd filter length)
þ hIII ½3z3 1 þ z2 þ z4 þ
Type IV: Odd symmetric function with odd filter order (even filter length)
þ hIV ½2z2 1 þ z þ z2 þ z3 þ z4 þ
ð6:41Þ
6.2 FIR Filters 291
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
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
Hamming
Triangular
(continued)
297
Table 6.11 (continued)
298
Modified Bartlett-Hann
Bohman
Chebyshev
(continued)
299
Table 6.11 (continued)
300
Parzen
(continued)
301
Table 6.11 (continued)
302
Taylor n ¼ 4 r ¼ 30
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
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
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 ( )
Fig. 6.11 Final FIR filter with N = 32 & hanning window for Table 6.13 specification
308 6 Filter Design
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.
∎
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.
Fig. 6.13 FIR filter (N = 32 & hanning window) for Table 6.13 specification with 3 dB main
lobe
6.2 FIR Filters 311
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
Find the frequency locations around the cutoff frequency to obtain the Dx .
Dx ¼ xst xp
st 7:95
N ¼ A2:285Dx ð6:44Þ
6.2 FIR Filters 313
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
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).
Ast 7:95
N¼
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
Z
3p=8
1 sinð3pn=8Þ
hIdeal LPF ½n ¼ 1ejxn dx ¼
2p pn
3p=8
Fig. 6.14 FIR filter with N = 18 & Kaiser window for Table 6.15 specification
6.2 FIR Filters 315
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
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
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
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
4p p
N
15
N þ1 4
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
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
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.
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
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
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
∎
Both type filters are illustrated in 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.
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
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
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
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.
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
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
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
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
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
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
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
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ÞÞ
P
N=2
H ðejx Þ ¼ c½n cosn ðxÞ ð6:63Þ
n¼0
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.
ω
π
Fig. 6.23 The optimal filter frequency response with maximal error locations for N = 32
344 6 Filter Design
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
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
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 Þ
The computed c[n] with Eq. (6.63) generates the first trial frequency response.
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.
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.
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
H ejx ¼ 0:1328 þ 0:8699 cosðxÞ þ 0:5 cos2 ðxÞ 0:3699 cos3 ðxÞ
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.
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
AP ¼ 40 log10 ð1 þ Rp Þ
H ½k ¼ H ½k
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
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
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
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');
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
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 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
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
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
X
L=21
1
1
H ejx ¼ 2 ht n þ cos x n þ
n¼0
2 2
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
AP ¼ 40 log10 ð1 þ Rp Þ
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 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Þ
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
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Þ
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 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
2p 2p
H ½k $ H k ¼H k
M 16
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
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
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
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
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
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.
The passband ripple Ap can be calculated from the maximum deviation Rp as below.
AP ¼ 40 log10 ð1 þ Rp Þ
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.
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
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
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
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
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).
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
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
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
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
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
p 1p 5p
xlst ¼ ¼
2 24 8
p 1p 3p
xlp ¼ þ ¼
2 24 8
p 1p p
xrp ¼ ¼
4 24 8
p 1 p 3p
xrst ¼ þ ¼
4 24 8
6.2 FIR Filters 381
LPF
1
ω
-π/2 0 π/4
Fig. 6.36 Frequency response of complex and nonlinear-phase equiripple design method LPF
Type I
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
...
Fig. 6.37 Frequency response of complex and nonlinear-phase equiripple design method HPF
Type I
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
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
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 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.
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
Fig. 6.38 Pole zero plot and frequency response in magnitude for given transfer function
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).
The group delay of given transfer function is shown in Fig. 6.39. The distri-
bution represents the non-linear and non-constant shape.
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.
loge H ðe Þ ¼ ln H ðe Þ
jx jx
Based on the above derivation, let’s figure out the group delay of allpass filter.
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Þ
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
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.
Solution
The corresponding Z transform is below.
H0 ðzÞ ¼ 1 3z4
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
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)
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
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.
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
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.
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.
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).
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.
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.
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:
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
jH ðjXÞj2 ¼ 1 2N
1þ X ð6:139Þ
Xp
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
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).
where s ¼ r þ jX
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
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
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 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.
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')
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
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
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
G G
jH ðsÞj2 ¼ H ðsÞH ðsÞ ¼ 2N ¼ 6 where s ¼ r þ jX
1þ s
jXp 1þ s
j6627:4
291091517618:824
H ðsÞ ¼
j2p
s 6627:4e 3 ðs 6627:4ejp Þ s 6627:4ej 3
4p
1z1
jX¼2fs
1 þ z1
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.
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
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.
∎
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).
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.
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
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
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
where s ¼ r þ jX
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
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.
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.
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
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
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
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.
∎
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
Fig. 6.55 Frequency response of designed Type I Chebyshev filter for Table 6.28
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
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
To control the ripple in the stopband, Eq. (6.172) is modified as Eq. (6.173).
jH ðjXÞj2 ¼ 1
e2 ð6:173Þ
1þ
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
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
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
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
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
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
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
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.
1
0.8
0.6
0.4
0.2
0
-0.2
-1 -0.5 0 0.5 1
6.3 IIR Filters 425
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');
forfs
jXst or s jXst g
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
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.
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
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 .
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
p
Xp ¼ 2fs tan ¼ 6627:4 rad=s
8
p
Xst ¼ 2fs tan ¼ 16000rad=s
4
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
jXst
zk ¼ p
; k ¼ 1; 2; . . .; N
cos ð2k 1Þ 2N
zk ¼ j22627:41; j22627:41
Follow Eq. (6.186) to build the filter equation in s domain based on the pLi , zk ,
and G.
0:09343s2 þ 47833766:89
H ðsÞ ¼
s2 þ 9312:8s þ 47833011:4
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
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
e : ripple factor
where
n : selectivity factor ðn
1Þ
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 Þ
12
N=1
2
10 3
4
-2
0 0.2 0.4 0.6 0.8 1 1.2
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
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
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 Þ
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')
1 0
0.9
-20
=1.5
0.8
=1.5
0.7 -40
)| =1
0.6 -60
)| =1
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
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
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
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Þ:
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
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
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.
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
Based on the left s plane poles and zeros, the transfer function is assembled as
below. Note that G is the zero-input gain.
Convert back to jX by replacing with s as below. The filter with rational function
is completed in the linear frequency domain jX .
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
Xst 16000 Xp
n¼ ¼ ¼ 2:4142 *n ¼1
Xp 6627:4 Xst
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.
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
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.
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 ¼ 0:04701
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
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
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
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 þ a1 y ½ n 1 þ þ aN y ½ n N
ð6:214Þ
¼ b0 x½n þ þ bM1 x½n ðM 1Þ þ bM x½n M
By placing the impulse signal into the input x[n], we can find the impulse
response as below
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
The a1 ; a2 ; and b0 are required to be estimated. The given impulse signal delivers
the impulse response as below.
...
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
ð6:222Þ
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
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
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
Once we obtain the a1 and a2, the frequency response helps to find b0 value as
below.
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Þ
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
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
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
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.
By placing the delta signal for input, impulse response can be obtained as below.
2
1 Response Response
Passband 0 Passband
)|
-2 -3dB
j
0.5
|H(e
-4
-6
0
0 500 1000 1500 2000 2500 3000 3500 4000 -8
-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
H ðzÞ ¼ 11:2124z
0:2786
1 þ 0:49z2
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
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.
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
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
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])
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.
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 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).
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
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 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 Þ
ð6:242Þ
½ ð L þ 1Þ 1 ¼ ½ ð L þ 1Þ ð N þ 1Þ ½ ð N þ 1Þ 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Þ
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.
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
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
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
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
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
-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
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]
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Þ
e
e½n ¼ hd ½n h½n $ E ðzÞ ¼ BAððzzÞÞ B ðzÞ
Z
ð6:247Þ
eA ðzÞ
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]
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
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
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Þ
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.
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
Organize the coefficients for denominator and numerator as below. Note that the
a10 is always one.
6.3 IIR Filters 475
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
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
-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
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.
∎
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.
-π π -π π
ωorg To BPF
ωtar1 ωtar2
-π π -π π
ωorg To BSF
ωtar1 ωtar2
-π π -π π
Fig. 6.84 Spectral distribution and feature frequencies of frequency transformation example
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).
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.
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.
p 3p
where xorg ¼ ; xtar ¼ ; and a ¼ 0
4 4
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.
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)
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)
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 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.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
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')
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
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 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
Fig. 6.90 Pole zero plot of BSF from transformation (left) and reflection (right)
486 6 Filter Design
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)
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
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
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.
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
P
M
hc ð t Þ ¼ G k es k t ð6:269Þ
k¼1
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
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.
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
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
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
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
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
(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
8. Design the following FIR filter by using the Remes exchange algorithm.
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.
(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.
14. Design the following IIR filter by using Butterworth method and bilinear
transformation.
15. Design the following IIR filter by using Type I Chebyshev method and bilinear
transformation.
498 6 Filter Design
16. Design the following IIR filter by using Type II Chebyshev method and bilinear
transformation.
17. Design the following IIR filter by using elliptic method and bilinear transfor-
mation.
(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.
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.
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.
22. The Elliptic method presented the following ARMA IIR LPF to meet 1000 Hz
halfpower frequency based on the 8000 Hz sampling frequency.
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
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
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.
– 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)
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
-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 j1:f j 1:8750
ð7:9Þ
7 e 7 8
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
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Þ
Following is the range of significand and exponent based on the above configuration.
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
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
(
ð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.
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
D ¼ 2B ð7:19Þ
^x ¼ QB ðxÞwhere x 2 R ð7:20Þ
P
B
^x ¼ Xm b0 þ bk 2 k
where Xm ¼ maxjx½nj ð7:21Þ
k¼1 n
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Þ
e ¼ ^x x ¼ QB ðxÞ x ð7:27Þ
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
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
P
N1
Pe ¼ N1 e2 ½k E½E 2 ð7:32Þ
k¼0
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.
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
1/ QB
f E(e)
- QB /2 0 - QB /2
e
R DQB R DQB
lE ¼ 2
DQB efE ðeÞde ¼ D
1
QB
2
DQB ede ¼ 0
2 2
Let the maximum signal magnitude is N times signal standard deviation rsignal .below.
Xm ¼ Nrsignal
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. ∎
– Fundamental blocks
The filter realization can be decomposed into three fundamental blocks in time
domain. Below is the conventional filter equation.
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
The x1 and x2 are the random binary fraction number with possible range as
below.
2 x1 þ x2 2 2B þ 1 ð7:39Þ
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.
The unified bit format for input and output causes overflow problem in addition
operation. See the below example.
518 7 Implementation Matters
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 j x1 x2 j 1 ð7:45Þ
Except zero, the minimum magnitude of the individual and product is below.
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.
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
P
2B
x1 x2 ¼ b0 þ bk 2k ð7:49Þ
k¼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
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
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
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 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Þ
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Þ
@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.
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
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.
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
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.
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.
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);
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
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.
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Þ
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
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 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
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
Incorrect
7.2 Filter Implementation Components 539
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
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
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.
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 ½nG1=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]
Overall
1.25
0.75
|H(e j )|
0.50
0.25
0
0 /4 /2 3 /4
Radian frequency ( )
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
^ ^ ^ ^
¼ 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
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.
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.
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
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
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
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
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
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.
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.
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.
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.
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.
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.
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.
The single quantization step is equivalent to the single noise source as below.
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
¼ BðzÞ
AðzÞ
Solution
The corresponding SOS for the given LPF is below. Note that the G is the global
gain.
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 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.
∎
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.
× × × × × ×
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
x[n]
× × × × ... × ×
– 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.
@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.
^ 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 ½njejxn ð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.
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.
∎
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.
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.
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.
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
× × × × ... × ×
b0 b1 b2 b3 ... bN-1 bN
+ y[n]
-
a1 a2 a3 a4 ... a M-1 aM
× × × × ... × ×
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
...
...
...
...
...
...
...
...
...
...
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)
a1 a2 a3 aM-1 aM
x[n]
b0 b1 b2 b3 bN-1 bN
y[n]
Fig. 7.38 Block diagram for IIR filter direct form II realization by computer language. Assume
that M is equal to N
x[n]
× × × × ... × ×
- - - - -
× × × × ... ×
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
+
y[n]
x[n] b01
+
b02
+ ... b0L
+
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.
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Þ
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Þ
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Þ
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
XÞ
ðN=21
2p
F ½k ¼ f ½qejN=2kq
q¼0
ð7:142Þ
XÞ
ðN=41
2p
jN=4 kr 2p
jN=2 k
XÞ
ðN=41
2p
jN=4 kr
¼ f ½2r e þe f ½2r þ 1e
r¼0 r¼0
XÞ
ðN=21
2p
G ½k ¼ g½qejN=2kq
q¼0
ð7:143Þ
XÞ
ðN=41
2p
jN=4 kr 2p
jN=2 k
XÞ
ð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.
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 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Þ
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Þ
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
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
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
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
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
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
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.
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
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
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
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Þ
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Þ
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
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Þ
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.
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
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
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.
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
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
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 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
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 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.
-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 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Þ
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.
P
N1
2p
jX ½k j jx½njej 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.
The increased DFT length N produces the following results for signal and noise
power.
(
x½
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.
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.
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.
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.
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.
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 ( )
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
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.
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)
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
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
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.
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
-10
-20
-30
-40
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)
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)
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)
-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
Not OK
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
ans =
{'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.
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.
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.
>>
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 =
>>
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
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
>> 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
-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.
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
-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)
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
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
word length
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.
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
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.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
-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
Fig. 8.22 Observe the difference between the floating-point and fixed-point configurations for
input
626 8 Filters with MATLAB
-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
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
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.
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
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
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.
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
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.
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.
100
Integer Input
50 Scaled Integer Output
-50
-100
-150
-200
-250
-300
-350
3900 3920 3940 3960 3980 4000
n
100
Integer Input
50 Scaled 12-bit Integer Output
-50
-100
-150
-200
-250
-300
-350
3900 3920 3940 3960 3980 4000
n
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
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)
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);
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
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
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.
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
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.
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.
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.
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)
...
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.
The speedup from the code generation and compiling can be computed by
following equation.
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.
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.
reader = dsp.AudioFileReader('handel.ogg','SamplesPerFrame',FrameSize);
% Audio file reader object
P = audioDeviceWriter(reader.SampleRate); % Audio device writer object
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
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.
>> 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
>> 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
>> 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.
>> 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.
>> 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.
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
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.
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
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
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.
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
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
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
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.
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
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
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.
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
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
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
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 =
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.
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 =
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 =
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
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.
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 =