You are on page 1of 800

Computa tion

Visua liza tion


Progra mming
For Use w ith MATLAB

Users Guide
Version 5
Signal Processing
Toolbox
How to Conta ct The Ma thW orks:
www.mathworks.com Web
comp.soft-sys.matlab Newsgroup
support@mathworks.com Techni cal support
suggest@mathworks.com Product enhancement suggesti ons
bugs@mathworks.com Bug reports
doc@mathworks.com Documentati on error reports
service@mathworks.com Order status, l i cense renewal s, passcodes
info@mathworks.com Sal es, pri ci ng, and general i nformati on
508-647-7000 Phone
508-647-7001 Fax
The MathWorks, I nc. Mai l
3 Appl e Hi l l Dri ve
Nati ck, MA 01760-2098
For contact i nformati on about worl dwi de offi ces, see the MathWorks Web si te.
Signal Processing Toolbox Users Guide
COPYRI GHT 1988 - 2001 by The MathWorks, I nc.
The software descri bed i n thi s document i s furni shed under a l i cense agreement. The software may be used
or copi ed onl y under the terms of the l i cense agreement. No part of thi s manual may be photocopi ed or repro-
duced i n any form wi thout pri or wri tten consent from The MathWorks, I nc.
FEDERAL ACQUI SI TI ON: Thi s provi si on appl i es to al l acqui si ti ons of the Program and Documentati on by
or for the federal government of the Uni ted States. By accepti ng del i very of the Program, the government
hereby agrees that thi s software qual i fi es as "commerci al " computer software wi thi n the meani ng of FAR
Part 12.212, DFARS Part 227.7202-1, DFARS Part 227.7202-3, DFARS Part 252.227-7013, and DFARS Part
252.227-7014. The terms and condi ti ons of The MathWorks, I nc. Software Li cense Agreement shal l pertai n
to the governments use and di scl osure of the Program and Documentati on, and shal l supersede any
confl i cti ng contractual terms or condi ti ons. I f thi s l i cense fai l s to meet the governments mi ni mum needs or
i s i nconsi stent i n any respect wi th federal procurement l aw, the government agrees to return the Program
and Documentati on, unused, to MathWorks.
MATLAB, Si mul i nk, Statefl ow, Handl e Graphi cs, and Real -Ti me Workshop are regi stered trademarks, and
Target Language Compi l er i s a trademark of The MathWorks, I nc.
Other product or brand names are trademarks or regi stered trademarks of thei r respecti ve hol ders.
Pri nti ng Hi story: 1988 Ori gi nal pri nti ng
January 1997 Fi rst pri nti ng New for MATLAB 5.1
January 1998 Second pri nti ng Revi sed for MATLAB 5.2
January 1999 (Onl i ne onl y) Revi sed for Versi on 4.2 (Rel ease 11)
August 1999 (Onl i ne onl y) Revi sed for Versi on 4.3 (Rel ease 11.1)
September 2000 Thi rd pri nti ng Revi sed for Versi on 5.0 (Rel ease 12)
June 2001 (Onl i ne onl y) Revi sed for Versi on 5.1 (Rel ease 12.1)
i
Contents
Preface
Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvi
What Is the Signal Processing Toolbox? . . . . . . . . . . . . . . . . xvii
R12 Related Products List . . . . . . . . . . . . . . . . . . . . . . . . . . . . xviii
How to Use This Manual . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxi
I f You Are a New User . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxi
I f You Are an Experi enced Tool box User . . . . . . . . . . . . . . . . . xxii
Al l Tool box Users . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxii
Installing the Signal Processing Toolbox . . . . . . . . . . . . . . . xxiii
Technical Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiv
Typographical Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . xxv
1
Signal Processing Basics
Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2
Signal Processing Toolbox Central Features . . . . . . . . . . . . 1-3
Fi l teri ng and FFTs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-3
Si gnal s and Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-3
Key Areas: Fi l ter Desi gn and Spectral Anal ysi s . . . . . . . . . . . . 1-3
I nteracti ve Tool s: SPTool and FDATool . . . . . . . . . . . . . . . . . . . 1-4
Extensi bi l i ty . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-4
ii Contents
Representing Signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-5
Vector Representati on . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-5
Waveform Generation: Time Vectors and Sinusoids . . . . . . 1-7
Common Sequences: Uni t I mpul se, Uni t Step, and Uni t Ramp 1-8
Mul ti channel Si gnal s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-8
Common Peri odi c Waveforms . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-9
Common Aperi odi c Waveforms . . . . . . . . . . . . . . . . . . . . . . . . . 1-10
The pul stran Functi on . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-11
The Si nc Functi on . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-12
The Di ri chl et Functi on . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-13
Working with Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-14
Filter Implementation and Analysis . . . . . . . . . . . . . . . . . . . 1-15
Convol uti on and Fi l teri ng . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-15
Fi l ters and Transfer Functi ons . . . . . . . . . . . . . . . . . . . . . . . . . 1-16
Fi l ter Coeffi ci ents and Fi l ter Names . . . . . . . . . . . . . . . . . . 1-16
Fi l teri ng wi th the fi l ter Functi on . . . . . . . . . . . . . . . . . . . . . . . 1-17
The filter Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-18
Other Functions for Filtering . . . . . . . . . . . . . . . . . . . . . . . . . 1-20
Mul ti rate Fi l ter Bank I mpl ementati on . . . . . . . . . . . . . . . . . . 1-20
Anti -Causal , Zero-Phase Fi l ter I mpl ementati on . . . . . . . . . . . 1-21
Frequency Domai n Fi l ter I mpl ementati on . . . . . . . . . . . . . . . . 1-23
Impulse Response . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-24
Frequency Response . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-25
Di gi tal Domai n . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-25
Anal og Domai n . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-27
Magni tude and Phase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-27
Del ay . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-29
Zero-Pole Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-31
Linear System Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-33
Di screte-Ti me System Model s . . . . . . . . . . . . . . . . . . . . . . . . . . 1-33
iii
Transfer Functi on . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-33
Zero-Pol e-Gai n . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-34
State-Space . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-35
Parti al Fracti on Expansi on (Resi due Form) . . . . . . . . . . . . 1-36
Second-Order Secti ons (SOS) . . . . . . . . . . . . . . . . . . . . . . . . 1-38
Latti ce Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-38
Convol uti on Matri x . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-41
Conti nuous-Ti me System Model s . . . . . . . . . . . . . . . . . . . . . . . 1-42
Li near System Transformati ons . . . . . . . . . . . . . . . . . . . . . . . . 1-43
Discrete Fourier Transform . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-45
Selected Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-48
2
Filter Design
Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-2
Filter Requirements and Specification . . . . . . . . . . . . . . . . . . 2-3
IIR Filter Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-5
Cl assi cal I I R Fi l ter Desi gn Usi ng Anal og Prototypi ng . . . . . . . 2-7
Compl ete Cl assi cal I I R Fi l ter Desi gn . . . . . . . . . . . . . . . . . . . 2-7
Desi gni ng I I R Fi l ters to Frequency Domai n Speci fi cati ons . 2-8
Compari son of Cl assi cal I I R Fi l ter Types . . . . . . . . . . . . . . . . . . 2-9
Butterworth Fi l ter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-9
Chebyshev Type I Fi l ter . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-10
Chebyshev Type I I Fi l ter . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-11
El l i pti c Fi l ter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-11
Bessel Fi l ter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-12
Di rect I I R Fi l ter Desi gn . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-14
General i zed Butterworth Fi l ter Desi gn . . . . . . . . . . . . . . . . 2-15
FIR Filter Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-17
Li near Phase Fi l ters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-18
Wi ndowi ng Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-19
iv Contents
Standard Band FI R Fi l ter Desi gn: fi r1 . . . . . . . . . . . . . . . . 2-21
Mul ti band FI R Fi l ter Desi gn: fi r2 . . . . . . . . . . . . . . . . . . . . 2-22
Mul ti band FI R Fi l ter Desi gn wi th Transi ti on Bands . . . . . . . 2-23
Basi c Confi gurati ons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-23
The Wei ght Vector . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-26
Anti -Symmetri c Fi l ters /Hi l bert Transformers . . . . . . . . . . 2-26
Di fferenti ators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-27
Constrai ned Least Squares FI R Fi l ter Desi gn . . . . . . . . . . . . . 2-28
Basi c Lowpass and Hi ghpass CLS Fi l ter Desi gn . . . . . . . . . 2-29
Mul ti band CLS Fi l ter Desi gn . . . . . . . . . . . . . . . . . . . . . . . . 2-30
Wei ghted CLS Fi l ter Desi gn . . . . . . . . . . . . . . . . . . . . . . . . . 2-31
Arbi trary-Response Fi l ter Desi gn . . . . . . . . . . . . . . . . . . . . . . . 2-32
Mul ti band Fi l ter Desi gn . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-33
Fi l ter Desi gn wi th Reduced Del ay . . . . . . . . . . . . . . . . . . . . 2-35
Special Topics in IIR Filter Design . . . . . . . . . . . . . . . . . . . . 2-38
Anal og Prototype Desi gn . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-39
Frequency Transformati on . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-39
Fi l ter Di screti zati on . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-42
I mpul se I nvari ance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-42
Bi l i near Transformati on . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-43
Selected Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-46
3
Statistical Signal Processing
Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-2
Correlation and Covariance . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-3
Bi as and Normal i zati on . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-4
Mul ti pl e Channel s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-5
Spectral Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-6
Spectral Esti mati on Method Overvi ew . . . . . . . . . . . . . . . . . . . . 3-8
Nonparametri c Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-10
The Peri odogram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-10
v
Performance of the Peri odogram 3-12
The Modi fi ed Peri odogram . . . . . . . . . . . . . . . . . . . . . . . . . . 3-18
Wel chs Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-20
Bi as and Normal i zati on i n Wel chs Method . . . . . . . . . . . . . 3-23
Mul ti taper Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-24
Cross-Spectral Densi ty Functi on . . . . . . . . . . . . . . . . . . . . . 3-27
Confi dence I nterval s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-27
Transfer Functi on Esti mate . . . . . . . . . . . . . . . . . . . . . . . . . 3-28
Coherence Functi on . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-29
Parametri c Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-30
Yul e-Wal ker AR Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-32
Burg Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-33
Covari ance and Modi fi ed Covari ance Methods . . . . . . . . . . 3-36
MUSI C and Ei genvector Anal ysi s Methods . . . . . . . . . . . . . 3-36
Ei genanal ysi s Overvi ew . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-37
Selected Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-39
4
Special Topics
Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-2
Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-3
Basi c Shapes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-3
General i zed Cosi ne Wi ndows . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-5
Kai ser Wi ndow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-6
Kai ser Wi ndows i n FI R Desi gn . . . . . . . . . . . . . . . . . . . . . . . . 4-8
Chebyshev Wi ndow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-10
Parametric Modeling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-12
Ti me-Domai n Based Model i ng . . . . . . . . . . . . . . . . . . . . . . . . . 4-14
Li near Predi cti on . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-14
Pronys Method (ARMA Model i ng) . . . . . . . . . . . . . . . . . . . . 4-15
Stei gl i tz-McBri de Method (ARMA Model i ng) . . . . . . . . . . . 4-17
Frequency-Domai n Based Model i ng . . . . . . . . . . . . . . . . . . . . . 4-19
vi Contents
Resampling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-22
Cepstrum Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-25
I nverse Compl ex Cepstrum . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-27
FFT-Based Time-Frequency Analysis . . . . . . . . . . . . . . . . . . 4-29
Median Filtering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-30
Communications Applications . . . . . . . . . . . . . . . . . . . . . . . . . 4-31
Deconvolution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-35
Specialized Transforms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-36
Chi rp z-Transform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-36
Di screte Cosi ne Transform . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-38
Hi l bert Transform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-40
Selected Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-42
5
Filter Design and Analysis Tool
Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-2
Fi l ter Desi gn Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-3
Usi ng the Fi l ter Desi gn and Anal ysi s Tool . . . . . . . . . . . . . . . . . 5-4
Anal yzi ng Fi l ter Responses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-4
Fi l ter Desi gn and Anal ysi s Tool Modes . . . . . . . . . . . . . . . . . . . 5-4
Getti ng Hel p . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-5
Opening the Filter Design and Analysis Tool . . . . . . . . . . . . 5-6
Choosing a Filter Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-7
Choosing a Filter Design Method . . . . . . . . . . . . . . . . . . . . . . . 5-8
vii
Setting the Filter Design Specifications . . . . . . . . . . . . . . . . . 5-9
Bandpass Fi l ter Frequency Speci fi cati ons . . . . . . . . . . . . . . . . . 5-9
Bandpass Fi l ter Magni tude Speci fi cati ons . . . . . . . . . . . . . . . . 5-10
Fi l ter Order . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-11
Computing the Filter Coefficients . . . . . . . . . . . . . . . . . . . . . 5-12
Analyzing the Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-13
Converting the Filter Structure . . . . . . . . . . . . . . . . . . . . . . . 5-15
Importing a Filter Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-17
Fi l ter Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-18
Di rect Form . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-18
Di rect Form I I (Second-Order Secti ons) . . . . . . . . . . . . . . . . 5-19
State-Space . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-19
Latti ce . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-19
Quanti zed Fi l ter (Qfi l t Object) . . . . . . . . . . . . . . . . . . . . . . . 5-20
Exporting a Filter Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-21
Exporti ng Fi l ter Coeffi ci ents to the Workspace . . . . . . . . . . . . 5-21
Exporti ng Fi l ter Coeffi ci ents to a Text Fi l e . . . . . . . . . . . . . . . 5-22
Exporti ng to a C Header Fi l e . . . . . . . . . . . . . . . . . . . . . . . . . . 5-22
Saving and Opening Filter Design Sessions . . . . . . . . . . . . . 5-25
6
SPTool: A Signal Processing GUI Suite
Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-2
SPTool: An Interactive Signal Processing Environment . . 6-3
SPTool Data Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-3
Opening SPTool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-5
viii Contents
Getting Help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-7
Context-Sensi ti ve Hel p: The Whats Thi s? Button . . . . . . . . . . 6-7
Overview of the Signal Browser: Signal Analysis . . . . . . . . . 6-8
Openi ng the Si gnal Browser . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-8
Overview of the Filter Designer: Filter Design . . . . . . . . . . 6-11
Fi l ter Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-11
FI R Fi l ter Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-11
I I R Fi l ter Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-11
Pol e/Zero Edi tor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-12
Spectral Overl ay Feature . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-12
Openi ng the Fi l ter Desi gner . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-12
Overview of the Filter Viewer: Filter Analysis . . . . . . . . . . 6-14
Openi ng the Fi l ter Vi ewer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-14
Overview of the Spectrum Viewer: Spectral Analysis . . . . 6-17
Openi ng the Spectrum Vi ewer . . . . . . . . . . . . . . . . . . . . . . . . . 6-17
Using SPTool: Filtering and Analysis of Noise . . . . . . . . . . 6-20
I mporti ng a Si gnal i nto SPTool . . . . . . . . . . . . . . . . . . . . . . . . . 6-20
Desi gni ng a Fi l ter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-22
Openi ng the Fi l ter Desi gner . . . . . . . . . . . . . . . . . . . . . . . . . 6-22
Speci fyi ng the Bandpass Fi l ter . . . . . . . . . . . . . . . . . . . . . . . 6-22
Appl yi ng a Fi l ter to a Si gnal . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-24
Anal yzi ng Si gnal s: Openi ng the Si gnal Browser . . . . . . . . . . . 6-26
Pl ayi ng a Si gnal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-27
Pri nti ng a Si gnal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-27
Spectral Anal ysi s i n the Spectrum Vi ewer . . . . . . . . . . . . . . . . 6-28
Creati ng a PSD Object From a Si gnal . . . . . . . . . . . . . . . . . 6-29
Openi ng the Spectrum Vi ewer wi th Two Spectra . . . . . . . . 6-29
Pri nti ng the Spectra . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-30
Exporting Signals, Filters, and Spectra . . . . . . . . . . . . . . . . 6-32
Openi ng the Export Di al og Box . . . . . . . . . . . . . . . . . . . . . . 6-32
Exporti ng a Fi l ter to the MATLAB Workspace . . . . . . . . . . 6-33
Accessing Filter Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . 6-34
ix
Accessi ng Fi l ter Parameters i n a Saved Fi l ter . . . . . . . . . . . . . 6-34
The tf Fi el d: Accessi ng Fi l ter Coeffi ci ents . . . . . . . . . . . . . . 6-34
The Fs Fi el d: Accessi ng Fi l ter Sampl e Frequency . . . . . . . . 6-34
The specs Fi el d: Accessi ng other Fi l ter Parameters . . . . . . 6-35
Accessi ng Parameters i n a Saved Spectrum . . . . . . . . . . . . . . 6-37
Importing Filters and Spectra into SPTool . . . . . . . . . . . . . 6-39
I mporti ng Fi l ters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-39
I mporti ng Spectra . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-41
Loading Variables from the Disk . . . . . . . . . . . . . . . . . . . . . . 6-43
Selecting Signals, Filters, and Spectra in SPTool . . . . . . . . 6-44
Editing Signals, Filters, or Spectra in SPTool . . . . . . . . . . . 6-45
Designing a Filter with the Pole/Zero Editor . . . . . . . . . . . . 6-46
Posi ti oni ng Pol es and Zeros . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-47
Redesigning a Filter Using the Magnitude Plot . . . . . . . . . 6-49
Setting Preferences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-50
Making Signal Measurements: Using Markers . . . . . . . . . . 6-52
7
Function Reference
Function Category List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-3
Alphabetical List of Functions . . . . . . . . . . . . . . . . . . . . . . . . . . 20
abs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-26
ac2pol y . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-27
ac2rc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-28
angl e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-29
arburg . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-30
x Contents
arcov . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-31
armcov . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-32
aryul e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-33
barthannwi n . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-34
bartl ett . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-36
bessel ap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-38
bessel f . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-39
bi l i near . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-42
bi trevorder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-47
bl ackman . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-49
bl ackmanharri s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-51
bohmanwi n . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-53
buffer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-55
buttap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-64
butter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-65
buttord . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-70
cceps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-75
cel l 2sos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-77
cheb1ap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-78
cheb1ord . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-79
cheb2ap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-83
cheb2ord . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-84
chebwi n . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-89
cheby1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-90
cheby2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-95
chi rp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-100
cohere . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-106
conv . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-110
conv2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-111
convmtx . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-113
corrcoef . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-115
corrmtx . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-116
cov . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-119
cpl xpai r . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-120
cremez . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-121
csd . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-129
czt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-133
dct . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-136
deci mate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-138
deconv . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-141
xi
demod . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-142
dftmtx . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-144
di ri c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-145
downsampl e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-146
dpss . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-148
dpsscl ear . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-151
dpssdi r . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-152
dpssl oad . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-153
dpsssave . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-154
el l i p . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-155
el l i pap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-161
el l i pord . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-162
eqtfl ength . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-167
fdatool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-168
fft . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-170
fft2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-173
fftfi l t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-174
fftshi ft . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-176
fi l ter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-177
fi l ter2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-180
fi l ternorm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-181
fi l tfi l t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-183
fi l ti c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-184
fi r1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-186
fi r2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-190
fi rcl s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-193
fi rcl s1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-196
fi rl s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-199
fi rrcos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-204
freqs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-206
freqspace . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-208
freqz . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-209
freqzpl ot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-213
fvtool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-216
gauspul s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-220
gausswi n . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-222
gmonopul s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-224
goertzel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-226
grpdel ay . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-231
hammi ng . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-234
xii Contents
hann . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-236
hi l bert . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-238
i cceps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-242
i dct . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-243
i fft . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-244
i fft2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-245
i mpi nvar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-246
i mpz . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-248
i nterp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-251
i ntfi l t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-253
i nvfreqs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-255
i nvfreqz . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-259
i s2rc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-262
kai ser . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-263
kai serord . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-265
l ar2rc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-270
l atc2tf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-271
l atcfi l t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-272
l evi nson . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-274
l p2bp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-276
l p2bs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-279
l p2hp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-281
l p2l p . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-283
l pc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-285
l sf2pol y . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-289
maxfl at . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-290
medfi l t1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-292
modul ate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-293
nuttal l wi n . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-296
pburg . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-299
pcov . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-304
pei g . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-309
peri odogram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-316
pmcov . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-321
pmtm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-326
pmusi c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-331
pol y2ac . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-339
pol y2l sf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-340
pol y2rc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-341
pol yscal e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-343
xiii
pol ystab . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-344
prony . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-345
psdpl ot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-347
pul stran . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-349
pwel ch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-353
pyul ear . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-359
rc2ac . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-364
rc2i s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-365
rc2l ar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-366
rc2pol y . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-367
rceps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-368
rectpul s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-369
rectwi n . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-370
remez . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-371
remezord . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-378
resampl e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-381
resi duez . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-384
rl evi nson . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-387
rootei g . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-390
rootmusi c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-393
sawtooth . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-396
schurrc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-397
seqperi od . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-398
sgol ay . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-400
sgol ayfi l t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-404
si nc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-406
sos2cel l . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-408
sos2ss . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-409
sos2tf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-411
sos2zp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-413
sosfi l t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-415
specgram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-416
sptool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-420
square . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-425
ss2sos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-426
ss2tf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-430
ss2zp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-431
stmcb . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-433
stri ps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-436
tf2l atc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-438
xiv Contents
tf2sos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-439
tf2ss . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-442
tf2zp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-444
tfe . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-447
tri ang . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-451
tri pul s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-453
tukeywi n . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-454
udecode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-456
uencode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-459
unwrap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-462
upfi rdn . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-463
upsampl e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-467
vco . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-469
wi ndow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-471
xcorr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-473
xcorr2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-477
xcov . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-478
yul ewal k . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-481
zp2sos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-483
zp2ss . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-487
zp2tf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-488
zpl ane . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-489

Preface
Overview . . . . . . . . . . . . . . . . . . . . . xvi
What Is the Signal Processing Toolbox? . . . . . . . xvi i
R12 Related Products List . . . . . . . . . . . . . . xvi i i
How to Use This Manual . . . . . . . . . . . . . . xxi
I f You Are a New User . . . . . . . . . . . . . . . . xxi
I f You Are an Experi enced Tool box User . . . . . . . . . xxi i
Al l Tool box Users . . . . . . . . . . . . . . . . . . xxi i
Installing the Signal Processing Toolbox . . . . . . . xxi i i
Technical Conventions . . . . . . . . . . . . . . . xxi v
Typographical Conventions . . . . . . . . . . . . . xxv
Preface
xvi
Overview
Thi s chapter provi des an i ntroducti on to the Si gnal Processi ng Tool box and the
documentati on. I t contai ns the fol l owi ng secti ons:
What I s the Si gnal Processi ng Tool box?
R12 Rel ated Products Li st
How to Use Thi s Manual
I nstal l i ng the Si gnal Processi ng Tool box
Techni cal Conventi ons
Typographi cal Conventi ons
What Is the Si gnal Processi ng Toolbox?
xvii
What Is the Signal Processing Toolbox?
The Si gnal Processi ng Tool box i s a col l ecti on of tool s bui l t on the MATLAB

numeri c computi ng envi ronment. The tool box supports a wi de range of si gnal
processi ng operati ons, from waveform generati on to fi l ter desi gn and
i mpl ementati on, parametri c model i ng, and spectral anal ysi s. The tool box
provi des two categori es of tool s:
Si gnal processi ng command l i ne functi ons
A sui te of graphi cal user i nterfaces for:
- I nteracti ve fi l ter desi gn
- Si gnal pl otti ng and anal ysi s
- Spectral anal ysi s
- Fi l teri ng si gnal s
- Anal yzi ng fi l ter desi gns
Preface
xviii
R12 Related Products List
The MathWorks provi des several products that are especi al l y rel evant to the
ki nds of tasks you can perform wi th the Si gnal Processi ng Tool box.
For more i nformati on about any of these products, see ei ther:
The onl i ne documentati on for that product i f i t i s i nstal l ed or i f you are
readi ng the documentati on from the CD
The MathWorks Web si te, at http://www.mathworks.com; see the products
secti on
Note The tool boxes l i sted bel ow al l i ncl ude functi ons that extend MATLABs
capabi l i ti es. The bl ocksets al l i ncl ude bl ocks that extend Si mul i nks
capabi l i ti es.
Product Description
Communi cati ons
Bl ockset
Si mul i nk bl ock l i brari es for model i ng the
physi cal l ayer of communi cati ons systems
Communi cati ons Tool box MATLAB functi ons for model i ng the physi cal
l ayer of communi cati ons systems
Data Acqui si ti on Tool box MATLAB functi ons for di rect access to l i ve,
measured data from MATLAB
Database Tool box Tool for connecti ng to, and i nteracti ng wi th,
most ODBC/JDBC databases from wi thi n
MATLAB
R12 Related Products Li st
xix
Devel opers Ki t for Texas
I nstruments DSP
Devel opers ki t that uni tes MATLAB,
Si mul i nk, and Real -Ti me Workshop code
generati on wi th the Texas I nstruments Code
Composer Studi o to provi de DSP software/
systems archi tects wi th sui te of tool s for DSP
devel opment, from si mul ati ng si gnal
processi ng al gori thms to opti mi zi ng and
runni ng code on Texas I nstruments DSPs
DSP Bl ockset Si mul i nk bl ock l i brari es for the desi gn,
si mul ati on, and prototypi ng of di gi tal si gnal
processi ng systems
Fuzzy Logi c Tool box Tool to hel p master fuzzy l ogi c techni ques and
thei r appl i cati on to practi cal control probl ems
I mage Processi ng
Tool box
Compl ete sui te of di gi tal i mage processi ng and
anal ysi s tool s for MATLAB
Neural Network Tool box Comprehensi ve envi ronment for neural
network research, desi gn, and si mul ati on
wi thi n MATLAB
Motorol a DSP
Devel opers Ki t
Devel oper's ki t for co-si mul ati ng and veri fyi ng
Motorol a 56300 and 56600 fi xed-poi nt DSP
code. Combi nes the al gori thm devel opment,
si mul ati on, and veri fi cati on capabi l i ti es of the
MathWorks system-l evel desi gn tool s wi th the
Motorol a Sui te 56assembl y l anguage
devel opment and debuggi ng tool s
Opti mi zati on Tool box Tool for general and l arge-scal e opti mi zati on of
nonl i near probl ems, as wel l as for l i near
programmi ng, quadrati c programmi ng,
nonl i near l east squares, and sol vi ng nonl i near
equati ons
Product Description
Preface
xx
Si mul i nk I nteracti ve, graphi cal envi ronment for
model i ng, si mul ati ng, and prototypi ng
dynami c systems
Stati sti cs Tool box Tool for anal yzi ng hi stori cal data, model i ng
systems, devel opi ng stati sti cal al gori thms, and
l earni ng and teachi ng stati sti cs
System I denti fi cati on
Tool box
Tool for bui l di ng accurate, si mpl i fi ed model s of
compl ex systems from noi sy ti me-seri es data
Wavel et Tool box Tool for si gnal and i mage anal ysi s,
compressi on, and de-noi si ng
Product Description
How to Use Thi s M anual
xxi
How to Use This Manual
Thi s secti on expl ai ns how to use the documentati on to get hel p about the Si gnal
Processi ng Tool box. Read the topi c that best fi ts your ski l l l evel :
I f You Are a New User
I f You Are an Experi enced Tool box User
Al l Tool box Users
If You Are a New User
Begi n wi th Chapter 1, Si gnal Processi ng Basi cs. Thi s chapter i ntroduces the
MATLAB si gnal processi ng envi ronment through the tool box functi ons. I t
descri bes the basi c functi ons of the Si gnal Processi ng Tool box, revi ewi ng i ts use
i n basi c waveform generati on, fi l ter i mpl ementati on and anal ysi s, i mpul se and
frequency response, zero-pol e anal ysi s, l i near system model s, and the di screte
Fouri er transform.
When you feel comfortabl e wi th the basi c functi ons, move on to Chapter 2 and
Chapter 3 for a more i n-depth i ntroducti on to usi ng the Si gnal Processi ng
Tool box:
Chapter 2, Fi l ter Desi gn, for a detai l ed expl anati on of usi ng the Si gnal
Processi ng Tool box i n i nfi ni te i mpul se response (I I R) and fi ni te i mpul se
response (FI R) fi l ter desi gn and i mpl ementati on, i ncl udi ng speci al topi cs i n
I I R fi l ter desi gn.
Chapter 3, Stati sti cal Si gnal Processi ng, for how to use the correl ati on,
covari ance, and spectral anal ysi s tool s to esti mate i mportant functi ons of
di screte random si gnal s.
Once you understand the general pri nci pl es and appl i cati ons of the tool box,
l earn how to use the i nteracti ve tool s:
Chapter 5, Fi l ter Desi gn and Anal ysi s Tool , and Chapter 6, SPTool : A
Si gnal Processi ng GUI Sui te, for an overvi ew of the i nteracti ve GUI
envi ronments and exampl es of how to use them for si gnal expl orati on, fi l ter
desi gn and i mpl ementati on, and spectral anal ysi s.
Fi nal l y, see the fol l owi ng chapter:
Preface
xxii
Chapter 4, Speci al Topi cs, for speci al i zed functi ons, i ncl udi ng fi l ter
wi ndows, parametri c model i ng, resampl i ng, cepstrum anal ysi s,
ti me-dependent Fouri er transforms and spectrograms, medi an fi l teri ng,
communi cati ons appl i cati ons, deconvol uti on, and speci al i zed transforms.
If You Are an Experienced Toolbox User
See Chapter 5, Fi l ter Desi gn and Anal ysi s Tool , and Chapter 6, SPTool : A
Si gnal Processi ng GUI Sui te, for an overvi ew of the i nteracti ve GUI
envi ronments and exampl es of how to use them for si gnal vi ewi ng, fi l ter desi gn
and i mpl ementati on, and spectral anal ysi s.
All Toolbox Users
Use Chapter 7, Functi on Reference, for l ocati ng i nformati on on speci fi c
functi ons. Reference descri pti ons i ncl ude a synopsi s of the functi ons syntax, as
wel l as a compl ete expl anati on of opti ons and operati ons. Many reference
descri pti ons al so i ncl ude hel pful exampl es, a descri pti on of the functi ons
al gori thm, and references to addi ti onal readi ng materi al .
Use thi s manual i n conjuncti on wi th the software to l earn about the powerful
features that MATLAB provi des. Each chapter provi des numerous exampl es
that appl y the tool box to representati ve si gnal processi ng tasks.
Some exampl es use MATLABs random number generati on functi on randn. I n
these cases, to dupl i cate the resul ts i n the exampl e, type
randn('state',0)
before runni ng the exampl e.
Installi ng the Si gnal Processi ng Toolbox
xxiii
Installing the Signal Processing Toolbox
To determi ne i f the Si gnal Processi ng Tool box i s i nstal l ed on your system, type
thi s command at the MATLAB prompt.
ver
When you enter thi s command, MATLAB di spl ays i nformati on about the
versi on of MATLAB you are runni ng, i ncl udi ng a l i st of al l tool boxes i nstal l ed
on your system and thei r versi on numbers.
For i nformati on about i nstal l i ng the tool box, see the MATLAB I nstallation
Guide for your pl atform.
Preface
xxiv
Technical Conventions
Thi s manual and the Si gnal Processi ng Tool box functi ons use the fol l owi ng
techni cal notati ons.
Nyqui st frequency One-hal f the sampl i ng frequency. Some
tool box functi ons normal i ze thi s val ue to 1.
x(1) The fi rst el ement of a data sequence or
fi l ter, correspondi ng to zero l ag.
or w Anal og frequency i n radi ans per second.
or w Di gi tal frequency i n radi ans per sampl e.
f Di gi tal frequency i n hertz.
[x, y) The i nterval from x to y, i ncl udi ng x but not
i ncl udi ng y.
... El l i pses i n the argument l i st for a gi ven
syntax on a functi on reference page
i ndi cate al l possi bl e argument l i sts for that
functi on appeari ng pri or to the gi ven
syntax are val i d.
Typographi cal C onventi ons
xxv
Typographical Conventions
Thi s manual uses some or al l of these conventi ons.
Item Convention Used Example
Exampl e code Monospace font To assi gn the val ue 5 to A,
enter
A = 5
Functi on names/syntax Monospace font The cos functi on fi nds the
cosi ne of each array el ement.
Syntax l i ne exampl e i s
MLGetVar ML_var_name
Keys Boldface wi th an i ni ti al capi tal
l etter
Press the Return key.
Li teral stri ngs (i n syntax
descri pti ons i n reference
chapters)
Monospace bold for l i teral s f = freqspace(n,'whole')
Mathemati cal
expressi ons
I talics for vari abl es
Standard text font for functi ons,
operators, and constants
Thi s vector represents the
pol ynomi al
p = x
2
+ 2x + 3
MATLAB output Monospace font MATLAB responds wi th
A =
5
Menu ti tl es, menu i tems,
di al og boxes, and control s
Boldface wi th an i ni ti al capi tal
l etter
Choose the File menu.
New terms I talics An array i s an ordered
col l ecti on of i nformati on.
Omi tted i nput arguments (...) el l i psi s denotes al l of the
i nput/output arguments from
precedi ng syntaxes.
[c,ia,ib] = union(...)
Stri ng vari abl es (from a
fi ni te l i st)
Monospace italics sysc = d2c(sysd,'method')
Preface
xxvi

1
Si gnal Processi ng Basi cs
Overview . . . . . . . . . . . . . . . . . . . . . 1-2
Signal Processing Toolbox Central Features . . . . . 1-3
Representing Signals . . . . . . . . . . . . . . . . 1-5
Waveform Generation: Time Vectors and Sinusoids . . 1-7
Working with Data . . . . . . . . . . . . . . . . . 1-14
Filter Implementation and Analysis . . . . . . . . . 1-15
The filter Function . . . . . . . . . . . . . . . . . 1-18
Other Functions for Filtering . . . . . . . . . . . . 1-20
Impulse Response . . . . . . . . . . . . . . . . . 1-24
Frequency Response . . . . . . . . . . . . . . . . 1-25
Zero-Pole Analysis . . . . . . . . . . . . . . . . . 1-31
Linear System Models . . . . . . . . . . . . . . . 1-33
Discrete Fourier Transform . . . . . . . . . . . . . 1-45
Selected Bibliography . . . . . . . . . . . . . . . 1-48
1 Si gnal Processi ng Basi cs
1-2
Overview
Thi s chapter descri bes how to begi n usi ng MATLAB and the Si gnal Processi ng
Tool box for your si gnal processi ng appl i cati ons. I t assumes a basi c knowl edge
and understandi ng of si gnal s and systems, i ncl udi ng such topi cs as fi l ter and
l i near system theory and basi c Fouri er anal ysi s. The chapter covers the
fol l owi ng topi cs:
Si gnal Processi ng Tool box Central Features
Representi ng Si gnal s
Waveform Generati on: Ti me Vectors and Si nusoi ds
Worki ng wi th Data
Fi l ter I mpl ementati on and Anal ysi s
The fi l ter Functi on
Other Functi ons for Fi l teri ng
I mpul se Response
Frequency Response
Zero-Pol e Anal ysi s
Li near System Model s
Di screte Fouri er Transform
Sel ected Bi bl i ography
Many exampl es throughout the chapter demonstrate how to appl y tool box
functi ons. I f you are not al ready fami l i ar wi th MATLABs si gnal processi ng
capabi l i ti es, use thi s chapter i n conjuncti on wi th the software to try exampl es
and l earn about the powerful features avai l abl e to you.
Si gnal Processi ng Toolbox C entral Features
1-3
Signal Processing Toolbox Central Features
The Si gnal Processi ng Tool box functi ons are al gori thms, expressed mostl y i n
M-fi l es, that i mpl ement a vari ety of si gnal processi ng tasks. These tool box
functi ons are a speci al i zed extensi on of the MATLAB computati onal and
graphi cal envi ronment.
Filtering and FFTs
Two of the most i mportant functi ons for si gnal processi ng are not i n the Si gnal
Processi ng Tool box at al l , but are bui l t-i n MATLAB functi ons:
filter appl i es a di gi tal fi l ter to a data sequence.
fft cal cul ates the di screte Fouri er transform of a sequence.
The operati ons these functi ons perform are the mai n computati onal
workhorses of cl assi cal si gnal processi ng. Both are descri bed i n thi s chapter.
The Si gnal Processi ng Tool box uses many other standard MATLAB functi ons
and l anguage features, i ncl udi ng pol ynomi al root fi ndi ng, compl ex ari thmeti c,
matri x i nversi on and mani pul ati on, and graphi cs tool s.
Signals and Systems
The basi c enti ti es that tool box functi ons work wi th are si gnal s and systems.
The functi ons emphasi ze di gi tal , or di screte, si gnal s and fi l ters, as opposed to
anal og, or conti nuous, si gnal s. The pri nci pal fi l ter type the tool box supports i s
the l i near, ti me-i nvari ant di gi tal fi l ter wi th a si ngl e i nput and a si ngl e output.
You can represent l i near ti me-i nvari ant systems usi ng one of several model s
(such as transfer functi on, state-space, zero-pol e-gai n, and second-order
secti on) and convert between representati ons.
Key Areas: Filter Design and Spectral Analysis
I n addi ti on to i ts core functi ons, the tool box provi des ri ch, customi zabl e support
for the key areas of fi l ter desi gn and spectral anal ysi s. I t i s easy to i mpl ement
a desi gn techni que that sui ts your appl i cati on, desi gn di gi tal fi l ters di rectl y, or
create anal og prototypes and di screti ze them. Tool box functi ons al so esti mate
power spectral densi ty and cross spectral densi ty, usi ng ei ther parametri c or
nonparametri c techni ques. Fi l ter Desi gn on page 2-1 and Stati sti cal Si gnal
Processi ng on page 3-1, respecti vel y detai l tool box functi ons for fi l ter desi gn
and spectral anal ysi s.
1 Si gnal Processi ng Basi cs
1-4
Some fi l ter desi gn and spectral anal ysi s functi ons i ncl uded i n the tool box are
computati on and graphi cal di spl ay of frequency response
system i denti fi cati on
generati ng si gnal s
di screte cosi ne, chi rp-z, and Hi l bert transforms
l atti ce fi l ters
resampl i ng
ti me-frequency anal ysi s
basi c communi cati on systems si mul ati on
Interactive Tools: SPTool and FDATool
The power of the Si gnal Processi ng Tool box i s greatl y enhanced by i ts
easy-to-use i nteracti ve tool s. SPTool provi des a ri ch graphi cal envi ronment for
si gnal vi ewi ng, fi l ter desi gn, and spectral anal ysi s. The Fi l ter Desi gn and
Anal ysi s Tool (FDATool ) provi des a more comprehensi ve col l ecti on of features
for addressi ng the probl em of fi l ter desi gn. The FDATool al so offers seaml ess
access to the addi ti onal fi l ter desi gn methods and quanti zati on features of the
Fi l ter Desi gn Tool box when that product i s i nstal l ed.
Extensibility
Perhaps the most i mportant feature of the MATLAB envi ronment i s that i t i s
extensi bl e: MATLAB l ets you create your own M-fi l es to meet numeri c
computati on needs for research, desi gn, or engi neeri ng of si gnal processi ng
systems. Si mpl y copy the M-fi l es provi ded wi th the Si gnal Processi ng Tool box
and modi fy them as needed, or create new functi ons to expand the functi onal i ty
of the tool box.
Representi ng Si gnals
1-5
Representing Signals
The central data construct i n MATLAB i s the numeric array, an ordered
col l ecti on of real or compl ex numeri c data wi th two or more di mensi ons. The
basi c data objects of si gnal processi ng (one-di mensi onal si gnal s or sequences,
mul ti channel si gnal s, and two-di mensi onal si gnal s) are al l natural l y sui ted to
array representati on.
Vector Representation
MATLAB represents ordi nary one-di mensi onal sampl ed data si gnal s, or
sequences, as vectors. Vectors are 1-by-n or n-by-1 arrays, where n i s the
number of sampl es i n the sequence. One way to i ntroduce a sequence i nto
MATLAB i s to enter i t as a l i st of el ements at the command prompt. The
statement
x = [4 3 7 -9 1]
creates a si mpl e fi ve-el ement real sequence i n a row vector. Transposi ti on
turns the sequence i nto a col umn vector
x = x'
resul ti ng i n
x =
4
3
7
-9
1
Col umn ori entati on i s preferabl e for si ngl e channel si gnal s because i t extends
natural l y to the mul ti channel case. For mul ti channel data, each col umn of a
matri x represents one channel . Each row of such a matri x then corresponds to
a sampl e poi nt. A three-channel si gnal that consi sts of x, 2x, and x/ i s
y = [x 2*x x/pi]
1 Si gnal Processi ng Basi cs
1-6
Thi s resul ts i n
y =
4.0000 8.0000 1.2732
3.0000 6.0000 0.9549
7.0000 14.0000 2.2282
-9.0000 -18.0000 -2.8648
1.0000 2.0000 0.3183
Waveform G enerati on: Ti me Vectors and Si nusoi ds
1-7
Waveform Generation: Time Vectors and Sinusoids
A vari ety of tool box functi ons generate waveforms. Most requi re you to begi n
wi th a vector representi ng a ti me base. Consi der generati ng data wi th a 1000
Hz sampl e frequency, for exampl e. An appropri ate ti me vector i s
t = (0:0.001:1)';
where MATLABs col on operator creates a 1001-el ement row vector that
represents ti me runni ng from zero to one second i n steps of one mi l l i second.
The transpose operator (') changes the row vector i nto a col umn; the
semi col on (;) tel l s MATLAB to compute but not di spl ay the resul t.
Gi ven t you can create a sampl e si gnal y consi sti ng of two si nusoi ds, one at 50
Hz and one at 120 Hz wi th twi ce the ampl i tude.
y = sin(2*pi*50*t) + 2*sin(2*pi*120*t);
The new vari abl e y, formed from vector t, i s al so 1001 el ements l ong. You can
add normal l y di stri buted whi te noi se to the si gnal and graph the fi rst fi fty
poi nts usi ng
randn('state',0);
yn = y + 0.5*randn(size(t));
plot(t(1:50),yn(1:50))
0 0.01 0.02 0.03 0.04 0.05
3
2
1
0
1
2
3
4
1 Si gnal Processi ng Basi cs
1-8
Common Sequences: Unit Impulse, Unit Step, and
Unit Ramp
Si nce MATLAB i s a programmi ng l anguage, an endl ess vari ety of di fferent
si gnal s i s possi bl e. Here are some statements that generate several commonl y
used sequences, i ncl udi ng the uni t i mpul se, uni t step, and uni t ramp functi ons.
t = (0:0.001:1)';
y = [1; zeros(99,1)]; % impulse
y = ones(100,1); % step (filter assumes 0 initial cond.)
y = t; % ramp
y = t.^2;
y = square(4*t);
Al l of these sequences are col umn vectors. The l ast three i nheri t thei r shapes
from t.
Multichannel Signals
Use standard MATLAB array syntax to work wi th mul ti channel si gnal s. For
exampl e, a mul ti channel si gnal consi sti ng of the l ast three si gnal s generated
above i s
z = [t t.^2 square(4*t)];
You can generate a mul ti channel uni t sampl e functi on usi ng the outer product
operator. For exampl e, a si x-el ement col umn vector whose fi rst el ement i s one,
and whose remai ni ng fi ve el ements are zeros, i s
a = [1 zeros(1,5)]';
To dupl i cate col umn vector a i nto a matri x wi thout performi ng any
mul ti pl i cati on, use MATLABs col on operator and the ones functi on.
c = a(:,ones(1,3));
Waveform G enerati on: Ti me Vectors and Si nusoi ds
1-9
Common Periodic Waveforms
The tool box provi des functi ons for generati ng wi del y used peri odi c waveforms:
sawtooth generates a sawtooth wave wi th peaks at t1 and a peri od of . An
opti onal width parameter speci fi es a fracti onal mul ti pl e of at whi ch the
si gnal s maxi mum occurs.
square generates a square wave wi th a peri od of . An opti onal parameter
speci fi es duty cycle, the percent of the peri od for whi ch the si gnal i s posi ti ve.
To generate 1.5 seconds of a 50 Hz sawtooth wave wi th a sampl e rate of 10 kHz
and pl ot 0.2 seconds of the generated waveform, use
fs = 10000;
t = 0:1/fs:1.5;
x = sawtooth(2*pi*50*t);
plot(t,x), axis([0 0.2 -1 1])
2
2
2
0 0.02 0.04 0.06 0.08 0.1 0.12 0.14 0.16 0.18 0.2
-1
-0.5
0
0.5
1
1 Si gnal Processi ng Basi cs
1-10
Common Aperiodic Waveforms
The tool box al so provi des functi ons for generati ng several wi del y used
aperi odi c waveforms:
gauspuls generates a Gaussi an-modul ated si nusoi dal pul se wi th a speci fi ed
ti me, center frequency, and fracti onal bandwi dth. Opti onal parameters
return i n-phase and quadrature pul ses, the RF si gnal envel ope, and the
cutoff ti me for the trai l i ng pul se envel ope.
chirp generates a l i near swept-frequency cosi ne si gnal . An opti onal
parameter speci fi es al ternati ve sweep methods. An opti onal parameter phi
al l ows i ni ti al phase to be speci fi ed i n degrees.
To compute 2 seconds of a l i near chi rp si gnal wi th a sampl e rate of 1 kHz, that
starts at DC and crosses 150 Hz at 1 second, use
t = 0:1/1000:2;
y = chirp(t,0,1,150);
To pl ot the spectrogram, use
specgram(y,256,1000,256,250)
Time
F
r
e
q
u
e
n
c
y
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6
0
50
100
150
200
250
300
350
400
450
500
Waveform G enerati on: Ti me Vectors and Si nusoi ds
1-11
The pulstran Function
The pulstran functi on generates pul se trai ns from ei ther conti nuous or
sampl ed prototype pul ses. The fol l owi ng exampl e generates a pul se trai n
consi sti ng of the sum of mul ti pl e del ayed i nterpol ati ons of a Gaussi an pul se.
The pul se trai n i s defi ned to have a sampl e rate of 50 kHz, a pul se trai n l ength
of 10 ms, and a pul se repeti ti on rate of 1 kHz; D speci fi es the del ay to each pul se
repeti ti on i n col umn 1 and an opti onal attenuati on for each repeti ti on i n
col umn 2. The pul se trai n i s constructed by passi ng the name of the gauspuls
functi on to pulstran, al ong wi th addi ti onal parameters that speci fy a 10 kHz
Gaussi an pul se wi th 50% bandwi dth.
T = 0:1/50E3:10E-3;
D = [0:1/1E3:10E-3;0.8.^(0:10)]';
Y = pulstran(T,D,'gauspuls',10E3,0.5);
plot(T,Y)
0 0.001 0.002 0.003 0.004 0.005 0.006 0.007 0.008 0.009 0.01
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
1 Si gnal Processi ng Basi cs
1-12
The Sinc Function
The sinc functi on computes the mathemati cal si nc functi on for an i nput vector
or matri x x. The si nc functi on i s the conti nuous i nverse Fouri er transform of
the rectangul ar pul se of wi dth and hei ght 1.
The si nc functi on has a val ue of 1 where x i s zero, and a val ue of
for al l other el ements of x.
To pl ot the si nc functi on for a l i nearl y spaced vector wi th val ues rangi ng from
-5 to 5, use the fol l owi ng commands.
x = linspace(-5,5);
y = sinc(x);
plot(x,y)
2
x ( ) si n
x
--------------------
-5 -4 -3 -2 -1 0 1 2 3 4 5
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
Waveform G enerati on: Ti me Vectors and Si nusoi ds
1-13
The Dirichlet Function
The tool box functi on diric computes the Di ri chl et functi on, someti mes cal l ed
the periodic sinc or aliased sinc functi on, for an i nput vector or matri x x. The
Di ri chl et functi on i s
where n i s a user-speci fi ed posi ti ve i nteger. For n odd, the Di ri chl et functi on
has a peri od of ; for n even, i ts peri od i s . The magni tude of thi s functi on
i s (1/n) ti mes the magni tude of the di screte-ti me Fouri er transform of the
n-poi nt rectangul ar wi ndow.
To pl ot the Di ri chl et functi on over the range 0 to 4 for n = 7 and n = 8, use
x = linspace(0,4*pi,300);
plot(x,diric(x,7))
plot(x,diric(x,8))
di ri c x ( )
1
k n 1 ( )
x 2k k 0 1 t 2 t , , , = , =
nx 2 ( ) si n
n x 2 ( ) si n
---------------------------- otherwi se

'

=
2 4
0 5 10 15
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
n = 7
0 5 10 15
-1
-0.5
0
0.5
1
n = 8
1 Si gnal Processi ng Basi cs
1-14
Working with Data
The exampl es i n the precedi ng secti ons obtai n data i n one of two ways:
By di rect i nput, that i s, enteri ng the data manual l y at the keyboard
By usi ng a MATLAB or tool box functi on, such as sin, cos, sawtooth, square,
or sinc
Some appl i cati ons, however, may need to i mport data from outsi de MATLAB.
Dependi ng on your data format, you can do thi s i n the fol l owi ng ways:
Load data from an ASCI I fi l e or MAT-fi l e wi th MATLABs load command.
Read the data i nto MATLAB wi th a l ow-l evel fi l e I /O functi on, such as fopen,
fread, and fscanf.
Devel op a MEX-fi l e to read the data.
Other resources are al so useful , such as a hi gh-l evel l anguage program (i n
Fortran or C, for exampl e) that converts your data i nto MAT-fi l e format see
the MATLAB External I nterfaces/API Reference for detai l s. MATLAB reads
such fi l es usi ng the load command.
Si mi l ar techni ques are avai l abl e for exporti ng data generated wi thi n
MATLAB. See the MATLAB documentati on for more detai l s on i mporti ng and
exporti ng data.
Fi lter Implementati on and Analysi s
1-15
Filter Implementation and Analysis
Thi s secti on descri bes how to fi l ter di screte si gnal s usi ng MATLABs filter
functi on and other functi ons i n the Si gnal Processi ng Tool box. I t al so di scusses
how to use the tool box functi ons to anal yze fi l ter characteri sti cs, i ncl udi ng
i mpul se response, magni tude and phase response, group del ay, and zero-pol e
l ocati ons.
Convolution and Filtering
The mathemati cal foundati on of fi l teri ng i s convol uti on. MATLABs conv
functi on performs standard one-di mensi onal convol uti on, convol vi ng one
vector wi th another.
conv([1 1 1],[1 1 1])
ans =
1 2 3 2 1
Note Convol ve rectangul ar matri ces for two-di mensi onal si gnal processi ng
usi ng the conv2 functi on.
A di gi tal fi l ters output y(k) i s rel ated to i ts i nput x(k) by convol uti on wi th i ts
i mpul se response h(k).
I f a di gi tal fi l ters i mpul se response h(k) i s fi ni te l ength, and the i nput x(k) i s
al so fi ni te l ength, you can i mpl ement the fi l ter usi ng conv. Store x(k) i n a vector
x, h(k) i n a vector h, and convol ve the two.
x = randn(5,1); % A random vector of length 5
h = [1 1 1 1]/4; % Length 4 averaging filter
y = conv(h,x);
y k ( ) h k ( ) x k ( ) h k l ( )x l ( )
l =

= =
1 Si gnal Processi ng Basi cs
1-16
Filters and Transfer Functions
I n general , the z-transform Y(z) of a di gi tal fi l ters output y(n) i s rel ated to the
z-transform X(z) of the i nput by
where H(z) i s the fi l ters transfer function. Here, the constants b(i) and a(i) are
the fi l ter coeffi ci ents and the order of the fi l ter i s the maxi mum of n and m.
Note The fi l ter coeffi ci ents start wi th subscri pt 1, rather than 0. Thi s refl ects
MATLABs standard i ndexi ng scheme for vectors.
MATLAB stores the coeffi ci ents i n two vectors, one for the numerator and one
for the denomi nator. By conventi on, MATLAB uses row vectors for fi l ter
coeffi ci ents.
Filter Coefficients and Filter Names
Many standard names for fi l ters refl ect the number of a and b coeffi ci ents
present:
When n = 0 (that i s, b i s a scal ar), the fi l ter i s an I nfi ni te I mpul se Response
(I I R), al l -pol e, recursi ve, or autoregressi ve (AR) fi l ter.
When m = 0 (that i s, a i s a scal ar), the fi l ter i s a Fi ni te I mpul se Response
(FI R), al l -zero, nonrecursi ve, or movi ng average (MA) fi l ter.
I f both n and m are greater than zero, the fi l ter i s an I I R, pol e-zero, recursi ve,
or autoregressi ve movi ng average (ARMA) fi l ter.
The acronyms AR, MA, and ARMA are usual l y appl i ed to fi l ters associ ated
wi th fi l tered stochasti c processes.
Y z ( ) H z ( )X z ( )
b 1 ( ) b 2 ( )z
1
L b n 1 + ( )z
n
+ + +
a 1 ( ) a 2 ( )z
1
L a m 1 + ( )z
m
+ + +
----------------------------------------------------------------------------------------X z ( ) = =
Fi lter Implementati on and Analysi s
1-17
Filtering with the filter Function
I t i s si mpl e to work back to a di fference equati on from the z-transform rel ati on
shown earl i er. Assume that a(1) = 1. Move the denomi nator to the l eft-hand
si de and take the i nverse z-transform.
I n terms of current and past i nputs, and past outputs, y(n) i s
Thi s i s the standard ti me-domai n representati on of a di gi tal fi l ter, computed
starti ng wi th y(1) and assumi ng zero i ni ti al condi ti ons. Thi s representati ons
progressi on i s
A fi l ter i n thi s form i s easy to i mpl ement wi th the filter functi on. For
exampl e, a si mpl e si ngl e-pol e fi l ter (l owpass) i s
b = 1; % Numerator
a = [1 -0.9]; % Denominator
where the vectors b and a represent the coeffi ci ents of a fi l ter i n transfer
functi on form. To appl y thi s fi l ter to your data, use
y = filter(b,a,x);
filter gi ves you as many output sampl es as there are i nput sampl es, that i s,
the l ength of y i s the same as the l ength of x. I f the fi rst el ement of a i s not 1,
filter di vi des the coeffi ci ents by a(1) before i mpl ementi ng the di fference
equati on.
y k ( ) a
2
y k 1 ( ) L a
m 1 +
y k m ( ) + + +
b
1
x k ( ) b
2
x k 1 ( ) L b
n 1 +
x k m ( ) + + +
=
y k ( ) b
1
x k ( ) b
2
x k 1 ( ) L b
n 1 +
x k n ( ) a
2
y k 1 ( ) L a
m 1 +
y k n ( ) + + + =
y 1 ( ) b
1
x 1 ( ) =
y 2 ( ) b
1
x 2 ( ) b
2
x 1 ( ) a
2
y 1 ( ) + =
y 3 ( ) b
1
x 3 ( ) b
2
x 2 ( ) b
3
x 1 ( ) a
2
y 2 ( ) a
3
y 1 ( ) + + =
M M =
1 Si gnal Processi ng Basi cs
1-18
The filter Function
filter i s i mpl emented as the transposed di rect-form I I structure shown bel ow,
where n-1 i s the fi l ter order. Thi s i s a canoni cal form that has the mi ni mum
number of del ay el ements.
At sampl e m, filter computes the di fference equati ons
I n i ts most basi c form, filter i ni ti al i zes the del ay outputs z
i
(1), i = 1, ..., n-1
to 0. Thi s i s equi val ent to assumi ng both past i nputs and outputs are zero. Set
the i ni ti al del ay outputs usi ng a fourth i nput parameter to filter, or access
the fi nal del ay outputs usi ng a second output parameter.
[y,zf] = filter(b,a,x,zi)
Access to i ni ti al and fi nal condi ti ons i s useful for fi l teri ng data i n secti ons,
especi al l y i f memory l i mi tati ons are a consi derati on. Suppose you have
col l ected data i n two segments of 5000 poi nts each.
x1 = randn(5000,1); % Generate two random data sequences.
x2 = randn(5000,1);
Perhaps the fi rst sequence, x1, corresponds to the fi rst 10 mi nutes of data and
the second, x2, to an addi ti onal 10 mi nutes. The whol e sequence i s x = [x1;x2].
I f there i s not suffi ci ent memory to hol d the combi ned sequence, fi l ter the
z
-1
z
-1
x(m)
y(m)
b( 3) b( 2) b(1)
a( 3) a( 2)
z
1
(m) z
2
(m)
z
-1
b(n)
a(n)
z
n-1
(m)
...
...
...
y m ( ) b 1 ( )x m ( ) z
1
m 1 ( ) + =
z
1
m ( ) b 2 ( )x m ( ) z
2
m 1 ( ) a 2 ( )y m ( ) + =
M M =
z
n 2
m ( ) b n 1 ( )x m ( ) z
n 1
m 1 ( ) a n 1 ( )y m ( ) + =
z
n 1
m ( ) b n ( )x m ( ) a n ( )y m ( ) =
The fi lter Functi on
1-19
subsequences x1 and x2 one at a ti me. To ensure conti nui ty of the fi l tered
sequences, use the fi nal condi ti ons from x1 as i ni ti al condi ti ons to fi l ter x2.
[y1,zf] = filter(b,a,x1);
y2 = filter(b,a,x2,zf);
The filtic functi on generates i ni ti al condi ti ons for filter. filtic computes
the del ay vector to make the behavi or of the fi l ter refl ect past i nputs and
outputs that you speci fy. To obtai n the same output del ay val ues zf as above
usi ng filtic, use
zf = filtic(b,a,flipud(y1),flipud(x1));
Thi s can be useful when fi l teri ng short data sequences, as appropri ate i ni ti al
condi ti ons hel p reduce transi ent startup effects.
1 Si gnal Processi ng Basi cs
1-20
Other Functions for Filtering
I n addi ti on to filter, several other functi ons i n the Si gnal Processi ng Tool box
perform the basi c fi l teri ng operati on. These functi ons i ncl ude upfirdn, whi ch
performs FI R fi l teri ng wi th resampl i ng, filtfilt, whi ch el i mi nates phase
di storti on i n the fi l teri ng process, fftfilt, whi ch performs the FI R fi l teri ng
operati on i n the frequency domai n, and latcfilt, whi ch fi l ters usi ng a l atti ce
i mpl ementati on.
Multirate Filter Bank Implementation
The functi on upfirdn al ters the sampl i ng rate of a si gnal by an i nteger rati o
P/Q. I t computes the resul t of a cascade of three systems that performs the
fol l owi ng tasks:
Upsampl i ng (zero i nserti on) by i nteger factor p
Fi l teri ng by FI R fi l ter h
Downsampl i ng by i nteger factor q

For exampl e, to change the sampl e rate of a si gnal from 44.1 kHz to 48 kHz, we
fi rst fi nd the smal l est i nteger conversi on rati o p/q. Set
d = gcd(48000,44100);
p = 48000/d;
q = 44100/d;
I n thi s exampl e, p = 160 and q = 147. Sampl e rate conversi on i s then
accompl i shed by typi ng
y = upfirdn(x,h,p,q)
Thi s cascade of operati ons i s i mpl emented i n an effi ci ent manner usi ng
pol yphase fi l teri ng techni ques, and i t i s a central concept of mul ti rate fi l teri ng
(see reference [1] for detai l s on mul ti rate fi l ter theory). Note that the qual i ty of
the resampl i ng resul t rel i es on the qual i ty of the FI R fi l ter h.
P
x(n) y(n)
FIR
H
Q
O ther Functi onsfor Fi lteri ng
1-21
Fi l ter banks may be i mpl emented usi ng upfirdn by al l owi ng the fi l ter h to be
a matri x, wi th one FI R fi l ter per col umn. A si gnal vector i s passed
i ndependentl y through each FI R fi l ter, resul ti ng i n a matri x of output si gnal s.
Other functi ons that perform mul ti rate fi l teri ng (wi th fi xed fi l ter) i ncl ude
resample, interp, and decimate.
Anti-Causal, Zero-Phase Filter Implementation
I n the case of FI R fi l ters, i t i s possi bl e to desi gn l i near phase fi l ters that, when
appl i ed to data (usi ng filter or conv), si mpl y del ay the output by a fi xed
number of sampl es. For I I R fi l ters, however, the phase di storti on i s usual l y
hi ghl y nonl i near. The filtfilt functi on uses the i nformati on i n the si gnal at
poi nts before and after the current poi nt, i n essence l ooki ng i nto the future,
to el i mi nate phase di storti on.
To see how filtfilt does thi s, recal l that i f the z-transform of a real sequence
x(n) i s X(z), the z-transform of the ti me reversed sequence x(n) i s X(1/z).
Consi der the processi ng scheme
When | z| = 1, that i s z = e
j
, the output reduces to X(e
j
)| H(e
j
)|
2
. Gi ven al l
the sampl es of the sequence x(n), a doubl y fi l tered versi on of x that has
zero-phase di storti on i s possi bl e.
For exampl e, a 1-second durati on si gnal sampl ed at 100 Hz, composed of two
si nusoi dal components at 3 Hz and 40 Hz, i s
fs = 100;
t = 0:1/fs:1;
x = sin(2*pi*t*3)+.25*sin(2*pi*t*40);
H(z) X(z)
X(z)H(z) X(1/z)H(1/z) X(1/z)H(1/z)H(z)
X(z)H(1/z)H(z) H(z)
Time
Reverse
Time
Reverse
1 Si gnal Processi ng Basi cs
1-22
Now create a 10-poi nt averagi ng FI R fi l ter, and fi l ter x usi ng both filter and
filtfilt for compari son.
b = ones(1,10)/10; % 10 point averaging filter
y = filtfilt(b,1,x); % Noncausal filtering
yy = filter(b,1,x); % Normal filtering
plot(t,x,t,y,'--',t,yy,':')
Both fi l tered versi ons el i mi nate the 40 Hz si nusoi d evi dent i n the ori gi nal ,
sol i d l i ne. The pl ot al so shows how filter and filtfilt di ffer; the dashed
(filtfilt) l i ne i s i n phase wi th the ori gi nal 3 Hz si nusoi d, whi l e the dotted
(filter) l i ne i s del ayed by about fi ve sampl es. Al so, the ampl i tude of the
dashed l i ne i s smal l er due to the magni tude squared effects of filtfilt.
filtfilt reduces fi l ter startup transi ents by careful l y choosi ng i ni ti al
condi ti ons, and by prependi ng onto the i nput sequence a short, refl ected pi ece
of the i nput sequence. For best resul ts, make sure the sequence you are
fi l teri ng has l ength at l east three ti mes the fi l ter order and tapers to zero on
both edges.
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
-1.5
-1
-0.5
0
0.5
1
1.5
O ther Functi onsfor Fi lteri ng
1-23
Frequency Domain Filter Implementation
Dual i ty between the ti me domai n and the frequency domai n makes i t possi bl e
to perform any operati on i n ei ther domai n. Usual l y one domai n or the other i s
more conveni ent for a parti cul ar operati on, but you can al ways accompl i sh a
gi ven operati on i n ei ther domai n.
To i mpl ement general I I R fi l teri ng i n the frequency domai n, mul ti pl y the
di screte Fouri er transform (DFT) of the i nput sequence wi th the quoti ent of the
DFT of the fi l ter.
n = length(x);
y = ifft(fft(x).*fft(b,n)./fft(a,n));
Thi s computes resul ts that are i denti cal to filter, but wi th di fferent startup
transi ents (edge effects). For l ong sequences, thi s computati on i s very
i neffi ci ent because of the l arge zero-padded FFT operati ons on the fi l ter
coeffi ci ents, and because the FFT al gori thm becomes l ess effi ci ent as the
number of poi nts n i ncreases.
For FI R fi l ters, however, i t i s possi bl e to break l onger sequences i nto shorter,
computati onal l y effi ci ent FFT l engths. The functi on
y = fftfilt(b,x)
uses the overl ap add method (see reference [1] at the end of thi s chapter) to
fi l ter a l ong sequence wi th mul ti pl e medi um-l ength FFTs. I ts output i s
equi val ent to filter(b,1,x).
1 Si gnal Processi ng Basi cs
1-24
Impulse Response
The i mpul se response of a di gi tal fi l ter i s the output ari si ng from the uni t
i mpul se i nput sequence defi ned as
I n MATLAB, you can generate an i mpul se sequence a number of ways; one
strai ghtforward way i s
imp = [1; zeros(49,1)];
The i mpul se response of the si mpl e fi l ter b = 1 and a = [1 -0.9] i s
h = filter(b,a,imp);
The impz functi on i n the tool box si mpl i fi es thi s operati on, choosi ng the number
of poi nts to generate and then maki ng a stem pl ot (usi ng the stem functi on).
impz(b,a)
The pl ot shows the exponenti al decay h(n) = 0.9n of the si ngl e pol e system.
x n ( )
1 n 1 = ,
0 n 1 ,

'

=
0 10 20 30 40 50 60 70 80 90
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
Frequency Response
1-25
Frequency Response
The Si gnal Processi ng Tool box enabl es you to perform frequency domai n
anal ysi s of both anal og and di gi tal fi l ters.
Digital Domain
freqz uses an FFT-based al gori thm to cal cul ate the z-transform frequency
response of a di gi tal fi l ter. Speci fi cal l y, the statement
[h,w] = freqz(b,a,p)
returns the p-poi nt compl ex frequency response, , of the di gi tal fi l ter.
I n i ts si mpl est form, freqz accepts the fi l ter coeffi ci ent vectors b and a, and an
i nteger p speci fyi ng the number of poi nts at whi ch to cal cul ate the frequency
response. freqz returns the compl ex frequency response i n vector h, and the
actual frequency poi nts i n vector w i n rad/s.
freqz can accept other parameters, such as a sampl i ng frequency or a vector of
arbi trary frequency poi nts. The exampl e bel ow fi nds the 256-poi nt frequency
response for a 12th-order Chebyshev Type I fi l ter. The cal l to freqz speci fi es a
sampl i ng frequency fs of 1000 Hz.
[b,a] = cheby1(12,0.5,200/500);
[h,f] = freqz(b,a,256,1000);
Because the parameter l i st i ncl udes a sampl i ng frequency, freqz returns a
vector f that contai ns the 256 frequency poi nts between 0 and fs/2 used i n the
frequency response cal cul ati on.
H e
j
( )
H e
j
( )
b 1 ( ) b 2 ( )e
j
L b n 1 + ( )e
j n ( )
+ + +
a 1 ( ) a 2 ( )e
j
L a m 1 + ( )e
j m ( )
+ + +
--------------------------------------------------------------------------------------------------- =
1 Si gnal Processi ng Basi cs
1-26
Frequency Normalization Thi s tool box uses the conventi on that uni t
frequency i s the Nyqui st frequency, defi ned as hal f the sampl i ng frequency.
The cutoff frequency parameter for al l basi c fi l ter desi gn functi ons i s
normal i zed by the Nyqui st frequency. For a system wi th a 1000 Hz sampl i ng
frequency, for exampl e, 300 Hz i s 300/500 = 0.6. To convert normal i zed
frequency to angul ar frequency around the uni t ci rcl e, mul ti pl y by . To
convert normal i zed frequency back to hertz, mul ti pl y by hal f the sampl e
frequency.
I f you cal l freqz wi th no output arguments, i t automati cal l y pl ots both
magni tude versus frequency and phase versus frequency. For exampl e, a
ni nth-order Butterworth l owpass fi l ter wi th a cutoff frequency of 400 Hz, based
on a 2000 Hz sampl i ng frequency, i s
[b,a] = butter(9,400/1000);
Now cal cul ate the 256-poi nt compl ex frequency response for thi s fi l ter, and pl ot
the magni tude and phase wi th a cal l to freqz.
freqz(b,a,256,2000)
0 100 200 300 400 500 600 700 800 900 1000
-1000
-800
-600
-400
-200
0
Frequency (Hertz)
P
h
a
s
e

(
d
e
g
r
e
e
s
)
0 100 200 300 400 500 600 700 800 900 1000
-400
-300
-200
-100
0
100
Frequency (Hertz)
M
a
g
n
i
t
u
d
e

R
e
s
p
o
n
s
e

(
d
B
)
Frequency Response
1-27
freqz can al so accept a vector of arbi trary frequency poi nts for use i n the
frequency response cal cul ati on. For exampl e,
w = linspace(0,pi);
h = freqz(b,a,w);
cal cul ates the compl ex frequency response at the frequency poi nts i n w for the
fi l ter defi ned by vectors b and a. The frequency poi nts can range from 0 to .
To speci fy a frequency vector that ranges from zero to your sampl i ng frequency,
i ncl ude both the frequency vector and the sampl i ng frequency val ue i n the
parameter l i st.
Analog Domain
freqs eval uates frequency response for an anal og fi l ter defi ned by two i nput
coeffi ci ent vectors, b and a. I ts operati on i s si mi l ar to that of freqz; you can
speci fy a number of frequency poi nts to use, suppl y a vector of arbi trary
frequency poi nts, and pl ot the magni tude and phase response of the fi l ter.
Magnitude and Phase
MATLAB provi des functi ons to extract magni tude and phase from a frequency
response vector h. The functi on abs returns the magni tude of the response;
angle returns the phase angl e i n radi ans. To extract and pl ot the magni tude
and phase of a Butterworth fi l ter.
[b,a] = butter(6,300/500);
[h,w] = freqz(b,a,512,1000);
m = abs(h); p = angle(h);
semilogy(w,m); title('Magnitude');
figure; plot(w,p*180/pi); title('Phase');
2
0 100 200 300 400 500
10
15
10
10
10
5
10
0
Magnitude
0 100 200 300 400 500
200
150
100
50
0
50
100
150
200
Phase
1 Si gnal Processi ng Basi cs
1-28
The unwrap functi on i s al so useful i n frequency anal ysi s. unwrap unwraps the
phase to make i t conti nuous across 360 phase di sconti nui ti es by addi ng
mul ti pl es of t360, as needed. To see how unwrap i s useful , desi gn a 25th-order
l owpass FI R fi l ter.
h = fir1(25,0.4);
Obtai n the fi l ters frequency response wi th freqz, and pl ot the phase i n
degrees.
[H,f] = freqz(h,1,512,2);
plot(f,angle(H)*180/pi); grid
I t i s di ffi cul t to di sti ngui sh the 360 jumps (an arti fact of the arctangent
functi on i nsi de angle) from the 180 jumps that si gni fy zeros i n the frequency
response.
Use unwrap to el i mi nate the 360 jumps.
plot(f,unwrap(angle(H))*180/pi); grid
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
-200
-150
-100
-50
0
50
100
150
200
Frequency Response
1-29
Delay
The group delay of a fi l ter i s a measure of the average del ay of the fi l ter as a
functi on of frequency. I t i s defi ned as the negati ve fi rst deri vati ve of a fi l ters
phase response. I f the compl ex frequency response of a fi l ter i s , then
the group del ay i s
where i s the phase angl e of . Compute group del ay wi th
[gd,w] = grpdelay(b,a,n)
whi ch returns the n-poi nt group del ay, , of the di gi tal fi l ter speci fi ed by b
and a, eval uated at the frequenci es i n vector w.
The phase delay of a fi l ter i s the negati ve of phase di vi ded by frequency
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
-1400
-1200
-1000
-800
-600
-400
-200
0
H e
j
( )

g
( )
d ( )
d
--------------- =
H e
j
( )

g
( )

p
( )
( )

----------- =
1 Si gnal Processi ng Basi cs
1-30
To pl ot both the group and phase del ays of a system on the same graph, type
[b,a] = butter(10,200/1000);
gd = grpdelay(b,a,128);
[h,f] = freqz(b,a,128,2000);
pd = -unwrap(angle(h))*(2000/(2*pi))./f;
plot(f,gd,'-',f,pd,'--')
axis([0 1000 -30 30])
legend('Group Delay','Phase Delay')
0 200 400 600 800 1000
30
20
10
0
10
20
30
Group Delay
Phase Delay
Zero-Pole Analysi s
1-31
Zero-Pole Analysis
The zplane functi on pl ots pol es and zeros of a l i near system. For exampl e, a
si mpl e fi l ter wi th a zero at -1/2 and a compl ex pol e pai r at and
i s
zer = -0.5;
pol = 0.9*exp(j*2*pi*[-0.3 0.3]');
The zero-pol e pl ot for the fi l ter i s
zplane(zer,pol)
For a system i n zero-pol e form, suppl y col umn vector arguments z and p to
zplane.
zplane(z,p)
For a system i n transfer functi on form, suppl y row vectors b and a as
arguments to zplane.
zplane(b,a)
0.9e
j 2 0.3 ( )
0.9e
j 2 0.3 ( )
-1 -0.5 0 0.5 1
-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
Real part
I
m
a
g
i
n
a
r
y

p
a
r
t
1 Si gnal Processi ng Basi cs
1-32
I n thi s case zplane fi nds the roots of b and a usi ng the roots functi on and pl ots
the resul ti ng zeros and pol es.
See Li near System Model s on page 1-33 for detai l s on zero-pol e and transfer
functi on representati on of systems.
Li near System M odels
1-33
Linear System Models
The Si gnal Processi ng Tool box provi des several model s for representi ng l i near
ti me-i nvari ant systems. Thi s fl exi bi l i ty l ets you choose the representati onal
scheme that best sui ts your appl i cati on and, wi thi n the bounds of numeri c
stabi l i ty, convert freel y to and from most other model s. Thi s secti on provi des a
bri ef overvi ew of supported l i near system model s and descri bes how to work
wi th these model s i n MATLAB.
Discrete-Time System Models
The di screte-ti me system model s are representati onal schemes for di gi tal
fi l ters. MATLAB supports several di screte-ti me system model s, whi ch are
descri bed i n the fol l owi ng secti ons:
Transfer Functi on
Zero-Pol e-Gai n
State-Space
Parti al Fracti on Expansi on (Resi due Form)
Second-Order Secti ons (SOS)
Latti ce Structure
Convol uti on Matri x
Tra nsfer Function
The transfer function i s a basi c z-domai n representati on of a di gi tal fi l ter,
expressi ng the fi l ter as a rati o of two pol ynomi al s. I t i s the pri nci pal
di screte-ti me model for thi s tool box. The transfer functi on model descri pti on
for the z-transform of a di gi tal fi l ters di fference equati on i s
Here, the constants b(i) and a(i) are the fi l ter coeffi ci ents, and the order of the
fi l ter i s the maxi mum of n and m. I n MATLAB, you store these coeffi ci ents i n
two vectors (row vectors by conventi on), one row vector for the numerator and
one for the denomi nator. See Fi l ters and Transfer Functi ons on page 1-16 for
more detai l s on the transfer functi on form.
Y z ( )
b 1 ( ) b 2 ( )z
1
L b n 1 + ( )z
n
+ + +
a 1 ( ) a 2 ( )z
1
L a m 1 + ( )z
m
+ + +
----------------------------------------------------------------------------------------X z ( ) =
1 Si gnal Processi ng Basi cs
1-34
Zero- Pole- Ga in
The factored or zero-pole-gain form of a transfer functi on i s
By conventi on, MATLAB stores pol ynomi al coeffi ci ents i n row vectors and
pol ynomi al roots i n col umn vectors. I n zero-pol e-gai n form, therefore, the zero
and pol e l ocati ons for the numerator and denomi nator of a transfer functi on
resi de i n col umn vectors. The factored transfer functi on gai n k i s a MATLAB
scal ar.
The poly and roots functi ons convert between pol ynomi al and zero-pol e-gai n
representati ons. For exampl e, a si mpl e I I R fi l ter i s
b = [2 3 4];
a = [1 3 3 1];
The zeros and pol es of thi s fi l ter are
q = roots(b)
q =
-0.7500 + 1.1990i
-0.7500 - 1.1990i
p = roots(a)
p =
-1.0000
-1.0000 + 0.0000i
-1.0000 - 0.0000i
k = b(1)/a(1)
k =
2
Returni ng to the ori gi nal pol ynomi al s,
bb = k*poly(q)
bb =
2.0000 3.0000 4.0000
H z ( )
q z ( )
p z ( )
---------- k
z q 1 ( ) ( ) z q 2 ( ) ( )L z q n ( ) ( )
z p 1 ( ) ( ) z p 2 ( ) ( )L z p n ( ) ( )
-------------------------------------------------------------------------------- = =
Li near System M odels
1-35
aa = poly(p)
aa =
1.0000 3.0000 3.0000 1.0000
Note that b and a i n thi s case represent the transfer functi on
For b = [2 3 4], the roots functi on mi sses the zero for z equal to 0. I n fact, i t
mi sses pol es and zeros for z equal to 0 whenever the i nput transfer functi on has
more pol es than zeros, or vi ce versa. Thi s i s acceptabl e i n most cases. To
ci rcumvent the probl em, however, si mpl y append zeros to make the vectors the
same l ength before usi ng the roots functi on; for exampl e, b = [b 0].
Sta te- Spa ce
I t i s al ways possi bl e to represent a di gi tal fi l ter, or a system of di fference
equati ons, as a set of fi rst-order di fference equati ons. I n matri x or state-space
form, you can wri te the equati ons as
where u i s the i nput, x i s the state vector, and y i s the output. For
si ngl e-channel systems, A i s an m-by-m matri x where m i s the order of the fi l ter,
B i s a col umn vector, C i s a row vector, and D i s a scal ar. State-space notati on i s
especi al l y conveni ent for mul ti channel systems where i nput u and output y
become vectors, and B, C, and D become matri ces.
State-space representati on extends easi l y to the MATLAB envi ronment. I n
MATLAB, A, B, C, and D are rectangul ar arrays; MATLAB treats them as
i ndi vi dual vari abl es.
Taki ng the z-transform of the state-space equati ons and combi ni ng them shows
the equi val ence of state-space and transfer functi on forms.
Dont be concerned i f you are not fami l i ar wi th the state-space representati on
of l i near systems. Some of the fi l ter desi gn al gori thms use state-space form
i nternal l y but do not requi re any knowl edge of state-space concepts to use them
H z ( )
2 3z
1
4z
2
+ +
1 3z
1
3z
2
z
3
+ + +
------------------------------------------------------
2z
3
3z
2
4z + +
z
3
3z
2
3z 1 + + +
-------------------------------------------- = =
x n 1 + ( ) Ax n ( ) Bu n ( ) + =
y n ( ) Cx n ( ) Du n ( ) + =
Y z ( ) H z ( )U z ( ) = where H z ( ) C zI A ( )
1
B D + = ,
1 Si gnal Processi ng Basi cs
1-36
successful l y. I f your appl i cati ons use state-space based si gnal processi ng
extensi vel y, however, consul t the Contr ol System Tool box for a comprehensi ve
l i brary of state-space tool s.
Pa r tia l Fra ction Ex pa nsion (Residue For m)
Each transfer functi on al so has a correspondi ng partial fraction expansion or
residue form representati on, gi ven by
provi ded H(z) has no repeated pol es. Here, n i s the degree of the denomi nator
pol ynomi al of the rati onal transfer functi on b(z)/a(z). I f r i s a pol e of mul ti pl i ci ty
s
r
, then H(z) has terms of the form
The residuez functi on i n the Si gnal Processi ng Tool box converts transfer
functi ons to and from the parti al fracti on expansi on form. The z on the end of
residuez stands for z-domai n, or di screte domai n. residuez returns the pol es
i n a col umn vector p, the resi dues correspondi ng to the pol es i n a col umn
vector r, and any i mproper part of the ori gi nal transfer functi on i n a row
vector k. residuez determi nes that two pol es are the same i f the magni tude of
thei r di fference i s smal l er than 0.1 percent of ei ther of the pol es magni tudes.
Parti al fracti on expansi on ari ses i n si gnal processi ng as one method of fi ndi ng
the i nverse z-transform of a transfer functi on. For exampl e, the parti al fracti on
expansi on of
i s
b = [-4 8];
a = [1 6 8];
[r,p,k] = residuez(b,a)
b z ( )
a z ( )
----------
r 1 ( )
1 p 1 ( )z
1

---------------------------- L
r n ( )
1 p n ( )z
1

----------------------------- k 1 ( ) k 2 ( )z
1
L k m n 1 + ( )z
m n ( )
+ + + + + + =
r j ( )
1 p j ( )z
1

---------------------------
r j 1 + ( )
1 p j ( )z
1
( )
2
----------------------------------- L
r j s
r
1 + ( )
1 p j ( )z
1
( )
s
r
------------------------------------ + + +
H z ( )
4 8z
1
+
1 6z
1
8z
2
+ +
---------------------------------------- =
Li near System M odels
1-37
r =
-12
8
p =
-4
-2
k =
[]
whi ch corresponds to
To fi nd the i nverse z-transform of H(z), fi nd the sum of the i nverse z-transforms
of the two addends of H(z), gi vi ng the causal i mpul se response
To veri fy thi s i n MATLAB, type
imp = [1 0 0 0 0];
resptf = filter(b,a,imp)
resptf =
-4 32 -160 704 -2944
respres = filter(r(1),[1 -p(1)],imp) + filter(r(2),[1 -p(2)],imp)
respres =
-4 32 -160 704 -2944
H z ( )
12
1 4z
1
+
---------------------
8
1 2z
1
+
--------------------- + =
h n ( ) 12 4 ( )
n
8 2 ( )
n
+ n 0 1 2 , , , = , =
1 Si gnal Processi ng Basi cs
1-38
Second- O rder Sections (SO S)
Any transfer functi on H(z) has a second-order secti ons representati on
where L i s the number of second-order secti ons that descri be the system.
MATLAB represents the second-order secti on form of a di screte-ti me system as
an L-by-6 array sos. Each row of sos contai ns a si ngl e second-order secti on,
where the row el ements are the three numerator and three denomi nator
coeffi ci ents that descri be the second-order secti on.
There are an uncountabl e number of ways to represent a fi l ter i n second-order
secti on form. Through careful pai ri ng of the pol e and zero pai rs, orderi ng of the
secti ons i n the cascade, and mul ti pl i cati ve scal i ng of the secti ons, i t i s possi bl e
to reduce quanti zati on noi se gai n and avoi d overfl ow i n some fi xed-poi nt fi l ter
i mpl ementati ons. The functi ons zp2sos and ss2sos, descri bed i n Li near
System Transformati ons on page 1-43, perform pol e-zero pai ri ng, secti on
scal i ng, and secti on orderi ng.
Note I n the Si gnal Processi ng Tool box, al l second-order secti on
transformati ons appl y onl y to di gi tal fi l ters.
La ttice Str ucture
For a di screte Nth order al l -pol e or al l -zero fi l ter descri bed by the pol ynomi al
coeffi ci ents a(n), n = 1, 2, , N+1, there are N correspondi ng l atti ce structure
coeffi ci ents k(n), n = 1, 2, , N. The parameters k(n) are al so cal l ed the
reflection coefficients of the fi l ter. Gi ven these refl ecti on coeffi ci ents, you can
i mpl ement a di screte fi l ter as shown bel ow.
H z ( ) H
k
z ( )
k 1 =
L

b
0k
b
1k
z
1
b
2k
z
2
+ +
a
0k
a
1k
z
1
a
2k
z
2
+ +
----------------------------------------------------------
k 1 =
L

= =
sos
b
01
b
11
b
21
a
01
a
11
a
21
b
02
b
12
b
22
a
02
a
12
a
22
M M M M M M
b
0L
b
1L
b
2L
a
0L
a
1L
a
2L
=
Li near System M odels
1-39
For a general pol e-zero I I R fi l ter descri bed by pol ynomi al coeffi ci ents a and b,
there are both l atti ce coeffi ci ents k(n) for the denomi nator a and l adder
coeffi ci ents v(n) for the numerator b. The l atti ce/l adder fi l ter may be
i mpl emented as
The tool box functi on tf2latc accepts an FI R or I I R fi l ter i n pol ynomi al form
and returns the correspondi ng refl ecti on coeffi ci ents. An exampl e FI R fi l ter i n
pol ynomi al form i s
b = [1.0000 0.6149 0.9899 0.0000 0.0031 -0.0082];

z
-1
y(m)
k(1)
k(1)

k(n)
k(n)
. . .
. . .
z
-1
FI R Latti ce Fi l ter
x(m)
x(m)

y(m)
k(1)
k(1)

k(n)
k(n)
. . .
. . .
z
-1
z
-1
I I R Latti ce Fi l ter
Minimum-phase output
All-pole output
Maximum-phase output
Allpass output
z
-1
+
+
x(m)
g(m)
+
k(N)
k(N)
z
-1
+
+
k(2)
k(2)
z
-1
+
+
k(1)
k(1)
+ + +
v(N+1) v(N) v(3) v(2) v(1)
f(m)
ARMA output
1 Si gnal Processi ng Basi cs
1-40
Thi s fi l ters l atti ce (refl ecti on coeffi ci ent) representati on i s
k = tf2latc(b)
k =
0.3090
0.9801
0.0031
0.0081
-0.0082
For I I R fi l ters, the magni tude of the refl ecti on coeffi ci ents provi des an easy
stabi l i ty check. I f al l the refl ecti on coeffi ci ents correspondi ng to a pol ynomi al
have magni tude l ess than 1, al l of that pol ynomi al s roots are i nsi de the uni t
ci rcl e. For exampl e, consi der an I I R fi l ter wi th numerator pol ynomi al b from
above and denomi nator pol ynomi al
a = [1 1/2 1/3];
The fi l ters l atti ce representati on i s
[k,v] = tf2latc(b,a)
k =
0.3750
0.3333
0
0
0
v =
0.6252
0.1212
0.9879
-0.0009
0.0072
-0.0082
Because abs(k) < 1 for al l refl ecti on coeffi ci ents i n k, the fi l ter i s stabl e.
Li near System M odels
1-41
The functi on latc2tf cal cul ates the pol ynomi al coeffi ci ents for a fi l ter from i ts
l atti ce (refl ecti on) coeffi ci ents. Gi ven the refl ecti on coeffi ci ent vector k(above),
the correspondi ng pol ynomi al form i s
b = latc2tf(k)
b =
1.0000 0.6149 0.9899 -0.0000 0.0031 -0.0082
The l atti ce or l atti ce/l adder coeffi ci ents can be used to i mpl ement the fi l ter
usi ng the functi on latcfilt.
Convolution M a trix
I n si gnal processi ng, convol vi ng two vectors or matri ces i s equi val ent to
fi l teri ng one of the i nput operands by the other. Thi s rel ati onshi p permi ts the
representati on of a di gi tal fi l ter as a convolution matrix.
Gi ven any vector, the tool box functi on convmtx generates a matri x whose i nner
product wi th another vector i s equi val ent to the convol uti on of the two vectors.
The generated matri x represents a di gi tal fi l ter that you can appl y to any
vector of appropri ate l ength; the i nner di mensi on of the operands must agree
to compute the i nner product.
The convol uti on matri x for a vector b, representi ng the numerator coeffi ci ents
for a di gi tal fi l ter, i s
b = [1 2 3]; x = randn(3,1);
C = convmtx(b',3)
C =
1 0 0
2 1 0
3 2 1
0 3 2
0 0 3
Two equi val ent ways to convol ve b wi th x are as fol l ows.
y1 = C*x;
y2 = conv(b,x);
1 Si gnal Processi ng Basi cs
1-42
Continuous-Time System Models
The conti nuous-ti me system model s are representati onal schemes for anal og
fi l ters. Many of the di screte-ti me system model s descri bed earl i er are al so
appropri ate for the representati on of conti nuous-ti me systems:
State-space form
Parti al fracti on expansi on
Transfer functi on
Zero-pol e-gai n form
I t i s possi bl e to represent any system of l i near ti me-i nvari ant di fferenti al
equati ons as a set of fi rst-order di fferenti al equati ons. I n matri x or state-space
form, you can express the equati ons as
where u i s a vector of nu i nputs, x i s an nx-el ement state vector, and y i s a vector
of ny outputs. I n MATLAB, store A, B, C, and D i n separate rectangul ar arrays.
An equi val ent representati on of the state-space system i s the Lapl ace
transform transfer functi on descri pti on
where
For si ngl e-i nput, si ngl e-output systems, thi s form i s gi ven by
Gi ven the coeffi ci ents of a Lapl ace transform transfer functi on, residue
determi nes the parti al fracti on expansi on of the system. See the descri pti on of
residue i n the MATLAB documentati on for detai l s.
The factored zero-pol e-gai n form i s
x

Ax Bu + =
y Cx Du + =
Y s ( ) H s ( )U s ( ) =
H s ( ) C sI A ( )
1
B D + =
H s ( )
b s ( )
a s ( )
----------
b 1 ( )s
n
b 2 ( )s
n 1
L b n 1 + ( ) + + +
a 1 ( )s
m
a 2 ( )s
m 1
L a m 1 + ( ) + + +
------------------------------------------------------------------------------------------ = =
H s ( )
z s ( )
p s ( )
---------- k
s z 1 ( ) ( ) s z 2 ( ) ( )L s z n ( ) ( )
s p 1 ( ) ( ) s p 2 ( ) ( )L s p n ( ) ( )
-------------------------------------------------------------------------------- = =
Li near System M odels
1-43
As i n the di screte-ti me case, MATLAB stores pol ynomi al coeffi ci ents i n row
vectors i n descendi ng powers of s. MATLAB stores pol ynomi al roots, or zeros
and pol es, i n col umn vectors.
Linear System Transformations
The Si gnal Processi ng Tool box provi des a number of functi ons that convert
between the vari ous l i near system model s; see Chapter 7, Functi on Reference
for a compl ete descri pti on of each. You can use the fol l owi ng chart to fi nd an
appropri ate transfer functi on: fi nd the row of the model to convert from on the
l eft si de of the chart and the col umn of the model to convert to on the top of the
chart and read the functi on name(s) at the i ntersecti on of the row and col umn.
Note Converti ng from one fi l ter structure or model to another may produce a
resul t wi th di fferent characteri sti cs than the ori gi nal . Thi s i s due to the
computers fi ni te-preci si on ari thmeti c and the vari ati ons i n the conversi ons
round-off computati ons.
Transfer
function
State-
space
Zero-
pole-
gain
Partial
fraction
Lattice
filter
Second-
order
sections
Convolution
matrix
Transfer
function
tf2ss tf2zp
roots
residuez
residue
tf2latc convmtx
State-space ss2tf ss2zp ss2sos
Zero-pole-
gain
zp2tf
poly
zp2ss zp2sos
Partial
fraction
residuez
residue
Lattice filter latc2tf
SOS sos2tf sos2ss sos2zp
Convolution
matrix
1 Si gnal Processi ng Basi cs
1-44
Many of the tool box fi l ter desi gn functi ons use these functi ons i nternal l y. For
exampl e, the zp2ss functi on converts the pol es and zeros of an anal og
prototype i nto the state-space form requi red for creati on of a Butterworth,
Chebyshev, or el l i pti c fi l ter. Once i n state-space form, the fi l ter desi gn functi on
performs any requi red frequency transformati on, that i s, i t transforms the
i ni ti al l owpass desi gn i nto a bandpass, hi ghpass, or bandstop fi l ter, or a
l owpass fi l ter wi th the desi red cutoff frequency. See the descri pti ons of the
i ndi vi dual fi l ter desi gn functi ons i n Chapter 7, Functi on Reference, for more
detai l s.
Note I n the Si gnal Processi ng Tool box, al l second-order secti on
transformati ons appl y onl y to di gi tal fi l ters.
Di screte Fouri er Transform
1-45
Discrete Fourier Transform
The di screte Fouri er transform, or DFT, i s the pri mary tool of di gi tal si gnal
processi ng. The foundati on of the Si gnal Processi ng Tool box i s the fast Fouri er
transform (FFT), a method for computi ng the DFT wi th reduced executi on
ti me. Many of the tool box functi ons (i ncl udi ng z-domai n frequency response,
spectrum and cepstrum anal ysi s, and some fi l ter desi gn and i mpl ementati on
functi ons) i ncorporate the FFT.
MATLAB provi des the functi ons fft and ifft to compute the di screte Fouri er
transform and i ts i nverse, respecti vel y. For the i nput sequence x and i ts
transformed versi on X (the di screte-ti me Fouri er transform at equal l y spaced
frequenci es around the uni t ci rcl e), the two functi ons i mpl ement the
rel ati onshi ps
I n these equati ons, the seri es subscri pts begi n wi th 1 i nstead of 0 because of
MATLABs vector i ndexi ng scheme, and
Note MATLAB uses a negati ve j for the fft functi on. Thi s i s an engi neeri ng
conventi on; physi cs and pure mathemati cs typi cal l y use a posi ti ve j.
fft, wi th a si ngl e i nput argument x, computes the DFT of the i nput vector or
matri x. I f x i s a vector, fft computes the DFT of the vector; i f x i s a rectangul ar
array, fft computes the DFT of each array col umn.
X k 1 + ( ) x n 1 + ( )W
n
kn
n 0 =
N 1

=
x n 1 + ( )
1
N
---- X k 1 + ( )W
n
kn
k 0 =
N 1

=
W
N
e
j
2
N
-------
,
_
=
1 Si gnal Processi ng Basi cs
1-46
For exampl e, create a ti me vector and si gnal .
t = (0:1/100:10-1/100); % Time vector
x = sin(2*pi*15*t) + sin(2*pi*40*t); % Signal
The DFT of the si gnal , and the magni tude and phase of the transformed
sequence, are then
y = fft(x); % Compute DFT of x
m = abs(y); p = unwrap(angle(y)); % Magnitude and phase
To pl ot the magni tude and phase, type the fol l owi ng commands.
f = (0:length(y)-1)*99/length(y); % Frequency vector
plot(f,m); title('Magnitude');
set(gca,'XTick',[15 40 60 85]);
figure; plot(f,p*180/pi); title('Phase');
set(gca,'XTick',[15 40 60 85]);
A second argument to fft speci fi es a number of poi nts n for the transform,
representi ng DFT l ength.
y = fft(x,n);
I n thi s case, fft pads the i nput sequence wi th zeros i f i t i s shorter than n, or
truncates the sequence i f i t i s l onger than n. I f n i s not speci fi ed, i t defaul ts to
the l ength of the i nput sequence. Executi on ti me for fft depends on the
l ength, n, of the DFT i t performs; see the fft reference page i n the MATLAB
documentati on for detai l s about the al gori thm.
15 40 60 85
0
100
200
300
400
500
600
Magnitude
15 40 60 85
0.5
0
0.5
1
1.5
2
2.5
3
x 10
4 Phase
Di screte Fouri er Transform
1-47
The i nverse di screte Fouri er transform functi on ifft al so accepts an i nput
sequence and, opti onal l y, the number of desi red poi nts for the transform. Try
the exampl e bel ow; the ori gi nal sequence x and the reconstructed sequence are
i denti cal (wi thi n roundi ng error).
t = (0:1/255:1);
x = sin(2*pi*120*t);
y = real(ifft(fft(x)));
Thi s tool box al so i ncl udes functi ons for the two-di mensi onal FFT and i ts
i nverse, fft2 and ifft2. These functi ons are useful for two-di mensi onal si gnal
or i mage processi ng. The goertzel functi on, whi ch i s another al gori thm to
compute the DFT, al so i s i ncl uded i n the tool box. Thi s functi on i s effi ci ent for
computi ng the DFT of a porti on of a l ong si gnal . See the descri pti ons i n Chapter
7, Functi on Reference, for detai l s.
I t i s someti mes conveni ent to rearrange the output of the fft or fft2 functi on
so the zero frequency component i s at the center of the sequence. The MATLAB
functi on fftshift moves the zero frequency component to the center of a vector
or matri x.
1 Si gnal Processi ng Basi cs
1-48
Selected Bibliography
Al gori thm devel opment for the Si gnal Processi ng Tool box has drawn heavi l y
upon the references l i sted bel ow. Al l are recommended to the i nterested reader
who needs to know more about si gnal processi ng than i s covered i n thi s
manual .
[1] Crochi ere, R.E., and L.R. Rabi ner. Multi-Rate Signal Processing.
Engl ewood Cl i ffs, NJ: Prenti ce Hal l , 1983. Pgs. 88-91.
[2] I EEE. Programs for Digital Signal Processing. I EEE Press. New York: John
Wi l ey & Sons, 1979.
[3] Jackson, L.B. Digital Filters and Signal Processing. Thi rd Ed. Boston:
Kl uwer Academi c Publ i shers, 1989.
[4] Kay, S.M. Modern Spectral Estimation. Engl ewood Cl i ffs, NJ: Prenti ce Hal l ,
1988.
[5] Oppenhei m, A.V., and R.W. Schafer. Discrete-Time Signal Processing.
Engl ewood Cl i ffs, NJ: Prenti ce Hal l , 1989.
[6] Parks, T.W., and C.S. Burrus. Digital Filter Design. New York: John Wi l ey
& Sons, 1987.
[7] Pratt,W.K. Digital I mage Processing. New York: John Wi l ey & Sons, 1991.
[8] Perci val , D.B., and A.T. Wal den. Spectral Analysis for Physical
Applications: Multitaper and Conventional Univariate Techniques. Cambri dge:
Cambri dge Uni versi ty Press, 1993.
[9] Proaki s, J.G., and D.G. Manol aki s. Digital Signal Processing: Principles,
Algorithms, and Applications. Upper Saddl e Ri ver, NJ: Prenti ce Hal l , 1996.
[10] Rabi ner, L.R., and B. Gol d. Theory and Application of Digital Signal
Processing. Engl ewood Cl i ffs, NJ: Prenti ce Hal l , 1975.
[11] Wel ch, P.D. The Use of Fast Fouri er Transform for the Esti mati on of
Power Spectra: A Method Based on Ti me Averagi ng Over Short, Modi fi ed
Peri odograms. I EEE Trans. Audio Electroacoust. Vol . AU-15 (June 1967).
Pgs. 70-73.

2
Fi l ter Desi gn
Overview . . . . . . . . . . . . . . . . . . . . . 2-2
Filter Requirements and Specification . . . . . . . . 2-3
IIR Filter Design . . . . . . . . . . . . . . . . . . 2-5
Cl assi cal I I R Fi l ter Desi gn Usi ng Anal og Prototypi ng . . . . 2-7
Compari son of Cl assi cal I I R Fi l ter Types . . . . . . . . . 2-9
FIR Filter Design . . . . . . . . . . . . . . . . . . 2-17
Li near Phase Fi l ters . . . . . . . . . . . . . . . . . 2-18
Wi ndowi ng Method . . . . . . . . . . . . . . . . . . 2-19
Mul ti band FI R Fi l ter Desi gn wi th Transi ti on Bands . . . . 2-23
Constrai ned Least Squares FI R Fi l ter Desi gn . . . . . . . 2-28
Arbi trary-Response Fi l ter Desi gn . . . . . . . . . . . . 2-32
Special Topics in IIR Filter Design . . . . . . . . . . 2-38
Anal og Prototype Desi gn . . . . . . . . . . . . . . . 2-39
Frequency Transformati on . . . . . . . . . . . . . . . 2-39
Fi l ter Di screti zati on . . . . . . . . . . . . . . . . . 2-42
Selected Bibliography . . . . . . . . . . . . . . . 2-46
2 Fi lter Desi gn
2-2
Overview
The Si gnal Processi ng Tool box provi des functi ons that support a range of fi l ter
desi gn methodol ogi es. The fol l owi ng secti ons expl ai n how to appl y the fi l ter
desi gn tool s to I nfinite I mpulse Response (I I R) and Finite I mpulse Response
(FI R) fi l ter desi gn probl ems:
Fi l ter Requi rements and Speci fi cati on
I I R Fi l ter Desi gn
FI R Fi l ter Desi gn
Speci al Topi cs i n I I R Fi l ter Desi gn
Sel ected Bi bl i ography
Fi lter Requi rements and Speci fi cati on
2-3
Filter Requirements and Specification
The goal of fi l ter desi gn i s to perform frequency dependent al terati on of a data
sequence. A possi bl e requi rement mi ght be to remove noi se above 30 Hz from
a data sequence sampl ed at 100 Hz. A more ri gorous speci fi cati on mi ght cal l for
a speci fi c amount of passband ri ppl e, stopband attenuati on, or transi ti on
wi dth. A very preci se speci fi cati on coul d ask to achi eve the performance goal s
wi th the mi ni mum fi l ter order, or i t coul d cal l for an arbi trary magni tude
shape, or i t mi ght requi re an FI R fi l ter.
Fi l ter desi gn methods di ffer pri mari l y i n how performance i s speci fi ed. For
l oosel y speci fi ed requi rements, as i n the fi rst case above, a Butterworth I I R
fi l ter i s often suffi ci ent. To desi gn a fi fth-order 30 Hz l owpass Butterworth
fi l ter and appl y i t to the data i n vector x,
[b,a] = butter(5,30/50);
y = filter(b,a,x);
The second i nput argument to butter speci fi es the cutoff frequency,
normal i zed to hal f the sampl i ng frequency (the Nyqui st frequency).
Frequency Normalization in the Signal Processing Toolbox Al l of the
fi l ter desi gn functi ons operate wi th normal i zed frequenci es, so they do not
requi re the system sampl i ng rate as an extra i nput argument. Thi s tool box
uses the conventi on that uni t frequency i s the Nyqui st frequency, defi ned as
hal f the sampl i ng frequency. The normal i zed frequency, therefore, i s al ways
i n the i nterval 0 f 1. For a system wi th a 1000 Hz sampl i ng frequency,
300 Hz i s 300/500 = 0.6. To convert normal i zed frequency to angul ar
frequency around the uni t ci rcl e, mul ti pl y by . To convert normal i zed
frequency back to hertz, mul ti pl y by hal f the sampl e frequency.
More ri gorous fi l ter requi rements tradi ti onal l y i ncl ude passband ri ppl e (Rp, i n
deci bel s), stopband attenuati on (Rs, i n deci bel s), and transi ti on wi dth (Ws-Wp,
i n hertz).
2 Fi lter Desi gn
2-4
You can desi gn Butterworth, Chebyshev Type I , Chebyshev Type I I , and
el l i pti c fi l ters that meet thi s type of performance speci fi cati on. The tool box
order sel ecti on functi ons esti mate the mi ni mum fi l ter order that meets a gi ven
set of requi rements.
To meet speci fi cati ons wi th more ri gi d constrai nts l i ke l i near phase or
arbi trary fi l ter shape, use the FI R and di rect I I R fi l ter desi gn routi nes.
10
-1
10
0
10
1
0
0.2
0.4
0.6
0.8
1
Frequency(rad/sec)
M
a
g
n
i
t
u
d
e
IIR Fi lter Desi gn
2-5
IIR Filter Design
The pri mary advantage of I I R fi l ters over FI R fi l ters i s that they typi cal l y meet
a gi ven set of speci fi cati ons wi th a much l ower fi l ter order than a correspondi ng
FI R fi l ter. Al though I I R fi l ters have nonl i near phase, data processi ng wi thi n
MATLAB i s commonl y performed off-l i ne, that i s, the enti re data sequence i s
avai l abl e pri or to fi l teri ng. Thi s al l ows for a noncausal , zero-phase fi l teri ng
approach (vi a the filtfilt functi on), whi ch el i mi nates the nonl i near phase
di storti on of an I I R fi l ter.
The cl assi cal I I R fi l ters, Butterworth, Chebyshev Types I and I I , el l i pti c, and
Bessel , al l approxi mate the i deal bri ck wal l fi l ter i n di fferent ways. Thi s
tool box provi des functi ons to create al l these types of cl assi cal I I R fi l ters i n both
the anal og and di gi tal domai ns (except Bessel , for whi ch onl y the anal og case
i s supported), and i n l owpass, hi ghpass, bandpass, and bandstop
confi gurati ons. For most fi l ter types, you can al so fi nd the l owest fi l ter order
that fi ts a gi ven fi l ter speci fi cati on i n terms of passband and stopband
attenuati on, and transi ti on wi dth(s).
The di rect fi l ter desi gn functi on yulewalk fi nds a fi l ter wi th magni tude
response approxi mati ng a desi red functi on. Thi s i s one way to create a
mul ti band bandpass fi l ter.
You can al so use the parametri c model i ng or system i denti fi cati on functi ons to
desi gn I I R fi l ters. These functi ons are di scussed i n Parametri c Model i ng on
page 4-12.
The general i zed Butterworth desi gn functi on maxflat i s di scussed i n the
secti on General i zed Butterworth Fi l ter Desi gn on page 2-15.
The fol l owi ng tabl e summari zes the vari ous fi l ter methods i n the tool box and
l i sts the functi ons avai l abl e to i mpl ement these methods.
2 Fi lter Desi gn
2-6
Method Description Functions
Anal og
Prototypi ng
Usi ng the pol es and zeros of
a cl assi cal l owpass
prototype fi l ter i n the
conti nuous (Lapl ace)
domai n, obtai n a di gi tal
fi l ter through frequency
transformati on and fi l ter
di screti zati on.
Compl ete desi gn functi ons:
besself, butter, cheby1, cheby2, ellip
Order esti mati on functi ons:
buttord, cheb1ord, cheb2ord, ellipord
Lowpass anal og prototype functi ons:
besselap, buttap, cheb1ap, cheb2ap,
ellipap
Frequency transformati on functi ons:
lp2bp, lp2bs, lp2hp, lp2lp
Fi l ter di screti zati on functi ons:
bilinear, impinvar
Di rect Desi gn Desi gn di gi tal fi l ter di rectl y
i n the di screte ti me-domai n
by approxi mati ng a
pi ecewi se l i near magni tude
response.
yulewalk
General i zed
Butterworth
Desi gn
Desi gn l owpass
Butterworth fi l ters wi th
more zeros than pol es.
maxflat
Parametri c
Model i ng
Fi nd a di gi tal fi l ter that
approxi mates a prescri bed
ti me or frequency domai n
response. (See the System
I denti fi cati on Tool box for
an extensi ve col l ecti on of
parametri c model i ng tool s.)
Ti me-domai n model i ng functi ons:
lpc, prony, stmcb
Frequency-domai n model i ng functi ons:
invfreqs, invfreqz
IIR Fi lter Desi gn
2-7
Classical IIR Filter Design Using Analog Prototyping
The pri nci pal I I R di gi tal fi l ter desi gn techni que thi s tool box provi des i s based
on the conversi on of cl assi cal l owpass anal og fi l ters to thei r di gi tal equi val ents.
The fol l owi ng secti ons descri be how to desi gn fi l ters and summari ze the
characteri sti cs of the supported fi l ter types. See Speci al Topi cs i n I I R Fi l ter
Desi gn on page 2-38 for detai l ed steps on the fi l ter desi gn process.
Complete Cla ssica l IIR Filter Design
You can easi l y create a fi l ter of any order wi th a l owpass, hi ghpass, bandpass,
or bandstop confi gurati on usi ng the fi l ter desi gn functi ons.
By defaul t, each of these functi ons returns a l owpass fi l ter; you need onl y
speci fy the desi red cutoff frequency Wn i n normal i zed frequency (Nyqui st
frequency = 1 Hz). For a hi ghpass fi l ter, append the stri ng 'high' to the
functi ons parameter l i st. For a bandpass or bandstop fi l ter, speci fy Wn as a
two-el ement vector contai ni ng the passband edge frequenci es, appendi ng the
stri ng 'stop' for the bandstop confi gurati on.
Filter Type Design Function
Bessel (anal og onl y) [b,a] = besself(n,Wn,options)
[z,p,k] = besself(n,Wn,options)
[A,B,C,D] = besself(n,Wn,options)
Butterworth [b,a] = butter(n,Wn,options)
[z,p,k] = butter(n,Wn,options)
[A,B,C,D] = butter(n,Wn,options)
Chebyshev Type I [b,a] = cheby1(n,Rp,Wn,options)
[z,p,k] = cheby1(n,Rp,Wn,options)
[A,B,C,D] = cheby1(n,Rp,Wn,options)
Chebyshev Type I I [b,a] = cheby2(n,Rs,Wn,options)
[z,p,k] = cheby2(n,Rs,Wn,options)
[A,B,C,D] = cheby2(n,Rs,Wn,options)
El l i pti c [b,a] = ellip(n,Rp,Rs,Wn,options)
[z,p,k] = ellip(n,Rp,Rs,Wn,options)
[A,B,C,D] = ellip(n,Rp,Rs,Wn,options)
2 Fi lter Desi gn
2-8
Here are some exampl e di gi tal fi l ters.
[b,a] = butter(5,0.4); % Lowpass Butterworth
[b,a] = cheby1(4,1,[0.4 0.7]); % Bandpass Chebyshev Type I
[b,a] = cheby2(6,60,0.8,'high'); % Highpass Chebyshev Type II
[b,a] = ellip(3,1,60,[0.4 0.7],'stop'); % Bandstop elliptic
To desi gn an anal og fi l ter, perhaps for si mul ati on, use a trai l i ng 's' and
speci fy cutoff frequenci es i n rad/s.
[b,a] = butter(5,.4,'s'); % Analog Butterworth filter
Al l fi l ter desi gn functi ons return a fi l ter i n the transfer functi on,
zero-pol e-gai n, or state-space l i near system model representati on, dependi ng
on how many output arguments are present.
Note Al l cl assi cal I I R l owpass fi l ters are i l l -condi ti oned for extremel y l ow
cut-off frequenci es. Therefore, i nstead of desi gni ng a l owpass I I R fi l ter wi th a
very narrow passband, i t can be better to desi gn a wi der passband and
deci mate the i nput si gnal .
Designing IIR Filters to Frequency Doma in Specifica tions
Thi s tool box provi des order sel ecti on functi ons that cal cul ate the mi ni mum
fi l ter order that meets a gi ven set of requi rements.
These are useful i n conjuncti on wi th the fi l ter desi gn functi ons. Suppose you
want a bandpass fi l ter wi th a passband from 1000 to 2000 Hz, stopbands
starti ng 500 Hz away on ei ther si de, a 10 kHz sampl i ng frequency, at most 1 dB
Filter Type Order Estimation Function
Butterworth [n,Wn] = buttord(Wp,Ws,Rp,Rs)
Chebyshev Type I [n,Wn] = cheb1ord(Wp, Ws, Rp, Rs)
Chebyshev Type I I [n,Wn] = cheb2ord(Wp, Ws, Rp, Rs)
El l i pti c [n,Wn] = ellipord(Wp, Ws, Rp, Rs)
IIR Fi lter Desi gn
2-9
of passband ri ppl e, and at l east 60 dB of stopband attenuati on. You can meet
these speci fi cati ons by usi ng the butter functi on as fol l ows.
[n,Wn] = buttord([1000 2000]/5000,[500 2500]/5000,1,60)
n =
12
Wn =
0.1951 0.4080
[b,a] = butter(n,Wn);
An el l i pti c fi l ter that meets the same requi rements i s gi ven by
[n,Wn] = ellipord([1000 2000]/5000,[500 2500]/5000,1,60)
n =
5
Wn =
0.2000 0.4000
[b,a] = ellip(n,1,60,Wn);
These functi ons al so work wi th the other standard band confi gurati ons, as wel l
as for anal og fi l ters; see Chapter 7, Functi on Reference, for detai l s.
Comparison of Classical IIR Filter Types
The tool box provi des fi ve di fferent types of cl assi cal I I R fi l ters, each opti mal i n
some way. Thi s secti on shows the basi c anal og prototype form for each and
summari zes major characteri sti cs.
Butter w orth Filter
The Butterworth fi l ter provi des the best Tayl or Seri es approxi mati on to the
i deal l owpass fi l ter response at anal og frequenci es and ; for any
order N, the magni tude squared response has 2N-1 zero deri vati ves at these
l ocati ons (maximally flat at and ). Response i s monotoni c
overal l , decreasi ng smoothl y from to . at
.
0 = =
0 = =
0 = = H j ( ) 1 2 =
1 =
2 Fi lter Desi gn
2-10
Chebyshev Type I Filter
The Chebyshev Type I fi l ter mi ni mi zes the absol ute di fference between the
i deal and actual frequency response over the enti re passband by i ncorporati ng
an equal ri ppl e of Rp dB i n the passband. Stopband response i s maxi mal l y fl at.
The transi ti on from passband to stopband i s more rapi d than for the
Butterworth fi l ter. at .
10
-1
10
0
10
1
0
0.2
0.4
0.6
0.8
1
Frequency(rad/sec)
M
a
g
n
i
t
u
d
e
H j ( ) 10
Rp 20
= 1 =
10
-1
10
0
10
1
0
0.2
0.4
0.6
0.8
1
Frequency(rad/sec)
M
a
g
n
i
t
u
d
e
IIR Fi lter Desi gn
2-11
Chebyshev Type II Filter
The Chebyshev Type I I fi l ter mi ni mi zes the absol ute di fference between the
i deal and actual frequency response over the enti re stopband by i ncorporati ng
an equal ri ppl e of Rs dB i n the stopband. Passband response i s maxi mal l y fl at.
The stopband does not approach zero as qui ckl y as the type I fi l ter (and does
not approach zero at al l for even-val ued fi l ter order n). The absence of ri ppl e i n
the passband, however, i s often an i mportant advantage.
at .
Elliptic Filter
El l i pti c fi l ters are equi ri ppl e i n both the passband and stopband. They
general l y meet fi l ter requi rements wi th the l owest order of any supported fi l ter
type. Gi ven a fi l ter order n, passband ri ppl e Rp i n deci bel s, and stopband ri ppl e
Rs i n deci bel s, el l i pti c fi l ters mi ni mi ze transi ti on wi dth. at
.
H j ( ) 10
Rs 20
=
1 =
10
-1
10
0
10
1
0
0.2
0.4
0.6
0.8
1
Frequency(rad/sec)
M
a
g
n
i
t
u
d
e
H j ( ) 10
Rp 20
=
1 =
2 Fi lter Desi gn
2-12
Bessel Filter
Anal og Bessel l owpass fi l ters have maxi mal l y fl at group del ay at zero
frequency and retai n nearl y constant group del ay across the enti re passband.
Fi l tered si gnal s therefore mai ntai n thei r waveshapes i n the passband
frequency range. Frequency mapped and di gi tal Bessel fi l ters, however, do not
have thi s maxi mal l y fl at property; thi s tool box supports onl y the anal og case
for the compl ete Bessel fi l ter desi gn functi on.
Bessel fi l ters general l y requi re a hi gher fi l ter order than other fi l ters for
sati sfactory stopband attenuati on. at and decreases as
fi l ter order n i ncreases.
10
-1
10
0
10
1
0
0.2
0.4
0.6
0.8
1
Frequency(rad/sec)
M
a
g
n
i
t
u
d
e
H j ( ) 1 2 < 1 =
IIR Fi lter Desi gn
2-13
Note The l owpass fi l ters shown above were created wi th the anal og
prototype functi ons besselap, buttap, cheb1ap, cheb2ap, and ellipap. These
functi ons fi nd the zeros, pol es, and gai n of an order n anal og fi l ter of the
appropri ate type wi th cutoff frequency of 1 rad/s. The compl ete fi l ter desi gn
functi ons (besself, butter, cheby1, cheby2, and ellip) cal l the prototypi ng
functi ons as a fi rst step i n the desi gn process. See Speci al Topi cs i n I I R Fi l ter
Desi gn on page 2-37 for detai l s.
To create si mi l ar pl ots, use n = 5 and, as needed, Rp = 0.5 and Rs = 20. For
exampl e, to create the el l i pti c fi l ter pl ot
[z,p,k] = ellipap(5,0.5,20);
w = logspace(-1,1,1000);
h = freqs(k*poly(z),poly(p),w);
semilogx(w,abs(h)), grid
10
-1
10
0
10
1
0
0.2
0.4
0.6
0.8
1
Frequency(rad/sec)
M
a
g
n
i
t
u
d
e
2 Fi lter Desi gn
2-14
Direct IIR Filter Design
Thi s tool box uses the term direct methods to descri be techni ques for I I R desi gn
that fi nd a fi l ter based on speci fi cati ons i n the di screte domai n. Unl i ke the
anal og prototypi ng method, di rect desi gn methods are not constrai ned to the
standard l owpass, hi ghpass, bandpass, or bandstop confi gurati ons. Rather,
these functi ons desi gn fi l ters wi th an arbi trary, perhaps mul ti band, frequency
response. Thi s secti on di scusses the yulewalk functi on, whi ch i s i ntended
speci fi cal l y for fi l ter desi gn; Parametri c Model i ng on page 4-12 di scusses
other methods that may al so be consi dered di rect, such as Pronys method,
Li near Predi cti on, the Stei gl i tz-McBri de method, and i nverse frequency
desi gn.
The yulewalk functi on desi gns recursi ve I I R di gi tal fi l ters by fi tti ng a speci fi ed
frequency response. yulewalks name refl ects i ts method for fi ndi ng the fi l ters
denomi nator coeffi ci ents: i t fi nds the i nverse FFT of the i deal desi red power
spectrum and sol ves the modi fi ed Yul e-Wal ker equati ons usi ng the resul ti ng
autocorrel ati on functi on sampl es. The statement
[b,a] = yulewalk(n,f,m)
returns row vectors b and a contai ni ng the n+1 numerator and denomi nator
coeffi ci ents of the order n I I R fi l ter whose frequency-magni tude characteri sti cs
approxi mate those gi ven i n vectors f and m. f i s a vector of frequency poi nts
rangi ng from 0 to 1, where 1 represents the Nyqui st frequency. m i s a vector
contai ni ng the desi red magni tude response at the poi nts i n f. f and m can
descri be any pi ecewi se l i near shape magni tude response, i ncl udi ng a
mul ti band response. The FI R counterpart of thi s functi on i s fir2, whi ch al so
desi gns a fi l ter based on an arbi trary pi ecewi se l i near magni tude response. See
FI R Fi l ter Desi gn on page 2-16 for detai l s.
Note that yulewalk does not accept phase i nformati on, and no statements are
made about the opti mal i ty of the resul ti ng fi l ter.
Desi gn a mul ti band fi l ter wi th yulewalk, and pl ot the desi red and actual
frequency response.
m = [0 0 1 1 0 0 1 1 0 0];
f = [0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 1];
[b,a] = yulewalk(10,f,m);
[h,w] = freqz(b,a,128);
plot(f,m,w/pi,abs(h))
IIR Fi lter Desi gn
2-15
Genera lized Butter w or th Filter Design
The tool box functi on maxflat enabl es you to desi gn general i zed Butterworth
fi l ters, that i s, Butterworth fi l ters wi th di fferi ng numbers of zeros and pol es.
Thi s i s desi rabl e i n some i mpl ementati ons where pol es are more expensi ve
computati onal l y than zeros. maxflat i s just l i ke the butter functi on, except
that i t you can speci fy two orders (one for the numerator and one for the
denomi nator) i nstead of just one. These fi l ters are maximally flat. Thi s means
that the resul ti ng fi l ter i s opti mal for any numerator and denomi nator orders,
wi th the maxi mum number of deri vati ves at 0 and the Nyqui st frequency =
both set to 0.
For exampl e, when the two orders are the same, maxflat i s the same as butter.
[b,a] = maxflat(3,3,0.25)
b =
0.0317 0.0951 0.0951 0.0317
a =
1.0000 -1.4590 0.9104 -0.1978
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
0
0.2
0.4
0.6
0.8
1
1.2
2 Fi lter Desi gn
2-16
[b,a] = butter(3,0.25)
b =
0.0317 0.0951 0.0951 0.0317
a =
1.0000 -1.4590 0.9104 -0.1978
However, maxflat i s more versati l e because i t al l ows you to desi gn a fi l ter wi th
more zeros than pol es.
[b,a] = maxflat(3,1,0.25)
b =
0.0950 0.2849 0.2849 0.0950
a =
1.0000 -0.2402
The thi rd i nput to maxfl at i s the half-power frequency, a frequency between
0 and 1 wi th a desi red magni tude response of .
You can al so desi gn l i near phase fi l ters that have the maxi mal l y fl at property
usi ng the 'sym' opti on.
maxflat(4,'sym',0.3)
ans =
0.0331 0.2500 0.4337 0.2500 0.0331
For compl ete detai l s of the maxflat al gori thm, see Sel esni ck and Burrus [2].
1 2
FIR Fi lter Desi gn
2-17
FIR Filter Design
Di gi tal fi l ters wi th fi ni te-durati on i mpul se response (al l -zero, or FI R fi l ters)
have both advantages and di sadvantages compared to i nfi ni te-durati on
i mpul se response (I I R) fi l ters.
FI R fi l ters have the fol l owi ng pri mary advantages:
They can have exactl y l i near phase.
They are al ways stabl e.
The desi gn methods are general l y l i near.
They can be real i zed effi ci entl y i n hardware.
The fi l ter startup transi ents have fi ni te durati on.
The pri mary di sadvantage of FI R fi l ters i s that they often requi re a much
hi gher fi l ter order than I I R fi l ters to achi eve a gi ven l evel of performance.
Correspondi ngl y, the del ay of these fi l ters i s often much greater than for an
equal performance I I R fi l ter.
Method Description Functions
Wi ndowi ng Appl y wi ndow to truncated
i nverse Fouri er transform of
desi red bri ck wal l fi l ter
fir1, fir2,
kaiserord
Mul ti band wi th
Transi ti on
Bands
Equi ri ppl e or l east squares
approach over sub-bands of the
frequency range
firls, remez,
remezord
Constrai ned
Least Squares
Mi ni mi ze squared i ntegral
error over enti re frequency
range subject to maxi mum
error constrai nts
fircls, fircls1
Arbi trary
Response
Arbi trary responses, i ncl udi ng
nonl i near phase and compl ex
fi l ters
cremez
Rai sed Cosi ne Lowpass response wi th
smooth, si nusoi dal transi ti on
firrcos
2 Fi lter Desi gn
2-18
Linear Phase Filters
Except for cremez, al l of the FI R fi l ter desi gn functi ons desi gn l i near phase
fi l ters onl y. The fi l ter coeffi ci ents, or taps, of such fi l ters obey ei ther an even
or odd symmetry rel ati on. Dependi ng on thi s symmetry, and on whether the
order n of the fi l ter i s even or odd, a l i near phase fi l ter (stored i n l ength n+1
vector b) has certai n i nherent restri cti ons on i ts frequency response.
The phase del ay and group del ay of l i near phase FI R fi l ters are equal and
constant over the frequency band. For an order n l i near phase FI R fi l ter, the
group del ay i s n/2, and the fi l tered si gnal i s si mpl y del ayed by n/2 ti me steps
(and the magni tude of i ts Fouri er transform i s scal ed by the fi l ters magni tude
response). Thi s property preserves the wave shape of si gnal s i n the passband;
that i s, there i s no phase di storti on.
The functi ons fir1, fir2, firls, remez, fircls, fircls1, and firrcos al l
desi gn type I and I I l i near phase FI R fi l ters by defaul t. Both firls and remez
desi gn type I I I and I V l i near phase FI R fi l ters gi ven a 'hilbert' or
'differentiator' fl ag. cremez can desi gn any type of l i near phase fi l ter, and
nonl i near phase fi l ters as wel l .
Note Because the frequency response of a type I I fi l ter i s zero at the Nyqui st
frequency (hi gh frequency), fir1 does not desi gn type I I hi ghpass and
bandstop fi l ters. For odd-val ued n i n these cases, fir1 adds 1 to the order and
returns a type I fi l ter.
Linear Phase
Filter Type
Filter
Order Symmetry of Coefficients
Response H(f),
f = 0
Response H(f),
f = 1 (Nyquist)
Type I Even even: No restri cti on No restri cti on
Type I I Odd No restri cti on H(1) = 0
Type I I I Even odd: H(0) = 0 H(1) = 0
Type I V Odd H(0) = 0 No restri cti on
b k ( ) b n 2 k + ( ) k 1 = n 1 + , , , =
b k ( ) b n 2 k + ( ) k 1 = n 1 + , , , =
FIR Fi lter Desi gn
2-19
Windowing Method
Consi der the i deal , or bri ck wal l , di gi tal l owpass fi l ter wi th a cutoff frequency
of
0
rad/s. Thi s fi l ter has magni tude 1 at al l frequenci es wi th magni tude l ess
than
0
, and magni tude 0 at frequenci es wi th magni tude between
0
and . I ts
i mpul se response sequence h(n) i s
Thi s fi l ter i s not i mpl ementabl e si nce i ts i mpul se response i s i nfi ni te and
noncausal . To create a fi ni te-durati on i mpul se response, truncate i t by
appl yi ng a wi ndow. By retai ni ng the central secti on of i mpul se response i n thi s
truncati on, you obtai n a l i near phase FI R fi l ter. For exampl e, a l ength 51 fi l ter
wi th a l owpass cutoff frequency
0
of rad/s i s
b = 0.4*sinc(0.4*(-25:25));
The wi ndow appl i ed here i s a si mpl e rectangul ar wi ndow. By Parseval s
theorem, thi s i s the l ength 51 fi l ter that best approxi mates the i deal l owpass
fi l ter, i n the i ntegrated l east squares sense. The fol l owi ng commands di spl ay
the fi l ters frequency response.
[H,w] = freqz(b,1,512,2);
s.xunits = 'rad/sample';
s.yunits = 'squared';
s.plot = 'mag'; % Plot magnitude only.
freqzplot(H,w,s)
title('Truncated Sinc Lowpass FIR Filter');
h n ( )
1
2
------ H ( )e
j n
d

1
2
------ e
j n
d

-------si nc

0

-------n ( ) = = =
0.4
2 Fi lter Desi gn
2-20
Note the ri ngi ng and ri ppl es i n the response, especi al l y near the band edge.
Thi s Gi bbs effect does not vani sh as the fi l ter l ength i ncreases, but a
nonrectangul ar wi ndow reduces i ts magni tude. Mul ti pl i cati on by a wi ndow i n
the ti me domai n causes a convol uti on or smoothi ng i n the frequency domai n.
Appl y a l ength 51 Hammi ng wi ndow to the fi l ter.
b = 0.4*sinc(0.4*(-25:25));
b = b.*hamming(51)';
[H,w] = freqz(b,1,512,2);
s.xunits = 'rad/sample';
s.yunits = 'squared';
s.plot = 'mag';
freqzplot(H,w,s)
title('Hamming-Windowed Truncated Sinc LP FIR Filter');
0 0.05 0.1 0.15 0.2 0.25 0.3
0
0.2
0.4
0.6
0.8
1
1.2
1.4
Normalized Frequency ( rad/sample)
M
a
g
n
i
t
u
d
e

s
q
u
a
r
e
d
Truncated Sinc Lowpass FIR Filter
FIR Fi lter Desi gn
2-21
As you can see, thi s greatl y reduces the ri ngi ng. Thi s i mprovement i s at the
expense of transi ti on wi dth (the wi ndowed versi on takes l onger to ramp from
passband to stopband) and opti mal i ty (the wi ndowed versi on does not
mi ni mi ze the i ntegrated squared error).
The functi ons fir1 and fir2 are based on thi s wi ndowi ng process. Gi ven a
fi l ter order and descri pti on of an i deal desi red fi l ter, these functi ons return a
wi ndowed i nverse Fouri er transform of that i deal fi l ter. Both use a Hammi ng
wi ndow by defaul t, but they accept any wi ndow functi on. See Overvi ew on
page 4-2 for an overvi ew of wi ndows and thei r properti es.
Sta nda rd Ba nd FIR Filter Design: fir1
fir1 i mpl ements the cl assi cal method of wi ndowed l i near phase FI R di gi tal
fi l ter desi gn. I t resembl es the I I R fi l ter desi gn functi ons i n that i t i s formul ated
to desi gn fi l ters i n standard band confi gurati ons: l owpass, bandpass, hi ghpass,
and bandstop.
The statements
n = 50;
Wn = 0.4;
b = fir1(n,Wn);
0 0.05 0.1 0.15 0.2 0.25 0.3
0
0.2
0.4
0.6
0.8
1
1.2
1.4
Normalized Frequency ( rad/sample)
M
a
g
n
i
t
u
d
e

s
q
u
a
r
e
d
HammingWindowed Truncated Sinc LP FIR Filter
2 Fi lter Desi gn
2-22
create row vector b contai ni ng the coeffi ci ents of the order n
Hammi ng-wi ndowed fi l ter. Thi s i s a l owpass, l i near phase FI R fi l ter wi th cutoff
frequency Wn. Wn i s a number between 0 and 1, where 1 corresponds to the
Nyqui st frequency, hal f the sampl i ng frequency. (Unl i ke other methods, here
Wn corresponds to the 6 dB poi nt.) For a hi ghpass fi l ter, si mpl y append the
stri ng 'high' to the functi ons parameter l i st. For a bandpass or bandstop
fi l ter, speci fy Wn as a two-el ement vector contai ni ng the passband edge
frequenci es; append the stri ng 'stop' for the bandstop confi gurati on.
b = fir1(n,Wn,window) uses the wi ndow speci fi ed i n col umn vector window for
the desi gn. The vector window must be n+1 el ements l ong. I f you do not speci fy
a wi ndow, fir1 appl i es a Hammi ng wi ndow.
Ka iser W indow Order Estima tion. The kaiserord functi on esti mates the fi l ter
order, cutoff frequency, and Kai ser wi ndow beta parameter needed to meet a
gi ven set of speci fi cati ons. Gi ven a vector of frequency band edges and a
correspondi ng vector of magni tudes, as wel l as maxi mum al l owabl e ri ppl e,
kaiserord returns appropri ate i nput parameters for the fir1 functi on.
M ultiba nd FIR Filter Design: fir2
The fir2 functi on al so desi gns wi ndowed FI R fi l ters, but wi th an arbi trari l y
shaped pi ecewi se l i near frequency response. Thi s i s i n contrast to fir1, whi ch
onl y desi gns fi l ters i n standard l owpass, hi ghpass, bandpass, and bandstop
confi gurati ons.
The commands
n = 50;
f = [0 .4 .5 1];
m = [1 1 0 0];
b = fir2(n,f,m);
return row vector b contai ni ng the n+1 coeffi ci ents of the order n FI R fi l ter
whose frequency-magni tude characteri sti cs match those gi ven by vectors f
and m. f i s a vector of frequency poi nts rangi ng from 0 to 1, where 1 represents
the Nyqui st frequency. m i s a vector contai ni ng the desi red magni tude response
at the poi nts speci fi ed i n f. (The I I R counterpart of thi s functi on i s yulewalk,
whi ch al so desi gns fi l ters based on arbi trary pi ecewi se l i near magni tude
responses. See I I R Fi l ter Desi gn on page 2-5 for detai l s.)
FIR Fi lter Desi gn
2-23
Multiband FIR Filter Design with Transition Bands
The firls and remez functi ons provi de a more general means of speci fyi ng the
i deal desi red fi l ter than the fir1 and fir2 functi ons. These functi ons desi gn
Hi l bert transformers, di fferenti ators, and other fi l ters wi th odd symmetri c
coeffi ci ents (type I I I and type I V l i near phase). They al so l et you i ncl ude
transi ti on or dont care regi ons i n whi ch the error i s not mi ni mi zed, and
perform band dependent wei ghti ng of the mi ni mi zati on.
The firls functi on i s an extensi on of the fir1 and fir2 functi ons i n that i t
mi ni mi zes the i ntegral of the square of the error between the desi red frequency
response and the actual frequency response.
The remez functi on i mpl ements the Parks-McCl el l an al gori thm, whi ch uses
the Remez exchange al gori thm and Chebyshev approxi mati on theory to desi gn
fi l ters wi th opti mal fi ts between the desi red and actual frequency responses.
The fi l ters are opti mal i n the sense that they mi ni mi ze the maxi mum error
between the desi red frequency response and the actual frequency response;
they are someti mes cal l ed minimax fi l ters. Fi l ters desi gned i n thi s way exhi bi t
an equi ri ppl e behavi or i n thei r frequency response, and hence are al so known
as equiripple fi l ters. The Parks-McCl el l an FI R fi l ter desi gn al gori thm i s
perhaps the most popul ar and wi del y used FI R fi l ter desi gn methodol ogy.
The syntax for firls and remez i s the same; the onl y di fference i s thei r
mi ni mi zati on schemes. The next exampl e shows how fi l ters desi gned wi th
firls and remez refl ect these di fferent schemes.
Ba sic Configura tions
The defaul t mode of operati on of firls and remez i s to desi gn type I or type I I
l i near phase fi l ters, dependi ng on whether the order you desi re i s even or odd,
respecti vel y. A l owpass exampl e wi th approxi mate ampl i tude 1 from 0 to
0.4 Hz, and approxi mate ampl i tude 0 from 0.5 to 1.0 Hz i s
n = 20; % Filter order
f = [0 0.4 0.5 1]; % Frequency band edges
a = [1 1 0 0]; % Desired amplitudes
b = remez(n,f,a);
From 0.4 to 0.5 Hz, remez performs no error mi ni mi zati on; thi s i s a transi ti on
band or dont care regi on. A transi ti on band mi ni mi zes the error more i n the
bands that you do care about, at the expense of a sl ower transi ti on rate. I n thi s
2 Fi lter Desi gn
2-24
way, these types of fi l ters have an i nherent trade-off si mi l ar to FI R desi gn by
wi ndowi ng.
To compare l east squares to equi ri ppl e fi l ter desi gn, use firls to create a
si mi l ar fi l ter. Type
bb = firls(n,f,a);
and compare thei r frequency responses.
[H,w] = freqz(b);
[HH,w] = freqz(bb);
plot(w/pi,abs(H),w/pi,abs(HH),'--'), grid
You can see that the fi l ter desi gned wi th remez exhi bi ts equi ri ppl e behavi or.
Al so note that the firls fi l ter has a better response over most of the passband
and stopband, but at the band edges (f = 0.4 and f = 0.5), the response i s
further away from the i deal than the remez fi l ter. Thi s shows that the remez
fi l ters maximum error over the passband and stopband i s smal l er and, i n fact,
i t i s the smal l est possi bl e for thi s band edge confi gurati on and fi l ter l ength.
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
0
0.2
0.4
0.6
0.8
1
1.2
1.4
FIR Fi lter Desi gn
2-25
Thi nk of frequency bands as l i nes over short frequency i nterval s. remez and
firls use thi s scheme to represent any pi ecewi se l i near desi red functi on wi th
any transi ti on bands. firls and remez desi gn l owpass, hi ghpass, bandpass,
and bandstop fi l ters; a bandpass exampl e i s
f = [0 0.3 0.4 0.7 0.8 1]; % Band edges in pairs
a = [0 0 1 1 0 0]; % Bandpass filter amplitude
Techni cal l y, these f and a vectors defi ne fi ve bands:
Two stopbands, from 0.0 to 0.3 and from 0.8 to 1.0
A passband from 0.4 to 0.7
Two transi ti on bands, from 0.3 to 0.4 and from 0.7 to 0.8
Exampl e hi ghpass and bandstop fi l ters are
f = [0 0.7 0.8 1]; % Band edges in pairs
a = [0 0 1 1]; % Highpass filter amplitude
f = [0 0.3 0.4 0.5 0.8 1]; % Band edges in pairs
a = [1 1 0 0 1 1]; % Bandstop filter amplitude
An exampl e mul ti band bandpass fi l ter i s
f = [0 0.1 0.15 0.25 0.3 0.4 0.45 0.55 0.6 0.7 0.75 0.85 0.9 1];
a = [1 1 0 0 1 1 0 0 1 1 0 0 1 1];
Another possi bi l i ty i s a fi l ter that has as a transi ti on regi on the l i ne connecti ng
the passband wi th the stopband; thi s can hel p control runaway magni tude
response i n wi de transi ti on regi ons.
f = [0 0.4 0.42 0.48 0.5 1];
a = [1 1 0.8 0.2 0 0]; % Passband,linear transition,stopband
2 Fi lter Desi gn
2-26
The Weight Vector
Both firls and remez al l ow you to pl ace more or l ess emphasi s on mi ni mi zi ng
the error i n certai n frequency bands rel ati ve to others. To do thi s, speci fy a
wei ght vector fol l owi ng the frequency and ampl i tude vectors. An exampl e
l owpass equi ri ppl e fi l ter wi th 10 ti mes l ess ri ppl e i n the stopband than the
passband i s
n = 20; % Filter order
f = [0 0.4 0.5 1]; % Frequency band edges
a = [1 1 0 0]; % Desired amplitudes
w = [1 10]; % Weight vector
b = remez(n,f,a,w);
A l egal wei ght vector i s al ways hal f the l ength of the f and a vectors; there must
be exactl y one wei ght per band.
Anti- Symmetric Filters / Hilber t Tra nsfor mers
When cal l ed wi th a trai l i ng 'h' or 'Hilbert' opti on, remez and firls desi gn
FI R fi l ters wi th odd symmetry, that i s, type I I I (for even order) or type I V (for
odd order) l i near phase fi l ters. An i deal Hi l bert transformer has thi s
anti -symmetry property and an ampl i tude of 1 across the enti re frequency
range. Try the fol l owi ng approxi mate Hi l bert transformers.
b = remez(21,[0.05 1],[1 1],'h'); % Highpass Hilbert
bb = remez(20,[0.05 0.95],[1 1],'h'); % Bandpass Hilbert
0 0.25 0.5 0.75 1
0
0.2
0.4
0.6
0.8
1
Frequency (Normalized)

Bandpass Hilbert
0 0.25 0.5 0.75 1
0
0.2
0.4
0.6
0.8
1
Frequency (Normalized)
Highpass Hilbert
FIR Fi lter Desi gn
2-27
You can fi nd the del ayed Hi l bert transform of a si gnal x by passi ng i t through
these fi l ters.
fs = 1000; % Sampling frequency
t = (0:1/fs:2)'; % Two second time vector
x = sin(2*pi*300*t); % 300 Hz sine wave example signal
xh = filter(bb,1,x); % Hilbert transform of x
The anal yti c si gnal correspondi ng to x i s the compl ex si gnal that has x as i ts
real part and the Hi l bert transform of x as i ts i magi nary part. For thi s FI R
method (an al ternati ve to the hilbert functi on), you must del ay x by hal f the
fi l ter order to create the anal yti c si gnal .
xd = [zeros(10,1); x(1:length(x)-10)]; % Delay 10 samples
xa = xd + j*xh; % Analytic signal
Thi s method does not work di rectl y for fi l ters of odd order, whi ch requi re a
noni nteger del ay. I n thi s case, the hilbert functi on, descri bed i n Speci al i zed
Transforms on page 4-36, esti mates the anal yti c si gnal . Al ternati vel y, use the
resample functi on to del ay the si gnal by a noni nteger number of sampl es.
Dif ferentia tors
Di fferenti ati on of a si gnal i n the ti me domai n i s equi val ent to mul ti pl i cati on of
the si gnal s Fouri er transform by an i magi nary ramp functi on. That i s, to
di fferenti ate a si gnal , pass i t through a fi l ter that has a response H() = j.
Approxi mate the i deal di fferenti ator (wi th a del ay) usi ng remez or firls wi th
a 'd' or 'differentiator' opti on.
b = remez(21,[0 1],[0 pi*fs],'d');
To obtai n the correct deri vati ve, scal e by pi*fs rad/s, where fs i s the sampl i ng
frequency i n hertz. For a type I I I fi l ter, the di fferenti ati on band shoul d stop
short of the Nyqui st frequency, and the ampl i tude vector must refl ect that
change to ensure the correct sl ope.
bb = remez(20,[0 0.9],[0 0.9*pi*fs],'d');
I n the 'd' mode, remez wei ghts the error by 1/ i n nonzero ampl i tude bands to
mi ni mi ze the maxi mum relative error. firls wei ghts the error by (1/)
2
i n
nonzero ampl i tude bands i n the 'd' mode.
2 Fi lter Desi gn
2-28
The fol l owi ng pl ots show the magni tude response for the di fferenti ators above.
Constrained Least Squares FIR Filter Design
The Constrai ned Least Squares (CLS) FI R fi l ter desi gn functi ons i mpl ement a
techni que that enabl es you to desi gn FI R fi l ters wi thout expl i ci tl y defi ni ng the
transi ti on bands for the magni tude response. The abi l i ty to omi t the
speci fi cati on of transi ti on bands i s useful i n several si tuati ons. For exampl e, i t
may not be cl ear where a ri gi dl y defi ned transi ti on band shoul d appear i f noi se
and si gnal i nformati on appear together i n the same frequency band. Si mi l arl y,
i t may make sense to omi t the speci fi cati on of transi ti on bands i f they appear
onl y to control the resul ts of Gi bbs phenomena that appear i n the fi l ters
response. See Sel esni ck, Lang, and Burrus [2] for di scussi on of thi s method.
I nstead of defi ni ng passbands, stopbands, and transi ti on regi ons, the CLS
method accepts a cutoff frequency (for the hi ghpass, l owpass, bandpass, or
bandstop cases), or passband and stopband edges (for mul ti band cases), for the
desi red response. I n thi s way, the CLS method defi nes transi ti on regi ons
i mpl i ci tl y, rather than expl i ci tl y.
The key feature of the CLS method i s that i t enabl es you to defi ne upper and
l ower threshol ds that contai n the maxi mum al l owabl e ri ppl e i n the magni tude
response. Gi ven thi s constrai nt, the techni que appl i es the l east square error
mi ni mi zati on techni que over the frequency range of the fi l ters response,
i nstead of over speci fi c bands. The error mi ni mi zati on i ncl udes any areas of
0 100 200 300 400 500
0
500
1000
1500
2000
2500
3000
3500
Differentiator, odd order
Frequency (Normalized)
0 100 200 300 400 500
0
500
1000
1500
2000
2500
3000
3500
Differentiator, even order
Frequency (Normalized)
FIR Fi lter Desi gn
2-29
di sconti nui ty i n the i deal , bri ck wal l response. An addi ti onal benefi t i s that
the techni que enabl es you to speci fy arbi trari l y smal l peaks resul ti ng from
Gi bbs phenomena.
There are two tool box functi ons that i mpl ement thi s desi gn techni que.
For detai l s on the cal l i ng syntax for these functi ons, see thei r reference
descri pti ons i n Chapter 7, Functi on Reference.
Ba sic Low pa ss a nd Highpa ss CLS Filter Design
The most basi c of the CLS desi gn functi ons, fircls1, uses thi s techni que to
desi gn l owpass and hi ghpass FI R fi l ters. As an exampl e, consi der desi gni ng a
fi l ter wi th order 61 i mpul se response and cutoff frequency of 0.3 (normal i zed).
Further, defi ne the upper and l ower bounds that constrai n the desi gn process
as:
Maxi mum passband devi ati on from 1 (passband ri ppl e) of 0.02.
Maxi mum stopband devi ati on from 0 (stopband ri ppl e) of 0.008.
To approach thi s desi gn probl em usi ng fircls1, use the fol l owi ng commands.
n = 61;
wo = 0.3;
dp = 0.02;
ds = 0.008;
h = fircls1(n,wo,dp,ds,'plot');
Description Function
Constrai ned l east square mul ti band FI R fi l ter desi gn fircls
Constrai ned l east square fi l ter desi gn for l owpass and
hi ghpass l i near phase fi l ters
fircls1
0
ds = 0.008
1
dp = 0.02
2 Fi lter Desi gn
2-30
M ultiba nd CLS Filter Design
fircls uses the same techni que to desi gn FI R fi l ters wi th a desi red pi ecewi se
constant magni tude response. I n thi s case, you can speci fy a vector of band
edges and a correspondi ng vector of band ampl i tudes. I n addi ti on, you can
speci fy the maxi mum amount of ri ppl e for each band.
For exampl e, assume the speci fi cati ons for a fi l ter cal l for:
From 0 to 0.3 (normal i zed): ampl i tude 0, upper bound 0.005, l ower
bound -0.005
From 0.3 to 0.5: ampl i tude 0.5, upper bound 0.51, l ower bound 0.49
From 0.5 to 0.7: ampl i tude 0, upper bound 0.03, l ower bound -0.03
From 0.7 to 0.9: ampl i tude 1, upper bound 1.02, l ower bound 0.98
From 0.9 to 1: ampl i tude 0, upper bound 0.05, l ower bound -0.05
Desi gn a CLS fi l ter wi th i mpul se response order 129 that meets these
speci fi cati ons.
n = 129;
f = [0 0.3 0.5 0.7 0.9 1];
a = [0 0.5 0 1 0];
up = [0.005 0.51 0.03 1.02 0.05];
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
-0.2
0
0.2
0.4
0.6
0.8
1
FIR Fi lter Desi gn
2-31
lo = [-0.005 0.49 -0.03 0.98 -0.05];
h = fircls(n,f,a,up,lo,'plot');
Weighted CLS Filter Design
Wei ghted CLS fi l ter desi gn l ets you desi gn l owpass or hi ghpass FI R fi l ters wi th
rel ati ve wei ghti ng of the error mi ni mi zati on i n each band. The fircls1
functi on enabl es you to speci fy the passband and stopband edges for the l east
squares wei ghti ng functi on, as wel l as a constant k that speci fi es the rati o of
the stopband to passband wei ghti ng.
For exampl e, consi der speci fi cati ons that cal l for an FI R fi l ter wi th i mpul se
response order of 55 and cutoff frequency of 0.3 (normal i zed). Al so assume
maxi mum al l owabl e passband ri ppl e of 0.02 and maxi mum al l owabl e stopband
ri ppl e of 0.004. I n addi ti on, add wei ghti ng requi rements:
Passband edge for the wei ght functi on of 0.28 (normal i zed)
Stopband edge for the wei ght functi on of 0.32
Wei ght error mi ni mi zati on 10 ti mes as much i n the stopband as i n the
passband
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
-0.2
0
0.2
0.4
0.6
0.8
1
1.2
2 Fi lter Desi gn
2-32
To approach thi s usi ng fircls1, type
n = 55;
wo = 0.3;
dp = 0.02;
ds = 0.004;
wp = 0.28;
ws = 0.32;
k = 10;
h = fircls1(n,wo,dp,ds,wp,ws,k,'plot');
Arbitrary-Response Filter Design
The cremez fi l ter desi gn functi on provi des a tool for desi gni ng FI R fi l ters wi th
arbi trary compl ex responses. I t di ffers from the other fi l ter desi gn functi ons i n
how the frequency response of the fi l ter i s speci fi ed: i t accepts the name of a
functi on whi ch returns the fi l ter response cal cul ated over a gri d of frequenci es.
Thi s capabi l i ty makes cremez a hi ghl y versati l e and powerful techni que for
fi l ter desi gn.
Thi s desi gn techni que may be used to produce nonl i near-phase FI R fi l ters,
asymmetri c frequency-response fi l ters (wi th compl ex coeffi ci ents), or more
symmetri c fi l ters wi th custom frequency responses.
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
-0.2
0
0.2
0.4
0.6
0.8
1
FIR Fi lter Desi gn
2-33
The desi gn al gori thm opti mi zes the Chebyshev (or mi ni max) error usi ng an
extended Remez-exchange al gori thm for an i ni ti al esti mate. I f thi s exchange
method fai l s to obtai n the opti mal fi l ter, the al gori thm swi tches to an
ascent-descent al gori thm that takes over to fi ni sh the convergence to the
opti mal sol uti on.
M ultiba nd Filter Design
Consi der a mul ti band fi l ter wi th the fol l owi ng speci al frequency-domai n
characteri sti cs.
A l i near-phase mul ti band fi l ter may be desi gned usi ng the predefi ned
frequency-response functi on multiband, as fol l ows.
b = cremez(38, [-1 -0.5 -0.4 0.3 0.4 0.8], ...
{'multiband', [5 1 2 2 2 1]}, [1 10 5]);
For the speci fi c case of a mul ti band fi l ter, we can use a shorthand fi l ter desi gn
notati on si mi l ar to the syntax for remez.
b = cremez(38,[-1 -0.5 -0.4 0.3 0.4 0.8], ...
[5 1 2 2 2 1], [1 10 5]);
As wi th remez, a vector of band edges i s passed to cremez. Thi s vector defi nes
the frequency bands over whi ch opti mi zati on i s performed; note that there are
two transi ti on bands, from -0.5 to -0.4 and from 0.3 to 0.4.
Band Amplitude Optimization
Weighting
[-1 -0.5] [5 1] 1
[-0.4 +0.3] [2 2] 10
[+0.4 +0.8] [2 1] 5
2 Fi lter Desi gn
2-34
I n ei ther case, the frequency response i s obtai ned and pl otted usi ng l i near
scal e.
[h,w] = freqz(b,1,512,'whole');
plot(w/pi-1,fftshift(abs(h))); grid;
xlabel('Normalized Frequency');
ylabel('Magnitude Response');
Note that the frequency response has been cal cul ated over the enti re
normal i zed frequency range [-1 +1] by passi ng the opti on 'whole' to freqz. I n
order to pl ot the negati ve frequency i nformati on i n a natural way, the response
has been wrapped, just as FFT data i s, usi ng fftshift.
The fi l ter response for thi s mul ti band fi l ter i s compl ex, whi ch i s expected
because of the asymmetry i n the frequency domai n.
-1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1
1
1.5
2
2.5
3
3.5
4
4.5
5
Normalized Frequency
M
a
g
n
i
t
u
d
e

R
e
s
p
o
n
s
e
FIR Fi lter Desi gn
2-35
Filter Design w ith Reduced Dela y
Consi der the desi gn of a 62-tap l owpass fi l ter wi th a hal f-Nyqui st cutoff. I f we
speci fy a negati ve offset val ue to the lowpass fi l ter desi gn functi on, the group
del ay offset for the desi gn i s si gni fi cantl y l ess than that obtai ned for a standard
l i near-phase desi gn. Thi s fi l ter desi gn may be computed as fol l ows.
b = cremez(61,[0 0.5 0.55 1],{'lowpass',-16});
The resul ti ng magni tude response i s
[h,w] = freqz(b,1,512,'whole');
plot(w/pi-1,fftshift(abs(h))); grid;
xlabel('Normalized Frequency');
ylabel('Magnitude Response');
0 5 10 15 20 25 30 35 40
-0.5
0
0.5
1
1.5
2
2.5
R
e
a
l

P
a
r
t
0 5 10 15 20 25 30 35 40
-0.2
0
0.2
I
m
a
g

P
a
r
t
2 Fi lter Desi gn
2-36
The group del ay of the fi l ter reveal s that the offset has been reduced from N/2
to N/2-16 (i .e., from 30.5 to 14.5). Now, however, the group del ay i s no l onger
fl at i n the passband regi on (pl otted over the normal i zed frequency range 0 to
0.5 for cl ari ty).
-1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1
0
0.2
0.4
0.6
0.8
1
1.2
1.4
Normalized Frequency
M
a
g
n
i
t
u
d
e

R
e
s
p
o
n
s
e
0 0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4 0.45 0.5
12
13
14
15
16
17
Normalized frequency (Nyquist == 1)
G
r
o
u
p

d
e
l
a
y

(
i
n

s
a
m
p
l
e
s
)
FIR Fi lter Desi gn
2-37
I f we compare thi s nonl i near-phase fi l ter to a l i near-phase fi l ter that has
exactl y 14.5 sampl es of group del ay, the resul ti ng fi l ter i s of order 2*14.5, or 29.
Usi ng b = cremez(29,[0 0.5 0.55 1],'lowpass'), the passband and
stopband ri ppl e i s much greater for the order 29 fi l ter. These compari sons can
assi st you i n deci di ng whi ch fi l ter i s more appropri ate for a speci fi c appl i cati on.
2 Fi lter Desi gn
2-38
Special Topics in IIR Filter Design
The cl assi c I I R fi l ter desi gn techni que fi nds an anal og l owpass fi l ter wi th cutoff
frequency of 1, transl ates thi s prototype fi l ter to the desi red band
confi gurati on, then transforms the fi l ter to the di gi tal domai n. The tool box
provi des functi ons for each step of thi s process.
The butter, cheby1, cheby2, and ellip functi ons are suffi ci ent for many
desi gn probl ems, and the l ower l evel functi ons are general l y not needed. But i f
you do have an appl i cati on where you need to transform the band edges of an
anal og fi l ter, or di screti ze a rati onal transfer functi on, thi s secti on descri bes
the tool s wi th whi ch to do so.
Classical IIR Filter Design
Analog Lowpass Prototype Creation Frequency Transformation Discretization
buttap
ellipap
cheb1ap
cheb2ap
besselap lp2lp
lp2bp
lp2hp
lp2bs
bilinear
impinvar
butter cheby1 cheby2 ellip besself
Minimum Order Computation for Classical IIR Filter Design
buttord cheb1ord cheb2ord ellipord
Complete Design
Speci al Topi cs i n IIR Fi lter Desi gn
2-39
Analog Prototype Design
Thi s tool box provi des a number of functi ons to create l owpass anal og prototype
fi l ters wi th cutoff frequency of 1, the fi rst step i n the cl assi cal approach to I I R
fi l ter desi gn. The tabl e bel ow summari zes the anal og prototype desi gn
functi ons for each supported fi l ter type; pl ots for each type are shown i n I I R
Fi l ter Desi gn on page 2-5.
Frequency Transformation
The second step i n the anal og prototypi ng desi gn techni que i s the frequency
transformati on of a l owpass prototype. The tool box provi des a set of functi ons
to transform anal og l owpass prototypes (wi th cutoff frequency of 1 rad/s) i nto
bandpass, hi ghpass, bandstop, and l owpass fi l ters of the desi red cutoff
frequency.
Filter Type Analog Prototype Function
Bessel [z,p,k] = besselap(n)
Butterworth [z,p,k] = buttap(n)
Chebyshev Type I [z,p,k] = cheb1ap(n,Rp)
Chebyshev Type I I [z,p,k] = cheb2ap(n,Rs)
El l i pti c [z,p,k] = ellipap(n,Rp,Rs)
2 Fi lter Desi gn
2-40
As shown, al l of the frequency transformati on functi ons can accept two l i near
system model s: transfer functi on and state-space form. For the bandpass and
bandstop cases
and
where
1
i s the l ower band edge and
2
i s the upper band edge.
The frequency transformati on functi ons perform frequency vari abl e
substi tuti on. I n the case of lp2bp and lp2bs, thi s i s a second-order
substi tuti on, so the output fi l ter i s twi ce the order of the i nput. For lp2lp and
lp2hp, the output fi l ter i s the same order as the i nput.
To begi n desi gni ng an order 10 bandpass Chebyshev Type I fi l ter wi th a val ue
of 3 dB for passband ri ppl e, enter
[z,p,k] = cheb1ap(5,3);
Freq. Transformation Transformation Function
Lowpass to l owpass [numt,dent] = lp2lp(num,den,Wo)
[At,Bt,Ct,Dt] = lp2lp(A,B,C,D,Wo)
Lowpass to hi ghpass [numt,dent] = lp2hp(num,den,Wo)
[At,Bt,Ct,Dt] = lp2hp(A,B,C,D,Wo)
Lowpass to bandpass [numt,dent] = lp2bp(num,den,Wo,Bw)
[At,Bt,Ct,Dt] = lp2bp(A,B,C,D,Wo,Bw)
Lowpass to bandstop [numt,dent] = lp2bs(num,den,Wo,Bw)
[At,Bt,Ct,Dt] = lp2bs(A,B,C,D,Wo,Bw)
s s
0
=
s

0
s
------- =
s

0
B

-------
s
0
( )
2
1 +
s
0

------------------------------- =
s
B

0
-------
s
0

s
0
( )
2
1 +
------------------------------- =

0

1

2
=
B


2

1
=
Speci al Topi cs i n IIR Fi lter Desi gn
2-41
Outputs z, p, and k contai n the zeros, pol es, and gai n of a l owpass anal og fi l ter
wi th cutoff frequency
c
equal to 1 rad/s. Use the lp2bp functi on to transform
thi s l owpass prototype to a bandpass anal og fi l ter wi th band edges
and . Fi rst, convert the fi l ter to state-space form so the lp2bp functi on
can accept i t.
[A,B,C,D] = zp2ss(z,p,k); % Convert to state-space form.
Now, fi nd the bandwi dth and center frequency, and cal l lp2bp.
u1 = 0.1*2*pi; u2 = 0.5*2*pi; % In radians per second
Bw = u2-u1;
Wo = sqrt(u1*u2);
[At,Bt,Ct,Dt] = lp2bp(A,B,C,D,Wo,Bw);
Fi nal l y, cal cul ate the frequency response and pl ot i ts magni tude.
[b,a] = ss2tf(At,Bt,Ct,Dt); % Convert to TF form.
w = linspace(0.01,1,500)*2*pi; % Generate frequency vector.
h = freqs(b,a,w); % Compute frequency response.
semilogy(w/2/pi,abs(h)), grid % Plot log magnitude vs. freq.
xlabel('Frequency (Hz)');
.

1
5 =

2
=
0 0.2 0.4 0.6 0.8 1
10
7
10
6
10
5
10
4
10
3
10
2
10
1
10
0
Frequency (Hz)
2 Fi lter Desi gn
2-42
Filter Discretization
The thi rd step i n the anal og prototypi ng techni que i s the transformati on of the
fi l ter to the di screte-ti me domai n. The tool box provi des two methods for thi s:
the i mpul se i nvari ant and bi l i near transformati ons. The fi l ter desi gn functi ons
butter, cheby1, cheby2, and ellip use the bi l i near transformati on for
di screti zati on i n thi s step.
Impulse Inva ria nce
The tool box functi on impinvar creates a di gi tal fi l ter whose i mpul se response
i s the sampl es of the conti nuous i mpul se response of an anal og fi l ter. Thi s
functi on works onl y on fi l ters i n transfer functi on form. For best resul ts, the
anal og fi l ter shoul d have negl i gi bl e frequency content above hal f the sampl i ng
frequency, because such hi gh frequency content i s al i ased i nto l ower bands
upon sampl i ng. I mpul se i nvari ance works for some l owpass and bandpass
fi l ters, but i s not appropri ate for hi ghpass and bandstop fi l ters.
Desi gn a Chebyshev Type I fi l ter and pl ot i ts frequency response.
[bz,az] = impinvar(b,a,2);
[H,w] = freqz(bz,az);
freqzplot(H,w)
Analog to Digital
Transformation
Transformation Function
I mpul se i nvari ance [numd,dend] = impinvar(num,den,fs)
Bi l i near transform [zd,pd,kd] = bilinear(z,p,k,fs,Fp)
[numd,dend] = bilinear(num,den,fs,Fp)
[Ad,Bd,Cd,Dd] = bilinear(At,Bt,Ct,Dt,fs,Fp)
Speci al Topi cs i n IIR Fi lter Desi gn
2-43
I mpul se i nvari ance retai ns the cutoff frequenci es of 0.1 Hz and 0.5 Hz.
Bilinea r Tra nsfor ma tion
The bi l i near transformati on i s a nonl i near mappi ng of the conti nuous domai n
to the di screte domai n; i t maps the s-pl ane i nto the z-pl ane by
Bi l i near transformati on maps the -axi s of the conti nuous domai n to the uni t
ci rcl e of the di screte domai n accordi ng to
The tool box functi on bilinear i mpl ements thi s operati on, where the frequency
warpi ng constant k i s equal to twi ce the sampl i ng frequency (2*fs) by defaul t,
and equal to i f you gi ve bilinear a trai l i ng argument that
represents a match frequency Fp. I f a match frequency Fp (i n hertz) i s
present, bilinear maps the frequency (i n rad/s) to the same
frequency i n the di screte domai n, normal i zed to the sampl i ng rate:
(i n rad/sampl e).
0 0.2 0.4 0.6 0.8 1
800
600
400
200
0
200
Normalized Frequency ( rad/sample)
P
h
a
s
e

(
d
e
g
r
e
e
s
)
0 0.2 0.4 0.6 0.8 1
150
100
50
0
Normalized Frequency ( rad/sample)
M
a
g
n
i
t
u
d
e

(
d
B
)
H z ( ) H s ( )
s k
z 1
z 1 +
------------ =
=
j
2tan
1

k
----
,
_
=
2f
p
f
p
f
s
( ) tan
2f
p
=
2f
p
f
s
=
2 Fi lter Desi gn
2-44
The bilinear functi on can perform thi s transformati on on three di fferent
l i near system representati ons: zero-pol e-gai n, transfer functi on, and
state-space form. Try cal l i ng bilinear wi th the state-space matri ces that
descri be the Chebyshev Type I fi l ter from the previ ous secti on, usi ng a
sampl i ng frequency of 2 Hz, and retai ni ng the l ower band edge of 0.1 Hz.
[Ad,Bd,Cd,Dd] = bilinear(At,Bt,Ct,Dt,2,0.1);
The frequency response of the resul ti ng di gi tal fi l ter i s
[bz,az] = ss2tf(Ad,Bd,Cd,Dd); % convert to TF
freqz(bz,az)
The l ower band edge i s at 0.1 Hz as expected. Noti ce, however, that the upper
band edge i s sl i ghtl y l ess than 0.5 Hz, al though i n the anal og domai n i t was
exactl y 0.5 Hz. Thi s i l l ustrates the nonl i near nature of the bi l i near
transformati on. To counteract thi s nonl i neari ty, i t i s necessary to create anal og
domai n fi l ters wi th prewarped band edges, whi ch map to the correct l ocati ons
upon bi l i near transformati on. Here the prewarped frequenci es u1 and u2
generate Bw and Wo for the lp2bp functi on.
fs = 2; % Sampling frequency (hertz)
u1 = 2*fs*tan(0.1*(2*pi/fs)/2); % Lower band edge (rad/s)
u2 = 2*fs*tan(0.5*(2*pi/fs)/2); % Upper band edge (rad/s)
Bw = u2 - u1; % Bandwidth
Wo = sqrt(u1*u2); % Center frequency
[At,Bt,Ct,Dt] = lp2bp(A,B,C,D,Wo,Bw);
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
-1000
-500
0
500
Normalized frequency (Nyquist == 1)
P
h
a
s
e

(
d
e
g
r
e
e
s
)
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
-300
-200
-100
0
Normalized frequency (Nyquist == 1)
M
a
g
n
i
t
u
d
e

R
e
s
p
o
n
s
e

(
d
B
)
Speci al Topi cs i n IIR Fi lter Desi gn
2-45
A di gi tal bandpass fi l ter wi th correct band edges 0.1 and 0.5 ti mes the Nyqui st
frequency i s
[Ad,Bd,Cd,Dd] = bilinear(At,Bt,Ct,Dt,fs);
The exampl e bandpass fi l ters from the l ast two secti ons coul d al so be created
i n one statement usi ng the compl ete I I R desi gn functi on cheby1. For i nstance,
an anal og versi on of the exampl e Chebyshev fi l ter i s
[b,a] = cheby1(5,3,[0.1 0.5]*2*pi,'s');
Note that the band edges are i n rad/s for anal og fi l ters, whereas for the di gi tal
case, frequency i s normal i zed.
[bz,az] = cheby1(5,3,[0.1 0.5]);
Al l of the compl ete desi gn functi ons cal l bilinear i nternal l y. They prewarp the
band edges as needed to obtai n the correct di gi tal fi l ter. See Chapter 7,
Functi on Reference, for more on these functi ons.
2 Fi lter Desi gn
2-46
Selected Bibliography
[1] Karam, L.J., and J.H. McCl el l an. Compl ex Chebyshev Approxi mati on for
FI R Fi l ter Desi gn. I EEE Trans. on Circuits and Systems I I . March 1995.
[2] Sel esni ck, I .W., and C.S. Burrus. General i zed Di gi tal Butterworth Fi l ter
Desi gn. Proceedings of the I EEE I nt. Conf. Acoust., Speech, Signal Processing.
Vol . 3 (May 1996).
[3] Sel esni ck, I .W., M. Lang, and C.S. Burrus. Constrai ned Least Square
Desi gn of FI R Fi l ters wi thout Speci fi ed Transi ti on Bands. Proceedings of the
I EEE I nt. Conf. Acoust., Speech, Signal Processing. Vol . 2 (May 1995).
Pgs. 1260-1263.

3
Stati sti cal Si gnal
Processi ng
Overview . . . . . . . . . . . . . . . . . . . . . 3-2
Correlation and Covariance . . . . . . . . . . . . . 3-3
Bi as and Normal i zati on . . . . . . . . . . . . . . . . 3-4
Mul ti pl e Channel s . . . . . . . . . . . . . . . . . . 3-5
Spectral Analysis . . . . . . . . . . . . . . . . . . 3-6
Spectral Esti mati on Method Overvi ew . . . . . . . . . . 3-8
Nonparametri c Methods . . . . . . . . . . . . . . . . 3-10
Parametri c Methods . . . . . . . . . . . . . . . . . 3-30
Selected Bibliography . . . . . . . . . . . . . . . 3-39
3 Stati sti cal Si gnal Processi ng
3-2
Overview
The Si gnal Processi ng Tool box provi des tool s for esti mati ng i mportant
functi ons of random si gnal s. I n parti cul ar, there are tool s to esti mate
correl ati on and covari ance sequences and spectral densi ty functi ons of di screte
si gnal s. The fol l owi ng secti ons expl ai n the correl ati on and covari ance functi ons
and di scuss the mathemati cal l y rel ated functi ons for esti mati ng the power
spectrum:
Correl ati on and Covari ance
Spectral Anal ysi s
Sel ected Bi bl i ography
C orrelati on and C ovari ance
3-3
Correlation and Covariance
The functi ons xcorr and xcov esti mate the cross-correl ati on and
cross-covari ance sequences of random processes. They al so handl e
autocorrel ati on and autocovari ance as speci al cases.
The true cross-correl ati on sequence i s a stati sti cal quanti ty defi ned as
where x
n
and y
n
are stati onary random processes, , and E{} i s the
expected val ue operator. The covari ance sequence i s the mean-removed
cross-correl ati on sequence
or, i n terms of the cross-correl ati on,
I n practi ce, you must esti mate these sequences, because i t i s possi bl e to access
onl y a fi ni te segment of the i nfi ni te-l ength random process. A common esti mate
based on N sampl es of x
n
and y
n
i s the determi ni sti c cross-correl ati on sequence
(al so cal l ed the ti me-ambi gui ty functi on)
where we assume for thi s di scussi on that x
n
and y
n
are i ndexed from 0 to N-1,
and from -(N-1) to N-1. The xcorr functi on eval uates thi s sum wi th an
effi ci ent FFT-based al gori thm, gi ven i nputs x
n
and y
n
stored i n l ength N
vectors x and y. I ts operati on i s equi val ent to convol uti on wi th one of the two
subsequences reversed i n ti me.
For exampl e,
x = [1 1 1 1 1]';
y = x;
R
xy
m ( ) E{x
n m +
y
*
n
} E{x
n
y
*
n m
} = =
n < <
C
xy
m ( ) E{ x
n m +

x
( ) y
n

y
( )
*
} =
C
xy
m ( ) R
xy
m ( )
x

*
y
=
R

xy m ( )
x
n m +
y
n
*
n 0 =
N m 1

m 0
R

yx
*
m ( ) m 0 <

'

=
R

xy m ( )
3 Stati sti cal Si gnal Processi ng
3-4
xyc = xcorr(x,y)
xyc =
1.0000
2.0000
3.0000
4.0000
5.0000
4.0000
3.0000
2.0000
1.0000
Noti ce that the resul ti ng sequence l ength i s one l ess than twi ce the l ength of
the i nput sequence. Thus, the Nth el ement i s the correl ati on at l ag 0. Al so
noti ce the tri angul ar pul se of the output that resul ts when convol vi ng two
square pul ses.
The xcov functi on esti mates autocovari ance and cross-covari ance sequences.
Thi s functi on has the same opti ons and eval uates the same sum as xcorr, but
fi rst removes the means of x and y.
Bias and Normalization
An esti mate of a quanti ty i s biased i f i ts expected val ue i s not equal to the
quanti ty i t esti mates. The expected val ue of the output of xcorr i s
xcorr provi des the unbi ased esti mate, di vi di ng by N-| m| , when you speci fy an
'unbiased' fl ag after the i nput sequences.
xcorr(x,y,'unbiased')
Al though thi s esti mate i s unbi ased, the end poi nts (near -(N-1) and N-1) suffer
from l arge vari ance because xcorr computes them usi ng onl y a few data poi nts.
A possi bl e trade-off i s to si mpl y di vi de by N usi ng the 'biased' fl ag.
xcorr(x,y,'biased')
E{R

xy m ( )} E{x
n m +
y
*
n
}
n 0 =
N m 1

N m ( )R
xy
m ( ) = =
C orrelati on and C ovari ance
3-5
Wi th thi s scheme, onl y the sampl e of the correl ati on at zero l ag (the Nth output
el ement) i s unbi ased. Thi s esti mate i s often more desi rabl e than the unbi ased
one because i t avoi ds random l arge vari ati ons at the end poi nts of the
correl ati on sequence.
xcorr provi des one other normal i zati on scheme. The syntax
xcorr(x,y,'coeff')
di vi des the output by norm(x)*norm(y) so that, for autocorrel ati ons, the
sampl e at zero l ag i s 1.
Multiple Channels
For a mul ti channel si gnal , xcorr and xcov esti mate the autocorrel ati on and
cross-correl ati on and covari ance sequences for al l of the channel s at once. I f S
i s an M-by-N si gnal matri x representi ng N channel s i n i ts col umns, xcorr(S)
returns a (2M-1)-by-N
2
matri x wi th the autocorrel ati ons and cross-correl ati ons
of the channel s of S i n i ts N
2
col umns. I f S i s a three-channel si gnal
S = [s1 s2 s3]
then the resul t of xcorr(S) i s organi zed as
R = [Rs1s1 Rs1s2 Rs1s3 Rs2s1 Rs2s2 Rs2s3 Rs3s1 Rs3s2 Rs3s3]
Two rel ated functi ons, cov and corrcoef, are avai l abl e i n the standard
MATLAB envi ronment. They esti mate covari ance and normal i zed covari ance
respecti vel y between the di fferent channel s at l ag 0 and arrange them i n a
square matri x.
3 Stati sti cal Si gnal Processi ng
3-6
Spectral Analysis
The goal of spectral estimation i s to descri be the di stri buti on (over frequency)
of the power contai ned i n a si gnal , based on a fi ni te set of data. Esti mati on of
power spectra i s useful i n a vari ety of appl i cati ons, i ncl udi ng the detecti on of
si gnal s buri ed i n wi de-band noi se.
The power spectrum of a stati onary random process x
n
i s mathemati cal l y
rel ated to the correl ati on sequence by the di screte-ti me Fouri er transform. I n
terms of normal i zed frequency, thi s i s gi ven by
Thi s can be wri tten as a functi on of physi cal frequency f (e.g., i n hertz) by usi ng
the rel ati on = 2f/f
s
, where f
s
i s the sampl i ng frequency.
The correl ati on sequence can be deri ved from the power spectrum by use of the
i nverse di screte-ti me Fouri er transform.
The average power of the sequence x
n
over the enti re Nyqui st i nterval i s
represented by
S
xx
( ) R
xx
m ( )e
j m
m =

=
S
xx
f ( ) R
xx
m ( )e
2j fm f
s

m =

=
R
xx
m ( )
S
xx
( )e
j m
2
------------------------------ d

S
xx
f ( )e
2j fm f
s

f
s
--------------------------------------- f d
f
s
2
f
s
2

= =
R
xx
0 ( )
S
xx
( )
2
----------------- d

S
xx
f ( )
f
s
--------------- f d
f
s
2
f
s
2

= =
Spectral Analysi s
3-7
The quanti ti es
from the above expressi on are defi ned as the power spectral density (PSD) of
the stati onary random si gnal x
n
.
The average power of a si gnal over a parti cul ar frequency band ,
, can be found by i ntegrati ng the PSD over that band.
You can see from the above expressi on that P
xx
() represents the power content
of a si gnal i n an infinitesimal frequency band, whi ch i s why we cal l i t the power
spectral density.
The uni ts of the PSD are power (e.g., watts) per uni t of frequency. I n the case
of P
xx
(), thi s i s watts/rad/sampl e or si mpl y watts/rad. I n the case of P
xx
(f), the
uni ts are watts/hertz. I ntegrati on of the PSD wi th respect to frequency yi el ds
uni ts of watts, as expected for the average power .
For real si gnal s, the PSD i s symmetri c about DC, and thus P
xx
() for
i s suffi ci ent to compl etel y characteri ze the PSD. However, i n order to obtai n
the average power over the enti re Nyqui st i nterval i t i s necessary to i ntroduce
the concept of the one-sided PSD.
The one-si ded PSD i s gi ven by
The average power of a si gnal over the frequency band , ,
can be computed usi ng the one-si ded PSD as
P
xx
( )
S
xx
( )
2
----------------- =
P
xx
f ( )
S
xx
f ( )
f
s
--------------- = and

1

2
[ , ]
0
1

2
<
P

1

2
, [ ]
P
xx
( ) d

P
xx
( ) d

2

1

+ =
P

1

2
, [ ]
0 <
P
onesi ded
( )
0 - 0 < ,
2P
xx
( ) 0 < ,

'

1

2
[ , ] 0
1

2
<
P

1

2
, [ ]
P
onesi ded
( ) d

=
3 Stati sti cal Si gnal Processi ng
3-8
Spectral Estimation Method Overview
The vari ous methods of spectrum esti mati on avai l abl e i n the Si gnal Processi ng
Tool box can be categori zed as fol l ows:
Nonparametri c methods
Parametri c methods
Subspace methods
Nonparametric methods are those i n whi ch the esti mate of the PSD i s made
di rectl y from the si gnal i tsel f. The si mpl est such method i s the periodogram.
An i mproved versi on of the peri odogram i s Welchs method [8]. A more modern
nonparametri c techni que i s the multitaper method (MTM).
Parametric methods are those i n whi ch the si gnal whose PSD we want to
esti mate i s assumed to be output of a l i near system dri ven by whi te noi se.
Exampl es are the Yule-Walker autoregressive (AR) method and the Burg
method. These methods esti mate the PSD by fi rst esti mati ng the parameters
(coeffi ci ents) of the l i near system that hypotheti cal l y generates the si gnal .
They tend to produce better resul ts than cl assi cal nonparametri c methods
when the data l ength of the avai l abl e si gnal i s rel ati vel y short.
Subspace methods, al so known as high-resolution methods or super-resolution
methods, generate frequency component esti mates for a si gnal based on an
ei genanal ysi s or ei gendecomposi ti on of the correl ati on matri x. Exampl es are
the multiple signal classification (MUSI C) method or the eigenvector (EV)
method. These methods are best sui ted for l i ne spectra that i s, spectra of
si nusoi dal si gnal s and are effecti ve i n the detecti on of si nusoi ds buri ed i n
noi se, especi al l y when the si gnal to noi se rati os are l ow.
Al l three categori es of methods are l i sted i n the tabl e bel ow wi th the
correspondi ng tool box functi on names. More i nformati on about each functi on
i s on the correspondi ng functi on reference page. See Parametri c Model i ng on
page 4-12 for detai l s about lpc and other parametri c esti mati on functi ons.
Spectral Analysi s
3-9
Method Description Functions
Peri odogram Power spectral densi ty esti mate periodogram
Wel ch Averaged peri odograms of
overl apped, wi ndowed si gnal secti ons
pwelch, csd,
tfe, cohere
Mul ti taper) Spectral esti mate from combi nati on
of mul ti pl e orthogonal wi ndows (or
tapers)
pmtm
Yul e-Wal ker
AR
Autoregressi ve (AR) spectral
esti mate of a ti me-seri es from i ts
esti mated autocorrel ati on functi on
pyulear
Burg Autoregressi ve (AR) spectral
esti mati on of a ti me-seri es by
mi ni mi zati on of l i near predi cti on
errors
pburg
Covari ance Autoregressi ve (AR) spectral
esti mati on of a ti me-seri es by
mi ni mi zati on of the forward
predi cti on errors
pcov
Modi fi ed
Covari ance
Autoregressi ve (AR) spectral
esti mati on of a ti me-seri es by
mi ni mi zati on of the forward and
backward predi cti on errors
pmcov
MUSI C Mul ti pl e si gnal cl assi fi cati on pmusic
Ei genvector Pseudospectrum esti mate peig
3 Stati sti cal Si gnal Processi ng
3-10
Nonparametric Methods
The fol l owi ng secti ons di scuss the peri odogram, modi fi ed peri odogram, Wel ch,
and mul ti taper methods of nonparametri c esti mati on, al ong wi th the rel ated
CSD functi on, transfer functi on esti mate, and coherence functi on.
The Periodogra m
One way of esti mati ng the power spectrum of a process i s to si mpl y fi nd the
di screte-ti me Fouri er transform of the sampl es of the process (usual l y done on
a gri d wi th an FFT) and take the magni tude squared of the resul t. Thi s
esti mate i s cal l ed the periodogram.
The peri odogram esti mate of the PSD of a l ength-L si gnal x
L
[n] i s
where
The actual computati on of X
L
(f) can be performed onl y at a fi ni te number of
frequency poi nts, N, and usual l y empl oys the FFT. I n practi ce, most
i mpl ementati ons of the peri odogram method compute the N-poi nt PSD
esti mate
where
I t i s wi se to choose N > L so that N i s the next power of two l arger than L. To
eval uate X
L
[f
k
], we si mpl y pad x
L
[n] wi th zeros to l ength N. I f L > N, we must
wrap x
L
[n] modul o-N pri or to computi ng X
L
[f
k
].
P

xx
f ( )
X
L
f ( )
2
f
s
L
-------------------- =
X
L
f ( ) x
L
n [ ]e
2j fn f
s

n 0 =
L 1

=
P

xx
f
k
[ ]
X
L
f
k
[ ]
2
f
s
L
-----------------------, = f
k
kf
s
N
--------, = k 0 1 N 1 , , , =
X
L
f
k
[ ] x
L
n [ ]e
2j kn N
n 0 =
N 1

=
Spectral Analysi s
3-11
As an exampl e, consi der the fol l owi ng 1001-el ement si gnal xn, whi ch consi sts
of two si nusoi ds pl us noi se.
randn('state',0);
fs = 1000; % Sampling frequency
t = (0:fs)/fs; % One second worth of samples
A = [1 2]; % Sinusoid amplitudes (row vector)
f = [150;140]; % Sinusoid frequencies (column vector)
xn = A*sin(2*pi*f*t) + 0.1*randn(size(t));
Note The three l ast l i nes i l l ustrate a conveni ent and general way to express
the sum of si nusoi ds. Together they are equi val ent to
xn = sin(2*pi*150*t) + 2*sin(2*pi*140*t) + 0.1*randn(size(t));
The peri odogram esti mate of the PSD can be computed by
Pxx = periodogram(xn,[],'twosided',1024,fs);
and a pl ot of the esti mate can be di spl ayed by si mpl y omi tti ng the output
argument, as bel ow.
periodogram(xn,[],'twosided',1024,fs);
0 100 200 300 400 500 600 700 800 900
90
80
70
60
50
40
30
20
10
0
Frequency (Hz)
P
o
w
e
r

S
p
e
c
t
r
a
l

D
e
n
s
i
t
y

(
d
B
/
H
z
)
Periodogram PSD Estimate
3 Stati sti cal Si gnal Processi ng
3-12
The average power can be computed by approxi mati ng the i ntegral wi th the
fol l owi ng sum.
Pow = (fs/length(Pxx)) * sum(Pxx)
Pow =
2.5028
You can al so compute the average power from the one-si ded PSD esti mate.
Pxxo = periodogram(xn,[],1024,fs);
Pow = (fs/(2*length(Pxxo))) * sum(Pxxo)
Pow =
2.4979
Per for ma nce of the Periodogra m
The fol l owi ng secti ons di scuss the performance of the peri odogram wi th regard
to the i ssues of l eakage, resol uti on, bi as, and vari ance.
Spectra l Lea ka ge. Consi der the power spectrum or PSD of a fi ni te-l ength si gnal
x
L
[n], as di scussed i n The Peri odogram on page 3-10. I t i s frequentl y useful
to i nterpret x
L
[n] as the resul t of mul ti pl yi ng an i nfi ni te si gnal , x[n], by a
fi ni te-l ength rectangul ar wi ndow, w
R
[n].
Because mul ti pl i cati on i n the ti me domai n corresponds to convol uti on i n the
frequency domai n, the Fouri er transform of the expressi on above i s
The expressi on devel oped earl i er for the peri odogram,
i l l ustrates that the peri odogram i s al so i nfl uenced by thi s convol uti on.
x
L
n [ ] x n [ ] w
R
n [ ] =
X
L
f ( )
1
f
s
---- X ( )W
R
f ( ) d
f
s
2
f
s
2

=
P

xx
f ( )
X
L
f ( )
2
f
s
L
-------------------- =
Spectral Analysi s
3-13
The effect of the convol uti on i s best understood for si nusoi dal data. Suppose
that x[n] i s composed of a sum of M compl ex si nusoi ds.
I ts spectrum i s
whi ch for a fi ni te-l ength sequence becomes
So i n the spectrum of the fi ni te-l ength si gnal , the Di rac del tas have been
repl aced by terms of the form , whi ch corresponds to the frequency
response of a rectangul ar wi ndow centered on the frequency f
k
.
The frequency response of a rectangul ar wi ndow has the shape of a si nc si gnal ,
as shown bel ow.
x n [ ] A
k
e
j
k
n
k 1 =
M

=
X f ( ) f
s
A
k
f f
k
( )
k 1 =
M

=
X
L
f ( ) A
k
f
k
( )
k 1 =
M

,


_
W
R
f ( ) d
f
s
2
f
s
2

A
k
W
R
f f
k
( )
k 1 =
M

= =
W
R
f f
k
( )
0.5 0 0.5
90
80
70
60
50
40
30
20
10
0
3 Stati sti cal Si gnal Processi ng
3-14
The pl ot di spl ays a mai n l obe and several si de l obes, the l argest of whi ch i s
approxi matel y 13.5 dB bel ow the mai nl obe peak. These l obes account for the
effect known as spectral leakage. Whi l e the i nfi ni te-l ength si gnal has i ts power
concentrated exactl y at the di screte frequency poi nts f
k
, the wi ndowed (or
truncated) si gnal has a conti nuum of power l eaked around the di screte
frequency poi nts f
k
.
Because the frequency response of a short rectangul ar wi ndow i s a much poorer
approxi mati on to the Di rac del ta functi on than that of a l onger wi ndow,
spectral l eakage i s especi al l y evi dent when data records are short. Consi der the
fol l owi ng sequence of 100 sampl es.
randn('state',0)
fs = 1000; % Sampling frequency
t = (0:fs/10)/fs; % One-tenth of a second worth of samples
A = [1 2]; % Sinusoid amplitudes
f = [150;140]; % Sinusoid frequencies
xn = A*sin(2*pi*f*t) + 0.1*randn(size(t));
periodogram(xn,[],1024,fs);
I t i s i mportant to note that the effect of spectral l eakage i s conti ngent sol el y on
the l ength of the data record. I t i s not a consequence of the fact that the
peri odogram i s computed at a fi ni te number of frequency sampl es.
0 100 200 300 400 500
80
70
60
50
40
30
20
10
0
Frequency (Hz)
P
o
w
e
r

S
p
e
c
t
r
a
l

D
e
n
s
i
t
y

(
d
B
/
H
z
)
Periodogram PSD Estimate
Spectral Analysi s
3-15
Resolution. Resolution refers to the abi l i ty to di scri mi nate spectral features, and
i s a key concept on the anal ysi s of spectral esti mator performance.
I n order to resol ve two si nusoi ds that are rel ati vel y cl ose together i n frequency,
i t i s necessary for the di fference between the two frequenci es to be greater than
the wi dth of the mai nl obe of the l eaked spectra for ei ther one of these si nusoi ds.
The mai nl obe wi dth i s defi ned to be the wi dth of the mai nl obe at the poi nt
where the power i s hal f the peak mai nl obe power (i .e., 3 dB wi dth). Thi s wi dth
i s approxi matel y equal to f
s
/L.
I n other words, for two si nusoi ds of frequenci es f
1
and f
2
, the resol vabi l i ty
condi ti on requi res that
I n the exampl e above, where two si nusoi ds are separated by onl y 10 Hz, the
data record must be greater than 100 sampl es to al l ow resol uti on of two
di sti nct si nusoi ds by a peri odogram.
Consi der a case where thi s cri teri on i s not met, as for the sequence of 67
sampl es bel ow.
randn('state',0)
fs = 1000; % Sampling frequency
t = (0:fs/15)./fs; % 67 samples
A = [1 2]; % Sinusoid amplitudes
f = [150;140]; % Sinusoid frequencies
xn = A*sin(2*pi*f*t) + 0.1*randn(size(t));
periodogram(xn,[],1024,fs);
f f
1
f
2
( )
f
s
L
---- > =
3 Stati sti cal Si gnal Processi ng
3-16
The above di scussi on about resol uti on di d not consi der the effects of noi se si nce
the si gnal -to-noi se rati o (SNR) has been rel ati vel y hi gh thus far. When the
SNR i s l ow, true spectral features are much harder to di sti ngui sh, and noi se
arti facts appear i n spectral esti mates based on the peri odogram. The exampl e
bel ow i l l ustrates thi s.
randn('state',0)
fs = 1000; % Sampling frequency
t = (0:fs/10)./fs; % One-tenth of a second worth of samples
A = [1 2]; % Sinusoid amplitudes
f = [150;140]; % Sinusoid frequencies
xn = A*sin(2*pi*f*t) + 2*randn(size(t));
periodogram(xn,[],1024,fs);
0 100 200 300 400 500
70
60
50
40
30
20
10
0
Frequency (Hz)
P
o
w
e
r

S
p
e
c
t
r
a
l

D
e
n
s
i
t
y

(
d
B
/
H
z
)
Periodogram PSD Estimate
Spectral Analysi s
3-17
Bia s of the Periodogra m. The peri odogram i s a bi ased esti mator of the PSD. I ts
expected val ue can be shown to be
whi ch i s si mi l ar to the fi rst expressi on for X
L
(f) i n Spectral Leakage on
page 3-12, except that the expressi on here i s i n terms of average power rather
than magni tude. Thi s suggests that the esti mates produced by the
peri odogram correspond to a leaky PSD rather than the true PSD.
Note that essenti al l y yi el ds a tri angul ar Bartl ett wi ndow (whi ch
i s apparent from the fact that the convol uti on of two rectangul ar pul ses i s a
tri angul ar pul se). Thi s resul ts i n a hei ght for the l argest si del obes of the l eaky
power spectra that i s about 27 dB bel ow the mai nl obe peak; i .e., about twi ce the
frequency separati on rel ati ve to the non-squared rectangul ar wi ndow.
The peri odogram i s asymptoti cal l y unbi ased, whi ch i s evi dent from the earl i er
observati on that as the data record l ength tends to i nfi ni ty, the frequency
response of the rectangul ar wi ndow more cl osel y approxi mates the Di rac del ta
functi on (al so true for a Bartl ett wi ndow). However, i n some cases the
peri odogram i s a poor esti mator of the PSD even when the data record i s l ong.
Thi s i s due to the vari ance of the peri odogram, as expl ai ned bel ow.
0 100 200 300 400 500
55
50
45
40
35
30
25
20
15
10
5
Frequency (Hz)
P
o
w
e
r

S
p
e
c
t
r
a
l

D
e
n
s
i
t
y

(
d
B
/
H
z
)
Periodogram PSD Estimate
E
X
L
f ( )
2
f
s
L
--------------------

' ;

1
f
s
L
-------- P
xx
( ) W
R
f ( )
2
d
f
s
2
f
s
2

=
W
R
f ( )
2
3 Stati sti cal Si gnal Processi ng
3-18
Va ria nce of the Periodogra m. The vari ance of the peri odogram can be shown to be
approxi matel y
whi ch i ndi cates that the vari ance does not tend to zero as the data l ength L
tends to i nfi ni ty. I n stati sti cal terms, the peri odogram i s not a consi stent
esti mator of the PSD. Neverthel ess, the peri odogram can be a useful tool for
spectral esti mati on i n si tuati ons where the SNR i s hi gh, and especi al l y i f the
data record i s l ong.
The M odified Periodogra m
The modified periodogram wi ndows the ti me-domai n si gnal pri or to computi ng
the FFT i n order to smooth the edges of the si gnal . Thi s has the effect of
reduci ng the hei ght of the si del obes or spectral l eakage. Thi s phenomenon
gi ves ri se to the i nterpretati on of si del obes as spuri ous frequenci es i ntroduced
i nto the si gnal by the abrupt truncati on that occurs when a rectangul ar
wi ndow i s used. For nonrectangul ar wi ndows, the end poi nts of the truncated
si gnal are attenuated smoothl y, and hence the spuri ous frequenci es i ntroduced
are much l ess severe. On the other hand, nonrectangul ar wi ndows al so broaden
the mai nl obe, whi ch resul ts i n a net reducti on of resol uti on.
The periodogram functi on al l ows you to compute a modi fi ed peri odogram by
speci fyi ng the wi ndow to be used on the data. For exampl e, compare a
rectangul ar wi ndow and a Hammi ng wi ndow.
randn('state',0)
fs = 1000; % Sampling frequency
t = (0:fs/10)./fs; % One-tenth of a second worth of samples
A = [1 2]; % Sinusoid amplitudes
f = [150;140]; % Sinusoid frequencies
xn = A*sin(2*pi*f*t) + 0.1*randn(size(t));
periodogram(xn,rectwin(length(xn)),1024,fs);
var
X
L
f ( )
2
f
s
L
--------------------

' ;

P
xx
2
f ( ) 1
2L f f
s
( ) si n
L 2f f
s
( ) si n
------------------------------------
,
_
2
+
Spectral Analysi s
3-19
periodogram(xn,hamming(length(xn)),1024,fs);
You can veri fy that al though the si del obes are much l ess evi dent i n the
Hammi ng-wi ndowed peri odogram, the two mai n peaks are wi der. I n fact, the
3 dB wi dth of the mai nl obe correspondi ng to a Hammi ng wi ndow i s
approxi matel y twi ce that of a rectangul ar wi ndow. Hence, for a fi xed data
l ength, the PSD resol uti on attai nabl e wi th a Hammi ng wi ndow i s
0 100 200 300 400 500
80
70
60
50
40
30
20
10
0
Frequency (Hz)
P
o
w
e
r

S
p
e
c
t
r
a
l

D
e
n
s
i
t
y

(
d
B
/
H
z
)
Periodogram PSD Estimate
0 100 200 300 400 500
80
70
60
50
40
30
20
10
0
Frequency (Hz)
P
o
w
e
r

S
p
e
c
t
r
a
l

D
e
n
s
i
t
y

(
d
B
/
H
z
)
Periodogram PSD Estimate
3 Stati sti cal Si gnal Processi ng
3-20
approxi matel y hal f that attai nabl e wi th a rectangul ar wi ndow. The competi ng
i nterests of mai nl obe wi dth and si del obe hei ght can be resol ved to some extent
by usi ng vari abl e wi ndows such as the Kai ser wi ndow.
Nonrectangul ar wi ndowi ng affects the average power of a si gnal because some
of the ti me sampl es are attenuated when mul ti pl i ed by the wi ndow. To
compensate for thi s, the periodogram functi on normal i zes the wi ndow to have
an average power of uni ty. Thi s way the choi ce of wi ndow does not affect the
average power of the si gnal .
The modi fi ed peri odogram esti mate of the PSD i s
where U i s the wi ndow normal i zati on constant
whi ch i s i ndependent of the choi ce of wi ndow. The addi ti on of U as a
normal i zati on constant ensures that the modi fi ed peri odogram i s
asymptoti cal l y unbi ased.
Welchs M ethod
An i mproved esti mator of the PSD i s the one proposed by Wel ch [8]. The
method consi sts of di vi di ng the ti me seri es data i nto (possi bl y overl appi ng)
segments, computi ng a modi fi ed peri odogram of each segment, and then
averagi ng the PSD esti mates. The resul t i s Wel chs PSD esti mate.
Wel chs method i s i mpl emented i n the Si gnal Processi ng Tool box by the pwelch
functi on. By defaul t, the data i s di vi ded i nto ei ght segments wi th 50% overl ap
between them. A Hammi ng wi ndow i s used to compute the modi fi ed
peri odogram of each segment.
The averagi ng of modi fi ed peri odograms tends to decrease the vari ance of the
esti mate rel ati ve to a si ngl e peri odogram esti mate of the enti re data record.
Al though overl ap between segments tends to i ntroduce redundant i nformati on,
thi s effect i s di mi ni shed by the use of a nonrectangul ar wi ndow, whi ch reduces
P

xx
f ( )
X
L
f ( )
2
f
s
L U
-------------------- =
U
1
L
--- - w n ( )
2
n 0 =
L 1

=
Spectral Analysi s
3-21
the i mportance or weight gi ven to the end sampl es of segments (the sampl es
that overl ap).
However, as menti oned above, the combi ned use of short data records and
nonrectangul ar wi ndows resul ts i n reduced resol uti on of the esti mator. I n
summary, there i s a tradeoff between vari ance reducti on and resol uti on. One
can mani pul ate the parameters i n Wel chs method to obtai n i mproved
esti mates rel ati ve to the peri odogram, especi al l y when the SNR i s l ow. Thi s i s
i l l ustrated i n the fol l owi ng exampl e.
Consi der an ori gi nal si gnal consi sti ng of 301 sampl es.
randn('state',1)
fs = 1000; % Sampling frequency
t = (0:0.3*fs)./fs; % 301 samples
A = [2 8]; % Sinusoid amplitudes (row vector)
f = [150;140]; % Sinusoid frequencies (column vector)
xn = A*sin(2*pi*f*t) + 5*randn(size(t));
periodogram(xn,rectwin(length(xn)),1024,fs);
0 100 200 300 400 500
60
50
40
30
20
10
0
10
Frequency (Hz)
P
o
w
e
r

S
p
e
c
t
r
a
l

D
e
n
s
i
t
y

(
d
B
/
H
z
)
Periodogram PSD Estimate
3 Stati sti cal Si gnal Processi ng
3-22
We can obtai n Wel chs spectral esti mate for 3 segments wi th 50% overl ap wi th
pwelch(xn,rectwin(150),75,512,fs);
I n the peri odogram above, noi se and the l eakage make one of the si nusoi ds
essenti al l y i ndi sti ngui shabl e from the arti fi ci al peaks. I n contrast, al though
the PSD produced by Wel chs method has wi der peaks, you can sti l l di sti ngui sh
the two si nusoi ds, whi ch stand out from the noi se fl oor.
However, i f we try to reduce the vari ance further, the l oss of resol uti on causes
one of the si nusoi ds to be l ost al together.
pwelch(xn,hamming(100),75,512,fs);
0 100 200 300 400 500
25
20
15
10
5
0
5
10
Frequency (Hz)
P
o
w
e
r

S
p
e
c
t
r
a
l

D
e
n
s
i
t
y

(
d
B
/
H
z
)
Welch PSD Estimate
Spectral Analysi s
3-23
For a more detai l ed di scussi on of Wel chs method of PSD esti mati on, see
Kay [2] and Wel ch [8].
Bia s a nd N or ma liza tion in Welchs M ethod
Wel chs method yi el ds a bi ased esti mator of the PSD. The expected val ue can
be found to be
where L
s
i s the l ength of the data segments and U i s the same normal i zati on
constant present i n the defi ni ti on of the modi fi ed peri odogram. As i s the case
for al l peri odograms, Wel chs esti mator i s asymptoti cal l y unbi ased. For a fi xed
l ength data record, the bi as of Wel chs esti mate i s l arger than that of the
peri odogram because L
s
< L.
The vari ance of Wel chs esti mator i s di ffi cul t to compute because i t depends on
both the wi ndow used and the amount of overl ap between segments. Basi cal l y,
the vari ance i s i nversel y proporti onal to the number of segments whose
modi fi ed peri odograms are bei ng averaged.
0 100 200 300 400 500
20
15
10
5
0
5
Frequency (Hz)
P
o
w
e
r

S
p
e
c
t
r
a
l

D
e
n
s
i
t
y

(
d
B
/
H
z
)
Welch PSD Estimate
E P

wel ch
{ }
1
f
s
L
s
U
---------------- P
xx
( ) W f ( )
2
d
f
s
2
f
s
2

=
3 Stati sti cal Si gnal Processi ng
3-24
M ultita per M ethod
The peri odogram can be i nterpreted as fi l teri ng a l ength L si gnal , x
L
[n],
through a fi l ter bank (a set of fi l ters i n paral l el ) of L FI R bandpass fi l ters. The
3 dB bandwi dth of each of these bandpass fi l ters can be shown to be
approxi matel y equal to f
s
/L. The magni tude response of each one of these
bandpass fi l ters resembl es that of the rectangul ar wi ndow di scussed i n
Spectral Leakage on page 3-12. The peri odogram can thus be vi ewed as a
computati on of the power of each fi l tered si gnal (i .e., the output of each
bandpass fi l ter) that uses just one sampl e of each fi l tered si gnal and assumes
that the PSD of x
L
[n] i s constant over the bandwi dth of each bandpass fi l ter.
As the l ength of the si gnal i ncreases, the bandwi dth of each bandpass fi l ter
decreases, maki ng i t a more sel ecti ve fi l ter, and i mprovi ng the approxi mati on
of constant PSD over the bandwi dth of the fi l ter. Thi s provi des another
i nterpretati on of why the PSD esti mate of the peri odogram i mproves as the
l ength of the si gnal i ncreases. However, there are two factors apparent from
thi s standpoi nt that compromi se the accuracy of the peri odogram esti mate.
Fi rst, the rectangul ar wi ndow yi el ds a poor bandpass fi l ter. Second, the
computati on of the power at the output of each bandpass fi l ter rel i es on a si ngl e
sampl e of the output si gnal , produci ng a very crude approxi mati on.
Wel chs method can be gi ven a si mi l ar i nterpretati on i n terms of a fi l ter bank.
I n Wel chs i mpl ementati on, several sampl es are used to compute the output
power, resul ti ng i n reduced vari ance of the esti mate. On the other hand, the
bandwi dth of each bandpass fi l ter i s l arger than that correspondi ng to the
peri odogram method, whi ch resul ts i n a l oss of resol uti on. The fi l ter bank
model thus provi des a new i nterpretati on of the compromi se between vari ance
and resol uti on.
Thompsons multitaper method (MTM) bui l ds on these resul ts to provi de an
i mproved PSD esti mate. I nstead of usi ng bandpass fi l ters that are essenti al l y
rectangul ar wi ndows (as i n the peri odogram method), the MTM method uses a
bank of opti mal bandpass fi l ters to compute the esti mate. These opti mal FI R
fi l ters are deri ved from a set of sequences known as discrete prolate spheroidal
sequences (DPSSs, al so known as Slepian sequences).
I n addi ti on, the MTM method provi des a ti me-bandwi dth parameter wi th
whi ch to bal ance the vari ance and resol uti on. Thi s parameter i s gi ven by the
ti me-bandwi dth product, NW and i t i s di rectl y rel ated to the number of tapers
used to compute the spectrum. There are al ways 2*NW-1 tapers used to form
the esti mate. Thi s means that, as NW i ncreases, there are more esti mates of
Spectral Analysi s
3-25
the power spectrum, and the vari ance of the esti mate decreases. However, the
bandwi dth of each taper i s al so proporti onal to NW, so as NW i ncreases, each
esti mate exhi bi ts more spectral l eakage (i .e., wi der peaks) and the overal l
spectral esti mate i s more bi ased. For each data set, there i s usual l y a val ue for
NW that al l ows an opti mal trade-off between bi as and vari ance.
The Si gnal Processi ng Tool box functi on that i mpl ements the MTM method i s
cal l ed pmtm. Use pmtm to compute the PSD of xn from the previ ous exampl es.
randn('state',0)
fs = 1000; % Sampling frequency
t = (0:fs)/fs; % One second worth of samples
A = [1 2]; % Sinusoid amplitudes
f = [150;140]; % Sinusoid frequencies
xn = A*sin(2*pi*f*t) + 0.1*randn(size(t));
[P,F] = pmtm(xn,4,1024,fs);
plot(F,10*log10(P)) % Plot in dB/Hz
xlabel('Frequency (Hz)');
ylabel('Power Spectral Density (dB/Hz)');
0 100 200 300 400 500
55
50
45
40
35
30
25
20
15
10
5
Frequency (Hz)
P
o
w
e
r

S
p
e
c
t
r
a
l

D
e
n
s
i
t
y

(
d
B
/
H
z
)
3 Stati sti cal Si gnal Processi ng
3-26
By l oweri ng the ti me-bandwi dth product, you can i ncrease the resol uti on at the
expense of l arger vari ance.
[P1,f] = pmtm(xn,3/2,1024,fs);
plot(f,10*log10(P1)) % Plot in dB/Hz
xlabel('Frequency (Hz)');
ylabel('Power Spectral Density (dB/Hz)');
Note that the average power i s conserved i n both cases.
Pow = (fs/1024) * sum(P)
Pow =
2.4926
Pow1 = (fs/1024) * sum(P1)
Pow1 =
2.4927
Thi s method i s more computati onal l y expensi ve than Wel chs method due to
the cost of computi ng the di screte prol ate spheroi dal sequences. For l ong data
seri es (10,000 poi nts or more), i t i s useful to compute the DPSSs once and save
them i n a MAT-fi l e. The M-fi l es dpsssave, dpssload, dpssdir, and dpssclear
are provi ded to keep a database of saved DPSSs i n the MAT-fi l e dpss.mat.
0 100 200 300 400 500
80
70
60
50
40
30
20
10
0
Frequency (Hz)
P
o
w
e
r

S
p
e
c
t
r
a
l

D
e
n
s
i
t
y

(
d
B
/
H
z
)
Spectral Analysi s
3-27
Cross- Spectra l Density Function
The PSD i s a speci al case of the cross spectral density (CSD) functi on, defi ned
between two si gnal s x
n
and y
n
as
As i s the case for the correl ati on and covari ance sequences, the tool box
estimates the PSD and CSD because si gnal l engths are fi ni te.
To esti mate the cross-spectral densi ty of two equal l ength si gnal s x and y usi ng
Wel chs method, the csd functi on forms the peri odogram as the product of the
FFT of x and the conjugate of the FFT of y. Unl i ke the real -val ued PSD, the
CSD i s a compl ex functi on. csd handl es the secti oni ng and wi ndowi ng of x and
y i n the same way as the pwelch functi on.
Sxy = csd(x,y,nfft,fs,window,numoverlap)
Confidence Inter va ls
You can compute confi dence i nterval s usi ng the csd functi on by i ncl udi ng an
addi ti onal i nput argument p that speci fi es the percentage of the confi dence
i nterval , and setti ng the numoverlap argument to 0.
[Sxy,Sxyc,f] = csd(x,y,nfft,fs,window,0,p)
p must be a scal ar between 0 and 1. Thi s functi on assumes chi -squared
di stri buted peri odograms of the nonoverl appi ng secti ons of wi ndowed data i n
computi ng the confi dence i nterval s. Thi s assumpti on i s val i d when the si gnal
i s a Gaussi an di stri buted random process. Provi ded these assumpti ons are
correct, the confi dence i nterval
[Sxy-Sxyc(:,1) Sxy+Sxyc(:,2)]
covers the true CSD wi th probabi l i ty p. I f you set numoverlap to any val ue
other than 0, you generate a warni ng i ndi cati ng that the secti ons overl ap and
the confi dence i nterval i s not rel i abl e.
S
xy
( ) R
xy
m ( )e
j m
m =

=
3 Stati sti cal Si gnal Processi ng
3-28
Tra nsfer Function Estima te
One appl i cati on of Wel chs method i s nonparametri c system i denti fi cati on.
Assume that H i s a l i near, ti me i nvari ant system, and x(n) and y(n) are the
i nput to and output of H, respecti vel y. Then the power spectrum of x(n) i s
rel ated to the CSD of x(n) and y(n) by
An esti mate of the transfer functi on between x(n) and y(n) i s
Thi s method esti mates both magni tude and phase i nformati on. The tfe
functi on uses Wel chs method to compute the CSD and power spectrum, and
then forms thei r quoti ent for the transfer functi on esti mate. Use tfe the same
way that you use the csd functi on.
Fi l ter the si gnal xn wi th an FI R fi l ter, then pl ot the actual magni tude response
and the esti mated response.
h = ones(1,10)/10; % Moving average filter
yn = filter(h,1,xn);
[HEST,f] = tfe(xn,yn,256,fs,256,128,'none');
H = freqz(h,1,f,fs);
subplot(2,1,1); plot(f,abs(H));
title('Actual Transfer Function Magnitude');
subplot(2,1,2); plot(f,abs(HEST));
title('Transfer Function Magnitude Estimate');
xlabel('Frequency (Hz)');
S
xy
( ) H ( )S
xx
( ) =
H

( )
S

xy
( )
S

xx
( )
----------------- =
Spectral Analysi s
3-29
Coherence Function
The magni tude-squared coherence between two si gnal s x(n) and y(n) i s
Thi s quoti ent i s a real number between 0 and 1 that measures the correl ati on
between x(n) and y(n) at the frequency .
The cohere functi on takes sequences x and y, computes thei r power spectra
and CSD, and returns the quoti ent of the magni tude squared of the CSD and
the product of the power spectra. I ts opti ons and operati on are si mi l ar to the
csd and tfe functi ons.
The coherence functi on of xn and the fi l ter output yn versus frequency i s
cohere(xn,yn,256,fs,256,128,'none')
0 100 200 300 400 500
0
0.2
0.4
0.6
0.8
1
Actual Transfer Function Magnitude
0 100 200 300 400 500
0
0.2
0.4
0.6
0.8
1
Transfer Function Magnitude Estimate
Frequency (Hz)
C
xy
( )
S
xy
( )
2
S
xx
( )S
yy
( )
----------------------------------- =
3 Stati sti cal Si gnal Processi ng
3-30
I f the i nput sequence l ength nfft, wi ndow l ength window, and the number of
overl appi ng data poi nts i n a wi ndow numoverlap, are such that cohere
operates on onl y a si ngl e record, the functi on returns al l ones. Thi s i s because
the coherence functi on for l i nearl y dependent data i s one.
Parametric Methods
Parametri c methods can yi el d hi gher resol uti ons than nonparametri c methods
i n cases when the si gnal l ength i s short. These methods use a di fferent
approach to spectral esti mati on; i nstead of tryi ng to esti mate the PSD di rectl y
from the data, they model the data as the output of a l i near system dri ven by
whi te noi se, and then attempt to esti mate the parameters of that l i near
system.
The most commonl y used l i near system model i s the all-pole model, a fi l ter
wi th al l of i ts zeroes at the ori gi n i n the z-pl ane. The output of such a fi l ter for
whi te noi se i nput i s an autoregressi ve (AR) process. For thi s reason, these
methods are someti mes referred to as AR methods of spectral esti mati on.
The AR methods tend to adequatel y descri be spectra of data that i s peaky,
that i s, data whose PSD i s l arge at certai n frequenci es. The data i n many
practi cal appl i cati ons (such as speech) tends to have peaky spectra so that AR
model s are often useful . I n addi ti on, the AR model s l ead to a system of l i near
equati ons whi ch i s rel ati vel y si mpl e to sol ve.
The Si gnal Processi ng Tool box offers the fol l owi ng AR methods for spectral
esti mati on:
Yul e-Wal ker AR method (autocorrel ati on method)
Burg method
0 50 100 150 200 250 300 350 400 450 500
0
0.2
0.4
0.6
0.8
1
Frequency
C
o
h
e
r
e
n
c
e

F
u
n
c
t
i
o
n

E
s
t
i
m
a
t
e
Coherence Function
Spectral Analysi s
3-31
Covari ance method
Modi fi ed covari ance method
Al l AR methods yi el d a PSD esti mate gi ven by
The di fferent AR methods esti mate the AR parameters a
p
(k) sl i ghtl y
di fferentl y, yi el di ng di fferent PSD esti mates. The fol l owi ng tabl e provi des a
summary of the di fferent AR methods.
P

AR
f ( )
1
f
s
----

p
1 a

p
k ( )e
2j kf f
s

k 1 =
p

+
2
------------------------------------------------------------------- =
Burg Covariance Modified Covariance Yule-Walker
Characteristics Does not appl y
wi ndow to data
Does not appl y
wi ndow to data
Does not appl y
wi ndow to data
Appl i es wi ndow to
data
Mi ni mi zes the
forward and
backward predi cti on
errors i n the l east
squares sense, wi th
the AR coeffi ci ents
constrai ned to sati sfy
the L-D recursi on
Mi ni mi zes the
forward predi cti on
error i n the l east
squares sense
Mi ni mi zes the
forward and
backward predi cti on
errors i n the l east
squares sense
Mi ni mi zes the
forward predi cti on
error i n the l east
squares sense
(al so cal l ed
Autocorrel ati on
method)
Advantages Hi gh resol uti on for
short data records
Better resol uti on than
Y-W for short data
records (more
accurate esti mates)
Hi gh resol uti on for
short data records
Performs as wel l as
other methods for
l arge data records
Al ways produces a
stabl e model
Abl e to extract
frequenci es from data
consi sti ng of p or more
pure si nusoi ds
Abl e to extract
frequenci es from data
consi sti ng of p or more
pure si nusoi ds
Al ways produces a
stabl e model
Does not suffer
spectral l i ne-spl i tti ng
3 Stati sti cal Si gnal Processi ng
3-32
Yule- Wa lker AR M ethod
The Yule-Walker AR method of spectral esti mati on computes the AR
parameters by formi ng a bi ased esti mate of the si gnal s autocorrel ati on
functi on, and sol vi ng the l east squares mi ni mi zati on of the forward predi cti on
error. Thi s resul ts i n the Yul e-Wal ker equati ons
The use of a bi ased esti mate of the autocorrel ati on functi on ensures that the
autocorrel ati on matri x above i s posi ti ve defi ni te. Hence, the matri x i s
i nverti bl e and a sol uti on i s guaranteed to exi st. Moreover, the AR parameters
thus computed al ways resul t i n a stabl e al l -pol e model . The Yul e-Wal ker
equati ons can be sol ved effi ci entl y vi a Levi nsons al gori thm, whi ch takes
advantage of the Toepl i tz structure of the autocorrel ati on matri x.
The tool box functi on pyulear i mpl ements the Yul e-Wal ker AR method.
Disadvantages Peak l ocati ons hi ghl y
dependent on i ni ti al
phase
May produce unstabl e
model s
May produce unstabl e
model s
Performs rel ati vel y
poorl y for short data
records
May suffer spectral
l i ne-spl i tti ng for
si nusoi ds i n noi se, or
when order i s very
l arge
Frequency bi as for
esti mates of si nusoi ds
i n noi se
Peak l ocati ons
sl i ghtl y dependent on
i ni ti al phase
Frequency bi as for
esti mates of si nusoi ds
i n noi se
Frequency bi as for
esti mates of si nusoi ds
i n noi se
Mi nor frequency bi as
for esti mates of
si nusoi ds i n noi se
Conditions for
Nonsingularity
Order must be l ess
than or equal to hal f
the i nput frame si ze
Order must be l ess
than or equal to 2/3
the i nput frame si ze
Because of the bi ased
esti mate, the
autocorrel ati on
matri x i s guaranteed
to posi ti ve-defi ni te,
hence nonsi ngul ar
Burg Covariance Modified Covariance Yule-Walker
r 1 ( ) r 2 ( )
*
L r p ( )
*
r 2 ( ) r 1 ( ) L r p 1 ( )
*
M O O M
r p ( ) L r 2 ( ) r 1 ( )
a 2 ( )
a 3 ( )
M
a p 1 + ( )
r 2 ( )
r 3 ( )
M
r p 1 + ( )
=
Spectral Analysi s
3-33
For exampl e, compare the spectrum of a speech si gnal usi ng Wel chs method
and the Yul e-Wal ker AR method.
load mtlb
[P1,f] = pwelch(mtlb,hamming(256),128,1024,fs);
[P2,f] = pyulear(mtlb,14,1024,fs);
plot(f,10*log10(P1),':',f,10*log10(P2)); grid
ylabel('PSD Estimates (dB/Hz)');
xlabel('Frequency (Hz)');
legend('Welch','Yule-Walker AR')
The sol i d-l i ne Yul e-Wal ker AR spectrum i s smoother than the peri odogram
because of the si mpl e underl yi ng al l -pol e model .
Burg M ethod
The Burg method for AR spectral esti mati on i s based on mi ni mi zi ng the
forward and backward predi cti on errors whi l e sati sfyi ng the Levi nson-Durbi n
recursi on (see Marpl e [3], Chapter 7, and Proaki s [6], Secti on 12.3.3). I n
contrast to other AR esti mati on methods, the Burg method avoi ds cal cul ati ng
the autocorrel ati on functi on, and i nstead esti mates the refl ecti on coeffi ci ents
di rectl y.
The pri mary advantages of the Burg method are resol vi ng cl osel y spaced
si nusoi ds i n si gnal s wi th l ow noi se l evel s, and esti mati ng short data records, i n
0 100 200 300 400 500 600
70
60
50
40
30
20
10
P
S
D

E
s
t
i
m
a
t
e
s

(
d
B
/
H
z
)
Frequency (Hz)
Welch
YuleWalker AR
3 Stati sti cal Si gnal Processi ng
3-34
whi ch case the AR power spectral densi ty esti mates are very cl ose to the true
val ues. I n addi ti on, the Burg method ensures a stabl e AR model and i s
computati onal l y effi ci ent.
The accuracy of the Burg method i s l ower for hi gh-order model s, l ong data
records, and hi gh si gnal -to-noi se rati os (whi ch can cause line splitting, or the
generati on of extraneous peaks i n the spectrum esti mate). The spectral densi ty
esti mate computed by the Burg method i s al so suscepti bl e to frequency shi fts
(rel ati ve to the true frequency) resul ti ng from the i ni ti al phase of noi sy
si nusoi dal si gnal s. Thi s effect i s magni fi ed when anal yzi ng short data
sequences.
The tool box functi on pburg i mpl ements the Burg method. Compare the
spectrum of the speech si gnal generated by both the Burg method and the
Yul e-Wal ker AR method. They are very si mi l ar for l arge si gnal l engths.
load mtlb
[P1,f] = pburg(mtlb(1:512),14,1024,fs); % 14th order model
[P2,f] = pyulear(mtlb(1:512),14,1024,fs); % 14th order model
plot(f,10*log10(P1),':',f,10*log10(P2)); grid
ylabel('Magnitude (dB)'); xlabel('Frequency (Hz)');
legend('Burg','Yule-Walker AR')
0 100 200 300 400 500 600
80
70
60
50
40
30
20
10
M
a
g
n
i
t
u
d
e

(
d
B
)
Frequency (Hz)
Burg
YuleWalker AR
Spectral Analysi s
3-35
Compare the spectrum of a noi sy si gnal computed usi ng the Burg method and
the Wel ch method.
randn('state',0)
fs = 1000; % Sampling frequency
t = (0:fs)/fs; % One second worth of samples
A = [1 2]; % Sinusoid amplitudes
f = [150;140]; % Sinusoid frequencies
xn = A*sin(2*pi*f*t) + 0.1*randn(size(t));
[P1,f] = pwelch(xn,hamming(256),128,1024,fs);
[P2,f] = pburg(xn,14,1024,fs);
plot(f,10*log10(P1),':',f,10*log10(P2)); grid
ylabel('PSD Estimates (dB/Hz)');
xlabel('Frequency (Hz)');
legend('Welch','Burg')
Note that, as the model order for the Burg method i s reduced, a frequency shi ft
due to the i ni ti al phase of the si nusoi ds wi l l become apparent.
0 100 200 300 400 500 600
60
50
40
30
20
10
0
P
S
D

E
s
t
i
m
a
t
e
s

(
d
B
/
H
z
)
Frequency (Hz)
Welch
Burg
3 Stati sti cal Si gnal Processi ng
3-36
Cova ria nce a nd M odified Cova ria nce M ethods
The covari ance method for AR spectral esti mati on i s based on mi ni mi zi ng the
forward predi cti on error. The modi fi ed covari ance method i s based on
mi ni mi zi ng the forward and backward predi cti on errors. The tool box functi ons
pcov and pmcov i mpl ement the respecti ve methods.
Compare the spectrum of the speech si gnal generated by both the covari ance
method and the modi fi ed covari ance method. They are nearl y i denti cal , even
for a short si gnal l ength.
load mtlb
[P1,f] = pcov(mtlb(1:64),14,1024,fs); % 14th order model
[P2,f] = pmcov(mtlb(1:64),14,1024,fs); % 14th order model
plot(f,10*log10(P1),':',f,10*log10(P2)); grid
ylabel('Magnitude (dB)'); xlabel('Frequency (Hz)');
legend('Covariance','Modified Covariance')
M USIC a nd Eigenvector Ana lysis M ethods
The pmusic and peig functi ons provi de two rel ated spectral anal ysi s methods:
pmusic provi des the mul ti pl e si gnal cl assi fi cati on (MUSI C) method
devel oped by Schmi dt
peig provi des the ei genvector (EV) method devel oped by Johnson
See Marpl e [3] (pgs. 373-378) for a summary of these methods.
0 500 1000 1500 2000 2500 3000 3500 4000
100
90
80
70
60
50
40
M
a
g
n
i
t
u
d
e

(
d
B
)
Frequency (Hz)
Covariance
Modified Covariance
Spectral Analysi s
3-37
Both of these methods are frequency esti mator techni ques based on
ei genanal ysi s of the autocorrel ati on matri x. Thi s type of spectral anal ysi s
categori zes the i nformati on i n a correl ati on or data matri x, assi gni ng
i nformati on to ei ther a si gnal subspace or a noi se subspace.
Eigena na lysis O ver view
Consi der a number of compl ex si nusoi ds embedded i n whi te noi se. You can
wri te the autocorrel ati on matri x R for thi s system as the sum of the si gnal
autocorrel ati on matri x (S) and the noi se autocorrel ati on matri x (W).
There i s a cl ose rel ati onshi p between the ei genvectors of the si gnal
autocorrel ati on matri x and the si gnal and noi se subspaces. The ei genvectors v
of S span the same si gnal subspace as the si gnal vectors. I f the system contai ns
M compl ex si nusoi ds and the order of the autocorrel ati on matri x i s p,
ei genvectors v
M+1
through v
p+1
span the noi se subspace of the autocorrel ati on
matri x.
Frequency Estima tor Functions. To generate thei r frequency esti mates,
ei genanal ysi s methods cal cul ate functi ons of the vectors i n the si gnal and noi se
subspaces. Both the MUSI C and EV techni ques choose a functi on that goes to
i nfi ni ty (denomi nator goes to zero) at one of the si nusoi dal frequenci es i n the
i nput si gnal . Usi ng di gi tal technol ogy, the resul ti ng esti mate has sharp peaks
at the frequenci es of i nterest; thi s means that there mi ght not be i nfi ni ty
val ues i n the vectors.
The MUSI C esti mate i s gi ven by the formul a
where N i s the si ze of the ei genvectors and e(f) i s a vector of compl ex si nusoi ds.
v represents the ei genvectors of the i nput si gnal s correl ati on matri x; v
k
i s the
k
th
ei genvector. H i s the conjugate transpose operator. The ei genvectors used
R S W + =
P
music
f ( )
1
e
H
f ( ) v
k
v
k
H
k p 1 + =
N

,


_
e f ( )
----------------------------------------------------------------
1
v
k
H
e f ( )
2
k p 1 + =
N

------------------------------------------- = =
e f ( ) 1 exp j 2f ( ) exp j 2f 2 ( ) exp j 2f 4 ( ) exp j 2f n 1 ( ) ( ) [ ]
H
=
3 Stati sti cal Si gnal Processi ng
3-38
i n the sum correspond to the smal l est ei genval ues and span the noi se subspace
(p i s the si ze of the si gnal subspace).
The expressi on i s equi val ent to a Fouri er transform (the vector e(f)
consi sts of compl ex exponenti al s). Thi s form i s useful for numeri c computati on
because the FFT can be computed for each v
k
and then the squared magni tudes
can be summed.
The EV method wei ghts the summati on by the ei genval ues of the correl ati on
matri x.
The pmusic and peig functi ons i n thi s tool box use the svd (si ngul ar val ue
decomposi ti on) functi on i n the si gnal case and the eig functi on for anal yzi ng
the correl ati on matri x and assi gni ng ei genvectors to the si gnal or noi se
subspaces. When svd i s used, pmusic and peig never compute the correl ati on
matri x expl i ci tl y, but the si ngul ar val ues are the ei genval ues.
v
k
H
e f ( )
P
ev
f ( )
1
v
k
H
e f ( )
2
k p 1 + =
N

,


_

----------------------------------------------------------- =
Selected Bi bli ography
3-39
Selected Bibliography
[1] Hayes, M.H. Statistical Digital Signal Processing and Modeling. New York:
John Wi l ey & Sons, 1996.
[2] Kay, S.M. Modern Spectral Estimation. Engl ewood Cl i ffs, NJ: Prenti ce Hal l ,
1988.
[3] Marpl e, S.L. Digital Spectral Analysis. Engl ewood Cl i ffs, NJ: Prenti ce Hal l ,
1987.
[4] Orfani di s, S.J. I ntroduction to Signal Processing. Upper Saddl e Ri ver, NJ:
Prenti ce Hal l , 1996.
[5] Perci val , D.B., and A.T. Wal den. Spectral Analysis for Physical
Applications: Multitaper and Conventional Univariate Techniques. Cambri dge:
Cambri dge Uni versi ty Press, 1993.
[6] Proaki s, J.G., and D.G. Manol aki s. Digital Signal Processing: Principles,
Algorithms, and Applications. Engl ewood Cl i ffs, NJ: Prenti ce Hal l , 1996.
[7] Stoi ca, P., and R. Moses. I ntroduction to Spectral Analysis. Upper Saddl e
Ri ver, NJ: Prenti ce Hal l , 1997.
[8] Wel ch, P.D. The Use of Fast Fouri er Transform for the Esti mati on of Power
Spectra: A Method Based on Ti me Averagi ng Over Short, Modi fi ed
Peri odograms. I EEE Trans. Audio Electroacoust. Vol . AU-15 (June 1967).
Pgs. 70-73.
3 Stati sti cal Si gnal Processi ng
3-40

4
Speci al Topi cs
Overview . . . . . . . . . . . . . . . . . . . . . 4-2
Windows . . . . . . . . . . . . . . . . . . . . . . 4-3
Basi c Shapes . . . . . . . . . . . . . . . . . . . . 4-3
General i zed Cosi ne Wi ndows . . . . . . . . . . . . . . 4-5
Kai ser Wi ndow . . . . . . . . . . . . . . . . . . . 4-6
Chebyshev Wi ndow . . . . . . . . . . . . . . . . . . 4-10
Parametric Modeling . . . . . . . . . . . . . . . . 4-12
Ti me-Domai n Based Model i ng . . . . . . . . . . . . . 4-14
Frequency-Domai n Based Model i ng . . . . . . . . . . . 4-19
Resampling . . . . . . . . . . . . . . . . . . . . 4-22
Cepstrum Analysis . . . . . . . . . . . . . . . . . 4-25
I nverse Compl ex Cepstrum . . . . . . . . . . . . . . 4-27
FFT-Based Time-Frequency Analysis . . . . . . . . . 4-29
Median Filtering . . . . . . . . . . . . . . . . . . 4-30
Communications Applications . . . . . . . . . . . . 4-31
Deconvolution . . . . . . . . . . . . . . . . . . . 4-35
Specialized Transforms . . . . . . . . . . . . . . . 4-36
Chi rp z-Transform . . . . . . . . . . . . . . . . . . 4-36
Di screte Cosi ne Transform . . . . . . . . . . . . . . . 4-38
Hi l bert Transform . . . . . . . . . . . . . . . . . . 4-40
Selected Bibliography . . . . . . . . . . . . . . . 4-42
4 Speci al Topi cs
4-2
Overview
The Si gnal Processi ng Tool box provi des functi ons that al l ow you to appl y a
vari ety of si gnal processi ng techni ques. The fol l owi ng secti ons descri be how to
use some of these functi ons:
Wi ndows
Parametri c Model i ng
Resampl i ng
Cepstrum Anal ysi s
FFT-Based Ti me-Frequency Anal ysi s
Medi an Fi l teri ng
Communi cati ons Appl i cati ons
Deconvol uti on
Speci al i zed Transforms
Sel ected Bi bl i ography
Wi ndows
4-3
Windows
I n both di gi tal fi l ter desi gn and power spectrum esti mati on, the choi ce of a
wi ndowi ng functi on can pl ay an i mportant rol e i n determi ni ng the qual i ty of
overal l resul ts. The mai n rol e of the wi ndow i s to damp out the effects of the
Gi bbs phenomenon that resul ts from truncati on of an i nfi ni te seri es.
The tool box wi ndow functi ons are shown i n the tabl e bel ow.
Basic Shapes
The basi c wi ndow i s the rectangular window, a vector of ones of the appropri ate
l ength. A rectangul ar wi ndow of l ength 50 i s
n = 50;
Window Function
Bartl ett-Hann wi ndow barthannwin
Bartl ett wi ndow bartlett
Bl ackman wi ndow blackman
Bl ackman-harri s wi ndow blackmanharris
Bohman wi ndow bohmanwin
Chebyshev wi ndow chebwin
Gaussi an wi ndow gausswin
Hammi ng wi ndow hamming
Hann wi ndow hann
Kai ser wi ndow kaiser
Nuttal l s Bl ackman-harri s wi ndow nuttallwin
Rectangul ar wi ndow rectwin
Tapered cosi ne wi ndow tukeywin
Tri angul ar wi ndow triang
4 Speci al Topi cs
4-4
w = rectwin(n);
Thi s tool box stores wi ndows i n col umn vectors by conventi on, so an equi val ent
expressi on i s
w = ones(50,1);
The Bartlett (or tri angul ar) window i s the convol uti on of two rectangul ar
wi ndows. The functi ons bartlett and triang compute si mi l ar tri angul ar
wi ndows, wi th three i mportant di fferences. The bartlett functi on al ways
returns a wi ndow wi th two zeros on the ends of the sequence, so that for n odd,
the center secti on of bartlett(n+2) i s equi val ent to triang(n).
bartlett(7)
ans =
0
0.3333
0.6667
1.0000
0.6667
0.3333
0
triang(5)
ans =
0.3333
0.6667
1.0000
0.6667
0.3333
For n even, bartlett i s sti l l the convol uti on of two rectangul ar sequences.
There i s no standard defi ni ti on for the tri angul ar wi ndow for n even; the sl opes
of the l i ne segments of the triang resul t are sl i ghtl y steeper than those of
bartlett i n thi s case.
w = bartlett(8);
[w(2:7) triang(6)]
ans =
Wi ndows
4-5
0.2857 0.1667
0.5714 0.5000
0.8571 0.8333
0.8571 0.8333
0.5714 0.5000
0.2857 0.1667
The fi nal di fference between the Bartl ett and tri angul ar wi ndows i s evi dent i n
the Fouri er transforms of these functi ons. The Fouri er transform of a Bartl ett
wi ndow i s negati ve for n even. The Fouri er transform of a tri angul ar wi ndow,
however, i s al ways nonnegati ve.
Thi s di fference can be i mportant when choosi ng a wi ndow for some spectral
esti mati on techni ques, such as the Bl ackman-Tukey method. Bl ackman-Tukey
forms the spectral esti mate by cal cul ati ng the Fouri er transform of the
autocorrel ati on sequence. The resul ti ng esti mate mi ght be negati ve at some
frequenci es i f the wi ndows Fouri er transform i s negati ve (see Kay [1], pg. 80).
Generalized Cosine Windows
Bl ackman, Hammi ng, Hann, and rectangul ar wi ndows are al l speci al cases of
the generalized cosine window. These wi ndows are combi nati ons of si nusoi dal
sequences wi th frequenci es 0, , and , where N i s the
wi ndow l ength. One way to generate them i s
ind = (0:n-1)'*2*pi/(n-1);
w = A - B*cos(ind) + C*cos(2*ind);
where A, B, and C are constants you defi ne. The concept behi nd these wi ndows
i s that by summi ng the i ndi vi dual terms to form the wi ndow, the l ow frequency
peaks i n the frequency domai n combi ne i n such a way as to decrease si del obe
hei ght. Thi s has the si de effect of i ncreasi ng the mai nl obe wi dth.
The Hammi ng and Hann wi ndows are two-term general i zed cosi ne wi ndows,
gi ven by A = 0.54, B = 0.46 for Hammi ng and A = 0.5, B = 0.5 for Hann (C = 0
i n both cases). The hamming and hann functi ons, respecti vel y, compute these
wi ndows.
Note that the defi ni ti on of the general i zed cosi ne wi ndow shown i n the earl i er
MATLAB code yi el ds zeros at sampl es 1 and n for A = 0.5 and B = 0.5.
The Bl ackman wi ndow i s a popul ar three-term wi ndow, gi ven by A = 0.42,
B = 0.5, C = 0.08. The blackman functi on computes thi s wi ndow.
2 N 1 ( ) 4 N 1 ( )
4 Speci al Topi cs
4-6
Kaiser Window
The Kaiser window i s an approxi mati on to the prol ate-spheroi dal wi ndow, for
whi ch the rati o of the mai nl obe energy to the si del obe energy i s maxi mi zed. For
a Kai ser wi ndow of a parti cul ar l ength, the parameter control s the si del obe
hei ght. For a gi ven , the si del obe hei ght i s fi xed wi th respect to wi ndow l ength.
The statement kaiser(n,beta) computes a l ength n Kai ser wi ndow wi th
parameter beta.
Exampl es of Kai ser wi ndows wi th l ength 50 and vari ous val ues for the beta
parameter are
n = 50;
w1 = kaiser(n,1);
w2 = kaiser(n,4);
w3 = kaiser(n,9);
[W1,f] = freqz(w1/sum(w1),1,512,2);
[W2,f] = freqz(w2/sum(w2),1,512,2);
[W3,f] = freqz(w3/sum(w3),1,512,2);
plot(f,20*log10(abs([W1 W2 W3]))); grid;
legend('beta = 1','beta = 4','beta = 9',3)
title('Three Kaiser Window Responses')
xlabel('Normalized Frequency (Nyquist = 1)')
ylabel('Normalized Magnitude (dB)')
0 0.2 0.4 0.6 0.8 1
180
160
140
120
100
80
60
40
20
0
Three Kaiser Window Responses
Normalized Frequency (Nyquist = 1)
N
o
r
m
a
l
i
z
e
d

M
a
g
n
i
t
u
d
e

(
d
B
)
beta = 1
beta = 4
beta = 9
Wi ndows
4-7
As i ncreases, the si del obe hei ght decreases and the mai nl obe wi dth i ncreases.
To see how the si del obe hei ght stays the same for a fi xed parameter as the
l ength i s vari ed, try
w1 = kaiser(50,4);
w2 = kaiser(20,4);
w3 = kaiser(101,4);
[W1,f] = freqz(w1/sum(w1),1,512,2);
[W2,f] = freqz(w2/sum(w2),1,512,2);
[W3,f] = freqz(w3/sum(w3),1,512,2);
plot(f,20*log10(abs([W1 W2 W3]))); grid;
legend('length = 50','length = 20','length = 101')
title('Three Kaiser Window Responses, Beta Fixed')
xlabel('Normalized Frequency (Nyquist = 1)')
ylabel('Normalized Magnitude (dB)')
0 0.2 0.4 0.6 0.8 1
120
100
80
60
40
20
0
20
Three Kaiser Window Responses, Beta Fixed
Normalized Frequency (Nyquist = 1)
N
o
r
m
a
l
i
z
e
d

M
a
g
n
i
t
u
d
e

(
d
B
)
length = 50
length = 20
length = 101
4 Speci al Topi cs
4-8
Ka iser W indow s in FIR Design
There are two desi gn formul as that can hel p you desi gn FI R fi l ters to meet a
set of fi l ter speci fi cati ons usi ng a Kai ser wi ndow. To achi eve a si del obe hei ght
of dB, the beta parameter i s
For a transi ti on wi dth of rad/s, use the l ength
Fi l ters desi gned usi ng these heuri sti cs wi l l meet the speci fi cati ons
approxi matel y, but you shoul d veri fy thi s. To desi gn a l owpass fi l ter wi th cutoff
frequency rad/s, transi ti on wi dth rad/s, and 40 dB of attenuati on i n
the stopband, try
[n,wn,beta] = kaiserord([0.4 0.6]*pi,[1 0],[0.01 0.01],2*pi);
h = fir1(n,wn,kaiser(n+1,beta),'noscale');
The kaiserord functi on esti mates the fi l ter order, cutoff frequency, and Kai ser
wi ndow beta parameter needed to meet a gi ven set of frequency domai n
speci fi cati ons.
The ri ppl e i n the passband i s roughl y the same as the ri ppl e i n the stopband.
As you can see from the frequency response, thi s fi l ter nearl y meets the
speci fi cati ons.
[H,f] = freqz(h,1,512,2);
plot(f,20*log10(abs(H))), grid

0.1102 8.7 ( ), 50 >


0.5842 21 ( )
0.4
0.07886 21 ( ) + , 50 21
0, 21 <

'

=
n
8
2.285
----------------------- 1 + =
0.5 0.2
Wi ndows
4-9
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
-100
-80
-60
-40
-20
0
20
Normalized Frequency (Nyquist == 1)
M
a
g
n
i
t
u
d
e

(
d
B
)
FIR Design using Kaiser Window
0.2
40 dB
4 Speci al Topi cs
4-10
Chebyshev Window
The Chebyshev wi ndow mi ni mi zes the mai nl obe wi dth, gi ven a parti cul ar
si del obe hei ght. I t i s characteri zed by an equi ri ppl e behavi or, that i s, i ts
si del obes al l have the same hei ght. The chebwin functi on, wi th l ength and
si del obe hei ght parameters, computes a Chebyshev wi ndow.
n = 51;
Rs = 40; % Sidelobe height in decibels
w = chebwin(n,Rs);
stem(w); title('Length 51 Chebyshev Window');
xlabel('Sample Number');
As shown i n the pl ot, the Chebyshev wi ndow has l arge spi kes at i ts outer
sampl es. Pl ot the frequency response to see the equi ri ppl es at -40 dB.
[W,f] = freqz(w,1,512,2);
plot(f,20*log10(abs(W)/sum(w))), grid
title('Chebyshev Window Magnitude Response');
xlabel('Normalized Frequency (Nyquist = 1)');
ylabel('Normalized Magnitude (dB)');
0 5 10 15 20 25 30 35 40 45 50
0
0.2
0.4
0.6
0.8
1
Sample Number
Length 51 Chebyshev Window
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
-80
-60
-40
-20
0
Normalized Frequency (Nyquist == 1)
N
o
r
m
a
i
l
z
e
d

M
a
g
n
i
t
u
d
e

(
d
B
)
Chebyshev Window Magnitude Response
Wi ndows
4-11
For a detai l ed di scussi on of the characteri sti cs and appl i cati ons of the vari ous
wi ndow types, see Oppenhei m and Schafer [2], pgs. 444-462, and Parks and
Burrus [3], pgs. 71-73.
4 Speci al Topi cs
4-12
Parametric Modeling
Parametri c model i ng techni ques fi nd the parameters for a mathemati cal model
descri bi ng a si gnal , system, or process. These techni ques use known
i nformati on about the system to determi ne the model . Appl i cati ons for
parametri c model i ng i ncl ude speech and musi c synthesi s, data compressi on,
hi gh-resol uti on spectral esti mati on, communi cati ons, manufacturi ng, and
si mul ati on.
The tool box parametri c model i ng functi ons operate wi th the rati onal transfer
functi on model . Gi ven appropri ate i nformati on about an unknown system
(i mpul se or frequency response data, or i nput and output sequences), these
functi ons fi nd the coeffi ci ents of a l i near system that model s the system.
One i mportant appl i cati on of the parametri c model i ng functi ons i s i n the
desi gn of fi l ters that have a prescri bed ti me or frequency response. These
functi ons provi de a data-ori ented al ternati ve to the I I R and FI R fi l ter desi gn
functi ons di scussed i n Chapter 2, Fi l ter Desi gn.
Parametri c M odeli ng
4-13
Here i s a summary of the parametri c model i ng functi ons i n thi s tool box. Note
that the System I denti fi cati on Tool box provi des a more extensi ve col l ecti on of
parametri c model i ng functi ons.
Because yulewalk i s geared expl i ci tl y toward ARMA fi l ter desi gn, i t i s
di scussed i n Chapter 2, Fi l ter Desi gn. pburg and pyulear are di scussed i n
Chapter 3, Stati sti cal Si gnal Processi ng, al ong wi th the other
(nonparametri c) spectral esti mati on methods.
Domain Functions Description
Ti me arburg Generate al l -pol e fi l ter coeffi ci ents that model an i nput data
sequence usi ng the Levi nson-Durbi n al gori thm.
arcov Generate al l -pol e fi l ter coeffi ci ents that model an i nput data
sequence by mi ni mi zi ng the forward predi cti on error.
armcov Generate al l -pol e fi l ter coeffi ci ents that model an i nput data
sequence by mi ni mi zi ng the forward and backward predi cti on
errors.
aryule Generate al l -pol e fi l ter coeffi ci ents that model an i nput data
sequence usi ng an esti mate of the autocorrel ati on functi on.
lpc,
levinson
Li near Predi cti ve Codi ng. Generate al l -pol e recursi ve fi l ter whose
i mpul se response matches a gi ven sequence.
prony Generate I I R fi l ter whose i mpul se response matches a gi ven
sequence.
stmcb Fi nd I I R fi l ter whose output, gi ven a speci fi ed i nput sequence,
matches a gi ven output sequence.
Frequency invfreqz,
invfreqs
Generate di gi tal or anal og fi l ter coeffi ci ents gi ven compl ex
frequency response data.
4 Speci al Topi cs
4-14
Time-Domain Based Modeling
The lpc, prony, and stmcb functi ons fi nd the coeffi ci ents of a di gi tal rati onal
transfer functi on that approxi mates a gi ven ti me-domai n i mpul se response.
The al gori thms di ffer i n compl exi ty and accuracy of the resul ti ng model .
Linea r Prediction
Li near predi cti on model i ng assumes that each output sampl e of a si gnal , x(k),
i s a l i near combi nati on of the past n outputs (that i s, i t can be l i nearl y
predi cted from these outputs), and that the coeffi ci ents are constant from
sampl e to sampl e.
An nth-order al l -pol e model of a si gnal x i s
a = lpc(x,n)
To i l l ustrate lpc, create a sampl e si gnal that i s the i mpul se response of an
al l -pol e fi l ter wi th addi ti ve whi te noi se.
randn('state',0);
x = impz(1,[1 0.1 0.1 0.1 0.1],10) + randn(10,1)/10;
The coeffi ci ents for a fourth-order al l -pol e fi l ter that model s the system are
a = lpc(x,4)
a =
1.0000 0.2574 0.1666 0.1203 0.2598
lpc fi rst cal l s xcorr to fi nd a bi ased esti mate of the correl ati on functi on of x,
and then uses the Levi nson-Durbi n recursi on, i mpl emented i n the levinson
functi on, to fi nd the model coeffi ci ents a. The Levi nson-Durbi n recursi on i s a
fast al gori thm for sol vi ng a system of symmetri c Toepl i tz l i near equati ons.
lpcs enti re al gori thm for n = 4 i s
r = xcorr(x);
r(1:length(x)-1) = []; % Remove corr. at negative lags
a = levinson(r,4)
a =
1.0000 0.2574 0.1666 0.1203 0.2598
x k ( ) a 2 ( )x k 1 ( ) a 3 ( )x k 2 ( ) a n 1 + ( )x k n ( ) =
Parametri c M odeli ng
4-15
You coul d form the l i near predi cti on coeffi ci ents wi th other assumpti ons by
passi ng a di fferent correl ati on esti mate to levinson, such as the bi ased
correl ati on esti mate.
r = xcorr(x,'biased');
r(1:length(x)-1) = []; % Remove corr. at negative lags
a = levinson(r,4)
a =
1.0000 0.2574 0.1666 0.1203 0.2598
Pronys M ethod (ARM A M odeling)
The prony functi on model s a si gnal usi ng a speci fi ed number of pol es and zeros.
Gi ven a sequence x and numerator and denomi nator orders n and m,
respecti vel y, the statement
[b,a] = prony(x,n,m)
fi nds the numerator and denomi nator coeffi ci ents of an I I R fi l ter whose
i mpul se response approxi mates the sequence x.
The prony functi on i mpl ements the method descri bed i n [3] Parks and Burrus
(pgs. 226-228). Thi s method uses a vari ati on of the covari ance method of AR
model i ng to fi nd the denomi nator coeffi ci ents a, and then fi nds the numerator
coeffi ci ents b for whi ch the resul ti ng fi l ters i mpul se response matches exactl y
the fi rst n + 1 sampl es of x. The fi l ter i s not necessari l y stabl e, but i t can
potenti al l y recover the coeffi ci ents exactl y i f the data sequence i s trul y an
autoregressi ve movi ng average (ARMA) process of the correct order.
Note The functi ons prony and stmcb (descri bed next) are more accuratel y
descri bed as ARX model s i n system i denti fi cati on termi nol ogy. ARMA
model i ng assumes noi se onl y at the i nputs, whi l e ARX assumes an external
i nput. prony and stmcb know the i nput si gnal : i t i s an i mpul se for prony and
i s arbi trary for stmcb.
4 Speci al Topi cs
4-16
A model for the test sequence x (from the earl i er lpc exampl e) usi ng a
thi rd-order I I R fi l ter i s
[b,a] = prony(x,3,3)
b =
0.9567 -0.3351 0.1866 -0.3782
a =
1.0000 -0.0716 0.2560 -0.2752
The impz command shows how wel l thi s fi l ters i mpul se response matches the
ori gi nal sequence.
format long
[x impz(b,a,10)]
ans =
0.95674351884718 0.95674351884718
-0.26655843782381 -0.26655843782381
-0.07746676935252 -0.07746676935252
-0.05223235796415 -0.05223235796415
-0.18754713506815 -0.05726777015121
0.15348154656430 -0.01204969926150
0.13986742016521 -0.00057632797226
0.00609257234067 -0.01271681570687
0.03349954614087 -0.00407967053863
0.01086719328209 0.00280486049427
Noti ce that the fi rst four sampl es match exactl y. For an exampl e of exact
recovery, recover the coeffi ci ents of a Butterworth fi l ter from i ts i mpul se
response.
[b,a] = butter(4,.2);
h = impz(b,a,26);
[bb,aa] = prony(h,4,4);
Try thi s exampl e; youl l see that bb and aa match the ori gi nal fi l ter coeffi ci ents
to wi thi n a tol erance of 10
-13
.
Parametri c M odeli ng
4-17
Steiglitz- M cBride M ethod (ARM A M odeling)
The stmcb functi on determi nes the coeffi ci ents for the system b(z)/a(z) gi ven an
approxi mate i mpul se response x, as wel l as the desi red number of zeros and
pol es. Thi s functi on i denti fi es an unknown system based on both i nput and
output sequences that descri be the systems behavi or, or just the i mpul se
response of the system. I n i ts defaul t mode, stmcb works l i ke prony.
[b,a] = stmcb(x,3,3)
b =
0.9567 -0.5181 0.5702 -0.5471
a =
1.0000 -0.2384 0.5234 -0.3065
stmcb al so fi nds systems that match gi ven i nput and output sequences.
y = filter(1,[1 1],x); % Create an output signal.
[b,a] = stmcb(y,x,0,1)
b =
1.0000
a =
1 1
I n thi s exampl e, stmcb correctl y i denti fi es the system used to create y from x.
The Stei gl i tz-McBri de method i s a fast i terati ve al gori thm that sol ves for the
numerator and denomi nator coeffi ci ents si mul taneousl y i n an attempt to
mi ni mi ze the si gnal error between the fi l ter output and the gi ven output
si gnal . Thi s al gori thm usual l y converges rapi dl y, but mi ght not converge i f the
model order i s too l arge. As for prony, stmcbs resul ti ng fi l ter i s not necessari l y
stabl e due to i ts exact model i ng approach.
stmcb provi des control over several i mportant al gori thmi c parameters; modi fy
these parameters i f you are havi ng troubl e model i ng the data. To change the
number of i terati ons from the defaul t of fi ve and provi de an i ni ti al esti mate for
the denomi nator coeffi ci ents
n = 10; % Number of iterations
a = lpc(x,3); % Initial estimates for denominator
[b,a] = stmcb(x,3,3,n,a);
4 Speci al Topi cs
4-18
The functi on uses an al l -pol e model created wi th prony as an i ni ti al esti mate
when you do not provi de one of your own.
To compare the functi ons lpc, prony, and stmcb, compute the si gnal error i n
each case.
a1 = lpc(x,3);
[b2,a2] = prony(x,3,3);
[b3,a3] = stmcb(x,3,3);
[x-impz(1,a1,10) x-impz(b2,a2,10) x-impz(b3,a3,10)]
ans =
-0.0433 0 -0.0000
-0.0240 0 0.0234
-0.0040 0 -0.0778
-0.0448 -0.0000 0.0498
-0.2130 -0.1303 -0.0742
0.1545 0.1655 0.1270
0.1426 0.1404 0.1055
0.0068 0.0188 0.0465
0.0329 0.0376 0.0530
0.0108 0.0081 -0.0162
sum(ans.^2)
ans =
0.0953 0.0659 0.0471
I n compari ng model i ng capabi l i ti es for a gi ven order I I R model , the l ast resul t
shows that for thi s exampl e, stmcb performs best, fol l owed by prony, then lpc.
Thi s rel ati ve performance i s typi cal of the model i ng functi ons.
Parametri c M odeli ng
4-19
Frequency-Domain Based Modeling
The invfreqs and invfreqz functi ons i mpl ement the i nverse operati ons of
freqs and freqz; they fi nd an anal og or di gi tal transfer functi on of a speci fi ed
order that matches a gi ven compl ex frequency response. Though the fol l owi ng
exampl es demonstrate invfreqz, the di scussi on al so appl i es to invfreqs.
To recover the ori gi nal fi l ter coeffi ci ents from the frequency response of a
si mpl e di gi tal fi l ter
[b,a] = butter(4,0.4) % Design Butterworth lowpass
b =
0.0466 0.1863 0.2795 0.1863 0.0466
a =
1.0000 -0.7821 0.6800 -0.1827 0.0301
[h,w] = freqz(b,a,64); % Compute frequency response
[bb,aa] = invfreqz(h,w,4,4) % Model: n = 4, m = 4
bb =
0.0466 0.1863 0.2795 0.1863 0.0466
aa =
1.0000 -0.7821 0.6800 -0.1827 0.0301
The vector of frequenci es w has the uni ts i n rad/sampl e, and the frequenci es
need not be equal l y spaced. invfreqz fi nds a fi l ter of any order to fi t the
frequency data; a thi rd-order exampl e i s
[bb,aa] = invfreqz(h,w,3,3) % Find third-order IIR
bb =
0.0464 0.1785 0.2446 0.1276
aa =
1.0000 -0.9502 0.7382 -0.2006
Both invfreqs and invfreqz desi gn fi l ters wi th real coeffi ci ents; for a data
poi nt at posi ti ve frequency f, the functi ons fi t the frequency response at both f
and -f.
4 Speci al Topi cs
4-20
By defaul t invfreqz uses an equati on error method to i denti fy the best model
from the data. Thi s fi nds b and a i n
by creati ng a system of l i near equati ons and sol vi ng them wi th MATLABs \
operator. Here A(w(k)) and B(w(k)) are the Fouri er transforms of the
pol ynomi al s a and b respecti vel y at the frequency w(k), and n i s the number of
frequency poi nts (the l ength of h and w). wt(k) wei ghts the error rel ati ve to the
error at di fferent frequenci es. The syntax
invfreqz(h,w,n,m,wt)
i ncl udes a wei ghti ng vector. I n thi s mode, the fi l ter resul ti ng from invfreqz i s
not guaranteed to be stabl e.
invfreqz provi des a superi or (output-error) al gori thm that sol ves the di rect
probl em of mi ni mi zi ng the wei ghted sum of the squared error between the
actual frequency response poi nts and the desi red response
To use thi s al gori thm, speci fy a parameter for the i terati on count after the
wei ght vector parameter
wt = ones(size(w)); % Create unity weighting vector
[bbb,aaa] = invfreqz(h,w,3,3,wt,30) % 30 iterations
bbb =
0.0464 0.1829 0.2572 0.1549
aaa =
1.0000 -0.8664 0.6630 -0.1614
The resul ti ng fi l ter i s al ways stabl e.
mi n
b a ,
wt k ( ) h k ( )A w k ( ) ( ) B w k ( ) ( )
2
k 1 =
n

mi n
b a ,
wt k ( ) h k ( )
B w k ( ) ( )
A w k ( ) ( )
--------------------
2
k 1 =
n

Parametri c M odeli ng
4-21
Graphi cal l y compare the resul ts of the fi rst and second al gori thms to the
ori gi nal Butterworth fi l ter.
[H1,w] = freqz(b,a);
[H2] = freqz(bb,aa);
[H3] = freqz(bbb,aaa);
s.plot = 'mag';
s.xunits = 'rad/sample';
s.yunits = 'linear';
freqzplot([H1 H2 H3],w);
legend('Original','First Estimate','Second Estimate',3);
grid on
To veri fy the superi ori ty of the fi t numeri cal l y, type
sum(abs(h-freqz(bb,aa,w)).^2) % Total error, algorithm 1
ans =
0.0200
sum(abs(h-freqz(bbb,aaa,w)).^2) % Total error, algorithm 2
ans =
0.0096
0 0.2 0.4 0.6 0.8 1
600
400
200
0
Normalized Frequency ( rad/sample)
P
h
a
s
e

(
d
e
g
r
e
e
s
)
0 0.2 0.4 0.6 0.8 1
300
200
100
0
100
Normalized Frequency ( rad/sample)
M
a
g
n
i
t
u
d
e

(
d
B
)
Original
First Estimate
Second Estimate
4 Speci al Topi cs
4-22
Resampling
The tool box provi des a number of functi ons that resampl e a si gnal at a hi gher
or l ower rate.
The resample functi on changes the sampl i ng rate for a sequence to any rate
that i s a rati o of two i ntegers. The basi c syntax for resample i s
y = resample(x,p,q)
where the functi on resampl es the sequence x at p/q ti mes the ori gi nal
sampl i ng rate. The l ength of the resul t y i s p/q ti mes the l ength of x.
One resampl i ng appl i cati on i s the conversi on of di gi ti zed audi o si gnal s from
one sampl i ng rate to another, such as from 48 kHz (the di gi tal audi o tape
standard) to 44.1 kHz (the compact di sc standard). I n the next exampl e, the
sampl i ng rates are di fferent but the i dea i s the same.
The exampl e fi l e contai ns a l ength 4001 vector of speech sampl ed at 7418 Hz.
clear
load mtlb
whos
Name Size Bytes Class
Fs 1x1 8 double array
mtlb 4001x1 32008 double array
Grand total is 4002 elements using 32016 bytes
Operation Function
Appl y FI R fi l ter wi th resampl i ng upfirdn
Cubi c spl i ne i nterpol ati on spline
Deci mati on decimate
I nterpol ati on interp
Other 1-D i nterpol ati on interp1
Resampl e at new rate resample
Resampli ng
4-23
Fs
Fs =
7418
To pl ay thi s speech si gnal on a workstati on that can onl y pl ay sound at
8192 Hz, use the rat functi on to fi nd i ntegers p and q that yi el d the correct
resampl i ng factor.
[p,q] = rat(8192/Fs,0.0001)
p =
127
q =
115
Si nce p/q*Fs = 8192.05 Hz, the tol erance of 0.0001 i s acceptabl e; to resampl e
the si gnal at very cl ose to 8192 Hz.
y = resample(mtlb,p,q);
resample appl i es a l owpass fi l ter to the i nput sequence to prevent al i asi ng
duri ng resampl i ng. I t desi gns thi s fi l ter usi ng the firls functi on wi th a Kai ser
wi ndow. The syntax
resample(x,p,q,l,beta)
control s the fi l ters l ength and the beta parameter of the Kai ser wi ndow.
Al ternati vel y, use the functi on intfilt to desi gn an i nterpol ati on fi l ter b and
use i t wi th
resample(x,p,q,b)
The decimate and interp functi ons do the same thi ng as resample wi th p = 1
and q = 1, respecti vel y. These functi ons provi de di fferent anti -al i as fi l teri ng
opti ons, and they i ncur a sl i ght si gnal del ay due to fi l teri ng. The interp
functi on i s si gni fi cantl y l ess effi ci ent than the resample functi on wi th q = 1.
The tool box al so contai ns a functi on, upfirdn, that appl i es an FI R fi l ter to an
i nput sequence and outputs the fi l tered sequence at a di fferent sampl e rate
than i ts ori gi nal rate. See Mul ti rate Fi l ter Bank I mpl ementati on on page
1-20.
The standard MATLAB envi ronment contai ns a functi on, spline, that works
wi th i rregul arl y spaced data. The MATLAB functi on interp1 performs
4 Speci al Topi cs
4-24
i nterpol ati on, or tabl e l ookup, usi ng vari ous methods i ncl udi ng l i near and
cubi c i nterpol ati on.
C epstrum Analysi s
4-25
Cepstrum Analysis
Cepstrum anal ysi s i s a nonl i near si gnal processi ng techni que wi th a vari ety of
appl i cati ons i n areas such as speech and i mage processi ng. The Si gnal
Processi ng Tool box provi des three functi ons for cepstrum anal ysi s.
The compl ex cepstrum for a sequence x i s cal cul ated by fi ndi ng the compl ex
natural l ogari thm of the Fouri er transform of x, then the i nverse Fouri er
transform of the resul ti ng sequence.
The tool box functi on cceps performs thi s operati on, esti mati ng the compl ex
cepstrum for an i nput sequence. I t returns a real sequence the same si ze as the
i nput sequence.
xhat = cceps(x)
The compl ex cepstrum transformati on i s central to the theory and appl i cati on
of homomorphic systems, that i s, systems that obey certai n general rul es of
superposi ti on. See Oppenhei m and Schafer [2] for a di scussi on of the compl ex
cepstrum and homomorphi c transformati ons, wi th detai l s on speech processi ng
appl i cati ons.
Try usi ng cceps i n an echo detecti on appl i cati on. Fi rst, create a 45 Hz si ne
wave sampl ed at 100 Hz.
t = 0:0.01:1.27;
s1 = sin(2*pi*45*t);
Operation Function
Compl ex cepstrum cceps
I nverse compl ex cepstrum icceps
Real cepstrum rceps
x

1
2
------ X e
j
( ) [ ] l og e
j n
d

=
4 Speci al Topi cs
4-26
Add an echo of the si gnal , wi th hal f the ampl i tude, 0.2 seconds after the
begi nni ng of the si gnal .
s2 = s1 + 0.5*[zeros(1,20) s1(1:108)];
The compl ex cepstrum of thi s new si gnal i s
c = cceps(s2);
plot(t,c)
Note that the compl ex cepstrum shows a peak at 0.2 seconds, i ndi cati ng the
echo.
The real cepstrum of a si gnal x, someti mes cal l ed si mpl y the cepstrum, i s
cal cul ated by determi ni ng the natural l ogari thm of magni tude of the Fouri er
transform of x, then obtai ni ng the i nverse Fouri er transform of the resul ti ng
sequence.
0 0.2 0.4 0.6 0.8 1 1.2 1.4
-1.5
-1
-0.5
0
0.5
1
c
x
1
2
------ X e
j
( ) l og e
j n
d

=
C epstrum Analysi s
4-27
The tool box functi on rceps performs thi s operati on, returni ng the real
cepstrum for a sequence x. The returned sequence i s a real -val ued vector the
same si ze as the i nput vector.
y = rceps(x)
By defi ni ti on, you cannot reconstruct the ori gi nal sequence from i ts real
cepstrum transformati on, as the real cepstrum i s based onl y on the magni tude
of the Fouri er transform for the sequence (see Oppenhei m and Schafer [2]). The
rceps functi on, however, can reconstruct a mi ni mum-phase versi on of the
ori gi nal sequence by appl yi ng a wi ndowi ng functi on i n the cepstral domai n. To
obtai n both the real cepstrum and the mi ni mum phase reconstructi on for a
sequence, use
[y,ym] = rceps(x)
where y i s the real cepstrum and ym i s the mi ni mum phase reconstructi on of x.
Inverse Complex Cepstrum
To i nvert the compl ex cepstrum, use the icceps functi on. I nversi on i s
compl i cated by the fact that the cceps functi on performs a data dependent
phase modi fi cati on so that the unwrapped phase of i ts i nput i s conti nuous at
zero frequency. The phase modi fi cati on i s equi val ent to an i nteger del ay. Thi s
del ay term i s returned by cceps i f you ask for a second output. For exampl e,
x = 1:10;
[xh,nd] = cceps(x)
xh =
Columns 1 through 7
2.2428 -0.0420 -0.0210 0.0045 0.0366 0.0788 0.1386
Columns 8 through 10
0.2327 0.4114 0.9249
nd =
1
4 Speci al Topi cs
4-28
To i nvert the compl ex cepstrum, use icceps wi th the ori gi nal del ay parameter.
icceps(xh,nd)
ans =
Columns 1 through 7
1.0000 2.0000 3.0000 4.0000 5.0000 6.0000 7.0000
Columns 8 through 10
8.0000 9.0000 10.0000
Note Wi th any modi fi cati on of the compl ex cepstrum, the ori gi nal del ay term
may no l onger be val i d. Use the icceps functi on wi th care.
FFT-Based Ti me-Frequency Analysi s
4-29
FFT-Based Time-Frequency Analysis
The Si gnal Processi ng Tool box provi des a functi on, specgram, that returns the
ti me-dependent Fouri er transform for a sequence, or di spl ays thi s i nformati on
as a spectrogram. The Tool box al so i ncl ues a spectrogram demo. The
time-dependent Fourier transform i s the di screte-ti me Fouri er transform for a
sequence, computed usi ng a sl i di ng wi ndow. Thi s form of the Fouri er
transform, al so known as the short-ti me Fouri er transform (STFT), has
numerous appl i cati ons i n speech, sonar, and radar processi ng. The
spectrogram of a sequence i s the magni tude of the ti me-dependent Fouri er
transform versus ti me.
To di spl ay the spectrogram of a l i near FM si gnal
fs = 10000;
t = 0:1/fs:2;
x = vco(sawtooth(2*pi*t,.75),[0.1 0.4]*fs,fs);
specgram(x,512,fs,kaiser(256,5),220)
Note that the spectrogram di spl ay i s an i mage, not a pl ot.
Time
F
r
e
q
u
e
n
c
y
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8
0
500
1000
1500
2000
2500
3000
3500
4000
4500
5000
4 Speci al Topi cs
4-30
Median Filtering
The functi on medfilt1 i mpl ements one-di mensi onal medi an fi l teri ng, a
nonl i near techni que that appl i es a sl i di ng wi ndow to a sequence. The medi an
fi l ter repl aces the center val ue i n the wi ndow wi th the medi an val ue of al l the
poi nts wi thi n the wi ndow [4]. I n computi ng thi s medi an, medfilt1 assumes
zeros beyond the i nput poi nts.
When the number of el ements n i n the wi ndow i s even, medfilt1 sorts the
numbers, then takes the average of the (n-1)/2 and (n-1)/2 + 1 el ements.
Two si mpl e exampl es wi th fourth- and thi rd-order medi an fi l ters are
medfilt1([4 3 5 2 8 9 1],4)
ans =
1.500 3.500 3.500 4.000 6.500 5.000 4.500
medfilt1([4 3 5 2 8 9 1],3)
ans =
3 4 3 5 8 8 1
See the medfilt2 functi on i n the I mage Processing Toolbox Users Guide for
i nformati on on two-di mensi onal medi an fi l teri ng.
C ommuni cati onsAppli cati ons
4-31
Communications Applications
The tool box provi des three functi ons for communi cati ons si mul ati on.
Modulation vari es the ampl i tude, phase, or frequency of a carrier signal wi th
reference to a message signal. The modulate functi on modul ates a message
si gnal wi th a speci fi ed modul ati on method.
The basi c syntax for the modulate functi on i s
y = modulate(x,fc,fs,'method',opt)
where:
x i s the message si gnal .
fc i s the carri er frequency.
fs i s the sampl i ng frequency.
method i s a fl ag for the desi red modul ati on method.
opt i s any addi ti onal argument that the method requi res. (Not al l
modul ati on methods requi re an opti on argument.)
The tabl e bel ow summari zes the modul ati on methods provi ded; see the
documentati on for modulate, demod, and vco for compl ete detai l s on each.
Operation Function
Modul ati on modulate
Demodul ati on demod
Vol tage control l ed osci l l ati on vco
Method Description
amdsb-sc or am Ampl i tude modul ati on, doubl e si de-band, suppressed
carri er
amdsb-tc Ampl i tude modul ati on, doubl e si de-band, transmi tted
carri er
4 Speci al Topi cs
4-32
I f the i nput x i s an array rather than a vector, modulate modul ates each
col umn of the array.
To obtai n the ti me vector that modulate uses to compute the modul ated si gnal ,
speci fy a second output parameter.
[y,t] = modulate(x,fc,fs,'method',opt)
The demod functi on performs demodulation, that i s, i t obtai ns the ori gi nal
message si gnal from the modul ated si gnal .
The syntax for demod i s
x = demod(y,fc,fs,'method',opt)
demod uses any of the methods shown for modulate, but the syntax for
quadrature ampl i tude demodul ati on requi res two output parameters.
[X1,X2] = demod(y,fc,fs,'qam')
I f the i nput y i s an array, demod demodul ates al l col umns.
Try modul ati ng and demodul ati ng a si gnal . A 50 Hz si ne wave sampl ed at
1000 Hz i s
t = (0:1/1000:2);
x = sin(2*pi*50*t);
amssb Ampl i tude modul ati on, si ngl e si de-band
fm Frequency modul ati on
pm Phase modul ati on
ppm Pul se posi ti on modul ati on
pwm Pul se wi dth modul ati on
qam Quadrature ampl i tude modul ati on
Method Description
C ommuni cati onsAppli cati ons
4-33
Wi th a carri er frequency of 200 Hz, the modul ated and demodul ated versi ons
of thi s si gnal are
y = modulate(x,200,1000,'am');
z = demod(y,200,1000,'am');
To pl ot porti ons of the ori gi nal , modul ated, and demodul ated si gnal
figure; plot(t(1:150),x(1:150)); title('Original Signal');
figure; plot(t(1:150),y(1:150)); title('Modulated Signal');
figure; plot(t(1:150),z(1:150)); title('Demodulated Signal');
Note The demodul ated si gnal i s attenuated because demodul ati on i ncl udes
two steps: mul ti pl i cati on and l owpass fi l teri ng. The mul ti pl i cati on produces a
component wi th frequency centered at 0 Hz and a component wi th frequency
at twi ce the carri er frequency. The fi l teri ng removes the hi gher frequency
component of the si gnal , produci ng the attenuated resul t.
0 0.02 0.04 0.06 0.08 0.1 0.12 0.14 0.16
1
0.8
0.6
0.4
0.2
0
0.2
0.4
0.6
0.8
1
Original Signal
0 0.02 0.04 0.06 0.08 0.1 0.12 0.14 0.16
1
0.8
0.6
0.4
0.2
0
0.2
0.4
0.6
0.8
1
Modulated Signal
0 0.02 0.04 0.06 0.08 0.1 0.12 0.14 0.16
0.8
0.6
0.4
0.2
0
0.2
0.4
0.6
Demodulated Signal
4 Speci al Topi cs
4-34
The vol tage control l ed osci l l ator functi on vco creates a si gnal that osci l l ates at
a frequency determi ned by the i nput vector. The basi c syntax for vco i s
y = vco(x,fc,fs)
where fc i s the carri er frequency and fs i s the sampl i ng frequency.
To scal e the frequency modul ati on range, use
y = vco(x,[Fmin Fmax],fs)
I n thi s case, vco scal es the frequency modul ati on range so val ues of x on the
i nterval [-1 1] map to osci l l ati ons of frequency on [Fmin Fmax].
I f the i nput x i s an array, vco produces an array whose col umns osci l l ate
accordi ng to the col umns of x.
See FFT-Based Ti me-Frequency Anal ysi s on page 4-29 for an exampl e usi ng
the vco functi on.
Deconvoluti on
4-35
Deconvolution
Deconvolution, or pol ynomi al di vi si on, i s the i nverse operati on of convol uti on.
Deconvol uti on i s useful i n recoveri ng the i nput to a known fi l ter, gi ven the
fi l tered output. Thi s method i s very sensi ti ve to noi se i n the coeffi ci ents,
however, so use cauti on i n appl yi ng i t.
The syntax for deconv i s
[q,r] = deconv(b,a)
where b i s the pol ynomi al di vi dend, a i s the di vi sor, q i s the quoti ent, and r i s
the remai nder.
To try deconv, fi rst convol ve two si mpl e vectors a and b (see Chapter 1, Si gnal
Processi ng Basi cs, for a descri pti on of the convol uti on functi on).
a = [1 2 3];
b = [4 5 6];
c = conv(a,b)
c =
4 13 28 27 18
Now use deconv to deconvol ve b from c.
[q,r] = deconv(c,a)
q =
4 5 6
r =
0 0 0 0 0
4 Speci al Topi cs
4-36
Specialized Transforms
I n addi ti on to the di screte Fouri er transform (DFT) descri bed i n Chapter 1,
Si gnal Processi ng Basi cs, the Si gnal Processi ng Tool box and the MATLAB
envi ronment together provi de the fol l owi ng transform functi ons:
The chi rp z-transform (CZT), useful i n eval uati ng the z-transform al ong
contours other than the uni t ci rcl e. The chi rp z-transform i s al so more
effi ci ent than the DFT al gori thm for the computati on of pri me-l ength
transforms, and i t i s useful i n computi ng a subset of the DFT for a sequence.
The di screte cosi ne transform (DCT), cl osel y rel ated to the DFT. The DCTs
energy compacti on properti es are useful for appl i cati ons l i ke si gnal codi ng.
The Hi l bert transform, whi ch faci l i tates the formati on of the anal yti c si gnal .
The anal yti c si gnal i s useful i n the area of communi cati ons, parti cul arl y i n
bandpass si gnal processi ng.
Chirp z-Transform
The chi rp z-transform, or CZT, computes the z-transform al ong spi ral contours
i n the z-pl ane for an i nput sequence. Unl i ke the DFT, the CZT i s not
constrai ned to operate al ong the uni t ci rcl e, but can eval uate the z-transform
al ong contours descri bed by
where A i s the compl ex starti ng poi nt, W i s a compl ex scal ar descri bi ng the
compl ex rati o between poi nts on the contour, and M i s the l ength of the
transform.
One possi bl e spi ral i s
A = 0.8*exp(j*pi/6);
W = 0.995*exp(-j*pi*.05);
M = 91;
z = A*(W.^(-(0:M-1)));
zplane([],z.')
z
l
AW
l
l 0 M 1 , , = , =
Speci ali zed Transforms
4-37
czt(x,M,W,A) computes the z-transform of x on these poi nts.
An i nteresti ng and useful spi ral set i s m evenl y spaced sampl es around the uni t
ci rcl e, parameteri zed by A = 1 and W = exp(-j*pi/M). The z-transform on thi s
contour i s si mpl y the DFT, obtai ned by
y = czt(x)
czt may be faster than the fft functi on for computi ng the DFT of sequences
wi th certai n odd l engths, parti cul arl y l ong pri me-l ength sequences.
-1.5 -1 -0.5 0 0.5 1 1.5
-1
-0.5
0
0.5
1
Real part
I
m
a
g
i
n
a
r
y

p
a
r
t
4 Speci al Topi cs
4-38
Discrete Cosine Transform
The tool box functi on dct computes the uni tary di screte cosi ne transform, or
DCT, for an i nput vector or matri x. Mathemati cal l y, the uni tary DCT of an
i nput sequence x i s
where
The DCT i s cl osel y rel ated to the di screte Fouri er transform; the DFT i s
actual l y one step i n the computati on of the DCT for a sequence. The DCT,
however, has better energy compaction properti es, wi th just a few of the
transform coeffi ci ents representi ng the majori ty of the energy i n the sequence.
The energy compacti on properti es of the DCT make i t useful i n appl i cati ons
such as data communi cati ons.
The functi on idct computes the i nverse DCT for an i nput sequence,
reconstructi ng a si gnal from a compl ete or parti al set of DCT coeffi ci ents. The
i nverse di screte cosi ne transform i s
where
y k ( ) w k ( ) x n ( )
2n 1 ( ) k 1 ( )
2N
------------------------------------------- cos
n 1 =
N

k 1 N , , = , =
w k ( )
1
N
--------- k 1 = ,
2
N
---- 2 k N ,

'

=
x n ( ) w n ( ) y k ( )
2n 1 ( ) k 1 ( )
2N
------------------------------------------- cos
k 1 =
N

n 1 N , , = , =
w n ( )
1
N
--------- n 1 = ,
2
N
---- 2 n N ,

'

=
Speci ali zed Transforms
4-39
Because of the energy compacti on menti oned above, i t i s possi bl e to reconstruct
a si gnal from onl y a fracti on of i ts DCT coeffi ci ents. For exampl e, generate a
25 Hz si nusoi dal sequence, sampl ed at 1000 Hz.
t = (0:1/999:1);
x = sin(2*pi*25*t);
Compute the DCT of thi s sequence and reconstruct the si gnal usi ng onl y those
components wi th val ue greater than 0.1 (64 of the ori gi nal 1000 DCT
coeffi ci ents).
y = dct(x) % Compute DCT
y2 = find(abs(y) < 0.9); % Use 17 coefficients
y(y2) = zeros(size(y2)); % Zero out points < 0.9
z = idct(y); % Reconstruct signal using inverse DCT
Pl ot the ori gi nal and reconstructed sequences.
subplot(2,1,1); plot(t,x);
title('Original Signal')
subplot(2,1,2); plot(t,z), axis([0 1 -1 1])
title('Reconstructed Signal')
0 0.2 0.4 0.6 0.8 1
1
0.5
0
0.5
1
Original Signal
0 0.2 0.4 0.6 0.8 1
1
0.5
0
0.5
1
Reconstructed Signal
4 Speci al Topi cs
4-40
One measure of the accuracy of the reconstructi on i s
norm(x-z)/norm(x)
that i s, the norm of the di fference between the ori gi nal and reconstructed
si gnal s, di vi ded by the norm of the ori gi nal si gnal . I n thi s case, the rel ati ve
error of reconstructi on i s 0.1443. The reconstructed si gnal retai ns
approxi matel y 85% of the energy i n the ori gi nal si gnal .
Hilbert Transform
The tool box functi on hilbert computes the Hi l bert transform for a real i nput
sequence x and returns a compl ex resul t of the same l ength
y = hilbert(x)
where the real part of y i s the ori gi nal real data and the i magi nary part i s the
actual Hi l bert transform. y i s someti mes cal l ed the analytic signal, i n reference
to the conti nuous-ti me anal yti c si gnal . A key property of the di screte-ti me
anal yti c si gnal i s that i ts z-transform i s 0 on the l ower hal f of the uni t ci rcl e.
Many appl i cati ons of the anal yti c si gnal are rel ated to thi s property; for
exampl e, the anal yti c si gnal i s useful i n avoi di ng al i asi ng effects for bandpass
sampl i ng operati ons. The magni tude of the anal yti c si gnal i s the compl ex
envel ope of the ori gi nal si gnal .
The Hi l bert transform i s rel ated to the actual data by a 90 phase shi ft; si nes
become cosi nes and vi ce versa. To pl ot a porti on of data (sol i d l i ne) and i ts
Hi l bert transform (dotted l i ne)
t = (0:1/1023:1);
x = sin(2*pi*60*t);
y = hilbert(x);
plot(t(1:50),real(y(1:50))), hold on
plot(t(1:50),imag(y(1:50)),':'), hold off
Speci ali zed Transforms
4-41
The anal yti c si gnal i s useful i n cal cul ati ng instantaneous attributes of a ti me
seri es, the attri butes of the seri es at any poi nt i n ti me. The i nstantaneous
ampl i tude of the i nput sequence i s the ampl i tude of the anal yti c si gnal . The
i nstantaneous phase angl e of the i nput sequence i s the (unwrapped) angle of
the anal yti c si gnal ; the i nstantaneous frequency i s the ti me rate of change of
the i nstantaneous phase angl e. You can cal cul ate the i nstantaneous frequency
usi ng the MATLAB functi on, diff.
0 0.01 0.02 0.03 0.04 0.05
-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
4 Speci al Topi cs
4-42
Selected Bibliography
[1] Kay, S.M. Modern Spectral Estimation. Engl ewood Cl i ffs, NJ: Prenti ce Hal l ,
1988.
[2] Oppenhei m, A.V., and R.W. Schafer. Discrete-Time Signal Processing.
Engl ewood Cl i ffs, NJ: Prenti ce Hal l , 1989.
[3] Parks, T.W., and C.S. Burrus. Digital Filter Design. New York: John Wi l ey
& Sons, 1987.
[4] Pratt,W.K. Digital I mage Processing. New York: John Wi l ey & Sons, 1991.

5
Fi l ter Desi gn and Anal ysi s
Tool
Overview . . . . . . . . . . . . . . . . . . . . . 5-2
Opening the Filter Design and Analysis Tool . . . . . 5-6
Choosing a Filter Type . . . . . . . . . . . . . . . 5-7
Choosing a Filter Design Method . . . . . . . . . . 5-8
Setting the Filter Design Specifications . . . . . . . 5-9
Computing the Filter Coefficients . . . . . . . . . . 5-12
Analyzing the Filter . . . . . . . . . . . . . . . . 5-13
Converting the Filter Structure . . . . . . . . . . . 5-15
Importing a Filter Design . . . . . . . . . . . . . . 5-17
Exporting a Filter Design . . . . . . . . . . . . . . 5-21
Saving and Opening Filter Design Sessions . . . . . . 5-25
5 Fi lter Desi gn and Analysi s Tool
5-2
Overview
Note The Fi l ter Desi gn and Anal ysi s Tool (FDATool ) requi res resol uti on
greater than 640 x 480.
The Filter Design and Analysis Tool (FDATool) i s a powerful user i nterface for
desi gni ng and anal yzi ng fi l ters. FDATool enabl es you to qui ckl y desi gn di gi tal
FI R or I I R fi l ters by setti ng fi l ter performance speci fi cati ons, by i mporti ng
fi l ters from your MATLAB workspace, or by di rectl y speci fyi ng fi l ter
coeffi ci ents. FDATool al so provi des tool s for anal yzi ng fi l ters, such as
magni tude and phase response pl ots and pol e-zero pl ots. You can use FDATool
as a conveni ent al ternati ve to the command l i ne fi l ter desi gn functi ons. Thi s
chapter contai ns the fol l owi ng secti ons, whi ch wal k you through a typi cal fi l ter
desi gn sessi on usi ng the FDATool :
Openi ng the Fi l ter Desi gn and Anal ysi s Tool
Choosi ng a Fi l ter Type
Choosi ng a Fi l ter Type
Choosi ng a Fi l ter Desi gn Method
Setti ng the Fi l ter Desi gn Speci fi cati ons
Computi ng the Fi l ter Coeffi ci ents
Anal yzi ng the Fi l ter
Converti ng the Fi l ter Structure
I mporti ng a Fi l ter Desi gn
Exporti ng a Fi l ter Desi gn
Savi ng and Openi ng Fi l ter Desi gn Sessi ons
Bel ow i s a bri ef i ntroducti on to the FDATool that wi l l gi ve you a better
understandi ng of how i t can be used.
5-3
Note I f you have i nstal l ed external hardware or targets that i nteract wi th
FDATool , you may see addi ti onal opti ons i n FDATool . Refer to the speci fi c
hardware or target manual for i nformati on on these opti ons.
These tool boxes/targets are i ntegrated wi th FDATool .
Fi l ter Desi gn Tool box
Devel oper's Ki t for Texas I nstruments DSP
Filter Design Methods
The tool gi ves you access to al l of the fi l ter desi gn methods i n the Si gnal
Processi ng Tool box:
Butterworth (butter)
Chebyshev Type I (cheby1)
Chebyshev Type I I (cheby2)
El l i pti c (ellip)
Equi ri ppl e (remez)
Least squares (firls)
Wi ndows
- Bartl ett-Hanni ng (barthannwin)
- Bartl ett (bartlett)
- Bl ackman (blackman)
- Bl ackman-Harri s (blackmanharris)
- Bohman (bohmanwin)
- Chebyshev (chebwin)
- Gaussi an (gausswin)
- Hammi ng (hamming)
- Hann (hann)
- Kai ser (kaiser)
- Nuttal l s Bl ackman-Harri s (nuttallwin)
- Rectangul ar (rectwin)
5 Fi lter Desi gn and Analysi s Tool
5-4
- Tapered cosi ne (tukeywin)
- Tri angul ar (triang)
You can i mpl ement any of these wi ndows manual l y usi ng fir1 or fir2.
Addi ti onal fi l ter desi gn methods are avai l abl e to users of the Fi l ter Desi gn
Tool box.
Using the Filter Design and Analysis Tool
There are di fferent ways that you can desi gn fi l ters usi ng the Fi l ter Desi gn and
Anal ysi s Tool . For exampl e:
You can fi rst choose a fi l ter type, such as bandpass, and then choose from the
avai l abl e FI R or I I R fi l ter desi gn methods.
You can speci fy the fi l ter by i ts type al one, al ong wi th certai n frequency- or
ti me-domai n speci fi cati ons such as passband frequenci es and stopband
frequenci es. The fi l ter you desi gn i s then computed usi ng the defaul t fi l ter
desi gn method and fi l ter order.
Analyzing Filter Responses
Once you have desi gned your fi l ter, you can anal yze di fferent fi l ter responses
i n FDATool or i n a separate Fi l ter Vi sual i zati on Tool (fvtool):
Magni tude response (freqz)
Phase response (freqz)
Pol e-zero pl ots (zplane)
I mpul se response (impz)
Group del ay (grpdelay)
Step response
You can al so di spl ay the fi l ter coeffi ci ents, export the coeffi ci ents to the
MATLAB workspace, and create a C header fi l e contai ni ng the coeffi ci ents.
Filter Design and Analysis Tool Modes
The Fi l ter Desi gn and Anal ysi s Tool operates i n two modes:
Design mode. I n thi s mode, you can:
5-5
- Desi gn fi l ters from scratch.
- Modi fy exi sti ng fi l ters desi gned by FDATool .
- Anal yze fi l ters.
I mport mode. I n thi s mode, you can:
- I mport previ ousl y saved fi l ters or fi l ter coeffi ci ents that you have stored i n
the MATLAB workspace.
- Anal yze i mported fi l ters.
I f you al so have the Fi l ter Desi gn Tool box i nstal l ed the addi ti onal quantize
mode i s avai l abl e. Use thi s mode to:
Quanti ze doubl e-preci si on fi l ters that you desi gn i n FDATool .
Quanti ze doubl e-preci si on fi l ters that you i mport i nto FDATool .
Anal yze quanti zed fi l ters.
Getting Help
At any ti me, you can ri ght-cl i ck or press the Whats this? button, , to get
i nformati on on the di fferent parts of the GUI .
5 Fi lter Desi gn and Analysi s Tool
5-6
Opening the Filter Design and Analysis Tool
To open the Fi l ter Desi gn and Anal ysi s Tool , type
fdatool
The Fi l ter Desi gn and Anal ysi s Tool opens i n the defaul t desi gn mode.
Analysis Zoom
Full View
Analysis
Select filter
Select filter
design method
Specify filter order or allow
automaticestimation
Compute filter
coefficients
Set filter specifications (depend on
filter type and design method)
Whats This
help
Display
Region
Print and
Print Preview
Set specifications for
FIRWindowmethod
Filter Parameters
(If Filter Design
Toolbox is installed,
a Quantization box
and Quantization
tab appear here.)
C hoosi ng a Fi lter Type
5-7
Choosing a Filter Type
You can choose from several fi l ter types:
Lowpass
Hi ghpass
Bandpass
Bandstop
Di fferenti ator
Hi l bert transformer
Mul ti band
Arbi trary magni tude
Arbi trary group del ay
Rai sed cosi ne
To desi gn a bandpass fi l ter, sel ect the radi o button next to Bandpass i n the
Filter Type regi on of the GUI .
Note Not al l fi l ter desi gn methods are avai l abl e for al l fi l ter types. Once you
choose your fi l ter type, thi s may restri ct the fi l ter desi gn methods avai l abl e to
you. Fi l ter desi gn methods that are not avai l abl e for a sel ected fi l ter type are
di mmed i n the Method menu, and removed from the Design Method regi on
of the GUI .
You can al so use the Type menu to sel ect a fi l ter type.
5 Fi lter Desi gn and Analysi s Tool
5-8
Choosing a Filter Design Method
You can use the defaul t fi l ter desi gn method for the fi l ter type that youve
sel ected, or you can sel ect a fi l ter desi gn method from the avai l abl e FI R and I I R
methods l i sted i n the GUI .
To sel ect the Remez al gori thm to compute FI R fi l ter coeffi ci ents, sel ect the FIR
radi o button and choose Equiripple from the l i st of methods.
You can al so use the Method menu to sel ect a fi l ter desi gn method.
Setti ng the Fi lter Desi gn Speci fi cati ons
5-9
Setting the Filter Design Specifications
The fi l ter desi gn speci fi cati ons that you can set vary accordi ng to fi l ter type and
desi gn method. For exampl e, to desi gn a bandpass fi l ter, you can enter:
Bandpass Fi l ter Frequency Speci fi cati ons
Bandpass Fi l ter Magni tude Speci fi cati ons
Fi l ter Order
The di spl ay regi on i l l ustrates fi l ter speci fi cati ons when you sel ect Filter
Specifications from the Analysis menu.
Bandpass Filter Frequency Specifications
For a bandpass fi l ter, you can set:
Uni ts of frequency:
- Hz
- kHz
- MHz
- Normal i zed (0 to 1)
Sampl i ng frequency
Passband frequenci es
Stopband frequenci es
5 Fi lter Desi gn and Analysi s Tool
5-10
You speci fy the passband wi th two frequenci es. The fi rst frequency determi nes
the l ower edge of the passband, and the second frequency determi nes the upper
edge of the passband.
Si mi l arl y, you speci fy the stopband wi th two frequenci es. The fi rst frequency
determi nes the upper edge of the fi rst stopband, and the second frequency
determi nes the l ower edge of the second stopband.
For thi s exampl e:
Keep the uni ts i n Hz (defaul t).
Set the sampl i ng frequency (Fs) to 2000 Hz.
Set the end of the fi rst stopband (Fstop1) to 200 Hz.
Set the begi nni ng of the passband (Fpass1) to 300 Hz.
Set the end of the passband (Fpass2) to 700 Hz.
Set the begi nni ng of the second stopband (Fstop2) to 800 Hz.
Bandpass Filter Magnitude Specifications
For a bandpass fi l ter, you can speci fy the fol l owi ng magni tude response
characteri sti cs:
Uni ts for the magni tude response (dB or l i near)
Passband ri ppl e
Stopband attenuati on
Setti ng the Fi lter Desi gn Speci fi cati ons
5-11
For thi s exampl e:
Keep the uni ts i n dB (defaul t).
Set the passband ri ppl e (Apass) to 0.1 dB.
Set the stopband attenuati on for both stopbands (Astop1, Astop2) to 75 dB.
Filter Order
You have two mutual l y excl usi ve opti ons for determi ni ng the fi l ter order when
you desi gn an equi ri ppl e fi l ter
Minimum order: The fi l ter desi gn method determi nes the mi ni mum order
fi l ter.
Specify order: You enter the fi l ter order i n a text box.
Sel ect the Minimum order radi o button for thi s exampl e.
Note that fi l ter order speci fi cati on opti ons depend on the fi l ter desi gn method
you choose. Some fi l ter methods may not have both opti ons avai l abl e.
5 Fi lter Desi gn and Analysi s Tool
5-12
Computing the Filter Coefficients
Now that youve speci fi ed the fi l ter desi gn, sel ect the Design Filter button to
compute the fi l ter coeffi ci ents.
Noti ce that the Design Filter button i s di mmed once youve computed the
coeffi ci ents for your fi l ter desi gn. Thi s button i s enabl ed agai n once you make
any changes to the fi l ter speci fi cati ons.
Analyzi ng the Fi lter
5-13
Analyzing the Filter
Once youve desi gned the fi l ter, you can vi ew the fol l owi ng fi l ter response
characteri sti cs i n the di spl ay regi on or i n a separate wi ndow:
Magni tude response
Phase response
Overl ai d magni tude and phase responses
Group del ay
I mpul se response
Step response
Pol e-zero pl ot
You can al so di spl ay the fi l ter coeffi ci ents i n thi s regi on.
You can access the anal ysi s methods as i tems i n the Analysis menu, or by
usi ng the tool bar buttons.

For exampl e, to l ook at the fi l ters magni tude response, sel ect the Magnitude
Response button on the tool bar.
5 Fi lter Desi gn and Analysi s Tool
5-14
To di spl ay the fi l ter response characteri sti cs i n a separate wi ndow, sel ect
Full ViewAnalysis from the Analysis menu. The Fi l ter Vi sual i zati on Tool
(fvtool) opens. You can use thi s tool to annotate your desi gn, vi ew other fi l ter
anal yses, and pri nt your fi l ter response.
You can cl i ck on the response to add a data marker that di spl ays i nformati on
about the parti cul ar poi nt on the response. Ri ght-cl i cki ng di spl ays a menu
where you can adjust the appearance of the data markers or del ete them.
C onverti ng the Fi lter Structure
5-15
Converting the Filter Structure
You can use the Convert structure button to convert the current fi l ter to a new
structure. Al l fi l ters can be converted to the fol l owi ng representati ons:
Direct form I
Direct form II
Direct form I transposed
Direct form II transposed
State-space
Lattice ARMA
Note I f you have i nstal l ed the Fi l ter Desi gn Tool box you wi l l see addi ti onal
structures i n the Convert structure di al og box.
I n addi ti on, the fol l owi ng conversi ons are avai l abl e for parti cul ar cl asses of
fi l ters:
Mi ni mum phase FI R fi l ters can be converted to Lattice MA (min. phase)
Maxi mum phase FI R fi l ters can be converted to Lattice MA (max. phase)
Al l pass fi l ters can be converted to Lattice allpass
I I R fi l ters can be converted to Lattice ARMA
Note Converti ng from one fi l ter structure to another may produce a resul t
wi th di fferent characteri sti cs than the ori gi nal . Thi s i s due to the computers
fi ni te-preci si on ari thmeti c and the vari ati ons i n the conversi ons round-off
computati ons.
When sel ected, the Use second-order sections check box i nstructs the tool to
store the converted fi l ter structure as a col l ecti on of second-order secti ons
rather than as a monol i thi c hi gher-order structure. The subordi nate Scale
menu l ets you sel ect from the fol l owi ng opti ons.
None (defaul t)
5 Fi lter Desi gn and Analysi s Tool
5-16
L-2 (L
2
norm)
L-infinity (L

norm)
The orderi ng of the second-order secti ons i s opti mi zed for the sel ected scal i ng
opti on. (The tf2sos functi on that performs the conversi on i s cal l ed wi th opti on
'down' for L
2
norm scal i ng, and wi th opti on 'up' for L

norm scal i ng.)


For exampl e:
Press the Convert structure button to open the Convert structure di al og
box.
Sel ect Direct form I i n the l i st of fi l ter structures.
Sel ect the Use second-order sections check box.
Sel ect L-infinity from the Scale menu for L

norm scal i ng.


Importi ng a Fi lter Desi gn
5-17
Importing a Filter Design
The Import Filter regi on al l ows you to i mport a fi l ter by speci fyi ng the fi l ter
coeffi ci ents, ei ther by enteri ng them expl i ci tl y or by referri ng to vari abl es i n
the MATLAB workspace. You can access thi s regi on by sel ecti ng Import Filter
from the Filter menu, or by pressi ng Ctrl+I.
The i mported fi l ter can be i n any of the representati ons l i sted i n the Filter
Structure menu, and descri bed i n Fi l ter Structures.
Sel ect the frequency uni ts from among the fol l owi ng opti ons i n the Units menu,
and speci fy the val ue of the sampl i ng frequency i n the Fs fi el d.
To i mport the fi l ter, press the Import Filter button. The Display Region i s
automati cal l y updated when the new fi l ter has been i mported.
5 Fi lter Desi gn and Analysi s Tool
5-18
Filter Structures
Di rect Form fi l ters
- Direct form I
- Direct form II
- Direct form I transposed
- Direct form II transposed
- Direct form II (Second-order sections)
State-space
Latti ce fi l ters
- Lattica allpass
- Lattice MA min. phase
- Lattice MA max. phase
- Lattice ARMA
Quantized filter (Qfilt object) avai l abl e onl y when Fi l ter Desi gn
Tool box i s i nstal l ed
The structure that you choose determi nes the type of coeffi ci ents that you need
to speci fy i n the text fi el ds to the ri ght.
Direct For m
For Direct Form I, Direct Form II, Direct Form I transposed, and Direct
Form II transposed, speci fy the fi l ter by i ts transfer functi on representati on:
The Numerator fi el d speci fi es a vari abl e name or val ue for the numerator
coeffi ci ent vector b, whi ch contai ns m+1 coeffi ci ents i n descendi ng powers of z.
The Denominator fi el d speci fi es a vari abl e name or val ue for the
denomi nator coeffi ci ent vector a, whi ch contai ns n+1 coeffi ci ents i n
descendi ng powers of z. For FI R fi l ters, the Denominator i s 1.
Fi l ters i n transfer functi on form can be produced by al l of the Si gnal Processi ng
Tool box fi l ter desi gn functi ons (such as fir1, fir2, remez, butter, yulewalk).
See Transfer Functi on on page 1-33 for more i nformati on.
H z ( )
B z ( )
A z ( )
-----------
b 1 ( ) b 2 ( )z
1
L b m 1 + ( )z
m
+ + +
a 1 ( ) a 2 ( )z
1
L a n 1 + ( )z
n
+ + +
--------------------------------------------------------------------------------------- = =
Importi ng a Fi lter Desi gn
5-19
Direct For m II (Second- O rder Sections)
For Direct form II (Second-order sections), speci fy the fi l ter by i ts
second-order secti on representati on:
The Gain fi el d speci fi es a vari abl e name or a val ue for the gai n g, and the SOS
Matrix fi el d speci fi es a vari abl e name or a val ue for the L-by-6 SOS matri x
whose rows contai n the numerator and denomi nator coeffi ci ents b
ik
and a
ik
of
the second-order secti ons of H(z).
Fi l ters i n second-order secti on form can be produced by functi ons such as
tf2sos, zp2sos, ss2sos, and sosfilt. See Second-Order Secti ons (SOS) on
page 1-38 for more i nformati on.
Sta te- Spa ce
For State-Space, speci fy the fi l ter by i ts state-space representati on:
The A, B, C, and D fi el ds each speci fy a vari abl e name or a val ue for the
matri ces i n thi s system.
Fi l ters i n state-space form can be produced by functi ons such as tf2ss and
zp2ss. See State-Space on page 1-35 for more i nformati on.
La ttice
For Lattice allpass, Lattice MA, and Lattice ARMA fi l ters, speci fy the fi l ter
by i ts l atti ce representati on:
H z ( ) g H
k
z ( )
k 1 =
L

g
b
0k
b
1k
z
1
b
2k
z
2
+ +
1 a
1k
z
1
a
2k
z
2
+ +
--------------------------------------------------------- -
k 1 =
L

= =
SOS
b
01
b
11
b
21
1 a
11
a
21
b
02
b
12
b
22
1 a
12
a
22
M M M M M M
b
0L
b
1L
b
2L
1 a
1L
a
2L
=
x

Ax Bu + =
y Cx Du + =
5 Fi lter Desi gn and Analysi s Tool
5-20
For Lattice allpass, the Lattice coeff fi el d speci fi es the l atti ce (refl ecti on)
coeffi ci ents, k(1) to k(N), were N i s the fi l ter order.
For Lattice MA (mi ni mum or maxi mum phase), the Lattice coeff fi el d
speci fi es the l atti ce (refl ecti on) coeffi ci ents, k(1) to k(N), were N i s the fi l ter
order.
For Lattice ARMA, the Lattice coeff fi el d speci fi es the l atti ce (refl ecti on)
coeffi ci ents, k(1) to k(N), and the Ladder coeff fi el d speci fi es the l adder
coeffi ci ents, v(1) to v(N+1), were N i s the fi l ter order.
Fi l ters i n l atti ce form can be produced by tf2latc. See Latti ce Structure on
page 1-38 for more i nformati on.
Q ua ntized Filter (Q filt O bject)
For Quantized filter, speci fy the fi l ter as a Qfi l t object. See qfilt i n the Fi l ter
Desi gn Tool box for more i nformati on.
Exporti ng a Fi lter Desi gn
5-21
Exporting a Filter Design
You can save your fi l ter desi gn by:
Exporti ng Fi l ter Coeffi ci ents to the Workspace
Exporti ng Fi l ter Coeffi ci ents to a Text Fi l e
Exporti ng the fi l ter coeffi ci ents to a MAT-fi l e (see Savi ng and Openi ng Fi l ter
Desi gn Sessi ons)
Creati ng a C header fi l e contai ni ng the coeffi ci ents
Exporting Filter Coefficients to the Workspace
To save fi l ter coeffi ci ents as vari abl es i n the MATLAB workspace
1 Sel ect Export from the File menu. The Export di al og box appears.
2 Sel ect Workspace from the Export To menu.
3 Assi gn vari abl e names usi ng the text boxes i n the Variable Names regi on.
I f you have vari abl es wi th the same names i n your workspace and you want
to overwri te them, check the Overwrite existing variables box.
4 Press the OK button.
5 Fi lter Desi gn and Analysi s Tool
5-22
Exporting Filter Coefficients to a Text File
To save fi l ter coeffi ci ents to a text fi l e
1 Sel ect Export from the File menu. The Export di al og box appears.
2 Sel ect Text-file from the Export To menu.
3 Press the OK button. The Export Filter Coefficients to a Text-file di al og
box appears.
4 Choose a fi l ename and press Save.
The coeffi ci ents are saved i n the text fi l e that you speci fi ed, and the MATLAB
Edi tor opens to di spl ay the fi l e.
Exporting to a C Header File
You may want to i ncl ude fi l ter i nformati on i n an external C program. To create
a C header fi l e wi th vari abl es that contai n fi l ter parameter data, fol l ow thi s
procedure:
1 Sel ect Export to C Header File from the File menu. The Export to C
Header File di al og box appears.
Exporti ng a Fi lter Desi gn
5-23
2 Enter the vari abl e names to be used i n the C header fi l e. The parti cul ar fi l ter
structure determi nes the vari abl es that are created i n the fi l e.
*length vari abl es contai n the total number of coeffi ci ents of that type.
Note Vari abl e names cannot be C l anguage reserved words, such as for.
3 Sel ect the Export Suggested button to use the suggested data type or sel ect
Export As and sel ect the desi red data type from the pul l down and sel ect the
desi red Fractional length.
Filter Structure Variable Parameter
Di rect Form I
Di rect Form I I
Di rect Form I transposed
Di rect Form I I transposed
Numerator, Numerator l ength*,
Denomi nator, Denomi nator l ength*, and
Number of secti ons (i nacti ve i f fi l ter has onl y
one secti on)
Latti ce ARMA Latti ce coeffs, Latti ce coeffs l ength*, Ladder
coeffs, Ladder coeffs l ength*, Number of
secti ons (i nacti ve i f fi l ter has onl y one
secti on)
Latti ce MA Latti ce coeffs, Latti ce coeffs l ength*, and
Number of secti ons (i nacti ve i f fi l ter has onl y
one secti on)
Di rect Form FI R
Di rect Form FI R
transposed
Numerator, Numerator l ength*, and Number
of secti ons (i nacti ve i f fi l ter has onl y one
secti on)
5 Fi lter Desi gn and Analysi s Tool
5-24
Note I f you do not have the Fi l ter Desi gn Tool box i nstal l ed, sel ecti ng any
data type other than doubl e-preci si on fl oati ng poi nt resul ts i n a fi l ter that
does not exactl y match the one you desi gned i n the FDATool . Thi s i s due to
roundi ng and truncati ng di fferences.
4 Cl i ck OK to save the fi l e and cl ose the di al og box or cl i ck Apply to save the
fi l e, but l eave the di al og box open for addi ti onal C header fi l e defi ni ti ons.
Savi ng and O peni ng Fi lter Desi gn Sessi ons
5-25
Saving and Opening Filter Design Sessions
You can save your fi l ter desi gn sessi on as a MAT-fi l e and return to the same
sessi on another ti me.
Sel ect the Save session button to save your sessi on as a MAT-fi l e. The fi rst
ti me you save a sessi on, a Save Filter Design File browser opens, prompti ng
you for a sessi on name.
For exampl e, save thi s desi gn sessi on as TestFilter.fda i n your current
worki ng di rectory by typi ng TestFilter i n the File name fi el d.
The .fda extensi on i s added automati cal l y to al l fi l ter desi gn sessi ons you save.
Note You can al so use the Save session and Save session as menu i tems i n
the File menu to save a sessi on. Thi s di al og opens every ti me you sel ect the
Save As menu i tem.
You can l oad exi sti ng sessi ons i nto the Fi l ter Desi gn and Anal ysi s Tool by
sel ecti ng the Open session button, . A Load Filter Design File browser
opens that al l ows you to sel ect from your previ ousl y saved fi l ter desi gn
sessi ons.
5 Fi lter Desi gn and Analysi s Tool
5-26

6
SPTool : A Si gnal
Processi ng GUI Sui te
Overview . . . . . . . . . . . . . . . . . . . . . 6-2
SPTool: An Interactive Signal Processing Environment 6-3
Opening SPTool . . . . . . . . . . . . . . . . . . 6-5
Getting Help . . . . . . . . . . . . . . . . . . . . 6-7
Overview of the Signal Browser: Signal Analysis . . . 6-8
Overview of the Filter Designer: Filter Design . . . . 6-11
Overview of the Filter Viewer: Filter Analysis . . . . 6-14
Overview of the Spectrum Viewer: Spectral Analysis . 6-17
Using SPTool: Filtering and Analysis of Noise . . . . . 6-20
Exporting Signals, Filters, and Spectra . . . . . . . . 6-32
Accessing Filter Parameters . . . . . . . . . . . . . 6-34
Importing Filters and Spectra into SPTool . . . . . . 6-39
Loading Variables from the Disk . . . . . . . . . . . 6-43
Selecting Signals, Filters, and Spectra in SPTool . . . 6-44
Editing Signals, Filters, or Spectra in SPTool . . . . . 6-45
Designing a Filter with the Pole/Zero Editor . . . . . 6-46
Redesigning a Filter Using the Magnitude Plot . . . . 6-49
6 SPTool: A Si gnal Processi ng G UI Sui te
6-2
Overview
SPTool i s a graphi cal user i nterface (GUI ) for anal yzi ng and mani pul ati ng
di gi tal si gnal s, fi l ters, and spectra. The fi rst few secti ons of thi s chapter gi ve
an overvi ew of SPTool and i ts associ ated GUI s
SPTool : An I nteracti ve Si gnal Processi ng Envi ronment
Openi ng SPTool
Overvi ew of the Si gnal Browser: Si gnal Anal ysi s
Overvi ew of the Fi l ter Desi gner: Fi l ter Desi gn
Overvi ew of the Fi l ter Vi ewer: Fi l ter Anal ysi s
Overvi ew of the Spectrum Vi ewer: Spectral Anal ysi s
Usi ng SPTool : Fi l teri ng and Anal ysi s of Noi se
The rest of thi s chapter i l l ustrates i n detai l how to use the GUI -based
i nteracti ve tool s by wal ki ng through some exampl es
Usi ng SPTool : Fi l teri ng and Anal ysi s of Noi se
I mporti ng a Si gnal i nto SPTool
Desi gni ng a Fi l ter
Appl yi ng a Fi l ter to a Si gnal
Anal yzi ng Si gnal s: Openi ng the Si gnal Browser
Spectral Anal ysi s i n the Spectrum Vi ewer
Exporti ng Si gnal s, Fi l ters, and Spectra
Accessi ng Fi l ter Parameters
Redesi gni ng a Fi l ter Usi ng the Magni tude Pl ot
Accessi ng Parameters i n a Saved Spectrum
I mporti ng Fi l ters and Spectra i nto SPTool
Loadi ng Vari abl es from the Di sk
Sel ecti ng Si gnal s, Fi l ters, and Spectra i n SPTool
Edi ti ng Si gnal s, Fi l ters, or Spectra i n SPTool
Desi gni ng a Fi l ter wi th the Pol e/Zero Edi tor
Maki ng Si gnal Measurements: Usi ng Markers
SPTool: An Interacti ve Si gnal Processi ng Envi ronment
6-3
SPTool: An Interactive Signal Processing Environment
SPTool i s an i nteracti ve GUI for di gi tal si gnal processi ng that can be used to
Anal yze si gnal s.
Desi gn fi l ters.
Anal yze (vi ew) fi l ters.
Fi l ter si gnal s.
Anal yze si gnal spectra.
You can accompl i sh these tasks usi ng four GUI s that you access from wi thi n
SPTool
The Signal Browser i s for anal yzi ng si gnal s. You can al so pl ay porti ons of
si gnal s usi ng your computers audi o hardware.
The Filter Designer i s for desi gni ng or edi ti ng FI R and I I R di gi tal fi l ters.
Most of the Si gnal Processi ng Tool box fi l ter desi gn methods avai l abl e at the
command l i ne are al so avai l abl e i n the Fi l ter Desi gner. Addi ti onal l y, you can
desi gn a fi l ter by usi ng the Pol e/Zero Edi tor to graphi cal l y pl ace pol es and
zeros on the z-pl ane.
The Filter Viewer i s for anal yzi ng fi l ter characteri sti cs. See Overvi ew of the
Fi l ter Vi ewer: Fi l ter Anal ysi s.
The Spectrum Viewer i s for spectral anal ysi s. You can use the Si gnal
Processi ng Tool box spectral esti mati on methods to esti mate the power
spectral densi ty of a si gnal . See Overvi ew of the Spectrum Vi ewer: Spectral
Anal ysi s.
SPTool Data Structures
You can use SPTool to anal yze si gnal s, fi l ters, or spectra that you create at the
MATLAB command l i ne.
You can bri ng si gnal s, fi l ters, or spectra from the MATLAB workspace i nto the
SPTool workspace usi ng the Import i tem under the File menu. Si gnal s, fi l ters,
or spectra that you create i n (or i mport i nto) the SPTool workspace exi st as
MATLAB structures. See the MATLAB documentati on for more i nformati on on
MATLAB structures.
6 SPTool: A Si gnal Processi ng G UI Sui te
6-4
When you use the Export i tem under the File menu to save si gnal s, fi l ters, and
spectra that you create or modi fy i n SPTool , these are al so saved as MATLAB
structures.
O peni ng SPTool
6-5
Opening SPTool
To open SPTool , type
sptool
When you fi rst open SPTool , i t contai ns a col l ecti on of defaul t si gnal s, fi l ters,
and spectra. You can speci fy your own preferences for what si gnal s, fi l ters, and
spectra you want to see when SPTool opens. See Desi gni ng a Fi l ter wi th the
Pol e/Zero Edi tor on page 6-46 for more detai l s.
You can access these three GUI s from SPTool by sel ecti ng a si gnal , fi l ter, or
spectrum and pressi ng the appropri ate View button.
Si gnal Browser
Fi l ter Vi ewer
Spectrum Vi ewer
6 SPTool: A Si gnal Processi ng G UI Sui te
6-6
You can access the Fi l ter Desi gner GUI by pressi ng the New button to create
a new fi l ter or the Edit button to edi t a sel ected fi l ter. The Apply button appl i es
a sel ected fi l ter to a sel ected si gnal .
The Create button opens the Spectrum Vi ewer and creates the power spectral
densi ty of the sel ected si gnal . The Update button opens the Spectrum Vi ewer
for the sel ected spectrum.
G etti ng Help
6-7
Getting Help
Use the Whats this? button to fi nd out more i nformati on about a parti cul ar
regi on of the GUI .
Context-Sensitive Help: The Whats This? Button
To fi nd i nformati on on a parti cul ar regi on of the Si gnal Browser, Fi l ter
Desi gner, Fi l ter Vi ewer, or Spectrum Vi ewer
1 Press the Whats this? button, .
2 Cl i ck on the regi on of the GUI you want i nformati on on.
You can al so use the Whats this? menu i tem i n the Help menu to l aunch
context-sensi ti ve hel p.
6 SPTool: A Si gnal Processi ng G UI Sui te
6-8
Overview of the Signal Browser: Signal Analysis
You can use the Si gnal Browser to di spl ay and anal yze si gnal s l i sted i n the
Signals l i st box i n SPTool .
Usi ng the Si gnal Browser you can
Anal yze and compare vector or array (matri x) si gnal s.
Zoom i n on porti ons of si gnal data.
Measure a vari ety of characteri sti cs of si gnal data.
Compare mul ti pl e si gnal s.
Pl ay porti ons of si gnal data on audi o hardware.
Pri nt si gnal pl ots.
Opening the Signal Browser
To open the Si gnal Browser from SPTool
1 Sel ecti ng one or more si gnal s i n the Signals l i st i n SPTool
2 Pressi ng the View button under the Signals l i st
O vervi ew of the Si gnal Browser: Si gnal Analysi s
6-9
The Si gnal Browser has the fol l owi ng components
A tool bar wi th buttons for conveni ent access to frequentl y used functi ons
Pri nt and pri nt previ ew
Pl ay an audi o si gnal
Di spl ay array and compl ex si gnal s
Zoom the si gnal i n and out
Sel ect one of several l oaded si gnal s
Set the di spl ay col or and l i ne styl e of a si gnal
6 SPTool: A Si gnal Processi ng G UI Sui te
6-10
A di spl ay regi on for anal yzi ng si gnal s, i ncl udi ng markers for measuri ng,
compari ng, or pl ayi ng si gnal s
A panner that di spl ays the enti re si gnal l ength, hi ghl i ghti ng the porti on
currentl y acti ve i n the di spl ay regi on
A Marker measurements area
Toggl e the markers on and off
Set marker types
Turn on the Whats Thi s hel p
O vervi ew of the Fi lter Desi gner: Fi lter Desi gn
6-11
Overview of the Filter Designer: Filter Design
The Fi l ter Desi gner provi des an i nteracti ve graphi cal envi ronment for the
desi gn of di gi tal I I R and FI R fi l ters based on speci fi cati ons that you enter on a
magni tude or pol e-zero pl ot.
Note You can al so use the Fi l ter Desi gn and Anal ysi s Tool (FDATool )
descri bed i n Chapter 5, Fi l ter Desi gn and Anal ysi s Tool , for fi l ter desi gn and
anal ysi s.
Filter Types
You can desi gn fi l ters of the fol l owi ng types usi ng the Fi l ter Desi gner
Bandpass
Lowpass
Bandstop
Hi ghpass
FIR Filter Methods
You can use the fol l owi ng fi l ter methods to desi gn FI R fi l ters
Equi ri ppl e
Least squares
Wi ndow
IIR Filter Methods
You can use the fol l owi ng fi l ter methods to desi gn I I R fi l ters
Butterworth
Chebyshev Type I
Chebyshev Type I I
El l i pti c
6 SPTool: A Si gnal Processi ng G UI Sui te
6-12
Pole/ Zero Editor
You can use the Pol e/Zero Edi tor to desi gn arbi trary FI R and I I R fi l ters by
pl aci ng and movi ng pol es and zeros on the compl ex z-pl ane.
Spectral Overlay Feature
You can al so superi mpose spectra on a fi l ters magni tude response to see i f the
fi l teri ng requi rements are met.
Opening the Filter Designer
Open the Fi l ter Desi gner from SPTool by ei ther
Pressi ng the New button i n the Filters l i st i n SPTool
Sel ecti ng a fi l ter you want to edi t from the Filters l i st i n SPTool , and then
pressi ng the Edit button
The Fi l ter Desi gner has the fol l owi ng components
O vervi ew of the Fi lter Desi gner: Fi lter Desi gn
6-13
A tool bar wi th the fol l owi ng buttons
A pul l down Filter menu for sel ecti ng a fi l ter from the l i st i n SPTool
A Sampling Frequency text box
A pul l down Algorithm menu for sel ecti ng a fi l ter desi gn method or a
pol e-zero pl ot di spl ay
A Specifications area for vi ewi ng or modi fyi ng a fi l ters desi gn parameters
or pol e-zero l ocati ons
A pl ot di spl ay regi on for graphi cal l y adjusti ng fi l ter magni tude responses or
the pol e-zero l ocati ons
A Measurements area for vi ewi ng the response characteri sti cs and stabi l i ty
of the current fi l ter
Pri nt and pri nt previ ew
Zoom i n and out
Passband vi ew
Overl ay spectrum
Turn on the Whats Thi s hel p
6 SPTool: A Si gnal Processi ng G UI Sui te
6-14
Overview of the Filter Viewer: Filter Analysis
You can use the Fi l ter Vi ewer to anal yze the fol l owi ng response characteri sti cs
of sel ected fi l ters
Magni tude response
Phase response
I mpul se response
Step response
Group del ay
Pol e and zero l ocati ons
The Fi l ter Vi ewer can di spl ay up to si x di fferent response characteri sti cs pl ots
for a sel ected fi l ter at any ti me. The Fi l ter Vi ewer provi des features for
Zoomi ng
Measuri ng fi l ter responses
Overl ayi ng fi l ter responses
Modi fyi ng di spl ay parameters such as frequency ranges or magni tude uni ts
Opening the Filter Viewer
You can open the Fi l ter Vi ewer from SPTool by
1 Sel ecti ng one or more fi l ters i n the Filters l i st i n SPTool
2 Pressi ng the View button under the Filters l i st
When you fi rst open the Fi l ter Vi ewer, i t di spl ays the defaul t pl ot confi gurati on
for the sel ected fi l ter(s).
O vervi ew of the Fi lter Vi ewer: Fi lter Analysi s
6-15
The fi l ters magni tude and phase pl ots are di spl ayed by defaul t. I n addi ti on,
the frequency i s di spl ayed wi th a l i near scal e on the i nterval [0,Fs/2].
The Fi l ter Vi ewer has the fol l owi ng components
A tool bar wi th buttons for conveni ent access to frequentl y used functi ons
Pri nt and pri nt previ ew
Zoom the si gnal i n and out
Sel ect one of several l oaded si gnal s
Set the di spl ay col or and l i ne styl e of a si gnal
6 SPTool: A Si gnal Processi ng G UI Sui te
6-16
A fi l ter i denti fi cati on regi on that di spl ays the fi l ter name and sampl i ng
frequency for the currentl y sel ected fi l ter(s)
A Plots regi on for sel ecti ng the response pl ots you want to di spl ay i n the
di spl ay area, and for speci fyi ng some frequency response di spl ay
characteri sti cs
A Frequency Axis regi on for speci fyi ng frequency scal i ng i n the di spl ay area
A di spl ay area for anal yzi ng one or more frequency response pl ots for the
sel ected fi l ter(s)
A Marker measurements area
Toggl e the markers on and off
Set marker types
Turn on the Whats Thi s hel p
O vervi ew of the Spectrum Vi ewer: Spectral Analysi s
6-17
Overview of the Spectrum Viewer: Spectral Analysis
You can use the Spectrum Vi ewer for esti mati ng and anal yzi ng a si gnal s
power spectral densi ty (PSD). You can use the PSD esti mates to understand a
si gnal s frequency content.
Usi ng the Spectrum Vi ewer you can
Anal yze and compare spectral densi ty pl ots.
Use di fferent spectral esti mati on methods to create spectra
- Burg (pburg)
- Covari ance (pcov)
- FFT (fft)
- Modi fi ed covari ance (pmcov)
- MTM (mul ti taper method) (pmtm)
- MUSI C (pmusic)
- Wel ch (pwelch)
- Yul e-Wal ker AR (pyulear)
Modi fy power spectral densi ty parameters such as FFT l ength, wi ndow type,
and sampl e frequency.
Pri nt spectral pl ots.
Opening the Spectrum Viewer
To open the Spectrum Vi ewer and create a PSD esti mate from SPTool
1 Sel ect a si gnal from the Signal l i st box i n SPTool .
2 Press the Create button i n the Spectra l i st.
3 Press the Apply button i n the Spectrum Vi ewer.
To open the Spectrum Vi ewer wi th a PSD esti mate al ready l i sted i n SPTool
1 Sel ect a PSD esti mate from the Spectra l i st box i n SPTool .
2 Press the View button i n the Spectra l i st.
6 SPTool: A Si gnal Processi ng G UI Sui te
6-18
For exampl e
1 Sel ect mtlb i n the defaul t Signals l i st i n SPTool .
2 Press the Create button i n SPTool to open the Spectrum Vi ewer.
3 Press the Apply button i n the Spectrum Vi ewer to pl ot the spectrum.
The Spectrum Vi ewer has the fol l owi ng components
A tool bar wi th buttons for conveni ent access to frequentl y used functi ons
Pri nt and pri nt previ ew
Zoom the si gnal i n and out
Sel ect one of several l oaded si gnal s
O vervi ew of the Spectrum Vi ewer: Spectral Analysi s
6-19
A si gnal i denti fi cati on regi on that provi des i nformati on about the si gnal
whose power spectral densi ty esti mate i s di spl ayed
A Parameters regi on for modi fyi ng the PSD parameters
A di spl ay regi on for anal yzi ng spectra and an Options menu for modi fyi ng
di spl ay characteri sti cs
Spectrum management control s
- Inherit from menu to i nheri t PSD speci fi cati ons from another PSD object
l i sted i n the menu
- Revert button to revert to the named PSDs ori gi nal speci fi cati ons
- Apply button for creati ng or updati ng PSD esti mates
Set the di spl ay col or and l i ne styl e of a si gnal
Toggl e the markers on and off
Set marker types
Turn on the Whats Thi s hel p
6 SPTool: A Si gnal Processi ng G UI Sui te
6-20
Using SPTool: Filtering and Analysis of Noise
The fol l owi ng secti ons provi de an exampl e of usi ng the GUI -based i nteracti ve
tool s to
Desi gn and i mpl ement an FI R bandpass di gi tal fi l ter
Appl y the fi l ter to a noi sy si gnal
Anal yze si gnal s and thei r spectra
The steps i ncl ude
1 Creati ng a noi sy si gnal i n the MATLAB workspace and i mporti ng i t i nto
SPTool
2 Desi gni ng a bandpass fi l ter usi ng the Fi l ter Desi gner
3 Appl yi ng the fi l ter to the ori gi nal noi se si gnal to create a bandl i mi ted noi se
si gnal
4 Compari ng the ti me domai n i nformati on of the ori gi nal and fi l tered si gnal s
usi ng the Si gnal Browser
5 Compari ng the spectra of both si gnal s usi ng the Spectrum Vi ewer
6 Exporti ng the fi l ter desi gn to the MATLAB workspace as a structure
7 Accessi ng the fi l ter coeffi ci ents from the exported MATLAB structure
Importing a Signal into SPTool
To i mport a si gnal i nto SPTool from the workspace or di sk, the si gnal must be
ei ther
A speci al MATLAB si gnal structure, such as that saved from a previ ous
SPTool sessi on
A si gnal created as a vari abl e (vector or matri x) i n the MATLAB workspace
For thi s exampl e, create a new si gnal at the command l i ne and then i mport i t
as a structure i nto SPTool .
1 Create a random si gnal i n the MATLAB workspace by typi ng
Usi ng SPTool: Fi lteri ng and Analysi s of N oi se
6-21
randn('state',0);
x = randn(5000,1);
2 I f SPTool i s not al ready open, open SPTool by typi ng
sptool
The SPTool wi ndow i s di spl ayed.
3 Sel ect Import from the File menu i n SPTool . The Import to SPTool di al og
opens.
Noti ce that the vari abl e x i s di spl ayed i n the Workspace Contents l i st. (I f
i t i s not, sel ect the From Workspace radi o button to di spl ay the contents of
the workspace.)
4 Sel ect the si gnal and i mport i t i nto the Data fi el d
a Make sure that Signal i s sel ected i n the Import As pul l -down menu.
Select FromWorkspaceto display
all MATLAB workspace variables
Select FromDiskto load the
contents of a MAT-file into the
Contents list.
Workspace/ File
Contents list
(SPTool structures appear in
square brackets. Vectors and
matrices are not in brackets.)
Move selections(s) fromthe
Contents list to the Datafield.
Sampling frequency of
imported signal
Name of imported
signal
Import signals,
filters, or spectra
6 SPTool: A Si gnal Processi ng G UI Sui te
6-22
b Sel ect the si gnal vari abl e x i n the Workspace Contents l i st.
c Cl i ck on the arrow to the l eft of the Data fi el d or type x i n the Data fi el d.
d Type 5000 i n the Sampling Frequency fi el d.
e Name the si gnal by typi ng noise i n the Name fi el d.
f Press OK.
At thi s poi nt, the si gnal noise[vector] i s sel ected i n SPTool s Signals l i st.
Note You can i mport fi l ters and spectra i nto SPTool i n much the same way as
you i mport si gnal s. See I mporti ng Fi l ters and Spectra i nto SPTool on page
6-39 for speci fi c detai l s.
You can al so i mport si gnal s from MAT-fi l es on your di sk, rather than from the
workspace. See Loadi ng Vari abl es from the Di sk on page 6-43 for more
i nformati on.
Type help sptool for i nformati on about i mporti ng from the command l i ne.
Designing a Filter
You can i mport an exi sti ng fi l ter i nto SPTool , or you can desi gn and edi t a new
fi l ter usi ng the Fi l ter Desi gner.
I n thi s exampl e
1 Open a defaul t fi l ter i n the Fi l ter Desi gner.
2 Speci fy an equi ri ppl e bandpass FI R fi l ter.
O pening the Filter Designer
To open the Fi l ter Desi gner, press the New button i n SPTool . Thi s opens the
Fi l ter Desi gner wi th a defaul t fi l ter named filt1.
Specifying the Ba ndpa ss Filter
Desi gn an equi ri ppl e bandpass FI R fi l ter wi th the fol l owi ng characteri sti cs
Sampl i ng frequency of 5000 Hz
Usi ng SPTool: Fi lteri ng and Analysi s of N oi se
6-23
Stopband frequency ranges of [0 500] Hz and [1500 2500] Hz
Passband frequency range of [750 1250] Hz
Ri ppl e i n the passband of 0.01 dB
Stopband attenuati on of 75 dB
To modi fy your fi l ter i n the Fi l ter Desi gner to meet these speci fi cati ons
1 Change the fi l ter sampl i ng frequency to 5000 by enteri ng thi s val ue i n the
Sampling Frequency text box.
2 Sel ect Equiripple FIR from the Algorithm l i st.
3 Sel ect bandpass from the Type l i st.
4 Set the passband edge frequenci es by enteri ng 750 for Fp1 and 1250 for Fp2.
5 Set the stopband edge frequenci es by enteri ng 500 for Fs1 and 1500 for Fs2.
6 Type 0.01 i nto the Rp fi el d and 75 i nto the Rs fi el d.
Rp sets the maxi mum passband ri ppl e and Rs sets the stopband attenuati on
for the fi l ter.
7 Press the Apply button to desi gn the new fi l ter.When the new fi l ter i s
desi gned, the magni tude response of the fi l ter i s di spl ayed wi th a sol i d l i ne
i n the di spl ay regi on.
6 SPTool: A Si gnal Processi ng G UI Sui te
6-24
The resul ti ng fi l ter i s an order-78 bandpass equi ri ppl e fi l ter.
Note You can use the sol i d l i ne i n the pl ot to modi fy your fi l ter desi gn. See
Redesi gni ng a Fi l ter Usi ng the Magni tude Pl ot on page 6-49 for more
i nformati on.
Applying a Filter to a Signal
When you appl y a fi l ter to a si gnal , you create a new si gnal i n SPTool
representi ng the fi l tered si gnal .
To appl y the fi l ter filt1 you just created to the si gnal noise
1 Sel ect SPTool from the Window menu i n the Fi l ter Desi gner.
Usi ng SPTool: Fi lteri ng and Analysi s of N oi se
6-25
2 Sel ect the si gnal noise[vector] from the Signals l i st and sel ect the fi l ter
(named filt1[design]) from the Filters l i st, as shown bel ow.
3 Press Apply to appl y the fi l ter filt1 to the si gnal noise.
The Apply Filter di al og box i s di spl ayed.
4 Keep the defaul t fi l ter structure sel ected i n the Algorithm l i st.
5 Name the new si gnal by typi ng blnoise i n the Output Signal fi el d i n thi s
di al og box.
6 SPTool: A Si gnal Processi ng G UI Sui te
6-26
6 Press OK to cl ose the Apply Filter di al og box.
The fi l ter i s appl i ed to the sel ected si gnal and the fi l tered si gnal
blnoise[vector] i s l i sted i n the Signals l i st i n SPTool .
Analyzing Signals: Opening the Signal Browser
You can anal yze and pri nt si gnal s usi ng the Si gnal Browser. You can al so pl ay
the si gnal s i f your computer has audi o output capabi l i ti es.
For exampl e, compare the si gnal noise to the fi l tered si gnal blnoise
1 Shift+cl i ck on the noise and blnoise si gnal s i n the Signals l i st of SPTool to
sel ect both si gnal s.
2 Press the View button under the Signals l i st.
The Si gnal Browser i s acti vated and both si gnal s are di spl ayed i n the
di spl ay regi on. (The names of both si gnal s are shown above the di spl ay
regi on.) I ni ti al l y, the ori gi nal noise si gnal covers up the bandl i mi ted
blnoise si gnal .
3 Push the sel ecti on button on the tool bar, , to sel ect the blnoise si gnal .
The di spl ay area i s updated. Now you can see the blnoise si gnal
superi mposed on top of the noise si gnal . The si gnal s are di spl ayed i n
di fferent col ors i n both the di spl ay regi on and the panner. You can change
the col or of the sel ected si gnal usi ng the Line Properties button on the
tool bar, .
Usi ng SPTool: Fi lteri ng and Analysi s of N oi se
6-27
Pla ying a Signa l
When you press the Play button i n the Si gnal Browser tool bar, , the acti ve
si gnal i s pl ayed on the computers audi o hardware.
1 To hear a porti on of the acti ve (sel ected) si gnal
a Use the verti cal markers to sel ect a porti on of the si gnal you want to pl ay.
Verti cal markers are enabl ed by the and buttons.
b Press the Play button.
2 To hear the other si gnal
a Sel ect the si gnal as i n step 3 above. You can al so sel ect the si gnal di rectl y
i n the di spl ay regi on.
b Press the Play button agai n.
Printing a Signa l
You can pri nt from the Si gnal Browser usi ng the Print button, .
6 SPTool: A Si gnal Processi ng G UI Sui te
6-28
You can use the l i ne di spl ay buttons to maxi mi ze the vi sual contrast between
the si gnal s by setti ng the l i ne col or for noise to gray and the l i ne col or for
blnoise to whi te. Do thi s before pri nti ng two si gnal s together.
Note You can fol l ow the same rul es to pri nt spectra, but you cant pri nt fi l ter
responses di rectl y from SPTool .
Use the Si gnal Browser regi on i n the Preferences di al og box i n SPTool to
suppress pri nti ng of both the panner and the marker setti ngs.
To pri nt both si gnal s, press the Print button i n the Si gnal Browser tool bar.
Spectral Analysis in the Spectrum Viewer
You can anal yze the frequency content of a si gnal usi ng the Spectrum Vi ewer,
whi ch esti mates and di spl ays a si gnal s power spectral densi ty.
For exampl e, to anal yze and compare the spectra of noise and blnoise
1 Create a power spectral densi ty (PSD) object, spect1, that i s associ ated wi th
the si gnal noise, and a second PSD object, spect2, that i s associ ated wi th
the si gnal blnoise.
Usi ng SPTool: Fi lteri ng and Analysi s of N oi se
6-29
2 Open the Spectrum Vi ewer to anal yze both of these spectra.
3 Pri nt both spectra.
Crea ting a PSD O bject From a Signa l
1 Cl i ck on SPTool , or sel ect SPTool from the Window menu of any acti ve open
GUI . SPTool i s now the acti ve wi ndow.
2 Sel ect the noise[vector] si gnal i n the Signals l i st of SPTool .
3 Press Create i n the Spectra l i st.
The Spectrum Vi ewer i s acti vated, and a PSD object (spect1) correspondi ng
to the noise si gnal i s created i n the Spectra l i st. The PSD i s not computed
or di spl ayed yet.
4 Press Apply i n the Spectrum Vi ewer to compute and di spl ay the PSD
esti mate spect1 usi ng the defaul t parameters.
The PSD of the noise si gnal i s di spl ayed i n the di spl ay regi on. The
i denti fyi ng i nformati on for the PSDs associ ated si gnal (noise) i s di spl ayed
above the Parameters regi on.
The PSD esti mate spect1 i s wi thi n 2 or 3 dB of 0, so the noi se has a fai rl y
fl at power spectral densi ty.
5 Fol l ow steps 1 through 4 for the bandl i mi ted noi se si gnal blnoise to create
a second PSD esti mate spect2.
The PSD esti mate spect2 i s fl at between 750 and 1250 Hz and has 75 dB
l ess power i n the stopband regi ons of filt1.
O pening the Spectr um View er w ith Tw o Spectra
1 Reacti vate SPTool agai n, as i n step 1 above.
2 Shift+cl i ck on spect1 and spect2 i n the Spectra l i st to sel ect them both.
3 Press View i n the Spectra l i st to reacti vate the Spectrum Vi ewer and
di spl ay both spectra together.
6 SPTool: A Si gnal Processi ng G UI Sui te
6-30
Printing the Spectra
Before pri nti ng the two spectra together, use the col or and l i ne styl e sel ecti on
button, , to di fferenti ate the two pl ots by l i ne styl e, rather than by col or.
To pri nt both spectra
1 Press the Print Preview button, , i n the tool bar on the Spectrum
Vi ewer.
2 From the Spectrum Viewer Print Preview wi ndow, drag the l egend out of
the di spl ay regi on so that i t doesnt obscure part of the pl ot.
3 Press the Print button i n the Spectrum Viewer Print Preview wi ndow.
Usi ng SPTool: Fi lteri ng and Analysi s of N oi se
6-31
6 SPTool: A Si gnal Processi ng G UI Sui te
6-32
Exporting Signals, Filters, and Spectra
You can export SPTool si gnal s, fi l ters, and spectra as structures to the
MATLAB workspace or to your di sk.
I n each case you
1 Sel ect the i tems i n SPTool you want to export.
2 Sel ect Export from the File menu.
O pening the Ex por t Dia log Box
To save the fi l ter filt1 you just created i n thi s exampl e, open the Export
di al og box wi th filt1 presel ected
1 Sel ect filt1 i n the SPTool Filters l i st.
2 Sel ect Export from the File menu.
The Export di al og box opens wi th filt1 presel ected.
Export as objects for use with
Control SystemToolbox
Select items to export
Exporti ng Si gnals, Fi lters, and Spectra
6-33
Ex por ting a Filter to the M ATLAB Workspa ce
To export the fi l ter filt1 to the MATLAB workspace
1 Sel ect filt1 from the Export List and desel ect al l other i tems usi ng
Ctrl+cl i ck.
2 Press the Export to Workspace button.
6 SPTool: A Si gnal Processi ng G UI Sui te
6-34
Accessing Filter Parameters
Accessing Filter Parameters in a Saved Filter
The MATLAB structures created by SPTool have several associ ated fi el ds,
many of whi ch are al so MATLAB structures. See the MATLAB documentati on
for general i nformati on about MATLAB structures.
For exampl e, after exporti ng a fi l ter filt1 to the MATLAB workspace, type
filt1
to di spl ay the fi el ds of the MATLAB fi l ter structure. The tf, Fs, and specs
fi el ds of the structure contai n the i nformati on that descri bes the fi l ter.
The tf Field: Accessing Filter Coef ficients
The tf fi el d i s a structure contai ni ng the transfer functi on representati on of
the fi l ter. Use thi s fi el d to obtai n the fi l ter coeffi ci ents
filt1.tf.num contai ns the numerator coeffi ci ents.
filt1.tf.den contai ns the denomi nator coeffi ci ents.
The vectors contai ned i n these structures represent pol ynomi al s i n descendi ng
powers of z. The numerator and denomi nator pol ynomi al s are used to speci fy
the transfer functi on
where
b i s a vector contai ni ng the coeffi ci ents from the tf.num fi el d.
a i s a vector contai ni ng the coeffi ci ents from the tf.den fi el d.
m i s the numerator order.
n i s the denomi nator order.
You can change the fi l ter representati on from the defaul t transfer functi on to
another form by usi ng the tf2ss or tf2zp functi ons.
The Fs Field: Accessing Filter Sa mple Frequency
The Fs fi el d contai ns the sampl i ng frequency of the fi l ter i n hertz.
H z ( )
B z ( )
A z ( )
-----------
b 1 ( ) b 2 ( )z
1
L b nb 1 + ( )z
m
+ + +
a 1 ( ) a 2 ( )z
1
L a na 1 + ( )z
n
+ + +
----------------------------------------------------------------------------------------- = =
Accessi ng Fi lter Parameters
6-35
The specs Field: Accessing other Filter Pa ra meters
The specs fi el d i s a structure contai ni ng parameters that you speci fi ed for the
fi l ter desi gn. The fi rst fi el d, specs.currentModule, contai ns a stri ng
representi ng the most recent desi gn method sel ected from the Fi l ter Desi gners
Algorithm l i st before you exported the fi l ter. The possi bl e contents of the
currentModule fi el d and the correspondi ng desi gn methods are shown bel ow.
Fol l owi ng the specs.currentModule fi el d, there may be up to seven addi ti onal
fi el ds, wi th l abel s such as specs.fdremez, specs.fdfirls, etc. The desi gn
speci fi cati ons for the most recentl y exported fi l ter are contai ned i n the fi el d
whose l abel matches the currentModule stri ng. For exampl e, i f the specs
structure i s
filt1.specs
ans
currentModule: 'fdremez'
fdremez: [1x1 struct]
the fi l ter speci fi cati ons are contai ned i n the fdremez fi el d, whi ch i s i tsel f a data
structure.
The speci fi cati ons i ncl ude the parameter val ues from the Specifications
regi on of the Fi l ter Desi gner, such as band edges and fi l ter order. For exampl e,
Table 6-1: Filter Specifications currentModule Field Values
Contents of the currentModule field Design Method
fdbutter Butterworth I I R
fdcheby1 Chebyshev Type I I I R
fdcheby2 Chebyshev Type I I I I R
fdellip El l i pti c I I R
fdfirls Least Squares FI R
fdkaiser Kai ser Wi ndow FI R
fdremez Equi ri ppl e FI R
6 SPTool: A Si gnal Processi ng G UI Sui te
6-36
the fi l ter above has the fol l owi ng speci fi cati ons stored i n
filt1.specs.fdremez.
filt1.specs.fdremez
ans =
setOrderFlag: 0
type: 3
f: [0 0.2000 0.3000 0.5000 0.6000 1]
m: [6x1 double]
Rp: 0.0100
Rs: 75
wt: [3.2371 1 3.2371]
order: 78
Because certai n fi l ter parameters are uni que to a parti cul ar desi gn, thi s
structure has a di fferent set of fi el ds for each fi l ter desi gn.
The tabl e bel ow descri bes the possi bl e fi el ds associ ated wi th the fi l ter desi gn
speci fi cati on fi el d (the specs fi el d) that can appear i n the exported structure.
Table 6-2: SPTool Structure Specifications for Filters
Parameter Description
Beta Kai ser wi ndow parameter.
f Contai ns a vector of band-edge frequenci es, normal i zed so
that 1 Hz corresponds to hal f the sampl e frequency.
Fpass Passband cutoff frequenci es. Scal ar for l owpass and
hi ghpass desi gns, two-el ement vector for bandpass and
bandstop desi gns.
Fstop Stopband cutoff frequenci es. Scal ar for l owpass and
hi ghpass desi gns, two-el ement vector for bandpass and
bandstop desi gns.
m The response magni tudes correspondi ng to the band-edge
frequenci es i n f.
order Fi l ter order.
Accessi ng Fi lter Parameters
6-37
Accessing Parameters in a Saved Spectrum
The fol l owi ng structure fi el ds descri be the spectra saved by SPTool .
Rp Passband ri ppl e (dB)
Rs Stopband attenuati on (dB)
setOrderFlag Contai ns 1 i f the fi l ter order was speci fi ed manual l y (i .e.,
the Minimum Order box i n the Specifications regi on
was not checked). Contai ns 0 i f the fi l ter order was
computed automati cal l y.
type Contai ns 1 for l owpass, 2 for hi ghpass, 3 for bandpass, or
4 for bandstop.
w3db -3 dB frequency for Butterworth I I R desi gns.
wind Vector of Kai ser wi ndow coeffi ci ents.
Wn Cutoff frequency for the Kai ser wi ndow FI R fi l ter when
setOrderFlag = 1.
wt Vector of wei ghts, one wei ght per frequency band.
Field Description
P The spectral power vector.
f The spectral frequency vector.
Table 6-2: SPTool Structure Specifications for Filters (Continued)
Parameter Description
6 SPTool: A Si gnal Processi ng G UI Sui te
6-38
You can access the i nformati on i n these fi el ds as you do wi th every MATLAB
structure.
For exampl e, i f you export an SPTool PSD esti mate spect1 to the workspace,
type
spect1.P
to obtai n the vector of associ ated power val ues.
confid A structure contai ni ng the confi dence i nterval s data
The confid.level fi el d contai ns the chosen
confi dence l evel .
The confid.Pc fi el d contai ns the spectral power
data for the confi dence i nterval s.
The confid.enable fi el d contai ns a 1 i f confi dence
l evel s are enabl ed for the power spectral densi ty.
signalLabel The name of the si gnal from whi ch the power spectral
densi ty was generated.
Fs The associ ated si gnal s sampl e rate.
Field Description
Importi ng Fi lters and Spectra i nto SPTool
6-39
Importing Filters and Spectra into SPTool
I n addi ti on to i mporti ng si gnal s i nto SPTool , you can i mport fi l ters or spectra
i nto SPTool from ei ther the workspace or from a fi l e.
The procedures are very si mi l ar to those expl ai ned i n
I mporti ng a Si gnal i nto SPTool on page 6-20 for l oadi ng vari abl es from the
workspace
Loadi ng Vari abl es from the Di sk on page 6-43 for l oadi ng vari abl es from
your di sk
Impor ting Filters
When you i mport fi l ters, fi rst sel ect the appropri ate fi l ter form from the Form
l i st.
6 SPTool: A Si gnal Processi ng G UI Sui te
6-40
For every fi l ter you speci fy a vari abl e name or a val ue for the fi l ters sampl i ng
frequency i n the Sampling Frequency fi el d. Each fi l ter form requi res di fferent
vari abl es.
Tra nsfer Function. For Transfer Function, you speci fy the fi l ter by i ts transfer
functi on representati on
The Numerator fi el d speci fi es a vari abl e name or val ue for the numerator
coeffi ci ent vector b, whi ch contai ns m+1 coeffi ci ents i n descendi ng powers of
z.
The Denominator fi el d speci fi es a vari abl e name or val ue for the
denomi nator coeffi ci ent vector a, whi ch contai ns n+1 coeffi ci ents i n
descendi ng powers of z.
Sta te Spa ce. For State Space, you speci fy the fi l ter by i ts state-space
representati on
The A-Matrix, B-Matrix, C-Matrix, and D-Matrix fi el ds speci fy a vari abl e
name or a val ue for each matri x i n thi s system.
Zeros, Poles, Ga in. For Zeros, Poles, Gain, you speci fy the fi l ter by i ts
zero-pol e-gai n representati on
The Zeros fi el d speci fi es a vari abl e name or val ue for the zeros vector z,
whi ch contai ns the l ocati ons of m zeros.
The Poles fi el d speci fi es a vari abl e name or val ue for the zeros vector p,
whi ch contai ns the l ocati ons of n pol es.
The Gain fi el d speci fi es a vari abl e name or val ue for the gai n k.
Second Order Sections. For 2nd Order Sections you speci fy the fi l ter by i ts
second-order secti on representati on
H z ( )
B z ( )
A z ( )
-----------
b 1 ( ) b 2 ( )z
1
L b m 1 + ( )z
m
+ + +
a 1 ( ) a 2 ( )z
1
L a n 1 + ( )z
n
+ + +
--------------------------------------------------------------------------------------- = =
x

Ax Bu + =
y Cx Du + =
H z ( )
Z z ( )
P z ( )
---------- k
z z 1 ( ) ( ) z z 2 ( ) ( )L z z m ( ) ( )
z p 1 ( ) ( ) z p 2 ( ) ( )L z p n ( ) ( )
------------------------------------------------------------------------------------ = =
Importi ng Fi lters and Spectra i nto SPTool
6-41
The SOS Matrix fi el d speci fi es a vari abl e name or a val ue for the L-by-6 SOS
matri x
whose rows contai n the numerator and denomi nator coeffi ci ents b
ik
and a
ik
of
the second-order secti ons of H(z).
Note I f you i mport a fi l ter that was not created i n SPTool , you can onl y edi t
that fi l ter usi ng the Pol e/Zero Edi tor.
Impor ting Spectra
When you i mport a power spectral densi ty (PSD), you speci fy
A vari abl e name or a val ue for the PSD vector i n the PSD fi el d
A vari abl e name or a val ue for the frequency vector i n the Freq. Vector fi el d
The PSD val ues i n the PSD vector correspond to the frequenci es contai ned i n
the Freq. Vector vector; the two vectors must have the same l ength.
H z ( ) H
k
z ( )
k 1 =
L

b
0k
b
1k
z
1
b
2k
z
2
+ +
1 a
1k
z
1
a
2k
z
2
+ +
--------------------------------------------------------- -
k 1 =
L

= =
sos
b
01
b
11
b
21
1 a
11
a
21
b
02
b
12
b
22
1 a
12
a
22
M M M M M M
b
0L
b
1L
b
2L
1 a
1L
a
2L
=
6 SPTool: A Si gnal Processi ng G UI Sui te
6-42
Loadi ng Vari ables from the Di sk
6-43
Loading Variables from the Disk
To i mport vari abl es representi ng si gnal s, fi l ters, or spectra from a MAT-fi l e on
your di sk
1 Sel ect the From Disk radi o button and do ei ther of the fol l owi ng
- Type the name of the fi l e you want to i mport i nto the MAT-file Name fi el d
and press ei ther the Tab or the Enter key on your keyboard.
- Sel ect Browse, and then fi nd and sel ect the fi l e you want to i mport usi ng
the Select File to Open di al og. Press OK to cl ose that di al og.
I n ei ther case, al l vari abl es i n the MAT-fi l e you sel ected are di spl ayed i n the
File Contents l i st.
2 Sel ect the vari abl es to be i mported i nto SPTool .
You can now i mport one or more vari abl es from the File Contents l i st i nto
SPTool , as l ong as these vari abl es are scal ars, vectors, or matri ces.
6 SPTool: A Si gnal Processi ng G UI Sui te
6-44
Selecting Signals, Filters, and Spectra in SPTool
Al l si gnal s, fi l ters, or spectra l i sted i n SPTool exi st as speci al MATLAB
structures. You can bri ng data representi ng si gnal s, fi l ters, or spectra i nto
SPTool from the MATLAB workspace. I n general , you can sel ect one or several
i tems i n a gi ven l i st box. An i tem i s sel ected when i t i s hi ghl i ghted.
The Signals l i st shows al l vector and array si gnal s i n the current SPTool
sessi on.
The Filters l i st shows al l desi gned and i mported fi l ters i n the current SPTool
sessi on.
The Spectra l i st shows al l spectra i n the current SPTool sessi on.
You can sel ect a si ngl e data object i n a l i st, a range of data objects i n a l i st, or
mul ti pl e separate data objects i n a l i st. You can al so have data objects
si mul taneousl y sel ected i n di fferent l i sts
To sel ect a si ngl e i tem, cl i ck on i t. Al l other i tems i n that l i st box become
desel ected.
To add or remove a range of i tems, Shift+cl i ck on the i tems at the top and
bottom of the secti on of the l i st that you want to add. You can al so drag your
mouse poi nter to sel ect these i tems.
To add a si ngl e data object to a sel ecti on or remove a si ngl e data object from
a mul ti pl e sel ecti on, Ctrl+cl i ck on the object.
Edi ti ng Si gnals, Fi lters, or Spectra i n SPTool
6-45
Editing Signals, Filters, or Spectra in SPTool
You can edi t sel ected i tems i n SPTool by
1 Sel ecti ng the names of the si gnal s, fi l ters, or spectra you want to edi t.
2 Sel ecti ng the appropri ate Edit menu i tem
- Duplicate to copy an i tem i n an SPTool l i st
- Clear to del ete an i tem i n an SPTool l i st
- Name to rename an i tem i n an SPTool l i st
- Sampling Frequency to modi fy the sampl i ng frequency associ ated wi th
ei ther a si gnal (and i ts associ ated spectra) or fi l ter i n an SPTool l i st
The pul l -down menu next to each menu i tem shows the names of al l sel ected
i tems.
You can al so edi t the fol l owi ng si gnal characteri sti cs by ri ght-cl i cki ng i n the
di spl ay regi on of the Si gnal Browser, the Fi l ter Vi ewer, or the Spectrum Vi ewer
The si gnal name
The sampl i ng frequency
The l i ne styl e properti es
Note I f you modi fy the sampl i ng frequency associ ated wi th a si gnal s
spectrum usi ng the ri ght-cl i ck menu on the Spectrum Vi ewer di spl ay regi on,
the sampl i ng frequency of the associ ated si gnal i s automati cal l y updated.
6 SPTool: A Si gnal Processi ng G UI Sui te
6-46
Designing a Filter with the Pole/ Zero Editor
To desi gn a fi l ter transfer functi on usi ng the Fi l ter Desi gner Pol e/Zero Edi tor
1 Sel ect the Pole/Zero Editor opti on from the Algorithm l i st to open the
Pol e/Zero Edi tor i n the Fi l ter Desi gner di spl ay.
2 Enter the desi red fi l ter gai n i n the Gain edi t box.
3 Sel ect a pol e or zero (or conjugate pai r) by sel ecti ng one of the (pol e) or
(zero) symbol s on the pl ot.
4 Choose the coordi nates to work i n by speci fyi ng Polar or Rectangular from
the Coordinates l i st.
5 Speci fy the new l ocati on(s) of the sel ected pol e, zero, or conjugate pai r by
typi ng val ues i nto the Mag and Angle fi el ds (for angul ar coordi nates) or X
and Y (for rectangul ar coordi nates) fi el ds. Al ternati vel y, posi ti on the pol es
and zeros by draggi ng the and symbol s.
6 Use the Conjugate pair check box to create a conjugate pai r from a l one pol e
or zero, or to break a conjugate pai r i nto two i ndi vi dual pol es or zeros.
Desi gn a new fi l ter or edi t an exi sti ng fi l ter i n the same way.
Tip Keep the Fi l ter Vi ewer open whi l e desi gni ng a fi l ter wi th the Pol e/Zero
Edi tor. Any changes that you make to the fi l ter transfer functi on i n the
Pol e/Zero Edi tor are then si mul taneousl y refl ected i n the response pl ots of the
Fi l ter Vi ewer.
Desi gni ng a Fi lter wi th the Pole/ Zero Edi tor
6-47
Positioning Poles and Zeros
You can use your mouse to move pol es and zeros around the pol e/zero pl ot and
modi fy your fi l ter desi gn
Add pol es or zeros usi ng the tool bar buttons for pol e pl acement, , and zero
pl acement, .
Erase pol es and zeros usi ng the eraser button, .
Move both members of a conjugate pai r si mul taneousl y by mani pul ati ng just
one of the pol es or zeros.
To ungroup conjugates, sel ect the desi red pai r and uncheck Conjugate pair i n
the Specifications regi on on the Fi l ter Desi gner.
When you pl ace two or more pol es (or two or more zeros) di rectl y on top of each
other, a number i s di spl ayed next to the symbol s (on the l eft for pol es, and on
the ri ght for zeros) i ndi cati ng the number of pol es or zeros at that l ocati on (e.g.,
for three zeros). Thi s number makes i t easy to keep track of al l the pol es
and zeros i n the pl ot area, even when several are superi mposed on each other
and are not vi sual l y di fferenti abl e. Note, however, that thi s number does not
i ndi cate the multiplicity of the pol es or zeros to whi ch i t i s attached.
Add poles Add zeros Delete poles/ zeros
Movepoles/ zerosby
draggingon plot
6 SPTool: A Si gnal Processi ng G UI Sui te
6-48
To detect whether or not a set of pol es or zeros are trul y mul ti pl es, use the zoom
tool s to magni fy the regi on around the pol es or zeros i n questi on. Because
numeri cal l i mi tati ons usual l y prevent any set of pol es or zeros from shari ng
exactly the same val ue, at a hi gh enough zoom l evel even trul y mul ti pl e pol es
or zeros appear di sti nct from each other.
A common way to assess whether a parti cul ar group of pol es or zeros contai ns
mul ti pl es i s by compari ng the mutual proxi mi ty of the group members agai nst
a sel ected threshol d val ue. As an exampl e, the residuez functi on defi nes a pol e
or zero as bei ng a mul ti pl e of another pol e or zero i f the absol ute di stance
separati ng them i s l ess than 0.1% of the l arger pol e or zeros magni tude.
Redesi gni ng a Fi lter Usi ng the M agni tude Plot
6-49
Redesigning a Filter Using the Magnitude Plot
After desi gni ng a fi l ter i n the Fi l ter Desi gner, you can redesi gn i t by draggi ng
the speci fi cati on l i nes on the magni tude pl ot. Use the speci fi cati on l i nes to
change passband ri ppl e, stopband attenuati on, and edge frequenci es.
I n the fol l owi ng exampl e, create a Chebyshev fi l ter and modi fy i t by draggi ng
the speci fi cati on l i nes
1 Sel ect Chebyshev Type I IIR from the Algorithm menu.
2 Sel ect highpass from the Type menu.
3 Type 2000 i n the Sampling Frequency fi el d.
4 Set the fol l owi ng parameters
a Fp = 800
b Fs = 700
c Rp = 2.5
d Rs = 35
5 Check Minimum Order so the Fi l ter Desi gner can cal cul ate the l owest fi l ter
order that produces the desi red characteri sti cs.
6 Press Apply to compute the fi l ter and update the response pl ot.
7 Posi ti on the cursor over the hori zontal fi l ter speci fi cati on l i ne for the
stopband. Thi s i s the fi rst (l eftmost) hori zontal speci fi cati on l i ne you see.
The cursor changes to the up/down drag i ndi cator.
8 Drag the l i ne unti l the Rs (stopband attenuati on) fi el d reads 100.
Note The Order val ue i n the Measurements regi on changes because a
hi gher fi l ter order i s needed to meet the new speci fi cati ons.
6 SPTool: A Si gnal Processi ng G UI Sui te
6-50
Setting Preferences
Use Preferences from the SPTool File menu to customi ze di spl ays and certai n
parameters for SPTool and i ts four component GUI s. The new setti ngs are
saved on di sk and are used when you restart SPTool from MATLAB.
I n the Preferences regi ons, you can
Sel ect col ors and markers for al l di spl ays.
Sel ect col ors and l i ne styl es for di spl ayed si gnal s.
Confi gure l abel s, and enabl e/di sabl e markers, panner, and zoom i n the
Si gnal Browser.
Confi gure di spl ay parameters, and enabl e/di sabl e markers and zoom i n the
Spectrum Vi ewer.
Confi gure fi l ter and di spl ay parameters, and enabl e/di sabl e zoom i n the
Fi l ter Vi ewer.
Confi gure ti l i ng preferences i n the Fi l ter Vi ewer.
Speci fy FFT l ength, and enabl e/di sabl e mouse zoom and gri d i n the Fi l ter
Desi gner.
Enabl e/di sabl e use of a defaul t sessi on fi l e.
Export fi l ters for use wi th the Control System Tool box.
Enabl e/di sabl e search for pl ug-i ns at start-up.
When you fi rst sel ect Preferences, the Preferences di al og box opens wi th
Markers sel ected by defaul t.
Setti ng Preferences
6-51
You can
Change the setti ngs for markers from thi s panel of the Preferences di al og.
Choose any of the other categori es l i sted to customi ze i ts setti ngs.
Cl i ck once on any l i sted category i n the l eft pane of the Preferences di al og to
sel ect i t.
6 SPTool: A Si gnal Processi ng G UI Sui te
6-52
Making Signal Measurements: Using Markers
You can use the markers on the Si gnal Browser, the Fi l ter Vi ewer, or the
Spectrum Vi ewer to make measurements on any of the fol l owi ng
A si gnal i n the Si gnal Browser
A fi l ter response i n the Fi l ter Vi ewer
A power spectral densi ty pl otted i n the Spectrum Vi ewer
The marker buttons from l eft to ri ght are
toggl e markers on/off
verti cal markers
hori zontal markers
verti cal markers wi th tracki ng
verti cal markers wi th tracki ng and sl ope
di spl ay peaks (l ocal maxi ma)
di spl ay val l eys (l ocal mi ni ma)
To make a measurement
1 Sel ect a l i ne to measure (or pl ay, i f you are i n the Si gnal Browser).
2 Sel ect one of the marker buttons to appl y a marker to the di spl ayed si gnal .
3 Posi ti on a marker i n the mai n di spl ay area by grabbi ng i t wi th your mouse
and draggi ng
a Sel ect a marker setti ng. I f you choose the Vertical, Track, or Slope
buttons, you can drag a marker to the ri ght or l eft. I f you choose the
Horizontal button, you can drag a marker up or down.
b Move the mouse over the marker (1 or 2) that you want to drag.
The hand cursor wi th the marker number i nsi de i t i s di spl ayed when
your mouse passes over a marker.
M aki ng Si gnal M easurements: Usi ng M arkers
6-53
c Drag the marker to where you want i t on the si gnal .
As you drag a marker, the bottom of the Si gnal Browser shows the current
posi ti on of both markers. Dependi ng on whi ch marker setti ng you sel ect,
some or al l of the fol l owi ng fi el ds are di spl ayed x1, y1, x2, y2, dx, dy, m.
These fi el ds are al so di spl ayed when you pri nt from the Si gnal Browser,
unl ess you suppress them.
You can al so posi ti on a marker by typi ng i ts x1 and x2 or y1 and y2 val ues i n
the regi on at the bottom.
6 SPTool: A Si gnal Processi ng G UI Sui te
6-54

7
Functi on Reference
Function Category List . . . . . . . . . . . . . . . 7-3
Alphabetical List of Functions . . . . . . . . . . . . 7-20
7 Functi on Reference
7-2
Detai l ed descri pti ons of al l Si gnal Processi ng Tool box functi ons are i n these
two secti ons:
Functi on Category Li st a l i st of functi ons, grouped by subject area
Al phabeti cal Li st of Functi ons reference pages i n al phabeti cal order
Functi on C ategory Li st
7-3
Function Category List
The Si gnal Processi ng Tool box functi ons are di vi ded i nto the fol l owi ng
categori es
Fi l ter Anal ysi s
Fi l ter I mpl ementati on
FI R Di gi tal Fi l ter Desi gn
I I R Di gi tal Fi l ter Desi gnCl assi cal and Di rect
I I R Fi l ter Order Esti mati on
Anal og Lowpass Fi l ter Prototypes
Anal og Fi l ter Desi gn
Anal og Fi l ter Transformati on
Fi l ter Di screti zati on
Li near System Transformati ons
Wi ndows
Transforms
Cepstral Anal ysi s
Stati sti cal Si gnal Processi ng and Spectral Anal ysi s
Parametri c Model i ng
Li near Predi cti on
Mul ti rate Si gnal Processi ng
Waveform Generati on
Speci al i zed Operati ons
Graphi cal User I nterfaces.
Filter Analysis
abs Absol ute val ue (magni tude).
angle Phase angl e.
freqs Frequency response of anal og fi l ters.
freqspace Frequency spaci ng for frequency response.
7 Functi on Reference
7-4
freqz Compute the frequency response of di gi tal fi l ters.
freqzplot Pl ot frequency response data.
grpdelay Compute the average fi l ter del ay (group del ay).
impz Compute the i mpul se response of di gi tal fi l ters.
unwrap Unwrap phase angl es.
zplane Zero-pol e pl ot.
Filter Implementation
conv Convol uti on and pol ynomi al mul ti pl i cati on.
conv2 Two-di mensi onal convol uti on.
deconv Deconvol uti on and pol ynomi al di vi si on.
fftfilt FFT-based FI R fi l teri ng usi ng the overl ap-add method.
filter Fi l ter data wi th a recursi ve (I I R) or nonrecursi ve (FI R)
fi l ter.
filter2 Two-di mensi onal di gi tal fi l teri ng.
filtfilt Zero-phase di gi tal fi l teri ng.
filtic Fi nd i ni ti al condi ti ons for a transposed di rect form I I fi l ter
i mpl ementati on.
latcfilt Latti ce and l atti ce-l adder fi l ter i mpl ementati on.
medfilt1 One-di mensi onal medi an fi l teri ng.
sgolayfilt Savi tzky-Gol ay fi l teri ng.
sosfilt Second-order (bi quadrati c) I I R di gi tal fi l teri ng.
Filter Analysis (Continued)
Functi on C ategory Li st
7-5
upfirdn Upsampl e, appl y an FI R fi l ter, and downsampl e.
FIR Digital Filter Design
convmtx Convol uti on matri x.
cremez Compl ex and nonl i near-phase equi ri ppl e FI R fi l ter desi gn.
fir1 Desi gn a wi ndow-based fi ni te i mpul se response fi l ter.
fir2 Desi gn a frequency sampl i ng-based fi ni te i mpul se response
fi l ter.
fircls Constrai ned l east square FI R fi l ter desi gn for mul ti band
fi l ters.
fircls1 Constrai ned l east square fi l ter desi gn for l owpass and
hi ghpass l i near phase FI R fi l ters.
firls Least square l i near-phase FI R fi l ter desi gn.
firrcos Rai sed cosi ne FI R fi l ter desi gn.
intfilt I nterpol ati on FI R fi l ter desi gn.
kaiserord Esti mate parameters for an FI R fi l ter desi gn wi th Kai ser
wi ndow.
remez Compute the Parks-McCl el l an opti mal FI R fi l ter desi gn.
remezord Parks-McCl el l an opti mal FI R fi l ter order esti mati on.
sgolay Savi tzky-Gol ay fi l ter desi gn.
Filter Implementation (Continued)
7 Functi on Reference
7-6
IIR Digital Filter DesignClassical and Direct
butter Butterworth anal og and di gi tal fi l ter desi gn.
cheby1 Chebyshev Type I fi l ter desi gn (passband ri ppl e).
cheby2 Chebyshev Type I I fi l ter desi gn (stopband ri ppl e).
ellip El l i pti c (Cauer) fi l ter desi gn.
maxflat General i zed di gi tal Butterworth fi l ter desi gn.
prony Pronys method for ti me-domai n I I R fi l ter desi gn.
stmcb Compute a l i near model usi ng Stei gl i tz-McBri de i terati on.
yulewalk Recursi ve di gi tal fi l ter desi gn.
IIR Filter Order Estimation
buttord Cal cul ate the order and cutoff frequency for a Butterworth
fi l ter.
cheb1ord Cal cul ate the order for a Chebyshev Type I fi l ter.
cheb2ord Cal cul ate the order for a Chebyshev Type I I fi l ter.
ellipord Cal cul ate the mi ni mum order for el l i pti c fi l ters.
Functi on C ategory Li st
7-7
Analog Lowpass Filter Prototypes
besselap Bessel anal og l owpass fi l ter prototype.
buttap Butterworth anal og l owpass fi l ter prototype.
cheb1ap Chebyshev Type I anal og l owpass fi l ter prototype.
cheb2ap Chebyshev Type I I anal og l owpass fi l ter prototype.
ellipap El l i pti c anal og l owpass fi l ter prototype.
Analog Filter Design
besself Bessel anal og fi l ter desi gn.
butter Butterworth anal og and di gi tal fi l ter desi gn.
cheby1 Chebyshev Type I fi l ter desi gn (passband ri ppl e).
cheby2 Chebyshev Type I I fi l ter desi gn (stopband ri ppl e).
ellip El l i pti c (Cauer) fi l ter desi gn.
Analog Filter Transformation
lp2bp Transform l owpass anal og fi l ters to bandpass.
lp2bs Transform l owpass anal og fi l ters to bandstop.
lp2hp Transform l owpass anal og fi l ters to hi ghpass.
lp2lp Change the cut-off frequency for a l owpass anal og fi l ter.
7 Functi on Reference
7-8
Filter Discretization
bilinear Bi l i near transformati on method for anal og-to-di gi tal fi l ter
conversi on.
impinvar I mpul se i nvari ance method for anal og-to-di gi tal fi l ter
conversi on.
Linear System Transformations
latc2tf Convert l atti ce fi l ter parameters to transfer functi on form.
polystab Stabi l i ze a pol ynomi al .
polyscale Scal e the roots of a pol ynomi al .
residuez z-transform parti al -fracti on expansi on.
sos2ss
Convert di gi tal fi l ter second-order secti on parameters to
state-space form.
sos2tf Convert di gi tal fi l ter second-order secti on data to transfer
functi on form.
sos2zp Convert di gi tal fi l ter second-order secti ons parameters to
zero-pol e-gai n form.
ss2sos Convert di gi tal fi l ter state-space parameters to
second-order secti ons form.
ss2tf Convert state-space fi l ter parameters to transfer functi on
form.
ss2zp Convert state-space fi l ter parameters to zero-pol e-gai n
form.
tf2latc Convert transfer functi on fi l ter parameters to l atti ce fi l ter
form.
Functi on C ategory Li st
7-9
tf2sos Convert di gi tal fi l ter transfer functi on data to second-order
secti ons form.
tf2ss Convert transfer functi on fi l ter parameters to state-space
form.
tf2zp Convert transfer functi on fi l ter parameters to
zero-pol e-gai n form.
zp2sos Convert di gi tal fi l ter zero-pol e-gai n parameters to
second-order secti ons form.
zp2ss Convert zero-pol e-gai n fi l ter parameters to state-space
form.
zp2tf Convert zero-pol e-gai n fi l ter parameters to transfer
functi on form.
Windows
barthannwin Compute a modi fi ed Bartl ett-Hann wi ndow.
bartlett Compute a Bartl ett wi ndow.
blackman Compute a Bl ackman wi ndow.
blackmanharris Compute a mi ni mum 4-term Bl ackman-Harri s wi ndow.
bohmanwin Compute a Bohman wi ndow.
chebwin Compute a Chebyshev wi ndow.
gausswin Compute a Gaussi an wi ndow.
hamming Compute a Hammi ng wi ndow.
hann Compute the Hann (Hanni ng) wi ndow.
kaiser Compute a Kai ser wi ndow.
Linear System Transformations (Continued)
7 Functi on Reference
7-10
nuttallwin Compute a Nuttal l -defi ned mi ni mum 4-term
Bl ackman-Harri s wi ndow.
rectwin Compute a rectangul ar wi ndow.
triang Compute a tri angul ar wi ndow.
tukeywin Compute a Tukey (tapered cosi ne) wi ndow.
window Wi ndow functi on gateway.
Windows (Continued)
Functi on C ategory Li st
7-11
Transforms
bitrevorder Permute i nput i nto bi t-reversed order.
czt Chi rp z-transform.
dct Di screte cosi ne transform (DCT).
dftmtx Di screte Fouri er transform matri x.
fft Compute the one-di mensi onal fast Fouri er transform.
fft2 Compute the two-di mensi onal fast Fouri er transform.
fftshift Rearrange the outputs of the FFT functi ons.
goertzel Compute the di screte Fouri er transform usi ng the second
order Goertzel al gori thm.
hilbert Compute the di screte-ti me anal yti c si gnal usi ng the Hi l bert
transform.
idct I nverse di screte cosi ne transform.
ifft One-di mensi onal i nverse fast Fouri er transform.
ifft2 Two-di mensi onal i nverse fast Fouri er transform.
Cepstral Analysis
cceps Compl ex cepstral anal ysi s.
icceps I nverse compl ex cepstrum.
rceps Real cepstrum and mi ni mum phase reconstructi on.
7 Functi on Reference
7-12
Statistical Signal Processing and Spectral Analysis
cohere Esti mate magni tude squared coherence functi on between
two si gnal s.
corrcoef Compute the correl ati on coeffi ci ent matri x.
corrmtx Compute a data matri x for autocorrel ati on matri x
esti mati on.
cov Compute the covari ance matri x.
csd Esti mate the cross spectral densi ty (CSD) of two si gnal s.
pburg Esti mate the power spectral densi ty usi ng the Burg
method.
pcov Esti mate the power spectral densi ty usi ng the covari ance
method.
peig Esti mate the pseudospectrum usi ng the ei genvector
method.
periodogram Esti mate the power spectral densi ty (PSD) of a si gnal usi ng
a peri odogram.
pmcov Esti mate the power spectral densi ty usi ng the modi fi ed
covari ance method.
pmtm Esti mate the power spectral densi ty usi ng the mul ti taper
method (MTM).
pmusic Esti mate the power spectral densi ty usi ng MUSI C
al gori thm.
psdplot Pl ot power spectral densi ty (PSD) data.
pwelch Esti mate the power spectral densi ty (PSD) of a si gnal usi ng
Wel chs method.
Functi on C ategory Li st
7-13
pyulear Esti mate the power spectral densi ty usi ng the Yul e-Wal ker
AR method.
rooteig Esti mate frequency and power content usi ng the
ei genvector method.
rootmusic Esti mate frequency and power content usi ng the root
MUSI C al gori thm.
tfe Esti mate the transfer functi on from i nput and output.
xcorr Esti mate the cross-correl ati on functi on.
xcorr2 Esti mate the two-di mensi onal cross-correl ati on.
xcov Esti mate the cross-covari ance functi on (equal to
mean-removed cross-correl ati on).
Parametric Modeling
arburg Compute an esti mate of AR model parameters usi ng the
Burg method.
arcov Compute an esti mate of AR model parameters usi ng the
covari ance method.
armcov Compute an esti mate of AR model parameters usi ng the
modi fi ed covari ance method.
aryule Compute an esti mate of AR model parameters usi ng the
Yul e-Wal ker method.
ident See the System I denti fi cati on Tool box documentati on.
invfreqs I denti fy conti nuous-ti me fi l ter parameters from frequency
response data.
Statistical Signal Processing and Spectral Analysis (Continued)
7 Functi on Reference
7-14
invfreqz I denti fy di screte-ti me fi l ter parameters from frequency
response data.
prony Pronys method for ti me domai n I I R fi l ter desi gn.
stmcb Compute a l i near model usi ng Stei gl i tz-McBri de i terati on.
Parametric Modeling (Continued)
Functi on C ategory Li st
7-15
Linear Prediction
ac2poly Convert an autocorrel ati on sequence to predi cti on
pol ynomi al .
ac2rc Convert an autocorrel ati on sequence to refl ecti on
coeffi ci ents.
is2rc Convert i nverse si ne parameters to refl ecti on coeffi ci ents.
lar2rc Convert l og area rati o parameters to refl ecti on coeffi ci ents.
levinson Compute the Levi nson-Durbi n recursi on.
lpc Compute l i near predi cti on fi l ter coeffi ci ents.
lsf2poly Convert l i ne spectral frequenci es to a predi cti on fi l ter
coeffi ci ents.
poly2ac Convert a predi cti on fi l ter pol ynomi al to an autocorrel ati on
sequence.
poly2lsf Convert predi cti on fi l ter coeffi ci ents to l i ne spectral
frequenci es.
poly2rc Convert a predi cti on fi l ter pol ynomi al to refl ecti on
coeffi ci ents.
rc2ac Convert refl ecti on coeffi ci ents to an autocorrel ati on
sequence.
rc2is Convert refl ecti on coeffi ci ents to i nverse si ne parameters.
rc2lar Convert refl ecti on coeffi ci ents to l og area rati o parameters.
rc2poly Convert refl ecti on coeffi ci ents to a predi cti on fi l ter
pol ynomi al .
rlevinson Compute the reverse Levi nson-Durbi n recursi on.
schurrc Compute refl ecti on coeffi ci ents from an autocorrel ati on
sequence.
7 Functi on Reference
7-16
Multirate Signal Processing
decimate Decrease the sampl i ng rate for a sequence (deci mati on).
downsample Reduce the sampl i ng rate by an i nteger factor.
interp I ncrease sampl i ng rate by an i nteger factor (i nterpol ati on).
interp1 One-di mensi onal data i nterpol ati on (tabl e l ookup).
resample Change sampl i ng rate by any rati onal factor.
spline Cubi c spl i ne i nterpol ati on.
upfirdn Upsampl e, appl y an FI R fi l ter, and downsampl e.
upsample I ncrease the sampl i ng rate by an i nteger factor
Waveform Generation
chirp Generate a swept-frequency cosi ne.
diric Compute the Di ri chl et or peri odi c si nc functi on.
gauspuls Generate a Gaussi an-modul ated si nusoi dal pul se.
gmonopuls Generate a Gaussi an monopul se.
pulstran Generate a pul se trai n.
rectpuls Generate a sampl ed aperi odi c rectangl e.
sawtooth Generate a sawtooth or tri angl e wave.
sinc Si nc functi on.
square Generate a square wave.
tripuls Generate a sampl ed aperi odi c tri angl e.
vco Vol tage control l ed osci l l ator.
Functi on C ategory Li st
7-17
7 Functi on Reference
7-18
Specialized Operations
buffer Buffer a si gnal vector i nto a matri x of data frames.
cell2sos Convert a cel l array for second-order secti ons to a
second-order secti on matri x.
cplxpair Group compl ex numbers i nto compl ex conjugate pai rs.
demod Demodul ati on for communi cati ons si mul ati on.
dpss Di screte prol ate spheroi dal sequences (Sl epi an sequences).
dpssclear Remove di screte prol ate spheroi dal sequences from
database.
dpssdir Di screte prol ate spheroi dal sequences database di rectory.
dpssload Load di screte prol ate spheroi dal sequences from database.
dpsssave Save di screte prol ate spheroi dal sequences i n database.
eqtflength Make the l engths of a transfer functi ons numerator and
denomi nator equal .
modulate Modul ati on for communi cati ons si mul ati on.
seqperiod Compute the peri od of a sequence.
sos2cell Convert a second-order secti on matri x to cel l arrays.
specgram Ti me-dependent frequency anal ysi s (spectrogram).
stem Pl ot di screte sequence data.
strips Stri p pl ot.
udecode Decode 2
n
-l evel quanti zed i nteger i nputs to fl oati ng-poi nt
outputs.
uencode Quanti ze and encode fl oati ng-poi nt i nputs to i nteger
outputs.
Functi on C ategory Li st
7-19
Graphical User Interfaces
fdatool Open the Fi l ter Desi gn and Anal ysi s Tool .
fvtool Open the Fi l ter Vi sual i zati on Tool .
sptool I nteracti ve di gi tal si gnal processi ng tool (SPTool ).
7
7-20
Alphabetical List of Functions 7
abs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-26
ac2pol y . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-27
ac2rc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-28
angl e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-29
arburg . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-30
arcov . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-31
armcov . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-32
aryul e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-33
barthannwi n . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-34
bartl ett . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-36
bessel ap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-38
bessel f . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-39
bi l i near . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-42
bi trevorder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-47
bl ackman . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-49
bl ackmanharri s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-51
bohmanwi n . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-53
buffer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-55
buttap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-64
butter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-65
buttord . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-70
cceps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-75
cel l 2sos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-77
cheb1ap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-78
cheb1ord . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-79
cheb2ap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-83
cheb2ord . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-84
chebwi n . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-89
cheby1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-90
cheby2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-95
chi rp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-100
cohere . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-106
conv . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-110
conv2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-111
convmtx . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-113
Alphabeti cal Li st of Functi ons
7-21
corrcoef . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-115
corrmtx . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-116
cov . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-119
cpl xpai r . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-120
cremez . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-121
csd . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-129
czt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-133
dct . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-136
deci mate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-138
deconv . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-141
demod . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-142
dftmtx . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-144
di ri c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-145
downsampl e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-146
dpss . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-148
dpsscl ear . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-151
dpssdi r . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-152
dpssl oad . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-153
dpsssave . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-154
el l i p . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-155
el l i pap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-161
el l i pord . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-162
eqtfl ength . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-167
fdatool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-168
fft . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-170
fft2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-173
fftfi l t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-174
fftshi ft . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-176
fi l ter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-177
fi l ter2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-180
fi l ternorm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-181
fi l tfi l t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-183
fi l ti c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-184
fi r1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-186
fi r2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-190
fi rcl s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-193
fi rcl s1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-196
7
7-22
fi rl s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-199
fi rrcos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-204
freqs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-206
freqspace . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-208
freqz . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-209
freqzpl ot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-213
fvtool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-216
gauspul s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-220
gausswi n . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-222
gmonopul s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-224
goertzel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-226
grpdel ay . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-231
hammi ng . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-234
hann . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-236
hi l bert . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-238
i cceps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-242
i dct . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-243
i fft . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-244
i fft2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-245
i mpi nvar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-246
i mpz . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-248
i nterp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-251
i ntfi l t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-253
i nvfreqs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-255
i nvfreqz . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-259
i s2rc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-262
kai ser . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-263
kai serord . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-265
l ar2rc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-270
l atc2tf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-271
l atcfi l t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-272
l evi nson . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-274
l p2bp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-276
l p2bs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-279
l p2hp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-281
l p2l p . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-283
l pc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-285
Alphabeti cal Li st of Functi ons
7-23
l sf2pol y . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-289
maxfl at . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-290
medfi l t1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-292
modul ate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-293
nuttal l wi n . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-296
pburg . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-299
pcov . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-304
pei g . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-309
peri odogram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-316
pmcov . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-321
pmtm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-326
pmusi c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-331
pol y2ac . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-339
pol y2l sf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-340
pol y2rc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-341
pol yscal e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-343
pol ystab . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-344
prony . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-345
psdpl ot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-347
pul stran . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-349
pwel ch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-353
pyul ear . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-359
rc2ac . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-364
rc2i s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-365
rc2l ar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-366
rc2pol y . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-367
rceps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-368
rectpul s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-369
rectwi n . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-370
remez . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-371
remezord . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-378
resampl e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-381
resi duez . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-384
rl evi nson . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-387
rootei g . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-390
rootmusi c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-393
sawtooth . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-396
7
7-24
schurrc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-397
seqperi od . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-398
sgol ay . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-400
sgol ayfi l t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-404
si nc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-406
sos2cel l . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-408
sos2ss . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-409
sos2tf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-411
sos2zp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-413
sosfi l t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-415
specgram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-416
sptool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-420
square . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-425
ss2sos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-426
ss2tf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-430
ss2zp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-431
stmcb . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-433
stri ps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-436
tf2l atc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-438
tf2sos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-439
tf2ss . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-442
tf2zp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-444
tfe . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-447
tri ang . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-451
tri pul s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-453
tukeywi n . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-454
udecode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-456
uencode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-459
unwrap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-462
upfi rdn . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-463
upsampl e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-467
vco . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-469
wi ndow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-471
xcorr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-473
xcorr2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-477
xcov . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-478
yul ewal k . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-481
Alphabeti cal Li st of Functi ons
7-25
zp2sos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-483
zp2ss . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-487
zp2tf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-488
zpl ane . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-489
abs
7-26
7abs
Purpose Absol ute val ue (magni tude)
Syntax y = abs(x)
Description y = abs(x) returns the absol ute val ue of the el ements of x. I f x i s compl ex, abs
returns the compl ex modul us (magni tude).
abs(x) = sqrt(real(x).^2 + imag(x).^2)
I f x i s a MATLAB stri ng, abs returns the numeri c val ues of the ASCI I
characters i n the stri ng. The di spl ay format of the stri ng changes; the i nternal
representati on does not.
The abs functi on i s part of the standard MATLAB l anguage.
Example Cal cul ate the magni tude of the FFT of a sequence.
t = (0:99)/100; % time vector
x = sin(2*pi*15*t) + sin(2*pi*40*t); % signal
y = fft(x); % compute DFT of x
m = abs(y); % magnitude
Pl ot the magni tude.
f = (0:length(y)-1)'/length(y)*100; % frequency vector
plot(f,m)
See Also angle
ac2poly
7-27
7ac2pol y
Purpose Convert an autocorrel ati on sequence to a l i near predi cti on fi l ter pol ynomi al
Syntax a = ac2poly(r)
[a,efinal] = ac2poly(r)
Description a = ac2poly(r) fi nds the l i near predi cti on, FI R fi l ter pol ynomi al a
correspondi ng to the autocorrel ati on sequence r. a i s the same l ength as r, and
a(1) = 1. The predi cti on fi l ter pol ynomi al represents the coeffi ci ents of the
predi cti on fi l ter whose output produces a si gnal whose autocorrel ati on
sequence i s approxi matel y the same as the gi ven autocorrel ati on sequence r.
[a,efinal] = ac2poly(r) returns the fi nal predi cti on error efinal,
determi ned by runni ng the fi l ter for length(r) steps.
Remarks You can appl y thi s functi on to real or compl ex data.
Example Consi der the autocorrel ati on sequence
r = [5.0000 -1.5450 -3.9547 3.9331 1.4681 -4.7500];
The correspondi ng predi cti on fi l ter pol ynomi al i s
[a,efinal] = ac2poly(r)
a =
1.0000 0.6147 0.9898 0.0004 0.0034 -0.0077
efinal =
0.1791
See Also ac2rc, poly2ac, rc2poly
References [1] Kay, S.M. Modern Spectral Estimation. Engl ewood Cl i ffs, NJ:
Prenti ce-Hal l , 1988.
ac2rc
7-28
7ac2rc
Purpose Convert an autocorrel ati on sequence to refl ecti on coeffi ci ents
Syntax [k,r0] = ac2rc(r)
Description [k,r0] = ac2rc(r) fi nds the refl ecti on coeffi ci ents k correspondi ng to the
autocorrel ati on sequence r. r0 contai ns the i ni ti al zero-l ag autocorrel ati on.
These refl ecti on coeffi ci ents can be used to speci fy the l atti ce predi cti on fi l ter
that produces a sequence wi th approxi matel y the same autocorrel ati on
sequence as the gi ven sequence r.
Remarks You can appl y thi s functi on to real or compl ex data.
See Also ac2poly, poly2rc, rc2ac
References [1] Kay, S.M. Modern Spectral Estimation. Engl ewood Cl i ffs, NJ:
Prenti ce-Hal l , 1988.
angle
7-29
7angl e
Purpose Phase angl e
Syntax p = angle(h)
Description p = angle(h) returns the phase angl es, i n radi ans, of the el ements of compl ex
vector or array h. The phase angl es l i e between - and .
For compl ex sequence h = x +iy = me
ip
, the magni tude and phase are gi ven by
m = abs(h)
p = angle(h)
To convert to the ori gi nal h from i ts magni tude and phase, type
i = sqrt(-1)
h = m.*exp(i*p)
The angle functi on i s part of the standard MATLAB l anguage.
Example Cal cul ate the phase of the FFT of a sequence.
t = (0:99)/100; % time vector
x = sin(2*pi*15*t) + sin(2*pi*40*t); % signal
y = fft(x); % compute DFT of x
p = unwrap(angle(y)); % phase
Pl ot the phase.
f = (0:length(y)-1)'/length(y)*100; % frequency vector
plot(f,p)
Algorithm angle can be expressed as
angle(x) = imag(log(x)) = atan2(imag(x),real(x))
See Also abs
arburg
7-30
7arburg
Purpose Compute an esti mate of AR model parameters usi ng the Burg method
Syntax a = arburg(x,p)
[a,e] = arburg(x,p)
[a,e,k] = arburg(x,p)
Description a = arburg(x,p) uses the Burg method to fi t a pth order autoregressi ve (AR)
model to the i nput si gnal , x, by mi ni mi zi ng (l east squares) the forward and
backward predi cti on errors whi l e constrai ni ng the AR parameters to sati sfy
the Levi nson-Durbi n recursi on. x i s assumed to be the output of an AR system
dri ven by whi te noi se. Vector a contai ns the normal i zed esti mate of the AR
system parameters, A(z), i n descendi ng powers of z.
Si nce the method characteri zes the i nput data usi ng an al l -pol e model , the
correct choi ce of the model order p i s i mportant.
[a,e] = arburg(x,p) returns the vari ance esti mate, e, of the whi te noi se i nput
to the AR model .
[a,e,k] = arburg(x,p) returns a vector, k, of refl ecti on coeffi ci ents.
See Also arcov, armcov, aryule, lpc, pburg, prony
H z ( )
e
A z ( )
------------
e
1 a
2
z
1
a
p 1 + ( )
z
p
+ + +
---------------------------------------------------------------------- = =
arcov
7-31
7arcov
Purpose Compute an esti mate of AR model parameters usi ng the covari ance method
Syntax a = arcov(x,p)
[a,e] = arcov(x,p)
Description a = arcov(x,p) uses the covari ance method to fi t a pth order autoregressi ve
(AR) model to the i nput si gnal , x, whi ch i s assumed to be the output of an AR
system dri ven by whi te noi se. Thi s method mi ni mi zes the forward predi cti on
error i n the l east-squares sense. Vector a contai ns the normal i zed esti mate of
the AR system parameters, A(z), i n descendi ng powers of z.
Because the method characteri zes the i nput data usi ng an al l -pol e model , the
correct choi ce of the model order p i s i mportant.
[a,e] = arcov(x,p) returns the vari ance esti mate, e, of the whi te noi se i nput
to the AR model .
See Also arburg, armcov, aryule, lpc, pcov, prony
H z ( )
e
A z ( )
------------
e
1 a
2
z
1
a
p 1 + ( )
z
p
+ + +
---------------------------------------------------------------------- = =
armcov
7-32
7armcov
Purpose Compute an esti mate of AR model parameters usi ng the modi fi ed covari ance
method
Syntax a = armcov(x,p)
[a,e] = armcov(x,p)
Description a = armcov(x,p) uses the modi fi ed covari ance method to fi t a pth order
autoregressi ve (AR) model to the i nput si gnal , x, whi ch i s assumed to be the
output of an AR system dri ven by whi te noi se. Thi s method mi ni mi zes the
forward and backward predi cti on errors i n the l east-squares sense. Vector a
contai ns the normal i zed esti mate of the AR system parameters, A(z), i n
descendi ng powers of z.
Because the method characteri zes the i nput data usi ng an al l -pol e model , the
correct choi ce of the model order p i s i mportant.
[a,e] = armcov(x,p) returns the vari ance esti mate, e, of the whi te noi se i nput
to the AR model .
See Also arburg, arcov, aryule, lpc, pmcov, prony
H z ( )
e
A z ( )
------------
e
1 a
2
z
1
a
p 1 + ( )
z
p
+ + +
---------------------------------------------------------------------- = =
aryule
7-33
7aryul e
Purpose Compute an esti mate of AR model parameters usi ng the Yul e-Wal ker method
Syntax a = aryule(x,p)
[a,e] = aryule(x,p)
[a,e,k] = aryule(x,p)
Description a = aryule(x,p) uses the Yul e-Wal ker method, al so cal l ed the autocorrel ati on
method, to fi t a pth order autoregressi ve (AR) model to the wi ndowed i nput
si gnal , x, by mi ni mi zi ng the forward predi cti on error i n the l east-squares
sense. Thi s formul ati on l eads to the Yul e-Wal ker equati ons, whi ch are sol ved
by the Levi nson-Durbi n recursi on. x i s assumed to be the output of an AR
system dri ven by whi te noi se. Vector a contai ns the normal i zed esti mate of the
AR system parameters, A(z), i n descendi ng powers of z.
Because the method characteri zes the i nput data usi ng an al l -pol e model , the
correct choi ce of the model order p i s i mportant.
[a,e] = aryule(x,p) returns the vari ance esti mate, e, of the whi te noi se i nput
to the AR model .
[a,e,k] = aryule(x,p) returns a vector, k, of refl ecti on coeffi ci ents.
See Also arburg, arcov, armcov, lpc, prony, pyulear
H z ( )
e
A z ( )
------------
e
1 a
2
z
1
a
p 1 + ( )
z
p
+ + +
---------------------------------------------------------------------- = =
barthannwin
7-34
7barthannwi n
Purpose Compute a modi fi ed Bartl ett-Hann wi ndow
Syntax w = barthannwin(n)
Description w = barthannwin(n) returns an n-poi nt modi fi ed Bartl ett-Hann wi ndow i n
the col umn vector w. Li ke Bartl ett, Hann, and Hammi ng wi ndows, thi s wi ndow
has a mai nl obe at the ori gi n and asymptoti cal l y decayi ng si del obes on both
si des. I t i s a l i near combi nati on of wei ghted Bartl ett and Hann wi ndows wi th
near si del obes l ower than both Bartl ett and Hann and wi th far si del obes l ower
than both Bartl ett and Hammi ng wi ndows. The mai nl obe wi dth of the modi fi ed
Bartl ett-Hann wi ndow i s not i ncreased rel ati ve to ei ther Bartl ett or Hann
wi ndow mai nl obes.
Note The Hann wi ndow i s al so cal l ed the Hanni ng wi ndow.
Example N=64;
w = barthannwin(N);
plot(w); axis([1 N 0 1]);
title('64-point Modified Bartlett-Hann window');
10 20 30 40 50 60
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
64point Modified BartlettHann window
barthannwin
7-35
Algorithm The equati on for computi ng the coeffi ci ents of a Modi fi ed Bartl ett-Hanni ng
wi ndow i s
where .
See Also bartlett, hann, blackman, blackmanharris, bohmanwin, chebwin, gausswin,
hamming, kaiser, nuttallwin, rectwin, triang, tukeywin, window
References [1] Ha, Y.H., and J.A. Pearce. A New Wi ndow and Compari son to Standard
Wi ndows. I EEE Transactions on Acoustics, Speech, and Signal Processing.
Vol . 37, No. 2, (February 1999). pp. 298-301.
[2] Oppenhei m, A.V., and R.W. Schafer. Discrete-Time Signal Processing.
Upper Saddl e Ri ver, NJ: Prenti ce-Hal l , 1999, p. 468.
w k 1 + [ ] 0.62 0.48
k
n 1
------------- 0.5
,
_
0.38 2
k
n 1
------------- 0.5
,
_
,
_
cos + =
0 k n 1 ( )
bartlett
7-36
7bartl ett
Purpose Compute a Bartl ett wi ndow
Syntax w = bartlett(n)
Description w = bartlett(n) returns an n-poi nt Bartl ett wi ndow i n the col umn vector w,
where n must be a posi ti ve i nteger. The coeffi ci ents of a Bartl ett wi ndow are
computed as fol l ows:
For n odd
For n even
The Bartl ett wi ndow i s very si mi l ar to a tri angul ar wi ndow as returned by the
triang functi on. The Bartl ett wi ndow al ways ends wi th zeros at sampl es 1 and
n, however, whi l e the tri angul ar wi ndow i s nonzero at those poi nts. For n odd,
the center n-2 poi nts of bartlett(n) are equi val ent to triang(n-2).
Note I f you speci fy a one-poi nt wi ndow (set n=1), the val ue 1 i s returned.
Example N=64;
w = bartlett(N);
plot(w); axis([1 N 0 1]);
title('Bartlett Window')
w k 1 + [ ]
2k
n 1
------------- 0 k
n 1
2
------------- ,
2
2 k ( )
n 1
------------ -
n 1
2
------------- k n 1 ,

'

=
w k 1 + [ ]
2 k ( )
n 1
------------- 0 k
n
2
--- 1 ,
2 n k 1 ( )
n 1
------------------------------
n
2
--- k n 1 ,

'

=
bartlett
7-37
See Also barthannwin, blackman, blackmanharris, bohmanwin, chebwin, gausswin,
hamming, hann, kaiser, nuttallwin, rectwin, triang, tukeywin, window
References [1] Oppenhei m, A.V., and R.W. Schafer. Discrete-Time Signal Processing.
Upper Saddl e Ri ver, NJ: Prenti ce-Hal l , 1999, pp. 468-471.
10 20 30 40 50 60
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
Bartlett Window
besselap
7-38
7bessel ap
Purpose Bessel anal og l owpass fi l ter prototype
Syntax [z,p,k] = besselap(n)
Description [z,p,k] = besselap(n) returns the pol es and gai n of an order n Bessel anal og
l owpass fi l ter prototype. n must be l ess than or equal to 25. The functi on
returns the pol es i n the l ength n col umn vector p and the gai n i n scal ar k. z i s
an empty matri x because there are no zeros. The transfer functi on i s
besselap normal i zes the pol es and gai n so that at l ow frequency and hi gh
frequency the Bessel prototype i s asymptoti cal l y equi val ent to the Butterworth
prototype of the same order [1]. The magni tude of the fi l ter i s l ess than
at the uni ty cutoff frequency
c
= 1.
Anal og Bessel fi l ters are characteri zed by a group del ay that i s maxi mal l y fl at
at zero frequency and al most constant throughout the passband. The group
del ay at zero frequency i s
Algorithm besselap fi nds the fi l ter roots from a l ook-up tabl e constructed usi ng the
Symbol i c Math Tool box.
See Also besself, buttap, cheb1ap, cheb2ap, ellipap
Al so see the Symbol i c Math Tool box documentati on.
References [1] Rabi ner, L.R., and B. Gol d. Theory and Application of Digital Signal
Processing. Engl ewood Cl i ffs, NJ: Prenti ce-Hal l , 1975. Pgs. 228-230.
H s ( )
k
s p 1 ( ) ( ) s p 2 ( ) ( )L s p n ( ) ( )
-------------------------------------------------------------------------------- =
1 2
2n ( )!
2
n
n!
--------------
,
_
1 n
besself
7-39
7bessel f
Purpose Bessel anal og fi l ter desi gn
Syntax [b,a] = besself(n,Wn)
[b,a] = besself(n,Wn,'ftype')
[z,p,k] = besself(...)
[A,B,C,D] = besself(...)
Description besself desi gns l owpass, bandpass, hi ghpass, and bandstop anal og Bessel
fi l ters. Anal og Bessel fi l ters are characteri zed by al most constant group del ay
across the enti re passband, thus preservi ng the wave shape of fi l tered si gnal s
i n the passband. Di gi tal Bessel fi l ters do not retai n thi s qual i ty, and besself
therefore does not support the desi gn of di gi tal Bessel fi l ters.
[b,a] = besself(n,Wn) desi gns an order n l owpass anal og fi l ter wi th cutoff
frequency Wn. I t returns the fi l ter coeffi ci ents i n the l ength n+1 row vectors b
and a, wi th coeffi ci ents i n descendi ng powers of s, deri ved from the transfer
functi on
Cutoff frequency i s the frequency at whi ch the magni tude response of the fi l ter
begi ns to decrease si gni fi cantl y. For besself, the cutoff frequency Wn must be
greater than 0. The magni tude response of a Bessel fi l ter desi gned by besself
i s al ways l ess than at the cutoff frequency, and i t decreases as the order
n i ncreases.
I f Wn i s a two-el ement vector, Wn = [w1 w2] wi th w1 < w2, then besself(n,Wn)
returns an order 2*n bandpass anal og fi l ter wi th passband w1 < < w2.
[b,a] = besself(n,Wn,'ftype') desi gns a hi ghpass or bandstop fi l ter, where
the stri ng 'ftype' i s:
'high' for a hi ghpass anal og fi l ter wi th cutoff frequency Wn
'stop' for an order 2*n bandstop anal og fi l ter i f Wn i s a two-el ement vector,
Wn = [w1 w2]
The stopband i s w1 < < w2.
H s ( )
B s ( )
A s ( )
---------- -
b 1 ( )s
n
b 2 ( )s
n 1
L b n 1 + ( ) + + +
s
n
a 2 ( )s
n 1
L a n 1 + ( ) + + +
------------------------------------------------------------------------------------- = =
1 2
besself
7-40
Wi th di fferent numbers of output arguments, besself di rectl y obtai ns other
real i zati ons of the anal og fi l ter. To obtai n zero-pol e-gai n form, use three output
arguments as shown bel ow.
[z,p,k] = besself(n,Wn) or
[z,p,k] = besself(n,Wn,'ftype') returns the zeros and pol es i n l ength n or
2*n col umn vectors z and p and the gai n i n the scal ar k.
To obtai n state-space form, use four output arguments as shown bel ow.
[A,B,C,D] = besself(n,Wn) or
[A,B,C,D] = besself(n,Wn,'ftype') where A, B, C, and D are
and u i s the i nput, x i s the state vector, and y i s the output.
Example Desi gn a fi fth-order anal og l owpass Bessel fi l ter that suppresses frequenci es
greater than 10,000 rad/s and pl ot the frequency response of the fi l ter usi ng
freqs.
[b,a] = besself(5,10000);
freqs(b,a) % Plot frequency response
x

Ax Bu + =
y Cx Du + =
besself
7-41
Limitations Lowpass Bessel fi l ters have a monotoni cal l y decreasi ng magni tude response,
as do l owpass Butterworth fi l ters. Compared to the Butterworth, Chebyshev,
and el l i pti c fi l ters, the Bessel fi l ter has the sl owest rol l off and requi res the
hi ghest order to meet an attenuati on speci fi cati on.
For hi gh order fi l ters, the state-space form i s the most numeri cal l y accurate,
fol l owed by the zero-pol e-gai n form. The transfer functi on coeffi ci ent form i s
the l east accurate; numeri cal probl ems can ari se for fi l ter orders as l ow as 15.
Algorithm besself performs a four-step al gori thm:
1 I t fi nds l owpass anal og prototype pol es, zeros, and gai n usi ng the besselap
functi on.
2 I t converts the pol es, zeros, and gai n i nto state-space form.
3 I t transforms the l owpass fi l ter i nto a bandpass, hi ghpass, or bandstop fi l ter
wi th desi red cutoff frequenci es usi ng a state-space transformati on.
4 I t converts the state-space fi l ter back to transfer functi on or zero-pol e-gai n
form, as requi red.
See Also besselap, butter, cheby1, cheby2, ellip
10
2
10
3
10
4
10
5
-200
0
200
Frequency (radians)
P
h
a
s
e

(
d
e
g
r
e
e
s
)
10
2
10
3
10
4
10
5
10
-5
10
0
Frequency (radians)
M
a
g
n
i
t
u
d
e
Frequency Response
bilinear
7-42
7bi l i near
Purpose Bi l i near transformati on method for anal og-to-di gi tal fi l ter conversi on
Syntax [zd,pd,kd] = bilinear(z,p,k,fs)
[zd,pd,kd] = bilinear(z,p,k,fs,Fp)
[numd,dend] = bilinear(num,den,fs)
[numd,dend] = bilinear(num,den,fs,Fp)
[Ad,Bd,Cd,Dd] = bilinear(A,B,C,D,fs)
[Ad,Bd,Cd,Dd] = bilinear(A,B,C,D,fs,Fp)
Description The bilinear transformation i s a mathemati cal mappi ng of vari abl es. I n di gi tal
fi l teri ng, i t i s a standard method of mappi ng the s or anal og pl ane i nto the z or
di gi tal pl ane. I t transforms anal og fi l ters, desi gned usi ng cl assi cal fi l ter desi gn
techni ques, i nto thei r di screte equi val ents.
The bi l i near transformati on maps the s-pl ane i nto the z-pl ane by
Thi s transformati on maps the j axi s (from = - to +) repeatedl y around
the uni t ci rcl e ( , from = to ) by
bilinear can accept an opti onal parameter Fp that speci fi es prewarpi ng. Fp, i n
hertz, i ndi cates a match frequency, that i s, a frequency for whi ch the
frequency responses before and after mappi ng match exactl y. I n prewarped
mode, the bi l i near transformati on maps the s-pl ane i nto the z-pl ane wi th
H z ( ) H s ( )
s 2f
s
z 1
z 1 +
------------ =
=
e
j
2tan
1

2f
s
--------
,
_
=
H z ( ) H s ( )
s
2f
p

f
p
f
s
----
,
_
tan
------------------------
z 1 ( )
z 1 + ( )
----------------- =
=
bilinear
7-43
Wi th the prewarpi ng opti on, bilinear maps the j axi s (from = - to +)
repeatedl y around the uni t ci rcl e ( , from = to ) by
I n prewarped mode, bilinear matches the frequency 2f
p
(i n radi ans per
second) i n the s-pl ane to the normal i zed frequency 2f
p
/f
s
(i n radi ans per
second) i n the z-pl ane.
The bilinear functi on works wi th three di fferent l i near system
representati ons: zero-pol e-gai n, transfer functi on, and state-space form.
Zero- Pole- Ga in
[zd,pd,kd] = bilinear(z,p,k,fs) and
[zd,pd,kd] = bilinear(z,p,k,fs,Fp) convert the s-domai n transfer functi on
speci fi ed by z, p, and k to a di screte equi val ent. I nputs z and p are col umn
vectors contai ni ng the zeros and pol es, k i s a scal ar gai n, and fs i s the sampl i ng
frequency i n hertz. bilinear returns the di screte equi val ent i n col umn vectors
zd and pd and scal ar kd. Fp i s the opti onal match frequency, i n hertz, for
prewarpi ng.
Tra nsfer Function
[numd,dend] = bilinear(num,den,fs) and
[numd,dend] = bilinear(num,den,fs,Fp) convert an s-domai n transfer
functi on gi ven by num and den to a di screte equi val ent. Row vectors num and den
speci fy the coeffi ci ents of the numerator and denomi nator, respecti vel y, i n
descendi ng powers of s.
e
j
2tan
1

f
p
f
s
----
,
_
tan
2f
p
-----------------------------
,



_
=
nums ( )
den s ( )
--------------------
num1 ( )s
n
L numn ( )s numn 1 + ( ) + + +
den 1 ( )s
m
L den m ( )s den m 1 + ( ) + + +
---------------------------------------------------------------------------------------------------------- - =
bilinear
7-44
fs i s the sampl i ng frequency i n hertz. bilinear returns the di screte equi val ent
i n row vectors numd and dend i n descendi ng powers of z (ascendi ng powers
of z
-1
). Fp i s the opti onal match frequency, i n hertz, for prewarpi ng.
Sta te- Spa ce
[Ad,Bd,Cd,Dd] = bilinear(A,B,C,D,fs) and
[Ad,Bd,Cd,Dd] = bilinear(A,B,C,D,fs,Fp) convert the conti nuous-ti me
state-space system i n matri ces A, B, C, D,
to the di screte-ti me system
fs i s the sampl i ng frequency i n hertz. bilinear returns the di screte equi val ent
i n matri ces Ad, Bd, Cd, Dd. Fp i s the opti onal match frequency, i n hertz, for
prewarpi ng.
Algorithm bilinear uses one of two al gori thms dependi ng on the format of the i nput
l i near system you suppl y. One al gori thm works on the zero-pol e-gai n format
and the other on the state-space format. For transfer functi on representati ons,
bilinear converts to state-space form, performs the transformati on, and
converts the resul ti ng state-space system back to transfer functi on form.
Zero- Pole- Ga in Algorithm
For a system i n zero-pol e-gai n form, bilinear performs four steps:
1 I f Fp i s present, k = 2*pi*Fp/tan(pi*Fp/fs); otherwi se k = 2*fs.
2 I t stri ps any zeros at usi ng
z = z(find(finite(z)));
x

Ax Bu + =
y Cx Du + =
x n 1 + [ ] A
d
x n [ ] B
d
u n [ ] + =
y n [ ] C
d
x n [ ] D
d
u n [ ] + =
bilinear
7-45
3 I t transforms the zeros, pol es, and gai n usi ng
pd = (1+p/k)./(1-p/k);
zd = (1+z/k)./(1-z/k);
kd = real(k*prod(fs-z)./prod(fs-p));
4 I t adds extra zeros at -1 so the resul ti ng system has equi val ent numerator
and denomi nator order.
Sta te- Spa ce Algorithm
For a system i n state-space form, bilinear performs two steps:
1 I f Fp i s present, k = 2*pi*Fp/tan(pi*Fp/fs); el se k = 2*fs.
2 I t computes Ad, Bd, Cd, and Dd i n terms of A, B, C, and D usi ng
bilinear i mpl ements these rel ati ons usi ng conventi onal MATLAB
statements. The scal ar r i s arbi trary; bilinear uses to ensure good
quanti zati on noi se properti es i n the resul ti ng system.
Diagnostics bilinear requi res that the numerator order be no greater than the
denomi nator order. I f thi s i s not the case, bilinear di spl ays
Numerator cannot be higher order than denominator.
For bilinear to di sti ngui sh between the zero-pol e-gai n and transfer functi on
l i near system formats, the fi rst two i nput parameters must be vectors wi th the
same ori entati on i n these cases. I f thi s i s not the case, bilinear di spl ays
First two arguments must have the same orientation.
See Also impinvar, lp2bp, lp2bs, lp2hp, lp2lp
A
d
I
1
k
---
,
_
A +
,
_
I
1
k
---
,
_
A
,
_
1
=
B
d
2k
r
------- I
1
k
---
,
_
A
,
_
1
B =
C
d
rC I
1
k
---
,
_
A
,
_
1
=
D
d
1
k
---
,
_
C I
1
k
---
,
_
A
,
_
1
B D + =
r 2 k =
bilinear
7-46
References [1] Parks, T.W., and C.S. Burrus. Digital Filter Design. New York: John Wi l ey
& Sons, 1987. Pgs. 209-213.
[2] Oppenhei m, A.V., and R.W. Schafer. Discrete-Time Signal Processing.
Upper Saddl e Ri ver, NJ: Prenti ce-Hal l , 1999, pp. 450-454.
bitrevorder
7-47
7bi trevorder
Purpose Permute data i nto bi t-reversed order
Syntax y = bitrevorder(x)
[y,i] = bitrevorder(x)
Description bitrevorder i s useful for pre-arrangi ng fi l ter coeffi ci ents so that bi t-reversed
orderi ng does not have to be performed as part of an FFT or i nverse FFT
computati on. Thi s can i mprove run-ti me effi ci ency for external appl i cati ons or
for Si mul i nk Bl ockset model s. Note that MATLAB fft and ifft process l i near
i nput and output.
y = bitrevorder(x) returns the i nput data i n bi t-reversed order i n vector or
matri x y. The l ength of x must be an i nteger power of 2. I f x i s a matri x, the
bi t-reversal occurs on the fi rst di mensi on of x wi th si ze greater than 1. y i s the
same si ze as x.
[y,i] = bitrevorder(x) returns the bi t-reversed vector or matri x y and the
bi t-reversed i ndi ces i, such that y = x(i). Recal l that MATLAB uses 1-based
i ndexi ng, so the fi rst i ndex of y wi l l be 1, not 0.
The fol l owi ng tabl e shows the numbers 0 through 7, the correspondi ng bi ts and
the bi t-reversed numbers.
Linear
Index
Bits Bit-
Reversed
Bit-Reversed
Index
0 000 000 0
1 001 100 4
2 010 010 2
3 011 110 6
4 100 001 1
5 101 101 5
6 110 011 3
7 111 111 7
bitrevorder
7-48
Example Obtai n the bi t-reversed ordered output of a vector.
x=[0:7]'; % Create a column vector
[x,bitrevorder(x)]
ans =
0 0
1 4
2 2
3 6
4 1
5 5
6 3
7 7
See Also fft, ifft
blackman
7-49
7bl ackman
Purpose Compute a Bl ackman wi ndow
Syntax w = blackman(n)
w = blackman(n,'sflag')
Description w = blackman(n) returns the n-poi nt symmetri c Bl ackman wi ndow i n the
col umn vector w, where n i s a posi ti ve i nteger.
w = blackman(n,'sflag') returns an n-poi nt Bl ackman wi ndow usi ng the
wi ndow sampl i ng speci fi ed by 'sflag', whi ch can be ei ther 'periodic' or
'symmetric' (the defaul t). When 'periodic' i s speci fi ed, blackman computes
a l ength n+1 wi ndow and returns the fi rst n poi nts.
Note I f you speci fy a one-poi nt wi ndow (set n=1), the val ue 1 i s returned.
Algorithm The equati on for computi ng the coeffi ci ents of a Bl ackman wi ndow i s
Bl ackman wi ndows have sl i ghtl y wi der central l obes and l ess si deband l eakage
than equi val ent l ength Hammi ng and Hann wi ndows.
Examples N=64;
w = blackman(N);
plot(w); axis([1 N 0 1]);
title('Blackman Window')
w k 1 + [ ] 0.42 0.5 2
k
n 1
-------------
,
_
cos 0.08 4
k
n 1
------------ -
,
_
cos + k 0 = n 1 , , , =
blackman
7-50
Algorithm The equati on for computi ng the coeffi ci ents of a Bl ackman wi ndow i s
Bl ackman wi ndows have sl i ghtl y wi der central l obes and l ess si deband l eakage
than equi val ent l ength Hammi ng and Hann wi ndows.
See Also barthannwin, bartlett, blackmanharris, bohmanwin, chebwin, gausswin,
hamming, hann, kaiser, nuttallwin, rectwin, triang, tukeywin, window
References [1] Oppenhei m, A.V., and R.W. Schafer. Discrete-Time Signal Processing.
Upper Saddl e Ri ver, NJ: Prenti ce-Hal l , 1999, pp. 468-471.
10 20 30 40 50 60
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
Blackman Window
w k 1 + [ ] 0.42 0.5 2
k
n 1
-------------
,
_
cos 0.08 4
k
n 1
------------ -
,
_
cos + k 0 = n 1 , , , =
blackmanharris
7-51
7bl ackmanharri s
Purpose Compute a mi ni mum 4-term Bl ackman-harri s wi ndow
Syntax w = blackmanharris(n)
Description w = blackmanharris(n) returns an n-poi nt, mi ni mum , 4-term
Bl ackman-harri s wi ndow i n the col umn vector w. The wi ndow i s mi ni mum i n
the sense that i ts maxi mum si del obes are mi ni mi zed.
Example N=32;
w = blackmanharris(N);
plot(w); axis([1 N 0 1]);
title('32-point Blackman-harris window');
Algorithm The equati on for computi ng the coeffi ci ents of a mi ni mum 4-term
Bl ackman-harri s wi ndow i s
where .
5 10 15 20 25 30
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
32point Blackmanharris window
w k 1 + [ ] a
0
a
1
2
k
n 1
-------------
,
_
a
2
4
k
n 1
-------------
,
_
cos a
3
6
k
n 1
-------------
,
_
cos + cos =
0 k n 1 ( )
blackmanharris
7-52
The coeffi ci ents for thi s wi ndow are
See Also barthannwin, bartlett, blackman, bohmanwin, chebwin, gausswin, hann,
hamming, kaiser, nuttallwin, rectwin, triang, tukeywin, window
References [1] harri s, f. j. On the Use of Wi ndows for Harmoni c Anal ysi s wi th the Di screte
Fouri er Transform. Proceedings of the I EEE. Vol . 66 (January 1978). pp.
51-84.
a
0
= 0.35875
a
1
= 0.48829
a
2
= 0.14128
a
3
= 0.01168
bohmanwin
7-53
7bohmanwi n
Purpose Compute a Bohman wi ndow
Syntax w = bohmanwin(n)
Description w = bohmanwin(n) returns an n-poi nt Bohman wi ndow i n col umn vector w. A
Bohman wi ndow i s the convol uti on of two hal f-durati on cosi ne l obes. I n the
ti me domai n, i t i s the product of a tri angul ar wi ndow and a si ngl e cycl e of a
cosi ne wi th a term added to set the fi rst deri vati ve to zero at the boundary.
Bohman wi ndows fal l off as 1/w
4
.
Example Compute a 64-poi nt Bohman wi ndow.
N=64;
w = bohmanwin(N);
plot(w); axis([1 N 0 1]);
title('64-point Bohman window');
Algorithm The equati on for computi ng the coeffi ci ents of a Bohman wi ndow i s
10 20 30 40 50 60
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
64point Bohman window
bohmanwin
7-54
where .
See Also barthannwin, bartlett, blackman, blackmanharris, chebwin, gausswin, hann,
hamming, kaiser, nuttallwin, rectwin, triang, tukeywin, window
References [1] harri s, f. j. On the Use of Wi ndows for Harmoni c Anal ysi s wi th the Di screte
Fouri er Transform. Proceedings of the I EEE. Vol . 66 (January 1978). p. 67.
w k 1 + [ ] 1.0
k
N
2
----
,
_
N
2
----
-------------------
k
N
2
----
,
_
N
2
----
-------------------
1

---
k
N
2
----
,
_
N
2
----
------------------- si n + cos =
0 k N
buffer
7-55
7buffer
Purpose Buffer a si gnal vector i nto a matri x of data frames
Syntax y = buffer(x,n)
y = buffer(x,n,p)
y = buffer(x,n,p,opt)
[y,z] = buffer(...)
[y,z,opt] = buffer(...)
Description y = buffer(x,n) parti ti ons a l ength-L si gnal vector x i nto nonoverl appi ng data
segments (frames) of l ength n. Each data frame occupi es one col umn of matri x
output y, whi ch has n rows and ceil(L/n) col umns. I f L i s not evenl y di vi si bl e
by n, the l ast col umn i s zero-padded to l ength n.
y = buffer(x,n,p) overl aps or underl aps successi ve frames i n the output
matri x by p sampl es:
For 0 < p < n (overl ap), buffer repeats the fi nal p sampl es of each frame at
the begi nni ng of the fol l owi ng frame. For exampl e, i f x = 1:30 and n = 7, an
overl ap of p = 3 l ooks l i ke thi s.
The fi rst frame starts wi th p zeros (the defaul t i ni ti al condi ti on), and the
number of col umns i n y i s ceil(L/(n-p)).
y =
0 2 6 10 14 18 22 26
0 3 7 11 15 19 23 27
0 4 8 12 16 20 24 28
1 5 9 13 17 21 25 29
2 6 10 14 18 22 26 30
3 7 11 15 19 23 27 0
4 8 12 16 20 24 28 0
buffer
7-56
For p < 0 (underl ap), buffer ski ps p sampl es between consecuti ve frames.
For exampl e, i f x = 1:30 and n = 7, a buffer wi th underl ap of p = -3 l ooks l i ke
thi s.
The number of col umns i n y i s ceil(L/(n-p)).
y = buffer(x,n,p,opt) speci fi es a vector of sampl es to precede x(1) i n an
overl appi ng buffer, or the number of i ni ti al sampl es to ski p i n an underl appi ng
buffer:
For 0 < p < n (overl ap), opt speci fi es a l ength-p vector to i nsert before x(1) i n
the buffer. Thi s vector can be consi dered an initial condition, whi ch i s needed
when the current bufferi ng operati on i s one i n a sequence of consecuti ve
bufferi ng operati ons. To mai ntai n the desi red frame overl ap from one buffer
to the next, opt shoul d contai n the fi nal p sampl es of the previ ous buffer i n
the sequence. See Conti nuous Bufferi ng bel ow.
By defaul t, opt i s zeros(p,1) for an overl appi ng buffer. Set opt to
'nodelay' to ski p the i ni ti al condi ti on and begi n fi l l i ng the buffer
i mmedi atel y wi th x(1). I n thi s case, L must be length(p) or l onger. For
exampl e, i f x = 1:30 and n = 7, a buffer wi th overl ap of p = 3 l ooks l i ke thi s.
For p < 0 (underl ap), opt i s an i nteger val ue i n the range [0,-p] speci fyi ng
the number of i ni ti al i nput sampl es, x(1:opt), to ski p before addi ng sampl es
y =
1 11 21
2 12 22
3 13 23
4 14 24
5 15 25
6 16 26
7 17 27
8 18 28
9 19 29
10 20 30
skipped
y =
1 5 9 13 17 21 25
2 6 10 14 18 22 26
3 7 11 15 19 23 27
4 8 12 16 20 24 28
5 9 13 17 21 25 29
6 10 14 18 22 26 30
7 11 15 19 23 27 0
buffer
7-57
to the buffer. The fi rst val ue i n the buffer i s therefore x(opt+1). By defaul t,
opt i s zero for an underl appi ng buffer.
Thi s opti on i s especi al l y useful when the current bufferi ng operati on i s one
i n a sequence of consecuti ve bufferi ng operati ons. To mai ntai n the desi red
frame underl ap from one buffer to the next, opt shoul d equal the di fference
between the total number of poi nts to ski p between frames (p) and the
number of poi nts that were available to be ski pped i n the previ ous i nput to
buffer. I f the previ ous i nput had fewer than p poi nts that coul d be ski pped
after fi l l i ng the fi nal frame of that buffer, the remai ni ng opt poi nts need to
be removed from the fi rst frame of the current buffer. See Conti nuous
Bufferi ng bel ow for an exampl e of how thi s works i n practi ce.
[y,z] = buffer(...) parti ti ons the l ength-L si gnal vector x i nto frames of
l ength n, and outputs onl y the full frames i n y. I f y i s an overl appi ng buffer, i t
has n rows and m col umns, where
m = floor(L/(n-p)) % When length(opt) = p
or
m = floor((L-n)/(n-p))+1 % When opt = 'nodelay'
I f y i s an underl appi ng buffer, i t has n rows and m col umns, where
m = floor((L-opt)/(n-p)) + (rem((L-opt),(n-p)) >= n)
I f the number of sampl es i n the i nput vector (after the appropri ate overl appi ng
or underl appi ng operati ons) exceeds the number of pl aces avai l abl e i n the
n-by-m buffer, the remai ni ng sampl es i n x are output i n vector z, whi ch for an
overl appi ng buffer has l ength
length(z) = L - m*(n-p) % When length(opt) = p
or
length(z) = L - ((m-1)*(n-p)+n)% When opt = 'nodelay'
and for an underl appi ng buffer has l ength
length(z) = (L-opt) - m*(n-p)
buffer
7-58
Output z shares the same ori entati on (row or col umn) as x. I f there are no
remai ni ng sampl es i n the i nput after the buffer wi th the speci fi ed overl ap or
underl ap i s fi l l ed, z i s an empty vector.
[y,z,opt] = buffer(...) returns the l ast p sampl es of a overl appi ng buffer i n
output opt. I n an underl appi ng buffer, opt i s the di fference between the total
number of poi nts to ski p between frames (-p) and the number of poi nts i n x that
were available to be ski pped after fi l l i ng the l ast frame:
For 0 < p < n (overl ap), opt (as an output) contai ns the fi nal p sampl es i n the
l ast frame of the buffer. Thi s vector can be used as the initial condition for a
subsequent bufferi ng operati on i n a sequence of consecuti ve bufferi ng
operati ons. Thi s al l ows the desi red frame overl ap to be mai ntai ned from one
buffer to the next. See Conti nuous Bufferi ng bel ow.
For p < 0 (underl ap), opt (as an output) i s the di fference between the total
number of poi nts to ski p between frames (-p) and the number of poi nts i n x
that were available to be ski pped after fi l l i ng the l ast frame.
opt = m*(n-p) + opt - L % z is the empty vector.
where opt on the ri ght-hand si de i s the i nput argument to buffer, and opt
on the l eft-hand si de i s the output argument. Here m i s the number of
col umns i n the buffer, whi ch i s
m = floor((L-opt)/(n-p)) + (rem((L-opt),(n-p))>=n)
Note that for an underl appi ng buffer output opt i s al ways zero when
output z contai ns data.
The opt output for an underl appi ng buffer i s especi al l y useful when the
current bufferi ng operati on i s one i n a sequence of consecuti ve bufferi ng
operati ons. The opt output from each bufferi ng operati on speci fi es the
number of sampl es that need to be ski pped at the start of the next bufferi ng
operati on to mai ntai n the desi red frame underl ap from one buffer to the
next. I f fewer than p poi nts were avai l abl e to be ski pped after fi l l i ng the fi nal
frame of the current buffer, the remai ni ng opt poi nts need to be removed
from the fi rst frame of the next buffer.
I n a sequence of bufferi ng operati ons, the opt output from each operati on
shoul d be used as the opt i nput to the subsequent bufferi ng operati on. Thi s
ensures that the desi red frame overl ap or underl ap i s mai ntai ned from buffer
buffer
7-59
to buffer, as wel l as from frame to frame wi thi n the same buffer. See
Conti nuous Bufferi ng bel ow for an exampl e of how thi s works i n practi ce.
Continuous Buf fering
I n a conti nuous bufferi ng operati on, the vector i nput to the buffer functi on
represents one frame i n a sequence of frames that make up a di screte si gnal .
These si gnal frames can ori gi nate i n a frame-based data acqui si ti on process, or
wi thi n a frame-based al gori thm l i ke the FFT.
As an exampl e, you mi ght acqui re data from an A/D card i n frames of 64
sampl es. I n the si mpl est case, you coul d rebuffer the data i nto frames of 16
sampl es; buffer wi th n = 16 creates a buffer of four frames from each
64-el ement i nput frame. The resul t i s that the si gnal of frame si ze 64 has been
converted to a si gnal of frame si ze 16; no sampl es were added or removed.
I n the general case where the ori gi nal si gnal frame si ze, L, i s not equal l y
di vi si bl e by the new frame si ze, n, the overfl ow from the l ast frame needs to be
captured and recycl ed i nto the fol l owi ng buffer. You can do thi s by i terati vel y
cal l i ng buffer on i nput x wi th the two-output-argument syntax.
[y,z] = buffer([z;x],n) % x is a column vector.
[y,z] = buffer([z,x],n) % x is a row vector.
Thi s si mpl y captures any buffer overfl ow i n z, and prepends the data to the
subsequent i nput i n the next cal l to buffer. Agai n, the i nput si gnal , x, of frame
si ze L, has been converted to a si gnal of frame si ze n wi thout any i nserti on or
del eti on of sampl es.
Note that conti nuous bufferi ng cannot be done wi th the si ngl e-output syntax
y = buffer(...), because the l ast frame of y i n thi s case i s zero padded, whi ch
adds new sampl es to the si gnal .
Conti nuous bufferi ng i n the presence of overl ap and underl ap i s handl ed wi th
the opt parameter, whi ch i s used as both an i nput and output to buffer. The
fol l owi ng two exampl es demonstrate how the opt parameter shoul d be used.
buffer
7-60
Examples Ex a mple 1 : Continuous O verla pping Buf fers
Fi rst create a buffer contai ni ng 100 frames, each wi th 11 sampl es.
data = buffer(1:1100,11); % 11 samples per frame
I magi ne that the frames (col umns) i n the matri x cal l ed data are the sequenti al
outputs of a data acqui si ti on board sampl i ng a physi cal si gnal : data(:,1) i s
the fi rst D/A output, contai ni ng the fi rst 11 si gnal sampl es; data(:,2) i s the
second output, contai ni ng the next 11 si gnal sampl es, and so on.
You want to rebuffer thi s si gnal from the acqui red frame si ze of 11 to a frame
si ze of 4 wi th an overl ap of 1. To do thi s, you wi l l repeatedl y cal l buffer to
operate on each successi ve i nput frame, usi ng the opt parameter to mai ntai n
consi stency i n the overl ap from one buffer to the next.
Set the buffer parameters.
n = 4; % New frame size
p = 1; % Overlap
opt = -5; % Value of y(1)
z = []; % Initialize the carry-over vector.
Now repeatedl y cal l buffer, each ti me passi ng i n a new si gnal frame from
data. Note that overfl ow sampl es (returned i n z) are carri ed over and
prepended to the i nput i n the subsequent cal l to buffer.
for i=1:size(data,2), % Loop over each source frame (column).
x = data(:,i); % A single frame of the D/A output
[y,z,opt] = buffer([z;x],n,p,opt);
disp(y); % Display the buffer of data.
pause
end
buffer
7-61
Heres what happens duri ng the fi rst four i terati ons.
Note that the si ze of the output matri x, y, can vary by a si ngl e col umn from one
i terati on to the next. Thi s i s typi cal for bufferi ng operati ons wi th overl ap or
underl ap.
[1:11] i=1
5 3 6
1 4 7
2 5 8
3 6 9
Iteration Input frame[z;x]' opt (input) opt (output) Output buffer (y) Overflow(z)
[10 11] 5 9
i=2 [10 11 12:22] 9 21
9 12 15 18
10 13 16 19
11 14 17 20
12 15 18 21
[22]
i=3 [22 23:33] 21 33
21 24 27 30
22 25 28 31
23 26 29 32
24 27 30 33
[]
33 36 39
34 37 40
35 38 41
36 39 42
[43 44] 42 [34:44]
i=4
33
buffer
7-62
Ex a mple 2 : Continuous Underla pping Buf fers
Agai n create a buffer contai ni ng 100 frames, each wi th 11 sampl es.
data = buffer(1:1100,11); % 11 samples per frame
Agai n, i magi ne that data(:,1) i s the fi rst D/A output, contai ni ng the fi rst 11
si gnal sampl es; data(:,2) i s the second output, contai ni ng the next 11 si gnal
sampl es, and so on.
You want to rebuffer thi s si gnal from the acqui red frame si ze of 11 to a frame
si ze of 4 wi th an underl ap of 2. To do thi s, you wi l l repeatedl y cal l buffer to
operate on each successi ve i nput frame, usi ng the opt parameter to mai ntai n
consi stency i n the underl ap from one buffer to the next.
Set the buffer parameters.
n = 4; % New frame size
p = -2; % Underlap
opt = 1; % Skip the first input element, x(1).
z = []; % Initialize the carry-over vector.
Now repeatedl y cal l buffer, each ti me passi ng i n a new si gnal frame from
data. Note that overfl ow sampl es (returned i n z) are carri ed over and
prepended to the i nput i n the subsequent cal l to buffer.
for i=1:size(data,2), % Loop over each source frame (column).
x = data(:,i); % A single frame of the D/A output
[y,z,opt] = buffer([z;x],n,p,opt);
disp(y); % Display the buffer of data.
pause
end
buffer
7-63
Heres what happens duri ng the fi rst three i terati ons.
Diagnostics Error messages are di spl ayed when p n or length(opt) length(p) i n an
overl appi ng buffer case.
Frame overlap P must be less than the buffer size N.
Initial conditions must be specified as a length-P vector.
See Also reshape
[1:11] i=1
2 8
3 9
4 10
5 11
Iteration Input frame[z;x]' opt (input) opt (output) Output buffer (y) Overflow(z)
[] 1 2
i=2 [12:22] 2 0
14
15
16
17
[20 21 22]
i=3 [20 21 22 23:33] 0 0
20 26
21 27
22 28
23 29
[32 33]
6
7
1
18
19
12
13

24 30
25 31
skip
skip
skip
skip
skip
skip
buttap
7-64
7buttap
Purpose Butterworth anal og l owpass fi l ter prototype
Syntax [z,p,k] = buttap(n)
Description [z,p,k] = buttap(n) returns the pol es and gai n of an order n Butterworth
anal og l owpass fi l ter prototype. The functi on returns the pol es i n the l ength n
col umn vector p and the gai n i n scal ar k. z i s an empty matri x because there
are no zeros. The transfer functi on i s
Butterworth fi l ters are characteri zed by a magni tude response that i s
maxi mal l y fl at i n the passband and monotoni c overal l . I n the l owpass case, the
fi rst 2n1 deri vati ves of the squared magni tude response are zero at = 0. The
squared magni tude response functi on i s
correspondi ng to a transfer functi on wi th pol es equal l y spaced around a ci rcl e
i n the l eft hal f pl ane. The magni tude response at the cutoff frequency
0
i s
al ways regardl ess of the fi l ter order. buttap sets
0
to 1 for a normal i zed
resul t.
Algorithm z = [];
p = exp(sqrt(-1)*(pi*(1:2:2*n-1)/(2*n)+pi/2)).';
k = real(prod(-p));
See Also besselap, butter, cheb1ap, cheb2ap, ellipap
References [1] Parks, T.W., and C.S. Burrus. Digital Filter Design. New York: John Wi l ey
& Sons, 1987. Chapter 7.
H s ( )
z s ( )
p s ( )
----------
k
s p 1 ( ) ( ) s p 2 ( ) ( )L s p n ( ) ( )
-------------------------------------------------------------------------------- = =
H ( )
2
1
1
0
( )
2n
+
----------------------------------- - =
1 2
butter
7-65
7butter
Purpose Butterworth anal og and di gi tal fi l ter desi gn
Syntax [b,a] = butter(n,Wn)
[b,a] = butter(n,Wn,'ftype')
[b,a] = butter(n,Wn,'s')
[b,a] = butter(n,Wn,'ftype','s')
[z,p,k] = butter(...)
[A,B,C,D] = butter(...)
Description butter desi gns l owpass, bandpass, hi ghpass, and bandstop di gi tal and anal og
Butterworth fi l ters. Butterworth fi l ters are characteri zed by a magni tude
response that i s maxi mal l y fl at i n the passband and monotoni c overal l .
Butterworth fi l ters sacri fi ce rol l off steepness for monotoni ci ty i n the pass- and
stopbands. Unl ess the smoothness of the Butterworth fi l ter i s needed, an
el l i pti c or Chebyshev fi l ter can general l y provi de steeper rol l off characteri sti cs
wi th a l ower fi l ter order.
Digita l Doma in
[b,a] = butter(n,Wn) desi gns an order n l owpass di gi tal Butterworth fi l ter
wi th cutoff frequency Wn. I t returns the fi l ter coeffi ci ents i n l ength n+1 row
vectors b and a, wi th coeffi ci ents i n descendi ng powers of z.
Cutoff frequency i s that frequency where the magni tude response of the fi l ter
i s . For butter, the normal i zed cutoff frequency Wn must be a number
between 0 and 1, where 1 corresponds to the Nyqui st frequency, radi ans per
sampl e.
I f Wn i s a two-el ement vector, Wn = [w1 w2], butter returns an order 2*n di gi tal
bandpass fi l ter wi th passband w1 < < w2.
H z ( )
B z ( )
A z ( )
-----------
b 1 ( ) b 2 ( )z
1
L b n 1 + ( )z
n
+ + +
1 a 2 ( )z
1
L a n 1 + ( )z
n
+ + +
------------------------------------------------------------------------------------ = =
1 2
butter
7-66
[b,a] = butter(n,Wn,'ftype') desi gns a hi ghpass or bandstop fi l ter, where
the stri ng 'ftype' i s ei ther:
'high' for a hi ghpass di gi tal fi l ter wi th cutoff frequency Wn
'stop' for an order 2*n bandstop di gi tal fi l ter i f Wn i s a two-el ement vector,
Wn = [w1 w2]. The stopband i s w1 < < w2.
Wi th di fferent numbers of output arguments, butter di rectl y obtai ns other
real i zati ons of the fi l ter. To obtai n zero-pol e-gai n form, use three output
arguments as shown bel ow.
[z,p,k] = butter(n,Wn) or
[z,p,k] = butter(n,Wn,'ftype') returns the zeros and pol es i n l ength n
col umn vectors z and p, and the gai n i n the scal ar k.
To obtai n state-space form, use four output arguments as shown bel ow.
[A,B,C,D] = butter(n,Wn) or
[A,B,C,D] = butter(n,Wn,'ftype') where A, B, C, and D are
and u i s the i nput, x i s the state vector, and y i s the output.
Ana log Doma in
[b,a] = butter(n,Wn,'s') desi gns an order n l owpass anal og Butterworth
fi l ter wi th cutoff frequency Wn rad/s. I t returns the fi l ter coeffi ci ents i n the
l ength n+1 row vectors b and a, i n descendi ng powers of s, deri ved from the
transfer functi on
butters cutoff frequency Wn must be greater than 0 rad/s.
I f Wn i s a two-el ement vector wi th w1 < w2, butter(n,Wn,'s') returns an order
2*n bandpass anal og fi l ter wi th passband w1 < < w2.
x n 1 + [ ] Ax n [ ] Bu n [ ] + =
y n [ ] Cx n [ ] Du n [ ] + =
H s ( )
B s ( )
A s ( )
---------- -
b 1 ( )s
n
b 2 ( )s
n 1
L b n 1 + ( ) + + +
s
n
a 2 ( )s
n 1
L a n 1 + ( ) + + +
------------------------------------------------------------------------------------- = =
butter
7-67
[b,a] = butter(n,Wn,'ftype','s') desi gns a hi ghpass or bandstop fi l ter.
Wi th di fferent numbers of output arguments, butter di rectl y obtai ns other
real i zati ons of the anal og fi l ter. To obtai n zero-pol e-gai n form, use three output
arguments as shown bel ow.
[z,p,k] = butter(n,Wn,'s') or
[z,p,k] = butter(n,Wn,'ftype','s') returns the zeros and pol es i n l ength
n or 2*n col umn vectors z and p and the gai n i n the scal ar k.
To obtai n state-space form, use four output arguments as shown bel ow.
[A,B,C,D] = butter(n,Wn,'s') or
[A,B,C,D] = butter(n,Wn,'ftype','s') where A, B, C, and D are
and u i s the i nput, x i s the state vector, and y i s the output.
Examples Ex a mple 1
For data sampl ed at 1000 Hz, desi gn a 9th-order hi ghpass Butterworth fi l ter
wi th cutoff frequency of 300 Hz.
[b,a] = butter(9,300/500,'high');
The fi l ters frequency response i s
freqz(b,a,128,1000)
x

Ax Bu + =
y Cx Du + =
butter
7-68
Ex a mple 2
Desi gn a 10th-order bandpass Butterworth fi l ter wi th a passband from 100 to
200 Hz and pl ot i ts i mpul se response, or unit sample response.
n = 5; Wn = [100 200]/500;
[b,a] = butter(n,Wn);
[y,t] = impz(b,a,101);
stem(t,y)
0 50 100 150 200 250 300 350 400 450 500
800
600
400
200
0
200
Frequency (Hz)
P
h
a
s
e

(
d
e
g
r
e
e
s
)
0 50 100 150 200 250 300 350 400 450 500
400
300
200
100
0
100
Frequency (Hz)
M
a
g
n
i
t
u
d
e

(
d
B
)
0 10 20 30 40 50 60 70 80 90 100
0.25
0.2
0.15
0.1
0.05
0
0.05
0.1
0.15
0.2
butter
7-69
Limitations For hi gh order fi l ters, the state-space form i s the most numeri cal l y accurate,
fol l owed by the zero-pol e-gai n form. The transfer functi on coeffi ci ent form i s
the l east accurate; numeri cal probl ems can ari se for fi l ter orders as l ow as 15.
Algorithm butter uses a fi ve-step al gori thm:
1 I t fi nds the l owpass anal og prototype pol es, zeros, and gai n usi ng the buttap
functi on.
2 I t converts the pol es, zeros, and gai n i nto state-space form.
3 I t transforms the l owpass fi l ter i nto a bandpass, hi ghpass, or bandstop fi l ter
wi th desi red cutoff frequenci es, usi ng a state-space transformati on.
4 For di gi tal fi l ter desi gn, butter uses bilinear to convert the anal og fi l ter
i nto a di gi tal fi l ter through a bi l i near transformati on wi th frequency
prewarpi ng. Careful frequency adjustment guarantees that the anal og
fi l ters and the di gi tal fi l ters wi l l have the same frequency response
magni tude at Wn or w1 and w2.
5 I t converts the state-space fi l ter back to transfer functi on or zero-pol e-gai n
form, as requi red.
See Also besself, buttap, buttord, cheby1, cheby2, ellip, maxflat
buttord
7-70
7buttord
Purpose Cal cul ate the order and cutoff frequency for a Butterworth fi l ter
Syntax [n,Wn] = buttord(Wp,Ws,Rp,Rs)
[n,Wn] = buttord(Wp,Ws,Rp,Rs,'s')
Description buttord cal cul ates the mi ni mum order of a di gi tal or anal og Butterworth fi l ter
requi red to meet a set of fi l ter desi gn speci fi cati ons.
Digita l Doma in
[n,Wn] = buttord(Wp,Ws,Rp,Rs) returns the l owest order, n, of the di gi tal
Butterworth fi l ter that l oses no more than Rp dB i n the passband and has at
l east Rs dB of attenuati on i n the stopband. The scal ar (or vector) of
correspondi ng cutoff frequenci es, Wn, i s al so returned. Use the output
arguments n and Wn i n butter.
Choose the i nput arguments to speci fy the stopband and passband accordi ng to
the fol l owi ng tabl e.
Table 7-1: Description of Stopband and Passband Filter Parameters
Wp Passband corner frequency Wp, the cutoff frequency, i s a scal ar
or a two-el ement vector wi th val ues between 0 and 1, wi th 1
correspondi ng to the normal i zed Nyqui st frequency, radi ans
per sampl e.
Ws Stopband corner frequency Ws, i s a scal ar or a two-el ement
vector wi th val ues between 0 and 1, wi th 1 correspondi ng to
the normal i zed Nyqui st frequency.
Rp Passband ri ppl e, i n deci bel s. Thi s val ue i s the maxi mum
permi ssi bl e passband l oss i n deci bel s.
Rs Stopband attenuati on, i n deci bel s. Thi s val ue i s the number of
deci bel s the stopband i s down from the passband.
buttord
7-71
Use the fol l owi ng gui de to speci fy fi l ters of di fferent types.
I f your fi l ter speci fi cati ons cal l for a bandpass or bandstop fi l ter wi th unequal
ri ppl e i n each of the passbands or stopbands, desi gn separate l owpass and
hi ghpass fi l ters accordi ng to the speci fi cati ons i n thi s tabl e, and cascade the
two fi l ters together.
Ana log Doma in
[n,Wn] = buttord(Wp,Ws,Rp,Rs,'s') fi nds the mi ni mum order n and cutoff
frequenci es Wn for an anal og Butterworth fi l ter. You speci fy the frequenci es Wp
and Ws si mi l ar to Tabl e 7-1, onl y i n thi s case you speci fy the frequency i n
radi ans per second, and the passband or the stopband can be i nfi ni te.
Use buttord for l owpass, hi ghpass, bandpass, and bandstop fi l ters as descri bed
i n Tabl e 7-2.
Table 7-2: Filter Type Stopband and Passband Specifications
Filter Type Stopband and Passband Conditions Stopband Passband
Lowpass Wp < Ws, both scal ars (Ws,1) (0,Wp)
Hi ghpass Wp > Ws, both scal ars (0,Ws) (Wp,1)
Bandpass The i nterval speci fi ed by Ws contai ns
the one speci fi ed by Wp
(Ws(1) < Wp(1) < Wp(2) < Ws(2)).
(0,Ws(1))
and
(Ws(2),1)
(Wp(1),Wp(2))
Bandstop The i nterval speci fi ed by Wp contai ns
the one speci fi ed by Ws
(Wp(1) < Ws(1) < Ws(2) < Wp(2)).
(0,Wp(1))
and
(Wp(2),1)
(Ws(1),Ws(2))
buttord
7-72
Examples Ex a mple 1
For data sampl ed at 1000 Hz, desi gn a l owpass fi l ter wi th l ess than 3 dB of
ri ppl e i n the passband, defi ned from 0 to 40 Hz, and at l east 60 dB of
attenuati on i n the stopband, defi ned from 150 Hz to the Nyqui st frequency
(500 Hz). Pl ot the fi l ters frequency response.
Wp = 40/500; Ws = 150/500;
[n,Wn] = buttord(Wp,Ws,3,60)
n =
5
Wn =
0.0810
[b,a] = butter(n,Wn);
freqz(b,a,512,1000); title('n=5 Butterworth Lowpass Filter')
0 50 100 150 200 250 300 350 400 450 500
500
400
300
200
100
0
Frequency (Hz)
P
h
a
s
e

(
d
e
g
r
e
e
s
)
0 50 100 150 200 250 300 350 400 450 500
400
300
200
100
0
100
Frequency (Hz)
M
a
g
n
i
t
u
d
e

(
d
B
)
n=5 Butterworth Lowpass Filter
buttord
7-73
Ex a mple 2
Next desi gn a bandpass fi l ter wi th passband of 60 Hz to 200 Hz, wi th l ess than
3 dB of ri ppl e i n the passband, and 40 dB attenuati on i n the stopbands that are
50 Hz wi de on both si des of the passband.
Wp = [60 200]/500; Ws = [50 250]/500;
Rp = 3; Rs = 40;
[n,Wn] = buttord(Wp,Ws,Rp,Rs)
n =
16
Wn =
0.1198 0.4005
[b,a] = butter(n,Wn);
freqz(b,a,128,1000)
title('n=16 Butterworth Bandpass Filter')
0 50 100 150 200 250 300 350 400 450 500
2500
2000
1500
1000
500
0
500
Frequency (Hz)
P
h
a
s
e

(
d
e
g
r
e
e
s
)
0 50 100 150 200 250 300 350 400 450 500
500
400
300
200
100
0
100
Frequency (Hz)
M
a
g
n
i
t
u
d
e

(
d
B
)
n=16 Butterworth Bandpass Filter
buttord
7-74
Algorithm buttords order predi cti on formul a i s descri bed i n [1]. I t operates i n the anal og
domai n for both anal og and di gi tal cases. For the di gi tal case, i t converts the
frequency parameters to the s-domai n before esti mati ng the order and natural
frequency, and then converts back to the z-domai n.
buttord i ni ti al l y devel ops a l owpass fi l ter prototype by transformi ng the
passband frequenci es of the desi red fi l ter to 1 rad/s (for l owpass and hi ghpass
fi l ters) and to -1 and 1 rad/s (for bandpass and bandstop fi l ters). I t then
computes the mi ni mum order requi red for a l owpass fi l ter to meet the stopband
speci fi cati on.
See Also butter, cheb1ord, cheb2ord, ellipord, kaiserord
References [1] Rabi ner, L.R., and B. Gol d. Theory and Application of Digital Signal
Processing. Engl ewood Cl i ffs, NJ: Prenti ce-Hal l , 1975. Pg. 227.
cceps
7-75
7cceps
Purpose Compl ex cepstral anal ysi s
Syntax xhat = cceps(x)
[xhat,nd] = cceps(x)
[xhat,nd,xhat1] = cceps(x)
[...] = cceps(x,n)
Description Cepstral anal ysi s i s a nonl i near si gnal processi ng techni que that i s appl i ed
most commonl y i n speech processi ng and homomorphi c fi l teri ng [1].
xhat = cceps(x) returns the compl ex cepstrum of the (assumed real )
sequence x. The i nput i s al tered, by the appl i cati on of a l i near phase term, to
have no phase di sconti nui ty at t radi ans. That i s, i t i s ci rcul arl y shi fted (after
zero paddi ng) by some sampl es, i f necessary, to have zero phase at radi ans.
[xhat,nd] = cceps(x) returns the number of sampl es nd of (ci rcul ar) del ay
added to x pri or to fi ndi ng the compl ex cepstrum.
[xhat,nd,xhat1] = cceps(x) returns a second compl ex cepstrum, computed
usi ng an al ternate rooti ng al gori thm, i n xhat1. The al ternate method
([1] p.795) i s useful for short sequences that can be rooted and do not have zeros
on the uni t ci rcl e. For these si gnal s, xhat1 can provi de a veri fi cati on of xhat.
[...] = cceps(x,n) zero pads x to l ength n and returns the l ength n compl ex
cepstrum of x.
Algorithm cceps, i n i ts basi c form, i s an M-fi l e i mpl ementati on of al gori thm 7.1 i n [2]. A
l engthy Fortran program reduces to three l i nes of MATLAB code:
h = fft(x);
logh = log(abs(h)) + sqrt(-1)*rcunwrap(angle(h));
y = real(ifft(logh));
rcunwrap i s a speci al versi on of unwrap that subtracts a strai ght l i ne from the
phase.
See Also icceps, hilbert, rceps, unwrap
References [1] Oppenhei m, A.V., and R.W. Schafer. Discrete-Time Signal Processing.
Upper Saddl e Ri ver, NJ: Prenti ce-Hal l , 1999, pp. 788-789.
cceps
7-76
[2] I EEE. Programs for Digital Signal Processing. I EEE Press. New York: John
Wi l ey & Sons, 1979.
cell2sos
7-77
7cel l 2sos
Purpose Convert a cel l array for second-order secti ons to a second-order secti on matri x
Syntax m = cell2sos(c)
Description m = cell2sos(c) changes a 1-by-L cel l array c consi sti ng of 1-by-2 cel l arrays
i nto an L-by-6 second-order secti on matri x m. Matri x m takes the same form as
the matri x generated by tf2sos. You can use m = cell2sos(c) to i nvert the
resul ts of c = sos2cell(m).
c must be a cel l array of the form
c = { {b1 a1} {b2 a2} ... {bL aL} }
where both bi and ai are row vectors of at most l ength 3, and i = 1, 2, ..., L. The
resul ti ng matri x m i s gi ven by
m = [b1 a1;b2 a2; ... ;bL aL]
See Also sos2cell, tf2sos
cheb1ap
7-78
7cheb1ap
Purpose Chebyshev Type I anal og l owpass fi l ter prototype
Syntax [z,p,k] = cheb1ap(n,Rp)
Description [z,p,k] = cheb1ap(n,Rp) returns the pol es and gai n of an order n Chebyshev
Type I anal og l owpass fi l ter prototype wi th Rp dB of ri ppl e i n the passband. The
functi on returns the pol es i n the l ength n col umn vector p and the gai n i n
scal ar k. z i s an empty matri x, because there are no zeros. The transfer
functi on i s
Chebyshev Type I fi l ters are equi ri ppl e i n the passband and monotoni c i n the
stopband. The pol es are evenl y spaced about an el l i pse i n the l eft hal f pl ane.
The Chebyshev Type I cutoff frequency i s set to 1.0 for a normal i zed resul t.
Thi s i s the frequency at whi ch the passband ends and the fi l ter has magni tude
response of 10
-Rp/20
.
See Also besselap, buttap, cheby1, cheb2ap, ellipap
References [1] Parks, T.W., and C.S. Burrus. Digital Filter Design. New York: John Wi l ey
& Sons, 1987. Chapter 7.
H s ( )
z s ( )
p s ( )
----------
k
s p 1 ( ) ( ) s p 2 ( ) ( )L s p n ( ) ( )
-------------------------------------------------------------------------------- = =

0
cheb1ord
7-79
7cheb1ord
Purpose Cal cul ate the order for a Chebyshev Type I fi l ter
Syntax [n,Wn] = cheb1ord(Wp,Ws,Rp,Rs)
[n,Wn] = cheb1ord(Wp,Ws,Rp,Rs,'s')
Description cheb1ord cal cul ates the mi ni mum order of a di gi tal or anal og Chebyshev
Type I fi l ter requi red to meet a set of fi l ter desi gn speci fi cati ons.
Digita l Doma in
[n,Wn] = cheb1ord(Wp,Ws,Rp,Rs) returns the l owest order n of the Chebyshev
Type I fi l ter that l oses no more than Rp dB i n the passband and has at l east
Rs dB of attenuati on i n the stopband. The scal ar (or vector) of correspondi ng
cutoff frequenci es Wn, i s al so returned. Use the output arguments n and Wn wi th
the cheby1 functi on.
Choose the i nput arguments to speci fy the stopband and passband accordi ng to
the fol l owi ng tabl e.
Table 7-3: Description of Stopband and Passband Filter Parameters
Wp Passband corner frequency Wp, the cutoff frequency, i s a scal ar
or a two-el ement vector wi th val ues between 0 and 1, wi th 1
correspondi ng to the normal i zed Nyqui st frequency, radi ans
per sampl e.
Ws Stopband corner frequency Ws, i s a scal ar or a two-el ement
vector wi th val ues between 0 and 1, wi th 1 correspondi ng to
the normal i zed Nyqui st frequency.
Rp Passband ri ppl e, i n deci bel s. Thi s val ue i s the maxi mum
permi ssi bl e passband l oss i n deci bel s.
Rs Stopband attenuati on, i n deci bel s. Thi s val ue i s the number of
deci bel s the stopband i s down from the passband.
cheb1ord
7-80
Use the fol l owi ng gui de to speci fy fi l ters of di fferent types
I f your fi l ter speci fi cati ons cal l for a bandpass or bandstop fi l ter wi th unequal
ri ppl e i n each of the passbands or stopbands, desi gn separate l owpass and
hi ghpass fi l ters accordi ng to the speci fi cati ons i n thi s tabl e, and cascade the
two fi l ters together.
Ana log Doma in
[n,Wn] = cheb1ord(Wp,Ws,Rp,Rs,'s') fi nds the mi ni mum order n and cutoff
frequenci es Wn for an anal og Chebyshev Type I fi l ter. You speci fy the
frequenci es Wp and Ws si mi l ar to Tabl e 7-3, onl y i n thi s case you speci fy the
frequency i n radi ans per second, and the passband or the stopband can be
i nfi ni te.
Use cheb1ord for l owpass, hi ghpass, bandpass, and bandstop fi l ters as
descri bed i n Tabl e 7-4.
Examples For data sampl ed at 1000 Hz, desi gn a l owpass fi l ter wi th l ess than 3 dB of
ri ppl e i n the passband defi ned from 0 to 40 Hz and at l east 60 dB of ri ppl e i n
the stopband defi ned from 150 Hz to the Nyqui st frequency (500 Hz).
Wp = 40/500; Ws = 150/500;
Rp = 3; Rs = 60;
[n,Wn] = cheb1ord(Wp,Ws,Rp,Rs)
Table 7-4: Filter Type Stopband and Passband Specifications
Filter Type Stopband and Passband Conditions Stopband Passband
Lowpass Wp < Ws, both scal ars (Ws,1) (0,Wp)
Hi ghpass Wp > Ws, both scal ars (0,Ws) (Wp,1)
Bandpass The i nterval speci fi ed by Ws contai ns
the one speci fi ed by Wp
(Ws(1) < Wp(1) < Wp(2) < Ws(2)).
(0,Ws(1))
and
(Ws(2),1)
(Wp(1),Wp(2))
Bandstop The i nterval speci fi ed by Wp contai ns
the one speci fi ed by Ws
(Wp(1) < Ws(1) < Ws(2) < Wp(2)).
(0,Wp(1))
and
(Wp(2),1)
(Ws(1),Ws(2))
cheb1ord
7-81
n =
4
Wn =
0.0800
[b,a] = cheby1(n,Rp,Wn);
freqz(b,a,512,1000);
title('n=4 Chebyshev Type I Lowpass Filter')
Next desi gn a bandpass fi l ter wi th a passband of 60 Hz to 200 Hz, wi th l ess
than 3 dB of ri ppl e i n the passband, and 40 dB attenuati on i n the stopbands
that are 50 Hz wi de on both si des of the passband.
Wp = [60 200]/500; Ws = [50 250]/500;
Rp = 3; Rs = 40;
[n,Wn] = cheb1ord(Wp,Ws,Rp,Rs)
n =
7
Wn =
0.1200 0.4000
[b,a] = cheby1(n,Rp,Wn);
freqz(b,a,512,1000);
title('n=7 Chebyshev Type I Bandpass Filter')
0 50 100 150 200 250 300 350 400 450 500
400
300
200
100
0
Frequency (Hz)
P
h
a
s
e

(
d
e
g
r
e
e
s
)
0 50 100 150 200 250 300 350 400 450 500
300
250
200
150
100
50
0
Frequency (Hz)
M
a
g
n
i
t
u
d
e

(
d
B
)
n=4 Chebyshev Type I Lowpass Filter
cheb1ord
7-82
Algorithm cheb1ord uses the Chebyshev l owpass fi l ter order predi cti on formul a descri bed
i n [1]. The functi on performs i ts cal cul ati ons i n the anal og domai n for both
anal og and di gi tal cases. For the di gi tal case, i t converts the frequency
parameters to the s-domai n before the order and natural frequency esti mati on
process, and then converts them back to the z-domai n.
cheb1ord i ni ti al l y devel ops a l owpass fi l ter prototype by transformi ng the
passband frequenci es of the desi red fi l ter to 1 rad/s (for l ow- or hi ghpass fi l ters)
or to -1 and 1 rad/s (for bandpass or bandstop fi l ters). I t then computes the
mi ni mum order requi red for a l owpass fi l ter to meet the stopband speci fi cati on.
See Also buttord, cheby1, cheb2ord, ellipord, kaiserord
References [1] Rabi ner, L.R., and B. Gol d. Theory and Application of Digital Signal
Processing. Engl ewood Cl i ffs, NJ: Prenti ce-Hal l , 1975. Pg. 241.
0 50 100 150 200 250 300 350 400 450 500
1500
1000
500
0
500
Frequency (Hz)
P
h
a
s
e

(
d
e
g
r
e
e
s
)
0 50 100 150 200 250 300 350 400 450 500
500
400
300
200
100
0
Frequency (Hz)
M
a
g
n
i
t
u
d
e

(
d
B
)
n=7 Chebyshev Type I Bandpass Filter
cheb2ap
7-83
7cheb2ap
Purpose Chebyshev Type I I anal og l owpass fi l ter prototype
Syntax [z,p,k] = cheb2ap(n,Rs)
Description [z,p,k] = cheb2ap(n,Rs) fi nds the zeros, pol es, and gai n of an order n
Chebyshev Type I I anal og l owpass fi l ter prototype wi th stopband ri ppl e Rs dB
down from the passband peak val ue. cheb2ap returns the zeros and pol es i n
l ength n col umn vectors z and p and the gai n i n scal ar k. I f n i s odd, z i s l ength
n-1. The transfer functi on i s
Chebyshev Type I I fi l ters are monotoni c i n the passband and equi ri ppl e i n the
stopband. The pol e l ocati ons are the i nverse of the pol e l ocati ons of cheb1ap,
whose pol es are evenl y spaced about an el l i pse i n the l eft hal f pl ane. The
Chebyshev Type I I cutoff frequency
0
i s set to 1 for a normal i zed resul t. Thi s
i s the frequency at whi ch the stopband begi ns and the fi l ter has magni tude
response of 10
-Rs/20
.
Algorithm Chebyshev Type I I fi l ters are someti mes cal l ed inverse Chebyshev fi l ters
because of thei r rel ati onshi p to Chebyshev Type I fi l ters. The cheb2ap functi on
i s a modi fi cati on of the Chebyshev Type I prototype al gori thm:
1 cheb2ap repl aces the frequency vari abl e wi th 1/, turni ng the l owpass
fi l ter i nto a hi ghpass fi l ter whi l e preservi ng the performance at = 1.
2 cheb2ap subtracts the fi l ter transfer functi on from uni ty.
See Also besselap, buttap, cheb1ap, cheby2, ellipap
References [1] Parks, T.W., and C.S. Burrus. Digital Filter Design. New York: John Wi l ey
& Sons, 1987. Chapter 7.
H s ( )
z s ( )
p s ( )
---------- k
s z 1 ( ) ( ) s z 2 ( ) ( )L s z n ( ) ( )
s p 1 ( ) ( ) s p 2 ( ) ( )L s p n ( ) ( )
-------------------------------------------------------------------------------- = =
cheb2ord
7-84
7cheb2ord
Purpose Cal cul ate the order for a Chebyshev Type I I fi l ter
Syntax [n,Wn] = cheb2ord(Wp,Ws,Rp,Rs)
[n,Wn] = cheb2ord(Wp,Ws,Rp,Rs,'s')
Description cheb2ord cal cul ates the mi ni mum order of a di gi tal or anal og Chebyshev
Type I I fi l ter requi red to meet a set of fi l ter desi gn speci fi cati ons.
Digita l Doma in
[n,Wn] = cheb2ord(Wp,Ws,Rp,Rs) returns the l owest order n of the Chebyshev
Type I I fi l ter that l oses no more than Rp dB i n the passband and has at l east
Rs dB of attenuati on i n the stopband. The scal ar (or vector) of correspondi ng
cutoff frequenci es Wn, i s al so returned. Use the output arguments n and Wn i n
cheby2.
Choose the i nput arguments to speci fy the stopband and passband accordi ng to
the fol l owi ng tabl e.
Table 7-5: Description of Stopband and Passband Filter Parameters
Wp Passband corner frequency Wp, the cutoff frequency, i s a scal ar
or a two-el ement vector wi th val ues between 0 and 1, wi th 1
correspondi ng to the normal i zed Nyqui st frequency, radi ans
per sampl e.
Ws Stopband corner frequency Ws, i s a scal ar or a two-el ement
vector wi th val ues between 0 and 1, wi th 1 correspondi ng to
the normal i zed Nyqui st frequency.
Rp Passband ri ppl e, i n deci bel s. Thi s val ue i s the maxi mum
permi ssi bl e passband l oss i n deci bel s.
Rs Stopband attenuati on, i n deci bel s. Thi s val ue i s the number of
deci bel s the stopband i s down from the passband.
cheb2ord
7-85
Use the fol l owi ng gui de to speci fy fi l ters of di fferent types.
I f your fi l ter speci fi cati ons cal l for a bandpass or bandstop fi l ter wi th unequal
ri ppl e i n each of the passbands or stopbands, desi gn separate l owpass and
hi ghpass fi l ters accordi ng to the speci fi cati ons i n thi s tabl e, and cascade the
two fi l ters together.
Ana log Doma in
[n,Wn] = cheb2ord(Wp,Ws,Rp,Rs,'s') fi nds the mi ni mum order n and cutoff
frequenci es Wn for an anal og Chebyshev Type I I fi l ter. You speci fy the
frequenci es Wp and Ws si mi l ar to Tabl e 7-5, onl y i n thi s case you speci fy the
frequency i n radi ans per second, and the passband or the stopband can be
i nfi ni te.
Use cheb2ord for l owpass, hi ghpass, bandpass, and bandstop fi l ters as
descri bed i n Tabl e 7-6.
Table 7-6: Filter Type Stopband and Passband Specifications
Filter Type Stopband and Passband Conditions Stopband Passband
Lowpass Wp < Ws, both scal ars (Ws,1) (0,Wp)
Hi ghpass Wp > Ws, both scal ars (0,Ws) (Wp,1)
Bandpass The i nterval speci fi ed by Ws contai ns
the one speci fi ed by Wp
(Ws(1) < Wp(1) < Wp(2) < Ws(2)).
(0,Ws(1))
and
(Ws(2),1)
(Wp(1),Wp(2))
Bandstop The i nterval speci fi ed by Wp contai ns
the one speci fi ed by Ws
(Wp(1) < Ws(1) < Ws(2) < Wp(2)).
(0,Wp(1))
and
(Wp(2),1)
(Ws(1),Ws(2))
cheb2ord
7-86
Examples Ex a mple 1
For data sampl ed at 1000 Hz, desi gn a l owpass fi l ter wi th l ess than 3 dB of
ri ppl e i n the passband defi ned from 0 to 40 Hz, and at l east 60 dB of
attenuati on i n the stopband defi ned from 150 Hz to the Nyqui st frequency
(500 Hz).
Wp = 40/500; Ws = 150/500;
Rp = 3; Rs = 60;
[n,Wn] = cheb2ord(Wp,Ws,Rp,Rs)
n =
4
Wn =
0.2597
[b,a] = cheby2(n,Rs,Wn);
freqz(b,a,512,1000);
title('n=4 Chebyshev Type II Lowpass Filter')
0 50 100 150 200 250 300 350 400 450 500
400
300
200
100
0
100
Frequency (Hz)
P
h
a
s
e

(
d
e
g
r
e
e
s
)
0 50 100 150 200 250 300 350 400 450 500
120
100
80
60
40
20
0
Frequency (Hz)
M
a
g
n
i
t
u
d
e

(
d
B
)
n=4 Chebyshev Type II Lowpass Filter
cheb2ord
7-87
Ex a mple 2
Next desi gn a bandpass fi l ter wi th a passband of 60 Hz to 200 Hz, wi th l ess
than 3 dB of ri ppl e i n the passband, and 40 dB attenuati on i n the stopbands
that are 50 Hz wi de on both si des of the passband.
Wp = [60 200]/500; Ws = [50 250]/500;
Rp = 3; Rs = 40;
[n,Wn] = cheb2ord(Wp,Ws,Rp,Rs)
n =
7
Wn =
0.1019 0.4516
[b,a] = cheby2(n,Rs,Wn);
freqz(b,a,512,1000)
title('n=7 Chebyshev Type II Bandpass Filter')
0 50 100 150 200 250 300 350 400 450 500
400
200
0
200
400
Frequency (Hz)
P
h
a
s
e

(
d
e
g
r
e
e
s
)
0 50 100 150 200 250 300 350 400 450 500
300
250
200
150
100
50
0
50
Frequency (Hz)
M
a
g
n
i
t
u
d
e

(
d
B
)
n=7 Chebyshev Type II Bandpass Filter
cheb2ord
7-88
Algorithm cheb2ord uses the Chebyshev l owpass fi l ter order predi cti on formul a descri bed
i n [1]. The functi on performs i ts cal cul ati ons i n the anal og domai n for both
anal og and di gi tal cases. For the di gi tal case, i t converts the frequency
parameters to the s-domai n before the order and natural frequency esti mati on
process, and then converts them back to the z-domai n.
cheb2ord i ni ti al l y devel ops a l owpass fi l ter prototype by transformi ng the
stopband frequenci es of the desi red fi l ter to 1 rad/s (for l ow- and hi ghpass
fi l ters) and to -1 and 1 rad/s (for bandpass and bandstop fi l ters). I t then
computes the mi ni mum order requi red for a l owpass fi l ter to meet the
passband speci fi cati on.
See Also buttord, cheb1ord, cheby2, ellipord, kaiserord
References [1] Rabi ner, L.R., and B. Gol d. Theory and Application of Digital Signal
Processing. Engl ewood Cl i ffs, NJ: Prenti ce-Hal l , 1975. Pg. 241.
chebwin
7-89
7chebwi n
Purpose Compute a Chebyshev wi ndow
Syntax w = chebwin(n,r)
Description w = chebwin(n,r) returns the col umn vector w contai ni ng the l ength n
Chebyshev wi ndow whose Fouri er transform si del obe magni tude i s r dB bel ow
the mai nl obe magni tude.
Note I f you speci fy a one-poi nt wi ndow (set n=1), the val ue 1 i s returned.
Examples N=64;
w = chebwin(N,100);
plot(w); axis([1 N 0 1]);
title('Chebyshev Window')
See Also barthannwin, bartlett, blackman, blackmanharris, bohmanwin, gausswin,
hamming, hann, kaiser, nuttallwin, rectwin, triang, tukeywin, window
References [1] I EEE. Programs for Digital Signal Processing. I EEE Press. New York: John
Wi l ey & Sons, 1979. Program 5.2.
10 20 30 40 50 60
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
Chebyshev Window
cheby1
7-90
7cheby1
Purpose Chebyshev Type I fi l ter desi gn (passband ri ppl e)
Syntax [b,a] = cheby1(n,Rp,Wn)
[b,a] = cheby1(n,Rp,Wn,'ftype')
[b,a] = cheby1(n,Rp,Wn,'s')
[b,a] = cheby1(n,Rp,Wn,'ftype','s')
[z,p,k] = cheby1(...)
[A,B,C,D] = cheby1(...)
Description cheby1 desi gns l owpass, bandpass, hi ghpass, and bandstop di gi tal and anal og
Chebyshev Type I fi l ters. Chebyshev Type I fi l ters are equi ri ppl e i n the
passband and monotoni c i n the stopband. Type I fi l ters rol l off faster than
type I I fi l ters, but at the expense of greater devi ati on from uni ty i n the
passband.
Digita l Doma in
[b,a] = cheby1(n,Rp,Wn) desi gns an order n Chebyshev l owpass di gi tal
Chebyshev fi l ter wi th cutoff frequency Wn and Rp dB of peak-to-peak ri ppl e i n
the passband. I t returns the fi l ter coeffi ci ents i n the l ength n+1 row vectors b
and a, wi th coeffi ci ents i n descendi ng powers of z.
Cutoff frequency i s the frequency at whi ch the magni tude response of the fi l ter
i s equal to -Rp dB. For cheby1, the cutoff frequency Wn i s a number between 0
and 1, where 1 corresponds to the Nyqui st frequency, radi ans per sampl e.
Smal l er val ues of passband ri ppl e Rp l ead to wi der transi ti on wi dths (shal l ower
rol l off characteri sti cs).
I f Wn i s a two-el ement vector, Wn = [w1 w2], cheby1 returns an order 2*n
bandpass fi l ter wi th passband w1 < < w2.
H z ( )
B z ( )
A z ( )
-----------
b 1 ( ) b 2 ( )z
1
L b n 1 + ( )z
n
+ + +
1 a 2 ( )z
1
L a n 1 + ( )z
n
+ + +
------------------------------------------------------------------------------------ = =

cheby1
7-91
[b,a] = cheby1(n,Rp,Wn,'ftype') desi gns a hi ghpass or bandstop fi l ter,
where the stri ng 'ftype i s ei ther:
'high' for a hi ghpass di gi tal fi l ter wi th cutoff frequency Wn
'stop' for an order 2*n bandstop di gi tal fi l ter i f Wn i s a two-el ement vector,
Wn = [w1 w2]
The stopband i s w1 < < w2.
Wi th di fferent numbers of output arguments, cheby1 di rectl y obtai ns other
real i zati ons of the fi l ter. To obtai n zero-pol e-gai n form, use three output
arguments as shown bel ow.
[z,p,k] = cheby1(n,Rp,Wn) or
[z,p,k] = cheby1(n,Rp,Wn,'ftype') returns the zeros and pol es i n l ength n
col umn vectors z and p and the gai n i n the scal ar k.
To obtai n state-space form, use four output arguments as shown bel ow.
[A,B,C,D] = cheby1(n,Rp,Wn) or
[A,B,C,D] = cheby1(n,Rp,Wn,'ftype') where A, B, C, and D are
and u i s the i nput, x i s the state vector, and y i s the output.
Ana log Doma in
[b,a] = cheby1(n,Rp,Wn,'s') desi gns an order n l owpass anal og Chebyshev
Type I fi l ter wi th cutoff frequency Wn rad/s. I t returns the fi l ter coeffi ci ents
i n l ength n+1 row vectors b and a, i n descendi ng powers of s, deri ved from the
transfer functi on
Cutoff frequency i s the frequency at whi ch the magni tude response of the fi l ter
i s -Rp dB. For cheby1, the cutoff frequency Wn must be greater than 0 rad/s.
x n 1 + [ ] Ax n [ ] Bu n [ ] + =
y n [ ] Cx n [ ] Du n [ ] + =
H s ( )
B s ( )
A s ( )
---------- -
b 1 ( )s
n
b 2 ( )s
n 1
L b n 1 + ( ) + + +
s
n
a 2 ( )s
n 1
L a n 1 + ( ) + + +
------------------------------------------------------------------------------------- = =
cheby1
7-92
I f Wn i s a two-el ement vector Wn = [w1 w2] wi th w1 < w2, then
cheby1(n,Rp,Wn,'s') returns an order 2*n bandpass anal og fi l ter wi th
passband w1 < < w2.
[b,a] = cheby1(n,Rp,Wn,'ftype','s') desi gns a hi ghpass or bandstop fi l ter.
You can suppl y di fferent numbers of output arguments for cheby1 to di rectl y
obtai n other real i zati ons of the anal og fi l ter. To obtai n zero-pol e-gai n form, use
three output arguments as shown bel ow.
[z,p,k] = cheby1(n,Rp,Wn,'s') or
[z,p,k] = cheby1(n,Rp,Wn,'ftype','s') returns the zeros and pol es i n
l ength n or 2*n col umn vectors z and p and the gai n i n the scal ar k.
To obtai n state-space form, use four output arguments as shown bel ow.
[A,B,C,D] = cheby1(n,Rp,Wn,'s') or
[A,B,C,D] = cheby1(n,Rp,Wn,'ftype','s') where A, B, C, and D are defi ned
as
and u i s the i nput, x i s the state vector, and y i s the output.
Examples Ex a mple 1 : Low pa ss Filter
For data sampl ed at 1000 Hz, desi gn a 9th-order l owpass Chebyshev Type I
fi l ter wi th 0.5 dB of ri ppl e i n the passband and a cutoff frequency of 300 Hz.
[b,a] = cheby1(9,0.5,300/500);
The frequency response of the fi l ter i s
freqz(b,a,512,1000)
x

Ax Bu + =
y Cx Du + =
cheby1
7-93
Ex a mple 2 : Ba ndpa ss Filter
Desi gn a 10th-order bandpass Chebyshev Type I fi l ter wi th a passband from
100 to 200 Hz and pl ot i ts i mpul se response.
n = 10; Rp = 0.5;
Wn = [100 200]/500;
[b,a] = cheby1(n,Rp,Wn);
[y,t] = impz(b,a,101); stem(t,y)
0 50 100 150 200 250 300 350 400 450 500
-1000
-800
-600
-400
-200
0
Frequency (Hertz)
P
h
a
s
e

(
d
e
g
r
e
e
s
)
0 50 100 150 200 250 300 350 400 450 500
-300
-200
-100
0
100
Frequency (Hertz)
M
a
g
n
i
t
u
d
e

R
e
s
p
o
n
s
e

(
d
B
)
n = 9 Chebyshev Type I Lowpass Filter
cheby1
7-94
Limitations For hi gh order fi l ters, the state-space form i s the most numeri cal l y accurate,
fol l owed by the zero-pol e-gai n form. The transfer functi on form i s the l east
accurate; numeri cal probl ems can ari se for fi l ter orders as l ow as 15.
Algorithm cheby1 uses a fi ve-step al gori thm:
1 I t fi nds the l owpass anal og prototype pol es, zeros, and gai n usi ng the
cheb1ap functi on.
2 I t converts the pol es, zeros, and gai n i nto state-space form.
3 I t transforms the l owpass fi l ter i nto a bandpass, hi ghpass, or bandstop fi l ter
wi th desi red cutoff frequenci es, usi ng a state-space transformati on.
4 For di gi tal fi l ter desi gn, cheby1 uses bilinear to convert the anal og fi l ter
i nto a di gi tal fi l ter through a bi l i near transformati on wi th frequency
prewarpi ng. Careful frequency adjustment guarantees that the anal og
fi l ters and the di gi tal fi l ters wi l l have the same frequency response
magni tude at Wn or w1 and w2.
5 I t converts the state-space fi l ter back to transfer functi on or zero-pol e-gai n
form, as requi red.
See Also besself, butter, cheb1ap, cheb1ord, cheby2, ellip
0 10 20 30 40 50 60 70 80 90 100
-0.2
-0.15
-0.1
-0.05
0
0.05
0.1
0.15
Impulse Response of n = 10 Chebyshev Type I Filter
cheby2
7-95
7cheby2
Purpose Chebyshev Type I I fi l ter desi gn (stopband ri ppl e)
Syntax [b,a] = cheby2(n,Rs,Wn)
[b,a] = cheby2(n,Rs,Wn,'ftype')
[b,a] = cheby2(n,Rs,Wn,'s')
[b,a] = cheby2(n,Rs,Wn,'ftype','s')
[z,p,k] = cheby2(...)
[A,B,C,D] = cheby2(...)
Description cheby2 desi gns l owpass, hi ghpass, bandpass, and bandstop di gi tal and anal og
Chebyshev Type I I fi l ters. Chebyshev Type I I fi l ters are monotoni c i n the
passband and equi ri ppl e i n the stopband. Type I I fi l ters do not rol l off as fast
as type I fi l ters, but are free of passband ri ppl e.
Digita l Doma in
[b,a] = cheby2(n,Rs,Wn) desi gns an order n l owpass di gi tal Chebyshev Type
I I fi l ter wi th cutoff frequency Wn and stopband ri ppl e Rs dB down from the peak
passband val ue. I t returns the fi l ter coeffi ci ents i n the l ength n+1 row vectors
b and a, wi th coeffi ci ents i n descendi ng powers of z.
Cutoff frequency i s the begi nni ng of the stopband, where the magni tude
response of the fi l ter i s equal to -Rs dB. For cheby2, the normal i zed cutoff
frequency Wn i s a number between 0 and 1, where 1 corresponds to the Nyqui st
frequency. Larger val ues of stopband attenuati on Rs l ead to wi der transi ti on
wi dths (shal l ower rol l off characteri sti cs).
I f Wn i s a two-el ement vector, Wn = [w1 w2], cheby2 returns an order 2*n
bandpass fi l ter wi th passband w1 < < w2.
[b,a] = cheby2(n,Rs,Wn,'ftype') desi gns a hi ghpass or bandstop fi l ter,
where the stri ng 'ftype' i s ei ther:
'high' for a hi ghpass di gi tal fi l ter wi th cutoff frequency Wn
'stop' for an order 2*n bandstop di gi tal fi l ter i f Wn i s a two-el ement vector,
Wn = [w1 w2]. The stopband i s w1 < < w2.
H z ( )
B z ( )
A z ( )
-----------
b 1 ( ) b 2 ( )z
1
L b n 1 + ( )z
n
+ + +
1 a 2 ( )z
1
L a n 1 + ( )z
n
+ + +
------------------------------------------------------------------------------------ = =
cheby2
7-96
Wi th di fferent numbers of output arguments, cheby2 di rectl y obtai ns other
real i zati ons of the fi l ter. To obtai n zero-pol e-gai n form, use three output
arguments as shown bel ow.
[z,p,k] = cheby2(n,Rs,Wn) or
[z,p,k] = cheby2(n,Rs,Wn,'ftype') returns the zeros and pol es i n l ength n
col umn vectors z and p and the gai n i n the scal ar k.
To obtai n state-space form, use four output arguments as shown bel ow.
[A,B,C,D] = cheby2(n,Rs,Wn) or
[A,B,C,D] = cheby2(n,Rs,Wn,'ftype') where A, B, C, and D are
and u i s the i nput, x i s the state vector, and y i s the output.
Ana log Doma in
[b,a] = cheby2(n,Rs,Wn,'s') desi gns an order n l owpass anal og Chebyshev
Type I I fi l ter wi th cutoff frequency Wn. I t returns the fi l ter coeffi ci ents i n the
l ength n+1 row vectors b and a, wi th coeffi ci ents i n descendi ng powers of s,
deri ved from the transfer functi on.
Cutoff frequency i s the frequency at whi ch the magni tude response of the fi l ter
i s equal to -Rs dB. For cheby2, the cutoff frequency Wn must be greater than 0
rad/s.
I f Wn i s a two-el ement vector Wn = [w1 w2] wi th w1 < w2, then
cheby2(n,Rs,Wn,'s') returns an order 2*n bandpass anal og fi l ter wi th
passband w1 < < w2.
[b,a] = cheby2(n,Rs,Wn,'ftype','s') desi gns a hi ghpass or bandstop fi l ter.
x n 1 + [ ] Ax n [ ] Bu n [ ] + =
y n [ ] Cx n [ ] Du n [ ] + =
H s ( )
B s ( )
A s ( )
---------- -
b 1 ( )s
n
b 2 ( )s
n 1
L b n 1 + ( ) + + +
s
n
a 2 ( )s
n 1
L a n 1 + ( ) + + +
------------------------------------------------------------------------------------- = =
cheby2
7-97
Wi th di fferent numbers of output arguments, cheby2 di rectl y obtai ns other
real i zati ons of the anal og fi l ter. To obtai n zero-pol e-gai n form, use three output
arguments as shown bel ow.
[z,p,k] = cheby2(n,Rs,Wn,'s') or
[z,p,k] = cheby2(n,Rs,Wn,'ftype','s') returns the zeros and pol es i n
l ength n or 2*n col umn vectors z and p and the gai n i n the scal ar k.
To obtai n state-space form, use four output arguments as shown bel ow.
[A,B,C,D] = cheby2(n,Rs,Wn,'s') or
[A,B,C,D] = cheby2(n,Rs,Wn,'ftype','s') where A, B, C, and D are
and u i s the i nput, x i s the state vector, and y i s the output.
Examples Ex a mple 1 : Low pa ss Filter
For data sampl ed at 1000 Hz, desi gn a ni nth-order l owpass Chebyshev Type I I
fi l ter wi th stopband attenuati on 20 dB down from the passband and a cutoff
frequency of 300 Hz.
[b,a] = cheby2(9,20,300/500);
The frequency response of the fi l ter i s
freqz(b,a,512,1000)
x

Ax Bu + =
y Cx Du + =
cheby2
7-98
Ex a mple 2 : Ba ndpa ss Filter
Desi gn a fi fth-order bandpass Chebyshev Type I I fi l ter wi th passband from 100
to 200 Hz and pl ot the i mpul se response of the fi l ter.
n = 5; r = 20;
Wn = [100 200]/500;
[b,a] = cheby2(n,r,Wn);
[y,t] = impz(b,a,101); stem(t,y)
0 50 100 150 200 250 300 350 400 450 500
-400
-300
-200
-100
0
100
Frequency (Hertz)
P
h
a
s
e

(
d
e
g
r
e
e
s
)
0 50 100 150 200 250 300 350 400 450 500
-80
-60
-40
-20
0
20
Frequency (Hertz)
M
a
g
n
i
t
u
d
e

R
e
s
p
o
n
s
e

(
d
B
)
n = 9 Chebyshev Type II Filter
0 10 20 30 40 50 60 70 80 90 100
-0.2
-0.15
-0.1
-0.05
0
0.05
0.1
0.15
0.2
Impulse Response of n = 5 Chebyshev Type II Filter
cheby2
7-99
Limitations For hi gh order fi l ters, the state-space form i s the most numeri cal l y accurate,
fol l owed by the zero-pol e-gai n form. The transfer functi on coeffi ci ent form i s
the l east accurate; numeri cal probl ems can ari se for fi l ter orders as l ow as 15.
Algorithm cheby2 uses a fi ve-step al gori thm:
1 I t fi nds the l owpass anal og prototype pol es, zeros, and gai n usi ng the
cheb2ap functi on.
2 I t converts pol es, zeros, and gai n i nto state-space form.
3 I t transforms the l owpass fi l ter i nto a bandpass, hi ghpass, or bandstop fi l ter
wi th desi red cutoff frequenci es, usi ng a state-space transformati on.
4 For di gi tal fi l ter desi gn, cheby2 uses bilinear to convert the anal og fi l ter
i nto a di gi tal fi l ter through a bi l i near transformati on wi th frequency
prewarpi ng. Careful frequency adjustment guarantees that the anal og
fi l ters and the di gi tal fi l ters wi l l have the same frequency response
magni tude at Wn or w1 and w2.
5 I t converts the state-space fi l ter back to transfer functi on or zero-pol e-gai n
form, as requi red.
See Also besself, butter, cheb2ap, cheb1ord, cheby1, ellip
chirp
7-100
7chi rp
Purpose Generate a swept-frequency cosi ne
Syntax y = chirp(t,f0,t1,f1)
y = chirp(t,f0,t1,f1,'method')
y = chirp(t,f0,t1,f1,'method',phi)
y = chirp(t,f0,t1,f1,'quadratic',phi,shape)
Description y = chirp(t,f0,t1,f1) generates sampl es of a l i near swept-frequency cosi ne
si gnal at the ti me i nstances defi ned i n array t, where f0 i s the i nstantaneous
frequency at ti me 0, and f1 i s the i nstantaneous frequency at ti me t1. f0 and
f1 are both i n hertz. I f unspeci fi ed, f0 i s 0, t1 i s 1, and f1 i s 100.
y = chirp(t,f0,t1,f1,'method') speci fi es al ternati ve sweep method opti ons,
where method can be:
linear, whi ch speci fi es an i nstantaneous frequency sweep f
i
(t) gi ven by
where
ensures that the desi red frequency breakpoi nt f
1
at ti me t
1
i s mai ntai ned.
quadratic, whi ch speci fi es an i nstantaneous frequency sweep f
i
(t) gi ven by
where
I f f
0
> f
1
(downsweep), the defaul t shape i s convex. I f f
0
< f
1
(upsweep), the
defaul t shape i s concave.
logarithmic speci fi es an i nstantaneous frequency sweep f
i
(t) gi ven by
where
f
i
t ( ) f
0
t + =
f
1
f
0
( ) t
1
=
f
i
t ( ) f
0
t
2
+ =
f
1
f
0
( ) t
1
2
=
f
i
t ( ) f
0
10
t
+ =
chirp
7-101
For a l og-sweep, f1 must be greater than f0.
Each of the above methods can be entered as 'li', 'q', and 'lo', respecti vel y.
y = chirp(t,f0,t1,f1,'method',phi) al l ows an i ni ti al phase phi to be
speci fi ed i n degrees. I f unspeci fi ed, phi i s 0. Defaul t val ues are substi tuted for
empty or omi tted trai l i ng i nput arguments.
y = chirp(t,f0,t1,f1,'quadratic',phi,shape) speci fi es the shape of the
quadrati c swept-frequency si gnal s spectrogram. shape i s ei ther concave or
convex, whi ch descri bes the shape of the parabol a i n the posi ti ve frequency
axi s. I f shape i s omi tted, the defaul t i s convex for downsweep (f
0
> f
1
) and i s
concave for upsweep (f
0
< f
1
).
l og
10
f
1
f
0
( ) [ ] t
1
=
Convex downsweep
shape
Concave upsweep
shape
t
f
f
t
chirp
7-102
Examples Ex a mple 1
Compute the spectrogram of a chi rp wi th l i near i nstantaneous frequency
devi ati on.
t = 0:0.001:2; % 2 secs @ 1kHz sample rate
y = chirp(t,0,1,150); % Start @ DC, cross 150Hz at t=1 sec
specgram(y,256,1e3,256,250) % Display the spectrogram
Time
F
r
e
q
u
e
n
c
y
Linear chirp
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6
0
50
100
150
200
250
300
350
400
450
500
chirp
7-103
Ex a mple 2
Compute the spectrogram of a chi rp wi th quadrati c i nstantaneous frequency
devi ati on.
t = -2:0.001:2; % t2 secs @ 1kHz sample rate
y = chirp(t,100,1,200,'quadratic'); % Start @ 100Hz, cross 200Hz
% at t=1 sec
specgram(y,128,1e3,128,120) % Display the spectrogram
Time
F
r
e
q
u
e
n
c
y
Quadratic chirp
0 0.5 1 1.5 2 2.5 3 3.5
0
50
100
150
200
250
300
350
400
450
500
chirp
7-104
Ex a mple 3
Compute the spectrogram of a convex quadrati c chi rp.
t= -1:0.001:1; % +/-1 second @ 1kHz sample rate
fo=100; f1=400; % Start at 100Hz, go up to 400Hz
y=chirp(t,fo,1,f1,'q',[],'convex');
specgram(y,256,1000) % Display the spectrogram.
Time
F
r
e
q
u
e
n
c
y
Convex chirp
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6
0
50
100
150
200
250
300
350
400
450
500
chirp
7-105
Ex a mple 4
Compute the spectrogram of a concave quadrati c chi rp.
t= 0:0.001:1; % 1 second @ 1kHz sample rate
fo=100; f1=25; % Start at 100Hz, go down to 25Hz
y=chirp(t,fo,1,f1,'q',[],'concave');
specgram(y,256,1000) % Display the spectrogram.
See Also cos, diric, gauspuls, pulstran, rectpuls, sawtooth, sin, sinc, square,
tripuls
Time
F
r
e
q
u
e
n
c
y
Concave chirp
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6
0
50
100
150
200
250
300
350
400
450
500
cohere
7-106
7cohere
Purpose Esti mate magni tude squared coherence functi on between two si gnal s
Syntax Cxy = cohere(x,y)
Cxy = cohere(x,y,nfft)
[Cxy,f] = cohere(x,y,nfft,fs)
Cxy = cohere(x,y,nfft,fs,window)
Cxy = cohere(x,y,nfft,fs,window,numoverlap)
Cxy = cohere(x,y,...,'dflag')
cohere(x,y)
Description Cxy = cohere(x,y) fi nds the magni tude squared coherence between l ength n
si gnal vectors x and y. The coherence i s a functi on of the power spectra of x
and y and the cross spectrum of x and y.
x and y must be the same l ength.
nfft speci fi es the FFT l ength that cohere uses. Thi s val ue determi nes the
frequenci es at whi ch the coherence i s esti mated. fs i s a scal ar that speci fi es the
sampl i ng frequency. window speci fi es a wi ndowi ng functi on and the number of
sampl es cohere uses i n i ts secti oni ng of the x and y vectors. numoverlap i s the
number of sampl es by whi ch the wi ndow secti ons overl ap for both x and y. Any
arguments that you omi t from the end of the parameter l i st use the defaul t
val ues shown bel ow.
Cxy = cohere(x,y) uses the fol l owi ng defaul t val ues:
nfft = min(256,length(x))
fs = 2
window i s a peri odi c Hann wi ndow of l ength nfft.
numoverlap = 0
I f x i s real , cohere esti mates the coherence functi on at posi ti ve frequenci es
onl y; i n thi s case, the output Cxy i s a col umn vector of l ength nfft/2 + 1 for
nfft even and (nfft + 1)/2 for n odd. I f x or y i s compl ex, cohere esti mates the
coherence functi on at both posi ti ve and negati ve frequenci es, and Cxy has
l ength nfft.
C
xy
f ( )
P
xy
f ( )
2
P
xx
f ( )P
yy
f ( )
------------------------------- =
cohere
7-107
Cxy = cohere(x,y,nfft) uses the FFT l ength nfft i n esti mati ng the power
spectrum for x. Speci fy nfft as a power of 2 for fastest executi on.
Cxy = cohere(x,y,nfft,fs) returns a vector f of frequenci es at whi ch the
functi on eval uates the coherence. fs i s the sampl i ng frequency. f i s the same
si ze as Cxy, so plot(f,Cxy) pl ots the coherence functi on versus properl y scal ed
frequency. fs has no effect on the output Cxy; i t i s a frequency scal i ng
mul ti pl i er.
cohere(x,y,nfft,fs,window) speci fi es a wi ndowi ng functi on and the number
of sampl es per secti on of the vectors x and y. I f you suppl y a scal ar for window,
cohere uses a Hann wi ndow of that l ength. The l ength of the wi ndow must be
l ess than or equal to nfft; cohere zero pads the secti ons i f the wi ndow l ength
exceeds nfft.
cohere(x,y,nfft,fs,window,numoverlap) overl aps the secti ons of x by
numoverlap sampl es.
Note I f you use cohere on two l i nearl y rel ated si gnal s [1] wi th a si ngl e,
non-overl appi ng wi ndow, the output for al l frequenci es i s Cxy = 1.
You can use the empty matri x [] to speci fy the defaul t val ue for any i nput
argument except x or y. For exampl e,
cohere(x,y,[],[],kaiser(128,5));
uses 256 as the val ue for nfft and 2 as the val ue for fs.
cohere(x,y,...,'dflag') speci fi es a detrend opti on, where 'dflag' i s:
'linear', to remove the best strai ght-l i ne fi t from the prewi ndowed secti ons
of x and y
'mean', to remove the mean from the prewi ndowed secti ons of x and y
'none', for no detrendi ng (defaul t)
The 'dflag' parameter must appear l ast i n the l i st of i nput arguments. cohere
recogni zes a 'dflag' stri ng no matter how many i ntermedi ate arguments are
omi tted.
cohere
7-108
cohere wi th no output arguments pl ots the coherence esti mate versus
frequency i n the current fi gure wi ndow.
Example Compute and pl ot the coherence esti mate between two col ored noi se sequences
x and y.
randn('state',0);
h = fir1(30,0.2,rectwin(31));
h1 = ones(1,10)/sqrt(10);
r = randn(16384,1);
x = filter(h1,1,r);
y = filter(h,1,x);
cohere(x,y,1024,[],[],512)
Diagnostics An appropri ate di agnosti c message i s di spl ayed when i ncorrect arguments are
used.
Requires window's length to be no greater than the FFT length.
Requires NOVERLAP to be strictly less than the window length.
Requires positive integer values for NFFT and NOVERLAP.
Requires vector (either row or column) input.
Requires inputs X and Y to have the same length.
0 0.2 0.4 0.6 0.8 1
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
Frequency
C
o
h
e
r
e
n
c
e

F
u
n
c
t
i
o
n

E
s
t
i
m
a
t
e
cohere
7-109
Algorithm cohere esti mates the magni tude squared coherence functi on [2] usi ng Wel chs
method of power spectrum esti mati on (see references [3] and [4]), as fol l ows:
1 I t di vi des the si gnal s x and y i nto separate overl appi ng secti ons, detrends
each secti on, and mul ti pl i es each secti on by window.
2 I t cal cul ates the l ength nfft fast Fouri er transform of each secti on.
3 I t averages the squares of the spectra of the x secti ons to form Pxx, averages
the squares of the spectra of the y secti ons to form Pyy, and averages the
products of the spectra of the x and y secti ons to form Pxy. I t cal cul ates Cxy
by the fol l owi ng formul a.
Cxy = abs(Pxy).^2/(Pxx.*Pyy)
See Also csd, pwelch, tfe
References [1] Stoi ca, P., and R. Moses. I ntroduction to Spectral Analysis. Upper Saddl e
Ri ver, NJ: Prenti ce-Hal l , 1997. Pgs. 61-64.
[2] Kay, S.M. Modern Spectral Estimation. Engl ewood Cl i ffs, NJ:
Prenti ce-Hal l , 1988. Pg. 454.
[3] Rabi ner, L.R., and B. Gol d. Theory and Application of Digital Signal
Processing. Engl ewood Cl i ffs, NJ: Prenti ce-Hal l , 1975.
[4] Wel ch, P.D. The Use of Fast Fouri er Transform for the Esti mati on of Power
Spectra: A Method Based on Ti me Averagi ng Over Short, Modi fi ed
Peri odograms. I EEE Trans. Audio Electroacoust. Vol . AU-15 (June 1967).
Pgs. 70-73.
conv
7-110
7conv
Purpose Convol uti on and pol ynomi al mul ti pl i cati on
Syntax c = conv(a,b)
Description c = conv(a,b) convol ves vectors a and b. The convol uti on sum i s
where N i s the maxi mum sequence l ength. The seri es i s i ndexed from n + 1 and
k + 1 i nstead of the usual n and k because MATLAB vectors run from 1 to n
i nstead of from 0 to n-1.
The conv functi on i s part of the standard MATLAB l anguage.
Example The convol uti on of a = [1 2 3] and b = [4 5 6] i s
c = conv(a,b)
c =
4 13 28 27 18
Algorithm The conv functi on i s an M-fi l e that uses the filter pri mi ti ve. conv computes
the convol uti on operati on as FI R fi l teri ng wi th an appropri ate number of zeros
appended to the i nput.
See Also conv2, convmtx, convn, deconv, filter, residuez, xcorr
c n 1 + ( ) a k 1 + ( )b n k ( )
k 0 =
N 1

=
conv2
7-111
7conv2
Purpose Two-di mensi onal convol uti on
Syntax C = conv2(A,B)
C = conv2(A,B,'shape')
Description C = conv2(A,B) computes the two-di mensi onal convol uti on of matri ces A
and B. I f one of these matri ces descri bes a two-di mensi onal FI R fi l ter, the other
matri x i s fi l tered i n two di mensi ons.
Each di mensi on of the output matri x C i s equal i n si ze to one l ess than the sum
of the correspondi ng di mensi ons of the i nput matri ces. When
[ma,na] = size(A) and [mb,nb] = size(B),
size(C) = [ma+mb-1,na+nb-1]
C = conv2(A,B,'shape') returns a subsecti on of the two-di mensi onal
convol uti on wi th si ze speci fi ed by 'shape', where:
'full' returns the ful l two-di mensi onal convol uti on (defaul t)
'same' returns the central part of the convol uti on that i s the same si ze as A
'valid' returns onl y those parts of the convol uti on that are computed
wi thout the zero-padded edges. Usi ng thi s opti on,
size(C) = [ma-mb+1,na-nb+1] when size(A) > size(B)
conv2 executes most qui ckl y when size(A) > size(B).
The conv2 functi on i s part of the standard MATLAB l anguage.
Examples I n i mage processi ng, the Sobel edge-fi ndi ng operati on i s a two-di mensi onal
convol uti on of an i nput array wi th the speci al matri x
s = [1 2 1; 0 0 0; -1 -2 -1];
Gi ven any i mage, the fol l owi ng code extracts the hori zontal edges.
h = conv2(I,s);
The fol l owi ng code extracts the verti cal edges fi rst, and then extracts both
hori zontal and verti cal edges combi ned.
v = conv2(I,s');
v2 = (sqrt(h.^2 + v.^2))
conv2
7-112
See Also conv, convn, deconv, filter2, xcorr, xcorr2
convmtx
7-113
7convmtx
Purpose Convol uti on matri x
Syntax A = convmtx(c,n)
A = convmtx(r,n)
Description A convolution matrix i s a matri x, formed from a vector, whose i nner product
wi th another vector i s the convol uti on of the two vectors.
A = convmtx(c,n) where c i s a l ength m col umn vector returns a matri x A of
si ze (m+n-1)-by-n. The product of A and another col umn vector x of l ength n i s
the convol uti on of c wi th x.
A = convmtx(r,n) where r i s a l ength m row vector returns a matri x A of si ze
n-by-(m+n-1). The product of A and another row vector x of l ength n i s the
convol uti on of r wi th x.
Example Generate a si mpl e convol uti on matri x.
h = [1 2 3 2 1];
convmtx(h,7)
ans =
1 2 3 2 1 0 0 0 0 0 0
0 1 2 3 2 1 0 0 0 0 0
0 0 1 2 3 2 1 0 0 0 0
0 0 0 1 2 3 2 1 0 0 0
0 0 0 0 1 2 3 2 1 0 0
0 0 0 0 0 1 2 3 2 1 0
0 0 0 0 0 0 1 2 3 2 1
Note that convmtx handl es edge condi ti ons by zero paddi ng.
I n practi ce, i t i s more effi ci ent to compute convol uti on usi ng
y = conv(c,x)
than by usi ng a convol uti on matri x.
n = length(x);
y = convmtx(c,n)*x
Algorithm convmtx uses the functi on toeplitz to generate the convol uti on matri x.
convmtx
7-114
See Also conv, convn, conv2, dftmtx
corrcoef
7-115
7corrcoef
Purpose Compute the correl ati on coeffi ci ent matri x
Syntax C = corrcoef(X)
C = corrcoef(X,Y)
Description corrcoef returns a matri x of correl ati on coeffi ci ents cal cul ated from an i nput
matri x whose rows are observati ons and whose col umns are vari abl es. I f
C = cov(X), then corrcoef(X) i s the matri x whose el ement (i, j) i s
C = corrcoef(X) i s the zeroth l ag of the covari ance functi on, that i s, the
zeroth l ag of xcov(x,'coeff') packed i nto a square array.
C = corrcoef(X,Y) i s the same as corrcoef([X Y]); that i s, i t concatenates X
and Y i n the row di recti on before i ts computati on.
corrcoef removes the mean from each col umn before cal cul ati ng the resul ts.
See the xcorr functi on for cross-correl ati on opti ons.
The corrcoef functi on i s part of the standard MATLAB l anguage.
See Also cov, mean, median, std, xcorr, xcov
corrcoef i j , ( )
C i j , ( )
C i i , ( )C j j , ( )
---------------------------------- - =
corrmtx
7-116
7corrmtx
Purpose Compute a data matri x for autocorrel ati on matri x esti mati on
Syntax X = corrmtx(x,m)
X = corrmtx(x,m,'method')
[X,R] = corrmtx(...)
Description X = corrmtx(x,m) returns an (n+m)-by-(m+1) rectangul ar Toepl i tz matri x X,
such that X'X i s a (bi ased) esti mate of the autocorrel ati on matri x for the
l ength n data vector x.
X = corrmtx(x,m,'method') computes the matri x X accordi ng to the method
speci fi ed by the stri ng 'method':
'autocorrelation': (defaul t) X i s the (n+m)-by-(m+1) rectangul ar Toepl i tz
matri x that generates an autocorrel ati on esti mate for the l ength n data
vector x, deri ved usi ng prewindowed and postwindowed data, based on an
mth order predi cti on error model .
'prewindowed': X i s the n-by-(m+1) rectangul ar Toepl i tz matri x that
generates an autocorrel ati on esti mate for the l ength n data vector x, deri ved
usi ng prewindowed data, based on an mth order predi cti on error model .
'postwindowed': X i s the n-by-(m+1) rectangul ar Toepl i tz matri x that
generates an autocorrel ati on esti mate for the l ength n data vector x, deri ved
usi ng postwindowed data, based on an mth order predi cti on error model .
'covariance': X i s the (n-m)-by-(m+1) rectangul ar Toepl i tz matri x that
generates an autocorrel ati on esti mate for the l ength n data vector x, deri ved
usi ng nonwindowed data, based on an mth order predi cti on error model .
'modified': X i s the 2(n-m)-by-(m+1) modi fi ed rectangul ar Toepl i tz matri x
that generates an autocorrel ati on esti mate for the l ength n data vector x,
deri ved usi ng forward and backward predi cti on error esti mates, based on an
mth order predi cti on error model .
[X,R] = corrmtx(...) al so returns the (m+1)-by-(m+1) autocorrel ati on matri x
esti mate R, cal cul ated as X'*X.
Examples randn('state',1); n=0:99;
s=exp(i*pi/2*n)+2*exp(i*pi/4*n)+exp(i*pi/3*n)+randn(1,100);
X=corrmtx(s,12,'mod');
corrmtx
7-117
Algorithm The Toepl i tz data matri x computed by corrmtx depends on the method you
sel ect. The matri x determi ned by the autocorrel ati on (defaul t) method i s gi ven
by the fol l owi ng matri x.
I n thi s matri x, m i s the same as the i nput argument m to corrmtx, and n i s
length(x). Vari ati ons of thi s matri x are used to return the output X of corrmtx
for each method:
'autocorrelation': (defaul t) X = X, above.
'prewindowed': X i s the n-by-(m+1) submatri x of X that i s gi ven by the
porti on of X above the l ower gray l i ne.
'postwindowed': X i s the n-by-(m+1) submatri x of X that i s gi ven by the
porti on of X bel ow the upper gray l i ne.
'covariance': X i s the (n-m)-by-(m+1) submatri x of X that i s gi ven by the
porti on of X between the two gray l i nes.
'modified': X i s the 2(n-m)-by-(m+1) matri x X
mod
shown bel ow.
X
x 1 ( ) L 0
M O M
x m 1 + ( ) L x1 )
M O M
x n m ( ) L x m 1 + ( )
M O M
x n ( ) L x n m ( )
M O M
0 L x n ( )
=
corrmtx
7-118
See Also peig, pmusic, rooteig, rootmusic, xcorr
References [1] Marpl e, S.L. Digital Spectral Analysis, Engl ewood Cl i ffs, NJ, Prenti ce-Hal l ,
1987, pp. 216-223.
X
mod
x m 1 + ( ) L x1 )
M O M
x n m ( ) L x m 1 + ( )
M O M
x n ( ) L x n m ( )
x

1 ( ) L x

m 1 + ( )
M N M
x

m 1 + ( ) L x

n m ( )
M N M
x

n m ( ) L x

n ( )
=
cov
7-119
7cov
Purpose Compute the covari ance matri x
Syntax c = cov(x)
c = cov(x,y)
Description cov computes the covari ance matri x. I f x i s a vector, c i s a scal ar contai ni ng the
vari ance. For an array where each row i s an observati on and each col umn a
vari abl e, cov(X) i s the covari ance matri x. diag(cov(X)) i s a vector of
vari ances for each col umn, and sqrt(diag(cov(X))) i s a vector of standard
devi ati ons.
cov(x) i s the zeroth l ag of the covari ance functi on, that i s, the zeroth l ag of
xcov(x)/(n-1) packed i nto a square array.
cov(x,y) where x and y are col umn vectors of equal l ength i s equi val ent to
cov([x y]), that i s, i t concatenates x and y i n the row di recti on before i ts
computati on.
cov removes the mean from each col umn before cal cul ati ng the resul ts.
The cov functi on i s part of the standard MATLAB l anguage.
Algorithm [n,p] = size(x);
x = x-ones(n,1)*(sum(x)/n);
y = x'*x/(n-1);
See Also corrcoef, mean, median, std, xcorr, xcov
cplxpair
7-120
7cpl xpai r
Purpose Group compl ex numbers i nto compl ex conjugate pai rs
Syntax y = cplxpair(x)
y = cplxpair(x,tol)
Description y = cplxpair(x) returns x wi th compl ex conjugate pai rs grouped together.
cplxpair orders the conjugate pai rs by i ncreasi ng real part. Wi thi n a pai r, the
el ement wi th negati ve i magi nary part comes fi rst. The functi on returns al l
purel y real val ues fol l owi ng al l the compl ex pai rs.
y = cplxpair(x,tol) i ncl udes a tol erance, tol, for determi ni ng whi ch
numbers are real and whi ch are pai red compl ex conjugates. By defaul t,
cplxpair uses a tol erance of 100*eps rel ati ve to abs(x(i)). cplxpair forces
the compl ex conjugate pai rs to be exact compl ex conjugates.
The cplxpair functi on i s part of the standard MATLAB l anguage.
Example Order fi ve pol es evenl y spaced around the uni t ci rcl e i nto compl ex pai rs.
cplxpair(exp(2*pi*sqrt(-1)*(0:4)/5)')
ans =
-0.8090 - 0.5878i
-0.8090 + 0.5878i
0.3090 - 0.9511i
0.3090 + 0.9511i
1.0000
Diagnostics I f there i s an odd number of compl ex numbers, or i f the compl ex numbers
cannot be grouped i nto compl ex conjugate pai rs wi thi n the tol erance, cplxpair
generates the error message.
Complex numbers can't be paired.
cremez
7-121
7cremez
Purpose Compl ex and nonl i near-phase equi ri ppl e FI R fi l ter desi gn
Syntax b = cremez(n,f,'fresp')
b = cremez(n,f,'fresp',w)
b = cremez(n,f,{'fresp',p1,p2,...},w)
b = cremez(n,f,a,w)
b = cremez(...,'sym')
b = cremez(...,'skip_stage2')
b = cremez(...,'debug')
b = cremez(...,{lgrid})
[b,delta,opt] = cremez(...)
Description cremez al l ows arbi trary frequency-domai n constrai nts to be speci fi ed for the
desi gn of a possi bl y compl ex FI R fi l ter. The Chebyshev (or mi ni max) fi l ter error
i s opti mi zed, produci ng equi ri ppl e FI R fi l ter desi gns.
b = cremez(n,f,'fresp') returns a l ength n+1 FI R fi l ter wi th the best
approxi mati on to the desi red frequency response as returned by functi on
fresp. f i s a vector of frequency band edge pai rs, speci fi ed i n the range -1
and 1, where 1 corresponds to the normal i zed Nyqui st frequency. The
frequenci es must be i n i ncreasi ng order, and f must have even l ength. The
frequency bands span f(k) to f(k+1) for k odd; the i nterval s f(k+1) to f(k+2)
for k odd are transi ti on bands or dont care regi ons duri ng opti mi zati on.
b = cremez(n,f,'fresp',w) uses the real , non-negati ve wei ghts i n vector w to
wei ght the fi t i n each frequency band. The l ength of w i s hal f the l ength of f, so
there i s exactl y one wei ght per band.
b = cremez(n,f,{'fresp',p1,p2,...},...) suppl i es opti onal parameters
p1, p2, ..., to the frequency response functi on fresp. Predefi ned 'fresp'
frequency response functi ons are i ncl uded for a number of common fi l ter
desi gns, as descri bed bel ow. For al l of the predefi ned frequency response
functi ons, the symmetry opti on 'sym' defaul ts to 'even' i f no negati ve
frequenci es are contai ned i n f and d = 0; otherwi se 'sym' defaul ts to 'none'.
(See the 'sym' opti on bel ow for detai l s.) For al l of the predefi ned frequency
response functi ons, d speci fi es a group-del ay offset such that the fi l ter response
cremez
7-122
has a group del ay of n/2+d i n uni ts of the sampl e i nterval . Negati ve val ues
create l ess del ay; posi ti ve val ues create more del ay. By defaul t d = 0:
lowpass, highpass, bandpass, bandstop
These functi ons share a common syntax, exempl i fi ed bel ow by the stri ng
'lowpass'.
b = cremez(n,f,'lowpass',...) and
b = cremez(n,f,{'lowpass',d},...) desi gn a l i near-phase
(n/2+d del ay) fi l ter.
multiband desi gns a l i near-phase frequency response fi l ter wi th arbi trary
band ampl i tudes.
b = cremez(n,f,{'multiband',a},...) and
b = cremez(n,f,{'multiband',a,d},...) speci fy vector a contai ni ng
the desi red ampl i tudes at the band edges i n f. The desi red ampl i tude at
frequenci es between pai rs of poi nts f(k) and f(k+1) for k odd i s the l i ne
segment connecti ng the poi nts (f(k),a(k)) and (f(k+1),a(k+1)).
differentiator desi gns a l i near-phase di fferenti ator. For these desi gns,
zero-frequency must be i n a transi ti on band, and band wei ghti ng i s set to be
i nversel y proporti onal to frequency.
b = cremez(n,f,{'differentiator',fs},...) and
b = cremez(n,f,{'differentiator',fs,d},...) speci fy the sampl e rate
fs used to determi ne the sl ope of the di fferenti ator response. I f omi tted, fs
defaul ts to 1.
hilbfilt desi gns a l i near-phase Hi l bert transform fi l ter response. For
Hi l bert desi gns, zero-frequency must be i n a transi ti on band.
b = cremez(n,f,'hilbfilt',...) and
b = cremez(N,F,{'hilbfilt',d},...) desi gn a l i near-phase
(n/2+d del ay) Hi l bert transform fi l ter.
b = cremez(n,f,a,w) i s a synonym for
b = cremez(n,f,{'multiband',a},w).
cremez
7-123
b = cremez(...,'sym') i mposes a symmetry constrai nt on the i mpul se
response of the desi gn, where 'sym' may be one of the fol l owi ng:
'none' i ndi cates no symmetry constrai nt. Thi s i s the defaul t i f any negati ve
band edge frequenci es are passed, or i f fresp does not suppl y a defaul t.
'even' i ndi cates a real and even i mpul se response. Thi s i s the defaul t for
hi ghpass, l owpass, bandpass, bandstop, and mul ti band desi gns.
'odd' i ndi cates a real and odd i mpul se response. Thi s i s the defaul t for
Hi l bert and di fferenti ator desi gns.
'real' i ndi cates conjugate symmetry for the frequency response
I f any 'sym' opti on other than 'none' i s speci fi ed, the band edges shoul d onl y
be speci fi ed over posi ti ve frequenci es; the negati ve frequency regi on i s fi l l ed i n
from symmetry. I f a 'sym' opti on i s not speci fi ed, the fresp functi on i s queri ed
for a defaul t setti ng.
b = cremez(...,'skip_stage2') di sabl es the second-stage opti mi zati on
al gori thm, whi ch executes onl y when cremez determi nes that an opti mal
sol uti on has not been reached by the standard Remez error-exchange.
Di sabl i ng thi s al gori thm may i ncrease the speed of computati on, but may i ncur
a reducti on i n accuracy. By defaul t, the second-stage opti mi zati on i s enabl ed.
b = cremez(...,'debug') enabl es the di spl ay of i ntermedi ate resul ts duri ng
the fi l ter desi gn, where 'debug' may be one of 'trace', 'plots', 'both', or
'off'. By defaul t i t i s set to 'off'.
b = cremez(...,{lgrid}) uses the i nteger lgrid to control the densi ty of the
frequency gri d, whi ch has roughl y 2^nextpow2(lgrid*n) frequency poi nts.
The defaul t val ue for lgrid i s 25. Note that the {lgrid} argument must be a
1-by-1 cel l array.
Any combi nati on of the 'sym', 'skip_stage2', 'debug', and {lgrid} opti ons
may be speci fi ed.
[b,delta] = cremez(...) returns the maxi mum ri ppl e hei ght delta.
cremez
7-124
[b,delta,opt] = cremez(...) returns a structure opt of opti onal resul ts
computed by cremez and contai ns the fol l owi ng fi el ds.
User-defi nabl e functi ons may be used, i nstead of the predefi ned frequency
response functi ons for fresp. The functi on i s cal l ed from wi thi n cremez usi ng
the fol l owi ng syntax
[dh,dw] = fresp(n,f,gf,w,p1,p2,...)
where:
n i s the fi l ter order.
f i s the vector of frequency band edges that appear monotoni cal l y between -1
and 1, where 1 corresponds to the Nyqui st frequency.
gf i s a vector of gri d poi nts that have been l i nearl y i nterpol ated over each
speci fi ed frequency band by cremez. gf determi nes the frequency gri d at
whi ch the response functi on must be eval uated. Thi s i s the same data
returned by cremez i n the fgrid fi el d of the opt structure.
w i s a vector of real , posi ti ve wei ghts, one per band, used duri ng opti mi zati on.
w i s opti onal i n the cal l to cremez; i f not speci fi ed, i t i s set to uni ty wei ghti ng
before bei ng passed to fresp.
dh and dw are the desi red compl ex frequency response and band wei ght
vectors, respecti vel y, eval uated at each frequency i n gri d gf.
p1, p2, ..., are opti onal parameters that may be passed to fresp.
opt.fgrid Frequency gri d vector used for the fi l ter desi gn opti mi zati on
opt.des Desi red frequency response for each poi nt i n opt.fgrid
opt.wt Wei ghti ng for each poi nt i n opt.fgrid
opt.H Actual frequency response for each poi nt i n opt.fgrid
opt.error Error at each poi nt i n opt.fgrid
opt.iextr Vector of i ndi ces i nto opt.fgrid for extremal frequenci es
opt.fextr Vector of extremal frequenci es
cremez
7-125
Addi ti onal l y, a prel i mi nary cal l i s made to fresp to determi ne the defaul t
symmetry property 'sym'. Thi s cal l i s made usi ng the syntax.
sym = fresp('defaults',{n,f,[],w,p1,p2,...})
The arguments may be used i n determi ni ng an appropri ate symmetry defaul t
as necessary. The functi on private/lowpass.m may be useful as a templ ate for
generati ng new frequency response functi ons.
Examples Ex a mple 1
Desi gn a 31-tap, l i near-phase, l owpass fi l ter.
b = cremez(30,[-1 -0.5 -0.4 0.7 0.8 1],'lowpass');
freqz(b,1,512,'whole');
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
3500
3000
2500
2000
1500
1000
500
0
Normalized Frequency ( rad/sample)
P
h
a
s
e

(
d
e
g
r
e
e
s
)
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
100
80
60
40
20
0
20
Normalized Frequency ( rad/sample)
M
a
g
n
i
t
u
d
e

(
d
B
)
cremez
7-126
Ex a mple 2
Desi gn a nonl i near-phase al l pass FI R fi l ter.
Fi rst sel ect (or create) the functi on fresp that returns the desi red frequency
response. For thi s exampl e, fresp i s the allpass.m functi on i n the
signal/signal/private di rectory whi ch returns the frequency response of a
nonl i near-phase al l pass fi l ter. Copy allpass.m to another l ocati on on the
MATLAB path before tryi ng the exampl e.
Before usi ng cremez wi th allpass.m to generate the fi l ter coeffi ci ents, cal l
allpass al one to create the desired response.
n = 22; % Filter order
f = [-1 1]; % Frequency band edges
w = [1 1]; % Weights for optimization
gf = linspace(-1,1,256); % Grid of frequency points
d = allpass(n,f,gf,w); % Desired frequency response
Vector d now contai ns the compl ex frequency response that we desi re for the
FI R fi l ter computed by cremez.
Now compute the FI R fi l ter that best approxi mates thi s response.
b = cremez(n,f,'allpass',w,'real'); % Approximation
freqz(b,1,256,'whole');
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
1500
1000
500
0
500
Normalized Frequency ( rad/sample)
P
h
a
s
e

(
d
e
g
r
e
e
s
)
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
90
80
70
60
50
40
30
Normalized Frequency ( rad/sample)
M
a
g
n
i
t
u
d
e

(
d
B
)
cremez
7-127
The freqz pl ot shows the frequency response of the fi l ter computed by cremez
to approxi mate the desi red response. Check the accuracy of the approxi mati on
by overl ayi ng the desired frequency response on the pl ot.
subplot(2,1,1); hold on
plot(pi*(gf+1),20*log10(abs(fftshift(d))),'r--')
subplot(2,1,2); hold on
plot(pi*(gf+1),unwrap(angle(fftshift(d)))*180/pi,'r--')
legend('Approximation','Desired')
Algorithm An extended versi on of the Remez exchange method i s i mpl emented for the
compl ex case. Thi s exchange method obtai ns the opti mal fi l ter when the
equi ri ppl e nature of the fi l ter i s restri cted to have n+2 extremal s. When i t does
not converge, the al gori thm swi tches to an ascent-descent al gori thm that takes
over to fi ni sh the convergence to the opti mal sol uti on. See the references for
further detai l s.
See Also fir1, fir2, firls, remez
References [1] Karam, L.J., and J.H. McCl el l an. Compl ex Chebyshev Approxi mati on for
FI R Fi l ter Desi gn. I EEE Trans. on Circuits and Systems I I . March 1995.
Pgs. 207-216.
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
3000
2000
1000
0
Normalized Angular Frequency ( rads/sample)
P
h
a
s
e

(
d
e
g
r
e
e
s
)
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
0.2
0.1
0
0.1
0.2
Normalized Angular Frequency ( rads/sample)
M
a
g
n
i
t
u
d
e

(
d
B
)
Approximation
Desired
cremez
7-128
[2] Karam, L.J. Design of Complex Digital FI R Filters in the Chebyshev Sense.
Ph.D. Thesi s, Georgi a I nsti tute of Technol ogy, March 1995.
[3] Demjanjov, V.F., and V.N. Mal ozemov. I ntroduction to Minimax. New York:
John Wi l ey & Sons, 1974.
csd
7-129
7csd
Purpose Esti mate the cross spectral densi ty (CSD) of two si gnal s
Syntax Pxy = csd(x,y)
Pxy = csd(x,y,nfft)
[Pxy,f] = csd(x,y,nfft,fs)
Pxy = csd(x,y,nfft,fs,window)
Pxy = csd(x,y,nfft,fs,window,numoverlap)
Pxy = csd(x,y,...,'dflag')
[Pxy,Pxyc,f] = csd(x,y,nfft,fs,window,numoverlap,p)
csd(x,y,...)
Description Pxy = csd(x,y) esti mates the cross spectral densi ty of the l ength n sequences
x and y usi ng the Wel ch method of spectral esti mati on. Pxy = csd(x,y) uses
the fol l owi ng defaul t val ues:
nfft = min(256,length(x))
fs = 2
window i s a peri odi c Hann wi ndow of l ength nfft.
numoverlap = 0
nfft speci fi es the FFT l ength that csd uses. Thi s val ue determi nes the
frequenci es at whi ch the cross spectrum i s esti mated. fs i s a scal ar that
speci fi es the sampl i ng frequency. window speci fi es a wi ndowi ng functi on and
the number of sampl es csd uses i n i ts secti oni ng of the x and y vectors.
numoverlap i s the number of sampl es by whi ch the secti ons overl ap. Any
arguments omi tted from the end of the parameter l i st use the defaul t val ues
shown above.
I f x and y are real , csd esti mates the cross spectral densi ty at posi ti ve
frequenci es onl y; i n thi s case, the output Pxy i s a col umn vector of l ength
nfft/2 + 1 for nfft even and (nfft + 1)/2 for nfft odd. I f x or y i s compl ex,
csd esti mates the cross spectral densi ty at both posi ti ve and negati ve
frequenci es and Pxy has l ength nfft.
Pxy = csd(x,y,nfft) uses the FFT l ength nfft i n esti mati ng the cross
spectral densi ty of x and y. Speci fy nfft as a power of 2 for fastest executi on.
[Pxy,f] = csd(x,y,nfft,fs) returns a vector f of frequenci es at whi ch the
functi on eval uates the CSD. f i s the same si ze as Pxy, so plot(f,Pxy) pl ots the
csd
7-130
spectrum versus properl y scal ed frequency. fs has no effect on the output Pxy;
i t i s a frequency scal i ng mul ti pl i er.
Pxy = csd(x,y,nfft,fs,window) speci fi es a wi ndowi ng functi on and the
number of sampl es per secti on of the x vector. I f you suppl y a scal ar for window,
csd uses a Hann wi ndow of that l ength. The l ength of the wi ndow must be l ess
than or equal to nfft; csd zero pads the secti ons i f the l ength of the wi ndow i s
l ess than nfft. csd returns an error i f the l ength of the wi ndow i s greater than
nfft.
Pxy = csd(x,y,nfft,fs,window,numoverlap) overl aps the secti ons of x and y
by numoverlap sampl es.
You can use the empty matri x [] to speci fy the defaul t val ue for any i nput
argument except x or y. For exampl e,
csd(x,y,[],10000)
i s equi val ent to
csd(x)
but wi th a sampl i ng frequency of 10,000 Hz i nstead of the defaul t of 2 Hz.
Pxy = csd(x,y,...,'dflag') speci fi es a detrend opti on, where the stri ng
'dflag i s one of the fol l owi ng:
'linear', to remove the best strai ght-l i ne fi t from the prewi ndowed secti ons
of x and y
'mean', to remove the mean from the prewi ndowed secti ons of x and y
'none', for no detrendi ng (defaul t)
The dflag parameter must appear l ast i n the l i st of i nput arguments. csd
recogni zes a dflag stri ng no matter how many i ntermedi ate arguments are
omi tted.
[Pxy,Pxyc,f] = csd(x,y,nfft,fs,window,numoverlap,p) where p i s a
posi ti ve scal ar between 0 and 1 returns a vector Pxyc that contai ns an esti mate
of the p*100 percent confi dence i nterval for Pxy. Pxyc i s a two-col umn matri x
the same l ength as Pxy. The i nterval [Pxyc(:,1),Pxyc(:,2)] covers the true
csd
7-131
CSD wi th probabi l i ty p. plot(f,[Pxy Pxyc]) pl ots the cross spectrum i nsi de
the p*100 percent confi dence i nterval . I f unspeci fi ed, p defaul ts to 0.95.
csd(x,y,...) pl ots the CSD versus frequency i n the current fi gure wi ndow. I f
the p parameter i s speci fi ed, the pl ot i ncl udes the confi dence i nterval .
Example Generate two col ored noi se si gnal s and pl ot thei r CSD wi th a confi dence
i nterval of 95%. Speci fy a l ength 1024 FFT, a 500 poi nt tri angul ar wi ndow wi th
no overl ap, and a sampl i ng frequency of 10 Hz.
randn('state',0);
h = fir1(30,0.2,rectwin(31));
h1 = ones(1,10)/sqrt(10);
r = randn(16384,1);
x = filter(h1,1,r);
y = filter(h,1,x);
csd(x,y,1024,10000,triang(500),0,[])
Algorithm csd i mpl ements the Wel ch method of spectral densi ty esti mati on (see
references [1] and [2]):
1 I t appl i es the wi ndow speci fi ed by the window vector to each successi ve
detrended secti on.
2 I t transforms each secti on wi th an nfft-poi nt FFT.
0 1000 2000 3000 4000 5000
70
60
50
40
30
20
10
0
10
20
Frequency
C
r
o
s
s

S
p
e
c
t
r
u
m

M
a
g
n
i
t
u
d
e

(
d
B
)
csd
7-132
3 I t forms the peri odogram of each secti on by scal i ng the product of the
transform of the y secti on and the conjugate of the transformed x secti on.
4 I t averages the peri odograms of the successi ve overl appi ng secti ons to form
Pxy, the cross spectral densi ty of x and y.
The number of secti ons that csd averages i s k, where k i s
fix((length(x)-numoverlap)/(length(window)-numoverlap))
Diagnostics An appropri ate di agnosti c message i s di spl ayed when i ncorrect arguments to
csd are used.
Requires window's length to be no greater than the FFT length.
Requires NOVERLAP to be strictly less than the window length.
Requires positive integer values for NFFT and NOVERLAP.
Requires vector (either row or column) input.
Requires inputs X and Y to have the same length.
Requires confidence parameter to be a scalar between 0 and 1.
See Also cohere, pburg, pmtm, pmusic, pwelch, pyulear, tfe
References [1] Rabi ner, L.R., and B. Gol d. Theory and Application of Digital Signal
Processing. Engl ewood Cl i ffs, NJ: Prenti ce-Hal l , 1975. Pgs. 414-419.
[2] Wel ch, P.D. The Use of Fast Fouri er Transform for the Esti mati on of Power
Spectra: A Method Based on Ti me Averagi ng Over Short, Modi fi ed
Peri odograms. I EEE Trans. Audio Electroacoust. Vol . AU-15 (June 1967).
Pgs. 70-73.
[3] Oppenhei m, A.V., and R.W. Schafer. Discrete-Time Signal Processing.
Upper Saddl e Ri ver, NJ: Prenti ce-Hal l , 1999, pp. 737.
czt
7-133
7czt
Purpose Chi rp z-transform
Syntax y = czt(x,m,w,a)
y = czt(x)
Description y = czt(x,m,w,a) returns the chi rp z-transform of si gnal x. The chi rp
z-transform i s the z-transform of x al ong a spi ral contour defi ned by w and a.
m i s a scal ar that speci fi es the l ength of the transform, w i s the rati o between
poi nts al ong the z-pl ane spi ral contour of i nterest, and scal ar a i s the compl ex
starti ng poi nt on that contour. The contour, a spi ral or chi rp i n the z-pl ane, i s
gi ven by
z = a*(w.^-(0:m-1))
y = czt(x) uses the fol l owi ng defaul t val ues:
m = length(x)
w = exp(j*2*pi/m)
a = 1
Wi th these defaul ts, czt returns the z-transform of x at m equal l y spaced poi nts
around the uni t ci rcl e. Thi s i s equi val ent to the di screte Fouri er transform of x,
or fft(x). The empty matri x [] speci fi es the defaul t val ue for a parameter.
I f x i s a matri x, czt(x,m,w,a) transforms the col umns of x.
Examples Create a random vector x of l ength 1013 and compute i ts DFT usi ng czt.
randn('state',0);
x = randn(1013,1);
y = czt(x);
Use czt to zoom i n on a narrow-band secti on (100 to 150 Hz) of a fi l ters
frequency response. Fi rst desi gn the fi l ter.
h = fir1(30,125/500,rectwin(31)); % filter
czt
7-134
Establ i sh frequency and CZT parameters.
fs = 1000; f1 = 100; f2 = 150; % in hertz
m = 1024;
w = exp(-j*2*pi*(f2-f1)/(m*fs));
a = exp(j*2*pi*f1/fs);
Compute both the DFT and CZT of the fi l ter.
y = fft(h,1000);
z = czt(h,m,w,a);
Create frequency vectors and compare the resul ts.
fy = (0:length(y)-1)'*1000/length(y);
fz = ((0:length(z)-1)'*(f2-f1)/length(z)) + f1;
plot(fy(1:500),abs(y(1:500))); axis([1 500 0 1.2])
title('FFT')
figure
plot(fz,abs(z)); axis([f1 f2 0 1.2])
title('CZT')
Algorithm czt uses the next power-of-2 l ength FFT to perform a fast convol uti on when
computi ng the z-transform on a speci fi ed chi rp contour [1].
Diagnostics I f m, w, or a i s not a scal ar, czt gi ves the fol l owi ng error message.
Inputs M, W, and A must be scalars.
See Also fft, freqz
100 200 300 400 500
0
0.2
0.4
0.6
0.8
1
FFT
100 110 120 130 140
0
0.2
0.4
0.6
0.8
1
CZT
czt
7-135
References [1] Rabi ner, L.R., and B. Gol d. Theory and Application of Digital Signal
Processing. Engl ewood Cl i ffs, NJ: Prenti ce-Hal l , 1975. Pgs. 393-399.
dct
7-136
7dct
Purpose Di screte cosi ne transform (DCT)
Syntax y = dct(x)
y = dct(x,n)
Description y = dct(x) returns the uni tary di screte cosi ne transform of x
where
N i s the l ength of x, and x and y are the same si ze. I f x i s a matri x, dct
transforms i ts col umns. The seri es i s i ndexed from n = 1 and k = 1 i nstead of
the usual n = 0 and k = 0 because MATLAB vectors run from 1 to N i nstead of
from 0 to N- 1.
y = dct(x,n) pads or truncates x to l ength n before transformi ng.
The DCT i s cl osel y rel ated to the di screte Fouri er transform. You can often
reconstruct a sequence very accuratel y from onl y a few DCT coeffi ci ents, a
useful property for appl i cati ons requi ri ng data reducti on.
y k ( ) w k ( ) x n ( )
2n 1 ( ) k 1 ( )
2N
------------------------------------------- cos
n 1 =
N

k 1 N , , = , =
w k ( )
1
N
--------- k 1 = ,
2
N
---- 2 k N ,

'

=
dct
7-137
Example Fi nd how many DCT coeffi ci ents represent 99% of the energy i n a sequence.
x = (1:100) + 50*cos((1:100)*2*pi/40);
X = dct(x);
[XX,ind] = sort(abs(X)); ind = fliplr(ind);
i = 1;
while (norm([X(ind(1:i)) zeros(1,100-i)])/norm(X)<.99)
i = i + 1;
end
i =
3
See Also fft, idct, dct2, idct2
References [1] Jai n, A.K. Fundamentals of Digital I mage Processing. Engl ewood Cl i ffs, NJ:
Prenti ce-Hal l , 1989.
[2] Pennebaker, W.B., and J.L. Mi tchel l . J PEG Still I mage Data Compression
Standard. New York, NY: Van Nostrand Rei nhol d, 1993. Chapter 4.
decimate
7-138
7deci mate
Purpose Decrease the sampl i ng rate for a sequence (deci mati on)
Syntax y = decimate(x,r)
y = decimate(x,r,n)
y = decimate(x,r,'fir')
y = decimate(x,r,n,'fir')
Description Deci mati on reduces the ori gi nal sampl i ng rate for a sequence to a l ower rate,
the opposi te of i nterpol ati on. The deci mati on process fi l ters the i nput data wi th
a l owpass fi l ter and then resampl es the resul ti ng smoothed si gnal at a l ower
rate.
y = decimate(x,r) reduces the sampl e rate of x by a factor r. The deci mated
vector y i s r ti mes shorter i n l ength than the i nput vector x. By defaul t,
decimate empl oys an ei ghth-order l owpass Chebyshev Type I fi l ter. I t fi l ters
the i nput sequence i n both the forward and reverse di recti ons to remove al l
phase di storti on, effecti vel y doubl i ng the fi l ter order.
y = decimate(x,r,n) uses an order n Chebyshev fi l ter. Orders above 13 are not
recommended because of numeri cal i nstabi l i ty. MATLAB di spl ays a warni ng
i n thi s case.
y = decimate(x,r,'fir') uses a 30-poi nt FI R fi l ter, i nstead of the Chebyshev
I I R fi l ter. Here decimate fi l ters the i nput sequence i n onl y one di recti on. Thi s
techni que conserves memory and i s useful for worki ng wi th l ong sequences.
y = decimate(x,r,n,'fir') uses a l ength n FI R fi l ter.
Example Deci mate a si gnal by a factor of four.
t = 0:.00025:1; % Time vector
x = sin(2*pi*30*t) + sin(2*pi*60*t);
y = decimate(x,4);
decimate
7-139
Vi ew the ori gi nal and deci mated si gnal s.
stem(x(1:120)), axis([0 120 -2 2]) % Original signal
title('Original Signal')
figure
stem(y(1:30)) % Decimated signal
title('Decimated Signal')
Algorithm decimate uses deci mati on al gori thms 8.2 and 8.3 from [1]:
1 I t desi gns a l owpass fi l ter. By defaul t, decimate uses a Chebyshev Type I
fi l ter wi th normal i zed cutoff frequency 0.8/r and 0.05 dB of passband
ri ppl e. For the fir opti on, decimate desi gns a l owpass FI R fi l ter wi th cutoff
frequency 1/r usi ng fir1.
2 For the FI R fi l ter, decimate appl i es the fi l ter to the i nput vector i n one
di recti on. I n the I I R case, decimate appl i es the fi l ter i n forward and reverse
di recti ons wi th filtfilt.
3 decimate resampl es the fi l tered data by sel ecti ng every rth poi nt.
Diagnostics I f r i s not an i nteger, decimate gi ves the fol l owi ng error message.
Resampling rate R must be an integer.
I f n speci fi es an I I R fi l ter wi th order greater than 13, decimate gi ves the
fol l owi ng warni ng.
Warning: IIR filters above order 13 may be unreliable.
See Also downsample, interp, resample, spline, upfirdn, upsample
0 50 100
-2
-1
0
1
2
Original Signal
0 10 20 30
-2
-1
0
1
2
Decimated Signal
decimate
7-140
References [1] I EEE. Programs for Digital Signal Processing. I EEE Press. New York: John
Wi l ey & Sons, 1979. Chapter 8.
deconv
7-141
7deconv
Purpose Deconvol uti on and pol ynomi al di vi si on
Syntax [q,r] = deconv(b,a)
Description [q,r] = deconv(b,a) deconvol ves vector a out of vector b, usi ng l ong di vi si on.
The resul t (quoti ent) i s returned i n vector q and the remai nder i n vector r such
that b = conv(q,a) + r.
I f a and b are vectors of pol ynomi al coeffi ci ents, convol vi ng them i s equi val ent
to pol ynomi al mul ti pl i cati on, and deconvol uti on i s equi val ent to pol ynomi al
di vi si on. The resul t of di vi di ng b by a i s quoti ent q and remai nder r.
The deconv functi on i s part of the standard MATLAB l anguage.
Example The convol uti on of a = [1 2 3] and b = [4 5 6] i s
c = conv(a,b)
c =
4 13 28 27 18
Use deconv to di vi de b back out.
[q,r] = deconv(c,a)
q =
4 5 6
r =
0 0 0 0 0
Algorithm Thi s functi on cal l s filter to compute the deconvol uti on as the i mpul se
response of an I I R fi l ter.
See Also conv, filter, residuez
demod
7-142
7demod
Purpose Demodul ati on for communi cati ons si mul ati on
Syntax x = demod(y,fc,fs,'method')
x = demod(y,fc,fs,'method',opt)
x = demod(y,fc,fs,'pwm','centered')
[x1,x2] = demod(y,fc,fs,'qam')
Description demod performs demodul ati on, that i s, i t obtai ns the ori gi nal si gnal from a
modul ated versi on of the si gnal . demod undoes the operati on performed by
modulate.
x = demod(y,fc,fs,'method') and
x = demod(y,fc,fs,'method',opt) demodul ate the real carri er si gnal y wi th a
carri er frequency fc and sampl i ng frequency fs, usi ng one of the opti ons l i sted
bel ow for method. (Note that some methods accept an opti on, opt.)
amdsb-sc
or
am
Amplitude demodulation, double sideband, suppressed
carrier. Mul ti pl i es y by a si nusoi d of frequency fc and appl i es a
fi fth-order Butterworth l owpass fi l ter usi ng filtfilt.
x = y.*cos(2*pi*fc*t);
[b,a] = butter(5,fc*2/fs);
x = filtfilt(b,a,x);
amdsb-tc Amplitude demodulation, double sideband, transmitted
carrier. Mul ti pl i es y by a si nusoi d of frequency fc, and appl i es a
fi fth-order Butterworth l owpass fi l ter usi ng filtfilt.
x = y.*cos(2*pi*fc*t);
[b,a] = butter(5,fc*2/fs);
x = filtfilt(b,a,x);
I f you speci fy opt, demod subtracts scal ar opt from x. The defaul t
val ue for opt i s 0.
amssb Amplitude demodulation, single sideband. Mul ti pl i es y by a
si nusoi d of frequency fc and appl i es a fi fth-order Butterworth
l owpass fi l ter usi ng filtfilt.
x = y.*cos(2*pi*fc*t);
[b,a] = butter(5,fc*2/fs);
x = filtfilt(b,a,x);
demod
7-143
The defaul t method i s 'am'. I n al l cases except 'ppm' and 'pwm', x i s the
same si ze as y.
I f y i s a matri x, demod demodul ates i ts col umns.
x = demod(y,fc,fs,'pwm','centered') fi nds the pul se wi dths assumi ng they
are centered at the begi nni ng of each peri od. x i s l ength length(y)*fc/fs.
See Also modulate, vco
fm Frequency demodulation. Demodul ates the FM waveform by
modul ati ng the Hi l bert transform of y by a compl ex exponenti al
of frequency -fc Hz and obtai ns the i nstantaneous frequency of
the resul t.
pm Phase demodulation. Demodul ates the PM waveform by
modul ati ng the Hi l bert transform of y by a compl ex exponenti al
of frequency fc Hz and obtai ns the i nstantaneous phase of the
resul t.
ppm Pulse-position demodulation. Fi nds the pul se posi ti ons of a
pul se-posi ti on modul ated si gnal y. For correct demodul ati on, the
pul ses cannot overl ap. x i s l ength length(t)*fc/fs.
pwm Pulse-width demodulation. Fi nds the pul se wi dths of a
pul se-wi dth modul ated si gnal y. demod returns i n x a vector
whose el ements speci fy the wi dth of each pul se i n fracti ons of a
peri od. The pul ses i n y shoul d start at the begi nni ng of each
carri er peri od, that i s, they shoul d be l eft justi fi ed.
qam Quadrature amplitude demodulation.
[x1,x2] = demod(y,fc,fs,'qam') mul ti pl i es y by a cosi ne and a
si ne of frequency fc and appl i es a fi fth-order Butterworth
l owpass fi l ter usi ng filtfilt.
x1 = y.*cos(2*pi*fc*t);
x2 = y.*sin(2*pi*fc*t);
[b,a] = butter(5,fc*2/fs);
x1 = filtfilt(b,a,x1);
x2 = filtfilt(b,a,x2);
dftmtx
7-144
7dftmtx
Purpose Di screte Fouri er transform matri x
Syntax A = dftmtx(n)
Description A discrete Fourier transform matrix i s a compl ex matri x of val ues around the
uni t ci rcl e, whose matri x product wi th a vector computes the di screte Fouri er
transform of the vector.
A = dftmtx(n) returns the n-by-n compl ex matri x A that, when mul ti pl i ed i nto
a l ength n col umn vector x.
y = A*x
computes the di screte Fouri er transform of x.
The i nverse di screte Fouri er transform matri x i s
Ai = conj(dftmtx(n))/n
Example I n practi ce, the di screte Fouri er transform i s computed more effi ci entl y and
uses l ess memory wi th an FFT al gori thm
x = 1:256;
y1 = fft(x);
than by usi ng the Fouri er transform matri x.
n = length(x);
y2 = x*dftmtx(n);
norm(y1-y2)
ans =
1.8297e-009
Algorithm dftmtx takes the FFT of the i denti ty matri x to generate the transform matri x.
See Also convmtx, fft
diric
7-145
7di ri c
Purpose Compute the Di ri chl et or peri odi c si nc functi on
Syntax y = diric(x,n)
Description y = diric(x,n) returns a vector or array y the same si ze as x. The el ements of
y are the Di ri chl et functi on of the el ements of x. n must be a posi ti ve i nteger.
The Di ri chl et functi on, or peri odi c si nc functi on, i s
for any nonzero i nteger n. Thi s functi on has peri od 2 for n odd and peri od 4
for n even. I ts peak val ue i s 1, and i ts mi ni mum val ue i s -1 for n even. The
magni tude of thi s functi on i s (1/n) ti mes the magni tude of the di screte-ti me
Fouri er transform of the n-poi nt rectangul ar wi ndow.
Diagnostics I f n i s not a posi ti ve i nteger, diric gi ves the fol l owi ng error message.
Requires n to be a positive integer.
See Also cos, gauspuls, pulstran, rectpuls, sawtooth, sin, sinc, square, tripuls
di ri c x n , ( )
1
x
2
------- n 1 ( )
x 0 2 t 4 t , , , =
nx 2 ( ) si n
n x 2 ( ) si n
----------------------------
el se

'

=
downsample
7-146
7downsampl e
Purpose Decrease the sampl i ng rate of the i nput si gnal
Syntax y = downsample(x,n)
y = downsample(x,n,phase)
Description y = downsample(x,n) decreases the sampl i ng rate of x by keepi ng every n
th

sampl e starti ng wi th the fi rst sampl e. x can be a vector or a matri x. I f x i s a
matri x, each col umn i s consi dered a separate sequence.
y = downsample(x,n,phase) speci fi es the number of sampl es by whi ch to
offset the downsampl ed sequence. phase must be an i nteger from 0 to n-1.
Examples Decrease the sampl i ng rate of a sequence by 3.
x = [1 2 3 4 5 6 7 8 9 10];
y = downsample(x,3)
y =
1 4 7 10
Decrease the sampl i ng rate of the sequence by 3 and add a phase offset of 2.
y = downsample(x,3,2)
y =
3 6 9
Decrease the sampl i ng rate of a matri x by 3.
x = [1 2 3; 4 5 6; 7 8 9; 10 11 12];
y = downsample(x,3);
x,y
x =
1 2 3
4 5 6
7 8 9
10 11 12
y =
1 2 3
10 11 12
downsample
7-147
See Also decimate, interp, interp1, resample, spline, upfirdn, upsample
dpss
7-148
7dpss
Purpose Di screte prol ate spheroi dal sequences (Sl epi an sequences)
Syntax [e,v] = dpss(n,nw)
[e,v] = dpss(n,nw,k)
[e,v] = dpss(n,nw,[k1 k2])
[e,v] = dpss(n,nw,'int')
[e,v] = dpss(n,nw,'int',Ni)
[e,v] = dpss(...,'trace')
Description [e,v] = dpss(n,nw) generates the fi rst 2*nw discrete prolate spheroidal
sequences (DPSS) of l ength n i n the col umns of e, and thei r correspondi ng
concentrati ons i n vector v. They are al so generated i n the DPSS MAT-fi l e
database dpss.mat. nw must be l ess than n/2.
[e,v] = dpss(n,nw,k) returns the k most band-l i mi ted di screte prol ate
spheroi dal sequences. k must be an i nteger such that 1 k n.
[e,v] = dpss(n,nw,[k1 k2]) returns the k1st through the k2nd di screte
prol ate spheroi dal sequences, where 1 k1 k2 n.
For al l of the above forms:
The Sl epi an sequences are cal cul ated di rectl y.
The sequences are generated i n the frequency band || (2W), where
W = nw/n i s the hal f-bandwi dth and i s i n rad/sampl e.
e(:,1) i s the l ength n si gnal most concentrated i n the frequency band
|| (2W) radi ans, e(:,2) i s the si gnal orthogonal to e(:,1) that i s most
concentrated i n thi s band, e(:,3) i s the si gnal orthogonal to both e(:,1)
and e(:,2) that i s most concentrated i n thi s band, etc.
For mul ti taper spectral anal ysi s, typi cal choi ces for nw are 2, 5/2, 3, 7/2, or 4.
[e,v] = dpss(n,nw,'int') uses the i nterpol ati on method speci fi ed by the
stri ng 'int' to compute e and v from the sequences i n dpss.mat wi th l ength
cl osest to n. The stri ng 'int' can be ei ther:
'spline': Use spl i ne i nterpol ati on.
'linear': Use l i near i nterpol ati on. Thi s i s much faster but l ess accurate
than spl i ne i nterpol ati on.
dpss
7-149
[e,v] = dpss(n,nw,'int',Ni) i nterpol ates from exi sti ng l ength Ni sequences.
The i nterpol ati on method 'linear' requi res Ni > n.
[e,v] = dpss(...,'trace') uses the trai l i ng stri ng 'trace' to di spl ay whi ch
i nterpol ati on method DPSS uses. I f you dont speci fy the i nterpol ati on method,
the di spl ay i ndi cates that you are usi ng the direct method.
Examples Ex a mple 1 : Using dpss, dpssa ve, a nd dpssdir
Create a catal ogue of 16 DPSS functi ons wi th nw = 4, and use spl i ne
i nterpol ati on on 10 of these functi ons whi l e di spl ayi ng the i nterpol ati on
method you use. You can do thi s usi ng dpss, dpsssave, and dpssdir.
% Create the catalogue of functions.
[e,v] = dpss(16,4);
% Save e and v in a MAT-file.
dpsssave(4,e,v);
% Find nw = 4. First create a structure called index.
index = dpssdir;
index.wlists
ans =
NW: 4
key: 1
% Use spline interpolation on 10 of the DPSS functions.
[e1,v1] = dpss(10,4,'spline',size(e,1),'trace');
Ex a mple 2 : Using dpss a nd dpssloa d
Create a set of DPSS functi ons usi ng dpss, and use the spl i ne method on a
subset of these functi ons. Use dpssload to l oad the MAT-fi l e created by dpss.
% Create the catalogue of functions.
[e,v] = dpss(16,4);
% Load dpss.mat, where e and v are saved.
[e1,v1] = dpssload(16,4);
% Use spline interpolation on 10 of the DPSS functions.
[e1,v1] = dpss(10,4,'spline');
See Also dpssclear, dpssdir, dpssload, dpsssave, pmtm
dpss
7-150
References [1] Perci val , D.B., and A.T. Wal den. Spectral Analysis for Physical
Applications: Multitaper and Conventional Univariate Techniques. Cambri dge:
Cambri dge Uni versi ty Press, 1993.
dpssclear
7-151
7dpsscl ear
Purpose Remove di screte prol ate spheroi dal sequences from database
Syntax dpssclear(n,nw)
Description dpssclear(n,nw) removes sequences wi th l ength n and ti me-bandwi dth
product nw from the DPSS MAT-fi l e database dpss.mat.
See Also dpss, dpssdir, dpssload, dpsssave
dpssdir
7-152
7dpssdi r
Purpose Di screte prol ate spheroi dal sequences database di rectory
Syntax dpssdir
dpssdir(n)
dpssdir(nw,'nw')
dpssdir(n,nw)
index = dpssdir
Description dpssdir manages the database di rectory that contai ns the generated DPSS
sampl es i n the DPSS MAT-fi l e database dpss.mat.
dpssdir l i sts the di rectory of saved sequences i n dpss.mat.
dpssdir(n) l i sts the sequences saved wi th l ength n.
dpssdir(nw,'nw') l i sts the sequences saved wi th ti me-bandwi dth product nw.
dpssdir(n,nw) l i sts the sequences saved wi th l ength n and ti me-bandwi dth
product nw.
index = dpssdir i s a structure array descri bi ng the DPSS database. Pass n
and nw opti ons as for the no output case to get a fi l tered index.
Examples See Exampl e 1: Usi ng dpss, dpssave, and dpssdi r on page 7-149.
See Also dpss, dpssclear, dpssload, dpsssave
dpssload
7-153
7dpssl oad
Purpose Load di screte prol ate spheroi dal sequences from database
Syntax [e,v] = dpssload(n,nw)
Description [e,v] = dpssload(n,nw) l oads al l sequences wi th l ength n and
ti me-bandwi dth product nw i n the col umns of e and thei r correspondi ng
concentrati ons i n vector v from the DPSS MAT-fi l e database dpss.mat.
Examples See Exampl e 2: Usi ng dpss and dpssl oad on page 7-149.
See Also dpss, dpssclear, dpssdir, dpsssave
dpsssave
7-154
7dpsssave
Purpose Save di screte prol ate spheroi dal sequences i n database
Syntax dpsssave(nw,e,v)
status = dpsssave(nw,e,v)
Description dpsssave(nw,e,v) saves the sequences i n the col umns of e and thei r
correspondi ng concentrati ons i n vector v i n the DPSS MAT-fi l e database
dpss.mat.
I t i s not necessary to speci fy sequence l ength, because the l ength of the
sequence i s determi ned by the number of rows of e.
nw i s the time-bandwidth product that was speci fi ed when the sequence was
created usi ng dpss.
status = dpsssave(nw,e,v) returns 0 i f the save was successful and 1 i f there
was an error.
Examples See Exampl e 1: Usi ng dpss, dpssave, and dpssdi r on page 7-149.
See Also dpss, dpssclear, dpssdir, dpssload
ellip
7-155
7el l i p
Purpose El l i pti c (Cauer) fi l ter desi gn
Syntax [b,a] = ellip(n,Rp,Rs,Wn)
[b,a] = ellip(n,Rp,Rs,Wn,'ftype')
[b,a] = ellip(n,Rp,Rs,Wn,'s')
[b,a] = ellip(n,Rp,Rs,Wn,'ftype','s')
[z,p,k] = ellip(...)
[A,B,C,D] = ellip(...)
Description ellip desi gns l owpass, bandpass, hi ghpass, and bandstop di gi tal and anal og
el l i pti c fi l ters. El l i pti c fi l ters offer steeper rol l off characteri sti cs than
Butterworth or Chebyshev fi l ters, but are equi ri ppl e i n both the pass- and
stopbands. I n general , el l i pti c fi l ters meet gi ven performance speci fi cati ons
wi th the l owest order of any fi l ter type.
Digita l Doma in
[b,a] = ellip(n,Rp,Rs,Wn) desi gns an order n l owpass di gi tal el l i pti c fi l ter
wi th cutoff frequency Wn, Rp dB of ri ppl e i n the passband, and a stopband Rs dB
down from the peak val ue i n the passband. I t returns the fi l ter coeffi ci ents i n the
l ength n+1 row vectors b and a, wi th coeffi ci ents i n descendi ng powers of z.
The cutoff frequency i s the edge of the passband, at whi ch the magni tude
response of the fi l ter i s -Rp dB. For ellip, the cutoff frequency Wn i s a number
between 0 and 1, where 1 corresponds to hal f the sampl i ng frequency (Nyqui st
frequency). Smal l er val ues of passband ri ppl e Rp and l arger val ues of stopband
attenuati on Rs both l ead to wi der transi ti on wi dths (shal l ower rol l off
characteri sti cs).
I f Wn i s a two-el ement vector, Wn = [w1 w2], ellip returns an order 2*n
bandpass fi l ter wi th passband w1 < < w2.
H z ( )
B z ( )
A z ( )
-----------
b 1 ( ) b 2 ( )z
1
L b n 1 + ( )z
n
+ + +
1 a 2 ( )z
1
L a n 1 + ( )z
n
+ + +
------------------------------------------------------------------------------------ = =
ellip
7-156
[b,a] = ellip(n,Rp,Rs,Wn,'ftype') desi gns a hi ghpass or bandstop fi l ter,
where the stri ng 'ftype' i s ei ther:
'high' for a hi ghpass di gi tal fi l ter wi th cutoff frequency Wn
'stop' for an order 2*n bandstop di gi tal fi l ter i f Wn i s a two-el ement vector,
Wn = [w1 w2]. The stopband i s w1 < < w2.
Wi th di fferent numbers of output arguments, ellip di rectl y obtai ns other
real i zati ons of the fi l ter. To obtai n zero-pol e-gai n form, use three output
arguments as shown bel ow.
[z,p,k] = ellip(n,Rp,Rs,Wn) or
[z,p,k] = ellip(n,Rp,Rs,Wn,'ftype') returns the zeros and pol es i n l ength
n col umn vectors z and p and the gai n i n the scal ar k.
To obtai n state-space form, use four output arguments as shown bel ow.
[A,B,C,D] = ellip(n,Rp,Rs,Wn) or
[A,B,C,D] = ellip(n,Rp,Rs,Wn,'ftype') where A, B, C, and D are
and u i s the i nput, x i s the state vector, and y i s the output.
Ana log Doma in
[b,a] = ellip(n,Rp,Rs,Wn,'s') desi gns an order n l owpass anal og el l i pti c
fi l ter wi th cutoff frequency Wn and returns the fi l ter coeffi ci ents i n the l ength
n+1 row vectors b and a, i n descendi ng powers of s, deri ved from the transfer
functi on
The cutoff frequency i s the edge of the passband, at whi ch the magni tude
response of the fi l ter i s -Rp dB. For ellip, the cutoff frequency Wn must be
greater than 0 rad/s.
x n 1 + [ ] Ax n [ ] Bu n [ ] + =
y n [ ] Cx n [ ] Du n [ ] + =
H s ( )
B s ( )
A s ( )
---------- -
b 1 ( )s
n
b 2 ( )s
n 1
L b n 1 + ( ) + + +
s
n
a 2 ( )s
n 1
L a n 1 + ( ) + + +
------------------------------------------------------------------------------------- = =
ellip
7-157
I f Wn i s a two-el ement vector wi th w1 < w2, then ellip(n,Rp,Rs,Wn,'s')
returns an order 2*n bandpass anal og fi l ter wi th passband w1 < < w2.
[b,a] = ellip(n,Rp,Rs,Wn,'ftype','s') desi gns a hi ghpass or bandstop
fi l ter.
Wi th di fferent numbers of output arguments, ellip di rectl y obtai ns other
real i zati ons of the anal og fi l ter. To obtai n zero-pol e-gai n form, use three output
arguments as shown bel ow.
[z,p,k] = ellip(n,Rp,Rs,Wn,'s') or
[z,p,k] = ellip(n,Rp,Rs,Wn,'ftype','s') returns the zeros and pol es i n
l ength n or 2*n col umn vectors z and p and the gai n i n the scal ar k.
To obtai n state-space form, use four output arguments as shown bel ow.
[A,B,C,D] = ellip(n,Rp,Rs,Wn,'s') or
[A,B,C,D] = ellip(n,Rp,Rs,Wn,'ftype','s') where A, B, C, and D are
and u i s the i nput, x i s the state vector, and y i s the output.
Examples Ex a mple 1
For data sampl ed at 1000 Hz, desi gn a si xth-order l owpass el l i pti c fi l ter wi th a
cutoff frequency of 300 Hz, 3 dB of ri ppl e i n the passband, and 50 dB of
attenuati on i n the stopband.
[b,a] = ellip(6,3,50,300/500);
The fi l ters frequency response i s
freqz(b,a,512,1000)
title('n=6 Lowpass Elliptic Filter')
x

Ax Bu + =
y Cx Du + =
ellip
7-158
Ex a mple 2
Desi gn a 20th-order bandpass el l i pti c fi l ter wi th a passband from 100 to 200 Hz
and pl ot i ts i mpul se response.
n = 10; Rp = 0.5; Rs = 20;
Wn = [100 200]/500;
[b,a] = ellip(n,Rp,Rs,Wn);
[y,t] = impz(b,a,101); stem(t,y)
title('Impulse Response of n=10 Elliptic Filter')
0 50 100 150 200 250 300 350 400 450 500
500
400
300
200
100
0
100
Frequency (Hz)
P
h
a
s
e

(
d
e
g
r
e
e
s
)
0 50 100 150 200 250 300 350 400 450 500
100
80
60
40
20
0
Frequency (Hz)
M
a
g
n
i
t
u
d
e

(
d
B
)
n=6 Lowpass Elliptic Filter
ellip
7-159
Limitations For hi gh order fi l ters, the state-space form i s the most numeri cal l y accurate,
fol l owed by the zero-pol e-gai n form. The transfer functi on form i s the l east
accurate; numeri cal probl ems can ari se for fi l ter orders as l ow as 15.
Algorithm The desi gn of el l i pti c fi l ters i s the most di ffi cul t and computati onal l y i ntensi ve
of the Butterworth, Chebyshev Type I and I I , and el l i pti c desi gns. ellip uses
a fi ve-step al gori thm:
1 I t fi nds the l owpass anal og prototype pol es, zeros, and gai n usi ng the
ellipap functi on.
2 I t converts the pol es, zeros, and gai n i nto state-space form.
3 I t transforms the l owpass fi l ter to a bandpass, hi ghpass, or bandstop fi l ter
wi th the desi red cutoff frequenci es usi ng a state-space transformati on.
4 For di gi tal fi l ter desi gn, ellip uses bilinear to convert the anal og fi l ter
i nto a di gi tal fi l ter through a bi l i near transformati on wi th frequency
prewarpi ng. Careful frequency adjustment guarantees that the anal og
fi l ters and the di gi tal fi l ters wi l l have the same frequency response
magni tude at Wn or w1 and w2.
5 I t converts the state-space fi l ter back to transfer functi on or zero-pol e-gai n
form, as requi red.
0 10 20 30 40 50 60 70 80 90 100
-0.2
-0.15
-0.1
-0.05
0
0.05
0.1
0.15
0.2
Impulse Response of n = 10 Elliptic Filter
ellip
7-160
See Also besself, butter, cheby1, cheby2, ellipap, ellipord
ellipap
7-161
7el l i pap
Purpose El l i pti c anal og l owpass fi l ter prototype
Syntax [z,p,k] = ellipap(n,Rp,Rs)
Description [z,p,k] = ellipap(n,Rp,Rs) returns the zeros, pol es, and gai n of an order n
el l i pti c anal og l owpass fi l ter prototype, wi th Rp dB of ri ppl e i n the passband,
and a stopband Rs dB down from the peak val ue i n the passband. The zeros and
pol es are returned i n l ength n col umn vectors z and p and the gai n i n scal ar k.
I f n i s odd, z i s l ength n - 1. The transfer functi on i s
El l i pti c fi l ters offer steeper rol l off characteri sti cs than Butterworth and
Chebyshev fi l ters, but they are equi ri ppl e i n both the passband and the
stopband. Of the four cl assi cal fi l ter types, el l i pti c fi l ters usual l y meet a gi ven
set of fi l ter performance speci fi cati ons wi th the l owest fi l ter order.
ellip sets the cutoff frequency of the el l i pti c fi l ter to 1 for a normal i zed
resul t. The cutoff frequency i s the frequency at whi ch the passband ends and
the fi l ter has a magni tude response of 10
-Rp/20
.
Algorithm ellipap uses the al gori thm outl i ned i n [1]. I t empl oys the M-fi l e ellipk to
cal cul ate the compl ete el l i pti c i ntegral of the fi rst ki nd and the M-fi l e ellipj
to cal cul ate Jacobi el l i pti c functi ons.
See Also besselap, buttap, cheb1ap, cheb2ap, ellip
References [1] Parks, T.W., and C.S. Burrus. Digital Filter Design. New York: John Wi l ey
& Sons, 1987. Chapter 7.
H s ( )
z s ( )
p s ( )
---------- k
s z 1 ( ) ( ) s z 2 ( ) ( )L s z n ( ) ( )
s p 1 ( ) ( ) s p 2 ( ) ( )L s p n ( ) ( )
-------------------------------------------------------------------------------- = =

0
ellipord
7-162
7el l i pord
Purpose Cal cul ate the mi ni mum order for el l i pti c fi l ters
Syntax [n,Wn] = ellipord(Wp,Ws,Rp,Rs)
[n,Wn] = ellipord(Wp,Ws,Rp,Rs,'s')
Description ellipord cal cul ates the mi ni mum order of a di gi tal or anal og el l i pti c fi l ter
requi red to meet a set of fi l ter desi gn speci fi cati ons.
Digita l Doma in
[n,Wn] = ellipord(Wp,Ws,Rp,Rs) returns the l owest order n of the el l i pti c
fi l ter that l oses no more than Rp dB i n the passband and has at l east Rs dB of
attenuati on i n the stopband. The scal ar (or vector) of correspondi ng cutoff
frequenci es Wn, i s al so returned. Use the output arguments n and Wn i n ellip.
Choose the i nput arguments to speci fy the stopband and passband accordi ng to
the fol l owi ng tabl e.
Table 7-7: Description of Stopband and Passband Filter Parameters
Wp Passband corner frequency Wp, the cutoff frequency, i s a scal ar
or a two-el ement vector wi th val ues between 0 and 1, wi th 1
correspondi ng to the normal i zed Nyqui st frequency, radi ans
per sampl e.
Ws Stopband corner frequency Ws, i s a scal ar or a two-el ement
vector wi th val ues between 0 and 1, wi th 1 correspondi ng to
the normal i zed Nyqui st frequency.
Rp Passband ri ppl e, i n deci bel s. Twi ce thi s val ue speci fi es the
maxi mum permi ssi bl e passband wi dth i n deci bel s.
Rs Stopband attenuati on, i n deci bel s. Thi s val ue i s the number of
deci bel s the stopband i s attenuated wi th respect to the
passband response.
ellipord
7-163
Use the fol l owi ng gui de to speci fy fi l ters of di fferent types.
I f your fi l ter speci fi cati ons cal l for a bandpass or bandstop fi l ter wi th unequal
ri ppl e i n each of the passbands or stopbands, desi gn separate l owpass and
hi ghpass fi l ters accordi ng to the speci fi cati ons i n thi s tabl e, and cascade the
two fi l ters together.
Ana log Doma in
[n,Wn] = ellipord(Wp,Ws,Rp,Rs,'s') fi nds the mi ni mum order n and cutoff
frequenci es Wn for an anal og fi l ter. You speci fy the frequenci es Wp and Ws
si mi l ar to Tabl e 7-7, onl y i n thi s case you speci fy the frequency i n radi ans per
second, and the passband or the stopband can be i nfi ni te.
Use ellipord for l owpass, hi ghpass, bandpass, and bandstop fi l ters as
descri bed i n Tabl e 7-8.
Table 7-8: Filter Type Stopband and Passband Specifications
Filter Type Stopband and Passband Conditions Stopband Passband
Lowpass Wp < Ws, both scal ars (Ws,1) (0,Wp)
Hi ghpass Wp > Ws, both scal ars (0,Ws) (Wp,1)
Bandpass The i nterval speci fi ed by Ws contai ns
the one speci fi ed by Wp
(Ws(1) < Wp(1) < Wp(2) < Ws(2)).
(0,Ws(1))
and
(Ws(2),1)
(Wp(1),Wp(2))
Bandstop The i nterval speci fi ed by Wp contai ns
the one speci fi ed by Ws
(Wp(1) < Ws(1) < Ws(2) < Wp(2)).
(0,Wp(1))
and
(Wp(2),1)
(Ws(1),Ws(2))
ellipord
7-164
Examples Ex a mple 1
For 1000 Hz data, desi gn a l owpass fi l ter wi th l ess than 3 dB of ri ppl e i n the
passband defi ned from 0 to 40 Hz and at l east 60 dB of ri ppl e i n the stopband
defi ned from 150 Hz to the Nyqui st frequency (500 Hz).
Wp = 40/500; Ws = 150/500;
Rp = 3; Rs = 60;
[n,Wn] = ellipord(Wp,Ws,Rp,Rs)
n =
4
Wn =
0.0800
[b,a] = ellip(n,Rp,Rs,Wn);
freqz(b,a,512,1000);
title('n=4 Elliptic Lowpass Filter')
0 50 100 150 200 250 300 350 400 450 500
400
300
200
100
0
100
Frequency (Hz)
P
h
a
s
e

(
d
e
g
r
e
e
s
)
0 50 100 150 200 250 300 350 400 450 500
120
100
80
60
40
20
0
Frequency (Hz)
M
a
g
n
i
t
u
d
e

(
d
B
)
n=4 Elliptic Lowpass Filter
ellipord
7-165
Ex a mple 2
Now desi gn a bandpass fi l ter wi th a passband from 60 Hz to 200 Hz, wi th l ess
than 3 dB of ri ppl e i n the passband, and 40 dB attenuati on i n the stopbands
that are 50 Hz wi de on both si des of the passband.
Wp = [60 200]/500; Ws = [50 250]/500;
Rp = 3; Rs = 40;
[n,Wn] = ellipord(Wp,Ws,Rp,Rs)
n =
5
Wn =
0.1200 0.4000
[b,a] = ellip(n,Rp,Rs,Wn);
freqz(b,a,512,1000);
title('n=5 Elliptic Bandpass Filter')
0 50 100 150 200 250 300 350 400 450 500
500
0
500
Frequency (Hz)
P
h
a
s
e

(
d
e
g
r
e
e
s
)
0 50 100 150 200 250 300 350 400 450 500
300
250
200
150
100
50
0
Frequency (Hz)
M
a
g
n
i
t
u
d
e

(
d
B
)
n=5 Elliptic Bandpass Filter
ellipord
7-166
Algorithm ellipord uses the el l i pti c l owpass fi l ter order predi cti on formul a descri bed
i n [1]. The functi on performs i ts cal cul ati ons i n the anal og domai n for both the
anal og and di gi tal cases. For the di gi tal case, i t converts the frequency
parameters to the s-domai n before esti mati ng the order and natural
frequenci es, and then converts them back to the z-domai n.
ellipord i ni ti al l y devel ops a l owpass fi l ter prototype by transformi ng the
passband frequenci es of the desi red fi l ter to 1 rad/s (for l ow- and hi ghpass
fi l ters) and to -1 and 1 rad/s (for bandpass and bandstop fi l ters). I t then
computes the mi ni mum order requi red for a l owpass fi l ter to meet the stopband
speci fi cati on.
See Also buttord, cheb1ord, cheb2ord, ellip
References [1] Rabi ner, L.R., and B. Gol d. Theory and Application of Digital Signal
Processing. Engl ewood Cl i ffs, NJ: Prenti ce-Hal l , 1975. Pg. 241.
eqtflength
7-167
7eqtfl ength
Purpose Make the l engths of a transfer functi ons numerator and denomi nator equal
Syntax [b,a] = eqtflength(num,den)
[b,a,n,m] = eqtflength(num,den)
Description [b,a] = eqtflength(num,den) modi fi es the vector num and/or the vector den,
so that the resul ti ng output vectors b and a have the same l ength. The i nput
vectors num and den may have di fferent l engths. The vector num represents the
numerator pol ynomi al of a gi ven di screte-ti me transfer functi on, and the vector
den represents i ts denomi nator. The resul ti ng numerator b and denomi nator a
represent the same di screte-ti me transfer functi on, but these vectors have the
same l ength.
[b,a,n,m] = eqtflength(num,den) modi fi es the vectors as above and al so
returns the numerator order n and the denomi nator m, not i ncl udi ng any
trai l i ng zeros.
Use eqtflength to obtai n a numerator and denomi nator of equal l ength before
appl yi ng transfer functi on conversi on functi ons such as tf2ss and tf2zp to
di screte-ti me model s.
Examples num = [1 0.5];
den = [1 0.75 0.6 0];
[b,a,n,m] = eqtflength(num,den)
b =
1.0000 0.5000 0
a =
1.0000 0.7500 0.6000
n =
1
m =
2
Algorithm eqtflength(num,den) appends zeros to ei ther num or den as necessary. I f both
num and den have trai l i ng zeros i n common, these are removed.
See Also tf2ss, tf2zp
fdatool
7-168
7fdatool
Purpose Open the Fi l ter Desi gn and Anal ysi s Tool
Syntax fdatool
Description fdatool opens the Fi l ter Desi gn and Anal ysi s Tool (FDATool ). Use thi s tool to:
Desi gn fi l ters
Anal yze fi l ters
Modi fy exi sti ng fi l ter desi gns
See Chapter 5, Fi l ter Desi gn and Anal ysi s Tool , for more i nformati on.
Remarks The Fi l ter Desi gn and Anal ysi s Tool provi des more desi gn methods than the
SPTool Fi l ter Desi gner.
fdatool
7-169
Note The Fi l ter Desi gn and Anal ysi s Tool requi res a screen resol uti on
greater than 640 x 480.
See Also sptool, fvtool
fft
7-170
7fft
Purpose Compute the one-di mensi onal fast Fouri er transform
Syntax y = fft(x)
y = fft(x,n)
Description fft computes the di screte Fouri er transform of a vector or matri x. Thi s
functi on i mpl ements the transform gi ven by
where W
N
= e
-j(2/N)
and N = length(x). Note that the seri es i s i ndexed as
n + 1 and k + 1 i nstead of the usual n and k because MATLAB vectors run from
1 to N i nstead of from 0 to N-1.
y = fft(x) i s the di screte Fouri er transform of vector x, computed wi th a fast
Fouri er transform (FFT) al gori thm. I f x i s a matri x, y i s the FFT of each col umn
of the matri x.
y = fft(x,n) i s the n-poi nt FFT. I f the l ength of x i s l ess than n, fft pads x
wi th trai l i ng zeros to l ength n. I f the l ength of x i s greater than n, fft truncates
the sequence x. I f x i s an array, fft adjusts the l ength of the col umns i n the
same manner.
The fft functi on i s part of the standard MATLAB l anguage.
Examples A common use of the Fouri er transform i s to fi nd the frequency components of
a ti me-domai n si gnal buri ed i n noi se. Consi der data sampl ed at 1000 Hz. Form
a si gnal consi sti ng of 50 Hz and 120 Hz si nusoi ds and corrupt the si gnal wi th
zero-mean random noi se.
randn('state',0)
t = 0:0.001:0.6;
x = sin(2*pi*50*t) + sin(2*pi*120*t);
y = x + 2*randn(1,length(t));
plot(y(1:50))
X k 1 + ( ) x n 1 + ( )W
n
kn
n 0 =
N 1

=
fft
7-171
I t i s di ffi cul t to i denti fy the frequency components by studyi ng the ori gi nal
si gnal . Convert to the frequency domai n by taki ng the di screte Fouri er
transform of the noi sy si gnal y usi ng a 512-poi nt fast Fouri er transform (FFT).
Y = fft(y,512);
The power spectral densi ty, a measurement of the energy at vari ous
frequenci es, i s
Pyy = Y.*conj(Y) / 512;
Graph the fi rst 256 poi nts (the other 256 poi nts are symmetri c) on a
meani ngful frequency axi s.
f = 1000*(0:255)/512;
plot(f,Pyy(1:256))
0 5 10 15 20 25 30 35 40 45 50
5
4
3
2
1
0
1
2
3
4
5
fft
7-172
See the pwelch functi on for detai l s on esti mati ng the spectral densi ty.
Someti mes i t i s useful to normal i ze the output of fft so that a uni t si nusoi d i n
the ti me domai n corresponds to uni t ampl i tude i n the frequency domai n. To
produce a normal i zed di screte-ti me Fouri er transform i n thi s manner, use
Pn = abs(fft(x))*2/length(x)
Algorithm fft i s a bui l t-i n MATLAB functi on. See the fft reference page i n the MATLAB
documentati on for detai l s about the al gori thm.
See Also dct, dftmtx, fft2, fftshift, filter, freqz, ifft, pwelch
0 100 200 300 400 500
0
10
20
30
40
50
60
70
fft2
7-173
7fft2
Purpose Compute the two-di mensi onal fast Fouri er transform
Syntax Y = fft2(X)
Y = fft2(X,m,n)
Description Y = fft2(X) performs a two-di mensi onal FFT, produci ng a resul t Y wi th the
same si ze as X. I f X i s a vector, Y has the same ori entati on as X.
Y = fft2(X,m,n) truncates or zero pads X, i f necessary, to create an m-by-n
array before performi ng the FFT. The resul t Y i s al so m-by-n.
The fft2 functi on i s part of the standard MATLAB l anguage.
Algorithm fft2(x) i s si mpl y
fft(fft(x).').'
Thi s computes the one-di mensi onal fft of each col umn of x, then of each row
of the resul t. The ti me requi red to compute fft2(x) depends on the number of
pri me factors i n [m,n] = size(x). fft2 i s fastest when m and n are powers of 2.
See Also fft, fftshift, ifft, ifft2
fftfilt
7-174
7fftfi l t
Purpose FFT-based FI R fi l teri ng usi ng the overl ap-add method
Syntax y = fftfilt(b,x)
y = fftfilt(b,x,n)
Description fftfilt fi l ters data usi ng the effi ci ent FFT-based method of overlap-add, a
frequency domai n fi l teri ng techni que that works onl y for FI R fi l ters.
y = fftfilt(b,x) fi l ters the data i n vector x wi th the fi l ter descri bed by
coeffi ci ent vector b. I t returns the data vector y. The operati on performed by
fftfilt i s descri bed i n the time domain by the di fference equati on
An equi val ent representati on i s the z-transform or frequency domain descri pti on
By defaul t, fftfilt chooses an FFT l ength and data bl ock l ength that
guarantee effi ci ent executi on ti me.
y = fftfilt(b,x,n) uses an FFT l ength of nfft = 2^nextpow2(n) and a data
bl ock l ength of nfft - length(b) + 1.
fftfilt works for both real and compl ex i nputs.
Examples Show that the resul ts from fftfilt and filter are i denti cal .
b = [1 2 3 4];
x = [1 zeros(1,99)]';
norm(fftfilt(b,x) - filter(b,1,x))
ans =
9.5914e-15
Algorithm fftfilt uses fft to i mpl ement the overlap-add method [1], a techni que that
combi nes successi ve frequency domai n fi l tered bl ocks of an i nput sequence.
fftfilt breaks an i nput sequence x i nto l ength L data bl ocks
y n ( ) b 1 ( )x n ( ) b 2 ( )x n 1 ( ) L b nb 1 + ( )x n nb ( ) + + + =
Y z ( ) b 1 ( ) b 2 ( )z
1
L b nb 1 + ( )z
nb
+ + + ( )X z ( ) =
x
L 2L 3L ceil(nx/L)*L
. . .
fftfilt
7-175
and convol ves each bl ock wi th the fi l ter b by
y = ifft(fft(x(i:i+L-1),nfft).*fft(b,nfft));
where nfft i s the FFT l ength. fftfilt overl aps successi ve output secti ons by
n-1 poi nts, where n i s the l ength of the fi l ter, and sums them.
fftfilt chooses the key parameters L and nfft i n di fferent ways, dependi ng
on whether you suppl y an FFT l ength n and on the l engths of the fi l ter and
si gnal . I f you do not speci fy a val ue for n (whi ch determi nes FFT l ength),
fftfilt chooses these key parameters automati cal l y:
I f length(x)i s greater than length(b), fftfilt chooses val ues that
mi ni mi ze the number of bl ocks ti mes the number of fl ops per FFT.
I f length(b) i s greater than or equal to length(x), fftfilt uses a si ngl e
FFT of l ength
2^nextpow2(length(b) + length(x) - 1)
Thi s essenti al l y computes
y = ifft(fft(B,nfft).*fft(X,nfft))
I f you suppl y a val ue for n, fftfilt chooses an FFT l ength, nfft, of
2^nextpow2(n)and a data bl ock l ength of nfft - length(b) + 1. I f n i s l ess than
length(b), fftfilt sets n to length(b).
See Also conv, filter, filtfilt
References [1] Oppenhei m, A.V., and R.W. Schafer, Discrete-Time Signal Processing,
Prenti ce-Hal l , 1989.
nb1
L
nb1 2L
nb1 3L
. . .
fftshift
7-176
7fftshi ft
Purpose Rearrange the outputs of the FFT functi ons
Syntax y = fftshift(x)
Description y = fftshift(x) rearranges the outputs of fft and fft2 by movi ng the zero
frequency component to the center of the spectral densi ty, whi ch i s someti mes
a more conveni ent form.
For vectors, fftshift(x) returns a vector wi th the l eft and ri ght hal ves
swapped.
For arrays, fftshift(x) swaps quadrants one and three wi th quadrants two
and four.
The fftshift functi on i s part of the standard MATLAB l anguage.
Examples For any array X
Y = fft2(x)
has Y(1,1) = sum(sum(X)); the DC component of the si gnal i s i n the upper-l eft
corner of the two-di mensi onal FFT. For
Z = fftshift(Y)
the DC component i s near the center of the matri x.
See Also fft, fft2
filter
7-177
7fi l ter
Purpose Fi l ter data wi th a recursi ve (I I R) or nonrecursi ve (FI R) fi l ter
Syntax y = filter(b,a,x)
[y,zf] = filter(b,a,x)
[...] = filter(b,a,x,zi)
[...] = filter(b,a,x,zi,dim)
Description y = filter(b,a,x) fi l ters the data i n vector x wi th the fi l ter descri bed by
coeffi ci ent vectors a and b to create the fi l tered data vector y. When x i s a
matri x, fi l ter operates on the col umns of x. When x i s an N-di mensi onal array,
fi l ter operates on the fi rst nonsi ngl eton di mensi on. a(1) cannot be 0, and i f
a(1) 1, filter normal i zes the fi l ter coeffi ci ents by a(1).
[y,zf] = filter(b,a,x) returns the fi nal val ues zf of the state vector. When
x i s a vector, the si ze of the fi nal condi ti on vector zf i s
max(length(b),length(a))-1, the number of del ays i n the fi l ter. When x i s a
mul ti di mensi onal array, zf i s an s-by-c matri x, where:
s i s the number of del ays i n the fi l ter.
c i s prod(size(x))/size(x,dim), where dim i s the di mensi on i nto whi ch you
are fi l teri ng (the fi rst nonsi ngl eton di mensi on by defaul t).
[...] = filter(b,a,x,zi) speci fi es i ni ti al state condi ti ons i n the vector zi.
The si ze of the i ni ti al condi ti on vector zi must be the same as
max(length(b),length(a))-1, the number of del ays i n the fi l ter.
[...] = filter(b,a,x,zi,dim) fi l ters the i nput data l ocated al ong the
di mensi on dim of x. Set zi to the empty vector [] to use zero i ni ti al condi ti ons.
The filter functi on i s part of the standard MATLAB l anguage.
filter
7-178
Examples Fi nd and graph the 101-poi nt uni t i mpul se response of a di gi tal fi l ter.
x = [1 zeros(1,100)];
[b,a] = butter(12,400/1000);
y = filter(b,a,x);
stem(y)
Algorithm filter i s i mpl emented as a transposed di rect form I I structure [1], as shown
bel ow
where n-1 i s the fi l ter order. The state vector z i s a vector whose components
are deri ved from the val ues of the i nputs to each del ay i n the fi l ter.
0 20 40 60 80 100 120
-0.2
-0.1
0
0.1
0.2
0.3
0.4
z
-1
z
-1
x(m)
y(m)
b( 3) b( 2) b(1)
a( 3) a( 2)
z
1
(m) z
2
(m)
z
-1
b(n)
a(n)
z
n-1
(m)
...
...
...
filter
7-179
The operati on of filter at sampl e m i s i mpl emented usi ng the transposed
di rect form I I structure. Thi s i s cal cul ated by the ti me domai n di fference
equati ons for y and the states z
i
.
Note the di vi si on by a(1). For effi ci ent computati on, sel ect thi s coeffi ci ent to be
a power of 2.
You can use filtic to generate the state vector z
i
(0) from past i nputs and
outputs.
The i nput-output descri pti on of thi s fi l teri ng operati on i n the z-transform
domai n i s a rati onal transfer functi on.
See Also fftfilt, filter2, filtfilt, filtic
References [1] Oppenhei m, A.V., and R.W. Schafer, Discrete-Time Signal Processing,
Prenti ce-Hal l , 1989, pp. 311-312.
y m ( )
b 1 ( )x m ( ) z
1
m 1 ( ) + ( )
a 1 ( )
---------------------------------------------------------- =
z
1
m ( ) b 2 ( )x m ( ) z
2
m 1 ( ) a 2 ( )y m ( ) + =
M M =
z
n 2
m ( ) b n 1 ( )x m ( ) z
n 1
m 1 ( ) a n 1 ( )y m ( ) + =
z
n 1
m ( ) b n ( )x m ( ) a n ( )y m ( ) =
Y z ( )
b 1 ( ) b 2 ( )z
1
L b nb 1 + ( )z
nb
+ + +
a 1 ( ) a 2 ( )z
1
L a na 1 + ( )z
na
+ + +
--------------------------------------------------------------------------------------------X z ( ) =
filter2
7-180
7fi l ter2
Purpose Two-di mensi onal di gi tal fi l teri ng
Syntax Y = filter2(B,X)
Y = filter2(B,X,'shape')
Description Y = filter2(B,X) fi l ters the two-di mensi onal data i n X wi th the
two-di mensi onal FI R fi l ter i n the matri x B. The resul t, Y, i s computed usi ng
two-di mensi onal convol uti on and i s the same si ze as X.
Y = filter2(B,X,'shape') returns Y computed wi th si ze speci fi ed by
'shape':
'same' returns the central part of the convol uti on that i s the same si ze as X
(defaul t).
'full' returns the ful l two-di mensi onal convol uti on, when size(Y) exceeds
size(X).
'valid' returns onl y those parts of the convol uti on that are computed
wi thout the zero-padded edges, when size(Y) i s l ess than size(X).
The filter2 functi on i s part of the standard MATLAB l anguage.
Algorithm The filter2 functi on uses conv2 to compute the ful l two-di mensi onal
convol uti on of the FI R fi l ter wi th the i nput matri x. By defaul t, filter2
extracts and returns the central part of the convol uti on that i s the same si ze as
the i nput matri x. Use the 'shape' parameter to speci fy an al ternate part of the
convol uti on for return.
See Also conv2, filter
filternorm
7-181
7fi l ternorm
Purpose Compute the 2-norm or i nfi ni ty-norm of a di gi tal fi l ter
Syntax filternorm(b,a)
filternorm(b,a,pnorm)
filternorm(b,a,2,tol)
Description A typi cal use for fi l ter norms i s i n di gi tal fi l ter scal i ng to reduce quanti zati on
effects. Scal i ng often i mproves the si gnal -to-noi se rati o of the fi l ter wi thout
resul ti ng i n data overfl ow. You, al so, can use the 2-norm to compute the energy
of the i mpul se response of a fi l ter.
filternorm(b,a) computes the 2-norm of the di gi tal fi l ter defi ned by the
numerator coeffi ci ents i n b and denomi nator coeffi ci ents i n a.
filternorm(b,a,pnorm) computes the 2- or i nfi ni ty-norm (i nf-norm) of the
di gi tal fi l ter, where pnorm i s ei ther 2 or inf.
filternorm(b,a,2,tol) computes the 2-norm of an I I R fi l ter wi th the
speci fi ed tol erance, tol. The tol erance can be speci fi ed onl y for I I R 2-norm
computati ons. pnorm i n thi s case must be 2. I f tol i s not speci fi ed, i t defaul ts to
1e-8.
Examples Compute the 2-norm wi th a tol erance of 1e-10 of an I I R fi l ter.
[b,a]=butter(5,.5);
L2=filternorm(b,a,2,1e-10)
L2 =
0.7071
Compute the i nf-norm of an FI R fi l ter.
b=remez(30,[.1 .9],[1 1],'Hilbert');
Linf=filternorm(b,1,inf)
Linf =
1.0028
filternorm
7-182
Algorithm Gi ven a fi l ter H(z) wi th frequency reponse H(e
j
), the L
p
-norm i s gi ven by
For the case , the norm si mpl i fi es to
For the case p =2, Parseval s theorem states that
where h(n) i s the i mpul se response of the fi l ter. The energy of the i mpul se
response, then, i s .
See Also zp2sos, norm
Reference Jackson, L.B., Digital Filters and Signal Processing, Thi rd Edi ti on, Kl uwer
Academi c Publ i shers, 1996, Chapter 11.
H
p
1
2
------ H e
j
( )
p
d

1
p
---

p = L

H

max

H e
j
( ) =
H
2
1
2
------ H e
j
( )
2
d

1
2
---
h n ( )
2
n =

1
2
---
= =
H
2
2
filtfilt
7-183
7fi l tfi l t
Purpose Zero-phase di gi tal fi l teri ng
Syntax y = filtfilt(b,a,x)
Description y = filtfilt(b,a,x) performs zero-phase di gi tal fi l teri ng by processi ng the
i nput data i n both the forward and reverse di recti ons (see probl em 5.39 i n [1]).
After fi l teri ng i n the forward di recti on, i t reverses the fi l tered sequence and
runs i t back through the fi l ter. The resul ti ng sequence has preci sel y zero-phase
di storti on and doubl e the fi l ter order. filtfilt mi ni mi zes start-up and endi ng
transi ents by matchi ng i ni ti al condi ti ons, and works for both real and compl ex
i nputs.
Note that filtfilt shoul d not be used wi th di fferenti ator and Hi l bert FI R
fi l ters, si nce the operati on of these fi l ters depends heavi l y on thei r phase
response.
Algorithm filtfilt i s an M-fi l e that uses the filter functi on. I n addi ti on to the
forward-reverse fi l teri ng, i t attempts to mi ni mi ze startup transi ents by
adjusti ng i ni ti al condi ti ons to match the DC component of the si gnal and by
prependi ng several fi l ter l engths of a fl i pped, refl ected copy of the i nput si gnal .
See Also fftfilt, filter, filter2
References [1] Oppenhei m, A.V., and R.W. Schafer, Discrete-Time Signal Processing,
Prenti ce-Hal l , 1989, pp. 311-312.
[2] Mi tra, S.K., Digital Signal Processing, 2nd ed., McGraw-Hi l l , 2001, Secti ons
4.4.2 and 8.2.5.
[3] Gustafsson, F., Determi ni ng the i ni ti al states i n forward-backward
fi l teri ng, I EEE Transactions on Signal Processing, Apri l 1996, Vol ume 44,
I ssue 4, pp. 988--992,
filtic
7-184
7fi l ti c
Purpose Fi nd i ni ti al condi ti ons for a transposed di rect form I I fi l ter i mpl ementati on
Syntax z = filtic(b,a,y,x)
z = filtic(b,a,y)
Description z = filtic(b,a,y,x) fi nds the i ni ti al condi ti ons, z, for the del ays i n the
transposed direct form I I fi l ter i mpl ementati on gi ven past outputs y and
i nputs x. The vectors b and a represent the numerator and denomi nator
coeffi ci ents, respecti vel y, of the fi l ters transfer functi on.
The vectors x and y contai n the most recent i nput or output fi rst, and ol dest
i nput or output l ast.
where n i s length(b)-1 (the numerator order) and m i s length(a)-1 (the
denomi nator order). I f length(x) i s l ess than n, filtic pads i t wi th zeros to
l ength n; i f length(y) i s l ess than m, filtic pads i t wi th zeros to l ength m.
El ements of x beyond x(n-1) and el ements of y beyond y(m-1) are unnecessary
so filtic i gnores them.
Output z i s a col umn vector of l ength equal to the l arger of n and m. z descri bes
the state of the del ays gi ven past i nputs x and past outputs y.
z = filtic(b,a,y) assumes that the i nput x i s 0 i n the past.
The transposed di rect form I I structure i s
where n-1 i s the fi l ter order.
filtic works for both real and compl ex i nputs.
x x 1 ( ) x 2 ( ) x 3 ( ) x n ( ) , , , , , { } =
y y 1 ( ) y 2 ( ) y 3 ( ) y m ( ) , , , , , { } =
z
-1
z
-1
x(m)
y(m)
b( 3) b( 2) b(1)
a( 3) a( 2)
z
1
(m) z
2
(m)
z
-1
b(n)
a(n)
z
n-1
(m)
...
...
...
filtic
7-185
Algorithm filtic performs a reverse di fference equati on to obtai n the del ay states z.
Diagnostics I f any of the i nput arguments y, x, b, or a i s not a vector (that i s, i f any
argument i s a scal ar or array), filtic gi ves the fol l owi ng error message.
Requires vector inputs.
See Also filter, filtfilt
References [1] Oppenhei m, A.V., and R.W. Schafer, Discrete-Time Signal Processing,
Prenti ce-Hal l , 1989, pp. 296, 301-302.
fir1
7-186
7fi r1
Purpose Desi gn a wi ndow-based fi ni te i mpul se response fi l ter
Syntax b = fir1(n,Wn)
b = fir1(n,Wn,'ftype')
b = fir1(n,Wn,window)
b = fir1(n,Wn,'ftype',window)
b = fir1(...,'normalization')
Description fir1 i mpl ements the cl assi cal method of wi ndowed l i near-phase FI R di gi tal
fi l ter desi gn [1]. I t desi gns fi l ters i n standard l owpass, hi ghpass, bandpass, and
bandstop confi gurati ons. By defaul t the fi l ter i s normal i zed so that the
magni tude response of the fi l ter at the center frequency of the passband i s
0 dB.
Note Use fir2 for wi ndowed fi l ters wi th arbi trary frequency response.
b = fir1(n,Wn) returns row vector b contai ni ng the n+1 coeffi ci ents of an
order n l owpass FI R fi l ter. Thi s i s a Hammi ng-wi ndow based, l i near-phase
fi l ter wi th normal i zed cutoff frequency Wn. The output fi l ter coeffi ci ents, b, are
ordered i n descendi ng powers of z.
Wn i s a number between 0 and 1, where 1 corresponds to the Nyqui st frequency.
I f Wn i s a two-el ement vector, Wn = [w1 w2], fir1 returns a bandpass fi l ter wi th
passband w1 < < w2.
I f Wn i s a mul ti -el ement vector, Wn = [w1 w2 w3 w4 w5 ... wn], fir1 returns
an order n mul ti band fi l ter wi th bands 0 < < w1, w1 < < w2, ..., wn < < 1.
By defaul t, the fi l ter i s scal ed so that the center of the fi rst passband has a
magni tude of exactl y 1 after wi ndowi ng.
B z ( ) b 1 ( ) b 2 ( )z
1
L b n 1 + ( )z
n
+ + + =
fir1
7-187
b = fir1(n,Wn,'ftype') speci fi es a fi l ter type, where 'ftype' i s:
'high' for a hi ghpass fi l ter wi th cutoff frequency Wn.
'stop' for a bandstop fi l ter, i f Wn = [w1 w2]. The stopband frequency range
i s speci fi ed by thi s i nterval .
'DC-1' to make the fi rst band of a mul ti band fi l ter a passband.
'DC-0' to make the fi rst band of a mul ti band fi l ter a stopband.
fir1 al ways uses an even fi l ter order for the hi ghpass and bandstop
confi gurati ons. Thi s i s because for odd orders, the frequency response at the
Nyqui st frequency i s 0, whi ch i s i nappropri ate for hi ghpass and bandstop
fi l ters. I f you speci fy an odd-val ued n, fir1 i ncrements i t by 1.
b = fir1(n,Wn,window) uses the wi ndow speci fi ed i n col umn vector window
for the desi gn. The vector window must be n+1 el ements l ong. I f no wi ndow i s
speci fi ed, fir1 uses a Hammi ng wi ndow (see hamming) of l ength n+1.
b = fir1(n,Wn,'ftype',window) accepts both 'ftype' and window
parameters.
b = fir1(...,'normalization') speci fi es whether or not the fi l ter
magni tude i s normal i zed. The stri ng 'normalization' can be:
'scale' (defaul t): Normal i ze the fi l ter so that the magni tude response of the
fi l ter at the center frequency of the passband i s 0 dB.
'noscale': Do not normal i ze the fi l ter.
The group del ay of the FI R fi l ter desi gned by fir1 i s n/2.
Algorithm fir1 uses the wi ndow method of FI R fi l ter desi gn [1]. I f w(n) denotes a wi ndow,
where 1 n N, and the i mpul se response of the i deal fi l ter i s h(n), where
h(n) i s the i nverse Fouri er transform of the i deal frequency response, then the
wi ndowed di gi tal fi l ter coeffi ci ents are gi ven by
b n ( ) w n ( )h n ( ) 1 n N , =
fir1
7-188
Examples Ex a mple 1
Desi gn a 48th-order FI R bandpass fi l ter wi th passband 0.35 0.65.
b = fir1(48,[0.35 0.65]);
freqz(b,1,512)
Ex a mple 2
The chirp.mat fi l e contai ns a si gnal , y, that has most of i ts power above fs/4,
or hal f the Nyqui st frequency. Desi gn a 34th-order FI R hi ghpass fi l ter to
attenuate the components of the si gnal bel ow fs/4. Use a cutoff frequency
of 0.48 and a Chebyshev wi ndow wi th 30 dB of ri ppl e.
load chirp % Load y and fs.
b = fir1(34,0.48,'high',chebwin(35,30));
freqz(b,1,512)
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
2500
2000
1500
1000
500
0
Normalized Frequency ( rad/sample)
P
h
a
s
e

(
d
e
g
r
e
e
s
)
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
100
80
60
40
20
0
20
Normalized Frequency ( rad/sample)
M
a
g
n
it
u
d
e

(
d
B
)
fir1
7-189
See Also cremez, filter, fir2, fircls, fircls1, firls, freqz, kaiserord, remez,
window
References [1] Programs for Digital Signal Processing, I EEE Press, New York, 1979.
Al gori thm 5.2.
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
2000
1500
1000
500
0
500
Normalized Frequency ( rad/sample)
P
h
a
s
e

(
d
e
g
r
e
e
s
)
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
120
100
80
60
40
20
0
20
Normalized Frequency ( rad/sample)
M
a
g
n
it
u
d
e

(
d
B
)
fir2
7-190
7fi r2
Purpose Desi gn a frequency sampl i ng-based fi ni te i mpul se response fi l ter
Syntax b = fir2(n,f,m)
b = fir2(n,f,m,window)
b = fir2(n,f,m,npt)
b = fir2(n,f,m,npt,window)
b = fir2(n,f,m,npt,lap)
b = fir2(n,f,m,npt,lap,window)
Description fir2 desi gns frequency sampl i ng-based di gi tal FI R fi l ters wi th arbi trari l y
shaped frequency response.
Note Use fir1 for wi ndows-based standard l owpass, bandpass, hi ghpass,
and bandstop confi gurati ons.
b = fir2(n,f,m) returns row vector b contai ni ng the n+1 coeffi ci ents of an
order n FI R fi l ter. The frequency-magni tude characteri sti cs of thi s fi l ter match
those gi ven by vectors f and m:
f i s a vector of frequency poi nts i n the range from 0 to 1, where 1 corresponds
to the Nyqui st frequency. The fi rst poi nt of f must be 0 and the l ast poi nt 1.
The frequency poi nts must be i n i ncreasi ng order.
m i s a vector contai ni ng the desi red magni tude response at the poi nts
speci fi ed i n f.
f and m must be the same l ength.
Dupl i cate frequency poi nts are al l owed, correspondi ng to steps i n the
frequency response.
Use plot(f,m) to vi ew the fi l ter shape.
The output fi l ter coeffi ci ents, b, are ordered i n descendi ng powers of z.
fir2 al ways uses an even fi l ter order for confi gurati ons wi th a passband at the
Nyqui st frequency. Thi s i s because for odd orders, the frequency response at
b z ( ) b 1 ( ) b 2 ( )z
1
L b n 1 + ( )z
n
+ + + =
fir2
7-191
the Nyqui st frequency i s necessari l y 0. I f you speci fy an odd-val ued n, fir2
i ncrements i t by 1.
b = fir2(n,f,m,window) uses the wi ndow speci fi ed i n the col umn vector
window. The vector window must be n+1 el ements l ong. I f no wi ndow i s speci fi ed,
fir2 uses a Hammi ng wi ndow (see hamming) of l ength n+1.
b = fir2(n,f,m,npt) or
b = fir2(n,f,m,npt,window) speci fi es the number of poi nts, npt, for the gri d
onto whi ch fir2 i nterpol ates the frequency response, wi thout or wi th a window
speci fi cati on.
b = fir2(n,f,m,npt,lap) and
b = fir2(n,f,m,npt,lap,window) speci fy the si ze of the regi on, lap, that
fir2 i nserts around dupl i cate frequency poi nts, wi th or wi thout a window
speci fi cati on.
See the Al gori thm secti on for more on npt and lap.
Examples Desi gn a 30th-order l owpass fi l ter and overpl ot the desi red frequency response
wi th the actual frequency response.
f = [0 0.6 0.6 1]; m = [1 1 0 0];
b = fir2(30,f,m);
[h,w] = freqz(b,1,128);
plot(f,m,w/pi,abs(h))
legend('Ideal','fir2 Designed')
title('Comparison of Frequency Response Magnitudes')
fir2
7-192
Algorithm The desi red frequency response i s i nterpol ated onto a dense, evenl y spaced gri d
of l ength npt. npt i s 512 by defaul t. I f two successi ve val ues of f are the same,
a regi on of lap poi nts i s set up around thi s frequency to provi de a smooth but
steep transi ti on i n the requested frequency response. By defaul t, lap i s 25. The
fi l ter coeffi ci ents are obtai ned by appl yi ng an i nverse fast Fouri er transform to
the gri d and mul ti pl yi ng by a wi ndow; by defaul t, thi s i s a Hammi ng wi ndow.
See Also butter, cheby1, cheby2, ellip, fir1, maxflat, remez, yulewalk
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
0
0.2
0.4
0.6
0.8
1
1.2
1.4
Comparison of Frequency Response Magnitudes
Ideal
fir2 Designed
fircls
7-193
7fi rcl s
Purpose Constrai ned l east square FI R fi l ter desi gn for mul ti band fi l ters
Syntax b = fircls(n,f,amp,up,lo)
fircls(n,f,amp,up,lo,'design_flag')
Description b = fircls(n,f,amp,up,lo) generates a l ength n+1 l i near phase FI R fi l ter b.
The frequency-magni tude characteri sti cs of thi s fi l ter match those gi ven by
vectors f and amp:
f i s a vector of transi ti on frequenci es i n the range from 0 to 1, where 1
corresponds to the Nyqui st frequency. The fi rst poi nt of f must be 0 and the
l ast poi nt 1. The frequency poi nts must be i n i ncreasi ng order.
amp i s a vector descri bi ng the pi ecewi se constant desi red ampl i tude of the
frequency response. The l ength of amp i s equal to the number of bands i n the
response and shoul d be equal to length(f)-1.
up and lo are vectors wi th the same l ength as amp. They defi ne the upper and
l ower bounds for the frequency response i n each band.
fircls al ways uses an even fi l ter order for confi gurati ons wi th a passband at
the Nyqui st frequency. Thi s i s because for odd orders, the frequency response
at the Nyqui st frequency i s necessari l y 0. I f you speci fy an odd-val ued n,
fircls i ncrements i t by 1.
fircls(n,f,amp,up,lo,'design_flag') enabl es you to moni tor the fi l ter
desi gn, where 'design_flag' can be:
'trace', for a textual di spl ay of the desi gn error at each i terati on step.
'plots', for a col l ecti on of pl ots showi ng the fi l ters ful l -band magni tude
response and a zoomed vi ew of the magni tude response i n each sub-band. Al l
pl ots are updated at each i terati on step.
'both', for both the textual di spl ay and pl ots.
fircls
7-194
Examples Desi gn an order 50 bandpass fi l ter.
n = 50;
f = [0 0.4 0.8 1];
amp = [0 1 0];
up = [0.02 1.02 0.01];
lo = [-0.02 0.98 -0.01];
b = fircls(n,f,amp,up,lo,'plots'); % Plot magnitude response
Note Normal l y, the l ower val ue i n the stopband wi l l be speci fi ed as negati ve.
By setti ng lo equal to 0 i n the stopbands, a nonnegati ve frequency response
ampl i tude can be obtai ned. Such fi l ters can be spectral l y factored to obtai n
mi ni mum phase fi l ters.
Algorithm The al gori thm i s a mul ti pl e exchange al gori thm that uses Lagrange
mul ti pl i ers and Kuhn-Tucker condi ti ons on each i terati on.
See Also fircls1, firls, remez
0 0.2 0.4 0.6 0.8 1 1.2 1.4
-2
0
2
0 0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4
-0.02
0
0.02
B
a
n
d

#
1
0.4 0.45 0.5 0.55 0.6 0.65 0.7 0.75 0.8
0.98
1
1.02
B
a
n
d

#
2
0.8 0.85 0.9 0.95 1
-0.01
0
0.01
B
a
n
d

#
3
Frequency
fircls
7-195
References [1] Sel esni ck, I .W., M. Lang, and C.S. Burrus, Constrai ned Least Square
Desi gn of FI R Fi l ters wi thout Speci fi ed Transi ti on Bands, Proceedings of the
I EEE I nt. Conf. Acoust., Speech, Signal Processing, Vol . 2 (May 1995),
pp. 1260-1263.
[2] Sel esni ck, I .W., M. Lang, and C.S. Burrus. Constrai ned Least Square
Desi gn of FI R Fi l ters wi thout Speci fi ed Transi ti on Bands. I EEE Transactions
on Signal Processing, Vol . 44, No. 8 (August 1996).
fircls1
7-196
7fi rcl s1
Purpose Constrai ned l east square fi l ter desi gn for l owpass and hi ghpass l i near phase
FI R fi l ters
Syntax b = fircls1(n,wo,dp,ds)
b = fircls1(n,wo,dp,ds,'high')
b = fircls1(n,wo,dp,ds,wt)
b = fircls1(n,wo,dp,ds,wt,'high')
b = fircls1(n,wo,dp,ds,wp,ws,k)
b = fircls1(n,wo,dp,ds,wp,ws,k,'high')
b = fircls1(n,wo,dp,ds,...,'design_flag')
Description b = fircls1(n,wo,dp,ds) generates a l owpass FI R fi l ter b, where n+1 i s the
fi l ter l ength, wo i s the normal i zed cutoff frequency i n the range between 0 and 1
(where 1 corresponds to the Nyqui st frequency), dp i s the maxi mum passband
devi ati on from 1 (passband ri ppl e), and ds i s the maxi mum stopband devi ati on
from 0 (stopband ri ppl e).
b = fircls1(n,wo,dp,ds,'high') generates a hi ghpass FI R fi l ter b. fircls1
al ways uses an even fi l ter order for the hi ghpass confi gurati on. Thi s i s because
for odd orders, the frequency response at the Nyqui st frequency i s
necessari l y 0. I f you speci fy an odd-val ued n, fircls1 i ncrements i t by 1.
b = fircls1(n,wo,dp,ds,wt) and
b = fircls1(n,wo,dp,ds,wt,'high') speci fi es a frequency wt above whi ch
(for wt > wo) or bel ow whi ch (for wt < wo) the fi l ter i s guaranteed to meet the
gi ven band cri teri on. Thi s wi l l hel p you desi gn a fi l ter that meets a passband
or stopband edge requi rement. There are four cases:
Lowpass:
- 0 < wt < wo < 1: the ampl i tude of the fi l ter i s wi thi n dp of 1 over the
frequency range 0 < < wt.
- 0 < wo < wt < 1: the ampl i tude of the fi l ter i s wi thi n ds of 0 over the
frequency range wt < < 1.
fircls1
7-197
Hi ghpass:
- 0 < wt < wo < 1: the ampl i tude of the fi l ter i s wi thi n ds of 0 over the
frequency range 0 < < wt.
- 0 < wo < wt < 1: the ampl i tude of the fi l ter i s wi thi n dp of 1 over the
frequency range wt < < 1.
b = fircls1(n,wo,dp,ds,wp,ws,k) generates a l owpass FI R fi l ter b wi th a
wei ghted functi on, where n+1 i s the fi l ter l ength, wo i s the normal i zed cutoff
frequency, dp i s the maxi mum passband devi ati on from 1 (passband ri ppl e), and
ds i s the maxi mum stopband devi ati on from 0 (stopband ri ppl e). wp i s the
passband edge of the L2 wei ght functi on and ws i s the stopband edge of the L2
wei ght functi on, where wp < wo < ws. k i s the rati o (passband L2 error)/(stopband
L2 error)
b = fircls1(n,wo,dp,ds,wp,ws,k,'high') generates a hi ghpass FI R fi l ter b
wi th a wei ghted functi on, where ws < wo < wp.
b = fircls1(n,wo,dp,ds,...,'design_flag') enabl es you to moni tor the
fi l ter desi gn, where 'design_flag' can be:
'trace', for a textual di spl ay of the desi gn tabl e used i n the desi gn
'plots', for pl ots of the fi l ters magni tude, group del ay, and zeros and pol es
'both', for both the textual di spl ay and pl ots
Note I n the desi gn of very narrow band fi l ters wi th smal l dp and ds, there
may not exi st a fi l ter of the gi ven l ength that meets the speci fi cati ons.
k
A ( ) D ( )
2
d
0
w
p

A ( ) D ( )
2
d
w
s

------------------------------------------------------ =
fircls1
7-198
Examples Desi gn an order 55 l owpass fi l ter wi th a cutoff frequency at 0.3.
n = 55; wo = 0.3;
dp = 0.02; ds = 0.008;
b = fircls1(n,wo,dp,ds,'plots'); % Plot magnitude response
Algorithm The al gori thm i s a mul ti pl e exchange al gori thm that uses Lagrange
mul ti pl i ers and Kuhn-Tucker condi ti ons on each i terati on.
See Also fircls, firls, remez
References [1] Sel esni ck, I .W., M. Lang, and C.S. Burrus, Constrai ned Least Square
Desi gn of FI R Fi l ters wi thout Speci fi ed Transi ti on Bands, Proceedings of the
I EEE I nt. Conf. Acoust., Speech, Signal Processing, Vol . 2 (May 1995),
pp. 1260-1263.
[2] Sel esni ck, I .W., M. Lang, and C.S. Burrus, Constrai ned Least Square
Desi gn of FI R Fi l ters wi thout Speci fi ed Transi ti on Bands, I EEE Transactions
on Signal Processing, Vol . 44, No. 8 (August 1996).
0 0.2 0.4 0.6 0.8 1
0
0.5
1
0 0.05 0.1 0.15 0.2 0.25
-0.04
-0.02
0
0.02
0.04
0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
-0.01
0
0.01
firls
7-199
7fi rl s
Purpose Least square l i near-phase FI R fi l ter desi gn
Syntax b = firls(n,f,a)
b = firls(n,f,a,w)
b = firls(n,f,a,'ftype')
b = firls(n,f,a,w,'ftype')
Description firls desi gns a l i near-phase FI R fi l ter that mi ni mi zes the wei ghted,
i ntegrated squared error between an i deal pi ecewi se l i near functi on and the
magni tude response of the fi l ter over a set of desi red frequency bands.
b = firls(n,f,a) returns row vector b contai ni ng the n+1 coeffi ci ents of the
order n FI R fi l ter whose frequency-ampl i tude characteri sti cs approxi matel y
match those gi ven by vectors f and a. The output fi l ter coeffi ci ents, or taps,
i n b obey the symmetry rel ati on.
These are type I (n odd) and type I I (n even) l i near-phase fi l ters. Vectors f and a
speci fy the frequency-ampl i tude characteri sti cs of the fi l ter:
f i s a vector of pai rs of frequency poi nts, speci fi ed i n the range between 0
and 1, where 1 corresponds to the Nyqui st frequency. The frequenci es must
be i n i ncreasi ng order. Dupl i cate frequency poi nts are al l owed and, i n fact,
can be used to desi gn a fi l ter exactl y the same as those returned by the fir1
and fir2 functi ons wi th a rectangul ar (rectwin) wi ndow.
a i s a vector contai ni ng the desi red ampl i tude at the poi nts speci fi ed i n f.
The desi red ampl i tude functi on at frequenci es between pai rs of poi nts
(f(k), f(k+1)) for k odd i s the l i ne segment connecti ng the poi nts (f(k), a(k))
and (f(k+1), a(k+1)).
The desi red ampl i tude functi on at frequenci es between pai rs of poi nts
(f(k), f(k+1)) for k even i s unspeci fi ed. These are transi ti on or dont care
regi ons.
f and a are the same l ength. Thi s l ength must be an even number.
firls al ways uses an even fi l ter order for confi gurati ons wi th a passband at
the Nyqui st frequency. Thi s i s because for odd orders, the frequency response
b k ( ) b n 2 k + ( ) k 1 = n 1 + , , , =
firls
7-200
at the Nyqui st frequency i s necessari l y 0. I f you speci fy an odd-val ued n, firls
i ncrements i t by 1.
The fi gure bel ow i l l ustrates the rel ati onshi p between the f and a vectors i n
defi ni ng a desi red ampl i tude response.
b = firls(n,f,a,w) uses the wei ghts i n vector w to wei ght the fi t i n each
frequency band. The l ength of w i s hal f the l ength of f and a, so there i s exactl y
one wei ght per band.
b = firls(n,f,a,'ftype') and
b = firls(n,f,a,w,'ftype') speci fy a fi l ter type, where 'ftype' i s:
'hilbert' for l i near-phase fi l ters wi th odd symmetry (type I I I and type I V).
The output coeffi ci ents i n b obey the rel ati on b(k) = -b(n+2-k),
k = 1, ... , n + 1. Thi s cl ass of fi l ters i ncl udes the Hi l bert transformer, whi ch
has a desi red ampl i tude of 1 across the enti re band.
'differentiator' for type I I I and type I V fi l ters, usi ng a speci al wei ghti ng
techni que. For nonzero ampl i tude bands, the i ntegrated squared error has a
wei ght of (1/f)
2
so that the error at l ow frequenci es i s much smal l er than at
hi gh frequenci es. For FI R di fferenti ators, whi ch have an ampl i tude
characteri sti c proporti onal to frequency, the fi l ters mi ni mi ze the rel ati ve
i ntegrated squared error (the i ntegral of the square of the rati o of the error
to the desi red ampl i tude).
1.0
0.0
Desired amplitude
response (a)
Normalized
frequency (f)
0.5
"Don't care"/transition regions
f = [0 .3 .4 .6 .7 .9]
a = [0 1 0 0 .5 .5]
0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.0 0.8 0.9 1.0 (Nyquist)
firls
7-201
Examples Ex a mple 1
Desi gn an order 255 l owpass fi l ter wi th transi ti on band.
b = firls(255,[0 0.25 0.3 1],[1 1 0 0]);
Ex a mple 2
Desi gn a 31 coeffi ci ent di fferenti ator.
b = firls(30,[0 0.9],[0 0.9],'differentiator');
Ex a mple 3
Desi gn a 24th-order anti -symmetri c fi l ter wi th pi ecewi se l i near passbands and
pl ot the desi red and actual frequency response.
F = [0 0.3 0.4 0.6 0.7 0.9];
A = [0 1 0 0 0.5 0.5];
b = firls(24,F,A,'hilbert');
for i=1:2:6,
plot([F(i) F(i+1)],[A(i) A(i+1)],'--'), hold on
end
[H,f] = freqz(b,1,512,2);
plot(f,abs(H)), grid on, hold off
legend('Ideal','firls Design')
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
Ideal
firls Design
firls
7-202
Algorithm Reference [1] descri bes the theoreti cal approach behi nd firls. The functi on
sol ves a system of l i near equati ons i nvol vi ng an i nner product matri x of si ze
roughl y n/2 usi ng MATLABs \ operator.
Thi s functi on desi gns type I , I I , I I I , and I V l i near-phase fi l ters. Type I and I I
are the defaul ts for n even and odd respecti vel y, whi l e the 'hilbert' and
'differentiator' fl ags produce type I I I (n even) and I V (n odd) fi l ters. The
vari ous fi l ter types have di fferent symmetri es and constrai nts on thei r
frequency responses (see [2] for detai l s).
Diagnostics An appropri ate di agnosti c message i s di spl ayed when i ncorrect arguments are
used.
F must be even length.
F and A must be equal lengths.
Requires symmetry to be 'hilbert' or 'differentiator'.
Requires one weight per band.
Frequencies in F must be nondecreasing.
Frequencies in F must be in range [0,1].
A more seri ous warni ng message i s
Warning: Matrix is close to singular or badly scaled.
Thi s tends to happen when the product of the fi l ter l ength and transi ti on wi dth
grows l arge. I n thi s case, the fi l ter coeffi ci ents b mi ght not represent the
desi red fi l ter. You can check the fi l ter by l ooki ng at i ts frequency response.
See Also fir1, fir2, firrcos, remez
Linear Phase
Filter Type
Filter
Order
Symmetry of Coefficients Response H(f),
f = 0
Response H(f),
f = 1 (Nyquist)
Type I Even even: No restri cti on No restri cti on
Type I I Odd No restri cti on H(1) = 0
Type I I I Even odd: H(0) = 0 H(1) = 0
Type I V Odd H(0) = 0 No restri cti on
b k ( ) b n 2 k + ( ) k 1 = n 1 + , , , =
b k ( ) b n 2 k + ( ) k 1 = n 1 + , , , =
firls
7-203
References [1] Parks, T.W., and C.S. Burrus, Digital Filter Design, John Wi l ey & Sons,
1987, pp. 54-83.
[2] Oppenhei m, A.V., and R.W. Schafer, Discrete-Time Signal Processing,
Prenti ce-Hal l , 1989, pp. 256-266.
firrcos
7-204
7fi rrcos
Purpose Rai sed cosi ne FI R fi l ter desi gn
Syntax b = firrcos(n,F0,df,fs)
b = firrcos(n,F0,df,fs,'bandwidth)
b = firrcos(n,F0,df)
b = firrcos(n,F0,r,fs,'rolloff')
b = firrcos(...,'type')
b = firrcos(...,'type',delay)
b = firrcos(...,'type',delay,window)
[b,a] = firrcos(...)
Description b = firrcos(n,F0,df,fs) or, equi val entl y,
b = firrcos(n,F0,df,fs,'bandwidth') returns an order n l owpass
l i near-phase FI R fi l ter wi th a rai sed cosi ne transi ti on band. The fi l ter has
cutoff frequency F0, transi ti on bandwi dth df, and sampl i ng frequency fs, al l i n
hertz. df must be smal l enough so that F0 t df/2 i s between 0 and fs/2. The
coeffi ci ents i n b are normal i zed so that the nomi nal passband gai n i s al ways
equal to 1. Speci fy fs as the empty vector [] to use the defaul t val ue fs = 2.
b = firrcos(n,F0,df) uses a defaul t sampl i ng frequency of fs = 2.
b = firrcos(n,F0,r,fs,'rolloff') i nterprets the thi rd argument, r, as the
rol l off factor i nstead of the transi ti on bandwi dth, df. r must be i n the range
[0,1].
b = firrcos(...,'type') desi gns ei ther a normal rai sed cosi ne fi l ter or a
square root rai sed cosi ne fi l ter accordi ng to how you speci fy of the stri ng
'type'. Speci fy 'type' as:
'normal', for a regul ar rai sed cosi ne fi l ter. Thi s i s the defaul t, and i s al so i n
effect when the 'type' argument i s l eft empty, [].
'sqrt', for a square root rai sed cosi ne fi l ter.
b = firrcos(...,'type',delay) speci fi es an i nteger del ay i n the range
[0,n+1]. The defaul t i s n/2 for even n and (n+1)/2 for odd n.
b = firrcos(...,'type',delay,window) appl i es a l ength n+1 wi ndow to the
desi gned fi l ter to reduce the ri ppl e i n the frequency response. window must be
firrcos
7-205
a l ength n+1 col umn vector. I f no wi ndow i s speci fi ed, a rectangul ar (rectwin)
wi ndow i s used. Care must be exerci sed when usi ng a wi ndow wi th a del ay
other than the defaul t.
[b,a] = firrcos(...) al ways returns a = 1.
Examples Desi gn an order 20 rai sed cosi ne FI R fi l ter wi th cutoff frequency 0.25 of the
Nyqui st frequency and a transi ti on bandwi dth of 0.25.
h = firrcos(20,0.25,0.25);
freqz(h,1)
See Also fir1, fir2, firls, remez
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
700
600
500
400
300
200
100
0
Normalized Frequency ( rad/sample)
P
h
a
s
e

(
d
e
g
r
e
e
s
)
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
120
100
80
60
40
20
0
20
Normalized Frequency ( rad/sample)
M
a
g
n
i
t
u
d
e

(
d
B
)
freqs
7-206
7freqs
Purpose Frequency response of anal og fi l ters
Syntax h = freqs(b,a,w)
[h,w] = freqs(b,a)
[h,w] = freqs(b,a,l)
freqs(b,a)
Description freqs returns the compl ex frequency response H(j) (Lapl ace transform) of an
anal og fi l ter
gi ven the numerator and denomi nator coeffi ci ents i n vectors b and a.
h = freqs(b,a,w) returns the compl ex frequency response of the anal og fi l ter
speci fi ed by coeffi ci ent vectors b and a. freqs eval uates the frequency response
al ong the i magi nary axi s i n the compl ex pl ane at the frequenci es speci fi ed i n
real vector w.
[h,w] = freqs(b,a) automati cal l y pi cks a set of 200 frequency poi nts w on
whi ch to compute the frequency response h.
[h,w] = freqs(b,a,l) pi cks l frequenci es on whi ch to compute the frequency
response h.
freqs wi th no output arguments pl ots the magni tude and phase response
versus frequency i n the current fi gure wi ndow.
freqs works onl y for real i nput systems and posi ti ve frequenci es.
Examples Fi nd and graph the frequency response of the transfer functi on gi ven by
a = [1 0.4 1];
b = [0.2 0.3 1];
w = logspace(-1,1);
freqs(b,a,w)
H s ( )
B s ( )
A s ( )
---------- -
b 1 ( )s
n
b 2 ( )s
n 1
L b n 1 + ( ) + + +
a 1 ( )s
m
a 2 ( )s
m 1
L a m 1 + ( ) + + +
------------------------------------------------------------------------------------------- = =
H s ( )
0.2s
2
0.3s 1 + +
s
2
0.4s 1 + +
----------------------------------------- =
freqs
7-207
You can al so create the pl ot wi th
h = freqs(b,a,w);
mag = abs(h);
phase = angle(h);
subplot(2,1,1), loglog(w,mag)
subplot(2,1,2), semilogx(w,phase)
To convert to hertz, degrees, and deci bel s, use
f = w/(2*pi);
mag = 20*log10(mag);
phase = phase*180/pi;
Algorithm freqs eval uates the pol ynomi al s at each frequency poi nt, then di vi des the
numerator response by the denomi nator response.
s = i*w;
h = polyval(b,s)./polyval(a,s);
See Also abs, angle, freqz, invfreqs, logspace, polyval
10
-1
10
0
10
1
10
-1
10
0
10
1
Frequency
M
a
g
n
i
t
u
d
e
10
-1
10
0
10
1
-150
-100
-50
0
Frequency
P
h
a
s
e

(
d
e
g
r
e
e
s
)
freqspace
7-208
7freqspace
Purpose Frequency spaci ng for frequency response
Syntax f = freqspace(n)
f = freqspace(n,'whole')
[f1,f2] = freqspace(n)
[f1,f2] = freqspace([m n])
[x1,y1] = freqspace(n,'meshgrid')
[x1,y1] = freqspace([m n],'meshgrid')
Description freqspace returns the i mpl i ed frequency range for equal l y spaced frequency
responses. Thi s i s useful when creati ng frequency vectors for use wi th freqz.
f = freqspace(n) returns the frequency vector f assumi ng n evenl y spaced
poi nts around the uni t ci rcl e. For n even or odd, f i s (0:2/n:1). For n even,
freqspace returns (n + 2)/2 poi nts. For N odd, i t returns (n + 1)/2 poi nts.
f = freqspace(n,'whole') returns n evenl y spaced poi nts around the whol e
uni t ci rcl e. I n thi s case, f i s 0:2/n:2*(n-1)/n.
[f1,f2] = freqspace(n) returns the two-di mensi onal frequency vectors f1
and f2 for an n-by-n matri x. For n odd, both f1 and f2 are
[-1 + 1/n:2/n:1-1/n]. For n even, both f1 and f2 are [-1:2/n:1-2/n].
[f1,f2] = freqspace([m n]) returns the two-di mensi onal frequency vectors
f1 and f2 for an m-by-n matri x.
[x1,y1] = freqspace(n,'meshgrid') and
[x1,y1] = freqspace([m n],'meshgrid') are equi val ent to
[f1,f2] = freqspace(...);
[x1,y1] = meshgrid(f1,f2);
See the MATLAB documentati on for detai l s on the meshgrid functi on.
See Also freqz, invfreqz
freqz
7-209
7freqz
Purpose Compute the frequency response of di gi tal fi l ters
Syntax [h,w]= freqz(b,a,l)
h = freqz(b,a,w)
[h,w] = freqz(b,a,l,'whole')
[h,w,s] = freqz(...)
[h,f] = freqz(b,a,l,fs)
h = freqz(b,a,f,fs)
[h,f] = freqz(b,a,l,'whole',fs)
[h,f,s] = freqz(...)
freqz(b,a,...)
Description [h,w] = freqz(b,a,l) returns the frequency response vector h and the
correspondi ng frequency vector w for the di gi tal fi l ter whose transfer functi on
i s determi ned by the (real or compl ex) numerator and denomi nator
pol ynomi al s represented i n the vectors b and a, respecti vel y. The vectors h
and w are both of l ength l. The frequency vector w has val ues rangi ng from 0 to
radi ans per sampl e. When you dont speci fy the i nteger l, or you speci fy i t as
the empty vector [], the frequency response i s cal cul ated usi ng the defaul t
val ue of 512 sampl es.
h = freqz(b,a,w) returns the frequency response vector h cal cul ated at the
frequenci es (i n radi ans per sampl e) suppl i ed by the vector w. The vector w can
have any l ength.
[h,w] = freqz(b,a,l,'whole') uses n sampl e poi nts around the enti re uni t
ci rcl e to cal cul ate the frequency response. The frequency vector w has l ength l
and has val ues rangi ng from 0 to 2 radi ans per sampl e.
[h,w,s] = freqz(...) returns a structure of pl otti ng i nformati on to be used
wi th freqzplot.
[h,f] = freqz(b,a,l,fs) returns the frequency response vector h and the
correspondi ng frequency vector f for the di gi tal fi l ter whose transfer functi on
i s determi ned by the (real or compl ex) numerator and denomi nator
pol ynomi al s represented i n the vectors b and a, respecti vel y. The vectors h
and f are both of l ength l. For thi s syntax, the frequency response i s cal cul ated
usi ng the sampl i ng frequency speci fi ed by the scal ar fs (i n hertz). The
freqz
7-210
frequency vector f i s cal cul ated i n uni ts of hertz (Hz). The frequency vector f
has val ues rangi ng from 0 to fs/2 Hz.
h = freqz(b,a,f,fs) returns the frequency response vector h cal cul ated at
the frequenci es (i n Hz) suppl i ed i n the vector f. The vector f can be any l ength.
[h,f] = freqz(b,a,l,'whole',fs) uses n poi nts around the enti re uni t ci rcl e
to cal cul ate the frequency response. The frequency vector f has l ength l and
has val ues rangi ng from 0 to fs Hz.
[h,f,units] = freqz(b,a,l,'whole',fs) returns the opti onal stri ng
argument units, speci fyi ng the uni ts for the frequency vector f. The stri ng
returned i n units i s 'Hz', denoti ng hertz.
freqz(b,a,...) pl ots the magni tude and unwrapped phase of the frequency
response of the fi l ter. The pl ot i s di spl ayed i n the current fi gure wi ndow.
Remarks I t i s best to choose a power of two for the thi rd i nput argument n, because freqz
uses an FFT al gori thm to cal cul ate the frequency response. See the reference
descri pti on of fft for more i nformati on.
Examples Pl ot the magni tude and phase response of an FI R fi l ter.
b = fir1(80,0.5,kaiser(81,8));
freqz(b,1);
freqz
7-211
Algorithm The frequency response [1] of a di gi tal fi l ter can be i nterpreted as the transfer
functi on eval uated at z = e
j
. You can al ways wri te a rati onal transfer functi on
i n the fol l owi ng form.
freqz determi nes the transfer functi on from the (real or compl ex) numerator
and denomi nator pol ynomi al s you speci fy, and returns the compl ex frequency
response H(e
j
) of a di gi tal fi l ter. The frequency response i s eval uated at
sampl e poi nts determi ned by the syntax that you use.
freqz general l y uses an FFT al gori thm to compute the frequency response
whenever you dont suppl y a vector of frequenci es as an i nput argument. I t
computes the frequency response as the rati o of the transformed numerator
and denomi nator coeffi ci ents, padded wi th zeros to the desi red l ength.
When you do suppl y a vector of frequenci es as an i nput argument, then freqz
eval uates the pol ynomi al s at each frequency poi nt usi ng Horners method of
nested pol ynomi al eval uati on [1], di vi di ng the numerator response by the
denomi nator response.
See Also abs, angle, fft, filter, freqs, freqzplot, impz, invfreqs, logspace
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
5000
4000
3000
2000
1000
0
Normalized Frequency ( rad/sample)
P
h
a
s
e

(
d
e
g
r
e
e
s
)
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
150
100
50
0
50
Normalized Frequency ( rad/sample)
M
a
g
n
it
u
d
e

(
d
B
)
H z ( )
B z ( )
A z ( )
-----------
b 1 ( ) b 2 ( )z
1
L b n 1 + ( )z
n
+ + +
a 1 ( ) a 2 ( )z
1
L a m 1 + ( )z
m
+ + +
---------------------------------------------------------------------------------------- = =
freqz
7-212
References [1] Oppenhei m, A.V., and R.W. Schafer, Discrete-Time Signal Processing,
Prenti ce-Hal l , 1989, pp. 203-205.
freqzplot
7-213
7freqzpl ot
Purpose Pl ot frequency response data
Syntax freqzplot(h,w)
freqzplot(h,w,s)
freqzplot(h,w,str)
Description freqzplot(h,w) pl ots the frequency response data contai ned i n h at the
frequenci es speci fi ed i n the vector w, where h can be ei ther a vector or a matri x.
w must be a vector whose l ength i s the number of rows i n h. The data i n h i s
pl otted versus frequency w on two pl ots:
The magni tude of h i s pl otted i n dB.
The phase of h i s pl otted i n degrees.
The uni ts for frequency on the pl ots are i n radi ans per sampl e. I f h i s a matri x,
the frequency responses of each col umn of h i s pl otted.
freqzplot(h,w,s) speci fi es a structure of pl otti ng opti ons, s, wi th the
fol l owi ng fi el ds:
s.xunitsa stri ng speci fyi ng the frequency axi s uni ts. The contents of
s.xunits can be one of the fol l owi ng:
- 'rad/sample' (defaul t)
- 'Hz'
- 'kHz'
- 'MHz'
- 'GHz'
- A user-speci fi ed stri ng
s.yunitsa stri ng speci fyi ng the verti cal axi s uni ts. The contents of
s.yunits can be one of the fol l owi ng:
- 'dB' (defaul t)
- 'linear'
- 'squared'
freqzplot
7-214
s.plota stri ng speci fyi ng the type of pl ot to produce. The contents of
s.plot can be one of the fol l owi ng:
- 'both' (defaul t)
- 'mag'
- 'phase'
Note that the s structure can be obtai ned as an output of freqz.
freqzplot(h,w,str) speci fi es a parti cul ar stri ng opti on from the s structure.
Thi s i s a qui ck way to sel ect a si ngl e pl otti ng opti on.
Examples nfft = 512; Fs = 44.1; % Fs is in kHz.
[b1,a1] = cheby1(5,0.4,0.5);
[b2,a2] = cheby1(5,0.5,0.5);
[h1,f,s] = freqz(b1,a1,nfft,Fs);
h2 = freqz(b2,a2,nfft,Fs);% Use the same nfft and Fs.
h = [h1 h2];
Use the qui ck method to speci fy onl y the s.yunits. The s.plot and s.xunits
use the defaul t val ues of both and rad/sample, respecti vel y.
freqzplot(h,f,squared)
0 1 2 3 4 5 6 7
500
400
300
200
100
0
Normalized Frequency ( rad/sample)
P
h
a
s
e

(
d
e
g
r
e
e
s
)
0 1 2 3 4 5 6 7
0
0.5
1
1.5
Normalized Frequency ( rad/sample)
M
a
g
n
i
t
u
d
e

S
q
u
a
r
e
d
freqzplot
7-215
Defi ne each of the s structure uni ts to customi ze the pl ot.
s.plot = 'mag'; % Plot the magnitude only.
s.xunits = 'khz'; % Label the frequency units correctly.
s.yunits = 'squared'; % Plot the magnitude squared.
freqzplot(h,f,s); % Compare the two Chebyshev filters.
See Also freqz, grpdelay, psdplot
0 5 10 15 20
0
0.2
0.4
0.6
0.8
1
1.2
1.4
Frequency (kHz)
M
a
g
n
i
t
u
d
e

s
q
u
a
r
e
d
fvtool
7-216
7fvtool
Purpose Open the Fi l ter Vi sual i zati on Tool
Syntax fvtool(b,a)
fvtool(b
1
,a
1
,b
2
,a
2
,...b
n
,a
n
)
Description fvtool(b,a) opens the Fi l ter Vi sual i zati on Tool (FVTool ) and computes the
magni tude response of the fi l ter defi ned wi th numerator, b and denomi nator,
a. Usi ng FVTool you can di spl ay the phase response, group del ay, i mpul se
response, step response, pol e-zero pl ot, and coeffi ci ents of the fi l ter.
fvtool(b
1
,a
1
,b
2
,a
2
,...b
n
,a
n
) opens FVTool and computes the magni tude
responses of mul ti pl e fi l ters defi ned wi th numerators, b
1
...b
n
and
denomi nators, a
1
...a
n
.
Note I n fdatool, sel ecti ng Full View Analysis from the Analysis menu
l aunches FVTool .
fvtool
7-217
Note I f you have the Fi l ter Desi gn Tool box i nstal l ed, you can use fvtool on
quanti zed fi l ter objects by usi ng fvtool(Hq,Hq1).
Examples Ex a mple 1
Di spl ay the magni tude response of an el l i pti c fi l ter.
Print and
preview
Edit plot
Add text
Add arrow
Add line
Zoom
Toggle
legend
Magnitude Phase
Magnitude
and Phase
Group
Delay
Impulse
Response
Step
Response
Pole-
Zero
Coefficients
Launch a
newFVTool
fvtool
7-218
[b,a]=ellip(6,3,50,300/500);
fvtool(b,a);
Ex a mple 2
Di spl ay and anal yze mul ti pl e FI R fi l ters.
n = 20; % Filter order
f = [0 0.4 0.5 1]; % Frequency band edges
a = [1 1 0 0]; % Desired amplitudes
b = remez(n,f,a);
b2 = remez(n*2,f,a); % Double the filter order
fvtool(b,1,b2,1);
fvtool
7-219
See Also fdatool, sptool
gauspuls
7-220
7gauspul s
Purpose Generate a Gaussi an-modul ated si nusoi dal pul se
Syntax yi = gauspuls(t,fc,bw)
yi = gauspuls(t,fc,bw,bwr)
[yi,yq] = gauspuls(...)
[yi,yq,ye] = gauspuls(...)
tc = gauspuls('cutoff',fc,bw,bwr,tpe)
Description gauspuls generates Gaussi an-modul ated si nusoi dal pul ses.
yi = gauspuls(t,fc,bw) returns a uni ty-ampl i tude Gaussi an RF pul se at the
ti mes i ndi cated i n array t, wi th a center frequency fc i n hertz and a fracti onal
bandwi dth bw, whi ch must be greater than 0. The defaul t val ue for fc i s
1000 Hz and for bw i s 0.5.
yi = gauspuls(t,fc,bw,bwr) returns a uni ty-ampl i tude Gaussi an RF pul se
wi th a fracti onal bandwi dth of bw as measured at a l evel of bwr dB wi th respect
to the normal i zed si gnal peak. The fracti onal bandwi dth reference l evel bwr
must be l ess than 0, because i t i ndi cates a reference l evel l ess than the peak
(uni ty) envel ope ampl i tude. The defaul t val ue for bwr i s -6 dB.
[yi,yq] = gauspuls(...) returns both the i n-phase and quadrature pul ses.
[yi,yq,ye] = gauspuls(...) returns the RF si gnal envel ope.
tc = gauspuls('cutoff',fc,bw,bwr,tpe) returns the cutoff ti me tc (greater
than or equal to 0) at whi ch the trai l i ng pul se envel ope fal l s bel ow tpe dB wi th
respect to the peak envel ope ampl i tude. The trai l i ng pul se envel ope l evel tpe
must be l ess than 0, because i t i ndi cates a reference l evel l ess than the peak
(uni ty) envel ope ampl i tude. The defaul t val ue for tpe i s -60 dB.
Remarks Defaul t val ues are substi tuted for empty or omi tted trai l i ng i nput arguments.
gauspuls
7-221
Examples Pl ot a 50 kHz Gaussi an RF pul se wi th 60% bandwi dth, sampl ed at a rate of
1 MHz. Truncate the pul se where the envel ope fal l s 40 dB bel ow the peak.
tc = gauspuls('cutoff',50e3,0.6,[],-40);
t = -tc : 1e-6 : tc;
yi = gauspuls(t,50e3,0.6);
plot(t,yi)
See Also chirp, cos, diric, pulstran, rectpuls, sawtooth, sin, sinc, square, tripuls
-4 -2 0 2 4
x 10
-5
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
gausswin
7-222
7gausswi n
Purpose Compute a Gaussi an wi ndow
Syntax w = gausswin(n)
w = gausswin(n,)
Description w = gausswin(n) returns an n-poi nt Gaussi an wi ndow i n the col umn vector w.
n i s a posi ti ve i nteger. The coeffi ci ents of a Gaussi an wi ndow are computed
from the fol l owi ng equati on.

where and .
w = gausswin(n,) returns an n-poi nt Gaussi an wi ndow where i s the
reci procal of the standard devi ati on. The wi dth of the wi ndow i s i nversel y
rel ated to the val ue of ; a l arger val ue of produces a narrower wi ndow. I f
i s omi tted, i t defaul ts to 2.5.
Note I f the wi ndow appears to be cl i pped, i ncrease the number of poi nts (n)
used for gausswin(n) .
Example N=64;
w = gausswin(N);
plot(w); axis([1 N 0 1]);
title('64-point Gaussian window');
w k 1 + e
1
2
---
k
N
2
----
N 2
--------------
,


_
2
=
0 k N 2
gausswin
7-223
Note The shape of thi s wi ndow i s si mi l ar i n the frequency domai n because
the Fouri er transform of a Gaussi an i s al so a Gaussi an.
See Also barthannwin, bartlett, blackman, blackmanharris, bohmanwin, chebwin,
hann, hamming, kaiser, nuttallwin, rectwin, triang, tukeywin, window
References [1] harri s, f.j. On the Use of Wi ndows for Harmoni c Anal ysi s wi th the Di screte
Fouri er Transform. Proceedings of the I EEE. Vol . 66, No. 1 (January 1978).
[2] Roberts, Ri chard A., and C.T. Mul l i s. Digital Signal Processing. Readi ng,
MA: Addi son-Wesl ey, 1987, pp. 135-136.
10 20 30 40 50 60
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
64point Gaussian window
gmonopuls
7-224
7gmonopul s
Purpose Generate a Gaussi an monopul se
Syntax y = gmonopuls(t,fc)
tc = gmonopuls('cutoff',fc)
Description y = gmonopuls(t,fc) returns sampl es of the uni ty-ampl i tude Gaussi an
monopul se wi th center frequency fc (i n hertz) at the ti mes i ndi cated i n array t.
By defaul t, fc = 1000 Hz.
tc = gmonopuls('cutoff',fc) returns the ti me durati on between the
maxi mum and mi ni mum ampl i tudes of the pul se.
Remarks Defaul t val ues are substi tuted for empty or omi tted trai l i ng i nput arguments.
Examples Ex a mple 1
Pl ot a 2 GHz Gaussi an monopul se sampl ed at a rate of 100 GHz.
fc = 2E9; fs=100E9;
tc = gmonopuls('cutoff',fc);
t = -2*tc : 1/fs : 2*tc;
y = gmonopuls(t,fc); plot(t,y)
4 3 2 1 0 1 2 3 4
x 10
10
1
0.8
0.6
0.4
0.2
0
0.2
0.4
0.6
0.8
1
gmonopuls
7-225
Ex a mple 2
Construct a pul se trai n from the monopul se of Exampl e 1 usi ng a spaci ng of
7.5 ns.
fc = 2E9; fs=100E9; % center freq, sample freq
D = [2.5 10 17.5]' * 1e-9; % pulse delay times
tc = gmonopuls('cutoff',fc); % width of each pulse
t = 0 : 1/fs : 150*tc; % signal evaluation time
yp = pulstran(t,D,@gmonopuls,fc);
plot(t,yp)
See Also chirp, gauspuls, pulstran, rectpuls, tripuls
0 0.5 1 1.5 2 2.5
x 10
8
1
0.8
0.6
0.4
0.2
0
0.2
0.4
0.6
0.8
1
goertzel
7-226
7goertzel
Purpose Compute the DFT usi ng the second-order Goertzel al gori thm
Syntax y = goertzel(x,i)
y = goertzel(x,i,dim)
Description goertzel computes the di screte Fouri er transform (DFT) of speci fi c i ndi ces i n
a vector or matri x.
y = goertzel(x,i) returns the DFT of vector x at the i ndi ces i n vector i,
computed usi ng the second-order Goertzel al gori thm. I f x i s a matri x, goertzel
computes each col umn separatel y. The i ndi ces i n vector i must be i nteger
val ues from 1 to N, where N i s the l ength of the fi rst matri x di mensi on of x that
i s greater than 1. The resul ti ng y has the same di mensi ons as x. I f i i s omi tted,
i t i s assumed to be [1:N], whi ch resul ts i n a ful l DFT computati on.
y = goertzel(x,i,dim) returns the di screte Fouri er transform (DFT) of
matri x x at the i ndi ces i n vector i, computed al ong the di mensi on dim of x.
Note fft computes al l DFT val ues at al l i ndi ces, whi l e goertzel computes
DFT val ues at a speci fi ed subset of i ndi ces (i .e., a porti on of the si gnal s
frequency range). I f l ess than l og
2
(N) poi nts are requi red, goertzel i s more
effi ci ent than the Fast Fouri er Transform (fft).
Two exampl es where goertzel can be useful are spectral anal ysi s of very l arge
si gnal s and dual -tone mul ti frequency (DTMF) si gnal detecti on.
Example Generate an 8-Hz si nusoi d and use the Goertzel al gori thm to detect i t usi ng the
fi rst 20 i ndi ces.
Fs = 1024;
Ts = 1/Fs;
f = 8;
N = 1024;
t = Ts*(0:N-1)';
x = sin(2*pi*f*t); % Generate 8 Hz sinusoid
figure(1);
plot(t,x);
goertzel
7-227
figure(2);
periodogram(x,[],[],Fs); % Use periodogram to obtain the PSD
% (computed with all N points of signal)
vec = 1:20;
X = goertzel(x,vec); % Now use Goertzel to obtain the PSD
0 0.2 0.4 0.6 0.8 1
1
0.8
0.6
0.4
0.2
0
0.2
0.4
0.6
0.8
1
8 Hz Sinusoidal Signal
0 100 200 300 400 500
400
350
300
250
200
150
100
50
0
Frequency (Hz)
P
o
w
e
r

S
p
e
c
t
r
a
l

D
e
n
s
i
t
y

(
d
B
/
H
z
)
Using Periodogram to Detect the 8 Hz Signal
goertzel
7-228
figure(3); % only in the region of interest
plot(vec-1,20*log10(abs(X)));
Algorithm goertzel i mpl ements thi s transfer functi on
where N i s the l ength of the si gnal and k i s the i ndex of the computed DFT. k
i s rel ated to the i ndi ces i n vector i above as k = i - 1.
The si gnal fl ow graph for thi s transfer functi on i s
0 5 10 15 20
250
200
150
100
50
0
50
100
Using Goertzel to Detect the 8 Hz Signal
H
k
z ( )
1 W
N
k
z
1

1 2
2
N
------k
,
_
z
1
z
2
+ cos
-------------------------------------------------------------- =
goertzel
7-229
and i t i s i mpl emented as
where and
To compute X[k] for a parti cul ar k, the Goertzel al gori thm requi res 4N real
mul ti pl i cati ons and 4N real addi ti ons. Al though thi s i s l ess effi ci ent than
computi ng the DFT by the di rect method, Goertzel uses recursi on to compute
and
whi ch are eval uated onl y at n = N. The di rect DFT does not use recursi on and
must compute each compl ex term separatel y.
See Also fft, fft2
v
k
n [ ] x n [ ] 2
2k
N
----------
,
_
v
k
n 1 [ ] v
k
n 2 [ ] cos + =
0 n N
X k [ ] y
k
N [ ] v
k
N [ ] W
N
k
v
k
N 1 [ ] = =
W
N
k 2k
N
----------
,
_
cos
goertzel
7-230
References [1] Burrus, C.S. and T.W. Parks. DFT/ FFT and Convolution Algorithms. John
Wi l ey & Sons, 1985, pp. 32-26.
[2] Mi tra, Sanji t K. Digital Signal Processing: A Computer-Based Approach.
New York, NY: McGraw-Hi l l , 1998, pp. 520-523.
grpdelay
7-231
7grpdel ay
Purpose Compute the average fi l ter del ay (group del ay)
Syntax [gd,w] = grpdelay(b,a,l)
[gd,f] = grpdelay(b,a,l,fs)
[gd,w] = grpdelay(b,a,l,'whole')
[gd,f] = grpdelay(b,a,l,'whole',fs)
gd = grpdelay(b,a,w)
gd = grpdelay(b,a,f,fs)
grpdelay(b,a)
Description The group delay of a fi l ter i s a measure of the average del ay of the fi l ter as a
functi on of frequency. I t i s the negati ve fi rst deri vati ve of the phase response
of the fi l ter. I f the compl ex frequency response of a fi l ter i s , then the
group del ay i s
where i s frequency and i s the phase angl e of .
[gd,w] = grpdelay(b,a,l) returns the i-poi nt group del ay, , of the
di gi tal fi l ter
gi ven the numerator and denomi nator coeffi ci ents i n vectors b and a. grpdelay
returns both gd, the group del ay, and w, a vector contai ni ng the l frequency
poi nts i n radi ans. grpdelay eval uates the group del ay at l poi nts equal l y
spaced around the upper hal f of the uni t ci rcl e, so w contai ns l poi nts between
0 and .
[gd,f] = grpdelay(b,a,l,fs) speci fi es a posi ti ve sampl i ng frequency fs i n
hertz. I t returns a l ength l vector f contai ni ng the actual frequency poi nts at
whi ch the group del ay i s cal cul ated, al so i n hertz. f contai ns l poi nts between
0 and fs/2.
H e
j
( )

g
( )
d ( )
d
--------------- =
H e
j
( )

g
( )
H z ( )
B z ( )
A z ( )
-----------
b 1 ( ) b 2 ( )z
1
L b n 1 + ( )z
n
+ + +
a 1 ( ) a 2 ( )z
1
L a m 1 + ( )z
m
+ + +
---------------------------------------------------------------------------------------- = =
grpdelay
7-232
[gd,w] = grpdelay(b,a,l,'whole') and
[gd,f] = grpdelay(b,a,l,'whole',fs) use n poi nts around the whol e uni t
ci rcl e (from 0 to 2, or from 0 to fs).
gd = grpdelay(b,a,w) and
gd = grpdelay(b,a,f,fs) return the group del ay eval uated at the poi nts i n w
(i n radi ans) or f (i n hertz), respecti vel y, where fs i s the sampl i ng frequency i n
hertz.
grpdelay wi th no output arguments pl ots the group del ay versus frequency i n
the current fi gure wi ndow.
grpdelay works for both real and compl ex i nput systems.
Examples Pl ot the group del ay of Butterworth fi l ter b(z)/a(z).
[b,a] = butter(6,0.2);
grpdelay(b,a,128)
0 0.2 0.4 0.6 0.8 1
0
2
4
6
8
10
12
Normalized Frequency ( rad/sample)
G
r
o
u
p

d
e
l
a
y

(
s
a
m
p
l
e
s
)
grpdelay
7-233
Pl ot both the group and phase del ays of a system on the same graph.
gd = grpdelay(b,a,512);
gd(1) = []; % Avoid NaNs
[h,w] = freqz(b,a,512); h(1) = []; w(1) = [];
pd = -unwrap(angle(h))./w;
plot(w,gd,w,pd,':')
xlabel('Frequency (rad/sec)'); grid;
legend('Group Delay','Phase Delay');
Algorithm grpdelay mul ti pl i es the fi l ter coeffi ci ents by a uni t ramp. After Fouri er
transformati on, thi s process corresponds to di fferenti ati on.
See Also cceps, fft, freqz, hilbert, icceps, rceps
0 0.5 1 1.5 2 2.5 3 3.5
6
4
2
0
2
4
6
8
10
12
Frequency (rad/sec)
Group Delay
Phase Delay
hamming
7-234
7hammi ng
Purpose Compute a Hammi ng wi ndow
Syntax w = hamming(n)
w = hamming(n,'sflag')
Description w = hamming(n) returns an n-poi nt symmetri c Hammi ng wi ndow i n the
col umn vector w. n shoul d be a posi ti ve i nteger. The coeffi ci ents of a Hammi ng
wi ndow are computed from the fol l owi ng equati on.
w = hamming(n,'sflag') returns an n-poi nt Hammi ng wi ndow usi ng the
wi ndow sampl i ng speci fi ed by 'sflag', whi ch can be ei ther 'periodic' or
'symmetric' (the defaul t). When 'periodic' i s speci fi ed, hamming computes a
l ength n+1 wi ndow and returns the fi rst n poi nts.
Note I f you speci fy a one-poi nt wi ndow (n=1), the val ue 1 i s returned.
Examples N=64;
w = hamming(N);
plot(w); axis([1 N 0 1]);
title('Hamming Window')
w k 1 + [ ] 0.54 0.46 2
k
n 1
-------------
,
_
cos k 0 = n 1 , , , =
hamming
7-235
See Also barthannwin, bartlett, blackman, blackmanharris, bohmanwin, chebwin,
gausswin, hann, kaiser, nuttallwin, rectwin, triang, tukeywin, window
References [1] Oppenhei m, A.V., and R.W. Schafer, Discrete-Time Signal Processing,
Prenti ce-Hal l , 1989, pp. 447-448.
10 20 30 40 50 60
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
Hamming Window
hann
7-236
7hann
Purpose Compute a Hann (Hanni ng) wi ndow
Syntax w = hann(n)
w = hann(n,'sflag')
Description w = hann(n) returns an n-poi nt symmetri c Hann wi ndow i n the col umn
vector w. n must be a posi ti ve i nteger. The coeffi ci ents of a Hann wi ndow are
computed from the fol l owi ng equati on.
w = hann(n,'sflag') returns an n-poi nt Hann wi ndow usi ng the wi ndow
sampl i ng speci fi ed by 'sflag', whi ch can be ei ther 'periodic' or
'symmetric' (the defaul t). When 'periodic' i s speci fi ed, hann computes a
l ength n+1 wi ndow and returns the fi rst n poi nts.
Note I f you speci fy a one-poi nt wi ndow (n=1), the val ue 1 i s returned.
Examples N=64;
w = hann(N);
plot(w); axis([1 N 0 1]);
title('Hann Window')
w k 1 + [ ] 0.5 1 2
k
n 1
-------------
,
_
cos
,
_
k 0 = n 1 , , , =
hann
7-237
See Also barthannwin, bartlett, blackman, blackmanharris, bohmanwin, chebwin,
gausswin, hamming, kaiser, nuttallwin, rectwin, triang, tukeywin, window
References [1] Oppenhei m, A.V., and R.W. Schafer, Discrete-Time Signal Processing,
Prenti ce-Hal l , 1989, pp. 447-448.
10 20 30 40 50 60
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
Hann Window
hilbert
7-238
7hi l bert
Purpose Compute the di screte-ti me anal yti c si gnal usi ng the Hi l bert transform
Syntax x = hilbert(xr)
x = hilbert(xr,n)
Description x = hilbert(xr) returns a compl ex hel i cal sequence, someti mes cal l ed the
analytic signal, from a real data sequence. The anal yti c si gnal x = xr + i*xi
has a real part, xr, whi ch i s the ori gi nal data, and an i magi nary part, xi, whi ch
contai ns the Hi l bert transform. The i magi nary part i s a versi on of the ori gi nal
real sequence wi th a 90 phase shi ft. Si nes are therefore transformed to cosi nes
and vi ce versa. The Hi l bert transformed seri es has the same ampl i tude and
frequency content as the ori gi nal real data and i ncl udes phase i nformati on that
depends on the phase of the ori gi nal data.
I f xr i s a matri x, x = hilbert(xr) operates col umnwi se on the matri x, fi ndi ng
the Hi l bert transform of each col umn.
x = hilbert(xr,n) uses an n poi nt FFT to compute the Hi l bert transform.
The i nput data xr i s zero-padded or truncated to l ength n, as appropri ate.
The Hi l bert transform i s useful i n cal cul ati ng i nstantaneous attri butes of a
ti me seri es, especi al l y the ampl i tude and frequency. The i nstantaneous
ampl i tude i s the ampl i tude of the compl ex Hi l bert transform; the
i nstantaneous frequency i s the ti me rate of change of the i nstantaneous phase
angl e. For a pure si nusoi d, the i nstantaneous ampl i tude and frequency are
constant. The i nstantaneous phase, however, i s a sawtooth, refl ecti ng the way
i n whi ch the l ocal phase angl e vari es l i nearl y over a si ngl e cycl e. For mi xtures
of si nusoi ds, the attri butes are short term, or l ocal , averages spanni ng no more
than two or three poi nts.
Reference [1] descri bes the Kol mogorov method for mi ni mum phase
reconstructi on, whi ch i nvol ves taki ng the Hi l bert transform of the l ogari thm of
the spectral densi ty of a ti me seri es. The tool box functi on rceps performs thi s
reconstructi on.
For a di screte-ti me anal yti c si gnal x, the l ast hal f of fft(x) i s zero, and the
fi rst (DC) and center (Nyqui st) el ements of fft(x) are purel y real .
Example xr = [1 2 3 4];
x = hilbert(xr)
hilbert
7-239
x =
1.0000+1.0000i 2.0000-1.0000i 3.0000-1.0000i 4.0000+1.0000i
You can see that the i magi nary part, imag(x) = [1 -1 -1 1], i s the Hi l bert
transform of xr, and the real part, real(x) = [1 2 3 4], i s si mpl y xr i tsel f.
Note that the l ast hal f of fft(x) = [10 -4+4i -2 0] i s zero (i n thi s exampl e,
the l ast hal f i s just the l ast el ement), and that the DC and Nyqui st el ements of
fft(x), 10 and -2 respecti vel y, are purel y real .
hilbert
7-240
Algorithm The anal yti c si gnal for a sequence x has a one-sided Fourier transform, that i s,
negati ve frequenci es are 0. To approxi mate the anal yti c si gnal , hilbert
cal cul ates the FFT of the i nput sequence, repl aces those FFT coeffi ci ents that
correspond to negati ve frequenci es wi th zeros, and cal cul ates the i nverse FFT
of the resul t.
I n detai l , hilbert uses a four-step al gori thm:
1 I t cal cul ates the FFT of the i nput sequence, stori ng the resul t i n a vector x.
2 I t creates a vector h whose el ements h(i) have the val ues:
- 1 for i = 1, (n/2)+1
- 2 for i = 2, 3, ... , (n/2)
- 0 for i = (n/2)+2, ... , n
3 I t cal cul ates the el ement-wi se product of x and h.
4 I t cal cul ates the i nverse FFT of the sequence obtai ned i n step 3 and returns
the fi rst n el ements of the resul t.
I f the i nput data xr i s a matri x, hilbert operates i n a si mi l ar manner,
extendi ng each step above to handl e the matri x case.
See Also fft, ifft, rceps
hilbert
7-241
References [1] Cl aerbout, J.F., Fundamentals of Geophysical Data Processing,
McGraw-Hi l l , 1976, pp. 59-62.
[2] Marpl e, S.L., Computi ng the di screte-ti me anal yti c si gnal vi a FFT, I EEE
Transactions on Signal Processing, Vol . 47, No. 9 (September 1999),
pp. 2600-2603.
[3] Oppenhei m, A.V., and R.W. Schafer, Discrete-Time Signal Processing,
2nd ed., Prenti ce-Hal l , 1998.
icceps
7-242
7i cceps
Purpose I nverse compl ex cepstrum
Syntax x = icceps(xhat,nd)
Description x = icceps(xhat,nd) returns the i nverse compl ex cepstrum of the (assumed
real ) sequence xhat, removi ng nd sampl es of del ay. I f xhat was obtai ned wi th
cceps(x), then the amount of del ay that was added to x was the el ement of
round(unwrap(angle(fft(x)))/pi) correspondi ng to radi ans.
See Also cceps, hilbert, rceps, unwrap
References [1] Oppenhei m, A.V., and R.W. Schafer, Discrete-Time Signal Processing,
Prenti ce-Hal l , 1989.
idct
7-243
7i dct
Purpose I nverse di screte cosi ne transform
Syntax x = idct(y)
x = idct(y,n)
Description The i nverse di screte cosi ne transform reconstructs a sequence from i ts di screte
cosi ne transform (DCT) coeffi ci ents. The idct functi on i s the i nverse of the dct
functi on.
x = idct(y) returns the i nverse di screte cosi ne transform of y
where
and N = length(x), whi ch i s the same as length(y). The seri es i s i ndexed
from n = 1 and k = 1 i nstead of the usual n = 0 and k = 0 because MATLAB
vectors run from 1 to N i nstead of from 0 to N-1.
x = idct(y,n) appends zeros or truncates the vector y to l ength n before
transformi ng.
I f y i s a matri x, idct transforms i ts col umns.
See Also dct, dct2, idct2, ifft
References [1] Jai n, A.K., Fundamentals of Digital I mage Processing, Prenti ce-Hal l , 1989.
[2] Pennebaker, W.B., and J.L. Mi tchel l , J PEG Still I mage Data Compression
Standard, Van Nostrand Rei nhol d, 1993, Chapter 4.
x n ( ) w k ( )y k ( )
2n 1 ( ) k 1 ( )
2N
------------------------------------------- cos
k 1 =
N

n 1 N , , = , =
w k ( )
1
N
--------- k 1 = ,
2
N
---- 2 k N ,

'

=
ifft
7-244
7i fft
Purpose One-di mensi onal i nverse fast Fouri er transform
Syntax y = ifft(x)
y = ifft(x,n)
Description ifft computes the i nverse Fouri er transform of a vector or array. Thi s functi on
i mpl ements the i nverse transform gi ven by
where W
N
= e
-j(2/N)
and N = length(x). Note that the seri es i s i ndexed as
n + 1 and k + 1 i nstead of the usual n and k because MATLAB vectors run from
1 to N i nstead of from 0 to N-1.
y = ifft(x) i s the i nverse Fouri er transform of vector x. I f x i s an array, y i s
the i nverse FFT of each col umn of the matri x.
y = ifft(x,n) i s the n-poi nt i nverse FFT. I f the l ength of x i s l ess than n, ifft
pads x wi th trai l i ng zeros to l ength n. I f the l ength of x i s greater than n, ifft
truncates the sequence x. When x i s an array, ifft adjusts the l ength of the
col umns i n the same manner.
The ifft functi on i s part of the standard MATLAB l anguage.
Algorithm The ifft functi on i s an M-fi l e. The al gori thm for ifft i s the same as that for
fft, except for a si gn change and a scal e factor of n = length(x). The executi on
ti me i s fastest when n i s a power of two and sl owest when n i s a l arge pri me.
See Also fft, fft2, fftshift, ifft2
x n 1 + ( )
1
N
---- X k 1 + ( )W
n
kn
k 0 =
N 1

=
ifft2
7-245
7i fft2
Purpose Two-di mensi onal i nverse fast Fouri er transform
Syntax Y = ifft2(X)
Y = ifft2(X,m,n)
Description Y = ifft2(X) returns the two-di mensi onal i nverse fast Fouri er transform
(FFT) of the array X. I f X i s a vector, Y has the same ori entati on as X.
Y = ifft2(X,m,n) truncates or zero pads X, i f necessary, to create an m-by-n
array before performi ng the i nverse FFT. The resul t Y i s al so m-by-n.
For any X, ifft2(fft2(X)) equal s X to wi thi n roundoff error. I f X i s real ,
ifft2(fft2(X)) may have smal l i magi nary parts.
The ifft2 functi on i s part of the standard MATLAB l anguage.
Algorithm The al gori thm for ifft2 i s the same as that for fft2, except for a si gn change
and scal e factors of [m n] = size(X). The executi on ti me i s fastest when m
and n are powers of two and sl owest when they are l arge pri mes.
See Also fft, fft2, fftn, fftshift, ifft, ifftn
impinvar
7-246
7i mpi nvar
Purpose I mpul se i nvari ance method for anal og-to-di gi tal fi l ter conversi on
Syntax [bz,az] = impinvar(b,a,fs)
[bz,az] = impinvar(b,a)
[bz,az] = impinvar(b,a,fs,tol)
Description [bz,az] = impinvar(b,a,fs) creates a di gi tal fi l ter wi th numerator and
denomi nator coeffi ci ents bz and az, respecti vel y, whose i mpul se response i s
equal to the i mpul se response of the anal og fi l ter wi th coeffi ci ents b and a,
scal ed by 1/fs. I f you l eave out the argument fs, or speci fy fs as the empty
vector [], i t takes the defaul t val ue of 1 Hz.
[bz,az] = impinvar(b,a,fs,tol) uses the tol erance speci fi ed by tol to
determi ne whether pol es are repeated. A l arger tol erance i ncreases the
l i kel i hood that impinvar i nterprets cl osel y l ocated pol es as mul ti pl i ci ti es
(repeated ones). The defaul t i s 0.001, or 0.1% of a pol es magni tude. Note that
the accuracy of the pol e val ues i s sti l l l i mi ted to the accuracy obtai nabl e by the
roots functi on.
Examples Convert an anal og l owpass fi l ter to a di gi tal fi l ter usi ng impinvar wi th a
sampl i ng frequency of 10 Hz.
[b,a] = butter(4,0.3,'s');
[bz,az] = impinvar(b,a,10)
bz =
1.0e-006 *
-0.0000 0.1324 0.5192 0.1273 0
az =
1.0000 -3.9216 5.7679 -3.7709 0.9246
impinvar
7-247
Algorithm impinvar performs the i mpul se-i nvari ant method of anal og-to-di gi tal transfer
functi on conversi on di scussed i n reference [1]:
1 I t fi nds the parti al fracti on expansi on of the system represented by b and a.
2 I t repl aces the pol es p by the pol es exp(p/fs).
3 I t fi nds the transfer functi on coeffi ci ents of the system from the resi dues
from step 1 and the pol es from step 2.
See Also bilinear, lp2bp, lp2bs, lp2hp, lp2lp
References [1] Parks, T.W., and C.S. Burrus, Digital Filter Design, John Wi l ey & Sons,
1987, pp. 206-209.
impz
7-248
7i mpz
Purpose Compute the i mpul se response of di gi tal fi l ters
Syntax [h,t] = impz(b,a)
[h,t] = impz(b,a,n)
[h,t] = impz(b,a,n,fs)
impz(b,a)
impz(...)
Description [h,t] = impz(b,a) computes the i mpul se response of the fi l ter wi th
numerator coeffi ci ents b and denomi nator coeffi ci ents a. impz chooses the
number of sampl es and returns the response i n the col umn vector h and sampl e
ti mes i n the col umn vector t (where t = [0:n-1]', and n = length(t) i s
computed automati cal l y).
[h,t] = impz(b,a,n) computes n sampl es of the i mpul se response when n i s
an i nteger (t = [0:n-1]'). I f n i s a vector of i ntegers, impz computes the
i mpul se response at those i nteger l ocati ons, starti ng the response computati on
from 0 (and t = n or t = [0 n]). I f, i nstead of n, you i ncl ude the empty vector []
for the second argument, the number of sampl es i s computed automati cal l y by
defaul t.
[h,t] = impz(b,a,n,fs) computes n sampl es and produces a vector t of
l ength n so that the sampl es are spaced 1/fs uni ts apart.
impz wi th no output arguments pl ots the i mpul se response i n the current
fi gure wi ndow usi ng stem(t,h).
impz works for both real and compl ex i nput systems.
Examples Pl ot the fi rst 50 sampl es of the i mpul se response of a fourth-order l owpass
el l i pti c fi l ter wi th cutoff frequency of 0.4 ti mes the Nyqui st frequency.
[b,a] = ellip(4,0.5,20,0.4);
impz(b,a,50)
impz
7-249
Algorithm impz fi l ters a l ength n i mpul se sequence usi ng
filter(b,a,[1 zeros(1,n-1)])
and pl ots the resul ts usi ng stem.
To compute n i n the auto-l ength case, impz ei ther uses n = length(b) for the
FI R case or fi rst fi nds the pol es usi ng p = roots(a), i f length(a) i s greater
than 1.
I f the fi l ter i s unstabl e, n i s chosen to be the poi nt at whi ch the term from the
l argest pol e reaches 10^6 ti mes i ts ori gi nal val ue.
I f the fi l ter i s stabl e, n i s chosen to be the poi nt at whi ch the term due to the
l argest ampl i tude pol e i s 5*10^-5 of i ts ori gi nal ampl i tude.
I f the fi l ter i s osci l l atory (pol es on the uni t ci rcl e onl y), impz computes fi ve
peri ods of the sl owest osci l l ati on.
I f the fi l ter has both osci l l atory and damped terms, n i s chosen to equal fi ve
peri ods of the sl owest osci l l ati on or the poi nt at whi ch the term due to the
l argest (nonuni ty) ampl i tude pol e i s 5*10^-5 of i ts ori gi nal ampl i tude,
whi chever i s greater.
0 5 10 15 20 25 30 35 40 45
-0.2
-0.1
0
0.1
0.2
0.3
0.4
0.5
impz
7-250
impz al so al l ows for del ays i n the numerator pol ynomi al . The number of del ays
i s i ncorporated i nto the computati on for the number of sampl es.
See Also impulse, stem
interp
7-251
7i nterp
Purpose I ncrease sampl i ng rate by an i nteger factor (i nterpol ati on)
Syntax y = interp(x,r)
y = interp(x,r,l,alpha)
[y,b] = interp(x,r,l,alpha)
Description I nterpol ati on i ncreases the ori gi nal sampl i ng rate for a sequence to a hi gher
rate. interp performs l owpass i nterpol ati on by i nserti ng zeros i nto the ori gi nal
sequence and then appl yi ng a speci al l owpass fi l ter.
y = interp(x,r) i ncreases the sampl i ng rate of x by a factor of r. The
i nterpol ated vector y i s r ti mes l onger than the ori gi nal i nput x.
y = interp(x,r,l,alpha) speci fi es l (fi l ter l ength) and alpha (cut-off
frequency). The defaul t val ue for l i s 4 and the defaul t val ue for alpha i s 0.5.
[y,b] = interp(x,r,l,alpha) returns vector b contai ni ng the fi l ter
coeffi ci ents used for the i nterpol ati on.
Examples I nterpol ate a si gnal by a factor of four.
t = 0:0.001:1; % Time vector
x = sin(2*pi*30*t) + sin(2*pi*60*t);
y = interp(x,4);
stem(x(1:30));
title('Original Signal');
figure
stem(y(1:120));
title('Interpolated Signal');
interp
7-252
Algorithm interp uses the l owpass i nterpol ati on Al gori thm 8.1 descri bed i n [1]:
1 I t expands the i nput vector to the correct l ength by i nserti ng zeros between
the ori gi nal data val ues.
2 I t desi gns a speci al symmetri c FI R fi l ter that al l ows the ori gi nal data to pass
through unchanged and i nterpol ates between so that the mean-square
errors between the i nterpol ated poi nts and thei r i deal val ues are mi ni mi zed.
3 I t appl i es the fi l ter to the i nput vector to produce the i nterpol ated output
vector.
The l ength of the FI R l owpass i nterpol ati ng fi l ter i s 2*l*r+1. The number of
ori gi nal sampl e val ues used for i nterpol ati on i s 2*l. Ordi nari l y, l shoul d be
l ess than or equal to 10. The ori gi nal si gnal i s assumed to be band l i mi ted wi th
normal i zed cutoff frequency 0 alpha 1, where 1 i s hal f the ori gi nal sampl i ng
frequency (the Nyqui st frequency). The defaul t val ue for l i s 4 and the defaul t
val ue for alpha i s 0.5.
Diagnostics I f r i s not an i nteger, interp gi ves the fol l owi ng error message.
Resampling rate R must be an integer.
See Also decimate, downsample, interp1, resample, spline, upfirdn, upsample
References [1] Programs for Digital Signal Processing, I EEE Press, New York, 1979,
Al gori thm 8.1.
0 20 40 60 80 100 120
-2
-1.5
-1
-0.5
0
0.5
1
1.5
2
Interpolated Signal
0 5 10 15 20 25 30
-2
-1.5
-1
-0.5
0
0.5
1
1.5
2
Original Signal
intfilt
7-253
7i ntfi l t
Purpose I nterpol ati on FI R fi l ter desi gn
Syntax b = intfilt(r,l,alpha)
b = intfilt(r,n,'Lagrange')
Description b = intfilt(r,l,alpha) desi gns a l i near phase FI R fi l ter that performs i deal
bandl i mi ted i nterpol ati on usi ng the nearest 2*l nonzero sampl es, when used
on a sequence i nterl eaved wi th r-1 consecuti ve zeros every r sampl es. I t
assumes an ori gi nal bandl i mi tedness of alpha ti mes the Nyqui st frequency.
The returned fi l ter i s i denti cal to that used by interp.
b = intfilt(r,n,'Lagrange') or
b = intfilt(r,n,'l') desi gns an FI R fi l ter that performs nth-order
Lagrange pol ynomi al i nterpol ati on on a sequence i nterl eaved wi th r-1
consecuti ve zeros every r sampl es. b has l ength (n + 1)*r for n even, and l ength
(n + 1)*r-1 for n odd.
Both types of fi l ters are basi cal l y l owpass and are i ntended for i nterpol ati on
and deci mati on.
Examples Desi gn a di gi tal i nterpol ati on fi l ter to upsampl e a si gnal by four, usi ng the
bandl i mi ted method.
alpha = 0.5; % "Bandlimitedness" factor
h1 = intfilt(4,2,alpha); % Bandlimited interpolation
The fi l ter h1 works best when the ori gi nal si gnal i s bandl i mi ted to alpha ti mes
the Nyqui st frequency. Create a bandl i mi ted noi se si gnal .
randn('state',0)
x = filter(fir1(40,0.5),1,randn(200,1)); % Bandlimit
Now zero pad the si gnal wi th three zeros between every sampl e. The resul ti ng
sequence i s four ti mes the l ength of x.
xr = reshape([x zeros(length(x),3)]',4*length(x),1);
I nterpol ate usi ng the filter command.
y = filter(h1,1,xr);
intfilt
7-254
y i s an i nterpol ated versi on of x, del ayed by seven sampl es (the group-del ay of
the fi l ter). Zoom i n on a secti on to see thi s.
plot(100:200,y(100:200),7+(101:4:196),x(26:49),'o')
intfilt al so performs Lagrange pol ynomi al i nterpol ati on of the ori gi nal
si gnal . For exampl e, fi rst-order pol ynomi al i nterpol ati on i s just l i near
i nterpol ati on, whi ch i s accompl i shed wi th a tri angul ar fi l ter.
h2 = intfilt(4,1,'l') % Lagrange interpolation
h2 =
0.2500 0.5000 0.7500 1.0000 0.7500 0.5000 0.2500
Algorithm The bandl i mi ted method uses firls to desi gn an i nterpol ati on FI R equi val ent
to that presented i n [1]. The pol ynomi al method uses Lagranges pol ynomi al
i nterpol ati on formul a on equal l y spaced sampl es to construct the appropri ate
fi l ter.
See Also decimate, downsample, interp, resample, upsample
References [1] Oetken, Parks, and Schl er, New Resul ts i n the Desi gn of Di gi tal
I nterpol ators, I EEE Trans. Acoust., Speech, Signal Processing, Vol . ASSP-23
(June 1975), pp. 301-309.
100 110 120 130 140 150 160 170 180 190 200
1.2
1
0.8
0.6
0.4
0.2
0
0.2
0.4
0.6
0.8
invfreqs
7-255
7i nvfreqs
Purpose I denti fy conti nuous-ti me fi l ter parameters from frequency response data
Syntax [b,a] = invfreqs(h,w,n,m)
[b,a] = invfreqs(h,w,n,m,wt)
[b,a] = invfreqs(h,w,n,m,wt,iter)
[b,a] = invfreqs(h,w,n,m,wt,iter,tol)
[b,a] = invfreqs(h,w,n,m,wt,iter,tol,'trace')
[b,a] = invfreqs(h,w,'complex',n,m,...)
Description invfreqs i s the i nverse operati on of freqs. I t fi nds a conti nuous-ti me transfer
functi on that corresponds to a gi ven compl ex frequency response. From a
l aboratory anal ysi s standpoi nt, invfreqs i s useful i n converti ng magni tude
and phase data i nto transfer functi ons.
[b,a] = invfreqs(h,w,n,m) returns the real numerator and denomi nator
coeffi ci ent vectors b and a of the transfer functi on
whose compl ex frequency response i s gi ven i n vector h at the frequency poi nts
speci fi ed i n vector w. Scal ars n and m speci fy the desi red orders of the
numerator and denomi nator pol ynomi al s.
Frequency i s speci fi ed i n radi ans between 0 and , and the l ength of h must be
the same as the l ength of w. invfreqs uses conj(h) at -w to ensure the proper
frequency domai n symmetry for a real fi l ter.
[b,a] = invfreqs(h,w,n,m,wt) wei ghts the fi t-errors versus frequency,
where wt i s a vector of wei ghti ng factors the same l ength as w.
[b,a] = invfreqs(h,w,n,m,wt,iter) and
[b,a] = invfreqs(h,w,n,m,wt,iter,tol) provi de a superi or al gori thm that
guarantees stabi l i ty of the resul ti ng l i near system and searches for the best fi t
usi ng a numeri cal , i terati ve scheme. The iter parameter tel l s invfreqs to end
the i terati on when the sol uti on has converged, or after iter i terati ons,
whi chever comes fi rst. invfreqs defi nes convergence as occurri ng when the
norm of the (modi fi ed) gradi ent vector i s l ess than tol, where tol i s an opti onal
parameter that defaul ts to 0.01. To obtai n a wei ght vector of al l ones, use
H s ( )
B s ( )
A s ( )
---------- -
b 1 ( )s
n
b 2 ( )s
n 1
L b n 1 + ( ) + + +
a 1 ( )s
m
a 2 ( )s
m 1
L a m 1 + ( ) + + +
------------------------------------------------------------------------------------------ = =
invfreqs
7-256
invfreqs(h,w,n,m,[],iter,tol)
[b,a] = invfreqs(h,w,n,m,wt,iter,tol,'trace') di spl ays a textual
progress report of the i terati on.
[b,a] = invfreqs(h,w,'complex',n,m,...) creates a compl ex fi l ter. I n thi s
case no symmetry i s enforced, and the frequency i s speci fi ed i n radi ans
between - and .
Remarks When bui l di ng hi gher order model s usi ng hi gh frequenci es, i t i s i mportant to
scal e the frequenci es, di vi di ng by a factor such as hal f the hi ghest frequency
present i n w, so as to obtai n wel l condi ti oned val ues of a and b. Thi s corresponds
to a rescal i ng of ti me.
Examples Ex a mple 1
Convert a si mpl e transfer functi on to frequency response data and then back
to the ori gi nal fi l ter coeffi ci ents.
a = [1 2 3 2 1 4]; b = [1 2 3 2 3];
[h,w] = freqs(b,a,64);
[bb,aa] = invfreqs(h,w,4,5)
bb =
1.0000 2.0000 3.0000 2.0000 3.0000
aa =
1.0000 2.0000 3.0000 2.0000 1.0000 4.0000
invfreqs
7-257
Noti ce that bb and aa are equi val ent to b and a, respecti vel y. However, aa has
pol es i n the l eft hal f-pl ane and thus the system i s unstabl e. Use invfreqss
i terati ve al gori thm to fi nd a stabl e approxi mati on to the system.
[bbb,aaa] = invfreqs(h,w,4,5,[],30)
bbb =
0.6816 2.1015 2.6694 0.9113 -0.1218
aaa =
1.0000 3.4676 7.4060 6.2102 2.5413 0.0001
Ex a mple 2
Suppose you have two vectors, mag and phase, that contai n magni tude and
phase data gathered i n a l aboratory, and a thi rd vector w of frequenci es. You
can convert the data i nto a conti nuous-ti me transfer functi on usi ng invfreqs.
[b,a] = invfreqs(mag.*exp(j*phase),w,2,3);
Algorithm By defaul t, invfreqs uses an equati on error method to i denti fy the best model
from the data. Thi s fi nds b and a i n
by creati ng a system of l i near equati ons and sol vi ng them wi th MATLABs \
operator. Here A(w(k)) and B(w(k)) are the Fouri er transforms of the
pol ynomi al s a and b, respecti vel y, at the frequency w(k), and n i s the number
of frequency poi nts (the l ength of h and w). Thi s al gori thm i s based on Levi [1].
Several vari ants have been suggested i n the l i terature, where the wei ghti ng
functi on wt gi ves l ess attenti on to hi gh frequenci es.
mi n
b a ,
wt k ( ) h k ( )A w k ( ) ( ) B w k ( ) ( )
2
k 1 =
n

invfreqs
7-258
The superi or (output-error) al gori thm uses the damped Gauss-Newton method
for i terati ve search [2], wi th the output of the fi rst al gori thm as the i ni ti al
esti mate. Thi s sol ves the di rect probl em of mi ni mi zi ng the wei ghted sum of the
squared error between the actual and the desi red frequency response poi nts.
See Also freqs, freqz, invfreqz, prony
References [1] Levi , E.C., Compl ex-Curve Fi tti ng, I RE Trans. on Automatic Control,
Vol . AC-4 (1959), pp. 37-44.
[2] Denni s, J.E., Jr., and R.B. Schnabel . Numerical Methods for Unconstrained
Optimization and Nonlinear Equations. Engl ewood Cl i ffs, NJ: Prenti ce-Hal l ,
1983.
mi n
b a ,
wt k ( ) h k ( )
B w k ( ) ( )
A w k ( ) ( )
--------------------
2
k 1 =
n

invfreqz
7-259
7i nvfreqz
Purpose I denti fy di screte-ti me fi l ter parameters from frequency response data
Syntax [b,a] = invfreqz(h,w,n,m)
[b,a] = invfreqz(h,w,n,m,wt)
[b,a] = invfreqz(h,w,n,m,wt,iter)
[b,a] = invfreqz(h,w,n,m,wt,iter,tol)
[b,a] = invfreqz(h,w,n,m,wt,iter,tol,'trace')
[b,a] = invfreqz(h,w,'complex',n,m,...)
Description invfreqz i s the i nverse operati on of freqz; i t fi nds a di screte-ti me transfer
functi on that corresponds to a gi ven compl ex frequency response. From a
l aboratory anal ysi s standpoi nt, invfreqz can be used to convert magni tude
and phase data i nto transfer functi ons.
[b,a] = invfreqz(h,w,n,m) returns the real numerator and denomi nator
coeffi ci ents i n vectors b and a of the transfer functi on
whose compl ex frequency response i s gi ven i n vector h at the frequency poi nts
speci fi ed i n vector w. Scal ars n and m speci fy the desi red orders of the
numerator and denomi nator pol ynomi al s.
Frequency i s speci fi ed i n radi ans between 0 and , and the l ength of h must be
the same as the l ength of w. invfreqz uses conj(h) at -w to ensure the proper
frequency domai n symmetry for a real fi l ter.
[b,a] = invfreqz(h,w,n,m,wt) wei ghts the fi t-errors versus frequency,
where wt i s a vector of wei ghti ng factors the same l ength as w.
[b,a] = invfreqz(h,w,n,m,wt,iter) and
[b,a] = invfreqz(h,w,n,m,wt,iter,tol) provi de a superi or al gori thm that
guarantees stabi l i ty of the resul ti ng l i near system and searches for the best fi t
usi ng a numeri cal , i terati ve scheme. The iter parameter tel l s invfreqz to end
the i terati on when the sol uti on has converged, or after iter i terati ons,
whi chever comes fi rst. invfreqz defi nes convergence as occurri ng when the
norm of the (modi fi ed) gradi ent vector i s l ess than tol, where tol i s an opti onal
parameter that defaul ts to 0.01. To obtai n a wei ght vector of al l ones, use
H z ( )
B z ( )
A z ( )
-----------
b 1 ( ) b 2 ( )z
1
L b n 1 + ( )z
n
+ + +
a 1 ( ) a 2 ( )z
1
L a m 1 + ( )z
m
+ + +
---------------------------------------------------------------------------------------- = =
invfreqz
7-260
invfreqz(h,w,n,m,[],iter,tol)
[b,a] = invfreqz(h,w,n,m,wt,iter,tol,'trace') di spl ays a textual
progress report of the i terati on.
[b,a] = invfreqz(h,w,'complex',n,m,...) creates a compl ex fi l ter. I n thi s
case no symmetry i s enforced, and the frequency i s speci fi ed i n radi ans
between - and .
Examples Convert a si mpl e transfer functi on to frequency response data and then back
to the ori gi nal fi l ter coeffi ci ents.
a = [1 2 3 2 1 4]; b = [1 2 3 2 3];
[h,w] = freqz(b,a,64);
[bb,aa] = invfreqz(h,w,4,5)
bb =
1.0000 2.0000 3.0000 2.0000 3.0000
aa =
1.0000 2.0000 3.0000 2.0000 1.0000 4.0000
Noti ce that bb and aa are equi val ent to b and a, respecti vel y. However, aa has
pol es outsi de the uni t ci rcl e and thus the system i s unstabl e. Use invfreqzs
i terati ve al gori thm to fi nd a stabl e approxi mati on to the system.
[bbb,aaa] = invfreqz(h,w,4,5,[],30)
bbb =
0.2427 0.2788 0.0069 0.0971 0.1980
aaa =
1.0000 -0.8944 0.6954 0.9997 -0.8933 0.6949
invfreqz
7-261
Algorithm By defaul t, invfreqz uses an equati on error method to i denti fy the best model
from the data. Thi s fi nds b and a i n
by creati ng a system of l i near equati ons and sol vi ng them wi th MATLABs \
operator. Here A((k)) and B((k)) are the Fouri er transforms of the
pol ynomi al s a and b, respecti vel y, at the frequency (k), and n i s the number
of frequency poi nts (the l ength of h and w). Thi s al gori thm i s a based on Levi [1].
The superi or (output-error) al gori thm uses the damped Gauss-Newton
method for i terati ve search [2], wi th the output of the fi rst al gori thm as the
i ni ti al esti mate. Thi s sol ves the di rect probl em of mi ni mi zi ng the wei ghted sum
of the squared error between the actual and the desi red frequency response
poi nts.
See Also freqs, freqz, invfreqz, prony
References [1] Levi , E.C., Compl ex-Curve Fi tti ng, I RE Trans. on Automatic Control,
Vol . AC-4 (1959), pp. 37-44.
[2] Denni s, J.E., Jr., and R.B. Schnabel , Numerical Methods for Unconstrained
Optimization and Nonlinear Equations, Prenti ce-Hal l , 1983.
mi n
b a ,
wt k ( ) h k ( )A k ( ) ( ) B k ( ) ( )
2
k 1 =
n

mi n
b a ,
wt k ( ) h k ( )
B k ( ) ( )
A k ( ) ( )
-------------------
2
k 1 =
n

is2rc
7-262
7i s2rc
Purpose Convert i nverse si ne parameters to refl ecti on coeffi ci ents
Syntax k = is2rc(isin)
Description k = is2rc(isin) returns a vector of refl ecti on coeffi ci ents k from a vector of
i nverse si ne parameters isin.
Examples isin = [0.2000 0.8727 0.0020 0.0052 -0.0052];
k = is2rc(isin)
k =
0.3090 0.9801 0.0031 0.0082 -0.0082
See Also ac2rc, lar2rc, poly2rc, rc2is
References [1] Del l er, J.R., J.G. Proaki s, and J.H.L. Hansen, Discrete-Time Processing of
Speech Signals, Prenti ce-Hal l , 1993.
kaiser
7-263
7kai ser
Purpose Compute a Kai ser wi ndow
Syntax w = kaiser(n,beta)
Description w = kaiser(n,beta) returns an n-poi nt Kai ser (I
0
si nh) wi ndow i n the
col umn vector w. beta i s the Kai ser wi ndow parameter that affects the
si del obe attenuati on of the Fouri er transform of the wi ndow.
To obtai n a Kai ser wi ndow that desi gns an FI R fi l ter wi th si del obe hei ght
- dB, use the fol l owi ng .
I ncreasi ng beta wi dens the mai n l obe and decreases the ampl i tude of the
si del obes (i ncreases the attenuati on).
Example N=200;
w = kaiser(N,0.5);
plot(w);
title('Kaiser Window, beta = .5')

0.1102 8.7 ( ), 50 >


0.5842 21 ( )
0.4
0.07886 21 ( ) + , 50 21
0, 21 <

'

=
0 20 40 60 80 100 120 140 160 180 200
0.94
0.95
0.96
0.97
0.98
0.99
1
Kaiser Window, beta = .5
kaiser
7-264
See Also barthannwin, bartlett, blackman, blackmanharris, bohmanwin, chebwin,
gausswin, hamming, hann, kaiserord, nuttallwin, rectwin, triang, tukeywin,
window
References [1] Kai ser, J.F., Nonrecursi ve Di gi tal Fi l ter Desi gn Usi ng the - si nh
Wi ndow Functi on, Proc. 1974 I EEE Symp. Circuits and Systems, (Apri l 1974),
pp. 20-23.
[2] Selected Papers in Digital Signal Processing I I , I EEE Press, New York,
1975.
[3] Oppenhei m, A.V., and R.W. Schafer, Discrete-Time Signal Processing,
Prenti ce-Hal l , 1989, p. 453.
I
0
kaiserord
7-265
7kai serord
Purpose Esti mate parameters for an FI R fi l ter desi gn wi th a Kai ser wi ndow
Syntax [n,Wn,beta,ftype] = kaiserord(f,a,dev)
[n,Wn,beta,ftype] = kaiserord(f,a,dev,fs)
c = kaiserord(f,a,dev,fs,'cell')
Description kaiserord returns a fi l ter order n and beta parameter to speci fy a Kai ser
wi ndow for use wi th the fir1 functi on. Gi ven a set of speci fi cati ons i n the
frequency domai n, kaiserord esti mates the mi ni mum FI R fi l ter order that wi l l
approxi matel y meet the speci fi cati ons. kaiserord converts the gi ven fi l ter
speci fi cati ons i nto passband and stopband ri ppl es and converts cutoff
frequenci es i nto the form needed for wi ndowed FI R fi l ter desi gn.
[n,Wn,beta,ftype] = kaiserord(f,a,dev) fi nds the approxi mate order n,
normal i zed frequency band edges Wn, and wei ghts that meet i nput
speci fi cati ons f, a, and dev. f i s a vector of band edges and a i s a vector
speci fyi ng the desi red ampl i tude on the bands defi ned by f. The l ength of f i s
twi ce the l ength of a, mi nus 2. Together, f and a defi ne a desi red pi ecewi se
constant response functi on. dev i s a vector the same si ze as a that speci fi es the
maxi mum al l owabl e error or devi ati on between the frequency response of the
output fi l ter and i ts desi red ampl i tude, for each band. The entri es i n dev
speci fy the passband ri ppl e and the stopband attenuati on. You speci fy each
entry i n dev as a posi ti ve number, representi ng absol ute fi l ter gai n (not i n
deci bel s).
Note I f, i n the vector dev, you speci fy unequal devi ati ons across bands, the
mi ni mum speci fi ed devi ati on i s used, si nce the Kai ser wi ndow method i s
constrai ned to produce fi l ters wi th mi ni mum devi ati on i n al l of the bands.
fir1 can use the resul ti ng order n, frequency vector Wn, mul ti band magni tude
type ftype, and the Kai ser wi ndow parameter beta. The ftype stri ng i s
i ntended for use wi th fir1; i t i s equal to 'high' for a hi ghpass fi l ter and 'stop'
for a bandstop fi l ter. For mul ti band fi l ters, i t can be equal to 'dc-0' when the
fi rst band i s a stopband (starti ng at f = 0) or 'dc-1' when the fi rst band i s a
passband.
kaiserord
7-266
To desi gn an FI R fi l ter b that approxi matel y meets the speci fi cati ons gi ven by
kaiser parameters f, a, and dev, use the fol l owi ng command.
b = fir1(n,Wn,kaiser(n+1,beta),ftype,'noscale')
[n,Wn,beta,ftype] = kaiserord(f,a,dev,fs) uses a sampl i ng frequency fs
i n Hz. I f you dont speci fy the argument fs, or i f you speci fy i t as the empty
vector [], i t defaul ts to 2 Hz, and the Nyqui st frequency i s 1 Hz. You can use
thi s syntax to speci fy band edges scal ed to a parti cul ar appl i cati ons sampl i ng
frequency. The frequency band edges i n f must be from 0 to fs/2.
c = kaiserord(f,a,dev,fs,'cell') i s a cel l -array whose el ements are the
parameters to fir1.
Note I n some cases, kaiserord underesti mates or overesti mates the order n.
I f the fi l ter does not meet the speci fi cati ons, try a hi gher order such as n+1, n+2,
and so on, or a try l ower order.
Resul ts are i naccurate i f the cutoff frequenci es are near 0 or the Nyqui st
frequency, or i f dev i s l arge (greater than 10%).
Remarks Be careful to di sti ngui sh between the meani ngs of fi l ter l ength and fi l ter order.
The fi l ter length i s the number of i mpul se response sampl es i n the FI R fi l ter.
General l y, the i mpul se response i s i ndexed from n = 0 to n = L-1, where L i s the
fi l ter l ength. The fi l ter order i s the hi ghest power i n a z-transform
representati on of the fi l ter. For an FI R transfer functi on, thi s representati on i s
a pol ynomi al i n z, where the hi ghest power i s z
L-1
and the l owest power i s z
0
.
The fi l ter order i s one l ess than the l ength (L-1) and i s al so equal to the number
of zeros of the z pol ynomi al .
Examples Ex a mple 1
Desi gn a l owpass fi l ter wi th passband defi ned from 0 to 1 kHz and stopband
defi ned from 1500 Hz to 4 kHz. Speci fy a passband ri ppl e of 5% and a stopband
attenuati on of 40 dB.
fsamp = 8000;
fcuts = [1000 1500];
mags = [1 0];
kaiserord
7-267
devs = [0.05 0.01];
[n,Wn,beta,ftype] = kaiserord(fcuts,mags,devs,fsamp);
hh = fir1(n,Wn,ftype,kaiser(n+1,beta),'noscale');
freqz(hh)
Ex a mple 2
Desi gn an odd-l ength bandpass fi l ter (note that odd l ength means even order,
so the i nput to fir1 must be an even i nteger).
fsamp = 8000;
fcuts = [1000 1300 2210 2410];
mags = [0 1 0];
devs = [0.01 0.05 0.01];
[n,Wn,beta,ftype] = kaiserord(fcuts,mags,devs,fsamp);
n = n + rem(n,2);
hh = fir1(n,Wn,ftype,kaiser(n+1,beta),'noscale');
[H,f] = freqz(hh,1,1024,fsamp);
plot(f,abs(H)), grid on
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
1400
1200
1000
800
600
400
200
0
Normalized Frequency ( rad/sample)
P
h
a
s
e

(
d
e
g
r
e
e
s
)
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
120
100
80
60
40
20
0
20
Normalized Frequency ( rad/sample)
M
a
g
n
i
t
u
d
e

(
d
B
)
kaiserord
7-268
Ex a mple 3
Desi gn a l owpass fi l ter wi th a passband cutoff of 1500 Hz, a stopband cutoff of
2000 Hz, passband ri ppl e of 0.01, stopband ri ppl e of 0.1, and a sampl i ng
frequency of 8000 Hz.
[n,Wn,beta,ftype] = kaiserord([1500 2000],[1 0],...
[0.01 0.1],8000);
b = fir1(n,Wn,ftype,kaiser(n+1,beta),'noscale');
Thi s i s equi val ent to
c = kaiserord([1500 2000],[1 0],[0.01 0.1],8000,'cell');
b = fir1(c{:});
Algorithm kaiserord uses empi ri cal l y deri ved formul as for esti mati ng the orders of
l owpass fi l ters, as wel l as di fferenti ators and Hi l bert transformers. Esti mates
for mul ti band fi l ters (such as bandpass fi l ters) are deri ved from the l owpass
desi gn formul as.
The desi gn formul as that underl i e the Kai ser wi ndow and i ts appl i cati on to
FI R fi l ter desi gn are
0 500 1000 1500 2000 2500 3000 3500 4000
0
0.2
0.4
0.6
0.8
1
1.2
1.4
kaiserord
7-269
where = -20l og
10
i s the stopband attenuati on expressed i n deci bel s (recal l
that
p
=
s
i s requi red).
The desi gn formul a i s
where n i s the fi l ter order and i s the wi dth of the smal l est transi ti on regi on.
See Also fir1, kaiser, remezord
References [1] Kai ser, J.F., Nonrecursi ve Di gi tal Fi l ter Desi gn Usi ng the - si nh
Wi ndow Functi on, Proc. 1974 I EEE Symp. Circuits and Systems, (Apri l 1974),
pp. 20-23.
[2] Selected Papers in Digital Signal Processing I I , I EEE Press, New York,
1975, pp. 123-126.
[3] Oppenhei m, A.V., and R.W. Schafer, Discrete-Time Signal Processing,
Prenti ce-Hal l , 1989, pp. 458-562.

0.1102 8.7 ( ), 50 >


0.5842 21 ( )
0.4
0.07886 21 ( ) + , 50 21
0, 21 <

'

=
n
7.95
2.285 ( )
---------------------------- =
I
0
lar2rc
7-270
7l ar2rc
Purpose Convert l og area rati o parameters to refl ecti on coeffi ci ents
Syntax k = lar2rc(g)
Description k = lar2rc(g) returns a vector of refl ecti on coeffi ci ents k from a vector of l og
area rati o parameters g.
Examples g = [0.6389 4.5989 0.0063 0.0163 -0.0163];
k = lar2rc(g)
k =
0.3090 0.9801 0.0031 0.0081 -0.0081
See Also ac2rc, is2rc, poly2rc, rc2lar
References [1] Del l er, J.R., J.G. Proaki s, and J.H.L. Hansen, Discrete-Time Processing of
Speech Signals, Prenti ce-Hal l , 1993.
latc2tf
7-271
7l atc2tf
Purpose Convert l atti ce fi l ter parameters to transfer functi on form
Syntax [num,den] = latc2tf(k,v)
[num,den] = latc2tf(k,'iiroption')
num = latc2tf(k,'firoption')
num = latc2tf(k)
Description [num,den] = latc2tf(k,v) fi nds the transfer functi on numerator num and
denomi nator den from the I I R l atti ce coeffi ci ents k and l adder coeffi ci ents v.
[num,den] = latc2tf(k,'iiroption') produces an I I R fi l ter transfer
functi on accordi ng to the val ue of the stri ng 'iiroption':
'allpole': Produces an al l -pol e fi l ter transfer functi on from the associ ated
al l -pol e I I R l atti ce fi l ter coeffi ci ents k.
'allpass': Produces an al l pass fi l ter transfer functi on from the associ ated
al l pass I I R l atti ce fi l ter coeffi ci ents k.
num = latc2tf(k,'firoption') produces an FI R fi l ter accordi ng to the val ue
of the stri ng 'firoption':
'min': Produces a mi ni mum-phase FI R fi l ter numerator from the associ ated
mi ni mum-phase FI R l atti ce fi l ter coeffi ci ents k.
'max': Produces a maxi mum-phase FI R fi l ter numerator from the associ ated
maxi mum-phase FI R l atti ce fi l ter coeffi ci ents k.
'FIR': Produces a general FI R fi l ter numerator from the l atti ce fi l ter
coeffi ci ents k (defaul t, i f you l eave off the stri ng al together).
See Also latcfilt, tf2latc
latcfilt
7-272
7l atcfi l t
Purpose Latti ce and l atti ce-l adder fi l ter i mpl ementati on
Syntax [f,g] = latcfilt(k,x)
[f,g] = latcfilt(k,v,x)
[f,g] = latcfilt(k,1,x)
[f,g,zf] = latcfilt(...,'ic',zi)
Description When fi l teri ng data, l atti ce coeffi ci ents can be used to represent:
FI R fi l ters
Al l -pol e I I R fi l ters
Al l pass I I R fi l ters
General I I R fi l ters
[f,g] = latcfilt(k,x) fi l ters x wi th the FI R l atti ce coeffi ci ents i n the
vector k. f i s the forward l atti ce fi l ter resul t and g i s the backward fi l ter resul t.
I f , f corresponds to the mi ni mum-phase output, and g corresponds to the
maxi mum-phase output.
I f k and x are vectors, the resul t i s a (si gnal ) vector. Matri x arguments are
permi tted under the fol l owi ng rul es:
I f x i s a matri x and k i s a vector, each col umn of x i s processed through the
l atti ce fi l ter speci fi ed by k.
I f x i s a vector and k i s a matri x, each col umn of k i s used to fi l ter x, and a
si gnal matri x i s returned.
I f x and k are both matri ces wi th the same number of col umns, then the ith
col umn of k i s used to fi l ter the ith col umn of x. A si gnal matri x i s returned.
[f,g] = latcfilt(k,v,x) fi l ters x wi th the I I R l atti ce coeffi ci ents k and
l adder coeffi ci ents v. k and v must be vectors, whi l e x can be a si gnal matri x.
[f,g] = latcfilt(k,1,x) fi l ters x wi th the I I R l atti ce speci fi ed by k, where k
and x can be vectors or matri ces. f i s the al l -pol e l atti ce fi l ter resul t and g i s the
al l pass fi l ter resul t.
[f,g,zf] = latcfilt(...,'ic',zi) accepts a l ength-k vector zi speci fyi ng
the i ni ti al condi ti on of the l atti ce states. Output zf i s a l ength-k vector
speci fyi ng the fi nal condi ti on of the l atti ce states.
k 1
latcfilt
7-273
See Also filter, latc2tf, tf2latc
levinson
7-274
7l evi nson
Purpose Compute the Levi nson-Durbi n recursi on
Syntax a = levinson(r,p)
Description The Levi nson-Durbi n recursi on i s an al gori thm for fi ndi ng an al l -pol e I I R fi l ter
wi th a prescri bed determi ni sti c autocorrel ati on sequence. I t has appl i cati ons i n
fi l ter desi gn, codi ng, and spectral esti mati on. The fi l ter that levinson produces
i s mi ni mum phase.
a = levinson(r,p) fi nds the coeffi ci ents of an pth-order autoregressi ve l i near
process whi ch has r as i ts autocorrel ati on sequence. r i s a real or compl ex
determi ni sti c autocorrel ati on sequence (a vector), and p i s the order of
denomi nator pol ynomi al A(z); that i s, a = [1 a(2) ... a(p+1)]. The fi l ter
coeffi ci ents are ordered i n descendi ng powers of z.
Algorithm levinson sol ves the symmetri c Toepl i tz system of l i near equati ons
where r = [r(1) ... r(p+1)] i s the i nput autocorrel ati on vector, and r(i)
*

denotes the compl ex conjugate of r(i). The al gori thm requi res O(p
2
) fl ops and i s
thus much more effi ci ent than the MATLAB \ command for l arge p. However,
the levinson functi on uses \ for l ow orders to provi de the fastest possi bl e
executi on.
H z ( )
1
A z ( )
---------- -
1
1 a 2 ( )z
1
L a p 1 + ( )z
p
+ + +
----------------------------------------------------------------------------- = =
r 1 ( ) r 2 ( )

L r p ( )

r 2 ( ) r 1 ( ) L r p 1 ( )

M O O M
r p ( ) L r 2 ( ) r 1 ( )
a 2 ( )
a 3 ( )
M
a p 1 + ( )
r 2 ( )
r 3 ( )
M
r p 1 + ( )
=
levinson
7-275
See Also lpc, prony, rlevinson, schurrc, stmcb
References [1] Ljung, L., System I dentification: Theory for the User, Prenti ce-Hal l , 1987,
pp. 278-280.
lp2bp
7-276
7l p2bp
Purpose Transform l owpass anal og fi l ters to bandpass
Syntax [bt,at] = lp2bp(b,a,Wo,Bw)
[At,Bt,Ct,Dt] = lp2bp(A,B,C,D,Wo,Bw)
Description lp2bp transforms anal og l owpass fi l ter prototypes wi th a cutoff frequency of
1 rad/s i nto bandpass fi l ters wi th desi red bandwi dth and center frequency. The
transformati on i s one step i n the di gi tal fi l ter desi gn process for the butter,
cheby1, cheby2, and ellip functi ons.
lp2bp can perform the transformati on on two di fferent l i near system
representati ons: transfer functi on form and state-space form. I n both cases, the
i nput system must be an anal og fi l ter prototype.
Tra nsfer Function For m (Polynomia l)
[bt,at] = lp2bp(b,a,Wo,Bw) transforms an anal og l owpass fi l ter prototype
gi ven by pol ynomi al coeffi ci ents i nto a bandpass fi l ter wi th center frequency Wo
and bandwi dth Bw. Row vectors b and a speci fy the coeffi ci ents of the numerator
and denomi nator of the prototype i n descendi ng powers of s.
Scal ars Wo and Bw speci fy the center frequency and bandwi dth i n uni ts of rad/s.
For a fi l ter wi th l ower band edge w1 and upper band edge w2, use
Wo = sqrt(w1*w2) and Bw = w2-w1.
lp2bp returns the frequency transformed fi l ter i n row vectors bt and at.
Sta te- Spa ce For m
[At,Bt,Ct,Dt] = lp2bp(A,B,C,D,Wo,Bw) converts the conti nuous-ti me
state-space l owpass fi l ter prototype i n matri ces A, B, C, D shown bel ow
b s ( )
a s ( )
----------
b 1 ( )s
n
L b n ( )s b n 1 + ( ) + + +
a 1 ( )s
m
L a m ( )s a m 1 + ( ) + + +
--------------------------------------------------------------------------------- =
x

Ax Bu + =
y Cx Du + =
lp2bp
7-277
i nto a bandpass fi l ter wi th center frequency Wo and bandwi dth Bw. For a fi l ter
wi th l ower band edge w1 and upper band edge w2, use Wo = sqrt(w1*w2) and
Bw = w2-w1.
The bandpass fi l ter i s returned i n matri ces At, Bt, Ct, Dt.
Algorithm lp2bp i s a hi ghl y accurate state-space formul ati on of the cl assi c anal og fi l ter
frequency transformati on. Consi der the state-space system
where u i s the i nput, x i s the state vector, and y i s the output. The Lapl ace
transform of the fi rst equati on (assumi ng zero i ni ti al condi ti ons) i s
Now i f a bandpass fi l ter i s to have center frequency
0
and bandwi dth B
w
, the
standard s-domai n transformati on i s
where Q =
0
/B
w
and p = s/
0
. Substi tuti ng thi s for s i n the Lapl ace
transformed state-space equati on, and consi deri ng the operator p as d/dt
resul ts i n
or
Now defi ne
whi ch, when substi tuted, l eads to
x

Ax Bu + =
y Cx Du + =
sX s ( ) AX s ( ) BU s ( ) + =
s Q p
2
1 + ( ) p =
Qx

Qx + A

x Bu

+ =
Qx

x B u

Qx =
Q

Qx =
Qx

Ax Q Bu + + =
lp2bp
7-278
The l ast two equati ons gi ve equati ons of state. Wri te them i n standard form
and mul ti pl y the di fferenti al equati ons by
0
to recover the ti me/frequency
scal i ng represented by p and fi nd state matri ces for the bandpass fi l ter.
Q = Wo/Bw; [ma,m] = size(A);
At = Wo*[A/Q eye(ma,m);-eye(ma,m) zeros(ma,m)];
Bt = Wo*[B/Q; zeros(ma,n)];
Ct = [C zeros(mc,ma)];
Dt = d;
I f the i nput to lp2bp i s i n transfer functi on form, the functi on transforms i t i nto
state-space form before appl yi ng thi s al gori thm.
See Also bilinear, impinvar, lp2bs, lp2hp, lp2lp
lp2bs
7-279
7l p2bs
Purpose Transform l owpass anal og fi l ters to bandstop
Syntax [bt,at] = lp2bs(b,a,Wo,Bw)
[At,Bt,Ct,Dt] = lp2bs(A,B,C,D,Wo,Bw)
Description lp2bs transforms anal og l owpass fi l ter prototypes wi th a cutoff frequency of
1 rad/s i nto bandstop fi l ters wi th desi red bandwi dth and center frequency. The
transformati on i s one step i n the di gi tal fi l ter desi gn process for the butter,
cheby1, cheby2, and ellip functi ons.
lp2bs can perform the transformati on on two di fferent l i near system
representati ons: transfer functi on form and state-space form. I n both cases, the
i nput system must be an anal og fi l ter prototype.
Tra nsfer Function For m (Polynomia l)
[bt,at] = lp2bs(b,a,Wo,Bw) transforms an anal og l owpass fi l ter prototype
gi ven by pol ynomi al coeffi ci ents i nto a bandstop fi l ter wi th center frequency Wo
and bandwi dth Bw. Row vectors b and a speci fy the coeffi ci ents of the numerator
and denomi nator of the prototype i n descendi ng powers of s.
Scal ars Wo and Bw speci fy the center frequency and bandwi dth i n uni ts of
radi ans/second. For a fi l ter wi th l ower band edge w1 and upper band edge w2,
use Wo = sqrt(w1*w2) and Bw = w2-w1.
lp2bs returns the frequency transformed fi l ter i n row vectors bt and at.
Sta te- Spa ce For m
[At,Bt,Ct,Dt] = lp2bs(A,B,C,D,Wo,Bw) converts the conti nuous-ti me
state-space l owpass fi l ter prototype i n matri ces A, B, C, D shown bel ow
b s ( )
a s ( )
----------
b 1 ( )s
n
L b n ( )s b n 1 + ( ) + + +
a 1 ( )s
m
L a m ( )s a m 1 + ( ) + + +
--------------------------------------------------------------------------------- =
x

Ax Bu + =
y Cx Du + =
lp2bs
7-280
i nto a bandstop fi l ter wi th center frequency Wo and bandwi dth Bw. For a fi l ter
wi th l ower band edge w1 and upper band edge w2, use Wo = sqrt(w1*w2) and
Bw = w2-w1.
The bandstop fi l ter i s returned i n matri ces At, Bt, Ct, Dt.
Algorithm lp2bs i s a hi ghl y accurate state-space formul ati on of the cl assi c anal og fi l ter
frequency transformati on. I f a bandstop fi l ter i s to have center frequency
0

and bandwi dth B
w
, the standard s-domai n transformati on i s
where Q =
0
/B
w
and p = s/
0
. The state-space versi on of thi s transformati on i s
Q = Wo/Bw;
At = [Wo/Q*inv(A) Wo*eye(ma);-Wo*eye(ma) zeros(ma)];
Bt = -[Wo/Q*(A B); zeros(ma,n)];
Ct = [C/A zeros(mc,ma)];
Dt = D - C/A*B;
See lp2bp for a deri vati on of the bandpass versi on of thi s transformati on.
See Also bilinear, impinvar, lp2bp, lp2hp, lp2lp
s
p
Q p
2
1 + ( )
------------------------ =
lp2hp
7-281
7l p2hp
Purpose Transform l owpass anal og fi l ters to hi ghpass
Syntax [bt,at] = lp2hp(b,a,Wo)
[At,Bt,Ct,Dt] = lp2hp(A,B,C,D,Wo)
Description lp2hp transforms anal og l owpass fi l ter prototypes wi th a cutoff frequency of
1 rad/s i nto hi ghpass fi l ters wi th desi red cutoff frequency. The transformati on
i s one step i n the di gi tal fi l ter desi gn process for the butter, cheby1, cheby2,
and ellip functi ons.
The lp2hp functi on can perform the transformati on on two di fferent l i near
system representati ons: transfer functi on form and state-space form. I n both
cases, the i nput system must be an anal og fi l ter prototype.
Tra nsfer Function For m (Polynomia l)
[bt,at] = lp2hp(b,a,Wo) transforms an anal og l owpass fi l ter prototype
gi ven by pol ynomi al coeffi ci ents i nto a hi ghpass fi l ter wi th cutoff frequency Wo.
Row vectors b and a speci fy the coeffi ci ents of the numerator and denomi nator
of the prototype i n descendi ng powers of s.
Scal ar Wo speci fi es the cutoff frequency i n uni ts of radi ans/second. The
frequency transformed fi l ter i s returned i n row vectors bt and at.
Sta te- Spa ce For m
[At,Bt,Ct,Dt] = lp2hp(A,B,C,D,Wo) converts the conti nuous-ti me
state-space l owpass fi l ter prototype i n matri ces A, B, C, D bel ow
i nto a hi ghpass fi l ter wi th cutoff frequency Wo. The hi ghpass fi l ter i s returned
i n matri ces At, Bt, Ct, Dt.
b s ( )
a s ( )
----------
b 1 ( )s
n
L b n ( )s b n 1 + ( ) + + +
a 1 ( )s
m
L a m ( )s a m 1 + ( ) + + +
--------------------------------------------------------------------------------- =
x

Ax Bu + =
y Cx Du + =
lp2hp
7-282
Algorithm lp2hp i s a hi ghl y accurate state-space formul ati on of the cl assi c anal og fi l ter
frequency transformati on. I f a hi ghpass fi l ter i s to have cutoff frequency
0
, the
standard s-domai n transformati on i s
The state-space versi on of thi s transformati on i s
At = Wo*inv(A);
Bt = -Wo*(A\B);
Ct = C/A;
Dt = D - C/A*B;
See lp2bp for a deri vati on of the bandpass versi on of thi s transformati on.
See Also bilinear, impinvar, lp2bp, lp2bs, lp2lp
s

0
p
------- =
lp2lp
7-283
7l p2l p
Purpose Change the cut-off frequency for a l owpass anal og fi l ter
Syntax [bt,at] = lp2lp(b,a,Wo)
[At,Bt,Ct,Dt] = lp2lp(A,B,C,D,Wo)
Description lp2lp transforms an anal og l owpass fi l ter prototype wi th a cutoff frequency of
1 rad/s i nto a l owpass fi l ter wi th any speci fi ed cutoff frequency. The
transformati on i s one step i n the di gi tal fi l ter desi gn process for the butter,
cheby1, cheby2, and ellip functi ons.
The lp2lp functi on can perform the transformati on on two di fferent l i near
system representati ons: transfer functi on form and state-space form. I n both
cases, the i nput system must be an anal og fi l ter prototype.
Tra nsfer Function For m (Polynomia l)
[bt,at] = lp2lp(b,a,Wo) transforms an anal og l owpass fi l ter prototype
gi ven by pol ynomi al coeffi ci ents i nto a l owpass fi l ter wi th cutoff frequency Wo.
Row vectors b and a speci fy the coeffi ci ents of the numerator and denomi nator
of the prototype i n descendi ng powers of s.
Scal ar Wo speci fi es the cutoff frequency i n uni ts of radi ans/second. lp2lp
returns the frequency transformed fi l ter i n row vectors bt and at.
Sta te- Spa ce For m
[At,Bt,Ct,Dt] = lp2lp(A,B,C,D,Wo) converts the conti nuous-ti me
state-space l owpass fi l ter prototype i n matri ces A, B, C, D bel ow
i nto a l owpass fi l ter wi th cutoff frequency Wo. lp2lp returns the l owpass fi l ter
i n matri ces At, Bt, Ct, Dt.
b s ( )
a s ( )
----------
b 1 ( )s
n
L b n ( )s b n 1 + ( ) + + +
a 1 ( )s
m
L a m ( )s a m 1 + ( ) + + +
--------------------------------------------------------------------------------- =
x

Ax Bu + =
y Cx Du + =
lp2lp
7-284
Algorithm lp2lp i s a hi ghl y accurate state-space formul ati on of the cl assi c anal og fi l ter
frequency transformati on. I f a l owpass fi l ter i s to have cutoff frequency
0
, the
standard s-domai n transformati on i s
The state-space versi on of thi s transformati on i s
At = Wo*A;
Bt = Wo*B;
Ct = C;
Dt = D;
See lp2bp for a deri vati on of the bandpass versi on of thi s transformati on.
See Also bilinear, impinvar, lp2bp, lp2bs, lp2hp
s p
0
=
lpc
7-285
7l pc
Purpose Compute l i near predi cti on fi l ter coeffi ci ents
Syntax [a,g] = lpc(x,p)
Description lpc determi nes the coeffi ci ents of a forward l i near predi ctor by mi ni mi zi ng the
predi cti on error i n the l east squares sense. I t has appl i cati ons i n fi l ter desi gn
and speech codi ng.
[a,g] = lpc(x,p) fi nds the coeffi ci ents of a pth-order l i near predi ctor (FI R
fi l ter) that predi cts the current val ue of the real -val ued ti me seri es x based on
past sampl es.
p i s the order of the predi cti on fi l ter pol ynomi al , a = [1 a(2) ... a(p+1)]. I f
p i s unspeci fi ed, lpc uses as a defaul t p = length(x)-1. I f x i s a matri x
contai ni ng a separate si gnal i n each col umn, lpc returns a model esti mate for
each col umn i n the rows of matri x a and a row vector of predi cti on error
vari ances g.
Examples Esti mate a data seri es usi ng a thi rd-order forward predi ctor, and compare to
the ori gi nal si gnal .
Fi rst, create the si gnal data as the output of an autoregressi ve process dri ven
by whi te noi se. Use the l ast 4096 sampl es of the AR process output to avoi d
start-up transi ents.
randn('state',0);
noise = randn(50000,1); % Normalized white Gaussian noise
x = filter(1,[1 1/2 1/3 1/4],noise);
x = x(45904:50000);
Compute the predi ctor coeffi ci ents, esti mated si gnal , predi cti on error, and
autocorrel ati on sequence of the predi cti on error.
a = lpc(x,3);
est_x = filter([0 -a(2:end)],1,x); % Estimated signal
e = x - est_x; % Prediction error
[acs,lags] = xcorr(e,'coeff'); % ACS of prediction error
x

n ( ) a 2 ( )x n 1 ( ) a 3 ( )x n 2 ( ) L a p 1 + ( )x n p ( ) =
lpc
7-286
The predi cti on error, e(n), can be vi ewed as the output of the predi cti on error
fi l ter A(z) shown bel ow, where H(z) i s the opti mal l i near predi ctor, x(n) i s the
i nput si gnal , and i s the predi cted si gnal .
Compare the predi cted si gnal to the ori gi nal si gnal .
plot(1:97,x(4001:4097),1:97,est_x(4001:4097),'--');
title('Original Signal vs. LPC Estimate');
xlabel('Sample Number'); ylabel('Amplitude'); grid;
legend('Original Signal','LPC Estimate')
Look at the autocorrel ati on of the predi cti on error.
plot(lags,acs);
title('Autocorrelation of the Prediction Error');
xlabel('Lags'); ylabel('Normalized Value'); grid;
x

n ( )
H z ( ) a 2 ( )z
1
a 3 ( )z
2
L a n 1 + ( )z
p
=
x

n ( )
x n ( )

+
e n ( )
Prediction Error
A z ( )
0 10 20 30 40 50 60 70 80 90 100
3
2
1
0
1
2
3
4
5
Original Signal vs. LPC Estimate
Sample Number
A
m
p
l
i
t
u
d
e
Original Signal
LPC Estimate
lpc
7-287
The predi cti on error i s approxi matel y whi te Gaussi an noi se, as expected for a
thi rd-order AR i nput process.
Algorithm lpc uses the autocorrel ati on method of autoregressi ve (AR) model i ng to fi nd
the fi l ter coeffi ci ents. The generated fi l ter mi ght not model the process exactl y
even i f the data sequence i s trul y an AR process of the correct order. Thi s i s
because the autocorrel ati on method i mpl i ci tl y wi ndows the data, that i s, i t
assumes that si gnal sampl es beyond the l ength of x are 0.
lpc computes the l east squares sol uti on to
where
5000 4000 3000 2000 1000 0 1000 2000 3000 4000 5000
0.2
0
0.2
0.4
0.6
0.8
1
1.2
Autocorrelation of the Prediction Error
Lags
N
o
r
m
a
l
i
z
e
d

V
a
l
u
e
Xa b
X
x 1 ( ) 0 L 0
x 2 ( ) x 1 ( ) O M
M x 2 ( ) O 0
x m ( ) M O x 1 ( )
0 x m ( ) O x 2 ( )
M O O M
0 L 0 x m ( )
= a
1
a 2 ( )
M
a p 1 + ( )
= b
1
0
M
0
= , ,
lpc
7-288
and m i s the l ength of x. Sol vi ng the l east squares probl em vi a the normal
equati ons
l eads to the Yul e-Wal ker equati ons
where r = [r(1) r(2) ... r(p+1)] i s an autocorrel ati on esti mate for x computed
usi ng xcorr. The Yul e-Wal ker equati ons are sol ved i n O(p
2
) fl ops by the
Levi nson-Durbi n al gori thm (see levinson).
See Also aryule, levinson, prony, pyulear, stmcb
References [1] Jackson, L.B., Digital Filters and Signal Processing, Second Edi ti on,
Kl uwer Academi c Publ i shers, 1989. pp. 255-257.
X
H
Xa X
H
b =
r 1 ( ) r 2 ( )* L r p ( )*
r 2 ( ) r 1 ( ) O M
M O O r 2 ( )*
r p ( ) L r 2 ( ) r 1 ( )
a 2 ( )
a 3 ( )
M
a p 1 + ( )
r 2 ( )
r 3 ( )
M
r p 1 + ( )
=
lsf2poly
7-289
7l sf2pol y
Purpose Convert l i ne spectral frequenci es to predi cti on fi l ter coeffi ci ents
Syntax a = lsf2poly(lsf)
Description a = lsf2poly(lsf) returns a vector a contai ni ng the predi cti on fi l ter
coeffi ci ents from a vector lsf of l i ne spectral frequenci es (al so known as l i ne
spectrum pai rs).
Examples lsf = [0.7842 1.5605 1.8776 1.8984 2.3593];
a = lsf2poly(lsf)
a =
1.0000 0.6148 0.9899 0.0001 0.0031 -0.0081
See Also ac2poly, poly2lsf, rc2poly
References [1] Del l er, J.R., J.G. Proaki s, and J.H.L. Hansen, Discrete-Time Processing of
Speech Signals, Prenti ce-Hal l , 1993.
[2] Rabi ner, L.R., and R.W. Schafer, Digital Processing of Speech Signals,
Prenti ce-Hal l , 1978.
maxflat
7-290
7maxfl at
Purpose General i zed di gi tal Butterworth fi l ter desi gn
Syntax [b,a,] = maxflat(n,m,Wn)
b = maxflat(n,'sym',Wn)
[b,a,b1,b2] = maxflat(n,m,Wn)
[...] = maxflat(n,m,Wn,'design_flag')
Description [b,a,] = maxflat(n,m,Wn) i s a l owpass Butterworth fi l ter wi th numerator
and denomi nator coeffi ci ents b and a of orders n and m respecti vel y. Wn i s the
normal i zed cutoff frequency at whi ch the magni tude response of the fi l ter i s
equal to (approx. -3 dB). Wn must be between 0 and 1, where 1 corresponds
to the Nyqui st frequency.
b = maxflat(n,'sym',Wn) i s a symmetri c FI R Butterworth fi l ter. n must be
even, and Wn i s restri cted to a subi nterval of [0,1]. The functi on rai ses an error
i f Wn i s speci fi ed outsi de of thi s subi nterval .
[b,a,b1,b2] = maxflat(n,m,Wn) returns two pol ynomi al s b1 and b2 whose
product i s equal to the numerator pol ynomi al b (that i s, b = conv(b1,b2)).
b1 contai ns al l the zeros at z = -1, and b2 contai ns al l the other zeros.
[...] = maxflat(n,m,Wn,'design_flag') enabl es you to moni tor the fi l ter
desi gn, where 'design_flag' i s:
'trace', for a textual di spl ay of the desi gn tabl e used i n the desi gn
'plots', for pl ots of the fi l ters magni tude, group del ay, and zeros and pol es
'both', for both the textual di spl ay and pl ots
Examples n = 10; na = 2; Wn = 0.2;
[b,a,b1,b2] = maxflat(n,m,Wn,'plots')
1 2
maxflat
7-291
Algorithm The method consi sts of the use of formul ae, pol ynomi al root fi ndi ng, and a
transformati on of pol ynomi al roots.
See Also butter, filter, freqz
References [1] Sel esni ck, I .W., and C.S. Burrus, General i zed Di gi tal Butterworth Fi l ter
Desi gn, Proceedings of the I EEE I nt. Conf. Acoust., Speech, Signal Processing,
Vol . 3 (May 1996).
0 0.2 0.4 0.6 0.8 1
0
0.5
1
/
M
a
g
n
i
t
u
d
e
Frequency response
1 0 1
1
0.5
0
0.5
1
Real
I
m
a
g
i
n
a
r
y
Polezero plot
< deg 10
0 0.5 1
4
5
6
7
8
/
S
a
m
p
l
e
s
Group delay
medfilt1
7-292
7medfi l t1
Purpose One-di mensi onal medi an fi l teri ng
Syntax y = medfilt1(x,n)
y = medfilt1(x,n,blksz)
y = medfilt1(x,n,blksz,dim)
Description y = medfilt1(x,n) appl i es an order n one-di mensi onal medi an fi l ter to
vector x; the functi on consi ders the si gnal to be 0 beyond the end poi nts.
Output y has the same l ength as x.
For n odd, y(k) i s the medi an of x(k-(n-1)/2:k+(n-1)/2).
For n even, y(k) i s the medi an of x(k-n/2), x(k-(n/2)+1), ..., x(k+(n/2)-1).
I n thi s case, medfilt1 sorts the numbers, then takes the average of the
(n-1)/2 and ((n-1)/2)+1 el ements.
The defaul t for n i s 3.
y = medfilt1(x,n,blksz) uses a for-l oop to compute blksz (bl ock si ze)
output sampl es at a ti me. Use blksz << length(x) i f you are l ow on memory,
si nce medfilt1 uses a worki ng matri x of si ze n-by-blksz. By defaul t,
blksz = length(x); thi s provi des the fastest executi on i f you have suffi ci ent
memory.
I f x i s a matri x, medfilt1 medi an fi l ters i ts col umns usi ng
y(:,i) = medfilt1(x(:,i),n,blksz)
i n a l oop over the col umns of x.
y = medfilt1(x,n,blksz,dim) speci fi es the di mensi on, dim, al ong whi ch the
fi l ter operates.
See Also filter, medfilt2, median
References [1] Pratt, W.K., Digital I mage Processing, John Wi l ey & Sons, 1978,
pp. 330-333.
modulate
7-293
7modul ate
Purpose Modul ati on for communi cati ons si mul ati on
Syntax y = modulate(x,fc,fs,'method')
y = modulate(x,fc,fs,'method',opt)
[y,t] = modulate(x,fc,fs)
Description y = modulate(x,fc,fs,'method') and
y = modulate(x,fc,fs,'method',opt) modul ate the real message si gnal x
wi th a carri er frequency fc and sampl i ng frequency fs, usi ng one of the opti ons
l i sted bel ow for 'method'. Note that some methods accept an opti on, opt.
amdsb-sc
or
am
Amplitude modulation, double sideband, suppressed carrier.
Mul ti pl i es x by a si nusoi d of frequency fc.
y = x.*cos(2*pi*fc*t)
amdsb-tc Amplitude modulation, double sideband, transmitted carrier.
Subtracts scal ar opt from x and mul ti pl i es the resul t by a si nusoi d
of frequency fc.
y = (x-opt).*cos(2*pi*fc*t)
I f the opt parameter i s not present, modulate uses a defaul t of
min(min(x)) so that the message si gnal (x-opt) i s enti rel y
nonnegati ve and has a mi ni mum val ue of 0.
amssb Amplitude modulation, single sideband. Mul ti pl i es x by a
si nusoi d of frequency fc and adds the resul t to the Hi l bert transform
of x mul ti pl i ed by a phase shi fted si nusoi d of frequency fc.
y =
x.*cos(2*pi*fc*t)+imag(hilbert(x)).*sin(2*pi*fc*t)
Thi s effecti vel y removes the upper si deband.
modulate
7-294
fm Frequency modulation. Creates a si nusoi d wi th i nstantaneous
frequency that vari es wi th the message si gnal x.
y = cos(2*pi*fc*t + opt*cumsum(x))
cumsum i s a rectangul ar approxi mati on to the i ntegral of x.
modulate uses opt as the constant of frequency modul ati on. I f opt
i s not present, modulate uses a defaul t of
opt = (fc/fs)*2*pi/(max(max(x)))
so the maxi mum frequency excursi on from fc i s fc Hz.
pm Phase modulation. Creates a si nusoi d of frequency fc whose
phase vari es wi th the message si gnal x.
y = cos(2*pi*fc*t + opt*x)
modulate uses opt as the constant of phase modul ati on. I f opt i s
not present, modulate uses a defaul t of
opt = pi/(max(max(x)))
so the maxi mum phase excursi on i s radi ans.
pwm Pulse-width modulation. Creates a pul se-wi dth modul ated
si gnal from the pul se wi dths i n x. The el ements of x must be
between 0 and 1, speci fyi ng the wi dth of each pul se i n fracti ons of
a peri od. The pul ses start at the begi nni ng of each peri od, that i s,
they are l eft justi fi ed.
modulate(x,fc,fs,'pwm','centered')
yi el ds pul ses centered at the begi nni ng of each peri od. y i s l ength
length(x)*fs/fc.
ppm Pulse-position modulation. Creates a pul se-posi ti on modul ated
si gnal from the pul se posi ti ons i n x. The el ements of x must be
between 0 and 1, speci fyi ng the l eft edge of each pul se i n fracti ons
of a peri od. opt i s a scal ar between 0 and 1 that speci fi es the
l ength of each pul se i n fracti ons of a peri od. The defaul t for opt i s
0.1. y i s l ength length(x)*fs/fc.
qam Quadrature amplitude modulation. Creates a quadrature
ampl i tude modul ated si gnal from si gnal s x and opt.
y = x.*cos(2*pi*fc*t) + opt.*sin(2*pi*fc*t)
opt must be the same si ze as x.
modulate
7-295
I f you do not speci fy 'method', then modulate assumes am. Except for the pwm
and ptm cases, y i s the same si ze as x.
I f x i s an array, modulate modul ates i ts col umns.
[y,t] = modulate(x,fc,fs) returns the i nternal ti me vector t that modulate
uses i n i ts computati ons.
See Also demod, vco
nuttallwin
7-296
7nuttal l wi n
Purpose Compute a mi ni mum 4-term Bl ackman-Harri s wi ndow, as defi ned by Nuttal l
Syntax w = nuttallwin(n)
Description w = nuttallwin(n) returns a mi ni mum, n-poi nt, 4-term Bl ackman-harri s
wi ndow i n the col umn vector w. The wi ndow i s mi ni mum i n the sense that i ts
maxi mum si del obes are mi ni mi zed. The coeffi ci ents for thi s wi ndow di ffer from
the Bl ackman-harri s wi ndow coeffi ci ents computed wi th blackmanharris and
produce sl i ghtl y l ower si del obes.
Example Compare 64-poi nt Bl ackman-Harri s and Nuttal l s Bl ackman-Harri s wi ndows
and pl ot the di fference between the wi ndows.
N = 64;
w = blackmanharris(N);
y = nuttallwin(N);
plot(1:N,w,1:N,y,'r--');axis([1 N 0 1]);
title('Comparison of 64-pt windows');
legend('Blackman-harris', 'Nuttall');
plot(y-w);
title('Difference between Blackman-harris and Nuttall windows')
10 20 30 40 50 60
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
Comparison of 64pt windows
Blackmanharris
Nuttall
nuttallwin
7-297
The maxi mum di fference, usi ng max(abs(y-w)), i s 0.0099.
Algorithm The equati on for computi ng the coeffi ci ents of a mi ni mum 4-term
Bl ackman-harri s wi ndow, accordi ng to Nuttal l , i s
where .
The coeffi ci ents for thi s wi ndow are
See Also blackmanharris, barthannwin, bartlett, blackman, bohmanwin, chebwin,
gausswin, hann, hamming, kaiser, rectwin, triang, tukeywin, window
0 10 20 30 40 50 60 70
0
0.001
0.002
0.003
0.004
0.005
0.006
0.007
0.008
0.009
0.01
Difference between Blackmanharris and Nuttall windows
a
0
= 0.3635819
a
1
= 0.4891775
a
2
= 0.1365995
a
3
= 0.0106411
w k 1 + [ ] a
0
a
1
2
k
n 1
-------------
,
_
a
2
4
k
n 1
-------------
,
_
cos a
3
6
k
n 1
-------------
,
_
cos + cos =
0 k n 1 ( )
nuttallwin
7-298
References [1] Nuttal l , Al bert H. Some Wi ndows wi th Very Good Si del obe Behavoi r.
I EEE Transactions on Acoustics, Speech, and Signal Processing. Vol . ASSP-29
(February 1981). pp. 84-91.
pburg
7-299
7pburg
Purpose Esti mate the power spectral densi ty usi ng the Burg method
Syntax Pxx = pburg(x,p)
[Pxx,w] = pburg(x,p)
[Pxx,w] = pburg(x,p,nfft)
[Pxx,f] = pburg(x,p,nfft,fs)
[Pxx,f] = pburg(x,p,nfft,fs,'range')
[Pxx,w] = pburg(x,p,nfft,'range')
pburg(...)
Description Pxx = pburg(x,p) i mpl ements the Burg al gori thm, a parametri c spectral
esti mati on method, and returns Pxx, an esti mate of the power spectral densi ty
(PSD) of the vector x. The entri es of x represent sampl es of a di screte-ti me
si gnal , and p i s the i nteger speci fyi ng the order of an autoregressi ve (AR)
predi cti on model for the si gnal , used i n esti mati ng the PSD.
The power spectral densi ty i s cal cul ated i n uni ts of power per radi ans per
sampl e. Real -val ued i nputs produce ful l power one-si ded (i n frequency) PSDs
(by defaul t), whi l e compl ex-val ued i nputs produce two-si ded PSDs.
I n general , the l ength of the FFT and the val ues of the i nput x determi ne the
l ength of Pxx and the range of the correspondi ng normal i zed frequenci es. For
thi s syntax, the (defaul t) FFT l ength i s 256. The fol l owi ng tabl e i ndi cates the
l ength of Pxx and the range of the correspondi ng normal i zed frequenci es for
thi s syntax.
[Pxx,w] = pburg(x,p) al so returns w, a vector of frequenci es at whi ch the
PSD i s esti mated. Pxx and w have the same l ength. The uni ts for frequency are
rad/sampl e.
Table 7-9: PSD Vector Characteristics for an FFT Length of 256 (Default)
Real/ Complex
Input Data
Length of Pxx Range of the Corresponding
Normalized Frequencies
Real -val ued 129 [0, ]
Compl ex-val ued 256 [0, 2)
pburg
7-300
[Pxx,w] = pburg(x,p,nfft) uses the Burg method to esti mate the PSD whi l e
speci fyi ng the l ength of the FFT wi th the i nteger nfft. I f you speci fy nfft as
the empty vector [], i t takes the defaul t val ue of 256.
The l ength of Pxx and the frequency range for w depend on nfft and the val ues
of the i nput x. The fol l owi ng tabl e i ndi cates the l ength of Pxx and the frequency
range for w i n thi s syntax.
[Pxx,f] = pburg(x,p,nfft,fs) uses the sampl i ng frequency fs speci fi ed as
an i nteger i n hertz (Hz) to compute the PSD vector (Pxx) and the correspondi ng
vector of frequenci es (f). I n thi s case, the uni ts for the frequency vector are
i n Hz. The spectral densi ty produced i s cal cul ated i n uni ts of power per Hz. I f
you speci fy fs as the empty vector [], the sampl i ng frequency defaul ts to 1 Hz.
The frequency range for f depends on nfft, fs, and the val ues of the i nput x.
The l ength of Pxx i s the same as i n the tabl e above. The fol l owi ng tabl e
i ndi cates the frequency range for f for thi s syntax.
Table 7-10: PSD and Frequency Vector Characteristics
Real/ Complex
Input Data
nfft Even/ Odd Length of Pxx Range of w
Real -val ued Even (nfft/2 + 1) [0, ]
Real -val ued Odd (nfft + 1)/2 [0, )
Compl ex-val ued Even or odd nfft [0, 2)
Table 7-11: PSD and Frequency Vector Characteristics with fs Specified
Real/ Complex Input Data nfft Even/ Odd Range of f
Real -val ued Even [0,fs/2]
Real -val ued Odd [0,fs/2)
Compl ex-val ued Even or odd [0,fs)
pburg
7-301
[Pxx,f] = pburg(x,p,nfft,fs,'range') or
[Pxx,w] = pburg(x,p,nfft,'range') speci fi es the range of frequency val ues
to i ncl ude i n f or w. Thi s syntax i s useful when x i s real . 'range' can be ei ther:
'twosided': Compute the two-si ded PSD over the frequency range [0,fs).
Thi s i s the defaul t for determi ni ng the frequency range for compl ex-val ued
x.
- I f you speci fy fs as the empty vector, [], the frequency range i s [0,1).
- I f you dont speci fy fs, the frequency range i s [0, 2).
'onesided': Compute the one-si ded PSD over the frequency ranges speci fi ed
for real x. Thi s i s the defaul t for determi ni ng the frequency range for
real -val ued x.
Note You can put the stri ng argument 'range' anywhere i n the i nput
argument l i st after p.
pburg(...) wi th no outputs pl ots the power spectral densi ty i n the current
fi gure wi ndow. The frequency range on the pl ot i s the same as the range of
output w (or f) for a gi ven set of parameters.
Remarks The power spectral densi ty i s computed as the di stri buti on of power per uni t
frequency.
Thi s al gori thm depends on your sel ecti ng an appropri ate model order for your
si gnal .
Examples Because the Burg method esti mates the spectral densi ty by fi tti ng an AR
predi cti on model of a gi ven order to the si gnal , fi rst generate a si gnal from an
AR (al l -pol e) model of a gi ven order. You can use freqz to check the magni tude
of the frequency response of your AR fi l ter. Thi s wi l l gi ve you an i dea of what
to expect when you esti mate the PSD usi ng pburg.
a = [1 -2.2137 2.9403 -2.1697 0.9606]; % AR filter coefficients
freqz(1,a) % AR filter frequency response
title('AR System Frequency Response')
pburg
7-302
Now generate the i nput si gnal x by fi l teri ng whi te noi se through the AR fi l ter.
Esti mate the PSD of x based on a fourth-order AR predi cti on model si nce i n thi s
case we know that the ori gi nal AR system model a has order 4.
randn('state',1);
x = filter(1,a,randn(256,1)); % AR system output
pburg(x,4) % Fourth-order estimate
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
200
150
100
50
0
50
100
Normalized Frequency ( rad/sample)
P
h
a
s
e

(
d
e
g
r
e
e
s
)
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
20
10
0
10
20
30
40
Normalized Frequency ( rad/sample)
M
a
g
n
i
t
u
d
e

(
d
B
)
AR System Frequency Response
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
30
20
10
0
10
20
30
Normalized Frequency ( rad/sample)
P
o
w
e
r

S
p
e
c
t
r
a
l

D
e
n
s
i
t
y

(
d
B
/

r
a
d
/
s
a
m
p
l
e
)
Burg PSD Estimate
pburg
7-303
Algorithm Li near predi cti on fi l ters can be used to model the second-order stati sti cal
characteri sti cs of a si gnal . The predi cti on fi l ter output can be used to model the
si gnal when the i nput i s whi te noi se.
The Burg method fi ts an AR l i near predi cti on fi l ter model of the speci fi ed order
to the i nput si gnal by mi ni mi zi ng (usi ng l east squares) the ari thmeti c mean of
the forward and backward predi cti on errors. The spectral densi ty i s then
computed from the frequency response of the predi cti on fi l ter. The AR fi l ter
parameters are constrai ned to sati sfy the Levi nson-Durbi n recursi on.
See Also arburg, lpc, pcov, peig, periodogram, pmcov, pmtm, pmusic, pwelch, psdplot,
pyulear
References [1] Marpl e, S.L. Digital Spectral Analysis, Engl ewood Cl i ffs, NJ, Prenti ce-Hal l ,
1987, Chapter 7.
[2] Stoi ca, P., and R.L. Moses, I ntroduction to Spectral Analysis, Prenti ce-Hal l ,
1997.
pcov
7-304
7pcov
Purpose Esti mate the power spectral densi ty usi ng the covari ance method
Syntax Pxx = pcov(x,p)
[Pxx,w] = pcov(x,p)
[Pxx,w] = pcov(x,p,nfft)
[Pxx,f] = pcov(x,p,nfft,fs)
[Pxx,f] = pcov(x,p,nfft,fs,'range')
[Pxx,w] = pcov(x,p,nfft,'range')
pcov(...)
Description Pxx = pcov(x,p) i mpl ements the covari ance al gori thm, a parametri c spectral
esti mati on method, and returns Pxx, an esti mate of the power spectral densi ty
(PSD) of the vector x. The entri es of x represent sampl es of a di screte-ti me
si gnal , and where p i s the i nteger speci fyi ng the order of an autoregressi ve (AR)
predi cti on model for the si gnal , used i n esti mati ng the PSD.
The power spectral densi ty i s cal cul ated i n uni ts of power per radi ans per
sampl e. Real -val ued i nputs produce ful l power one-si ded (i n frequency) PSDs
(by defaul t), whi l e compl ex-val ued i nputs produce two-si ded PSDs.
I n general , the l ength of the FFT and the val ues of the i nput x determi ne the
l ength of Pxx and the range of the correspondi ng normal i zed frequenci es. For
thi s syntax, the (defaul t) FFT l ength i s 256. The fol l owi ng tabl e i ndi cates the
l ength of Pxx and the range of the correspondi ng normal i zed frequenci es for
thi s syntax.
[Pxx,w] = pcov(x,p) al so returns w, a vector of frequenci es at whi ch the PSD
i s esti mated. Pxx and w have the same l ength. The uni ts for frequency are
rad/sampl e.
Table 7-12: PSD Vector Characteristics for an FFT Length of 256 (Default)
Real/ Complex
Input Data
Length of Pxx Range of the Corresponding
Normalized Frequencies
Real -val ued 129 [0, ]
Compl ex-val ued 256 [0, 2)
pcov
7-305
[Pxx,w] = pcov(x,p,nfft) uses the covari ance method to esti mate the PSD
whi l e speci fyi ng the l ength of the FFT wi th the i nteger nfft. I f you speci fy nfft
as the empty vector [], i t takes the defaul t val ue of 256.
The l ength of Pxx and the frequency range for w depend on nfft and the val ues
of the i nput x. The fol l owi ng tabl e i ndi cates the l ength of Pxx and the frequency
range for w i n thi s syntax.
[Pxx,f] = pcov(x,p,nfft,fs) uses the sampl i ng frequency fs speci fi ed as an
i nteger i n hertz (Hz) to compute the PSD vector (Pxx) and the correspondi ng
vector of frequenci es (f). I n thi s case, the uni ts for the frequency vector are
i n Hz. The spectral densi ty produced i s cal cul ated i n uni ts of power per Hz. I f
you speci fy fs as the empty vector [], the sampl i ng frequency defaul ts to 1 Hz.
The frequency range for f depends on nfft, fs, and the val ues of the i nput x.
The l ength of Pxx i s the same as i n the tabl e above. The fol l owi ng tabl e
i ndi cates the frequency range for f for thi s syntax.
Table 7-13: PSD and Frequency Vector Characteristics
Real/ Complex
Input Data
nfft Even/ Odd Length of Pxx Range of w
Real -val ued Even (nfft/2 + 1) [0, ]
Real -val ued Odd (nfft + 1)/2 [0, )
Compl ex-val ued Even or odd nfft [0, 2)
Table 7-14: PSD and Frequency Vector Characteristics with fs Specified
Real/ Complex Input Data nfft Even/ Odd Range of f
Real -val ued Even [0,fs/2]
Real -val ued Odd [0,fs/2)
Compl ex-val ued Even or odd [0,fs)
pcov
7-306
[Pxx,f] = pcov(x,p,nfft,fs,'range') or
[Pxx,w] = pcov(x,p,nfft,'range') speci fi es the range of frequency val ues
to i ncl ude i n f or w. Thi s syntax i s useful when x i s real . 'range' can be ei ther:
'twosided': Compute the two-si ded PSD over the frequency range [0,fs).
Thi s i s the defaul t for determi ni ng the frequency range for
compl ex-val ued x.
- I f you speci fy fs as the empty vector, [], the frequency range i s [0,1).
- I f you dont speci fy fs, the frequency range i s [0, 2).
'onesided': Compute the one-si ded PSD over the frequency ranges speci fi ed
for real x. Thi s i s the defaul t for determi ni ng the frequency range for
real -val ued x.
Note You can put the stri ng argument 'range' anywhere i n the i nput
argument l i st after p.
pcov(...) wi th no outputs pl ots the power spectral densi ty i n the current
fi gure wi ndow. The frequency range on the pl ot i s the same as the range of
output w (or f) for a gi ven set of parameters.
Remarks The power spectral densi ty i s computed as the di stri buti on of power per uni t
frequency.
Thi s al gori thm depends on your sel ecti ng an appropri ate model order for your
si gnal .
Examples Because the covari ance method esti mates the spectral densi ty by fi tti ng an AR
predi cti on model of a gi ven order to the si gnal , fi rst generate a si gnal from an
AR (al l -pol e) model of a gi ven order. You can use freqz to check the magni tude
of the frequency response of your AR fi l ter. Thi s wi l l gi ve you an i dea of what
to expect when you esti mate the PSD usi ng pcov.
a = [1 -2.2137 2.9403 -2.1697 0.9606]; % AR filter coefficients
freqz(1,a) % AR filter frequency response
title('AR System Frequency Response')
pcov
7-307
Now generate the i nput si gnal x by fi l teri ng whi te noi se through the AR fi l ter.
Esti mate the PSD of x based on a fourth-order AR predi cti on model si nce i n thi s
case we know that the ori gi nal AR system model a has order 4.
randn('state',1);
x = filter(1,a,randn(256,1)); % Signal generated from AR filter
pcov(x,4) % Fourth-order estimate
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
200
150
100
50
0
50
100
Normalized Frequency ( rad/sample)
P
h
a
s
e

(
d
e
g
r
e
e
s
)
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
20
10
0
10
20
30
40
Normalized Frequency ( rad/sample)
M
a
g
n
i
t
u
d
e

(
d
B
)
AR System Frequency Response
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
30
20
10
0
10
20
30
Normalized Frequency ( rad/sample)
P
o
w
e
r

S
p
e
c
t
r
a
l

D
e
n
s
i
t
y

(
d
B
/

r
a
d
/
s
a
m
p
l
e
)
Covariance PSD Estimate
pcov
7-308
Algorithm Li near predi cti on fi l ters can be used to model the second-order stati sti cal
characteri sti cs of a si gnal . The predi cti on fi l ter output can be used to model the
si gnal when the i nput i s whi te noi se.
The covari ance method esti mates the PSD of a si gnal usi ng the covari ance
method. The covari ance (or nonwi ndowed) method fi ts an AR l i near predi cti on
fi l ter model to the si gnal by mi ni mi zi ng the forward predi cti on error (based on
causal observati ons of your i nput si gnal ) i n the l east squares sense. The
spectral esti mate returned by pcov i s the squared magni tude of the frequency
response of thi s AR model .
See Also arcov, lpc, pburg, peig, periodogram, pmcov, pmtm, pmusic, pwelch, psdplot,
pyulear
References [1] Marpl e, S.L. Digital Spectral Analysis, Engl ewood Cl i ffs, NJ, Prenti ce-Hal l ,
1987, Chapter 7.
[2] Stoi ca, P., and R.L. Moses, I ntroduction to Spectral Analysis, Prenti ce-Hal l ,
1997.
peig
7-309
7pei g
Purpose Esti mate the pseudospectrum usi ng the ei genvector method
Syntax [S,w] = peig(x,p)
[S,w] = peig(...,nfft)
[S,f] = peig(x,p,nfft,fs)
[S,f] = peig(...,'corr')
[S,f] = peig(x,p,nfft,fs,nwin,noverlap)
[...] = peig(...,'range')
[...,v,e] = peig(...)
peig(...)
Description [S,w] = peig(x,p) i mpl ements the ei genvector spectral esti mati on method
and returns S, the pseudospectrum esti mate of the i nput si gnal x, and w, a
vector of normal i zed frequenci es (i n rad/sampl e) at whi ch the pseudospectrum
i s eval uated. The pseudospectrum i s cal cul ated usi ng esti mates of the
ei genvectors of a correl ati on matri x associ ated wi th the i nput data x, where x
i s speci fi ed as ei ther:
A row or col umn vector representi ng one observati on of the si gnal
A rectangul ar array for whi ch each row of x represents a separate
observati on of the si gnal (for exampl e, each row i s one output of an array of
sensors, as i n array processi ng), such that x'*x i s an esti mate of the
correl ati on matri x
Note You can use the output of corrmtx to generate such an array x.
You can speci fy the second i nput argument p as ei ther:
A scal ar i nteger. I n thi s case, the si gnal subspace di mensi on i s p.
A two-el ement vector. I n thi s case, p(2), the second el ement of p, represents
a threshol d that i s mul ti pl i ed by
mi n
, the smal l est esti mated ei genval ue of
the si gnal s correl ati on matri x. Ei genval ues bel ow the threshol d
mi n
*p(2)
are assi gned to the noi se subspace. I n thi s case, p(1) speci fi es the maxi mum
di mensi on of the si gnal subspace.
peig
7-310
The extra threshol d parameter i n the second entry i n p provi des you more
fl exi bi l i ty and control i n assi gni ng the noi se and si gnal subspaces.
S and w have the same l ength. I n general , the l ength of the FFT and the val ues
of the i nput x determi ne the l ength of the computed S and the range of the
correspondi ng normal i zed frequenci es. The fol l owi ng tabl e i ndi cates the l ength
of S (and w) and the range of the correspondi ng normal i zed frequenci es for thi s
syntax.
[S,w] = peig(...,nfft) speci fi es the l ength of the FFT used to esti mate the
pseudospectrum wi th the i nteger nfft. The defaul t val ue for nfft (entered as
an empty vector []) i s 256.
The fol l owi ng tabl e i ndi cates the l ength of S and w, and the frequency range
for w for thi s syntax.
[S,f] = peig(x,p,nfft,fs)) returns the pseudospectrum i n the vector S
eval uated at the correspondi ng vector of frequenci es f (i n Hz). You suppl y the
sampl i ng frequency fs i n Hz. I f you speci fy fs wi th the empty vector [], the
sampl i ng frequency defaul ts to 1 Hz.
Table 7-15: S Characteristics for an FFT Length of 256 (Default)
Real/ Complex
Input Data
Length of S and w Range of the Corresponding
Normalized Frequencies
Real -val ued 129 [0, ]
Compl ex-val ued 256 [0, 2)
Table 7-16: S and Frequency Vector Characteristics
Real/ Complex
Input Data
nfft Even/ Odd Length of S
and w
Range of w
Real -val ued Even (nfft/2 + 1) [0, ]
Real -val ued Odd (nfft + 1)/2 [0, )
Compl ex-val ued Even or odd nfft [0, 2)
peig
7-311
The frequency range for f depends on nfft, fs, and the val ues of the i nput x.
The l ength of S (and f) i s the same as i n Tabl e 7-16. The fol l owi ng tabl e
i ndi cates the frequency range for f for thi s syntax.
[S,f] = peig(...,'corr') forces the i nput argument x to be i nterpreted as a
correl ati on matri x rather than matri x of si gnal data. For thi s syntax x must be
a square matri x, and al l of i ts ei genval ues must be nonnegati ve.
[S,f] = peig(x,p,nfft,fs,nwin,noverlap) al l ows you to speci fy nwin, a
scal ar i nteger i ndi cati ng a rectangul ar wi ndow l ength, or a real -val ued vector
speci fyi ng wi ndow coeffi ci ents. Use the scal ar i nteger noverlap i n conjuncti on
wi th nwin to speci fy the number of i nput sampl e poi nts by whi ch successi ve
wi ndows overl ap. noverlap i s not used i f x i s a matri x. The defaul t val ue for
nwin i s 2*p(1) and noverlap i s nwin-1.
Wi th thi s syntax, the i nput data x i s segmented and wi ndowed before the
matri x used to esti mate the correl ati on matri x ei genval ues i s formul ated. The
segmentati on of the data depends on nwin, noverlap, and the form of x.
Comments on the resul ti ng wi ndowed segments are descri bed i n the fol l owi ng
tabl e.
Table 7-17: S and Frequency Vector Characteristics with fs Specified
Real/ Complex Input Data nfft Even/ Odd Range of f
Real -val ued Even [0,fs/2]
Real -val ued Odd [0,fs/2)
Compl ex-val ued Even or odd [0,fs)
Table 7-18: Windowed Data Depending on x and nwin
Input data x Form of nwin Windowed Data
Data vector Scal ar Length i s nwin
Data vector Vector of coeffi ci ents Length i s length(nwin)
peig
7-312
See Tabl e 7-19 for rel ated i nformati on on thi s syntax.
Note The arguments nwin and noverlap are i gnored when you i ncl ude the
stri ng 'corr' i n the syntax.
[...] = peig(...,'range') speci fi es the range of frequency val ues to i ncl ude
i n f or w. Thi s syntax i s useful when x i s real . 'range' can be ei ther:
'whole': Compute the pseudospectrum over the frequency range [0,fs).
Thi s i s the defaul t for determi ni ng the frequency range for compl ex-val ued x.
- I f you speci fy fs as the empty vector, [], the frequency range i s [0,1).
- I f you dont speci fy fs, the frequency range i s [0, 2).
'half': Compute the pseudospectrum over the frequency ranges speci fi ed
for real x. Thi s i s the defaul t for determi ni ng the frequency range for
real -val ued x.
Note You can put the stri ng arguments 'range' or 'corr' anywhere i n the
i nput argument l i st after p.
[...,v,e] = peig(...) returns the matri x v of noi se ei genvectors, al ong wi th
the associ ated ei genval ues i n the vector e. The col umns of v span the noi se
subspace of di mensi on size(v,2). The di mensi on of the si gnal subspace i s
size(v,1)-size(v,2). For thi s syntax, e i s a vector of esti mated ei genval ues
of the correl ati on matri x.
Data matri x Scal ar Data i s not wi ndowed.
Data matri x Vector of coeffi ci ents length(nwin) must be the
same as the col umn l ength of x,
and noverlap i s not used.
Table 7-18: Windowed Data Depending on x and nwin (Continued)
Input data x Form of nwin Windowed Data
peig
7-313
peig(...) wi th no output arguments pl ots the pseudospectrum i n the current
fi gure wi ndow.
Remarks I n the process of esti mati ng the pseudospectrum, peig computes the noi se and
si gnal subspaces from the esti mated ei genvectors v
j
and ei genval ues
j
of the
si gnal s correl ati on matri x. The smal l est of these ei genval ues i s used i n
conjuncti on wi th the threshol d parameter p(2) to affect the di mensi on of the
noi se subspace i n some cases.
The l ength n of the ei genvectors computed by peig i s the sum of the di mensi ons
of the si gnal and noi se subspaces. Thi s ei genvector l ength depends on your
i nput (si gnal data or correl ati on matri x) and the syntax you use.
The fol l owi ng tabl e summari zes the dependency of the ei genvector l ength on
the i nput argument.
You shoul d speci fy nwin > p(1) or length(nwin) > p(1) i f you want p(2) > 1 to
have any effect.
Table 7-19: Eigenvector Length Depending on Input Data and Syntax
Form of Input Data x Comments on the Syntax Length n of
Eigenvectors
Row or col umn vector nwin i s speci fi ed as a scal ar
i nteger.
nwin
Row or col umn vector nwin i s speci fi ed as a
vector.
length(nwin)
Row or col umn vector nwin i s not speci fi ed. 2*p(1)
l-by-m matri x I f nwin i s speci fi ed as a
scal ar, i t i s not used. I f
nwin i s speci fi ed as a
vector, length(nwin) must
equal m.
m
m-by-m nonnegati ve
defi ni te matri x
The stri ng 'corr' i s
speci fi ed and nwin i s not
used.
m
peig
7-314
Examples I mpl ement the ei genvector method to fi nd the pseudospectrum of the sum of
three si nusoi ds i n noi se, usi ng the defaul t FFT l ength of 256. Use the modi fi ed
covari ance method for the correl ati on matri x esti mate.
randn('state',1); n=0:99;
s=exp(i*pi/2*n)+2*exp(i*pi/4*n)+exp(i*pi/3*n)+randn(1,100);
X=corrmtx(s,12,'mod');
peig(X,3,'whole') % Uses the default NFFT of 256.
Algorithm The ei genvector method esti mates the pseudospectrum from a si gnal or a
correl ati on matri x usi ng a wei ghted versi on of the MUSI C al gori thm deri ved
from Schmi dts ei genspace anal ysi s method [1][2]. The al gori thm performs
ei genspace anal ysi s of the si gnal s correl ati on matri x i n order to esti mate the
si gnal s frequency content. The ei genval ues and ei genvectors of the si gnal s
correl ati on matri x are esti mated usi ng svd i f you dont suppl y the correl ati on
matri x. Thi s al gori thm i s parti cul arl y sui tabl e for si gnal s that are the sum of
si nusoi ds wi th addi ti ve whi te Gaussi an noi se.
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8
15
10
5
0
5
10
15
20
25
30
Normalized Frequency ( rad/sample)
d
B
Eigenvector Method Pseudospectrum
peig
7-315
The ei genvector method produces a pseudospectrum esti mate gi ven by
where N i s the di mensi on of the ei genvectors and v
k
i s the kth ei genvector of
the correl ati on matri x of the i nput si gnal . The i nteger p i s the di mensi on of the
si gnal subspace, so the ei genvectors v
k
used i n the sum correspond to the
smal l est ei genval ues of the correl ati on matri x. The ei genvectors used i n the
PSD esti mate span the noi se subspace. The vector e(f) consi sts of compl ex
exponenti al s, so the i nner product
amounts to a Fouri er transform. Thi s i s used for computati on of the PSD
esti mate. The FFT i s computed for each v
k
and then the squared magni tudes
are summed and scal ed.
See Also corrmtx, pburg, periodogram, pmtm, pmusic, prony, pwelch, psdplot, rooteig,
rootmusic
References [1] Marpl e, S.L. Digital Spectral Analysis, Engl ewood Cl i ffs, NJ, Prenti ce-Hal l ,
1987, pp. 373-378.
[2] Schmi dt, R.O, Mul ti pl e Emi tter Locati on and Si gnal Parameter
Esti mati on, I EEE Trans. Antennas Propagation, Vol . AP-34 (March 1986),
pp. 276-280.
[3] Stoi ca, P., and R.L. Moses, I ntroduction to Spectral Analysis, Prenti ce-Hal l ,
1997.
P
ev
f ( )
1
v
k
H
e f ( )
2
k 1
N

,


_

----------------------------------------------------------- =

k
v
k
H
e f ( )
periodogram
7-316
7peri odogram
Purpose Esti mate the power spectral densi ty (PSD) of a si gnal usi ng a peri odogram
Syntax [Pxx,w] = periodogram(x)
[Pxx,w] = periodogram(x,window)
[Pxx,w] = periodogram(x,window,nfft)
[Pxx,f] = periodogram(x,window,nfft,fs)
[Pxx,...] = periodogram(x,...,'range')
periodogram(...)
Description [Pxx,w] = periodogram(x) returns the power spectral densi ty (PSD)
esti mate Pxx of the sequence x usi ng a peri odogram. The power spectral
densi ty i s cal cul ated i n uni ts of power per radi ans per sampl e. The
correspondi ng vector of frequenci es w i s computed i n radi ans per sampl e, and
has the same l ength as Pxx.
A real -val ued i nput vector x produces a ful l power one-si ded (i n frequency) PSD
(by defaul t), whi l e a compl ex-val ued x produces a two-si ded PSD.
I n general , the l ength N of the FFT and the val ues of the i nput x determi ne the
l ength of Pxx and the range of the correspondi ng normal i zed frequenci es. For
thi s syntax, the (defaul t) l ength N of the FFT i s the l arger of 256 and the next
power of two greater than the l ength of x. The fol l owi ng tabl e i ndi cates the
l ength of Pxx and the range of the correspondi ng normal i zed frequenci es for
thi s syntax.
[Pxx,w] = periodogram(x,window) returns the PSD esti mate Pxx computed
usi ng the modi fi ed peri odogram method. The vector window speci fi es the
coeffi ci ents of the wi ndow used i n computi ng a modi fi ed peri odogram of the
i nput si gnal . Both i nput arguments must be vectors of the same l ength. When
you dont suppl y the second argument window, or set i t to the empty vector [],
Table 7-20: PSD Vector Characteristics for an FFT Length of N (Default)
Real/ Complex
Input Data
Length of Pxx Range of the Corresponding
Normalized Frequencies
Real -val ued (N/2) +1 [0, ]
Compl ex-val ued N [0, 2)
periodogram
7-317
a rectangul ar wi ndow (rectwin) i s used by defaul t. I n thi s case the standard
peri odogram i s cal cul ated.
[Pxx,w] = periodogram(x,window,nfft) uses the modi fi ed peri odogram to
esti mate the PSD whi l e speci fyi ng the l ength of the FFT wi th the i nteger nfft.
I f you set nfft to the empty vector [], i t takes the defaul t val ue for N l i sted i n
the previ ous syntax.
The l ength of Pxx and the frequency range for w depend on nfft and the val ues
of the i nput x. The fol l owi ng tabl e i ndi cates the l ength of Pxx and the frequency
range for w for thi s syntax.
Note periodogram uses an nfft-poi nt FFT of the wi ndowed data
(x.*window) to compute the peri odogram. I f the val ue you speci fy for nfft i s
l ess than the l ength of x, then x.*window i s wrapped modul o nfft. I f the val ue
you speci fy for nfft i s greater than the l ength of x, then x.*window i s
zero-padded to compute the FFT.
[Pxx,f] = periodogram(x,window,nfft,fs) uses the sampl i ng frequency fs
speci fi ed as an i nteger i n hertz (Hz) to compute the PSD vector (Pxx) and the
correspondi ng vector of frequenci es (f). I n thi s case, the uni ts for the frequency
vector are i n Hz. The spectral densi ty produced i s cal cul ated i n uni ts of power
per Hz. I f you speci fy fs as the empty vector [], the sampl i ng frequency
defaul ts to 1 Hz.
Table 7-21: PSD and Frequency Vector Characteristics
Real/ Complex
Input Data
nfft Even/ Odd Length of Pxx Range of w
Real -val ued Even (nfft/2 + 1) [0, ]
Real -val ued Odd (nfft + 1)/2 [0, )
Compl ex-val ued Even or odd nfft [0, 2)
periodogram
7-318
The frequency range for f depends on nfft, fs, and the val ues of the i nput x.
The l ength of Pxx i s the same as i n the tabl e above. The fol l owi ng tabl e
i ndi cates the frequency range for f for thi s syntax.
[Pxx,f] = periodogram(x,window,nfft,fs,'range') or
[Pxx,w] = periodogram(x,window,nfft,'range') speci fi es the range of
frequency val ues to i ncl ude i n f or w. Thi s syntax i s useful when x i s real .
'range' can be ei ther:
'twosided': Compute the two-si ded PSD over the frequency range [0,fs).
Thi s i s the defaul t for determi ni ng the frequency range for
compl ex-val ued x.
- I f you speci fy fs as the empty vector, [], the frequency range i s [0,1).
- I f you dont speci fy fs, the frequency range i s [0, 2).
'onesided': Compute the one-si ded PSD over the frequency ranges speci fi ed
for real x. Thi s i s the defaul t for determi ni ng the frequency range for
real -val ued x.
Note You can put the stri ng argument 'range' anywhere i n the i nput
argument l i st after window.
periodogram(...) wi th no outputs pl ots the power spectral densi ty i n dB per
uni t frequency i n the current fi gure wi ndow. The frequency range on the pl ot
i s the same as the range of output w (or f) for the syntax you use.
Table 7-22: PSD and Frequency Vector Characteristics with fs Specified
Real/ Complex Input Data nfft Even/ Odd Range of f
Real -val ued Even [0,fs/2]
Real -val ued Odd [0,fs/2)
Compl ex-val ued Even or odd [0,fs)
periodogram
7-319
Examples Compute the peri odogram of a 200 Hz si gnal embedded i n addi ti ve noi se usi ng
the defaul t wi ndow.
randn('state',0);
Fs = 1000;
t = 0:1/Fs:.3;
x = cos(2*pi*t*200)+0.1*randn(size(t));
periodogram(x,[],'twosided',512,Fs)
Algorithm The peri odogram for a sequence [x
1
, ... , x
n
] i s gi ven by the fol l owi ng formul a.
Thi s expressi on forms an esti mate of the power spectrum of the si gnal defi ned
by the sequence [x
1
, ... , x
n
].
0 100 200 300 400 500 600 700 800 900
70
60
50
40
30
20
10
Frequency (Hz)
P
o
w
e
r

S
p
e
c
t
r
a
l

D
e
n
s
i
t
y

(
d
B
/
H
z
)
Periodogram PSD Estimate
S e
j
( )
1
n
--- x
l
e
j l
l 1 =
n

2
=
periodogram
7-320
I f you wei ght your si gnal sequence by a wi ndow [w
1
, ... , w
n
], then the wei ghted
or modi fi ed peri odogram i s defi ned as
I n ei ther case, periodogram uses an nfft-poi nt FFT to compute the power
spectral densi ty as , where F i s:
2 when you do not suppl y the sampl i ng frequency
fs when you suppl y the sampl i ng frequency
See Also pburg, pcov, peig, pmcov, pmtm, pmusic, pwelch, psdplot, pyulear
References [1] Stoi ca, P., and R.L. Moses, I ntroduction to Spectral Analysis, Prenti ce-Hal l ,
1997, pp. 24-26.
[2] Wel ch, P.D, The Use of Fast Fouri er Transform for the Esti mati on of Power
Spectra: A Method Based on Ti me Averagi ng Over Short, Modi fi ed
Peri odograms, I EEE Trans. Audio Electroacoustics, Vol . AU-15 (June 1967),
pp. 70-73.
[3] Oppenhei m, A.V., and R.W. Schafer, Discrete-Time Signal Processing,
Prenti ce-Hal l , 1989, pp. 730-742.
S e
j
( )
1
n
--- w
l
x
l
e
j l
l 1 =
n

2
1
n
--- w
l
2
l 1 =
n

--------------------------------------------- =
S e
j
( ) F
pmcov
7-321
7pmcov
Purpose Esti mate the power spectral densi ty usi ng the modi fi ed covari ance method
Syntax Pxx = pmcov(x,p)
[Pxx,w] = pmcov(x,p)
[Pxx,w] = pmcov(x,p,nfft)
[Pxx,f] = pmcov(x,p,nfft,fs)
[Pxx,f] = pmcov(x,p,nfft,fs,'range')
[Pxx,w] = pmcov(x,p,nfft,'range')
pmcov(...)
Description Pxx = pmcov(x,p) i mpl ements the modi fi ed covari ance al gori thm, a
parametri c spectral esti mati on method, and returns Pxx, an esti mate of the
power spectral densi ty (PSD) of the vector x. The entri es of x represent sampl es
of a di screte-ti me si gnal , and p i s the i nteger speci fyi ng the order of an
autoregressi ve (AR) predi cti on model for the si gnal , used i n esti mati ng the
PSD.
The power spectral densi ty i s cal cul ated i n uni ts of power per radi ans per
sampl e. Real -val ued i nputs produce ful l power one-si ded (i n frequency) PSDs
(by defaul t), whi l e compl ex-val ued i nputs produce two-si ded PSDs.
I n general , the l ength of the FFT and the val ues of the i nput x determi ne the
l ength of Pxx and the range of the correspondi ng normal i zed frequenci es. For
thi s syntax, the (defaul t) FFT l ength i s 256. The fol l owi ng tabl e i ndi cates the
l ength of Pxx and the range of the correspondi ng normal i zed frequenci es for
thi s syntax.
[Pxx,w] = pmcov(x,p) al so returns w, a vector of frequenci es at whi ch the
PSD i s esti mated. Pxx and w have the same l ength. The uni ts for frequency are
rad/sampl e.
Table 7-23: PSD Vector Characteristics for an FFT Length of 256 (Default)
Real/ Complex
Input Data
Length of Pxx Range of the Corresponding
Normalized Frequencies
Real -val ued 129 [0, ]
Compl ex-val ued 256 [0, 2)
pmcov
7-322
[Pxx,w] = pmcov(x,p,nfft) uses the covari ance method to esti mate the PSD
whi l e speci fyi ng the l ength of the FFT wi th the i nteger nfft. I f you speci fy nfft
as the empty vector [], i t takes the defaul t val ue of 256.
The l ength of Pxx and the frequency range for w depend on nfft and the val ues
of the i nput x. The fol l owi ng tabl e i ndi cates the l ength of Pxx and the frequency
range for w for thi s syntax.
[Pxx,f] = pmcov(x,p,nfft,fs) uses the sampl i ng frequency fs speci fi ed as
an i nteger i n hertz (Hz) to compute the PSD vector (Pxx) and the correspondi ng
vector of frequenci es (f). I n thi s case, the uni ts for the frequency vector are
i n Hz. The spectral densi ty produced i s cal cul ated i n uni ts of power per Hz. I f
you speci fy fs as the empty vector [], the sampl i ng frequency defaul ts to 1 Hz.
The frequency range for f depends on nfft, fs, and the val ues of the i nput x.
The l ength of Pxx i s the same as i n Tabl e 7-24. The fol l owi ng tabl e i ndi cates the
frequency range for f i n thi s syntax.
Table 7-24: PSD and Frequency Vector Characteristics
Real/ Complex
Input Data
nfft Even/ Odd Length of Pxx Range of w
Real -val ued Even (nfft/2 + 1) [0, ]
Real -val ued Odd (nfft + 1)/2 [0, )
Compl ex-val ued Even or odd nfft [0, 2)
Table 7-25: PSD and Frequency Vector Characteristics with fs Specified
Real/ Complex Input Data nfft Even/ Odd Range of f
Real -val ued Even [0,fs/2]
Real -val ued Odd [0,fs/2)
Compl ex-val ued Even or odd [0,fs)
pmcov
7-323
[Pxx,f] = pmcov(x,p,nfft,fs,'range') or
[Pxx,w] = pmcov(x,p,nfft,'range') speci fi es the range of frequency val ues
to i ncl ude i n f or w. Thi s syntax i s useful when x i s real . 'range' can be ei ther:
'twosided': Compute the two-si ded PSD over the frequency range [0,fs).
Thi s i s the defaul t for determi ni ng the frequency range for
compl ex-val ued x.
- I f you speci fy fs as the empty vector, [], the frequency range i s [0,1).
- I f you dont speci fy fs, the frequency range i s [0, 2).
'onesided': Compute the one-si ded PSD over the frequency ranges speci fi ed
for real x. Thi s i s the defaul t for determi ni ng the frequency range for
real -val ued x.
Note You can put the stri ng argument 'range' anywhere i n the i nput
argument l i st after p.
pmcov(...) wi th no outputs pl ots the power spectral densi ty i n the current
fi gure wi ndow. The frequency range on the pl ot i s the same as the range of
output w (or f) for a gi ven set of parameters.
Remarks The power spectral densi ty i s computed as the di stri buti on of power per uni t
frequency.
Thi s al gori thm depends on your sel ecti ng an appropri ate model order for your
si gnal .
Examples Because the modi fi ed covari ance method esti mates the spectral densi ty by
fi tti ng an AR predi cti on model of a gi ven order to the si gnal , fi rst generate a
si gnal from an AR (al l -pol e) model of a gi ven order. You can use freqz to check
the magni tude of the frequency response of your AR fi l ter. Thi s wi l l gi ve you an
i dea of what to expect when you esti mate the PSD usi ng pmcov.
a = [1 -2.2137 2.9403 -2.1697 0.9606]; % AR filter coefficients
freqz(1,a) % AR filter frequency response
title('AR System Frequency Response')
pmcov
7-324
Now generate the i nput si gnal x by fi l teri ng whi te noi se through the AR fi l ter.
Esti mate the PSD of x based on a fourth-order AR predi cti on model si nce i n thi s
case we know that the ori gi nal AR system model a has order 4.
randn('state',1);
x = filter(1,a,randn(256,1)); % AR filter output
pmcov(x,4) % Fourth-order estimate
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
200
150
100
50
0
50
100
Normalized Frequency ( rad/sample)
P
h
a
s
e

(
d
e
g
r
e
e
s
)
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
20
10
0
10
20
30
40
Normalized Frequency ( rad/sample)
M
a
g
n
i
t
u
d
e

(
d
B
)
AR System Frequency Response
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
30
20
10
0
10
20
30
Normalized Frequency ( rad/sample)
P
o
w
e
r

S
p
e
c
t
r
a
l

D
e
n
s
i
t
y

(
d
B
/

r
a
d
/
s
a
m
p
l
e
)
Modified Covariance PSD Estimate
pmcov
7-325
Algorithm Li near predi cti on fi l ters can be used to model the second-order stati sti cal
characteri sti cs of a si gnal . The predi cti on fi l ter output can be used to model the
si gnal when the i nput i s whi te noi se.
pmcov esti mates the PSD of the si gnal vector usi ng the modi fi ed covari ance
method. Thi s method fi ts an autoregressi ve (AR) l i near predi cti on fi l ter model
to the si gnal by si mul taneousl y mi ni mi zi ng the forward and backward
predi cti on errors (based on causal observati ons of your i nput si gnal ) i n the
l east squares sense. The spectral esti mate returned by pmcov i s the magni tude
squared frequency response of thi s AR model .
See Also armcov, lpc, pburg, pcov, peig, periodogram, pmtm, pmusic, pwelch, prony,
psdplot, pyulear
References [1] Marpl e, S.L. Digital Spectral Analysis, Engl ewood Cl i ffs, NJ, Prenti ce-Hal l ,
1987, Chapter 7.
[2] Stoi ca, P., and R.L. Moses, I ntroduction to Spectral Analysis, Prenti ce-Hal l ,
1997.
pmtm
7-326
7pmtm
Purpose Esti mate the power spectral densi ty usi ng the mul ti taper method (MTM)
Syntax [Pxx,w] = pmtm(x,nw)
[Pxx,w] = pmtm(x,nw,nfft)
[Pxx,f] = pmtm(x,nw,nfft,fs)
[Pxx,Pxxc,f] = pmtm(x,nw,nfft,fs)
[Pxx,Pxxc,f] = pmtm(x,nw,nfft,fs,p)
[Pxx,Pxxc,f] = pmtm(x,e,v,nfft,fs,p)
[Pxx,Pxxc,f] = pmtm(x,dpss_params,nfft,fs,p)
[...] = pmtm(...,'method')
[...] = pmtm(...,'range')
pmtm(...)
Description pmtm esti mates the power spectral densi ty (PSD) of the ti me seri es x usi ng the
mul ti taper method (MTM) descri bed i n [1]. Thi s method uses l i near or
nonl i near combi nati ons of modi fi ed peri odograms to esti mate the PSD. These
peri odograms are computed usi ng a sequence of orthogonal tapers (wi ndows i n
the frequency domai n) speci fi ed from the di screte prol ate spheroi dal sequences
(see dpss).
[Pxx,w] = pmtm(x,nw) esti mates the PSD Pxx for the i nput si gnal x, usi ng
2*nw-1 di screte prol ate spheroi dal sequences as data tapers for the mul ti taper
esti mati on method. nw i s the ti me-bandwi dth product for the di screte prol ate
spheroi dal sequences. I f you speci fy nw as the empty vector [], a defaul t val ue
of 4 i s used. Other typi cal choi ces are 2, 5/2, 3, or 7/2. pmtm al so returns w, a
vector of frequenci es at whi ch the PSD i s esti mated. Pxx and w have the same
l ength. The uni ts for frequency are rad/sampl e.
The power spectral densi ty i s cal cul ated i n uni ts of power per radi ans per
sampl e. Real -val ued i nputs produce (by defaul t) ful l power one-si ded (i n
frequency) PSDs, whi l e compl ex-val ued i nputs produce two-si ded PSDs.
I n general , the l ength N of the FFT and the val ues of the i nput x determi ne the
l ength of Pxx and the range of the correspondi ng normal i zed frequenci es. For
thi s syntax, the (defaul t) l ength N of the FFT i s the l arger of 256 and the next
power of two greater than the l ength of the segment. The fol l owi ng tabl e
pmtm
7-327
i ndi cates the l ength of Pxx and the range of the correspondi ng normal i zed
frequenci es for thi s syntax.
[Pxx,w] = pmtm(x,nw,nfft) uses the mul ti taper method to esti mate the PSD
whi l e speci fyi ng the l ength of the FFT wi th the i nteger nfft. I f you speci fy nfft
as the empty vector [], i t adopts the defaul t val ue for N descri bed i n the
previ ous syntax.
The l ength of Pxx and the frequency range for w depend on nfft and the val ues
of the i nput x. The fol l owi ng tabl e i ndi cates the l ength of Pxx and the frequency
range for w for thi s syntax.
[Pxx,f] = pmtm(x,nw,nfft,fs) uses the sampl i ng frequency fs speci fi ed as
an i nteger i n hertz (Hz) to compute the PSD vector (Pxx) and the correspondi ng
vector of frequenci es (f). I n thi s case, the uni ts for the frequency vector f are
i n Hz. The spectral densi ty produced i s cal cul ated i n uni ts of power per Hz. I f
you speci fy fs as the empty vector [], the sampl i ng frequency defaul ts to 1 Hz.
Table 7-26: PSD Vector Characteristics for an FFT Length of N (Default)
Real/ Complex
Input Data
Length of Pxx Range of the Corresponding
Normalized Frequencies
Real -val ued (N/2) +1 [0, ]
Compl ex-val ued N [0, 2)
Table 7-27: PSD and Frequency Vector Characteristics
Real/ Complex
Input Data
nfft Even/ Odd Length of Pxx Range of w
Real -val ued Even (nfft/2 + 1) [0, ]
Real -val ued Odd (nfft + 1)/2 [0, )
Compl ex-val ued Even or odd nfft [0, 2)
pmtm
7-328
The frequency range for f depends on nfft, fs, and the val ues of the i nput x.
The l ength of Pxx i s the same as i n Tabl e 7-27. The fol l owi ng tabl e i ndi cates the
frequency range for f for thi s syntax.
[Pxx,Pxxc,f] = pmtm(x,nw,nfft,fs) returns Pxxc, the 95% confi dence
i nterval for Pxx. Confi dence i nterval s are computed usi ng a chi -squared
approach. Pxxc i s a two-col umn matri x wi th the same number of rows as Pxx.
Pxxc(:,1) i s the l ower bound of the confi dence i nterval and Pxxc(:,2) i s the
upper bound of the confi dence i nterval .
[Pxx,Pxxc,f] = pmtm(x,nw,nfft,fs,p) returns Pxxc, the p*100% confi dence
i nterval for Pxx, where p i s a scal ar between 0 and 1. I f you dont speci fy p, or
i f you speci fy p as the empty vector [], the defaul t 95% confi dence i nterval i s
used.
[Pxx,Pxxc,f] = pmtm(x,e,v,nfft,fs,p) returns the PSD esti mate Pxx, the
confi dence i nterval Pxxc, and the frequency vector f from the data tapers
contai ned i n the col umns of the matri x e, and thei r concentrati ons i n the
vector v. The l ength of v i s the same as the number of col umns i n e. You can
obtai n the data to suppl y as these arguments from the outputs of dpss.
[Pxx,Pxxc,f] = pmtm(x,dpss_params,nfft,fs,p) uses the cel l array
dpss_params contai ni ng the i nput arguments to dpss (l i sted i n order, but
excl udi ng the fi rst argument) to compute the data tapers. For exampl e,
pmtm(x,{3.5,'trace'},512,1000) cal cul ates the prol ate spheroi dal
sequences for nw = 3.5, usi ng nfft = 512, and fs = 1000, and di spl ays the
method that dpss uses for thi s cal cul ati on. See dpss for other opti ons.
Table 7-28: PSD and Frequency Vector Characteristics with fs Specified
Real/ Complex Input Data nfft Even/ Odd Range of f
Real -val ued Even [0, fs/2]
Real -val ued Odd [0, fs/2)
Compl ex-val ued Even or odd [0, fs)
pmtm
7-329
[...] = pmtm(...,'method') speci fi es the al gori thm used for combi ni ng the
i ndi vi dual spectral esti mates. The stri ng 'method' can be one of the fol l owi ng:
'adapt': Thomsons adapti ve nonl i near combi nati on (defaul t)
'unity': A l i near combi nati on of the wei ghted peri odograms wi th uni ty
wei ghts
'eigen': A l i near combi nati on of the wei ghted peri odograms wi th
ei genval ue wei ghts
[...] = pmtm(...,'range') speci fi es the range of frequency val ues to i ncl ude
i n f or w. Thi s syntax i s useful when x i s real . 'range' can be ei ther:
'twosided': Compute the two-si ded PSD over the frequency range [0,fs).
Thi s i s the defaul t for determi ni ng the frequency range for compl ex-val ued
x.
- I f you speci fy fs as the empty vector, [], the frequency range i s [0,1).
- I f you dont speci fy fs, the frequency range i s [0, 2).
'onesided': Compute the one-si ded PSD over the frequency ranges speci fi ed
for real x. Thi s i s the defaul t for determi ni ng the frequency range for
real -val ued x.
Note You can put the stri ng arguments 'range' or 'method' anywhere after
the i nput argument nw or v.
pmtm(...) wi th no output arguments pl ots the PSD esti mate and the
confi dence i nterval s i n the current fi gure wi ndow. I f you dont speci fy fs, the
95% confi dence i nterval i s pl otted. I f you do speci fy fs, the confi dence i nterval s
pl otted depend on the val ue of p.
pmtm
7-330
Examples Thi s exampl e anal yzes a si nusoi d i n whi te noi se.
randn('state',0);
fs = 1000; t = 0:1/fs:0.3;
x = cos(2*pi*t*200) + 0.1*randn(size(t));
[Pxx,Pxxc,f] = pmtm(x,3.5,512,fs,0.99);
psdplot([Pxx Pxxc],f,'hz','db')
title('PMTM PSD Estimate with 99% Confidence Intervals')
See Also dpss, pburg, pcov, peig, periodogram, pmcov, pmusic, pwelch, psdplot,
pyulear
References [1] Perci val , D.B., and A.T. Wal den, Spectral Analysis for Physical
Applications: Multitaper and Conventional Univariate Techniques, Cambri dge
Uni versi ty Press, 1993.
[2] Thomson, D.J., Spectrum esti mati on and harmoni c anal ysi s, Proceedings
of the I EEE, Vol . 70 (1982), pp. 1055-1096.
0 50 100 150 200 250 300 350 400 450 500
70
60
50
40
30
20
10
Frequency (Hz)
P
o
w
e
r

S
p
e
c
t
r
a
l

D
e
n
s
i
t
y

(
d
B
/
H
z
)
PMTM PSD Estimate with 99% Confidence Intervals
pmusic
7-331
7pmusi c
Purpose Esti mate the pseudospectrum usi ng the MUSI C al gori thm
Syntax [S,w] = pmusic(x,p)
[S,w] = pmusic(...,nfft)
[S,f] = pmusic(x,p,nfft,fs))
[S,f] = pmusic(...,'corr')
[S,f] = pmusic(x,p,nfft,fs,nwin,noverlap)
[...] = pmusic(...,'range')
[...,v,e] = pmusic(...)
pmusic(...)
Description [S,w] = pmusic(x,p) i mpl ements the MUSI C (Mul ti pl e Si gnal Cl assi fi cati on)
al gori thm and returns S, the pseudospectrum esti mate of the i nput si gnal x,
and a vector w of normal i zed frequenci es (i n rad/sampl e) at whi ch the
pseudospectrum i s eval uated. The pseudospectrum i s cal cul ated usi ng
esti mates of the ei genvectors of a correl ati on matri x associ ated wi th the i nput
data x, where x i s speci fi ed as ei ther:
A row or col umn vector representi ng one observati on of the si gnal
A rectangul ar array for whi ch each row of x represents a separate
observati on of the si gnal (for exampl e, each row i s one output of an array of
sensors, as i n array processi ng), such that x'*x i s an esti mate of the
correl ati on matri x
Note You can use the output of corrmtx to generate such an array x.
You can speci fy the second i nput argument p as ei ther:
A scal ar i nteger. I n thi s case, the si gnal subspace di mensi on i s p.
A two-el ement vector. I n thi s case, p(2), the second el ement of p, represents
a threshol d that i s mul ti pl i ed by
mi n
, the smal l est esti mated ei genval ue of
the si gnal s correl ati on matri x. Ei genval ues bel ow the threshol d
mi n
*p(2)
are assi gned to the noi se subspace. I n thi s case, p(1) speci fi es the maxi mum
di mensi on of the si gnal subspace.
pmusic
7-332
The extra threshol d parameter i n the second entry i n p provi des you more
fl exi bi l i ty and control i n assi gni ng the noi se and si gnal subspaces.
S and w have the same l ength. I n general , the l ength of the FFT and the val ues
of the i nput x determi ne the l ength of the computed S and the range of the
correspondi ng normal i zed frequenci es. The fol l owi ng tabl e i ndi cates the l ength
of S (and w) and the range of the correspondi ng normal i zed frequenci es for thi s
syntax.
[S,w] = pmusic(...,nfft) speci fi es the l ength of the FFT used to esti mate
the pseudospectrum wi th the i nteger nfft. The defaul t val ue for nfft (entered
as an empty vector []) i s 256.
The fol l owi ng tabl e i ndi cates the l ength of S and w, and the frequency range for
w i n thi s syntax.
[S,f] = pmusic(x,p,nfft,fs) returns the pseudospectrum i n the vector S
eval uated at the correspondi ng vector of frequenci es f (i n Hz). You suppl y the
sampl i ng frequency fs i n Hz. I f you speci fy fs wi th the empty vector [], the
sampl i ng frequency defaul ts to 1 Hz.
Table 7-29: S Characteristics for an FFT Length of 256 (Default)
Real/ Complex
Input Data
Length of S and w Range of the Corresponding
Normalized Frequencies
Real -val ued 129 [0, ]
Compl ex-val ued 256 [0, 2)
Table 7-30: S and Frequency Vector Characteristics
Real/ Complex
Input Data
nfft Even/ Odd Length of S
and w
Range of w
Real -val ued Even (nfft/2 + 1) [0, ]
Real -val ued Odd (nfft + 1)/2 [0, )
Compl ex-val ued Even or odd nfft [0, 2)
pmusic
7-333
The frequency range for f depends on nfft, fs, and the val ues of the i nput x.
The l ength of S (and f) i s the same as i n Tabl e 7-30. The fol l owi ng tabl e
i ndi cates the frequency range for f for thi s syntax.
[S,f] = pmusic(...,'corr') forces the i nput argument x to be i nterpreted as
a correl ati on matri x rather than matri x of si gnal data. For thi s syntax x must
be a square matri x, and al l of i ts ei genval ues must be nonnegati ve.
[S,f] = pmusic(x,p,nfft,fs,nwin,noverlap) al l ows you to speci fy nwin, a
scal ar i nteger i ndi cati ng a rectangul ar wi ndow l ength, or a real -val ued vector
speci fyi ng wi ndow coeffi ci ents. Use the scal ar i nteger noverlap i n conjuncti on
wi th nwin to speci fy the number of i nput sampl e poi nts by whi ch successi ve
wi ndows overl ap. noverlap i s not used i f x i s a matri x. The defaul t val ue for
nwin i s 2*p(1) and noverlap i s nwin-1.
Wi th thi s syntax, the i nput data x i s segmented and wi ndowed before the
matri x used to esti mate the correl ati on matri x ei genval ues i s formul ated. The
segmentati on of the data depends on nwin, noverlap, and the form of x.
Comments on the resul ti ng wi ndowed segments are descri bed i n the fol l owi ng
tabl e.
Table 7-31: S and Frequency Vector Characteristics with fs Specified
Real/ Complex Input Data nfft Even/ Odd Range of f
Real -val ued Even [0,fs/2]
Real -val ued Odd [0,fs/2)
Compl ex-val ued Even or odd [0,fs)
Table 7-32: Windowed Data Depending on x and nwin
Input data x Form of nwin Windowed Data
Data vector Scal ar Length i s nwin
Data vector Vector of coeffi ci ents Length i s length(nwin)
pmusic
7-334
See Tabl e 7-33 for rel ated i nformati on on thi s syntax.
Note The arguments nwin and noverlap are i gnored when you i ncl ude the
stri ng 'corr' i n the syntax.
[...] = pmusic(...,'range') speci fi es the range of frequency val ues to
i ncl ude i n f or w. Thi s syntax i s useful when x i s real . 'range' can be ei ther:
'whole': Compute the pseudospectrum over the frequency range [0,fs).
Thi s i s the defaul t for determi ni ng the frequency range for compl ex-val ued x.
- I f you speci fy fs as the empty vector, [], the frequency range i s [0,1).
- I f you dont speci fy fs, the frequency range i s [0, 2).
'half': Compute the pseudospectrum over the frequency ranges speci fi ed
for real x. Thi s i s the defaul t for determi ni ng the frequency range for
real -val ued x.
Note You can put the stri ng arguments 'range' or 'corr' anywhere i n the
i nput argument l i st after p.
[...,v,e] = pmusic(...) returns the matri x v of noi se ei genvectors, al ong
wi th the associ ated ei genval ues i n the vector e. The col umns of v span the noi se
subspace of di mensi on size(v,2). The di mensi on of the si gnal subspace i s
size(v,1)-size(v,2). For thi s syntax, e i s a vector of esti mated ei genval ues
of the correl ati on matri x.
Data matri x Scal ar Data i s not wi ndowed.
Data matri x Vector of coeffi ci ents length(nwin) must be the
same as the col umn l ength of x,
and noverlap i s not used.
Table 7-32: Windowed Data Depending on x and nwin (Continued)
Input data x Form of nwin Windowed Data
pmusic
7-335
pmusic(...) wi th no output arguments pl ots the pseudospectrum i n the
current fi gure wi ndow.
Remarks I n the process of esti mati ng the pseudospectrum, pmusic computes the noi se
and si gnal subspaces from the esti mated ei genvectors v
j
and ei genval ues
j
of
the si gnal s correl ati on matri x. The smal l est of these ei genval ues i s used i n
conjuncti on wi th the threshol d parameter p(2) to affect the di mensi on of the
noi se subspace i n some cases.
The l ength n of the ei genvectors computed by pmusic i s the sum of the
di mensi ons of the si gnal and noi se subspaces. Thi s ei genvector l ength depends
on your i nput (si gnal data or correl ati on matri x) and the syntax you use.
The fol l owi ng tabl e summari zes the dependency of the ei genvector l ength on
the i nput argument.
You shoul d speci fy nwin > p(1) or length(nwin) > p(1) i f you want p(2) > 1 to
have any effect.
Table 7-33: Eigenvector Length Depending on Input Data and Syntax
Form of Input Data x Comments on the Syntax Length n of
Eigenvectors
Row or col umn vector nwin i s speci fi ed as a scal ar
i nteger.
nwin
Row or col umn vector nwin i s speci fi ed as a
vector.
length(nwin)
Row or col umn vector nwin i s not speci fi ed. 2*p(1)
l-by-m matri x I f nwin i s speci fi ed as a
scal ar, i t i s not used. I f
nwin i s speci fi ed as a
vector, length(nwin) must
equal m.
m
m-by-m nonnegati ve
defi ni te matri x
The stri ng 'corr' i s
speci fi ed and nwin i s not
used.
m
pmusic
7-336
Examples Ex a mple 1 : pmusic w ith no Sa mpling Specified
Thi s exampl e anal yzes a si gnal vector x, assumi ng that two real si nusoi dal
components are present i n the si gnal subspace. I n thi s case, the di mensi on of
the si gnal subspace i s 4 because each real si nusoi d i s the sum of two compl ex
exponenti al s.
randn('state',0);
n = 0:199;
x = cos(0.257*pi*n) + sin(0.2*pi*n) + 0.01*randn(size(n));
pmusic(x,4)
Ex a mple 2 : Specifying Sa mpling Frequency a nd Subspa ce Dimensions
Thi s exampl e anal yzes the same si gnal vector x wi th an ei genval ue cutoff of
10% above the mi ni mum. Setti ng p(1) = Inf forces the si gnal /noi se subspace
deci si on to be based on the threshol d parameter p(2). Speci fy the ei genvectors
of l ength 7 usi ng the nwin argument, and set the sampl i ng frequency fs to
8 kHz.
randn('state',0);
n = 0:199;
x = cos(0.257*pi*n) + sin(0.2*pi*n) + 0.01*randn(size(n));
[P,f] = pmusic(x,[Inf,1.1],[],8000,7); % Window length = 7
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
10
0
10
20
30
40
50
60
Normalized Frequency ( rad/sample)
d
B
MUSIC Pseudospectrum
pmusic
7-337
Ex a mple 3 : Entering a Correla tion M a trix
Suppl y a posi ti ve defi ni te correl ati on matri x R for esti mati ng the spectral
densi ty. Use the defaul t 256 sampl es.
R = toeplitz(cos(0.1*pi*[0:6])) + 0.1*eye(7);
[P,f] = pmusic(R,4,'corr');
Ex a mple 4 : Entering a Signa l Da ta M a trix Genera ted from corr mtx
Enter a si gnal data matri x Xm generated from data usi ng corrmtx.
randn('state',0);
n = 0:699;
x = cos(0.257*pi*(n)) + 0.1*randn(size(n));
Xm = corrmtx(x,7,'mod');
[P,w] = pmusic(Xm,2);
Ex a mple 5 : Using W indow ing to Crea te the Ef fect of a Signa l Da ta M a trix
Use the same si gnal , but l et pmusic form the 100-by-7 data matri x usi ng i ts
wi ndowi ng i nput arguments. I n addi ti on, speci fy an FFT of l ength 512.
randn('state',0);
n = 0:699;
x = cos(0.257*pi*(n)) + 0.1*randn(size(n));
[PP,ff] = pmusic(x,2,512,[],7,0);
Algorithm The name MUSI C i s an acronym for MUl ti pl e SI gnal Cl assi fi cati on. The
MUSI C al gori thm esti mates the pseudospectrum from a si gnal or a correl ati on
matri x usi ng Schmi dts ei genspace anal ysi s method [1]. The al gori thm
performs ei genspace anal ysi s of the si gnal s correl ati on matri x i n order to
esti mate the si gnal s frequency content. Thi s al gori thm i s parti cul arl y sui tabl e
for si gnal s that are the sum of si nusoi ds wi th addi ti ve whi te Gaussi an noi se.
The ei genval ues and ei genvectors of the si gnal s correl ati on matri x are
esti mated i f you dont suppl y the correl ati on matri x.
The MUSI C pseudospectrum esti mate i s gi ven by
P
music
f ( )
1
e
H
f ( ) v
k
v
k
H
k 1
N

,


_
e f ( )
----------------------------------------------------------------
1
v
k
H
e f ( )
2
k p 1 +
N

------------------------------------------- = =
pmusic
7-338
where N i s the di mensi on of the ei genvectors and v
k
i s the k-th ei genvector of
the correl ati on matri x. The i nteger p i s the di mensi on of the si gnal subspace,
so the ei genvectors v
k
used i n the sum correspond to the smal l est ei genval ues
and al so span the noi se subspace. The vector e(f) consi sts of compl ex
exponenti al s, so the i nner product
amounts to a Fouri er transform. Thi s i s used for computati on of the
pseudospectrum esti mate. The FFT i s computed for each v
k
and then the
squared magni tudes are summed.
See Also corrmtx, pburg, peig, periodogram, pmtm, prony, psdplot, pwelch, rooteig,
rootmusic
References [1] Marpl e, S.L. Digital Spectral Analysis, Engl ewood Cl i ffs, NJ, Prenti ce-Hal l ,
1987, pp. 373-378.
[2] Schmi dt, R.O, Mul ti pl e Emi tter Locati on and Si gnal Parameter
Esti mati on, I EEE Trans. Antennas Propagation, Vol . AP-34 (March 1986),
pp. 276-280.
[3] Stoi ca, P., and R.L. Moses, I ntroduction to Spectral Analysis, Prenti ce-Hal l ,
Engl ewood Cl i ffs, NJ, 1997.
v
k
H
e f ( )
poly2ac
7-339
7pol y2ac
Purpose Convert a predi cti on fi l ter pol ynomi al to an autocorrel ati on sequence
Syntax r = poly2ac(a,efinal)
Description r = poly2ac(a,efinal) fi nds the autocorrel ati on vector r correspondi ng to
the predi cti on fi l ter pol ynomi al a. The autocorrel ati on sequence produced i s
approxi matel y the same as that of the output of the autoregressi ve predi cti on
fi l ter whose coeffi ci ents are determi ned by a. poly2ac al so produces the fi nal
length(r) step predi cti on error efinal. I f a(1) i s not equal to 1, poly2ac
normal i zes the predi cti on fi l ter pol ynomi al by a(1). a(1) cannot be 0.
Remarks You can appl y thi s functi on to both real and compl ex pol ynomi al s.
Examples a = [1.0000 0.6147 0.9898 0.0004 0.0034 -0.0077];
efinal = 0.2;
r = poly2ac(a,efinal)
r =
5.5917
-1.7277
-4.4231
4.3985
1.6426
-5.3126
See Also ac2poly, poly2rc, rc2ac
References [1] Kay, S.M. Modern Spectral Estimation, Engl ewood Cl i ffs, NJ,
Prenti ce-Hal l , 1988.
poly2lsf
7-340
7pol y2l sf
Purpose Convert predi cti on fi l ter coeffi ci ents to l i ne spectral frequenci es
Syntax lsf = poly2lsf(a)
Description lsf = poly2lsf(a) returns a vector lsf of l i ne spectral frequenci es (al so
known as l i ne spectrum pai rs) from a vector a of predi cti on fi l ter coeffi ci ents.
Examples a = [1.0000 0.6149 0.9899 0.0000 0.0031 -0.0082];
lsf = poly2lsf(a)
lsf =
0.7842
1.5605
1.8776
1.8984
2.3593
See Also lsf2poly
References [1] Del l er, J.R., J.G. Proaki s, and J.H.L. Hansen, Discrete-Time Processing of
Speech Signals, Prenti ce-Hal l , 1993.
[2] Rabi ner, L.R., and R.W. Schafer, Digital Processing of Speech Signals,
Prenti ce-Hal l , 1978.
poly2rc
7-341
7pol y2rc
Purpose Convert a predi cti on fi l ter pol ynomi al to refl ecti on coeffi ci ents
Syntax k = poly2rc(a)
[k,r0] = poly2rc(a,efinal)
Description k = poly2rc(a) converts the predi cti on fi l ter pol ynomi al a to the refl ecti on
coeffi ci ents of the correspondi ng l atti ce structure. a can be real or compl ex, and
a(1) cannot be 0. I f a(1) i s not equal to 1, poly2rc normal i zes the predi cti on
fi l ter pol ynomi al by a(1). k i s a row vector of si ze length(a)-1.
[k,r0] = poly2rc(a,efinal) returns the zero-l ag autocorrel ati on, r0, based
on the fi nal predi cti on error, efinal.
A si mpl e, fast way to check i f a has al l of i ts roots i nsi de the uni t ci rcl e i s to
check i f each of the el ements of k has magni tude l ess than 1.
stable = all(abs(poly2rc(a))<1)
Examples a = [1.0000 0.6149 0.9899 0.0000 0.0031 -0.0082];
efinal = 0.2;
[k,r0] = poly2rc(a,efinal)
k =
0.3090
0.9801
0.0031
0.0081
-0.0082
r0 =
5.6032
Limitations I f abs(k(i)) == 1 for any i, fi ndi ng the refl ecti on coeffi ci ents i s an
i l l -condi ti oned probl em. poly2rc returns some NaNs and provi de a warni ng
message i n thi s case.
poly2rc
7-342
Algorithm poly2rc i mpl ements the recursi ve rel ati onshi p
Thi s rel ati onshi p i s based on Levi nsons recursi on [1]. To i mpl ement i t,
poly2rc l oops through a i n reverse order after di scardi ng i ts fi rst el ement. For
each l oop i terati on i, the functi on:
1 Sets k(i) equal to a(i)
2 Appl i es the second rel ati onshi p above to el ements 1 through i of the
vector a.
a = (ak(i)*fliplr(a))/(1k(i)^2);
See Also ac2rc, latc2tf, latcfilt, poly2ac, rc2poly, tf2latc
References [1] Kay, S.M. Modern Spectral Estimation, Engl ewood Cl i ffs, NJ,
Prenti ce-Hal l , 1988.
k n ( ) a
n
n ( ) =
a
n 1
m ( )
a
n
m ( ) k n ( )a
n
n m ( )
1 k n ( )
2

---------------------------------------------------------- m 1 = 2 n 1 , , , , =
polyscale
7-343
7pol yscal e
Purpose Scal e the roots of a pol ynomi al
Syntax b = polyscale(a,alpha)
Description b = polyscale(a,alpha) scal es the roots of a pol ynomi al i n the z-pl ane,
where a i s a vector contai ni ng the pol ynomi al coeffi ci ents and alpha i s the
scal i ng factor.
I f alpha i s a real val ue i n the range [0 1], then the roots of a are radi al l y scal ed
toward the ori gi n i n the z-pl ane. Compl ex val ues for alpha al l ow arbi trary
changes to the root l ocati ons.
Remark By reduci ng the radi us of the roots i n an autoregressi ve pol ynomi al , the
bandwi dth of the spectral peaks i n the frequency response i s expanded
(fl attened). Thi s operati on i s often referred to as bandwidth expansion.
See Also polystab, roots
polystab
7-344
7pol ystab
Purpose Stabi l i ze pol ynomi al
Syntax b = polystab(a)
Description polystab stabi l i zes a pol ynomi al wi th respect to the uni t ci rcl e; i t refl ects roots
wi th magni tudes greater than 1 i nsi de the uni t ci rcl e.
b = polystab(a) returns a row vector b contai ni ng the stabi l i zed pol ynomi al ,
where a i s a vector of pol ynomi al coeffi ci ents, normal l y i n the z-domai n.
Examples polystab can convert a l i near-phase fi l ter i nto a mi ni mum-phase fi l ter wi th
the same magni tude response.
h = fir1(25,0.4);
hmin = polystab(h) * norm(h)/norm(polystab(h));
Algorithm polystab fi nds the roots of the pol ynomi al and maps those roots found outsi de
the uni t ci rcl e to the i nsi de of the uni t ci rcl e.
v = roots(a);
vs = 0.5*(sign(abs(v)-1)+1);
v = (1-vs).*v + vs./conj(v);
b = a(1)*poly(v);
See Also roots
a z ( ) a 1 ( ) a 2 ( )z
1
L a m 1 + ( )z
m
+ + + =
prony
7-345
7prony
Purpose Pronys method for ti me domai n I I R fi l ter desi gn
Syntax [b,a] = prony(h,n,m)
Description Pronys method i s an al gori thm for fi ndi ng an I I R fi l ter wi th a prescri bed ti me
domai n i mpul se response. I t has appl i cati ons i n fi l ter desi gn, exponenti al
si gnal model i ng, and system i denti fi cati on (parametri c model i ng).
[b,a] = prony(h,n,m) fi nds a fi l ter wi th numerator order n, denomi nator
order m, and the ti me domai n i mpul se response i n h. I f the l ength of h i s l ess
than the l argest order (n or m), h i s padded wi th zeros. prony returns the fi l ter
coeffi ci ents i n row vectors b and a, of l ength n + 1 and m + 1, respecti vel y. The
fi l ter coeffi ci ents are i n descendi ng powers of z.
Examples Recover the coeffi ci ents of a Butterworth fi l ter from i ts i mpul se response.
[b,a] = butter(4,0.2)
b =
0.0048 0.0193 0.0289 0.0193 0.0048
a =
1.0000 -2.3695 2.3140 -1.0547 0.1874
h = filter(b,a,[1 zeros(1,25)]);
[bb,aa] = prony(h,4,4)
bb =
0.0048 0.0193 0.0289 0.0193 0.0048
ab =
1.0000 -2.3695 2.3140 -1.0547 0.1874
Algorithm prony i mpl ements the method descri bed i n reference [1]. Thi s method uses a
vari ati on of the covari ance method of AR model i ng to fi nd the denomi nator
coeffi ci ents a and then fi nds the numerator coeffi ci ents b for whi ch the i mpul se
H z ( )
B z ( )
A z ( )
-----------
b 1 ( ) b 2 ( )z
1
L b n 1 + ( )z
n
+ + +
a 1 ( ) a 2 ( )z
1
L a m 1 + ( )z
m
+ + +
---------------------------------------------------------------------------------------- = =
prony
7-346
response of the output fi l ter matches exactl y the fi rst n + 1 sampl es of x. The
fi l ter i s not necessari l y stabl e, but potenti al l y can recover the coeffi ci ents
exactl y i f the data sequence i s trul y an autoregressi ve movi ng average (ARMA)
process of the correct order.
See Also butter, cheby1, cheby2, ellip, invfreqz, levinson, lpc, stmcb
References [1] Parks, T.W., and C.S. Burrus, Digital Filter Design, John Wi l ey & Sons,
1987, pp. 226-228.
psdplot
7-347
7psdpl ot
Purpose Pl ot power spectral densi ty (PSD) data
Syntax psdplot(Pxx,w)
psdplot(Pxx,w,'units')
psdplot(Pxx,w,'units','yscale')
psdplot(Pxx,w,'units','yscale','title')
Description psdplot(Pxx,w) pl ots the power spectral densi ty data contai ned i n the vector
Pxx at the frequenci es speci fi ed i n the vector w. The vectors Pxx and w must
have the same l ength. The magni tude of the data vector Pxx i s pl otted i n dB per
radi ans per sampl e versus frequency w on one pl ot. The uni ts for frequency on
the pl ots are rad/sampl e.
psdplot(Pxx,w,'units') di spl ays the frequency uni ts accordi ng to the stri ng
'units'. Thi s stri ng can be ei ther:
'rad/sample' (defaul t)
'Hz'
psdplot(Pxx,w,'units','yscale') di spl ays the spectral densi ty magni tude
uni ts accordi ng to the stri ng 'yscale'. Thi s stri ng can be ei ther:
'db' (defaul t), for pl otti ng the PSD i n dB per uni ts of frequency
'linear', for pl otti ng the PSD i n uni ts of power per uni ts of frequency
psdplot(Pxx,w,'units','yscale','title') uses the contents of the stri ng
'title' as the ti tl e of the pl ot.
Examples t = 0:0.001:0.3;
x = cos(2*pi*t*200) + randn(size(t));
[Pxx,w] = periodogram(x,[],'twosided',512);
psdplot(Pxx,w,'','','Sample PSD Plot')
psdplot
7-348
See Also freqzplot, pburg, pcov, peig, periodogram, pmcov, pmusic, pwelch, pyulear
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8
35
30
25
20
15
10
5
0
5
10
15
Normalized Frequency ( rad/sample)
P
o
w
e
r

S
p
e
c
t
r
a
l

D
e
n
s
i
t
y

(
d
B
/

r
a
d
/
s
a
m
p
l
e
)
Sample PSD Plot
pulstran
7-349
7pul stran
Purpose Generate a pul se trai n
Syntax y = pulstran(t,d,'func')
y = pulstran(t,d,'func',p1,p2,...)
y = pulstran(t,d,p,fs)
y = pulstran(t,d,p)
Description pulstran generates pul se trai ns from conti nuous functi ons or sampl ed
prototype pul ses.
y = pulstran(t,d,'func') generates a pul se trai n based on sampl es of a
conti nuous functi on, 'func', where 'func' i s:
'gauspuls', for generati ng a Gaussi an-modul ated si nusoi dal pul se
'rectpuls', for generati ng a sampl ed aperi odi c rectangl e
'tripuls', for generati ng a sampl ed aperi odi c tri angl e
pulstran i s eval uated length(d) ti mes and returns the sum of the eval uati ons
y = func(t-d(1)) + func(t-d(2)) + ...
The functi on i s eval uated over the range of argument val ues speci fi ed i n
array t, after removi ng a scal ar argument offset taken from the vector d. Note
that func must be a vectori zed functi on that can take an array t as an
argument.
An opti onal gai n factor may be appl i ed to each del ayed eval uati on by speci fyi ng
d as a two-col umn matri x, wi th the offset defi ned i n col umn 1 and associ ated
gai n i n col umn 2 of d. Note that a row vector wi l l be i nterpreted as speci fyi ng
del ays onl y.
pulstran(t,d,'func',p1,p2,...) al l ows addi ti onal parameters to be passed
to 'func' as necessary. For exampl e,
func(t-d(1),p1,p2,...) + func(t-d(2),p1,p2,...) + ...
pulstran(t,d,p,fs) generates a pul se trai n that i s the sum of mul ti pl e
del ayed i nterpol ati ons of the prototype pul se i n vector p, sampl ed at the
rate fs, where p spans the ti me i nterval [0,(length(p)-1)/fs], and i ts
sampl es are i denti cal l y 0 outsi de thi s i nterval . By defaul t, l i near i nterpol ati on
i s used for generati ng del ays.
pulstran
7-350
pulstran(t,d,p) assumes that the sampl i ng rate fs i s equal to 1 Hz.
pulstran(...,'func') speci fi es al ternati ve i nterpol ati on methods. See
interp1 for a l i st of avai l abl e methods.
Examples Ex a mple 1
Thi s exampl e generates an asymmetri c sawtooth waveform wi th a repeti ti on
frequency of 3 Hz and a sawtooth wi dth of 0.1s. I t has a si gnal l ength of 1s and
a 1 kHz sampl e rate.
t = 0 : 1/1e3 : 1; % 1 kHz sample freq for 1 sec
d = 0 : 1/3 : 1; % 3 Hz repetition freq
y = pulstran(t,d,'tripuls',0.1,-1);
plot(t,y)
0 0.2 0.4 0.6 0.8 1
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
pulstran
7-351
Ex a mple 2
Thi s exampl e generates a peri odi c Gaussi an pul se si gnal at 10 kHz, wi th 50%
bandwi dth. The pul se repeti ti on frequency i s 1 kHz, sampl e rate i s 50 kHz, and
pul se trai n l ength i s 10 msec. The repeti ti on ampl i tude shoul d attenuate by 0.8
each ti me.
t = 0 : 1/50E3 : 10e-3;
d = [0 : 1/1E3 : 10e-3 ; 0.8.^(0:10)]';
y = pulstran(t,d,'gauspuls',10e3,0.5);
plot(t,y)
0 0.002 0.004 0.006 0.008 0.01
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
pulstran
7-352
Ex a mple 3
Thi s exampl e generates a trai n of 10 Hammi ng wi ndows.
p = hamming(32);
t = 0:320; d = (0:9)'*32;
y = pulstran(t,d,p);
plot(t,y)
See Also chirp, cos, diric, gauspuls, rectpuls, sawtooth, sin, sinc, square, tripuls
0 50 100 150 200 250 300 350
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
pwelch
7-353
7pwel ch
Purpose Esti mate the power spectral densi ty (PSD) of a si gnal usi ng Wel chs method
Syntax [Pxx,w] = pwelch(x)
[Pxx,w] = pwelch(x,window)
[Pxx,w] = pwelch(x,window,noverlap)
[Pxx,w] = pwelch(x,window,noverlap,nfft)
[Pxx,f] = pwelch(x,window,noverlap,nfft,fs)
[...] = pwelch(x,window,noverlap,...,'range')
pwelch(...)
Description Note pwelch computes the power spectral densi ty, not the power spectrum.
The di fference between them i s di scussed i n Spectral Anal ysi s on page 3-6.
[Pxx,w] = pwelch(x) esti mates the power spectral densi ty Pxx of the i nput
si gnal vector x usi ng Wel chs averaged modi fi ed peri odogram method of
spectral esti mati on. Wi th thi s syntax:
The vector x i s segmented i nto ei ght secti ons of equal l ength, each wi th 50%
overl ap.
Any remai ni ng (trai l i ng) entri es i n x that cannot be i ncl uded i n the ei ght
segments of equal l ength are di scarded.
Each segment i s wi ndowed wi th a Hammi ng wi ndow (see hamming) that i s
the same l ength as the segment.
The power spectral densi ty i s cal cul ated i n uni ts of power per radi ans per
sampl e. The correspondi ng vector of frequenci es w i s computed i n radi ans per
sampl e, and has the same l ength as Pxx.
A real -val ued i nput vector x produces a ful l power one-si ded (i n frequency) PSD
(by defaul t), whi l e a compl ex-val ued x produces a two-si ded PSD.
I n general , the l ength N of the FFT and the val ues of the i nput x determi ne the
l ength of Pxx and the range of the correspondi ng normal i zed frequenci es. For
thi s syntax, the (defaul t) l ength N of the FFT i s the l arger of 256 and the next
power of two greater than the l ength of the segment. The fol l owi ng tabl e
pwelch
7-354
i ndi cates the l ength of Pxx and the range of the correspondi ng normal i zed
frequenci es for thi s syntax.
[Pxx,w] = pwelch(x,window) cal cul ates the modi fi ed peri odogram usi ng
ei ther:
The wi ndow l ength window for the Hammi ng wi ndow when window i s a
posi ti ve i nteger
The wi ndow wei ghts speci fi ed i n window when window i s a vector
Wi th thi s syntax, the i nput vector x i s di vi ded i nto an i nteger number of
segments wi th 50% overl ap, and each segment i s the same l ength as the
wi ndow. Entri es i n x that are l eft over after i t i s di vi ded i nto segments are
di scarded. I f you speci fy window as the empty vector [], then the si gnal data i s
di vi ded i nto ei ght segments, and a Hammi ng wi ndow i s used on each one.
[Pxx,w] = pwelch(x,window,noverlap) di vi des x i nto segments accordi ng to
window, and uses the i nteger noverlap to speci fy the number of si gnal sampl es
(el ements of x) that are common to two adjacent segments. noverlap must be
l ess than the l ength of the wi ndow you speci fy. I f you speci fy noverlap as the
empty vector [], then pwelch determi nes the segments of x so that there i s 50%
overl ap (defaul t).
[Pxx,w] = pwelch(x,window,noverlap,nfft) uses Wel chs method to
esti mate the PSD whi l e speci fyi ng the l ength of the FFT wi th the i nteger nfft.
I f you set nfft to the empty vector [], i t adopts the defaul t val ue for N l i sted
i n the previ ous syntax.
Table 7-34: PSD Vector Characteristics for an FFT Length of N (Default)
Real/ Complex
Input Data
Length of Pxx Range of the Corresponding
Normalized Frequencies
Real -val ued (N/2) +1 [0, ]
Compl ex-val ued N [0, 2)
pwelch
7-355
The l ength of Pxx and the frequency range for w depend on nfft and the val ues
of the i nput x. The fol l owi ng tabl e i ndi cates the l ength of Pxx and the frequency
range for w for thi s syntax.
[Pxx,f] = pwelch(x,window,noverlap,nfft,fs) uses the sampl i ng
frequency fs speci fi ed i n hertz (Hz) to compute the PSD vector (Pxx) and the
correspondi ng vector of frequenci es (f). I n thi s case, the uni ts for the frequency
vector are i n Hz. The spectral densi ty produced i s cal cul ated i n uni ts of power
per Hz. I f you speci fy fs as the empty vector [], the sampl i ng frequency
defaul ts to 1 Hz.
The frequency range for f depends on nfft, fs, and the val ues of the i nput x.
The l ength of Pxx i s the same as i n Tabl e 7-35. The fol l owi ng tabl e i ndi cates the
frequency range for f for thi s syntax.
Table 7-35: PSD and Frequency Vector Characteristics
Real/ Complex
Input Data
nfft Even/ Odd Length of Pxx Range of w
Real -val ued Even (nfft/2 + 1) [0, ]
Real -val ued Odd (nfft + 1)/2 [0, )
Compl ex-val ued Even or odd nfft [0, 2)
Table 7-36: PSD and Frequency Vector Characteristics with fs Specified
Real/ Complex Input Data nfft Even/ Odd Range of f
Real -val ued Even [0,fs/2]
Real -val ued Odd [0,fs/2)
Compl ex-val ued Even or odd [0,fs)
pwelch
7-356
[...] = pwelch(x,window,noverlap,...,'range') speci fi es the range of
frequency val ues. Thi s syntax i s useful when x i s real . The stri ng 'range' can
be ei ther:
'twosided': Compute the two-si ded PSD over the frequency range [0,fs).
Thi s i s the defaul t for determi ni ng the frequency range for
compl ex-val ued x.
- I f you speci fy fs as the empty vector, [], the frequency range i s [0,1).
- I f you dont speci fy fs, the frequency range i s [0, 2).
'onesided': Compute the one-si ded PSD over the frequency ranges speci fi ed
for real x. Thi s i s the defaul t for determi ni ng the frequency range for
real -val ued x.
The stri ng 'range' can appear anywhere i n the syntax after noverlap.
pwelch(x,...) wi th no output arguments pl ots the PSD esti mate i n dB per
uni t frequency i n the current fi gure wi ndow.
Examples Esti mate the PSD of a si gnal composed of a si nusoi d pl us noi se, sampl ed at
1000 Hz. Use 33-sampl e wi ndows wi th 32-sampl e overl ap, and the defaul t FFT
l ength, and di spl ay the two-si ded PSD esti mate.
randn('state',0);
Fs = 1000; t = 0:1/Fs:.3;
x = cos(2*pi*t*200) + randn(size(t)); % 200Hz cosine plus noise
pwelch(x,33,32,[],Fs,'twosided')
pwelch
7-357
Algorithm pwelch cal cul ates the power spectral densi ty usi ng Wel chs method (see
references):
1 The i nput si gnal vector x i s di vi ded i nto k overl appi ng segments accordi ng
to window and noverlap (or thei r defaul t val ues).
2 The speci fi ed (or defaul t) wi ndow i s appl i ed to each segment of x.
3 An nfft-poi nt FFT i s appl i ed to the wi ndowed data.
4 The (modi fi ed) peri odogram of each wi ndowed segment i s computed.
5 The set of modi fi ed peri odograms i s averaged to form the spectrum esti mate
S(e
j
).
6 The resul ti ng spectrum esti mate i s scal ed to compute the power spectral
densi ty as , where F i s:
- 2 when you do not suppl y the sampl i ng frequency
- fs when you suppl y the sampl i ng frequency
0 100 200 300 400 500 600 700 800 900
34
32
30
28
26
24
22
Frequency (Hz)
P
o
w
e
r

S
p
e
c
t
r
a
l

D
e
n
s
i
t
y

(
d
B
/
H
z
)
Welch PSD Estimate
S e
j
( ) F
pwelch
7-358
The number of segments k that x i s di vi ded i nto i s cal cul ated as:
Ei ght i f you dont speci fy window, or i f you speci fy i t as the empty vector []
i f you speci fy window as a nonempty vector or a scal ar
I n thi s equati on, m i s the l ength of the si gnal vector x, o i s the number of
overl appi ng sampl es (noverlap), and l i s the l ength of each segment (the
wi ndow l ength).
See Also pburg, pcov, peig, periodogram, pmcov, pmtm, pmusic, psdplot, pyulear
References [1] Hayes, M., Statistical Digital Signal Processing and Modeling, John Wi l ey
& Sons, 1996.
[2] Stoi ca, P., and R.L. Moses, I ntroduction to Spectral Analysis, Prenti ce-Hal l ,
Engl ewood Cl i ffs, NJ, 1997, pp. 52-54.
[3] Wel ch, P.D, The Use of Fast Fouri er Transform for the Esti mati on of Power
Spectra: A Method Based on Ti me Averagi ng Over Short, Modi fi ed
Peri odograms, I EEE Trans. Audio Electroacoustics, Vol . AU-15 (June 1967),
pp. 70-73.
k
m o
l o
-------------- =
pyulear
7-359
7pyul ear
Purpose Esti mate the power spectral densi ty usi ng the Yul e-Wal ker AR method
Syntax Pxx = pyulear(x,p)
[Pxx,w] = pyulear(x,p,nfft)
[Pxx,f] = pyulear(x,p,nfft,fs)
[Pxx,f] = pyulear(x,p,nfft,fs,'range')
[Pxx,w] = pyulear(x,p,nfft,'range')
pyulear(...)
Description Pxx = pyulear(x,p) i mpl ements the Yul e-Wal ker al gori thm, a parametri c
spectral esti mati on method, and returns Pxx, an esti mate of the power spectral
densi ty (PSD) of the vector x. The entri es of x represent sampl es of a
di screte-ti me si gnal . p i s the i nteger speci fyi ng the order of an autoregressi ve
(AR) predi cti on model for the si gnal , used i n esti mati ng the PSD.
The power spectral densi ty i s cal cul ated i n uni ts of power per radi ans per
sampl e. Real -val ued i nputs produce ful l power one-si ded (i n frequency) PSDs
(by defaul t), whi l e compl ex-val ued i nputs produce two-si ded PSDs.
I n general , the l ength of the FFT and the val ues of the i nput x determi ne the
l ength of Pxx and the range of the correspondi ng normal i zed frequenci es. For
thi s syntax, the (defaul t) FFT l ength i s 256. The fol l owi ng tabl e i ndi cates the
l ength of Pxx and the range of the correspondi ng normal i zed frequenci es for
thi s syntax.
[Pxx,w] = pyulear(x,p) al so returns w, a vector of frequenci es at whi ch the
PSD i s esti mated. Pxx and w have the same l ength. The uni ts for frequency are
rad/sampl e.
Table 7-37: PSD Vector Characteristics for an FFT Length of 256 (Default)
Real/ Complex
Input Data
Length of Pxx Range of the Corresponding
Normalized Frequencies
Real -val ued 129 [0, ]
Compl ex-val ued 256 [0, 2)
pyulear
7-360
[Pxx,w] = pyulear(x,p,nfft) uses the Yul e-wal ker method to esti mate the
PSD whi l e speci fyi ng the l ength of the FFT wi th the i nteger nfft. I f you speci fy
nfft as the empty vector [], i t adopts the defaul t val ue of 256.
The l ength of Pxx and the frequency range for w depend on nfft and the val ues
of the i nput x. The fol l owi ng tabl e i ndi cates the l ength of Pxx and the frequency
range for w for thi s syntax.
[Pxx,f] = pyulear(x,p,nfft,fs) uses the sampl i ng frequency fs speci fi ed
as an i nteger i n hertz (Hz) to compute the PSD vector (Pxx) and the
correspondi ng vector of frequenci es (f). I n thi s case, the uni ts for the frequency
vector are i n Hz. The spectral densi ty produced i s cal cul ated i n uni ts of power
per Hz. I f you speci fy fs as the empty vector [], the sampl i ng frequency
defaul ts to 1 Hz.
The frequency range for f depends on nfft, fs, and the val ues of the i nput x.
The l ength of Pxx i s the same as i n Tabl e 7-38. The fol l owi ng tabl e i ndi cates the
frequency range for f for thi s syntax.
Table 7-38: PSD and Frequency Vector Characteristics
Real/ Complex
Input Data
nfft Even/ Odd Length of Pxx Range of w
Real -val ued Even (nfft/2 + 1) [0, ]
Real -val ued Odd (nfft + 1)/2 [0, )
Compl ex-val ued Even or odd nfft [0, 2)
Table 7-39: PSD and Frequency Vector Characteristics with fs Specified
Real/ Complex Input Data nfft Even/ Odd Range of f
Real -val ued Even [0,fs/2]
Real -val ued Odd [0,fs/2)
Compl ex-val ued Even or odd [0,fs)
pyulear
7-361
[Pxx,f] = pyulear(x,p,nfft,fs,'range') or
[Pxx,w] = pyulear(x,p,nfft,'range') speci fi es the range of frequency
val ues to i ncl ude i n f or w. Thi s syntax i s useful when x i s real . 'range' can be
ei ther:
'twosided': Compute the two-si ded PSD over the frequency range [0,fs).
Thi s i s the defaul t for determi ni ng the frequency range for
compl ex-val ued x.
- I f you speci fy fs as the empty vector, [], the frequency range i s [0,1).
- I f you dont speci fy fs, the frequency range i s [0, 2).
'onesided': Compute the one-si ded PSD over the frequency ranges speci fi ed
for real x. Thi s i s the defaul t for determi ni ng the frequency range for
real -val ued x.
Note You can put the stri ng argument 'range' anywhere i n the i nput
argument l i st after p.
pyulear(...) pl ots the power spectral densi ty i n the current fi gure wi ndow.
The frequency range on the pl ot i s the same as the range of output w (or f) for
a gi ven set of parameters.
Remarks The power spectral densi ty i s computed as the di stri buti on of power per uni t
frequency.
Thi s al gori thm depends on your sel ecti ng an appropri ate model order for your
si gnal .
Examples Because the Yul e-wal ker method esti mates the spectral densi ty by fi tti ng an
AR predi cti on model of a gi ven order to the si gnal , fi rst generate a si gnal from
an AR (al l -pol e) model of a gi ven order. You can use freqz to check the
magni tude of the frequency response of your AR fi l ter. Thi s wi l l gi ve you an
i dea of what to expect when you esti mate the PSD usi ng pyulear.
a = [1 -2.2137 2.9403 -2.1697 0.9606]; % AR filter coefficients
freqz(1,a) % AR filter frequency response
title('AR System Frequency Response')
pyulear
7-362
Now generate the i nput si gnal x by fi l teri ng whi te noi se through the AR fi l ter.
Esti mate the PSD of x based on a fourth-order AR predi cti on model , si nce i n
thi s case, we know that the ori gi nal AR system model a has order 4.
randn('state',1);
x = filter(1,a,randn(256,1)); % AR system output
pyulear(x,4) % Fourth-order estimate
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
200
150
100
50
0
50
100
Normalized Frequency ( rad/sample)
P
h
a
s
e

(
d
e
g
r
e
e
s
)
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
20
10
0
10
20
30
40
Normalized Frequency ( rad/sample)
M
a
g
n
i
t
u
d
e

(
d
B
)
AR System Frequency Response
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
25
20
15
10
5
0
5
10
15
20
25
Normalized Frequency ( rad/sample)
P
o
w
e
r

S
p
e
c
t
r
a
l

D
e
n
s
i
t
y

(
d
B
/

r
a
d
/
s
a
m
p
l
e
)
YuleWalker PSD Estimate
pyulear
7-363
Algorithm Li near predi cti on fi l ters can be used to model the second-order stati sti cal
characteri sti cs of a si gnal . The predi cti on fi l ter output can be used to model the
si gnal when the i nput i s whi te noi se.
pyulear esti mates the PSD of an i nput si gnal vector usi ng the Yul e-Wal ker AR
method. Thi s method, al so cal l ed the autocorrel ati on or wi ndowed method, fi ts
an autoregressi ve (AR) l i near predi cti on fi l ter model to the si gnal by
mi ni mi zi ng the forward predi cti on error (based on al l observati ons of the i n put
sequence) i n the l east squares sense. Thi s formul ati on l eads to the
Yul e-Wal ker equati ons, whi ch are sol ved by the Levi nson-Durbi n recursi on.
The spectral esti mate returned by pyulear i s the squared magni tude of the
frequency response of thi s AR model .
See Also aryule, lpc, pburg, pcov, peig, periodogram, pmcov, pmtm, pmusic, prony,
psdplot, pwelch
References [1] Marpl e, S.L., Digital Spectral Analysis, Prenti ce-Hal l , 1987, Chapter 7.
[2] Stoi ca, P., and R.L. Moses, I ntroduction to Spectral Analysis, Prenti ce-Hal l ,
1997.
rc2ac
7-364
7rc2ac
Purpose Convert refl ecti on coeffi ci ents to an autocorrel ati on sequence
Syntax r = rc2ac(k,r0)
Description r = rc2ac(k,r0) fi nds the autocorrel ati on coeffi ci ents, r, of the output of the
di screte-ti me predi cti on error fi l ter from the l atti ce-form refl ecti on coeffi ci ents
k and i ni ti al zero-l ag autocorrel ati on r0.
Examples k = [0.3090 0.9800 0.0031 0.0082 -0.0082];
r0 = 0.1;
a = rc2ac(k,r0)
a =
0.1000
-0.0309
-0.0791
0.0787
0.0294
-0.0950
See Also ac2rc, poly2ac, rc2poly
References [1] Kay, S.M., Modern Spectral Estimation, Prenti ce-Hal l , Engl ewood Cl i ffs,
NJ, 1988.
rc2is
7-365
7rc2i s
Purpose Convert refl ecti on coeffi ci ents to i nverse si ne parameters
Syntax isin = rc2is(k)
Description isin = is2rc(k) returns a vector of i nverse si ne parameters isin from a
vector of refl ecti on coeffi ci ents k.
Examples k = [0.3090 0.9801 0.0031 0.0082 -0.0082];
isin = rc2is(k)
isin =
0.2000 0.8728 0.0020 0.0052 -0.0052
See Also is2rc
References [1] Del l er, J.R., J.G. Proaki s, and J.H.L. Hansen, Discrete-Time Processing of
Speech Signals, Prenti ce-Hal l , 1993.
rc2lar
7-366
7rc2l ar
Purpose Convert refl ecti on coeffi ci ents to l og area rati o parameters
Syntax g = rc2lar(k)
Description g = rc2lar(k) returns a vector of l og area rati o parameters g from a vector of
refl ecti on coeffi ci ents k.
Examples k = [0.3090 0.9801 0.0031 0.0082 -0.0082];
g = rc2lar(k)
g =
0.6389 4.6002 0.0062 0.0164 -0.0164
See Also lar2rc
References [1] Del l er, J.R., J.G. Proaki s, and J.H.L. Hansen, Discrete-Time Processing of
Speech Signals, Prenti ce-Hal l , 1993.
rc2poly
7-367
7rc2pol y
Purpose Convert refl ecti on coeffi ci ents to a predi cti on fi l ter pol ynomi al
Syntax a = rc2poly(k)
[a,efinal] = rc2poly(k,r0)
Description a = rc2poly(k) converts the refl ecti on coeffi ci ents k correspondi ng to the
l atti ce structure to the predi cti on fi l ter pol ynomi al a, wi th a(1) = 1. The output
a i s row vector of l ength length(k)+1.
[a,efinal] = rc2poly(k,r0) returns the fi nal predi cti on error efinal based
on the zero-l ag autocorrel ati on, r0.
Example Consi der a l atti ce I I R fi l ter gi ven by refl ecti on coeffi ci ents k.
k = [0.3090 0.9800 0.0031 0.0082 -0.0082];
I ts equi val ent predi cti on fi l ter representati on i s gi ven by
a = rc2poly(k)
a =
1.0000 0.6148 0.9899 0.0000 0.0032 -0.0082
Algorithm rc2poly computes output a usi ng Levi nsons recursi on [1]. The functi on:
1 Sets the output vector a to the fi rst el ement of k
2 Loops through the remai ni ng el ements of k
For each l oop i terati on i, a = [a + a(i-1:-1:1)*k(i) k(i)].
3 I mpl ements a = [1 a]
See Also ac2poly, latc2tf, latcfilt, poly2rc, rc2ac, rc2is, rc2lar, tf2latc
References [1] Kay, S.M., Modern Spectral Estimation, Prenti ce-Hal l , Engl ewood Cl i ffs,
NJ, 1988.
rceps
7-368
7rceps
Purpose Real cepstrum and mi ni mum phase reconstructi on
Syntax y = rceps(x)
[y,ym] = rceps(x)
Description The real cepstrum i s the i nverse Fouri er transform of the real l ogari thm of the
magni tude of the Fouri er transform of a sequence.
rceps(x) returns the real cepstrum of the real sequence x. The real cepstrum
i s a real -val ued functi on.
[y,ym] = rceps(x) returns both the real cepstrum y and a mi ni mum phase
reconstructed versi on ym of the i nput sequence.
Algorithm rceps i s an M-fi l e i mpl ementati on of al gori thm 7.2 i n [2], that i s,
y = real(ifft(log(abs(fft(x)))));
Appropri ate wi ndowi ng i n the cepstral domai n forms the reconstructed
mi ni mum phase si gnal .
w = [1; 2*ones(n/2-1,1); ones(1 - rem(n,2),1); zeros(n/2-1,1)];
ym = real(ifft(exp(fft(w.*y))));
See Also cceps, fft, hilbert, icceps, unwrap
References [1] Oppenhei m, A.V., and R.W. Schafer, Digital Signal Processing, Engl ewood
Cl i ffs, NJ, Prenti ce-Hal l , 1975.
[2] Programs for Digital Signal Processing, I EEE Press, New York, 1979.
rectpuls
7-369
7rectpul s
Purpose Generate a sampl ed aperi odi c rectangl e
Syntax y = rectpuls(t)
y = rectpuls(t,w)
Description y = rectpuls(t) returns a conti nuous, aperi odi c, uni ty-hei ght rectangul ar
pul se at the sampl e ti mes i ndi cated i n array t, centered about t = 0 and wi th a
defaul t wi dth of 1. Note that the i nterval of non-zero ampl i tude i s defi ned to be
open on the ri ght, that i s, rectpuls(-0.5) = 1 whi l e rectpuls(0.5) = 0.
y = rectpuls(t,w) generates a rectangl e of wi dth w.
rectpuls i s typi cal l y used i n conjuncti on wi th the pul se trai n generati ng
functi on pulstran.
See Also chirp, cos, diric, gauspuls, pulstran, sawtooth, sin, sinc, square, tripuls
rectwin
7-370
7rectwi n
Purpose Compute a rectangul ar wi ndow
Syntax w = rectwin(n)
Description w = rectwin(n) returns a rectangul ar wi ndow of l ength n i n the col umn
vector w. Thi s functi on i s provi ded for compl eteness; a rectangul ar wi ndow i s
equi val ent to no wi ndow at al l .
Algorithm w = ones(n,1);
See Also barthannwin, bartlett, blackman, blackmanharris, bohmanwin, chebwin,
gausswin, hamming, hann, kaiser, nuttallwin, triang, tukeywin, window
References [1] Oppenhei m, A.V., and R.W. Schafer. Discrete-Time Signal Processing.
Upper Saddl e Ri ver, NJ: Prenti ce-Hal l , 1999, pp. 468-471.
remez
7-371
7remez
Purpose Compute the Parks-McCl el l an opti mal FI R fi l ter desi gn
Syntax b = remez(n,f,a)
b = remez(n,f,a,w)
b = remez(n,f,a,'ftype')
b = remez(n,f,a,w,'ftype')
b = remez(...,{lgrid})
b = remez(n,f,'fresp',w)
b = remez(n,f,'fresp',w,'ftype')
b = remez(n,f,{'fresp',p1,p2,...},w)
b = remez(n,f,{'fresp',p1,p2,...},w,'ftype')
[b,delta] = remez(...)
[b,delta,opt] = remez(...)
Description remez desi gns a l i near-phase FI R fi l ter usi ng the Parks-McCl el l an
al gori thm [1]. The Parks-McCl el l an al gori thm uses the Remez exchange
al gori thm and Chebyshev approxi mati on theory to desi gn fi l ters wi th an
opti mal fi t between the desi red and actual frequency responses. The fi l ters are
opti mal i n the sense that the maxi mum error between the desi red frequency
response and the actual frequency response i s mi ni mi zed. Fi l ters desi gned thi s
way exhi bi t an equi ri ppl e behavi or i n thei r frequency responses and are
someti mes cal l ed equiripple fi l ters. remez exhi bi ts di sconti nui ti es at the head
and tai l of i ts i mpul se response due to thi s equi ri ppl e nature.
b = remez(n,f,a) returns row vector b contai ni ng the n+1 coeffi ci ents of the
order n FI R fi l ter whose frequency-ampl i tude characteri sti cs match those
gi ven by vectors f and a.
The output fi l ter coeffi ci ents (taps) i n b obey the symmetry rel ati on
b k ( ) b n 2 k + ( ) k 1 = n 1 + , , , =
remez
7-372
Vectors f and a speci fy the frequency-magni tude characteri sti cs of the fi l ter:
f i s a vector of pai rs of normal i zed frequency poi nts, speci fi ed i n the range
between 0 and 1, where 1 corresponds to the Nyqui st frequency. The
frequenci es must be i n i ncreasi ng order.
a i s a vector contai ni ng the desi red ampl i tudes at the poi nts speci fi ed i n f.
The desi red ampl i tude at frequenci es between pai rs of poi nts (f(k), f(k+1)) for
k odd i s the l i ne segment connecti ng the poi nts (f(k), a(k)) and
(f(k+1), a(k+1)).
The desi red ampl i tude at frequenci es between pai rs of poi nts (f(k), f(k+1)) for
k even i s unspeci fi ed. The areas between such poi nts are transi ti on or dont
care regi ons.
f and a must be the same l ength. The l ength must be an even number.
The rel ati onshi p between the f and a vectors i n defi ni ng a desi red frequency
response i s shown i n the exampl e bel ow.
remez al ways uses an even fi l ter order for confi gurati ons wi th a passband at
the Nyqui st frequency. Thi s i s because for odd orders, the frequency response
at the Nyqui st frequency i s necessari l y 0. I f you speci fy an odd-val ued n, remez
i ncrements i t by 1.
1.0
0.0
Desired amplitude
response (a)
Normalized
frequency (f)
0.5
"Don't care"/transition regions
f = [0 .3 .4 .6 .7 .9]
a = [0 1 0 0 .5 .5]
0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.0 0.8 0.9 1.0 (Nyquist)
remez
7-373
remez(n,f,a,w) uses the wei ghts i n vector w to wei ght the fi t i n each frequency
band. The l ength of w i s hal f the l ength of f and a, so there i s exactl y one wei ght
per band.
b = remez(n,f,a,'ftype') and
b = remez(n,f,a,w,'ftype') speci fy a fi l ter type, where 'ftype' i s
'hilbert', for l i near-phase fi l ters wi th odd symmetry (type I I I and type I V)
The output coeffi ci ents i n b obey the rel ati on b(k) = -b(n+2-k), k = 1, ...,
n + 1. Thi s cl ass of fi l ters i ncl udes the Hi l bert transformer, whi ch has a
desi red ampl i tude of 1 across the enti re band.
For exampl e,
h = remez(30,[0.1 0.9],[1 1],'hilbert');
desi gns an approxi mate FI R Hi l bert transformer of l ength 31.
'differentiator', for type I I I and type I V fi l ters, usi ng a speci al wei ghti ng
techni que
For nonzero ampl i tude bands, i t wei ghts the error by a factor of 1/f so that
the error at l ow frequenci es i s much smal l er than at hi gh frequenci es. For
FI R di fferenti ators, whi ch have an ampl i tude characteri sti c proporti onal to
frequency, these fi l ters mi ni mi ze the maxi mum rel ati ve error (the maxi mum
of the rati o of the error to the desi red ampl i tude).
b = remez(...,{lgrid}) uses the i nteger lgrid to control the densi ty of the
frequency gri d, whi ch has roughl y (lgrid*n)/(2*bw) frequency poi nts, where
bw i s the fracti on of the total frequency band i nterval [0,1] covered by f.
I ncreasi ng lgrid often resul ts i n fi l ters that more exactl y match an equi ri ppl e
fi l ter, but that take l onger to compute. The defaul t val ue of 16 i s the mi ni mum
val ue that shoul d be speci fi ed for lgrid. Note that the {lgrid} argument must
be a 1-by-1 cel l array.
b = remez(n,f,'fresp',w) returns row vector b contai ni ng the n+1
coeffi ci ents of the order n FI R fi l ter whose frequency-ampl i tude characteri sti cs
best approxi mate the response speci fi ed by functi on fresp. The functi on i s
cal l ed from wi thi n remez wi th the fol l owi ng syntax.
[dh,dw] = fresp(n,f,gf,w)
remez
7-374
The arguments are si mi l ar to those for remez:
n i s the fi l ter order.
f i s the vector of normal i zed frequency band edges that appear monotoni cal l y
between 0 and 1, where 1 i s the Nyqui st frequency.
gf i s a vector of gri d poi nts that have been l i nearl y i nterpol ated over each
speci fi ed frequency band by remez. gf determi nes the frequency gri d at
whi ch the response functi on must be eval uated, and contai ns the same data
returned by cremez i n the fgrid fi el d of the opt structure.
w i s a vector of real , posi ti ve wei ghts, one per band, used duri ng opti mi zati on.
w i s opti onal i n the cal l to remez; i f not speci fi ed, i t i s set to uni ty wei ghti ng
before bei ng passed to fresp.
dh and dw are the desi red compl ex frequency response and band wei ght
vectors, respecti vel y, eval uated at each frequency i n gri d gf.
The predefi ned frequency response functi on fresp that remez cal l s i s remezfrf
i n the signal/private di rectory.
b = remez(n,f,{'fresp',p1,p2,...},w) al l ows you to speci fy addi ti onal
parameters (p1, p2, etc.) to pass to fresp. Note that b = remez(n,f,a,w) i s a
synonym for b = remez(n,f,{'remezfrf',a},w), where a i s a vector
contai ni ng the desi red ampl i tudes at the poi nts speci fi ed i n f.
b = remez(n,f,'fresp',w,'ftype') and
b = remez(n,f,{'fresp',p1,p2,...},w,'ftype') desi gn anti symmetri c
(odd) rather than symmetri c (even) fi l ters, where 'ftype' i s ei ther 'd' for a
di fferenti ator or 'h' for a Hi l bert transformer.
I n the absence of a speci fi cati on for ftype, a prel i mi nary cal l i s made to fresp
to determi ne the defaul t symmetry property sym. Thi s cal l i s made usi ng the
syntax.
sym = fresp('defaults',{n,f,[],w,p1,p2,...})
The arguments n, f, w, etc., may be used as necessary i n determi ni ng an
appropri ate val ue for sym, whi ch remez expects to be ei ther 'even' or 'odd'. I f
the fresp functi on does not support thi s cal l i ng syntax, remez defaul ts to even
symmetry.
remez
7-375
[b,delta] = remez(...) returns the maxi mum ri ppl e hei ght i n delta.
[b,delta,opt] = remez(...) returns a structure wi th the fol l owi ng fi el ds.
Example Graph the desi red and actual frequency responses of a 17th-order
Parks-McCl el l an bandpass fi l ter.
f = [0 0.3 0.4 0.6 0.7 1]; a = [0 0 1 1 0 0];
b = remez(17,f,a);
[h,w] = freqz(b,1,512);
plot(f,a,w/pi,abs(h))
legend('Ideal','remez Design')
opt.fgrid Frequency gri d vector used for the fi l ter desi gn opti mi zati on
opt.des Desi red frequency response for each poi nt i n opt.fgrid
opt.wt Wei ghti ng for each poi nt i n opt.fgrid
opt.H Actual frequency response for each poi nt i n opt.fgrid
opt.error Error at each poi nt i n opt.fgrid (opt.des-opt.H)
opt.iextr Vector of i ndi ces i nto opt.fgrid for extremal frequenci es
opt.fextr Vector of extremal frequenci es
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
0
0.2
0.4
0.6
0.8
1
1.2
1.4
Ideal
remez Design
remez
7-376
Algorithm remez i s a MEX-fi l e versi on of the ori gi nal Fortran code from [1], al tered to
desi gn arbi trari l y l ong fi l ters wi th arbi trari l y many l i near bands.
remez desi gns type I , I I , I I I , and I V l i near-phase fi l ters. Type I and type I I are
the defaul ts for n even and n odd, respecti vel y, whi l e type I I I (n even) and
type I V (n odd) are obtai ned wi th the 'hilbert' and 'differentiator' fl ags.
The di fferent types of fi l ters have di fferent symmetri es and certai n constrai nts
on thei r frequency responses (see [5] for more detai l s).
Diagnostics I f you get the fol l owi ng warni ng message,
- Failure to Converge -
Probable cause is machine rounding error.
i t i s possi bl e that the fi l ter desi gn may sti l l be correct. Veri fy the desi gn by
checki ng i ts frequency response.
See Also butter, cheby1, cheby2, cremez, ellip, fir1, fir2, fircls, fircls1, firls,
firrcos, gremez, remezord, yulewalk
References [1] Programs for Digital Signal Processing, I EEE Press, New York, 1979,
Al gori thm 5.1.
[2] Selected Papers in Digital Signal Processing, I I , I EEE Press, New York,
1979.
[3] Parks, T.W., and C.S. Burrus, Digital Filter Design, John Wi l ey & Sons,
New York:, 1987, p. 83.
Linear Phase
Filter Type
Filter
Order
Symmetry of Coefficients Response H(f),
f = 0
Response H(f),
f = 1 (Nyquist)
Type I Even even: No restri cti on No restri cti on
Type I I Odd No restri cti on H(1) = 0
Type I I I Even odd: H(0) = 0 H(1) = 0
Type I V Odd H(0) = 0 No restri cti on
b k ( ) b n 2 k + ( ) k 1 = n 1 + , , , =
b k ( ) b n 2 k + ( ) k 1 = n 1 + , , , =
remez
7-377
[4] Rabi ner, L.R., J.H. McCl el l an, and T.W. Parks, FI R Di gi tal Fi l ter Desi gn
Techni ques Usi ng Wei ghted Chebyshev Approxi mati ons, Proc. I EEE 63
(1975).
[5] Oppenhei m, A.V., and R.W. Schafer, Discrete-Time Signal Processing,
Prenti ce-Hal l , Engl ewood Cl i ffs, NJ, 1989, pp. 256-266.
remezord
7-378
7remezord
Purpose Parks-McCl el l an opti mal FI R fi l ter order esti mati on
Syntax [n,fo,ao,w] = remezord(f,a,dev)
[n,fo,ao,w] = remezord(f,a,dev,fs)
c = remezord(f,a,dev,fs,'cell')
Description [n,fo,ao,w] = remezord(f,a,dev) fi nds the approxi mate order, normal i zed
frequency band edges, frequency band ampl i tudes, and wei ghts that meet
i nput speci fi cati ons f, a, and dev.
f i s a vector of frequency band edges (between 0 and f
s
/2, where f
s
i s the
sampl i ng frequency), and a i s a vector speci fyi ng the desi red ampl i tude on
the bands defi ned by f. The l ength of f i s two l ess than twi ce the l ength of a.
The desi red functi on i s pi ecewi se constant.
dev i s a vector the same si ze as a that speci fi es the maxi mum al l owabl e
devi ati on or ri ppl es between the frequency response and the desi red
ampl i tude of the output fi l ter for each band.
Use remez wi th the resul ti ng order n, frequency vector fo, ampl i tude response
vector ao, and wei ghts w to desi gn the fi l ter b whi ch approxi matel y meets the
speci fi cati ons gi ven by remezord i nput parameters f, a, and dev.
b = remez(n,fo,ao,w)
[n,fo,ao,w] = remezord(f,a,dev,fs) speci fi es a sampl i ng frequency fs.
fs defaul ts to 2 Hz, i mpl yi ng a Nyqui st frequency of 1 Hz. You can therefore
speci fy band edges scal ed to a parti cul ar appl i cati ons sampl i ng frequency.
I n some cases remezord underesti mates the order n. I f the fi l ter does not meet
the speci fi cati ons, try a hi gher order such as n+1 or n+2.
c = remezord(f,a,dev,fs,'cell') generates a cel l -array whose el ements
are the parameters to remez.
Examples Ex a mple 1
Desi gn a mi ni mum-order l owpass fi l ter wi th a 500 Hz passband cutoff
frequency and 600 Hz stopband cutoff frequency, wi th a sampl i ng frequency of
2000 Hz, at l east 40 dB attenuati on i n the stopband, and l ess than 3 dB of
ri ppl e i n the passband.
remezord
7-379
rp = 3; % Passband ripple
rs = 40; % Stopband ripple
fs = 2000; % Sampling frequency
f = [500 600]; % Cutoff frequencies
a = [1 0]; % Desired amplitudes
% Compute deviations
dev = [(10^(rp/20)-1)/(10^(rp/20)+1) 10^(-rs/20)];
[n,fo,ao,w] = remezord(f,a,dev,fs);
b = remez(n,fo,ao,w);
freqz(b,1,1024,fs);
title('Lowpass Filter Designed to Specifications');
Note that the fi l ter fal l s sl i ghtl y short of meeti ng the stopband attenuati on and
passband ri ppl e speci fi cati ons. Usi ng n+1 i n the cal l to remez i nstead of n
achi eves the desi red ampl i tude characteri sti cs.
Ex a mple 2
Desi gn a l owpass fi l ter wi th a 1500 Hz passband cutoff frequency and 2000 Hz
stopband cutoff frequency, wi th a sampl i ng frequency of 8000 Hz, a maxi mum
stopband ampl i tude of 0.1, and a maxi mum passband error (ri ppl e) of 0.01.
0 100 200 300 400 500 600 700 800 900 1000
1200
1000
800
600
400
200
0
Frequency (Hz)
P
h
a
s
e

(
d
e
g
r
e
e
s
)
0 100 200 300 400 500 600 700 800 900 1000
100
80
60
40
20
0
20
Frequency (Hz)
M
a
g
n
i
t
u
d
e

(
d
B
)
Lowpass Filter Designed to Specifications
remezord
7-380
[n,fo,ao,w] = remezord([1500 2000],[1 0],[0.01 0.1],8000 );
b = remez(n,fo,ao,w);
Thi s i s equi val ent to
c = remezord( [1500 2000],[1 0],[0.01 0.1],8000,'cell');
b = remez(c{:});
Note I n some cases, remezord underesti mates or overesti mates the order n. I f
the fi l ter does not meet the speci fi cati ons, try a hi gher order such as n+1
or n+2.
Resul ts are i naccurate i f the cutoff frequenci es are near 0 or the Nyqui st
frequency.
Algorithm remezord uses the al gori thm suggested i n [1]. Thi s method i s i naccurate for
band edges cl ose to ei ther 0 or the Nyqui st frequency (fs/2).
See Also buttord, cheb1ord, cheb2ord, ellipord, kaiserord, remez
References [1] Rabi ner, L.R., and O. Herrmann, The Predi ctabi l i ty of Certai n Opti mum
Fi ni te I mpul se Response Di gi tal Fi l ters, I EEE Trans. on Circuit Theory,
Vol . CT-20, No. 4 (Jul y 1973), pp. 401-408.
[2] Rabi ner, L.R., and B. Gol d. Theory and Application of Digital Signal
Processing. Engl ewood Cl i ffs, NJ: Prenti ce-Hal l , 1975, pp. 156-157.
resample
7-381
7resampl e
Purpose Change sampl i ng rate by any rati onal factor
Syntax y = resample(x,p,q)
y = resample(x,p,q,n)
y = resample(x,p,q,n,beta)
y = resample(x,p,q,b)
[y,b] = resample(x,p,q)
Description y = resample(x,p,q) resampl es the sequence i n vector x at p/q ti mes the
ori gi nal sampl i ng rate, usi ng a pol yphase fi l ter i mpl ementati on. p and q must
be posi ti ve i ntegers. The l ength of y i s equal to ceil(length(x)*p/q). I f x i s a
matri x, resample works down the col umns of x.
resample appl i es an anti -al i asi ng (l owpass) FI R fi l ter to x duri ng the
resampl i ng process. I t desi gns the fi l ter usi ng firls wi th a Kai ser wi ndow.
y = resample(x,p,q,n) uses n terms on ei ther si de of the current sampl e,
x(k), to perform the resampl i ng. The l ength of the FI R fi l ter resample uses i s
proporti onal to n; l arger val ues of n provi de better accuracy at the expense of
more computati on ti me. The defaul t for n i s 10. I f you l et n = 0, resample
performs a nearest-nei ghbor i nterpol ati on
y(k) = x(round((k-1)*q/p)+1)
where y(k) = 0 i f the i ndex to x i s greater than length(x).
y = resample(x,p,q,n,beta) uses beta as the desi gn parameter for the
Kai ser wi ndow that resample empl oys i n desi gni ng the l owpass fi l ter. The
defaul t for beta i s 5.
y = resample(x,p,q,b) fi l ters x usi ng the vector of fi l ter coeffi ci ents b.
[y,b] = resample(x,p,q) returns the vector b, whi ch contai ns the
coeffi ci ents of the fi l ter appl i ed to x duri ng the resampl i ng process.
resample
7-382
Examples Resampl e a si mpl e l i near sequence at 3/2 the ori gi nal rate.
fs1 = 10; % Original sampling frequency in Hz
t1 = 0:1/fs1:1; % Time vector
x = t1; % Define a linear sequence
y = resample(x,3,2); % Now resample it
t2 = (0:(length(y)-1))*2/(3*fs1); % New time vector
plot(t1,x,'*',t2,y,'o',-0.5:0.01:1.5,-0.5:0.01:1.5,':')
legend('original','resampled'); xlabel('Time')
Noti ce that the l ast few poi nts of the output y are i naccurate. I n i ts fi l teri ng
process, resample assumes the sampl es at ti mes before and after the gi ven
sampl es i n x are equal to zero. Thus l arge devi ati ons from zero at the end
poi nts of the sequence x can cause i naccuraci es i n y at i ts end poi nts. The
fol l owi ng two pl ots i l l ustrate thi s si de effect of resample.
x = [1:10 9:-1:1]; y = resample(x,3,2);
subplot(2,1,1);
plot(1:19,x,'*',(0:28)*2/3 + 1,y,'o');
title('Edge Effects Not Noticeable');
legend('original','resampled');
0.5 0 0.5 1 1.5
0.5
0
0.5
1
1.5
Time
original
resampled
resample
7-383
x = [10:-1:1 2:10]; y = resample(x,3,2);
subplot(2,1,2);
plot(1:19,x,'*',(0:28)*2/3 + 1,y,'o')
title('Edge Effects Very Noticeable');
legend('original','resampled');
Algorithm resample performs an FI R desi gn usi ng firls, fol l owed by rate changi ng
i mpl emented wi th upfirdn.
See Also decimate, downsample, firls, interp, interp1, intfilt, kaiser, spline,
upfirdn, upsample
0 5 10 15 20
0
2
4
6
8
10
Edge Effects Not Noticeable
original
resampled
0 5 10 15 20
0
5
10
15
Edge Effects Very Noticeable
original
resampled
residuez
7-384
7resi duez
Purpose z-transform parti al -fracti on expansi on
Syntax [r,p,k] = residuez(b,a)
[b,a] = residuez(r,p,k)
Description residuez converts a di screte ti me system, expressed as the rati o of two
pol ynomi al s, to parti al fracti on expansi on, or resi due, form. I t al so converts the
parti al fracti on expansi on back to the ori gi nal pol ynomi al coeffi ci ents.
[r,p,k] = residuez(b,a) fi nds the resi dues, pol es, and di rect terms of a
parti al fracti on expansi on of the rati o of two pol ynomi al s, b(z) and a(z).
Vectors b and a speci fy the coeffi ci ents of the pol ynomi al s of the di screte-ti me
system b(z)/ a(z) i n descendi ng powers of z.
I f there are no mul ti pl e roots and a > n-1,
The returned col umn vector r contai ns the resi dues, col umn vector p contai ns
the pol e l ocati ons, and row vector k contai ns the di rect terms. The number of
pol es i s
n = length(a)-1 = length(r) = length(p)
The di rect term coeffi ci ent vector k i s empty i f length(b) i s l ess than
length(a); otherwi se
length(k) = length(b) - length(a) + 1
I f p(j) = ... = p(j+s-1) i s a pol e of mul ti pl i ci ty s, then the expansi on
i ncl udes terms of the form
b z ( ) b
0
b
1
z
1
b
2
z
2
L b
m
z
m
+ + + + =
a z ( ) a
0
a
1
z
1
a
2
z
2
L a
n
z
n
+ + + + =
b z ( )
a z ( )
----------
r 1 ( )
1 p 1 ( )z
1

---------------------------- L
r n ( )
1 p n ( )z
1

----------------------------- k 1 ( ) k 2 ( )z
1
L k m n 1 + ( )z
m n ( )
+ + + + + + =
r j ( )
1 p j ( )z
1

---------------------------
r j 1 + ( )
1 p j ( )z
1
( )
2
----------------------------------- L
r j s
r
1 + ( )
1 p j ( )z
1
( )
s
r
------------------------------------ + + +
residuez
7-385
[b,a] = residuez(r,p,k) wi th three i nput arguments and two output
arguments, converts the parti al fracti on expansi on back to pol ynomi al s wi th
coeffi ci ents i n row vectors b and a.
The residue functi on i n the standard MATLAB l anguage i s very si mi l ar to
residuez. I t computes the parti al fracti on expansi on of conti nuous-ti me
systems i n the Lapl ace domai n (see reference [1]), rather than di screte-ti me
systems i n the z-domai n as does residuez.
Algorithm residuez appl i es standard MATLAB functi ons and parti al fracti on techni ques
to fi nd r, p, and k from b and a. I t fi nds
The di rect terms a usi ng deconv (pol ynomi al l ong di vi si on) when
length(b) > length(a)-1.
The pol es usi ng p = roots(a).
Any repeated pol es, reorderi ng the pol es accordi ng to thei r mul ti pl i ci ti es.
The resi due for each nonrepeati ng pol e p
i
by mul ti pl yi ng b(z)/a(z) by
1/(1 - p
i
z
-1
) and eval uati ng the resul ti ng rati onal functi on at z = p
i
.
The resi dues for the repeated pol es by sol vi ng
S2*r2 = h - S1*r1
for r2 usi ng \. h i s the i mpul se response of the reduced b(z)/ a(z), S1 i s a
matri x whose col umns are i mpul se responses of the fi rst-order systems made
up of the nonrepeati ng roots, and r1 i s a col umn contai ni ng the resi dues for
the nonrepeati ng roots. Each col umn of matri x S2 i s an i mpul se response.
For each root p
j
of mul ti pl i ci ty s
j
, S2 contai ns s
j
col umns representi ng the
i mpul se responses of each of the fol l owi ng systems.
The vector h and matri ces S1 and S2 have n + xtra rows, where n i s the total
number of roots and the i nternal parameter xtra, set to 1 by defaul t,
determi nes the degree of overdetermi nati on of the system of equati ons.
See Also convmtx, deconv, poly, prony, residue, roots, ss2tf, tf2ss, tf2zp, zp2ss
1
1 pj z
1

-----------------------
1
1 pj z
1
( )
2
------------------------------- L
1
1 pj z
1
( )
s
j
-------------------------------- , , ,
residuez
7-386
References [1] Oppenhei m, A.V., and R.W. Schafer, Digital Signal Processing,
Prenti ce-Hal l , Engl ewood Cl i ffs, NJ, 1975, pp. 166-170.
rlevinson
7-387
7rl evi nson
Purpose Compute the reverse Levi nson-Durbi n recursi on
Syntax r = rlevinson(a,efinal)
[r,u] = rlevinson(a,efinal)
[r,u,k] = rlevinson(a,efinal)
[r,u,k,e] = rlevinson(a,efinal)
Description The reverse Levi nson-Durbi n recursi on i mpl ements the step-down al gori thm
for sol vi ng the fol l owi ng symmetri c Toepl i tz system of l i near equati ons for r,
where r = [r(1) L r(p+1)] and r(i)
*
denotes the compl ex conjugate of r(i).
r = rlevinson(a,efinal) sol ves the above system of equati ons for r gi ven
vector a, where a = [1 a(2) La(p+1)]. I n l i near predi cti on appl i cati ons, r
represents the autocorrel ati on sequence of the i nput to the predi cti on error
fi l ter, where r(1) i s the zero-l ag el ement. The fi gure bel ow shows the typi cal
fi l ter of thi s type, where H(z) i s the opti mal l i near predi ctor, x(n) i s the i nput
si gnal , i s the predi cted si gnal , and e(n) i s the predi cti on error.

I nput vector a represents the pol ynomi al coeffi ci ents of thi s predi cti on error
fi l ter i n descendi ng powers of z.
r 1 ( ) r 2 ( )

L r p ( )

r 2 ( ) r 1 ( ) L r p 1 ( )

M O O M
r p ( ) L r 2 ( ) r 1 ( )
a 2 ( )
a 3 ( )
M
a p 1 + ( )
r 2 ( )
r 3 ( )
M
r p 1 + ( )
=
x

n ( )
H z ( ) a 2 ( )z
1
a 3 ( )z
2
L a n 1 + ( )z
p
=
x

n ( )
x n ( )

+
e n ( )
Prediction Error
A z ( )
A z ( ) 1 a 2 ( )z
1
L a n 1 + ( )z
p
+ + + =
rlevinson
7-388
The fi l ter must be mi ni mum phase to generate a val i d autocorrel ati on
sequence. efinal i s the scal ar predi cti on error power, whi ch i s equal to the
vari ance of the predi cti on error si gnal ,
2
(e).
[r,u] = rlevinson(a,efinal) returns upper tri angul ar matri x U from the
UDU
*
decomposi ti on
where
and E i s a di agonal matri x wi th el ements returned i n output e (see bel ow). Thi s
decomposi ti on permi ts the effi ci ent eval uati on of the i nverse of the
autocorrel ati on matri x, R
-1
.
Output matri x u contai ns the predi cti on fi l ter pol ynomi al , a, from each
i terati on of the reverse Levi nson-Durbi n recursi on
where a
i
(j) i s the jth coeffi ci ent of the ith order predi cti on fi l ter pol ynomi al (i .e.,
step i i n the recursi on). For exampl e, the 5th order predi cti on fi l ter pol ynomi al
i s
a5 = u(5:-1:1,5)'
Note that u(p+1:-1:1,p+1)' i s the i nput pol ynomi al coeffi ci ent vector a.
R
1
UE
1
U

=
R
r 1 ( ) r 2 ( )

L r p ( )

r 2 ( ) r 1 ( ) L r p 1 ( )

M O O M
r p ( ) L r 2 ( ) r 1 ( )
=
U
a
1
1 ( )

a
2
2 ( )

L a
p 1 +
p 1 + ( )

0 a
2
1 ( )

O a
p 1 +
p ( )

0 0 O a
p 1 +
p 1 ( )

M O O M
0 L 0 a
p 1 +
1 ( )

=
rlevinson
7-389
[r,u,k] = rlevinson(a,efinal) returns a vector k of l ength (p+1) contai ni ng
the refl ecti on coeffi ci ents. The refl ecti on coeffi ci ents are the conjugates of the
val ues i n the fi rst row of u.
k = conj(u(1,2:end))
[r,u,k,e] = rlevinson(a,efinal) returns a vector of l ength p+1 contai ni ng
the predi cti on errors from each i terati on of the reverse Levi nson-Durbi n
recursi on: e(1) i s the predi cti on error from the fi rst-order model , e(2) i s the
predi cti on error from the second-order model , and so on.
These predi cti on error val ues form the di agonal of the matri x E i n the UDU
*

decomposi ti on of R
-1
.
See Also levinson, lpc, prony, stmcb
References [1] Kay, S.M., Modern Spectral Estimation: Theory and Application,
Prenti ce-Hal l , Engl ewood Cl i ffs, NJ, 1988.
R
1
UE
1
U

=
rooteig
7-390
7rootei g
Purpose Esti mate frequency and power content usi ng the ei genvector method
Syntax [w,pow] = rooteig(x,p)
[f,pow] = rooteig(...,fs)
[w,pow] = rooteig(...,'corr')
Description [w,pow] = rooteig(x,p) esti mates the frequency content i n the ti me sampl es
of a si gnal x, and returns w, a vector of frequenci es i n rad/sampl e, and the
correspondi ng si gnal power i n the vector pow i n dB per rad/sampl e. The i nput
si gnal x i s speci fi ed ei ther as:
A row or col umn vector representi ng one observati on of the si gnal
A rectangul ar array for whi ch each row of x represents a separate
observati on of the si gnal (for exampl e, each row i s one output of an array of
sensors, as i n array processi ng), such that x'*x i s an esti mate of the
correl ati on matri x
Note You can use the output of corrmtx to generate such an array x.
You can speci fy the second i nput argument p as ei ther:
A scal ar i nteger. I n thi s case, the si gnal subspace di mensi on i s p.
A two-el ement vector. I n thi s case, p(2), the second el ement of p, represents
a threshol d that i s mul ti pl i ed by
mi n
, the smal l est esti mated ei genval ue of
the si gnal s correl ati on matri x. Ei genval ues bel ow the threshol d
mi n
*p(2)
are assi gned to the noi se subspace. I n thi s case, p(1) speci fi es the maxi mum
di mensi on of the si gnal subspace.
The extra threshol d parameter i n the second entry i n p provi des you more
fl exi bi l i ty and control i n assi gni ng the noi se and si gnal subspaces.
The l ength of the vector w i s the computed di mensi on of the si gnal subspace.
For real -val ued i nput data x, the l ength of the correspondi ng power vector pow
i s gi ven by
length(pow) = 0.5*length(w)
For compl ex-val ued i nput data x, pow and w have the same l ength.
rooteig
7-391
[f,pow] = rooteig(...,fs) returns the vector of frequenci es f cal cul ated
i n Hz. You suppl y the sampl i ng frequency fs i n Hz. I f you speci fy fs wi th the
empty vector [], the sampl i ng frequency defaul ts to 1 Hz.
[w,pow] = rooteig(...,'corr') forces the i nput argument x to be
i nterpreted as a correl ati on matri x rather than a matri x of si gnal data. For thi s
syntax, you must suppl y a square matri x for x, and al l of i ts ei genval ues must
be nonnegati ve.
Note You can pl ace the stri ng 'corr' anywhere after p.
Examples Fi nd the frequency content i n a si gnal composed of three compl ex exponenti al s
i n noi se. Use the modi fi ed covari ance method to esti mate the correl ati on
matri x used by the ei genvector method.
randn('state',1); n=0:99;
s = exp(i*pi/2*n)+2*exp(i*pi/4*n)+exp(i*pi/3*n)+randn(1,100);
% Estimate correlation matrix using modified covariance method.
X=corrmtx(s,12,'mod');
[W,P] = rooteig(X,3)
W =
0.7811
1.5767
1.0554
P =
3.9971
1.1362
1.4102
Algorithm The ei genvector method used by rooteig i s the same as that used by peig. The
al gori thm performs ei genspace anal ysi s of the si gnal s correl ati on matri x i n
order to esti mate the si gnal s frequency content.
rooteig
7-392
The di fference between peig and rooteig i s:
peig returns the pseudospectrum at al l frequency sampl es.
rooteig returns the esti mated di screte frequency spectrum, al ong wi th the
correspondi ng si gnal power esti mates.
rooteig i s most useful for frequency esti mati on of si gnal s made up of a sum of
si nusoi ds embedded i n addi ti ve whi te Gaussi an noi se.
See Also corrmtx, peig, pmusic, rootmusic
rootmusic
7-393
7rootmusi c
Purpose Esti mate frequency and power content usi ng the root MUSI C al gori thm
Syntax [w,pow] = rootmusic(x,p)
[f,pow] = rootmusic(...,fs)
[w,pow] = rootmusic(...,'corr')
Description [w,pow] = rootmusic(x,p) esti mates the frequency content i n the ti me
sampl es of a si gnal x, and returns w, a vector of frequenci es i n rad/sampl e, and
the correspondi ng si gnal power i n the vector pow i n dB per rad/sampl e. The
i nput si gnal x i s speci fi ed ei ther as:
A row or col umn vector representi ng one observati on of the si gnal
A rectangul ar array for whi ch each row of x represents a separate
observati on of the si gnal (for exampl e, each row i s one output of an array of
sensors, as i n array processi ng), such that x'*x i s an esti mate of the
correl ati on matri x
Note You can use the output of corrmtx to generate such an array x.
The second i nput argument, p i s the number of compl ex si nusoi ds i n x. You can
speci fy p as ei ther:
A scal ar i nteger. I n thi s case, the si gnal subspace di mensi on i s p.
A two-el ement vector. I n thi s case, p(2), the second el ement of p, represents
a threshol d that i s mul ti pl i ed by
mi n
, the smal l est esti mated ei genval ue of
the si gnal s correl ati on matri x. Ei genval ues bel ow the threshol d
mi n
*p(2)
are assi gned to the noi se subspace. I n thi s case, p(1) speci fi es the maxi mum
di mensi on of the si gnal subspace.
The extra threshol d parameter i n the second entry i n p provi des you more
fl exi bi l i ty and control i n assi gni ng the noi se and si gnal subspaces.
The l ength of the vector w i s the computed di mensi on of the si gnal subspace.
For real -val ued i nput data x, the l ength of the correspondi ng power vector pow
i s gi ven by
length(pow) = 0.5*length(w)
rootmusic
7-394
For compl ex-val ued i nput data x, pow and w have the same l ength.
[f,pow] = rootmusic(...,fs) returns the vector of frequenci es f cal cul ated
i n Hz. You suppl y the sampl i ng frequency fs i n Hz. I f you speci fy fs wi th the
empty vector [], the sampl i ng frequency defaul ts to 1 Hz.
[w,pow] = rootmusic(...,'corr') forces the i nput argument x to be
i nterpreted as a correl ati on matri x rather than a matri x of si gnal data. For thi s
syntax, you must suppl y a square matri x for x, and al l of i ts ei genval ues must
be nonnegati ve.
Note You can pl ace the stri ng 'corr' anywhere after p.
Examples Fi nd the frequency content i n a si gnal composed of three compl ex exponenti al s
i n noi se. Use the modi fi ed covari ance method to esti mate the correl ati on
matri x used by the MUSI C al gori thm.
randn('state',1); n=0:99;
s = exp(i*pi/2*n)+2*exp(i*pi/4*n)+exp(i*pi/3*n)+randn(1,100);
% Estimate correlation matrix using modified covariance method.
X=corrmtx(s,12,'mod');
[W,P] = rootmusic(X,3)
W =
1.5769
0.7817
1.0561
P =
1.1358
3.9975
1.4102
Algorithm The MUSI C al gori thm used by rootmusic i s the same as that used by pmusic.
The al gori thm performs ei genspace anal ysi s of the si gnal s correl ati on matri x
i n order to esti mate the si gnal s frequency content.
rootmusic
7-395
The di fference between pmusic and rootmusic i s:
pmusic returns the pseudospectrum at al l frequency sampl es.
rootmusic returns the esti mated di screte frequency spectrum, al ong wi th
the correspondi ng si gnal power esti mates.
rootmusic i s most useful for frequency esti mati on of si gnal s made up of a sum
of si nusoi ds embedded i n addi ti ve whi te Gaussi an noi se.
Diagnostics I f the i nput si gnal , x i s real and an odd number of si nusoi ds, p i s speci fi ed, thi s
error message i s di spl ayed
Real signals require an even number p of complex sinusoids.
See Also corrmtx, peig, pmusic, rooteig
sawtooth
7-396
7sawtooth
Purpose Generate a sawtooth or tri angl e wave
Syntax x = sawtooth(t)
x = sawtooth(t,width)
Description sawtooth(t) generates a sawtooth wave wi th peri od 2 for the el ements of
ti me vector t. sawtooth(t) i s si mi l ar to sin(t), but creates a sawtooth wave
wi th peaks of -1 and 1 i nstead of a si ne wave. The sawtooth wave i s defi ned to
be -1 at mul ti pl es of 2 and to i ncrease l i nearl y wi th ti me wi th a sl ope of 1/ at
al l other ti mes.
sawtooth(t,width) generates a modi fi ed tri angl e wave where width, a scal ar
parameter between 0 and 1, determi nes the poi nt between 0 and 2 at whi ch
the maxi mum occurs. The functi on i ncreases from -1 to 1 on the i nterval 0 to
2*width, then decreases l i nearl y from 1 to -1 on the i nterval 2*width to 2.
Thus a parameter of 0.5 speci fi es a standard tri angl e wave, symmetri c about
ti me i nstant wi th peak-to-peak ampl i tude of 1. sawtooth(t,1) i s equi val ent
to sawtooth(t).
See Also chirp, cos, diric, gauspuls, pulstran, rectpuls, sin, sinc, square, tripuls
schurrc
7-397
7schurrc
Purpose Compute refl ecti on coeffi ci ents from an autocorrel ati on sequence
Syntax k = schurrc(r)
[k,e] = schurrc(r)
Description k = schurrc(r) uses the Schur al gori thm to compute a vector k of refl ecti on
coeffi ci ents from a vector r representi ng an autocorrel ati on sequence. k and r
are the same si ze. The refl ecti on coeffi ci ents represent the l atti ce parameters
of a predi cti on fi l ter for a si gnal wi th the gi ven autocorrel ati on sequence, r.
When r i s a matri x, schurrc treats each col umn of r as an i ndependent
autocorrel ati on sequence, and produces a matri x k, the same si ze as r. Each
col umn of k represents the refl ecti on coeffi ci ents for the l atti ce fi l ter for
predi cti ng the process wi th the correspondi ng autocorrel ati on sequence r.
[k,e] = schurrc(r) al so computes the scal ar e, the predi cti on error vari ance.
When r i s a matri x, e i s a row vector. The l ength of e i s the same as the number
of col umns of r.
Examples Create an autocorrel ati on sequence from the MATLAB speech si gnal contai ned
i n mtlb.mat, and use the Schur al gori thm to compute the refl ecti on coeffi ci ents
of a l atti ce predi cti on fi l ter for thi s autocorrel ati on sequence.
load mtlb
r = xcorr(mtlb(1:5),'unbiased');
k = schurrc(r(5:end))
k =
-0.7583
0.1384
0.7042
-0.3699
See Also levinson
References [1] Proaki s, J. and D. Manol aki s, Digital Signal Processing: Principles,
Algorithms, and Applications, Thi rd edi ti on, Prenti ce-Hal l , 1996, pp. 868-873.
seqperiod
7-398
7seqperi od
Purpose Compute the peri od of a sequence
Syntax p = seqperiod(x)
[p,num] = seqperiod(x)
Description p = seqperiod(x) returns the i nteger p that corresponds to the peri od of the
sequence i n a vector x. The peri od p i s computed as the mi ni mum l ength of a
subsequence x(1:p) of x that repeats i tsel f conti nuousl y every p sampl es i n x.
The l ength of x does not have to be a mul ti pl e of p, so that an i ncompl ete
repeti ti on i s permi tted at the end of x. I f the sequence x i s not peri odi c, then
p = length(x).
I f x i s a matri x, then seqperiod checks for peri odi ci ty al ong each col umn of x.
The resul ti ng output p i s a row vector wi th the same number of col umns as x.
I f x i s a mul ti di mensi onal array, then seqperiod checks for peri odi ci ty al ong
the fi rst nonsi ngl eton di mensi on of x. I n thi s case:
- p i s a mul ti di mensi onal array of i ntegers wi th a l eadi ng si ngl eton
di mensi on.
- The l engths of the remai ni ng di mensi ons of p correspond to those of the
di mensi ons of x after the fi rst nonsi ngl eton one.
[p,num] = seqperiod(x) al so returns the number num of repeti ti ons of x(1:p)
i n x. num mi ght not be an i nteger.
Examples x = [4 0 1 6;
2 0 2 7;
4 0 1 5;
2 0 5 6];
p = seqperiod(x)
p =
2 1 4 3
seqperiod
7-399
The resul t i mpl i es:
The fi rst col umn of x has peri od 2.
The second col umn of x has peri od 1.
The thi rd col umn of x i s not peri odi c, so p(3) i s just the number of rows of x.
The fourth col umn of x has peri od 3, al though the l ast (second) repeti ti on of
the peri odi c sequence i s i ncompl ete.
sgolay
7-400
7sgol ay
Purpose Savi tzky-Gol ay fi l ter desi gn
Syntax b = sgolay(k,f)
b = sgolay(k,f,w)
[b,g] = sgolay(...)
Description b = sgolay(k,f) desi gns a Savi tzky-Gol ay FI R smoothi ng fi l ter b. The
pol ynomi al order k must be l ess than the frame si ze, f, whi ch must be odd. I f
k = f-1, the desi gned fi l ter produces no smoothi ng. The output, b, i s an f-by-f
matri x whose rows represent the ti me-varyi ng FI R fi l ter coeffi ci ents. I n a
smoothi ng fi l ter i mpl ementati on (for exampl e, sgolayfilt), the l ast (f-1)/2
rows (each an FI R fi l ter) are appl i ed to the si gnal duri ng the startup transi ent,
and the fi rst (f-1)/2 rows are appl i ed to the si gnal duri ng the termi nal
transi ent. The center row i s appl i ed to the si gnal i n the steady state.
b = sgolay(k,f,w) speci fi es a wei ghti ng vector w wi th l ength f, whi ch
contai ns the real , posi ti ve-val ued wei ghts to be used duri ng the l east-squares
mi ni mi zati on.
[b,g] = sgolay(...) [returns the matri x g of di fferenti ati on fi l ters. Each
col umn of g i s a di fferenti ati on fi l ter for deri vati ves of order p-1 where p i s the
col umn i ndex. Gi ven a si gnal x of l ength f, you can fi nd an esti mate of the p
th

order deri vati ve, xp, of i ts mi ddl e val ue from:
xp((f+1)/2) = (factorial(p)) * g(:,p+1)' * x
Remarks Savi tzky-Gol ay smoothi ng fi l ters (al so cal l ed di gi tal smoothi ng pol ynomi al
fi l ters or l east squares smoothi ng fi l ters) are typi cal l y used to smooth out a
noi sy si gnal whose frequency span (wi thout noi se) i s l arge. I n thi s type of
appl i cati on, Savi tzky-Gol ay smoothi ng fi l ters perform much better than
standard averagi ng FI R fi l ters, whi ch tend to fi l ter out a si gni fi cant porti on of
the si gnal s hi gh frequency content al ong wi th the noi se. Al though
Savi tzky-Gol ay fi l ters are more effecti ve at preservi ng the perti nent hi gh
frequency components of the si gnal , they are l ess successful than standard
averagi ng FI R fi l ters at rejecti ng noi se.
Savi tzky-Gol ay fi l ters are opti mal i n the sense that they mi ni mi ze the
l east-squares error i n fi tti ng a pol ynomi al to each frame of noi sy data.
sgolay
7-401
Example Use sgolay to smooth a noi sy si nusoi d and di spl ay the resul t and the fi rst and
second deri vati ves.
N = 4;
F = 21;
[b,g]=sgolay(N,F);
x=5*sin(.4*pi*0:.2:199);
y=x+randn(1,996); % Noisy sinusoid
for n = (F+1)/2:996-(F+1)/2,
% Zero-th order derivative (equivalent to sgolayfilt except
% that it doesn't compute transients)
z0(n)=g(:,1)'*y(n - (F+1)/2 + 1: n + (F+1)/2 - 1)';
% 1st order derivative
z1(n)=g(:,2)'*y(n - (F+1)/2 + 1: n + (F+1)/2 - 1)';
% 2nd order derivative
z2(n)=2*g(:,3)'*y(n - (F+1)/2 + 1: n + (F+1)/2 - 1)';
end
plot([x(1:length(z0))',y(1:length(z0))',z0'])
legend('Noiseless sinusoid','Noisy sinusoid',...
'Smoothed sinusoid')
figure
plot([diff(x(1:length(z0)+1))',z1'])
legend('Noiseless first-order derivative',...
'Smoothed first-order derivative')
figure
plot([diff(diff(x(1:length(z0)+2)))',z2'])
legend('Noiseless second-order derivative',...
'Smoothed second-order derivative')
Note The fi gures bel ow are zoomed to show more detai l .
sgolay
7-402
140 160 180 200 220
6
4
2
0
2
4
6
Noiseless sinusoid
Noisy sinusoid
Smoothed sinusoid
Zero-th order
140 160 180 200 220
6
4
2
0
2
4
6
Noiseless sinusoid
Noisy sinusoid
Smoothed sinusoid
Fi rst deri vati ve
sgolay
7-403
See Also fir1, firls, filter, sgolayfilt
References [1] Orfani di s, S.J., I ntroduction to Signal Processing, Prenti ce-Hal l , Engl ewood
Cl i ffs, NJ, 1996.
40 60 80 100 120 140 160 180 200 220
0.25
0.2
0.15
0.1
0.05
0
0.05
0.1
0.15
0.2
0.25
Noiseless secondorder derivative
Smoothed secondorder derivative
Second deri vati ve
sgolayfilt
7-404
7sgol ayfi l t
Purpose Savi tzky-Gol ay fi l teri ng
Syntax y = sgolayfilt(x,k,f)
y = sgolayfilt(x,k,f,w)
y = sgolayfilt(x,k,f,w,dim)
Description y = sgolayfilt(x,k,f) appl i es a Savi tzky-Gol ay FI R smoothi ng fi l ter to the
data i n vector x. I f x i s a matri x, sgolayfilt operates on each col umn. The
pol ynomi al order k must be l ess than the frame si ze, f, whi ch must be odd. I f
k = f-1, the fi l ter produces no smoothi ng.
y = sgolayfilt(x,k,f,w) speci fi es a wei ghti ng vector w wi th l ength f, whi ch
contai ns the real , posi ti ve-val ued wei ghts to be used duri ng the l east-squares
mi ni mi zati on. I f w i s not speci fi ed or i f i t i s speci fi ed as empty, [], w defaul ts to
an i denti ty matri x.
y = sgolayfilt(x,k,f,w,dim) speci fi es the di mensi on, dim, al ong whi ch the
fi l ter operates. I f dim i s not speci fi ed, sgolayfilt operates al ong the fi rst
non-si ngl eton di mensi on; that i s, di mensi on 1 for col umn vectors and
nontri vi al matri ces, and di mensi on 2 for row vectors.
Remarks Savi tzky-Gol ay smoothi ng fi l ters (al so cal l ed di gi tal smoothi ng pol ynomi al
fi l ters or l east-squares smoothi ng fi l ters) are typi cal l y used to smooth out a
noi sy si gnal whose frequency span (wi thout noi se) i s l arge. I n thi s type of
appl i cati on, Savi tzky-Gol ay smoothi ng fi l ters perform much better than
standard averagi ng FI R fi l ters, whi ch tend to fi l ter out a si gni fi cant porti on of
the si gnal s hi gh frequency content al ong wi th the noi se. Al though
Savi tzky-Gol ay fi l ters are more effecti ve at preservi ng the perti nent hi gh
frequency components of the si gnal , they are l ess successful than standard
averagi ng FI R fi l ters at rejecti ng noi se.
Savi tzky-Gol ay fi l ters are opti mal i n the sense that they mi ni mi ze the
l east-squares error i n fi tti ng a pol ynomi al to frames of noi sy data.
Example Smooth the mtlb si gnal by appl yi ng a cubi c Savi tzky-Gol ay fi l ter to data
frames of l ength 41.
load mtlb % Load the data.
smtlb = sgolayfilt(mtlb,3,41); % Apply the 3rd-order filter.
sgolayfilt
7-405
subplot(2,1,1)
plot([1:2000],mtlb(1:2000)); axis([0 2000 -4 4]);
title('mtlb'); grid;
subplot(2,1,2)
plot([1:2000],smtlb(1:2000)); axis([0 2000 -4 4]);
title('smtlb'); grid;
See Also medfilt1, filter, sgolay, sosfilt
References [1] Orfani di s, S.J., I ntroduction to Signal Processing, Prenti ce-Hal l , Engl ewood
Cl i ffs, NJ, 1996.
0 500 1000 1500 2000
4
2
0
2
4
mtlb
0 500 1000 1500 2000
4
2
0
2
4
smtlb
sinc
7-406
7si nc
Purpose Si nc functi on
Syntax y = sinc(x)
Description sinc computes the si nc functi on of an i nput vector or array, where the si nc
functi on i s
Thi s functi on i s the conti nuous i nverse Fouri er transform of the rectangul ar
pul se of wi dth 2 and hei ght 1.
y = sinc(x) returns an array y the same si ze as x, whose el ements are the
sinc functi on of the el ements of x.
The space of functi ons bandl i mi ted i n the frequency range i s
spanned by the i nfi ni te (yet countabl e) set of si nc functi ons shi fted by i ntegers.
Thus any such bandl i mi ted functi on g(t) can be reconstructed from i ts sampl es
at i nteger spaci ngs.
Example Perform i deal bandl i mi ted i nterpol ati on by assumi ng that the si gnal to be
i nterpol ated i s 0 outsi de of the gi ven ti me i nterval and that i t has been sampl ed
at exactl y the Nyqui st frequency.
t = (1:10)'; % A column vector of time samples
randn('state',0);
x = randn(size(t)); % A column vector of data
ts = linspace(-5,15,600)'; % times at which to interpolate data
y = sinc(ts(:,ones(size(t))) - t(:,ones(size(ts)))')*x;
si nc t ( )
1 t 0 = ,
t ( ) si n
t
------------------- t 0 ,

'

=
si nc t ( )
1
2
------ e
j t
d

=
[ , ]
g t ( ) g n ( )si nc t n ( )
n =

=
sinc
7-407
plot(t,x,'o',ts,y)
See Also chirp, cos, diric, gauspuls, pulstran, rectpuls, sawtooth, sin, square,
tripuls
5 0 5 10 15
2
1.5
1
0.5
0
0.5
1
1.5
2
sos2cell
7-408
7sos2cel l
Purpose Convert a second-order secti on matri x to cel l arrays
Syntax c = sos2cell(m)
c = sos2cell(m,g)
Description c = sos2cell(m) changes an L-by-6 second-order secti on matri x m generated
by tf2sos i nto a 1-by-L cel l array of 1-by-2 cel l arrays c. You can use c to
speci fy a quanti zed fi l ter wi th L cascaded second-order secti ons.
The matri x m shoul d have the form
m = [b1 a1;b2 a2; ... ;bL aL]
where both bi and ai, wi th i = 1, ..., L, are 1-by-3 row vectors. The resul ti ng c
i s a 1-by-L cel l array of cel l s of the form
c = { {b1 a1} {b2 a2} ... {bL aL} }
c = sos2cell(m,g) wi th the opti onal gai n term g, prepends the constant
val ue g to c. When you use the added gai n term i n the command, c i s a 1-by-L
cel l array of cel l s of the form
c = {{g,1} {b1,a1} {b2,a2}...{bL,aL} }
Examples Use sos2cell to convert the 2-by-6 second-order secti on matri x produced by
tf2sos i nto a 1-by-2 cel l array c of cel l s. Di spl ay the second entry i n the fi rst
cel l i n c.
[b,a] = ellip(4,0.5,20,0.6);
m = tf2sos(b,a);
c = sos2cell(m);
c{1}{2}
ans =
1.0000 0.1677 0.2575
See Also tf2sos, cell2sos
sos2ss
7-409
7sos2ss
Purpose Convert di gi tal fi l ter second-order secti on parameters to state-space form
Syntax [A,B,C,D] = sos2ss(sos)
[A,B,C,D] = sos2ss(sos,g)
Description sos2ss converts a second-order secti on representati on of a gi ven di gi tal fi l ter
to an equi val ent state-space representati on.
[A,B,C,D] = sos2ss(sos) converts the system sos, i n second-order secti on
form, to a si ngl e-i nput, si ngl e-output state-space representati on.
The di screte transfer functi on i n second-order secti on form i s gi ven by
sos i s a L-by-6 matri x organi zed as
The entri es of sos must be real for proper conversi on to state space. The
returned matri x A i s si ze N-by-N, where N = 2L-1, B i s a l ength N-1 col umn
vector, C i s a l ength N-1 row vector, and D i s a scal ar.
[A,B,C,D] = sos2ss(sos,g) converts the system sos i n second-order secti on
form wi th gai n g.
x n 1 + [ ] Ax n [ ] Bu n [ ] + =
y n [ ] Cx n [ ] Du n [ ] + =
H z ( ) H
k
z ( )
k 1 =
L

b
0k
b
1k
z
1
b
2k
z
2
+ +
1 a
1k
z
1
a
2k
z
2
+ +
--------------------------------------------------------- -
k 1 =
L

= =
sos
b
01
b
11
b
21
1 a
11
a
21
b
02
b
12
b
22
1 a
12
a
22
M M M M M M
b
0L
b
1L
b
2L
1 a
1L
a
2L
=
H z ( ) g H
k
z ( )
k 1 =
L

=
sos2ss
7-410
Example Compute the state-space representati on of a si mpl e second-order secti on
system wi th a gai n of 2.
sos = [1 1 1 1 0 -1; -2 3 1 1 10 1];
[A,B,C,D] = sos2ss(sos)
A =
-10 0 10 1
1 0 0 0
0 1 0 0
0 0 1 0
B =
1
0
0
0
C =
21 2 -16 -1
D =
-2
Algorithm sos2ss fi rst converts from second-order secti ons to transfer functi on usi ng
sos2tf, and then from transfer functi on to state-space usi ng tf2ss.
See Also sos2tf, sos2zp, ss2sos, tf2ss, zp2ss
sos2tf
7-411
7sos2tf
Purpose Convert di gi tal fi l ter second-order secti on data to transfer functi on form
Syntax [b,a] = sos2tf(sos)
[b,a] = sos2tf(sos,g)
Description sos2tf converts a second-order secti on representati on of a gi ven di gi tal fi l ter
to an equi val ent transfer functi on representati on.
[b,a] = sos2tf(sos) returns the numerator coeffi ci ents b and denomi nator
coeffi ci ents a of the transfer functi on that descri bes a di screte-ti me system
gi ven by sos i n second-order secti on form. The second-order secti on format of
H(z) i s gi ven by
sos i s an L-by-6 matri x that contai ns the coeffi ci ents of each second-order
secti on stored i n i ts rows.
Row vectors b and a contai n the numerator and denomi nator coeffi ci ents of
H(z) stored i n descendi ng powers of z.
[b,a] = sos2tf(sos,g) returns the transfer functi on that descri bes a
di screte-ti me system gi ven by sos i n second-order secti on form wi th gai n g.
H z ( ) H
k
z ( )
k 1 =
L

b
0k
b
1k
z
1
b
2k
z
2
+ +
1 a
1k
z
1
a
2k
z
2
+ +
--------------------------------------------------------- -
k 1 =
L

= =
sos
b
01
b
11
b
21
1 a
11
a
21
b
02
b
12
b
22
1 a
12
a
22
M M M M M M
b
0L
b
1L
b
2L
1 a
1L
a
2L
=
H z ( )
B z ( )
A z ( )
-----------
b
1
b
2
z
1
L b
n 1 +
z
n
+ + +
a
1
a
2
z
1
L a
m 1 +
z
m
+ + +
------------------------------------------------------------------------ = =
H z ( ) g H
k
z ( )
k 1 =
L

=
sos2tf
7-412
Example Compute the transfer functi on representati on of a si mpl e second-order secti on
system.
sos = [1 1 1 1 0 -1; -2 3 1 1 10 1];
[b,a] = sos2tf(sos)
b =
-2 1 2 4 1
a =
1 10 0 -10 -1
Algorithm sos2tf uses the conv functi on to mul ti pl y al l of the numerator and
denomi nator second-order pol ynomi al s together.
See Also latc2tf, sos2ss, sos2zp, ss2tf, tf2sos, zp2tf
sos2zp
7-413
7sos2zp
Purpose Convert di gi tal fi l ter second-order secti on parameters to zero-pol e-gai n form
Syntax [z,p,k] = sos2zp(sos)
[z,p,k] = sos2zp(sos,g)
Description sos2zp converts a second-order secti on representati on of a gi ven di gi tal fi l ter
to an equi val ent zero-pol e-gai n representati on.
[z,p,k] = sos2zp(sos) returns the zeros z, pol es p, and gai n k of the system
gi ven by sos i n second-order secti on form. The second-order secti on format of
H(z) i s gi ven by
sos i s an L-by-6 matri x that contai ns the coeffi ci ents of each second-order
secti on i n i ts rows.
Col umn vectors z and p contai n the zeros and pol es of the transfer
functi on H(z).
where the orders n and m are determi ned by the matri x sos.
[z,p,k] = sos2zp(sos,g) returns the zeros z, pol es p, and gai n k of the
system gi ven by sos i n second-order secti on form wi th gai n g.
H z ( ) H
k
z ( )
k 1 =
L

b
0k
b
1k
z
1
b
2k
z
2
+ +
1 a
1k
z
1
a
2k
z
2
+ +
--------------------------------------------------------- -
k 1 =
L

= =
sos
b
01
b
11
b
21
1 a
11
a
21
b
02
b
12
b
22
1 a
12
a
22
M M M M M M
b
0L
b
1L
b
2L
1 a
1L
a
2L
=
H z ( ) k
z z
1
( ) z z
2
( )L z z
n
( )
p p
1
( ) p p
2
( )L p p
m
( )
---------------------------------------------------------------------- =
H z ( ) g H
k
z ( )
k 1 =
L

=
sos2zp
7-414
Example Compute the pol es, zeros, and gai n of a si mpl e system i n second-order secti on
form.
sos = [1 1 1 1 0 -1; -2 3 1 1 10 1];
[z,p,k] = sos2zp(sos)
z =
-0.5000 + 0.8660i
-0.5000 - 0.8660i
1.7808
-0.2808
p =
-1.0000
1.0000
-9.8990
-0.1010
k =
-2
Algorithm sos2zp fi nds the pol es and zeros of each second-order secti on by repeatedl y
cal l i ng tf2zp.
See Also sos2ss, sos2tf, ss2zp, tf2zp, zp2sos
sosfilt
7-415
7sosfi l t
Purpose Second-order (bi quadrati c) I I R di gi tal fi l teri ng
Syntax y = sosfilt(sos,x)
Description y = sosfilt(sos,x) appl i es the second-order secti on di gi tal fi l ter sos to the
vector x. The output, y, i s the same l ength as x.
sos represents the second-order secti on di gi tal fi l ter H(z)
by an L-by-6 matri x contai ni ng the coeffi ci ents of each second-order secti on i n
i ts rows.
I f x i s a matri x, sosfilt appl i es the fi l ter to each col umn of x i ndependentl y.
Output y i s a matri x of the same si ze, contai ni ng the fi l tered data
correspondi ng to each col umn of x.
See Also filter, medfilt1, sgolayfilt
References [1] Orfani di s, S.J., I ntroduction to Signal Processing, Prenti ce-Hal l , Engl ewood
Cl i ffs, NJ, 1996.
H z ( ) H
k
z ( )
k 1 =
L

b
0k
b
1k
z
1
b
2k
z
2
+ +
1 a
1k
z
1
a
2k
z
2
+ +
--------------------------------------------------------- -
k 1 =
L

= =
sos
b
01
b
11
b
21
1 a
11
a
21
b
02
b
12
b
22
1 a
12
a
22
M M M M M M
b
0L
b
1L
b
2L
1 a
1L
a
2L
=
specgram
7-416
7specgram
Purpose Ti me-dependent frequency anal ysi s (spectrogram)
Syntax B = specgram(a)
B = specgram(a,nfft)
[B,f] = specgram(a,nfft,fs)
[B,f,t] = specgram(a,nfft,fs)
B = specgram(a,nfft,fs,window)
B = specgram(a,nfft,fs,window,numoverlap)
specgram(a)
B = specgram(a,f,fs,window,numoverlap)
Description specgram computes the wi ndowed di screte-ti me Fouri er transform of a si gnal
usi ng a sl i di ng wi ndow. The spectrogram i s the magni tude of thi s functi on.
B = specgram(a) cal cul ates the wi ndowed di screte-ti me Fouri er transform for
the si gnal i n vector a. Thi s syntax uses the defaul t val ues:
nfft = min(256,length(a))
fs = 2
window i s a peri odi c Hann (Hanni ng) wi ndow of l ength nfft.
numoverlap = length(window)/2
nfft speci fi es the FFT l ength that specgram uses. Thi s val ue determi nes the
frequenci es at whi ch the di screte-ti me Fouri er transform i s computed. fs i s a
scal ar that speci fi es the sampl i ng frequency. window speci fi es a wi ndowi ng
functi on and the number of sampl es specgram uses i n i ts secti oni ng of vector a.
numoverlap i s the number of sampl es by whi ch the secti ons overl ap. Any
arguments that you omi t from the end of the i nput parameter l i st use the
defaul t val ues shown above.
I f a i s real , specgram computes the di screte-ti me Fouri er transform at posi ti ve
frequenci es onl y. I f n i s even, specgram returns nfft/2+1 rows (i ncl udi ng the
zero and Nyqui st frequency terms). I f n i s odd, specgram returns nfft/2 rows.
The number of col umns i n B i s
k = fix((n-numoverlap)/(length(window)-numoverlap))
I f a i s compl ex, specgram computes the di screte-ti me Fouri er transform at both
posi ti ve and negati ve frequenci es. I n thi s case, B i s a compl ex matri x wi th nfft
specgram
7-417
rows. Ti me i ncreases l i nearl y across the col umns of B, starti ng wi th sampl e 1
i n col umn 1. Frequency i ncreases l i nearl y down the rows, starti ng at 0.
B = specgram(a,nfft) uses the speci fi ed FFT l ength nfft i n i ts cal cul ati ons.
[B,f] = specgram(a,nfft,fs) returns a vector f of frequenci es at whi ch the
functi on computes the di screte-ti me Fouri er transform. fs has no effect on the
output B; i t i s a frequency scal i ng mul ti pl i er.
[B,f,t] = specgram(a,nfft,fs) returns frequency and ti me vectors f and t
respecti vel y. t i s a col umn vector of scal ed ti mes, wi th l ength equal to the
number of col umns of B. t(j) i s the earl i est ti me at whi ch the jth wi ndow
i ntersects a. t(1) i s al ways equal to 0.
B = specgram(a,nfft,fs,window) speci fi es a wi ndowi ng functi on and the
number of sampl es per secti on of the x vector. I f you suppl y a scal ar for window,
specgram uses a Hann wi ndow of that l ength. The l ength of the wi ndow must
be l ess than or equal to nfft.
B = specgram(a,nfft,fs,window,numoverlap) overl aps the secti ons of x by
numoverlap sampl es.
You can use the empty matri x [] to speci fy the defaul t val ue for any i nput
argument. For exampl e,
B = specgram(x,[],10000)
i s equi val ent to
B = specgram(x)
but wi th a sampl i ng frequency of 10,000 Hz i nstead of the defaul t 2 Hz.
specgram(...) wi th no output arguments di spl ays the scal ed l ogari thm of the
spectrogram i n the current fi gure wi ndow usi ng
imagesc(t,f,20*log10(abs(b))), axis xy, colormap(jet)
The axis xy mode di spl ays the l ow-frequency content of the fi rst porti on of the
si gnal i n the l ower-l eft corner of the axes. specgram uses fs to l abel the axes
accordi ng to true ti me and frequency.
specgram
7-418
B = specgram(a,f,fs,window,numoverlap) computes the spectrogram at the
frequenci es speci fi ed i n f, usi ng ei ther the chi rp z-transform (for more than 20
evenl y spaced frequenci es) or a pol yphase deci mati on fi l ter bank. f i s a vector
of frequenci es i n hertz; i t must have at l east two el ements.
Example Di spl ay the spectrogram of a di gi ti zed speech si gnal .
load mtlb
specgram(mtlb,512,Fs,kaiser(500,5),475)
title('Spectrogram')
Note You can vi ew and mani pul ate a si mi l ar spectrogram i n the Si gnal
Processi ng Tool box Demos, whi ch you access i n from the MATLAB Launch
Pad.
Algorithm specgram cal cul ates the spectrogram for a gi ven si gnal as fol l ows:
1 I t spl i ts the si gnal i nto overl appi ng secti ons and appl i es the wi ndow
speci fi ed by the window parameter to each secti on.
Time
F
r
e
q
u
e
n
c
y
Spectrogram
0 0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4 0.45
0
500
1000
1500
2000
2500
3000
3500
specgram
7-419
2 I t computes the di screte-ti me Fouri er transform of each secti on wi th a
l ength nfft FFT to produce an esti mate of the short-term frequency content
of the si gnal ; these transforms make up the col umns of B. The quanti ty
(length(window) - numoverlap) speci fi es by how many sampl es specgram
shi fts the wi ndow.
3 For real i nput, specgram truncates the spectrogram to the fi rst nfft/2 + 1
poi nts for nfft even and (nfft + 1)/2 for nfft odd.
Diagnostics An appropri ate di agnosti c message i s di spl ayed when i ncorrect arguments are
used.
Requires window's length to be no greater than the FFT length.
Requires NOVERLAP to be strictly less than the window length.
Requires positive integer values for NFFT and NOVERLAP.
Requires vector input.
See Also cohere, csd, pwelch, tfe
References [1] Oppenhei m, A.V., and R.W. Schafer, Discrete-Time Signal Processing,
Prenti ce-Hal l , Engl ewood Cl i ffs, NJ, 1989, pp. 713-718.
[2] Rabi ner, L.R., and R.W. Schafer, Digital Processing of Speech Signals,
Prenti ce-Hal l , Engl ewood Cl i ffs, NJ, 1978.
sptool
7-420
7sptool
Purpose Open the di gi tal si gnal processi ng GUI (SPTool )
Syntax sptool
Description sptool opens SPTool , a graphi cal user i nterface (GUI ) that manages a sui te of
four other GUI s. These GUI s provi de access to many of the si gnal , fi l ter, and
spectral anal ysi s functi ons i n the tool box. When you type sptool at the
command l i ne, the fol l owi ng GUI opens.
Usi ng SPTool you can:
Anal yze si gnal s l i sted i n the Signals l i st box wi th the Si gnal Browser
Desi gn or edi t fi l ters wi th the Fi l ter Desi gner (i ncl udes a Pol e/Zero Edi tor)
Anal yze fi l ter responses for fi l ters l i sted i n the Filters l i st box wi th the Fi l ter
Vi ewer
Appl y fi l ters i n the Filters l i st box to si gnal s i n the Signals l i st box
Create and anal yze si gnal spectra wi th the Spectrum Vi ewer
Pri nt the Si gnal Browser, Fi l ter Vi ewer, Fi l ter Desi gner, and Spectrum
Vi ewer
You can acti vate the four i ntegrated si gnal processi ng GUI s from SPTool .
sptool
7-421
Signa l Brow ser
The Si gnal Browser al l ows you to vi ew, measure, and anal yze the ti me-domai n
i nformati on of one or more si gnal s. To acti vate the Si gnal Browser, press the
View button under the Signals l i st box i n SPTool .
Filter Designer
The Fi l ter Desi gner al l ows you to desi gn and edi t FI R and I I R fi l ters of vari ous
l engths and types, wi th standard (l owpass, hi ghpass, bandpass, bandstop, and
mul ti band) confi gurati ons. To acti vate the Fi l ter Desi gner, press ei ther the
New button or the Edit button under the Filters l i st box i n SPTool .
The Fi l ter Desi gner has a Pol e/Zero Edi tor you can access from the Algorithms
pul l down.
sptool
7-422
Filter View er
The Fi l ter Vi ewer al l ows you to vi ew the characteri sti cs of a desi gned or
i mported fi l ter, i ncl udi ng i ts magni tude response, phase response, group del ay,
pol e-zero pl ot, i mpul se response, and step response. To acti vate the Fi l ter
Vi ewer, press the View button under the Filters l i st box i n SPTool .
sptool
7-423
You can anal yze mul ti pl e fi l ter responses by checki ng several response pl ot
opti ons, as shown i n the next fi gure.
sptool
7-424
Spectr um View er
The Spectrum Vi ewer al l ows you to graphi cal l y anal yze frequency-domai n data
usi ng a vari ety of methods of spectral densi ty esti mati on, i ncl udi ng the Burg
method, the FFT method, the mul ti taper method (MTM), the MUSI C
ei genvector method, Wel chs method, and the Yul e-Wal ker AR method. To
acti vate the Spectrum Vi ewer:
Press the Create button under the Spectra l i st box to compute the power
spectral densi ty for a si gnal sel ected i n the Signals l i st box i n SPTool . You
may need to press Apply to vi ew the spectra.
Press the View button to anal yze spectra sel ected under the Spectra l i st box
i n SPTool .
Press the Update button under the Spectra l i st box i n SPTool to modi fy a
sel ected power spectral densi ty si gnal .
I n addi ti on, you can ri ght-cl i ck i n any pl ot di spl ay area of the GUI s to modi fy
si gnal properti es.
See Chapter 6, SPTool : A Si gnal Processi ng GUI Sui te, for a ful l di scussi on of
how to use SPTool .
See Also fdatool
square
7-425
7square
Purpose Generate a square wave
Syntax x = square(t)
x = square(t,duty)
Description x = square(t) generates a square wave wi th peri od 2 for the el ements of
ti me vector t. square(t) i s si mi l ar to sin(t), but creates a square wave wi th
peaks of 1 i nstead of a si ne wave.
x = square(t,duty) generates a square wave wi th speci fi ed duty cycl e, duty.
The duty cycle i s the percent of the peri od i n whi ch the si gnal i s posi ti ve.
See Also chirp, cos, diric, gauspuls, pulstran, rectpuls, sawtooth, sin, square,
tripuls
ss2sos
7-426
7ss2sos
Purpose Convert di gi tal fi l ter state-space parameters to second-order secti ons form
Syntax [sos,g] = ss2sos(A,B,C,D)
[sos,g] = ss2sos(A,B,C,D,iu)
[sos,g] = ss2sos(A,B,C,D,'order')
[sos,g] = ss2sos(A,B,C,D,iu,'order')
[sos,g] = ss2sos(A,B,C,D,iu,'order','scale')
sos = ss2sos(...)
Description ss2sos converts a state-space representati on of a gi ven di gi tal fi l ter to an
equi val ent second-order secti on representati on.
[sos,g] = ss2sos(A,B,C,D) fi nds a matri x sos i n second-order secti on form
wi th gai n g that i s equi val ent to the state-space system represented by i nput
arguments A, B, C, and D. The i nput system must be si ngl e output and real . sos
i s an L-by-6 matri x
whose rows contai n the numerator and denomi nator coeffi ci ents b
ik
and a
ik
of
the second-order secti ons of H(z).
[sos,g] = ss2sos(A,B,C,D,iu) speci fi es a scal ar iu that determi nes whi ch
i nput of the state-space system A, B, C, D i s used i n the conversi on. The defaul t
for iu i s 1.
sos
b
01
b
11
b
21
1 a
11
a
21
b
02
b
12
b
22
1 a
12
a
22
M M M M M M
b
0L
b
1L
b
2L
1 a
1L
a
2L
=
H z ( ) g H
k
z ( )
k 1 =
L

g
b
0k
b
1k
z
1
b
2k
z
2
+ +
1 a
1k
z
1
a
2k
z
2
+ +
--------------------------------------------------------- -
k 1 =
L

= =
ss2sos
7-427
[sos,g] = ss2sos(A,B,C,D,'order') and
[sos,g] = ss2sos(A,B,C,D,iu,'order') speci fy the order of the rows i n sos,
where 'order' i s:
'down', to order the secti ons so the fi rst row of sos contai ns the pol es cl osest
to the uni t ci rcl e
'up', to order the secti ons so the fi rst row of sos contai ns the pol es farthest
from the uni t ci rcl e (defaul t)
The zeros are al ways pai red wi th the pol es cl osest to them.
[sos,g] = ss2sos(A,B,C,D,iu,'order','scale') speci fi es the desi red
scal i ng of the gai n and the numerator coeffi ci ents of al l second-order secti ons,
where 'scale' i s:
'none', to appl y no scal i ng (defaul t)
'inf', to appl y i nfi ni ty-norm scal i ng
'two', to appl y 2-norm scal i ng
Usi ng i nfi ni ty-norm scal i ng i n conjuncti on wi th up-orderi ng mi ni mi zes the
probabi l i ty of overfl ow i n the real i zati on. Usi ng 2-norm scal i ng i n conjuncti on
wi th down-orderi ng mi ni mi zes the peak round-off noi se.
sos = ss2sos(...) embeds the overal l system gai n, g, i n the fi rst secti on,
H
1
(z), so that
Example Fi nd a second-order secti on form of a Butterworth l owpass fi l ter.
[A,B,C,D] = butter(5,0.2);
sos = ss2sos(A,B,C,D)
sos =
0.0013 0.0013 0 1.0000 -0.5095 0
1.0000 2.0008 1.0008 1.0000 -1.0966 0.3554
1.0000 1.9979 0.9979 1.0000 -1.3693 0.6926
H z ( ) H
k
z ( )
k 1 =
L

=
ss2sos
7-428
Algorithm ss2sos uses a four-step al gori thm to determi ne the second-order secti on
representati on for an i nput state-space system:
1 I t fi nds the pol es and zeros of the system gi ven by A, B, C, and D.
2 I t uses the functi on zp2sos, whi ch fi rst groups the zeros and pol es i nto
compl ex conjugate pai rs usi ng the cplxpair functi on. zp2sos then forms the
second-order secti ons by matchi ng the pol e and zero pai rs accordi ng to the
fol l owi ng rul es:
a Match the pol es cl osest to the uni t ci rcl e wi th the zeros cl osest to those
pol es.
b Match the pol es next cl osest to the uni t ci rcl e wi th the zeros cl osest to
those pol es.
c Conti nue unti l al l of the pol es and zeros are matched.
ss2sos groups real pol es i nto secti ons wi th the real pol es cl osest to them i n
absol ute val ue. The same rul e hol ds for real zeros.
3 I t orders the secti ons accordi ng to the proxi mi ty of the pol e pai rs to the uni t
ci rcl e. ss2sos normal l y orders the secti ons wi th pol es cl osest to the uni t
ci rcl e l ast i n the cascade. You can tel l ss2sos to order the secti ons i n the
reverse order by speci fyi ng the 'down' fl ag.
4 ss2sos scal es the secti ons by the norm speci fi ed i n the 'scale' argument.
For arbi trary H(), the scal i ng i s defi ned by
where p can be ei ther or 2. See the references for detai l s. Thi s scal i ng i s
an attempt to mi ni mi ze overfl ow or peak round-off noi se i n fi xed poi nt fi l ter
i mpl ementati ons.
Diagnostics I f there i s more than one i nput to the system, ss2sos gi ves the fol l owi ng error
message.
State-space system must have only one input.
See Also cplxpair, sos2ss, ss2tf, ss2zp, tf2sos, zp2sos
H
p
1
2
------ H ( )
p
d
0
2

1
p
---
=
ss2sos
7-429
References [1] Jackson, L.B., Digital Filters and Signal Processing, 3rd ed., Kl uwer
Academi c Publ i shers, Boston, 1996. Chapter 11.
[2] Mi tra, S.K., Digital Signal Processing: A Computer-Based Approach,
McGraw-Hi l l , New York, 1998. Chapter 9.
[3] Vai dyanathan, P.P.,Robust Di gi tal Fi l ter Structures, Handbook for
Digital Signal Processing, S.K. Mi tra and J.F. Kai ser, ed., John Wi l ey & Sons,
New York, 1993, Chapter 7.
ss2tf
7-430
7ss2tf
Purpose Convert state-space fi l ter parameters to transfer functi on form
Syntax [b,a] = ss2tf(A,B,C,D,iu)
Description ss2tf converts a state-space representati on of a gi ven system to an equi val ent
transfer functi on representati on.
[b,a] = ss2tf(A,B,C,D,iu) returns the transfer functi on
of the system
from the iu-th i nput. Vector a contai ns the coeffi ci ents of the denomi nator i n
descendi ng powers of s. The numerator coeffi ci ents are returned i n array b wi th
as many rows as there are outputs y. ss2tf al so works wi th systems i n di screte
ti me, i n whi ch case i t returns the z-transform representati on.
The ss2tf functi on i s part of the standard MATLAB l anguage.
Algorithm The ss2tf functi on uses poly to fi nd the characteri sti c pol ynomi al det(sI -A)
and the equal i ty
See Also latc2tf, sos2tf, ss2sos, ss2zp, tf2ss, zp2tf
H s ( )
B s ( )
A s ( )
---------- - C sI A ( )
1
B D + = =
x

Ax Bu + =
y Cx Du + =
H s ( ) C sI A ( )
1
B
det sI A BC + ( ) det sI A ( )
det sI A ( )
------------------------------------------------------------------------------ = =
ss2zp
7-431
7ss2zp
Purpose Convert state-space fi l ter parameters to zero-pol e-gai n form
Syntax [z,p,k] = ss2zp(A,B,C,D,i)
Description ss2zp converts a state-space representati on of a gi ven system to an equi val ent
zero-pol e-gai n representati on. The zeros, pol es, and gai ns of state-space
systems represent the transfer functi on i n factored form.
[z,p,k] = ss2zp(A,B,C,D,i) cal cul ates the transfer functi on i n factored
form
of the conti nuous-ti me system
from the ith i nput (usi ng the ith col umns of B and D). The col umn vector p
contai ns the pol e l ocati ons of the denomi nator coeffi ci ents of the transfer
functi on. The matri x z contai ns the numerator zeros i n i ts col umns, wi th as
many col umns as there are outputs y (rows i n C). The col umn vector k contai ns
the gai ns for each numerator transfer functi on.
ss2zp al so works for di screte ti me systems. The i nput state-space system must
be real .
The ss2zp functi on i s part of the standard MATLAB l anguage.
Example Here are two ways of fi ndi ng the zeros, pol es, and gai ns of a di screte-ti me
transfer functi on
b = [2 3];
a = [1 0.4 1];
[b,a] = eqtflength(b,a);
[z,p,k] = tf2zp(b,a)
H s ( )
Z s ( )
P s ( )
---------- k
s z
1
( ) s z
2
( )L s z
n
( )
s p
1
( ) s p
2
( )L s p
n
( )
------------------------------------------------------------------ = =
x

Ax Bu + =
y Cx Du + =
H z ( )
2 3z
1
+
1 0.4z
1
z
2
+ +
----------------------------------------- =
ss2zp
7-432
z =
0.0000
-1.5000
p =
-0.2000 + 0.9798i
-0.2000 - 0.9798i
k =
2
[A,B,C,D] = tf2ss(b,a);
[z,p,k] = ss2zp(A,B,C,D,1)
z =
0.0000
-1.5000
p =
-0.2000 + 0.9798i
-0.2000 - 0.9798i
k =
2
Algorithm ss2zp fi nds the pol es from the ei genval ues of the A array. The zeros are the
fi ni te sol uti ons to a general i zed ei genval ue probl em.
z = eig([A B;C D], diag([ones(1,n) 0]);
I n many si tuati ons thi s al gori thm produces spuri ous l arge, but fi ni te, zeros.
ss2zp i nterprets these l arge zeros as i nfi ni te.
ss2zp fi nds the gai ns by sol vi ng for the fi rst nonzero Markov parameters.
See Also pzmap, sos2zp, ss2sos, ss2tf, tf2zp, zp2ss
References [1] Laub, A.J., and B.C. Moore, Cal cul ati on of Transmi ssi on Zeros Usi ng QZ
Techni ques, Automatica 14 (1978), p. 557.
stmcb
7-433
7stmcb
Purpose Compute a l i near model usi ng Stei gl i tz-McBri de i terati on
Syntax [b,a] = stmcb(h,nb,na)
[b,a] = stmcb(y,x,nb,na)
[b,a] = stmcb(h,nb,na,niter)
[b,a] = stmcb(y,x,nb,na,niter)
[b,a] = stmcb(h,nb,na,niter,ai)
[b,a] = stmcb(y,x,nb,na,niter,ai)
Description Stei gl i tz-McBri de i terati on i s an al gori thm for fi ndi ng an I I R fi l ter wi th a
prescri bed ti me domai n i mpul se response. I t has appl i cati ons i n both fi l ter
desi gn and system i denti fi cati on (parametri c model i ng).
[b,a] = stmcb(h,nb,na) fi nds the coeffi ci ents b and a of the system b(z)/ a(z)
wi th approxi mate i mpul se response h, exactl y nb zeros, and exactl y na pol es.
[b,a] = stmcb(y,x,nb,na) fi nds the system coeffi ci ents b and a of the system
that, gi ven x as i nput, has y as output. x and y must be the same l ength.
[b,a] = stmcb(h,nb,na,niter) and
[b,a] = stmcb(y,x,nb,na,niter) use niter i terati ons. The defaul t for niter
i s 5.
[b,a] = stmcb(h,nb,na,niter,ai) and
[b,a] = stmcb(y,x,nb,na,niter,ai) use the vector ai as the i ni ti al esti mate
of the denomi nator coeffi ci ents. I f ai i s not speci fi ed, stmcb uses the output
argument from [b,ai] = prony(h,0,na) as the vector ai.
stmcb returns the I I R fi l ter coeffi ci ents i n l ength nb+1 and na+1 row vectors b
and a. The fi l ter coeffi ci ents are ordered i n descendi ng powers of z.
H z ( )
B z ( )
A z ( )
-----------
b 1 ( ) b 2 ( )z
1
L b nb 1 + ( )z
nb
+ + +
a 1 ( ) a 2 ( )z
1
L a na 1 + ( )z
na
+ + +
-------------------------------------------------------------------------------------------- = =
stmcb
7-434
Example Approxi mate the i mpul se response of a Butterworth fi l ter wi th a system of
l ower order.
[b,a] = butter(6,0.2);
h = filter(b,a,[1 zeros(1,100)]);
freqz(b,a,128)
[bb,aa] = stmcb(h,4,4);
freqz(bb,aa,128)
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
600
500
400
300
200
100
0
Normalized Frequency ( rad/sample)
P
h
a
s
e

(
d
e
g
r
e
e
s
)
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
300
250
200
150
100
50
0
50
Normalized Frequency ( rad/sample)
M
a
g
n
i
t
u
d
e

(
d
B
)
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
100
80
60
40
20
0
20
Normalized Frequency ( rad/sample)
P
h
a
s
e

(
d
e
g
r
e
e
s
)
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
20
10
0
10
20
30
40
Normalized Frequency ( rad/sample)
M
a
g
n
i
t
u
d
e

(
d
B
)
stmcb
7-435
Algorithm stmcb attempts to mi ni mi ze the squared error between the i mpul se response h
of b(z)/ a(z) and the i nput si gnal x.
stmcb i terates usi ng two steps:
1 I t prefi l ters h and x usi ng 1/a(z).
2 I t sol ves a system of l i near equati ons for b and a usi ng \.
stmcb repeats thi s process niter ti mes. No checki ng i s done to see i f the b and a
coeffi ci ents have converged i n fewer than niter i terati ons.
Diagnostics I f x and y have di fferent l engths, stmcb produces thi s error message,
Input signal X and output signal Y must have the same length.
See Also levinson, lpc, aryule, prony
References [1] Stei gl i tz, K., and L.E. McBri de, A Techni que for the I denti fi cati on of Li near
Systems, I EEE Trans. Automatic Control, Vol . AC-10 (1965), pp. 461-464.
[2] Ljung, L., System I dentification: Theory for the User, Prenti ce-Hal l ,
Engl ewood Cl i ffs, NJ, 1987, p. 297.
mi n
a b ,
x i ( ) h i ( )
2
i 0 =

strips
7-436
7stri ps
Purpose Stri p pl ot
Syntax strips(x)
strips(x,n)
strips(x,sd,fs)
strips(x,sd,fs,scale)
Description strips(x) pl ots vector x i n hori zontal stri ps of l ength 250. I f x i s a matri x,
strips(x) pl ots each col umn of x. The l eft-most col umn (col umn 1) i s the top
hori zontal stri p.
strips(x,n) pl ots vector x i n stri ps that are each n sampl es l ong.
strips(x,sd,fs) pl ots vector x i n stri ps of durati on sd seconds, gi ven a
sampl i ng frequency of fs sampl es per second.
strips(x,sd,fs,scale) scal es the verti cal axes.
I f x i s a matri x, strips(x,n), strips(x,sd,fs), and strips(x,sd,fs,scale)
pl ot the di fferent col umns of x on the same stri p pl ot.
strips i gnores the i magi nary part of compl ex-val ued x.
Example Pl ot two seconds of a frequency modul ated si nusoi d i n 0.25 second stri ps.
fs = 1000; % Sampling frequency
t = 0:1/fs:2; % Time vector
x = vco(sin(2*pi*t),[10 490],fs); % FM waveform
strips(x,0.25,fs)
strips
7-437
See Also plot, stem
0 0.05 0.1 0.15 0.2 0.25
1.75
1.5
1.25
1
0.75
0.5
0.25
0
tf2latc
7-438
7tf2l atc
Purpose Convert transfer functi on fi l ter parameters to l atti ce fi l ter form
Syntax [k,v] = tf2latc(b,a)
k = tf2latc(1,a)
[k,v] = tf2latc(1,a)
k = tf2latc(b)
k = tf2latc(b,phase)
Description [k,v] = tf2latc(b,a) fi nds the l atti ce parameters k and the l adder
parameters v for an I I R (ARMA) l atti ce-l adder fi l ter, normal i zed by a(1). Note
that an error i s generated i f one or more of the l atti ce parameters are exactl y
equal to 1.
k = tf2latc(1,a) fi nds the l atti ce parameters k for an I I R al l -pol e (AR)
l atti ce fi l ter.
[k,v] = tf2latc(1,a) returns the scal ar l adder coeffi ci ent at the correct
posi ti on i n vector v. Al l other el ements of v are zero.
k = tf2latc(b) fi nds the l atti ce parameters k for an FI R (MA) l atti ce fi l ter,
normal i zed by b(1).
k = tf2latc(b,phase) speci fi es the type of FI R (MA) l atti ce fi l ter, where
phase i s
max, for a maxi mum phase fi l ter.
min, for a mi ni mum phase fi l ter.
See Also latc2tf, latcfilt, tf2sos, tf2ss, tf2zp
tf2sos
7-439
7tf2sos
Purpose Convert di gi tal fi l ter transfer functi on data to second-order secti ons form
Syntax [sos,g] = tf2sos(b,a)
[sos,g] = tf2sos(b,a,'order')
[sos,g] = tf2sos(b,a,'order','scale')
sos = tf2sos(...)
Description tf2sos converts a transfer functi on representati on of a gi ven di gi tal fi l ter to an
equi val ent second-order secti on representati on.
[sos,g] = tf2sos(b,a) fi nds a matri x sos i n second-order secti on form wi th
gai n g that i s equi val ent to the di gi tal fi l ter represented by transfer functi on
coeffi ci ent vectors a and b.
sos i s an L-by-6 matri x
whose rows contai n the numerator and denomi nator coeffi ci ents b
ik
and a
ik
of
the second-order secti ons of H(z).
[sos,g] = tf2sos(b,a,'order') speci fi es the order of the rows i n sos, where
'order' i s:
'down', to order the secti ons so the fi rst row of sos contai ns the pol es cl osest
to the uni t ci rcl e
'up', to order the secti ons so the fi rst row of sos contai ns the pol es farthest
from the uni t ci rcl e (defaul t)
H z ( )
B z ( )
A z ( )
-----------
b
1
b
2
z
1
L b
n 1 +
z
n
+ + +
a
1
a
2
z
1
L a
m 1 +
z
m
+ + +
------------------------------------------------------------------------ = =
sos
b
01
b
11
b
21
1 a
11
a
21
b
02
b
12
b
22
1 a
12
a
22
M M M M M M
b
0L
b
1L
b
2L
1 a
1L
a
2L
=
H z ( ) g H
k
z ( )
k 1 =
L

g
b
0k
b
1k
z
1
b
2k
z
2
+ +
1 a
1k
z
1
a
2k
z
2
+ +
--------------------------------------------------------- -
k 1 =
L

= =
tf2sos
7-440
[sos,g] = tf2sos(b,a,'order','scale') speci fi es the desi red scal i ng of the
gai n and numerator coeffi ci ents of al l second-order secti ons, where 'scale' i s:
'none', to appl y no scal i ng (defaul t)
'inf', to appl y i nfi ni ty-norm scal i ng
'two', to appl y 2-norm scal i ng
Usi ng i nfi ni ty-norm scal i ng i n conjuncti on wi th up-orderi ng mi ni mi zes the
probabi l i ty of overfl ow i n the real i zati on. Usi ng 2-norm scal i ng i n conjuncti on
wi th down-orderi ng mi ni mi zes the peak round-off noi se.
sos = tf2sos(...) embeds the overal l system gai n, g, i n the fi rst secti on,
H
1
(z), so that
Algorithm tf2sos uses a four-step al gori thm to determi ne the second-order secti on
representati on for an i nput transfer functi on system:
1 I t fi nds the pol es and zeros of the system gi ven by b and a.
2 I t uses the functi on zp2sos, whi ch fi rst groups the zeros and pol es i nto
compl ex conjugate pai rs usi ng the cplxpair functi on. zp2sos then forms the
second-order secti ons by matchi ng the pol e and zero pai rs accordi ng to the
fol l owi ng rul es:
a Match the pol es cl osest to the uni t ci rcl e wi th the zeros cl osest to those
pol es.
b Match the pol es next cl osest to the uni t ci rcl e wi th the zeros cl osest to
those pol es.
c Conti nue unti l al l of the pol es and zeros are matched.
tf2sos groups real pol es i nto secti ons wi th the real pol es cl osest to them i n
absol ute val ue. The same rul e hol ds for real zeros.
3 I t orders the secti ons accordi ng to the proxi mi ty of the pol e pai rs to the uni t
ci rcl e. tf2sos normal l y orders the secti ons wi th pol es cl osest to the uni t
ci rcl e l ast i n the cascade. You can tel l tf2sos to order the secti ons i n the
reverse order by speci fyi ng the 'down' fl ag.
H z ( ) H
k
z ( )
k 1 =
L

=
tf2sos
7-441
4 tf2sos scal es the secti ons by the norm speci fi ed i n the 'scale' argument.
For arbi trary H(), the scal i ng i s defi ned by
where p can be ei ther or 2. See the references for detai l s on the scal i ng.
Thi s scal i ng i s an attempt to mi ni mi ze overfl ow or peak round-off noi se i n
fi xed poi nt fi l ter i mpl ementati ons.
See Also cplxpair, sos2tf, ss2sos, tf2ss, tf2zp, zp2sos
References [1] Jackson, L.B., Digital Filters and Signal Processing, 3rd ed., Kl uwer
Academi c Publ i shers, Boston, 1996, Chapter 11.
[2] Mi tra, S.K., Digital Signal Processing: A Computer-Based Approach,
McGraw-Hi l l , New York, 1998, Chapter 9.
[3] Vai dyanathan, P.P., Robust Di gi tal Fi l ter Structures, Handbook for
Digital Signal Processing, S.K. Mi tra and J.F. Kai ser, ed., John Wi l ey & Sons,
New York, 1993, Chapter 7.
H
p
1
2
------ H ( )
p
d
0
2

1
p
---
=
tf2ss
7-442
7tf2ss
Purpose Convert transfer functi on fi l ter parameters to state-space form
Syntax [A,B,C,D] = tf2ss(b,a)
Description tf2ss converts the parameters of a transfer functi on representati on of a gi ven
system to those of an equi val ent state-space representati on.
[A,B,C,D] = tf2ss(b,a) returns the A, B, C, and D matri ces of a state space
representati on for the si ngl e-i nput transfer functi on
i n control l er canoni cal form
The i nput vector a contai ns the denomi nator coeffi ci ents i n descendi ng powers
of s. The rows of the matri x b contai n the vectors of numerator coeffi ci ents (each
row corresponds to an output). I n the di screte-ti me case, you must suppl y b and
a to correspond to the numerator and denomi nator pol ynomi al s wi th
coeffi ci ents i n descendi ng powers of z.
For di screte-ti me systems you must make b have the same number of col umns
as the l ength of a. You can do thi s by paddi ng each numerator represented i n b
(and possi bl y the denomi nator represented i n the vector a) wi th trai l i ng zeros.
You can use the functi on eqtflength to accompl i sh thi s i f b and a are vectors
of unequal l engths.
The tf2ss functi on i s part of the standard MATLAB l anguage.
Example Consi der the system
H s ( )
B s ( )
A s ( )
---------- -
b
1
s
n 1
L b
n 1
s b
n
+ + +
a
1
s
m 1
L a
m 1
s a
m
+ + +
------------------------------------------------------------------------ C sI A ( )
1
B D + = = =
x

Ax Bu + =
y Cx Du + =
H s ( )
2s 3 +
s
2
2s 1 + +
s
2
0.4s 1 + +
--------------------------------- =
tf2ss
7-443
To convert thi s system to state-space, type
b = [0 2 3; 1 2 1];
a = [1 0.4 1];
[A,B,C,D] = tf2ss(b,a)
A =
-0.4000 -1.0000
1.0000 0
B =
1
0
C =
2.0000 3.0000
1.6000 0
D =
0
1
Note There i s di sagreement i n the l i terature on nami ng conventi ons for the
canoni cal forms. I t i s easy, however, to generate si mi l ari ty transformati ons
that convert these resul ts to other forms.
See Also sos2ss, ss2tf, tf2sos, tf2zp, zp2ss
tf2zp
7-444
7tf2zp
Purpose Convert transfer functi on fi l ter parameters to zero-pol e-gai n form
Syntax [z,p,k] = tf2zp(b,a)
Description tf2zp fi nds the zeros, pol es, and gai ns of a transfer functi on.
[z,p,k] = tf2zp(b,a) fi nds the matri x of zeros z, the vector of pol es p, and
the associ ated vector of gai ns k from the transfer functi on parameters b and a:
The numerator pol ynomi al s are represented as col umns of the matri x b.
The denomi nator pol ynomi al i s represented i n the vector a.
Gi ven a SI MO conti nuous-ti me system i n pol ynomi al transfer functi on form
or
you can use the output of tf2zp to produce the si ngl e-i nput, mul ti output
(SI MO) factored transfer functi on form
or
H s ( )
B s ( )
A s ( )
---------- -
b
1
s
n 1
L b
n 1
s b
n
+ + +
a
1
s
m 1
L a
m 1
s a
m
+ + +
------------------------------------------------------------------------ = =
H z ( )
B z ( )
A z ( )
------------
b
1
b
2
z
1
L b
n 1
z
n
b
n
z
n 1
+ + +
a
1
a
2
z
1
L a
m 1
z
m
a
m
z
m 1
+ + +
--------------------------------------------------------------------------------------------------- = =
H s ( )
Z s ( )
P s ( )
---------- k
s z
1
( ) s z
2
( )L s z
m
( )
s p
1
( ) s p
2
( )L s p
n
( )
------------------------------------------------------------------ = =
H z ( )
Z z ( )
P z ( )
---------- k
z z
1
( ) z z
2
( )L z z
m
( )
z p
1
( ) z p
2
( )L z p
n
( )
------------------------------------------------------------------- = =
tf2zp
7-445
The fol l owi ng descri bes the i nput and output arguments for tf2zp:
The vector a speci fi es the coeffi ci ents of the denomi nator pol ynomi al A(s)
(or A(z)) i n descendi ng powers of s (z
-1
).
The ith row of the matri x b represents the coeffi ci ents of the ith numerator
pol ynomi al (the ith row of B(s) or B(z)). Speci fy as many rows of b as there
are outputs.
For conti nuous-ti me systems, choose the number nb of col umns of b to be l ess
than or equal to the l ength na of the vector a.
For di screte-ti me systems, choose the number nb of col umns of b to be equal
to the l ength na of the vector a. You can use the functi on eqtflength to
provi de equal l ength vectors i n the case that b and a are vectors of unequal
l engths. Otherwi se, pad the numerators i n the matri x b (and, possi bl y, the
denomi nator vector a) wi th zeros.
The zero l ocati ons are returned i n the col umns of the matri x z, wi th as many
col umns as there are rows i n b.
The pol e l ocati ons are returned i n the col umn vector p and the gai ns for each
numerator transfer functi on i n the vector k.
The tf2zp functi on i s part of the standard MATLAB l anguage.
Example Fi nd the zeros, pol es, and gai ns of the di screte-ti me system
b = [2 3];
a = [1 0.4 1];
[b,a] = eqtflength(b,a); % Make lengths equal.
[z,p,k] = tf2zp(b,a) % Obtain the zero-pole-gain form.
H z ( )
2 3z
1
+
1 0.4z
1
z
2
+ +
----------------------------------------- =
tf2zp
7-446
z =
0
-1.5000
p =
-0.2000 + 0.9798i
-0.2000 - 0.9798i
k =
2
See Also sos2zp, ss2zp, tf2sos, tf2ss, zp2tf
tfe
7-447
7tfe
Purpose Esti mate the transfer functi on from i nput and output
Syntax Txy = tfe(x,y)
Txy = tfe(x,y,nfft)
[Txy,f] = tfe(x,y,nfft,fs)
Txy = tfe(x,y,nfft,fs,window)
Txy = tfe(x,y,nfft,fs,window,numoverlap)
Txy = tfe(x,y,...,'dflag')
tfe(x,y)
Description Txy = tfe(x,y) fi nds a transfer functi on esti mate Txy gi ven i nput si gnal
vector x and output si gnal vector y. The transfer function i s the quoti ent of the
cross spectrum of x and y and the power spectrum of x.
The rel ati onshi p between the i nput x and output y i s model ed by the l i near,
ti me-i nvari ant transfer functi on Txy.
Vectors x and y must be the same l ength. Txy = tfe(x,y) uses the fol l owi ng
defaul t val ues:
nfft = min(256,(length(x))
fs = 2
window i s a peri odi c Hann (Hanni ng) wi ndow of l ength nfft
numoverlap = 0
nfft speci fi es the FFT l ength that tfe uses. Thi s val ue determi nes the
frequenci es at whi ch the power spectrum i s esti mated. fs i s a scal ar that
speci fi es the sampl i ng frequency. window speci fi es a wi ndowi ng functi on and
the number of sampl es tfe uses i n i ts secti oni ng of the x and y vectors.
numoverlap i s the number of sampl es by whi ch the secti ons overl ap. Any
arguments that are omi tted from the end of the parameter l i st use the defaul t
val ues shown above.
I f x i s real , tfe esti mates the transfer functi on at posi ti ve frequenci es onl y; i n
thi s case, the output Txy i s a col umn vector of l ength nfft/2+1 for nfft even
and (nfft+1)/2 for nfft odd. I f x or y i s compl ex, tfe esti mates the transfer
functi on for both posi ti ve and negati ve frequenci es and Txy has l ength nfft.
T
xy
f ( )
P
xy
f ( )
P
xx
f ( )
--------------- =
tfe
7-448
Txy = tfe(x,y,nfft) uses the speci fi ed FFT l ength nfft i n esti mati ng the
transfer functi on.
[Txy,f] = tfe(x,y,nfft,fs) returns a vector f of frequenci es at whi ch tfe
esti mates the transfer functi on. fs i s the sampl i ng frequency. f i s the same si ze
as Txy, so plot(f,Txy) pl ots the transfer functi on esti mate versus properl y
scal ed frequency. fs has no effect on the output Txy; i t i s a frequency scal i ng
mul ti pl i er.
Txy = tfe(x,y,nfft,fs,window) speci fi es a wi ndowi ng functi on and the
number of sampl es per secti on of the x vector. I f you suppl y a scal ar for window,
Txy uses a Hann wi ndow of that l ength. The l ength of the wi ndow must be l ess
than or equal to nfft; tfe zero pads the secti ons i f the l ength of the wi ndow
exceeds nfft.
Txy = tfe(x,y,nfft,fs,window,numoverlap) overl aps the secti ons of x by
numoverlap sampl es.
You can use the empty matri x [] to speci fy the defaul t val ue for any i nput
argument except x or y. For exampl e,
Txy = tfe(x,y,[],[],kaiser(128,5))
uses 256 as the val ue for nfft and 2 as the val ue for fs.
Txy = tfe(x,y,...,'dflag') speci fi es a detrend opti on, where 'dflag' i s:
'linear', to remove the best strai ght-l i ne fi t from the prewi ndowed secti ons
of x and y
'mean', to remove the mean from the prewi ndowed secti ons of x and y
'none', for no detrendi ng (defaul t)
The 'dflag' parameter must appear l ast i n the l i st of i nput arguments. tfe
recogni zes a 'dflag' stri ng no matter how many i ntermedi ate arguments are
omi tted.
tfe(...) wi th no output arguments pl ots the magni tude of the transfer
functi on esti mate as deci bel s versus frequency i n the current fi gure wi ndow.
tfe
7-449
Example Compute and pl ot the transfer functi on esti mate between two col ored noi se
sequences x and y.
h = fir1(30,0.2,rectwin(31));
x = randn(16384,1);
y = filter(h,1,x);
tfe(x,y,1024,[],[],512)
title('Transfer Function Estimate')
Algorithm tfe uses a four-step al gori thm:
1 I t mul ti pl i es the detrended secti ons by window.
2 I t takes the l ength nfft FFT of each secti on.
3 I t averages the squares of the spectra of the x secti ons to form Pxx and
averages the products of the spectra of the x and y secti ons to form Pxy.
4 I t cal cul ates Txy:
Txy = Pxy./Pxx
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
-45
-40
-35
-30
-25
-20
-15
-10
-5
0
5
Frequency
T
r
a
n
f
e
r

F
u
n
c
t
i
o
n

E
s
t
i
m
a
t
e

(
d
B
)
Transfer Function Estimate
tfe
7-450
Diagnostics An appropri ate di agnosti c message i s di spl ayed when i ncorrect arguments are
used.
Requires window's length to be no greater than the FFT length.
Requires NOVERLAP to be strictly less than the window length.
Requires positive integer values for NFFT and NOVERLAP.
Requires vector (either row or column) input.
Requires inputs X and Y to have the same length.
See Also etfe, cohere, csd, pwelch, spa
triang
7-451
7tri ang
Purpose Compute a tri angul ar wi ndow
Syntax w = triang(n)
Description triang(n) returns an n-poi nt tri angul ar wi ndow i n the col umn vector w. The
coeffi ci ents of a tri angul ar wi ndow are
For n odd:
For n even:
The tri angul ar wi ndow i s very si mi l ar to a Bartl ett wi ndow. The Bartl ett
wi ndow al ways ends wi th zeros at sampl es 1 and n, whi l e the tri angul ar
wi ndow i s nonzero at those poi nts. For n odd, the center n-2 poi nts of
triang(n-2) are equi val ent to bartlett(n).
Example N=200;
w = triang(200);
plot(w);
title('Triangular Window')
w k [ ]
2k
n 1 +
------------- 1 k
n 1 +
2
------------- ,
2 n k 1 + ( )
n 1 +
-------------------------------
n 1 +
2
------------- k n ,

'

=
w k [ ]
2k 1
n
---------------- 1 k
n
2
--- ,
2 n k 1 + ( )
n
-------------------------------
n
2
--- 1 + k n ,

'

=
triang
7-452
See Also bartlett, barthannwin, blackman, blackmanharris, bohmanwin, chebwin,
gausswin, hamming, hann, kaiser, nuttallwin, rectwin, tukeywin, window
References [1] Oppenhei m, A.V., and R.W. Schafer, Discrete-Time Signal Processing,
Prenti ce-Hal l , Engl ewood Cl i ffs, NJ, 1989, pp. 447-448.
0 20 40 60 80 100 120 140 160 180 200
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
Triangular Window
tripuls
7-453
7tri pul s
Purpose Generate a sampl ed aperi odi c tri angl e
Syntax y = tripuls(T)
y = tripuls(T,w)
y = tripuls(T,w,s)
Description y = tripuls(T) returns a conti nuous, aperi odi c, symmetri c, uni ty-hei ght
tri angul ar pul se at the ti mes i ndi cated i n array T, centered about T=0 and wi th
a defaul t wi dth of 1.
y = tripuls(T,w) generates a tri angul ar pul se of wi dth w.
y = tripuls(T,w,s) generates a tri angul ar pul se wi th skew s, where
-1 < s < 1. When s i s 0, a symmetri c tri angul ar pul se i s generated.
See Also chirp, cos, diric, gauspuls, pulstran, rectpuls, sawtooth, sin, square,
tripuls
tukeywin
7-454
7tukeywi n
Purpose Compute a Tukey wi ndow
Syntax w = tukeywin(n,)
Description w = tukeywin(n,r) returns an n-poi nt, Tukey wi ndow i n col umn vector w.
Tukey wi ndows are cosi ne-tapered wi ndows. i s the rati o of taper to constant
secti ons and i s between 0 and 1 defi ne. i s a rectwin wi ndow and i s
a hann wi ndow.
Example Compute 128-poi nt Tukey wi ndows wi th fi ve di fferent tapers.
wtuk = [];
for i = linspace(0,1,5)
wtuk = [wtuk tukeywin(128,i)];
end
plot(linspace(0,1,128),wtuk)
axis([0 1 0 1.05 ] );
legend('R=0 Rect.','R=1/4','R=1/2','R=3/4','R=1 Hanning',0);
title('Tukey Windows for Five Taper Ratio Values');
Algorithm The equati on for computi ng the coeffi ci ents of a Tukey wi ndow i s
0 1
0 0.2 0.4 0.6 0.8 1
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
Tukey Windows for Five Taper Ratio Values
R=0 Rect.
R=1/4
R=1/2
R=3/4
R=1 Hanning
tukeywin
7-455
See Also barthannwin, bartlett, blackman, blackmanharris, bohmanwin, chebwin,
gausswin, hann, hamming, kaiser, nuttallwin, rectwin, triang, window
References [1] harri s, f. j. On the Use of Wi ndows for Harmoni c Anal ysi s wi th the Di screte
Fouri er Transform. Proceedings of the I EEE. Vol . 66 (January 1978). pp.
66-67.
w k 1 + [ ]
1.0 0 k
N
2
---- 1 + ( ) ,
0.5 1.0
k
N
2
---- 1 + ( )
N 1 ( )
--------------------------------- cos +
N
2
---- 1 + ( ) k N ,

'

=
udecode
7-456
7udecode
Purpose Decode 2
n
-l evel quanti zed i nteger i nputs to fl oati ng-poi nt outputs
Syntax y = udecode(u,n)
y = udecode(u,n,v)
y = udecode(u,n,v,'saturatemode')
Description y = udecode(u,n) i nverts the operati on of uencode and reconstructs
quanti zed fl oati ng-poi nt val ues from an encoded mul ti di mensi onal array of
i ntegers u. The i nput argument n must be an i nteger between 2 and 32. The
i nteger n speci fi es that there are 2
n
quanti zati on l evel s for the i nputs, so that
entri es i n u must be ei ther:
Si gned i ntegers i n the range [-2
n
/2, (2
n
/2) - 1]
Unsi gned i ntegers i n the range [0, 2
n
-1]
I nputs can be real or compl ex val ues of any i nteger data type (uint8, uint16,
uint32, int8, int16, int32). Overfl ows (entri es i n u outsi de of the ranges
speci fi ed above) are saturated to the endpoi nts of the range i nterval . The
output y has the same di mensi ons as u. I ts entri es have val ues i n the range
[-1,1].
y = udecode(u,n,v) decodes u such that the output y has val ues i n the range
[-v,v], where the defaul t val ue for v i s 1.
y = udecode(u,n,v,'SaturateMode') decodes u and treats i nput overfl ows
(entri es i n u outsi de of [-v,v]) accordi ng to the stri ng 'saturatemode', whi ch
can be one of the fol l owi ng:
'saturate': Saturate overfl ows. Thi s i s the defaul t method for treati ng
overfl ows.
- Entri es i n si gned i nputs u whose val ues are outsi de of the range
[-2
n
/2, (2
n
/2) - 1] are assi gned the val ue determi ned by the cl osest endpoi nt
of thi s i nterval .
- Entri es i n unsi gned i nputs u whose val ues are outsi de of the range
[0, 2
n
-1] are assi gned the val ue determi ned by the cl osest endpoi nt of thi s
i nterval .
udecode
7-457
'wrap': Wrap al l overfl ows accordi ng to the fol l owi ng:
- Entri es i n si gned i nputs u whose val ues are outsi de of the range
[-2
n
/2, (2
n
/2) - 1] are wrapped back i nto that range usi ng modul o 2
n
ari thmeti c (cal cul ated usi ng u = mod(u+2^n/2,2^n)-(2^n/2)).
- Entri es i n unsi gned i nputs u whose val ues are outsi de of the range
[0, 2
n
-1] are wrapped back i nto the requi red range before decodi ng usi ng
modul o 2
n
ari thmeti c (cal cul ated usi ng u = mod(u,2^n)).
Examples u = int8([-1 1 2 -5]); % Create a signed 8-bit integer string.
ysat = udecode(u,3) % Decode with 3 bits.
ysat =
-0.2500 0.2500 0.5000 -1.0000
Noti ce the l ast entry i n u saturates to 1, the defaul t peak i nput magni tude.
Change the peak i nput magni tude.
ysatv = udecode(u,3,6) % Set the peak input magnitude to 6.
ysatv =
-1.5000 1.5000 3.0000 -6.0000
The l ast i nput entry sti l l saturates. Try wrappi ng the overfl ows.
ywrap = udecode(u,3,6,'wrap')
ywrap =
-1.5000 1.5000 3.0000 4.5000
Try addi ng more quanti zati on l evel s.
yprec = udecode(u,5)
yprec =
-0.0625 0.0625 0.1250 -0.3125
Algorithm The al gori thm adheres to the defi ni ti on for uni form decodi ng speci fi ed i n I TU-T
Recommendati on G.701. I nteger i nput val ues are uni quel y mapped (decoded)
from one of 2
n
uni forml y spaced i nteger val ues to quanti zed fl oati ng-poi nt
val ues i n the range [-v,v]. The smal l est i nteger i nput val ue al l owed i s
mapped to -v and the l argest i nteger i nput val ue al l owed i s mapped to v.
udecode
7-458
Val ues outsi de of the al l owabl e i nput range are ei ther saturated or wrapped,
accordi ng to speci fi cati on.
The real and i magi nary components of compl ex i nputs are decoded
i ndependentl y.
See Also uencode
References General Aspects of Digital Transmission Systems: Vocabulary of Digital
Transmission and Multiplexing, and Pulse Code Modulation (PCM) Terms,
I nternati onal Tel ecommuni cati on Uni on, I TU-T Recommendati on G.701,
March, 1993.
uencode
7-459
7uencode
Purpose Quanti ze and encode fl oati ng-poi nt i nputs to i nteger outputs
Syntax y = uencode(u,n)
y = uencode(u,n,v)
y = uencode(u,n,v,'SignFlag')
Description y = uencode(u,n) quanti zes the entri es i n a mul ti di mensi onal array of
fl oati ng-poi nt numbers u and encodes them as i ntegers usi ng 2
n
-l evel
quanti zati on. n must be an i nteger between 2 and 32 (i ncl usi ve). I nputs can be
real or compl ex, doubl e- or si ngl e-preci si on. The output y and the i nput u are
arrays of the same si ze. The el ements of the output y are unsi gned i ntegers
wi th magni tudes i n the range [0, 2
n
-1]. El ements of the i nput u outsi de of the
range [-1,1] are treated as overfl ows and are saturated.
For entri es i n the i nput u that are l ess than -1, the val ue of the output of
uencode i s 0.
For entri es i n the i nput u that are greater than 1, the val ue of the output of
uencode i s 2
n
-1.
y = uencode(u,n,v) al l ows the i nput u to have entri es wi th fl oati ng-poi nt
val ues i n the range [-v,v] before saturati ng them (the defaul t val ue for v i s 1).
El ements of the i nput u outsi de of the range [-v,v] are treated as overfl ows
and are saturated.
For i nput entri es l ess than -v, the val ue of the output of uencode i s 0.
For i nput entri es greater than v, the val ue of the output of uencode i s 2
n
-1.
y = uencode(u,n,v,'SignFlag') maps entri es i n a mul ti di mensi onal array of
fl oati ng-poi nt numbers u whose entri es have val ues i n the range [-v,v] to an
i nteger output y. I nput entri es outsi de thi s range are saturated. The i nteger
type of the output depends on the stri ng 'SignFlag' and the number of
quanti zati on l evel s 2
n
. The stri ng 'SignFlag' can be one of the fol l owi ng:
'signed': Outputs are si gned i ntegers wi th magni tudes i n the range
[-2
n
/2, (2
n
/2) - 1].
'unsigned' (defaul t): Outputs are unsi gned i ntegers wi th magni tudes i n the
range [0, 2
n
-1].
uencode
7-460
The output data types are opti mi zed for the number of bi ts as shown i n the
tabl e bel ow.
Examples Map fl oati ng-poi nt scal ars i n [-1, 1] to uint8 (unsi gned) i ntegers, and produce
a stai rcase pl ot. Note that the hori zontal axi s pl ots from -1 to 1 and the verti cal
axi s pl ots from 0 to 7 (2^3-1).
u = [-1:0.01:1];
y = uencode(u,3);
plot(u,y,'.')
n Unsigned Integer Signed Integer
2 to 8 uint8 int8
9 to 16 uint16 int16
17 to 32 uint32 int32
1 0.8 0.6 0.4 0.2 0 0.2 0.4 0.6 0.8 1
0
1
2
3
4
5
6
7
uencode
7-461
Now l ook at saturati on effects when you under speci fy the peak val ue for the
i nput.
u = [-2:0.5:2];
y = uencode(u,5,1)
y =
0 0 0 8 16 24 31 31 31
Now l ook at the output for
u = [-2:0.5:2];
y = uencode(u,5,2,'signed')
y =
-8 -4 0 4 8 12 16 20 23
Algorithm uencode maps the fl oati ng-poi nt i nput val ue to an i nteger val ue determi ned by
the requi rement for 2
n
l evel s of quanti zati on. Thi s encodi ng adheres to the
defi ni ti on for uni form encodi ng speci fi ed i n I TU-T Recommendati on G.701.
The i nput range [-v,v] i s di vi ded i nto 2
n
evenl y spaced i nterval s. I nput
entri es i n the range [-v,v] are fi rst quanti zed accordi ng to thi s subdi vi si on of
the i nput range, and then mapped to one of 2
n
i ntegers. The range of the output
depends on whether or not you speci fy that you want si gned i ntegers.
See Also udecode
References General Aspects of Digital Transmission Systems: Vocabulary of Digital
Transmission and Multiplexing, and Pulse Code Modulation (PCM) Terms,
I nternati onal Tel ecommuni cati on Uni on, I TU-T Recommendati on G.701,
March, 1993.
unwrap
7-462
7unwrap
Purpose Unwrap phase angl es
Syntax p = unwrap(p)
Description p = unwrap(p) corrects the phase angl es i n vector p by addi ng mul ti pl es of
, where needed, to smooth the transi ti ons across branch cuts. When p i s a
matri x, unwrap corrects the phase angl es down each col umn. The phase must
be i n radi ans.
The unwrap functi on i s part of the standard MATLAB l anguage.
Limitations unwrap tri es to detect branch cut crossi ngs, but i t can be fool ed by sparse,
rapi dl y changi ng phase val ues.
See Also abs, angle
2 t
upfirdn
7-463
7upfi rdn
Purpose Upsampl e, appl y an FI R fi l ter, and downsampl e
Syntax yout = upfirdn(xin,h)
yout = upfirdn(xin,h,p)
yout = upfirdn(xin,h,p,q)
[yout,zf] = upfirdn(xin,h,...,zi)
Description upfirdn performs a cascade of three operati ons:
1 Upsampl i ng the i nput data i n the matri x xin by a factor of the i nteger p
(i nserti ng zeros)
2 FI R fi l teri ng the upsampl ed si gnal data wi th the i mpul se response sequence
gi ven i n the vector or matri x h
3 Downsampl i ng the resul t by a factor of the i nteger q (throwi ng away
sampl es)
upfirdn has been i mpl emented as a MEX-fi l e for maxi mum speed, so onl y the
outputs actual l y needed are computed. The FI R fi l ter i s usual l y a l owpass
fi l ter, whi ch you must desi gn usi ng another functi on such as remez or fir1.
Note The functi on resample performs an FI R desi gn usi ng firls, fol l owed
by rate changi ng i mpl emented wi th upfirdn.
yout = upfirdn(xin,h) fi l ters the i nput si gnal xin wi th the FI R fi l ter havi ng
i mpul se response h. I f xin i s a row or col umn vector, then i t represents a si ngl e
si gnal . I f xin i s a matri x, then each col umn i s fi l tered i ndependentl y. I f h i s a
row or col umn vector, then i t represents one FI R fi l ter. I f h i s a matri x, then
each col umn i s a separate FI R i mpul se response sequence. I f yout i s a row or
col umn vector, then i t represents one si gnal . I f yout i s a matri x, then each
col umn i s a separate output. No upsampl i ng or downsampl i ng i s i mpl emented
wi th thi s syntax.
yout = upfirdn(xin,h,p) speci fi es the i nteger upsampl i ng factor p, where p
has a defaul t val ue of 1.
upfirdn
7-464
yout = upfirdn(xin,h,p,q) speci fi es the i nteger downsampl i ng factor q,
where q has a defaul t val ue of 1.
[yout,zf] = upfirdn(xin,h,...,zi) speci fi es i ni ti al state condi ti ons i n the
vector zi.
The si ze of the i ni ti al condi ti on vector zi must be the same as length(h)-1, the
number of del ays i n the FI R fi l ter.
When xin i s a vector, the si ze of the fi nal condi ti on vector zf i s length(h)-1,
the number of del ays i n the fi l ter. When xin i s a matri x, zf i s an matri x wi th
(length(h)-1) rows and (size(xin,2)) col umns.
Note Si nce upfirdn performs convol uti on and rate changi ng, the yout
si gnal s have a di fferent l ength than xin. The number of rows of yout i s
approxi matel y p/q ti mes the number of rows of xin.
Remarks Usual l y the i nputs xin and the fi l ter h are vectors, i n whi ch case onl y one
output si gnal i s produced. However, when these arguments are arrays, each
col umn i s treated as a separate si gnal or fi l ter. Val i d combi nati ons are:
1 xin i s a vector and h i s a vector.
There i s one fi l ter and one si gnal , so the functi on convol ves xin wi th h. The
output si gnal yout i s a row vector i f xin i s a row; otherwi se, yout i s a col umn
vector.
2 xin i s a matri x and h i s a vector.
There i s one fi l ter and many si gnal s, so the functi on convol ves h wi th each
col umn of xin. The resul ti ng yout wi l l be an matri x wi th the same number
of col umns as xin.
3 xin i s a vector and h i s a matri x.
There are many fi l ters and one si gnal , so the functi on convol ves each col umn
of h wi th xin. The resul ti ng yout wi l l be an matri x wi th the same number of
col umns as h.
upfirdn
7-465
4 xin i s a matri x and h i s a matri x, both wi th the same number of col umns.
There are many fi l ters and many si gnal s, so the functi on convol ves
correspondi ng col umns of xin and h. The resul ti ng yout i s an matri x wi th
the same number of col umns as xin and h.
Examples I f both p and q are equal to 1 (that i s, there i s no rate changi ng), the resul t i s
ordi nary convol uti on of two si gnal s (equi val ent to conv).
yy = upfirdn(xx,hh);
Thi s exampl e i mpl ements a seven-channel fi l ter bank by convol vi ng seven
di fferent fi l ters wi th one i nput si gnal , then downsampl es by fi ve.
% Assume that hh is an L-by-7 array of filters.
yy = upfirdn(xx,hh,1,5);
I mpl ement a rate change from 44.1 kHz (CD sampl i ng rate) to 48 kHz (DAT
rate), a rati o of 160/147. Thi s requi res a l owpass fi l ter wi th cutoff frequency at

c
= 2/160.
% Design lowpass filter with cutoff at 1/160th of fs.
hh = fir1(300,2/160); % Need a very long lowpass filter
yy = upfirdn(xx,hh,160,147);
I n thi s exampl e, the fi l ter desi gn and resampl i ng are separate steps. Note that
resample woul d do both steps as one.
Algorithm upfirdn uses a pol yphase i nterpol ati on structure. The number of mul ti pl y-add
operati ons i n the pol yphase structure i s approxi matel y (L
h
L
x
-pL
x
)/q where L
h

and L
x
are the l engths of h[n] and x[n], respecti vel y.
A more accurate fl ops count i s computed i n the program, but the actual count
i s sti l l approxi mate. For l ong si gnal s x[n], the formul a i s often exact.
Diagnostics I f p and q are l arge and do not have many common factors, you may see thi s
message
Filter length is too large - reduce problem complexity.
I nstead, you shoul d use an i nterpol ati on functi on, such as interp1, to perform
the resampl i ng and then fi l ter the i nput.
upfirdn
7-466
See Also conv, decimate, downsample, filter, interp, intfilt, resample, upsample
References [1] Crochi ere, R.E., and L.R. Rabi ner, Multi-Rate Signal Processing,
Prenti ce-Hal l , Engl ewood Cl i ffs, NJ, 1983, pp. 88-91.
[2] Crochi ere, R.E., A General Program to Perform Sampl i ng Rate Conversi on
of Data by Rati onal Rati os, Programs for Digital Signal Processing, I EEE
Press, New York, 1979, pp. 8.2-1 to 8.2-7.
upsample
7-467
7upsampl e
Purpose I ncrease the sampl i ng rate of the i nput si gnal
Syntax y = upsample(x,n)
y = upsample(x,n,phase)
Description y = upsample(x,n) i ncreases the sampl i ng rate of x by i nserti ng n-1 zeros
between sampl es. x can be a vector or a matri x. I f x i s a matri x, each col umn i s
consi dered a separate sequence. The upsampl ed y has x*n sampl es.
y = upsample(x,n,phase) speci fi es the number of sampl es by whi ch to offset
the upsampl ed sequence. phase must be an i nteger from 0 to n-1.
Examples I ncrease the sampl i ng rate of a sequence by 3.
x = [1 2 3 4];
y = upsample(x,3);
x,y
x =
1 2 3 4
y =
1 0 0 2 0 0 3 0 0 4 0 0
I ncrease the sampl i ng rate of the sequence by 3 and add a phase offset of 2.
x = [1 2 3 4];
y = upsample(x,3,2);
x,y
x =
1 2 3 4
y =
0 0 1 0 0 2 0 0 3 0 0 4
upsample
7-468
I ncrease the sampl i ng rate of a matri x by 3.
x = [1 2; 3 4; 5 6;];
y = upsample(x,3);
x,y
x =
1 2
3 4
5 6
y =
1 2
0 0
0 0
3 4
0 0
0 0
5 6
0 0
0 0
See Also decimate, downsample, interp, interp1, resample, spline, upfirdn
vco
7-469
7vco
Purpose Vol tage control l ed osci l l ator
Syntax y = vco(x,fc,fs)
y = vco(x,[Fmin Fmax],fs)
Description y = vco(x,fc,fs) creates a si gnal that osci l l ates at a frequency determi ned
by the real i nput vector or array x wi th sampl i ng frequency fs. fc i s the carri er
or reference frequency; when x i s 0, y i s an fc Hz cosi ne wi th ampl i tude 1
sampl ed at fs Hz. x ranges from -1 to 1, where x = -1 corresponds to
0 frequency output, x = 0 corresponds to fc, and x = 1 corresponds to 2*fc.
Output y i s the same si ze as x.
y = vco(x,[Fmin Fmax],fs) scal es the frequency modul ati on range so that
1 val ues of x yi el d osci l l ati ons of Fmin Hz and Fmax Hz respecti vel y. For best
resul ts, Fmin and Fmax shoul d be i n the range 0 to fs/2.
By defaul t, fs i s 1 and fc i s fs/4.
I f x i s a matri x, vco produces a matri x whose col umns osci l l ate accordi ng to the
col umns of x.
Example Generate two seconds of a si gnal sampl ed at 10,000 sampl es/second whose
i nstantaneous frequency i s a tri angl e functi on of ti me.
fs = 10000;
t = 0:1/fs:2;
x = vco(sawtooth(2*pi*t,0.75),[0.1 0.4]*fs,fs);
Pl ot the spectrogram of the generated si gnal .
specgram(x,512,fs,kaiser(256,5),220)
vco
7-470
Algorithm vco performs FM modul ati on usi ng the modulate functi on.
Diagnostics I f any val ues of x l i e outsi de [-1, 1], vco gi ves the fol l owi ng error message.
X outside of range [-1,1].
See Also demod, modulate
Time
F
r
e
q
u
e
n
c
y
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8
0
500
1000
1500
2000
2500
3000
3500
4000
4500
5000
window
7-471
7wi ndow
Purpose Compute a speci fi c wi ndow
Syntax w = window(fhandle,n)
w = window(fhandle,n,winopt)
w = window(fhandle,n,sidelobe)
Description w = window(fhandle,n) returns the n-poi nt wi ndow, speci fi ed by i ts functi on
handl e, fhandle, i n col umn vector w. Functi on handl es are wi ndow functi on
names preceded by an @.
Note For more i nformati on on each wi ndow functi on and i ts opti on(s), refer
to i ts reference page.
w = window(fhandle,N,winopt) returns the wi ndow speci fi ed by i ts functi on
handl e, fhandle, and i ts opti on val ue or stri ng i n winopt. Onl y blackman,
chebwin, gausswin, hamming, hann, and tukeywin wi ndows take an opti on.
w = window(fhandle,N,sidelobe) returns the wi ndow speci fi ed by i ts
functi on handl e, fhandle. I f fhandle i s ei ther @chebwin or @kaiser, a second
numeri cal parameter must be entered. For Chebyshev sidelobe i s the number
of deci bel s that the si del obe magni tude i s bel ow the mai nl obe; for Kai ser
sidelobe i s the beta val ue.
Example Create and pl ot three wi ndows.
N = 65;
@barthannwin @hamming
@bartlett @hann
@blackman @kaiser
@blackmanharris @nuttallwin
@bohmanwin @rectwin
@chebwin @triang
@gausswin @tukeywin
window
7-472
w = window(@blackmanharris,N);
w1 = window(@hamming,N);
w2 = window(@gausswin,N,2.5);
plot(1:N,[w,w1,w2]); axis([1 N 0 1]);
legend('Blackman-Harris','Hamming','Gaussian');
See Also barthannwin, bartlett, blackman, blackmanharris, bohmanwin, chebwin,
gausswin, hamming, hann, kaiser, nuttallwin, rectwin, triang, tukeywin
10 20 30 40 50 60
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
BlackmanHarris
Hamming
Gaussian
xcorr
7-473
7xcorr
Purpose Esti mate the cross-correl ati on functi on
Syntax c = xcorr(x,y)
c = xcorr(x)
c = xcorr(x,y,'option')
c = xcorr(x,'option')
c = xcorr(x,y,maxlags)
c = xcorr(x,maxlags)
c = xcorr(x,y,maxlags,'option')
c = xcorr(x,maxlags,'option')
[c,lags] = xcorr(...)
Description xcorr esti mates the cross-correl ati on sequence of a random process.
Autocorrel ati on i s handl ed as a speci al case.
The true cross-correl ati on sequence i s
where x
n
and y
n
are joi ntl y stati onary random processes, , and E {}
i s the expected val ue operator. xcorr must esti mate the sequence because, i n
practi ce, onl y a fi ni te segment of one real i zati on of the i nfi ni te-l ength random
process i s avai l abl e.
c = xcorr(x,y) returns the cross-correl ati on sequence i n a l ength 2*N-1
vector, where x and y are l ength N vectors (N>1). I f x and y are not the same
l ength, the shorter vector i s zero-padded to the l ength of the l onger vector.
By defaul t, xcorr computes raw correl ati ons wi th no normal i zati on.
The output vector c has el ements gi ven by c(m) = c
xy
(m-N), m=1, ..., 2N-1.
I n general , the correl ati on functi on requi res normal i zati on to produce an
accurate esti mate (see bel ow).
R
xy
m ( ) E{x
n m +
y
*
n
} E{x
n
y
*
n m
} = =
n < <
R

xy m ( )
x
n m +
y
n
*
n 0 =
N m 1

m 0
R

yx
*
m ( ) m 0 <

'

=
xcorr
7-474
c = xcorr(x) i s the autocorrel ati on sequence for the vector x. I f x i s an N-by-P
matri x, c i s a matri x wi th 2N-1 rows whose P
2
col umns contai n the
cross-correl ati on sequences for al l combi nati ons of the col umns of x. For more
i nformati on on matri x processi ng wi th xcorr, see Mul ti pl e Channel s on
page 3-5.
c = xcorr(x,y,'option') speci fi es a normal i zati on opti on for the
cross-correl ati on, where 'option' i s:
'biased': Bi ased esti mate of the cross-correl ati on functi on
'unbiased': Unbi ased esti mate of the cross-correl ati on functi on
'coeff': Normal i zes the sequence so the autocorrel ati ons at zero l ag are
i denti cal l y 1.0
'none', to use the raw, unscal ed cross-correl ati ons (defaul t)
See reference [1] for more i nformati on on the properti es of bi ased and unbi ased
correl ati on esti mates.
c = xcorr(x,'option') speci fi es one of the above normal i zati on opti ons for
the autocorrel ati on.
c = xcorr(x,y,maxlags) returns the cross-correl ati on sequence over the l ag
range [-maxlags:maxlags]. Output c has l ength 2*maxlags+1.
c = xcorr(x,maxlags) returns the autocorrel ati on sequence over the l ag
range [-maxlags:maxlags]. Output c has l ength 2*maxlags+1. I f x i s an
N-by-P matri x, c i s a matri x wi th 2*maxlags+1 rows whose P
2
col umns contai n
the autocorrel ati on sequences for al l combi nati ons of the col umns of x.
c = xcorr(x,y,maxlags,'option') speci fi es both a maxi mum number of l ags
and a scal i ng opti on for the cross-correl ati on.
c = xcorr(x,maxlags,'option') speci fi es both a maxi mum number of l ags
and a scal i ng opti on for the autocorrel ati on.
c
xy biased ,
m ( )
1
N
----c
xy
m ( ) =
c
xy unbiased ,
m ( )
1
N m
-------------------c
xy
m ( ) =
xcorr
7-475
[c,lags] = xcorr(...) returns a vector of the l ag i ndi ces at whi ch c was
esti mated, wi th the range [-maxlags:maxlags]. When maxlags i s not
speci fi ed, the range of lags i s [-N+1:N-1].
I n al l cases, the cross-correl ati on or autocorrel ati on computed by xcorr has the
zeroth l ag i n the mi ddl e of the sequence, at el ement or row maxlags+1 (el ement
or row N i f maxlags i s not speci fi ed).
Examples The second output, lags, i s useful for pl otti ng the cross-correl ati on or
autocorrel ati on. For exampl e, the esti mated autocorrel ati on of zero-mean
Gaussi an whi te noi se c
ww
(m) can be di spl ayed for -10 m 10 usi ng
ww = randn(1000,1);
[c_ww,lags] = xcorr(ww,10,'coeff');
stem(lags,c_ww)
Swappi ng the x and y i nput arguments reverses (and conjugates) the output
correl ati on sequence. For row vectors, the resul ti ng sequences are reversed l eft
to ri ght; for col umn vectors, up and down. The fol l owi ng exampl e i l l ustrates
thi s property (mat2str i s used for a compact di spl ay of compl ex numbers).
x = [1,2i,3]; y = [4,5,6];
[c1,lags] = xcorr(x,y);
c1 = mat2str(c1,2), lags
c1 =
[6-i*8.9e-016 5+i*12 22+i*10 15+i*8 12+i*8.9e-016]
lags =
-2 -1 0 1 2
c2 = conj(fliplr(xcorr(y,x)));
c2 = mat2str(c2,2)
c2 =
[6-i*8.9e-016 5+i*12 22+i*10 15+i*8 12+i*8.9e-016]
For the case where i nput argument x i s a matri x, the output col umns are
arranged so that extracti ng a row and rearrangi ng i t i nto a square array
produces the cross-correl ati on matri x correspondi ng to the l ag of the chosen
row. For exampl e, the cross-correl ati on at zero l ag can be retri eved by
randn('state',0)
X = randn(2,2);
[M,P] = size(X);
c = xcorr(X);
xcorr
7-476
c0 = zeros(P); c0(:) = c(M,:) % Extract zero-lag row
c0 =
2.9613 -0.5334
-0.5334 0.0985
You can cal cul ate the matri x of correl ati on coeffi ci ents that the MATLAB
functi on corrcoef generates by substi tuti ng
c = xcov(X,'coef')
i n the l ast exampl e. The functi on xcov subtracts the mean and then cal l s
xcorr.
Use fftshift to move the second hal f of the sequence starti ng at the zeroth l ag
to the front of the sequence. fftshift swaps the fi rst and second hal ves of a
sequence.
Algorithm For more i nformati on on esti mati ng covari ance and correl ati on functi ons, see
[1].
See Also conv, corrcoef, cov, xcorr2, xcov
References [1] Orfani di s, S.J., Optimum Signal Processing. An I ntroduction. 2nd Edition,
Prenti ce-Hal l , Engl ewood Cl i ffs, NJ, 1996.
xcorr2
7-477
7xcorr2
Purpose Esti mate the two-di mensi onal cross-correl ati on
Syntax C = xcorr2(A)
C = xcorr2(A,B)
Description C = xcorr2(A,B) returns the cross-correl ati on of matri ces A and B wi th no
scal i ng. xcorr2 i s the two-di mensi onal versi on of xcorr. I t has i ts maxi mum
val ue when the two matri ces are al i gned so that they are shaped as si mi l arl y
as possi bl e.
xcorr2(A) i s the autocorrel ati on matri x of i nput matri x A. I t i s i denti cal to
xcorr2(A,A).
See Also conv2, filter2, xcorr
xcov
7-478
7xcov
Purpose Esti mate the cross-covari ance functi on (mean-removed cross-correl ati on)
Syntax v = xcov(x,y)
v = xcov(x)
v = xcov(x,'option')
[c,lags] = xcov(x,y,maxlags)
[c,lags] = xcov(x,maxlags)
[c,lags] = xcov(x,y,maxlags,'option')
Description xcov esti mates the cross-covari ance sequence of random processes.
Autocovari ance i s handl ed as a speci al case.
The true cross-covari ance sequence i s the cross-correl ati on of mean-removed
sequences
where and are the mean val ues of the two stati onary random processes,
and E{} i s the expected val ue operator. xcov esti mates the sequence because,
i n practi ce, access i s avai l abl e to onl y a fi ni te segment of the i nfi ni te-l ength
random process.
v = xcov(x,y) returns the cross-covari ance sequence i n a l ength 2N-1 vector,
where x and y are l ength N vectors. For i nformati on on how arrays are
processed wi th xcov, see Mul ti pl e Channel s on page 3-5.
v = xcov(x) i s the autocovari ance sequence for the vector x. Where x i s an
N-by-P array, v = xcov(x) returns an array wi th 2N-1 rows whose P
2
col umns
contai n the cross-covari ance sequences for al l combi nati ons of the col umns of x.
By defaul t, xcov computes raw covari ances wi th no normal i zati on. For a
l ength N vector

xy
( ) E x
n m +

x
( ) y
n

y
( )
*
{ } =

x

y
c
xy
m ( )
x n m + ( )
1
N
---- x
i
i 0 =
N 1

,


_
y
n
*
1
N
---- y
i
*
i 0 =
N 1

,


_
n 0 =
N m 1

m 0
c
yx
*
m ( ) m 0 <

'

=
xcov
7-479
The output vector c has el ements gi ven by c(m) = c
xy
(m-N), m= 1, ..., 2N-1.
The covari ance functi on requi res normal i zati on to esti mate the functi on
properl y.
v = xcov(x,'option') speci fi es a scal i ng opti on, where 'option' i s:
'biased', for bi ased esti mates of the cross-covari ance functi on
'unbiased', for unbi ased esti mates of the cross-covari ance functi on
'coeff', to normal i ze the sequence so the auto-covari ances at zero l ag are
i denti cal l y 1.0
'none', to use the raw, unscal ed cross-covari ances (defaul t)
See [1] for more i nformati on on the properti es of bi ased and unbi ased
correl ati on and covari ance esti mates.
[c,lags] = xcov(x,y,maxlags) where x and y are l ength m vectors, returns
the cross-covari ance sequence i n a l ength 2*maxlags+1 vector c. lags i s a
vector of the l ag i ndi ces where c was esti mated, that i s, [-maxlags:maxlags].
[c,lags] = xcov(x,maxlags) i s the autocovari ance sequence over the range
of l ags [-maxlags:maxlags].
[c,lags] = xcov(x,maxlags) where x i s an m-by-p array, returns array c wi th
2*maxlags+1 rows whose P
2
col umns contai n the cross-covari ance sequences
for al l combi nati ons of the col umns of x.
[c,lags] = xcov(x,y,maxlags,'option') speci fi es a scal i ng opti on, where
'option' i s the l ast i nput argument.
I n al l cases, xcov gi ves an output such that the zeroth l ag of the covari ance
vector i s i n the mi ddl e of the sequence, at el ement or row maxlag+1 or at m.
Examples The second output lags i s useful when pl otti ng. For exampl e, the esti mated
autocovari ance of uni form whi te noi se c
ww
(m) can be di spl ayed for -10 m 10
usi ng
ww = randn(1000,1); % Generate uniform noise with mean = 1/2.
[cov_ww,lags] = xcov(ww,10,'coeff');
stem(lags,cov_ww)
xcov
7-480
Algorithm xcov computes the mean of i ts i nputs, subtracts the mean, and then cal l s
xcorr. For more i nformati on on esti mati ng covari ance and correl ati on
functi ons, see [1].
Diagnostics xcov does not check for any errors other than the correct number of i nput
arguments. I nstead, i t rel i es on the error checki ng i n xcorr.
See Also conv, corrcoef, cov, xcorr, xcorr2
References [1] Orfani di s, S.J., Optimum Signal Processing. An I ntroduction. 2nd Edition,
Prenti ce-Hal l , Engl ewood Cl i ffs, NJ, 1996.
yulewalk
7-481
7yul ewal k
Purpose Recursi ve di gi tal fi l ter desi gn
Syntax [b,a] = yulewalk(n,f,m)
Description yulewalk desi gns recursi ve I I R di gi tal fi l ters usi ng a l east-squares fi t to a
speci fi ed frequency response.
[b,a] = yulewalk(n,f,m) returns row vectors b and a contai ni ng the n+1
coeffi ci ents of the order n I I R fi l ter whose frequency-magni tude characteri sti cs
approxi matel y match those gi ven i n vectors f and m:
f i s a vector of frequency poi nts, speci fi ed i n the range between 0 and 1,
where 1 corresponds to hal f the sampl e frequency (the Nyqui st frequency).
The fi rst poi nt of f must be 0 and the l ast poi nt 1, wi th al l i ntermedi ate
poi nts i n i ncreasi ng order. Dupl i cate frequency poi nts are al l owed,
correspondi ng to steps i n the frequency response.
m i s a vector contai ni ng the desi red magni tude response at the poi nts
speci fi ed i n f.
f and m must be the same l ength.
plot(f,m) di spl ays the fi l ter shape.
The output fi l ter coeffi ci ents are ordered i n descendi ng powers of z.
When speci fyi ng the frequency response, avoi d excessi vel y sharp transi ti ons
from passband to stopband. You may need to experi ment wi th the sl ope of the
transi ti on regi on to get the best fi l ter desi gn.
Example Desi gn an 8th-order l owpass fi l ter and overpl ot the desi red frequency response
wi th the actual frequency response.
f = [0 0.6 0.6 1];
m = [1 1 0 0];
[b,a] = yulewalk(8,f,m);
[h,w] = freqz(b,a,128);
plot(f,m,w/pi,abs(h),'--')
legend('Ideal','yulewalk Designed')
title('Comparison of Frequency Response Magnitudes')
B z ( )
A z ( )
-----------
b 1 ( ) b 2 ( )z
1
L b n 1 + ( )z
n
+ + +
a 1 ( ) a 2 ( )z
1
L a n 1 + ( )z
n
+ + +
------------------------------------------------------------------------------------- =
yulewalk
7-482
Algorithm yulewalk performs a l east-squares fi t i n the ti me domai n. I t computes the
denomi nator coeffi ci ents usi ng modi fi ed Yul e-Wal ker equati ons, wi th
correl ati on coeffi ci ents computed by i nverse Fouri er transformati on of the
speci fi ed frequency response. To compute the numerator, yulewalk takes the
fol l owi ng steps:
1 Computes a numerator pol ynomi al correspondi ng to an addi ti ve
decomposi ti on of the power frequency response.
2 Eval uates the compl ete frequency response correspondi ng to the numerator
and denomi nator pol ynomi al s.
3 Uses a spectral factori zati on techni que to obtai n the i mpul se response of the
fi l ter.
4 Obtai ns the numerator pol ynomi al by a l east-squares fi t to thi s i mpul se
response.
See Also butter, cheby1, cheby2, ellip, fir2, firls, maxflat, remez
References [1] Fri edl ander, B., and B. Porat, The Modi fi ed Yul e-Wal ker Method of ARMA
Spectral Esti mati on, I EEE Transactions on Aerospace Electronic Systems,
AES-20, No. 2 (March 1984), pp. 158-173.
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
0
0.2
0.4
0.6
0.8
1
1.2
1.4
Comparison of Frequency Response Magnitudes
Ideal
yulewalk Designed
zp2sos
7-483
7zp2sos
Purpose Convert di gi tal fi l ter zero-pol e-gai n parameters to second-order secti ons form
Syntax [sos,g] = zp2sos(z,p,k)
[sos,g] = zp2sos(z,p,k,'order')
[sos,g] = zp2sos(z,p,k,'order','scale')
sos = zp2sos(...)
Description zp2sos converts a di screte-ti me zero-pol e-gai n representati on of a gi ven di gi tal
fi l ter to an equi val ent second-order secti on representati on.
Use [sos,g] = zp2sos(z,p,k) to obtai n a matri x sos i n second-order secti on
form wi th gai n g equi val ent to the di screte-ti me zero-pol e-gai n fi l ter
represented by i nput arguments z, p, and k. Vectors z and p contai n the zeros
and pol es of the fi l ters transfer functi on H(z), not necessari l y i n any parti cul ar
order.
where n and m are the l engths of z and p, respecti vel y, and k i s a scal ar gai n.
The zeros and pol es must be real or compl ex conjugate pai rs. sos i s an L-by-6
matri x
whose rows contai n the numerator and denomi nator coeffi ci ents b
ik
and a
ik
of
the second-order secti ons of H(z).
The number L of rows of the matri x sos i s the cl osest i nteger greater than or
equal to the maxi mum of n/2 and m/2.
H z ( ) k
z z
1
( ) z z
2
( )L z z
n
( )
z p
1
( ) z p
2
( )L z p
m
( )
-------------------------------------------------------------------- =
sos
b
01
b
11
b
21
1 a
11
a
21
b
02
b
12
b
22
1 a
12
a
22
M M M M M M
b
0L
b
1L
b
2L
1 a
1L
a
2L
=
H z ( ) g H
k
z ( )
k 1 =
L

g
b
0k
b
1k
z
1
b
2k
z
2
+ +
1 a
1k
z
1
a
2k
z
2
+ +
--------------------------------------------------------- -
k 1 =
L

= =
zp2sos
7-484
[sos,g] = zp2sos(z,p,k,'order') speci fi es the order of the rows i n sos,
where 'order' i s:
'down', to order the secti ons so the fi rst row of sos contai ns the pol es cl osest
to the uni t ci rcl e
'up', to order the secti ons so the fi rst row of sos contai ns the pol es farthest
from the uni t ci rcl e (defaul t)
[sos,g] = zp2sos(z,p,k,'order','scale') speci fi es the desi red scal i ng of
the gai n and the numerator coeffi ci ents of al l second-order secti ons, where
'scale' i s:
'none', to appl y no scal i ng (defaul t)
'inf', to appl y i nfi ni ty-norm scal i ng
'two', to appl y 2-norm scal i ng
Usi ng i nfi ni ty-norm scal i ng i n conjuncti on wi th up-orderi ng mi ni mi zes the
probabi l i ty of overfl ow i n the real i zati on. Usi ng 2-norm scal i ng i n conjuncti on
wi th down-orderi ng mi ni mi zes the peak round-off noi se.
sos = zp2sos(...) embeds the overal l system gai n, g, i n the fi rst secti on,
H
1
(z), so that
Example Fi nd a second-order secti on form of a Butterworth l owpass fi l ter.
[z,p,k] = butter(5,0.2);
sos = zp2sos(z,p,k);
H z ( ) H
k
z ( )
k 1 =
L

=
zp2sos
7-485
Algorithm zp2sos uses a four-step al gori thm to determi ne the second-order secti on
representati on for an i nput zero-pol e-gai n system:
1 I t groups the zeros and pol es i nto compl ex conjugate pai rs usi ng the
cplxpair functi on.
2 I t forms the second-order secti on by matchi ng the pol e and zero pai rs
accordi ng to the fol l owi ng rul es:
a Match the pol es cl osest to the uni t ci rcl e wi th the zeros cl osest to those
pol es.
b Match the pol es next cl osest to the uni t ci rcl e wi th the zeros cl osest to
those pol es.
c Conti nue unti l al l of the pol es and zeros are matched.
zp2sos groups real pol es i nto secti ons wi th the real pol es cl osest to them i n
absol ute val ue. The same rul e hol ds for real zeros.
3 I t orders the secti ons accordi ng to the proxi mi ty of the pol e pai rs to the uni t
ci rcl e. zp2sos normal l y orders the secti ons wi th pol es cl osest to the uni t
ci rcl e l ast i n the cascade. You can tel l zp2sos to order the secti ons i n the
reverse order by speci fyi ng the down fl ag.
4 zp2sos scal es the secti ons by the norm speci fi ed i n the 'scale' argument.
For arbi trary H(), the scal i ng i s defi ned by
where p can be ei ther or 2. See the references for detai l s on the scal i ng.
Thi s scal i ng i s an attempt to mi ni mi ze overfl ow or peak round-off noi se i n
fi xed poi nt fi l ter i mpl ementati ons.
See Also cplxpair, filternorm, sos2zp, ss2sos, tf2sos, zp2ss, zp2tf
H
p
1
2
------ H ( )
p
d
0
2

1
p
---
=
zp2sos
7-486
References [1] Jackson, L.B., Digital Filters and Signal Processing, 3rd ed., Kl uwer
Academi c Publ i shers, Boston, 1996, Chapter 11.
[2] Mi tra, S.K., Digital Signal Processing: A Computer-Based Approach,
McGraw-Hi l l , New York, 1998, Chapter 9.
[3] Vai dyanathan, P.P., Robust Di gi tal Fi l ter Structures, Handbook for
Digital Signal Processing, S.K. Mi tra and J.F. Kai ser, ed., John Wi l ey & Sons,
New York, 1993, Chapter 7.
zp2ss
7-487
7zp2ss
Purpose Convert zero-pol e-gai n fi l ter parameters to state-space form
Syntax [A,B,C,D] = zp2ss(z,p,k)
Description zp2ss converts a zero-pol e-gai n representati on of a gi ven system to an
equi val ent state-space representati on.
[A,B,C,D] = zp2ss(z,p,k) fi nds a si ngl e i nput, mul ti pl e output, state-space
representati on
gi ven a system i n factored transfer functi on form.
Col umn vector p speci fi es the pol e l ocati ons, and matri x z the zero l ocati ons
wi th as many col umns as there are outputs. The gai ns for each numerator
transfer functi on are i n vector k. The A, B, C, and D matri ces are returned i n
control l er canoni cal form.
Inf val ues may be used as pl ace hol ders i n z i f some col umns have fewer zeros
than others.
Algorithm zp2ss, for si ngl e-i nput systems, groups compl ex pai rs together i nto two-by-two
bl ocks down the di agonal of the A matri x. Thi s requi res the zeros and pol es to
be real or compl ex conjugate pai rs.
See Also sos2ss, ss2zp, tf2ss, zp2sos, zp2tf
x

Ax Bu + =
y Cx Du + =
H s ( )
Z s ( )
P s ( )
---------- k
s z
1
( ) s z
2
( )L s z
n
( )
s p
1
( ) s p
2
( )L s p
n
( )
------------------------------------------------------------------ = =
zp2tf
7-488
7zp2tf
Purpose Convert zero-pol e-gai n fi l ter parameters to transfer functi on form
Syntax [b,a] = zp2tf(z,p,k)
Description zp2tf forms transfer functi on pol ynomi al s from the zeros, pol es, and gai ns of a
system i n factored form.
[b,a] = zp2tf(z,p,k) fi nds a rati onal transfer functi on
gi ven a system i n factored transfer functi on form
Col umn vector p speci fi es the pol e l ocati ons, and matri x z speci fi es the zero
l ocati ons, wi th as many col umns as there are outputs. The gai ns for each
numerator transfer functi on are i n vector k. The zeros and pol es must be real
or come i n compl ex conjugate pai rs. The pol ynomi al denomi nator coeffi ci ents
are returned i n row vector a and the pol ynomi al numerator coeffi ci ents are
returned i n matri x b, whi ch has as many rows as there are col umns of z.
Inf val ues can be used as pl ace hol ders i n z i f some col umns have fewer zeros
than others.
Algorithm The system i s converted to transfer functi on form usi ng poly wi th p and the
col umns of z.
See Also sos2tf, ss2tf, tf2zp, zp2sos, zp2ss
B s ( )
A s ( )
---------- -
b
1
s
n 1 ( )
L b
n 1 ( )
s b
n
+ + +
a
1
s
m 1 ( )
L a
m 1 ( )
s a
m
+ + +
-------------------------------------------------------------------------------- =
H s ( )
Z s ( )
P s ( )
---------- k
s z
1
( ) s z
2
( )L s z
m
( )
s p
1
( ) s p
2
( )L s p
n
( )
------------------------------------------------------------------ = =
zplane
7-489
7zpl ane
Purpose Zero-pol e pl ota
Syntax zplane(z,p)
zplane(b,a)
[hz,hp,ht] = zplane(z,p)
Description Thi s functi on di spl ays the pol es and zeros of di screte-ti me systems.
zplane(z,p) pl ots the zeros speci fi ed i n col umn vector z and the pol es speci fi ed
i n col umn vector p i n the current fi gure wi ndow. The symbol 'o' represents a
zero and the symbol 'x' represents a pol e. The pl ot i ncl udes the uni t ci rcl e for
reference. I f z and p are arrays, zplane pl ots the pol es and zeros i n the col umns
of z and p i n di fferent col ors.
You can overri de the automati c scal i ng of zplane usi ng
axis([xmin xmax ymin ymax])
or
set(gca,'ylim',[ymin ymax])
or
set(gca,'xlim',[xmin xmax])
after cal l i ng zplane. Thi s i s useful i n the case where one or a few of the zeros
or pol es have such a l arge magni tude that the others are grouped ti ghtl y
around the ori gi n and are hard to di sti ngui sh.
zplane(b,a) where b and a are row vectors, fi rst uses roots to fi nd the zeros
and pol es of the transfer functi on represented by numerator coeffi ci ents b and
denomi nator coeffi ci ents a.
[hz,hp,ht] = zplane(z,p) returns vectors of handl es to the zero l i nes, hz,
and the pol e l i nes, hp. ht i s a vector of handl es to the axes/uni t ci rcl e l i ne and
to text objects, whi ch are present when there are mul ti pl e zeros or pol es. I f
there are no zeros or no pol es, hz or hp i s the empty matri x [].
zplane
7-490
Examples For data sampl ed at 1000 Hz, pl ot the pol es and zeros of a 4th-order el l i pti c
l owpass di gi tal fi l ter wi th cutoff frequency of 200 Hz, 3 dB of ri ppl e i n the
passband, and 30 dB of attenuati on i n the stopband.
[z,p,k] = ellip(4,3,30,200/500);
zplane(z,p);
title('4th-Order Elliptic Lowpass Digital Filter');
To generate the same pl ot wi th a transfer functi on representati on of the fi l ter,
use the fol l owi ng commands.
[b,a] = ellip(4,3,30,200/500); % Transfer function
zplane(b,a)
See Also freqz
1 0.5 0 0.5 1
1
0.8
0.6
0.4
0.2
0
0.2
0.4
0.6
0.8
1
Real Part
I
m
a
g
i
n
a
r
y

P
a
r
t
4thOrder Elliptic Lowpass Digital Filter
I-1
Index
N umerics
2-norm 7-181
A
A/D conversi on 7-459
abs 7-26
ac2poly 7-27
ac2rc 7-28
al i ased si nc functi ons 1-13
command for 7-145
al i asi ng
i mpul se i nvari ance 2-42
preventi ng 4-23
reduci ng 4-40
al l -pol e fi l ters. See I I R fi l ters
al l -zero fi l ters. See FI R fi l ters
am 4-31
AM. See ampl i tude modul ati on
amdsbsc 4-31, 7-293
amdsbtc 4-31, 7-293
ampl i tude demodul ati on
doubl e si de-band, suppressed carri er 7-142
doubl e si de-band, transmi tted carri er 7-142
si ngl e si de-band 7-142
ampl i tude modul ati on 4-31
doubl e si de-band, suppressed carri er 7-293
doubl e si de-band, transmi tted carri er 7-293
quadrature 4-32
si ngl e si de-band 7-293
amssb 4-32, 7-293
anal og fi l ters 2-39
bandpass 7-276
bandstop 7-279
Bessel 2-12, 2-39, 7-38, 7-39
bi l i near transformati on 2-43
Butterworth 2-9, 2-39, 7-64, 7-65, 7-66
Chebyshev 2-39
Chebyshev Type I 2-10, 7-78, 7-90
Chebyshev Type I I 2-11, 7-96
converti ng to di gi tal 2-42, 7-246
desi gn 2-8
di screti zati on 2-42
el l i pti c 2-39, 7-155
frequency response 1-27, 2-13, 7-206
hi ghpass 7-281
i mpul se i nvari ance 2-42
i nverse 7-255
l owpass 7-283
order esti mati on
Butterworth 7-71
Chebyshev Type I 7-80, 7-85
Chebyshev Type I I 7-85
el l i pti c 7-163
pl otti ng 2-13
representati onal model s 1-42
See also I I R fi l ters
anal og frequency xxvi
anal og si gnal s. See si gnal s
anal yti c si gnal s 7-238
angle 7-29
anti -symmetri c fi l ters 2-26
AR fi l ters, stabi l i ty check 7-341
AR model s. See autoregressi ve (AR) model s
arburg 4-13, 7-30
arcov 4-13, 7-31
ARMA fi l ters 1-16, 4-15, 4-17
Pronys method 4-15
Stei gl i tz-McBri de method 4-17
See also I I R fi l ters
armcov 4-13, 7-32
ARX model s 4-15
aryule 4-13, 7-33
Index
I-2
ASCI I fi l es, i mporti ng 1-14
autocorrel ati on 7-339, 7-474
autocorrel ati on sequences
converti ng from refl ecti on coeffi ci ents 7-364
esti mati on, vari ance 3-4
fi l ter coeffi ci ents
converti ng to and from 7-27, 7-28, 7-339
fi l ters, mul ti pl e channel s 3-5
two-di mensi onal 7-477
autocovari ance 7-478
mul ti pl e channel s 3-5
autoregressi ve (AR) model s 1-16
Burg method 7-30, 7-299, 7-303
covari ance method 7-31, 7-304
modi fi ed covari ance method 7-32, 7-321,
7-325
Yul e-Wal ker AR method 7-33, 7-359, 7-363
See also I I R fi l ters
autoregressi ve movi ng average (ARMA) fi l ters.
See ARMA fi l ters
averagi ng fi l ters 1-15
axi s l abel s 6-50
axi s parameters
Fi l ter Vi ewer 6-50
Spectrum Vi ewer 6-50
B
band edges, prewarpi ng 2-44
bandl i mi ted i nterpol ati on 7-406
bandpass fi l ters 7-71, 7-80, 7-85, 7-163
Bessel 7-39
Butterworth 7-65
Chebyshev Type I 7-90, 7-92
Chebyshev Type I I 7-95
desi gn 2-7
el l i pti c 7-155
exampl e, Chebyshev Type I 2-40
FI R 2-22, 7-188
i mpul se i nvari ance 2-42
transformati on from l owpass to 7-276
bandstop fi l ters 2-7, 7-71, 7-80, 7-85, 7-163
Bessel 7-39
Butterworth 7-66
Chebyshev Type I 7-91
Chebyshev Type I I 7-95
el l i pti c 7-156
FI R 2-22, 7-187
transformati on from l owpass to 7-279
bandwi dth 2-41
barthannwi n 4-3, 7-34
bartlett 4-3, 7-36
exampl e 4-4
triang, compari son to 7-36
Bartl ett wi ndows 4-4
coeffi ci ents 7-36
Bartl ett-Hanni ng 7-34
Bessel fi l ters 2-12, 2-39, 7-38
bandpass 7-39
bandstop 7-39
characteri sti cs 2-12
hi ghpass 7-39
l i mi tati ons 7-41
l owpass 7-39
roots 7-38
besselap 2-6, 7-38
exampl e 2-12
besself 2-6, 2-7, 7-39
bi as
correl ati on 3-4, 4-14
power spectral densi ty 3-17, 3-18, 3-23
vari ance trade-off 3-4
bilinear 2-6, 2-42, 2-43, 7-42
bi l i near transformati ons 2-43, 2-44, 7-42
Index
I-3
output representati on 7-43
prewarpi ng 2-44, 7-42
bi t reversal 7-47
bi trevorder 7-47
blackman 4-3, 7-49
Bl ackman wi ndows 4-5, 7-49
Bl ackman-Harri s 7-51
bl ackmanharri s 4-3, 7-51
Bl ackman-Harri s wi ndows 7-296
Bohman 7-53
bohmanwi n 4-3, 7-53
boxcar 7-55
boxcar wi ndows. See rectangul ar wi ndows
brackets, i ndi cati ng cl osed i nterval xxvi
buffer 7-55
bufferi ng 7-55
Burg method 3-8, 3-9, 3-33
exampl e 3-34
Wel chs method, compari son 3-35
buttap 2-6, 7-64
exampl e 2-9
butter 2-6, 2-7, 7-65
Butterworth fi l ters 2-9, 2-39, 7-64
bandpass 7-65
bandstop 7-66
characteri sti cs 2-9
desi gn 7-65
general i zed 2-15
hi ghpass 7-66
l i mi tati ons 7-69
l owpass 7-65
order esti mati on 2-8, 7-70
buttord 2-6, 7-70
C
canoni cal forms 1-18, 7-443
carri er frequency 4-31, 7-293, 7-469
carri er si gnal s 4-31, 7-142
cascade, fi l ters 1-38
Cauer fi l ters. See el l i pti c fi l ters
cceps 4-25, 4-27, 7-75
exampl e 4-25
cell2sos 7-77
center frequency 2-41
central features 1-2
cepstrum
anal ysi s 4-25
appl i cati ons 4-25
compl ex 4-25
i nverse 4-25, 4-27
overvi ew 4-25
real 4-25, 4-26, 7-368
reconstructi ng si gnal s (mi ni mum-phase) 4-27
cheb1ap 2-6, 7-78
exampl e 2-10, 2-40
cheb1ord 2-6, 7-79
cheb2ap 2-6, 7-83
exampl e 2-11
cheb2ord 2-6, 7-84
chebwin 4-3, 7-89, 7-116
cheby1 2-6, 2-7, 7-90
exampl e 2-45
cheby2 2-6, 2-7, 7-95
Chebyshev error mi ni mi zati on 2-23, 7-371
Chebyshev Type I fi l ters 2-10, 2-39, 7-78, 7-90
bandpass 7-90, 7-92
bandstop 7-91
characteri sti cs 2-10
desi gn 7-90
hi ghpass 7-91
l owpass 7-90
order esti mati on 2-8, 7-79
Chebyshev Type I I fi l ters 2-39, 7-95
Index
I-4
bandpass 7-95
bandstop 7-95
characteri sti cs 2-11
hi ghpass 7-95
l i mi tati ons 7-94
l owpass 7-95
order esti mati on 2-8
Chebyshev wi ndows 4-10, 7-89
frequency response 4-10
chirp 1-10, 7-100
chi rp si gnal s 1-10
chi rp z-transforms (CZT) 4-36, 7-133
di screte Fouri er transforms, compari son 4-36
frequency anal ysi s, narrowband 7-133
codi ng, PCM 7-459
coeffi ci ents
correl ati on 7-115
fi l ter 1-16, 6-34, 7-27, 7-339, 7-341, 7-367
l i near predi cti on 7-285
refl ecti on 1-38, 7-28, 7-341, 7-364, 7-367
sequence 7-364
cohere 3-9, 7-106
l i nearl y dependent data 3-30
cohere 3-29
coherence 3-29, 7-106
l i nearl y dependent data 3-30
col ors, SPTool 6-50
communi cati ons 4-12, 4-31, 7-293
See also modul ati on, demodul ati on, vol tage
control l ed osci l l ati on
communi cati ons si mul ati on 7-142
compact di sc standards 4-22
compacti on 4-39
compl ex conjugate 7-120
compl ex envel ope. See Hi l bert transforms
compl ex numbers, groupi ng by conjugate 7-120
confi dence i nterval s
cross spectral densi ty 3-27
power spectral densi ty 3-27
warni ngs 3-27
context-sensi ti ve hel p 6-7
conti nuous si gnal s. See si gnal s
conti nuous-ti me fi l ters. See anal og fi l ters
control systems 1-36
Control Systems Tool box 1-36
conv 1-15, 1-21, 7-110
conv2 1-15, 7-111
conversi ons
autocorrel ati on sequences to and from fi l ter
coeffi ci ents 7-27
autocorrel ati on sequences to and from refl ecti on
coeffi ci ents 7-28
errors i n 1-43, 5-15
fi l ter coeffi ci ents to autocorrel ati on sequences
7-339
fi l ter coeffi ci ents to refl ecti on coeffi ci ents 7-341,
7-367
functi ons (tabl e) 1-43
refl ecti on coeffi ci ents to autocorrel ati on
sequences 7-364
second-order secti on forms to state-space forms
7-409
second-order secti on forms to transfer functi ons
7-411
second-order secti on forms to zero-pol e-gai n
forms 7-413
state-space forms to second-order secti on forms
7-426
state-space forms to zero-pol e-gai n forms 7-431
transfer functi ons to l atti ce forms 7-438
transfer functi ons to second-order secti on forms
7-439
transfer functi ons to state-space forms 7-442
Index
I-5
zero-pol e-gai n forms to second-order secti on
forms 7-483
zero-pol e-gai n forms to state-space forms
7-487
convmtx 1-41, 1-43, 7-113
convol uti on 7-110
cross-correl ati on 3-3
exampl e 1-15
fi l teri ng 1-15, 7-180
matri ces for 1-41, 1-43, 7-113
exampl e 7-113
two-di mensi onal 7-111
corrcoef 7-115
correl ati on 3-2
bi as 3-4, 4-14
coeffi ci ent matri ces 7-115
cross-correl ati on 7-473
matri ces
covari ance method 7-116
modi fi ed covari ance method 7-116
See also autocorrel ati on sequences,
cross-correl ati on sequences
correl ati on matri ces 7-116
corrmtx 7-116
cosi ne wi ndows 4-5
cov 7-119
covari ance 3-2
matri ces 7-119
See also autocovari ance, cross-covari ance
covari ance method 3-9, 3-36, 7-308
exampl e 3-36
See also modi fi ed covari ance method
cplxpair 7-120
cremez 2-17, 7-121
cross spectral densi ty 3-27, 7-129
confi dence i nterval s 3-27
See also power spectral densi ty, spectral
esti mati on
cross-correl ati on sequences 3-3
esti mati on 7-473
bi ased 3-4
unbi ased 3-4
fi l ters, mul ti pl e channel s 3-5
normal i zati on 3-5
two-di mensi onal 7-477
cross-covari ance 3-3, 7-478
mul ti pl e channel s 3-5
csd 3-9, 3-27, 7-129
cutoff frequency 2-39, 7-39
czt 4-37, 7-133
CZT. See chi rp z-transforms
D
D.C. component suppressi on 1-47
data
mul ti channel 1-5, 1-8
vectors 1-7
data compressi on 4-12
data matri ces 1-5, 1-8
data vectors 1-5
dct 4-38, 7-136
exampl e 4-39
decimate 7-138
deci mati on 7-138
FI R fi l ter for 7-253
decodi ng 7-456
deconv 4-35, 7-141
exampl e 4-35
deconvol uti on 4-35, 7-141
defaul t sessi on fi l e 6-50
del ays
group 1-29
Index
I-6
noni nteger 2-27
phase 1-29
si gnal s 2-27
demod 4-31, 4-32, 7-142
exampl e 4-32
demodul ati on 4-32, 7-142
ampl i tude, quadrature 7-143
exampl e 4-32
methods 4-32, 7-142
phase 7-143
pul se posi ti on 7-143
pul se wi dth 7-143
DFT. See di screte Fouri er transforms
dftmtx 7-144
di fference equati ons 1-33
di fferenti ators 2-27, 7-200, 7-373
di gi tal audi o tape standards 4-22
di gi tal fi l ters
anti -causal 1-21
Butterworth 7-65
cascade 1-38
Chebyshev Type I I 7-95
coeffi ci ents 1-16
convol uti on matri ces 1-41
desi gn 2-3
el l i pti c 7-155
FI R 2-17
I I R, compari son to 2-17
fi xed-poi nt i mpl ementati on 1-38
frequency data, i denti fi cati on from 7-259
frequency response 1-25
group del ay 1-29, 7-231
I I R 2-5
FI R fi l ters, compari son to 2-5
i mpl ementati on 1-15, 7-174, 7-177
convol uti on 1-15
FFT-based (FI R) 7-174
filter 1-17
overl ap-add method 1-23
i mpul se response 1-15, 1-24, 7-248
i ni ti al condi ti ons 1-18
l i near model s 1-33
model s 1-33
names 1-16
order 1-16
state-space representati on 1-35
order esti mati on
Butterworth 7-70, 7-79, 7-84
Chebyshev Type I 7-79, 7-84
Chebyshev Type I I 7-84
el l i pti c 7-162
equi ri ppl e FI R 7-378
phase del ays 1-29, 7-231
pol es 1-31, 1-34
second-order secti ons 1-38
speci fi cati ons 2-8
startup transi ents 1-22
structures
l atti ce/l adder 1-38
transposed di rect form I I 1-18
ti me-domai n representati on 1-17
transfer functi ons representati on 1-16
transi ents 1-23
two-di mensi onal 7-180
zero-phase 1-21, 7-183
zeros 1-31, 1-34
See also FI R fi l ters, I I R fi l ters
di gi tal frequency xxvi
di rect desi gn 2-6
diric 7-145
Di ri chl et functi ons 1-13
command for 7-145
di screte cosi ne transforms (DCT) 7-136
appl i cati ons 4-38
Index
I-7
energy compacti on property 4-39
exampl e 4-39
i nverse 4-38, 7-243
si gnal s, reconstructi ng 4-39
di screte Fouri er transforms (DFT) 1-3, 1-45, 2-27,
7-170
al gori thms 1-46
appl i cati ons 7-170
ei genvector equi val ent 3-38
exampl e 1-46
goertzel 1-47
I I R fi l ter i mpl ementati on 1-23
i nverse 1-45, 7-244
matri ces 7-144
two-di mensi onal 1-47, 7-245
magni tude 1-46
matri ces 7-144
phase 1-46
si gnal l ength dependenci es 1-46
spectral anal ysi s 3-6, 3-10
ti me-dependent 4-29
two-di mensi onal 1-47, 7-173
See also fast Fouri er transforms (FFT), fft
di screte prol ate spheroi dal sequences
See DPSS
di screti zati on 7-246
bi l i near transformati ons 2-43
prewarpi ng 2-44
i mpul se i nvari ance 2-42
di screti zati on, fi l ters 2-42
di sk, l oadi ng vari abl es from 6-43
di vi si on, pol ynomi al s 7-141
DPSS
di rect method 7-149
i nterpol ati on 7-148
dpss 7-148
dpss.mat 3-26
dpssclear 3-26, 7-151
dpssdir 3-26, 7-152
dpssload 3-26, 7-153
dpsssave 3-26, 7-154
duty cycl es 1-9
E
echoes, detecti on 4-25
edge effects 1-23
ei genanal ysi s 3-37
frequency esti mati on 3-37
ei genvector method 3-8, 3-36, 7-309
root MUSI C 7-390
See also mul ti pl e si gnal cl assi fi cati on method
ellip 2-6, 2-7, 7-155
ellipap 2-6, 7-161
exampl e 2-11
ellipord 2-6, 7-162, 7-167
el l i pti c fi l ters 2-39, 7-155
bandpass 7-155
bandstop 7-156
characteri sti cs 2-11
hi ghpass 7-156
l i mi tati ons 7-159
l owpass 7-155
order esti mati on 2-8, 7-162, 7-167
encodi ng
PCM 7-459
uni form 7-459
eqtflength 7-167
equi ri ppl e characteri sti cs
Chebyshev Type I fi l ters (passband) 2-10
Chebyshev Type I I fi l ters (stopband) 2-11
Chebyshev wi ndows 4-10
el l i pti c fi l ters 2-11, 7-155, 7-161
Parks-McCl el l an desi gn 7-371
Index
I-8
equi ri ppl e fi l ters 2-23
error mi ni mi zati on
desi red and actual response, between 2-23
frequency bands, wei ghti ng 2-26
mi ni max 2-23
esti mati on
cross spectral densi ty 3-27
nonparametri c
mul ti pl e si gnal cl assi fi cati on method
(MUSI C) 3-8
mul ti taper method (MTM) 3-8
Wel chs method 3-8
parametri c 3-8
Burg method 7-30
covari ance method 7-31
modi fi ed covari ance method 7-32
Yul e-Wal ker method 7-33
spectral densi ty 3-8, 3-10
transfer functi ons 3-28
See also parametri c model i ng
F
fast Fouri er Transforms (FFT)
Goertzel al gori thm 7-226
fast Fouri er transforms (FFT) 1-23, 1-45
fft 1-23
frequency response 1-25
radi x-2 al gori thm 7-172
si gnal processi ng, rol e i n 1-45
two-di mensi onal 7-173
fdatool 7-168
fdatool 5-1
hel p on 6-7
openi ng 5-6
fft 1-3, 1-23, 1-45, 7-170
exampl e 1-46
executi on ti me 1-46
number of sampl es 1-46
output 1-47, 7-176
radi x-2 al gori thm 7-172
FFT fi l teri ng 1-23
FFT. See fast Fouri er transforms
fft2 1-47, 1-47, 7-173
output 1-47
fftfilt 1-20, 7-174
filter, compari son to 7-174
fftshift 1-47, 1-47, 7-176
fi l ter
coeffi ci ents 1-16
medi an 4-30
order 1-16
filter 1-3, 1-17, 1-21, 7-177
fftfilt, compari son to 7-174
filtfilt, compari son 1-22
fi nal condi ti on parameters 1-18
i mpl ementati on 1-18
i ni ti al condi ti on parameters 1-18
i ni ti al condi ti ons 7-184
fi l ter coeffi ci ents
refl ecti on coeffi ci ents, conversi ons to 7-341,
7-367
fi l ter desi gn GUI 5-2
anal ysi s buttons 5-13
anal ysi s functi ons 5-13
computi ng coeffi ci ents 5-12
desi gn methods 5-8
desi gn sessi ons
openi ng 5-25
savi ng 5-25
exporti ng fi l ters 5-21
fi l ter desi gn speci fi cati on 5-9
fi l ter order speci fi cati on 5-11
fi l ter type 5-7
Index
I-9
fi l ters
archi tecture 5-15
i mpl ementati on 5-15
real i zati on 5-15
structure 5-15
frequency response speci fi cati on 5-9
group del ay 5-13
i mporti ng coeffi ci ents 5-17
i mporti ng fi l ters 5-17
i mpul se response 5-13
magni tude response 5-13
magni tude response specs 5-10
openi ng 5-6
phase del ay 5-13
phase response 5-13
pol e-zero pl ots 5-13
savi ng coeffi ci ents 5-21
step response 5-13
Fi l ter Desi gner 6-11, 7-421
FFT l ength 6-50
fi l ter types 6-11
fi l ters
edi ti ng 6-41
redesi gni ng 6-49
savi ng 6-33
FI R fi l ters 6-11
FI R methods 6-11
gri d l i nes 6-50
I I R methods 6-11
openi ng 6-12, 6-22
overvi ew 6-11
pl ots
customi zi ng 6-50
magni tude 6-49
Pol e/Zero Edi tor 6-46
sampl e frequency 6-34
spectra, overl ayi ng 6-12
zoomi ng 6-50
fi l ter parameters 6-50
Fi l ter Vi ewer 6-14, 7-422
axi s parameters 6-50
fi l ter parameters 6-50
measurements 6-52
openi ng 6-14
overvi ew 6-14
preferences, ti l i ng 6-50
pri nti ng 6-27
rul ers 6-52
zoomi ng 6-50
filter2 7-180
fi l ternrom 7-181
fi l ters 1-3
anal og 2-9, 2-12, 7-38, 7-64, 7-78
anti -causal 1-21
anti -symmetri c 2-26
averagi ng 1-15
bandpass
Butterworth 7-70
Chebyshev Type I 7-79
Chebyshev Type I I 7-84
el l i pti c 7-162
bandstop
Butterworth 7-70
Chebyshev Type I 7-79
Chebyshev Type I I 7-84
el l i pti c 7-162
Butterworth 2-8, 7-65
general i zed 2-15
Chebyshev 2-8
Type I 7-90
Type I I 7-95
coeffi ci ents 1-17, 1-33, 2-18, 6-34
bi t reversal 7-47
Index
I-10
converti ng to autocorrel ati on sequence
7-339
export to C header fi l e 5-22
export to text fi l e 5-22
export to workspace 5-21
convol uti on 1-15
creati ng 2-8
desi gn 6-11
Fi l ter Desi gner 6-11
FI R 2-23
general i zed 2-6
di screti zati on 2-42
el l i pti c 2-8, 7-155
equi ri ppl e 2-23
FI R 7-371
si ngl e band 2-21
frequency data, i denti fi cati on from 7-255
frequency domai n 1-23
frequency transformati on functi ons 2-39,
2-40
hi ghpass
Butterworth 7-70
Chebyshev Type I 7-79
Chebyshev Type I I 7-84
el l i pti c 7-162
i mpl ementati on 1-23, 7-174, 7-177
i ni ti al condi ti ons 1-18, 1-19
i nverse 7-255, 7-259
l atti ce/l adder 1-38
l i near phase 2-17, 2-18
l i near ti me-i nvari ant di gi tal 1-3
l owpass
Butterworth 7-70
Chebyshev Type I 7-79
Chebyshev Type I I 7-84
el l i pti c 7-162
measurements 6-52
medi an 7-292
mi ni max 2-23
mi ni mum phase 7-344
names 1-16
norm 7-181
order 1-16, 2-8, 7-70, 7-79, 7-162, 7-167
order esti mati on 2-8
phase, modul ati on 4-27
predi cti on 4-14
quanti zed, state vectors 7-178
Savi tzky-Gol ay 7-400, 7-404
Schur real i zati ons 7-397
second-order secti on forms 1-38, 1-44, 7-415
speci fi cati ons 2-8
SPTool 6-39
transposed di rect form I I structure 1-18
two-di mensi onal 7-180
types 2-18
zero-phase 1-21, 7-183
See also FI R fi l ters, I I R fi l ters, di gi tal fi l ters,
anal og fi l ters
filtfilt 1-20, 1-21, 2-5, 7-183
exampl e 1-21
filter, compari son 1-22
i ni ti al condi ti ons 1-22
filtic 1-19, 7-184
FI R fi l ters 1-16, 2-17
deci mati on 7-253
di fferenti ators 2-27, 7-200, 7-373
equi ri ppl e 2-17, 2-23, 2-24
exampl e 6-20
Fi l ter Desi gner 6-11
frequency domai n 1-20
frequency response 7-190
Hi l bert transformers 2-26, 7-200, 7-373
I I R fi l ters, compari son 2-17
i mpl ementati on 1-18, 7-177
Index
I-11
FFT-based 1-23, 7-174
overl ap-add method 1-23, 7-174
i nterpol ati on 7-253
Kai ser wi ndows 4-8
l atti ce/l adder 1-38
l east squares 2-17, 2-24, 7-199
constrai ned 2-17, 2-28
equi ri ppl e, compari son 2-24
l i near phase 2-29
mul ti band 2-29, 2-30
wei ghted 2-31
l i near phase 2-18, 2-23, 7-199, 7-371
mul ti band 2-17, 2-22, 2-23
order esti mati on, remez 7-378
overl ap-add method 7-174
Parks-McCl el l an method 2-23, 7-371
rai sed cosi ne method 2-17
resampl i ng 1-20
responses 2-32
compl ex fi l ters 2-17, 7-121
del ays, reduci ng 2-35
nonl i near phase 2-17, 7-121
standard band 2-21
types 7-202, 7-376
wi ndowi ng method 2-17
wi ndows 2-19, 7-186
fir1 2-17, 2-21
fir2 2-17, 2-21
fircls 2-17, 7-193
fircls1 2-17, 7-196
firls 2-17, 2-23, 7-199
di fferenti ators 2-27
fi l ter characteri sti cs 7-202
remez, compari son to 2-24
wei ght vectors 2-26
firrcos 2-17, 7-204
fi xed-poi nt i mpl ementati on, di gi tal fi l ters 1-38
fm 4-32
FM. See frequency modul ati on
fopen 1-14
Fouri er transforms. See di screte Fouri er
transforms, fast Fouri er transforms
fread 1-14
freqs 1-27, 7-206
freqspace 7-208
frequency 7-372
anal og xxvi
angul ar 2-3
carri er 4-31, 7-293, 7-469
center 2-41
cutoff 2-39
di gi tal xxvi
esti mati on
ei genanal ysi s 3-37
ei genvector (EV) method 3-37
mul ti pl e si gnal cl assi fi cati on (MUSI C)
method 3-37
normal i zati on 2-3
Nyqui st xxvi , 2-3
prewarpi ng 7-42
vectors 2-25, 7-190, 7-193, 7-481
frequency anal ysi s, ti me-dependent 7-416
frequency demodul ati on 7-143
frequency domai n
dual i ty wi th ti me-domai n 1-23
fi l ters 1-23
FI R fi l teri ng 1-20
transformati on functi ons 2-39, 7-276, 7-279,
7-281, 7-283
exampl e 2-41
l owpass to bandpass 7-276
l owpass to bandstop 7-279
l owpass to hi ghpass 7-281
Index
I-12
frequency domai n based model i ng. See
parametri c model i ng
frequency modul ati on 7-294
frequency response 1-25, 2-14, 7-190
Bessel fi l ters 2-12
Butterworth fi l ters 2-9
Chebyshev Type I fi l ters 2-10
Chebyshev Type I I fi l ters 2-11
Chebyshev wi ndows 4-10
el l i pti c fi l ters 2-11
error mi ni mi zati on 2-23
eval uati ng 1-25
exampl e 1-26
i nverse 7-255
Kai ser wi ndow 4-7
l i near phase 2-18
magni tude 1-27
monotoni c 2-9
mul ti band 2-14
phase 1-27
unwrappi ng 1-28
pl otti ng 1-26, 7-213
sampl es, spaci ng 7-208
sampl i ng frequency 1-25
frequency vectors 7-372
freqz 1-25, 7-209
sampl i ng frequenci es 1-25
sampl i ng frequency 1-25
spaci ng 7-208
freqzplot 7-213
From Di sk radi o button 6-43
fscanf 1-14
G
gai ns, scal ar 1-34
gauspuls 1-10, 1-11, 7-220
Gaussi an monopul se 7-224
Gauss-Newton method 7-258, 7-261
gausswi n 4-3
general i zed Butterworth fi l ters 2-15
general i zed cosi ne wi ndows 4-5
general i zed fi l ters 2-6
Gi bbs effect 2-20
reduced by wi ndow 4-3
gmonopul s 7-224
goertzel 7-226
graphi cal user i nterface (GUI ) 1-4
See also i nteracti ve tool s, SPTool
gri d l i nes 6-50
group del ay 1-29, 2-18, 7-231
exampl e 1-30
passband 2-12
grpdelay 1-29, 7-231
GUI -based tool s. See i nteracti ve tool s
H
hamming 4-3, 7-234
Hammi ng wi ndows 2-20, 3-18, 4-5, 7-234
hann 4-3
hann 7-236
Hann wi ndows 7-236
Hanni ng wi ndows 4-5, 7-236
hanning. See hann
hi ghpass fi l ters 2-7, 7-71, 7-80, 7-85, 7-163
Bessel 7-39
Butterworth 7-66
Chebyshev Type I 7-91
Chebyshev Type I I 7-95
el l i pti c 7-156
FI R 2-22, 7-188
l owpass, transformati on from 7-281
hilbert 2-27, 4-40
Index
I-13
exampl e 4-40
Hi l bert transformers 7-200, 7-373
Hi l bert transforms 4-36, 4-40, 7-238
anal yti c si gnal s, of 2-27
exampl e 4-40
i nstantaneous attri butes 4-41
homomorphi c systems 4-25
Hz 7-300, 7-305, 7-322, 7-360
I
icceps 4-25, 4-27, 7-242
exampl e 4-28
idct 4-38, 7-243
i deal l owpass fi l ters 2-19
See also l owpass fi l ters
ifft 1-45, 7-244
sampl es, speci fyi ng 1-47
ifft2 1-47, 7-245
I I R fi l ters 2-5, 2-6, 2-8, 2-9, 2-14
Bessel 2-12
Butterworth 2-8, 2-9
Butterworth, general i zed 2-15
Chebyshev 2-8, 2-10, 2-11
Chebyshev Type I 2-10
Chebyshev Type I I 2-11
desi gn 2-7, 2-38
el l i pti c 2-8, 2-11
Fi l ter Desi gner 6-11
fi l ter types, compari son 2-9
FI R fi l ters, compari son to 2-5
frequency response 2-14
i mpl ementati on 7-177
frequency domai n 1-23
zero-phase 1-21
l atti ce/l adder 1-38
Levi nson-Durbi n recursi on 7-274
maxi mal l y fl at 2-15
mul ti band 2-14
order esti mati on 2-8
pl otti ng responses 2-13
Pronys method 7-345
speci fi cati ons 2-8
Stei gl i tz-McBri de i terati on 7-433
Yul e-Wal ker 2-14, 7-481
See also di rect desi gn
i mage processi ng 1-47, 7-111
impinvar 2-6, 2-42, 7-246
I mport di al og box
From Di sk radi o button 6-43
Workspace Contents l i st 6-21
i mpul se i nvari ance 2-42, 7-246
l i mi tati ons 2-42
i mpul se response 1-24, 7-248
computi ng wi th filter 1-24
computi ng wi th impz 1-24
exampl e 1-24
i mpul se i nvari ance 2-42
l owpass fi l ters, i deal 2-19
impz 7-248
exampl e 1-24
i ndexi ng 1-16
i nf-norm 7-181
i ni ti al condi ti ons 1-18, 1-19, 1-22, 7-184
i nstantaneous attri butes 4-41
i nteracti ve tool s 1-4, 6-3
exampl e 6-20
Fi l ter Desi gn and Anal ysi s Tool 5-2
Fi l ter Desi gner 6-11, 7-421
Fi l ter Vi ewer 7-422
Si gnal Browser 7-421
Spectrum Vi ewer 6-17, 7-424
SPTool 7-420
interp 7-251
Index
I-14
i nterpol ati on 7-251
bandl i mi ted 7-406
FI R fi l ters 7-253
i nterval notati on xxvi
intfilt 7-253
i nverse cepstrum, compl ex 4-27
i nverse di screte cosi ne transforms 7-243
accuracy of si gnal reconstructi on 4-40
i nverse di screte Fouri er transforms 1-45, 7-244
ifft 1-45
matri ces 7-144
two-di mensi onal 1-47, 7-245
i nverse fi l ters 7-259, 7-345
anal og 7-255
di gi tal 7-259
i nverse Fouri er transforms, conti nuous.
Seesinc
i nverse-si ne parameters
refl ecti on coeffi ci ents, transformati ons from
7-262
refl ecti on coeffi ci ents, transformati ons to
7-365
invfreqs 2-6, 4-13, 4-19, 7-255
invfreqz 2-6, 4-13, 4-19, 7-259
is2rc 7-262
K
kaiser 4-3, 7-263
exampl e 4-6
Kai ser wi ndow 3-20
Kai ser wi ndows 4-6, 7-263
beta parameter 4-6, 7-263
exampl e 4-6
FI R fi l ters 4-8
frequency response 4-7
kaiserord 2-17, 7-265
L
l adder fi l ters. See l atti ce/l adder fi l ters
Lagrange i nterpol ati on fi l ter 7-253
Lapl ace transforms 1-42
state-space forms 1-42
lar2rc 7-270
latc2tf 1-41, 1-43, 7-271
latcfilt 1-20, 1-41, 7-272
l atti ce/l adder fi l ters 1-38, 1-39, 1-43
coeffi ci ents 1-39
latcfilt 1-41
Schur al gori thm 7-397
transfer functi ons, conversi ons from 7-438
l east squares method, FI R fi l ters 7-199, 7-202
levinson 4-13, 7-274, 7-387
parametri c model i ng 4-14
Levi nson-Durbi n recursi on 4-14, 7-274, 7-387
l i ne spectral frequenci es
predi cti on pol ynomi al coeffi ci ents,
transformati on from 7-340
predi cti on pol ynomi al coeffi ci ents,
transformati on to 7-289
l i ne styl e, SPTool 6-50
l i near model s. See model s
l i near phase 2-17, 2-18, 7-199
characteri sti cs 2-18
fi l ters 7-371
l i near predi cti on coeffi ci ents 7-285
l i near predi cti on model i ng 4-14
l i near predi cti ve codi ng 4-14
l i near system transformati ons. See conversi ons
load 1-14
l og area rati on parameters
refl ecti on coeffi ci ents, transformati ons from
7-270
refl ecti on coeffi ci ents, transformati ons to 7-366
l owpass fi l ters 2-7, 7-71, 7-80, 7-85, 7-163
Index
I-15
Bessel 7-39
Butterworth 7-65
Chebyshev Type I 7-90
Chebyshev Type I I 7-95
cutoff frequency, transl ati on of 7-283
deci mati on 7-138
el l i pti c 7-155
FI R 2-22
i deal 2-19
i mpul se i nvari ance 2-42
i mpul se response 2-19
i nterpol ati on 7-251
lp2bp 2-6, 2-40, 7-276
exampl e 2-41
lp2bs 2-6, 2-40, 7-279
lp2hp 2-6, 2-40, 7-281
lp2lp 2-6, 2-40, 7-283
lpc 2-6, 4-13, 7-285
See also l i near predi cti ve codi ng, Pronys
method
LPC. See l i near predi cti on coeffi ci ents
l se 7-224
lsf2poly 7-289
M
magni tude
Fouri er transforms 1-46
frequency response 1-27
pl ots 6-49
transfer functi ons 3-28
vectors 2-25, 7-190, 7-193, 7-481
manufacturi ng 4-12
match frequency (for prewarpi ng) 7-42
MAT-fi l es
dpss.mat 3-26
format, converti ng to 1-14
i mporti ng 1-14
SPTool 6-43
matri ces
convol uti on 1-41, 7-113
correl ati on coeffi ci ent 7-115
covari ance 7-119
data 1-5, 1-8
di screte Fouri er transforms 7-144
i nverse di screte Fouri er transforms 7-144
matri x forms. See state-space forms
maxflat 2-6, 2-15, 7-290
maxi mal l y fl at fi l ters 2-15
medfilt1 4-30, 7-292
medi an fi l ters 4-30, 7-292
MEX-fi l es 1-14
M-fi l es 1-4
mi ni max method, FI R fi l ters 2-23
See also Parks-McCl el l an method
mi ni mum phase 7-344
model s 1-33
autoregressi ve 7-30, 7-31, 7-32, 7-33
Burg method 7-299, 7-303
covari ance method 7-304
modi fi ed covari ance method 7-321, 7-325
Yul e-Wal ker AR method 7-359, 7-363
bi l i near transformati ons 2-44
transformati ons, di screte/conti nuous 2-44
modi fi ed covari ance method 3-36
exampl e 3-36
modulate 4-31, 4-32, 7-293
exampl e 4-32
method fl ags 4-31
modul ati on 4-31, 7-293
ampl i tude 4-31
See also ampl i tude modul ati on
exampl e 4-32
frequency 4-32
Index
I-16
phase 4-32
pul se posi ti on 4-32
pul se wi dth 4-32
quadrature ampl i tude 4-32
resul ts of 4-32
si gnal s 4-31, 7-293
movi ng average (MA) fi l ters 1-16
See also FI R fi l ters
MTM. See mul ti taper method
mul ti band fi l ters
FI R 2-22
FI R, wi th transi ti on bands 2-23
I I R 2-14
mul ti channel data 1-8
mul ti pl e si gnal cl assi fi cati on method (MUSI C)
3-8, 3-9, 3-36, 7-331, 7-337
correl ati on matri ces 7-116
ei genvector method 7-309, 7-314
root musi c 7-393
mul ti pl i cati on, pol ynomi al s 7-110
mul ti pl i ci ty, of zeros and pol es 6-47
mul ti rate fi l ters 1-20
banks 1-20
mul ti taper method (MTM) 3-8, 3-9, 3-24
average power, conservati on of 3-26
exampl e 3-25
Wel chs method, compari son to 3-26
MUSI C al gori thm. See mul ti pl e si gnal
cl assi fi cati on method
N
nonrecursi ve fi l ters. See FI R fi l ters
normal i zati on 3-4
correl ati on 3-5, 7-473, 7-474
power spectral densi ty 3-17, 3-18, 3-23
Nuttal l wi ndows 7-296
nuttal l wi n 4-3, 7-296
Nyqui st frequency xxvi , 2-3, 7-155
Nyqui st i nterval 7-155
O
order
esti mati on 2-8, 7-378
Butterworth 7-70
Chebyshev Type I 7-79
el l i pti c 7-162, 7-167
fi l ters, of 1-16, 2-8
osci l l ators, vol tage control l ed 7-469
overl ap-add method
FI R fi l ter i mpl ementati on 1-23
FI R fi l ters 7-174
P
Panner check box, Si gnal Browser 6-50
parametri c model i ng 4-12, 7-259
appl i cati ons 4-12
frequency domai n based 4-19
summary 2-6
techni ques 4-12
ti me-domai n based 4-14
Burg method 7-30
covari ance method 7-31
l i near predi cti ve codi ng 4-14, 4-15
modi fi ed covari ance method 7-32
Stei gl i tz-McBri de method 4-17
Yul e-Wal ker method 7-33
parentheses, i ndi cati ng open i nterval xxvi
Parks-McCl el l an method 2-23, 7-371
parti al fracti on expansi on 1-36, 1-42, 1-43, 7-384
determi ni ng wi th residue 1-42
exampl e 1-36
Index
I-17
passband 7-70, 7-79, 7-84, 7-162
equi ri ppl e 2-10, 2-11
group del ay 2-12
pburg 3-9, 3-34, 7-299
exampl e 3-34
PCM 7-459
pcov 3-9, 3-36, 7-304
exampl e 3-36
peig 3-36
pei g 7-309
peri od, fi ndi ng i n a sequence 7-398
peri odi c si nc functi ons 7-145
See also Di ri chl et functi ons
periodogram 7-316
peri odograms 3-10, 7-316, 7-320
phase
computi ng 7-29
del ays 1-29, 2-18, 7-231
exampl e 1-30
demodul ati on 7-143
di storti on
el i mi nati ng 1-20, 1-21
FI R fi l ters 1-21
I I R fi l ters 1-21
Fouri er transforms 1-46
frequency response 1-27
modul ati on 4-32, 7-294
fi l ters 4-27
transfer functi ons, of 3-28
unwrappi ng 1-28, 7-462
pl ots
anal og fi l ters 2-13
cepstrum, compl ex 4-26
coherence functi on 3-29
DFT 1-46
frequency response 1-26
functi ons for 7-347
group del ay 1-30
magni tude 1-27, 6-49
phase 1-27
del ays 1-30
stri p pl ots 7-436
transfer functi ons 3-28
zero-pol e 1-31, 7-489
pl otti ng functi ons 7-213
pl ug-i ns 6-50
pm 4-32
pmcov 3-9, 3-36, 7-321
exampl e 3-36
p-model . See parametri c model i ng
pmtm 3-9, 7-326
exampl e 3-25
pmusic 3-9, 3-36, 7-331
Pol e/Zero Edi tor 6-46
pol e-zero fi l ters. See I I R fi l ters
poly 1-34, 1-43
poly2ac 7-339
poly2lsf 7-340
poly2rc 7-341
pol ynomi al s
di vi si on 4-35, 7-141
mul ti pl i cati on 7-110
roots 1-34, 1-43
scal i ng 7-344
stabi l i ty check 7-341
stabi l i zati on 7-343
pol yphase fi l teri ng techni ques 1-20
pol yscal e 7-343
polystab 7-343, 7-344
power spectral densi ty 3-6
bi as 3-17, 3-18, 3-23
confi dence i nterval s 3-27
esti mati on
Burg method 3-9, 3-33, 7-299
Index
I-18
covari ance method 3-9, 3-36, 7-304
modi fi ed covari ance method 3-9, 7-321
mul ti taper method 3-24, 7-326
MUSI C method 3-37, 7-331
root musi c 7-390, 7-393
Wel chs method 3-9, 3-20, 3-23
Yul e-Wal ker AR method 3-9, 3-32, 7-359
mul ti taper method 3-9
MUSI C method 3-9
normal i zati on 3-17, 3-18, 3-23
pl ots 6-17
Spectrum Vi ewer 6-17
SPTool 6-41
uni ts of 3-7
ppm 4-32
predi cti on fi l ters 4-14
predi cti on pol ynomi al s
l i ne spectral frequenci es, transformati ons
from 7-289
l i ne spectral frequenci es, transformati ons to
7-340
Preferences menu i tem 6-50
prewarpi ng 7-42
Pri nt di al og box 6-28, 6-30
Pri nt Previ ew wi ndow
Si gnal Browser preferences 6-28
Spectrum Vi ewer 6-30
pri nti ng, Spectrum Vi ewer 6-53
prol ate-spheroi dal wi ndows 4-6
prony 2-6, 4-13, 4-15, 7-345
Pronys method 4-15, 7-345
model i ng 4-15
psdplot 7-347
pseudospectrum 7-337
ei genvector method 7-309, 7-314
MUSI C al gori thm 7-337
pul se posi ti on demodul ati on 7-143
pul se posi ti on modul ati on 4-32
pul se ti me modul ati on 7-294
pul se trai n generator 7-349
pul se trai ns
generati ng 1-11
pulstran 1-11
pul se wi dth demodul ati on 7-143
pul se wi dth modul ati on 4-32, 7-294
pulstran 1-11, 7-349
pwelch 3-9, 3-20, 7-353
pwm 4-32
pyulear 3-9, 3-32, 7-359
exampl e 3-33, 3-34
Q
qam 4-32
quadrature ampl i tude demodul ati on 7-143
quadrature ampl i tude modul ati on 4-32, 7-294
quanti zati on 7-181, 7-456, 7-459
PCM 7-459
quanti zed fi l ters 7-178
second-order secti ons
coeffi ci ents i n a cel l array 7-408
coeffi ci ents i n a matri x 7-77
R
radar appl i cati ons 4-29
rai sed cosi ne fi l ters 7-204
randn xxi v
random number, generati on xxi v
range notati on xxvi
rc2ac 7-364
rc2is 7-365
rc2lar 7-366
rc2poly 7-367
Index
I-19
rceps 4-25, 4-27, 7-368
rebufferi ng 7-55
rectangul ar wi ndows 2-19, 4-3, 7-370
rectpuls 7-369
rectwin 4-3
exampl e 4-4
rectwi n 7-370
recursi ve fi l ters. See I I R fi l ters
references 1-48, 3-39, 4-42
refl ecti on coeffi ci ents 1-38, 1-39
converti ng to autocorrel ati on sequence 7-364
fi l ter coeffi ci ents, conversi ons from 7-341,
7-367
i nverse si ne parameters, transformati on from
7-365
i nverse si ne parameters, transformati on to
7-262
l og area rati o parameters, transformati on from
7-366
l og area rati o parameters, transformati on to
7-270
Schur al gori thm 7-397
remez 2-17, 2-23, 7-371
di fferenti ators 2-27
fi l ter characteri sti cs 7-376
firls, compari son to 2-24
Hi l bert transformers 2-26
order esti mati on 7-378
wei ght vectors 2-26
Remez exchange al gori thm 2-23, 7-371
remezord 2-17, 7-378
resample 7-381
resampl i ng 4-22, 7-381
FI R fi l ters 1-20
See also deci mati on, i nterpol ati on
residue 1-42, 1-43, 1-43
resi due forms. See parti al fracti on expansi on
residuez 1-43, 7-384
rlevinson 7-387
root MUSI C 7-393
ei genvector method 7-390
rooteig 7-390
rootmusic 7-393
roots 1-34, 1-43
pol ynomi al s 1-34
rul ers
posi ti oni ng 6-53
Si gnal Browser 6-50
Spectrum Vi ewer 6-50
S
sampl i ng frequency
changi ng
noni nteger resampl i ng factors 4-22, 7-381
wi th upfirdn 1-20
decreasi ng 7-146
decreasi ng by i nteger factor 7-138
FI R fi l ters 1-20
freqz 1-27
i ncreasi ng 7-251, 7-467
i rregul arl y spaced data 4-23
Nyqui st i nterval 7-155
range 1-27
spaci ng 1-27
savi ng data
Spectrum Vi ewer 6-37
Savi tzky-Gol ay fi l ters 7-400, 7-404
sawtooth 1-9, 7-390, 7-396
sawtooth wave 1-9
scal i ng 7-343
schur 7-397
Schur al gori thm 7-397
schurrc 7-397
Index
I-20
second-order secti on forms 1-38, 1-43
fi l ters 7-415
matri ces 1-38
SPTool 6-40
state-space forms, conversi ons from 7-426
state-space forms, conversi ons to 7-409
transfer functi ons, conversi ons from 7-411,
7-439
zero-pol e-gai n forms, conversi ons from 7-483
zero-pol e-gai n forms, conversi ons to 7-413
second-order secti ons
coeffi ci ents i n cel l arrays 7-408
coeffi ci ents i n matri ces 7-77
seqperiod 7-398
sgolay 7-400, 7-404
sgolayfilt 7-404
Si gnal Browser 6-8, 7-421
axi s l abel s 6-50
markers, preferences 6-50
openi ng 6-8
overvi ew 6-8
Panner, preferences 6-50
Pri nt Previ ew wi ndow 6-28
pri nti ng 6-10, 6-26, 6-27, 6-53
si gnal s, measuri ng 6-52
zoomi ng, preferences 6-50
Si gnal Processi ng Tool box 1-3
si gnal s 2-27
addi ng noi se 1-7
anal yti c 4-40, 7-238
aperi odi c 1-10
appl i cati ons 4-40
array 6-8
bufferi ng 7-55
carri er 4-31, 7-142
chi rp 1-10
conti nuous (anal og) 1-3
di fferenti ators 2-27
diric 1-13
di screte (di gi tal ) 1-3
generati ng 1-8
l i near swept-frequency cosi ne. See chi rp
measurements 6-52
modul ati on 4-31, 7-293
mul ti channel 3-5
peri odi c 1-9
pl otti ng 1-7
properti es 4-40
pulstran 1-11
rebufferi ng 7-55
reconstructi on
DCT coeffi ci ents, from 4-39
mi ni mum phase 4-27, 7-368
representi ng 1-5
mul ti channel 1-5
si ngl e channel 1-5
sawtooth 1-9, 7-396
exampl e 1-9
sinc 1-12
si nusoi dal 1-7, 1-10
pul se, Gaussi an-modul ated 1-10
square wave 1-9, 7-425
tri angl e 7-396
sinc 1-12, 7-406
bandl i mi ted i nterpol ati on exampl e 7-406
si nc functi ons 1-12, 7-406
basi c exampl e 1-12
Sl epi an sequences. See di screte prol ate spheroi dal
sequences
sonar appl i cati ons 4-29
sos2cell 7-408
sos2ss 1-43, 7-409
sos2tf 1-43, 7-411
sos2zp 1-43, 7-413
Index
I-21
sosfi l t 7-415
specgram 4-29, 7-416
exampl e 4-29, 7-469
speci fi cati on l i nes. See Fi l ter Desi gner
speci fi cati ons, fi l ters 2-8
spectra. See spectrum
spectral anal ysi s 3-6
cross spectral densi ty 3-27
power spectrum 3-6
Spectrum Vi ewer 6-17
See also spectral esti mati on
spectral densi ty 3-6
measurements 6-52
pl otti ng functi ons 7-347
Spectrum Vi ewer 6-17
uni ts of 3-7
See also power spectral densi ty, cross spectral
densi ty
spectral densi ty pl ots 6-17
spectral esti mati on 3-10
Burg method 3-9, 3-33, 7-299, 7-300
covari ance method 7-304, 7-308
ei genvector method 7-309, 7-310, 7-314
modi fi ed covari ance method 3-9, 7-321
mul ti taper method 3-9, 7-326
MUSI C al gori thm 7-331, 7-337
MUSI C method 3-9, 7-332
nonparametri c
mul ti pl e si gnal cl assi fi cati on method
(MUSI C) 3-8
mul ti taper method (MTM) 3-8
Wel chs method 3-8
parametri c
Burg method 7-30
covari ance method 7-31
modi fi ed covari ance method 7-32
Yul e-Wal ker method 7-33
peri odograms 7-320
root MUSI C 7-390, 7-393
Wel chs method 3-8, 3-9, 3-20, 3-23, 3-27, 7-109,
7-131, 7-353, 7-357
Yul e-Wal ker AR method 2-14, 3-8, 3-9, 3-32,
3-33, 7-359, 7-360
spectrogram 4-29, 7-416
exampl e 4-29, 7-469
Spectrum Vi ewer 6-17, 7-424
acti vati ng 6-17
axi s parameters 6-50
markers, preferences 6-50
measurements 6-52
openi ng 6-17
overvi ew 6-17
Pri nt Previ ew 6-30
pri nti ng 6-17, 6-27, 6-53
rul ers 6-52
spectra structures 6-37
spectral densi ty pl ots 6-17
wi ndows 6-18
zoomi ng 6-50
speech processi ng 4-12, 4-23
spline 4-23
SPTool 6-3, 7-420
col ors, customi zi ng 6-50
context-sensi ti ve hel p 6-7
customi zi ng 6-50
data
enteri ng 1-14
objects 6-44
sel ecti ng 6-44
data structures 6-3
edi ti ng 6-45
exampl e 6-20
exporti ng data 1-14, 6-32
fi l ter desi gn 6-22
Index
I-22
fi l teri ng 6-24
fi l ters 6-39
coeffi ci ents 6-34
i mporti ng 6-22, 6-39
parameters 6-34
speci fi cati ons 6-35
fi l ters, savi ng 6-33
hel p on 6-7
I mport di al og 6-21
i mporti ng 1-14, 6-20, 6-22, 6-39
i tems, sel ecti ng 6-44
l i ne styl e, customi zi ng 6-50
MAT-fi l es 6-43
MATLAB workspace 6-3
mul ti sel ecti on of i tems 6-44
operati on 6-3
Pol e/Zero Edi tor 6-46
preferences 6-50
Preferences menu i tem 6-50
Pri nt di al og box 6-28, 6-30
pri nti ng 6-27
fi l ters 6-28
spectra 6-28
ri ght-cl i ck edi t menu 6-45
rul ers 6-52
sampl e frequency 6-34
savi ng 6-32
second-order secti on forms 6-40
Si gnal Browser 6-26
si gnal s
anal ysi s 6-26
measurements 6-52
pl ayi ng 6-27
sound 6-27
spectra
anal yzi ng 6-28
i mporti ng 6-22
spectral densi ti es
i mporti ng 6-39, 6-41
pl ots 6-41
Spectrum Vi ewer 6-28
state-space forms 6-40
transfer functi ons
exporti ng 6-34
speci fyi ng 6-40
workspace 6-3
zero-pol e-gai n forms 6-40
sptool 7-420
square 1-9, 7-425
square wave 1-9
ss2sos 1-43, 7-426
ss2tf 1-43, 7-430
ss2zp 1-43, 7-431
stabi l i ty check, pol ynomi al s 7-341
stabi l i zati on 7-344
standards, di gi tal audi o tape 4-22
startup transi ents, reduci ng 1-22, 7-183
state vectors 7-178
state-space forms 1-35, 1-42, 1-43
scal ar 1-35
second-order secti on forms, conversi ons from
7-409
second-order secti on forms, conversi ons to
7-426
SPTool 6-40
transfer functi ons, conversi ons to 7-442
zero-pol e-gai n forms, conversi ons from 7-487
zero-pol e-gai n forms, converti ons to 7-431
stati sti cal operati ons 3-3
See also autocorrel ati on sequences,
cross-correl ati on sequences,
cross-covari ance
Stei gl i tz-McBri de method 4-17, 7-433
stmcb 2-6, 4-13, 4-17, 7-433
Index
I-23
stopband 7-70, 7-79, 7-84, 7-162
equi ri ppl e 2-11
stri p pl ots 7-436
strips 7-436
structures
converti ng 1-43, 5-15
l atti ce/l adder 1-38
transposed di rect form I I 7-178
structures, di gi tal fi l ters
l atti ce/l adder 1-38
transposed di rect form I I 1-18
swept-frequency cosi ne generator. See chi rp
system i denti fi cati on 4-15
system model s. See model s
T
tapers, PSD esti mates 3-24
taps 2-18
tf2latc 1-39, 1-43, 7-438
tf2sos 7-439
tf2ss 1-43, 7-442
tf2zp 1-43, 7-431, 7-444
tfe 3-9, 3-28, 7-447
ti l i ng preferences 6-50
ti me seri es attri butes 4-41
ti me-domai n based model i ng. See parametri c
model i ng
tool boxes
Control Systems Tool box 1-36
Si gnal Processi ng Tool box 1-3
Symbol i c Math Tool box 7-38
transfer functi ons 1-16, 1-33, 1-36, 1-43
coeffi ci ents 1-16, 6-34
esti mati on 7-447
usi ng Wel chs method 3-28
factori ng 1-34
l atti ce forms, conversi ons to 7-438
second-order secti on forms, conversi ons from
7-411
second-order secti on forms, conversi ons to
7-439
SPTool 6-40
state-space forms, conversi ons to 7-442
zero-pol e-gai n forms 1-34
transformati ons
bi l i near 2-43, 7-42
di screte/conti nuous 2-44
frequency 2-39, 7-276, 7-279, 7-281, 7-283
model s, between 1-43
transforms 4-36
chi rp z-transforms (CZT) 4-36, 7-133
di screte cosi ne 7-136
di screte Fouri er 1-45, 7-170
Hi l bert 4-40, 7-238
i nverse di screte cosi ne 4-38, 7-243
i nverse di screte Fouri er 7-244
transi ents, fi l ters 1-23
transi ti on band 2-23
transposed di rect form I I 7-178
i ni ti al condi ti ons 7-184
triang 4-3, 7-451
exampl e 4-4
tri angul ar wi ndows 7-451
tripuls 7-453
Tukey 7-454
tukeywi n 4-3, 7-454
two-di mensi onal operati ons
di screte Fouri er transforms 1-47, 7-173
i nverse di screte Fouri er transforms 1-47,
7-245
See also fi l ters, two-di mensi onal
two-di mensi onal si gnal processi ng 1-47
typographi cal conventi ons (tabl e) xxvi i
Index
I-24
U
udecode 7-456
uencode 7-459
uni form encodi ng 7-459
uni t ci rcl e 7-344
uni t i mpul se functi on 1-8
uni t ramp functi on 1-8
uni t sampl e, mul ti channel representati on 1-8
uni t step functi on 1-8
uni ts of power spectral densi ty (PSD) 3-7
unwrap 1-28, 7-462
upfirdn 1-20, 4-23, 7-463
upsample 7-467
V
vari ance, correl ati on sequence esti mate 3-4
vco 4-31, 4-34, 7-148, 7-469
vectors
data 1-5, 1-7
frequency 2-25, 7-190, 7-193, 7-372, 7-481
i ndexi ng xxvi , 1-16
magni tude 2-25, 7-190, 7-193, 7-481
wei ghti ng 7-200
vol tage control l ed osci l l ators 4-34, 7-469
W
waveforms. See si gnal s
Wel chs method 3-9, 3-20
bi as 3-23
Burg method, compari son to 3-35
MTM method, compari son to 3-26
normal i zati on 3-23
power spectral densi ty esti mati on 3-8, 3-23,
3-27, 7-109, 7-131, 7-357
system i denti fi cati on, nonparametri c 3-28
Yul e-Wal ker AR method, compari son to 3-33
whi te noi se 1-7
wi ndow 7-471
wi ndows
Bartl ett 4-4, 7-36
Bartl ett-Hanni ng 7-34
Bl ackman 4-5, 7-49
Bl ackman-Harri s 7-51, 7-296
bl ackmanharri s vs. nuttal l wi n 7-51, 7-296
Bohman 7-53
boxcar 2-19
Chebyshev 4-10, 7-89
cosi ne, general i zed 4-5
fi l ters 2-19
FI R fi l ters 2-19
bandpass 7-186
bandstop 7-187
hi ghpass 7-187
l owpass 7-186
mul ti band fi l ters 2-22
si ngl e band desi gn 2-21
fir1 2-22
general i zed cosi ne 4-5
Hammi ng 2-20, 3-18, 4-5, 7-234
Hann 7-236
Hanni ng 4-5, 7-236
Kai ser 3-20, 4-6, 7-263
Nuttal l 7-296
peri odograms 3-12, 3-18
prol ate-spheroi dal 4-6
rectangul ar 2-19, 7-370
shapes 4-3
tri angul ar 7-451
Tukey 7-454
Workspace Contents l i st 6-21
Index
I-25
X
xcorr 3-3, 7-473
parametri c model i ng 4-14
xcorr2 7-477
xcov 3-3, 7-478
Y
yulewalk 2-6, 2-14, 7-481
exampl e 2-14
Yul e-Wal ker AR method 3-8, 3-9, 3-32, 7-481
exampl e 3-33, 3-34
Wel chs method, compari son to 3-33
Yul e-Wal ker equati ons 2-14
Z
zero frequency component, centeri ng 1-47
zero-order hol d. See averagi ng fi l ters
zero-phase fi l teri ng 7-183
zero-pol e anal ysi s 7-489
zero-pol e pl ots 1-31, 7-489
zero-pol e-gai n forms 1-34, 1-42, 1-43
exampl e 1-31
second-order secti on forms, conversi ons from
7-413
second-order secti on forms, conversi ons to
7-483
SPTool 6-40
state-space forms, conversi ons from 7-431
state-space forms, conversi ons to 7-487
zeros and pol es
mul ti pl i ci ty of 6-47
transfer functi ons 1-34
zoomi ng 6-50
zp2sos 1-43, 7-483
zp2ss 1-43, 7-487
zp2tf 1-43, 7-488
zplane 1-31, 7-489
z-transforms 1-16, 1-33
chi rp z-transforms (CZT) 4-36, 7-133
di screte Fouri er transforms 1-45, 7-170
Index
I-26

You might also like