DSP Programs Using Scilab PDF
DSP Programs Using Scilab PDF
Processing
-90
-100
db
-->sl=syslin('c',a,b,c,d);
Magnitude
With
-110
-120
-->bode(sl,.1,100);
-130
-140
-150
-160 -->s=poly(0,'s'); Hz
Scilab
-1 0 1 2 3
10 10 10 10 10
degrees Phase
0
-->S1=s+2*%pi*(15+100*%i);
-90
-180
-->S2=s+2*%pi*(15-100*%i);
Hz
-1 0 1 2 3
10 10 10 10 10
-->h1=1/real(S1*S2)
h1 =
13.44
1
12.12
-------------------------
10.79
2
9.47
403666.82 + 188.49556s + s
8.14
6.81
5.49
-->h1=syslin('c',h1);
4.16
2.84
1.51
-->bode(h1,10,1000,.01);
0.19
4.64 7.44 10.23 13.02 15.82 18.61 21.41 24.20 27.00 29.79 32.58
Scilab Group
-->h2=ss2tf(sl);
-->bode(h1*h2,.1,1000,.01);
SIGNAL
PROCESSING
WITH
SCILAB
Scilab Group
INRIA Meta2 Project/ENPC Cergrene
This document is an updated version of a primary work by Carey Bunks, Francois Delebecque, Georges
Le Vey and Serge Steer
Contents
2 Representation of Signals 21
2.1 Frequency Response . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
2.1.1 Bode Plots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
2.1.2 Phase and Group Delay . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
2.1.3 Appendix: Scilab Code Used to Generate Examples . . . . . . . . . . . . . . . . . 35
2.2 Sampling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
2.3 Decimation and Interpolation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
2.3.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
2.3.2 Interpolation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
2.3.3 Decimation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
2.3.4 Interpolation and Decimation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
2.3.5 Examples using intdec . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
2.4 The DFT and the FFT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
2.4.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
2.4.2 Examples Using the fft Primitive . . . . . . . . . . . . . . . . . . . . . . . . . . 51
2.5 Convolution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
2.5.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
2.5.2 Use of the convol function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
2.6 The Chirp Z-Transform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
2.6.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
2.6.2 Calculating the CZT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
2.6.3 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
iii
3 FIR Filters 63
3.1 Windowing Techniques . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
3.1.1 Filter Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
3.1.2 Choice of Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
3.1.3 How to use wfir . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
3.1.4 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
3.2 Frequency Sampling Technique . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
3.3 Optimal filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
3.3.1 Minimax Approximation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
3.3.2 The Remez Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
3.3.3 Function remezb . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
3.3.4 Examples Using the function remezb . . . . . . . . . . . . . . . . . . . . . . . . . 78
3.3.5 Scilab function eqfir . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
4 IIR Filters 85
4.1 Analog filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
4.1.1 Butterworth Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
4.1.2 Chebyshev filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
4.1.3 Elliptic filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
4.2 Design of IIR Filters From Analog Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
4.3 Approximation of Analog Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
4.3.1 Approximation of the Derivative . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
4.3.2 Approximation of the Integral . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
4.4 Design of Low Pass Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
4.5 Transforming Low Pass Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
4.6 How to Use the Function iir . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
4.7 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
4.8 Another Implementation of Digital IIR Filters . . . . . . . . . . . . . . . . . . . . . . . . . 115
4.8.1 The eqiir function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
4.8.2 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
Bibliography 191
Chapter 1
1.1 Introduction
The purpose of this document is to illustrate the use of the Scilab software package in a signal processing
context. We have gathered a collection of signal processing algorithms which have been implemented as
Scilab functions.
This manual is in part a pedagogical tool concerning the study of signal processing and in part a practical
guide to using the signal processing tools available in Scilab. For those who are already well versed in the
study of signal processing the tutorial parts of the manual will be of less interest.
For each signal processing tool available in the signal processing toolbox there is a tutorial section in
the manual explaining the methodology behind the technique. This section is followed by a section which
describes the use of a function designed to accomplish the signal processing described in the preceding sec-
tions. At this point the reader is encouraged to launch a Scilab session and to consult the on-line help related
to the function in order to get the precise and complete description (syntax, description of its functionality,
examples and related functions). This section is in turn followed by an examples section demonstrating the
use of the function. In general, the example section illustrates more clearly than the syntax section how to
use the different modes of the function.
In this manual the typewriter-face font is used to indicate either a function name or an example
dialogue which occurs in Scilab.
Each signal processing subject is illustrated by examples and figures which were demonstrated using
Scilab. To further assist the user, there exists for each example and figure an executable file which recreates
the example or figure. To execute an example or figure one uses the following Scilab command
-->exec(file.name)
which causes Scilab to execute all the Scilab commands contained in the file called file.name.
To know what signal processing tools are available in Scilab one would type
-->disp(siglib)
which produces a list of all the signal processing functions available in the signal processing library.
1.2 Signals
For signal processing the first point to know is how to load and save signals or only small portions of lengthy
signals that are to be used or are to be generated by Scilab. Finally, the generation of synthetic (random)
signals is an important tool in the development in implementation of signal processing tools. This section
addresses all of these topics.
1
2 CHAPTER 1. DESCRIPTION OF THE BASIC TOOLS
-->save(file_name[,var_list])
where file name is the file to be written to and var list is the list of variables to be written. The
inverse to the operation save is accomplished by the primitive load which has the syntax
-->load(file_name[,var_list])
-->write(file,x[,form])
The second argument, x, is a matrix of values which are to be written to the file.
The syntax for read is
-->x=read(file,m,n[,form])
The arguments m and n are the row and column dimensions of the resulting data matrix x. and form is
again the format specification statement.
In order to illustrate the use of the on-line help for reading this manual we give the result of the Scilab
command
-->help read
NAME
read - matrices read
CALLING SEQUENCE
[x]=read(file-name,m,n,[format])
[x]=read(file-name,m,n,k,format)
PARAMETERS
k : integer
DESCRIPTION
reads row after row the mxn matrix x (n=1 for character chain) in the file
file-name (string or integer).
The type of the result will depend on the specified form. If form is
numeric (d,e,f,g) the matrix will be a scalar matrix and if form contains
the character a the matrix will be a matrix of character strings.
A direct access file can be used if using the parameter k which is is the
vector of record numbers to be read (one record per row), thus m must be
m=prod(size(k)).
EXAMPLE
A=rand(3,5); write(foo,A);
B=read(foo,3,5)
B=read(foo,-1,5)
read(%io(1),1,1,(a)) // waits for users input
SEE ALSO
file, readb, write, %io, x_dialog
y = 1y=2 x + my (1.1)
1=2
where y is the matrix square root of y . A matrix square root can be obtained using the chol primitive
as follows
-->m=[-2;1;10];
4 CHAPTER 1. DESCRIPTION OF THE BASIC TOOLS
-->L2=chol(L);
-->rand(seed);
-->rand(normal);
-->x=rand(3,1)
x =
! - 0.7616491 !
! 1.4739762 !
! 0.8529775 !
-->y=L2*x+m
y =
! - 3.3192149 !
! 2.0234185 !
! 12.161519 !
taking note that it is the transpose of the matrix obtained from chol that is used for the square root of
the desired covariance matrix. Sequences of random numbers following a specific normally distributed
probability law can also be obtained by filtering. That is, a white standard normal sequence of random
numbers is passed through a linear filter to obtain a normal sequence with a specific spectrum. For a filter
which has a discrete Fourier transform H (w) the resulting filtered sequence will have a spectrum S (w) =
jH (w)j2 . More on filtering is discussed in Section 1.8.
2
2 - 3x + x
--> roots(q1)
ans =
! 1. !
! 2. !
1 + 2x
--> roots(q2)
ans =
- 0.5
! 1. 2. !
! 3. 4. !
--> q3=poly(a,x)
q3 =
2
- 2 - 5x + x
--> roots(q3)
ans =
! - 0.3722813 !
! 5.3722813 !
Notice that the first polynomial q1 uses the roots default and, consequently, the polynomial takes
the form (s 1)(s 2) = 2 3s + s2 . The second polynomial q2 is defined by its coefficients given
by the elements of the vector. Finally, the third polynomial q3 calculates the characteristic polynomial of
the matrix a which is by definition det(sI a). Here the calculation of the roots primitive yields the
eigenvalues of the matrix a.
Scilab can manipulate polynomials in the same manner as other mathematical objects such as scalars,
6 CHAPTER 1. DESCRIPTION OF THE BASIC TOOLS
vectors, and matrices. That is, polynomials can be added, subtracted, multiplied, and divided by other
polynomials. The following Scilab session illustrates operations between polynomials
--> x=poly(0,x)
x =
--> q1=3*x+1
q1 =
1 + 3x
--> q2=x**2-2*x+4
q2 =
2
4 - 2x + x
--> q2+q1
ans =
2
5 + x + x
--> q2-q1
ans =
2
3 - 5x + x
--> q2*q1
ans =
2 3
4 + 10x - 5x + 3x
--> q2/q1
ans =
2
4 - 2x + x
----------
1 + 3x
--> q2./q1
1.3. POLYNOMIALS AND SYSTEM TRANSFER FUNCTIONS 7
ans =
2
4 - 2x + x
----------
1 + 3x
Notice that in the above session we started by defining a basic polynomial element x (which should not
be confused with the character string x which represents the formal variable of the polynomial). An-
other point which is very important in what is to follow is that division of polynomials creates a rational
polynomial which is represented by a list (see help list and help type in Scilab).
A rational is represented by a list containing four elements. The first element takes the value r
indicating that this list represents a rational polynomial. The second and third elements of the list are the
numerator and denominator polynomials, respectively, of the rational. The final element of the list is either
[] or a character string (More on this subject is addressed later in this chapter (see Section 1.3.2). The
following dialogue illustrates the elements of a list representing a rational polynomial.
2
2 - 3x + x
------------------
2 3
- 60 + 47x - 12x + x
--> p(1)
ans =
!r num den dt !
--> p(2)
ans =
2
2 - 3x + x
--> p(3)
ans =
2 3
- 60 + 47x - 12x + x
--> p(4)
8 CHAPTER 1. DESCRIPTION OF THE BASIC TOOLS
ans =
[]
--> h=[1:5,4:-1:1];
--> hz=poly(h,z,c);
--> f=(0:.1:1);
--> hf=freq(hz,1,exp(%pi*%i*f));
--> hf
ans =
! 25. !
! 6.3137515 - 19.431729i !
! - 8.472136 - 6.1553671i !
! - 1.9626105 + 1.42592i !
! 1.110D-16 - 4.441D-16i !
! 1. - 7.499D-33i !
! 0.4721360 - 1.4530851i !
! - 0.5095254 - 0.3701919i !
! - 5.551D-17i !
! 0.1583844 + 0.4874572i !
! 1. + 4.899D-16i !
Here, h is an FIR filter of length 9 with a triangular impulse response. The transfer function of the filter
is obtained by forming a polynomial which represents the z -transform of the filter. This is followed by
1.4. STATE SPACE REPRESENTATION 9
evaluating the polynomial at the points exp(2in) for n = 0; 1; : : : ; 10 which amounts to evaluating the
z -transform on the unit circle at ten equally spaced points in the range of angles [0; ].
-->sl=syslin(domain,num,den)
Another use for the function syslin for state-space descriptions of linear systems is described in the
following section.
-->sl=syslin(domain,a,b,c [,d[,x0]])
-->sl=tf2ss(h)
An important detail is that the transfer function h must be of minimum phase. That is, the denominator
polynomial must be of equal or higher order than that of the numerator polynomial.
-->h=ss2tf(sl)
2 3
0.2569156 + 0.7707468z + 0.7707468z + 0.2569156z
------------------------------------------------
2 3
0.0562972 + 0.4217870z + 0.5772405z + z
-->h1=syslin(d,h1);
-->s1=tf2ss(h1)
s1 =
!lss A B C D X0 dt !
s1(2) = A matrix =
! 0.0223076 0.5013809 0. !
! - 0.3345665 - 0.3797154 - 0.4502218 !
! 0.1124639 0.4085596 - 0.2198328 !
s1(3) = B matrix =
! - 2.3149238 !
! - 2.1451754 !
! 0.2047095 !
s1(4) = C matrix =
! - 0.2688835 0. - 8.327D-17 !
s1(5) = D matrix =
0.2569156
1.6. INTERCONNECTING SYSTEMS 11
a - s1 - s2 - a
s1*s2
- s1
?-
+
6
a q i a
s1+s2
- s2
- s1
?-
a
+ [s1,s2]
6
i a
a - s2
- s1 - a
a q
[s1;s2]
- s2 - a
! 0. !
! 0. !
! 0. !
Here the transfer function of a discrete IIR filter is created using the function iir (see Section 4.2). The
fourth element of h1 is set using the function syslin and then using tf2ss the state-space representation
is obtained in list form.
representations. For each of the four block diagrams in Figure 1.1 the Scilab command which makes the
illustrated interconnection is shown to the left of the diagram in typewriter-face font format.
Bh = A 1 (Ah I )B:
This is exactly what the function dscr does to discretize a continuous-time linear system in state-space
form.
The function dscr can operate on system matrices, linear system descriptions in state-space form, and
linear system descriptions in transfer function form. The syntax using system matrices is as follows
-->[f,g[,r]]=dscr(syslin(c,a,b,[],[]),dt [,m])
1.7. DISCRETIZING CONTINUOUS SYSTEMS 13
where a and b are the two matrices associated to the continuous-time state-space description
and f and g are the resulting matrices for a discrete time system
where the sampling period is dt. In the case where the fourth argument m is given, the continuous time
system is assumed to have a stochastic input so that now the continuous-time equation is
where w(t) is a white, zero-mean, Gaussian random process of covariance m and now the resulting discrete-
time equation is
x(n + 1) = F x(n) + Gu(n) + q(n) (1.8)
where q (n) is a white, zero-mean, Gaussian random sequence of covariance r.
The dscr function syntax when the argument is a linear system in state-space form is
-->[sld[,r]]=dscr(sl,dt[,m])
where sl and sld are lists representing continuous and discrete linear systems representations, respectively.
Here m and r are the same as for the first function syntax. In the case where the function argument is a linear
system in transfer function form the syntax takes the form
-->[hd]=dscr(h,dt)
where now h and hd are transfer function descriptions of the continuous and discrete systems, respectively.
The transfer function syntax does not allow the representation of a stochastic system.
As an example of the use of dscr consider the following Scilab session.
! 2. 1. !
! 0. 2. !
--> b=[1;1]
b =
! 1. !
! 1. !
--> [sld]=dscr(syslin(c,a,b,eye(2,2)),.1);
--> sld(2)
ans =
14 CHAPTER 1. DESCRIPTION OF THE BASIC TOOLS
! 1.2214028 0.1221403 !
! 0. 1.2214028 !
--> sld(3)
ans =
! 0.1164208 !
! 0.1107014 !
-->t=1:200;
-->x1=sin(2*%pi*t/20);
-->x2=sin(2*%pi*t/3);
-->x=x1+x2;
-->z=poly(0,z);
-->hz=syslin(d,poly(h,z,c)./z**33);
-->yhz=flts(x,hz);
-->plot(yhz);
1.9. PLOTTING SIGNALS 15
Notice that in the above example that a signal consisting of the sum of two sinusoids of different frequencies
is filtered by a low-pass filter. The cut-off frequency of the filter is such that after filtering only one of the
two sinusoids remains. Figure 1.2 illustrates the original sum of sinusoids and Figure 1.3 illustrates the
filtered signal.
2.1
1.7
1.3
0.9
0.5
0.1
-0.3
-0.7
-1.1
-1.5
-1.9
0 20 40 60 80 100 120 140 160 180 200
-->[h,hm,fr]=wfir(bp,55,[.20.25],hm,[0 0]);
-->plot(h)
Here a band-pass filter with cut-off frequencies of .2 and .25 is constructed using a Hamming window. The
filter length is 55. More on how to make FIR filters can be found in Chapter 3.
The resulting plot is shown in Figure 1.4.
The frequency response of signals and systems requires evaluating the s-transform on the j! -axis or
the z -transform on the unit circle. An example of evaluating the magnitude of the frequency response of a
continuous-time system is as follows.
16 CHAPTER 1. DESCRIPTION OF THE BASIC TOOLS
1.3
0.9
0.5
0.1
-0.3
-0.7
-1.1
0 20 40 60 80 100 120 140 160 180 200
0.10
0.08
0.06
0.04
0.02
-0.02
-0.04
-0.06
-0.08
-0.10
0 10 20 30 40 50 60
-->hs=analpf(4,cheb1,[.1 0],5)
hs =
161.30794
---------------------------------------------------
2 3 4
179.23104 + 96.905252s + 37.094238s + 4.9181782s + s
-->fr=0:.1:15;
-->hf=freq(hs(2),hs(3),%i*fr);
-->hm=abs(hf);
-->plot(fr,hm),
Here we make an analog low-pass filter using the functions analpf (see Chapter 4 for more details). The
filter is a type I Chebyshev of order 4 where the cut-off frequency is 5 Hertz. The primitive freq (see
Section 1.3.1) evaluates the transfer function hs at the values of fr on the j! -axis. The result is shown in
Figure 1.5
1.0
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
0 2 4 6 8 10 12 14 16
A similar type of procedure can be effected to plot the magnitude response of discrete filters where the
evaluation of the transfer function is done on the unit circle in the z -plane by using the function frmag.
-->[xm,fr]=frmag(num[,den],npts)
18 CHAPTER 1. DESCRIPTION OF THE BASIC TOOLS
The returned arguments are xm, the magnitude response at the values in fr, which contains the normal-
ized discrete frequency values in the range [0; 0:5].
-->[hm,fr]=frmag(hn,256);
-->plot(fr,hm),
Here an FIR band-pass filter is created using the function eqfir (see Chapter 3).
1.2
1.0
0.8
0.6
0.4
0.2
0
0 0.1 0.2 0.3 0.4 0.5
Other specific plotting functions are bode for the Bode plot of rational system transfer functions (see
Section 2.1.1), group for the group delay (see Section 2.1.2) and plzr for the poles-zeros plot.
2 3 4
0.0939809 + 0.3759234z + 0.5638851z + 0.3759234z + 0.0939809z
-------------------------------------------------------------
2 3 4
0.0176648 + 1.928D-17z + 0.4860288z + 4.317D-17z + z
1.10. DEVELOPMENT OF SIGNAL PROCESSING TOOLS 19
-->plzr(hz)
Here a fourth order, low-pass, IIR filter is created using the function iir (see Section 4.2). The resulting
pole-zero plot is illustrated in Figure 1.7
0.880
0.659
0.439
0.218
-0.002
-0.223
-0.443
-0.664
-0.884
real axis
-1.104
-1.562 -1.250 -0.938 -0.626 -0.314 -0.002 0.310 0.622 0.934 1.246 1.558
Poles
Zeros
21
22 CHAPTER 2. REPRESENTATION OF SIGNALS
and
(!) = j tan 1 (!=( a)): (2.8)
We plot the magnitude in (2.7) using two straight line approximations. That is, for j! j jaj we have that
M (!) 20 log jaj which is a constant (i.e., a straight line with zero slope). For j!j jaj we have that
M (!) 20 log j!j which is a straight line on a log scale which has a slope of -20 db/decade. The inter-
section of these two straight lines is at w = a. Figure 2.1 illustrates these two straight line approximations
for a = 10.
-10
-25
Log scale
-40
0 1 2
10 10 10
-45
-90
0 1 2 3
10 10 10 10
In the case where the poles and zeros of H (s) are not all real but occur in conjugate pairs (which is
always the case for real systems) we must consider the term
1
H (s) =
[s (a + jb)][s (a jb)]
1
= 2 (2.9)
s 2as + (a2 + b2 )
where a and b are real. Evaluating (2.9) for s = j! yields
1
H (s) =
(a2 + b2 !2 ) 2aj!
1
= p : (2.10)
!4 + 2(a2 b2 )!2 + (a2 + b2 ) exp(j tan 1 [ a2 +b22a!!2 ])
For ! very small, the magnitude component in (2.10) is approximately 1=(a2 + b2 ) and for ! very large
the magnitude becomes approximately 1=! 2 . Consequently, for small ! the magnitude response can be
approximated by the straight line M (! ) 20 log10 ja2 +b2 j and for ! large we have M (! ) 20
p log j!2 j
which is a straight line with a slope of -40db/decade. These two straight lines intersect at ! = a2 + b2 .
Figure 2.3 illustrates
the straight line approximations for a = 10 and b = 25. The behavior of the magnitude plot when ! is
neither small nor large with respect to a and b depends on whether b is greater than a or not. In the case where
b is less than a, the magnitude plot is similar to the case where the roots of the transfer function are strictly
real, and consequently, the magnitude varies p p line approximations
monotonically between the two straight
shown in Figure 2.3. The correction at ! = a2 + b2 is -6db plus 20 log ja=( a2 + b2 )j. For b greater
than a, however, the term in (2.10) exhibits resonance.
p 2 This resonance is manifested as a local maximum
of the magnitude response which occurs at ! = b 2
a . The value of the magnitude response at this
maximum is 20 log j2abj. The effect of resonance is illustrated in Figure 2.3 as the upper dotted curve.
Non-resonant behavior is illustrated in Figure 2.3 by the lower dotted curve.
24 CHAPTER 2. REPRESENTATION OF SIGNALS
-50
-65
-80
0 1 2
10 10 10
The phase curve for the expression in (2.10) is approximated as follows. For ! very small the imaginary
component of (2.10) is small and the real part is non-zero. Thus, the phase is approximately zero. For !
ppart
very large the real of (2.10) dominates the imaginary part and, consequently, the phase is approximately
180 . At ! = a + b2 the real part of (2.10) is zero and the imaginary part is negative so that the phase
2
is exactly 90 . The phase curve is shown in Figure 2.4.
-45
-90
-135
-180
0 1 2 3
10 10 10 10
x_ = 2x + u
y = 18x + u:
The initial condition is not important since the Bode plot is of the steady state behavior of the system.
-->//Bode plot
-->a=-2*%pi;b=1;c=18*%pi;d=1;
-->sl=syslin(c,a,b,c,d);
-->bode(sl,.1,100);
The result of the call to bode for this example is illustrated in Figure 2.5.
The following example illustrates the use of the bode function when the user has an explicit rational
polynomial representation of the system.
-->s=poly(0,s);
26 CHAPTER 2. REPRESENTATION OF SIGNALS
Magnitude
20 db
18
16
14
12
10
8
6
4
2 Hz
0.
-1 0 1 2
10 10 10 10
Phase
0 degrees
-10
-20
-30
-40
-50
.
Hz
-60
-1 0 1 2
10 10 10 10
-->h1=1/real((s+2*%pi*(15+100*%i))*(s+2*%pi*(15-100*%i)))
h1 =
1
-------------------------
2
403666.82 + 188.49556s + s
-->h1=syslin(c,h1);
-->bode(h1,10,1000,.01);
The result of the call to bode for this example is illustrated in Figure 2.6.
The final example combines the systems used in the two previous examples by attaching them together
in series. The state-space description is converted to a rational polynomial description using the ss2tf
function.
-->a=-2*%pi;b=1;c=18*%pi;d=1;
-->sl=syslin(c,a,b,c,d);
-->s=poly(0,s);
-->h1=1/real((s+2*%pi*(15+100*%i))*(s+2*%pi*(15-100*%i)));
2.1. FREQUENCY RESPONSE 27
Magnitude
-100 db
-110
-120
-130
-140
-150 .
Hz
-160
1 2 3
10 10 10
Phase
0 degrees
-20
-40
-60
-80
-100
-120
-140
-160
Hz
.
-180
1 2 3
10 10 10
-->h1=syslin(c,h1);
-->h2=ss2tf(sl)
h2 =
62.831853 + s
-------------
6.2831853 + s
-->bode(h1*h2,.1,1000,.01);
Notice that the rational polynomial which results from the call to the function ss2tf automatically has
its fourth argument set to the value c. The result of the call to bode for this example is illustrated in
Figure 2.7.
where A(! ) is the magnitude of H (! ) and (! ) is the phase of H (! ). Then the phase delay, tp (! ), and the
group delay, tg (! ), are defined by
tp (!) = (!)=! (2.12)
28 CHAPTER 2. REPRESENTATION OF SIGNALS
Magnitude
-90 db
-100
-110
-120
-130
-140
-150 .
Hz
-160
-1 0 1 2 3
10 10 10 10 10
Phase
0 degrees
-20
-40
-60
-80
-100
-120
-140
-160
Hz
.
-180
-1 0 1 2 3
10 10 10 10 10
and
tg (!) = d(!)=d!: (2.13)
Now assume that H (! ) represents an ideal band pass filter. By ideal we mean that the magnitude of H (! )
is a non-zero constant for !0 !c < j! j < !0 + !c and zero otherwise, and that the phase of H (! ) is
linear plus a constant in these regions. Furthermore, the impulse response of H (! ) is real. Consequently,
the magnitude of H (! ) has even symmetry and the phase of H (! ) has odd symmetry.
Since the phase of H (! ) is linear plus a constant it can be expressed as
(!) = (!0 ) + 0 (!0 )(! !0 ); ! > 0
(!0 ) + 0 (!0 )(! + !0 ); ! < 0 (2.14)
where !0 represents the center frequency of the band pass filter. The possible discontinuity of the phase
at ! = 0 is necessary due to the fact that (! ) must be an odd function. The expression in (2.14) can be
rewritten using the definitions for phase and group delay in (2.12) and (2.13). This yields
!0 tp + (! !0 )tg ; ! > 0
(!) = (2.15)
!0 tp + (! + !0 )tg ; ! < 0
where, now, we take tp = tp (!0 ) and tg = tg (!0 ).
Now assume that a signal, f (t), is to be filtered by H (! ) where f (t) is composed of a modulated
band-limited signal. That is,
f (t) = fl (t) cos(!0 t) (2.16)
where !0 is the center frequency of the band pass filter and Fl (! ) is the Fourier transform a the bandlimited
signal fl (t) (Fl (! ) = 0 for j! j > !c ). It is now shown that the output of the filter due to the input in (2.16)
takes the following form
g(t) = fl (t + tg ) cos[!0 (t + tp )]: (2.17)
To demonstrate the validity of (2.17) the Fourier transform of the input in (2.16) is written as
1
F (!) = [Fl (! !0 ) + Fl (! + !0 )] (2.18)
2
2.1. FREQUENCY RESPONSE 29
where (2.18) represents the convolution of Fl (!) with the Fourier transform of cos(!0 t). The Fourier
transform of the filter, H (! ), can be written
8
< e!0 tp +(! !0 )tg ; !0 !c < ! < !0 + !c
H (! ) =
:
e !0 tp +(!+!0 )tg ; !0 !c < ! < !0 + !c (2.19)
0; otherwise
1 1
Z
g(t) = F (!)H (!)
2 1
Z
1 1 !0 +!c
= [ F (! !0 )ej [(! !0 )tg +!0 tp ] ej!t d!
2 2 !0 !c l
Z !0 +!c
+ Fl (! + !0 )ej [(!+!0 )tg !0 tp ] ej!t d! ] (2.21)
!0 !c
1.0
0.8
0.6
0.4
0.2
-0.2
-0.4
-0.6
-0.8
-1.0
0 10 20 30 40 50 60
-1
-2
-3
-4
0 10 20 30 40 50 60
1.0
0.8
0.6
0.4
0.2
-0.2
-0.4
-0.6
-0.8
-1.0
0 10 20 30 40 50 60
17
13
-3
-7
-11
-15
0 10 20 30 40 50 60
sinusoidal carrier is now phase shifted by =2. This output signal is displayed in Figure 2.10 as the solid
curve. For reference the input signal is plotted as the dotted curve.
To illustrate the effect of the group delay on the filtering process a new filter is constructed as is displayed
in Figure 2.11.
Here the phase is again displayed as the dotted curve. The group delay is the slope of the phase curve as
it passes through zero in the pass band region of the filter. Here tg = 1 and tp = 0. The result of filtering
with this phase curve is display in Figure 2.12. As expected, the envelope is shifted but the sinusoid is not
shifted within the reference frame of the window. The original input signal is again plotted as the dotted
curve for reference.
1.0
0.8
0.6
0.4
0.2
-0.2
-0.4
-0.6
-0.8
-1.0
0 10 20 30 40 50 60
As can be seen from the explanation given in this section, it is preferable that the group delay of a filter
be constant. A non-constant group delay tends to cause signal deformation. This is due to the fact that the
different frequencies which compose the signal are time shifted by different amounts according to the value
of the group delay at that frequency. Consequently, it is valuable to examine the group delay of filters during
the design procedure. The function group accepts filter parameters in several formats as input and returns
the group delay as output. The syntax of the function is as follows:
-->[tg,fr]=group(npts,h)
The group delay tg is evaluated in the interval [0,.5) at equally spaced samples contained in fr. The
number of samples is governed by npts. Three formats can be used for the specification of the filter. The
filter h can be specified by a vector of real numbers, by a rational polynomial representing the z-transform
of the filter, or by a matrix polynomial representing a cascade decomposition of the filter. The three cases
are illustrated below.
The first example is for a linear-phase filter designed using the function wfir
2.1. FREQUENCY RESPONSE 33
-->[h w]=wfir(lp,7,[.2,0],hm,[0.01,-1]);
-->h
ans =
! - 0.0049893 !
! 0.0290002 !
! 0.2331026 !
! 0.4 !
! 0.2331026 !
! 0.0290002 !
! - 0.0049893 !
-->[tg,fr]=group(100,h);
-->plot2d(fr,tg,-1,011, ,[0,2,0.5,4.])
4.0
3.8
3.6
3.4
3.2
3.0
2.8
2.6
2.4
2.2
2.0
0.00 0.05 0.10 0.15 0.20 0.25 0.30 0.35 0.40 0.45 0.50
the group delay is a constant, as is to be expected for a linear phase filter. The second example specifies
a rational polynomial for the filter transfer function:
-->z=poly(0,z);
-->h=z/(z-0.5)
34 CHAPTER 2. REPRESENTATION OF SIGNALS
h =
z
-------
- 0.5 + z
-->[tg,fr]=group(100,h);
-->plot(fr,tg)
1.0
0.8
0.6
0.4
0.2
-0.2
-0.4
0 0.1 0.2 0.3 0.4 0.5
Finally, the third example gives the transfer function of the filter in cascade form.
-->cels=[];
-->for col=h,
--> nf=[col(1:2);1];nd=[col(3:4);1];
--> num=poly(nf,z,c);den=poly(nd,z,c);
--> cels=[cels,tlist([r,num,den],num,den,[])];
-->end;
-->[tg,fr]=group(100,cels);
2.1. FREQUENCY RESPONSE 35
-->//plot(fr,tg)
The result is shown in Figure 2.15. The cascade realization is known for numerical stability.
-1
-2
0 0.1 0.2 0.3 0.4 0.5
//exec(group1_5.code)
//create carrier and narrow band signal
xinit(group1.ps);
wc=1/4;
x=sin(2*%pi*(0:54)*wc);
y=exp(-abs(-27:27)/5);
f=x.*y;
plot([1 1 55],[1 -1 -1]),
nn=prod(size(f))
plot2d((1:nn),f,[2],"000"),
nn=prod(size(y))
plot2d((1:nn),y,[3],"000"),
plot2d((1:nn),-y,[3],"000"),
xend(),
xinit(group2.ps);
//make band pass filter
[h w]=wfir(bp,55,[maxi([wc-.15,0]),mini([wc+.15,.5])],kr,60.);
36 CHAPTER 2. REPRESENTATION OF SIGNALS
hf=fft(h,-1);
hm=abs(hf);
hp=%pi*ones(1:28);//tg is zero
hp(29:55)=-hp(28:-1:2);
hr=hm.*cos(hp);
hi=hm.*sin(hp);
hn=hr+%i*hi;
plot([1 1 55],[4 -4 -4]),
plot2d([1 55],[0 0],[1],"000"),
nn=prod(size(hp))
plot2d((1:nn),hp,[2],"000"),
nn=prod(size(hm))
plot2d((1:nn),2.5*hm,[1],"000"),
xend(),
xinit(group3.ps);
//filter signal with band pass filter
ff=fft(f,-1);
gf=hn.*ff;
g=fft(gf,1);
plot([1 1 55],[1 -1 -1]),
nn=prod(size(g))
plot2d((1:nn),real(g),[2],"000"),
nn=prod(size(f))
plot2d((1:nn),f,[1],"000"),
xend(),
xend(),
xinit(group5.ps);
2.2. SAMPLING 37
ff=fft(f,-1);
gf=hn.*ff;
g=fft(gf,1);
plot([1 1 55],[1 -1 -1]),
nn=prod(size(g))
plot2d((1:nn),real(g),[2],"000"),
nn=prod(size(f))
plot2d((1:nn),f,[1],"000"),
xend(),
2.2 Sampling
The remainder of this section explains in detail the relationship between continuous and discrete signals.
To begin, it is useful to examine the Fourier transform pairs for continuous and discrete time signals.
For x(t) and X (
) a continuous time signal and its Fourier transform, respectively, we have that
Z 1
X (
) = x(t)e j
t dt (2.24)
1
1
Z 1
x(t) = X (
)ej
t d
: (2.25)
2 1
For x(n) and X (! ) a discrete time signal and its Fourier transform, respectively, we have that
1
X
X (! ) = x(n)e j!n (2.26)
n= 1
Z
1
x(n) = X (!)ej!n d!: (2.27)
2
The discrete time signal, x(n), is obtained by sampling the continuous time signal, x(t), at regular intervals
of length T called the sampling period. That is,
We now derive the relationship between the Fourier transforms of the continuous and discrete time signals.
The discussion follows [21].
Using (2.28) in (2.25) we have that
1
Z 1
x(n) = X (
)ej
nT d
: (2.29)
2 1
Rewriting the integral in (2.29) as a sum of integrals over intervals of length 2=T we have that
1 X 1 Z (2r+)=T
x(n) = X (
)ej
nT d
(2.30)
2 r= 1 (2r )=T
38 CHAPTER 2. REPRESENTATION OF SIGNALS
1 X 1 Z =T 2r j
nT j 2nr
x(n) = X (
+ )e e d
: (2.31)
2 r= 1 =T T
Interchanging the sum and the integral in (2.31) and noting that ej 2nr = 1 due to the fact that n and r are
always integers yields
1
Z =T 1
X 2r j
nT
x(n) = [ X (
+ )]e d
: (2.32)
2 =T r= 1 T
Finally, the change of variables ! =
T gives
1
Z
1 X1 ! 2r j!n
x(n) = [ X( + )]e d! (2.33)
2 T r= 1 T T
which is identical in form to (2.27). Consequently, the following relationship exists between the Fourier
transforms of the continuous and discrete time signals:
1 X 1 ! 2r
X (! ) = X( + )
T r= 1 T T
1 X 1 2r
= X (
+ ): (2.34)
T r= 1 T
From (2.34) it can be seen that the Fourier transform of x(n), X (! ), is periodic with period 2=T . The
form of X (! ) consists of repetitively shifting and superimposing the Fourier transform of x(t), X (
), scaled
by the factor 1=T . For example, if X (
) is as depicted in Figure 2.16, where the highest non-zero frequency
of X (
) is denoted by
c = 2fc , then there are two possibilities for X (! ). If =T >
c = 2fc then
X (!) is as in Figure 2.17, and, if =T <
c = 2fc , then X (!) is as in Figure 2.18. That is to say that if
the sampling frequency fs = 1=T is greater than twice the highest frequency in x(t) then there is no overlap
in the shifted versions of X (
) in (2.34). However, if fs < 2fc then the resulting X (! ) is composed of
overlapping versions of X (
).
to say that if the sampling frequency fs = 1=T is greater than twice the highest frequency in x(t) then
there is no overlap in the shifted versions of X (
) in (2.34). However, if fs < 2fc then the resulting X (! )
is composed of overlapping versions of X (
).
The sampling rate T = 1=(2fc ) is the well known Nyquist sampling rate and any signal sampled at a
rate higher than the Nyquist rate retains all of the information that was contained in the original unsampled
signal. It can be concluded that sampling can retain or alter the character of the original continuous time
signal. If sampling is performed at more than twice the highest frequency in x(t) then the signal nature is
retained. Indeed, the original signal can be recuperated from the sampled signal by low pass filtering (as
is demonstrated below). However, if the signal is undersampled this results in a signal distortion known as
aliasing.
To recuperate the original analog signal from the sampled signal it is assumed that
c < =T (i.e., that
the signal is sampled at more than twice its highest frequency). Then from (2.34)
X (
) = T X (!) (2.35)
5.0
X(W)
4.3
3.6
2.9
2.2
X(0)
1.5
0.8
0.1 -Wc Wc W
-0.6
-1.3
-2.0
-5 -4 -3 -2 -1 0 1 2 3 4 5
5.0
X(W)
4.3
3.6
2.9
2.2
X(0)/T
1.5
0.8
0.1 W
pi/T
-0.6
-1.3
-2.0
-5 -4 -3 -2 -1 0 1 2 3 4 5
5.0
X(W)
4.3
3.6
2.9
2.2
X(0)/T
1.5
0.8
0.1 W
pi/T
-0.6
-1.3
-2.0
-5 -4 -3 -2 -1 0 1 2 3 4 5
T 1
Z =T X
x(t) = [ x(nT )e j
nT ]ej
t d
: (2.37)
2 =T 1
Interchanging the sum and the integral gives
1
X T
Z =T
x(t) = x(nT )[ ej
(t nT ) d
]: (2.38)
1 2 =T
The expression in brackets in (2.38) can be recognized as a time shifted inverse Fourier transform of a low
pass filter with cut-off frequency =T . Consequently, (2.38) is a convolution between the sampled signal
and a low pass filter, as was stated above.
We now illustrate the effects of aliasing. Since square integrable functions can always be decomposed
as a sum of sinusoids the discussion is limited to a signal which is a cosine function. The results of what
happens to a cosine signal when it is undersampled is directly extensible to more complicated signals.
We begin with a cosine signal as is illustrated in Figure 2.19.
The cosine in Figure 2.19 is actually a sampled signal which consists of 5000 samples. One period of
the cosine in the figure is 200 samples long, consequently, the Nyquist sampling rate requires that we retain
one sample in every 100 to retain the character of the signal. By sampling the signal at a rate less than the
Nyquist rate it would be expected that aliasing would occur. That is, it would be expected that the sum of
two cosines would be evident in the resampled data. Figure 2.20 illustrates the data resulting from sampling
the cosine in Figure 2.19 at a rate of ones every 105 samples.
As can be seen in Figure 2.20, the signal is now the sum of two cosines which is illustrated by the beat
signal illustrated by the dotted curves.
1.7
1.3
0.9
0.5
0.1
-0.3
-0.7
-1.1
-1.5
0 1e3 2e3 3e3 4e3 5e3
1.7
1.3
0.9
0.5
0.1
-0.3
-0.7
-1.1
-1.5
0 10 20 30 40 50
2.3.1 Introduction
There often arises a need to change the sampling rate of a digital signal. The Fourier transform of a
continuous-time signal, x(t), and the Fourier transform of the discrete-time signal, x(nT ), obtained by
sampling x(t) with frequency 1=T . are defined, respectively, in (2.39) and (2.40) below
Z 1
X^ (!) = x(t)e j!t dt (2.39)
1
1
X
X (ej!T ) = x(nT )e j!T : (2.40)
n= 1
The relationship between these two transforms is (see [21]) :
1 X 1 j! j 2r
X (ej!T ) = X^ ( + ): (2.41)
T r= 1 T T
Figure 2.21 illustrates the magnitude of the Fourier transform X^ (!) of a signal x(t). Figure 2.22 shows two
periods of the associated Fourier transform X (e jwT ) of x(nT ) where the sampling frequency was taken to
be the Nyquist rate. As indicated by (2.41), the magnitude of X (ejwT ) with respect to the magnitude of
X^ (!) is scaled by 1=T .
1.0
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
-60 -40 -20 0 20 40 60
1.0
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
-7 -5 -3 -1 1 3 5 7
Figure 2.22: exec(intdec1 4.code) Fourier Transform of the Discrete Time Signal
Consequently, one could obtain x(t) sampled at a different sampling rate T 0 from the sampled signal x(nT )
by using (2.42) to reconstruct x(t) and then resampling. In practice, however, this is impractical. It is much
more convenient to keep all operations in the digital domain once one already has a discrete-time signal.
The Scilab function intdec accomplishes a sampling rate change by interpolation and decimation. The
interpolation takes the input signal and produces an output signal which is sampled at a rate L (an integer)
times more frequently than the input. Then decimation takes the input signal and produces an output signal
which is sampled at a rate M (also an integer) times less frequently than the input.
2.3.2 Interpolation
In interpolating the input signal by the integer L we wish to obtain a new signal x(nT 0 ) where x(nT 0 )
would be the signal obtained if we had originally sampled the continuous-time signal x(t) at the rate 1=T 0 =
L=T . If the original signal is bandlimited and the sampling rate f = 1=T is greater than twice the highest
frequency of x(t) then it can be expected that the new sampled signal x(nT 0 ) (sampled at a rate of f 0 =
1=T 0 = L=T = Lf ) could be obtained directly from the discrete signal x(nT ).
An interpolation of x(nT ) to x(nT 0 ) where T 0 = T=L can be found by inserting L 1 zeros between
each element of the sequence x(nT ) and then low pass filtering. To see this we construct the new sequence
v(nT 0 ) by putting L 1 zeros between the elements of x(nT )
v(nT 0 ) = x(nT=L); n = 0; L; 2L; : : : (2.43)
0; otherwise :
Since T 0 = T=L, v(nT 0 ) is sampled L times more frequently than x(nT ). The Fourier transform of (2.43)
yields
0
1
X
V (ej!T ) = v(nT 0 )e j!nT 0
n= 1
44 CHAPTER 2. REPRESENTATION OF SIGNALS
1
X
= x(nT )e j!nLT 0
n= 1
1
X
= x(nT )e j!nT
n= 1
= X (ej!T ): (2.44)
0
From (2.44) it can be seen that V (ej!T ) is periodic with period 2=T and, also, period 2=T 0 = 2L=T .
This fact is illustrated in Figure 2.23 where L = 3. Since the sampling frequency of V is 1=T 0 we see that
by filtering v (nT 0 ) with a low
3.2
2.8
2.4
2.0
1.6
1.2
0.8
0.4
0
-19 -15 -11 -7 -3 1 5 9 13 17 21
pass filter with cut-off frequency at =T we obtain exactly the interpolated sequence, x(nT 0 ), which we
seek (see Figure 2.24), except for a scale factor of L (see (2.41)).
2.3.3 Decimation
Where the object of interpolation is to obtain x(nT 0 ) from x(nT ) where T 0 = L=T , the object of decimation
is to find x(nT 00 ) from x(nT ) where T 00 = MT , M an integer. That is, x(nT 00 ) should be equivalent to
a sequence obtained by sampling x(t) M times less frequently than that for x(nT ). Obviously this can be
accomplished by keeping only every M th sample of x(nT ). However, if the sampling frequency 1=T is
close to the Nyquist rate then keeping only every M th sample results in aliasing. Consequently, low pass
filtering the sequence x(nT ) before discarding M 1 of each M points is advisable. Assuming that the
signal x(nT ) is sampled at the Nyquist rate, the cut-off frequency of the low pass filter must be at =(MT ).
1.0
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
-7 -5 -3 -1 1 3 5 7
Put
x(nT ) - L-1 Zeros
Between
- LPF - M-1Discard
of Every - x(nMT=L)
Each Sample M Samples
filter for the diagram illustrated in the figure. It accomplishes this by using the wfir filter design function.
This is followed by taking the Fourier transform of both the input signal and the low-pass filter (whose
magnitude is first scaled by L) by using the fft function. Care must be taken to obtain a linear convolution
between the two sequences by adding on an appropriate number of zeros to each sequence before the FFT
is performed. After multiplying the two transformed sequences together an inverse Fourier transform is
performed. Finally, the output is obtained by discarding M 1 of each M points. The cut-off frequency of
the low pass filter is =T if L > M and is (L )=(MT ) if L < M .
The practical implementation of the interpolation and decimation procedure is as follows. If the length
of the input is N then after putting L 1 zeros between each element of x the resulting sequence will be of
length (N 1)L + 1. This new sequence is then lengthened by K 1 zeros where K is the length of the
low pass filter. This lengthening is to obtain a linear convolution between the input and the low pass filter
with the use of the FFT. The cut-off frequency of the low pass filter is chosen to be (:5N )=[(N 1)L + K ]
if L > M and (:5NL)=(M [(N 1)L + K ]) if L < M . The FFTs of the two modified sequences are
multiplied element by element and then are inverse Fourier transformed. The resulting sequence is of length
(N 1)L + K . To obtain a sequence of length of (N 1)L +1 elements, (K 1)=2 elements are discarded
off of each end. Finally, M 1 out of every M elements are discarded to form the output sequence.
46 CHAPTER 2. REPRESENTATION OF SIGNALS
13
11
-1
0 10 20 30 40 50
Figure 2.27. As can be seen, x(nT ) is a bandlimited sequence. A new sequence v (nT 0 ) is created by
putting 7 zeros between each element of x(nT ). We use a Hamming windowed lowpass filter of length 33
(Figure 2.28)
to filter v (nT 0 ). The discrete Fourier transform of v (nT 0 ) is illustrated in Figure 2.29. As is to be
expected, the Fourier transform of v (nT 0 ) looks like the Fourier transform of x(nT ) repeated 8 times.
The result of multiplying the magnitude response of the filter with that of the sequence v (nT 0 ) is shown
in Figure 2.30. Since the low pass filter is not ideal the resulting filtered sequence has some additional high
frequency energy in it (i.e., the small lobes seen in Figure 2.30).
Finally, after taking the inverse discrete Fourier transform and discarding 4 out of every 5 samples we
obtain the sequence illustrated in Figure 2.31.
28
24
20
16
12
0
0 10 20 30 40 50
0
0 100 200 300 400 500
24
20
16
12
0
0 100 200 300 400 500
200
180
160
140
120
100
80
60
40
20
0
0 100 200 300 400 500
13
11
-1
0 10 20 30 40 50 60 70 80
A careful examination of (2.45) reveals that X (k ), the DFT of x(n), is periodic with period N (due to
the fact that for fixed n the term exp( j 2nk=N ) is periodic with period N ). That X (k ) is periodic also
follows from the fact that (2.45) can be interpreted as samples of the z -transform of x(n) at N equally
spaced spaced samples on the unit circle. For reasons of symmetry, the DFT is defined to consist of the N
distinct points of X (k ) for k = 0; 1; : : : ; N 1.
The N points of the sequence x(n) can be recovered from N points of X (k ). This recovery is called
the inverse DFT and takes the form
1 NX1 2
x(n) = X (k)ej N nk : (2.46)
N k=0
It should be noted that (2.46) yields a periodic sequence in n of period N and that it is the N values of x(n),
n = 0; 1; : : : ; N 1 which yield the desired finite length sequence.
In order to better understand the DFT, one can think of (2.45) as being represented by a matrix compu-
tation
2 3
2 3 1 1 1 1 2 3
X (1) 6
6 1 e j 2N e j 4N e j 2(N
N
1) 7
7 x(1)
6 X (2) 7 6 76 x(2) 7
6
6 ..
7
7 = 6
6 1 e j 4N e j 8N e j 4(N
N
1)
76
76 ..
7
7: (2.47)
4 . 5 6 . .. .. .. 74 . 5
6 .. . . . 7
X (N 1) 4
1)2
5 x(N 1)
1 e j 2(NN 1) e j 4(NN 1) e j (N N
The inverse DFT can be calculated in a similar fashion, where the matrix used is the Hermitian transpose
of that in (2.47) times a factor of 1=N . From (2.47) it can be seen that the DFT requires order N 2 multi-
plications. The most direct application of the DFT is the calculation of the spectrum of finite length discrete
signals. In fact, the DFT is a projection of x(n) onto the orthogonal basis consisting of the N complex
exponentials exp( j 2nk=N ) indexed by k . Another important property of the DFT has to do with the
50 CHAPTER 2. REPRESENTATION OF SIGNALS
inverse DFT of the product of two transformed sequences. Taking x(n) and h(n) to be two sequences of
length N the DFTs of these two sequences are
X1
N
X (k ) = x(n)e j 2N nk (2.48)
n=0
and
X1
N
H (k ) = h(n)e j 2N nk : (2.49)
n=0
Taking the inverse DFT of the product Y (k ) = H (k )X (k ) yields
1 NX1 2
y(n) = H (k)X (k)ej N nk
N k=0
X1
N NX1 1 NX1 j 2N (n
= h(m) x(r) e m r)k
m=0 r=0
N k=0
X1
N
= h(m)x(n m) (2.50)
m=0
where the last equality follows from the fact that
1 NX1 j 2N (n
e m r)k = 1; r = n m : (2.51)
N k=0 0; otherwise
In (2.50) it should be noted that when the argument of x is outside of the the range [0; N 1] that the value of
x is obtained from evaluating the argument modulo N (which follows from the periodicity of the x obtained
by using the inverse DFT). A very important application of the DFT is for calculating the interaction of
discrete signals and discrete linear systems. When a discrete signal is introduced to the input of a linear
system, the resulting output is a convolution of the input signal with the impulse response of the linear
system. The convolution operation, which is discussed in more detail in the section on convolution, requires
order N 2 multiplications where the signal and system impulse response are both of length N . Calculating
the convolution by FFT requires order N log2 N multiplications.
It is equally possible to compute a multi-dimensional DFT. For a multi-dimensional sequence x(n1 ; n2 ; : : : ; nM )
the multi-dimensional DFT is defined by
X (k1 ; k2 ; : : : ; kM ) =
1 1
NX N2 1 M 1
NX
n1 k1 X
j N2 nM kM
2 2
jN jN n2 k2
e 1 e 2 e M x(n1 ; n2 ; : : : ; nM ): (2.52)
n1 =1 n2 =1 nM =1
The inverse multi-dimensional DFT is analogous to the calculation above with a change of sign for the
complex exponentials and a factor of 1=(N1 N2 NM ).
The FFT algorithm is a computationally efficient way of calculating the DFT. The computational sav-
ings realized by the FFT are obtained by exploiting certain symmetries and periodicities which exist in the
calculation of the DFT. To show how the FFT exploits these properties of the DFT we assume that N = 2
for
a positive integer and we calculate the DFT of x(n) as follows
X1
N
X (k ) = x(n)e j 2N nk
n=0
2.4. THE DFT AND THE FFT 51
X X
= x(n)e j 2N nk + x(n)e j 2N nk
n=even n=odd
N
X
2
1 N
X
2
1
2 2
j N= rk 2 j N= rk
= x(2r)e 2 + ej N k x(2r + 1)e 2 (2.53)
r=0 r=0
where the final equality is obtained by making the change of variables n = 2r . The expression in (2.53) is
composed of a sum of two N=2 point DFTs, one for the N=2 point sequence x(0), x(2), : : :, x(N 2),
and the other for the N=2 point sequence x(1), x(3), : : :, x(N 1). An addition to the two N=2 point
DFTs in (2.53), the calculation also requires N additional multiplications for the N terms exp(j 2k=N ),
k = 0; 1; : : : ; N 1.
The purpose of calculating the DFT as in (2.53) is that a computational savings has been realized. As has
already been shown the calculation of the N point DFT from (2.45) requires order N 2 multiplications. Since
(2.53) requires the calculation of two N=2 point DFTs plus N additional multiplications, the computational
load is of order 2(N=2)2 + N = N 2 =2 + N . For
> 1 (i.e., for N 4) we have realized a computational
savings by using (2.53). Furthermore, the operation in (2.53) can be repeated in that each of the N=2 point
DFTs can be split into two N=4 point DFTs plus N additional multiplications. This yields a computational
complexity of 4(N=4)2 + 2N multiplications. Continuing in this way
= log2 N times, the final result is
an algorithm with computational complexity of N log2 N multiplications.
The above discussion of the computational advantages of the FFT is based on the assumption that N =
2 . Similar developments of the FFT can be derived based on any prime factorization of N . The more prime
factors N has the greater computational efficiency can be obtained in using the FFT. In fact, it may be useful
in some applications to artificially extend the length of a sequence (by adding on zeros) in order that the
length of the sequence will be more factorable. The FFT primitive in Scilab automatically accounts for the
prime factorization of the sequence length.
-->x=0:63;y=cos(2*%pi*x/16);
-->yf=fft(y,-1);
-->plot(x,real(yf));
-->xend(),
The cosine data is displayed in Figure 2.32. resulting output from the fft primitive is displayed in Fig-
ure 2.33. Figure 2.33 displays the magnitude of the DFT.
Note, however, that since the cosine function is an even symmetric function, the DFT of the cosine is
strictly real and, thus, the magnitude and the real part of the DFT are the same. Furthermore, since we are
calculating a 64-point DFT of a cosine with frequency 2=16 it is expected that the DFT should have peaks
at k = 4 and k = 60. This follows from the fact that the value k = 64 of the DFT corresponds to a frequency
52 CHAPTER 2. REPRESENTATION OF SIGNALS
1.0
0.8
0.6
0.4
0.2
-0.2
-0.4
-0.6
-0.8
-1.0
0 10 20 30 40 50 60 70
35
31
27
23
19
15
11
-1
0 10 20 30 40 50 60 70
of 2 and, consequently, the value k = 4 must correspond to the frequency 2=16, which is the frequency
of the signal under examination.
The second example calculates the DFT of a three-dimensional signal. The calculation proceeds as
follows.
-->y1=matrix(1:6,2,3)
y1 =
! 1. 3. 5. !
! 2. 4. 6. !
-->y2=matrix(7:12,2,3)
y2 =
! 7. 9. 11. !
! 8. 10. 12. !
-->y=matrix([y1,y2],1,12)
y =
column 1 to 11
! 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. !
column 12
! 12. !
-->yf=mfft(y,-1,[2 3 2])
yf =
column 1 to 7
column 8 to 12
! 0 0 0 0 0 !
-->yf1=matrix(yf(1:6),2,3)
yf1 =
-->yf2=matrix(yf(7:12),2,3)
54 CHAPTER 2. REPRESENTATION OF SIGNALS
yf2 =
! - 36. 0 0 !
! 0 0 0 !
In the above series of calculations the signal y is three-dimensional and is represented by the two matrices
y1 and y2. The first dimension of y are the rows of the matrices, the second dimension of y are the columns
of the matrices, and the third dimension of y are the sequence of matrices represented by y1 and y2. The
signal y is represented by the vector y which is in vector form. The DFT of y is calculated using the function
mfft where flag = 1 and dim = [2 3 2]. Naturally, the DFT of the three-dimensional signal is itself
three-dimensional. The result of the DFT calculation is represented by the two matrices yf1 and yf2.
2.5 Convolution
2.5.1 Introduction
Given two continuous time functions x(t) and h(t), a new continuous time function can be obtained by
convolving x(t) with h(t). Z 1
y(t) = h(t u)x(u)du: (2.54)
1
An analogous convolution operation can be defined for discrete time functions. Letting x(n) and h(n)
represent discrete time functions, by the discrete time convolution gives y (n) is :
1
X
y(n) = h(n k)x(k): (2.55)
k= 1
If h(t) represents the impulse response of a linear, time-invariant system and if x(t) is an input to this
system then the output of the system, y (t), can be calculated as the convolution between x(t) and h(t) (i.e.,
as in (2.54). Figure 2.34 illustrates how convolution is related to linear systems. If the system, h(t) is causal
(i.e., h(t) = 0 for t < 0) and, in addition, the signal x(t) is applied to the system at time t = 0, then (2.54)
becomes Z t
y(t) = h(t u)x(u)du: (2.56)
0
Similarly, for h(n) a time invariant, causal, discrete linear system with input x(n) starting at time n = 0,
the output y (n) is the convolution
n
X
y(n) = h(n k)x(k): (2.57)
k=0
2.5. CONVOLUTION 55
An important property of the convolution operation is that the calculation can be effected by using
Fourier transforms. This is due to the fact that convolution in the time domain is equivalent to multiplication
in the frequency domain. Let X (! ), H (! ), and Y (! ) represent the Fourier transforms of x(t), h(t), and
y(t), respectively, where Z 1
Y (!) = y(t)e j!t dt: (2.58)
1
If the relationship in (2.54) is valid, then it also follows that
There is an analogous relationship between the Fourier transform and convolution for discrete time sig-
nals. Letting X (ej! ), H (ej! ), and Y (ej! ) be the Fourier transforms of x(n), h(n), and y (n), respectively,
where, for example
1
X
Y (ej! ) = y(n)e j!n (2.60)
n= 1
we have that the discrete time convolution operation can be represented in the Fourier domain as
The fact that convolution in the time domain is equivalent to multiplication in the frequency domain
means that the calculations in (2.54) and (2.55) can be calculated (at least approximately) by a computation-
ally efficient algorithm, the FFT. This is accomplished by calculating the inverse DFT of the product of the
DFTs of x(n) and h(n). Care must be taken to ensure that the resulting calculation is a linear convolution
(see the section on the DFT and the FFT). The linear convolution is accomplished by adding enough zeros
onto the two sequences so that the circular convolution accomplished by the DFT is equivalent to a linear
convolution.
The convolution of two finite length sequences can be calculated by the Scilab function convol.
-->y=convol(h,x)
where both h and x are finite length vectors and y is a vector representing the resulting convolution of the
inputs. An example of the use of the function under the first format is as follows.
-->x=1:3
x =
! 1. 2. 3. !
-->h=ones(1,4)
h =
56 CHAPTER 2. REPRESENTATION OF SIGNALS
! 1. 1. 1. 1. !
-->y=convol(h,x)
y =
! 1. 3. 6. 6. 5. 3. !
The syntax used for the function under the second format is
-->[y,y1]=convol(h,x,y0)
where y0 and y1 are required to update the calculations of the convolution at each iteration and where the
use of the second format requires the following function supplied by the user.
//exec(convol1.code)
x1=getx(xlen_1,xstart_1);
[y,y1]=convol(h,x1);
for k=2:nsecs-1,
xk=getx(xlen_k,xstart_k);
[y,y1]=convol(h,xk,y1);
end,
xn=getx(xlen_n,xstart_n);
y=convol(h,xn,y1);
where, nsecs is the number of sections of x to be used in the convolution calculation and, in addition, the
user must supply a function getx which obtains segments of the data x following the format.
function [xv]=getx(xlen,xstart)
.
.
.
where xlen is the length of data requested and xstart is the length of the data vector to be used.
X1
N
X (k ) = x(n)e j (2nk)=N (2.62)
n=0
k = 0; 1; : : : ; N 1
and the z-transform of x(n) is given by
1
X
X (z ) = x(n)z n
n= 1
2.6. THE CHIRP Z-TRANSFORM 57
X1
N
= x(n)z n (2.63)
n=0
The N 1 points of the DFT of x(n) are related to the z-transform of x(n) in that they are samples of the
z-transform taken at equally spaced intervals on the unit circle in the z-plane.
There are applications [25] where it is desired to calculate samples of the z-transform at locations either
off the unit circle or at unequally spaced angles on the unit circle. The chirp z-transform (CZT) is an efficient
algorithm which can be used for calculating samples of some of these z-transforms. In particular, the CZT
can be used to efficiently calculate the values of the z-transform of a finite-length, discrete-time sequence if
the z-transform points are of the form
zk = AW k (2.64)
where
A = A0 ej
W = W0 e j (2.65)
and where A0 and W0 are real valued constants and and are angles.
The set of points fzk g lie on a spiral where z0 is at distance A0 from the origin and at angle from the
x-axis. The remaining points are located at equally spaced angles, , and approach the origin for W0 > 1,
move away from the origin for W0 < 1, and remain on a circle of radius A0 for W0 = 1. Figure 2.35 shows
the location of samples of the z-transform for W0 < 1 on the left hand side of the figure and of W0 < 1
on the right hand side of the figure. In both parts of the figure the position of z0 is indicated by the sample
connected to the origin by a straight line.
58 CHAPTER 2. REPRESENTATION OF SIGNALS
A n =h(n) 1=h(k)
X1
N
X (zk ) = x(n)A n W nk ; k = 0; 1; : : : ; M 1 (2.66)
n=0
X1
N
X (zk ) = x(n)A n W 2 n W 2 k W
1 2 1 2 1
2
(k n)2
n=0
X1
N
= W 2k
1 2
[x(n)A n W 2 n W
1 2 1
2
(k n)2 ]: (2.68)
n=0
It can be seen that imbedded in (2.68) is a convolution of two sequences g (n) and h(n) where
g(n) = x(n)A n W 2 n
1 2
(2.69)
and
h(n) = W
1
2
n2 : (2.70)
Consequently, (2.68) can be represented by the block diagram in Figure 2.36. (The circular junctions in
Figure 2.36 represent multiplication of the two incoming signals).
The convolution in (2.68) can be efficiently implemented using an FFT. Since the input sequence is of
length N and the output sequence is of length M , it is necessary to use N + M 1 elements from h(n).
These N + M 1 elements are h( N + 1); h( N + 2); : : : ; h(n); : : : ; h(M 2); h(M 1). After taking
2.6. THE CHIRP Z-TRANSFORM 59
the product of the N + M 1 point FFT of h(n) and of g (n) (where M 1 zero points have been added
to the end of g (n)), the inverse FFT yields a circular convolution of h(n) and g (n). Care must be taken to
choose the correct M points corresponding to the linear convolution desired. The function czt implements
the chirp z-transform.
2.6.3 Examples
The first example presented here calculates the CZT of the sequence x(n) = n for n = 0; 1; : : : ; 9 where ten
points are calculated in the z-plane and the parameter values are W 0 = 1, = 2=10, A0 = 1, and = 0.
This example should yield results identical to those obtained by taking the FFT of the sequence x(n). The
sequence of commands is as follows,
-->[czx]=czt((0:9),10,1,2*%pi/10,1,0);
-->czx
ans =
! 45. + 3.331D-15i !
! - 5. - 15.388418i !
! - 5. - 6.8819096i !
! - 5. - 3.6327126i !
! - 5. - 1.6245985i !
! - 5. + 2.863D-15i !
! - 5. + 1.6245985i !
! - 5. + 3.6327126i !
! - 5. + 6.8819096i !
! - 5. + 15.388418i !
As can be verified using the function fft, the above result is identical to that obtained by taking the FFT of
the sequence x(n) which is shown below,
-->fft((0:9),-1)
ans =
! 45. !
! - 5. - 15.388418i !
! - 5. - 6.8819096i !
! - 5. - 3.6327126i !
! - 5. - 1.6245985i !
! - 5. !
! - 5. + 1.6245985i !
! - 5. + 3.6327126i !
! - 5. + 6.8819096i !
! - 5. + 15.388418i !
60 CHAPTER 2. REPRESENTATION OF SIGNALS
The second example calculates the DFT of the same sequence, x(n), above, however, just at five equally
spaced points in [ =4; =4] on the unit circle in the z-plane. The spacing between the points is =8 for
five points in [ =4; =4]. The result is
-->x=0:9;
-->[czx]=czt(x,5,1,%pi/8,1,-%pi/4);
-->czx
ans =
! 10.363961 + 3.2928932i !
! - 25.451987 - 16.665207i !
! 45. + 3.553D-14i !
! - 25.451987 + 16.665207i !
! 10.363961 - 3.2928932i !
Now taking a sixteen point FFT of the sequence x(n) (accomplished by adding six zeros to the end of the
sequence x(n)) it can be seen that the CZT computed above yields exactly the desired points on the unit
circle in the z-plane. That is to say that the last three points of czx correspond to the first three points of the
FFT of x(n) and the first two points of czx correspond to the last two points of the FFT.
-->y=0*ones(1:16);
-->y(1:10)=0:9;
-->fft(y,-1)
ans =
! 45. !
! - 25.451987 + 16.665207i !
! 10.363961 - 3.2928932i !
! - 9.0640653 - 2.3284927i !
! 4. + 5.i !
! - 1.2790805 - 5.6422012i !
! - 2.363961 + 4.7071068i !
! 3.7951327 - 2.6485014i !
! - 5. !
! 3.7951327 + 2.6485014i !
! - 2.363961 - 4.7071068i !
! - 1.2790805 + 5.6422012i !
! 4. - 5.i !
! - 9.0640653 + 2.3284927i !
! 10.363961 + 3.2928932i !
! - 25.451987 - 16.665207i !
2.6. THE CHIRP Z-TRANSFORM 61
62 CHAPTER 2. REPRESENTATION OF SIGNALS
Chapter 3
The problem, in practice, is that for many filters of interest the resulting impulse response is infinite and
non-causal. An example of this is the low pass filter which, given its cut-off frequency, !c , is defined by
H (!j!c) = 1; j!j !c
(3.2)
0; otherwise
The associated impulse response is obtained by applying (3.1) to (3.2) which yields
1
h(nj!c) = sin(!c n) 1<n<1 (3.3)
n
A technique for obtaining a finite length implementation to (3.3) is to take the N elements of h(n) which
are centered around n = 0 and to discard all the remaining elements. This operation can be represented by
multiplying the sequence in (3.3) by an appropriately shifted version of a rectangular window of the form
RN (n) = 1; 0 n N 1
(3.4)
0; otherwise
The magnitude of the resulting windowed sequence frequency response is depicted in Figure 3.1 super-
imposed on the ideal frequency response (the dotted curve). The filter illustrated in Figure 3.1 has length
N = 33 and a cut-off frequency of !c = :2. As can be seen, the
approximation is marked by a ripple in both the pass and stop bands. This ripple finds its greatest
deviations near the discontinuity at !c . The observed ripple is due to the convolution of the ideal frequency
response given by (3.2) with the frequency response of the rectangular window. For many applications the
ripples in the frequency response of Figure 3.1 are unacceptable.
It is possible to decrease the amount of rippling by using different types of windows. The performance of
a window is governed by its frequency response. Since the frequency response of the window is convolved
with the desired frequency response the objective is to find a window which has a frequency response which
is as impulsive as possible. That is, the frequency response should have a narrow main lobe with most of
the energy in this lobe and side lobes which are as small as possible. The width of the main lobe governs,
63
64 CHAPTER 3. FIR FILTERS
1.2
1.0
0.8
0.6
0.4
0.2
0
0 0.1 0.2 0.3 0.4 0.5
for example, the width of the transition band between the pass and stop bands of a low pass filter. The side
lobes govern the amount ripple in the pass and stop bands. The area under the main lobe governs the amount
of rejection available in the stop bands.
The choice of window in the design process is a matter of trading off, on one hand, the effects of
transition band width, ripple, and rejection in the stop band with, on the other hand, the filter length and the
window type.
Using the result in (3.3), the impulse response of the high pass filter is given by
1.125
1.000
0.875
0.750
0.625
0.500
0.375
0.250
0.125
0.000
-0.125
-3.14 -2.51 -1.88 -1.26 -0.63 0.00 0.63 1.26 1.88 2.51 3.14
1.125
1.000
0.875
0.750
0.625
0.500
0.375
0.250
0.125
0.000
-0.125
-3.14 -2.51 -1.88 -1.26 -0.63 0.00 0.63 1.26 1.88 2.51 3.14
1.125
1.000
0.875
0.750
0.625
0.500
0.375
0.250
0.125
0.000
-0.125
-3.14 -2.51 -1.88 -1.26 -0.63 0.00 0.63 1.26 1.88 2.51 3.14
the functional form of the frequency response, F (!j!l ; !h ) can be obtained by shifting the low pass
filter two times as follows
where D (! j!l ; !h ) is the frequency response of the stop band filter. The impulse response of this filter is
1.125
1.000
0.875
0.750
0.625
0.500
0.375
0.250
0.125
0.000
-0.125
-3.14 -2.51 -1.88 -1.26 -0.63 0.00 0.63 1.26 1.88 2.51 3.14
governs its efficacy in filter design. Consequently, for each window type, we try to give its frequency
response and a qualitative analysis of its features with respect to the frequency response of the rectangular
window.
The frequency response of the rectangular window is obtained by taking the Fourier transform of (3.4)
X1
N
RN (!) = e j!n (3.16)
n=0
sin(!N=2) j (N 1)!=2
= e : (3.17)
sin(!=2)
The magnitude of (3.17) is plotted as the solid line in Figure 3.6. Evaluating (3.17) at ! = 0 yields the height
of the main lobe which is RN (0) = N . The zeros of RN (! ) are located at ! = 2n=N , n = 1; 2; : : :,
and, consequently, the base of the main lobe has width 4=N . The area under the main lobe can be bounded
from above by the area of a rectangle (depicted by a dotted curve in Figure 3.6) of area 4 and from below
by that of a triangle (also shown in Figure 3.6) of area 2 . Thus, the area under the main lobe is essentially
independent of the value of N and the percentage area under the main lobe decreases with increasing N .
This fact is important because it illustrates that the rectangular window is limited in its ability to perform
like an impulse.
By comparison the percentage area under the main lobe of the triangular window is approximately
constant as the value of N increases. The impulse response of the triangular window is
8
< (n + 1)=N; 0nN 1
T2N 1 (n) = (2N 1 n)=N; N n 2N 2 (3.18)
:
0; otherwise:
p the impulse response for the triangular window can be obtained by scaling the rectangular window by
Since
1= N and convolving it with itself, the frequency response, T2N 1 (!), is the square of RN (!)=N or
sin2 (!N=2) j (N 1)!
T2N 1 (!) = e :
N sin2 (!=2)
(3.19)
68 CHAPTER 3. FIR FILTERS
36
32
28
24
20
16
12
0
-0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8
As can be seen from (3.19), the width of the main lobe of the triangular window is the same width as that
of the rectangular window (i.e. 4=N ). However, the impulse response of the triangular window is twice as
long as that of the rectangular window. Consequently, the triangularly windowed filter shows less ripple but
broader transition bands than the rectangularly windowed filter.
The Hamming window is like the triangular window in that its main lobe is about twice as wide as that of
a rectangular window for an equal length impulse response. All but :04% of the Hamming windows energy
is in the main lobe. The Hamming window is defined by
HN (n) = + (1 ) cos( 2Nn ); (N 1)=2 n (N 1)=2 (3.20)
0; otherwise :
where = :54. Other values for are possible. For example when = :5 then (3.20) is known as the
Hanning window.. The frequency response of (3.20) can be obtained by noting that HN (n) is a rectangularly
windowed version of the constant and an infinite length cosine. Thus
where Io (x) is the modified zeroth-order Bessel function and is a constant which controls the trade-off of
the side-lobe heights and the width of the main lobe. The Kaiser window yields an optimal window in the
3.1. WINDOWING TECHNIQUES 69
sense that the side lobe ripple is minimized in the least squares sense for a certain main lobe width. A closed
form for the frequency response of the Kaiser window is not available.
The Chebyshev window is obtained as the inverse DFT of a Chebyshev polynomial evaluated at equally
spaced intervals on the unit circle. The Chebyshev window uniformly minimizes the amount of ripple in
the side lobes for a given main lobe width and filter length. A useful aspect of the design procedure for the
Chebyshev window is that given any two of the three parameters: the window length, N ; half the main lobe
width, f ; the side lobe height, p , the third can be determined analytically using the formulas which follow.
For f and p known, N is obtained from
1 ((1 + p )=(p ))
N 1 + cosh
cosh 1 (1=(cos(f )))
: (3.25)
1
f = cos 1 (1= cosh(cosh 1 ((1 + p )=p )=(N 1))): (3.26)
Finally, for N and f known, p is obtained from
--> [wft,wfm,fr]=wfir()
where the parentheses are a required part of the name. This format of the function is interactive and will
prompt the user for required input parameters such as the filter type (lp=low pass, hp=high pass, bp=band
pass, sb=stop band), filter length (an integer n > 2), window type (re=rectangular, tr=triangular,
hm=hamming, kr=kaiser, ch=chebyshev) and other special parameters such as for the the generalized
Hamming window (0 < < 1) and for the Kaiser window ( > 0). The three returned arguments are:
wft: A vector containing the windowed filter coefficients for a filter of length n.
wfm: A vector of length 256 containing the frequency response of the windowed filter.
fr: A vector of length 256 containing the frequency axis values (0 fr :5) associated to the values
contained in wfm.
--> [wft,wfm,fr]=wfir(ftype,forder,cfreq,wtype,fpar)
This format of the function is not interactive and, consequently, all the input parameters must be passed
as arguments to the function. The first argument ftype indicates the type of filter to be constructed and
can take the values lp, hp, bp, and sb representing, respectively the filters low-pass, high-
pass, band-pass, and stop-band. The argument forder is a positive integer giving the order of the desired
filter. The argument cfreq is a two-vector for which only the first element is used in the case of low-
pass and high-pass filters. Under these circumstances cfreq(1) is the cut-off frequency (in normalized
Hertz) of the desired filter. For band-pass and stop-band filters both elements of cfreq are used, the
first being the low frequency cut-off and the second being the high frequency cut-off of the filter. Both
values of cfreq must be in the range [0; :5) corresponding to the possible values of a discrete frequency
70 CHAPTER 3. FIR FILTERS
response. The argument wtype indicates the type of window desired and can take the values re, tr,
hm, hn, kr, and ch representing, respectively, the windows rectangular, triangular, Hamming,
Hanning, Kaiser, and Chebyshev. Finally, the argument fpar is a two-vector for which only the first element
is used in the case of Kaiser window and for which both elements are used in the case of a Chebyshev
window. In the case of a Kaiser window the first element of fpar indicates the relative trade-off between
the main lobe of the window frequency response and the side-lobe height and must be a positive integer. For
more on this parameter see [24]. For the case of the Chebyshev window one can specify either the width of
the windows main lobe or the height of the window sidelobes. The first element of fpar indicates the side-
lobe height and must take a value in the range [0; 1) and the second element gives the main-lobe width and
must take a value in the range [0; :5). The unspecified element of the fpar-vector is indicated by assigning
it a negative value. Thus, fpar=[.01,-1] means that the Chebyshev window will have side-lobes of
height :01 and the main-lobe width is left unspecified.
Note: Because of the properties of FIR linear phase filters it is not possible to design an even length high
pass or stop band filter.
3.1.4 Examples
This section gives several examples of windowed filter design. In the first example we choose a low pass
filter of length n = 33 using a Kaiser window with parameter = 5:6. The resulting magnitude of the
windowed filter is plotted in Figure 3.7 where the magnitude axis is given on a log scale.
-1
-3
-5
-7
-9
-11
-13
-15
-17
0 0.1 0.2 0.3 0.4 0.5
Figure 3.7: exec(fir7.code) Low pass filter with Kaiser window, n = 33, = 5:6
The second example is a stop band filter of length 127 using a Hamming window with parameter =
:54. The resulting magnitude of the windowed filter is plotted in Figure 3.8 where the magnitude is given
on a log scale.
The third example is a band pass filter of length 55 using a Chebyshev window with parameter dp = :001
and df = :0446622. The resulting magnitude of the windowed filter is plotted in Figure 3.9 where the
magnitude is given on a log scale.
3.1. WINDOWING TECHNIQUES 71
-1
-3
-5
-7
-9
-11
-13
0 0.1 0.2 0.3 0.4 0.5
Figure 3.8: exec(fir8.code) Stop band filter with Hamming window, n = 127, = :54
-1
-2
-3
-4
-5
-6
-7
-8
0 0.1 0.2 0.3 0.4 0.5
Figure 3.9: exec(fir9.code) Band pass filter with Chebyshev window, n = 55, dp = :001, df =
:0446622
72 CHAPTER 3. FIR FILTERS
1 z X1
N N H (k)
H (z ) = 1 ej (2=N )k ) (3.28)
N k=0
(1 z
This means that one way of approximating any continuous frequency response is to sample in frequency,
at N equi-spaced points around the unit circle (the frequency samples), and interpolate between them to
obtain the continuous frequency response. Thus, the approximation error will be exactly zero at the sampling
frequencies and finite between them. This fact has to be related to the reconstruction of a continuous function
from its samples, as exposed in section 2.2 for the case of a continuous-time signal.
The interpolation formula for an FIR filter, that is its frequency response, is obtained by evaluating (3.28)
on the unit circle:
e j!(N 1)=2 X1
N
H (k)e jk=N sin(N!=2)
H (ej! ) =
N k=0
sin(!=2 k=N )
e j!(N 1)=2 X1
N
= H (k)S (!; k) (3.29)
N k=0
where
sin(N!=2)
jk=N
S (!; k) = e
sin(!=2 k=N )
sin(N (!=2) k=N )
= e jk=N (3.30)
sin(!=2 k=N )
are the interpolating functions. Thus, the contribution of every frequency sample to the continuous frequency
response is proportional to the interpolating function sin(N!=2)= sin(!=2) shifted by k=N in frequency.
The main drawback of this technique is the lack of flexibility in specifying the transition band width, which
is equal to the number of samples the user decides to put in times =N , and thus is strongly related to N .
Moreover, the specification of frequency samples in transition bands, giving minimum ripple near the band
edges, is not immediate. Nevertheless, it will be seen, in a later chapter on filter optimization techniques,
that simple linear programming techniques can be used to drastically reduce the error approximation by
optimizing only those samples located in the transition bands. To illustrate this point, Figure 3.10 shows the
response obtained for a type 1 band pass filter with length 65 : first with no sample in the transition bands
and second (dashed curve) with one sample of magnitude .5 in each of these bands. It is worth noting at this
point that the linear-FIR design problem with arbitrary frequency response specification is more efficiently
solved using a minmax approximation approach, which is exposed in the next section.
Finally, depending on where the initial frequency sample occurs, two distinct sets of frequency samples
can be given, corresponding to the so-called type 1 and type 2 FIR filters :
k
fk = k = 0; : : : ; N 1 for type 1 filters
N
k + 1=2
fk = k = 0; : : : ; N 1 for type 2 filters
N
3.2. FREQUENCY SAMPLING TECHNIQUE 73
1.2
1.0
0.8
0.6
0.4
0.2
-0.2
0 0.1 0.2 0.3 0.4 0.5
Figure 3.10: exec(fstyp121.code)Type 1 band pass filter with no sample or one sample in each
transition band
The type of design is at users will and depends on the application: for example, a band edge may be closer
to a type 1 than to a type 2 frequency sampling point. This point is illustrated in Figure 3.11 for the case of
a low pass filter with length 64 and no sample in the transition band.
The full line (resp. the dashed line) gives the approximated response for the type 1 (resp. type 2) FIR
linear filter. We give now the way the two previous examples have been generated and the code of the func-
tion fsfir which calculates the approximated response. Figure 3.10 was obtained with the following set
of instructions :
-->hst2=fsfirlin(hd,1);//corresponding filter
-->pas=1/prod(size(hst1))*.5;
-->n=prod(size(hst1))
n =
257.
74 CHAPTER 3. FIR FILTERS
1.2
1.0
0.8
0.6
0.4
0.2
-0.2
0 0.1 0.2 0.3 0.4 0.5
-->plot(fg(1:n),hst1);
-->plot2d(fg(1:n),hst2,[3],"000");
-->hd=ones(1,32);hd(65)=0;//definition of samples
-->hst1=fsfirlin(hd,1);//type 1 filter
-->hst2=fsfirlin(hd,2);//type 2 filter
-->pas=1/prod(size(hst1))*.5;
-->plot2d([fg;fg],[hst1;hst2]);
to a minimum squared error approximation to the desired filter. This section is devoted to the description
of a filter design function which seeks to optimize such an alternative criterion : the minimax or Chebyshev
error approximation.
r(x) = Ax b (3.32)
where
jjrk (x)jj1 = max
k
jrk (x)j: (3.34)
Equation (3.34) defines the supremum norm of the vector r (x). The supremum norm of r (x) for a particular
value of x is the component of r (x) (i.e., the rk (x)) which is the largest. The minimax approximation in
(3.33) is the value of x which, out of all possible values for x, makes (3.34) the smallest.
The minimax approximation can be contrasted by the minimum squared error approximation, x ^2 , as
defined by
x^2 = arg min jjr(x)jj2
x
(3.35)
where
N
X
jjr(x)jj2 = [ rk 2 (x)]1=2 : (3.36)
k=1
There is a relationship between (3.34) and (3.36) which can be seen by examining the class of norms defined
on r (x) by
N
X
jjr(x)jjn = [ rk n (x)]1=n : (3.37)
k=1
For n = 2 the expression in (3.37) is the squared error norm in (3.36) and for n ! 1 the norm in (3.37) be-
comes the supremum norm in (3.34) (which explains the notation jjjj1 ). If r (x) was a continuous function
instead of a discrete component vector then the sum in (3.36) would become an integral and the interpreta-
tion of the approximation in (3.35) would be that the best approximation was the one which minimized the
area under the magnitude of the error function r (x). By contrast the interpretation of the approximation in
(3.33) would be that the best approximation is the one which minimizes the maximum magnitude of r (x).
As an example, consider the system of four linear equations in one unknown:
x = 2
1
x = 1
3
76 CHAPTER 3. FIR FILTERS
x = 4
6
x = 3 (3.38)
15
The plot of the magnitude of the four error functions jrk (x)j, k = 1; 2; 3; 4 is shown in Figure 3.12.
7
|x-2|
6 |x-4|
|x/3-1|
1 |6x/15-3|
0
0 2 4 6 8 10 12
Also shown in Figure 3.12 is a piece-wise continuous function denoted by the cross-hatched segments of
the rk (x). This is the function which represents jjr (x)jj1 as a function of x. Consequently, it is easy to see
which value of x minimizes jjr (x)jj1 for this problem. It is the value of x which lies at the cross-hatched
intersection of the functions jx 2j and j 156 x 3j, that is x^1 = 3:571. The maximum error at this value is
1:571.
By comparison the mean squared error approximation for a system of linear equations as in (3.31) is
x^2 = (AT A) 1 AT b (3.39)
where T denotes the transpose (and assuming that AT A is invertible). Consequently, for the example in
6 ]T and that b = [2; 1; 4; 3]T and thus x^2 = 3:317. The maximum
(3.38) we have that A = [1; 31 ; 1; 15
error here is 1:673. As expected the maximum error for the approximation x ^2 is bigger than that for the
approximation x ^1 .
where
kE (f )k1 = f max
f f
0
jE (f )j
1
(3.42)
is known as both the Chebyshev and the minimax norm of E (f ). The details of the Remez algorithm can be
found in [5].
The function H (f ) is constrained, for our purposes, to the class of functions
N
X
H (f ) = an cos(2fn): (3.43)
n=0
Furthermore, we take the interval of approximation to be [0; :5]. Under these conditions the posed problem
corresponds to digital filter design where the functions H (f ) represent the discrete Fourier transform of an
FIR, linear phase filter of odd length and even symmetry. Consequently, the function H (f ) can be written
N
X
H (f ) = hn e j 2fn (3.44)
n= N
The relationship between the coefficients in (3.43) and (3.44) is an = 2hn for n = 1; 2; : : : ; N and a0 = h0 .
With respect to the discussion in the previous section the problem posed here can be viewed as an
overspecified system of linear equations in the N + 1 unknowns, an , where the number of equations is
uncountably infinite. The Remez algorithm seeks to solve this overspecified system of linear equations in
the minimax sense. The next section describes the Scilab function remezb and how it can be used to design
FIR filters.
--> an=remezb(nc,fg,df,wf)
where df and wf are vectors which are sampled values of the functions D (f ) and W (f ) (see the previous
section for definition of notation), respectively. The sampled values of D (f ) and W (f ) are taken on a grid
of points along the f -axis in the interval [0; :5]. The values of the frequency grid are in the vector fg. The
values of fg are not obliged to be equi-spaced in the interval [0; :5]. In fact, it is very useful, for certain
problems, to specify an fg which has elements which are equi-spaced in only certain sub-intervals of [0; :5]
(see the examples in the following section). The value of nc is the number of cosine functions to be used
in the evaluation of the approximating function H (f ) (see (3.43)). The value of the variable nc must be a
positive, odd integer if the problem is to correspond to an FIR filter. The an are the values of the coefficients
in (3.43) which correspond to the optimal H (f ).
To obtain the coefficients of the corresponding FIR filter it suffices to create a vector hn using the Scilab
commands:
//exec(remez8.code)
hn(1:nc-1)=an(nc:-1:2)/2;
hn(nc)=an(1);
hn(nc+1:2*nc-1)=an(2:nc)/2;
78 CHAPTER 3. FIR FILTERS
Even length filters can be implemented as follows. For an even length filter to have linear phase the filter
must have even symmetry about the origin. Consequently, it follows that the filter must take values at the
points n = 21 ; 32 ; : : : ; N 2 1 and that the frequency response of the filter has the form
N + 21
X
H (f ) = hn e j 2fn : (3.45)
n= N 1
2
Due to the even symmetry of the frequency response, H (f ), (3.45) can be put into the form
N
X 1
H (f ) = bn cos[2(n )f ] (3.46)
n=1
2
where the relationship between the hn in (3.45) and the bn in (3.46) is h(n) = 12 b(N n) for n =
1; 2; : : : ; N .
The expression for H (f ) in (3.46) can be rewritten so that
X1
N
H (f ) = cos(f ) ~bn cos(2nf ): (3.47)
n=0
where b(n) = 21 [~b(n 1) + ~b(n)] for n = 2; 3; : : : ; N 1 and b(1) = ~b(0) + 21 ~b(1) and b(N ) = 12 ~b(N 1).
Since the expression in (3.47) is identical to that in (3.43) all that is required to make the function remezb
work is a change in the values of the desired and weight vectors by the factor cos 1 (f ). That is, the
arguments given to the function remezb are ddf and wwf where ddf = df= cos(f ) and wwf =
wf cos(f ). Caution must be used in choosing the values of fg since for f = :5 the division of df by
cos(f ) = 0 is not acceptable. The output, an, of the function can be converted to the filter coefficients hn
by using the Scilab commands
//exec(remez2.code)
hn(1)=.25*an(nc);
hn(2:nc-1)=.25*(an(nc:-1:3)+an(nc-1:-1:2));
hn(nc)=.5*an(1)+.25*an(2);
hn(nc+1:2*nc)=hn(nc:-1:1);
Noting that the form of (3.47) has the term cos(f ) as a factor, it can be seen that H (:5) = 0 regardless
of the choice of filter coefficients. Consequently, the user should not attempt to design filters which are of
even length and which have non-zero magnitude at f = :5.
-->nc=21;
-->ngrid=nc*250;
-->fg=.5*(0:(ngrid-1))/(ngrid-1);
-->ds(1:ngrid/2)=ones(1:ngrid/2);
-->ds(ngrid/2+1:ngrid)=0*ones(1:ngrid/2);
-->wt=ones(fg);
-->an=remezb(nc,fg,ds,wt)
an =
! 0.5000000 !
! 0.6369345 !
! 1.405D-07 !
! - 0.2131882 !
! - 1.037D-07 !
! 0.1289952 !
! 6.083D-08 !
! - 0.0933182 !
! - 2.101D-07 !
! 0.0738747 !
! 3.184D-07 !
! - 0.0618530 !
! - 0.0000011 !
! 0.0538913 !
! 0.0000022 !
! - 0.0484436 !
! - 0.0000100 !
! 0.0447016 !
! - 0.0000202 !
! - 0.5168409 !
! 0.0000417 !
! 0. !
As described in the previous section the cosine coefficients an are converted into the coefficients for a even
symmetry FIR filter which has frequency response as illustrated in Figure 3.13.
The error of the solution illustrated in Figure 3.13 is very large; it can become reasonable by leaving a
transition band when giving the specification of the frequency grid. The following example shows how this
is done; remezb is specified as follows :
-->nc=21;
80 CHAPTER 3. FIR FILTERS
1.6
1.4
1.2
1.0
0.8
0.6
0.4
0.2
0
0 0.1 0.2 0.3 0.4 0.5
Figure 3.13: exec(remez2 4.code) Low Pass Filter with No Transition Band
-->ngrid=nc*16;
-->fg=(0:-1+ngrid/2)*.24*2/(ngrid-2);
-->fg(ngrid/2+1:ngrid)=fg(1:ngrid/2)+.26*ones(1:ngrid/2);
-->ds(1:ngrid/2)=ones(1:ngrid/2);
-->ds(ngrid/2+1:ngrid)=0*ones(1:ngrid/2);
-->wt=ones(fg);
Here the frequency grid fg is specified in the intervals [0; :24] and [:26; :5] leaving the interval [:24; :26] as
an unconstrained transition band. The frequency magnitude response of the resulting filter is illustrated in
Figure 3.14. As can be seen the response in Figure 3.14 is much more acceptable than that in Figure 3.13.
A third and final example using the function remezb is illustrated below. In this example the desired
function is triangular in shape. The input data was created using the following Scilab commands
-->nc=21;
-->ngrid=nc*16;
-->fg=.5*(0:(ngrid-1))/(ngrid-1);
3.3. OPTIMAL FILTERS 81
1.2
1.0
0.8
0.6
0.4
0.2
0
0 0.1 0.2 0.3 0.4 0.5
Figure 3.14: exec(remez2 4.code) Low Pass Filter with Transition Band [:24; :26]
-->ds(1:ngrid/2)=(0:-1+ngrid/2)*2/(ngrid-2);
-->ds(ngrid/2+1:ngrid)=ds(ngrid/2:-1:1);
-->wt=ones(fg);
The resulting frequency magnitude response is illustrated in Figure 3.15.This example illustrates the strength
of the function remezb. The function is not constrained to standard filter design problems such as the class
of band pass filters. The function is capable of designing linear phase FIR filters of any desired magnitude
response.
-->nf=32;
-->bedge=[00.2;.220.28;.30.5];
-->des=[1 0 1];
82 CHAPTER 3. FIR FILTERS
1.0
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
0 0.1 0.2 0.3 0.4 0.5
-->wate=[1 1 1];
The resulting magnitude response of the filter coefficients is shown in Figure 3.16. As can be seen the design
is very bad. This is due to the fact that the design is made with an even length filter and at the same time
requires that the frequency response at f = :5 be non-zero.
The same example with nf = 33 is run with the result shown in Figure 3.17.
The final example is that of a high pass filter whose input parameters were created as follows:
-->nf=33;
-->bedge=[00.35;.380.5];
-->des=[0 1];
-->wate=[1 1];
1.9
1.7
1.5
1.3
1.1
0.9
0.7
0.5
0.3
0.1
0 0.1 0.2 0.3 0.4 0.5
1.2
1.0
0.8
0.6
0.4
0.2
0
0 0.1 0.2 0.3 0.4 0.5
1.2
1.0
0.8
0.6
0.4
0.2
0
0 0.1 0.2 0.3 0.4 0.5
Thus, h(! ) is the spectrum of the output of a linear filter which admits a white noise as input. We shall
consider in this section only prototype lowpass filters, i.e., ideally we want to obtain h(! ) = 0 for ! > !c
and h(! ) = 1 for ! < !c . Highpass, bandpass and stopband filters are then easily constructed by a simple
change of variables.
The construction consists of finding a function H2 of the complex variable s such that H2 (s) = H (s)H ( s)
(i.e., is symmetric with respect to the imaginary axis and such that H2 (i! ) = h2 (! ) along the imaginary
axis). Furthermore, the function H2 (s) will be chosen to be rational and, consequently, defined by its poles
and zeros.
The transfer function of the filter, H (s), will then be defined by selecting all the poles and zeros which
lie in the left hand side of the complex s-plane. In this way we obtain a stable and minimum phase filter.
1
h2n (!j!c ) = ! 2n (4.2)
1+( )
!c
Here, !c is the cutoff frequency and n the order. A typical response can be plotted with the function
buttmag (see Figure 4.1):
The following code gives an example of the squared magnitude of a Butterworth filter of order 13 (see
Figure 4.1).
85
86 CHAPTER 4. IIR FILTERS
-->h=buttmag(13,300,1:1000);
-->mag=20*log(h)/log(10);
-->plot2d((1:1000),mag,[1],"011"," ",[0,-180,1000,20]),
20
-20
-40
-60
-80
-100
-120
-140
-160
-180
0 100 200 300 400 500 600 700 800 900 1000
From Figure 4.1 we see that the magnitude is a decreasing function of the frequency. Also we see that
1
h2n (!c j!c) =
2
independently of the order n.
Let us define now the stable transfer function H (s) (Butterworth filter) by:
k0
H (s) = Qn
k=1 (s pk )
where
pk = ei[1=2+(2k 1)=2n] k = 1; : : : ; n
This is done by the small function zpbutt which computes the poles pk and the gain k0 :
For instance, with n=7 and !c = 3, we obtain the following transfer function:
-->n=7;
4.1. ANALOG FILTERS 87
-->omegac=3;
-->[pols,gain]=zpbutt(n,omegac);
-->h=poly(gain,s,coeff)/real(poly(pols,s))
h =
2187
------------------------------------------------------------------
2 3 4
2187 + 3276.0963s + 2453.7738s + 1181.9353s + 393.97843s
5 6 7
+ 90.880512s + 13.481878s + s
The poles pk of H are located on the unit circle and are symmetric with respect to the real axis as is
illustrated in Figure 4.2. The figure was obtained as follows:
-->n=13;
-->angles=ones(1,n)*(%pi/2+%pi/(2*n))+(0:n-1)*%pi/n;
-->xset("mark",0,1);
-->lim=1.2*sqrt(2.);
-->plot2d(real(s),imag(s),[-3],"012"," ",[-lim,-1.2,lim,1.2]);
-->xarc(-1,1,2,2,0,360*64);
-->xsegs([-lim,0;lim,0],[0,-1.2;0,1.2])
1
We note the symmetry of the coefficients in H (s) i.e., that H (s) = H~ (s) = sn H ( ) , which follows
s
1
from the fact that for each pole pk there corresponds the pole = pk . Also, we see that H ( s) is ob-
pk
tained in the same way as H (s) by selecting the (unstable) poles pk instead of the pk . Since the set
f(pk ; pk ) k = 1; : : : ; ng is made with the 2n roots of the polynomial p(s) = 1 + ( s2 )n. Thus, we
have:
1
H (s)H ( s) =
1 + ( s2 )n
88 CHAPTER 4. IIR FILTERS
It follows immediately from (4.1) that H (s) realizes the response (4.2).We see that H (s) is obtained by a
very simple spectral factorization of p(s), which here can be done analytically.
Order determination: The filter order, n, completely specifies a Butterworth filter. In general n is de-
termined by giving a desired attenuation A1 at a specified normalized frequency f = !!rc . The filter order,
n, is given by the solution of A12 = h2n (f ). We obtain immediately:
log10 (A2 1)
n= (4.3)
2 log10 (f )
4.1.2 Chebyshev filters
The nth order Chebyshev polynomial Tn (x) is defined recursively by:
Tn+1 (x) = 2xTn (x) Tn 1 (x)
T0 (x) = 1 T1 (x) = x
It may be shown that Tn (x) is given more explicitly by:
cos(n cos 1 (x)) if jxj < 1
Tn (x) = cosh(n cosh 1 (x)) otherwise
(4.4)
The recursive function chepol implements this computation: We note that the roots of Tn are real and
symmetric with respect to the imaginary axis. These polynomials are used to analytically define the squared-
magnitude of the frequency response for a class of analog filters.
This function is completely specified once its three parameters (!c ; ; n) are given.
Using chepol, it is easy to compute the squared-magnitude response (4.5). The function cheb1mag
evaluates h21;n (! j !c ; ) for a given sample vector of ! 0 s. Note that for any value of n one has
1
h21;n (!c j !c ; ) =
1 + 2
The function h1 is decreasing for ! > !c with fast convergence to zero for large values of the order n.
The number of oscillations in the passband is also increasing with n. If at ! = !r > !c , h21;n reaches the
value A12 then the parameters (!c ; ; n) and (A; !r ) are linked by the equation h21;n (!r j!c ; ) = A12 which
may be written also as
!
A2 = 1 + 2 Tn2 ( r ) (4.6)
!c
!
Using (4.4) this latter equation may be solved more explicitly: n cosh 1 (f ) = cosh 1 (g) with f = r and
!c
g= A2 1.
Below is an example of the magnitude plotted in Figure 4.3.
-->n=13;epsilon=0.2;omegac=3;sample=0:0.05:10;
-->h=cheb1mag(n,omegac,epsilon,sample);
-->plot(sample,h,frequencies,magnitude)
magnitude
1.0
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
frequencies
0
0 1 2 3 4 5 6 7 8 9 10
Let us now calculate the transfer function of a Type 1 Chebyshev filter. The transfer function is all-pole
and the poles lie on an ellipse which can be determined totally by specifying the parameter , the order n and
1
the cutoff frequency !c . The horizontal and vertical rays a and b of this ellipse are given by: a = !c
2
+
1
and b = !c where
2
p 1=n
1 + 1 + 2
=( )
The poles (pk = k + i
k ; k = 1; 2; : : : ; n) are simple and, in order to have a stable filter, are regularly
spaced over the left hand side of the ellipse. The function zpch1 computes the poles (and the gain) of a
Type 1 Chebyshev filter.
With the function zpch1 we can now calculate the transfer function which realizes the preceding ex-
ample and recover the desired magnitude. Compare Figures 4.3 and 4.4, the latter figure being obtained as
follows:
-->n=13;epsilon=0.2;omegac=3;sample=0:0.05:10;
-->[p,gain]=zpch1(n,epsilon,omegac);
-->tr_fct=poly(gain,s,coef)/real(poly(p,s))
tr_fct =
1946.1951
-----------------------------------------------------------------
2 3 4
1946.1951 + 7652.7444s + 14314.992s + 18875.541s + 17027.684s
5 6 7 8
+ 13282.001s + 7398.971s + 3983.2216s + 1452.2192s
9 10 11 12 13
+ 574.73496s + 131.30929s + 39.153835s + 4.4505809s + s
-->rep=abs(freq(tr_fct(2),tr_fct(3),%i*sample));
-->plot(sample,rep,frequencies,magnitude)
-->xend()
4.1. ANALOG FILTERS 91
magnitude
1.0
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
frequencies
0
0 1 2 3 4 5 6 7 8 9 10
Order determination: We have seen that the parameter specifies the size of the passband ripple and !c
is the passband edge, thus, one has
1
1 + 2
h21;n(! j !c) 1 for 0 ! !c
The order n is generally determined by specifying a desired attenuation A1 at a given normalized frequency
f = !!rc . As in (4.6), n is given by the solution of A12 = h21;n (f j!c; ):
p p
cosh 1 ( A2 1 ) log(g + (g2 1))
n= = p
cosh 1 (f ) log(f + (f 2 1)
p
where g = ( A 2 1 )
2
Here !r is the passband edge and A the attenuation at !r . The function cheb2mag computes the squared-
magnitude response. Note that the sample vector must not include the value zero. Also, for any value of the
order n one has:
1
h22;n (!r j !r ; A) = 2
A
The function is decreasing for 0 < ! < !r and displays ripple for ! > !r .
Also note that when the equation (4.6) is satisfied both Type 1 and type 2 functions h1;n and h2;n take
the same values at !c and !r :
1
h21;n (!r j!c; ) = h22;n (!r j!r ; A) = 2
A
92 CHAPTER 4. IIR FILTERS
1
h22;n (!c j!c; ) = h22;n (!cj!r ; A) =
1 + 2
We can now plot for example a squared-magnitude response for the following specifications: 1=A =
0:2; !r = 6; and n = 10. The sample vector of !s is chosen as 0:0.05:10. The magnitude plotted in dB
is given by Figure 4.5, and was generated by the following code:
-->n=10;omegar=6;A=1/0.2;sample=0.0001:0.05:10;
-->h2=cheb2mag(n,omegar,A,sample);
-->plot(sample,log(h2)/log(10),frequencies,magnitude in dB)
-->minval=(-maxi(-log(h2)))/log(10);
-->plot2d([omegar;omegar],[minval;0],[1],"000");
-->attenuation=-log(A*A)/log(10);
-->plot2d(sample,attenuation*ones(sample),[2],"000")
magnitude in dB
0
-1
-2
-3
-4
frequencies
-5
0 1 2 3 4 5 6 7 8 9 10
The transfer function of a type 2 Chebyshev filter has both poles and zeros. The zeros are imaginary and
are located at
!r
zk = i k = 1; 2; : : : ; n
cos( (2k2n1) )
The poles pk = k + i
k k = 1; 2; : : : ; n are found by solving for the singularities of the denominator
of h. They are defined by:
k
k =
k 2 + k 2
k
k =
k 2 + k 2
where
(2k 1)
k = a sin( )
2n
(2k 1)
k = b cos( )
2n
and
1
a=
2
+
1
b=
2
p 1=n
= (A + A2 1)
The function zpch2 computes the poles and zeros of a type 2 Chebyshev filter, given its parameters
(!r ; A; n), according to the preceding formulas.
Let us consider the preceding example: we had n = 10, !r = 6, A = 5.
-->n=10;
-->omegar=6;
-->A=1/0.2;
-->[z,p,gain]=zpch2(n,A,omegar);
-->num=real(poly(z,s)); //Numerator
-->den=real(poly(p,s)); //Denominator
2 4 6 8 10
6.192D+09 + 4.300D+08s + 10450944s + 103680s + 360s + 0.2s
----------------------------------------------------------------
2 3 4
6.192D+09 + 1.526D+09s + 6.179D+08s + 1.069D+08s + 20878805s
5 6 7 8
94 CHAPTER 4. IIR FILTERS
Order determination: We have seen that the parameter A specifies the size of the passband ripple and !r
is the stopband edge. Thus, one has
1
0 h22;n (! j !r ; A) 2 for !r !
A
The order n is generally determined by specifying a desired attenuation 1+12 at a given normalized fre-
quency f = !!rc (remember that in order to define a type 2 Chebyshev filter !r must be given). In a similar
way as in (4.6), n is given by the solution of 1+12 = h22;n (f j!r ; A). Because of the symmetry in and A we
obtain the same solution as for type 1 filters:
p p
cosh 1 ( A2 1 ) log(g + (g2 1))
n= = p
cosh 1 (f ) log(f + (f 2 1)
r
A2 1
where g =
2
4.1.3 Elliptic filters
The elliptic filter presents ripple in both the passband and stopband. It is based on the properties of the
Jacobian elliptic function (see [8],[1]) that we briefly introduce now.
Elliptic integral
Let us define for z in the complex plane the function
Z z
dt
u(z ) = (4.7)
0 (1 t2 )1=2 (1 mt2 )1=2
where m is a real constant 0 < m < 1. (We will also use the notation u(z; m) when necessary.)
We may assume that the functions u1 = (1 t2 ) 2 and u2 = (1 mt2 ) 2 are defined e.g. in the domain
1 1
D made of the complex plane cut along the lines fz; Re(z) = 1 and Im(z) < 0g and fz; Re(z) = p1m
and Im(z ) < 0g. In other words we may choose for these complex functions the determination of the phase
between =2 and 3=2. These functions are then completely specified in D by analytic continuation once
we have fixed their values at 0 as being +1.
Let us define now in the above open connected domain D the function
1 1
(t) = =
u1 (t)u2 (t) (1 t2 ) 2 (1 mt2 ) 21
1
and consider the path S which encircles the positive right quarter of the complex plane composed of the
positive real axis, the point at infinity and the imaginary axis traversed from 1 to zero.
As t increases along the positive real axis the function (t) first assumes positive real values for 0
p p
t < 1, then for 1 < t < 1= m, (t) assumes purely imaginary values and for t > 1= m, (t) assumes
4.1. ANALOG FILTERS 95
real negative values. At 1 we have (t) = 0 and as t decreases from 1 to 0 along the imaginary axis (t)
assumes purely imaginary values.
Let us examine now the consequences of these properties on the function u. When z traces the same
path S the function u(z ) traces the border of a rectangle R0 with corners at (O; K; K + iK 0 ; iK 0 ), each
side being the image of the four parts of the strip S defined above. This follows from the identities:
Z 1 Z 1
K (m) = (t)dt = (t)dt
0 p1m
and Z p1m Z 1
iK 0 (m) = (t)dt = (it)dt
1 0
Thus the points (0; 1; p(1m) ; 1) of the real axis are respectively mapped by u into the points (0; K; K +
iK 0 ; iK 0 ) of the complex plane and the intervals (0; 1),(1; p1m ),( p1m ; 1) are respectively mapped into the
intervals (0; K ),(K; K + iK 0 ),(K + iK 0 ; iK 0 ).
It may be shown that u realizes a conformal mapping of the first quadrant of the complex plane into
the rectangle R0 . In particular any point z with Re(z ) 0 and Im(z ) 0 admits an unique image in
the rectangle. In a similar way we can map, under u, each of the four quadrants of the complex plane into
a rectangle R (called the fundamental rectangle of periods) with corners at ( K iK 0 ; K iK 0 ; K +
iK 0 ; K + iK 0 ), made of four smaller rectangles defined as R0 above and having the origin as common
point. The function u defines a one-to-one correspondence of the complex plane into R.
The function u has been implemented as the %asn function. This function may receive a real vector x
as argument. The calculation is made componentwise. A specific algorithm [4] is implemented in fortran.
We note that it sufficient to be able to compute u(x) for x 2 (0; 1) to have u(z ) for all nonnegative real and
purely imaginary values z thanks to the following changes of variable:
Z x y Z
dt dt
1 2 1 2 =
1 (t2 1) (1 mt2 )
= =
0 (1 t2 ) (1 m1 t2 )1=2
1 =2
with m1
2 p
= 1 m , y2 = m11 x x2 1 and x 2 (1; 1= m)
Z x Z y
dt dt
1=2 =
pm (t2
1
1) (mt2 1)1=2 0 (1 t2 )1=2 (1 mt2 )1=2
with y 2 = mx1 2 and x 2 (1=
pm; 1)
Z x y Z
dt dt
1 2 1 2 =
0 (1 + t2 ) (1 + mt2 )
= =
0 (1 t2 ) (1 m1 t2 )1=2
1 =2
with m1 = 1 m and y 2 = 1+x x2 , which gives u for purely imaginary values of its argument.
2
We can now for example use %asn to plot three sides of the rectangle R0 as the image by %asn of
the three associated real intervals (see Figure 4.6). Here m = 0:8 and we see that how a linear scale is
transformed by %asn (parametric plot). In particular at x = 10 the point iK 0 is not reached (as expected).
-->//The rectangle R0
-->m=0.8+%eps;
-->z=%asn(1/sqrt(m),m);
96 CHAPTER 4. IIR FILTERS
-->K=real(z);KT=imag(z);
-->x2max=1/sqrt(m);
-->x1=0:0.05:1;x2=1:((x2max-1)/20):x2max;x3=x2max:0.05:10;
-->x=[x1,x2,x3];
-->rect=[0,-KT,1.1*K,2*KT]
rect =
-->y=%asn(x,m);
-->plot2d(real(y),imag(y),[1],"011"," ",rect);
-->xtitle( ,real(y),imag(y))
-->[n1,n2]=size(x)
n2 =
220.
n1 =
1.
-->x1=0:0.5:1;x2=1:0.3:x2max;x3=x2max:1:10;
-->x1=[0,0.25,0.5,0.75,1.0,1.1,1.2,1.3,1.4,2,3,4,10]
x1 =
column 1 to 10
column 11 to 13
! 3. 4. 10. !
-->rect=[0,-KT,1.1*K,2*KT]
rect =
-->y1=%asn(x1,m);
4.1. ANALOG FILTERS 97
-->xnumb(real(y1),imag(y1)+0.1*ones(imag(y1)),x1)
-->plot2d(real(y1),imag(y1),[-2],"011"," ",rect);
imag(y)
3.32
2.82
2.32
1.33 1.1
0.83
0.33
0 0.25 0.5 0.75 1
-0.17
-0.66
-1.16
real(y)
-1.66
0.000 0.248 0.497 0.745 0.993 1.241 1.490 1.738 1.986 2.235 2.483
Figure 4.6: exec(analog6.code) The rectangle R0 , image by u of the positive real axis.
The integrals K and K 0 are known as the complete elliptic integral: they may be calculated by %asn
since we have K (m) + iK 0 (m) = u( p 1 ; m). These numbers may also be calculated by the Arithmetic-
(m)
Geometric-Mean algorithm which is implemented as the %K function. Note that here m can be vector-valued
and %K computes K (m) componentwise (this fact will be useful later).
Elliptic function
For y inside the fundamental rectangle R the Jacobian elliptic function sn is defined as the inverse function
of u i.e. we have for a fixed value of the parameter m:
u(z ) = y , z = sn(y)
In particular we have for the corners of the rectangle R0 defined above: sn(0) = 0, sn(K ) = 1,
sn(K + iK 0 ) = p1m , sn(iK 0 ) = 1. In fact, the function sn may be extended to the full complex plane as
a meromorphic function.
Indeed,the symmetry principle states that if f is an analytic function defined in an open set D whose
boundary contains an interval L of the complex plane and if in addition this interval is itself mapped by f
into another interval L0 = f (L) of the complex plane, then f can be extended to the set (D ), symmetric
set of D with respect to L, by the formula f ( (z )) = 0 (f (z )) where and 0 are the symmetries with
respect to L and L0 respectively.
98 CHAPTER 4. IIR FILTERS
Since the sides of the fundamental rectangle are mapped into intervals of the real and imaginary axis of
the complex plane by sn, it may be easily shown that the function sn may be extended to the full complex
plane by successive symmetries leading to a doubly periodic function with periods 4K and 2iK 0 .
For real values of its argument, sn(y ) behaves like the sine function and for purely imaginary values
of its argument, sn(y ) is purely imaginary and has poles at : : : ; 3iK 0 ; iK 0 ; iK 0 ; 3iK 0 ; : : :. For y in the
interval ( iK 0 ; +iK 0 ), sn(y ) behaves like i times the tan function and this pattern is repeated periodic-
ally. For m = 0, one has K = =2, K 0 = 1 and sn coincides with the sin function. For m = 1, one has
K = 1, K 0 = =2 and sn coincides with the tanh function.
The function sn has been implemented by the following function %sn which calls a fortran routine for
real values of the argument, and use the addition formulas ([1]) for imaginary values of the argument. Note
that x is allowed to be complex and vector-valued.
Let us plot for example the real and imaginary behavior of sn; this is done by the following commands
which produce the Figures 4.7 and 4.8 and give respectively sn(x) for 0 x 4K and sn(iy ) for
0 y 3K 0 =2.
-->m=0.36; //m=k2
-->K=%k(m);
-->real_val=0:(P/50):P;
-->plot(real_val,real(%sn(real_val,m)),x real,sn(x))
sn(x)
1.0
0.8
0.6
0.4
0.2
-0.2
-0.4
-0.6
-0.8
x real
-1.0
0 1 2 3 4 5 6 7 8
For imaginary values of the argument we must take care of the pole of sn(z ) at z = iK 0 :
4.1. ANALOG FILTERS 99
-->m=0.36; //m=k2
-->KT=%k(1-m);
-->ima_val1=[0.:(Ip/50):(KT-0.01)];
-->ima_val2=[(KT+0.01):(Ip/50):(Ip+KT)];
-->z1=%sn(%i*ima_val1,m);z2=%sn(%i*ima_val2,m);
-->rect=[0,-30,Ip+KT,30];
-->plot2d([KT,KT],[-30,30],[1],"011", ,rect);
-->plot2d([-30,30],[0,0],[1],"000");
-->plot2d(ima_val1,imag(z1),[1],"000");
-->plot2d(ima_val2,imag(z2),[1],"000");
sn(x)
30
24
18
12
-6
-12
-18
-24
x imaginary
-30
0.00 0.60 1.20 1.80 2.39 2.99 3.59 4.19 4.79 5.39 5.99
The positions of poles and zeros of the sn function will allow to define the squared magnitude response of
a prototype lowpass elliptic filter. The zeros of the sn function are located at 2pK + 2qiK 0 ,where p and q
are arbitrary integers and its poles are located at 2pK + (2q + 1)K 0 .
For a fixed value of the parameter m = m1 , let us consider a path n joining the points (0; nK1 ; nK1 +
iK 0 1 ; iK 0 1 ) with n an odd integer and denoting K1 = K (m1 ) and K 0 1 = K (1 m1 ). From the discussion
above we see that for z 2 (0; nK1 ) the function sn(z ) oscillates between 0 and 1 periodically as shown in
Figure 4.7. For z 2 (nK1 ; nK + iK 0 1 ), sn(z ) assumes purely imaginary values and increases in magnitude,
with (real) limit values sn(nK1 ) = 1 and sn(nK1 + iK 0 1 ) = pm 1 . Finally for z 2 (nK + iK1 0 ; iK1 0 ),
1
1
v(z ) = (4.8)
1 + 2 sn2(z; m1 )
Clearly, v(z ) oscillates between 1 and 1+12 for z 2 (0; nK1 ) and between 0 and 1+1
2
for z 2 (nK1 +
m1
iK1 0 ; iK1 0 ).
Also, clearly v (z ) is a continuous function of z , which is real-valued for z in the path n
and if we chose the parameter m1 = A2 1 we can obtain an interesting behavior. The function ell1mag
2
computes v (z ) for a given sample vector z in the complex plane and for given parameters and m1 .
Now, we define the vector z = [z1 ; z2 ; z3 ] as a discretization of the path n , with z1 a dicretization of
(0; nK1 ), z2 a discretization of (nK1 ; nK1 + ik1 0 ) and z3 a discretization of (nK1 + iK1 0 ; iK1 0 ). Then we
can produce Figure 4.9 which clearly shows the behavior of v (z ) for the above three parts of z .
-->n=9;eps=0.2;A=3;m1=eps*eps/(A*A-1);
-->K1=%k(m1);K1T=%k(1-m1);
-->z1max=n*K1;z2max=K1T;
-->z1=0:(z1max/100):z1max;
-->z2=%i*(0:(z2max/50):z2max);z2=z2+z1max*ones(z2);
-->z3=z1max:-(z1max/100):0;z3=z3+%i*z2max*ones(z3);
-->plot(ell1mag(eps,m1,[z1,z2,z3]));
-->omc=prod(size(z1));
-->omr=prod(size([z1,z2]));
-->plot2d([omc,omc],[0,1],[2],"000");
-->plot2d([omr,omr],[0,1],[2],"000");
4.1. ANALOG FILTERS 101
1.1
0.9
0.7
0.5
0.3
0.1
-0.1
0 40 80 120 160 200 240 280
Of course, many other paths than n are possible, giving a large variety of different behaviors. Note
that the number of oscillations in both the passband and stopband is n, an arbitrary odd integer and the
amplitudes of the oscillations are entirely specified by the choice of the parameter m1 .
Thus, we have obtained a function v whose behavior seems to correspond to a good squared magnitude
for the prototype filter that we want to realize. However, this function is defined along the path n of the
complex plane. Since frequencies, ! , are given as positive real values we must find a mapping of the positive
real axis onto the path n . But this is precisely done by the function u(z ) = sn 1 (z ) given in (4.7) or more
generally, after scaling by the function sn 1 ( !zc ; m) + . Indeed, as we have seen, such a function maps
the positive real axis into the border of a rectangle R(; ; m). The size of this rectangle depends on the
parameter m and we have to chose m; ; such that R(; ; m) = n .
To be more specific, we have to choose now the value of the parameter m such that:
sn(nK1 ; m) + = !c (4.9)
sn(nK1 + iK 0 1 ; m) + = !r (4.10)
Recalling that sn 1 (1; m) = K (m) and sn 1 ( p1m ; m) = K (m) + iK 0 (m) we see that to satisfy these
equations we must chose
nK1 K1 0
= = 0
K K
and
= 0 if n is odd
K1 if n is even
K 0 (m1 ) K (m) 1
n= =
K (m1 ) K 0 (m)
(4.11)
102 CHAPTER 4. IIR FILTERS
0(m1 ) K (1 m1 ) 0
K (m) K (1 m)
(We note 1 = K K (m1 ) = K (m1 ) and = K (m) = K (m) ). Usually m1 is small (close to 0) which
yields 1 large, and m is large (close to 1) which yields large.
In practice very good specifications are obtained with rather low orders. In order to plot the frequency
response magnitude of an elliptic prototype lowpass filter we can proceed as follows: first select the ripple
K0
parameters and A and compute m1 = A2 1 and 1 = K11 , then for various integer values of n compute
2
m such that equation (4.11) is satisfied or until the ratio !!rc is acceptable.
See Figure 4.10
-->mm1=0:0.01:1;mm1(1)=0.00000001;mm1(101)=0.9999;
-->m=0*mm1;n=3;i=1;
-->anorm=1.-2.*%eps;
-->for m1=mm1,
--> y=%asn(anorm/sqrt(m1),m1);
--> K1=real(y);
--> K12=imag(y);
--> chi1=K12/K1;
--> m(i)=findm(chi1/n);
--> i=i+1;
-->end,
-->plot(real(log(mm1)),real(log(m))),
Much flexibility is allowed in the choice of the parameters, provided that equation (4.11) is satisfied.
The functions find freq and find ripple may be used to find the stopband edge !r when !c , , A,
and n are given and to find when the parameters n, !c , !r , and A are given.
The following code shows how to find compatible parameters and produce Figure 4.11.
-->deff([alpha,beta]=alpha_beta(n,m,m1),...
-->if 2*int(n/2)=n then, beta=K1; else, beta=0;end;...
-->alpha=%k(1-m1)/%k(1-m);)
Warning: obsolete use of = instead of ==
if 2*int(n/2)=n then, beta=K1; else, beta=0;end;alpha=%k(1-m1)/%k(1-m);
!
at line 2 of function alpha_beta called by :
beta=0;end;alpha=%k(1-m1)/%k(1-m);
-->epsilon=0.1;
-1
-2
-3
-4
-5
-20 -18 -16 -14 -12 -10 -8 -6 -4 -2 0
-->m1=(epsilon*epsilon)/(A*A-1);n=5;omegac=6;
-->m=find_freq(epsilon,A,n);
-->omegar = omegac/sqrt(m)
omegar =
6.8315017
-->%k(1-m1)*%k(m)/(%k(m1)*%k(1-m))-n //Check...
ans =
1.776D-15
-->[alpha,beta]=alpha_beta(n,m,m1)
beta =
0.
alpha =
3.5754638
-->alpha*%asn(1,m)-n*%k(m1) //Check
ans =
3.553D-15
104 CHAPTER 4. IIR FILTERS
-->sample=0:0.01:20;
-->z=alpha*%asn(sample/omegac,m)+beta*ones(sample);
-->plot(sample,ell1mag(epsilon,m1,z))
1.0
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
0 2 4 6 8 10 12 14 16 18 20
The design of an elliptic filter is more complex than for the filters that we have defined until now. First the
parameters n, m1 , and m which characterize the squared magnitude response cannot be chosen independ-
ently (see (4.11)). We have seen how to solve this difficulty. Second, the squared magnitude response is not
a rational function and moreover it has an infinite number of poles and zeros.
The construction is accomplished in two steps: first a transformation is made in the complex plane which
maps the real axis to the imaginary axis and transforms the rectangular path n to a rectangular path 0n
in the LHS of the complex plane. Then the elliptic function sn is used to perform a transformation which
maps the imaginary axis into 0n . Finally, only poles and zeros which are inside 0n are kept for the transfer
function.
Let us consider the pole-zero pattern of the function v (z ). Clearly, the poles of sn(z ) become double
zeros of v (z ) and the poles of v (z ) are found by solving the equation:
1 + 2 sn2 (z ) = 0
4.1. ANALOG FILTERS 105
Thus the zeros of v (z ) in n are located at i K 0 ; i K 0 + 2K; i K 0 + 4K; : : : ; i K 0 + 2p K and the poles
of v (z ) in n are located at i u0 ; i u0 + 2K; i u0 + 4K; : : : ; i u0 + 2p K with 2p + 1 = n and where we have
noted u0 = sn 1 ( i ; m1 ).
0
Consider now the transformation = i KK0 ((mm1)) u = i nK K (m)
(m1 ) u (n being given in (4.11)). The above
pole-zero pole pattern is mapped inside the LHS of the complex plane and the contour n is mapped into
0n = (0; i K; i K 0 + K; K 0 ), and these points are respectively the image of the points (0; i !c ; i !r ; i 1)
of the imaginary axis by the function z ! i !c sn( iz; m).
The function zpell performs these transformations and computes the poles and zeros of a prototype
elliptic filter.
We illustrate the use of this function by the following example which uses the preceding numerical
values of the parameters , A, !c , !r . The code produces Figure 4.12.
-->//Filter with zpell
-->m1=(epsilon*epsilon)/(A*A-1);n=5;omegac=6;
-->m=find_freq(epsilon,A,n);
-->omegar = omegac/sqrt(m)
omegar =
6.8315017
-->[z,p,g]=zpell(epsilon,A,omegac,omegar);
-->num=real(poly(z,s));den=real(poly(p,s));
-->transfer=g*num/den
transfer =
2 4
10783.501 + 340.56385s + 2.454884s
----------------------------------------------------------------
2 3 4 5
10783.501 + 3123.7307s + 773.85348s + 120.79402s + 11.89508s + s
-->sample=0:0.01:20;
-->rep=freq(g*num,den,%i*sample);
-->plot(sample,abs(rep))
106 CHAPTER 4. IIR FILTERS
1.0
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
0 2 4 6 8 10 12 14 16 18 20
1 X 1 2k
H (z )jz=esT = H (s + j ): (4.12)
T k= 1 T
The approximation in (4.12) takes z = esT . Consequently, the left half s-plane maps into the unit circle in
the z-plane, the right half s-plane maps outside the unit circle, and the j! -axis in the s-plane maps to the
unit circle in the z-plane. Thus, this approximation technique preserves causal, stable filters. However, since
(4.12) consists of a superposition of shifted versions of H (s) along the j! -axis, aliasing can occur if the
analog filter is not bandlimited.
Because most analog filter design techniques do not yield bandlimited filters aliasing is a problem.
For example, a high pass filter cannot be bandlimited. Furthermore, because of aliasing distortion, filter
specifications pertaining to band widths and errors are not necessarily preserved under the impulse invariance
approximation.
In the following section two alternative approximation techniques are discussed. Each of these tech-
niques avoids problems associated with aliasing.
4.3. APPROXIMATION OF ANALOG FILTERS 107
and A(s) and B (s) are polynomial functions of s. The relationship between the input, X (s), and the output,
Y (s), of the filter in (4.13) can be expressed as
Y (s) = H (s)X (s) (4.14)
where the fan g and the fbm g are the coefficients of the polynomial functions A(s) and B (s), respectively.
The relationship between the input and the output in the time domain is directly inferred from (4.15),
N M
X dn X dm
an y (t ) = b m x(t): (4.16)
n=0
dtn m=0
dtm
The differential equation in (4.16) can be approximated by using the Backward Difference Formula approx-
imation to the derivative. That is, for T small we take
Because the operation in (4.17) is linear and time-invariant the approximation can be represented by the
z-transform,
1 z 1
Z fy0 (n)g = ( )Z fy(n)g (4.18)
T
where Z fg represents the z-transform operation and y 0 (n) and y (n) are sampled sequences
of the time
0
functions y (t) and y (t), respectively.
Higher order derivatives can be approximated by repeated application of (4.17) which in turn can be
represented with the z-transform by repeated multiplication by the factor (1 z 1 )=T . Consequently, the
result in (4.16) can be approximately represented by the z-transform as
N
X 1 z 1 n XM
1 z 1 m
[ an ( ) ]Y (z ) = [ bm ( ) ]X (z ): (4.19)
n=0
T m=0
T
Comparing (4.19) to (4.15) allows an identification of a transform from the s-plane to the z-plane,
1 z 1
s= : (4.20)
T
Solving (4.20) for z yields
1
z= : (4.21)
1 sT
108 CHAPTER 4. IIR FILTERS
-1
-2
-3
-4
-4 -3 -2 -1 0 1 2 3 4
between the s-plane and the z-plane. The expression in (4.25) is known as the bilinear transform.
Solving (4.25) for z yields
1 + (sT=2)
z= (4.26)
1 (sT=2)
and evaluating (4.26) for s = j
gives
1 + (j
T=2)
z= : (4.27)
1 (j
T=2)
The expression in (4.27) is an all-pass transformation which has unit magnitude and phase which takes
values from to on the unit circle as
goes from 1 to 1. The transformation in (4.26) maps the
left half s-plane into the unit circle in the z-plane and the right half s-plane outside of the unit circle in the z-
plane. Consequently, stable causal analog filters yield stable causal digital filters under this transformation.
Furthermore, the j
-axis in the s-plane maps to the unit circle in the z-plane. The mapping of the j
-axis
onto the unit circle is not linear and, thus, there is a frequency warping distortion of the analog filter design
when this transform is used.
Because many filters of interest, such as low pass, band pass, band pass, and stop band filters have
magnitudes which are piece-wise constant, frequency warping distortion is of no consequence. That is, the
bilinear transformation maintains the characteristics of the analog filter design. However, if, in addition, the
phase of the analog filter is linear, the bilinear transformation will destroy this property when used to obtain
a digital filter.
An example of a typical digital low-pass filter design from a Chebyshev analog filter design of the first
type is as follows. The digital low-pass filter is to have a cut-off frequency of =2. This constraint is
transformed to an analog constraint using (4.30). The resulting analog constraint takes the cut-off frequency
to be 2 tan(=4) = 2. Now the function zpch1 is used to design the Chebyshev filter of the first type of
2
p the ripple of a Chebyshev filter is 1=(1 + ) it follows that for a
order 3 and passband ripple of .05. Since
ripple of .05 in the passband that = (1=:95) 1 = :22942. Thus, the call to the function looks like
-->[pols,gn]=zpch1(3,.22942,2);
-->gn
gn =
8.7176358
-->pols
ans =
! - 0.7915862 - 2.2090329i !
! - 1.5831724 - 1.562D-16i !
! - 0.7915862 + 2.2090329i !
-->hs=gn/real(poly(pols,s))
hs =
8.7176358
---------------------------------------
2 3
8.7176358 + 8.0128698s + 3.1663448s + s
where the transfer function hs is calculated from the gain and the poles returned from the function. The
magnitude of the the transfer function can be plotted as follows
gn =
8.7176358
ans =
! - 0.7915862 - 2.2090329i !
! - 1.5831724 - 1.562D-16i !
! - 0.7915862 + 2.2090329i !
hs =
8.7176358
---------------------------------------
2 3
8.7176358 + 8.0128698s + 3.1663448s + s
4.4. DESIGN OF LOW PASS FILTERS 111
-->fr=0:.05:3*%pi;
-->hsm=abs(freq(hs(2),hs(3),%i*fr));
-->plot(fr,hsm)
1.0
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
0 1 2 3 4 5 6 7 8 9 10
Now the analog low-pass filter design can be transformed to a digital filter design using the bilinear
transform as follows
gn =
8.7176358
ans =
! - 0.7915862 - 2.2090329i !
! - 1.5831724 - 1.562D-16i !
! - 0.7915862 + 2.2090329i !
hs =
8.7176358
---------------------------------------
2 3
8.7176358 + 8.0128698s + 3.1663448s + s
112 CHAPTER 4. IIR FILTERS
-->z=poly(0,z);
-->hz=horner(hs,2*(z-1)/(z+1))
hz =
2 3
8.7176358 + 26.152907z + 26.152907z + 8.7176358z
------------------------------------------------
2 3
- 2.6427245 + 21.461789z + 5.5132676z + 45.408755z
The result of the transform yields a filter which has a magnitude as shown in Figure 4.15.
1.2
1.0
0.8
0.6
0.4
0.2
0
0 0.1 0.2 0.3 0.4 0.5
where
sin[(!c !u )=2]
= : (4.32)
sin[(!c + !u )=2]
For a high-pass filter of cut-off frequency !u one can use the transformation
z+
z! (4.33)
1 + z
where
cos[(!c !u )=2]
= : (4.34)
cos[(!c + !u )=2]
For a band-pass filter with !u and !l the upper and lower band edges, respectively, one would use the
transformation
z 2 (2k=(k + 1))z + ((k 1)=(k + 1))
z! (4.35)
1 (2k=(k + 1))z + ((k 1)=(k + 1))z 2
where
cos[(!u + !l )=2]
= (4.36)
cos[(!u !l )=2]
and
k = cot[(!u !l )=2] tan(!c =2): (4.37)
Finally, for a stop-band filter with !u and !l the upper and lower band edges, respectivly, the following
transformation is used
z 2 (2=(k + 1))z ((k 1)=(k + 1))
z! (4.38)
1 (2=(k + 1))z ((k 1)=(k + 1))z 2
where
cos[(!u + !l )=2]
= (4.39)
cos[(!u !l )=2]
and
k = tan[(!u !l )=2] tan(!c =2): (4.40)
--> [hz]=iir(n,ftype,fdesign,frq,delta)
The argument n is the filter order which must be a positive integer. The argument ftype is the filter type
and can take values lp for a low-pass filter, hp for a high-pass filter, bp for a band-pass filter, or
sb for a stop-band filter.
The argument fdesign indicates the type of analog filter design technique is to be used to design the
filter. The value of fdesign can be butt for a Butterworth filter design, cheb1 for a Chebyshev
filter design of the first type, cheb2 for a Chebyshev filter design of the second type, or ellip for
an elliptic filter design.
The argument frq is a two-vector which contains cut-off frequencies of the desired filter. For low-pass
and high-pass filters only the first element of this vector is used. The first element indicates the cut-off
frequency of the desired filter. The second element of this vector is used for band-pass and stop-band filters.
This second element is the upper band edge of the band-pass or stop-band filter, whereas the first element of
the vector is the lower band edge.
114 CHAPTER 4. IIR FILTERS
The argument delta is a two-vector of ripple values. In the case of the Butterworth filter, delta is
not used. For Chebyshev filters of the first type, only the first element of this vector is used and it serves
as the value of the ripple in the pass band. Consequently, the magnitude of a Chebyshev filter of the first
type ripples between 1 and 1-delta(1) in the pass band. For a Chebyshev filter of the second type only
the second element of delta is used. This value of delta is the ripple in the stop band of the filter.
Consequently, the magnitude of a Chebyshev filter of the second type ripples between 0 and delta(2) in
the stop band. Finally, for the elliptic filter, both the values of the first and second elements of the vector
delta are used and they are the ripple errors in the pass and stop bands, respectively.
The output of the function, hz, is a rational polynomial giving the coefficients of the desired filter.
4.7 Examples
In this section we present two examples using the iir filter design function. We remind the user that an
important part of the filter design process is that there is always a trade-off between the performance and
the expense of a filter design. For a filter with a small error in the pass and stop bands and with a narrow
transition band it will be necessary to implement a filter of higher order (which requires more multiplies).
Consequently, the filter design procedure is iterative. The user specifies a model order and then examines the
magnitude of the resulting filter to see if the design specifications are met. If specifications are not satisfied,
then the user must start again with a filter of higher model order. Another important point to keep in mind
when using the function is that band pass and stop band filters will generate transfer functions of twice the
model order specified. This is due to that transformation of the prototype low pass filter using an all pass
filter of order two (see Section 4.5).
The first example is of a low-pass filter design using a Chebyshev filter of the first type for the analog
design. The cut-off frequency of the digital filter is !c = :2, the filter order is n = 5, and the ripple in the
passband is = :05. The call to the function is as follows
-->hz=iir(5,lp,cheb1,[.2 0],[.050.05])
hz =
2 3 4
0.0103696 + 0.0518480z + 0.1036960z + 0.1036960z + 0.0518480z
5
+ 0.0103696z
------------------------------------------------------------------
2 3 4
- 0.2213294 + 0.9336888z - 1.9526644z + 2.5422088z - 1.9700766z
5
+ z
-->hz=iir(3,bp,ellip,[.150.25],[.080.03])
4.8. ANOTHER IMPLEMENTATION OF DIGITAL IIR FILTERS 115
1.2
1.0
0.8
0.6
0.4
0.2
0
0 0.1 0.2 0.3 0.4 0.5
hz =
2 3 4
- 0.0476402 + 0.0423997z - 0.0013489z - 2.116D-17z + 0.0013489z
5 6
- 0.0423997z + 0.0476402z
------------------------------------------------------------------
2 3 4
0.5045339 - 1.0411237z + 2.4255266z - 2.6216751z + 2.9974049z
5 6
- 1.646036z + z
and the resulting magnitude of the transfer function is illustrated in Figure 4.17.
Notice that the transfer function here is of order six whereas the specified order was three. For band pass
and stop band filters the user must specify a filter order of half the desired order to obtain the desired result.
1.0
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
0 0.1 0.2 0.3 0.4 0.5
The filter is given either by the set of its poles and zeros (output variables zpoles and zzeros of the
eqiir function) or equivalently by a the representation:
N
Y
H (z ) = fact ni (z )=di (z )
1
where the rational fraction ni (z )=di (z ) is the i-th element of cells.
4.8.2 Examples
Example 1 (Lowpass elliptic filter): Design of a lowpass elliptic filter with maximum ripples p = 0:02,
s = 0:001 and cutoff frequencies !1 = 2 10 and !2 = 4 10 .
-->[cells,fact,Zeros,Zpoles]=...
-->eqiir(lp,ellip,[2*%pi/10,4*%pi/10],0.02,0.001);
-->Zpoles
ans =
! 0.6906008 - 0.5860065i !
! 0.6906008 + 0.5860065i !
! 0.6373901 - 0.3437403i !
! 0.6373901 + 0.3437403i !
! 0.6247028 !
-->Zeros
ans =
4.8. ANOTHER IMPLEMENTATION OF DIGITAL IIR FILTERS 117
! 0.2677115 - 0.9634991i !
! 0.2677115 + 0.9634991i !
! - 0.1744820 - 0.9846604i !
! - 0.1744820 + 0.9846604i !
! - 1. !
-->cells
ans =
! 2 !
! 1 - 0.5354229z + z !
! -------------------------- !
! 2 !
! 0.8203331 - 1.3812015z + z !
! !
! 2 !
! 1 + 0.3489640z + z !
! -------------------------- !
! 2 !
! 0.5244235 - 1.2747803z + z !
! !
! 1 + z !
! ------------- !
! - 0.6247028 + z !
-->transfer=fact*poly(Zeros,z)/poly(Zpoles,z)
transfer =
2 3 4
0.0059796 + 0.0048646z + 0.0097270z + 0.0097270z + 0.0048646z
5
+ 0.0059796z
------------------------------------------------------------------
2 3 4
- 0.2687484 + 1.5359753z - 3.7100842z + 4.7646843z - 3.2806846z
5
+ z
Example 2 (Lowpass Butterworth filter): Design of a lowpass Butterworth filter with the following
specifications:
- 5dB passband attenuation at the normalized cutoff frequencies :25=10 and - 120dB attenuation at the
stopband edge 0:5=10.
-->om=[.25*%pi/10,4*%pi/10];
118 CHAPTER 4. IIR FILTERS
-->pdB=5;
-->sdB=120;
-->deltap=(1.0-10.0**(-0.05*pdB));
-->deltas=10.00**(-0.05*sdB);
-->[cells,fact,zers,pols]=eqiir(lp,butt,om,deltap,deltas);
-->cells
cells =
column 1 to 2
! 2 2!
! 1 + 2z + z 1 + 2z + z !
! -------------------------- -------------------------- !
! 2 2 !
! 0.9450100 - 1.9368524z + z 0.8621663 - 1.8543562z + z !
column 3
! 1 + z !
! ------------- !
! - 0.9123352 + z !
-->n=prod(cells(2));
-->d=prod(cells(3));
-->tr=n./d
tr =
2 3 4 5
1 + 5z + 10z + 10z + 5z + z
---------------------------------------------------------------
2 3 4 5
- 0.7433304 + 3.937017z - 8.3477808z + 8.8576437z - 4.7035438z + z
Example 3 (Lowpass type 1 Chebyshev filter): Design of a lowpass type 1 Chebyshev filter with 2dB
ripple in the passband and -30 dB attenuation at the stopband edge. The sampling frequency is assumed to
be 3000Hz and the cutoff frequencies at 37.5Hz and 75Hz respectively.
-->sf=3000;
4.8. ANOTHER IMPLEMENTATION OF DIGITAL IIR FILTERS 119
-->f1=37.5;
-->f2=75;
-->as=30;
-->ap=2;
-->om=[f1*(2*%pi)/sf,f2*(2*%pi)/sf];
-->deltas=10.00**(-0.05*as);
-->deltap=(1.0-10.0**(-0.05*ap));
-->[cells,fact,zers,pols]=...
-->eqiir(lp,ch1,om,deltap,deltas);
-->cells
cells =
! 2 2 !
! 1 - 1.9711824z + z 1 - 1.8376851z + z !
! ------------------ ------------------ !
! 2 2 !
! Nan +Nanz + z Nan +Nanz + z !
Example 4 (Elliptic symmetric bandpass filter): Design of a symmetric bandpass filter with edges at
!1 = 0:251463; !2 = =10; !3 = 2=10; !4 = 0:773302 and ripples in the passband and stopband given
respectively by p = 0:022763, s = 0:01.
-->//Elliptic bandpass filter
-->om=[0.251463,1*%pi/10,2*%pi/10,0.773302];
-->deltap=0.022763;
-->deltas=0.01;
-->[cells,fact,zers,pols]=eqiir(bp,el,om,deltap,deltas);
-->n=prod(cells(2));d=prod(cells(3));
-->rep=freq(n,d,exp(%i*(0:0.01:%pi)));
-->rep=fact*abs(rep);
120 CHAPTER 4. IIR FILTERS
-->n=prod(size(rep))
n =
315.
-->plot(20*log(rep(2:n))/log(10))
The preceding example shows how to compute the magnitude response by using the freq primitive.
The example is plotted in Figure 4.18.
-10
-20
-30
-40
-50
-60
-70
-80
-90
-100
0 40 80 120 160 200 240 280 320
Spectral Estimation
1 NX1
Sx (!) = j x(n)e
N n=0
j!n j2: (5.1)
In an analogous fashion the cross-spectrum of two signals x(n) and y (n) is defined to be
1 NX1 NX1
Sxy (!) = ( x(n)e j!n )( y(n)e j!n ) : (5.2)
N n=0 n=0
The power spectra of random, zero-mean, wide sense stationary signals are obtained from the Fourier trans-
form of the correlation functions of these signals. Thus, for Rx representing the autocorrelation function of
x and Rxy representing the cross-correlation function of x with y we have by definition that
Rx (m) = E fx(n + m)x (n)g (5.3)
Rxy (m) = E fx(n + m)y (n)g: (5.4)
Consequently, the power spectrum and cross-power spectrum of x(n) and of x(n) with y(n) are, respect-
ively,
1
X
Sx (!) = Rx (m)e j!m (5.5)
m= 1
1
X
Sxy (!) = Rxy (m)e j!m : (5.6)
m= 1
The formulas (5.5) and (5.6) require estimates of the correlation functions. Possible candidates for the
estimates of the auto and cross correlation functions of finite length random signals (i.e., x(n) 6= 0 and
y(n) 6= 0 for n = 0; 1; : : : ; N 1) are
1 m
NX
1
R^ x (m) = x(n + m)x (n) (5.7)
N n=0
1 m
NX
1
R^ xy (m) = x(n + m)y (n): (5.8)
N n=0
121
122 CHAPTER 5. SPECTRAL ESTIMATION
The estimates in (5.7) and (5.8) are unbiased, consistent estimators in the limit as N ! 1. Furthermore,
in the case where the random signals are jointly Gaussian, these estimators are the maximum likelihood
estimates of the correlation functions. Another interesting property of the estimators in (5.7) and (5.8) is
that when substituted, respectively, into the expressions in (5.5) and (5.6), after some algebraic manipulation,
yield exactly the expressions in (5.1) and (5.2).
Unfortunately, there is a serious problem with the above power spectrum estimation scheme. This prob-
lem is that the resulting power spectral estimates, in the limit, are not consistent. That is, the error variance
of the estimate does not decrease with increasing data. Consequently, power spectral estimates obtained by
taking the magnitude squared of the Fourier transform are high-variance, low-quality estimates.
In the sections which follow two techniques are discussed which yield improved spectral estimates.
These techniques are both based on averaging spectral estimates obtained from the classical approach just
described. This averaging, although introducing some biasing, yields greatly improved estimates in that, in
the limit, these estimates become consistent.
The first averaging technique also sections the data into overlapping segments. However, in this case
the magnitude squared of the Fourier transform is calculated from each segment and then these are averaged
together to yield the spectral estimate. This technique is called the modified periodogram method for spectral
estimation.
The second averaging technique sections the data into overlapping segments. For each segment an
estimate of the correlation function is calculated. These estimates are then averaged and the estimated
power spectral density is the Fourier transform of the average. This technique is known as the correlation
method for spectral estimation.
Both techniques use windows to diminish the effects that finite data has on spectral estimation. These
effects are identical to the problems encountered in FIR filter design, and, consequently, the reader is referred
to the FIR filter design section for an explanation of the issues involved in the choice of windows. In
the discussion which follows cross-spectral estimation is not discussed considering that the cross-spectral
estimate can be obtained as a simple modification of the auto-spectral estimation techniques.
1 NX1
I (! ) = j w(n)x(n)e
U n=0
j!n j2 : (5.9)
where w(n) is a window function which has energy U . Consequently, if K sub-segments of length N are
used to calculate the spectrum of the signal then the modified periodogram spectral estimate, S^x , is just the
average of the K periodograms
^ 1 KX1
Sx(!) = I (5.10)
K k=0 k
where each of the Ik is the periodogram (calculated as in (5.9)) of the k th segment of data.
Normally, the K segments of data are taken so that there is a regular pattern of overlap in the success-
ive segments. That is, the k th and (k + 1)th segments overlap by D points. Figure 5.1 illustrates three
consecutive overlapping segments of a data sequence.
5.2. THE MODIFIED PERIODOGRAM METHOD 123
1.400
1.025
0.650
0.275
-0.100
-0.475
-0.850
-1.225
-1.600 x1
x2
-1.975
x3
-2.350
1.0 26.5 52.0 77.5 103.0 128.5 154.0 179.5 205.0 230.5 256.0
It can be shown that an overlap of fifty percent in the data segments results in an approximately fifty
percent reduction in the variance of the estimate of the power spectrum [24]. Normally, one chooses the
length of the data segments to reflect the a priori knowledge of the correlation length of the data. That
is to say that if the correlation between two data samples separated by more than M points is considered
negligible then the data segment should be of a length on the order of M . The number of data segments
used determines the variance of the spectral estimate. The variance decreases proportionally to the number
of independent segments. Of course, with a limited quantity of data the number of data segments must also
be limited.
The function pspect calculates an estimate of the power spectrum using the modified periodogram
method.
-->rand(normal);
-->rand(seed,0);
124 CHAPTER 5. SPECTRAL ESTIMATION
-->x=rand(1:1024-33+1);
-->nf=33;
-->bedge=[00.1;.1250.5];
-->des=[1 0];
-->wate=[1 1];
-->hn=eqfir(nf,bedge,des,wate);
-->h1=[hn 0*ones(1:maxi(size(x))-1)];
-->x1=[x 0*ones(1:maxi(size(hn))-1)];
-->hf=fft(h1,-1);
-->xf=fft(x1,-1);
-->yf=hf.*xf;
-->y=real(fft(yf,1));
As can be seen, a total of 1024 data points are available for the estimation of the spectrum. The logarithm
of the magnitude squared of the filter frequency response is shown in Figure 5.2.
The data obtained above are used to estimate the power spectrum in the following way
-->[sm]=pspect(100,200,tr,y);
The log-magnitude of the power spectrum (sm) is plotted in Figure 5.3. It should be pointed out here that the
value of the section lengths was chosen to be 200 in this example to obtain additional resolution in the plot
of the Fourier transform of the estimated power spectrum in Figure 5.3. However, there is very acceptable
behavior of the spectral estimate when the section length is on the order of twice the filter length. This is
due to the fact that one does not expect correlations in the data that are much longer than the filter length.
Normally, the section lengths are chosen to reflect the a priori knowledge of the correlation length in the
data.
As can be seen the estimated spectrum matches the theoretical spectrum (Figure 5.2) very well. In
particular, the peaks of the spectrum in both the pass and stop bands matches well with those of the filter
magnitude response. Furthermore, the normalization of the estimate is accurate with respect to the filter
response.
5.2. THE MODIFIED PERIODOGRAM METHOD 125
-1
-5
-9
-13
-17
-21
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0
-1
-2
-3
-4
-5
-6
-7
-8
-9
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0
where Ffg represents the Fourier transform operation, w(m) is a window function, and R~ x (m) is the
average of the K estimates
K
1X
R~ x = R^ : (5.13)
K k=1 k
The correlation method of spectral estimation is based on the corr primitive in Scilab. The primit-
ive corr is useful for any application requiring correlations or cross-correlations. Documentation on this
primitive can be found in the introductory manual for Scilab.
The function cspect calculates an estimate of the power spectrum using the correlation method for
spectral estimation.
-1
-2
-3
-4
-5
-6
-7
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0
where
1
X
X (!) = xn e j!n : (5.15)
n= 1
In many applications it is very useful to know the power spectrum of a signal, however, it is rare that the
obtained signal can be characterized as being deterministic. Often the signal is present in a noisy environ-
ment and, in addition, is obtained with instrumentation which degrades the signal with measurement noise.
Consequently, for a non-deterministic signal one seeks to estimate the power spectrum. It can be shown [21]
that taking the Fourier transform of a non-deterministic signal in order to estimate its power spectrum is a
very poor approach. The problem is that the resulting power spectrum is a highly variable estimate of the
true power spectrum and that the variance does not decrease to zero as one increases the data length (i.e.,
the estimator is not consistent).
The problem of estimating the power spectrum can be modified as follows. Let x(n) be a zero-mean,
stationary signal and let rx (n) be the autocorrelation function of the signal (that is, rx (n) = E fx(k )x (n +
k)g). Then the power spectrum Sx (n) of x(n) is taken to be the Fourier transform of rx (n)
1
X
Sx (!) = rx (n)e j!n : (5.16)
n= 1
Assuming that statistical averages of the signal x(n) are equal to time averages we can take as an estimate
128 CHAPTER 5. SPECTRAL ESTIMATION
for rx (n)
N
1 X
r^x (n) = lim x(m)x(m n): (5.17)
N !1 2N + 1
m= N
However, after plugging (5.17) into (5.16) and performing some algebraic manipulation it can be seen that
(5.16) is just the magnitude squared of the Fourier transform of x(n). Consequently, (5.16) is not any more
useful than (5.14) for estimating the power spectrum of a non-deterministic signal.
One can improve the statistical properties of the power spectrum estimate by smoothing the result ob-
tained in (5.16) or by breaking the input, x(n), into pieces, performing the calculation in (5.17) and (5.16)
for each piece, and then averaging these results together. These approaches are the classical methods of
power spectral estimation.
These classical methods of power spectral estimation are undesirable for two reasons. The estimate
obtained from these methods is based on a finite (i.e., windowed) segment of the autocorrelation function.
This means that the resulting estimated power spectrum is a convolution of the true power spectrum and of
the Fourier transform of the window. Consequently, the resolution of spectral features is diminished and the
estimate of the power spectrum at any point is biased by leakage from other parts of the power spectrum
through the window sidelobes.
The maximum entropy spectral estimate (MESE) of the power spectrum yields an improved spectral
density estimate. Thats to say that for MESE the resolution is improved and the bias is decreased in
comparison with the classical spectral estimation methods. This improvement is due to the fact that the
MESE uses a model based estimation procedure.
where Z
1
S^x (!)ej!n d! = r^x (n); n = 0; 1; : : : ; N 1: (5.19)
2
Equation (5.18) expresses the optimality condition of maximizing the entropy of S (! ) subject to the N
constraints posed in (5.19).
Since entropy is a measure of randomness, the MESE is the spectral estimate which is maximally random
given the constraints in (5.19). Intuitively, the MESE incorporates no information in the estimated spectrum
other than the knowledge of the autocorrelation lags. That is to say that the bias should be eliminated (or
at least minimized in some sense) since no non-data related constraints are imposed on the spectrum. As
was discussed in the introduction, windowed-autocorrelation spectral estimates suffered from bias due to
the leakage from the window sidelobes. The window imposes a non-data related constraint on the power
spectrum estimate in that the autocorrelation function is assumed to be identically zero outside of the support
of the window.
Furthermore, as is discussed in [16], it can be shown that the MESE is equivalent to the Fourier transform
of an infinite length autocorrelation sequence which is obtained by extrapolating the sequence of length N
5.4. THE MAXIMUM ENTROPY METHOD 129
in (5.19). The extrapolation is accomplished using an auto-regressive, all-pole model of order N 1 given
by
X1
N
r^x(n) = ak r^n k ; n N: (5.20)
k=1
Any autocorrelation sequence can be modeled by (5.20) given a large enough model order, N . Consequently,
in principle, the resolution of the MESE should be much better than that of a windowed spectral estimate
since the MESE uses an infinite length autocorrelation sequence.
The solution to (5.18) and (5.19) can be found by using the calculus of variations [11] and, as demon-
strated in [16], the solution takes the form
2
S^x (!) = PN 1 (5.21)
j1 + n=1 an expf j!ngj
2
where the parameter set f 2 ; a1 ; a2 ; : : : ; aN 1 g is obtained by solving the system of linear equations
2 32 3 2 3
r^x (0) r^x (1) r^x(N 1) 1 2
6
6 r^x (1) r^x (0) r^x(N 2) 77 66 a1 77 66 0 77
6 .. .. .. 76 .. 7 =6 .. 7 (5.22)
4 . . . 54 . 5 4 . 5
r^x (N 1) r^x (N 2) r^x (0) aN 1 0
where the Toeplitz matrix in (5.22) is composed of the N estimated correlation lags r^x (n). The system of
N linear equations in (5.22) are known as the Yule-Walker equations and an efficient algorithm for their
solution is described in the next section.
-->[sm,fr]=mese(x)
where one wants to obtain a power spectral estimate of x, the input data sequence, and sm is the resulting
estimate obtained on the normalized frequency axis (0 fr :5).
130 CHAPTER 5. SPECTRAL ESTIMATION
-->[ar,sigma2,rc]=lev(r)
where r is a vector of auto-correlation coefficients (r (0); r (1); : : : ; r (N 1)), ar is the vector which satisfies
the Yule-Walker equations, sigma2 is the scalar which satisfies the Yule-Walker equations, and rc is a
vector of reflection coefficients.
5.4.6 Examples
Here we give an example of estimating the power spectrum of a very short data sequence using the MESE
and also using the magnitude squared of the Fourier transform. The data is eleven samples of the sum of
two sinusoids in additive, uniformly distributed, white noise. The functional form of the data sequence is
where w(n) is the white noise sequence which takes on values in [ 1; 1] and n = 0; 1; :::; 10. Figure 5.5
shows the input data sequence, x(n). Figures 5.6 and 5.7 show the maximum entropy and magnitude squared
estimates of the power spectrum, respectively.
-1
-2
1 2 3 4 5 6 7 8 9 10 11
As can be seen, the MESE resolves two peaks according to the two sinusoidal frequences in x(n). The
squared magnitude of the Fourier transform of x(n) does not have a long enough signal to resolve the two
peaks of the spectrum. Furthermore, the power spectrum estimate in Figure 5.7 shows spurious sidelobes
which have nothing to do with the data.
5.4. THE MAXIMUM ENTROPY METHOD 131
18
16
14
12
10
0
0 0.1 0.2 0.3 0.4 0.5
16
14
12
10
0
0 0.1 0.2 0.3 0.4 0.5
Figure 5.7: exec(mem1 3.code) Squared Magnitude of the Fourier Transform of x(n)
132 CHAPTER 5. SPECTRAL ESTIMATION
Chapter 6
xk+1 = Fk xk + Gk wk
yk = Hk xk + vk (6.1)
where
wk N (0; Qk )
vk N (0; Rk )
x0 N (m0; 0 )
(6.2)
and x0 , fwk g, and fvk g are independent random vectors. The state vector, xk , has dimension N and the
observation vector, yk , has dimension M . Furthermore, it is assumed that Rk > 0.
The problem to be addressed here is the estimation of the state vector, xk , given observations of the vec-
tors Yk = fy0 ; y1 ; : : : ; yk g. Because the collection of variables fxk ; y0 ; y1 ; : : : ; yk g are jointly Gaussian one
could estimate xk by maximizing the likelihood of the conditional probability distribution p(xk jYk ) given
the values of the conditional variables. Equivalently, one could search the estimate, x ^k , which minimized the
mean square error, k = xk x ^k . In either case it is known that the optimal estimate (maximum likelihood
or least squares) for the jointly Gaussian variables is the conditional mean. The error in the estimate is the
conditional covariance.
In what follows, the conditional mean and covariance of xk given Yk is developed. This is followed by a
description of the Kalman filter, an extremely practical recursive method for calculating the conditional mean
and covariance. Several different implementations of the Kalman filter are discussed here: The steady-state
Kalman filter which can be used when the system matrices in (6.1) and (6.3) are non-time varying, the non-
stationary Kalman filter for use when the system matrices in (6.1) and (6.3) are time-varying, and, finally,
the square-root Kalman filter which is used (for time-varying and non-time-varying system matrices) when
greater numerical accuracy is required.
133
134 CHAPTER 6. OPTIMAL FILTERING AND SMOOTHING
covariance. Consequently, assuming that z is a Gaussian random vector composed of two sub-vectors x and
y, then
z = xy N mx ; x xy
my yx y
(6.3)
where mx denotes the mean of x, xy denotes the covariance of x with y , and x is the covariance of x with
itself.
It is known that the marginal and conditional distributions of a Gaussian random vector are also Gaus-
sian. In particular, the conditional distribution of x given y , p(xjy ), is
p(xjy) = N (mxjy ; xjy ) (6.4)
where mxjy denotes the conditional mean and xjy denotes the conditional covariance. These two quantities
may be calculated by
mxjy = mx + xy y 1 (y my )
xjy = x xy y 1 yx : (6.5)
(It is useful to note the x and y are not necessarily of the same dimension). Equation (6.5) is very important
in our development of the Kalman filter equations.
With regard to the problem posed in the introduction to this section, the minimum mean square error is
calculated in a straight forward manner. One stacks the individual observation vectors into a single vector,
Yk , and then, since xk and Yk are jointly Gaussian , one applies (6.5) to obtain the conditional mean and
covariance of xk given Yk . The problem with this approach is that for increasing k the vector Yk is of
increasing dimension, and consequently, the matrix inverse and multiplication operations in (6.5) become
increasingly burdensome.
The next few sections are devoted to showing how the linear system of (6.1) and the special properties
of (6.5) can be used to obtain a recursive update to the estimation of xk . That is, given the best estimate of
xk based on the observations Yk (we denote this estimate by x^kjk ) and a new observation yk+1, it is shown
how to obtain the best estimate of x ^k+1jk+1 and its error covariance matrix Pk+1jk+1 .
Consequently, the minimum mean square error estimate of y is y^ = Hmx and the associated error covariance
of this estimate is Py = H x H T + R = HPx H T + R.
Now note that if y and z were independent that yz would be zero and then (6.13) could be written as
= z z^(y)
= z [mz + zy y 1 (y my )]
= (z mz ) zy y 1 (y my ) (6.16)
where z^(y ) is the minimum mean square estimate of z given observation of y (obtained by using (6.5)).
The new random vector, , has several interesting properties. First, because
and
it follows that is independent of both y and x^(y) These properties are very useful for developing the
Kalman filter equations of the next section.
Now (6.15) can be rewritten so that
x^(y; z ) = x^(y; )
1
= mx + [ xy x ] 0y 0 y my
1 1
= mx + xy y (y my ) + x
= x^(y) + x 1 (6.20)
and
(Note that the equality of x^(y; z ) and x^(y; ) is due to the fact that no information is lost in making the
change of variables in (6.16). We are simply adding a constant vector to z which renders and y independent
of each other). The error covariance, Px (y; ), associated with (6.20) is
1
Px (y; ) = x [ xy x ] 0 y 0 yx
x
1
= x xy y yx x x 1
= Px (y) x 1 x : (6.23)
(where the final equality follows from the fact that vk and xk are independent random vectors), and
(where the second equality follows from (6.13) and (6.19)). Substituting (6.25), (6.26), and (6.27) into (6.24)
yields
where Kk = Pkjk 1 HkT [Hk Pkjk 1 HkT + Rk ] 1 is called the Kalman gain of the filter. (Note: Since the
model proposed in the first section of this chapter assumes that Rk > 0 it follows that Kk always exists.
However, when Rk is not strictly positive definite there may be problems performing the matrix inverse
necessary to calculate Kk ). Using (6.7) and (6.8) in conjunction with (6.1) gives the two auxiliary equations
x^k+1jk = Fk x^kjk
Pk+1jk = Fk Pkjk FkT + Gk Qk GTk : (6.29)
Combining the equations in (6.28) and (6.29) yields one set of recursive equations
The only remaining detail is to identify the initial conditions of the Kalman filter which are obtained from
the a priori statistics of x0
x^0j 1 = m0
P0j 1 = 0 : (6.31)
138 CHAPTER 6. OPTIMAL FILTERING AND SMOOTHING
rank[ G F G F N 1G ] = N (6.32)
(recall that F is an N N matrix). A necessary and sufficient condition that the system be observable is
that 2 3
H
6 HF 7
rank 6
6 ..
7
7 =N (6.33)
4 . 5
HF N 1
Now if the system in (6.1) is both controllable and observable then
[xe,pe]=sskf(y,f,h,q,r,x0)
xk+1 = fxk + wk
yk = hxk + vk
where
wk N (0; q)
vk N (0; r)
x0 N ( x0; 0 ):
The remaining input, y = [y0 ; y1 ; : : : ; yn ], is a matrix where the individual observations yk are contained
in the matrix as column vectors.
The outputs xe and pe are the estimated state and the steady-state error covariance matrix. The form
of the estimates is xe = [^ x0j0 ; x^1j1 ; : : : ; x^njn ] where each x^kjk is a column in the matrix. The steady-state
error covariance matrix is a square matrix of the dimension of the state.
11
10
7
6
5
4
2
1
8 12 16 20 24 28 32 36
14
12
10
4
2
0
4 8 12 16 20 24 28 32 36
The figure shows the actual state path and the Kalman estimate of the state path as a dotted and solid
line, respectively. The actual locations of the state and estimated values are indicated by the star and circle
symbols on the respective paths. The ellipses in the figure are centered about the positions of the actual
state path and their borders represent two standard deviations of estimation error calculated from the error
covariance matrices. The values of the standard deviations for the above example are displayed below:
-->//create system
-->//noise statistics
142 CHAPTER 6. OPTIMAL FILTERING AND SMOOTHING
-->q=[.030.01;.010.03];r=2*eye(2);
-->rand(seed,2);rand(normal);p0c=chol(p0);
-->x0=m0+p0c*rand(ones(m0));
-->yt=[];
-->xke0=m0;pk0=p0;
-->ecv=[pk0(1,1) pk0(2,2)];
-->//loop
-->n=10;
-->for k=1:n,
-->//generate the state and observation at time k (i.e. x(k+1) and y(k))
-->[x1,y]=system(x0,f,g,h,q,r);x0=x1;
-->//track the state with the standard kalman filter
-->[xke1,pk1,xd,pd]=kalm(y,xke0,pk0,f,g,h,q,r);
-->ecv=[ecv [pk1(1,1) pk1(2,2)]];
-->xke0=xke1;pk0=pk1;
-->//end loop
-->end;
-->sqrt(ecv)
ans =
! 1.4142136 1.4142136 !
! 0.9949874 0.6757712 !
! 0.5421994 0.3838288 !
! 0.4476458 0.3251576 !
! 0.4093299 0.3018837 !
! 0.3909608 0.2908610 !
! 0.3815271 0.2852390 !
! 0.3765212 0.2822672 !
! 0.3738201 0.2806671 !
! 0.3723499 0.2797971 !
6.1. THE KALMAN FILTER 143
! 0.3715458 0.2793216 !
Each row of the above vector represents the standard deviations of the state vector error covariance mat-
rix where the first row is the standard deviation of the a priori error in the state vector and the last row is
the standard deviation of the state vector estimate at the last step of the Kalman filter. The above standard
deviation vector is instructive. It should be noted that for both state values, the standard deviation is con-
verging to a steady state value. For the first element of the state vector this value is .7800312 and for the
second element of the state vector the value is .2824549. The convergence is to be expected since the above
formulation of the system is both controllable and observable.
If we were to change the above system formulation so that the dynamics equation were now
xk+1 = 1:1 :1 x + 1 0 w (6.37)
0 :8 k 0 0 k
the system would be uncontrollable. Re-running the Kalman filter with this re-formulation yields the fol-
lowing sequence of standard deviations:
-->//create system
-->//noise statistics
-->q=[.030.01;.010.03];r=2*eye(2);
-->rand(seed,2);rand(normal);p0c=chol(p0);
-->x0=m0+p0c*rand(ones(m0));yt=[];
-->xke0=m0;pk0=p0;
-->ecv=[pk0(1,1) pk0(2,2)];
-->//loop
-->n=10;
144 CHAPTER 6. OPTIMAL FILTERING AND SMOOTHING
-->for k=1:n,
-->//generate the state and observation at time k (i.e. x(k+1) and y(k))
--> [x1,y]=system(x0,f,g,h,q,r);x0=x1;
-->//track the state with the standard kalman filter
--> [xke1,pk1,xd,pd]=kalm(y,xke0,pk0,f,g,h,q,r);
--> ecv=[ecv [pk1(1,1) pk1(2,2)]];
--> xke0=xke1;pk0=pk1;
-->//end loop
-->end;
-->sqrt(ecv)
ans =
! 1.4142136 1.4142136 !
! 0.9949874 0.6531973 !
! 0.3985411 0.2392907 !
! 0.2911323 0.1560029 !
! 0.2425784 0.1132241 !
! 0.2158299 0.0858488 !
! 0.1999103 0.0665470 !
! 0.1900973 0.0522259 !
! 0.1839436 0.0412863 !
! 0.1800504 0.0327832 !
! 0.1775755 0.0261029 !
As can be seen, the second state variable has a standard deviation which is not converging to a positive
value. In fact the value of this standard deviation converges to zero. As was discussed in the section on
the asymptotic behavior of the Kalman filter, this is what was to be expected. The result of this behavior is
that the Kalman filter ignores any observed information regarding the second state variable since the error
variance is going to zero (and, thus, the filter thinks that it has perfect information concerning this state
value). If the above model is perfectly accurate then such an eventuality is not a problem. However, in
practice there are modeling errors and, consequently, if the new observations are ignored, there is a danger
that the Kalman filter estimates will begin to diverge from the actual state of the process.
Now we change the original model formulation again so that the observation equation is now
0 0
yk = 0 1 xk + vk : (6.38)
Under these conditions the system is not observable. The evolution of the standard deviation for this example
is:
-->//create system
--> f=[1.10.1;00.8];
-->//noise statistics
--> q=[.030.01;.010.03];
--> r=2*eye(2);
--> rand(seed,2),
--> rand(normal),
--> p0c=chol(p0);
--> x0=m0+p0c*rand(ones(m0));
--> yt=[];
--> xke0=m0;
--> pk0=p0;
-->//loop
--> n=10;
--> sqrt(ecv)
ans =
! 1.4142136 1.4142136 !
! 1.5652476 0.1732051 !
! 1.7292966 0.1732051 !
! 1.9090394 0.1732051 !
! 2.1061169 0.1732051 !
! 2.322326 0.1732051 !
! 2.559636 0.1732051 !
! 2.8202071 0.1732051 !
! 3.1064101 0.1732051 !
! 3.4208486 0.1732051 !
! 3.7663822 0.1732051 !
Here the standard deviation of the first state variable is growing without bound. This is due to two things.
First, the system is unobservable in the first state variable. Consequently, the observations provide no useful
information concerning the estimate of this state. Secondly, since the system matrix f has un unstable
eigenvalue the standard deviation of this state, in the limit, is unbounded.
The Scilab code used to generate the examples in this section is displayed below. The code for the
steady-state Kalman filter example is as follows:
-->rand(seed,5);rand(normal);
-->q=[.030.01;.010.03];u=rand(2,11);
-->f=[1.10.1;00.8];g=(chol(q));
-->x=ltitr(f,g,u,x0);
-->h=eye(2,2);[xe]=sskf(y,f,h,q,r,m0);
6.1. THE KALMAN FILTER 147
-->//plot result
-->a=mini([x(1,:),xe(1,:)]);a=-0.1*abs(a)+a;
-->b=maxi([x(1,:),xe(1,:)]);b=.1*abs(b)+b;
-->c=mini([x(2,:),xe(2,:)]);c=-0.1*abs(c)+c;
-->d=maxi([x(2,:),xe(2,:)]);d=.1*abs(d)+d;
-->plot2d(x(1,:),x(2,:),[1],000, )
-->plot2d(xe(1,:),xe(2,:),[2],000, ),
-->plot2d(xe(1,:),xe(2,:),[-3],000, ),
-->xend(),
The code used to generate the non-steady-state Kalman filter example is:
-->//create system
-->//noise statistics
-->q=[.030.01;.010.03];r=2*eye(2,2);
-->rand(seed,2);rand(normal);
-->p0c=chol(p0);x0=m0+p0c*rand(ones(m0));yt=[];
148 CHAPTER 6. OPTIMAL FILTERING AND SMOOTHING
-->xke0=m0;pk0=p0;
-->x=x0;xke=m0;
-->//loop
-->n=10;
-->deff([]=ellipse(m1,m2,s1,s2,s12),...
--> t=0:.1:.1+%pi*2;...
--> c=2*cos(t);...
--> s=2*sin(t);...
--> rho=s12/sqrt(s1*s2);...
--> cr=sqrt(s1)*c+m1*ones(c);...
--> sr=sqrt(s2)*(rho*c+sqrt(1-rho*rho)*s)+m2*ones(s);...
--> plot2d(cr,sr,[1],"000"),)
-->//plot result
-->a=mini([x(1,:)-2*sqrt(ell(1,:)),xke(1,:)]);a=-0.1*abs(a)+a;
-->b=maxi([x(1,:)+2*sqrt(ell(1,:)),xke(1,:)]);b=.1*abs(b)+b;
-->c=mini([x(2,:)-2*sqrt(ell(2,:)),xke(2,:)]);c=-0.1*abs(c)+c;
6.2. THE SQUARE ROOT KALMAN FILTER 149
-->d=maxi([x(2,:)+2*sqrt(ell(2,:)),xke(2,:)]);d=.1*abs(d)+d;
-->plot2d(x(1,:),x(2,:),[2],"000"),
-->plot2d(xke(1,:),xke(2,:),[1],"000"),
-->plot2d(x(1,:),x(2,:),[-2],"000"),
-->plot2d(xke(1,:),xke(2,:),[-3],"000")
-->xend(),
xk+1 = Fk xk + wk (6.39)
where wk and vk are independent zero-mean Gaussian vectors of covariance Qk and Rk , respectively. The
model in (6.39) is modified so that wk = Gk k and vk = Lk k where k is a zero-mean Gaussian random
vector with unit covariance matrix (i.e., E fk Tk g = I ). Since wk and vk are independent Gk LTk = Lk GTk =
0: Now, the model in (6.39) can be expressed as
yk = H k Lk xk
xk+1 Fk Gk k : (6.40)
" #
Hk Pk1j=k2 1 Lk
Ak 0 :
T =
Fk Pk1j=k2 1 Gk
k (6.43)
Bk Ck
(The matrix Tk can always be constructed as a combination of Householder transformations. The House-
holder transformation and the construction of Tk are detailed in the next section).
Using Tk , (6.42) can be rewritten so that
" # " #
k
Hk Pk1j=k2 1 Lk Pkjk1=21kjk 1
k+1jk 1 = 1 =2 Tk TkT
Fk Pkjk 1 Gk k
= Ak 0 (6.44)
Bk Ck k
where k is a zero-mean Gaussian random vector with unit covariance. We can now derive the significance
of (6.44) by calculating the conditional mean and conditional covariance of k+1jk 1 given k . Using (6.5)
we obtain
and
k+1jk
1 k
= Bk ATk
k = Ak ATk
k+1jk 1
= Bk BkT + Ck CkT : (6.47)
It can be seen that (6.45) yields the Kalman filter equations. Consequently, using (6.47) we obtain the
1=2
Kalman gain, Kk , and the updated square root of the error covariance, Pk+1jk , as
Kk = Bk Ak 1
Pk1+1
=2
jk = C k : (6.48)
All that remains is specification of the Householder transformation which is done in the following section.
T = TT
T TT = I
T T = I: (6.51)
Furthermore, the matrix T has a geometric interpretation. The vector uniquely defines a hyper-plane in
RN as the sub-space in RN which is orthogonal to . The matrix T acts as a reflector in that T maps
vectors in RN to their reflected images through the hyper-plane defined by .
Householder transformations can be used to upper triangularize matrices. This is accomplished as fol-
lows. Let A = [a1 ; a2 ; ; aM ] be an N M matrix where ak is an N -vector and let T1 be a Householder
transformation where 1 is constructed such that
2 q 3
PN 2
6 k=1 a1k 7
T1 a1 = a~1 =
6
6 0 7
7 (6.52)
6 .. 7
4 . 5
0
152 CHAPTER 6. OPTIMAL FILTERING AND SMOOTHING
(i.e., we find the 1 such that when a1 is reflected through the hyper-plane defined by 1 its image is as
above). The choice for 1 which accomplishes this goal is
2 q 3
PN 2
6
a11 + k=1 a1k 7
1 =
6
6 a12 7
7 (6.53)
6 .. 7
4 . 5
a1N
where a1k is the k th element of the N -vector a1 .
The Householder transformation, T1 , can be used now to transform the matrix A,
where a
~1 is as in (6.52) and the remaining columns of A are transformed to a~k = T1 ak .
Now we construct a second Householder transformation, T2 such that
2 3
q 21 a~
6 PN 7
6
6
~22k
k=2 a 7
7
T2 a~2 = a~2 = 6
6 0 7
7 (6.55)
6 .. 7
4 . 5
0
That is, the first element of a
~2 is left unchanged, the second element becomes the norm of the rest of the
elements and the remaining elements become zero. The choice for 2 which accomplishes this is
2 3
q
0
6 PN 7
6
6
a~22 + ~22k 7
k=2 a 7
2 = 6
6 a~23 7:
7 (6.56)
6 .. 7
4 . 5
a~2N
Calculating T2 T1 A yields
T2 T1 A = [~a1 ; a~2 ; a~3 ; ; a~M ] (6.57)
where a~1 is still as in (6.52) and a~2 is as in (6.55). Continuing recursively in this way we can upper
triangularize the A matrix.
The Scilab primitive qr performs a triangularization of a matrix using Householder transformations. In
particular, it is the r part of the qr-decomposition which yields the desired triangularized matrix.
where x^(t) denotes the least mean squared estimate and RH P (t; s) is an N M matrix function of two
b M
arguments t and s (i.e., [H (t; s)]ij = hij (t; s) and x
^i (t) = a j =1 hij (t; s)yj (s)ds).
By the principle of orthogonality the error in the estimate in (6.58), x(t) x ^(t), must be orthogonal to
y(u) for t; u 2 [a; b]. Thus,
Z b
0 = E f(x(t) x^(t))yT (u)g = Rxy (t; u) H (t; s)Ryy (s; u)ds: (6.59)
a
Solving the matrix integral equation in (6.59) for H (t; s) yields the optimal estimator for x(t) when used in
(6.58). A general solution of (6.59) is not possible, however, for some very important special cases (6.59) is
resolvable. For example, if the covariance functions Rxy and Ryy are wide sense stationary and with rational
spectral densities then specific solutions techniques are available.
The sections which follow address Wiener filtering for a special formulation of the relationship between
x(t) and y(t) (albeit, a relationship for which many engineering problems of interest can be formulated) and,
consequently, permits a solution to the problem posed by (6.58) and (6.59). This special formulation con-
sists of a state space difference equation identical to that used in the development of the Kalman filter. This
realization has some advantages in that it allows finite interval estimation of non-stationary processes. The
disadvantage of this procedure is that sometimes the only knowledge of the processes x and y is their cov-
ariance structures. In this case, the construction of a state-space model which has the appropriate covariance
characteristics may not always be readily evident.
xk+1 = Fk xk + Gk uk
yk = Hk xk + vk (6.60)
where x0 , uk , and vk are independent and Gaussian random vectors with statistics
uk N (0; Qk )
vk N (0; Rk )
x0 N (m0 ; 0 )
(6.61)
From the formulation in (6.60) and (6.61) one can determine the covariance functions Rxy and Ryy and,
thus, it is reasonable to try and solve a discrete version of (6.59) to obtain the optimal filter. However, there
154 CHAPTER 6. OPTIMAL FILTERING AND SMOOTHING
are certain aspects of the dynamics and observations models which permit a solution to the problem posed
in the previous section without explicitly solving for the filter designated by (6.59).
The solution to the discrete version of (6.58) based on the modelization of the underlying processes given
by (6.60) and (6.61) can be achieved by several different Kalman filter formulations. The particular approach
used here is known as the Rauch-Tung-Striebel formulation [10]. In this approach a Kalman filter is used on
the data in the usual way to obtain estimates x ^kjk 1 and x^kjk along with their associated error covariances
Pkjk 1 and Pkjk . A second recursive filter is then used on the estimates and their error covariances to obtain
the estimates x^kjN and their error covariances PkjN (that is, the estimate and error covariance of xk based
on all the data in the interval [0; N ]). This second filter processes the estimates in the backward direction
using x^N jN and PN jN to initialize the filter, then using x^N 1jN 1 , x^N 1jN 2 , PN 1jN 1 , and PN 1jN 2
to obtain x^N 1jN and PN 1jN , etc., continuing recursively in this way over the entire interval.
A complete development of the Rauch-Tung-Striebel approach is too involved to recount here. We
outline a procedure which may be used to obtain the result without discussing all the details. The interested
reader can find a complete and unified development in [20].
The approach we take is based on a constrained maximum likelihood solution to the problem. We form a
cost function, J (u; v ), which we desire to minimize with respect to its arguments. The function J is defined
by
J (u; v) = uT Q 1 u + vT R 1 v (6.62)
where
2 3
m0
6
6 u0 7
7
u = 6
6 u1 7
7
6 .. 7
4 . 5
uN 1
2 3
v0
6
6 v1 7
7
v = 6 .. 7
4 . 5
vN
2 3
0 0 0
6
6 0 Q0 0 7
7
Q = 6 .. .. .. 7
4 . . . 5
0 0 QN 1
2 3
R0 0 0
6
6 0 R1 0 7
7
R = 6 .. .. .. 7 (6.63)
4 . . . 5
0 0 RN
and where m0 and 0 are the a priori statistics of x0 . The functional in (6.62) is minimized subject to the
constraints
Sx = Gu
y = Hx + v (6.64)
6.3. THE WIENER FILTER 155
where
2 3
x0
6
6 x1 7
7
x = 6 .. 7
4 . 5
xN
2 3
y0
6
6 y1 7
7
y = 6 .. 7
4 . 5
yN
2 3
I 0 0 0
6
6 F0 I 0 0 7
7
S = 6 .. .. .. .. 7
4 . . . . 5
0 FN 1 I 0
2 3
I 0 0
6 0 G
6 0 0 7
7
G = 6 . .. .. 7
4 .. . . 5
0 0 GN 1
2 3
H0 0 0
6
6 0 G1 0 77
H = 6 .. .. .. 7: (6.65)
4 . . . 5
0 0 HN
Minimizing (6.62) subject to the system constraints in (6.64) yields the estimate x
= [^xT0jN ; x^T1jN ; : : : ; x^TN jN ]T .
^T
The optimization can be accomplished using the Lagrange multiplier technique where a new functional J~ is
formed from (6.62) and (6.64)
J~(u; v) = J (u; v) + T (Sx Gu) (6.66)
where , an unknown vector of the same dimension as x, is called the Lagrange multiplier. After some
algebra and setting the partial derivatives of J~ with respect to u and x to zero we obtain the so-called
Hamiltonian (see [15])
S GQGT x^ 0
H R H
T 1 S T ^ = H R 1y :
T (6.67)
x^0 = 0 ^ 0 + m0 (6.69)
which when ^ 0 = 0 yields the usual Kalman filter initial condition x^0j 1 = m0 . The second equation
obtained by the Gaussian elimination is
^1
which, when = 0 and after some algebra, yields the Kalman filter filter-update equation x^0j0 = x^0j 1 +
P0j 1 0
H T (H 0 P0j 1 H0T + R0 ) 1 (y0 H0 x^0j 1 ). Continuing in this way the Gaussian elimination yields the
2N equations
x^kjk = x^kjk 1 + Pkjk 1 HkT (Hk Pkjk 1 HkT + Rk ) 1 (yk Hk x^kjk 1)
x^k+1jk = Fk x^kjk (6.71)
where
After eliminating the lower diagonal of the matrix in (6.68) the upper diagonal is eliminated in the same
way, however, now the ^ k are not set to zero which results in the equations
where
^ k have been identified as the x^kjN . It can be seen that equations (6.71) and (6.72) specify
and where the
the standard Kalman filter. Equations (6.73) and (6.74) yield the Rauch-Tung-Striebel smoother.
-->[xs,ps,xf,pf]=wf(y,x0,p0,f,g,h,q,r)
The inputs f, g, and h are the system matrices in the interval [t0 ; tf ]. The construction of, for example, f is
accomplished by arranging the individual matrices Fk into a block-row matrix [F0 ; F1 ; : : : ; FN ]. The other
system matrices are identical in construction. The inputs q and r are the covariance matrices of dynamics
and observation noise. These matrices are also constructed in a fashion identical to that for f. The inputs
x0 and p0 are the initial state estimate vector and error variance matrix. The vector x0 must be in column
form. Finally, the input y are the observations in the interval [t0 ; tf ]. The form of y is a matrix where the
first column is the observation y0 , the second column y1 , etc. The outputs are the smoothed estimates xs of
x0 , x1 , etc. arranged in a matrix of similar form to y and ps which is arranged identically to the form of the
input matrices.
6.3. THE WIENER FILTER 157
6.3.3 Example
In this section, the wiener function is demonstrated on a two-dimensional problem. The input to the filter
is synthetic data obtained using the same system dynamics given to the wiener function. The system used
in the example is as follows.
xk+1 = 1:15 :1 x + 1 0 w
0 :8 k 0 1 k
1 0
yk = 0 1 x k + vk
where
Ef wk wkT g = :01 0
0 :01
Ef vk vkT g = 20 0
0 20
and
E fx0 g = 10
10
100 0
E f(x0 m0 )(x0 m0 )T g = 0 100
Figure 6.3 shows the results of using the wiener function on the synthetic data generated by the model
above. Here the dotted line indicates the actual state values generated by the system. The circles on the
dotted line serve to mark the actual state locations. The solid line marked by circles indicates the Kalman
filter estimate of the state. The estimate of x0 is located in the upper left corner of the figure and the estimate
of x12 is located in the lower right corner of the figure. As can be seen the initial estimates obtained by the
Kalman filter are not so good with respect to the final estimates obtained by the filter. This is due to the
large initial error covariance matrix given for the initial estimate of the state vector. The solid line marked
by stars is the smoothed Kalman filter estimate. As can be seen, the final smoothed estimate is identical to
that of the regular Kalman filter. However, as the smoothed Kalman filter estimate works its way back to
the initial state value, the estimate becomes greatly improved, as is to be expected since these states are now
estimated based on all of the observed data.
The Scilab code which generated the example in this section is as follows.
-->//test of the wiener filter function
31
27
23
19
15
11
7
3
-1
-5 -1 3 7 11 15 19 23 27 31 35
-->q=[.01 0;00.01];r=20*eye(2,2);
-->rand(seed,66);rand(normal);
-->p0c=chol(p0);x0=m0+p0c*rand(ones(m0));
-->y=h*x0+chol(r)*rand(ones(1:hi));yt=y;
-->x=x0;
-->// loop
-->ft=[f];gt=[g];ht=[h];qt=[q];rt=[r];
-->n=10;
-->for k=1:n,
-->// generate the state and observation at time k (i.e. xk and yk)
-->[x1,y]=system(x0,f,g,h,q,r);
-->x=[x x1];yt=[yt y];x0=x1;
-->ft=[ft f];gt=[gt g];ht=[ht h];
-->qt=[qt q];rt=[rt r];
6.3. THE WIENER FILTER 159
-->[xs,ps,xf,pf]=wiener(yt,m0,p0,ft,gt,ht,qt,rt);
-->a=mini([x(1,:)-2*sqrt(ps(1,1:2:2*(n+1))),xf(1,:),xs(1,:)]);
-->b=maxi([x(1,:)+2*sqrt(ps(1,1:2:2*(n+1))),xf(1,:),xs(1,:)]);
-->c=mini([x(2,:)-2*sqrt(ps(2,2:2:2*(n+1))),xf(2,:),xs(2,:)]);
-->d=maxi([x(2,:)+2*sqrt(ps(2,2:2:2*(n+1))),xf(2,:),xs(2,:)]);
-->xmargin=maxi([abs(a),abs(b)]);
-->ymargin=maxi([abs(c),abs(d)]);
-->a=-0.1*xmargin+a;b=.1*xmargin+b;
-->c=-0.1*ymargin+c;d=.1*ymargin+d;
-->// plot frame, real state (x), and estimates (xf, and xs)
-->plot2d(x(1,:),x(2,:),[2],"000"),
-->plot2d(xf(1,:),xf(2,:),[2],"000"),
-->plot2d(xs(1,:),xs(2,:),[2],"000"),
-->plot2d(xs(1,:),xs(2,:),[-2],"000"),
-->plot2d(xf(1,:),xf(2,:),[-3],"000"),
-->plot2d(x(1,:),x(2,:),[-4],"000"),
160 CHAPTER 6. OPTIMAL FILTERING AND SMOOTHING
Chapter 7
In this chapter, some optimization techniques are investigated for the design of IIR as well as FIR filters.
Those techniques are particuliarly usefull when non standard responses are desired.
where index 0 stands for zeros and index p for poles, no confusion being to be expected with index p in
the L p error criterion. Usually the specifications for a filter are given separately for the magnitude jH (ej! )j
and/or the group delay (! ); the corresponding expressions are:
K
Y (1 2r0k cos(! 0k ) + r02k )1=2 (1 2r0k cos(! + 0k ) + r02k )1=2
=A 2 )1=2 (1 2rpk cos(! + pk ) + r2 )1=2 (7.4)
k=1
(1 2rpk cos(! pk ) + rpk pk
161
162 CHAPTER 7. OPTIMIZATION IN FILTER DESIGN
and
(; !) =
K
rpk cos(! pk ) 1 rpk cos(! + pk )
f (1 21r cos
X
2 1 2 + 2 )1=2
k=1 pk (! pk ) + rpk ) = (1 2rpk cos(! + pk ) + rpk
1 r0k cos(! 0k ) 1 r0k cos(! + 0k )
(1 2r0k cos(! 0k ) + r0k )1=2 (1 2r0k cos(! + 0k ) + r02k )1=2
2 g (7.5)
Defining the desired magnitude response ad (!j ) and group delay d (! ), the minimum L p -design problem
can be formulated by mean of the following error function:
J
X
E () = wa (!j )[a(; !j ) ad (!j )]2p
j =1
J
X
+ (1 ) w (!j )[ (; !j ) d (!j )]2p (7.6)
j =1
where wa (!j ) and w (!j ) are weighting functions defined on a dense grid of frequencies f!j =0 !j g
and is a real number belonging to [0; 1] that reflects the importance of the specifications on the magnitude
relative to that on the group delay in a straightforward fashion. One seek after a vector such that E ( )
is minimum: this problem is easily solved in Scilab with the help of the function optim the purpose of
which is the resolution of general nonlinear optimization problems . We refer the reader to the relevant
documentation [7] for a detailed explanation of its use. The optim function needs some input parameters,
the main of which being what is called a simulator: it may be given as a Scilab function and its purpose is
to give the cost function of the relevant problem as well as its gradient relative to the specified parameters.
For the minimum L p design problem, the simulator is named iirlp and makes use of two other macros:
iirmag and iirgroup; it gives E () together with its gradient relative to .
The following example will give an idea of what can be achieved with this optimization technique: we
are given a low-pass elliptic filter with normalized cut-off frequency 0.25, transition bandwidth equal to
0.15, ripple in the passband of 0.1 and ripple in the stopband of 0.01 (i.e. 40dB of attenuation); with the
Scilab function eqiir we have obtained a filter of the fourth order together with its zeros and poles.
--> [ce0,f0,ze0,po0]=eqiir(lp,ellip,%pi*[.5;.65;0;0],.1,.01);
--> hz0=f0*prod(ce0(2))./prod(ce0(3))
hz0 =
2 3 4
0.1164375 + 0.320825z + 0.4377450z + 0.320825z + 0.1164375z
-----------------------------------------------------------
2 3 4
0.1744334 - 0.3436685z + 0.9682733z - 0.4106181z + z
Now we want to inverse this filter, that is we seek after a filter the magnitude reponse of which times that of
the original elliptic filter equals one in the passband, while in the stopband the total attenuation is less than
80dB. This situation appears for example when a digital filter is needed, after analog-to-digital conversion,
to compensate the deformations of a signal by an anti-aliasing analog filter. The corresponding specifications
are obtained the following way:
7.1. OPTIMIZED IIR FILTERS 163
-->//transition bandwidth0.1
-->[ce0,f0,ze0,po0]=eqiir(lp,ellip,%pi*[.5;.65;0;0],.1,.01);
-->hz0=f0*prod(ce0(2))./prod(ce0(3));
-->//the last value (10) is the initial value of the gain factor.
-->ze0=ze0(1:2:4);po0=po0(1:2:4);
-->x=x0;
-->omega=%pi*(0.01:0.01:1);
-->p=1;
-->wa(1:52)=ones(1,52);
-->wa(53:100)=.5*ones([53:100]);
-->rp0=abs(freq(hz0(2),hz0(3),exp(%i*omega)));
-->//plot(rp0)
164 CHAPTER 7. OPTIMIZATION IN FILTER DESIGN
-->ad(1:49)=ones(1,49)./rp0(1:49);
-->ad(50:100)=rp0(50:100);
-->x=[x0(1:4) x0(5:8)];
-->[cout,xx1,grad,to]=optim(iirmod,x);
-->binf=[0;-2*%pi].*.ones(4,1);
-->bsup=[1;2*%pi].*.ones(4,1);
-->binf=[binf(1:4) binf(5:8)]
binf =
! 0. - 6.2831853 !
! 0. - 6.2831853 !
! 0. - 6.2831853 !
! 0. - 6.2831853 !
-->bsup=[bsup(1:4) bsup(5:8)]
bsup =
! 1. 6.2831853 !
! 1. 6.2831853 !
! 1. 6.2831853 !
! 1. 6.2831853 !
-->[cout,xx2,grad,to]=optim(iirmod,b,binf,bsup,x);
-->z=poly(0,z);
-->z1=xx2(1,1)*exp(%i*xx2(1,2));
-->z2=xx2(2,1)*exp(%i*xx2(2,2));
-->num=(z-z1)*(z-z1)*(z-z2)*(z-z2)
num =
7.1. OPTIMIZED IIR FILTERS 165
real part
2 3 4
0.2608817 + 0.7621389z + 1.5250529z + 1.4539504z + z
imaginary part
2.776D-17 + 5.551D-17z
-->num=real(num);
-->p1=xx2(3,1)*exp(%i*xx2(3,2));
-->p2=xx2(4,1)*exp(%i*xx2(4,2));
-->den=(z-p1)*(z-p1)*(z-p2)*(z-p2);
-->den=real(den);
-->sl=syslin(c,num/den);
-->ff=repfreq(sl,0.01,0.5,0.01);
-->rp1=abs(freq(num,den,exp(%i*omega)));
-->plot(rp1);
-->plot(rp0);
-->xbasc();
-->plot(20.*log(rp0.*rp1));
Although the constraints on the parameters can be easily specified, an unconstrained optimization procedure
has been applied because the initial values are unknown (hence may be far away from the optimal solution, if
any) and the order is unknown too. Instead, as indicated in [23], the Scilab function optim will be applied
several times and when some pole or zero goes outside the unit circle, it will be replaced by the symmetric
(with respect to the unit circle) complex number and a new optimization runned. To see the results obtained
with a constrained optimization, it may be interesting to run the following command, recalling that the
constraints on the poles and zeros are:
0 r0k 1 0 rpk 1
0 0k 2 0 pk 2 (7.7)
hz0 =
166 CHAPTER 7. OPTIMIZATION IN FILTER DESIGN
2 3 4
0.1164375 + 0.320825z + 0.4377450z + 0.320825z + 0.1164375z
-----------------------------------------------------------
2 3 4
0.1744334 - 0.3436685z + 0.9682733z - 0.4106181z + z
-->ze0=ze0(1:2:4);po0=po0(1:2:4);
-->x=x0;
-->omega=%pi*(0.01:0.01:1);
-->wa(1:52)=ones(1,52);
-->wa(53:100)=.5*ones([53:100]);
-->rp0=abs(freq(hz0(2),hz0(3),exp(%i*omega)));
-->ad(1:49)=ones(1,49)./rp0(1:49);
-->ad(50:100)=rp0(50:100);
--> x0 = ...
--> [ 1.
--> 1.
--> 0.8750714
--> 0.4772780
--> 2.0975887
--> 2.636041
--> 1.6018558
--> 1.0620259
--> 10. ];
-->x=[x0(1:4) x0(5:8)];
-->binf=[0;-2*%pi].*.ones(4,1);
-->bsup=[1;2*%pi].*.ones(4,1);
-->binf=[binf(1:4) binf(5:8)]
binf =
! 0. - 6.2831853 !
! 0. - 6.2831853 !
! 0. - 6.2831853 !
! 0. - 6.2831853 !
7.1. OPTIMIZED IIR FILTERS 167
-->bsup=[bsup(1:4) bsup(5:8)]
bsup =
! 1. 6.2831853 !
! 1. 6.2831853 !
! 1. 6.2831853 !
! 1. 6.2831853 !
-->//[cout,xx2,grad,to]=optim(iirmod,b,binf,bsup,x);
Another method to solve this problem would be to run an optimization with penalties on the constraints, in
order to keep the poles and zeros inside the unit circle: we did not try it. Now, back to the unconstrained
optimization, after several runs of optim without constraints, an optimal solution has been achieved for the
chosen filter order. Nevertheless it is seen on Figure 7.1 that this solution is not satisfactory:
magnitude
1.0
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
0 10 20 30 40 50 60 70 80 90 100
normalized frequency
Figure 7.1: exec(optiir.1.code) Minimum mean-square design. Fourth order IIR filter
Figure 7.2 shows that the product of the two magnitude responses is far from being equal to one in the
passband and that the total prescribed attenuation is not achieved (the horizontal line is at -80 dB):
So a second-order block has been added (four more parameters) to the transfer function found at the
preceding step, leading to a filter of order six:
magnitude in dB
0
-10
-20
-30
-40
-50
-60
-70
-80
0 10 20 30 40 50 60 70 80 90 100
normalized frequency
--> 0.8377264
--> 0.3147539
--> 0.9
--> - 3.6886696
--> 2.0017663
--> 1.7
--> 1.605514
--> 1.4517773
--> 1.3
--> 0.1771141 ];
-->omega=%pi*(0.01:0.01:1);
-->z=poly(0,z);
-->num=z-x01(1);
-->den=z-x01(7);
-->for i=1:5
-->num=num*(z-x01(i+1));
-->den=den*(z-x01(i+7));
-->end;
-->sl=syslin(c,num/den);
-->ff=repfreq(sl,0.01,0.5,0.01);
7.1. OPTIMIZED IIR FILTERS 169
-->hz01=abs(freq(num,den,exp(%i*omega)));
The same optimization procedure has been applied with this initial value, resulting in the following solution
vector:
--> x = ...
--> [ 1.
--> 1.
--> 0.6887491
--> 0.8828249
--> 0.1052913
--> 0.7457737
--> - 3.6219555
--> 2.1085705
--> 1.4768262
--> 1.6081331
--> - 0.127d-08
--> 1.3457622
--> 0.1243695 ];
the desired magnitude reponse and the one achieved with that solution appear in Figure 7.3, while the product
of the log-magnitude responses is in Figure 7.4.
1.3
1.2
1.1
1.0
0.9
0.8
0.7
0 10 20 30 40 50 60 70 80 90 100
Figure 7.3: exec(optiir.3.code) Minimum mean-square design. Sixth order IIR filter
170 CHAPTER 7. OPTIMIZATION IN FILTER DESIGN
10
-10
-30
-50
-70
-90
-110
-130
-150
-170
-190
0 10 20 30 40 50 60 70 80 90 100
As we are interested in what happens in the passband, focusing on it is needed: this is done in Figure 7.5
and we see that for ! 2 [0; :45] the ripple is equal to 0.07 dB. The reader may convince himself that better
approximation may be obtained with an increase of the filter order; we mention too that the specification of
ad at the beginning of the transition is not likely to be that of a real filter (it has not a monotone decreasing
behaviour in that region !) and that a more realistic desired response could have been best approximated
with the same number of parameters.
X1
N
H (ej! ) = H (k)S (!; k) (7.8)
k=0
where
jk=N sin(N!=2)
S (!; k) = e
sin(!=2 k=N )
sin(N (!=2) k=N )
= e jk=N (7.9)
sin(!=2 k=N )
7.2. OPTIMIZED FIR FILTERS 171
10
-10
-30
-50
-70
-90
-110
-130
-150
-170
-190
0 10 20 30 40 50 60 70 80 90 100
are the interpolating functions. Usually in filter design, specifications are given in passbands and stopbands
while absent in transition bands for which the width rather is given. For that reason, H (ej! ) can be written:
p
X
H (ej! ) = B (!) + Ti Ai (!) (7.10)
i=1
where B (! ) gives the contribution to H (ej! ) of all the fixed frequency samples (that is those in the pass-
bands and the stopbands) and the Ai (! ) the contribution of all the unconstrained samples (that is the ones
in the transitions) with respective magnitude Ti , these being to be optimized. In the sequel, the union of
passbands will be called region 1,noted R1 and that of passbands region 2, noted R2 . We now want, for a
fixed approximation error in R1 , to find the linear phase FIR filter giving the maximum attenuation in R2 -
note that the converse is another possible issue - This can be formulated as follows:
For some fixed and desired frequency response Hd (ej! ), find the set of Ti , solution of:
Because of the linearity of Hd (ej! ) with respect to the Ti , we are led to a linear programming problem,
the cost function to minimize being the maximum attenuation in R2 , which will be denoted by Tp+1 for
notational convenience and the constraints on the Ti ; i = 1 : : : p, being formulated with the help of (7.12).
The optimization problem may be formulated as to find the set of Ti0 s such that Tp+1 is minimum subject to
172 CHAPTER 7. OPTIMIZATION IN FILTER DESIGN
the constraints: Pp 9
i=1 Ti Ai (! ) B (!) + Hd(ej! ) =
Pp
! 2 R1
i=1 Ti Ai (! ) + B (!) Hd(ej! ) ;
Pp 9
i=1 Ti Ai (! ) Tp+1 B (!) + Hd(ej! ) =
Pp
! 2 R2
i=1 Ti Ai (! ) Tp+1 B (!) Hd(ej! ) ;
Now the problem is in a suitable form for solution via the classical Simplex Method. Let us mention too
that, with minor changes, the problem -and the associated macro- may be stated as to find the filter with
minimum ripple in the passbands for a given attenuation in the stopbands. In the following, only an example
of the standard lowpass filter type is treated although any other frequency response can be approximated
with this method.
Example 1 : figure 7.6 shows the frequency response of a lowpass type 1 filter with the following spe-
cifications: n=64; cut-off frequency, fc =.15; = 0:01; three samples in the transition.
1.2
1.0
0.8
0.6
0.4
0.2
0
0 10 20 30 40 50 60 70
Figure 7.6: exec(optfir1.code) Linear programming design. 64-point lowpass FIR filter
Figure 7.7 shows the log magnitude squared of the initial filter defined by the rectangular window and
the optimized filter. 0:28 and 0:30 = 0:001 and three samples in each transition.
7.2. OPTIMIZED FIR FILTERS 173
100
-100
-200
-300
-400
-500
-600
-700
-800
-900
0 10 20 30 40 50 60 70
Stochastic realization
Let yk be a wide sense stationary gaussian process with covariance function fRn ; n 2 Zg. It is well-known
that yk may be considered as the output of a filter F with a white noise et as input. The Stochastic Realization
problem for yk is the construction of an algorithm giving F ; in addition, F is usually asked to be causal
and minimum delay (i.e. with causal inverse), for reasons of realizability. One major consequence of this
additional constraint is that F , when it exists, is minimal and unique, up to a transformation of coordinates.
The filter F is called the Modeling Filter and its inverse F 1 the Whitening Filter . Let us consider the
following examples, in which the information on yk is given two different ways. First, let be given Sy (z ), the
spectrum of yk . Then, the whitening filter of yk is the solution E (z ) of the Spectral Factorization problem
of Sy (z ), that is the solution of :
E (z )Sy (z )E T (z 1 ) = I (8.1)
such that E (z ) and E 1 (z ) are analytical in the unit disc, that is that the modeling filter of yk is causal
and minimum delay. The stochastic realization problem is then the computation of E (z ), given Sy (ei ).
Solutions to this problem will be given in section 8.1 with direct factorization of matrix polynomials and in
8.2 via a state-space approach.
Another example is when the covariance function Rn = E (yk ykT n ) of yk is given - the information on
yk is then equivalent to that in the previous example- The whitening filter giving the innovation, or prediction
error, is obtained by minimizing with respect to the coefficients Ak , the mean square prediction error :
X
E (ket k2 ) = E fkyk Ak yt k k2 g (8.2)
k>0
The stochastic realization problem is then the computation of the Ak as the solution of the following Yule-
Walker , normal equations :
2 32 3 2 3
R0 R1 R2 : : : A1 R1
6
6 R1T R0 R1 : : : 76
76 A2 7
7
6 R2 7
6 R2T R1T R0 : : : 76 A3 7 =6
6 R3
7
7 (8.3)
4 54 5 4 5
.. .. ..
. . .
This system being Toeplitz, it may be efficiently solved using a Levinson-type algorithm ,as will be exposed
in section 8.4.
175
176 CHAPTER 8. STOCHASTIC REALIZATION
Consider for example the following 2 2 matrix polynomial a(z ), generated from the simulation of a two-
dimensional process with three poles followed by a levinson filtering (see section 8.4):
-->//Spectral factorization
-->z=poly(0,z);
! 2 !
! - 0.44 z + z - 0.15 z !
! !
! 2 !
! - 0.18 z - 0.44 z + z !
-->sp=a*horner(a,1/z);
-->sp=sp*z;
-->sp=sp(2)
sp =
! 2 2 !
! 1 + 3.2161z + z 1 + 2.1452z + z !
! !
! 2 2 !
! 1 + 2.1452z + z 1 + 3.226z + z !
-->d=sfact(sp)
d =
-->d1=horner(d,1/z);
-->d1=d1(2)
d1 =
-->sp-d*d1
ans =
! 0 0 !
! !
! 0 0 !
we have that
8n 1; Rn = HF n 1G (8.7)
Letting Y (z ) and U (z ) be the z-transforms of yk and uk respectively, it follows from (8.5) that :
Y (z ) = (z )U (z ) (8.8)
where
(z ) = J + Hz (I F z) 1L (8.9)
178 CHAPTER 8. STOCHASTIC REALIZATION
is a rational matrix without poles in a vicinity of the unit disc. Thus, the spectrum Sy of yk may be written
in the following factored form:
Sy () = (ei ) (e i ) 2 [ ; ] (8.10)
where denotes the transposed conjugate of . Furthermore, from (8.8), we can write:
U (z ) = 1 (z )Y (z ) (8.11)
and when J > 0 (in the sense of positive matrices) :
1 (z ) = J 1 J 1 Hz (I (F LJ 1 H )z ) 1 LJ 1 (8.12)
so that uk may be obtained from yk by a Laurent expansion of 1 in the vicinity of the unit circle, leading
to the whitening filter .
It is worth noting that when yk is scalar, then (z ) = B (z )=A(z ), where A and B are coprime polyno-
mials and B has no zero in a vicinity of the unit disc; in other words, yk is an ARMA process .
w~k is a stationary, gaussian white noise with covariance R~ . From w~k the standard gaussian white noise u~k
may be obtained as: u ~k = R~ 1=2 w~k .
We are now able to introduce the innovations model:
x~k+1 = F x~k + T w~k+1 (8.15)
yk+1 = H x~k + w~k+1
where
T = E (xk w~kT )R~ 1 (8.16)
From (8.15), we get the following model too :
x~k+1 = F x~k + T R~ 1=2 u~k+1
yk+1 = H x~k + R~ 1=2 u~k+1
(8.17)
which is of the desired type (8.5). The transfer function matrix ~ (z ) of the model (8.17) writes :
~ (z ) = [I + Hz (I F z ) 1 T ]R~ 1=2 (8.18)
and is a maximal factorization of the spectral density of yk , known as the minimum-delay factorization .
One consequence of this fact is that the innovation may be calculated as :
w~k = yk+1 H x~k (8.19)
The importance of the filter model lies in that all the minimal markovian representations of yk have the same
filter, so that the problem we are faced with is to find this filter, given the statistics of yk . For this reason of
uniqueness, we will say that x~k is the filter of yk .
8.3. COMPUTING THE SOLUTION 179
we have that :
HM;N = OC (8.23)
Now, from the observability matrix O , define the two following matrices:
2 3
H
0 6 HF 7
O =6
6 ..
7
7 (8.24)
4 . 5
HF q 2
and 2 3
HF
O" = 6
4
..
.
7
5 (8.25)
HF q 1
It is straightforward that:
0
O" = O F (8.26)
180 CHAPTER 8. STOCHASTIC REALIZATION
so that the matrix F is obtained as the least-squares solution of (8.26). H is obtained as the first bloc-row of
O and G as the first bloc-column of C : this is the PHC approximation method.
Numerically, the factorization (8.23) is done via singular-value decomposition:
The phc macro This macro implements the preceding algorithm to find the triple (H; F; G). In the fol-
lowing example, a 64-point length covariance sequence has been generated for a two-dimensional process,
the first component of which is the sum of two sinusoids with discrete frequencies =10 and 2=10, while
the second component is the sum of two sinusoids with frequencies =10 and 1:9=10, both being in addit-
ive, gaussian white noise. This is done as follows:
-->x=%pi/10:%pi/10:102.4*%pi;
-->rand(seed);rand(normal);
-->y=[.8*sin(x)+.8*sin(2*x)+rand(x);.8*sin(x)+.8*sin(1.99*x)+rand(x)];
-->c=[];
-->c=matrix(c,2,128);cov=[];
-->for j=1:64,cov=[cov;c(:,(j-1)*2+1:2*j)];end;
Then the Hankel matrix HM;N is built with the function hank. Finally, the P siLab function phc gives the
desired triple (H; F; G).
R0 = H P~ H T + R~ (8.29)
G = F P~ H T + T R~ (8.30)
P~ = F P~ F T + T RT
~ T (8.31)
8.3. COMPUTING THE SOLUTION 181
R~ = R0 H P~ H T (8.32)
T = (G F P~ H T )(R0 H P~ H T ) 1 (8.33)
~ and T depend solely on P~ and supposing that R~ is positive, we can write after elimination of
Noting that R
~
R between (8.29), (8.30) and (8.31):
P~ = F P~ F T + (G F P~ H T )(R0 H P~ H T ) 1 (GT H P~ F T ) (8.34)
which is the well-known algebraic Riccati equation . A matrix P~ is called a solution of the Riccati equation
if it is positive definite, such that R0 H P~ H T > 0 and satisfies equation (8.34). Although this equation has
several solutions, the following result gives an answer to our problem: the covariance P~ of the filter is the
minimal solution of the algebraic Riccati equation. We shall give now two algorithms giving this minimal
solution : the Faurre algorithm and the Lindquist algorithm .
The Faurre algorithm [9]: in this method, the solution P~ is obtained as the growing limit of the sequence
of matrices PN such that:
-->x=%pi/10:%pi/10:102.4*%pi;
-->rand(seed,0);rand(normal);sx=sin(x);
-->y=[sx+sin(2*x);sx+sin(1.9*x)]+rand(2,1024);
-->c=[];
-->c=matrix(c,2,128);cov=[];r0=c(1:2,1:2);
-->hk=hank(20,20,c);
-->[h,f,g]=phc(hk,2,6);
-->[p,s1,t1,l1,rT,tT]=srfaur(h,f,g,r0,200);
-->r12=sqrt(.5*(rT+rT));
-->r12=real(r12);f=real(f);tT=real(tT);
-->spec(l1*l1)
ans =
1.0D-17 *
! 0. !
! 0. !
! 0. !
! 0. !
! 647184.16 !
! 94723947. !
-->rand(seed,0);rand(normal);
-->xest=ltitr(f,tT*r12,rand(2,1024));
-->rand(seed,0);rand(normal);
-->yest=h*xest+r12*rand(2,1024);
-->cest=[];
-->cest=matrix(cest,2,128);
8.4. LEVINSON FILTERING 183
The Lindquist algorithm [9]: This algorithm makes use of the fact that R ~ and T may be computed from
K = P~ H instead of P~ itself, leading to substantial computational savings when the observation has a much
T
lower dimension that the state, the most frequent situation. Refering the reader to [9] for the derivations, we
give now the algorithm itself:
8
< KN +1 = KN + N R~ N1 TN H T
N +1 = [F (G F KN )(R0 HKN ) 1 H ] N (8.37)
:
R~ N +1 = R~ N T H T (R
N 0 HKN ) 1 H N
with the initial conditions:
K0 = 0 0 = G R~ 0 = R 0 (8.38)
T = (G F K )(R0 HK ) 1 (8.39)
N
X
= E (yk ykT ) ANj E (yk j ykT )
j =1
N
X
= R0 ANj R j (8.44)
j =1
where the second equality holds from the orthogonality principle between the estimate and the prediction
error. Classically, N is taken as a measure of the quality of the estimation, since it is a monotone decreas-
ing function of N (the longer the sample, the better the estimation). One may for example compare it to
a preassigned mean-square estimation error. So, the problem is to find a procedure which calculates, suc-
cessively for each N , the coefficients AN
j and N . An answer is given with Levinson-type algorithms, an
important property of which is their recursivity in the order: one particularity, relative to other input-output
representations such as state-space models or rational matrices, is that in this approach the filter structure -
its order for example- is considered as a parameter as well as any other, leading to the idea of lattice filter
and to cascade-type realizations of transfer functions. Let us describe now the Levinson algorithm in the
case of a vector-valued time-series, noting that in the scalar case the backward prediction error is no use
because R k = Rk , leading to simpler derivations, albeit similar. For the exposition we shall make use of a
Hilbert space approach, following the treatment given in 5.4.3.
N
X
fk (N ) = yk N BjN yk N +j (8.46)
j =1
with the convention that: ek (0) = fk (0) = yk . We shall need also the following linear space: Ypq =
spanfyp; : : : ; yq g. In the present geometrical approach, the covariance E (xyT ) of x and y will be noted
[x; y] (scalar product) and if E (xyT ) = 0, we shall write x ? y (x orthogonal to y), as well as A ? B for
two orthogonal linear spaces. In view of these definitions, the following relations hold:
ek (N + 1) ek (N ) 2 Ykk N1 1 (8.49)
ek (N + 1) ek (N ) ? Ykk N1 (8.50)
8.4. LEVINSON FILTERING 185
Recalling (8.48), relations (8.49) and (8.50) caracterize the space spanned by fk 1 (N ); hence there exists a
matrix KN such that:
ek (N + 1) ek (N ) = KN fk 1 (N ) (8.51)
[ek (N + 1); yk N 1 ]
= [ek (N ); yk N 1 ] KN :[fk 1(N ); yk N 1] (8.53)
=0
hence giving:
KN = [ek (N ); yk 1
N 1 ][fk 1 (N ); yk N 1] (8.54)
We recognize the second scalar product as the backward mean-square error N . Relations for the backward
prediction error may be obtained the same way; they are:
fk (N + 1) fk 1 (N ) = KN ek (N ) (8.56)
fk (N + 1) ? yk (8.57)
Here too the second scalar product is seen to be the forward mean-square error N . Relations (8.51), (8.54),
(8.56), (8.58) give the sought after recursions; their lattice structure may be explicited with the help of the
following matrix polynomials:
N
X
AN (z ) = I ANj z j (8.59)
j =1
N
X
BN (z ) = z N I BjN z N j (8.60)
j =1
and the covariance matrices: Rn = [yk ; yk n], from which KN and KN may be expressed:
N
X N
X
KN = (RN +1 ANj RN +1 j )(R0 BjN Rj ) 1
j =1 j =1
= N 1 (8.61)
N
186 CHAPTER 8. STOCHASTIC REALIZATION
N
X N
X
KN = (R N 1 BjN R N 1+j )(R0 ANj R j ) 1
j =1 j =1
= N N1 (8.62)
with evident definitions. The last recursion to be given is that for N , for which we will use the expressions
of KN (8.61) and KN in (8.62), and the definition of N :
N = [ek (N ); yk ] (8.63)
N +1 = [ek (N + 1); yk ]
= [ek (N ) N N1 fk 1 (N ); yk ]
= [ek (N ); yk ] N N1 [fk 1 (N ); yk ]
= N N N1 N (8.64)
N +1 = N N N1 N (8.65)
Numerous tools such as DFT, periodogram, maximum entropy method, have been presented in previous
chapters for the spectral analysis of stationary processes. But, in many practical situations (speech, acoustics,
biomedicine applications, ...), this assumption of stationarity fails to be true. Specific tools are then to be
used when the spectral content of a signal under consideration is time dependent. Two such tools will be
presented in this chapter: The W igner -V ille representation and the classical Short-T ime periodogram
, which are particuliar cases of a more general class of spectral estimators[18]. Nevertheless, due to the
superiority of the so-called wigner spectrum, no numerical computation will be done for the short-time
periodogram.
illustrating the symmetry between the definitions in both time and frequency domains. Among the properties
listed in [6] are the -periodicity and the hermitic property, the last leading to the fact that the Wigner
distribution of real signals is real. One more important result is the following:
Z =2
1
Wf (n; )d = jf (n)j2 (9.5)
2 =2
which means that the integral over a period of the Wigner distribution is equal to the instantaneous signal
power.
187
188 CHAPTER 9. TIME-FREQUENCY REPRESENTATIONS OF SIGNALS
where (p; 2k ) is the Fourier transform of a data window caracterizing the weighting on the products. A
first choice of (p; 2k ) is:
1 X
ST P (p; 2k) = hN (j + k)hN (j k)eipj (9.8)
2N 1 j 2Z
leading to the well-known short time periodogram:
1 X
ST P (n; ) = j X (k)hN (k n)e
2N 1 j 2Z
in j2 (9.9)
which actually is the classical periodogram of the signal to which has been applied a sliding window;
smoothed versions may be obtained for this estimator[18] If now (p; 2k ) is chosen to be:
X
SP W (p; 2k) = jhN (k)j2 gM (m)e ipm (9.10)
m2Z
equation (9.6) particularizes in the smoothed pseudo-wigner spectral estimator:
X X
P W (n; ) = 2 e i2k jhN (k)j2 gM (m)X (n + m k)X (n + m k) (9.11)
k 2Z m2Z
where hN (k ) and gM (m) are windows with respective length 2N 1 and 2M 1. One major advantage
in chosing SP W (n; 2k ) is that it is a separable function, so that independent smoothing can be applied in
the time and frequency directions, as opposed to ST P (n; 2k ) which is governed by uncertainty relations
between the time and frequency weightings. Thence, the bias, known to be introduced by weighting func-
tions in spectral estimation, can be controlled separately for the pseudo-wigner estimator. Morever, in the
case of unsmoothed pseudo-wigner (M = 1), the bias in the time direction vanishes while always present
for the short time periodogram.
Now, we can compute the wigner spectrum estimator: let x(n) denote the analytical signal of the
def
sampled realization of the process X (t). Setting M = 1 (unsmoothed estimator) and l = (l=N ),
we can write with the help of (9.10):
X1
N
P W (n; l ) = 2 e i2k(l=N ) jhN (k)j2 x(n + k)x (n k) (9.12)
k= N +1
X1
N
= 2(2Ref e i2k(l=N ) jhN (k)j2 x(n + k)x (n k)g jx(n)j2 )
k=0
9.2. TIME-FREQUENCY SPECTRAL ESTIMATION 189
and this expression may be easily computed via the FFT with the Scilab function wigner.
Example 1 : The following example is taken from [18]: the signal is a finite duration sinusoid modulated
by a parabola:
8
< p(t) sin( 216 t + u(t 488)) 408 < t < 568
S (t) =
:
0 0 t 408 ; 567 t 951
p(t) is the parabolataking its maximum in t = 488, u(t) is the unit step function, hN is the 64-point
rectangular window; the time and frequency increments are respectively equal to 12 and =128; M has
been set to one (unsmoothed estimator). The signal generation and wigner spectrum computation are then
as follows:
-->// parabola
-->b=[1.28;0;0];
-->x=a\b;
-->t=408:568;
-->p=x*[t.*t;t;ones(t)];
-->u=[0*ones(408:487) ones(488:568)];
-->s=p.*sin(2*%pi/16*t+u*%pi);
-->s=[0*ones(0:407) s 0*ones(569:951)];
-->h=ones(1,64);
-->w=wigner(s,h,12,128);
-->plot3d(1:69,1:64,abs(w(1:69,1:64)));
190 CHAPTER 9. TIME-FREQUENCY REPRESENTATIONS OF SIGNALS
-->xend()
115
58
0
1
1.0
32.5 35
Y X
64.0 69
[1] M. Abramowitz, I.A. Stegun, eds., Handbook of Mathematical Functions, National Bureau of Stand-
ards Applied Mathematics Series, no. 55, Superintendent of Documents, U.S. Goverment Printing
Office, Washington, D.C., 1964.
[2] B.D.O. Anderson and J.B. Moore, Optimal Filtering, Englewood Cliffs, NJ: Prenctice Hall, 1979.
[3] Gerald J. Bierman, Factorization Methods for Discrete Sequential Estimation, Academic Press, New
York, 1977.
[4] B.C. Carlson, Special Functions of Applied Mathematics, Academic Press, New York, 1977.
[6] T.A.C.M. Claasen and W.F.G. Mecklenbrauker, The Wigner distribution: a tool for time frequency
signal analysis, Phillips J. Res., vol. 35, pp. 217-250, 276-300, 372-389, 1980.
[7] F. Delebecque, C. Klimann and S. Steer, Basile, guide dutilisation, Internal Report INRIA, 1987.
[9] P. Faurre, Realisations markoviennes de processus stationnaires , These detat, Rapport Laboria n0 13,
1973.
[11] Francis B. Hildebrand, Methods of Applied Mathematics, Prentice Hall, Englewood Cliffs, N.J., 1965.
[12] B.L. Ho and R.E. Kalman, Effective construction of linear state variable models from Input/Output
data, Proc. 3rd Allerton Conference, 1963.
[13] R. Hooke, T.A. Jeeves, Direct Search solution of numerical and statistical problems, Journ. Assoc.
Comput. Mach., Vol 8 No 2, pp 212-229, April 1961.
[14] T. Kailath, Lectures on Wiener and Kalman Filtering, Springer-Verlag, New York, 1981.
[16] Steven M. Kay and Stanley L. Marple, Spectrum Analysis - A Modern Perspective, Proc. IEEE, vol.
69, no. 11, pp. 1380-1419, Nov. 1981.
[17] S. Kung, A new identification and model reduction algorithm via singular value decompositions,
Proc. 12th Asilomar Conf. Circuits, Syst. Comput., Pacific Grove, CA, pp 705-714, Nov 1978.
[18] W. Martin and P. Flandrin, Wigner-Ville spectral analysis of nonstationary processes, IEEE Trans.
Acoust., Speech, Signal Processing, Vol. ASSP-33, N0 6, Dec. 1985.
191
192 BIBLIOGRAPHY
[19] C. Moler, MATLAB Users Guide, Tech. Rep. CS81-1, Dept. of Computer Sci., Univ. New Mexico,
August, 1982.
[20] R. Nikoukhah, A Deterministic and Stochastic Theory of Two-Point Boundary-Value Descriptor Sys-
tems, Ph.D. dissertation, Dept. of Elec. Eng. and Comp. Science, M.I.T., 1988.
[21] A.V. Oppenheim and R.W. Schafer, Digital Signal Processing, Prentice Hall, 1975.
[23] Programs for Digital Signal Processing, IEEE Press John Wiley and Sons, 1979.
[24] L. Rabiner and B. Gold, Theory and Application of Digital Signal Processing, Prentice Hall, 1975.
[25] L.R. Rabiner, R.W. Schafer, and C.M. Rader, The Chirp Z-Transform Algorithm and its Applica-
tions, Bell Sys. Tech. J., vol 48, pp. 1249-1292, May 1969.
[26] J. Rissanen, Recursive identification of linear systems, SIAM Journal of Control, Vol 9, 1971.
[27] G. Ruckebusch, Representations markoviennes de processus gaussiens stationnaires, These 3eme cyle
math. stat., Paris VI, 1975.
[28] K. Steiglitz, Designing Short-Word recursive digital filters, Proc. 9th Allerton Conf. on Circuit and
Systems Theory, pp 778-788, Oct. 1971.
[29] G.W. Stewart, Introduction to Matrix Computations, Academic Press, New York, 1973.
[30] C.F. Van Loan, Computing integrals involving matrix exponentials, IEEE Trans. Autom. Control, vol
AC-23, pp. 395-404, 1978.
List of Figures
193
194 LIST OF FIGURES
7.1 exec(optiir.1.code) Minimum mean-square design. Fourth order IIR filter . . . . 167
7.2 exec(optiir.2.code) Resulting magnitude response. Log scale . . . . . . . . . . 168
7.3 exec(optiir.3.code) Minimum mean-square design. Sixth order IIR filter . . . . 169
7.4 exec(optiir.4.code) Resulting magnitude response. Log scale . . . . . . . . . . 170
7.5 exec(optiir.5.code) Log-magnitude response. ! 2 [0; 0:45] . . . . . . . . . . . 171
7.6 exec(optfir1.code) Linear programming design. 64-point lowpass FIR filter . . . 172
7.7 exec(optfir2.code) Linear programming design. . . . . . . . . . . . . . . . . . 173
A F
analog filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 Faurre algorithm . . . . . . . . . . . . . . . . . . . . . . . . . 181
Butterworth . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 FFT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
Chebyshev . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88 examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
first type . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88 filter
second type . . . . . . . . . . . . . . . . . . . . . . . . . 91 model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178
elliptic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94 FIR filter design
arma process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178 examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
frequency sampling . . . . . . . . . . . . . . . . . . . . 72
B function syntax . . . . . . . . . . . . . . . . . . . . . . . . 69
bilinear transform . . . . . . . . . . . . . . . . . . . . . . . . 109 minimax optimization . . . . . . . . . . . . . . . . . .74
Bode plot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 windowing technique . . . . . . . . . . . . . . . . . . 63
examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 FIR filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .63
Bode plot,function syntax . . . . . . . . . . . . . . . . . . 24 Fourier transform . . . . . . . . . . . . . . . . . . . . . . . . . 187
Butterworth filter . . . . . . . . . . . . . . . . . . . . . . . . . . 85 function syntax
bode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
C
convol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
Chandrasekhar . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
dscr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
changing system representation . . . . . . . . . . . . . . 9
eqfir . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
Chebyshev approximation . . . . . . . . . . . . . . . . . . 75
eqiir . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
Chebyshev filter . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
flts
first type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
for state-space . . . . . . . . . . . . . . . . . . . . . . 14
second type . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
for transfer function . . . . . . . . . . . . . . . . . 14
chirp z-transform . . . . . . . . . . . . . . . . . . . . . . . . . . 56
frmag . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
group . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
convolution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
iir . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
function syntax . . . . . . . . . . . . . . . . . . . . . . . . 55
kalm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
correlation method . . . . . . . . . . . . . . . . . . . . . . . 126
load . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
cost function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162 read . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
remezb . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
D roots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
decimation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40, 44 save . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
DFT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .46 srkf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
discretization of continuous systems . . . . . . . . . 12 ss2tf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
sskf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
E syslin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
elliptic filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94 tf2ss . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
elliptic function . . . . . . . . . . . . . . . . . . . . . . . . . . . 97 wfir . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
elliptic integral . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94 wiener . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156
error criterion . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161 write . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
196
INDEX 197
G library siglib . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
gaussian Lindquist algorithm . . . . . . . . . . . . . . . . . . . . . . . 181
process . . . . . . . . . . . . . . . . . . . . . . . . . 175, 177 linear programming . . . . . . . . . . . . . . . . . . . . . . . 170
space . . . . . . . . . . . . . . . . . . . . . . . . . . . 177, 178
white noise . . . . . . . . . . . . . . . . . . . . . . . . . . 177 M
Gaussian random vectors macro syntax
conditional statistics . . . . . . . . . . . . . . . . . . 133 lev . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
filtered by linear systems . . . . . . . . . . . . . . 134 mese . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
recursive estimation . . . . . . . . . . . . . . . . . . 135 macro,spfact . . . . . . . . . . . . . . . . . . . . . . . . . . 176
group delay . . . . . . . . . . . . . . . . . . . . . . 27, 161, 162 magnitude response . . . . . . . . . . . . . . . . . . . . . . . 162
function syntax . . . . . . . . . . . . . . . . . . . . . . . . 32 markovian
model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177
H representation . . . . . . . . . . . . . . . . . . . . . . . . 178
hankel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179 matrix polynomial . . . . . . . . . . . . . . . . . . . . . . . . 175
Householder transformation . . . . . . . . . . . . . . . 151 maximum entropy method . . . . . . . . . . . . . . . . . 127
examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
I
macro syntax . . . . . . . . . . . . . . . . . . . . . . . . 129
IIR filter design . . . . . . . . . . . . . . . . . . . . . . . . . . 106
mean-square error . . . . . . . . . . . . . . . . . . . . . . . . 161
alternate implementation . . . . . . . . . . . . . . 115
minimax approximation . . . . . . . . . . . . . . . . . . . . 75
examples . . . . . . . . . . . . . . . . . . . . . . . 114, 116
minimum
function code . . . . . . . . . . . . . . . . . . . . . . . . 115
delay . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175
function syntax . . . . . . . . . . . . . . . . . . . . . . 113
factorization . . . . . . . . . . . . . . . . . . . . . . . 178
IIR filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
Lp error . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
innovation . . . . . . . . . . . . . . . . . . . . . . . . . . 175, 178
minimum Lp design . . . . . . . . . . . . . . . . . . . . . . 161
innovations
modeling filter . . . . . . . . . . . . . . . . . . . . . . . . . . . 175
model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178
process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178
O
interconnecting systems . . . . . . . . . . . . . . . . . . . . 11
observability matrix . . . . . . . . . . . . . . . . . . . . . . 179
interpolation . . . . . . . . . . . . . . . . . . . . . . . . . . . 40, 43
optimal filtering and smoothing . . . . . . . . . . . . 133
interpolation-decimation
optimal FIR filter design . . . . . . . . . . . . . . . . . . . 75
example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
K function syntax . . . . . . . . . . . . . . . . . . . . 77, 81
Kalman filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133 optimization . . . . . . . . . . . . . . . . . . . . . . . . . 161, 162
asymptotic properties . . . . . . . . . . . . . . . . . 138 optimized
equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136 FIR filters . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140 IIR filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
function syntax . . . . . . . . . . . . . . . . . . . . . . 140
square root . . . . . . . . . . . . . . . . . . . . . . . . . . 149 P
function syntax . . . . . . . . . . . . . . . . . . . . 152 periodogram method . . . . . . . . . . . . . . . . . . . . . . 122
steady state example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
example . . . . . . . . . . . . . . . . . . . . . . . . . . . 139 phase delay . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
function syntax . . . . . . . . . . . . . . . . . . . . 139 plotting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
continuous magnitude . . . . . . . . . . . . . . . . . .17
L discrete magnitude . . . . . . . . . . . . . . . . . . . . 18
levinson . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176, 184 impulse response . . . . . . . . . . . . . . . . . . . . . . 15
levinson filters poles and zeros . . . . . . . . . . . . . . . . . . . . . . . . 19
lattice filters . . . . . . . . . . . . . . . . . . . . . . . . . 183 poly . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Levinsons algorithm . . . . . . . . . . . . . . . . . . . . . 129 polynomials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
macro syntax . . . . . . . . . . . . . . . . . . . . . . . . 130 evaluation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
198 INDEX
T
time series . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
time-frequency . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
toeplitz . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175, 183
toolbox library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
transforming low pass filters . . . . . . . . . . . . . . . 112
transition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
W
whitening filter . . . . . . . . . . . . . . . . . . . . . . . . . . . 175
Wiener filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
function syntax . . . . . . . . . . . . . . . . . . . . . . 156
wigner . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
windowing
FIR filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63