Vous êtes sur la page 1sur 720

Computation

Visualization
Programming
For Use with MATLAB

Users Guide
Version 4.2
Signal Processing
Toolbox
How to Contact The MathWorks:
508-647-7000 Phone
508-647-7001 Fax
The Mat hWor ks, Inc. Mail
24 Pr ime Par k Way
Nat ick, MA 01760-1500
http://www.mathworks.com Web
ftp.mathworks.com Anonymous FTP ser ver
comp.soft-sys.matlab Newsgr oup
support@mathworks.com Technical suppor t
suggest@mathworks.com Pr oduct enhancement suggest ions
bugs@mathworks.com Bug r epor t s
doc@mathworks.com Document at ion er r or r epor t s
subscribe@mathworks.com Subscr ibing user r egist r at ion
service@mathworks.com Or der st at us, license r enewals, passcodes
info@mathworks.com Sales, pr icing, and gener al infor mat ion
S ignal Processing Toolbox Users Guide
COPYRIGHT 1988 - 1999 by The Mat hWor ks, Inc. All Right s Reser ved.
The soft war e descr ibed in t his document is fur nished under a license agr eement . The soft war e may be used
or copied only under t he t er ms of t he license agr eement . No par t of t his manual may be phot ocopied or r epr o-
duced in any for m wit hout pr ior wr it t en consent fr om The Mat hWor ks, Inc.
U.S. GOVERNMENT: If Licensee is acquir ing t he Pr ogr ams on behalf of any unit or agency of t he U.S.
Gover nment , t he following shall apply: (a) For unit s of t he Depar t ment of Defense: t he Gover nment shall
have only t he r ight s specified in t he license under which t he commer cial comput er soft war e or commer cial
soft war e document at ion was obt ained, as set for t h in subpar agr aph (a) of t he Right s in Commer cial
Comput er Soft war e or Commer cial Soft war e Document at ion Clause at DFARS 227.7202-3, t her efor e t he
r ight s set for t h her ein shall apply; and (b) For any ot her unit or agency: NOTICE: Not wit hst anding any
ot her lease or license agr eement t hat may per t ain t o, or accompany t he deliver y of, t he comput er soft war e
and accompanying document at ion, t he r ight s of t he Gover nment r egar ding it s use, r epr oduct ion, and disclo-
sur e ar e as set for t h in Clause 52.227-19 (c)(2) of t he FAR.
MATLAB, Simulink, St at eflow, Handle Gr aphics, and Real-Time Wor kshop ar e r egist er ed t r ademar ks, and
Tar get Language Compiler is a t r ademar k of The Mat hWor ks, Inc.
Ot her pr oduct or br and names ar e t r ademar ks or r egist er ed t r ademar ks of t heir r espect ive holder s.
Pr int ing Hist or y: December 1996 Fir st pr int ing New for MATLAB 5.0
J anuar y 1998 Second pr int ing Revised for MATLAB 5.2
J anuar y 1999 (Online only) Revised for Ver sion 4.2 (Release 11)

PHONE
FAX
u
MAIL
INTERNET
@
i
Contents
Before You Begi n
What Is the Si gnal Processing Toolbox? . . . . . . . . . . . . . . . . . . . xi i
How to Use Thi s Manual . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi i i
Installati on . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv
Typographi cal Conventi ons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvi
Technical Not at ions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvi i
1
Si gnal Processi ng Basi cs
Si gnal Processi ng Toolbox Central Features . . . . . . . . . . . . . . 1-2
Filt er ing and FFTs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2
Signals and Syst ems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2
Key Ar eas: Filt er Design and Spect r al Analysis . . . . . . . . . . . . 1-3
Gr aphical User Int er face (GUI) . . . . . . . . . . . . . . . . . . . . . . . . . 1-3
Ext ensibilit y . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-3
Repre senti ng Si gnals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-4
Vect or Repr esent at ion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-4
Waveform Generati on: Ti me Vectors and Si nusoi ds . . . . . . . 1-6
Common Sequences: Unit Impulse, Unit St ep, and Unit Ramp 1-7
Mult ichannel Signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-7
Common Per iodic Wavefor ms . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-7
Common Aper iodic Wavefor ms . . . . . . . . . . . . . . . . . . . . . . . . . . 1-8
The pulst r an Funct ion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-9
The Sinc Funct ion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-10
The Dir ichlet Funct ion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-11
i i Contents
Worki ng wi t h Dat a . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-13
Filte r Imple me ntati on and Analysi s . . . . . . . . . . . . . . . . . . . . . . 1-14
Convolut ion and Filt er ing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-14
Filt er s and Tr ansfer Funct ions . . . . . . . . . . . . . . . . . . . . . . . . . 1-15
Filt er Coefficient s and Filt er Names . . . . . . . . . . . . . . . . . . 1-15
Filt er ing wit h t he filt er Funct ion . . . . . . . . . . . . . . . . . . . . . . . 1-16
fi lt er Functi on Implement at i on and Ini ti al Condit i ons . . . 1-17
Other Functi ons for Fi lt e ri ng . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-19
Mult ir at e Filt er Bank Implement at ion . . . . . . . . . . . . . . . . . . 1-19
Ant i-Causal, Zer o-Phase Filt er Implement at ion . . . . . . . . . . . 1-20
Fr equency Domain Filt er Implement at ion . . . . . . . . . . . . . . . . 1-22
Impulse Re sponse . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-23
Frequency Res ponse . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-24
Digit al Domain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-24
Analog Domain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-26
Magnit ude and Phase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-26
Delay . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-28
Ze ro-Pole Analys i s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-30
Linear Syst e m Mode ls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-32
Discr et e-Time Syst em Models . . . . . . . . . . . . . . . . . . . . . . . . . . 1-32
Tr ansfer Funct ion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-32
Zer o-Pole-Gain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-33
St at e-Space . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-34
Par t ial Fr act ion Expansion (Residue For m) . . . . . . . . . . . . 1-35
Second-Or der Sect ions (SOS) . . . . . . . . . . . . . . . . . . . . . . . . 1-36
Lat t ice St r uct ur e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-37
Convolut ion Mat r ix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-39
Cont inuous-Time Syst em Models . . . . . . . . . . . . . . . . . . . . . . . 1-40
Linear Syst em Tr ansfor mat ions . . . . . . . . . . . . . . . . . . . . . . . . 1-41
i i i
Di screte Fouri er Transform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-43
Re ference s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-46
2
Fi lter Des i gn
Filte r Re qui re me nts and Spe cifi cati on . . . . . . . . . . . . . . . . . . . . 2-2
IIR Fi lte r De si gn . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-4
Classical IIR Filt er Design Using Analog Pr ot ot yping . . . . . . . 2-6
Complet e Classical IIR Filt er Design . . . . . . . . . . . . . . . . . . . 2-6
Designing IIR Filt er s t o Fr equency Domain Specificat ions . 2-7
Compar ison of Classical IIR Filt er Types . . . . . . . . . . . . . . . . . . 2-8
But t er wor t h Filt er . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-8
Chebyshev Type I Filt er . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-9
Chebyshev Type II Filt er . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-10
Ellipt ic Filt er . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-10
Bessel Filt er . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-11
Dir ect IIR Filt er Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-13
Gener alized But t er wor t h Filt er Design . . . . . . . . . . . . . . . . 2-14
FIR Filte r Desi gn . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-16
Linear Phase Filt er s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-17
Windowing Met hod . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-18
St andar d Band FIR Filt er Design: fir 1 . . . . . . . . . . . . . . . . 2-20
Mult iband FIR Filt er Design: fir 2 . . . . . . . . . . . . . . . . . . . . 2-21
Mult iband FIR Filt er Design wit h Tr ansit ion Bands . . . . . . . 2-22
Basic Configur at ions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-22
The Weight Vect or . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-24
Ant i-Symmet r ic Filt er s / Hilber t Tr ansfor mer s . . . . . . . . . . 2-25
Differ ent iat or s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-26
Const r ained Least Squar es FIR Filt er Design . . . . . . . . . . . . . 2-27
Basic Lowpass and Highpass CLS Filt er Design . . . . . . . . . 2-28
Mult iband CLS Filt er Design . . . . . . . . . . . . . . . . . . . . . . . . 2-29
Weight ed CLS Filt er Design . . . . . . . . . . . . . . . . . . . . . . . . . 2-30
i v Contents
Ar bit r ar y-Response Filt er Design . . . . . . . . . . . . . . . . . . . . . . . 2-31
Mult iband Filt er Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-32
Filt er Design wit h Reduced Delay . . . . . . . . . . . . . . . . . . . . 2-34
Speci al Topi cs i n IIR Filte r Desi gn . . . . . . . . . . . . . . . . . . . . . . . 2-37
Analog Pr ot ot ype Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-38
Fr equency Tr ansfor mat ion . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-38
Filt er Discr et izat ion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-41
Impulse Invar iance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-42
Bilinear Tr ansfor mat ion . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-43
Re ference s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-46
3
Stati st i cal Si gnal Proces si ng
Correlati on and Covari ance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-2
Bias and Nor malizat ion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-3
Mult iple Channels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-4
Spectral Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-5
Welchs Met hod . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-6
Power Spect r al Densit y Funct ion . . . . . . . . . . . . . . . . . . . . . 3-10
Bias and Nor malizat ion in Welchs Met hod . . . . . . . . . . . . . 3-12
Cr oss-Spect r al Densit y Funct ion . . . . . . . . . . . . . . . . . . . . . 3-14
Confidence Int er vals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-14
Tr ansfer Funct ion Est imat e . . . . . . . . . . . . . . . . . . . . . . . . . 3-14
Coher ence Funct ion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-15
Mult it aper Met hod . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-16
Yule-Walker AR Met hod . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-19
Bur g Met hod . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-20
Covar iance and Modified Covar iance Met hods . . . . . . . . . . . . 3-22
MUSIC and Eigenvect or Analysis Met hods . . . . . . . . . . . . . . . 3-23
Eigenanalysis Over view . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-24
Cont r olling Subspace Thr esholds . . . . . . . . . . . . . . . . . . . . . 3-25
v
Re ference s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-27
4
Speci al Topi cs
Wi ndows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-2
Basic Shapes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-2
Gener alized Cosine Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-4
Kaiser Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-4
Kaiser Windows in FIR Design . . . . . . . . . . . . . . . . . . . . . . . . 4-7
Chebyshev Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-9
Parametri c Modeli ng . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-10
Time-Domain Based Modeling . . . . . . . . . . . . . . . . . . . . . . . . . 4-11
Linear Pr edict ion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-12
Pr onys Met hod (ARMA Modeling) . . . . . . . . . . . . . . . . . . . . 4-13
St eiglit z-McBr ide Met hod (ARMA Modeling) . . . . . . . . . . . 4-15
Fr equency-Domain Based Modeling . . . . . . . . . . . . . . . . . . . . . 4-16
Re s ampli ng . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-20
Ce pstrum Analysi s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-23
Inver se Complex Cepst r um . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-25
FFT-Based Ti me-Frequency Analys i s . . . . . . . . . . . . . . . . . . . . . 4-27
Me dian Fi lte ri ng . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-28
Communi cati ons Appli cat ions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-29
De convolut ion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-33
Speci ali ze d Trans forms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-34
Chir p z-Tr ansfor m . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-34
Discr et e Cosine Tr ansfor m . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-36
Hilber t Tr ansfor m . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-38
vi Contents
Re ference s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-40
5
Interacti ve Tools
SPTool: An Interacti ve Si gnal Processing Envi ronment . . . 5-2
Over view . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-2
Using SPTool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-3
Opening SPTool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-3
Quick St ar t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-3
Example: Impor t ing Signal Dat a fr om a MAT-File . . . . . . . . 5-3
Basic SPTool Funct ions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-5
File Menu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-6
Help Menu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-6
Impor t ing Signals, Filt er s, and Spect r a . . . . . . . . . . . . . . . . . . . 5-7
Loading Var iables fr om t he MATLAB Wor kspace . . . . . . . . 5-7
Loading Var iables fr om Disk . . . . . . . . . . . . . . . . . . . . . . . . . 5-8
Impor t ing Wor kspace Cont ent s and File Cont ent s . . . . . . . . 5-8
Wor king wit h Signals, Filt er s, and Spect r a . . . . . . . . . . . . . . . 5-13
Component List s in SPTool . . . . . . . . . . . . . . . . . . . . . . . . . . 5-14
Select ing Dat a Object s in SPTool . . . . . . . . . . . . . . . . . . . . . 5-15
Edit ing Dat a Object s in SPTool . . . . . . . . . . . . . . . . . . . . . . 5-15
Viewing a Signal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-17
Viewing a Filt er . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-17
Designing a Filt er . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-17
Applying a Filt er . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-18
Cr eat ing a Spect r um . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-19
Viewing a Spect r um . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-19
Updat ing a Spect r um . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-19
vi i
Cust omizing Pr efer ences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-20
Ruler Set t ings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-21
Color Set t ings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-22
Signal Br owser Set t ings . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-23
Spect r um Viewer Set t ings . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-24
Filt er Viewer Set t ings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-25
Filt er Viewer Tiling Set t ings . . . . . . . . . . . . . . . . . . . . . . . . 5-26
Filt er Designer Set t ings . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-27
Default Session Set t ing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-28
Expor t ing Component s Set t ing . . . . . . . . . . . . . . . . . . . . . . . 5-29
Plug-Ins Set t ing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-30
Saving and Discar ding Changes t o Pr efer ences Set t ings . . 5-30
Cont r ols for Viewing and Measur ing . . . . . . . . . . . . . . . . . . . . 5-31
Zoom Cont r ols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-31
Ruler Cont r ols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-33
Making Signal Measur ement s . . . . . . . . . . . . . . . . . . . . . . . 5-37
Using t he Si gnal Browser: Interacti ve Si gnal Analysi s . . . 5-43
Opening t he Signal Br owser . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-43
Basic Signal Br owser Funct ions . . . . . . . . . . . . . . . . . . . . . . . . 5-44
Menus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-45
Zoom Cont r ols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-46
Ruler and Line Display Cont r ols . . . . . . . . . . . . . . . . . . . . . 5-46
Help But t on . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-46
Display Management Cont r ols . . . . . . . . . . . . . . . . . . . . . . . 5-47
Main Axes Display Ar ea . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-47
Panner . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-48
Making Signal Measur ement s . . . . . . . . . . . . . . . . . . . . . . . 5-49
Viewing and Explor ing Signals . . . . . . . . . . . . . . . . . . . . . . . . . 5-49
Select ing and Displaying a Signal . . . . . . . . . . . . . . . . . . . . 5-49
Panner Display . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-52
Manipulat ing Displays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-53
Wor king wit h Signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-54
Pr int ing Signal Dat a . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-54
Saving Signal Dat a . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-57
Us ing t he Filte r Desi gne r: Inte racti ve Filte r Desi gn . . . . . . 5-59
Opening t he Filt er Designer . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-59
vi i i Contents
Basic Filt er Designer Funct ions . . . . . . . . . . . . . . . . . . . . . . . . 5-60
Menus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-60
Filt er Pop-Up Menu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-60
Zoom Cont r ols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-61
Help But t on . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-61
Gener al Cont r ols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-62
Filt er Specificat ions PanelDesign Met hods . . . . . . . . . . . 5-63
Filt er Measur ement s PanelDesign Met hods . . . . . . . . . . 5-65
Filt er Specificat ions PanelPole/Zer o Edit or . . . . . . . . . . . 5-66
Filt er Measur ement s PanelPole/Zer o Edit or . . . . . . . . . . 5-68
Magnit ude Plot (Display) Ar eaDesign Met hods . . . . . . . . 5-69
Magnit ude Plot (Display) Ar eaPole/Zer o Edit or . . . . . . . . 5-71
Designing Finit e Impulse Response (FIR) Filt er s . . . . . . . . . . 5-73
Example: FIR Filt er Design, St andar d Band Configur at ion 5-73
Filt er Design Opt ions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-75
Or der Select ion for FIR Filt er Design . . . . . . . . . . . . . . . . . 5-75
Designing Infinit e Impulse Response (IIR) Filt er s . . . . . . . . . 5-76
Example: Classical IIR Filt er Design . . . . . . . . . . . . . . . . . . 5-76
Filt er Design Opt ions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-77
Or der Select ion for IIR Filt er Design . . . . . . . . . . . . . . . . . . 5-78
Redesigning a Filt er Using t he Magnit ude Plot . . . . . . . . . . . . 5-78
Saving Filt er Dat a . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-79
Viewing Fr equency Response Plot s . . . . . . . . . . . . . . . . . . . . . . 5-82
Us ing t he Filter Vi ewer: Interacti ve Fi lt er Analysi s . . . . . . 5-84
Opening t he Filt er Viewer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-84
Basic Filt er Viewer Funct ions . . . . . . . . . . . . . . . . . . . . . . . . . . 5-84
Menus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-86
Filt er Ident ificat ion Panel . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-86
Plot s Panel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-86
Fr equency Axis Set t ings . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-87
Zoom Cont r ols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-87
Help But t on . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-87
Main Plot s Ar ea . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-88
i x
Viewing Filt er Plot s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-89
Viewing Magnit ude Response . . . . . . . . . . . . . . . . . . . . . . . . 5-89
Viewing Phase Response . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-91
Viewing Gr oup Delay . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-93
Viewing a Zer o-Pole Plot . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-94
Viewing Impulse Response . . . . . . . . . . . . . . . . . . . . . . . . . . 5-94
Viewing St ep Response . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-95
Using t he Spectrum Vi ewer: Interact i ve PSD Analysi s . . . 5-97
Opening t he Spect r um Viewer . . . . . . . . . . . . . . . . . . . . . . . . . 5-97
Basic Spect r um Viewer Funct ions . . . . . . . . . . . . . . . . . . . . . . 5-98
Menus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-99
Signal ID Panel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-100
Spect r um Management But t ons . . . . . . . . . . . . . . . . . . . . . 5-100
Zoom Cont r ols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-101
Ruler and Line Display Cont r ols . . . . . . . . . . . . . . . . . . . . 5-101
Help But t on . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-101
Main Axes Display Ar ea . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-101
Making Spect r um Measur ement s . . . . . . . . . . . . . . . . . . . . 5-102
Viewing Spect r al Densit y Plot s . . . . . . . . . . . . . . . . . . . . . . . . 5-102
Cont r olling and Manipulat ing Plot s . . . . . . . . . . . . . . . . . . . . 5-102
Changing Plot Pr oper t ies . . . . . . . . . . . . . . . . . . . . . . . . . . 5-102
Choosing Comput at ion Par amet er s . . . . . . . . . . . . . . . . . . 5-103
Comput at ion Met hods and Par amet er s . . . . . . . . . . . . . . . 5-104
Set t ing Confidence Int er vals . . . . . . . . . . . . . . . . . . . . . . . . 5-107
Pr int ing Spect r um Dat a . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-107
Saving Spect r um Dat a . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-110
Example: Ge nerati on of Bandlimited Noi se . . . . . . . . . . . . . . 5-113
Cr eat e, Impor t , and Name a Signal . . . . . . . . . . . . . . . . . . . . 5-113
Design a Filt er . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-115
Apply t he Filt er t o a Signal . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-116
View, Play, and Pr int t he Signals . . . . . . . . . . . . . . . . . . . . . . 5-117
Compar e Spect r a of Bot h Signals . . . . . . . . . . . . . . . . . . . . . . 5-120
6
Reference
x Contents
Befor e You Begin
What Is the Si gnal Processing Toolbox? . . . . . . . . . . . . . . . .xii
How to Use Thi s Manual . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiii
Installati on . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv
Typographi cal Conventi ons . . . . . . . . . . . . . . . . . . . . . . . . . . xvi
Technical Not at ions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvii
Before You Begin
xii
What Is the Signal Processing Toolbox?
This sect ion descr ibes how t o begin using t he Signal Pr ocessing Toolbox. It
explains how t o use t his manual and point s you t o addit ional books for t oolbox
inst allat ion infor mat ion.
The Signal Pr ocessing Toolbox is a collect ion of t ools built on t he MATLAB

numer ic comput ing envir onment . The t oolbox suppor t s a wide r ange of signal
pr ocessing oper at ions, fr om wavefor m gener at ion t o filt er design and
implement at ion, par amet r ic modeling, and spect r al analysis. The t oolbox
pr ovides t wo cat egor ies of t ools:
Signal pr ocessing funct ions
Gr aphical, int er act ive t ools
The fir st cat egor y of t ools is made up of funct ions t hat you can call fr om t he
command line or fr om your own applicat ions. Many of t hese funct ions ar e
MATLAB M-files, ser ies of MATLAB st at ement s t hat implement specialized
signal pr ocessing algor it hms. You can view t he MATLAB code for t hese
funct ions using t he st at ement
type function_name
or by opening t he M-file in t he MATLAB Edit or /Debugger . You can change t he
way any t oolbox funct ion wor ks by copying and r enaming t he M-file, t hen
modifying your copy. You can also ext end t he t oolbox by adding your own
M-files.
Second, t he t oolbox pr ovides a number of int er act ive t ools t hat let you access
many of t he funct ions t hr ough a graphical user interface (GUI). The GUI-based
t ools pr ovide an int egr at ed envir onment for filt er design, analysis, and
implement at ion, as well as signal explor at ion and edit ing. For example, wit h
t he gr aphical user int er face t ools you can:
Use t he mouse t o gr aphically edit t he magnit ude r esponse of a filt er or
measur e t he slope of a signal wit h onscr een r uler s.
Play a signal on your syst ems audio har dwar e by select ing a menu it em or
pr essing a cor r esponding keyst r oke combinat ion.
Cust omize t he par amet er s and met hod of comput ing t he spect r um of a
signal.
How to Use This Manual
xi i i
How to Use This Manual
If you are a new user. Begin wit h Chapt er 1, Signal Pr ocessing Basics. This
chapt er int r oduces t he MATLAB signal pr ocessing envir onment t hr ough t he
t oolbox funct ions. It descr ibes t he basic funct ions of t he Signal Pr ocessing
Toolbox, r eviewing it s use in basic wavefor m gener at ion, filt er implement at ion
and analysis, impulse and fr equency r esponse, zer o-pole analysis, linear
syst em models, and t he discr et e Four ier t r ansfor m.
When you feel comfor t able wit h t he basic funct ions, move on t o Chapt er 2 and
Chapt er 3 for a mor e in-dept h int r oduct ion t o using t he Signal Pr ocessing
Toolbox:
Chapt er 2, Filt er Design, for a det ailed explanat ion of using t he Signal
Pr ocessing Toolbox in infinit e impulse r esponse (IIR) and finit e impulse
r esponse (FIR) filt er design and implement at ion, including special t opics in
IIR filt er design.
Chapt er 3, St at ist ical Signal Pr ocessing, for how t o use t he cor r elat ion,
covar iance, and spect r al analysis t ools t o est imat e impor t ant funct ions of
discr et e r andom signals.
Once you under st and t he gener al pr inciples and applicat ions of t he t oolbox,
lear n how t o use t he int er act ive t ools.
Chapt er 5, Int er act ive Tools, for an over view of t he int er act ive GUI
envir onment and examples of how t o use it for signal explor at ion, filt er
design and implement at ion, and spect r al analysis.
Finally, see t he following chapt er for a discussion of specialized t oolbox
funct ions.
Chapt er 4, Special Topics, for specialized funct ions, including filt er
windows, par amet r ic modeling, r esampling, cepst r um analysis,
t ime-dependent Four ier t r ansfor ms and spect r ogr ams, median filt er ing,
communicat ions applicat ions, deconvolut ion, and specialized t r ansfor ms.
If you are an experienced toolbox user. See Chapt er 5, Int er act ive Tools, for an
over view of t he int er act ive GUI envir onment and examples of how t o use it for
signal viewing, filt er design and implement at ion, and spect r al analysis.
Before You Begin
xiv
All toolbox users. Use Chapt er 6, Refer ence, for locat ing infor mat ion on specific
funct ions. Refer ence descr ipt ions include a synopsis of t he funct ions synt ax, as
well as a complet e explanat ion of opt ions and oper at ions. Many r efer ence
descr ipt ions also include helpful examples, a descr ipt ion of t he funct ions
algor it hm, and r efer ences t o addit ional r eading mat er ial.
Use t his manual in conjunct ion wit h t he soft war e t o lear n about t he power ful
feat ur es t hat MATLAB pr ovides. Each chapt er pr ovides numer ous examples
t hat apply t he t oolbox t o r epr esent at ive signal pr ocessing t asks.
Some examples use MATLABs r andom number gener at ion funct ion randn. In
t hese cases, t o duplicat e t he r esult s in t he example, t ype
randn('seed',0)
befor e r unning t he example.
Installation
xv
Installation
To inst all t his t oolbox on a wor kst at ion, see t he MATLAB Installation Guide
for UNIX. To inst all t he t oolbox on a PC, see t he MATLAB PC Installation
Guide.
To det er mine if t he Signal Pr ocessing Toolbox is alr eady inst alled on your
syst em, check for a subdir ect or y named signal wit hin t he main t oolbox
dir ect or y or folder .
Before You Begin
xvi
Typographical Conventions
To Indicate This Manual Uses Example
Example code Monospace type. To assign t he value 5 t o
A, ent er
A = 5
MATLAB
out put
Monospace type. MATLAB r esponds wit h
A =
5
Funct ion names Monospace type. The cos funct ion finds
t he cosine of each ar r ay
element .
New t er ms Italics. An array is an or der ed
collect ion of
infor mat ion.
Keys Boldface wit h an
init ial capit al let t er.
Pr ess t he Return key.
Menu names,
it ems, and GUI
cont r ols
Boldface wit h an
init ial capit al let t er.
Choose t he Fi le menu.
Mat hemat ical
expr essions
Var iables in italics.
Funct ions,
oper at or s, and
const ant s in
st andar d t ype.
This vect or r epr esent s
t he polynomial
p = x
2
+ 2x + 3
Typographical Conventions
xvi i
Technical Notations
This manual and t he Signal Pr ocessing Toolbox funct ions use t he following
t echnical not at ions:
Nyquist fr equency One-half t he sampling fr equency. Most
t oolbox funct ions nor malize t his value t o 1.
x(1) The fir st element of a dat a sequence or
filt er, cor r esponding t o zer o lag.
Analog fr equency in r adians per second.
or w Digit al fr equency in r adians per second.
f Digit al fr equency in Her t z.
[x, y) The int er val fr om x t o y, including x but not
including y
Before You Begin
xvi i i
1
Signal Pr ocessing Basics
Si gnal Processi ng Toolbox Central Features . . . . . . . . . . . 1-2
Repre senti ng Si gnals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-4
Waveform Generati on: Ti me Vectors and Si nusoi ds . . . . 1-6
Worki ng wi th Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-13
Fi lter Implementati on and Analysi s . . . . . . . . . . . . . . . . . . 1-14
fi lt er Funct ion Implement ati on and Ini t ial Condi ti ons . 1-17
Ot her Funct ions for Fi lteri ng . . . . . . . . . . . . . . . . . . . . . . . . 1-19
Impulse Response . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-23
Frequency Response . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-24
Ze ro-Pole Analys i s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-30
Li near Sys te m Mode ls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-32
Di screte Fouri er Transform . . . . . . . . . . . . . . . . . . . . . . . . . 1-43
Refe re nce s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-46
1 Signal Processing Basics
1-2
Signal Processing Toolbox Central Features
This chapt er descr ibes how t o begin using MATLAB and t he Signal Pr ocessing
Toolbox for your signal pr ocessing applicat ions. It assumes a basic knowledge
and under st anding of signals and syst ems, including such t opics as filt er and
linear syst em t heor y and basic Four ier analysis.
Many examples t hr oughout t he chapt er demonst r at e how t o apply t oolbox
funct ions. If you ar e not alr eady familiar wit h MATLABs signal pr ocessing
capabilit ies, use t his chapt er in conjunct ion wit h t he soft war e t o t r y examples
and lear n about t he power ful feat ur es available t o you.
The Signal Pr ocessing Toolbox funct ions ar e algor it hms, expr essed most ly in
M-files, t hat implement a var iet y of signal pr ocessing t asks. These t oolbox
funct ions ar e a specialized ext ension of t he MATLAB comput at ional and
gr aphical envir onment .
Filtering and FFTs
Two of t he most impor t ant funct ions for signal pr ocessing ar e not in t he Signal
Pr ocessing Toolbox at all, but ar e built -in MATLAB funct ions:
filter applies a digit al filt er t o a dat a sequence.
fft calculat es t he discr et e Four ier t r ansfor m of a sequence.
The oper at ions t hese funct ions per for m ar e t he main comput at ional
wor khor ses of classical signal pr ocessing. Bot h ar e descr ibed in t his chapt er .
The Signal Pr ocessing Toolbox uses many ot her st andar d MATLAB funct ions
and language feat ur es, including polynomial r oot finding, complex ar it hmet ic,
mat r ix inver sion and manipulat ion, and gr aphics t ools.
Signals and Systems
The basic ent it ies t hat t oolbox funct ions wor k wit h ar e signals and syst ems.
The funct ions emphasize digit al, or discr et e, signals and filt er s, as opposed t o
analog, or cont inuous, signals. The pr incipal filt er t ype t he t oolbox suppor t s is
t he linear , t ime-invar iant digit al filt er wit h a single input and a single out put .
You can r epr esent linear t ime-invar iant syst ems using one of sever al models
(such as t r ansfer funct ion, st at e-space, zer o-pole-gain, and second-or der
sect ion) and conver t bet ween r epr esent at ions.
Signal Processing Toolbox Central Features
1-3
Key Areas: Filter Design and Spectral Analysis
In addit ion t o it s cor e funct ions, t he t oolbox pr ovides r ich, cust omizable suppor t
for t he key ar eas of filt er design and spect r al analysis. It is easy t o implement
a design t echnique t hat suit s your applicat ion, design digit al filt er s dir ect ly, or
cr eat e analog pr ot ot ypes and discr et ize t hem. Toolbox funct ions also est imat e
power spect r al densit y and cr oss spect r al densit y, using eit her par amet r ic or
nonpar amet r ic t echniques. Chapt er s 2 and 3, r espect ively, det ail t oolbox
funct ions for filt er design and spect r al analysis.
Ther e ar e funct ions for comput at ion and gr aphical display of fr equency
r esponse, as well as funct ions for syst em ident ificat ion; gener at ing signals;
discr et e cosine, chir p-z, and Hilber t t r ansfor ms; lat t ice filt er s; r esampling;
t ime-fr equency analysis; and basic communicat ion syst ems simulat ion.
Graphical User Interface (GUI)
The power of t he Signal Pr ocessing Toolbox is gr eat ly enhanced by it s
easy-t o-use gr aphical user int er face. The GUI pr ovides an int egr at ed set of
int er act ive t ools for per for ming a wide var iet y of signal pr ocessing t asks. These
t ools enable you t o use t he mouse and menus t o manipulat e a r ich gr aphical
envir onment for signal viewing, filt er design and implement at ion, and spect r al
analysis.
Extensibility
Per haps t he most impor t ant feat ur e of t he MATLAB envir onment is t hat it is
ext ensible: MATLAB let s you cr eat e your own M-files t o meet numer ic
comput at ion needs for r esear ch, design, or engineer ing of signal pr ocessing
syst ems. Simply copy t he M-files pr ovided wit h t he Signal Pr ocessing Toolbox
and modify t hem as needed, or cr eat e new funct ions t o expand t he funct ionalit y
of t he t oolbox.
1 Signal Processing Basics
1-4
Representing Signals
The cent r al dat a const r uct in MATLAB is t he numeric array, an or der ed
collect ion of r eal or complex numer ic dat a wit h t wo or mor e dimensions. The
basic dat a object s of signal pr ocessing (one-dimensional signals or sequences,
mult ichannel signals, and t wo-dimensional signals) ar e all nat ur ally suit ed t o
ar r ay r epr esent at ion.
Vector Representation
MATLAB r epr esent s or dinar y one-dimensional sampled dat a signals, or
sequences, as vectors. Vect or s ar e 1-by-n or n-by-1 ar r ays, wher e n is t he
number of samples in t he sequence. One way t o int r oduce a sequence int o
MATLAB is t o ent er it as a list of element s at t he command pr ompt . The
st at ement
x = [4 3 7 9 1]
cr eat es a simple five-element r eal sequence in a r ow vect or . Tr ansposit ion
t ur ns t he sequence int o a column vect or
x = x'
r esult ing in
x =
4
3
7
9
1
Column or ient at ion is pr efer able for single channel signals because it ext ends
nat ur ally t o t he mult ichannel case. For mult ichannel dat a, each column of a
mat r ix r epr esent s one channel. Each r ow of such a mat r ix t hen cor r esponds t o
a sample point . A t hr ee-channel signal t hat consist s of x, 2x, and x/ is
y = [x 2*x x/pi]
Representing Signals
1-5
This r esult s in
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
1 Signal Processing Basics
1-6
Waveform Generation: Time Vectors and Sinusoids
A var iet y of t oolbox funct ions gener at e wavefor ms. Most r equir e you t o begin
wit h a vect or r epr esent ing a t ime base. Consider gener at ing dat a wit h a 1000
Hz sample fr equency, for example. An appr opr iat e t ime vect or is
t = (0:0.001:1)';
wher e MATLABs colon oper at or cr eat es a 1001-element r ow vect or t hat
r epr esent s t ime r unning fr om zer o t o one second in st eps of one millisecond.
The t r anspose oper at or (') changes t he r ow vect or int o a column; t he
semicolon (;) t ells MATLAB t o comput e but not display t he r esult .
Given t you can cr eat e a sample signal y consist ing of t wo sinusoids, one at 50
Hz and one at 120 Hz wit h t wice t he amplit ude:
y = sin(2*pi*50*t) + 2*sin(2*pi*120*t);
The new var iable y, for med fr om vect or t, is also 1001 element s long. You can
add nor mally dist r ibut ed whit e noise t o t he signal and gr aph t he fir st fift y
point s using
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
-4
-3
-2
-1
0
1
2
3
4
Waveform Generation: Time Vectors and Sinusoids
1-7
Common Sequences: Unit Impulse, Unit Step, and
Unit Ramp
Since MATLAB is a pr ogr amming language, an endless var iet y of differ ent
signals is possible. Her e ar e some st at ement s t hat gener at e sever al commonly
used sequences, including t he unit impulse, unit st ep, and unit r amp funct ions:
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);
All of t hese sequences ar e column vect or s t he last t hr ee inher it t heir shapes
fr om t.
Multichannel Signals
Use st andar d MATLAB ar r ay synt ax t o wor k wit h mult ichannel signals. For
example, a mult ichannel signal consist ing of t he last t hr ee signals gener at ed
above is
z = [t t.^2 square(4*t)];
You can gener at e a mult ichannel unit sample funct ion using t he out er pr oduct
oper at or . For example, a six-element column vect or whose fir st element is one,
and whose r emaining five element s ar e zer os, is
a = [1 zeros(1,5)]';
To duplicat e column vect or a int o a mat r ix wit hout per for ming any
mult iplicat ion, use MATLABs colon oper at or and t he ones funct ion.
c = a(:,ones(1,3));
Common Periodic Waveforms
The t oolbox pr ovides funct ions for gener at ing widely used per iodic wavefor ms:
1 Signal Processing Basics
1-8
sawtooth gener at es a sawt oot h wave wit h peaks at t1 and a per iod of 2. An
opt ional width par amet er specifies a fr act ional mult iple of 2 at which t he
signals maximum occur s.
square gener at es a squar e wave wit h a per iod of 2. An opt ional par amet er
specifies duty cycle, t he per cent of t he per iod for which t he signal is posit ive.
To gener at e 1.5 seconds of a 50 Hz sawt oot h wave wit h a sample r at e of 10 kHz
and plot 0.2 seconds of t he gener at ed wavefor m, use
Fs = 10000;
t = 0:1/Fs:1.5;
x = sawtooth(2*pi*50*t);
plot(t,x), axis([0 0.2 1 1])
Common Aperiodic Waveforms
The t oolbox also pr ovides funct ions for gener at ing sever al widely used
aper iodic wavefor ms:
gauspuls gener at es a Gaussian-modulat ed sinusoidal pulse wit h a specified
t ime, cent er fr equency, and fr act ional bandwidt h. Opt ional par amet er s
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
Waveform Generation: Time Vectors and Sinusoids
1-9
r et ur n in-phase and quadr at ur e pulses, t he RF signal envelope, and t he
cut off t ime for t he t r ailing pulse envelope.
chirp gener at es a linear swept -fr equency cosine signal. An opt ional
par amet er specifies alt er nat ive sweep met hods. An opt ional par amet er phi
allows init ial phase t o be specified in degr ees.
To comput e 2 seconds of a linear chir p signal wit h a sample r at e of 1 kHz, t hat
st ar t s at DC and cr osses 150 Hz at 1 second, use
t = 0:1/1000:2;
y = chirp(t,0,1,150);
To plot t he spect r ogr am, use
specgram(y,256,1000,256,250)
The pulstran Function
The pulstran funct ion gener at es pulse t r ains fr om eit her cont inuous or
sampled pr ot ot ype pulses. The following example gener at es a pulse t r ain
consist ing of t he sum of mult iple delayed int er polat ions of a Gaussian pulse.
The pulse t r ain is defined t o have a sample r at e of 50 kHz, a pulse t r ain lengt h
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
1 Signal Processing Basics
1-10
of 10 ms, and a pulse r epet it ion r at e of 1 kHz; D specifies t he delay t o each pulse
r epet it ion in column 1 and an opt ional at t enuat ion for each r epet it ion in
column 2. The pulse t r ain is const r uct ed by passing t he name of t he gauspuls
funct ion t o pulstran, along wit h addit ional par amet er s t hat specify a 10 kHz
Gaussian pulse wit h 50% bandwidt h:
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)
The Sinc Function
The sinc funct ion comput es t he mat hemat ical sinc funct ion for an input vect or
or mat r ix x. The sinc funct ion is t he cont inuous inver se Four ier t r ansfor m of
t he r ect angular pulse of widt h 2 and height 1:
The sinc funct ion has a value of 1 wher e x is zer o, and a value of
for all ot her element s of x.
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
x ( ) sin
x
--------------------
Waveform Generation: Time Vectors and Sinusoids
1-11
To plot t he sinc funct ion for a linear ly spaced vect or wit h values r anging fr om
5 t o 5,
x = linspace(5,5);
y = sinc(x);
plot(x,y)
The Dirichlet Function
The t oolbox funct ion diric comput es t he Dir ichlet funct ion, somet imes called
t he periodic sinc or aliased sinc funct ion, for an input vect or or mat r ix x. The
Dir ichlet funct ion is
wher e n is a user -specified posit ive int eger . For n odd, t he Dir ichlet funct ion
has a per iod of 2; for n even, it s per iod is 4. The magnit ude of t his funct ion is
(1/n) t imes t he magnit ude of t he discr et e-t ime Four ier t r ansfor m of t he n-point
r ect angular window.
-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
dir ic x ( )
1
k n 1 ( )
x 2k k 0 1 t 2 t , , , = , =
n x 2 ( ) sin
n x 2 ( ) sin
----------------------------
otherwise

'

=
1 Signal Processing Basics
1-12
To plot t he Dir ichlet funct ion over t he r ange 0 t o 4 for n = 7 and n = 8, use
x = linspace(0,4*pi,300);
plot(x,diric(x,7))
plot(x,diric(x,8))
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
Working with Data
1-13
Working with Data
The examples in t he pr eceding sect ions obt ain dat a in one of t wo ways:
By dir ect input , t hat is, ent er ing t he dat a manually at t he keyboar d
By using a MATLAB or t oolbox funct ion, such as sin, cos, sawtooth, square,
or sinc
Some applicat ions, however , may need t o impor t dat a fr om out side MATLAB.
Depending on your dat a for mat , you can do t his in t he following ways:
Load dat a fr om an ASCII file or MAT-file wit h MATLABs load command
Read t he dat a int o MATLAB wit h a low-level file I/O funct ion, such as fopen,
fread, and fscanf
Develop a MEX-file t o r ead t he dat a
Ot her r esour ces ar e also useful, such as a high-level language pr ogr am (in
For t r an or C, for example) t hat conver t s your dat a int o MAT-file for mat see
t he MATLAB Application Programming Interface r efer ence manual for det ails.
MATLAB r eads such files using t he load command.
Similar t echniques ar e available for expor t ing dat a gener at ed wit hin
MATLAB. See Using MATLAB for mor e det ails on impor t ing and expor t ing
dat a, and see t he online MATLAB Function Reference for descr ipt ions of file
loading and I/O r out ines.
1 Signal Processing Basics
1-14
Filter Implementation and Analysis
This sect ion descr ibes how t o filt er discr et e signals using MATLABs filter
funct ion and ot her funct ions in t he Signal Pr ocessing Toolbox. It also discusses
how t o use t he t oolbox funct ions t o analyze filt er char act er ist ics, including
impulse r esponse, magnit ude and phase r esponse, gr oup delay, and zer o-pole
locat ions.
Convolution and Filtering
The mat hemat ical foundat ion of filt er ing is convolut ion. MATLABs conv
funct ion per for ms st andar d one-dimensional convolut ion, convolving one
vect or wit h anot her .
conv([1 1 1],[1 1 1])
ans =
1 2 3 2 1
NOTE Convolve r ect angular mat r ices for t wo-dimensional signal pr ocessing
using t he conv2 funct ion.
A digit al filt er s out put y(n) is r elat ed t o it s input x(n) by convolut ion wit h it s
impulse r esponse h(n).
If a digit al filt er s impulse r esponse h(n) is finit e lengt h, and t he input x(n) is
also finit e lengt h, you can implement t he filt er using conv. St or e x(n) in a vect or
x, h(n) in a vect or h, and convolve t he t wo.
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 n ( ) h n ( ) x n ( ) h n m ( )x m ( )
m =

= =
Filter Implementation and Analysis
1-15
Filters and Transfer Functions
In gener al, t he z-t r ansfor m Y(z) of a digit al filt er s out put y(n) is r elat ed t o t he
z-t r ansfor m X(z) of t he input by
wher e H(z) is t he filt er s transfer function. Her e, t he const ant s b(i) and a(i) ar e
t he filt er coefficient s and t he or der of t he filt er is t he maximum of na and nb.
NOTE The filt er coefficient s st ar t wit h subscr ipt 1, r at her t han 0. This
r eflect s MATLABs st andar d indexing scheme for vect or s.
MATLAB st or es t he coefficient s in t wo vect or s, one for t he numer at or and one
for t he denominat or . By convent ion, MATLAB uses r ow vect or s for filt er
coefficient s.
Filter Coefficients and Filter Names
Many st andar d names for filt er s r eflect t he number of a and b coefficient s
pr esent :
When nb = 0 (t hat is, b is a scalar ), t he filt er is an Infinit e Impulse Response
(IIR), all-pole, r ecur sive, or aut or egr essive (AR) filt er .
When na = 0 (t hat is, a is a scalar ), t he filt er is a Finit e Impulse Response
(FIR), all-zer o, nonr ecur sive, or moving aver age (MA) filt er .
If bot h na and nb ar e gr eat er t han zer o, t he filt er is an IIR, pole-zer o,
r ecur sive, or aut or egr essive moving aver age (ARMA) filt er .
The acr onyms AR, MA, and ARMA ar e usually applied t o filt er s associat ed
wit h filt er ed st ochast ic pr ocesses.
Y z ( ) H z ( )X z ( )
b 1 ( ) b 2 ( )z
1
L b n b 1 + ( )z
n b
+ + +
a 1 ( ) a 2 ( )z
1
L a n a 1 + ( )z
n a
+ + +
-----------------------------------------------------------------------------------------X z ( ) = =
1 Signal Processing Basics
1-16
Filtering with the filter Function
It is simple t o wor k back t o a differ ence equat ion fr om t he z-t r ansfor m r elat ion
shown ear lier . Assume t hat a(1) = 1. Move t he denominat or t o t he left -hand
side and t ake t he inver se z-t r ansfor m.
In t er ms of cur r ent and past input s, and past out put s, y(n) is
This is t he st andar d t ime-domain r epr esent at ion of a digit al filt er , comput ed
st ar t ing wit h y(1) and assuming zer o init ial condit ions. This r epr esent at ions
pr ogr ession is
A filt er in t his for m is easy t o implement wit h t he filter funct ion. For
example, a simple single-pole filt er (lowpass) is
b = 1; % numerator
a = [1 0.9]; % denominator
wher e t he vect or s b and a r epr esent t he coefficient s of a filt er in t r ansfer
funct ion for m. To apply t his filt er t o your dat a
y = filter(b,a,x);
filter gives you as many out put samples as t her e ar e input samples, t hat is,
t he lengt h of y is t he same as t he lengt h of x. If t he fir st element of a is not 1,
filter divides t he coefficient s by a(1) befor e implement ing t he differ ence
equat ion.
y n ( ) a 2 ( )y n 1 ( ) L a n a 1 + ( )y n n a ( ) + + + b 1 ( )x n ( ) b 2 ( )x n 1 ( ) L b n b 1 + ( )x n n b ( ) + + + =
y n ( ) b 1 ( )x n ( ) b 2 ( )x n 1 ( ) L b n b 1 + ( )x n n b ( ) a 2 ( )y n 1 ( ) L a n a 1 + ( ) y n n a ( ) + + + =
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 =
filter Function Implementation and Initial Conditions
1-17
filter Function Implementation and Initial Conditions
filter is implement ed as a t r ansposed dir ect for m II st r uct ur e
wher e n-1 is t he filt er or der . This is a canonical for m t hat has t he minimum
number of delay element s.
At sample m, filter comput es t he differ ence equat ions
In it s most basic for m, filter init ializes t he delay out put s z
i
(1), i = 1, ..., n-1
t o 0. This is equivalent t o assuming bot h past input s and out put s ar e zer o. Set
t he init ial delay out put s using a four t h input par amet er t o filter, or access
t he final delay out put s using a second out put par amet er .
[y,zf] = filter(b,a,x,zi)
Access t o init ial and final condit ions is useful for filt er ing dat a in sect ions,
especially if memor y limit at ions ar e a consider at ion. Suppose you have
collect ed dat a in t wo segment s of 5000 point s each.
x1 = randn(5000,1); % two random sequences to
x2 = randn(5000,1); % serve as simulated data
Per haps t he fir st sequence, x1, cor r esponds t o t he fir st 10 minut es of dat a and
t he second, x2, t o an addit ional 10 minut es. The whole sequence is
x = [x1; x2]. If t her e is not sufficient memor y t o hold t he combined sequence,
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 ( ) =
1 Signal Processing Basics
1-18
filt er t he subsequences x1 and x2 one at a t ime. To ensur e cont inuit y of t he
filt er ed sequences, use t he final condit ions fr om x1 as init ial condit ions t o filt er
x2.
[y1,zf] = filter(b,a,x1);
y2 = filter(b,a,x2,zf);
The filtic funct ion gener at es init ial condit ions for filter. filtic comput es
t he delay vect or t o make t he behavior of t he filt er r eflect past input s and
out put s t hat you specify. To obt ain t he same out put delay values zf as above
using filtic
zf = filtic(b,a,flipud(y1),flipud(x1));
This can be useful when filt er ing shor t dat a sequences, as appr opr iat e init ial
condit ions help r educe t r ansient st ar t up effect s.
Other Functions for Filtering
1-19
Other Functions for Filtering
In addit ion t o filter, sever al ot her funct ions in t he Signal Pr ocessing Toolbox
per for m t he basic filt er ing oper at ion. These funct ions include upfirdn, which
per for ms FIR filt er ing wit h r esampling, filtfilt, which eliminat es phase
dist or t ion in t he filt er ing pr ocess, fftfilt, which per for ms t he FIR filt er ing
oper at ion in t he fr equency domain, and latcfilt, which filt er s using a lat t ice
implement at ion.
Multirate Filter Bank Implementation
The funct ion upfirdn alt er s t he sampling r at e of a signal by an int eger r at io
P/Q. It comput es t he r esult of t he cascade of t hr ee syst ems: (1) upsampling
(zer o inser t ion) by int eger fact or p, (2) filt er ing by FIR filt er h, and (3)
downsampling by int eger fact or q.
For example, t o change t he sample r at e of a signal fr om 44.1 kHz t o 48 kHz,
we fir st find t he smallest int eger conver sion r at io p/q.
d = gcd(48000,44100);
p = 48000/d;
q = 44100/d;
wher e we find t hat p = 160 and q = 147. Sample r at e conver sion is t hen
accomplished by y = upfirdn(x,h,p,q). This cascade of oper at ions is
implement ed in an efficient manner using polyphase filt er ing t echniques, and
it is a cent r al concept of mult ir at e filt er ing (see r efer ence [1] for det ails on
mult ir at e filt er t heor y). Not e t hat t he qualit y of t he r esampling r esult r elies on
t he qualit y of t he FIR filt er h.
Filt er banks may be implement ed using upfirdn by allowing t he filt er h t o be
a mat r ix, wit h one FIR filt er per column. A signal vect or is passed
independent ly t hr ough each FIR filt er , r esult ing in a mat r ix of out put signals.
Ot her funct ions t hat per for m mult ir at e filt er ing (wit h fixed filt er ) include
resample, interp, and decimate.
P
x(n) y(n)
FIR
H
Q
1 Signal Processing Basics
1-20
Anti-Causal, Zero-Phase Filter Implementation
In t he case of FIR filt er s, it is possible t o design linear phase filt er s t hat , when
applied t o dat a (using filter or conv), simply delay t he out put by a fixed
number of samples. For IIR filt er s, however , t he phase dist or t ion is usually
highly nonlinear . The filtfilt funct ion uses t he infor mat ion in t he signal at
point s befor e and aft er t he cur r ent point , in essence looking int o t he fut ur e,
t o eliminat e phase dist or t ion.
To see how filtfilt does t his, r ecall t hat if t he z-t r ansfor m of a r eal sequence
x(n) is X(z), t he z-t r ansfor m of t he t ime r ever sed sequence x(n) is X(1/z).
Consider t he pr ocessing scheme
When | z| = 1, t hat is z = e
j
, t he out put r educes t o X(e
j
)| H(e
j
)|
2
. Given all
t he samples of t he sequence x(n), a doubly filt er ed ver sion of x t hat has
zer o-phase dist or t ion is possible.
For example, a one-second dur at ion signal sampled at 100 Hz, composed of t wo
sinusoidal component s at 3 Hz and 40 Hz, is
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
Other Functions for Filtering
1-21
Now cr eat e a 10-point aver aging FIR filt er , and filt er x using bot h filter and
filtfilt for compar ison:
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,':')
Bot h filt er ed ver sions eliminat e t he 40 Hz sinusoid evident in t he or iginal,
solid line. The plot also shows how filter and filtfilt differ ; t he dashed
(filtfilt) line is in phase wit h t he or iginal 3 Hz sinusoid, while t he dot t ed
(filter) line is delayed by about five samples. Also, t he amplit ude of t he
dashed line is smaller due t o t he magnit ude squar ed effect s of filtfilt.
filtfilt r educes filt er st ar t up t r ansient s by car efully choosing init ial
condit ions, and by pr epending ont o t he input sequence a shor t , r eflect ed piece
of t he input sequence. For best r esult s, make sur e t he sequence you ar e
filt er ing has lengt h at least t hr ee t imes t he filt er or der and t aper s t o zer o on
bot h 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
1 Signal Processing Basics
1-22
Frequency Domain Filter Implementation
Dualit y bet ween t he t ime domain and t he fr equency domain makes it possible
t o per for m any oper at ion in eit her domain. Usually one domain or t he ot her is
mor e convenient for a par t icular oper at ion, but you can always accomplish a
given oper at ion in eit her domain.
To implement gener al IIR filt er ing in t he fr equency domain, mult iply t he
discr et e Four ier t r ansfor m (DFT) of t he input sequence wit h t he quot ient of t he
DFT of t he filt er ,
n = length(x);
y = ifft(fft(x).*fft(b,n)./fft(a,n));
This comput es r esult s t hat ar e ident ical t o filter, but wit h differ ent st ar t up
t r ansient s (edge effect s). For long sequences, t his comput at ion is ver y
inefficient because of t he lar ge zer o-padded FFT oper at ions on t he filt er
coefficient s, and because t he FFT algor it hm becomes less efficient as t he
number of point s n incr eases.
For FIR filt er s, however , it is possible t o br eak longer sequences int o shor t er ,
comput at ionally efficient FFT lengt hs. The funct ion
y = fftfilt(b,x)
uses t he over lap add met hod (see r efer ence [1] at t he end of t his chapt er ) t o
filt er a long sequence wit h mult iple medium-lengt h FFTs. It s out put is
equivalent t o filter(b,1,x).
Impulse Response
1-23
Impulse Response
The impulse r esponse of a digit al filt er is t he out put ar ising fr om t he input
sequence
In MATLAB, you can gener at e an impulse sequence a number of ways; one
st r aight for war d way is
imp = [1; zeros(49,1)];
The impulse r esponse of t he simple filt er b = 1 and a = [1 0.9] is
h = filter(b,a,imp);
The impz funct ion in t he t oolbox simplifies t his oper at ion, choosing t he number
of point s t o gener at e and t hen making a st em plot (using t he stem funct ion).
impz(b,a)
The plot shows t he exponent ial decay h(n) = 0.9n of t he single pole syst em.
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
1 Signal Processing Basics
1-24
Frequency Response
The Signal Pr ocessing Toolbox enables you t o per for m fr equency domain
analysis of bot h analog and digit al filt er s.
Digital Domain
freqz uses an FFT-based algor it hm t o calculat e t he z-t r ansfor m fr equency
r esponse of a digit al filt er . Specifically, t he st at ement
[h,w] = freqz(b,a,n)
r et ur ns t he n-point complex fr equency r esponse, H(e
j
), of t he digit al filt er .
In it s simplest for m, freqz accept s t he filt er coefficient vect or s b and a, and an
int eger n specifying t he number of point s at which t o calculat e t he fr equency
r esponse. freqz r et ur ns t he complex fr equency r esponse in vect or h, and t he
act ual fr equency point s in vect or w in r adians/second.
freqz can accept ot her par amet er s, such as a sampling fr equency or a vect or of
ar bit r ar y fr equency point s. The example below finds t he 256-point fr equency
r esponse for a 12t h-or der Chebyshev t ype I filt er . The call t o freqz specifies a
sampling fr equency Fs of 1000 Hz.
[b,a] = cheby1(12,0.5,200/500);
[h,f] = freqz(b,a,256,1000);
Because t he par amet er list includes a sampling fr equency, freqz r et ur ns a
vect or f t hat cont ains t he 256 fr equency point s bet ween 0 and Fs/2 used in t he
fr equency r esponse calculat ion.
H e
j
( )
b 1 ( ) b 2 ( )e
j
L b n b 1 + ( )e
j n b ( )
+ + +
a 1 ( ) a 2 ( )e
j
L a n a 1 + ( )e
j n a ( )
+ + +
---------------------------------------------------------------------------------------------------- =
Frequency Response
1-25
Frequency Normalization This t oolbox uses t he convent ion t hat unit
fr equency is t he Nyquist fr equency, defined as half t he sampling fr equency.
The cut off fr equency par amet er for all basic filt er design funct ions is
nor malized by t he Nyquist fr equency. For a syst em wit h a 1000 Hz sampling
fr equency, for example, 300 Hz is 300/500 = 0.6. To conver t nor malized
fr equency t o angular fr equency ar ound t he unit cir cle, mult iply by . To
conver t nor malized fr equency back t o Her t z, mult iply by half t he sample
fr equency.
If you call freqz wit h no out put ar gument s, it aut omat ically plot s bot h
magnit ude ver sus fr equency and phase ver sus fr equency. For example, a
nint h-or der But t er wor t h lowpass filt er wit h a cut off fr equency of 400 Hz, based
on a 2000 Hz sampling fr equency, is
[b,a] = butter(9,400/1000);
Now calculat e t he 256-point complex fr equency r esponse for t his filt er , and plot
t he magnit ude and phase wit h a call t o 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
)
1 Signal Processing Basics
1-26
freqz can also accept a vect or of ar bit r ar y fr equency point s for use in t he
fr equency r esponse calculat ion. For example,
w = linspace(0,pi);
h = freqz(b,a,w);
calculat es t he complex fr equency r esponse at t he fr equency point s in w for t he
filt er defined by vect or s b and a. The fr equency point s can r ange fr om 0 t o 2.
To specify a fr equency vect or t hat r anges fr om zer o t o your sampling fr equency,
include bot h t he fr equency vect or and t he sampling fr equency value in t he
par amet er list .
Analog Domain
freqs evaluat es fr equency r esponse for an analog filt er defined by t wo input
coefficient vect or s b and a. It s oper at ion is similar t o t hat of freqz; you can
specify a number of fr equency point s t o use (by default , t he funct ion uses 200),
supply a vect or of ar bit r ar y fr equency point s, and plot t he magnit ude and
phase r esponse of t he filt er .
Magnitude and Phase
MATLAB pr ovides funct ions t o ext r act magnit ude and phase fr om a fr equency
r esponse vect or h. The funct ion abs r et ur ns t he magnit ude of t he r esponse;
angle r et ur ns t he phase angle in r adians. To ext r act and plot t he magnit ude
and phase of a But t er wor t h filt er .
[b,a] = butter(6,300/500); [h,w] = freqz(b,a,512,1000);
m = abs(h); p = angle(h);
semilogy(w,m);
plot(w,p*180/pi)
0 100 200 300 400
10
-15
10
-10
10
-5
10
0
0 100 200 300 400
-200
-100
0
100
200
Frequency Response
1-27
The unwrap funct ion is also useful in fr equency analysis. unwrap unwr aps t he
phase t o make it cont inuous acr oss 360 phase discont inuit ies by adding
mult iples of t360, as needed. To see how unwrap is useful, design a 25t h-or der
lowpass FIR filt er .
h = fir1(25,0.4);
Obt ain t he filt er s fr equency r esponse wit h freqz, and plot t he phase in
degr ees.
[H,f] = freqz(h,1,512,2);
plot(f,angle(H)*180/pi); grid
It is difficult t o dist inguish t he 360 jumps (an ar t ifact of t he ar ct angent
funct ion inside angle) fr om t he 180 jumps t hat signify zer os in t he fr equency
r esponse.
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
1 Signal Processing Basics
1-28
Use unwrap t o eliminat e t he 360 jumps.
plot(f,unwrap(angle(H))*180/pi); grid
Delay
The group delay of a filt er is a measur e of t he aver age delay of t he filt er as a
funct ion of fr equency. It is defined as t he negat ive fir st der ivat ive of a filt er s
phase r esponse. If t he complex fr equency r esponse of a filt er is H(e
j
), t hen t he
gr oup delay is
wher e is t he phase angle of H(e
j
). Comput e gr oup delay wit h
[gd,w] = grpdelay(b,a,n)
which r et ur ns t he n-point gr oup delay, , of t he digit al filt er specified by b
and a, evaluat ed at t he fr equencies in vect or w.
The phase delay of a filt er is t he negat ive of phase divided by fr equency
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

g
( )
d ( )
d
--------------- =

g
( )

p
( )
( )

----------- =
Frequency Response
1-29
To plot bot h t he gr oup and phase delays of a syst em on t he same gr aph.
[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
1 Signal Processing Basics
1-30
Zero-Pole Analysis
The zplane funct ion plot s poles and zer os of a linear syst em. For example, a
simple filt er wit h a 0 at -1/2 and a complex pole pair at and
is
zer = 0.5;
pol = .9*exp(j*2*pi*[0.3 .3]');
The zer o-pole plot for t he filt er is
zplane(zer,pol)
For a syst em in zer o-pole for m, supply column vect or ar gument s z and p t o
zplane.
zplane(z,p)
For a syst em in t r ansfer funct ion for m, supply r ow vect or s b and a as
ar gument s t o zplane.
zplane(b,a)
In t his case zplane finds t he r oot s of b and a using t he roots funct ion and plot s
t he r esult ing zer os and poles.
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
Zero-Pole Analysis
1-31
See Linear Syst em Models on page 1-32 for det ails on zer o-pole and t r ansfer
funct ion r epr esent at ion of syst ems.
1 Signal Processing Basics
1-32
Linear System Models
The Signal Pr ocessing Toolbox pr ovides sever al models for r epr esent ing linear
t ime-invar iant syst ems. This flexibilit y let s you choose t he r epr esent at ional
scheme t hat best suit s your applicat ion and, wit hin t he bounds of numer ic
st abilit y, conver t fr eely t o and fr om most ot her models. This sect ion pr ovides a
br ief over view of suppor t ed linear syst em models and descr ibes how t o wor k
wit h t hese models in MATLAB.
Discrete-Time System Models
The discr et e-t ime syst em models ar e r epr esent at ional schemes for digit al
filt er s. MATLAB suppor t s sever al discr et e-t ime syst em models:
Tr ansfer funct ion
Zer o-pole-gain for m
St at e-space for m
Par t ial fr act ion expansion
Second-or der sect ion for m
Lat t ice st r uct ur e for m
Convolut ion mat r ices
Transfer Function
The transfer function is a basic z-domain r epr esent at ion of a digit al filt er ,
expr essing t he filt er as a r at io of t wo polynomials. It is t he pr incipal
discr et e-t ime model for t his t oolbox. The t r ansfer funct ion model descr ipt ion
for t he z-t r ansfor m of a digit al filt er s differ ence equat ion is
Her e, t he const ant s b(i) and a(i) ar e t he filt er coefficient s, and t he or der of t he
filt er is t he maximum of na and nb. In MATLAB, you st or e t hese coefficient s in
t wo vect or s (r ow vect or s by convent ion), one r ow vect or for t he numer at or and
one for t he denominat or . See Filt er s and Tr ansfer Funct ions on page 1-15 for
mor e det ails on t he t r ansfer funct ion for m.
Y z ( )
b 1 ( ) b 2 ( )z
1
L b n b 1 + ( )z
n b
+ + +
a 1 ( ) a 2 ( )z
1
L a n a 1 + ( )z
n a
+ + +
---------------------------------------------------------------------------------------- -X z ( ) =
Linear System Models
1-33
Zero-Pole-Gain
The fact or ed or zero-pole-gain for m of a t r ansfer funct ion is
By convent ion, MATLAB st or es polynomial coefficient s in r ow vect or s and
polynomial r oot s in column vect or s. In zer o-pole-gain for m, t her efor e, t he zer o
and pole locat ions for t he numer at or and denominat or of a t r ansfer funct ion
r eside in column vect or s. The fact or ed t r ansfer funct ion gain k is a MATLAB
scalar .
The poly and roots funct ions conver t bet ween polynomial and zer o-pole-gain
r epr esent at ions. For example, a simple IIR filt er is
b = [2 3 4];
a = [1 3 3 1];
The zer os and poles of t his filt er ar e
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
H z ( )
q z ( )
p z ( )
---------- k
z q 1 ( ) ( ) z q 2 ( ) ( )Lz q n ( ) ( )
z p 1 ( ) ( ) z p 2 ( ) ( )Lz p n ( ) ( )
----------------------------------------------------------------------------- = =
1 Signal Processing Basics
1-34
Ret ur ning t o t he or iginal polynomials,
bb = k*poly(q)
bb =
2.0000 3.0000 4.0000
aa = poly(p)
aa =
1.0000 3.0000 3.0000 1.0000
Not e t hat b and a in t his case r epr esent t he t r ansfer funct ion
For b = [2 3 4], t he roots funct ion misses t he zer o for z equal t o 0. In fact , it
misses poles and zer os for z equal t o 0 whenever t he input t r ansfer funct ion has
mor e poles t han zer os, or vice ver sa. This is accept able in most cases. To
cir cumvent t he pr oblem, however , simply append zer os t o make t he vect or s t he
same lengt h befor e using t he roots funct ion, for example, b = [b 0].
State-Space
It is always possible t o r epr esent a digit al filt er , or a syst em of differ ence
equat ions, as a set of fir st -or der differ ence equat ions. In mat r ix or state-space
for m, you can wr it e t he equat ions as
wher e u is t he input , x is t he st at e vect or , and y is t he out put . For
single-channel syst ems, A is an m-by-m mat r ix wher e m is t he or der of t he filt er ,
B is a column vect or , C is a r ow vect or , and D is a scalar . St at e-space not at ion is
especially convenient for mult ichannel syst ems wher e input u and out put y
become vect or s, and B, C, and D become mat r ices.
St at e-space r epr esent at ion ext ends easily t o t he MATLAB envir onment . In
MATLAB, A, B, C, and D ar e r ect angular ar r ays; MATLAB t r eat s t hem as
individual var iables.
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 ( ) + =
Linear System Models
1-35
Taking t he z-t r ansfor m of t he st at e-space equat ions and combining t hem shows
t he equivalence of st at e-space and t r ansfer funct ion for ms.
Dont be concer ned if you ar e not familiar wit h t he st at e-space r epr esent at ion
of linear syst ems. Some of t he filt er design algor it hms use st at e-space for m
int er nally but do not r equir e any knowledge of st at e-space concept s t o use t hem
successfully. If your applicat ions use st at e-space based signal pr ocessing
ext ensively, however , consult t he Cont r ol Syst em Toolbox for a compr ehensive
libr ar y of st at e-space t ools.
Partial Fraction Expansion (Residue Form)
Each t r ansfer funct ion also has a cor r esponding partial fraction expansion or
residue for m r epr esent at ion, given by
pr ovided H(z) has no r epeat ed poles. Her e, n is t he degr ee of t he denominat or
polynomial of t he r at ional t r ansfer funct ion b(z)/a(z). If r is a pole of mult iplicit y
s
r
, t hen H(z) has t er ms of t he for m
The residuez funct ion in t he Signal Pr ocessing Toolbox conver t s t r ansfer
funct ions t o and fr om t he par t ial fr act ion expansion for m. The z on t he end of
residuez st ands for z-domain, or discr et e domain. residuez r et ur ns t he poles
in a column vect or p, t he r esidues cor r esponding t o t he poles in a column vect or
r, and any impr oper par t of t he or iginal t r ansfer funct ion in a r ow vect or k.
residuez det er mines t hat t wo poles ar e t he same if t he magnit ude of t heir
differ ence is smaller t han 0.1 per cent of eit her of t he poles magnit udes.
Par t ial fr act ion expansion ar ises in signal pr ocessing as one met hod of finding
t he inver se z-t r ansfor m of a t r ansfer funct ion. For example, t he par t ial fr act ion
expansion of
Y z ( ) H z ( )U z ( ) = wher e H z ( ) C z I A ( )
1
B D + = ,
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
+ +
---------------------------------------- =
1 Signal Processing Basics
1-36
is
b = [4 8];
a = [1 6 8];
[r,p,k] = residuez(b,a)
r =
12
8
p =
4
2
k =
[]
cor r esponding t o
To find t he inver se z-t r ansfor m of H(z), find t he sum of t he inver se z-t r ansfor ms
of t he t wo addends of H(z), giving t he causal impulse r esponse
To ver ify t his in MATLAB
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
Second-Order Sections (SOS)
Any t r ansfer funct ion H(z) has a second-or der sect ions r epr esent at ion
H z ( )
12
1 4z
1
+
---------------------
8
1 2z
1
+
--------------------- + =
h n ( ) 12 4 ( )
n
8 2 ( )
n
+ n 0 1 2 , , , = , =
Linear System Models
1-37
wher e L is t he number of second-or der sect ions t hat descr ibe t he syst em.
MATLAB r epr esent s t he second-or der sect ion for m of a discr et e-t ime syst em as
an L-by-6 ar r ay sos. Each r ow of sos cont ains a single second-or der sect ion,
wher e t he r ow element s ar e t he t hr ee numer at or and t hr ee denominat or
coefficient s t hat descr ibe t he second-or der sect ion.
Ther e ar e an uncount able number of ways t o r epr esent a filt er in second-or der
sect ion for m. Thr ough car eful pair ing of t he pole and zer o pair s, or der ing of t he
sect ions in t he cascade, and mult iplicat ive scaling of t he sect ions, it is possible
t o r educe quant izat ion noise gain and avoid over flow in some fixed-point filt er
implement at ions. The funct ions zp2sos and ss2sos, descr ibed lat er in Linear
Syst em Tr ansfor mat ions, per for m pole-zer o pair ing, sect ion scaling, and
sect ion or der ing.
Lattice Structure
For a discr et e Nt h or der all-pole or all-zer o filt er descr ibed by t he polynomial
coefficient s a(n), n = 1,2,,N+1, t her e ar e N cor r esponding lat t ice st r uct ur e
coefficient s k(n), n =1,2,,N. The par amet er s k(n) ar e also called t he reflection
H z ( ) H
k
z ( )
k 1 =
L

b
0k
b
1k
z
1
b
2 k
z
2
+ +
a
0k
a
1 k
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
1 L
a
2 L
=
1 Signal Processing Basics
1-38
coefficients of t he filt er . Given t hese r eflect ion coefficient s, you can implement
a discr et e filt er as
For a gener al pole-zer o IIR filt er descr ibed by polynomial coefficient s a and b,
t her e ar e bot h lat t ice coefficient s k(n) for t he denominat or a and ladder
coefficient s v(n) for t he numer at or b. The lat t ice/ladder filt er may be
implement ed as

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

k(n)
k(n)
. . .
. . .
z
-1
FIR Lat t ice Filt er
x(m)
x(m)

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

k(n)
k(n)
. . .
. . .
z
-1
z
-1
IIR Lat t ice Filt er
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)
Linear System Models
1-39
The t oolbox funct ion tf2latc accept s an FIR or IIR filt er in polynomial for m
and r et ur ns t he cor r esponding r eflect ion coefficient s. An example IIR filt er in
polynomial for m is
a = [1.0000 0.6149 0.9899 0.0000 0.0031 0.0082];
This filt er s lat t ice (r eflect ion coefficient ) r epr esent at ion is
k = tf2latc(a)
k =
0.3090
0.9800
0.0031
0.0081
0.0082
The magnit ude of t he r eflect ion coefficient s pr ovides an easy st abilit y check for
a filt er . If all t he r eflect ion coefficient s cor r esponding t o a polynomial have
magnit ude less t han 1, all of t hat polynomials r oot s ar e inside t he unit cir cle.
The funct ion latc2tf calculat es t he polynomial coefficient s for a filt er fr om it s
lat t ice (r eflect ion) coefficient s. Given t he r eflect ion coefficient vect or k(above),
t he cor r esponding polynomial for m is
a = latc2tf(k)
a =
1.0000 0.6149 0.9899 0.0000 0.0031 0.0082
The lat t ice or lat t ice/ladder coefficient s can be used t o implement t he filt er
using t he funct ion latcfilt.
Convolution Matrix
In signal pr ocessing, convolving t wo vect or s or mat r ices is equivalent t o
filt er ing one of t he input oper ands by t he ot her . This r elat ionship per mit s t he
r epr esent at ion of a digit al filt er as a convolution matrix.
Given any vect or , t he t oolbox convmtx funct ion gener at es a mat r ix whose inner
pr oduct wit h anot her vect or is equivalent t o t he convolut ion of t he t wo vect or s.
The gener at ed mat r ix r epr esent s a digit al filt er t hat you can apply t o any
1 Signal Processing Basics
1-40
vect or of appr opr iat e lengt h; t he inner dimension of t he oper ands must agr ee
t o comput e t he inner pr oduct .
The convolut ion mat r ix for a vect or b, r epr esent ing t he numer at or coefficient s
for a digit al filt er , is
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 ways t o convolve b wit h x ar e
y1 = C*x;
y2 = conv(b,x);
Type t his example int o MATLAB; t he r esult s for y1 and y2 ar e equal.
Continuous-Time System Models
The cont inuous-t ime syst em models ar e r epr esent at ional schemes for analog
filt er s. Many of t he discr et e-t ime syst em models descr ibed ear lier ar e also
appr opr iat e for t he r epr esent at ion of cont inuous-t ime syst ems:
St at e-space for m
Par t ial fr act ion expansion
Tr ansfer funct ion
Zer o-pole-gain for m
It is possible t o r epr esent any syst em of linear t ime-invar iant differ ent ial
equat ions as a set of fir st -or der differ ent ial equat ions. In mat r ix or state-space
for m, you can expr ess t he equat ions as
x

Ax Bu + =
y Cx Du + =
Linear System Models
1-41
wher e u is a vect or of nu input s, x is an nx-element st at e vect or , and y is a vect or
of ny out put s. In MATLAB, st or e A, B, C, and D in separ at e r ect angular ar r ays.
An equivalent r epr esent at ion of t he st at e-space syst em is t he Laplace
t r ansfor m t r ansfer funct ion descr ipt ion
wher e
For single-input , single-out put syst ems, t his for m is given by
Given t he coefficient s of a Laplace t r ansfor m t r ansfer funct ion, residue
det er mines t he par t ial fr act ion expansion of t he syst em. See t he descr ipt ion of
residue in t he MATLAB Language Reference Manual for det ails.
The fact or ed zer o-pole-gain for m is
As in t he discr et e-t ime case, MATLAB st or es polynomial coefficient s in r ow
vect or s in descending power s of s. MATLAB st or es polynomial r oot s, or zer os
and poles, in column vect or s.
Linear System Transformations
The Signal Pr ocessing Toolbox pr ovides a number of funct ions t hat conver t
bet ween t he var ious linear syst em models; see t he r efer ence descr ipt ion in
Chapt er 6 for a complet e descr ipt ion of each. You can use t he following char t t o
find an appr opr iat e t r ansfer funct ion: find t he r ow of t he model t o conver t from
on t he left side of t he char t and t he column of t he model t o conver t to on t he t op
of t he char t and r ead t he funct ion name(s) at t he int er sect ion of t he r ow and
column.
Y s ( ) H s ( )U s ( ) =
H s ( ) C s I A ( )
1
B D + =
H s ( )
b s ( )
a s ( )
----------
b 1 ( )s
n b
b 2 ( )s
n b 1
L b n b 1 + ( ) + + +
a 1 ( )s
n a
a 2 ( )s
n a 1
L a n a 1 + ( ) + + +
---------------------------------------------------------------------------------------------- = =
H s ( )
z s ( )
p s ( )
---------- k
s z 1 ( ) ( ) s z 2 ( ) ( )Ls z n ( ) ( )
s p 1 ( ) ( ) s p 2 ( ) ( )Ls p n ( ) ( )
----------------------------------------------------------------------------- = =
1 Signal Processing Basics
1-42
Many of t he t oolbox filt er design funct ions use t hese funct ions int er nally. For
example, t he zp2ss funct ion conver t s t he poles and zer os of an analog
pr ot ot ype int o t he st at e-space for m r equir ed for cr eat ion of a But t er wor t h,
Chebyshev, or ellipt ic filt er . Once in st at e-space for m, t he filt er design funct ion
per for ms any r equir ed fr equency t r ansfor mat ion, t hat is, it t r ansfor ms t he
init ial lowpass design int o a bandpass, highpass, or bandst op filt er , or a
lowpass filt er wit h t he desir ed cut off fr equency. See Chapt er 6 and t he
r efer ence descr ipt ions of t he individual filt er design funct ions for mor e det ails.
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
Second-
order
sections
sos2tf sos2ss sos2zp
Convolution
matrix
Discrete Fourier Transform
1-43
Discrete Fourier Transform
The discr et e Four ier t r ansfor m, or DFT, is t he pr imar y t ool of digit al signal
pr ocessing. The foundat ion of t he Signal Pr ocessing Toolbox is t he Fast Four ier
Tr ansfor m (FFT), a met hod for comput ing t he DFT wit h r educed execut ion
t ime. Many of t he t oolbox funct ions (including z-domain fr equency r esponse,
spect r um and cepst r um analysis, and some filt er design and implement at ion
funct ions) incor por at e t he FFT.
MATLAB pr ovides t he funct ions fft and ifft t o comput e t he discr et e Four ier
t r ansfor m and it s inver se, r espect ively. For t he input sequence x and it s
t r ansfor med ver sion X (t he discr et e-t ime Four ier t r ansfor m at equally spaced
fr equencies ar ound t he unit cir cle), t he t wo funct ions implement t he
r elat ionships
In t hese equat ions, t he ser ies subscr ipt s begin wit h 1 inst ead of 0 because of
MATLABs vect or indexing scheme, and
NOTE MATLAB uses a negat ive j for t he fft funct ion. This is an engineer ing
convent ion; physics and pur e mat hemat ics t ypically use a posit ive j.
fft, wit h a single input ar gument x, comput es t he DFT of t he input vect or or
mat r ix. If x is a vect or , fft comput es t he DFT of t he vect or ; if x is a r ect angular
ar r ay, fft comput es t he DFT of each ar r ay column.
X k 1 + ( ) x n 1 + ( )W
n
k n
n 0 =
N 1

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

=
W
N
e
j
2
N
-------
,
_
=
1 Signal Processing Basics
1-44
For example, cr eat e a t ime vect or and signal.
t = (0:1/99:1); % time vector
x = sin(2*pi*15*t) + sin(2*pi*40*t);% signal
The DFT of t he signal, and t he magnit ude and phase of t he t r ansfor med
sequence, ar e t hen
y = fft(x); % Compute DFT of x.
m = abs(y); p = unwrap(angle(y)); % mag. and phase
To plot t he magnit ude and phase
f = (0:length(y)1)*99/length(y); % frequency vector
plot(f,m)
set(gca,'XTick',[15 40 60 85]);
plot(f,p*180/pi)
set(gca,'XTick',[15 40 60 85]);
A second ar gument t o fft specifies a number of point s n for t he t r ansfor m,
r epr esent ing DFT lengt h.
y = fft(x,n);
In t his case, fft pads t he input sequence wit h zer os if it is shor t er t han n, or
t r uncat es t he sequence if it is longer t han n. If n is not specified, it default s t o
t he lengt h of t he input sequence.
15 40 60 85
0
10
20
30
40
50
15 40 60 85
-1500
-1000
-500
0
Discrete Fourier Transform
1-45
Execut ion t ime for fft depends on t he lengt h n of t he DFT it per for ms:
For any n t hat is a power of t wo, fft uses t he high-speed r adix-2 algor it hm.
This r esult s in t he fast est execut ion t ime. Addit ionally, t he algor it hm for
power of t wo n is highly opt imized for r eal x, pr oviding a 40% speed-up over
t he complex case.
For any composit e number n t hat is not a power of t wo, fft uses a pr ime
fact or algor it hm. The speed of t his algor it hm depends on bot h t he size of n
and number of pr ime fact or s it has. Alt hough 1013 and 1000 ar e close in
magnit ude, fft t r ansfor ms a sequence of lengt h 1000 much mor e quickly
t han a sequence of lengt h 1013.
For a pr ime number n, fft cannot use an FFT algor it hm, and inst ead
per for ms t he slower , comput at ion-int ensive DFT dir ect ly.
The inver se discr et e Four ier t r ansfor m funct ion ifft also accept s an input
sequence and, opt ionally, t he number of desir ed point s for t he t r ansfor m. Tr y
t he example below; t he or iginal sequence x and t he r econst r uct ed sequence ar e
ident ical (wit hin r ounding er r or ).
t = (0:1/255:1);
x = sin(2*pi*120*t);
y = real(ifft(fft(x)));
This t oolbox also includes funct ions for t he t wo-dimensional FFT and it s
inver se, fft2 and ifft2. These funct ions ar e useful for t wo-dimensional signal
or image pr ocessing; see t he r efer ence descr ipt ions in Chapt er 6 for det ails.
It is somet imes convenient t o r ear r ange t he out put of t he fft or fft2 funct ion
so t he zer o fr equency component is at t he cent er of t he sequence. The MATLAB
funct ion fftshift moves t he zer o fr equency component t o t he cent er of a vect or
or mat r ix.
1 Signal Processing Basics
1-46
References
Algor it hm development for t he Signal Pr ocessing Toolbox has dr awn heavily
upon t he r efer ences list ed below. All ar e r ecommended t o t he int er est ed r eader
who needs t o know mor e about signal pr ocessing t han is cover ed in t his
manual.
1 Cr ochier e, R.E., and L.R. Rabiner . Multi-Rate S ignal Processing. Englewood
Cliffs, NJ : Pr ent ice Hall, 1983. Pgs. 88-91.
2 IEEE. Programs for Digital S ignal Processing. IEEE Pr ess. New Yor k: J ohn
Wiley & Sons, 1979.
3 J ackson, L.B. Digital Filters and S ignal Processing. Thir d Ed. Bost on:
Kluwer Academic Publisher s, 1989.
4 Kay, S.M. Modern S pectral Estimation. Englewood Cliffs, NJ : Pr ent ice Hall,
1988.
5 Oppenheim, A.V., and R.W. Schafer . Discrete-Time S ignal Processing.
Englewood Cliffs, NJ : Pr ent ice Hall, 1989.
6 Par ks, T.W., and C.S. Bur r us. Digital Filter Design. New Yor k: J ohn Wiley
& Sons, 1987.
7 Pr at t ,W.K. Digital Image Processing. New Yor k: J ohn Wiley & Sons, 1991.
8 Per cival, D.B., and A.T. Walden. S pectral Analysis for Physical Applications:
Multitaper and Conventional Univariate Techniques. Cambr idge:
Cambr idge Univer sit y Pr ess, 1993.
9 Pr oakis, J .G., and D.G. Manolakis. Digital S ignal Processing: Principles,
Algorithms, and Applications. Upper Saddle River , NJ : Pr ent ice Hall, 1996.
10 Rabiner , L.R., and B. Gold. Theory and Application of Digital S ignal
Processing. Englewood Cliffs, NJ : Pr ent ice Hall, 1975.
11 Welch, P.D. The Use of Fast Four ier Tr ansfor m for t he Est imat ion of Power
Spect r a: A Met hod Based on Time Aver aging Over Shor t , Modified
Per iodogr ams. IEEE Trans. Audio Electroacoust . Vol. AU-15 (J une 1967).
Pgs. 70-73.
2
Filt er Design
Fi lter Requi rements and Specifi cati on . . . . . . . . . . . . . . . . 2-2
IIR Filter Desi gn . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-4
Classical IIR Filt er Design Using Analog Pr ot ot yping . . . . . . . . 2-6
Compar ison of Classical IIR Filt er Types . . . . . . . . . . . . . . . . . . 2-8
FIR Fi lte r Des i gn . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-16
Linear Phase Filt er s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-17
Windowing Met hod . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-18
Mult iband FIR Filt er Design wit h Tr ansit ion Bands . . . . . . . . 2-22
Const r ained Least Squar es FIR Filt er Design . . . . . . . . . . . . . 2-27
Ar bit r ar y-Response Filt er Design . . . . . . . . . . . . . . . . . . . . . . . 2-31
Speci al Topi cs i n IIR Fi lter Desi gn . . . . . . . . . . . . . . . . . . . 2-37
Analog Pr ot ot ype Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-38
Fr equency Tr ansfor mat ion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-38
Filt er Discr et izat ion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-41
Refe re nce s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-45
2 Filter Design
2-2
Filter Requirements and Specification
The Signal Pr ocessing Toolbox pr ovides funct ions t hat suppor t a r ange of filt er
design met hodologies. This chapt er explains how t o apply t he filt er design t ools
t o Infinite Impulse Response (IIR) and Finite Impulse Response (FIR) filt er
design pr oblems.
The goal of filt er design is t o per for m fr equency dependent alt er at ion of a dat a
sequence. A possible r equir ement might be t o r emove noise above 30 Hz fr om
a dat a sequence sampled at 100 Hz. A mor e r igor ous specificat ion might call for
a specific amount of passband r ipple, st opband at t enuat ion, or t r ansit ion
widt h. A ver y pr ecise specificat ion could ask t o achieve t he per for mance goals
wit h t he minimum filt er or der , or it could call for an ar bit r ar y magnit ude
shape, or it might r equir e an FIR filt er .
Filt er design met hods differ pr imar ily in how per for mance is specified. For
loosely specified r equir ement s, as in t he fir st case above, a But t er wor t h IIR
filt er is oft en sufficient . To design a fift h-or der 30 Hz lowpass But t er wor t h
filt er and apply it t o t he dat a in vect or x,
[b,a] = butter(5,30/50);
y = filter(b,a,x);
The second input ar gument t o butter indicat es t he cut off fr equency,
nor malized t o half t he sampling fr equency (t he Nyquist fr equency).
Frequency Normalization in the Signal Processing Toolbox All of t he
filt er design funct ions oper at e wit h nor malized fr equencies, so t hey do not
r equir e t he syst em sampling r at e as an ext r a input ar gument . This t oolbox
uses t he convent ion t hat unit fr equency is t he Nyquist fr equency, defined as
half t he sampling fr equency. The nor malized fr equency, t her efor e, is always in
t he int er val 0 f 1. For a syst em wit h a 1000 Hz sampling fr equency, 300 Hz
is 300/500 = 0.6. To conver t nor malized fr equency t o angular fr equency
ar ound t he unit cir cle, mult iply by . To conver t nor malized fr equency back t o
Her t z, mult iply by half t he sample fr equency.
Filter Requirements and Specification
2-3
Mor e r igor ous filt er r equir ement s t r adit ionally include passband r ipple (Rp, in
decibels), st opband at t enuat ion (Rs, in decibels), and t r ansit ion widt h (WsWp,
in Her t z).
You can design But t er wor t h, Chebyshev t ype I, Chebyshev t ype II, and ellipt ic
filt er s t hat meet t his t ype of per for mance specificat ion. The t oolbox or der
select ion funct ions est imat e t he minimum filt er or der t hat meet s a given set of
r equir ement s.
To meet specificat ions wit h mor e r igid const r aint s like linear phase or
ar bit r ar y filt er shape, use t he FIR and dir ect IIR filt er design r out ines.
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 Filter Design
2-4
IIR Filter Design
The pr imar y advant age of IIR filt er s over FIR filt er s is t hat t hey t ypically meet
a given set of specificat ions wit h a much lower filt er or der t han a cor r esponding
FIR filt er . Alt hough IIR filt er s have nonlinear phase, dat a pr ocessing wit hin
MATLAB is commonly per for med off-line, t hat is, t he ent ir e dat a sequence is
available pr ior t o filt er ing. This allows for a noncausal, zer o-phase filt er ing
appr oach (via t he filtfilt funct ion), which eliminat es t he nonlinear phase
dist or t ion of an IIR filt er .
The classical IIR filt er s, But t er wor t h, Chebyshev t ypes I and II, ellipt ic, and
Bessel, all appr oximat e t he ideal br ickwall filt er in differ ent ways. This
t oolbox pr ovides funct ions t o cr eat e all t hese t ypes of classical IIR filt er s in bot h
t he analog and digit al domains (except Bessel, for which only t he analog case
is suppor t ed), and in lowpass, highpass, bandpass, and bandst op
configur at ions. For most filt er t ypes, you can also find t he lowest filt er or der
t hat fit s a given filt er specificat ion in t er ms of passband and st opband
at t enuat ion, and t r ansit ion widt h(s).
The dir ect filt er design funct ion yulewalk finds a filt er wit h magnit ude
r esponse appr oximat ing a desir ed funct ion. This is one way t o cr eat e a
mult iband bandpass filt er .
You can also use t he par amet r ic modeling or syst em ident ificat ion funct ions t o
design IIR filt er s. These funct ions ar e discussed in t he Par amet r ic Modeling
sect ion of Chapt er 4.
The gener alized But t er wor t h design funct ion maxflat is discussed in t he
sect ion Gener alized But t er wor t h Filt er Design on page 2-14.
The following t able summar izes t he var ious filt er met hods in t he t oolbox and
list s t he funct ions available t o implement t hese met hods.
IIR Filter Design
2-5
* See the System Identification Toolbox for an extensive collection of parametric modeling tools.
Method Description Functions
Analog
Pr ot ot yping
Using t he poles and zer os of
a classical lowpass
pr ot ot ype filt er in t he
cont inuous (Laplace)
domain, obt ain a digit al
filt er t hr ough fr equency
t r ansfor mat ion and filt er
discr et izat ion.
Complet e design funct ions:
besself, butter, cheby1, cheby2, ellip
Or der est imat ion funct ions:
buttord, cheb1ord, cheb2ord, ellipord
Lowpass analog pr ot ot ype funct ions:
besselap, buttap, cheb1ap, cheb2ap,
ellipap
Fr equency t r ansfor mat ion funct ions:
lp2bp, lp2bs, lp2hp, lp2lp
Filt er discr et izat ion funct ions:
bilinear, impinvar
Dir ect Design Design digit al filt er
dir ect ly in t he discr et e
domain by appr oximat ing a
piecewise linear magnit ude
r esponse.
yulewalk
Par amet r ic
Modeling*
Find a digit al filt er t hat
appr oximat es a pr escr ibed
t ime or fr equency domain
r esponse.
Time-domain modeling funct ions:
lpc, prony, stmcb
Fr equency-domain modeling funct ions:
invfreqs, invfreqz
Gener alized
But t er wor t h
Design
Design lowpass
But t er wor t h filt er s wit h
mor e zer os t han poles.
maxflat
2 Filter Design
2-6
Classical IIR Filter Design Using Analog Prototyping
The pr incipal IIR digit al filt er design t echnique t his t oolbox pr ovides is based
on t he conver sion of classical lowpass analog filt er s t o t heir digit al equivalent s.
The following sect ions descr ibe how t o design filt er s and summar ize t he
char act er ist ics of t he suppor t ed filt er t ypes. See Special Topics in IIR Filt er
Design on page 2-37 for det ailed st eps on t he filt er design pr ocess.
Complete Classical IIR Filter Design
You can easily cr eat e a filt er of any or der wit h a lowpass, highpass, bandpass,
or bandst op configur at ion using t he filt er design funct ions.
By default , each of t hese funct ions r et ur ns a lowpass filt er ; you need only
specify t he desir ed cut off fr equency Wn in nor malized fr equency (Nyquist
fr equency = 1 Hz). For a highpass filt er , append t he st r ing 'high' t o t he
funct ions par amet er list . For a bandpass or bandst op filt er , specify Wn as a
t wo-element vect or cont aining t he passband edge fr equencies, appending t he
st r ing 'stop' for t he bandst op configur at ion.
Filter Type Design Function
But t er wor t h [b,a] = butter(n,Wn,options)
[z,p,k] = butter(n,Wn,options)
[A,B,C,D] = butter(n,Wn,options)
Chebyshev t ype 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 t ype II [b,a] = cheby2(n,Rs,Wn,options)
[z,p,k] = cheby2(n,Rs,Wn,options)
[A,B,C,D] = cheby2(n,Rs,Wn,options)
Ellipt ic [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)
Bessel (analog only) [b,a] = besself(n,Wn,options)
[z,p,k] = besself(n,Wn,options)
[A,B,C,D] = besself(n,Wn,options)
IIR Filter Design
2-7
Her e ar e some example digit al filt er s.
[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 design an analog filt er , per haps for simulat ion, use a t r ailing 's' and
specify cut off fr equencies in r adians/second.
[b,a] = butter(5,.4,'s'); % analog Butterworth filter
All filt er design funct ions r et ur n a filt er in t he t r ansfer funct ion,
zer o-pole-gain, or st at e-space linear syst em model r epr esent at ion, depending
on how many out put ar gument s ar e pr esent .
NOTE All classical IIR lowpass filt er s ar e ill-condit ioned for ext r emely low
cut -off fr equencies. Ther efor e, inst ead of designing a lowpass IIR filt er wit h a
ver y nar r ow passband, it can be bet t er t o design a wider passband and
decimat e t he input signal.
Designing IIR Filters to Frequency Domain Specifications
This t oolbox pr ovides or der select ion funct ions t hat calculat e t he minimum
filt er or der t hat meet s a given set of r equir ement s.
These ar e useful in conjunct ion wit h t he filt er design funct ions. Suppose you
want a bandpass filt er wit h a passband fr om 1000 t o 2000 Hz, st opbands
st ar t ing 500 Hz away on eit her side, a 10 kHz sampling fr equency, at most 1 dB
Filter Type Order Estimation Function
But t er wor t h [n,Wn] = buttord(Wp,Ws,Rp,Rs)
Chebyshev t ype I [n,Wn] = cheb1ord(Wp, Ws, Rp, Rs)
Chebyshev t ype II [n,Wn] = cheb2ord(Wp, Ws, Rp, Rs)
Ellipt ic [n,Wn] = ellipord(Wp, Ws, Rp, Rs)
2 Filter Design
2-8
of passband r ipple, and at least 60 dB of st opband at t enuat ion. To meet t hese
specificat ions wit h t he butter funct ion.
[n,Wn] = buttord([1000 2000]/5000,[500 2500]/5000,1,60)
n =
12
Wn =
0.1951 0.4080
[b,a] = butter(n,Wn);
An ellipt ic filt er t hat meet s t he same r equir ement s is given 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 funct ions also wor k wit h t he ot her st andar d band configur at ions, as well
as for analog filt er s; see Chapt er 6 for det ails.
Comparison of Classical IIR Filter Types
The t oolbox pr ovides five differ ent t ypes of classical IIR filt er s, each opt imal in
some way. This sect ion shows t he basic analog pr ot ot ype for m for each and
summar izes major char act er ist ics.
Butterworth Filter
The But t er wor t h filt er pr ovides t he best Taylor Ser ies appr oximat ion t o t he
ideal lowpass filt er r esponse at = 0 and = ; for any or der N, t he magnit ude
squar ed r esponse has 2N1 zer o der ivat ives at t hese locat ions (maximally flat
IIR Filter Design
2-9
at = 0 and = ). Response is monot onic over all, decr easing smoot hly fr om
= 0 t o = . | H(j)| = sqrt(1/2) at = 1.
Chebyshev Type I Filter
The Chebyshev t ype I filt er minimizes t he absolut e differ ence bet ween t he
ideal and act ual fr equency r esponse over t he ent ir e passband by incor por at ing
an equal r ipple of Rp dB in t he passband. St opband r esponse is maximally flat .
The t r ansit ion fr om passband t o st opband is mor e r apid t han for t he
But t er wor t h filt er . | H(j)| = 10
-Rp/20
at = 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
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 Filter Design
2-10
Chebyshev Type II Filter
The Chebyshev t ype II filt er minimizes t he absolut e differ ence bet ween t he
ideal and act ual fr equency r esponse over t he ent ir e st opband, by incor por at ing
an equal r ipple of Rs dB in t he st opband. Passband r esponse is maximally flat .
The st opband does not appr oach zer o as quickly as t he t ype I filt er (and does
not appr oach zer o at all for even-valued n). The absence of r ipple in t he
passband, however , is oft en an impor t ant advant age. | H(j)| = 10
-Rs/20
at
= 1.
Elliptic Filter
Ellipt ic filt er s ar e equir ipple in bot h t he passband and st opband. They
gener ally meet filt er r equir ement s wit h t he lowest or der of any suppor t ed filt er
t ype. Given a filt er or der n, passband r ipple Rp in decibels, and st opband r ipple
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 Filter Design
2-11
Rs in decibels, ellipt ic filt er s minimize t r ansit ion widt h. | H(j)| = 10
-Rp/20
at
= 1.
Bessel Filter
Analog Bessel lowpass filt er s have maximally flat gr oup delay at zer o
fr equency and r et ain near ly const ant gr oup delay acr oss t he ent ir e passband.
Filt er ed signals t her efor e maint ain t heir waveshapes in t he passband
fr equency r ange. Fr equency mapped and digit al Bessel filt er s, however , do not
have t his maximally flat pr oper t y; t his t oolbox suppor t s only t he analog case
for t he complet e Bessel filt er design funct ion.
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 Filter Design
2-12
Bessel filt er s gener ally r equir e a higher filt er or der t han ot her filt er s for
sat isfact or y st opband at t enuat ion. | H(j)| < at = 1 and decr eases as n
incr eases.
NOTE The lowpass filt er s shown above wer e cr eat ed wit h t he analog
pr ot ot ype funct ions besselap, buttap, cheb1ap, cheb2ap, and ellipap. These
funct ions find t he zer os, poles, and gain of an or der n analog filt er of t he
appr opr iat e t ype wit h cut off fr equency of 1 r ad/sec. The complet e filt er design
funct ions (besself, butter, cheby1, cheby2, and ellip) call t he pr ot ot yping
funct ions as a fir st st ep in t he design pr ocess. See Special Topics in IIR Filt er
Design on page 2-37 for det ails.
To cr eat e similar plot s, use n = 5 and, as needed, Rp = 0.5 and Rs = 20. For
example, t o cr eat e t he ellipt ic filt er plot :
[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
1 2
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 Filter Design
2-13
Direct IIR Filter Design
This t oolbox uses t he t er m direct methods t o descr ibe t echniques for IIR design
t hat find a filt er based on specificat ions in t he discr et e domain. Unlike t he
analog pr ot ot yping met hod, dir ect design met hods ar e not const r ained t o t he
st andar d lowpass, highpass, bandpass, or bandst op configur at ions. Rat her ,
t hese funct ions design filt er s wit h an ar bit r ar y, per haps mult iband, fr equency
r esponse. This sect ion discusses t he yulewalk funct ion, which is int ended
specifically for filt er design; Par amet r ic Modeling in Chapt er 4 discusses
ot her met hods t hat may also be consider ed dir ect , such as Pr onys met hod,
Linear Pr edict ion, t he St eiglit z-McBr ide met hod, and inver se fr equency
design.
yulewalk designs r ecur sive IIR digit al filt er s by fit t ing a specified fr equency
r esponse. yulewalks name r eflect s it s met hod for finding t he filt er s
denominat or coefficient s: it finds t he inver se FFT of t he ideal desir ed power
spect r um and solves t he modified Yule-Walker equat ions using t he r esult ing
aut ocor r elat ion funct ion samples. The st at ement
[b,a] = yulewalk(n,f,m)
r et ur ns r ow vect or s b and a cont aining t he n+1 numer at or and denominat or
coefficient s of t he or der n IIR filt er whose fr equency-magnit ude char act er ist ics
appr oximat e t hose given in vect or s f and m. f is a vect or of fr equency point s
r anging fr om 0 t o 1, wher e 1 r epr esent s t he Nyquist fr equency. m is a vect or
cont aining t he desir ed magnit ude r esponse at t he point s in f. f and m can
descr ibe any piecewise linear shape magnit ude r esponse, including a
mult iband r esponse. The FIR count er par t of t his funct ion is fir2, which also
designs a filt er based on an ar bit r ar y piecewise linear magnit ude r esponse. See
FIR Filt er Design on page 2-16 for det ails.
Not e t hat yulewalk does not accept phase infor mat ion, and no st at ement s ar e
made about t he opt imalit y of t he r esult ing filt er .
2 Filter Design
2-14
Design a mult iband filt er wit h yulewalk, and plot t he desir ed and act ual
fr equency r esponse.
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))
Generalized Butterworth Filter Design
The t oolbox funct ion maxflat enables you t o design gener alized But t er wor t h
filt er s, t hat is, But t er wor t h filt er s wit h differ ing number s of zer os and poles.
This is desir able in some implement at ions wher e poles ar e mor e expensive
comput at ionally t han zer os. maxflat is just like t he butter funct ion, except
t hat it you can specify two or der s (one for t he numer at or and one for t he
denominat or ) inst ead of just one. These filt er s ar e maximally flat. This means
t hat t he r esult ing filt er is opt imal for any numer at or and denominat or or der s,
wit h t he maximum number of der ivat ives at 0 and t he Nyquist fr equency =
bot h set t o 0.
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
IIR Filter Design
2-15
For example, when t he t wo or der s ar e t he same, maxflat is t he 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
[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 is mor e ver sat ile, because you can design a filt er wit h mor e
zer os t han poles.
[b,a] = maxflat(3,1,0.25)
b =
0.0950 0.2849 0.2849 0.0950
a =
1.0000 -0.2402
The t hir d input t o maxflat is t he half-power frequency, a fr equency bet ween
0 and 1 wit h a desir ed magnit ude r esponse of .
You can also design linear phase filt er s t hat have t he maximally flat pr oper t y
using t he 'sym' opt ion.
maxflat(4,'sym',0.3)
ans =
0.0331 0.2500 0.4337 0.2500 0.0331
For complet e det ails of t he maxflat algor it hm, see Selesnick and Bur r us [2].
1 2
2 Filter Design
2-16
FIR Filter Design
Digit al filt er s wit h finit e-dur at ion impulse r esponse (all-zer o, or FIR filt er s)
have bot h advant ages and disadvant ages compar ed t o infinit e-dur at ion
impulse r esponse (IIR) filt er s.
FIR filt er s have t he following pr imar y advant ages:
They can have exact ly linear phase.
They ar e always st able.
The design met hods ar e gener ally linear .
They can be r ealized efficient ly in har dwar e.
The filt er st ar t up t r ansient s have finit e dur at ion.
The pr imar y disadvant age of FIR filt er s is t hat t hey oft en r equir e a much
higher filt er or der t han IIR filt er s t o achieve a given level of per for mance.
Cor r espondingly, t he delay of t hese filt er s is oft en much gr eat er t han for an
equal per for mance IIR filt er .
Method Description Functions
Windowing Apply window t o t r uncat ed
inver se Four ier t r ansfor m of
desir ed br ickwall filt er
fir1,fir2,kaiserord
Mult iband
wit h
Tr ansit ion
Bands
Equir ipple or least squar es
appr oach over sub-bands of t he
fr equency r ange
firls,remez,remezord
Const r ained
Least
Squar es
Minimize squar ed int egr al
er r or over ent ir e fr equency
r ange subject t o maximum
er r or const r aint s
fircls,fircls1
FIR Filter Design
2-17
Linear Phase Filters
Except for cremez, all of t he FIR filt er design funct ions design linear phase
filt er s only. The filt er coefficient s, or t aps, of such filt er s obey eit her an even
or odd symmet r y r elat ion. Depending on t his symmet r y, and on whet her t he
or der n of t he filt er is even or odd, a linear phase filt er (st or ed in lengt h n+1
vect or b) has cer t ain inher ent r est r ict ions on it s fr equency r esponse.
The phase delay and gr oup delay of linear phase FIR filt er s ar e equal and
const ant over t he fr equency band. For an or der n linear phase FIR filt er , t he
gr oup delay is n/2, and t he filt er ed signal is simply delayed by n/2 t ime st eps
(and t he magnit ude of it s Four ier t r ansfor m is scaled by t he filt er s magnit ude
r esponse). This pr oper t y pr eser ves t he wave shape of signals in t he passband,
t hat is, t her e is no phase dist or t ion.
The funct ions fir1, fir2, firls, remez, fircls, fircls1, and firrcos all
design t ype I and II linear phase FIR filt er s by default . Bot h firls and remez
design t ype III and IV linear phase FIR filt er s given a 'hilbert' or
'differentiator' flag. cremez can design any t ype of linear phase filt er , and
nonlinear phase filt er s as well.
Ar bit r ar y
Response
Ar bit r ar y r esponses, including
nonlinear phase and complex
filt er s
cremez
Raised
Cosine
Lowpass r esponse wit h
smoot h, sinusoidal t r ansit ion
firrcos
Method Description Functions
Linear
Phase
Filter Type
Filter
Order n Symmetry of Coefficients
Response H(f),
f = 0
Response H(f),
f = 1 (Nyquist)
Type I Even even: No r est r ict ion No r est r ict ion
Type II Odd No r est r ict ion H(1) = 0
Type III Even odd: H(0) = 0 H(1) = 0
Type IV Odd H(0) = 0 No r est r ict ion
b k ( ) b n 2 k + ( ) k 1 = n 1 + , , , =
b k ( ) b n 2 k + ( ) k 1 = n 1 + , , , =
2 Filter Design
2-18
NOTE Because t he fr equency r esponse of a t ype II filt er is zer o at t he Nyquist
r at e (high fr equency), fir1 does not design t ype II highpass and bandst op
filt er s. For odd-valued n in t hese cases, fir1 adds 1 t o t he or der and r et ur ns a
t ype I filt er.
Windowing Method
Consider t he ideal, or br ick-wall, digit al lowpass filt er wit h a cut off fr equency
of
0
r ad/sec. This filt er has magnit ude 1 at all fr equencies wit h magnit ude less
t han
0
, and magnit ude 0 at fr equencies wit h magnit ude bet ween
0
and . It s
impulse r esponse sequence h(n) is
This filt er is not implement able since it s impulse r esponse is infinit e and
noncausal. To cr eat e a finit e-dur at ion impulse r esponse, t r uncat e it by
applying a window. By r et aining t he cent r al sect ion of impulse r esponse in t his
t r uncat ion, you obt ain a linear phase FIR filt er . For example, a lengt h 51 filt er
wit h a lowpass cut off fr equency
0
of 0.4 r ad/sec is
b = 0.4*sinc(0.4*(25:25));
The window applied her e is a simple r ect angular or boxcar window. By
Par sevals t heor em, t his is t he lengt h 51 filt er t hat best appr oximat es t he ideal
h n ( )
1
2
------ H ( )e
j n
d

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

------ -sinc

------ -n ( ) = = =
FIR Filter Design
2-19
lowpass filt er , in t he int egr at ed least squar es sense. To view it s fr equency
r esponse:
[H,w] = freqz(b,1,512,2);
plot(w,abs(H)), grid
Not e t he r inging and r ipples in t he r esponse, especially near t he band edge.
This Gibbs effect does not vanish as t he filt er lengt h incr eases, but a
nonr ect angular window r educes it s magnit ude. Mult iplicat ion by a window in
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
Truncated Sinc Lowpass FIR Filter
Normalized Frequency (Nyquist == 1)
M
a
g
n
i
t
u
d
e

R
e
s
p
o
n
s
e
2 Filter Design
2-20
t he t ime domain causes a convolut ion or smoot hing in t he fr equency domain.
Apply a lengt h 51 Hamming window t o t he filt er .
b = b.*hamming(51)';
[H,w] = freqz(b,1,512,2);
plot(w,abs(H)), grid
As you can see, t his gr eat ly r educes t he r inging. This impr ovement is at t he
expense of t r ansit ion widt h (t he windowed ver sion t akes longer t o r amp fr om
passband t o st opband) and opt imalit y (t he windowed ver sion does not
minimize t he int egr at ed squar ed er r or ).
The funct ions fir1 and fir2 ar e based on t his windowing pr ocess. Given a
filt er or der and descr ipt ion of an ideal desir ed filt er , t hese funct ions r et ur n a
windowed inver se Four ier t r ansfor m of t hat ideal filt er . Bot h use a Hamming
window by default , but t hey accept any window funct ion. See t he Windows
sect ion of Chapt er 4 for an over view of windows and t heir pr oper t ies.
Standard Band FIR Filter Design: fir1
fir1 implement s t he classical met hod of windowed linear phase FIR digit al
filt er design. It r esembles t he IIR filt er design funct ions in t hat it is for mulat ed
t o design filt er s in st andar d band configur at ions: lowpass, bandpass, highpass,
and bandst op.
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
Normalized Frequency (Nyquist == 1)
M
a
g
n
i
t
u
d
e

R
e
s
p
o
n
s
e
Hamming Windowed Truncated SINC LP FIR Filter
FIR Filter Design
2-21
The st at ement s
n = 50;
Wn = 0.4;
b = fir1(n,Wn);
cr eat e r ow vect or b cont aining t he coefficient s of t he or der n
Hamming-windowed filt er . This is a lowpass, linear phase FIR filt er wit h cut off
fr equency Wn. Wn is a number bet ween 0 and 1, wher e 1 cor r esponds t o t he
Nyquist fr equency, half t he sampling fr equency. (Unlike ot her met hods, her e
Wn cor r esponds t o t he 6 dB point .) For a highpass filt er , simply append t he
st r ing 'high' t o t he funct ions par amet er list . For a bandpass or bandst op
filt er , specify Wn as a t wo-element vect or cont aining t he passband edge
fr equencies; append t he st r ing 'stop' for t he bandst op configur at ion.
b = fir1(n,Wn,window) uses t he window specified in column vect or window for
t he design. The vect or window must be n+1 element s long. If you do not specify
a window, fir1 applies a Hamming window.
Kaiser Window Order Estimation. The kaiserord funct ion est imat es t he filt er
or der , cut off fr equency, and Kaiser window bet a par amet er needed t o meet a
given set of specificat ions. Given a vect or of fr equency band edges and a
cor r esponding vect or of magnit udes, as well as maximum allowable r ipple,
kaiserord r et ur ns appr opr iat e input par amet er s for t he fir1 funct ion. For
det ails on kaiserord, see t he r efer ence descr ipt ion in Chapt er 6.
Multiband FIR Filter Design: fir2
The funct ion fir2 also designs windowed FIR filt er s, but wit h an ar bit r ar ily
shaped piecewise linear fr equency r esponse. This is in cont r ast t o fir1, which
only designs filt er s in st andar d lowpass, highpass, bandpass, and bandst op
configur at ions.
The commands
n = 50;
f = [0 .4 .5 1];
m = [1 1 0 0];
b = fir2(n,f,m);
r et ur n r ow vect or b cont aining t he n+1 coefficient s of t he or der n FIR filt er
whose fr equency-magnit ude char act er ist ics mat ch t hose given by vect or s f and
m. f is a vect or of fr equency point s r anging fr om 0 t o 1, wher e 1 r epr esent s t he
2 Filter Design
2-22
Nyquist fr equency. m is a vect or cont aining t he desir ed magnit ude r esponse at
t he point s specified in f. (The IIR count er par t of t his funct ion is yulewalk,
which also designs filt er s based on ar bit r ar y piecewise linear magnit ude
r esponses. See IIR Filt er Design for det ails.)
Multiband FIR Filter Design with Transition Bands
The firls and remez funct ions pr ovide a mor e gener al means of specifying t he
ideal desir ed filt er t han t he fir1 and fir2 funct ions. These funct ions design
Hilber t t r ansfor mer s, differ ent iat or s, and ot her filt er s wit h odd symmet r ic
coefficient s (t ype III and t ype IV linear phase). They also let you include
t r ansit ion or dont car e r egions in which t he er r or is not minimized, and
per for m band dependent weight ing of t he minimizat ion.
firls is an ext ension of t he fir1 and fir2 funct ions in t hat it minimizes t he
int egr al of t he squar e of t he er r or bet ween t he desir ed fr equency r esponse and
t he act ual fr equency r esponse.
remez implement s t he Par ks-McClellan algor it hm, which uses t he Remez
exchange algor it hm and Chebyshev appr oximat ion t heor y t o design filt er s wit h
opt imal fit s bet ween t he desir ed and act ual fr equency r esponses. The filt er s ar e
opt imal in t he sense t hat t hey minimize t he maximum er r or bet ween t he
desir ed fr equency r esponse and t he act ual fr equency r esponse; t hey ar e
somet imes called minimax filt er s. Filt er s designed in t his way exhibit an
equir ipple behavior in t heir fr equency r esponse, and hence ar e also known as
equiripple filt er s. The Par ks-McClellan FIR filt er design algor it hm is per haps
t he most popular and widely used FIR filt er design met hodology.
The synt ax for firls and remez is t he same; t he only differ ence is t heir
minimizat ion schemes. The next example shows how filt er s designed wit h
firls and remez r eflect t hese differ ent schemes.
Basic Configurations
The default mode of oper at ion of firls and remez is t o design t ype I or t ype II
linear phase filt er s, depending on whet her t he or der you desir e is even or odd,
r espect ively. A lowpass example wit h appr oximat e amplit ude 1 fr om 0 t o 0.4
Hz, and appr oximat e amplit ude 0 fr om 0.5 t o 1.0 Hz is
n = 20; % filter order
f = [0 .4 .5 1]; % frequency band edges
a = [1 1 0 0]; % desired amplitudes
b = remez(n,f,a);
FIR Filter Design
2-23
Fr om 0.4 t o 0.5 Hz, remez per for ms no er r or minimizat ion; t his is a t r ansit ion
band or dont car e r egion. A t r ansit ion band minimizes t he er r or mor e in t he
bands t hat you do car e about , at t he expense of a slower t r ansit ion r at e. In t his
way, t hese t ypes of filt er s have an inher ent t r ade-off similar t o FIR design by
windowing.
To compar e least squar es t o equir ipple filt er design, use firls t o cr eat e a
similar filt er .
bb = firls(n,f,a);
and compar e t heir fr equency r esponses:
[H,w]=freqz(b);
[HH,w]=freqz(bb);
plot(w/pi,abs(H),w/pi,abs(HH),'--'), grid
You can see t hat t he filt er designed wit h remez exhibit s equir ipple behavior .
Also not e t hat t he firls filt er has a bet t er r esponse over most of t he passband
and st opband, but at t he band edges (f = 0.4 and f = 0.5), t he r esponse is
fur t her away fr om t he ideal t han t he remez filt er . This shows t hat t he remez
filt er s maximum er r or over t he pass- and st opbands is smaller and, in fact , it
is t he smallest possible for t his band edge configur at ion and filt er lengt h.
Think of fr equency bands as lines over shor t fr equency int er vals. remez and
firls use t his scheme t o r epr esent any piecewise linear desir ed funct ion wit h
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 Filter Design
2-24
any t r ansit ion bands. firls and remez design lowpass, highpass, bandpass,
and bandst op filt er s; a bandpass example is
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
Technically, t hese f and a vect or s define five bands:
Two st opbands, fr om 0.0 t o 0.3 and fr om 0.8 t o 1.0
A passband fr om 0.4 t o 0.7
Two t r ansit ion bands, fr om 0.3 t o 0.4 and fr om 0.7 t o 0.8
Example highpass and bandst op filt er s ar e
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 example mult iband bandpass filt er is
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];
Anot her possibilit y is a filt er t hat has as a t r ansit ion r egion t he line connect ing
t he passband wit h t he st opband; t his can help cont r ol r unaway magnit ude
r esponse in wide t r ansit ion r egions:
f = [0 0.4 0.42 0.48 0.5 1];
a = [1 1 0.8 0.2 0 0]; % passband,linear transition,stopband
The Weight Vector
Bot h firls and remez allow you t o place mor e or less emphasis on minimizing
t he er r or in cer t ain fr equency bands r elat ive t o ot her s. To do t his, specify a
weight vect or following t he fr equency and amplit ude vect or s. An example
FIR Filter Design
2-25
lowpass equir ipple filt er wit h 10 t imes less r ipple in t he st opband t han t he
passband is
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 legal weight vect or is always half t he lengt h of t he f and a vect or s; t her e must
be exact ly one weight per band.
Anti-Symmetric Filters / Hilbert Transformers
When called wit h a t r ailing 'h' or 'Hilbert' opt ion, remez and firls design
FIR filt er s wit h odd symmet r y, t hat is, t ype III (for even or der ) or t ype IV (for
odd or der ) linear phase filt er s. An ideal Hilber t t r ansfor mer has t his
ant i-symmet r y pr oper t y and an amplit ude of 1 acr oss t he ent ir e fr equency
r ange. Tr y t he following appr oximat e Hilber t t r ansfor mer s:
b = remez(21,[0.05 1],[1 1],'h'); % highpass Hilbert
bb = remez(20,[0.05 0.95],[1 1],'h'); % bandpass Hilbert
You can find t he delayed Hilber t t r ansfor m of a signal x by passing it t hr ough
t hese filt er s:
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
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
2 Filter Design
2-26
The analyt ic signal cor r esponding t o x is t he complex signal t hat has x as it s
r eal par t and t he Hilber t t r ansfor m of x as it s imaginar y par t . For t his FIR
met hod (an alt er nat ive t o t he hilbert funct ion), you must delay x by half t he
filt er or der t o cr eat e t he analyt ic signal.
xd = [zeros(10,1); x(1:length(x)10)]; % delay 10 samples
xa = xd + j*xh; % analytic signal
This met hod does not wor k dir ect ly for filt er s of odd or der , which r equir e a
nonint eger delay. In t his case, t he hilbert funct ion, descr ibed in t he
Specialized Tr ansfor ms sect ion in Chapt er 4, est imat es t he analyt ic signal.
Alt er nat ively, use t he resample funct ion t o delay t he signal by a nonint eger
number of samples.
Differentiators
Differ ent iat ion of a signal in t he t ime domain is equivalent t o mult iplicat ion of
t he signals Four ier t r ansfor m by an imaginar y r amp funct ion. That is, t o
differ ent iat e a signal, pass it t hr ough a filt er t hat has a r esponse H(w) = jw.
Appr oximat e t he ideal differ ent iat or (wit h a delay) using remez or firls wit h
a 'd' or 'differentiator' opt ion.
b = remez(21,[0 1],[0 pi*Fs],'d');
To obt ain t he cor r ect der ivat ive, scale by pi*Fs r ad/sec, wher e Fs is t he
sampling fr equency in Her t z. For a t ype III filt er , t he differ ent iat ion band
should st op shor t of t he Nyquist fr equency, and t he amplit ude vect or must
r eflect t hat change t o ensur e t he cor r ect slope.
bb = remez(20,[0 0.9],[0 0.9*pi*Fs],'d');
In t he 'd' mode, remez weight s t he er r or by 1/w in nonzer o amplit ude bands t o
minimize t he maximum relative er r or . firls weight s t he er r or by (1/w)
2
in
nonzer o amplit ude bands in t he 'd' mode.
FIR Filter Design
2-27
The magnit ude r esponse plot s for t he differ ent iat or s shown above ar e
Constrained Least Squares FIR Filter Design
The Const r ained Least Squar es (CLS) FIR filt er design funct ions implement a
t echnique t hat enables you t o design FIR filt er s wit hout explicit ly defining t he
t r ansit ion bands for t he magnit ude r esponse. The abilit y t o omit t he
specificat ion of t r ansit ion bands is useful in sever al sit uat ions. For example, it
may not be clear wher e a r igidly defined t r ansit ion band should appear if noise
and signal infor mat ion appear t oget her in t he same fr equency band. Similar ly,
it may make sense t o omit t he specificat ion of t r ansit ion bands if t hey appear
only t o cont r ol t he r esult s of Gibbs phenomena t hat appear in t he filt er s
r esponse. See Selesnick, Lang, and Bur r us [2] for discussion of t his met hod.
Inst ead of defining passbands, st opbands, and t r ansit ion r egions, t he CLS
met hod accept s a cut off fr equency (for t he highpass, lowpass, bandpass, or
bandst op cases), or passband and st opband edges (for mult iband cases), for t he
desir ed r esponse. In t his way, t he CLS met hod defines t r ansit ion r egions
implicit ly, r at her t han explicit ly.
The key feat ur e of t he CLS met hod is t hat it enables you t o define upper and
lower t hr esholds t hat cont ain t he maximum allowable r ipple in t he magnit ude
r esponse. Given t his const r aint , t he t echnique applies t he least squar e er r or
minimizat ion t echnique over t he fr equency r ange of t he filt er s r esponse,
inst ead of over specific bands. The er r or minimizat ion includes any ar eas of
discont inuit y in t he ideal, br ick wall r esponse. An addit ional benefit is t hat
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)
2 Filter Design
2-28
t he t echnique enables you t o specify ar bit r ar ily small peaks r esult ing fr om
Gibbs phenomena.
Ther e ar e t wo t oolbox funct ions t hat implement t his design t echnique.
For det ails on t he calling synt ax for t hese funct ions, see t heir r efer ence
descr ipt ions in Chapt er 6.
Basic Lowpass and Highpass CLS Filter Design
The most basic of t he CLS design funct ions, fircls1, uses t his t echnique t o
design lowpass and highpass FIR filt er s. As an example, consider designing a
filt er wit h or der 61 impulse r esponse and cut off fr equency of 0.3 (nor malized).
Fur t her , define t he upper and lower bounds t hat const r ain t he design pr ocess
as:
Maximum passband deviat ion fr om 1 (passband r ipple) of 0.02.
Maximum st opband deviat ion fr om 0 (st opband r ipple) of 0.008.
Description Function
Const r ained least squar e mult iband FIR filt er design. fircls
Const r ained least squar e filt er design for lowpass and
highpass linear phase filt er s
fircls1
0
ds = 0.008
1
dp = 0.02
FIR Filter Design
2-29
To appr oach t his design pr oblem using fircls1
n = 61;
wo = 0.3;
dp = 0.02;
ds = 0.008;
h = fircls1(n,wo,dp,ds,'plot');
Multiband CLS Filter Design
fircls uses t he same t echnique t o design FIR filt er s wit h a desir ed piecewise
const ant magnit ude r esponse. In t his case, you can specify a vect or of band
edges and a cor r esponding vect or of band amplit udes. In addit ion, you can
specify t he maximum amount of r ipple for each band.
For example, assume t he specificat ions for a filt er call for :
Fr om 0 t o 0.3 (nor malized): amplit ude 0, upper bound 0.005, lower
bound -0.005
Fr om 0.3 t o 0.5: amplit ude 0.5, upper bound 0.51, lower bound 0.49
Fr om 0.5 t o 0.7: amplit ude 0, upper bound 0.03, lower bound -0.03
Fr om 0.7 t o 0.9: amplit ude 1, upper bound 1.02, lower bound 0.98
Fr om 0.9 t o 1: amplit ude 0, upper bound 0.05, lower bound -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
2 Filter Design
2-30
Design a CLS filt er wit h impulse r esponse or der 129 t hat meet s t hese
specificat ions.
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];
lo = [0.005 0.49 0.03 0.98 0.05];
h = fircls(n,f,a,up,lo,'plot');
Weighted CLS Filter Design
Weight ed CLS filt er design let s you design lowpass or highpass FIR filt er s wit h
r elat ive weight ing of t he er r or minimizat ion in each band. The fircls1
funct ion enables you t o specify t he passband and st opband edges for t he least
squar es weight ing funct ion, as well as a const ant k t hat specifies t he r at io of
t he st opband t o passband weight ing.
For example, consider specificat ions t hat call for an FIR filt er wit h impulse
r esponse or der of 55 and cut off fr equency of 0.3 (nor malized). Also assume
maximum allowable passband r ipple of 0.02 and maximum allowable st opband
r ipple of 0.004. In addit ion, add weight ing r equir ement s:
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
FIR Filter Design
2-31
Passband edge for t he weight funct ion of 0.28 (nor malized)
St opband edge for t he weight funct ion of 0.32
Weight er r or minimizat ion 10 t imes as much in t he st opband as in t he
passband
To appr oach t his using fircls1:
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 filt er design funct ion pr ovides a t ool for designing FIR filt er s wit h
ar bit r ar y complex r esponses. It differ s fr om t he ot her filt er design funct ions in
how t he fr equency r esponse of t he filt er is specified: it accept s t he name of a
funct ion which r et ur ns t he filt er r esponse calculat ed over a gr id of fr equencies.
This capabilit y makes cremez a highly ver sat ile and power ful t echnique for
filt er design.
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
2 Filter Design
2-32
This design t echnique may be used t o pr oduce nonlinear -phase FIR filt er s,
asymmet r ic fr equency-r esponse filt er s (wit h complex coefficient s), or mor e
symmet r ic filt er s wit h cust om fr equency r esponses.
The design algor it hm opt imizes t he Chebyshev (or minimax) er r or using an
ext ended Remez-exchange algor it hm for an init ial est imat e. If t his exchange
met hod fails t o obt ain t he opt imal filt er , t he algor it hm swit ches t o an
ascent -descent algor it hm t hat t akes over t o finish t he conver gence t o t he
opt imal solut ion.
For det ails on t he calling synt ax for cremez, see t he r efer ence descr ipt ion in
Chapt er 6.
Multiband Filter Design
Consider a mult iband filt er wit h t he following special fr equency-domain
char act er ist ics:
A linear -phase mult iband filt er may be designed using t he pr edefined
fr equency-r esponse funct ion multiband, as follows.
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 t he specific case of a mult iband filt er , we can use a shor t hand filt er design
not at ion similar t o t he synt ax 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 wit h remez, a vect or of band edges is passed t o cremez. This vect or defines
t he fr equency bands over which opt imizat ion is per for med; not e t hat t her e ar e
t wo t r ansit ion bands, fr om -0.5 t o -0.4 and fr om 0.3 t o 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
FIR Filter Design
2-33
In eit her case, t he fr equency r esponse is obt ained and plot t ed using linear
scale.
[h,w] = freqz(b,1,512,whole);
plot(w/pi1,fftshift(abs(h)));
Not e t hat t he fr equency r esponse has been calculat ed over t he ent ir e
nor malized fr equency r ange [-1 +1] by passing t he opt ion 'whole' t o freqz. In
or der t o plot t he negat ive fr equency infor mat ion in a nat ur al way, t he r esponse
has been wr apped, just as FFT dat a is, using fftshift.
-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
2 Filter Design
2-34
The filt er r esponse for t his mult iband filt er is complex, which is expect ed
because of t he asymmet r y in t he fr equency domain. The filt er r esponse is
Filter Design with Reduced Delay
Consider t he design of a 62-t ap lowpass filt er wit h a half-Nyquist cut off. If we
specify a negat ive offset value t o t he lowpass filt er design funct ion, t he gr oup
delay offset for t he design is significant ly less t han t hat obt ained for a st andar d
linear -phase design. This filt er design may be comput ed as follows.
b = cremez(61, [0 0.5 0.55 1], {'lowpass', 16});
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
FIR Filter Design
2-35
The r esult ing magnit ude r esponse is
[h,w] = freqz(b,1,512,'whole');
plot(w/pi1,fftshift(abs(h)));
The gr oup delay of t he filt er r eveals t hat t he offset has been r educed fr om
N/2=30.5 t o N/216=14.5. Now, however , t he gr oup delay is no longer flat in
t he passband r egion (plot t ed over t he nor malized fr equency r ange 0 t o 0.5 for
clar it y).
-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
)
2 Filter Design
2-36
If we compar e t his nonlinear -phase filt er t o a linear -phase filt er t hat has
exact ly 14.5 samples of gr oup delay, t he r esult ing filt er is of or der 2*14.5 or 29.
Using b = cremez(29,[0 0.5 0.55 1],'lowpass'), t he passband and
st opband r ipple is much gr eat er for t he or der 29 filt er . These compar isons can
assist you in deciding which filt er is mor e appr opr iat e for a specific applicat ion.
Special Topics in IIR Filter Design
2-37
Special Topics in IIR Filter Design
The classic IIR filt er design t echnique finds an analog lowpass filt er wit h cut off
fr equency of 1, t r anslat es t his pr ot ot ype filt er t o t he desir ed band
configur at ion, t hen t r ansfor ms t he filt er t o t he digit al domain. The t oolbox
pr ovides funct ions for each st ep of t his pr ocess.
The butter, cheby1, cheby2, and ellip funct ions ar e sufficient for many
design pr oblems, and t he lower level funct ions ar e gener ally not needed. But if
you do have an applicat ion wher e you need t o t r ansfor m t he band edges of an
analog filt er , or discr et ize a r at ional t r ansfer funct ion, t his sect ion descr ibes
t ools t o 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
2 Filter Design
2-38
Analog Prototype Design
This t oolbox pr ovides a number of funct ions t o cr eat e lowpass analog pr ot ot ype
filt er s wit h cut off fr equency of 1, t he fir st st ep in t he classical appr oach t o IIR
filt er design. The t able below summar izes t he analog pr ot ot ype design
funct ions for each suppor t ed filt er t ype; plot s for each t ype ar e shown in t he
IIR Filt er Design sect ion above.
Frequency Transformation
The second st ep in t he analog pr ot ot yping design t echnique is t he fr equency
t r ansfor mat ion of a lowpass pr ot ot ype. The t oolbox pr ovides a set of funct ions
t o t r ansfor m analog lowpass pr ot ot ypes (wit h cut off fr equency of 1 r ad/sec) int o
bandpass, highpass, bandst op, and lowpass filt er s of t he desir ed cut off
fr equency.
Filter Type Analog Prototype Function
Bessel [z,p,k] = besselap(n)
But t er wor t h [z,p,k] = buttap(n)
Chebyshev t ype I [z,p,k] = cheb1ap(n,Rp)
Chebyshev t ype II [z,p,k] = cheb2ap(n,Rs)
Ellipt ic [z,p,k] = ellipap(n,Rp,Rs)
Special Topics in IIR Filter Design
2-39
As shown, all of t he fr equency t r ansfor mat ion funct ions can accept t wo linear
syst em models: t r ansfer funct ion and st at e-space for m. For t he bandpass and
bandst op cases
and
wher e
1
is t he lower band edge and
2
is t he upper band edge.
The fr equency t r ansfor mat ion funct ions per for m fr equency var iable
subst it ut ion. In t he case of lp2bp and lp2bs, t his is a second-or der
subst it ut ion, so t he out put filt er is t wice t he or der of t he input . For lp2lp and
lp2hp, t he out put filt er is t he same or der as t he input .
Freq. Transformation Transformation Function
Lowpass t o lowpass [numt,dent] = lp2lp(num,den,Wo)
[At,Bt,Ct,Dt] = lp2lp(A,B,C,D,Wo)
Lowpass t o highpass [numt,dent] = lp2hp(num,den,Wo)
[At,Bt,Ct,Dt] = lp2hp(A,B,C,D,Wo)
Lowpass t o bandpass [numt,dent] = lp2bp(num,den,Wo,Bw)
[At,Bt,Ct,Dt] = lp2bp(A,B,C,D,Wo,Bw)
Lowpass t o bandst op [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
=
2 Filter Design
2-40
To begin designing an or der 10 bandpass Chebyshev t ype I filt er wit h a value
of 3 dB for passband r ipple
[z,p,k] = cheb1ap(5,3);
z, p, and k cont ain t he poles, zer os, and gain of a lowpass analog filt er wit h
cut off fr equency
c
equal t o 1 r ad/sec. Use t he lp2bp funct ion t o t r ansfor m t his
lowpass pr ot ot ype t o a bandpass analog filt er wit h band edges W
1
= /5 and
W
2
= . Fir st , conver t t he filt er t o st at e-space for m so t he lp2bp funct ion can
accept it .
[A,B,C,D] = zp2ss(z,p,k); % Convert to statespace form.
Now, find t he bandwidt h and cent er fr equency, and call lp2bp.
u1 = 0.1*2*pi; u2 = 0.5*2*pi; % in radians per second
Bw = u2u1;
Wo = sqrt(u1*u2);
[At,Bt,Ct,Dt] = lp2bp(A,B,C,D,Wo,Bw);
Special Topics in IIR Filter Design
2-41
Finally, calculat e t he fr equency r esponse and plot it s magnit ude.
[b,a] = ss2tf(At,Bt,Ct,Dt);% Convert to TF form.
w = linspace(.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.
Filter Discretization
The t hir d st ep in t he analog pr ot ot yping t echnique is t he t r ansfor mat ion of t he
filt er t o t he discr et e-t ime domain. The t oolbox pr ovides t wo met hods for t his:
t he impulse invar iant and bilinear t r ansfor mat ions. The filt er design funct ions
pi/5 pi
10
-7
10
-6
10
-5
10
-4
10
-3
10
-2
10
-1
10
0
Frequency (rad/sec)
2 Filter Design
2-42
butter, cheby1, cheby2, and ellip use t he bilinear t r ansfor mat ion for
discr et izat ion in t his st ep.
Impulse Invariance
The t oolbox funct ion impinvar cr eat es a digit al filt er whose impulse r esponse
is t he samples of t he cont inuous impulse r esponse of an analog filt er . This
funct ion wor ks only on filt er s in t r ansfer funct ion for m. For best r esult s, t he
analog filt er should have negligible fr equency cont ent above half t he sampling
fr equency, because such high fr equency cont ent is aliased int o lower bands
upon sampling. Impulse invar iance wor ks for some lowpass and bandpass
filt er s, but is not appr opr iat e for highpass and bandst op filt er s.
Analog to Digital
Transformation
Transformation Function
Impulse invar iance [numd,dend] = impinvar(num,den,Fs)
Bilinear t r ansfor m [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)
Special Topics in IIR Filter Design
2-43
Design a Chebyshev t ype I filt er and plot it s fr equency r esponse.
[bz,az] = impinvar(b,a,2);
freqz(bz,az)
Impulse invar iance r et ains t he cut off fr equencies of 0.1 Hz and 0.5 Hz.
Bilinear Transformation
The bilinear t r ansfor mat ion is a nonlinear mapping of t he cont inuous domain
t o t he discr et e domain; it maps t he s-plane int o t he z-plane by
Bilinear t r ansfor mat ion maps t he j axis of t he cont inuous domain t o t he unit
cir cle of t he discr et e domain accor ding t o
The t oolbox funct ion bilinear implement s t his oper at ion, wher e t he fr equency
war ping const ant k is equal t o t wice t he sampling fr equency (2*Fs) by default
and equal t o 2*pi*Fp/tan(pi*Fp/Fs) if you give bilinear a t r ailing ar gument
t hat r epr esent s a mat ch fr equency Fp. If a mat ch fr equency Fp (in Her t z) is
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
-800
-600
-400
-200
0
200
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
-150
-100
-50
0
Normalized frequency (Nyquist == 1)
M
a
g
n
i
t
u
d
e

R
e
s
p
o
n
s
e

(
d
B
)
H z ( ) H s ( )
s k
z 1
z 1 +
------------ =
=
2t an
1

k
----
,
_
=
2 Filter Design
2-44
pr esent , bilinear maps t he fr equency = 2f
p
(in r adians/second) t o t he same
fr equency in t he discr et e domain, nor malized t o t he sampling r at e: = 2f
p
/ f
s
(also in r adians/second).
The bilinear funct ion can per for m t his t r ansfor mat ion on t hr ee differ ent
linear syst em r epr esent at ions: zer o-pole-gain, t r ansfer funct ion, and
st at e-space for m. Tr y calling bilinear wit h t he st at e-space mat r ices t hat
descr ibe t he Chebyshev t ype I filt er fr om t he pr evious sect ion, using a sampling
fr equency of 2 Hz, and r et aining t he lower band edge of 0.1 Hz.
[Ad,Bd,Cd,Dd] = bilinear(At,Bt,Ct,Dt,2,0.1);
The fr equency r esponse of t he r esult ing digit al filt er is
[bz,az] = ss2tf(Ad,Bd,Cd,Dd); % convert to TF
freqz(bz,az)
The lower band edge is at 0.1 Hz as expect ed. Not ice, however , t hat t he upper
band edge is slight ly less t han 0.5 Hz, alt hough in t he analog domain it was
exact ly 0.5 Hz. This illust r at es t he nonlinear nat ur e of t he bilinear
t r ansfor mat ion. To count er act t his nonlinear it y, it is necessar y t o cr eat e analog
domain filt er s wit h pr ewar ped band edges, which map t o t he cor r ect locat ions
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
)
Special Topics in IIR Filter Design
2-45
upon bilinear t r ansfor mat ion. Her e t he pr ewar ped fr equencies u1 and u2
gener at e Bw and Wo for t he lp2bp funct ion.
Fs = 2; % sampling frequency (Hertz)
u1 = 2*Fs*tan(.1*(2*pi/Fs)/2); % lower band edge (radians/second)
u2 = 2*Fs*tan(.5*(2*pi/Fs)/2); % upper band edge (radians/second)
Bw = u2u1; % bandwidth
Wo = sqrt(u1*u2); % center frequency
[At,Bt,Ct,Dt] = lp2bp(A,B,C,D,Wo,Bw);
A digit al bandpass filt er wit h cor r ect band edges 0.1 and 0.5 t imes t he Nyquist
fr equency is
[Ad,Bd,Cd,Dd] = bilinear(At,Bt,Ct,Dt,Fs);
The example bandpass filt er s fr om t he last t wo sect ions could also be cr eat ed
in one st at ement using t he complet e IIR design funct ion cheby1. For inst ance,
an analog ver sion of t he example Chebyshev filt er is
[b,a] = cheby1(5,3,[0.1 0.5]*2*pi,'s');
Not e t hat t he band edges ar e in r adians/second for analog filt er s, wher eas for
t he digit al case, fr equency is nor malized (t he Nyquist fr equency is equal t o 1
Hz).
[bz,az] = cheby1(5,3,[0.1 0.5]);
All of t he complet e design funct ions call bilinear int er nally. They pr ewar p t he
band edges as needed t o obt ain t he cor r ect digit al filt er . See Chapt er 6 for mor e
on t hese funct ions.
2 Filter Design
2-46
References
1 Kar am, L.J ., and J .H. McClellan. Complex Chebyshev Appr oximat ion for
FIR Filt er Design. IEEE Trans. on Circuits and S ystems II. Mar ch 1995.
2 Selesnick, I.W., and C.S. Bur r us. Gener alized Digit al But t er wor t h Filt er
Design. Proceedings of the IEEE Int. Conf. Acoust., S peech, S ignal
Processing. Vol. 3 (May 1996).
3 Selesnick, I.W., M. Lang, and C.S. Bur r us. Const r ained Least Squar e
Design of FIR Filt er s wit hout Specified Tr ansit ion Bands. Proceedings of
the IEEE Int. Conf. Acoust., S peech, S ignal Processing. Vol. 2 (May 1995).
Pgs. 1260-1263.
3
St at ist ical Signal
Pr ocessing
Correlati on and Covari ance . . . . . . . . . . . . . . . . . . . . . . . . . . 3-2
Bias and Nor malizat ion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-3
Mult iple Channels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-4
Spe ctral Analys i s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-5
Welchs Met hod . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-6
Mult it aper Met hod . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-16
Yule-Walker AR Met hod . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-19
Bur g Met hod . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-20
Covar iance and Modified Covar iance Met hods . . . . . . . . . . . . . 3-22
MUSIC and Eigenvect or Analysis Met hods . . . . . . . . . . . . . . . 3-23
Refe re nce s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-27
3 Statistical Signal Processing
3-2
Correlation and Covariance
The Signal Pr ocessing Toolbox pr ovides t ools for est imat ing impor t ant
funct ions of r andom signals. In par t icular , t her e ar e t ools t o est imat e
cor r elat ion and covar iance sequences and spect r al densit y funct ions of discr et e
signals. This chapt er explains t he cor r elat ion and covar iance funct ions and
discusses t he mat hemat ically r elat ed funct ions for est imat ing t he power
spect r um.
The funct ions xcorr and xcov est imat e t he cr oss-cor r elat ion and
cr oss-covar iance sequences of r andom pr ocesses. They also handle
aut ocor r elat ion and aut ocovar iance as special cases.
The t r ue cr oss-cor r elat ion sequence is a st at ist ical quant it y defined as
wher e x
n
and y
n
ar e st at ionar y r andom pr ocesses, - , and E{}is t he
expect ed value oper at or . The cr oss-covar iance sequence is t he mean-r emoved
cr oss-cor r elat ion sequence
or , in t er ms of t he cr oss-cor r elat ion,
In pr act ice, you must est imat e t hese sequences, because it is possible t o access
only a finit e segment of t he infinit e-lengt h r andom pr ocess. A common est imat e
based on N samples of x
n
and y
n
is t he det er minist ic cr oss-cor r elat ion sequence
(also called t he t ime-ambiguit y funct ion)

x y
m ( ) E{x
n
y
*
n m +
} =
n < <
C
x y
m ( ) E{ x
n

x
( ) y
*
n m +

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

*
y
=
R

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

m 0
R

y x
*
m ( ) m 0 <

'

=
Correlation and Covariance
3-3
wher e we assume for t his discussion t hat x
n
and y
n
ar e indexed fr om 0 t o N-1,
and fr om -(N-1) t o N-1. The xcorr funct ion evaluat es t his sum wit h
an efficient FFT-based algor it hm, given input s x
n
and y
n
st or ed in lengt h N
vect or s x and y. It s oper at ion is equivalent t o convolut ion wit h one of t he t wo
subsequences r ever sed in t ime.
For example,
x = [1 1 1 1 1]';
y = x;
xyc = xcorr(x,y)
xyc =
1.0000
2.0000
3.0000
4.0000
5.0000
4.0000
3.0000
2.0000
1.0000
Not ice t hat t he r esult ing sequence is t wice t he lengt h of t he input sequence
minus 1. Thus, t he Nt h element is t he cor r elat ion at lag 0. Also not ice t he
t r iangular pulse of t he out put t hat r esult s when convolving t wo squar e pulses.
The xcov funct ion est imat es aut ocovar iance and cr oss-covar iance sequences.
This funct ion has t he same opt ions and evaluat es t he same sum as xcorr, but
fir st r emoves t he means of x and y.
Bias and Normalization
An est imat e of a quant it y is biased if it s expect ed value is not equal t o t he
quant it y it est imat es. The expect ed value of t he out put of xcorr is
R

y x
*
m ( )
E{R

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

N m ( )
xy
m ( ) = =
3 Statistical Signal Processing
3-4
xcorr pr ovides t he unbiased est imat e, dividing by N-| m| , when you specify an
'unbiased' flag aft er t he input sequences.
xcorr(x,y,'unbiased')
Alt hough t his est imat e is unbiased, t he end point s (near -(N-1) and N-1) suffer
fr om lar ge var iance because xcorr comput es t hem using only a few dat a point s.
A possible t r ade-off is t o simply divide by N using t he 'biased' flag.
xcorr(x,y,'biased')
Wit h t his scheme, only t he sample of t he cor r elat ion at 0 lag (t he Nt h out put
element ) is unbiased. This est imat e is oft en mor e desir able t han t he unbiased
one because it avoids r andom lar ge var iat ions at t he end point s of t he
cor r elat ion sequence.
xcorr pr ovides one ot her nor malizat ion scheme. The synt ax
xcorr(x,y,'coeff')
divides t he out put by norm(x)*norm(y) so t hat , for aut ocor r elat ions, t he
sample at 0 lag is 1.
Multiple Channels
For a mult ichannel signal, xcorr and xcov est imat e t he aut ocor r elat ion and
cr oss-cor r elat ion and covar iance sequences for all of t he channels at once. If S
is an M-by-N signal mat r ix r epr esent ing N channels in it s columns, xcorr(S)
r et ur ns a (2M-1)-by-N
2
mat r ix wit h t he aut ocor r elat ions and cr oss-cor r elat ions
of t he channels of S in it s N
2
columns. If S is a 3-channel signal
S = [s1 s2 s3]
t hen t he r esult of xcorr(S) is or ganized as
R = [Rs1s1 Rs1s2 Rs1s3 Rs2s1 Rs2s2 Rs2s3 Rs3s1 Rs3s2 Rs3s3]
Two r elat ed funct ions, cov and corrcoef, ar e available in t he st andar d
MATLAB envir onment . They est imat e covar iance and nor malized covar iance
r espect ively bet ween t he differ ent channels at lag 0 and ar r ange t hem in a
squar e mat r ix.
Spectral Analysis
3-5
Spectral Analysis
Spect r al analysis seeks t o descr ibe t he fr equency cont ent of a signal, r andom
pr ocess, or syst em, based on a finit e set of dat a. Est imat ion of power spect r a is
useful in a var iet y of applicat ions, including t he det ect ion of signals bur ied in
wide-band noise.
The power spectral density (PSD) of a st at ionar y r andom pr ocess x
n
is r elat ed
mat hemat ically t o t he cor r elat ion sequence by t he discr et e-t ime Four ier
t r ansfor m,
This funct ion of fr equency has t he pr oper t y t hat it s int egr al over a fr equency
band is equal t o t he power of t he signal x
n
in t hat band.
The PSD is a special case of t he cross spectral density (CSD) funct ion, defined
bet ween t wo signals x
n
and y
n
as
As is t he case for t he cor r elat ion and covar iance sequences, t he t oolbox
estimates t he PSD and CSD because signal lengt hs ar e finit e.
The var ious met hods of PSD est imat ion can be ident ified as parametric or
nonparametric. One t echnique offer ed in t he Signal Pr ocessing Toolbox is t he
popular nonpar amet r ic scheme developed by Welch [5]. This is complement ed
by mor e moder n nonpar amet r ic t echniques such as t he multitaper method
(MTM) and t he multiple signal classification (MUSIC) or eigenvector (EV)
method, which is well suit ed for line spect r a (dat a made up of sinusoids). The
Yule-Walker autoregressive (AR) method is a par amet r ic met hod t hat est imat es
t he aut ocor r elat ion funct ion t o solve for t he AR model par amet er s. The Burg
method is anot her par amet r ic spect r al est imat ion met hod t hat minimizes t he
for war d and backwar d linear pr edict ion er r or s while sat isfying t he
Levinson-Dur bin r ecur sion. These met hods ar e list ed in t he t able below wit h
t he cor r esponding t oolbox funct ion name. The number below each met hod
name indicat es t he page t hat descr ibes t he met hod in gr eat er det ail. See
P
x x
( )
x x
m ( )e
j m
m =

=
P
x y
( )
x y
m ( )e
j m
m =

=
3 Statistical Signal Processing
3-6
Par amet r ic Modeling in Chapt er 4 for det ails about lpc and ot her par amet r ic
est imat ion funct ions.
Welchs Method
One way of est imat ing t he power spect r um of a pr ocess is t o simply find t he
discr et e-t ime Four ier t r ansfor m of t he samples of t he pr ocess (usually done on
Method Description Functions
Bur g
(3-20)
Aut or egr essive (AR) spect r al
est imat ion of a t ime-ser ies by
minimizat ion of linear pr edict ion
er r or s
pburg
Covar iance
(3-22)
Aut or egr essive (AR) spect r al
est imat ion of a t ime-ser ies by
minimizat ion of t he for war d
pr edict ion er r or s
pcov
Modified
Covar iance
(3-22)
Aut or egr essive (AR) spect r al
est imat ion of a t ime-ser ies by
minimizat ion of t he for war d and
backwar d pr edict ion er r or s
pmcov
Mult it aper
(3-16)
Spect r al est imat e fr om combinat ion
of mult iple or t hogonal windows (or
t aper s)
pmtm
MUSIC
(3-23)
Mult iple signal classificat ion or
eigenvect or met hod
pmusic
Welch
(3-6)
Aver aged per iodogr ams of
over lapped, windowed signal sect ions
pwelch, csd,
tfe, cohere
Yule-Walker AR
(3-19)
Aut or egr essive (AR) spect r al
est imat e of a t ime-ser ies fr om it s
est imat ed aut ocor r elat ion funct ion
pyulear
Spectral Analysis
3-7
a gr id wit h an FFT) and t ake t he magnit ude squar ed of t he r esult . An example
1001-element signal xn, which consist s of t wo sinusoids plus noise, is given by
Fs = 1000; % sampling frequency
t = 0:1/Fs:1; % one second worth of samples
xn = sin(2*pi*50*t) + 2*sin(2*pi*120*t) + randn(size(t));
A cr ude est imat e of t he PSD of xn is
Pxx = abs(fft(xn,1024)).^2/1001;
This est imat e is called t he periodogram. Scale t he magnit ude squar ed of t he
FFT by t he squar e of t he nor m of t he dat a window applied t o t he signal (in t his
case, a lengt h 1001 r ect angular window) t o ensur e t hat t he est imat e is
asymptotically unbiased. That is, as t he number of samples incr eases, t he
expect ed value of t he per iodogr am appr oaches t he t r ue PSD.
The pr oblem wit h t he per iodogr am est imat e is t hat it s var iance is lar ge (on t he
or der of t he PSD squar ed) and does not decr ease as t he number of samples
incr eases. The following t wo examples show t his; as FFT lengt h incr eases, t he
per iodogr am does not become smoot her .
Pxx_short = abs(fft(xn,256)).^2/256;
plot((0:255)/256*Fs,10*log10(Pxx_short))
plot((0:1023)/1024*Fs,10*log10(Pxx))
Reduce t he var iance of t he PSD est imat e by br eaking t he signal int o
nonover lapping sect ions and aver aging t he per iodogr ams of t hese sect ions.
Pxx = (abs(fft(xn( 1:256))).^2 + abs(fft(xn(257:512))).^2 + ...
abs(fft(xn(513:768))).^2 ) / (256*3);
plot((0:255)/256*Fs,10*log10(Pxx))
0 100 200 300 400 500 600 700 800 900 1000
-10
-5
0
5
10
15
20
25
Frequency (Hz)
P
o
w
e
r

S
p
e
c
t
r
u
m

(
d
B
)
Averaged Periodogram (no overlap)
3 Statistical Signal Processing
3-8
This aver aged est imat e has one t hir d t he var iance of t he lengt h 256
per iodogr am shown ear lier . The mor e sect ions you aver age, t he lower t he
var iance of t he r esult . However , t he signal lengt h limit s t he number of sect ions
0 100 200 300 400 500 600 700 800 900 1000
-20
-10
0
10
20
30
Frequency (Hz)
P
o
w
e
r

S
p
e
c
t
r
u
m

(
d
B
)
Short Periodogram
0 100 200 300 400 500 600 700 800 900 1000
-30
-20
-10
0
10
20
30
Frequency (Hz)
P
o
w
e
r

S
p
e
c
t
r
u
m

(
d
B
)
Periodogram
Spectral Analysis
3-9
possible (t o t hr ee sect ions of lengt h 256 in t he pr evious example). To obt ain
mor e sect ions, br eak t he signal int o over lapping sect ions.
Pxx = (abs(fft(xn( 1:256))).^2 + abs(fft(xn(129:384))).^2 + ...
abs(fft(xn(257:512))).^2 + abs(fft(xn(385:640))).^2 + ...
abs(fft(xn(513:768))).^2 + ...
abs(fft(xn(641:896))).^2 ) / (256*6);
plot((0:255)/256*Fs,10*log10(Pxx))
In t his case t he sect ions ar e st at ist ically dependent , r esult ing in higher
var iance; t hus t her e is a t r ade-off bet ween t he number of sect ions and t he
over lap r at e.
Anot her way t o impr ove t he per iodogr am est imat e is t o apply a nonr ect angular
dat a window t o t he sect ions befor e comput ing t he per iodogr am, r esult ing in a
modified periodogram. This r educes t he effect of sect ion dependence due t o
over lap, because t he window is t aper ed t o 0 on t he edges. Also, a
nonr ect angular window diminishes t he side-lobe int er fer ence or spect r al
leakage while incr easing t he widt h of spect r al peaks. Wit h a suit able window
(such as Hamming, Hanning, or Kaiser ), over lap r at es of about half t he sect ion
lengt h have been found t o lower t he var iance of t he est imat e significant ly.
0 100 200 300 400 500 600 700 800 900 1000
-10
-5
0
5
10
15
20
25
Frequency (Hz)
P
o
w
e
r

S
p
e
c
t
r
u
m

(
d
B
)
Averaged Periodogram (128 sample overlap)
3 Statistical Signal Processing
3-10
The applicat ion of a Hanning window r esult s in
w = hanning(256)';
Pxx = ( abs(fft(w.*xn( 1:256))).^2 + ...
abs(fft(w.*xn(129:384))).^2 + ...
abs(fft(w.*xn(257:512))).^2 + ...
abs(fft(w.*xn(385:640))).^2 + ...
abs(fft(w.*xn(513:768))).^2 + ...
abs(fft(w.*xn(641:896))).^2 ) / (norm(w)^2*6);
plot((0:255)/256*Fs,10*log10(Pxx))
Not ice in t his plot t hat t he spect r al peaks have widened, and t he noise floor, or
level of t he noise, seems t o be t he flat t est of any est imat e so far . This met hod
of aver aged, modified per iodogr ams is Welchs met hod of PSD est imat ion.
The funct ions pwelch and csd pr ovide cont r ol over all t he par amet er s discussed
so far (FFT lengt h, window, and amount of over lap) in comput ing t he PSD and
CSD of signals using Welchs met hod.
For a mor e det ailed discussion of Welchs met hod of PSD est imat ion, see
Kay [1] and Welch [5].
Power Spectral Density Function
The pwelch funct ion aver ages and scales t he modified per iodogr ams of sect ions
of a signal. Simply specify t he par amet er s t hat cont r ol t he algor it hm as
ar gument s t o t he funct ion.
An est imat e for t he PSD of a sequence xn using pwelchs default FFT lengt h
(256), window (Hanning of lengt h 256), and over lap samples (none) is
Pxx = pwelch(xn);
0 100 200 300 400 500 600 700 800 900 1000
-10
-5
0
5
10
15
20
25
Frequency (Hz)
P
o
w
e
r

S
p
e
c
t
r
u
m

(
d
B
)
Averaged Modified Periodogram (128 sample overlap, Hanning window)
Spectral Analysis
3-11
Pxx has unit s of power per unit fr equency int er val. For example, if t he or iginal
sequence xn has unit s of volt s, Pxx has unit s of Wat t s/Hz.
To r ecr eat e t he last example accur at ely, specify 128 as t he number of samples
t o over lap:
nfft = 256; % length of FFT
window = hanning(256); % window function
noverlap = 128; % number of samples overlap
Pxx = pwelch(xn,nfft,Fs,window,noverlap);
Pxx is scaled by t he r ecipr ocal of t he sampling fr equency, 1/Fs. pwelch wit hout
any out put s gener at es a plot of t he PSD over t he fr equency r ange [0,Fs/2):
pwelch(xn,nfft,Fs,window,noverlap)
If you want t o plot t he PSD your self, obt ain t he fr equency vect or t hr ough an
addit ional out put ar gument .
[Pxx,f] = pwelch(xn,nfft,Fs,256,noverlap);
plot(f,10*log10(Pxx))
All t he spect r al est imat ion funct ions allow you t o specify an empt y mat r ix, [],
in place of an input ar gument t o use t he default value of t hat ar gument . In t he
command above, because t he values for nfft and window ar e act ually t he same
as t he default s, you could r eplace t hem bot h wit h t he empt y mat r ix.
[Pxx,f] = pwelch(xn,[],Fs,[],noverlap);
0 50 100 150 200 250 300 350 400 450 500
40
35
30
25
20
15
10
5
Welchs Spectral Estimate P
xx
(f) / f
s
Frequency (Hz)
P
o
w
e
r

S
p
e
c
t
r
a
l

D
e
n
s
i
t
y

(
d
B
)
3 Statistical Signal Processing
3-12
Since t he signal xn is r eal, pwelch r et ur ns only t he fr equencies fr om 0 t hr ough
t he Nyquist fr equency. In cont r ast , t he ear lier FFT example gener at ed PSD
est imat es r anging fr om 0 t hr ough Fs.
Bias and Normalization in Welchs Method
In st udying t he out put of pwelch shown ear lier , sever al r evealing
char act er ist ics about t he signal xn ar e evident . The noise floor is flat at 0
decibels (dB), implying whit e noise of var iance 1. Fur t her mor e, t he signal
par t of xn is concent r at ed in t wo peaks at 50 and 120 Hz. The r elat ion of t he
peak height s is meaningful. For inst ance, t he 50 Hz peak is 6 dB below t he 120
Hz peak, ver ifying t hat t he higher fr equency sinusoid has t wice t he magnit ude
as t he lower (10
6/20
= 2.0). Unlike t he r elat ive height s, t he act ual height of t he
peaks does not t ell us much about t he or iginal amplit ude of t he sinusoids
wit hout addit ional analysis.
To obt ain useful infor mat ion about t he peak amplit udes of t he under lying
sinusoids, not e t hat t he expect ed value of t he est imat ed PSD is
Because t he expect ed value is not equal t o t he t r ue PSD, t he est imat e is biased.
This quant it y is t he convolut ion of t he t r ue PSD wit h t he squar ed magnit ude
of t he windows discr et e-t ime Four ier t r ansfor m W(), scaled by t he squar ed
nor m of t he window. The scaling fact or is t he sum of t he squar es of t he window
funct ion:
This says t hat if P
xx
() has a peak of height 1 at a par t icular fr equency
0
, t he
est imat e will have appr oximat e height at t hat fr equency,
pr ovided t he window W() is nar r ow wit h r espect t o t he spacing bet ween t he
peak and ot her spect r al feat ur es. So, t o obt ain an est imat e which on aver age
r eflect s t he height of t he or iginal peaks, mult iply t he r esult of pwelch by
E P

xx ( ) { }
1
2 w
2
------------------- P
x x
( ) W ( ) d

=
w
2
w n ( )
2

=
W 0 ( )
2
w
2

Spectral Analysis
3-13
norm(w)^2/sum(w)^2, wher e w is t he window vect or . This scaling is
independent of window lengt h and shape. For example:
w1 = hanning(256); w2 = hanning(500);
[Pxx1,f1] = pwelch(xn,256,Fs,w1,128);
[Pxx2,f2] = pwelch(xn,1024,Fs,w2,250);
subplot(2,1,1)
plot(f1,10*log10(Pxx1*norm(w1)^2/sum(w1)^2))
axis([0 500 70 20]); grid
subplot(2,1,2)
plot(f2,10*log10(Pxx2*norm(w2)^2/sum(w2)^2))
axis([0 500 70 20]); grid
In bot h plot s, which show t he spect r um at posit ive fr equencies only (t he
negat ive fr equencies ar e t he same), t he higher fr equency peak has a value of 0
dB, and t he lower fr equency peak is at -6 dB. The 120 Hz sinusoid height of 0
dB cor r esponds t o a squar ed amplit ude of 1. This r esult s fr om t he sinusoid of
amplit ude 2 having complex exponent ial component s of amplit ude 1 at bot h
posit ive and negat ive fr equency. Similar ly, t he 50 Hz sinusoid has bot h
posit ive and negat ive fr equency component s wit h squar ed amplit ude of
()
2
= , or 10*log10(.25) = -6 dB, as shown in t he plot . Also, not e t hat t he
second plot r eflect s a slight ly lower noise floor , which is t he r esult of a longer
window lengt h.
0 100 200 300 400 500
70
60
50
40
30
20
0 100 200 300 400 500
70
60
50
40
30
20
3 Statistical Signal Processing
3-14
Cross-Spectral Density Function
To est imat e t he cr oss-spect r al densit y of t wo equal lengt h signals x and y using
Welchs met hod, t he csd funct ion for ms t he per iodogr am as t he pr oduct of t he
FFT of x and t he conjugat e of t he FFT of y. Unlike t he r eal-valued PSD, t he
CSD is a complex funct ion. csd handles t he sect ioning and windowing of x and
y in t he same way as t he pwelch funct ion.
Pxy = csd(x,y,nfft,Fs,window,noverlap)
Confidence Intervals
Bot h t he pwelch and csd funct ions can comput e confidence int er vals. Simply
pr ovide an input ar gument p, which specifies t he per cent age of t he confidence
int er val.
[Pxx,Pxxc,f] = pwelch(x,nfft,Fs,window,noverlap,p)
[Pxy,Pxyc,f] = csd(x,y,nfft,Fs,window,noverlap,p)
p must be a scalar bet ween 0 and 1. The funct ions assume chi-squar ed
dist r ibut ed per iodogr ams of nonover lapping sect ions in comput ing t he
confidence int er vals. (This assumpt ion is valid when t he signal is a Gaussian
dist r ibut ed r andom pr ocess.) Pr ovided t hese assumpt ions ar e cor r ect , t her e is
a p*100% pr obabilit y t hat t he confidence int er val
[PxxPxxc(:,1) Pxx+Pxxc(:,2)]
cover s t he t r ue PSD. If t he sect ions over lap, t he confidence int er val is not
r eliable and t he funct ions display a war ning message.
Transfer Function Estimate
One applicat ion of Welchs met hod is nonpar amet r ic syst em ident ificat ion.
Assume t hat H is a linear , t ime invar iant syst em, and x(n) and y(n) ar e t he
input t o and out put of H, r espect ively. Then t he PSD of x(n) is r elat ed t o t he
CSD of x(n) and y(n) by
An est imat e of t he t r ansfer funct ion bet ween x(n) and y(n) is
P
xy
( ) H ( )P
xx
( ) =
H

( )
P

xy ( )
P

xx ( )
----------------- =
Spectral Analysis
3-15
This met hod est imat es bot h magnit ude and phase infor mat ion. The tfe
funct ion uses Welchs met hod t o comput e t he CSD and PSD and t hen for ms
t heir quot ient for t he t r ansfer funct ion est imat e. Use tfe t he same way t hat
you use t he csd funct ion.
Filt er t he signal xn wit h an FIR filt er , t hen plot t he act ual magnit ude r esponse
and t he est imat ed r esponse.
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)');
Coherence Function
The magnit ude-squar ed coher ence bet ween t wo signals x(n) and y(n) is
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
( )
P
x y
( )
2
P
xx
( )P
yy
( )
----------------------------------- =
3 Statistical Signal Processing
3-16
This quot ient is a r eal number bet ween 0 and 1 t hat measur es t he cor r elat ion
bet ween x(n) and y(n) at t he fr equency .
The cohere funct ion t akes sequences x and y, comput es t heir PSDs and CSD,
and r et ur ns t he quot ient of t he magnit ude squar ed of t he CSD and t he pr oduct
of t he PSDs. It s opt ions and oper at ion ar e similar t o t he csd and tfe funct ions.
The coher ence funct ion of xn and t he filt er out put yn ver sus fr equency is
cohere(xn,yn,256,Fs,256,128,'none')
If t he input sequence lengt h, window lengt h, and over lap ar e such t hat cohere
oper at es on only a single r ecor d, t he funct ion r et ur ns all ones.
Multitaper Method
The multitaper method (MTM) uses or t hogonal windows (or t aper s) t o obt ain
appr oximat ely independent est imat es of t he power spect r um and t hen
combines t hem t o yield an est imat e. This est imat e exhibit s mor e degr ees of
fr eedom and allows for easier quant ificat ion of t he bias and var iance t r ade-offs,
compar ed t o convent ional per iodogr am met hods. Many convent ional spect r al
est imat es use a single t aper (or window), wit h some ir r et r ievable loss of
infor mat ion at t he beginning and t he end of t he ser ies. In t he mult it aper
met hod, addit ional t aper s ar e used t o r ecover some of t he lost infor mat ion.
This br ief discussion of t he mult it aper met hod pr ovides an int uit ive look at t he
algor it hm t o assist in det er mining when t o use it . For a mor e det ailed and
t hor ough explanat ion, see Per cival and Walden [3].
The simple par amet er for t he mult it aper met hod is t he t ime-bandwidt h
pr oduct , NW. This par amet er is a r esolut ion par amet er dir ect ly r elat ed t o t he
number of t aper s used t o comput e t he spect r um. Ther e ar e always 2*NW-1
t aper s used t o for m t he est imat e. This means t hat , as NW incr eases, t her e ar e
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 Analysis
3-17
mor e est imat es of t he power spect r um, and t he var iance of t he est imat e
decr eases. However , t he bandwidt h of each t aper is also pr opor t ional t o NW, so
as NW incr eases, each est imat e exhibit s mor e spect r al leakage (i.e., wider
peaks) and t he over all spect r al est imat e is mor e biased. For each dat a set ,
t her e is usually a value for NW t hat allows an opt imal t r ade-off bet ween bias
and var iance.
Using pmtm on t he dat a fr om t he pr evious sect ion, xn, yields
Fs = 1000;
t = 0:1/Fs:1;
randn('seed',0)
xn = sin(2*pi*50*t) + 2*sin(2*pi*120*t) + randn(size(t));
[P,f] = pmtm(xn,4,1024,Fs);
plot(f,10*log10(P)) % plot in decibels
axis([30 150 20 30])
40 60 80 100 120 140
-20
-15
-10
-5
0
5
10
15
20
25
30
Frequency (Hz)
M
a
g
n
i
t
u
d
e

(
d
B
)
3 Statistical Signal Processing
3-18
By lower ing t he t ime-bandwidt h pr oduct , t he peaks become nar r ower .
[P1,f] = pmtm(xn,3/2,1024,Fs);
plot(f,10*log10(P1)) % plot in decibels
axis([30 150 20 30])
Not e t hat t he ar ea under t he peaks r emains about t he same, as can be seen
when bot h ar e plot t ed t oget her on a linear scale.
plot(f,[P P1])
axis([30 150 0 400])
40 60 80 100 120 140
-20
-15
-10
-5
0
5
10
15
20
25
30
Frequency (Hz)
M
a
g
n
i
t
u
d
e

(
d
B
)
40 60 80 100 120 140
0
50
100
150
200
250
300
350
400
Frequency (Hz)
M
a
g
n
i
t
u
d
e
Spectral Analysis
3-19
This conser vat ion of t ot al power is ver ifiable numer ically.
sum(P)
ans =
1.8447e+03
sum(P1)
ans =
1.8699e+03
Not e t hat t ot al power is only appr oximat ely conser ved in t his case. This is
because t he adapt ive weight ing pr ocedur e t hat is used t o minimize leakage
does not st r ict ly conser ve t ot al power .
This met hod is mor e expensive comput at ionally t han Welchs met hod, because
of t he cost of comput ing t he discr et e pr olat e spher oidal sequences (DPSSs, also
known as Slepian sequences). For long dat a ser ies (10,000 point s or mor e), it is
useful t o comput e t he DPSSs once and save t hem in a MAT-file. The M-files
dpsssave, dpssload, dpssdir, and dpssclear ar e pr ovided, t o keep a dat abase
of saved DPSSs in t he MAT-file dpss.mat.
Yule-Walker AR Method
The Yule-Walker AR method is an aut or egr essive t echnique for spect r al densit y
est imat ion (see Mar ple [2], Chapt er 7, and Pr oakis[4], Sect ion 12.3.2). This
met hod solves for t he AR model par amet er s by t he aut ocor r elat ion met hod.
The Yule-Walker AR est imat e is obt ained by solut ion of t he nor mal equat ions.
Her e, a = [1 a(2) ... a(n+1)] is a vect or of aut or egr essive coefficient s, t he
element s of vect or r = [r(1) r(2) ... r(n+1)] ar e cor r elat ions, and t he left -hand
side aut ocor r elat ion mat r ix is Her mit ian Toeplit z and posit ive definit e.
r 1 ( ) r 2 ( )
*
L r n ( )
*
r 2 ( ) r 1 ( ) L r n 1 ( )
*
M O O M
r n ( ) L r 2 ( ) r 1 ( )
a 2 ( )
a 3 ( )
M
a n 1 + ( )
r 2 ( )
r 3 ( )
M
r n 1 + ( )
=
3 Statistical Signal Processing
3-20
The spect r al densit y est imat e is
wher e e(f) is a complex sinusoid.
The t oolbox funct ion pyulear implement s t he Yule-Walker AR met hod.
For example, compar e t he spect r um of a speech signal using Welchs met hod
and t he Yule-Walker AR met hod:
load mtlb
[P1,f] = pwelch(mtlb,1024,Fs,256);
[P2,f] = pyulear(mtlb,14,1024,Fs); % 14th order model
plot(f,10*log10(P1),':',f,10*log10(P2)); grid
ylabel('Magnitude (dB)'); xlabel('Frequency (Hz)');
legend('Welch','YuleWalker AR')
The solid Yule-Walker AR spect r um is smoot her t han t he per iodogr am because
of t he simple under lying all-pole model.
Burg Method
The Bur g met hod for AR spect r al est imat ion is based on minimizing t he
for war d and backwar d pr edict ion er r or s while sat isfying t he Levinson-Dur bin
r ecur sion (see Mar ple[2], Chapt er 7, and Pr oakis[4], Sect ion 12.3.3). In
cont r ast t o ot her AR est imat ion met hods, t he Bur g met hod avoids calculat ing
P
YuleAR
f ( )
1
a
H
e f ( )
2
----------------------- =
0 500 1000 1500 2000 2500 3000 3500 4000
90
80
70
60
50
40
30
20
M
a
g
n
i
t
u
d
e

(
d
B
)
Frequency (Hz)
Welch
YuleWalker AR
Spectral Analysis
3-21
t he aut ocor r elat ion funct ion, and inst ead est imat es t he r eflect ion coefficient s
dir ect ly.
The pr imar y advant ages of t he Bur g met hod ar e r esolving closely spaced
sinusoids in signals wit h low noise levels, and est imat ing shor t dat a r ecor ds, in
which case t he AR power spect r al densit y est imat es ar e ver y close t o t he t r ue
values. In addit ion, t he Bur g met hod ensur es a st able AR model and is
comput at ionally efficient .
The accur acy of t he Bur g met hod is lower for high-or der models, long dat a
r ecor ds, and high signal-t o-noise r at ios (which can cause line splitting, or t he
gener at ion of ext r aneous peaks in t he spect r um est imat e). The spect r al densit y
est imat e comput ed by t he Bur g met hod is also suscept ible t o fr equency shift s
(r elat ive t o t he t r ue fr equency) r esult ing fr om t he init ial phase of noisy
sinusoidal signals. This effect is magnified when analyzing shor t dat a
sequences.
The t oolbox funct ion pburg implement s t he Bur g met hod. Compar e t he
spect r um of t he speech signal gener at ed by bot h t he Bur g met hod and t he
Yule-Walker AR met hod. They ar e ver y similar for lar ge signal lengt hs.
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','YuleWalker AR')
0 500 1000 1500 2000 2500 3000 3500 4000
90
80
70
60
50
40
30
20
M
a
g
n
i
t
u
d
e

(
d
B
)
Frequency (Hz)
Burg
YuleWalker AR
3 Statistical Signal Processing
3-22
Compar e t he spect r um of a noisy signal comput ed using t he Bur g met hod and
t he Welch met hod.
Fs = 1000;
t = 0:1/Fs:1;
xn = sin(2*pi*50*t) + 2*sin(2*pi*120*t) + randn(size(t));
[P1,f] = pwelch(xn,1024 ,Fs);
[P2,f] = pburg(xn,17,1024,Fs); % 17th order model
plot(f,10*log10(P1),':',f,10*log10(P2)), grid
ylabel('Magnitude (dB)'); xlabel('Frequency (Hz)');
axis([0 200 50 0])
legend('Welch','Burg')
Not e t hat , as t he model or der for t he Bur g met hod is r educed, a fr equency shift
due t o t he init ial phase of t he sinusoids will become appar ent .
Covariance and Modified Covariance Methods
The covar iance met hod for AR spect r al est imat ion is based on minimizing t he
for war d pr edict ion er r or . The modified covar iance met hod is based on
minimizing t he for war d and backwar d pr edict ion er r or s. The t oolbox funct ions
pcov and pmcov implement t he r espect ive met hods.
0 50 100 150 200
50
45
40
35
30
25
20
15
10
5
0
M
a
g
n
i
t
u
d
e

(
d
B
)
Frequency (Hz)
Welch
Burg
Spectral Analysis
3-23
Compar e t he spect r um of t he speech signal gener at ed by bot h t he covar iance
met hod and t he modified covar iance met hod. They ar e near ly ident ical, even
for a shor t signal lengt h.
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')
MUSIC and Eigenvector Analysis Methods
The pmusic funct ion pr ovides t wo r elat ed spect r al analysis met hods:
The mult iple signal classificat ion met hod (MUSIC) developed by Schmidt
The eigenvect or (EV) met hod developed by J ohnson
See Mar ple [2] (pgs. 373-378) for a summar y of t hese met hods.
Bot h of t hese met hods ar e fr equency est imat or t echniques based on
eigenanalysis of t he aut ocor r elat ion mat r ix. This t ype of spect r al analysis
cat egor izes t he infor mat ion in a cor r elat ion or dat a mat r ix, assigning
infor mat ion t o eit her a signal subspace or a noise subspace.
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
3 Statistical Signal Processing
3-24
Eigenanalysis Overview
Consider a number of complex sinusoids embedded in whit e noise. You can
wr it e t he aut ocor r elat ion mat r ix R for t his syst em as t he sum of t he signal
aut ocor r elat ion mat r ix (S ) and t he noise aut ocor r elat ion mat r ix (W).
Ther e is a close r elat ionship bet ween t he eigenvect or s of t he signal
aut ocor r elat ion mat r ix and t he signal and noise subspaces. The eigenvect or s v
of S span t he same signal subspace as t he signal vect or s. If t he syst em cont ains
M complex sinusoids and t he or der of t he aut ocor r elat ion mat r ix is p,
eigenvect or s v
M+1
t hr ough v
p+1
span t he noise subspace of t he aut ocor r elat ion
mat r ix.
Frequency Estimator Functions. To gener at e t heir fr equency est imat es,
eigenanalysis met hods calculat e funct ions of t he vect or s in t he signal and noise
subspaces. Bot h t he MUSIC and EV t echniques choose a funct ion t hat
t heor et ically goes t o infinit y at one of t he sinusoidal fr equencies in t he input
signal. Using digit al t echnology, t he r esult ing est imat e has shar p peaks at t he
fr equencies of int er est ; t his means t hat t her e wont be infinit y values in t he
vect or s.
The MUSIC est imat e is given by t he for mula
wher e N is t he size of t he eigenvect or s and e (f) is a complex sinusoid vect or :
v r epr esent s t he eigenvect or s of t he input signals cor r elat ion mat r ix; v
k
is t he
k
t h
eigenvect or . H is t he conjugat e t r anspose oper at or . The eigenvect or s used
in t he sum cor r espond t o t he smallest eigenvalues and span t he noise subspace
(p is t he size of t he signal subspace).
The expr ession is equivalent t o a Four ier t r ansfor m (t he vect or e(f)
consist s of complex exponent ials). This for m is useful for numer ic comput at ion
because t he FFT can be comput ed for each v
k
and t hen t he squar ed magnit udes
can be summed.
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
=
v
k
H
e f ( )
Spectral Analysis
3-25
The EV met hod weight s t he summat ion by t he eigenvalues of t he cor r elat ion
mat r ix:
The pmusic funct ion in t his t oolbox uses t he svd (singular value decomposit ion)
funct ion in t he signal case and t he eig funct ion for analyzing t he cor r elat ion
mat r ix and assigning eigenvect or s t o t he signal or noise subspaces. When svd
is used, pmusic never comput es t he cor r elat ion mat r ix explicit ly, but t he
singular values ar e t he eigenvalues.
Controlling Subspace Thresholds
To pr ovide user cont r ol over t he assignment s of eigenvect or s t o t he signal and
noise subspaces, t he pmusic funct ion accept s a t hr eshold ar gument thresh.
thresh is a t wo-element vect or wher e t he fir st element is t he number of
eigenvect or s spanning t he signal subspace and t he second element is a
t hr eshold t est :
If thresh(2) 1, t hen thresh(1) specifies t he number of eigenvect or s
spanning t he signal subspace. In t his case t he values of thresh(1) must be
in t he r ange [0, N), wher e N is:
- The column lengt h of xR if xR is a dat a mat r ix
- The mat r ix size if xR is a cor r elat ion mat r ix
- The window lengt h if xR is a signal vect or
If thresh(1) N, t hen thresh(2) is a value gr eat er t han or equal t o 1 t hat
specifies t he absolut e t hr eshold for split t ing t he eigenvalues bet ween t he
signal and noise subspaces. That is, if a given eigenvalue is less t han or equal
t o t he pr oduct thresh(2)min{
k
}, t hen t he given eigenvect or is assigned t o
t he noise subspace.
If thresh(1) < N and thresh(2) 1, thresh(1) st ill specifies t he maximum
number of eigenvect or s in t he signal subspace. However , t he t hr eshold t est
specified by thresh(2) can also assign eigenvect or s t o t he noise subspace.
If thresh(1) N and thresh(2) < 1, t her e ar e no noise eigenvect or s. This is
an invalid case and pmusic gener at es an er r or .
P
ev
f ( )
1
v
k
H
e f ( )
2
k p 1 + =
N

,


_

----------------------------------------------------------- =
3 Statistical Signal Processing
3-26
For complet e det ails on using t he thresh par amet er , see t he r efer ence
descr ipt ion of pmusic in Chapt er 6.
References
3-27
References
1 Kay, S.M. Modern S pectral Estimation. Englewood Cliffs, NJ : Pr ent ice Hall,
1988.
2 Mar ple, S.L. Digital S pectral Analysis. Englewood Cliffs, NJ : Pr ent ice Hall,
1987.
3 Per cival, D.B., and A.T. Walden. S pectral Analysis for Physical Applications:
Multitaper and Conventional Univariate Techniques. Cambr idge:
Cambr idge Univer sit y Pr ess, 1993.
4 Pr oakis, J .G., and D.G. Manolakis. Digital S ignal Processing: Principles,
Algorithms, and Applications. Englewood Cliffs, NJ : Pr ent ice Hall, 1996.
5 Welch, P.D. The Use of Fast Four ier Tr ansfor m for t he Est imat ion of Power
Spect r a: A Met hod Based on Time Aver aging Over Shor t , Modified
Per iodogr ams. IEEE Trans. Audio Electroacoust. Vol. AU-15 (J une 1967).
Pgs. 70-73.
3 Statistical Signal Processing
3-28
4
Special Topics
Wi ndows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-2
Basic Shapes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-2
Gener alized Cosine Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-4
Kaiser Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-4
Chebyshev Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-9
Parametric Mode li ng . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-10
Time-Domain Based Modeling . . . . . . . . . . . . . . . . . . . . . . . . . . 4-11
Fr equency-Domain Based Modeling . . . . . . . . . . . . . . . . . . . . . 4-16
Resampli ng . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-20
Ce pstrum Analysi s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-23
Inver se Complex Cepst r um . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-25
FFT-Base d Time-Frequency Analysi s . . . . . . . . . . . . . . . . . 4-27
Me di an Filte ri ng . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-28
Communi cati ons Appli cat i ons . . . . . . . . . . . . . . . . . . . . . . . 4-29
De convolut i on . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-33
Speci ali ze d Transforms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-34
Chir p z-Tr ansfor m . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-34
Discr et e Cosine Tr ansfor m . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-36
Hilber t Tr ansfor m . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-38
Refe re nce s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-40
4 Special Topics
4-2
Windows
In bot h digit al filt er design and power spect r um est imat ion, t he choice of a
windowing funct ion can play an impor t ant r ole in det er mining t he qualit y of
over all r esult s. The main r ole of t he window is t o damp out t he effect s of t he
Gibbs phenomenon t hat r esult s fr om t r uncat ion of an infinit e ser ies.
The t oolbox window funct ions ar e shown in t he t able below.
Basic Shapes
The basic window is t he rectangular window, a vect or of ones of t he appr opr iat e
lengt h. A r ect angular window of lengt h 50 is
n = 50;
w = boxcar(n);
This t oolbox st or es windows in column vect or s by convent ion, so an equivalent
expr ession is
w = ones(50,1);
The Bartlett (or t r iangular ) window is t he convolut ion of t wo r ect angular
windows. The funct ions bartlett and triang comput e similar t r iangular
windows, wit h t hr ee impor t ant differ ences. The bartlett funct ion always
Window Function
Bar t let t window bartlett
Blackman window blackman
Rect angular window boxcar
Chebyshev window chebwin
Hamming window hamming
Hanning window hanning
Kaiser window kaiser
Tr iangular window triang
Windows
4-3
r et ur ns a window wit h t wo zer os on t he ends of t he sequence, so t hat for n odd,
t he cent er sect ion of bartlett(n+2) is equivalent t o 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 is st ill t he convolut ion of t wo r ect angular sequences.
Ther e is no st andar d definit ion for t he t r iangular window for n even; t he slopes
of t he line segment s of triangs r esult ar e slight ly st eeper t han t hose of
bartletts in t his case:
w = bartlett(8);
[w(2:7) triang(6)]
ans =
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 final differ ence bet ween t he Bar t let t and t r iangular windows is evident in
t he Four ier t r ansfor ms of t hese funct ions. The Four ier t r ansfor m of a Bar t let t
4 Special Topics
4-4
window is negat ive for n even. The Four ier t r ansfor m of a t r iangular window,
however , is always nonnegat ive.
This differ ence can be impor t ant when choosing a window for some spect r al
est imat ion t echniques, such as t he Blackman-Tukey met hod. Blackman-Tukey
for ms t he spect r al est imat e by calculat ing t he Four ier t r ansfor m of t he
aut ocor r elat ion sequence. The r esult ing est imat e might be negat ive at some
fr equencies if t he windows Four ier t r ansfor m is negat ive (see Kay [1], pg. 80).
Generalized Cosine Windows
Blackman, Hamming, Hanning, and r ect angular windows ar e all special cases
of t he generalized cosine window. These windows ar e combinat ions of
sinusoidal sequences wit h fr equencies 0, 2/(N-1), and 4/(N-1), wher e N is t he
window lengt h. One way t o gener at e t hem is
ind = (0:n1)'*2*pi/(n1);
w = A B*cos(ind) + C*cos(2*ind);
wher e A, B, and C ar e const ant s you define. The concept behind t hese windows
is t hat by summing t he individual t er ms t o for m t he window, t he low fr equency
peaks in t he fr equency domain combine in such a way as t o decr ease sidelobe
height . This has t he side effect of incr easing t he mainlobe widt h.
The Hamming and Hanning windows ar e t wo-t er m gener alized cosine
windows, given by A = 0.54, B = 0.46 for Hamming and A = 0.5, B = 0.5 for
Hanning (C = 0 in bot h cases). The hamming and hanning funct ions,
r espect ively, comput e t hese windows.
Not e t hat t he definit ion of t he gener alized cosine window shown in t he ear lier
MATLAB code yields zer os at samples 1 and n for A = 0.5 and B = 0.5. To
eliminat e t hese zer os on t he edges of t he window, hanning uses a cosine of
fr equency 2/(N+1) inst ead of 2/(N-1).
The Blackman window is a popular t hr ee-t er m window, given by
A = 0.42, B = 0.5, C = 0.08. The blackman funct ion comput es t his window.
Kaiser Window
The Kaiser window is an appr oximat ion t o t he pr olat e-spher oidal window, for
which t he r at io of t he mainlobe ener gy t o t he sidelobe ener gy is maximized. For
a Kaiser window of a par t icular lengt h, t he par amet er cont r ols t he sidelobe
height . For a given , t he sidelobe height is fixed wit h r espect t o window lengt h.
Windows
4-5
The st at ement kaiser(n,beta) comput es a lengt h n Kaiser window wit h
par amet er beta.
Examples of Kaiser windows wit h lengt h 50 and var ious values for t he beta
par amet er ar e
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])))
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 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 = 2
beta = 3
4 Special Topics
4-6
As incr eases, t he sidelobe height decr eases and t he mainlobe widt h incr eases.
To see how t he sidelobe height st ays t he same for a fixed par amet er as t he
lengt h is var ied, t r y
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])))
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
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
Windows
4-7
Kaiser Windows in FIR Design
Ther e ar e t wo design for mulas t hat can help you design FIR filt er s t o meet a
set of filt er specificat ions using a Kaiser window. To achieve a sidelobe height
of dB, t he beta par amet er is
For a t r ansit ion widt h of r ad/sec, use t he lengt h
Filt er s designed using t hese heur ist ics will meet t he specificat ions
appr oximat ely, but you should ver ify t his. To design a lowpass filt er wit h cut off
fr equency 0.5 r ad/sec, t r ansit ion widt h 0.2 r ad/sec, and 40 dB of at t enuat ion
in t he st opband, t r y
[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 funct ion est imat es t he filt er or der , cut off fr equency, and Kaiser
window bet a par amet er needed t o meet a given set of fr equency domain
specificat ions.

0.1102 8.7 ( ), 50 >


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

'

=
n
8
2.285
----------------------- 1 + =
4 Special Topics
4-8
The r ipple in t he passband is r oughly t he same as t he r ipple in t he st opband.
As you can see fr om t he fr equency r esponse, t his filt er near ly meet s t he
specificat ions.
[H,f] = freqz(h,1,512,2);
plot(f,20*log10(abs(H))), grid
For det ails on kaiserord, see t he r efer ence descr ipt ion in Chapt er 6.
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
Windows
4-9
Chebyshev Window
The Chebyshev window minimizes t he mainlobe widt h, given a par t icular
sidelobe height . It is char act er ized by an equir ipple behavior , t hat is, it s
sidelobes all have t he same height . The chebwin funct ion, wit h lengt h and
sidelobe height par amet er s, comput es a Chebyshev window.
n = 51;
Rs = 40; % sidelobe height in decibels
w = chebwin(n,Rs);
stem(w)
As shown in t he plot , t he Chebyshev window has lar ge spikes at it s out er
samples.
Plot t he fr equency r esponse t o see t he equir ipples at -40 dB.
[W,f] = freqz(w,1,512,2);
plot(f,20*log10(abs(W)/sum(w))), grid
For a det ailed discussion of t he char act er ist ics and applicat ions of t he var ious
window t ypes, see [2] Oppenheim and Schafer , pgs. 444-462, and [3] Par ks and
Bur r us, pgs. 71-73.
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
4 Special Topics
4-10
Parametric Modeling
Par amet r ic modeling t echniques find t he par amet er s for a mat hemat ical model
descr ibing a signal, syst em, or pr ocess. These t echniques use known
infor mat ion about t he syst em t o det er mine t he model. Applicat ions for
par amet r ic modeling include speech and music synt hesis, dat a compr ession,
high-r esolut ion spect r al est imat ion, communicat ions, manufact ur ing, and
simulat ion.
The t oolbox par amet r ic modeling funct ions oper at e wit h t he r at ional t r ansfer
funct ion model. Given appr opr iat e infor mat ion about an unknown syst em
(impulse or fr equency r esponse dat a, or input and out put sequences), t hese
funct ions find t he coefficient s of a linear syst em t hat models t he syst em.
One impor t ant applicat ion of t he par amet r ic modeling funct ions is in t he
design of filt er s t hat have a pr escr ibed t ime or fr equency r esponse. These
funct ions pr ovide a dat a-or ient ed alt er nat ive t o t he IIR and FIR filt er design
funct ions discussed in Chapt er 2.
Her e is a summar y of t he par amet r ic modeling funct ions in t his t oolbox. Not e
t hat t he Syst em Ident ificat ion Toolbox pr ovides a mor e ext ensive collect ion of
par amet r ic modeling funct ions.
Parametric Modeling
4-11
Because yulewalk is gear ed explicit ly t owar d ARMA filt er design, it is
discussed in Chapt er 2. pburg and pyulear ar e discussed in Chapt er 3 along
wit h t he ot her (nonpar amet r ic) spect r al est imat ion met hods.
Time-Domain Based Modeling
The lpc, prony, and stmcb funct ions find t he coefficient s of a digit al r at ional
t r ansfer funct ion t hat appr oximat es a given t ime-domain impulse r esponse.
The algor it hms differ in complexit y and accur acy of t he r esult ing model.
Domain Functions Description
Time arburg Gener at e all-pole filt er coefficient s t hat model an input dat a
sequence using t he Levinson-Dur bin algor it hm.
arcov Gener at e all-pole filt er coefficient s t hat model an input dat a
sequence by minimizing t he for war d pr edict ion er r or.
armcov Gener at e all-pole filt er coefficient s t hat model an input dat a
sequence by minimizing t he for war d and backwar d pr edict ion
er r or s.
aryule Gener at e all-pole filt er coefficient s t hat model an input dat a
sequence using an est imat e of t he aut ocor r elat ion funct ion.
lpc,
levinson
Linear Pr edict ive Coding. Gener at e all-pole r ecur sive filt er whose
impulse r esponse mat ches a given sequence.
prony Gener at e IIR filt er whose impulse r esponse mat ches a given
sequence.
stmcb Find IIR filt er whose out put , given a specified input sequence,
mat ches a given out put sequence.
Fr equency invfreqz,
invfreqs
Gener at e digit al or analog filt er coefficient s given complex
fr equency r esponse dat a.
4 Special Topics
4-12
Linear Prediction
Linear pr edict ion modeling assumes t hat each out put sample of a signal, x(k),
is a linear combinat ion of t he past n out put s (t hat is, it can be linear ly
pr edict ed fr om t hese out put s), and t hat t he coefficient s ar e const ant fr om
sample t o sample.
An nt h-or der all-pole model of a signal x is
a = lpc(x,n)
To illust r at e lpc, cr eat e a sample signal t hat is t he impulse r esponse of an
all-pole filt er wit h addit ive whit e noise.
randn('seed',0)
x = impz(1,[1 0.1 0.1 0.1 0.1],10) + randn(10,1)/10;
The coefficient s for a four t h-or der all-pole filt er t hat models t he syst em ar e
a = lpc(x,4)
a =
1.0000 0.0395 0.0338 0.0668 0.1264
lpc fir st calls xcorr t o find a biased est imat e of t he cor r elat ion funct ion of x,
and t hen uses t he Levinson-Dur bin r ecur sion, implement ed in t he levinson
funct ion, t o find t he model coefficient s a. The Levinson-Dur bin r ecur sion is a
fast algor it hm for solving a syst em of symmet r ic Toeplit z linear equat ions.
lpcs ent ir e algor it hm for n = 4 is
r = xcorr(x);
r(1:length(x)1) = []; % remove corr. at negative lags
a = levinson(r,4)
a =
1.0000 0.0395 0.0338 0.0668 0.1264
x k ( ) a 2 ( )x k 1 ( ) a 3 ( )x k 2 ( ) L a n 1 + ( )x k n ( ) =
Parametric Modeling
4-13
You could for m t he linear pr edict ion coefficient s wit h ot her assumpt ions by
passing a differ ent cor r elat ion est imat e t o levinson, such as t he unbiased
cor r elat ion est imat e.
r = xcorr(x,'unbiased');
r(1:length(x)1) = []; % remove corr. at negative lags
a = levinson(r,4)
a =
1.0000 0.0554 0.0462 0.0974 0.2115
Pronys Method (ARMA Modeling)
The prony funct ion models a signal using a specified number of poles and zer os.
Given a sequence x and numer at or and denominat or or der s nb and na,
r espect ively, t he st at ement
[b,a] = prony(x,nb,na)
finds t he numer at or and denominat or coefficient s of an IIR filt er whose
impulse r esponse appr oximat es t he sequence x.
prony implement s t he met hod descr ibed in [3] Par ks and Bur r us
(pgs. 226-228). This met hod uses a var iat ion of t he covar iance met hod of AR
modeling t o find t he denominat or coefficient s a, and t hen finds t he numer at or
coefficient s b for which t he r esult ing filt er s impulse r esponse mat ches exact ly
t he fir st nb + 1 samples of x. The filt er is not necessar ily st able, but it can
pot ent ially r ecover t he coefficient s exact ly if t he dat a sequence is t r uly an
aut or egr essive moving aver age (ARMA) pr ocess of t he cor r ect or der .
NOTE The funct ions prony and stmcb (descr ibed next ) ar e mor e accur at ely
descr ibed as ARX models in syst em ident ificat ion t er minology. ARMA
modeling assumes noise only at t he input s, while ARX assumes an ext er nal
input . prony and stmcb know t he input signal: it is an impulse for prony and
is ar bit r ar y for stmcb.
4 Special Topics
4-14
A model for t he t est sequence x (fr om t he ear lier lpc example) using a
t hir d-or der IIR filt er is
[b,a] = prony(x,3,3)
b =
1.1165 0.2181 0.6084 0.5369
a =
1.0000 0.1619 0.4765 0.4940
The impz command shows how well t his filt er s impulse r esponse mat ches t he
or iginal sequence.
format long
[x impz(b,a,10)]
ans =
1.11649535105007 1.11649535105007
0.03731609173676 0.03731609173676
0.08249198453223 0.08249198453223
0.04583930972315 0.04583930972315
0.14255125351637 0.02829072973977
0.20400424807471 0.01433198229497
0.02685697779814 0.01148698991026
0.18956307836948 0.02266475846451
0.02717716288172 0.00206242734272
0.08057060786906 0.00545783754743
Not ice t hat t he fir st four samples mat ch exact ly. For an example of exact
r ecover y, r ecover t he coefficient s of a But t er wor t h filt er fr om it s impulse
r esponse.
[b,a] = butter(4,.2);
h = impz(b,a,26);
[bb,aa] = prony(h,4,4);
Tr y t his example; youll see t hat bb and aa mat ch t he or iginal filt er coefficient s
t o wit hin a t oler ance of 10
-13
.
Parametric Modeling
4-15
Steiglitz-McBride Method (ARMA Modeling)
stmcb det er mines t he coefficient s for t he syst em b(z)/a(z) given an appr oximat e
impulse r esponse x, as well as t he desir ed number of zer os and poles. This
funct ion ident ifies an unknown syst em based on bot h input and out put
sequences t hat descr ibe t he syst ems behavior , or just t he impulse r esponse of
t he syst em. In it s default mode, stmcb wor ks like prony
[b,a] = stmcb(x,3,3)
b =
1.1165 0.6213 0.8365 1.3331
a =
1.0000 0.5401 0.6109 1.1298
stmcb also finds syst ems t hat mat ch given input and out put sequences
y = filter(1,[1 1],x); % Create an output signal.
[b,a] = stmcb(y,x,0,1)
b =
1
a =
1 1
In t his example, stmcb cor r ect ly ident ifies t he syst em used t o cr eat e y fr om x.
The St eiglit z-McBr ide met hod is a fast it er at ive algor it hm t hat solves for t he
numer at or and denominat or coefficient s simult aneously in an at t empt t o
minimize t he signal er r or bet ween t he filt er out put and t he given out put
signal. This algor it hm usually conver ges r apidly, but might not conver ge if t he
model or der is t oo lar ge. As for prony, stmcbs r esult ing filt er is not necessar ily
st able due t o it s exact modeling appr oach.
stmcb pr ovides cont r ol over sever al impor t ant algor it hmic par amet er s; modify
t hese par amet er s if you ar e having t r ouble modeling t he dat a. To change t he
number of it er at ions fr om t he default of five and pr ovide an init ial est imat e for
t he denominat or coefficient s
n = 10; % number of iterations
a = lpc(x,3); % initial estimates for denominator
[b,a] = stmcb(x,3,3,n,a);
4 Special Topics
4-16
The funct ion uses an all-pole model cr eat ed wit h prony as an init ial est imat e
when you do not pr ovide one of your own.
To compar e t he funct ions lpc, prony, and stmcb, comput e t he signal er r or in
each case
a1 = lpc(x,3);
[b2,a2] = prony(x,3,3);
[b3,a3] = stmcb(x,3,3);
[ ximpz(1,a1,10) ximpz(b2,a2,10) ximpz(b3,a3,10) ]
ans =
0.1165 0 0
0.0058 0 0.0190
0.0535 0.0000 0.0818
0.0151 0.0000 0.0176
0.1473 0.1143 0.0476
0.2005 0.1897 0.0869
0.0233 0.0154 0.0103
0.1901 0.1669 0.0093
0.0275 0.0251 0.0294
0.0808 0.0751 0.0022
sum(ans.^2)
ans =
0.1226 0.0834 0.0182
In compar ing modeling capabilit ies for a given or der IIR model, t he last r esult
shows t hat for t his example, stmcb per for ms best , followed by prony, t hen lpc.
This r elat ive per for mance is t ypical of t he modeling funct ions.
Frequency-Domain Based Modeling
The invfreqs and invfreqz funct ions implement t he inver se oper at ions of
freqs and freqz; t hey find an analog or digit al t r ansfer funct ion of a specified
or der t hat mat ches a given complex fr equency r esponse. Though t he following
examples demonst r at e invfreqz, t he discussion also applies t o invfreqs.
Parametric Modeling
4-17
To r ecover t he or iginal filt er coefficient s fr om t he fr equency r esponse of a
simple digit al filt er
[b,a] = butter(4,.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 resp.
[bb,aa] = invfreqz(h,w,4,4) % model: nb = 4, na = 4
bb =
0.0466 0.1863 0.2795 0.1863 0.0466
aa =
1.0000 0.7821 0.6800 0.1827 0.0301
The vect or of fr equencies w has t he unit s in r ads/sample, and t he fr equencies
need not be equally spaced. invfreqz finds a filt er of any or der t o fit t he
fr equency dat a; a t hir d-or der example is
[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
Bot h invfreqs and invfreqz design filt er s wit h r eal coefficient s; for a dat a
point at posit ive fr equency f, t he funct ions fit t he fr equency r esponse at bot h f
and f.
4 Special Topics
4-18
By default invfreqz uses an equat ion er r or met hod t o ident ify t he best model
fr om t he dat a. This finds b and a in
by cr eat ing a syst em of linear equat ions and solving t hem wit h MATLABs \
oper at or . Her e A(w(k)) and B(w(k)) ar e t he Four ier t r ansfor ms of t he
polynomials a and b r espect ively at t he fr equency w(k), and n is t he number of
fr equency point s (t he lengt h of h and w). wt (k) weight s t he er r or r elat ive t o t he
er r or at differ ent fr equencies. The synt ax
invfreqz(h,w,nb,na,wt)
includes a weight ing vect or . In t his mode, t he filt er r esult ing fr om invfreqz is
not guar ant eed t o be st able.
invfreqz pr ovides a super ior (out put -er r or ) algor it hm t hat solves t he dir ect
pr oblem of minimizing t he weight ed sum of t he squar ed er r or bet ween t he
act ual fr equency r esponse point s and t he desir ed r esponse
To use t his algor it hm, specify a par amet er for t he it er at ion count aft er t he
weight vect or par amet er
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
min
b a ,
wt k ( ) h k ( )A w k ( ) ( ) B w k ( ) ( )
2
k 1 =
n

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

Parametric Modeling
4-19
The r esult ing filt er is always st able. Gr aphically compar e t he r esult s of t he
fir st and second algor it hms t o t he or iginal But t er wor t h filt er .
[H1,w1] = freqz(b,a,'magnitude','linear','phase','no');
[H2,w2] = freqz(bb,aa,'magnitude','linear','phase','no');
[H3,w3] = freqz(bbb,aaa,'magnitude','linear','phase','no');
plot(w1/pi,abs(H1),w2/pi,abs(H2),'--',w3/pi,abs(H3),':')
legend('Original','First Estimate','Second Estimate');
grid on
To ver ify t he super ior it y of t he fit numer ically
sum(abs(hfreqz(bb,aa,w)).^2) % total error, algorithm 1
ans =
0.0200
sum(abs(hfreqz(bbb,aaa,w)).^2) % total error, algorithm 2
ans =
0.0096
0 0.2 0.4 0.6 0.8 1
0
0.2
0.4
0.6
0.8
1
1.2
1.4
Original
First Estimate
Second Estimate
4 Special Topics
4-20
Resampling
The t oolbox pr ovides a number of funct ions t hat r esample a signal at a higher
or lower r at e.
The resample funct ion changes t he sampling r at e for a sequence t o any r at e
t hat is a r at io of t wo int eger s. The basic synt ax for resample is
y = resample(x,p,q)
wher e t he funct ion r esamples t he sequence x at p/q t imes t he or iginal
sampling r at e. The lengt h of t he r esult y is p/q t imes t he lengt h of x.
One r esampling applicat ion is t he conver sion of digit ized audio signals fr om
one sampling r at e t o anot her , such as fr om 48 kHz (t he Digit al Audio Tape
st andar d) t o 44.1 kHz (t he Compact Disc st andar d). In t he next example, t he
sampling r at es ar e differ ent but t he idea is t he same.
Operation Function
Resample at new r at e resample
Decimat ion decimate
Int er polat ion interp
Apply FIR filt er wit h r esampling upfirdn
Cubic spline int er polat ion spline
Ot her 1-D int er polat ion interp1
Resampling
4-21
The example file cont ains a lengt h 4001 vect or of speech sampled 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
Fs
Fs =
7418
To play t his speech signal on a wor kst at ion t hat can only play sound at 8192
Hz, use t he rat funct ion t o find int eger s p and q t hat yield t he cor r ect
r esampling fact or .
[p,q] = rat(8192/Fs,.0001)
p =
127
q =
115
Since p/q*Fs = 8192.05 Hz, t he t oler ance of 0.0001 is accept able; t o r esample
t he signal at ver y close t o 8192 Hz.
y = resample(mtlb,p,q);
resample applies a lowpass filt er t o t he input sequence t o pr event aliasing
dur ing r esampling. It designs t his filt er using t he firls funct ion wit h a Kaiser
window. The synt ax
resample(x,p,q,l,beta)
cont r ols t he filt er s lengt h and t he bet a par amet er of t he Kaiser window.
Alt er nat ively, use t he funct ion intfilt t o design an int er polat ion filt er b and
use it wit h
resample(x,p,q,b)
4 Special Topics
4-22
The decimate and interp funct ions do t he same t hing as resample wit h p = 1
and q = 1, r espect ively. These funct ions pr ovide differ ent ant i-alias filt er ing
opt ions, and t hey incur a slight signal delay due t o filt er ing. The interp
funct ion is significant ly less efficient t han t he resample funct ion wit h q = 1.
The t oolbox also cont ains a funct ion, upfirdn, t hat applies an FIR filt er t o an
input sequence and out put s t he filt er ed sequence at a differ ent sample r at e
t han it s or iginal r at e. See Mult ir at e Filt er Bank Implement at ion on page
1-19 and t he r efer ence descr ipt ion of upfirdn in Chapt er 6 for mor e det ails.
The st andar d MATLAB envir onment cont ains a funct ion, spline, t hat wor ks
wit h ir r egular ly spaced dat a. The MATLAB funct ion interp1 per for ms
int er polat ion, or t able lookup, using var ious met hods including linear and
cubic int er polat ion. See t he online MATLAB Function Reference for
infor mat ion on spline and interp1.
Cepstrum Analysis
4-23
Cepstrum Analysis
Cepst r um analysis is a nonlinear signal pr ocessing t echnique wit h a var iet y of
applicat ions in ar eas such as speech and image pr ocessing. The Signal
Pr ocessing Toolbox pr ovides t hr ee funct ions for cepst r um analysis.
The complex cepst r um for a sequence x is calculat ed by finding t he complex
nat ur al logar it hm of t he Four ier t r ansfor m of x, t hen t he inver se Four ier
t r ansfor m of t he r esult ing sequence.
The t oolbox funct ion cceps per for ms t his oper at ion, est imat ing t he complex
cepst r um for an input sequence. It r et ur ns a r eal sequence t he same size as t he
input sequence
xhat = cceps(x)
The complex cepst r um t r ansfor mat ion is cent r al t o t he t heor y and applicat ion
of homomorphic systems, t hat is, syst ems t hat obey cer t ain gener al r ules of
super posit ion. See [2] Oppenheim and Schafer for a discussion of t he complex
cepst r um and homomor phic t r ansfor mat ions, wit h det ails on speech pr ocessing
applicat ions.
Tr y using cceps in an echo det ect ion applicat ion. Fir st , cr eat e a 45 Hz sine
wave sampled at 100 Hz
t = 0:0.01:1.27;
s1 = sin(2*pi*45*t);
Operation Function
Complex cepst r um cceps
Real cepst r um rceps
Inver se complex cepst r um icceps
x
1
2
------ X e
j
( ) [ ] log e
j n
d

=
4 Special Topics
4-24
Add an echo of t he signal, wit h half t he amplit ude, 0.2 seconds aft er t he
beginning of t he signal.
s2 = s1 + 0.5*[zeros(1,20) s1(1:108)];
The complex cepst r um of t his new signal is
c = cceps(s2);
plot(t,c)
Not e t hat t he complex cepst r um shows a peak at 0.2 seconds, indicat ing t he
echo.
The real cepstrum of a signal x, somet imes called simply t he cepst r um, is
calculat ed by det er mining t he nat ur al logar it hm of magnit ude of t he Four ier
t r ansfor m of x, t hen obt aining t he inver se Four ier t r ansfor m of t he r esult ing
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
( ) log e
j n
d

=
Cepstrum Analysis
4-25
The t oolbox funct ion rceps per for ms t his oper at ion, r et ur ning t he r eal
cepst r um for a sequence x. The r et ur ned sequence is a r eal-valued vect or t he
same size as t he input vect or .
y = rceps(x)
By definit ion, you cannot r econst r uct t he or iginal sequence fr om it s r eal
cepst r um t r ansfor mat ion, as t he r eal cepst r um is based only on t he magnit ude
of t he Four ier t r ansfor m for t he sequence (see [2]). The rceps funct ion,
however , can r econst r uct a minimum-phase ver sion of t he or iginal sequence by
applying a windowing funct ion in t he cepst r al domain. To obt ain bot h t he r eal
cepst r um and t he minimum phase r econst r uct ion for a sequence, use
[y,ym] = rceps(x)
wher e y is t he r eal cepst r um and ym is t he minimum phase r econst r uct ion of x.
Inverse Complex Cepstrum
To inver t t he complex cepst r um, use t he icceps funct ion. Inver sion is
complicat ed by t he fact t hat t he cceps funct ion per for ms a dat a dependent
phase modificat ion so t hat t he unwr apped phase of it s input is cont inuous at
zer o fr equency. The phase modificat ion is equivalent t o an int eger delay. This
delay t er m is r et ur ned by cceps if you ask for a second out put . For example,
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 Special Topics
4-26
To inver t t he complex cepst r um, use icceps wit h t he or iginal delay par amet er .
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 Wit h any modificat ion of t he complex cepst r um, t he or iginal delay
t er m may no longer be valid. Use t he icceps funct ion wit h car e.
FFT-Based Time-Frequency Analysis
4-27
FFT-Based Time-Frequency Analysis
The Signal Pr ocessing Toolbox pr ovides a funct ion, specgram, t hat r et ur ns t he
t ime-dependent Four ier t r ansfor m for a sequence, or displays t his infor mat ion
as a spect r ogr am. The time-dependent Fourier transform is t he discr et e-t ime
Four ier t r ansfor m for a sequence, comput ed using a sliding window. This for m
of t he Four ier t r ansfor m, also known as t he shor t -t ime Four ier t r ansfor m
(STFT), has numer ous applicat ions in speech, sonar , and r adar pr ocessing. The
spectrogram of a sequence is t he magnit ude of t he t ime-dependent Four ier
t r ansfor m ver sus t ime.
To display t he spect r ogr am of a linear FM signal
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)
Not e t hat t he spect r ogr am display is an image, not a plot .
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 Special Topics
4-28
Median Filtering
The funct ion medfilt1 implement s one-dimensional median filt er ing, a
nonlinear t echnique t hat applies a sliding window t o a sequence. The median
filt er r eplaces t he cent er value in t he window wit h t he median value of all t he
point s wit hin t he window [4]. In comput ing t his median, medfilt1 assumes
zer os beyond t he input point s.
When t he number of element s n in t he window is even, medfilt1 sor t s t he
number s, t hen t akes t he aver age of t he ((n1)/2 & ((n1)/2)+1) element s.
Two simple examples wit h four t h- and t hir d-or der median filt er s ar e
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 t he Image Processing Toolbox Users Guide for infor mat ion on
t wo-dimensional median filt er ing.
Communications Applications
4-29
Communications Applications
The t oolbox pr ovides t hr ee funct ions for communicat ions simulat ion.
Modulation var ies t he amplit ude, phase, or fr equency of a carrier signal wit h
r efer ence t o a message signal. The modulate funct ion modulat es a message
signal wit h a specified modulat ion met hod.
The basic synt ax for t he modulate funct ion is
y = modulate(x,Fc,Fs,'method',opt)
wher e:
x is t he message signal.
Fc is t he car r ier fr equency.
Fs is t he sampling fr equency.
method is a flag for t he desir ed modulat ion met hod.
opt is any addit ional ar gument t hat t he met hod r equir es. (Not all
modulat ion met hods r equir e an opt ion ar gument .)
The t able below summar izes t he modulat ion met hods pr ovided; see Chapt er 6
for complet e det ails on each.
Operation Function
Modulat ion modulate
Demodulat ion demod
Volt age cont r olled oscillat ion vco
Method Description
amdsbsc or am Amplit ude modulat ion, double side-band, suppr essed
car r ier
amdsbtc Amplit ude modulat ion, double side-band, t r ansmit t ed
car r ier
4 Special Topics
4-30
If t he input x is an ar r ay r at her t han a vect or , modulate modulat es each
column of t he ar r ay.
To obt ain t he t ime vect or t hat modulate uses t o comput e t he modulat ed signal,
specify a second out put par amet er .
[y,t] = modulate(x,Fc,Fs,'method',opt)
The demod funct ion per for ms demodulation, t hat is, it obt ains t he or iginal
message signal fr om t he modulat ed signal.
The synt ax for demod is
x = demod(y, Fc,Fs,'method',opt)
demod uses any of t he met hods shown for modulate, but t he synt ax for
quadr at ur e amplit ude demodulat ion r equir es t wo out put par amet er s.
[X1,X2] = demod(y,Fc,Fs,'qam')
If t he input y is an ar r ay, demod demodulat es all columns.
Tr y modulat ing and demodulat ing a signal. A 50 Hz sine wave sampled at 1000
Hz is
t = (0:1/1000:2);
x = sin(2*pi*50*t);
amssb Amplit ude modulat ion, single side-band
fm Fr equency modulat ion
pm Phase modulat ion
ptm Pulse t ime modulat ion
pwm Pulse widt h modulat ion
qam Quadr at ur e amplit ude modulat ion
Method Description
Communications Applications
4-31
Wit h a car r ier fr equency of 200 Hz, t he modulat ed and demodulat ed ver sions
of t his signal ar e
y = modulate(x,200,1000,'am');
z = demod(y,200,1000,'am');
To plot por t ions of t he or iginal, modulat ed, and demodulat ed signal
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');
The volt age cont r olled oscillat or funct ion vco cr eat es a signal t hat oscillat es at
a fr equency det er mined by t he input vect or . The basic synt ax for vco is
y = vco(x,Fc,Fs)
wher e Fc is t he car r ier fr equency and Fs is t he sampling fr equency.
To scale t he fr equency modulat ion r ange
y = vco(x,[Fmin Fmax],Fs)
0 0.05 0.1 0.15
-1
-0.5
0
0.5
1
Original Signal
0 0.05 0.1 0.15
-2
-1
0
1
2
Modulated Signal
0 0.05 0.1
-1
-0.5
0
0.5
1
Demodulated Signal
4 Special Topics
4-32
In t his case, vco scales t he fr equency modulat ion r ange so values of x on t he
int er val [1 1] map t o oscillat ions of fr equency on [Fmin Fmax].
If t he input x is an ar r ay, vco pr oduces an ar r ay whose columns oscillat e
accor ding t o t he columns of x.
See FFT-Based Time-Fr equency Analysis on page 4-27 for an example using
t he vco funct ion.
Deconvolution
4-33
Deconvolution
Deconvolution, or polynomial division, is t he inver se oper at ion of convolut ion.
Deconvolut ion is useful in r ecover ing t he input t o a known filt er , given t he
filt er ed out put . This met hod is ver y sensit ive t o noise in t he coefficient s,
however , so use caut ion in applying it .
The synt ax for deconv is
[q,r] = deconv(b,a)
wher e b is t he polynomial dividend, a is t he divisor , q is t he quot ient , and r is
t he r emainder .
To t r y deconv, fir st convolve t wo simple vect or s a and b (see Chapt er 1 for a
descr ipt ion of t he convolut ion funct ion)
a = [1 2 3];
b = [4 5 6];
c = conv(a,b)
c =
4 13 28 27 18
Now use deconv t o deconvolve b fr om c
[q,r] = deconv(c,a)
q =
4 5 6
r =
0 0 0 0 0
See t he S ystem Identification Toolbox Users Guide for advanced applicat ions
of signal deconvolut ion.
4 Special Topics
4-34
Specialized Transforms
In addit ion t o t he discr et e Four ier t r ansfor m (DFT) descr ibed in Chapt er 1, t he
Signal Pr ocessing Toolbox and t he MATLAB envir onment t oget her pr ovide t he
following t r ansfor m funct ions:
The chir p z-t r ansfor m (CZT), useful in evaluat ing t he z-t r ansfor m along
cont our s ot her t han t he unit cir cle. The chir p z-t r ansfor m is also mor e
efficient t han t he DFT algor it hm for t he comput at ion of pr ime-lengt h
t r ansfor ms, and it is useful in comput ing a subset of t he DFT for a sequence.
The discr et e cosine t r ansfor m (DCT), closely r elat ed t o t he DFT. The DCTs
ener gy compact ion pr oper t ies ar e useful for applicat ions like signal coding.
The Hilber t t r ansfor m, which facilit at es t he for mat ion of t he analyt ic signal.
The analyt ic signal is useful in t he ar ea of communicat ions, par t icular ly in
bandpass signal pr ocessing.
Chirp z-Transform
The chir p z-t r ansfor m, or CZT, comput es t he z-t r ansfor m along spir al cont our s
in t he z-plane for an input sequence. Unlike t he DFT, t he CZT is not
const r ained t o oper at e along t he unit cir cle, but can evaluat e t he z-t r ansfor m
along cont our s descr ibed by
wher e A is t he complex st ar t ing point , W is a complex scalar descr ibing t he
complex r at io bet ween point s on t he cont our , and M is t he lengt h of t he
t r ansfor m.
z
l
AW
l
l 0 M 1 , , = , =
Specialized Transforms
4-35
One possible spir al is
A = 0.8*exp(j*pi/6);
W = 0.995*exp(j*pi*.05);
M = 91;
z = A*(W.^((0:M1)));
zplane([],z.')
czt(x,M,W,A) comput es t he z-t r ansfor m of x on t hese point s.
An int er est ing and useful spir al set is m evenly spaced samples ar ound t he unit
cir cle, par amet er ized by A = 1 and W = exp(j*pi/M). The z-t r ansfor m on t his
cont our is simply t he DFT, obt ained by
y = czt(x)
czt is fast er t han t he fft funct ion for comput ing t he DFT of sequences wit h
cer t ain odd lengt hs, par t icular ly long pr ime-lengt h sequences. (Tr y compar ing
t he execut ion t ime for t he fft and czt funct ions for a sequence of lengt h 1013.)
-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 Special Topics
4-36
Discrete Cosine Transform
The t oolbox funct ion dct comput es t he unit ar y discr et e cosine t r ansfor m, or
DCT, for an input vect or or mat r ix. Mat hemat ically, t he unit ar y DCT of an
input sequence x is
wher e
The DCT is closely r elat ed t o t he discr et e Four ier t r ansfor m; t he DFT is
act ually one st ep in t he comput at ion of t he DCT for a sequence. The DCT,
however , has bet t er energy compaction pr oper t ies, wit h just a few of t he
t r ansfor m coefficient s r epr esent ing t he major it y of t he ener gy in t he sequence.
The ener gy compact ion pr oper t ies of t he DCT make it useful in applicat ions
such as dat a communicat ions.
The funct ion idct comput es t he inver se DCT for an input sequence,
r econst r uct ing a signal fr om a complet e or par t ial set of DCT coefficient s. The
inver se discr et e cosine t r ansfor m is
wher e
y k ( ) w n ( )x n ( )
2n 1 ( ) k 1 ( )
2N
------------------------------------------- cos
n 1 =
N

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

'

=
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 ,

'

=
Specialized Transforms
4-37
Because of t he ener gy compact ion ment ioned above, it is possible t o r econst r uct
a signal fr om only a fr act ion of it s DCT coefficient s. For example, gener at e a 10
Hz sinusoidal sequence, sampled at 1000 Hz.
t = (0:1/999:1);
x = sin(2*pi*25*t);
Comput e t he DCT of t his sequence and r econst r uct t he signal using only t hose
component s wit h value gr eat er t han 53 (12 of t he or iginal 1000 DCT
coefficient s).
y = dct(x); % compute DCT
y2 = find(abs(y) < 53); % use 12 coefs.
y(y2) = zeros(size(y2)); % zero out points < 53
z = idct(y); % reconstruct signal using inverse DCT
Plot t he or iginal and r econst r uct ed sequences.
plot(t,x)
plot(t,z), axis([0 1 1 1])
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
-1
-0.5
0
0.5
1
Original Signal
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
-1
-0.5
0
0.5
1
Reconstructed Signal
4 Special Topics
4-38
One measur e of t he accur acy of t he r econst r uct ion is
norm(xz)/norm(x)
t hat is, t he nor m of t he differ ence bet ween t he or iginal and r econst r uct ed
signals, divided by t he nor m of t he or iginal signal. In t his case, t he r elat ive
er r or of r econst r uct ion is 0.1778. The r econst r uct ed signal r et ains
appr oximat ely 82% of t he ener gy in t he or iginal signal.
Hilbert Transform
The t oolbox funct ion hilbert comput es t he Hilber t t r ansfor m for a r eal input
sequence x and r et ur ns a complex r esult of t he same lengt h
y = hilbert(x)
wher e t he r eal par t of y is t he or iginal r eal dat a and t he imaginar y par t is t he
act ual Hilber t t r ansfor m. y is somet imes called t he analytic signal, in r efer ence
t o t he cont inuous-t ime analyt ic signal. A key pr oper t y of t he discr et e-t ime
analyt ic signal is t hat it s z-t r ansfor m is 0 on t he lower half of t he unit cir cle.
Many applicat ions of t he analyt ic signal ar e r elat ed t o t his pr oper t y; for
example, t he analyt ic signal is useful in avoiding aliasing effect s for bandpass
sampling oper at ions. The magnit ude of t he analyt ic signal is t he complex
envelope of t he or iginal signal.
Specialized Transforms
4-39
The Hilber t t r ansfor m is r elat ed t o t he act ual dat a by a 90 phase shift ; sines
become cosines and vice ver sa. To plot a por t ion of dat a (solid line) and it s
Hilber t t r ansfor m (dot t ed line)
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
The analyt ic signal is useful in calculat ing instantaneous attributes of a t ime
ser ies, t he at t r ibut es of t he ser ies at any point in t ime. The inst ant aneous
amplit ude of t he input sequence is t he amplit ude of t he analyt ic signal. The
inst ant aneous phase angle of t he input sequence is t he (unwr apped) angle of
t he analyt ic signal; t he inst ant aneous fr equency is t he t ime r at e of change of
t he inst ant aneous phase angle. You can calculat e t he inst ant aneous fr equency
using diff, as descr ibed in t he online MATLAB Function Reference.
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 Special Topics
4-40
References
1 Kay, S.M. Modern S pectral Estimation. Englewood Cliffs, NJ : Pr ent ice Hall,
1988.
2 Oppenheim, A.V., and R.W. Schafer . Discrete-Time S ignal Processing.
Englewood Cliffs, NJ : Pr ent ice Hall, 1989.
3 Par ks, T.W., and C.S. Bur r us. Digital Filter Design. New Yor k: J ohn Wiley
& Sons, 1987.
4 Pr at t ,W.K. Digital Image Processing. New Yor k: J ohn Wiley & Sons, 1991.
5
Int er act ive Tools
SPTool: An Interacti ve Si gnal Processi ng Environment . 5-2
Usi ng SPTool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-3
Usi ng t he Si gnal Browser: Interacti ve Si gnal Analysi s . 5-43
Us i ng t he Fi lter Desi gner: Interacti ve Fi lter De si gn . . . 5-59
Us i ng t he Fi lter Viewer: Interactive Fi lt er Analysis . . . 5-84
Us i ng t he Spectrum Vi ewer: Interacti ve PSD Analysi s . 5-97
Example: Generati on of Bandli mi te d Noise . . . . . . . . . . 5-113
5 Interactive Tools
5-2
SPTool: An Interactive Signal Processing Environment
The Signal Pr ocessing Toolbox includes an int er act ive gr aphical user int er face
(GUI), called SPTool, for per for ming digit al signal pr ocessing t asks. SPTool
pr ovides an easy-t o-use int er face t o many of t he most impor t ant t oolbox
funct ions. Wit h it , you can use t he mouse and on-scr een cont r ols t o impor t ,
view, measur e, and pr int digit al signals; design, view, and implement digit al
filt er s; and analyze t he fr equency cont ent of signals.
This chapt er descr ibes how t o use t he differ ent component s of SPTool. Wher e
appr opr iat e, we point you t o ot her ar eas of t he manual t hat descr ibe how t o
per for m similar t asks by calling funct ions fr om t he command line or fr om
M-files.
The sect ion Example: Gener at ion of Bandlimit ed Noise at t he end of t his
chapt er descr ibes how t o use t his gr aphical envir onment for a complet e filt er
design and analysis t ask.
Overview
SPTool is a gr aphical envir onment for analyzing and manipulat ing digit al
signals, filt er s, and spect r a. It is t he st ar t ing point for using t he int er act ive
signal pr ocessing envir onment . In SPTool, you can impor t signals, filt er s, and
spect r a eit her fr om t he wor kspace or as MAT-files. Thr ough SPTool, you access
four addit ional GUI t ools t hat pr ovide an int egr at ed envir onment for signal
br owsing, filt er design, analysis, and implement at ion. The four component s of
t he int er act ive signal pr ocessing envir onment include:
The S ignal Browser, which pr ovides a gr aphical view of t he signal object s
cur r ent ly select ed in SPTool and enables you t o display, measur e, analyze,
and pr int t hese signals int er act ively
The Filter Designer, which enables you t o cr eat e and edit lowpass, highpass,
bandpass, and bandst op FIR and IIR digit al filt er s of var ious lengt hs and
t ypes using t he filt er design funct ions of t he Signal Pr ocessing Toolbox
The Filter Viewer, which enables you t o view var ious char act er ist ics of a
filt er t hat youve impor t ed or designed, including it s magnit ude and phase
r esponses, gr oup delay, zer o-pole plot , and impulse and st ep r esponses
The S pectrum Viewer, which enables you t o cr eat e, view, modify, and pr int
spect r a int er act ively, and t o per for m gr aphical analysis of fr equency domain
dat a using a var iet y of common met hods of spect r al est imat ion
Using SPTool
5-3
Using SPTool
SPTool is t he dat a management t ool for t he int er act ive GUI envir onment of t he
Signal Pr ocessing Toolbox. Using SPTool you can:
Load a saved session
Impor t a signal, filt er , or spect r um
Duplicat e or clear a signal, filt er , or spect r um
Change t he name of a signal, filt er , or spect r um
Change t he sampling fr equency of a signal or filt er
Act ivat e t he Signal Br owser , Filt er Viewer , Filt er Designer , or Spect r um
Viewer
Save a session
Use t he Wi ndow menu t o change t o any open MATLAB figur e window
Opening SPTool
Open SPTool fr om t he MATLAB command window by t yping
sptool
and pr essing Enter.
Quick Start
Once SPTool is open, you can impor t dat a fr om t he wor kspace or a file. You can
t hen view it in t he Signal Br owser or gener at e it s spect r um in t he Spect r um
Viewer .
To get st ar t ed r ight away, wor k t hr ough t he following example. Then cont inue
t hr ough t his chapt er t o lear n t he det ails of using SPTool and it s component
t ools.
Or , you can skip t he example, r ead t hr ough t he r est of t his sect ion (fr om Basic
SPTool Funct ions t o Using t he Signal Br owser : Int er act ive Signal Analysis),
and t hen wor k t hr ough t he example.
Example: Importing Signal Data from a MAT-File
This example uses t he sample file mtlb.mat, which is in t he
toolbox/signal/signal dir ect or y.
5 Interactive Tools
5-4
1 Select Import fr om t he Fi le menu.
The Import to SPTool window is displayed.
2 Make sur e t hat Si gnal is displayed in t he Import As pop-up menu.
3 Pr ess t he From Di s k r adio but t on.
You can eit her ent er a MAT-file name or pr ess Brows e t o open t he file dialog
box and select a MAT-file.
4 To get st ar t ed, t ype t he file name mtlb and pr ess Tab or Enter. Not e t hat
SPTool adds t he .mat ext ension aut omat ically.
The dat a fr om t he file you select ed is displayed in t he Fi le Conte nts list . In
t his example, mtlb is t he signal dat a and Fs is t he sampling fr equency.
Not ice t hat sig1 is displayed in t he Name field. This is t he default name of
t he impor t ed signal.
5 Click on mtlb t o select it , and t hen pr ess t he ar r ow at t he left of t he Data
field. mtlb is t r ansfer r ed t o t he Data field.
6 Click on Fs t o select it , and t hen pr ess t he ar r ow at t he left of t he Sampli ng
Fre quency field.
Fs is t r ansfer r ed t o t he Sampli ng Fre quency field.
Using SPTool
5-5
7 Pr ess OK.
The signal has been impor t ed int o SPTool wit h t he name sig1.
You can look at t his signal in t he Signal Br owser by pr essing t he Vi ew but t on
under Si gnals .
You can look at t he fr equency cont ent of t he signal in t he Spect r um Viewer by
pr essing t he Cre ate but t on under Spectra and t hen pr essing Apply in t he
Spect r um Viewer .
Basic SPTool Functions
When you fir st open SPTool, it cont ains a collect ion of default signals, filt er s,
and spect r a. You can impor t addit ional signals, filt er s, and spect r a int o SPTool,
and you can also design filt er s using t he Filt er Designer and cr eat e spect r a
using t he Spect r um Viewer . You can save and expor t dat a fr om SPTool and
cust omize many pr oper t ies of t he SPTool envir onment . The following figur e
shows t he SPTool window and it s Fi le and Help menus, which ar e descr ibed
below.
5 Interactive Tools
5-6
File Menu
Open Session. Select Ope n Se ss i onfr om t he Fi le menu t o load a saved session
file. An SPTool session is saved in a file wit h an .spt ext ension.
Import. Select Import fr om t he Fi le menu t o impor t a signal, filt er , or
spect r um int o SPTool fr om eit her t he wor kspace or fr om a file. You can impor t
var iables fr om any MAT-file int o SPTool. See Impor t ing Signals, Filt er s, and
Spect r a on page 5-7 and Example: Impor t ing Signal Dat a fr om a MAT-File
on page 5-3 for mor e infor mat ion.
Export. Select Export fr om t he Fi le menu t o expor t signals, filt er s, and
spect r a t o t he MATLAB wor kspace as st r uct ur e var iables. See Saving Signal
Dat a on page 5-57, Saving Filt er Dat a on page 5-79, and Saving Spect r um
Dat a on page 5-110 for complet e infor mat ion.
Save Session. Select Save Ses s i on and Save Ses si on As fr om t he Fi le menu
t o save t he cur r ent session. Save Ses si on over wr it es t he exist ing session file.
Save Ses si on As saves t he cur r ent session wit h a name you specify. An
SPTool session is saved in a MAT-file wit h an .spt ext ension.
Preferences. Select Prefere nces fr om t he Fi le menu t o cust omize pr efer ences
for t he behavior of all t he Signal Pr ocessing GUI t ools. See Cust omizing
Pr efer ences on page 5-20 for a complet e discussion.
Close. Select Clos e fr om t he Fi le menu t o close SPTool and all ot her act ive
Signal Pr ocessing GUI t ools. SPTool pr ompt s you t o save if you have not
r ecent ly saved t he cur r ent session.
When you close SPTool, all signal and filt er cust omizat ion and r uler
infor mat ion set in any of t he GUI t ools ar e lost . Set t ings you changed and saved
using t he Pre fe rence s dialog box in SPTool ar e used t he next t ime you open
SPTool.
Help Menu
Overview Select Ove rvi e w fr om t he Fi le menu t o get gener al help on
SPTool and t he Signal Pr ocessing Toolbox GUI envir onment . This also gives
you access t o t he MATLAB Help Desk.
Using SPTool
5-7
Context Sensitive Select Conte xt Sensi ti ve fr om t he Fi le menu for help on a
specific par t of SPTool. When you click on Context Sensi ti ve, t he mouse
point er becomes an ar r ow wit h a quest ion mar k symbol. You can t hen click on
anyt hing in SPTool, including menu it ems, t o find out what it is and how t o use
it .
Importing Signals, Filters, and Spectra
You can impor t a signal, filt er , or spect r um int o SPTool fr om eit her t he
wor kspace or fr om a file.
Select Import fr om t he Fi le menu t o open t he Import to SPTool window:
Loading Variables from the MATLAB Workspace
To impor t var iables fr om t he MATLAB wor kspace, fir st list t he wor kspace
var iables in t he Workspace Contents list . Then select t he var iables t o be
impor t ed int o SPTool:
Load the contents of a file into the File Contents list by clicking here, and
either typing a filename in the box and pressing Tab or Enter, or pressing
Browse and selecting a MAT-file.
Display all MATLAB workspace variables in the
Workspace Contents list box by clicking here.
Workspace Contents
or File Contents list.
5 Interactive Tools
5-8
1 Click t he From Works pace r adio but t on.
The cont ent s of t he MATLAB wor kspace ar e displayed in t he Workspace
Contents list .
2 You can now impor t one or mor e var iables fr om t he Works pace Conte nts
list int o SPTool. See Impor t ing Wor kspace Cont ent s and File Cont ent s
below.
Loading Variables from Disk
To impor t var iables fr om a MAT-file on disk, fir st list t he files var iables in t he
Fi le Contents list . Then select t he var iables t o be impor t ed int o SPTool:
1 Click t he From Di sk r adio but t on.
2 Type t he name of t he file you want t o impor t int o t he MAT-fi le Name field
and pr ess Tab or Enter.
or
Pr ess Browse , and t hen find and select t he file you want t o impor t using t he
File Sear ch window. Pr ess OK.
The dat a fr om t he file you select ed is displayed in t he Fi le Conte nts list .
3 You can now impor t one or mor e var iables fr om t he Fi le Conte nts list int o
SPTool (see below).
Importing Workspace Contents and File Contents
Once youve loaded t he cont ent s of t he wor kspace or a file int o t he Works pace
Conte nts or Fi le Conte nts list , you can select one or mor e var iables fr om t he
list t o impor t int o SPTool. You can impor t a var iable as a signal, a filt er , or a
spect r um. You can also impor t a var iable whose value r epr esent s a sampling
fr equency or ot her design par amet er .
Depending on whet her your e impor t ing a signal, a filt er , or a spect r um, you
can cust omize differ ent par amet er s befor e you impor t t he dat a int o SPTool. In
each case, however , t he gener al pr ocedur e for specifying a var iable or a value
is t he same. In t he following example, t he select ed var iable is being impor t ed
as a signal. See Impor t ing a Signal on page 5-10, Impor t ing a Filt er on page
Using SPTool
5-9
5-11, and Impor t ing a Spect r um on page 5-13 for det ails on cust omizing
var iables t hat ar e impor t ed int o SPTool.
1 Click on a var iable name in t he Works pace Conte nts list or t he
Fi le Contents list t o select it .
If t he var iable is not a saved dat a object fr om SPTool, select t he appr opr iat e
dat a t ype (Si gnal, Fi lter, or Spectrum) fr om t he Import As pop-up menu
and t ype a name int o t he Name field.
If t he var iable is a saved dat a object fr om SPTool, it s name is displayed in
t he Name field, and it s t ype (Si gnal, Fi lter, or Spe ctrum) is aut omat ically
select ed in t he Import As pop-up menu.
2 Pr ess t he ar r ow at t he left of t he Data field. The select ed var iable is
t r ansfer r ed t o t he Data field.
NOTE You can also t ype a var iable name int o t he Data field dir ect ly.
3 To change t he sampling fr equency of t he var iable your e impor t ing, you can
eit her :
a Click on a var iable in t he Works pace Contents list or Fi le Contents list
whose value is a sampling fr equency, and t hen pr ess t he ar r ow at t he left
of t he Sampli ng Frequency field.
The select ed var iable is t r ansfer r ed t o t he Sampli ng Frequency field.
or
b Type a value or var iable name in t he Sampli ng Freque ncy field.
5 Interactive Tools
5-10
4 Pr ess OK.
The signal is impor t ed int o SPTool wit h t he specified name and sampling
fr equency.
5 To impor t anot her var iable, select Import again, pr ess t he From
Workspace or From Fi le r adio but t on, and r epeat st eps 1 t hr ough 4 for each
var iable t hat you want t o load int o SPTool.
NOTE When your e impor t ing fr om t he wor kspace, you can specify eit her a
var iable or a value for each dat a field. When your e impor t ing fr om a disk, you
can only specify var iables.
Importing a Signal. When you impor t a signal, you specify:
A var iable name for t he signal dat a (or t he signal dat a values) in t he Data
field
A var iable or a value for t he signals sampling fr equency in t he Sampli ng
Frequency field
Using SPTool
5-11
Importing a Filter. When you impor t a filt er , fir st select t he appr opr iat e filt er
for m fr om t he Form pop-up menu.
Each filt er for m r equir es differ ent var iables.
For Trans fer Functi on, you specify t he filt er by it s t r ansfer funct ion
r epr esent at ion:
- The Nume rator field specifies a var iable name or value for t he numer at or
coefficient vect or b, which cont ains m+1 coefficient s in descending power s
of z.
- The De nomi nator field specifies a var iable name or value for t he
denominat or coefficient vect or a, which cont ains n+1 coefficient s in
descending power s of z.
For State Space, you specify t he filt er by it s st at e-space r epr esent at ion:
The A-Matri x, B-Matri x, C-Matri x, and D-Matri x fields specify a var iable
name or a value for each mat r ix in t his syst em.
For Ze ros , Poles, Gai n, you specify t he filt er by it s zer o-pole-gain
r epr esent at ion:
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 + =
5 Interactive Tools
5-12
- The Zeros field specifies a var iable name or value for t he zer os vect or z,
which cont ains t he locat ions of m zer os.
- The Poles field specifies a var iable name or value for t he zer os vect or p,
which cont ains t he locat ions of n poles.
- The Gai n field specifies a var iable name or value for t he gain k.
For 2nd Order Secti ons you specify t he filt er by it s second-or der sect ion
r epr esent at ion:
The SOS Matri x field specifies a var iable name or a value for t he L-by-6 SOS
mat r ix
whose r ows cont ain t he numer at or and denominat or coefficient s b
ik
and a
ik
of t he second-or der sect ions of H(z):
For ever y filt er , you specify:
A var iable name or a value for t he filt er s sampling fr equency in t he
Sampli ng Fre quency field
H z ( )
Z z ( )
P z ( )
---------- k
z z 1 ( ) ( ) z z 2 ( ) ( )Lz z m ( ) ( )
z p 1 ( ) ( ) z p 2 ( ) ( )Lz p 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

= =
s os
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
=
Using SPTool
5-13
Importing a Spectrum. When you impor t a spect r um, you specify:
A var iable name or a value for t he power spect r al densit y (PSD) vect or in t he
PSD field
A var iable name or a value for t he fr equency vect or in t he Freq. Ve ctor field
The PSD values in t he PSD vect or cor r espond t o t he fr equencies cont ained
in t he Freq. Ve ctor vect or ; t he t wo vect or s must have t he same lengt h.
Working with Signals, Filters, and Spectra
When a signal, filt er , or spect r um is impor t ed int o SPTool or cr eat ed in SPTool,
it is displayed in t he appr opr iat e list box, as shown below. Using t he Edi t menu
funct ions and SPTool but t ons, you can edit var ious pr oper t ies of t he dat a in
SPTool and invoke all of SPTools digit al signal pr ocessing funct ions.
5 Interactive Tools
5-14
Component Lists in SPTool
Each signal, filt er , and spect r um in SPTool is displayed in t he appr opr iat e
Si gnals list , Fi lters list , or Spectra list .
Signals ar e displayed wit h t he signal type [vector] or [array]:
- A vector signal ([vector]) has one column of dat a.
- An array signal ([array]) has mor e t han one column of dat a.
Filt er s ar e displayed wit h t he filter type [design] or [imported]:
- A designed filter ([design]) is a filt er t hat was cr eat ed using t he Filt er
Designer . This t ype of filt er can also be edit ed in t he Filt er Designer .
- An imported filter ([imported]) is a filt er t hat was impor t ed fr om t he
MATLAB wor kspace or a file, or one t hat was edit ed in t he Pole/Zer o
Edit or .
Spectrum View button Signal View button
Filter View button
Signals list
Filters list
Spectra list
Using SPTool
5-15
Spect r a ar e displayed wit h t he spectrum type [auto]:
An auto-spectrum ([auto]) is a spect r um whose sour ce is a single signal, as
opposed t o t he cr oss-spect r um of t wo channels of dat a. spectrum[auto] is t he
only spect r um t ype in SPTool.
Selecting Data Objects in SPTool
Each signal, filt er , and spect r um in SPTool is one dat a object . A dat a object is
select ed when it is highlight ed. When you fir st impor t or cr eat e a dat a object ,
it is select ed.
The Si gnals list shows all vect or and ar r ay signals in t he cur r ent SPTool
session.
The Fi lters list shows all designed and impor t ed filt er s in t he cur r ent SPTool
session.
The Spectra list shows all spect r a in t he cur r ent SPTool session.
You can select a single dat a object in a list , a r ange of dat a object s in a list , or
mult iple separ at e dat a object s in a list . You can also have dat a object s
simult aneously select ed in differ ent list s:
To select a single unselect ed dat a object , click on it . All ot her dat a object s in
t hat list box become unselect ed.
To add or r emove a r ange of dat a object s, Shi ft-click on t he dat a object s at
t he t op and bot t om of t he sect ion of t he list t hat you want t o add.
To add a single dat a object t o a select ion or r emove a single dat a object fr om
a mult iple select ion, Ctrl-click on t he object . You can also use t he r ight
mouse but t on.
Editing Data Objects in SPTool
The Edi t menu ent r ies ar e available only when t her e is at least one select ed
dat a object (signal, filt er , or spect r um) in SPTool. Use t he Edi t menu t o
duplicat e and clear object s in SPTool and t o edit object names and change
sampling fr equencies.
A signal, filt er , or spect r um must be select ed t o be edit ed. When you click on an
Edi t menu ent r y, all selected dat a object s ar e displayed in a pop-up menu.
5 Interactive Tools
5-16
To edit an SPTool object :
1 Select a signal, filt er , or spect r um.
2 Select t he appr opr iat e Edi t menu funct ion.
The pop-up menu shows t he names of all select ed dat a object s.
3 Dr ag t o choose a specific signal, filt er , or spect r um for edit ing.
Duplicate. Use Dupli cate fr om t he Edi t menu t o make a copy of t he select ed
signal, filt er , or spect r um in SPTool.
Select Dupli cate and dr ag t o choose t he signal, filt er , or spect r um you want t o
copy. When you select a dat a object t o duplicat e it , a new dat a object of t he
same t ype is aut omat ically cr eat ed. The new dat a object is named as a copy of
t he select ed dat a object . It is placed at t he bot t om of t he list and is select ed. You
can change it s name using Name fr om t he Edi t menu.
Clear. Use Cle ar fr om t he Edi t menu t o delet e t he select ed signal, filt er , or
spect r um fr om SPTool.
Select Cle ar and dr ag t o choose t he signal, filt er , or spect r um you want t o
r emove. The dat a object is delet ed fr om t he cur r ent SPTool session.
Name. Use Name fr om t he Edi t menu t o give t he select ed signal, filt er , or
spect r um a new, unique name.
1 Select Name... and dr ag t o choose t he signal, filt er , or spect r um you want t o
r ename.
The Name Change dialog box is displayed.
2 Type in t he new name and pr ess OK.
Sampling Frequency. Use Sampli ng Frequency fr om t he Edi t menu t o supply
a sampling fr equency for a select ed signal or filt er . The sampling fr equency
may be a number , such as 1, 0.001, or 1/5000, or a valid MATLAB expr ession
including wor kspace var iables, such as Fs, 1/Ts, or cos(0.1*pi).
Using SPTool
5-17
1 Select Sampli ng Freque ncy... and dr ag t o choose t he signal or filt er you
want t o change.
The Sampli ng Frequency... dialog box is displayed.
2 Type in t he value, var iable name, or expr ession and pr ess OK.
Viewing a Signal
Use t he Signal Vi ew but t on t o make t he Signal Br owser act ive and view one or
mor e impor t ed signals. The Signal Br owser pr ovides t ools for gr aphical
analysis of t he select ed signal(s).
Select one or mor e signals fr om t he Si gnals list and pr ess t he Vi ew but t on in
t he signal panel. The Signal Br owser displays t he select ed signal(s). See Using
t he Signal Br owser : Int er act ive Signal Analysis on page 5-43 for a full
descr ipt ion of Signal Br owser funct ions and oper at ions.
Viewing a Filter
Use t he Vi ew but t on in t he Fi lte rs panel t o make t he Filt er Viewer act ive and
view impor t ed filt er s or filt er s designed/edit ed in t he Filt er Designer . The
Filt er Viewer pr ovides t ools for analyzing filt er s; you can invest igat e t he
magnit ude r esponse, phase, gr oup delay, zer os and poles, and impulse and st ep
r esponses of t he select ed filt er s.
Select one or mor e filt er s fr om t he Fi lte rs list and pr ess t he Vi e w but t on in t he
filt er panel. The Filt er Viewer displays t he select ed filt er s. See Using t he
Filt er Viewer : Int er act ive Filt er Analysis on page 5-84 for a full descr ipt ion of
Filt er Viewer funct ions and oper at ions.
Designing a Filter
New Design. Use t he Filt er New Des i gn but t on t o make t he Filt er Designer
act ive and design a filt er . The Filt er Designer let s you cr eat e FIR and IIR
digit al filt er s of var ious lengt hs and t ypes using t he filt er design funct ions in
t he Signal Pr ocessing Toolbox.
Pr ess t he New Des i gn but t on in t he Fi lter panel. The Filt er Designer displays
a filt er cr eat ed wit h t he default set t ings and assigns it a default name of filtn,
wher e n is a unique sequent ial ident ifying digit . Once t he default filt er is
cr eat ed, you can use it as is or edit it wit h t he Filt er Designer . You can r ename
it using Name fr om t he Edi t menu.
5 Interactive Tools
5-18
Edit Design. Use t he Fi lte r panels Edi t Des i gn but t on t o make t he Filt er
Designer act ive and edit a filt er . Impor t ed filt er s always open in t he Pole/Zer o
Edit or .
Select one or mor e filt er s fr om t he Fi lte rs list and pr ess t he Edi t De si gn
but t on in t he filt er panel. The Filt er Designer displays t he fir st of t he select ed
filt er s. The ot her select ed filt er s can be edit ed, one at a t ime, by select ing t hem
fr om t he Fi lter pop-up menu. See Using t he Filt er Designer : Int er act ive Filt er
Design on page 5-59 for a full descr ipt ion of Filt er Designer funct ions and
oper at ions.
Applying a Filter
Use t he Apply Fi lte r but t on t o apply a filt er t o a select ed signal. This cr eat es
a new signal:
1 Select one signal fr om t he Si gnals list and one filt er fr om t he Fi lters list and
pr ess t he Apply Fi lte r but t on in t he filt er panel.
The Apply Fi lter dialog box is displayed.
2 Select t he filt er ing algor it hm fr om t he Algori thm pop-up menu, t ype t he
name for t he new signal in t he Output Si gnal field, and pr ess OK.
The available filt er algor it hms ar e:
- Tr ansposed dir ect -for m II (uses t he filter funct ion)
- Zer o-phase IIR (uses t he filtfilt funct ion)
- FFT-based FIR (uses t he fftfilt funct ion)
The select ed filt er is applied t o t he select ed input signal and t he new out put
signal is list ed in t he Si gnals list .
Drag to select the
algorithm you want
to use.
Type the new signal
name here.
Using SPTool
5-19
Creating a Spectrum
Use t he Create but t on t o act ivat e t he Spect r um Viewer and gener at e a default
spect r um of a select ed signal. Once youve gener at ed a spect r um, you can view
it in a var iet y of ways, measur e it , and modify it in t he Spect r um Viewer .
1 Select one signal fr om t he Si gnals list and pr ess t he Create but t on in t he
Spe ctra panel.
The Spect r um Viewer is act ivat ed and a spect r um object wit h default
par amet er s is cr eat ed in t he Spectra panel. The PSD dat a is not comput ed
or displayed yet . The newly cr eat ed spect r um object has a default name of
specn, wher e n is a unique sequent ial ident ifying digit . Once t he spect r um
object is cr eat ed, you can use it wit h t he default set t ings, or cont inue t o edit
it in t he Spect r um Viewer . You can r ename it using Name fr om t he Edi t
menu.
2 Modify t he spect r um par amet er s (e.g., Me thod and Nfft) as desir ed.
3 Pr ess Apply in t he Spect r um Viewer t o comput e t he spect r um dat a. This
but t on is enabled when t he spect r um has just been cr eat ed or when you have
changed one or mor e par amet er s in t he Spect r um Viewer .
The updat ed spect r um is displayed in t he Spect r um Viewer . See Using t he
Spect r um Viewer : Int er act ive PSD Analysis on page 5-97 for a full
descr ipt ion of Spect r um Viewer par amet er s and displays.
Viewing a Spectrum
Select one or mor e spect r a fr om t he Spectra list and pr ess Vi ew in t he Spe ctra
panel. The Spect r um Viewer displays t he select ed spect r um or spect r a.
Updating a Spectrum
Use t he Update but t on t o updat e t he select ed spect r um so t hat it r eflect s t he
dat a in t he cur r ent ly select ed signal.
1 Select one signal fr om t he Si gnals list and one spect r um fr om t he Spe ctra
list and pr ess Update in t he Spe ctra panel.
The spect r al dat a fr om t he cur r ent spect r um is r emoved fr om t he Spect r um
Viewer . The Spect r um Viewer is act ivat ed. No spect r um is displayed yet .
5 Interactive Tools
5-20
2 Pr ess Apply in t he Spect r um Viewer t o comput e t he spect r um and complet e
t he updat e.
The spect r um is r egener at ed wit h t he same par amet er s but using t he dat a
in t he cur r ent ly select ed signal. This feat ur e is useful when you have alt er ed
a signal (by filt er ing it , for example), and want t o updat e t he exist ing
spect r um t o r eflect t he change.
Customizing Preferences
Use Prefere nces fr om t he Fi le menu t o cust omize displays and cer t ain
par amet er s for SPTool and it s four component t ools. The new set t ings ar e
saved on disk and ar e used when you r est ar t MATLAB.
In t he Prefere nces panels, you can:
Select color s and mar ker s for r uler s, and set t he init ial r uler st yle
Select color and line st yle sequence for displayed signals
Configur e axis labels, and enable/disable r uler s, panner , and mouse zoom in
t he Signal Br owser
Configur e axis par amet er s, and enable/disable r uler s and mouse zoom in t he
Spect r um Viewer
Configur e filt er and axis par amet er s and enable/disable mouse zoom in t he
Filt er Viewer
Configur e t iling pr efer ences in t he Filt er Viewer
Specify FFT lengt h, and enable/disable mouse zoom and gr id in t he Filt er
Designer
Enable/disable use of a default session file
Configur e filt er s for expor t t o t he Cont r ol Syst em Toolbox (for user s of t hat
pr oduct )
Enable/disable sear ch for plug-ins at st ar t -up
When you fir st select Prefere nces , t he Prefere nces dialog box displays t he
Rulers panel. You can change t he set t ings for r uler s, or choose on any of t he
ot her set t ings cat egor ies t o cust omize ot her set t ings.
Click once on a set t ings cat egor y t o select it .
Using SPTool
5-21
The following sect ions descr ibe all of t he set t ings you can modify. The
illust r at ions show t he default set t ings for each cat egor y. For addit ional
infor mat ion on pr efer ence set t ings, use t he He lp... but t on at t he bot t om of t he
Prefe rence s dialog box.
Ruler Settings
The Rulers pr efer ences apply t o t he r uler s in t he Signal Br owser , Spect r um
Viewer , and Filt er Viewer . These pr efer ences also apply t o pr int out s fr om t he
Signal Br owser and Spect r um Viewer .
Ruler Color. Specifies t he color of t he r uler s. Color is specified as a st r ing
(e.g., 'r') or RGB t r iple (e.g., [1 0 0]).
Ruler Marker. Specifies t he mar ker used in t he t r ack and slope r uler s.
Marker Size. Specifies t he size of t he r uler mar ker in point s. This can be any
posit ive value.
Initial Type. Specifies t he t ype of r uler (hor izont al, ver t ical, t r ack, or slope) t hat
is select ed when you fir st open t he Signal Br owser , Spect r um Viewer , or Filt er
Viewer .
5 Interactive Tools
5-22
Color Settings
The Colors pr efer ences apply t o signals displayed in t he Signal Br owser ,
Spect r um Viewer , and Filt er Viewer . These pr efer ences also apply t o pr int out s
fr om t he Signal Br owser and Spect r um Viewer .
Color Order. Specifies t he color or der t o cycle t hr ough for dat a plot t ed in t he
Signal Br owser , Spect r um Viewer , and Filt er Viewer . The default is t he axis
color or der .
Type in a new value or value st r ing t o change t he color or der . Color is specified
as a st r ing (e.g., 'r') or RGB t r iple (e.g., [1 0 0]), an n-by-3 mat r ix of n color s,
or an n-by-1 cell ar r ay of such object s.
Line Style Order. Specifies t he line st yles t o cycle t hr ough for dat a plot t ed in t he
Signal Br owser , Spect r um Viewer , and Filt er Viewer . The default is t he axis
line st yle or der .
Type in a new st r ing value (e.g., '--') or an ar r ay of st r ings
(e.g., {'-','--',':'}) t o change t he line st yle or der .
Using SPTool
5-23
Signal Browser Settings
The Si gnal Browse r pr efer ences let you set opt ional x-axis and y-axis labels,
enable and disable t he display of t he r uler s and t he panner , and t oggle zoom
per sist ence.
Except for zoom per sist ence, t hese pr efer ences also apply t o pr int ing fr om t he
Signal Br owser . See Pr int ing Signal Dat a on page 5-54 for det ails on pr int ing
fr om t he Signal Br owser .
X Label, Y Label. Type in a st r ing for t he x-axis label and t he y-axis label in t he
Signal Br owser . The default is Time for t he x-axis.
Rulers. Click in t he check box t o display (checked) or hide (unchecked) t he r uler
but t ons and t he r uler panel in t he Signal Br owser . See Ruler Cont r ols on
page 5-33 for det ails on using t he r uler s in t he Signal Br owser .
Panner. Click in t he check box t o display (checked) or hide (unchecked) t he
panner in t he Signal Br owser . See Panner Display on page 5-52 for det ails on
using t he panner in t he Signal Br owser .
Stay in Zoom-mode After Zoom. Click in t he check box t o enable (checked) or
disable (unchecked) zoom per sist ence in t he Signal Br owser . See Zoom
Cont r ols on page 5-31 for det ails on zoom cont r ols in t he Signal Br owser .
5 Interactive Tools
5-24
Spectrum Viewer Settings
The Spe ctrum Vi ewe r pr efer ences let you set axis par amet er s, enable and
disable t he display of t he r uler s, and t oggle zoom per sist ence.
Except for zoom per sist ence, t hese pr efer ences also apply t o pr int ing fr om t he
Spect r um Viewer . See Pr int ing Spect r um Dat a on page 5-107 for det ails on
pr int ing fr om t he Spect r um Viewer .
Magnitude Axis Scaling. Specifies t he scaling unit s for t he magnit ude (y) axis in
t he Spect r um Viewer . Scaling unit s can be deci bels or li near.
Frequency Axis Scaling. Specifies t he scaling unit s for t he fr equency (x) axis in t he
Spect r um Viewer . Scaling unit s can be li near or log.
Frequency Axis Range. Specifies t he numer ical r ange for t he fr equency (x) axis in
t he Spect r um Viewer . Scaling opt ions ar e [0,Fs /2], [0,Fs], or [-Fs /2,Fs /2].
Rulers. Click in t he check box t o display (checked) or hide (unchecked) t he r uler
but t ons and t he r uler panel in t he Spect r um Viewer . See Ruler Cont r ols on
page 5-33 for det ails on using t he r uler s in t he Spect r um Viewer .
Stay in Zoom-mode After Zoom. Click in t he check box t o enable (checked) or
disable (unchecked) zoom per sist ence in t he Spect r um Viewer . See Zoom
Cont r ols on page 5-31 for det ails on zoom cont r ols in t he Spect r um Viewer .
Using SPTool
5-25
Filter Viewer Settings
The Fi lte r Vi ewe r pr efer ences let you set key filt er plot configur at ion
par amet er s and t oggle zoom per sist ence.
FFT Length. Specifies t he number of point s at which t he fr equency r esponse is
comput ed (for t he magnit ude, phase, and gr oup delay plot s).
Time Response Length. Specifies t he t ime r esponse lengt h (in samples) for t he
impulse and st ep r esponse plot s. An empt y value, [ ], for an FIR filt er indicat es
t hat t he complet e r esponse lengt h will be shown; an empt y value for an IIR
filt er indicat es t hat t he r esponse lengt h will be aut omat ically det er mined using
t he impz funct ion.
Magnitude Axis Scaling. Specifies t he scaling unit s for t he magnit ude (y) axis in
t he Filt er Viewer . Scaling unit s can be li near, log, or de ci be ls.
Phase Units. Specifies t he phase unit s for t he phase r esponse plot . Phase unit s
can be de gree s or radi ans.
Frequency Axis Scaling. Specifies t he scaling unit s for t he fr equency (x) axis in t he
Filt er Viewer . Scaling unit s can be li near or log.
Frequency Axis Range. Specifies t he numer ical r ange for t he fr equency (x) axis in
t he Filt er Viewer . Scaling opt ions ar e [0,Fs/2], [0,Fs ], or [-Fs/2,Fs/2].
5 Interactive Tools
5-26
Rulers. Click in t he check box t o display (checked) or hide (unchecked) t he r uler
but t ons and t he r uler panel in t he Filt er Viewer . See Ruler Cont r ols on page
5-33 for det ails on using t he r uler s in t he Filt er Viewer .
Stay in Zoom-mode After Zoom. Click in t he check box t o enable (checked) or
disable (unchecked) zoom per sist ence in t he Filt er Viewer . See Zoom Cont r ols
on page 5-31 for det ails on zoom cont r ols in t he Filt er Viewer .
Filter Viewer Tiling Settings
The Fi lter Vi e werTi li ng pr efer ences let you change t he way t he Filt er Viewer
displays t he analysis plot s.
Click t he r adio but t on t o select how t he plot s ar e t iled in t he display ar ea.
Opt ions ar e 2-by-3 Gri d, 3-by-2 Gri d, Ve rti cal (6-by-1 Gri d), and
Hori zontal (1-by-6 Gri d).
This specifies how t he plot s ar e ar r anged when all six plot opt ions ar e t ur ned
on. When fewer opt ions ar e t ur ned on, t he plot s ar e displayed as symmet r ically
as possible.
Using SPTool
5-27
Filter Designer Settings
The Fi lte r De si gner pr efer ences let you set key filt er configur at ion and plot
par amet er s.
FFT Length. Specifies t he number of point s used t o calculat e a filt er s fr equency
r esponse.
Display grid lines. Tur ns plot gr id lines on (checked) or off (unchecked).
Auto Design initial value. Specifies t he default set t ing for t he Auto Des i gn check
box in t he Filt er Designer . When t he Filt er Designer is fir st launched, t he Auto
Des i gn check box will have t he same set t ing (checked or unchecked) as t he
Auto Des i gn i ni ti al value check box her e.
Stay in Zoom-mode After Zoom. Tur ns per sist ent zooming on and off, as descr ibed
in Zoom Cont r ols on page 5-31.
5 Interactive Tools
5-28
Default Session Setting
The Default Se ss i on pr efer ence let s you specify whet her or not t o load a
default session file when SPTool is launched.
Default Session. Enables (checked) or disables (unchecked) loading of a default
session file, which must have t he name startup.spt, when st ar t ing SPTool.
An SPTool session file is a MAT-file (see Using MATLAB) wit h a .spt
ext ension.
The Default Se ss i on pr efer ence only affect s t he session cont ent s when you
st ar t SPTool. You can load a new session file aft er st ar t ing SPTool using t he
Ope n Se ss i on opt ion in t he SPTool Fi le menu. You can also save a session file
at any t ime using t he Save Se ss i on opt ion in t he Fi le menu. If you close SPTool
wit hout having r ecent ly saved a session file, you will be pr ompt ed t o do so. (See
File Menu on page 5-6.)
NOTE Changes t hat you make in t he SPTool pr efer ence panels ar e saved in
a separ at e MAT-file, which is r eloaded t he next t ime you open SPTool (see
Saving and Discar ding Changes t o Pr efer ences Set t ings on page 5-30). The
De fault Ses s i on pr efer ence does not affect t hese pr efer ence set t ings.
Using SPTool
5-29
Exporting Components Setting
The Exporti ng Compone nts pr efer ence let s you specify whet her or not t o
expor t filt er s cr eat ed in SPTool as TF object s for t he Cont r ol Syst em Toolbox.
Export Filters as TF objects. Enables (checked) or disables (unchecked) expor t ing of
SPTool filt er s as TF (t r ansfer funct ion) object s, for use in t he Cont r ol Syst em
Toolbox (see t he Control S ystem Toolbox Users Guide).
NOTE This pr efer ence cat egor y only appear s in t he in SPTool Pre ferences
dialog box if you have inst alled t he Cont r ol Syst em Toolbox.
5 Interactive Tools
5-30
Plug-Ins Setting
The Plug-Ins pr efer ence let s you sear ch for plug-ins when SPTool is st ar t ed up.
Search for Plug-Ins at start-up. Enables (checked) or disables (unchecked)
sear ching for inst alled plug-ins.
A plug-in is an ext ension t o SPTool. Plug-ins include cust omized add-on panels
and new but t ons in t he panels in SPTool, new spect r al met hods in t he
Spect r um Viewer , and new SPTool pr efer ences. You can also plug one or mor e
t oolboxes int o SPTool.
You need t o use t his set t ing only when you have inst alled ext ensions or have
ot her t oolboxes plugged int o SPTool.
To use SPTool wit h ext ensions, check Se arch for Plug-i ns at start-up, close
SPTool, and r est ar t it .
Saving and Discarding Changes to Preferences Settings
The but t ons at t he bot t om of t he Pre fe rence s panels let you save or discar d
any changes you have made, or r et ur n t o t he default set t ings.
Factory Settings. Rest or es t he pr efer ences in t he cur r ent panel t o t heir or iginal
set t ings; t hat is, t he set t ings at t he t ime t he Signal Pr ocessing Toolbox was
fir st inst alled.
Using SPTool
5-31
Revert Panel. Cancels changes in t he cur r ent panel only. Set t ings in t he cur r ent
panel r ever t t o t he pr evious set t ings.
Cancel. Cancels changes in all pr efer ence cat egor ies and closes t he
Prefe rence s dialog box. Set t ings in all panels r ever t t o t heir pr evious st at e.
OK. Applies changes in all Prefere nces panels and closes t he Prefere nces
dialog box. Set t ings in all panels ar e saved in a MAT-file called sigprefs.mat.
If sigprefs.mat does not exist , eit her on t he cur r ent MATLAB pat h or in t he
cur r ent dir ect or y, you ar e pr ompt ed for a locat ion t o save t he file. The saved
set t ings ar e used t he next t ime you open SPTool.
Controls for Viewing and Measuring
The GUI t ools shar e common cont r ols for viewing and measur ing signals.
These cont r ols ar e descr ibed in t his sect ion. Not all t ools use all of t he viewing
and measur ing cont r ols; specific det ails about t he t ools and pr ocedur es for
viewing and measur ing ar e descr ibed in t he sect ion on each t ool.
Zoom Controls
The GUI t ools shar e a common set of zoom cont r ol but t ons. The Signal Br owser
and Spect r um Viewer use t he same set of common zoom cont r ol but t ons, which
affect bot h on-scr een and pr int ed images.
The Filt er Designer has one addit ional viewing but t on, t he Pas s Band but t on.
The Filt er Viewer has a subset of t he zoom cont r ol but t ons.
Each but t on wor ks t he same way in ever y GUI t ool in which it occur s.
In or dinar y use, you pr ess a but t on once t o zoom in or out of t he signal display.
5 Interactive Tools
5-32
Zoom In-X, Zoom Out-X, Zoom In-Y, and Zoom Out-Y. Click once t o per for m one zoom
oper at ion (in or out ) on t he x- or y-axis. Each zoom oper at ion changes t he axes
limit s by a fact or of t wo on t he specified axis, about t he cent er of t he displayed
signal. You can pr ess r epeat edly on one or mor e but t ons t o cont inue t o change
t he scale in one or bot h axes.
When you zoom in t he x-axis (hor izont al scaling), t he y limit s (ver t ical scaling)
of t he main axes ar e not changed. Similar ly, when you zoom in t he y-axis, t he
x limit s of t he main axes ar e not changed.
Full View. Click once t o r est or e t he displayed signal t o it s full r ange in bot h axes.
Mouse Zoom. Click once t o act ivat e zoom mode. The cur sor changes t o a
cr osshair . You can eit her zoom in wit hout specifying a zoom window, or you can
use a zoom r ect angle t o select a specific zoom window. In eit her case, t he x- and
y-axis ar e aut omat ically adjust ed t o display t he select ed signal:
To zoom in wit hout specifying a zoom window, click on t he plot . The posit ion
of t he cr osshair is t he cent er of a zoom oper at ion t hat halves bot h t he x- and
y-axis limit s.
To use a zoom r ect angle, click wher e you want t he r ect angle t o begin, dr ag
t he mouse diagonally t o wher e you want it t o end, and r elease t he mouse
but t on.
To get out of mouse zoom mode wit hout zooming in or out , pr ess t he Mous e
Zoom but t on again.
Zoom Persistence. Mouse zooming can eit her be one-time or persistent:
One-t ime zooming is act ivat ed when you pr ess t he Mous e Zoom but t on. It
aut omat ically t ur ns it self off aft er you click in t he display ar ea and t he zoom
oper at ion occur s. This is t he default for all t he t ools.
Per sist ent zooming is also act ivat ed by pr essing t he Mous e Zoom but t on. It
does not t ur n off aft er you click in t he display ar ea and a zoom oper at ion
occur s; you can cont inue t o click and zoom wit hout r eset t ing t he Mouse
Zoom but t on.
You can change whet her zooming is one-t ime or per sist ent by select ing
Prefere nces fr om t he Fi le menu and t oggling Stay i n Zoom-mode After
Zoom in t he Prefere nces panels for t he Signal Br owser , t he Spect r um Viewer ,
t he Filt er Designer , and t he Filt er Viewer .
Using SPTool
5-33
When Stay i n Zoom-mode After Zoom is select ed, zooming is per sist ent . To
t ur n off mouse zooming when Stay i n Zoom-mode After Zoom is select ed,
pr ess t he Mouse Zoom but t on.
Passband Zoom (Filter Designer). Click once t o zoom in on t he passband of t he
r esponse.
Bot h t he x- and y-limit s of t he main axes ar e changed so t hat t he passband fills
t he main axes.
Ther e is no st opband zoom but t on. To zoom t he st opband, use st andar d Mous e
Zoom, cent er ing t he cr osshair on t he ar ea of t he st opband you want t o view. If
you ar e in passband zoom, fir st pr ess Full Vi e w t o r et ur n t o t he st andar d view.
Ruler Controls
The Signal Br owser , Filt er Viewer , and Spect r um Viewer shar e a common set
of r uler cont r ols. Use t he r uler s t o make measur ement s on t he signals or
spect r a in t he main axes (display) ar ea. The r uler cont r ols give you a var iet y of
ways t o r ead and cont r ol t he values of t he r uler s in t he main axes. Wit h t he
r uler s you can measur e such infor mat ion as t he ver t ical and hor izont al
dist ance bet ween feat ur es in a signal or spect r um, t he dimensions of peaks and
valleys, and slope infor mat ion.
In t he following discussion, t he Signal Br owser is shown. The r uler cont r ols
include t he Selecti on cont r ols at t he t op r ight of t he window and t he but t ons
and edit boxes in t he Rule rs panel. The cont r ols in t he Filt er Viewer and
Spect r um Viewer wor k t he same way. The cont r ols in t he Signal Br owser and
t he Spect r um Viewer also affect images pr int ed fr om t hese t ools.
In t he Filt er Viewer , t he r uler s appear on only one subplot at a t ime. You can
choose which subplot t he r uler s appear on by select ing t he subplot fr om t he
pop-up menu at t he t op of t he Rulers panel, or by clicking on a line in t he plot
t hat you want t o measur e. If a subplot is not cur r ent ly visible when you select
it s name fr om t he pop-up menu, t he Filt er Viewer cr eat es t he subplot and
places t he r uler s in it .
5 Interactive Tools
5-34
Selecting a Line to Measure. When t her e is only one signal displayed, t he displayed
signal is aut omat ically select ed and is measur ed when you use t he r uler s.
When t her e is mor e t han one signal displayed, only one signal (line) may be
select ed and measur ed at a t ime.
When a signal (line) is select ed, you can use t he r uler cont r ols (Ve rti cal,
Hori zontal, Track, or Slope ) and t he Peaks and/or Valleys cont r ols on t he
select ed line. The label of t he select ed signal (line) is displayed in t he Se lecti on
pop-up menu.
Ther e ar e t wo ways t o select a signal (line):
Click on t he Se lecti on pop-up menu and dr ag t o select t he line t o measur e.
All signals t hat ar e cur r ent ly select ed in SPTool ar e list ed. Vect or signals in
t he Signal Br owser , spect r a in t he Spect r um Viewer , and filt er s in t he Filt er
Viewer ar e list ed as single var iables; in t he Signal Br owser , each column of
a t wo-dimensional signal mat r ix is list ed as a separ at e var iable.
Move t he mouse point er over any point in t he line you want t o select and click
on it .
Find ruler buttons
Ruler control buttons
Selection pop-up menu Selection display
Color button
Rulers panel
Display peaks and valleys
buttons
Save Rulers button
Edit boxes
Using SPTool
5-35
The label of t he signal, including t he column number if t he line is one column
of a mat r ix, is displayed in t he Se lecti on pop-up menu.
The line select ion display changes t o t he color and pat t er n of t he select ed
signal, spect r um, or filt er .
Line Selection Pop-Up Menu. Use t o select a line (vect or signal, ar r ay column,
filt er , or spect r um) t o measur e.
Click t he Selecti on pop-up menu and dr ag t o select t he line.
Line Selection Display. The line color and st yle of t he select ed signal ar e displayed.
Color Button. Use t o edit t he line st yle or display color of t he select ed line.
Click on t he Color but t on at t he t op r ight of t he window t o display t he
Edi t Li ne pop-up menu, which is shown on t he left . The label of t he select ed
line is displayed in t he Labe l field.
Click t he Li ne Style pop-up menu and dr ag t o select a line st yle, as shown
on t he left .
Click a r adio but t on t o select a color . If you select Othe r, you can t ype a color
value in t he Ente r colors pe c box; t he color value can be a st r ing (e.g., 'r')
or an RGB t r iple (e.g., [1 0 0]).
Click OK t o apply t he line st yle and color you select ed.
Find Ruler Buttons. Use t he find r uler but t ons t o br ing one or bot h r uler s int o t he
viewing ar ea of t he main axes. When bot h r uler s ar e wit hin t he signal display
(main axes) ar ea, t he Fi nd Ruler but t ons, at t he t op r ight of t he main axes
ar ea, ar e not displayed.
If t he r uler s ar e not wit hin t he signal display ar ea, bot h Fi nd Rule r
but t ons ar e displayed, as shown on t he r ight .
If one r uler is wit hin t he signal display ar ea, t he but t on for t he ot her
r uler is displayed, as shown on t he r ight .
Click a Fi nd Ruler but t on t o br ing t he specified r uler int o t he display ar ea.
When a r uler is visible, you can click on it and dr ag it t o make a measur ement
on t he select ed signal. See Making Signal Measur ement s on page 5-37 for
det ails on manipulat ing t he r uler s and measur ing t he select ed signal.
5 Interactive Tools
5-36
Ruler Control Buttons. Use t he r uler cont r ol but t ons t o select t he t ype of
measur ement you want t o make: Verti cal, Hori zontal, Track, or Slope. The
default set t ing is Track.
Click a r uler cont r ol but t on t o select it . The Rule rs panel changes depending
on which r uler cont r ol is select ed. See Making Signal Measur ement s on page
5-37 for det ails on t he four kinds of measur ement s you can make and t he
par amet er s for each one.
Rulers Panel and Edit Boxes. The Rulers panel changes depending on which r uler
cont r ol is select ed: Verti cal, Hori zontal, Track, or Slope . It shows t he
par amet er s for t he select ed r uler cont r ol. Depending on which r uler cont r ol is
select ed, t he following fields ar e displayed: x1, y1, x2, y2, dx, dy, m. The
pict ur e on t he left shows t he Rulers panel when Slope is select ed.
When you pr ess a r uler cont r ol but t on, r uler s ar e displayed super imposed on
t he signal(s) in t he main axes display ar ea. The r uler s ar e eit her ver t ical (for
Verti cal, Track, and Slope) or hor izont al (for Hori zontal). For Track and
Slope , r uler mar ker s ar e also displayed. The r uler s and r uler mar ker s ar e
associat ed wit h t he cur r ent ly select ed signal. The following pict ur e shows t he
r uler s and r uler mar ker s t hat ar e displayed when Slope is select ed.
To posit ion a r uler , you can click and dr ag on it . When you dr ag a r uler , t he
par amet er s in t he Rule rs panel change t o r eflect t he measur ement s on t he
select ed signal.
You can also posit ion a r uler by specifying par amet er s in t he edit boxes in t he
Rulers panel. The par amet er s ar e eit her t he x1 and x2 values or t he y1 and y2
values, depending on which r uler cont r ol is select ed.
Using SPTool
5-37
Type t he value or var iable for t he r uler par amet er in t he x1 and x2 boxes or t he
y1 and y2 boxes. See Making Signal Measur ement s on page 5-37 for det ails
on manipulat ing t he r uler s and t he par amet er s you can measur e wit h each
one.
Peaks and Valleys. Use t hese but t ons t o show or hide t he local maxima and/or
local minima of t he cur r ent ly select ed signal, filt er r esponse, or spect r um. Only
peaks or valleys, or bot h peaks and valleys may be displayed.
Click Pe aks t o t oggle showing (down) or hiding (up) t he maxima of t he
signal.
Click Valle ys t o t oggle showing (down) or hiding (up) t he minima of t he
signal.
In t r ack and slope mode (see Making Signal Measur ement s on page 5-37), t he
r uler s ar e const r ained t o t he peaks or valleys. In hor izont al and ver t ical mode,
t he peaks and valleys ar e only visual and do not affect t he behavior of t he
r uler s.
Save Rulers Button. Once youve set up and made a cer t ain set of
measur ement s, you may find it useful t o save t hem for fut ur e r efer ence. Use
t he Save Rulers but t on t o save a st r uct ur e in t he MATLAB wor kspace wit h
t he fields x1, y1, x2, y2, dx, dy, m, peaks, and valleys. Undefined values ar e set
t o NaN.
1 Click Save Rulers t o save t he cur r ent measur ement s as a var iable in t he
wor kspace.
The Save Ruler s dialog box is displayed.
2 Type a var iable name in t he edit field and pr ess OK.
Making Signal Measurements
Use t he r uler s t o make measur ement s on a select ed line, which is a vect or or a
column of a mat r ix in t he Signal Br owser , a filt er r esponse in t he Filt er Viewer ,
or a spect r um in t he Spect r um Viewer . To make a measur ement :
1 Select a line as descr ibed in Select ing a Line t o Measur e on page 5-34.
2 Apply a r uler t o t he display as descr ibed in Ruler Cont r ol But t ons on page
5-36.
5 Interactive Tools
5-38
3 Posit ion a r uler wher e you want it in t he main axes ar ea by clicking and
dr agging it :
a Move t he mouse over t he r uler (1 or 2) t hat you want t o dr ag.
The hand cur sor is displayed when your e over a r uler , wit h t he r uler
number inside it :
b Click and dr ag t he r uler t o wher e you want it on t he signal.
Depending on which r uler cont r ol is select ed, you can dr ag t he r uler t o t he
r ight and left (Ve rti cal, Track, and Slope ) or up and down (Hori zontal).
As you dr ag a r uler , t he Rule rs panel shows t he cur r ent posit ion of bot h
r uler s. Depending on which r uler cont r ol is select ed, t he following fields ar e
displayed: x1, y1, x2, y2, dx, dy, m. These fields will also be displayed in
pr int out s fr om t he Signal Br owser , unless you suppr ess t hem. See Pr int ing
Signal Dat a on page 5-54 and Pr int ing Spect r um Dat a on page 5-107 for
det ails on pr int ing fr om t hese t ools.
You can also posit ion a r uler by t yping it s x1 and x2 or y1 and y2 values in t he
Rulers panel, as descr ibed on page 5-36.
Ruler Controls: Vertical. Ther e ar e t wo ver t ical r uler s, called r uler 1 and r uler 2.
When ver t ical r uler s ar e in use, t he measur ement s displayed in t he Rulers
Using SPTool
5-39
panel ar e x1 (t he posit ion of r uler 1 on t he x-axis), x2 (t he posit ion of r uler 2 on
t he x-axis), and dx (t he value of x2-x1).
Pr ess Verti cal t o put t he r uler s in ver t ical mode.
In ver t ical mode, you may change t he x-values of t he r uler s (t hat is, t heir
hor izont al posit ion). As t he x1 and x2 values change, t he value of dx changes
aut omat ically.
Change t he x1 and x2 values in one of t wo ways:
Dr ag t he r uler s t o t he left and t he r ight wit h t he mouse
Ent er t heir values in t he x1 and x2 edit boxes in t he Rulers panel
Ruler Controls: Horizontal. Ther e ar e t wo hor izont al r uler s, called r uler 1 and
r uler 2. When hor izont al r uler s ar e in use, t he measur ement s displayed in t he
5 Interactive Tools
5-40
Rulers panel ar e y1 (t he posit ion of r uler 1 on t he y-axis), y2 (t he posit ion of
r uler 2 on t he y-axis), and dy (t he value of y2-y1).
Pr ess Hori zontal t o put t he r uler s in hor izont al mode.
In hor izont al mode, you may change t he y-values of t he r uler s (t hat is, t heir
ver t ical posit ion). As t he y1 and y2 values change, t he value of dy changes
aut omat ically.
Change t he y1 and y2 values in one of t wo ways:
Dr agging t he r uler s up and down wit h t he mouse
Ent er ing t heir values in t he y1 and y2 edit boxes in t he Rulers panel
Ruler Controls: Track. Ther e ar e t wo ver t ical r uler s, called r uler 1 and r uler 2,
wit h a mar ker on each t hat shows t he y-values of t he signal at t he x-values of
t he r uler s. When t r ack r uler s ar e in use, t he measur ement s displayed in t he
Rulers panel ar e x1 (t he posit ion of r uler 1 on t he x-axis), y1 (t he posit ion of
Using SPTool
5-41
r uler 1 on t he y-axis), x2 (t he posit ion of r uler 2 on t he x-axis), y2 (t he posit ion
of r uler 2 on t he y-axis), dx (t he value of x2-x1), and dy (t he value of y2-y1).
Pr ess Track t o put t he r uler s in t r ack mode.
You can change t he t r ack mar ker in t he Rulers panel fr om t he Preferences
dialog box; see Ruler Set t ings on page 5-21.
In t r ack mode, you may change t he x-values of t he r uler s (t hat is, t heir
hor izont al posit ion). As t he x1 and x2 values change, t he values of y1, y2, dx,
and dy change aut omat ically.
Change t he x1 and x2 values in one of t wo ways:
Dr agging t he r uler s t o t he left and t he r ight wit h t he mouse
Ent er ing t heir values in t he x1 and x2 edit boxes in t he Rulers panel
Ruler Controls: Slope. Ther e ar e t wo ver t ical r uler s, called r uler 1 and r uler 2,
wit h t he slope line passing t hr ough t he y-axis int er sect ions of t he t wo ver t ical
r uler s and t he signal. The r uler s also t r ack t he signal wit h mar ker s on each
r uler t hat shows t he y-values of t he signal at t he x-values of t he r uler s. The line
connect ing (x1, y1) and (x2, y2) is included in t he main plot , so you can
appr oximat e der ivat ives and slopes of t he signal.
5 Interactive Tools
5-42
When slope r uler s ar e in use, t he measur ement s displayed in t he Rule rs panel
ar e x1 (t he posit ion of r uler 1 on t he x-axis), y1 (t he posit ion of r uler 1 on t he
y-axis), x2 (t he posit ion of r uler 2 on t he x-axis), y2 (t he posit ion of r uler 2 on
t he y-axis), dx (t he value of x2 - x1), dy (t he value of y2 - y1), and m (equal t o
dy/ dx, t he slope of t he line bet ween x1 and x2).
Pr ess Slope t o put t he r uler s in slope mode.
In slope mode, you may change t he x-values of t he r uler s (t hat is, t heir
hor izont al posit ion). As t he x1 and x2 values change, t he values of dy and m
change aut omat ically.
Change t he x1 and x2 values in one of t wo ways:
Dr agging t he r uler s t o t he left and t he r ight wit h t he mouse
Ent er ing t heir values in t he x1 and x2 edit boxes in t he Rulers panel
Using the Signal Browser: Interactive Signal Analysis
5-43
Using the Signal Browser: Interactive Signal Analysis
The Signal Br owser t ool is an int er act ive signal explor at ion envir onment . It
pr ovides a gr aphical view of t he signal object (s) cur r ent ly select ed in t he
Si gnals column of SPTool.
Using t he Signal Br owser you can:
View and compar e vect or or ar r ay signals
Zoom in on a r ange of signal dat a t o examine it mor e closely
Measur e a var iet y of char act er ist ics of signal dat a
Play signal dat a on audio har dwar e
Pr int signal dat a
Opening the Signal Browser
To open or act ivat e t he Signal Br owser fr om SPTool:
1 Click on one or mor e signals in t he Si gnals list of SPTool.
2 Pr ess Vi e w in t he Si gnals panel of SPTool.
The Signal Br owser is act ivat ed and t he select ed signal(s) ar e loaded int o
t he Signal Br owser and displayed.
5 Interactive Tools
5-44
Basic Signal Browser Functions
The Signal Br owser has t he following component s:
A main axes (display) ar ea for viewing signals gr aphically
Display management cont r ols: Array Si gnals and t he complex signal
display pop-up menu
Zoom cont r ols for get t ing a closer look at signal feat ur es
Ruler s and line display cont r ols for making signal measur ement s and
compar isons
A panner for seeing what par t of t he signal is cur r ent ly being displayed and
for quickly moving t he view t o ot her feat ur es of t he signal
Menu opt ions for pr int ing signal dat a
A menu opt ion for playing a select ed signal t hr ough audio equipment
Viewing (zoom) controls Measuring (line and ruler) controls
Panner
Main axes
(display) area
Display management controls
Using the Signal Browser: Interactive Signal Analysis
5-45
Menus
File Menu. Use Page Setup... fr om t he Fi le menu t o open t he st andar d
MATLAB Page Se tup dialog box, in which you can set t he or ient at ion, size and
posit ion, limit s, and color of your pr int out .
See Using MATLAB Graphics for mor e infor mat ion about t he Page Setup
dialog box.
Use Pri nt Pre vi e w... fr om t he Fi le menu t o open a MATLAB figur e window
wit h a pr eview of t he infor mat ion fr om t he Signal Br owser window t hat will
appear in your pr int out . See Signal Br owser Set t ings on page 5-23 and
Pr int ing Signal Dat a on page 5-54 for det ails about pr int ing fr om t he Signal
Br owser .
Use Pri nt... fr om t he Fi le menu t o open t he st andar d pr int dialog box, fr om
which you can pr int your signal dat a.
Use Close fr om t he Fi le menu t o close t he Signal Br owser . All signal select ion
and r uler infor mat ion will be lost . (You may want t o save r uler infor mat ion t o
t he wor kspace using t he Save Rulers ... but t on, as descr ibed on page 5-37.)
Set t ings you changed and saved using t he Pre ferences dialog box in SPTool
ar e saved and used t he next t ime you open a Signal Br owser .
5 Interactive Tools
5-46
Options Menu. Use Play fr om t he Opti ons menu t o play t he select ed signal.
Play wor ks only when you have sound capabilit ies on your comput er . If your
comput er does not have sound capabilit ies, t his menu choice does not hing.
The ent ir e select ed signal is played at eit her Fs (t he sampling fr equency of t he
signal) or at t he default plat for m sampling fr equency if Fs is less t han 25 Hz.
The r eal par t and t he imaginar y par t of a complex signal ar e played in separ at e
channels.
Window Menu. Use t he Wi ndow menu t o select a cur r ent ly open MATLAB
window.
Zoom Controls
The available zoom cont r ols in t he Signal Br owser ar e Mouse Zoom, Full
Vi ew, Zoom In-Y, Zoom Out-Y, Zoom In-X, and Zoom Out-X. See Zoom
Cont r ols on page 5-31 for det ails on using t he zoom cont r ols in t he Signal
Br owser .
Zoom per sist ence is off by default in t he Signal Br owser ; use t he Signal
Br owser set t ings panel in t he Pre fe rence s dialog box in SPTool t o t oggle zoom
per sist ence on and off. See Signal Br owser Set t ings on page 5-23.
Ruler and Line Display Controls
Using t he r uler s and line display cont r ols, you can measur e a var iet y of
char act er ist ics of signals in t he Signal Br owser . See Ruler Cont r ols on page
5-33 for det ails on using r uler s and modifying line displays in t he Signal
Br owser .
The r uler s ar e displayed by default in t he Signal Br owser ; you can t ur n off t he
r uler display in t he Si gnal Browse r set t ings panel in t he Prefere nces dialog
box. See Signal Br owser Set t ings on page 5-23.
Help Button
To use cont ext -sensit ive help, pr ess t he He lp but t on. The mouse point er
becomes an ar r ow wit h a quest ion mar k symbol. You can t hen click on anyt hing
in t he Signal Br owser , including menu it ems, t o find out what it is and how t o
use it .
Using the Signal Browser: Interactive Signal Analysis
5-47
Display Management Controls
Array Signals Button. Use t his t o ent er a column index vect or for a select ed
ar r ay signal. All ar r ay signals st ar t out wit h only t he fir st column displayed.
The Array Si gnals but t on is enabled when at least one ar r ay signal is
select ed in SPTool:
1 Pr ess Array Si gnals
The Column Selecti on for Array Si gnals dialog box is displayed.
All ar r ay signals t hat ar e select ed in SPTool ar e shown in t he list .
2 Select a signal fr om t he list .
3 Type a column index vect or for t he select ed signal.
Valid index vect or s ar e of t he for m 1 or 1:3 or [1 3 5].
Complex Signal Display. Use t o specify whet her t he Signal Br owser plot s t he r eal
par t , t he imaginar y par t , t he magnit ude, or t he angle of a complex signal.
This menu is enabled when at least one of t he signal var iables select ed in
SPTool is complex. The Complex Display mode affect s all of t he var iables in t he
cur r ent select ion, even t hose t hat ar e st r ict ly r eal.
Click and dr ag t o select t he plot t ing mode.
Main Axes Display Area
The Si gnals list in SPTool shows all signals in t he cur r ent SPTool session. One
or mor e signals may be select ed. The signal dat a of all select ed signals ar e
displayed gr aphically in t he main axes display ar ea of t he Signal Br owser .
5 Interactive Tools
5-48
When t her e is only one signal displayed, it s pr oper t ies ar e r eflect ed in t he
display management cont r ols and it s measur ement s ar e displayed in t he r uler
display panel. When mor e t han one signal is displayed, select t he line you want
t o focus on.
When a signal is select ed, you can use t he r uler cont r ols on t he select ed line
(see Making Signal Measur ement s on page 5-37), you can choose how t o
display t he signal (see Display Management Cont r ols on page 5-47), and you
can play t he signal (see Opt ions Menu on page 5-46). The label of t he select ed
signal (line) is displayed in t he Selecti on pop-up menu.
Use one of t hr ee ways t o select a signal (line) in t he Signal Br owser :
Click on t he Se lecti on pop-up menu and dr ag t o select t he line t o measur e.
Move t he mouse point er over any point in t he line in t he main axes display
and click on it .
Move t he mouse point er over any point in t he line in t he panner and click on
it .
See Select ing a Line t o Measur e on page 5-34 for det ails.
Axes Labels. By default , t he x-axis in t he Signal Br owser is labeled Time. You
can change t he x-axis label and add a y-axis label using t he Si gnal Brows er
set t ings panel in t he Prefere nces dialog box in SPTool. See Signal Br owser
Set t ings on page 5-23.
Click-and-Drag Panning. You can use t he mouse t o pan ar ound t he main axes
display; click on a line in t he main axes, hold down t he mouse but t on, and dr ag
t he mouse.
Click-and-dr ag panning is not enabled in mouse zoom mode.
Panner
The panner gives a panor amic view of t he signal(s) displayed in t he main axes.
The panner always displays t he ent ir e signal sample. When you zoom in on t he
main axes, a pat ch in t he panner shows t he sect ion of t he plot t hat is cur r ent ly
in view in t he main axes. Click-and-dr ag t he pat ch in t he panner window t o pan
dynamically acr oss t he signal dat a in t he main axes.
You can also select a line by clicking on it in t he panner ; t he select ed line is
highlight ed in bot h t he panner and in t he main axes display ar ea.
Using the Signal Browser: Interactive Signal Analysis
5-49
See Panner Display on page 5-52 for mor e det ails.
The panner is displayed by default in t he Signal Br owser ; you can t ur n off t he
panner in t he Signal Br owser set t ings panel in t he Prefere nces dialog box in
SPTool. See Signal Br owser Set t ings on page 5-23.
Making Signal Measurements
Use t he r uler s t o make a var iet y of measur ement s on t he select ed signal. See
Making Signal Measur ement s on page 5-37 for det ails.
Viewing and Exploring Signals
You can open or act ivat e t he Signal Br owser in SPTool by select ing one or mor e
signals and pr essing Vi e w in t he Signal panel. The select ed signals ar e loaded
int o t he Signal Br owser . See Viewing a Signal on page 5-17 for det ails.
Selecting and Displaying a Signal
When t he Signal Br owser is act ivat ed, all select ed signals ar e displayed in t he
main axes display ar ea and in t he panner . The dat a of t he select ed signals ar e
plot t ed against an equally spaced t ime vect or in bot h t he main axes display and
t he panner .
5 Interactive Tools
5-50
When t he var iable is a vect or , one signal is displayed, as in t he example above.
It is aut omat ically select ed and it s name, size, t ype, and sampling fr equency
ar e displayed above t he main axes display; t he name is also highlight ed in t he
Se lecti on pop-up menu.
When mor e t han one signal is select ed, each signal is displayed in a differ ent
color in bot h t he main axes display and t he panner .
The names of all signals ar e displayed above t he main axes display. The fir st
signal in t he list is aut omat ically select ed in bot h t he main axes display and
t he panner , it s name is highlight ed in t he Selecti on pop-up menu, and it s color
is shown in t he Selecti on display.
Using the Signal Browser: Interactive Signal Analysis
5-51
When t he signal is an ar r ay, only t he fir st column is init ially displayed in bot h
t he main axes and t he panner .
To display a differ ent ar r ay column, or mor e t han one column of t he ar r ay,
pr ess t he Array Si gnals but t on and specify t he columns t o be displayed (see
Ar r ay Signals But t on on page 5-47). All displayed columns of an ar r ay ar e
shown in t he same color ; t he select ed column is emphasized wit h a heavier line
5 Interactive Tools
5-52
in bot h t he main axes and t he panner , and it s label is displayed in t he
Se lecti on pop-up menu.
Panner Display
The panner displays t he ent ir e signal sample at all t imes.
Using the Signal Browser: Interactive Signal Analysis
5-53
When t he signal in t he main axes is zoomed, t he par t of t he signal t hat is shown
in t he main axes is shown in t he panner wit h a window ar ound it .
Each t ime you zoom, t he panner is updat ed t o fr ame t he r egion of dat a
displayed in t he main axes.
Click-and-dr ag on t he panner window t o move it . As t he window moves over t he
signal in t he panner , t he signal in t he main axes ar ea is panned.
Manipulating Displays
Changing Signal Displays. The signals ar e displayed in t he default line color s and
default line st yles. You can change t he default s using t he Color Order and
Li ne Style Order fields in t he Colors set t ings panel (see Color Set t ings on
page 5-22).
Changing the Sample Interval. You can change t he sample int er val by select ing
Sampli ng Fre que ncy fr om t he Edi t menu in SPTool. See Edit ing Dat a
Object s in SPTool on page 5-15.
Displaying Complex Signals. You can change how complex number s ar e displayed
by select ing Re al, Imagi nary, Magni tude, or Angle fr om t he pop-up menu.
See Ar r ay Signals But t on on page 5-47.
Changing Signal Browser Displays. Using t he Si gnal Brows er set t ings panel in t he
Prefe rence s dialog box in SPTool, you can set opt ional x-axis and y-axis labels,
5 Interactive Tools
5-54
enable and disable t he display of t he r uler s and t he panner , and t oggle zoom
per sist ence. See Signal Br owser Set t ings on page 5-23.
Working with Signals
Once a signal is displayed, you can br owse it in a var iet y of ways:
You can zoom in on a specific ar ea of t he display (see Zoom Cont r ols on page
5-31).
You can mar k off a segment of t he display wit h t he r uler s (see Ruler
Cont r ols on page 5-33) and save r uler set t ings (see Save Ruler s But t on
on page 5-37).
You can select a segment of t he display wit h t he panner (see Panner
Display on page 5-52).
You can make cer t ain measur ement s on t he displayed signals (see Making
Signal Measur ement s on page 5-37).
When t her e is mor e t han one signal in t he display, you can select which one
you want t o measur e (see Select ing a Line t o Measur e on page 5-34).
You can use t he ot her GUI t ools t o manipulat e signals in a var iet y of ways:
You can int er act ively design and analyze filt er s t o be applied t o signals (see
Using t he Filt er Designer : Int er act ive Filt er Design on page 5-59 and
Using t he Filt er Viewer : Int er act ive Filt er Analysis on page 5-84).
You can cr eat e a spect r um for a signal and int er act ively analyze it s spect r al
densit y wit h a var iet y of est imat ion met hods (see Using t he Spect r um
Viewer : Int er act ive PSD Analysis on page 5-97).
You access t he Filt er Designer , Filt er Viewer , and Spect r um Viewer t ools fr om
SPTool. You can access SPTool fr om t he Signal Br owser in one of t wo ways:
Click on an act ive SPTool window
Act ivat e SPTool using t he Wi ndow menu in t he Signal Br owser
Printing Signal Data
You can pr int all of t he signal dat a t hat you can display and manipulat e in t he
Signal Br owser . Your pr int out will cont ain up t o t hr ee component s:
Using the Signal Browser: Interactive Signal Analysis
5-55
The plot s of one or mor e signals, as displayed in t he main axes ar ea
The panner display of t he signal(s) displayed in t he main axes ar ea
The r uler measur ement s of t he select ed signal
You can pr eview your pr int out by choosing Pri nt Pre vi e w... fr om t he Fi le
menu in t he Signal Br owser window. This opens t he Si gnal Brows er Pri nt
Previ ew window, shown below wit h default set t ings for signal mtlb.
The Clos e but t on on t he Si gnal Brows er Pri nt Previ ew window closes t he
pr int pr eview window and r et ur ns you t o t he Signal Br owser .
The Pri nt... but t on on t he Si gnal Browse r Pri nt Pre vi e w window opens t he
st andar d pr int dialog box, fr om which you can pr int t he cont ent s of your pr int
pr eview window.
If you choose t o pr int fr om t he pr int dialog, bot h t hat dialog and t he Si gnal
Brows er Pri nt Previ ew window will close, and t he cont ent s of t he pr int
pr eview will pr int .
If you choose not t o pr int , t he pr int dialog and t he Si gnal Brows er Pri nt
Previ ew window will close, and you will r et ur n t o t he Signal Br owser .
Any changes you make, befor e opening t he pr int pr eview window, t hat affect
t he display of dat a in t he Signal Br owser (see Viewing and Explor ing Signals
5 Interactive Tools
5-56
on page 5-49) will affect t he display of dat a in t he Si gnal Brows er Pri nt
Previ ew window in exact ly t he same way. For example, in t he pr int pr eview
shown below:
The plot of t he mtlb dat a has been mouse zoomed (see Zoom Cont r ols on
page 5-31).
The panner display r eflect s t he cur r ent zoom level by enclosing t he zoomed
por t ion of t he whole signal in a window (see Panner Display on page 5-52).
The r uler s have been moved int o t he zoomed ar ea and t he r uler cont r ols have
been changed fr om Track t o Slope (see Ruler Cont r ols on page 5-33).
The r uler measur ement s displayed r eflect t he changes t o t he r uler s in t he
display ar ea (see Making Signal Measur ement s on page 5-37).
Changes you make in t he Pre fe rence s dialog box in SPTool, befor e opening t he
pr int pr eview window, will also affect t he Si gnal Browse r Pri nt Pre vi e w
window in t he same way t hat t hey affect t he Signal Br owser it self. For
example, in t he pr int pr eview shown below, t he panner display and t he r uler
measur ement s have been suppr essed, and t he axis labels have been changed,
Using the Signal Browser: Interactive Signal Analysis
5-57
by changes t o t he Signal Br owser pr efer ences (see Signal Br owser Set t ings
on page 5-23).
NOTE The HandleVisibility pr oper t y of t he Pri nt Pre vi e w figur e window
is set t o 'on'. This allows you t o modify t he pr eview using Handle Gr aphics
commands fr om t he MATLAB command line or t he Plot Edit or t ools (see
Using MATLAB Graphics for mor e infor mat ion). Changes t hat you make in
t he pr eview window pr int exact ly as t hey appear on t he scr een; however, t hey
ar e not saved when t he Pri nt Previ ew figur e window is closed.
Saving Signal Data
Aft er cr eat ing a signal in SPTool (by applying a filt er t o an impor t ed signal, for
example), you can expor t t he signal infor mat ion t o t he wor kspace or t o disk
using Export... fr om t he Fi le menu in SPTool. The signal infor mat ion is st or ed
in a st r uct ur e t hat you can access t o r et r ieve t he signal dat a and sample
fr equency. The signal st r uct ur e also cont ains a number of fields t hat ar e used
int er nally by SPTool.
To see t he fields of t he signal st r uct ur e, t r y expor t ing a signal t o t he wor kspace:
5 Interactive Tools
5-58
1 Impor t a signal int o SPTool if t her e ar e none cur r ent ly loaded (see
Impor t ing Signals, Filt er s, and Spect r a on page 5-7). Label t he impor t ed
signal sig1.
2 Expor t t he signal. Select Export... fr om t he Fi le menu.
3 In t he Export dialog box, select sig1 and pr ess t he Export to Works pace
but t on.
4 Type who at t he MATLAB command line t o look at t he var iables in t he
wor kspace. The var iable called sig1 is t he signal st r uct ur e you expor t ed
fr om SPTool.
5 Type sig1 at t he command line t o list t he fields of t he signal st r uct ur e.
The data and Fs fields of t he signal st r uct ur e cont ain t he infor mat ion t hat
defines t he signal. The ot her fields ar e used int er nally by SPTool and ar e
subject t o change in fut ur e r eleases:
The data field is a vect or or ar r ay cont aining t he signals dat a.
The Fs field cont ains t he sample fr equency of t he signal in Her t z.
Using the Filter Designer: Interactive Filter Design
5-59
Using the Filter Designer: Interactive Filter Design
The Filt er Designer pr ovides an int er act ive gr aphical envir onment for t he
design of digit al IIR and FIR filt er s based on specificat ions t hat you ent er on a
magnit ude or pole-zer o plot . Using t he Filt er Designer , you can design IIR and
FIR filt er s of var ious lengt hs and t ypes, wit h st andar d fr equency band
configur at ions (highpass, lowpass, bandpass, bandst op, and mult iband).
Using t he Filt er Designer you can:
Design IIR filt er s wit h st andar d band configur at ions, using t he But t er wor t h,
Chebyshev t ype I, Chebyshev t ype II, and ellipt ic design opt ions
Design FIR filt er s wit h st andar d band configur at ions, using t he equir ipple,
least squar es, and Kaiser window design opt ions
Design FIR and IIR filt er s wit h ar bit r ar y band configur at ions, using t he
Pole/Zer o Edit or
Redesign a filt er by manually adjust ing indicat or s in t he magnit ude plot , or
by gr aphically r eposit ioning t he t r ansfer funct ions poles and zer os
Over lay a spect r um on t he filt er s magnit ude r esponse plot
When you have designed a filt er t o your specificat ions, you can apply t he filt er
t o a select ed signal using t he Apply but t on in SPTool (see Applying a Filt er
on page 5-18).
NOTE For infor mat ion on using filt er design funct ions fr om t he command
line or fr om M-files, see Chapt er 2.
Opening the Filter Designer
You can open or act ivat e t he Filt er Designer fr om SPTool by pr essing t he New
Des i gn or Edi t Des i gn but t ons:
To cr eat e a filt er , pr ess Ne w De si gn in SPTool. A default filt er is gener at ed
and displayed in t he Filt er Designer . You can view t he filt er in a var iet y of
ways in t he Filt er Viewer and modify it in t he Filt er Designer .
To edit a filt er , select it in SPTool and pr ess Edi t De si gn. You can modify t he
filt er in a var iet y of ways in t he Filt er Designer .
5 Interactive Tools
5-60
See Designing a Filt er on page 5-17 for complet e det ails.
Basic Filter Designer Functions
The Filt er Designer has t he following component s:
A pop-up menu for select ing differ ent filt er design met hods
A magnit ude plot (display) ar ea for gr aphically adjust ing filt er r esponses
A pole-zer o plot (display) ar ea for gr aphically adjust ing filt er t r ansfer
funct ions
A Spe ci fi cati ons panel for viewing and modifying t he design par amet er s or
pole-zer o locat ions of t he cur r ent filt er
A Meas urements panel for viewing t he r esponse char act er ist ics and
st abilit y of t he cur r ent filt er
Specificat ion lines for gr aphically adjust ing t he magnit ude r esponse
par amet er s of a filt er
Measur ement lines for measur ing t he magnit ude r esponse par amet er s of a
filt er
Zoom cont r ols for get t ing a closer look at t he magnit ude r esponse or pole-zer o
feat ur es
The following sect ions descr ibe t he differ ent component s of t he Filt er
Designer s int er face and how you can use t hem t oget her t o cr eat e and edit
filt er s.
Menus
File Menu. Use Close fr om t he Fi le menu t o close t he Filt er Designer . Set t ings
you changed and saved using t he Prefere nces dialog box in SPTool ar e saved
and used t he next t ime you open t he Filt er Designer .
Window Menu. Use t he Wi ndow menu t o select a MATLAB figur e window.
Filter Pop-Up Menu
The Fi lte r pop-up menu displays all of t he filt er s cur r ent ly select ed in SPTool.
Select a filt er in t he menu t o make it t he cur r ent filt er in t he Filt er Designer .
Using the Filter Designer: Interactive Filter Design
5-61
Zoom Controls
The available zoom cont r ols in t he Filt er Designer ar e Zoom In-Y, Zoom
Out-Y, Zoom In-X, Zoom Out-X, Pas s Band, Full Vi ew, and Mous e Zoom.
See Zoom Cont r ols on page 5-31 for det ails on using t he zoom cont r ols.
Zoom per sist ence is off by default in t he Filt er Designer ; use t he Filt er
Designer set t ings panel in t he Prefere nces dialog box t o t oggle zoom
per sist ence on and off. See Filt er Designer Set t ings on page 5-27.
Help Button
To use cont ext -sensit ive help, pr ess t he Help but t on. The mouse point er
becomes an ar r ow wit h a quest ion mar k symbol. You can t hen click on any
General controls
Viewing (zoom) controls
Specifications panel for
setting filter parameters
Magnitude response and pole-zero display area
Measurements
panel for
viewing filter
characteristics
Apply the specifications,
or revert to the previous
specifications
5 Interactive Tools
5-62
object in t he Filt er Designer , including menu it ems, t o find out what it is and
how t o use it .
General Controls
Beneat h t he zoom cont r ols ar e sever al gener al cont r ols for filt er design and
display. Some of t hese cont r ols ar e available only when an opt imal filt er design
met hod (e.g., Equi ri pple FIR, Butte rworth IIR) is select ed fr om t he
Algori thm menu, and ar e not available when t he Pole/Zero Edi tor is select ed.
Algorithm. Use t he Algori thm pop-up menu t o select a design met hod for t he
cur r ent filt er . The fir st seven opt ions in t he Algori thm menu t he optimal
design methods all design filt er s based on a high-level specificat ion of filt er
magnit ude r esponse char act er ist ics (such as passband fr equencies or st opband
at t enuat ion). The filt er char act er ist ics ar e specified numer ically in t he
Speci fi cati ons panel or gr aphically on t he magnit ude r esponse plot .
The eight h opt ion, Pole/Zero Edi tor, is not an opt imal design met hod but
allows low-level specificat ion of t he filt er s t r ansfer funct ion via numer ical or
gr aphical pole-zer o placement .
When you select one of t he opt imal design met hods fr om t he menu, t he
magnit ude r esponse plot , Spe ci fi cati ons panel, and Measure ments panel all
updat e t o r eflect t he design par amet er s available for t hat met hod. When you
select Pole /Ze ro Edi tor, t he magnit ude r esponse plot is r eplaced by t he z-plane
for pole-zer o placement .
Auto Design (optimal design methods only). When t he Auto Des i gn check box is
checked, t he filt er s magnit ude r esponse is r edr awn whenever you change a
filt er specificat ion, eit her by ent er ing a value in t he Speci fi cati ons panel or by
dr agging a specificat ion line on t he plot . When t he box is not checked, t he new
r esponse is comput ed and r edr awn only when you pr ess t he Apply but t on or
r elease t he specificat ion line. Auto Des i gn is init ially off by default ; use t he
Optimal design
methods
Transfer function
pole-zero placement
Using the Filter Designer: Interactive Filter Design
5-63
Fi lter Desi gner set t ings panel in t he Pre ferences dialog box t o change t his
default set t ing. See Filt er Designer Set t ings on page 5-27.
Sampling Frequency. The Sampli ng Frequency field allows you t o specify t he
filt er s sampling fr equency in Her t z. To change t he sampling fr equency, t ype a
value in t he box and pr ess Enter. This is t he same as changing t he sampling
fr equency by select ing Sampli ng Fre quency... fr om t he SPTool Edi t menu (see
Edit ing Dat a Object s in SPTool on page 5-15). The fr equency axis of t he
magnit ude r esponse plot is updat ed t o r eflect t he new sampling fr equency.
Changing t he Sampli ng Fre quency in t he Pole/Zer o Edit or does not alt er t he
pole-zer o plot , but does scale t he cor r esponding magnit ude plot in t he Filt er
Viewer (if t he Viewer is open).
Overlay Spectrum (design methods only). The Filt er Designer allows you t o over lay
a signal spect r um on t he filt er s magnit ude r esponse plot . Pr ess t he Overlay
Spectrum... but t on t o display a list of t he cur r ent spect r a in SPTool. Select a
spect r um fr om t he list and pr ess OK t o over lay it on t he cur r ent magnit ude
r esponse plot . Not e t hat t he spect r um is plot t ed on t he exist ing fr equency axis,
which is scaled t o t he filt er s sampling fr equency.
Filter Specifications PanelDesign Methods
When you design a new filt er wit h t he design met hods, t he Filt er Designer
init ially cont ains t he specificat ions and magnit ude r esponse plot for an or der
22, lowpass, equir ipple filt er .
Use t he Type pop-up menu in t he Spe ci fi cati ons panel t o select a band
configur at ion. Use t he edit boxes below it in t he panel t o change t he band edge
fr equencies and t he amount of r ipple in t he passband and at t enuat ion in t he
st opband. Check t he Mi ni mum Order box t o let t he Filt er Designer
aut omat ically det er mine t he lowest filt er or der t hat achieves t he cur r ent
specificat ions.
The design par amet er s available in t he Spe ci fi cati ons panel depend on t he
filt er design select ed in t he Algori thm pop-up menu, t he band configur at ion
select ed in t he Type pop-up menu, and t he st at e of t he Mi ni mum Orde r check
box.
Specifications Parameters Automatic Order Selection. When t he Mi ni mum Order
box is checked, all of t he filt er designs except Le as t Squares FIR display t he
same set of par amet er s in t he Speci fi cati ons panel. (The or der for t he Least
Squares FIR design cannot be aut omat ically comput ed). For lowpass and
5 Interactive Tools
5-64
highpass band configur at ions, t hese par amet er s include t he passband edge
fr equency Fp, t he st opband edge fr equency Fs, t he passband r ipple Rp, and t he
st opband at t enuat ion Rs. For bandpass and bandst op configur at ions, t he
par amet er s include t he lower and upper passband edge fr equencies, Fp1 and
Fp2, t he lower and upper st opband edge fr equencies, Fs1 and Fs2, t he
passband r ipple Rp, and t he st opband at t enuat ion Rs. Fr equency values ar e in
Her t z, and r ipple and at t enuat ion values ar e in dB.
Specifications ParametersManual Order Selection. When t he Mi ni mum Order box
is not checked, an Orde r par amet er for set t ing t he filt er or der appear s below
it , and each filt er design displays a unique set of par amet er s in t he
Speci fi cati ons panel. These ar e shown in t he t able below, wher e Wp and Ws
ar e t he weight s for t he passband and st opband, Bet a is t he Kaiser window
par amet er , Fc is t he cut off fr equency, and F3db is t he -3 dB fr equency.
Designing a New Filter With the Design Methods. In gener al, follow t hese st eps t o
design a new filt er using t he Speci fi cati ons panel par amet er s:
1 Click-and-dr ag t o select an appr opr iat e opt imal
filt er design met hod fr om t he Algori thm pop-up
menu.
2 Click-and-dr ag t o select t he band configur at ion
fr om t he Type pop-up menu.
3 Type in t he Speci fi cati ons panels edit able fields
t o change t he values for band edge fr equencies, r ipple, at t enuat ion, and
ot her filt er char act er ist ics.
Lowpass Highpass Bandpass Bandstop
Equiripple FIR Fp, Fs, Wp, Ws Fp, Fs, Wp, Ws Fp1, Fp2, Fs1, Fs2, Wp, Ws Fp1, Fp2, Fs1, Fs2, Wp, Ws
Least Squares FIR Fp, Fs, Wp, Ws Fp, Fs, Wp, Ws Fp1, Fp2, Fs1, Fs2, Wp, Ws Fp1, Fp2, Fs1, Fs2, Wp, Ws
Kaiser Window FIR Fc, Bet a Fc, Bet a Fc1, Fc2, Bet a Fc1, Fc2, Bet a
Butterworth IIR F3db F3db F3db 1, F3db 2 F3db 1, F3db 2
Chebyshev Type I IIR Fp, Rp Fp, Rp Fp1, Fp2, Rp Fp1, Fp2, Rp
Chebyshev Type II IIR Fs, Rs Fs, Rs Fs1, Fs2, Rs Fs1, Fs2, Rs
Elliptic IIR Fp, Rp, Rs Fp, Rp, Rs Fp1, Fp2, Rp, Rs Fp1, Fp2, Rp, Rs
Using the Filter Designer: Interactive Filter Design
5-65
4 Pr ess Enter aft er t yping in an edit able t ext box t o ent er t he value. If Auto
De si gn is not checked, pr ess t he Apply but t on below t he Speci fi cati ons
panel t o updat e t he magnit ude plot .
5 To specify a filt er or der , pr ess Mi ni mi ze Orde r t o deselect t he check box and
disable aut omat ic filt er or der select ion. Then t ype a value for t he Order
par amet er . If Auto Des i gn is not checked, pr ess Apply.
Edit a new filt er or an exist ing filt er in t he same way. Not e t hat when Auto
Des i gn is disabled and you change a filt er s par amet er values, t he magnit ude
r esponse plot changes fr om solid lines t o dashed lines. This indicat es t hat t he
plot no longer r eflect s t he cur r ent specificat ions. When you pr ess t he Apply
but t on, t he new r esponse is comput ed and t he lines r ever t t o t he solid st yle.
When Auto De si gn is enabled, t he plot updat es whenever you change a filt er
specificat ion.
Filter Measurements PanelDesign Methods
When you design a filt er , t he Meas ure ments panel (shown at left ) displays t he
values of filt er par amet er s t hat do not appear in t he Speci fi cati ons panel. For
example, when t he Filt er Designer pr ovides an Fs par amet er in t he
Speci fi cati ons panel, it displays t he Actual Fs value in t he Meas ure ments
panel. Similar ly, when t he Mi ni mum Order opt ion is select ed in t he
Speci fi cati ons panel, t he comput ed filt er or der is displayed in t he Orde r field
of t he Me asureme nts panel. The values in t he Me asureme nts panel ar e
updat ed whenever t he magnit ude plot is r edr awn.
Measurement Parameters Automatic Order Selection. The par amet er combinat ions
t hat appear in t he Measure ments panel ar e shown in t he following t wo t ables.
The fir st t able list s t he par amet er s t hat appear when Mi ni mum Orde r is
checked (aut omat ic or der select ion). The st opband edge fr equency par amet er s
list ed (Fs, Fs1, Fs2) ar e t he actual edge fr equencies for t he design, r at her t han
t he desired fr equencies ent er ed in t he Spe ci fi cati ons panel.
5 Interactive Tools
5-66
Measurement Parameters Manual Order Selection. The next t able shows t he
par amet er set s t hat appear in t he Me as ureme nts panel when Mi ni mum
Orde r is not select ed. The measur ement s t hat can be int er act ively changed by
dr agging t he r ed measur ement lines on t he r esponse plot ar e shown shaded.
Filter Specifications PanelPole/Zero Editor
When you design a new filt er using t he Pole/Zer o Edit or , t he Filt er Designer
init ially displays a pole-zer o plot for t he default or der -22 filt er .
The gener al pole-zer o (fact or ed) for m of t he t r ansfer funct ion of a digit al filt er
is:
wher e z
1
, z
2
, ..., z
m
ar e t he filt er zer os, p
1
, p
2
, ..., p
n
ar e t he filt er poles, and k is
t he over all t r ansfer funct ion gain. The number of zer os and poles do not need
t o be t he same.
The cont r ols in t he Speci fi cati ons panel allow you t o set t he over all gain and
t o numer ically adjust t he posit ion of each pole and zer o using polar or
r ect angular coor dinat es.
Lowpass Highpass Bandpass Bandstop
Equiripple FIR
Or der, Rp, Rs, Wp,
Ws
Or der, Rp, Rs, Wp,
Ws
Or der, Rp, Rs, Wp, Ws Or der, Rp, Rs, Wp, Ws
Least Squares FIR Or der cannot be aut omat ically comput ed.
Kaiser Window FIR
Or der, Fc, Bet a,
Rp, Rs
Or der, Fc, Bet a,
Rp, Rs
Or der, Fc1, Fc2, Bet a, Rp,
Rs
Or der, Fc1, Fc2, Bet a, Rp,
Rs
Butterworth IIR Or der, Rp, F3db Or der, Rp, F3db Or der, Rp, F3db 1, F3db 2 Or der, Rp, F3db 1, F3db 2
Chebyshev Type I IIR Or der, Fs Or der, Fs Or der, Fs1, Fs2 Or der, Fs1, Fs2
Chebyshev Type II IIR Or der, Fs Or der, Fs Or der, Fs1, Fs2 Or der, Fs1, Fs2
Elliptic IIR Or der, Fs Or der, Fs Or der, Fs1, Fs2 Or der, Fs1, Fs2
Lowpass Highpass Bandpass Bandstop
Equiripple FIR Rp, Rs Rp, Rs Rp, Rs Rp, Rs
Least Squares FIR Rp, Rs Rp, Rs Rp, Rs Rp, Rs
Kaiser Window FIR Fp, Fs, Rp, Rs Fp, Fs, Rp, Rs Fp1, Fp2, Fs1, Fs2, Rp, Rs Fp1, Fp2, Fs1, Fs2, Rp, Rs
Butterworth IIR Fp, Fs, Rp, Rs Fp, Fs, Rp, Rs Fp1, Fp2, Fs1, Fs2, Rp, Rs Fp1, Fp2, Fs1, Fs2, Rp, Rs
Chebyshev Type I IIR Fs, Rs Fs, Rs Fs1, Fs2, Rs Fs1, Fs2, Rs
Chebyshev Type II IIR Fp, Rp Fp, Rp Fp1, Fp2, Rp Fp1, Fp2, Rp
Elliptic IIR Fs Fs Fs1, Fs2 Fs1, Fs2
H z ( )
Z z ( )
P z ( )
---------- k
z z
1
( ) z z
2
( )Lz z
m
( )
z p
1
( ) z p
2
( )Lz p
n
( )
---------------------------------------------------------------- = =
Using the Filter Designer: Interactive Filter Design
5-67
The value you ent er in t he Gai n edit box specifies t he gain, k. The Coordi nat es
pop-up menu let s you posit ion t he poles and zer os using eit her polar or
r ect angular measur ement s. When Polar is select ed, you can specify t he
coor dinat es of t he cur r ent ly select ed pole or zer o by ent er ing values in t he Mag
and Angle edit boxes. The r esult ing locat ion of t he select ed pole or zer o is
wher e M is t he magnit ude specified by Mag, and is t he angle in r adians
specified by Angle .
When Rectangular is select ed, you can specify t he coor dinat es of t he cur r ent ly
select ed pole or zer o by ent er ing values in t he X and Y edit boxes. The r esult ing
locat ion of t he select ed pole or zer o is
The Conjugate pai r checkbox cont r ols whet her t he cur r ent select ion is a
complex conjugat e pair of poles or zer os, or a lone pole or zer o. When a lone pole
or zer o is select ed on t he pole-zer o plot , t he Conjugate pai r checkbox is
inact ive. If you now enable t he Conjugate pai r checkbox by clicking it , a new
conjugat e pole or zer o (as appr opr iat e) is cr eat ed t o complet e t he pair .
When a conjugat e pair of poles or zer os is select ed on t he plot (by clicking one
of t he pair ), t he Conjugate pai r checkbox is act ive. If you now disable t he
Conjugate pai r checkbox by clicking it , t he conjugat e pair is br oken int o t wo
lone poles or zer os at t he same posit ions, and only one of t hese r emains
select ed.
When t he Conjugate pai r checkbox is select ed, t he coor dinat es you specify (in
eit her angular or r ect angular for m) cont r ol t he locat ion of t he cur r ent ly
select ed complex conjugat e pair of poles or zer os, wit h locat ions
or
Designing a New Filter with the Pole/Zero Editor. In gener al, follow t hese st eps t o
design a new filt er using t he Spe ci fi cati ons panel par amet er s:
z Me
j
=
z X j Y + =
z X j Y t =
z Me
j t
=
5 Interactive Tools
5-68
1 Click-and-dr ag t o select t he Pole/Zero Edi tor
opt ion fr om t he Algori thm pop-up menu.
2 Ent er t he desir ed filt er gain in t he Gai n edit box.
3 Select a pole or zer o (or conjugat e pair ) by clicking
on one of t he or symbols on t he plot .
4 Choose t he coor dinat es t o wor k in by specifying Polar or Rectangular fr om
t he Coordi nates pop-up menu.
5 Specify t he new locat ion(s) of t he select ed pole, zer o, or conjugat e pair by
t yping values int o t he Mag and Angle (for angular coor dinat es) or X and Y
(for r ect angular coor dinat es) edit boxes.
6 Use t he Conjugate pai r checkbox t o cr eat e a conjugat e pair fr om a lone pole
or zer o or t o br eak a conjugat e pair int o t wo individual poles or zer os.
Edit a new filt er or an exist ing filt er in t he same way.
TIP Keep t he Filt er Viewer open while designing a filt er wit h t he Pole/Zer o
Edit or. Any changes t hat you make t o t he filt er t r ansfer funct ion in t he
Pole/Zer o Edit or ar e t hen simult aneously r eflect ed in t he r esponse plot s of t he
Filt er Viewer.
Filter Measurements PanelPole/Zero Editor
When you design a filt er , t he Measure ments panel (shown at left ) displays
useful infor mat ion about t he filt er being designed. The panel always shows t he
number of zer os and poles (t he lar ger of which is t he or der of t he filt er ), and
indicat es whet her t he filt er is st able or unst able (poles out side t he unit cir cle).
The panel also shows t he phase char act er ist ics of t he filt er . Wher e m is t he
t ot al number of zer os, t he four possible phase condit ions ar e:
Mi ni mum Phase , which indicat es t hat bet ween 1 and m-1 zer os ar e on t he
unit cir cle, while t he r est of t he zer os ar e inside t he unit cir cle
Pole
Zero
i 1 m , , = z
i
1
Using the Filter Designer: Interactive Filter Design
5-69
Stri ctly Mi ni mum Phas e, which indicat es t hat all of t he zer os ar e inside t he
unit cir cle
Maxi mum Phas e, which indicat es t hat bet ween 1 and m zer os ar e on t he
unit cir cle, while t he r est of t he zer os ar e out side t he unit cir cle
Stri ctly Maxi mum Phase, which indicat es t hat all of t he zer os ar e out side
t he unit cir cle
When t he Measureme nts panel does not indicat e any of t he above condit ions,
zer os ar e bot h inside and out side t he unit cir cle.
When a new pole or zer o is being placed on t he plot (using t he Add Poles or
Add Zeros t ools, descr ibed on page 5-72) t he Measurements panel shows
addit ional posit ioning infor mat ion. Aft er pr essing eit her t he Add Poles or Add
Zeros but t on, and befor e clicking on t he plot t o place t he new pole(s) or zer o(s),
t he Meas ure ments panel displays t he pr ecise posit ion of t he point er over t he
plot ar ea.
All values in t he Me as ureme nts panel ar e updat ed cont inuously as a pole or
zer o is r eposit ioned.
Magnitude Plot (Display) AreaDesign Methods
The r esponse of t he filt er select ed in t he Fi lter pop-up menu is displayed
gr aphically in t he magnit ude r esponse plot ar ea of t he Filt er Designer , and it s
char act er ist ics ar e shown in t he Speci fi cati ons and Me as urements panels.
i 1 m , , = z
i
1 <
i 1 m , , = z
i
1
i 1 m , , = z
i
1 >
Add Poles Pointer
Add Zeros Pointer
5 Interactive Tools
5-70
You can zoom in on t he displayed filt er in t he magnit ude plot (see Zoom
Cont r ols on page 5-31) and you can dr ag t he specificat ion lines t o r edesign t he
displayed filt er visually (see t he next sect ion).
Specification Lines. You can r edesign a filt er by manipulat ing t he gr een
specificat ion lines in t he magnit ude plot . Using t he specificat ion lines, you can
change t he passband r ipple, st opband at t enuat ion, and edge fr equencies of a
filt er :
Set passband r ipple or st opband at t enuat ion by clicking on a gr een line and
dr agging it up or down. The Rp and Rs values displayed in t he
Spe ci fi cati ons panel change as you dr ag. If Auto De si gn is checked, t he
r esponse plot also updat es as you dr ag t he lines. If Auto De si gn is disabled,
t he r esponse plot updat es when you r elease t he mouse.
NOTE Wit h IIR filt er s you can only dr ag t he lower passband bar and t he
st opband bar. The upper passband bar is fixed at 0.
Set edge fr equencies eit her by clicking on t he edge of a horizontal gr een line
(t he mouse point er changes t o ) and dr agging t he edge t o a new fr equency,
or by clicking anywher e on a vertical gr een line (if t he Filt er Designer
pr ovides one) and dr agging it hor izont ally t o a new fr equency. The Fp and Fs
values displayed in t he Spe ci fi cati ons panel change as you dr ag. If Auto
Des i gn is checked, t he r esponse plot also updat es as you dr ag t he lines. If
Auto Desi gn is disabled, t he r esponse plot updat es when you r elease t he
mouse.
See Redesigning a Filt er Using t he Magnit ude Plot on page 5-78 for det ails.
Measurement Lines. A number of t he filt er designs pr ovide r uler s on t he r esponse
plot t hat allow you t o measur e r esponse magnit ude levels. These measur ement
lines, which appear in r ed on t he plot , ar e available for t he Kaiser window,
But t er wor t h, Chebyshev t ype I, and Chebyshev t ype II filt er s when t he
Mi ni mum Order check box is not select ed. As you dr ag a measur ement line,
t he cor r esponding values in t he Measureme nts panel change t o r eflect t he
measur ement lines cur r ent posit ion.
Using the Filter Designer: Interactive Filter Design
5-71
Magnitude Plot (Display) AreaPole/Zero Editor
The plot ar ea of t he Pole/Zer o Edit or displays t he filt er t r ansfer funct ions pole
and zer os on t he complex z-plane. The unit cir cle is shown in dashed lines,
along wit h t he ver t ical and hor izont al gr id lines, t o pr ovide a visual r efer ence
for pole-zer o placement .
You can zoom in on t he z-plane (see Zoom Cont r ols on page 5-31) and you can
dr ag t he pole and zer o symbols t o r edesign t he filt er t r ansfer funct ion visually
(see t he next sect ion).
Positioning Poles and Zeros. You can r edesign t he t r ansfer funct ion by simply
clicking and dr agging on one of t he pole or zer o symbols. Poles or zer os appear
gr een (r at her t han t he usual blue) when select ed. In a conjugat e pair of poles
or zer os, bot h conjugat es ar e select ed when eit her is clicked; conjugat e pair s
move t oget her when dr agged, maint aining equal dist ance fr om t he r eal axis at
all t imes. To ungr oup conjugat es, select t he desir ed pair and uncheck
Conjugate pai r in t he Speci fi cati ons panel.
When t wo or mor e pole symbols (or t wo or mor e zer o symbols) ar e placed
dir ect ly on t op of each ot her , a number is displayed next t o t he symbols (on t he
left for poles, and on t he r ight for zer os) indicat ing t he number of poles or zer os
at t hat locat ion (e.g., ). This number makes it easy t o keep t r ack of all t he
poles and zer os in t he plot ar ea, even when sever al ar e super imposed on each
ot her and ar e not visually differ ent iable. Not e, however , t hat t his number does
not indicat e t he multiplicity of t he poles or zer os t o which it is at t ached.
5 Interactive Tools
5-72
To help det ect whet her a set of poles or zer os ar e t r uly mult iples, use t he zoom
t ools t o magnify t he r egion ar ound t he poles or zer os in quest ion. Because
numer ical limit at ions usually pr event any set of poles or zer os fr om shar ing
exactly t he same value, at a high enough zoom level even t r uly mult iple poles
or zer os appear dist inct fr om each ot her . A common way t o assess whet her a
par t icular gr oup of poles or zer os cont ains mult iples is by compar ing t he
mut ual pr oximit y of t he gr oup member s against a select ed t hr eshold value. As
an example, t he residuez funct ion defines a pole or zer o as being a mult iple of
anot her pole or zer o if t he absolut e dist ance separ at ing t hem is less t han 0.1%
of t he lar ger pole or zer os magnit ude.
Tools. The Pole/Zer o Edit or pr ovides sever al t ools t o assist wit h pole-zer o
placement . The t ools ar e locat ed at t he t op left of t he pole-zer o plot ar ea.
At t he bot t om of t he plot ar ea, t her e ar e t wo addit ional but t ons, Send To Back
and De lete All. Use Send To Back when you ar e unable t o select a pole or zer o
because anot her pole or zer o is in t he way. Select t he int er fer ing pole or zer o on
t he plot , and pr ess Send To Back t o move t hat pole or zer o behind all ot her
symbols on t he plot (i.e., last in t he st acking or der ). You can t hen select t he
desir ed pole or zer o wit hout t he int er fer ence of t he ot her symbol.
Icon Name Description
Dr ag Poles/Zer os Tool
Use t his t ool t o select and dr ag poles and zer os on
t he plot .
Add Poles Tool
Use t his t ool t o add poles t o t he plot . Simply click
on t he plot wher e you want t o place t he new pole
(or conjugat e pair, when t he Conjugate pai r
checkbox is select ed).
Add Zer os Tool
Use t his t ool t o add zer os t o t he plot . Simply click
on t he plot wher e you want t o place t he new zer o
(or conjugat e pair, when t he Conjugate pai r
checkbox is select ed).
Delet e Poles/Zer os Tool
Use t his t ool t o delet e poles and zer os fr om t he
plot . Simply click on any pole or zer o t o delet e it .
When you click on a set of poles or zer o occupying
t he same locat ion, only t he t op-most pole or zer o
is r emoved. You can also use t he Dele te or
Backspace key on t he keyboar d t o delet e t he
cur r ent ly select ed pole or zer o.
Using the Filter Designer: Interactive Filter Design
5-73
The De le te All but t on delet es ever y pole and zer o in t he plot ar ea.
NOTE The Delete All oper at ion cannot be undone. Once all t he poles and
zer os ar e r emoved, t hey cannot be r est or ed.
Designing Finite Impulse Response (FIR) Filters
The Filt er Designer pr ovides t hr ee opt ions for basic FIR filt er design. These
opt ions allow you t o cr eat e FIR filt er s wit h st andar d band configur at ions
(lowpass, highpass, bandpass, or bandst op configur at ions only). The t hr ee
opt ions for FIR filt er design in t he Algori thm pop-up menu ar e:
Equi ri pple FIR, which accesses t he t oolbox funct ion remez t o cr eat e an
equir ipple FIR filt er .
Le as t Squares FIR, which accesses t he t oolbox funct ion firls t o cr eat e an
FIR filt er using t he least squar e design met hod.
Kai s er Wi ndow FIR, which accesses t he fir1 funct ion t o cr eat e an FIR filt er
using a Kaiser window.
Example: FIR Filter Design, Standard Band Configuration
In t he following example, use t he Kaiser window filt er design opt ion:
1 Select Kai se r Wi ndow FIR as t he filt er design fr om t he Algori thm pop-up
menu.
2 Select bandpass fr om t he Type pop-up menu as t he configur at ion.
3 Set t he filt er s sampling fr equency t o 2000 Hz by ent er ing t his value in t he
Sampli ng Frequency t ext box.
4 Pr ess Apply t o r edr aw t he r esponse wit h t hese set t ings.
NOTE You must pr ess Apply befor e you change t he following par amet er s.
5 Check t he Mi ni mum Orde r check box t o enable aut omat ic or der select ion.
5 Interactive Tools
5-74
6 Set Fp1 t o 290 and Fp2 t o 525.
These fields r espect ively define t he lower and upper passband edge
fr equencies in Her t z.
7 Set Fs1 t o 200 and Fs2 t o 625.
These fields r espect ively define t he lower and upper st opband edge
fr equencies in Her t z.
8 Set Rp (passband r ipple) t o 4 and Rs (st opband at t enuat ion) t o 30.
Rp and Rs ar e specified in dB.
9 Pr ess t he Apply but t on.
The Filt er Designer calls fir1 t o cr eat e t he filt er using a Kaiser window. The
Filt er Designer updat es t he magnit ude plot t o show t he new filt er s magnit ude
r esponse.
Using the Filter Designer: Interactive Filter Design
5-75
Filter Design Options
When t he Mi ni mum Order opt ion is disabled, you can specify par amet er s t hat
define char act er ist ics unique t o cer t ain filt er t ypes:
For equir ipple and least squar es filt er s: t he weight s for er r or minimizat ion
For Kaiser window filt er s: t he cut off fr equency and par amet er of t he Kaiser
window
Order Selection for FIR Filter Design
As descr ibed ear lier , t he FIR filt er design opt ions available t hr ough t he Filt er
Designer call t he t oolbox funct ions remez, firls, and fir1. In calculat ing filt er
or der , t he Filt er Designer uses t he same guidelines as t he t oolbox funct ions:
The Equi ri pple FIR design opt ion calls t he remezord or der est imat ion
funct ion t o det er mine a filt er or der t hat meet s a set of specificat ions. In some
cases, remezord under est imat es t he filt er or der n. If t he filt er does not
appear t o meet t he given specificat ions using Mi ni mum Order or der
select ion, deselect Mi ni mum Order and manually specify a slight ly lar ger
or der (n+1 or n+2).
The Leas t Squares FIR design opt ion calls t he t oolbox funct ion firls.
Because t he t oolbox does not pr ovide an or der est imat ion funct ion for use
wit h firls, you cannot use t he Mi ni mum Order opt ion wit h t he Leas t
Squares FIR met hod.
The Kai s er Wi ndow FIR design opt ion calls kaiserord, t he or der est imat ion
funct ion, which somet imes under est imat es t he filt er or der n. If t he filt er does
not appear t o meet t he given specificat ions using Mi ni mum Order or der
select ion, deselect Mi ni mum Order and manually specify a slight ly lar ger
or der (n+1 or n+2).
All of t he FIR filt er design opt ions in t he Filt er Designer r equir e an even filt er
or der for t he highpass and bandst op configur at ions. For mor e infor mat ion on
or der select ion wit h t he FIR filt er design opt ions, see t he r efer ence descr ipt ions
of remez, remezord, kaiserord, firls, and fir1 in Chapt er 6.
5 Interactive Tools
5-76
Designing Infinite Impulse Response (IIR) Filters
The Filt er Designer let s you design a number of classical IIR filt er s, including
But t er wor t h, Chebyshev t ype I, Chebyshev t ype II, and ellipt ic filt er s.
Example: Classical IIR Filter Design
In t he following example, design a simple Chebyshev t ype I filt er :
1 Select Che bys hev Type I IIR as t he filt er design fr om t he Algori thm
pop-up menu.
2 Select hi ghpass fr om t he Type menu as t he configur at ion.
3 Set t he filt er s sample fr equency t o 2000 Hz by ent er ing t his value in t he
Sampli ng Freque ncy t ext box.
4 Pr ess Apply t o r edr aw t he r esponse wit h t hese set t ings.
NOTE You must pr ess Apply befor e you change t he following par amet er s.
5 Check t he Mi ni mum Order check box.
6 Set Fp (passband edge fr equency) t o 800 and Fs (st opband edge fr equency)
t o 700.
Fp and Fs ar e specified in Her t z.
7 Set Rp (passband r ipple) t o 2.5 and Rs (st opband at t enuat ion) t o 35.
Rp and Rs ar e specified in dB.
8 Pr ess Apply t o dr aw t he magnit ude r esponse.
9 Deselect Mi ni mum Orde r and specify a filt er or der of 7. Pr ess Apply t o
r edr aw t he magnit ude r esponse.
Using the Filter Designer: Interactive Filter Design
5-77
The Filt er Designer calls t he appr opr iat e filt er design funct ion t o cr eat e t he
filt er .
To zoom in on plot det ails, use t he zoom cont r ol but t ons as descr ibed in Zoom
Cont r ols on page 5-31.
Filter Design Options
When t he Mi ni mum Order opt ion is disabled, you can specify par amet er s t hat
define char act er ist ics unique t o cer t ain filt er t ypes:
For But t er wor t h filt er s: t he -3 dB fr equencies
For Chebyshev t ype I filt er s: t he passband edge fr equencies
For Chebyshev t ype II filt er s: t he st opband edge fr equencies
For ellipt ic filt er s: t he passband edge fr equencies
In t he following example, r edesign t he Chebyshev t ype I filt er fr om t he
pr evious example as a But t er wor t h filt er , using a -3 dB fr equency of 800 Hz:
5 Interactive Tools
5-78
1 Select t he Butterworth IIR filt er design fr om t he Algori thm menu.
The magnit ude r esponse plot changes t o r eflect t he new design.
2 Type a value of 800 in t he F3db t ext field.
3 Pr ess Apply t o updat e t he r esponse plot .
Order Selection for IIR Filter Design
The IIR filt er design opt ions available t hr ough t he Filt er Designer call t he
t oolbox filt er design funct ions. In calculat ing t he or der for a given filt er , t he
Filt er Designer uses t he cor r esponding or der est imat ion funct ion if t he
Mi ni mum Order check box is select ed.
For det ails on or der select ion wit h t he IIR filt er design opt ions, see t he
r efer ence descr ipt ions of buttord, cheb1ord, cheb2ord, and ellipord in
Chapt er 6.
Redesigning a Filter Using the Magnitude Plot
Aft er designing a filt er in t he Filt er Designer , you can r edesign it by dr agging
t he specificat ion lines in t he magnit ude plot . Use t he specificat ion lines t o
change passband r ipple, st opband at t enuat ion, and edge fr equencies (see
Specificat ion Lines on page 5-70 for det ails). In t he following example, cr eat e
a Chebyshev filt er and modify it by dr agging t he specificat ion lines:
1 Cr eat e a Chebyshev t ype I highpass filt er wit h a sample fr equency of
2000 Hz. Set t he following par amet er s:
Fp = 800
Fs = 700
Rp = 2.5
Rs = 35
2 Check Mi ni mum Order so t he Filt er Designer can calculat e t he lowest filt er
or der t hat pr oduces t he desir ed char act er ist ics.
3 Pr ess Apply t o updat e t he r esponse plot .
4 Posit ion t he cur sor over t he gr een line specifying t he st opband.
The cur sor changes t o t he up/down dr ag indicat or .
Using the Filter Designer: Interactive Filter Design
5-79
5 Dr ag t he line unt il t he Rs (st opband at t enuat ion) field r eads 100.
Not e t hat t he Orde r value in t he Me as ureme nts panel changes because a
higher filt er or der is needed t o meet t he new specificat ions.
Saving Filter Data
Aft er designing a filt er in t he Filt er Designer , you can expor t t he filt er
infor mat ion t o t he wor kspace or t o disk using Export... fr om t he Fi le menu in
SPTool. The filt er infor mat ion is st or ed in a st r uct ur e t hat you can access t o
r et r ieve t he coefficient s and design par amet er s of t he filt er you cr eat ed. The
filt er st r uct ur e also cont ains a number of fields t hat ar e used int er nally by
SPTool.
To see t he fields of t he filt er st r uct ur e, fir st expor t a filt er t o t he wor kspace:
1 Cr eat e a new filt er by pr essing New De si gn in SPTool. The new filt er is
called filt1.
2 Select Export... fr om t he Fi le menu.
3 In t he Export from SPTool dialog box, select filt1 and pr ess t he Export
to Works pace but t on.
4 Type who at t he MATLAB command line t o look at t he var iables in t he
wor kspace. The var iable called filt1 is t he filt er st r uct ur e you expor t ed
fr om SPTool.
5 At t he command line t ype filt1 t o list t he fields of t he filt er st r uct ur e.
The tf, Fs, and specs fields of t he filt er st r uct ur e cont ain t he infor mat ion t hat
descr ibes t he filt er . These fields ar e discussed below. The ot her fields in t he
st r uct ur e ar e used int er nally by SPTool, and ar e subject t o change in fut ur e
r eleases.
tf. The tf field is a st r uct ur e cont aining t he t r ansfer funct ion r epr esent at ion of
t he filt er :
tf.num cont ains t he numer at or coefficient s
tf.den cont ains t he denominat or coefficient s
5 Interactive Tools
5-80
bot h in descending power s of z
wher e b is a vect or cont aining t he coefficient s fr om t he tf.num field, a is a
vect or cont aining t he coefficient s fr om t he tf.den field, m is t he numer at or
or der , and n is t he denominat or or der . You can change t he filt er r epr esent at ion
fr om t he default t r ansfer funct ion t o anot her for m by using t he tf2ss or tf2zp
funct ions.
Fs. The Fs field cont ains t he sampling fr equency of t he filt er in Her t z.
specs. The specs field is a st r uct ur e cont aining infor mat ion about t he filt er
design. The fir st field, specs.currentModule, cont ains a st r ing r epr esent ing
t he design select ed for t he filt er in t he Filt er Designer s Algori thm pop-up
menu. The possible cont ent s of t he currentModule field, and t he cor r esponding
designs, ar e shown below.
Following t he specs.currentModule field, t her e may be up t o seven addit ional
fields, wit h labels such as specs.fdremez, specs.fdfirls, et c. The design
specificat ions for t he most r ecent ly expor t ed filt er ar e cont ained in t he field
currentModule Algorithm
fdbutter But t er wor t h IIR
fdcheby1 Chebyshev Type I IIR
fdcheby2 Chebyshev Type II IIR
fdellip Ellipt ic IIR
fdfirls Least Squar es FIR
fdkaiser Kaiser Window FIR
fdremez Equir ipple FIR
H z ( )
B z ( )
A z ( )
-----------
b 1 ( ) b 2 ( )z
1
L b n b 1 + ( )z
m
+ + +
a 1 ( ) a 2 ( )z
1
L a n a 1 + ( )z
n
+ + +
-------------------------------------------------------------------------------------- = =
Using the Filter Designer: Interactive Filter Design
5-81
whose label mat ches t he currentModule st r ing. For example, if t he specs
st r uct ur e is
currentModule: 'fdkaiser'
fdremez: [1x1 struct]
fdfirls: [1x1 struct]
fdkaiser: [1x1 struct]
t he filt er specificat ions ar e cont ained in t he fdkaiser field, which is it self a
dat a st r uct ur e.
The specificat ions include t he par amet er values fr om t he Speci fi cati ons panel
of t he Filt er Designer , such as band edges and filt er or der . For example, t he
Kaiser window filt er above has t he following specificat ions st or ed in
specs.fdkaiser.
setOrderFlag: 0
type: 1
f: [0 0.1000 0.1500 1]
Rp: 3
Rs: 20
Wn: 0.1250
order: 34
Beta: 0
wind: [35x1 double]
Because cer t ain filt er par amet er s ar e unique t o a par t icular design, t his
st r uct ur e has a differ ent set of fields for each filt er design. For example, t he
Beta field above only appear s in t he specs st r uct ur e if t he design is a Kaiser
window FIR filt er .
The t able below list s t he possible specificat ions fields t hat can appear in t he
expor t st r uct ur e, and descr ibes t heir cont ent s.
Parameter Description
Beta Kaiser window par amet er.
f Cont ains a vect or of band-edge fr equencies, nor malized
t o 1 (i.e., 1 = Nyquist ).
5 Interactive Tools
5-82
Viewing Frequency Response Plots
It is oft en useful t o view a filt er s fr equency r esponse, impulse r esponse, and
st ep r esponse dur ing t he filt er design pr ocess. You can use t he Filt er Viewer t o
view fr equency-domain infor mat ion about filt er s in t he Filt er Designer :
Fpass Passband cut off fr equencies. Scalar for lowpass and
highpass designs, t wo-element vect or for bandpass and
bandst op designs.
Fstop St opband cut off fr equencies. Scalar for lowpass and
highpass designs, t wo-element vect or for bandpass and
bandst op designs.
m The r esponse magnit udes cor r esponding t o t he band-edge
fr equencies in f.
order Filt er or der.
Rp Passband r ipple (dB)
Rs St opband at t enuat ion (dB)
setOrderFlag Cont ains 1 if t he filt er or der was specified manually (i.e.,
t he Mi ni mum Orde r box in t he Spe ci fi cati ons panel was
not checked). Cont ains 0 if t he filt er or der was comput ed
aut omat ically.
type Cont ains 1 for lowpass, 2 for highpass, 3 for bandpass, or
4 for bandst op.
w3db -3 dB fr equency for But t er wor t h IIR designs.
wind Vect or of Kaiser window coefficient s.
Wn Cut off fr equency for t he Kaiser window FIR filt er when
setOrderFlag = 1.
wt Vect or of weight s, one weight per fr equency band.
Parameter Description
Using the Filter Designer: Interactive Filter Design
5-83
1 Act ivat e SPTool fr om t he Wi ndow menu.
2 Make sur e t he filt er s you want t o analyze ar e select ed in t he Fi lters list .
3 Pr ess Vi e w in t he Filt er panel.
The Filt er Viewer is act ivat ed wit h t he select ed filt er s displayed.
4 To edit one of t he filt er s your e viewing, you can r eact ivat e t he Filt er
Designer fr om t he Wi ndow menu in t he Filt er Viewer .
5 When you want t o r eview a filt er s char act er ist ics aft er youve edit ed it ,
r eact ivat e t he Filt er Viewer fr om t he Wi ndow menu in t he Filt er Designer .
When t he Filt er Viewer is open at t he same t ime t hat t he Filt er Designer is
open, t hey bot h display t he same filt er . You can move back and for t h bet ween
t he Filt er Designer and t he Filt er Viewer unt il t he filt er design is finished.
You can apply t he filt er t o a signal by act ivat ing SPTool, select ing t he filt er in
t he Fi lte rs list , and t he signal t o apply it t o fr om t he Si gnals list , and pr essing
Apply. See Applying a Filt er on page 5-18 for det ails.
See Using t he Filt er Viewer : Int er act ive Filt er Analysis on page 5-84 for mor e
infor mat ion on t he Filt er Viewer .
5 Interactive Tools
5-84
Using the Filter Viewer: Interactive Filter Analysis
An impor t ant aspect of filt er design is filt er analysis, which encompasses bot h
fr equency and t ime-domain analysis of a filt er . The Filt er Viewer is a
GUI-based fr equency analysis t ool t hat pr ovides an int er act ive envir onment
for t he gr aphical display of digit al filt er char act er ist ics.
The Filt er Viewer can display six differ ent char act er ist ics subplot s of a select ed
filt er . Any combinat ion of t he six subplot s may be displayed.
Using t he Filt er Viewer you can:
View magnit ude-r esponse plot s for one or mor e filt er s
View phase-r esponse plot s for one or mor e filt er s
View gr oup-delay plot s for one or mor e filt er s
View zer o-pole plot s for one or mor e filt er s
View impulse-r esponse plot s for one or mor e filt er s
View st ep-r esponse plot s for one or mor e filt er s
Zoom in t o explor e filt er r esponse det ails
Modify select ed plot par amet er s and display char act er ist ics
Measur e a var iet y of char act er ist ics of t he filt er r esponse
For infor mat ion on fr equency analysis using t oolbox funct ions fr om t he
command line or fr om M-files, see Fr equency Response in Chapt er 1 of t his
manual.
Opening the Filter Viewer
Open or act ivat e t he Filt er Viewer fr om SPTool:
1 Select one or mor e filt er s fr om t he Fi lters list in SPTool.
2 Pr ess Vi ew in t he Fi lters panel in SPTool.
The Filt er Viewer is act ivat ed and t he select ed filt er s ar e loaded int o t he
Filt er Viewer and displayed.
Basic Filter Viewer Functions
The Filt er Viewer has t he following component s:
Using the Filter Viewer: Interactive Filter Analysis
5-85
A Plots panel for select ing which subplot s display in t he main plot s window
A Rulers panel and line display cont r ols for making signal measur ement s
and compar isons
A Freque ncy Axi s panel for specifying x-axis scaling in t he main plot s
window
A filt er ident ificat ion panel t hat displays infor mat ion about t he cur r ent ly
select ed filt er (s)
A main plot s (display) ar ea for viewing one or mor e fr equency-domain plot s
for t he select ed filt er (s)
Zoom cont r ols for get t ing a closer look at filt er r esponse char act er ist ics
When you fir st open or act ivat e t he Filt er Viewer , it displays t he default plot
configur at ion for t he select ed filt er (s):
The filt er smagnit ude and phase plot s ar e displayed. The fr equency axis of t he
plot s is set t o li near, and t he fr equency axis r ange is set t o [0,Fs /2].
Plots panel, including menus for
modifying plot characteristics
Frequency Axis panel
Filter ID panel
View (zoom) controls
Rulers panel, including controls for measuring filter responses
Line display controls
5 Interactive Tools
5-86
You can choose t o display one or any combinat ion of t he six available subplot s
by using t he check boxes in t he Plots panel, and you can modify many of t he
plot display char act er ist ics using t he pop-up menus in t he Plots panel and t he
Freque ncy Axi s panel.
Menus
File Menu. Use Clos e fr om t he Fi le menu t o close t he Filt er Viewer . Set t ings you
changed and saved using t he Pre fe rence s dialog box in SPTool ar e saved and
used t he next t ime you open a Filt er Viewer .
Window Menu. Use t he Wi ndow menu t o select a cur r ent ly open MATLAB
figur e window.
Filter Identification Panel
This panel displays t he var iable names and t he highest sampling fr equency of
t he cur r ent ly select ed filt er s. To change names or sampling fr equencies, use
Name or Sampli ng Frequency fr om t he Edi t menu in SPTool.
Plots Panel
The check boxes in t his panel select t he subplot s t o display in t he main plot s
ar ea. Any combinat ion of subplot s may be displayed.
To display a subplot , check t he box at t he left of t he plot descr ipt ion.
Ther e ar e six available subplot s:
Magni tude: displays t he magnit ude of t he fr equency r esponse of t he
cur r ent ly select ed filt er (s).
Phas e: displays t he phase of t he fr equency r esponse.
Group De lay: displays t he negat ive of t he der ivat ive of t he phase r esponse.
Ze ros and Poles : displays t he poles and zer os of t he filt er t r ansfer
funct ion(s) and t heir pr oximit y t o t he unit cir cle.
Impulse Res pons e: displays t he r esponse of t he cur r ent ly select ed filt er (s)
t o a discr et e-t ime unit -height impulse at t=0.
Ste p Re spons e: displays t he r esponse of t he cur r ent ly select ed filt er (s) t o a
discr et e-t ime unit -height st ep funct ion.
Using the Filter Viewer: Interactive Filter Analysis
5-87
You can cust omize t he display char act er ist ics of t he magnit ude and phase
subplot s using t he Magni tude and Phase pop-up menus. The opt ions include:
Magni tude: Scaling for t he magnit ude plot may be li near, log, or de ci be ls .
Phase : Phase unit s may be de gre es or radi ans.
You can also change t he magnit ude and phase display char act er ist ics for t he
Filt er Viewer using t he Filt er set t ings panel of t he Preferences dialog box in
SPTool.
Frequency Axis Settings
You can change fr equency axis scaling and r ange par amet er s for plot s in t he
Filt er Viewer .
Click on t he opt ion in t he Frequency Axi s panel you want t o edit and dr ag t o
select a value. The opt ions include:
Scale : Scaling for t he fr equency axis may be li near or log.
Range: The r ange for t he fr equency axis may be [0,Fs /2], [0,Fs], or
[-Fs /2,Fs /2], wher e Fs r epr esent s t he filt er s sampling fr equency.
The fr equency r ange cannot be negat ive if Scale is set t o log.
You can also change t he fr equency axis display char act er ist ics for t he Filt er
Viewer using t he Fi lter Vi ewe r set t ings panel of t he Pre fe rence s dialog box
in SPTool.
Zoom Controls
The available zoom cont r ols in t he Filt er Viewer ar e Mous e Zoom and Full
Vi e w. You can zoom independent ly in each displayed subplot .
By default , per sist ent zooming is disabled in t he Filt er Viewer . You can t ur n
per sist ent zooming on fr om t he Fi lter Vi e we r set t ings panel of t he
Prefe rence s dialog box in SPTool.
See Zoom Cont r ols on page 5-31 for det ails on using t he zoom cont r ols in t he
Filt er Viewer .
Help Button
To use cont ext -sensit ive help, pr ess t he Help but t on. The mouse point er
becomes an ar r ow wit h a quest ion mar k symbol. You can t hen click on anyt hing
5 Interactive Tools
5-88
in t he Filt er Viewer , including menu it ems, t o find out what it is and how t o
use it .
Main Plots Area
One or mor e of t he six filt er r esponse subplot s may be displayed gr aphically in
t he main plot s ar ea of t he Filt er Viewer . You can specify how t he subplot s ar e
ar r anged by select ing Fi lter Vi ewe r Ti li ng fr om t he Prefere nces dialog box in
SPTool. The opt ions ar e 2-by-3 Gri d, 3-by-2 Gri d, Ve rti cal (6-by-1 Gri d), and
Hori zontal (1-by-6 Gri d).
The following figur e shows t he Filt er Viewer when four subplot s ar e t ur ned on
and t he 2-by-3 gr id opt ion is select ed.
You can exper iment t o find t he t iling opt ion t hat wor ks best for each specific
combinat ion and number of subplot s.
You can zoom in on a subplot by pr essing Mous e Zoom and t hen clicking on or
dr agging over a select ed ar ea of t he subplot . By default , mouse zooming in t he
Filt er Viewer is not per sist ent ; aft er you click once, t he zoom mode is t ur ned
off. You can make zooming per sist ent by checking Stay i n Zoom-mode after
Using the Filter Viewer: Interactive Filter Analysis
5-89
Zoom in t he SPTool Pre fe rence s dialog box. This allows you t o click r epeat edly
in a subplot t o cont inue t o zoom in on a par t icular feat ur e of t he display.
Aft er you zoom in on a subplot , you can click and dr ag t o pan ar ound t he
subplot :
1 Pr ess Mous e Zoom t o t ur n on mouse zoom mode.
2 Click on a feat ur e of a subplot t o zoom in on it .
3 If per sist ent zooming is enabled, pr ess Mous e Zoom again t o t ur n off mouse
zoom mode.
4 Click again in t he same subplot , hold down t he mouse but t on unt il t he hand
cur sor is displayed, and dr ag t he mouse t o pan ar ound t he subplot .
Viewing Filter Plots
This sect ion has a br ief descr ipt ion and pict ur e of each of t he six filt er r esponse
plot s available in t he Filt er Viewer . A sequence of connect ed examples shows
you how t o display each plot on it s own; you can also display any combinat ion
of plot s, as needed.
Each plot in t he example sequence displays t he r esponse of an or der 22
equir ipple lowpass filt er wit h a sampling fr equency of 1 Hz.
Regar dless of how many or what combinat ion of plot s is displayed, you can
zoom in on and pan each subplot independent ly.
Viewing Magnitude Response
A magnit ude r esponse plot is gener ally t he simplest way t o obt ain a high-level
view of a filt er s shape and fit t o specificat ions. In t he following example, use
t he Filt er Designer t o cr eat e a st andar d default filt er and t hen view it s
magnit ude r esponse plot in t he Filt er Viewer :
5 Interactive Tools
5-90
1 Fr om SPTool, pr ess Cre ate.
The Filt er Designer is act ivat ed and a st andar d default filt er is cr eat ed and
displayed.
This is an or der 22 equir ipple lowpass filt er wit h a sampling fr equency of
1 Hz.
2 Use t he Wi ndow menu in t he Filt er Designer t o act ivat e SPTool.
3 Pr ess Vi ew fr om t he Fi lte rs panel in SPTool t o act ivat e t he Filt er Viewer .
The Filt er Viewer is displayed wit h a magnit ude r esponse plot and a phase
r esponse plot .
Using the Filter Viewer: Interactive Filter Analysis
5-91
4 Click t he check box next t o t he Phas e opt ion t o t ur n off t he phase plot .
The magnit ude plot for t he default filt er is displayed.
By default , t his plot uses t he default scaling (li near) for bot h axes and t he
default r ange for t he fr equency axis.
You can change t he following display char act er ist ics of t he magnit ude plot :
Use t he Magni tude pop-up menu t o choose bet ween li near, log, or de ci be ls
scaling of t he y-axis.
Use t he Scale pop-up menu t o choose bet ween li ne ar and log scaling of t he
x-axis.
Use t he Range pop-up menu t o choose bet ween t he following r anges for t he
x-axis: [0,Fs /2], [0,Fs ], or [-Fs/2,Fs/2], wher e Fs r epr esent s t he filt er s
sampling fr equency.
Viewing Phase Response
In addit ion t o displaying magnit ude r esponse, t he Filt er Viewer can calculat e
and plot t he filt er s phase r esponse. Phase response is t he angular component
of a filt er s fr equency r esponse. To display only a phase r esponse plot for t he
cur r ent filt er :
5 Interactive Tools
5-92
1 Click t he check box next t o t he Magni tude opt ion t o t ur n off t he magnit ude
plot .
2 Click t he check box next t o t he Phase opt ion t o t ur n on t he phase plot and
updat e t he display.
By default , t his plot uses t he default phase (degrees) and t he default scaling
and r ange for t he fr equency axis.
You can change t he following display char act er ist ics of t he phase plot :
Use t he Phase pop-up menu t o choose bet ween displaying phase in degrees
or radi ans.
Use t he Scale pop-up menu t o choose bet ween li near and log scaling of t he
x-axis.
Use t he Range pop-up menu t o choose bet ween t he following r anges for t he
x-axis: [0,Fs/2], [0,Fs], or [-Fs /2,Fs /2], wher e Fs r epr esent s t he filt er s
sampling fr equency.
Using the Filter Viewer: Interactive Filter Analysis
5-93
Viewing Group Delay
Group delay is a measur e of t he aver age delay of a filt er as a funct ion of
fr equency. To display only a gr oup delay plot for t he cur r ent ly select ed filt er (s):
1 Click t he check box next t o t he Phas e opt ion t o t ur n off t he phase plot .
2 Click t he check box next t o t he Group Delay opt ion t o t ur n on t he gr oup
delay plot and updat e t he display.
By default , t his plot uses t he default scaling and r ange for t he fr equency
axis.
You can change t he following display char act er ist ics of t he gr oup delay plot :
Use t he Scale pop-up menu t o choose bet ween li ne ar and log scaling of t he
x-axis.
Use t he Range pop-up menu t o choose bet ween t he following r anges for t he
x-axis: [0,Fs /2], [0,Fs ], or [-Fs/2,Fs/2], wher e Fs r epr esent s t he highest
sampling fr equency of t he cur r ent ly select ed filt er s.
5 Interactive Tools
5-94
Viewing a Zero-Pole Plot
The zero-pole plot displays t he poles and zer os of t he t r ansfer funct ion and t heir
pr oximit y t o t he unit cir cle. An r epr esent s a pole of t he t r ansfer funct ion; a
r epr esent s a zer o of t he t r ansfer funct ion. To display only a zer o-pole plot for
t he cur r ent ly select ed filt er (s):
1 Click t he check box next t o t he Group De lay opt ion t o t ur n off t he gr oup
delay plot .
2 Click t he check box next t o t he Zeros and Pole s opt ion t o t ur n on t he
zer o-pole plot and updat e t he display.
Viewing Impulse Response
The impulse response plot displays t he r esponse of t he cur r ent filt er (s) t o a
discr et e-t ime unit -height impulse at t=0.
To display only an impulse r esponse plot for t he cur r ent ly select ed filt er (s):
Using the Filter Viewer: Interactive Filter Analysis
5-95
1 Click t he check box next t o t he Zeros and Poles opt ion t o t ur n off t he
zer o-pole plot .
2 Click t he check box next t o t he Impulse Res pons e opt ion t o t ur n on t he
impulse r esponse plot and updat e t he display.
You can change t he following display char act er ist ics of t he impulse r esponse
plot :
Edit t he Ti me Res ponse Length field in t he Fi lte r Vi ewe r Prefe rence s panel
t o set t he number of samples used t o display t he impulse r esponse.
Viewing Step Response
The step response plot displays t he r esponse of t he cur r ent filt er (s) t o a
discr et e-t ime unit -height st ep funct ion. To display only a st ep r esponse plot for
t he cur r ent ly select ed filt er (s):
5 Interactive Tools
5-96
1 Click t he check box next t o t he Impuls e Response opt ion t o t ur n off t he
impulse r esponse plot .
2 Click t he check box next t o t he Step Re sponse opt ion t o t ur n on t he st ep
r esponse plot and updat e t he display.
You can change t he following display char act er ist ics of t he st ep r esponse plot :
Edit t he Ti me Re spons e Le ngth field in t he Fi lter Vi e wer Prefere nces panel
t o set t he number of samples used t o display t he st ep r esponse.
Using the Spectrum Viewer: Interactive PSD Analysis
5-97
Using the Spectrum Viewer: Interactive PSD Analysis
The Spect r um Viewer pr ovides an int er act ive envir onment for t he est imat ion
of power spect r al densit y for one dat a channel. It allows you t o view and modify
spect r a cr eat ed in SPTool.
Using t he Spect r um Viewer you can:
View and compar e spect r al densit y plot s
Use differ ent est imat ion met hods, including Bur g, FFT, MTM, MUSIC,
Welch, and Yule-Walker AR
Modify spect r um par amet er s such as FFT lengt h, window t ype, and sample
fr equency
Pr int spect r um dat a
For infor mat ion on spect r al analysis using t oolbox funct ions fr om t he command
line or fr om M-files, see Chapt er 3 of t his manual.
Opening the Spectrum Viewer
You can open or act ivat e t he Spect r um Viewer fr om SPTool by pr essing one of
t he following but t ons: Cre ate, Vi ew, and Update . See Cr eat ing a Spect r um
on page 5-19, Viewing a Spect r um on page 5-19, and Updat ing a Spect r um
on page 5-19 for complet e det ails.
Her e is a br ief summar y of each met hod of act ivat ing t he Spect r um Viewer :
To cr eat e a spect r um, select a signal in SPTool and pr ess Create . Pr ess
Apply in t he Spect r um Viewer .
A default spect r um of t he select ed signal is gener at ed and displayed. You can
view it in a var iet y of ways, measur e it , and modify it in t he Spect r um
Viewer .
To view a spect r um, select one or mor e spect r a in SPTool and pr ess Vi ew in
t he Spectra panel.
To updat e a spect r um, select exact ly one signal and one spect r um in SPTool
and pr ess Update. Pr ess Apply in t he Spect r um Viewer .
The spect r um is updat ed t o r eflect t he dat a in t he cur r ent ly select ed signal.
5 Interactive Tools
5-98
Basic Spectrum Viewer Functions
The Spect r um Viewer window has t he following component s:
A Parame ters panel for viewing and modifying t he par amet er s or met hod of
t he cur r ent spect r um
A signal ident ificat ion panel t hat displays infor mat ion about t he signal
linked t o t he cur r ent spect r um
A main axes (display) ar ea for viewing spect r a gr aphically
Zoom cont r ols for get t ing a closer look at spect r al feat ur es
Ruler s and line-display cont r ols for making spect r al measur ement s and
compar isons
Spect r um management cont r ols: Inhe ri t from..., Re ve rt, and Apply
Menu opt ions for modifying plot display char act er ist ics
Menu opt ions for pr int ing spect r um dat a
Main axes area
Signal ID
Ruler and line display controls
Zoom controls
Parameters panel
Using the Spectrum Viewer: Interactive PSD Analysis
5-99
Menus
File Menu. Use Page Setup... fr om t he Fi le menu t o open t he st andar d
MATLAB Page Se tup dialog box (see Using MATLAB Graphics), in which you
can set t he or ient at ion, size and posit ion, limit s, and color of your pr int out .
Use Pri nt Pre vi e w... fr om t he Fi le menu t o open a MATLAB figur e window
wit h a pr eview of t he infor mat ion fr om t he Spect r um Viewer window t hat will
appear in your pr int out . See Spect r um Viewer Set t ings on page 5-24 and
Pr int ing Spect r um Dat a on page 5-107 for det ails of pr int ing fr om t he
Spect r um Viewer .
Use Pri nt... fr om t he Fi le menu t o open t he st andar d oper at ing syst em pr int
dialog box, fr om which you can pr int your spect r um dat a.
Use Clos e fr om t he Fi le menu t o close t he Spect r um Viewer . All spect r um
select ion and r uler infor mat ion will be lost . Set t ings you changed and saved
using t he Prefe rence s dialog box in SPTool ar e saved and used t he next t ime
you open t he Spect r um Viewer .
Options Menu. Use t hese opt ions t o change scaling and r ange par amet er s for
plot s in t he Spect r um Viewer .
Click on t he opt ion you want t o edit and dr ag t o select a value.
5 Interactive Tools
5-100
The opt ions include:
Magni tude Scale: Scaling for t he magnit ude plot may be dB or li near.
Frequency Range: The r ange for t he fr equency axis may be [0, Fs/2], [0, Fs],
or [-Fs/2, Fs /2], wher e Fs is t he sampling fr equency. If mult iple spect r a ar e
displayed, t he value of Fs is t he maximum of all t he sampling fr equencies.
Fs is not defined for t he case of a spect r um whose signal is <None>, t hat is, a
spect r um whose associat ed signal has been delet ed fr om SPTool. In t his case,
a value t wice t he highest fr equency in t he spect r ums fr equency vect or is
chosen.
The fr equency r ange cannot be negat ive if Frequency Scale is set t o log.
Frequency Scale: Scaling for t he fr equency axis may be li ne ar or log.
Window Menu. Use t he Wi ndow menu t o select a cur r ent ly open MATLAB
figur e window.
Signal ID Panel
This panel displays infor mat ion about t he signal linked t o t he cur r ent ly
select ed spect r um. The infor mat ion includes t he signals name, size, dat a t ype
(real or complex), and sampling fr equency. To change any of t hese signal
pr oper t ies, use SPTool.
To associat e a complet ely new signal wit h a displayed spect r um, select t he
signal in SPTool and pr ess Update in t he Spectra panel.
Spectrum Management Buttons
Inherit from Choose a spect r um fr om t his menu t o let t he act ive spect r um
inher it it s par amet er s (not including t he associat ed signal).
Pr ess Inhe ri t from and dr ag t o select t he spect r um fr om which you want t o
inher it par amet er s.
Revert. Rest or es t he pr oper t ies of t he cur r ent spect r um t o what t hey wer e t he
last t ime Apply was pr essed.
Apply. Comput e and display t he act ive spect r um using t he par amet er s set in
t he Parameters panel.
Using the Spectrum Viewer: Interactive PSD Analysis
5-101
Zoom Controls
The available zoom cont r ols in t he Spect r um Viewer ar e Mous e Zoom, Full
Vi e w, Zoom In-Y, Zoom Out-Y, Zoom In-X, and Zoom Out-X. See Zoom
Cont r ols on page 5-31 for det ails on using t he zoom cont r ols in t he Spect r um
Viewer .
Ruler and Line Display Controls
Using t he r uler s and line-display cont r ols, you can measur e a var iet y of
char act er ist ics of spect r a in t he Spect r um Viewer . See Ruler Cont r ols on page
5-33 for det ails on using r uler s and modifying line displays in t he Spect r um
Viewer .
Help Button
To use cont ext -sensit ive help, pr ess t he Help but t on. The mouse point er
becomes an ar r ow wit h a quest ion mar k symbol. You can t hen click on anyt hing
in t he Spect r um Viewer , including menu it ems, t o find out what it is and how
t o use it .
Main Axes Display Area
The Spectra list in SPTool shows all spect r a in t he cur r ent SPTool session. One
or mor e spect r a may be select ed. The spect r al dat a of all select ed spect r a ar e
displayed gr aphically in t he main axes display ar ea of t he Spect r um Viewer .
NOTE If a spect r um is not displayed, or if it is displayed wit h t he wr ong
signal infor mat ion, pr ess Apply t o r ecomput e t he spect r al dat a.
When t her e is only one spect r um displayed, it s pr oper t ies ar e displayed in t he
Parameters panel and it s measur ement s ar e displayed in t he Rulers panel.
When mor e t han one spect r um is displayed, select t he line you want t o focus on.
When a spect r um is select ed, you can use t he r uler cont r ols on t he select ed line
(see Making Signal Measur ement s on page 5-37) and you can modify it s
par amet er s (see below). The label of t he select ed spect r um (line) is displayed in
t he Selecti on pop-up menu.
5 Interactive Tools
5-102
Select a spect r um (line) in one of t wo ways:
Click on t he Se lecti on pop-up menu and dr ag t o select t he line t o measur e
Move t he mouse point er over any point in t he line you want t o select and click
on it
See Select ing a Line t o Measur e on page 5-34 for det ails.
Click-and-Drag Panning. You can use t he mouse t o pan ar ound t he main axes
display:
Click on a line in t he main axes, hold down t he mouse but t on, and dr ag t he
mouse.
Click-and-dr ag panning is not enabled in mouse zoom mode.
Making Spectrum Measurements
Use t he r uler s t o make a var iet y of measur ement s on t he select ed spect r um.
See Making Signal Measur ement s on page 5-37 for det ails.
Viewing Spectral Density Plots
Spect r al densit y est imat ion is a t echnique t hat finds t he appr oximat e
fr equency cont ent of a signal. The Spect r um Viewer calculat es single-channel
power spect r al densit y (PSD). When you fir st gener at e a spect r um, t he
Spect r um Viewer shows a default power spect r al densit y funct ion of t he input
dat a. By default , t he Spect r um Viewer uses t he Welch met hod of PSD
est imat ion wit h a lengt h-256 Hanning window and an FFT lengt h of 1024.
You can change plot pr oper t ies and comput at ion par amet er s for a displayed
spect r um, and you can set confidence int er vals.
Controlling and Manipulating Plots
Changing Plot Properties
You can cont r ol t he axes unit s and scaling pr oper t ies t hat affect t he Spect r um
Viewer s plot s.
Using the Spectrum Viewer: Interactive PSD Analysis
5-103
Use t he Opti ons menu t o select :
Linear or decibel scaling for t he magnit ude axis
Linear or logar it hmic scaling for t he fr equency axis
The fr equency r ange t o view
See Opt ions Menu on page 5-99 for det ails.
You can also zoom in on any of t he Spect r um Viewer s plot s. See Zoom
Cont r ols on page 5-31 for det ails.
You can set ot her scaling pr oper t ies in t he Parame te rs panel, depending on
t he PSD met hod comput at ion par amet er s you choose.
Choosing Computation Parameters
The Spect r um Viewer let s you cont r ol t he PSD est imat ion par amet er s of t he
select ed spect r um. Differ ent par amet er s ar e available, depending on which
met hod of PSD comput at ion you choose. Set t hese par amet er s fr om t he
Parameters panel, as illust r at ed in t he following st eps:
1 Click on t he Me thod pop-up menu and dr ag t o select one of t he following
met hods:
- Bur g
- Covar iance
- FFT
- Modified Covar iance
- MTM
- MUSIC
- Welch
- Yule AR
Appr opr iat e par amet er select ions ar e displayed for each met hod you choose.
5 Interactive Tools
5-104
2 Modify t he appr opr iat e par amet er s.
- When a par amet er is in a pop-up menu, click on t he par amet er label and
dr ag t o select a value fr om t he menu.
- When a par amet er is in an edit box, t ype t he value or var iable int o t he box.
You can also modify t he par amet er s by using Inhe ri t from t o copy t he
par amet er s of anot her spect r um in SPTool. See Inher it fr om on page
5-100 for det ails.
3 If you change your mind, you can discar d changes you make by pr essing
Reve rt.
4 To apply t he modified par amet er s, pr ess Apply.
The new par amet er s ar e applied t o t he select ed spect r um; t he Spect r um
Viewer r ecalculat es t he spect r al densit y funct ion and displays t he modified
spect r um.
Computation Methods and Parameters
You can choose fr om seven PSD comput at ion met hods. Each met hod has it s
own set of par amet er s.
This sect ion shows t he Paramete rs panel for each of t he PSD comput at ion
met hods. For det ailed definit ions and values for each par amet er , use
cont ext -sensit ive help (see Help But t on on page 5-101).
Burg. For t he Bur g met hod, you can specify t he following
par amet er s:
Orde r
Nfft
Using the Spectrum Viewer: Interactive PSD Analysis
5-105
Covariance. For t he Covar iance met hod, you can specify t he
following par amet er s:
Order
Nfft
FFT. For t he FFT met hod, you can specify t he following
par amet er :
Nfft
Mod. Covar. For t he Modified Covar iance met hod, you can
specify t he following par amet er s:
Order
Nfft
MTM. For t he MTM met hod, you can specify t he following
par amet er s:
NW
Nfft
5 Interactive Tools
5-106
We i ghts
Select one of t he following fr om t he pop-up menu:
- adapt
- uni ty
- ei gen
Conf. Int.
Check t o comput e a confidence int er val and t ype in a value (see Set t ing
Confidence Int er vals on page 5-107).
MUSIC. For t he MUSIC met hod, you can specify t he following
par amet er s:
Si gnal Di m.
Thres hold
Nfft
Nwi nd
Wi ndow
Overlap
Corr. Matri x
Check if select ed signal is a cor r elat ion mat r ix.
Ei ge nve ctor Wei ghts
Check t o select eigenvect or weight s.
Welch. For Welchs met hod, you can specify t he following
par amet er s:
NFFT
Nwi nd
Wi ndow
Overlap
Scali ng
Select one of t he following fr om t he pop-up menu:
- Unbi as ed
- Peaks
Using the Spectrum Viewer: Interactive PSD Analysis
5-107
Conf. Int.
Check t o comput e a confidence int er val and t ype in a value (see Set t ing
Confidence Int er vals on page 5-107).
Yule AR. For t he Yule AR met hod, you can specify t he following
par amet er s:
Order
Nfft
Corr. Matri x
Check if select ed signal is a cor r elat ion mat r ix.
Setting Confidence Intervals
By default , t he Spect r um Viewer does not comput e confidence int er vals for
spect r al densit y. You can enable t he comput at ion of confidence int er vals for t he
Welch and MTM met hods by following t hese st eps:
1 Click t he Conf. Int. check box so t hat it is select ed.
2 Type a value for t he confidence level in t he Conf. Int. edit box.
This value must be a scalar bet ween 0 and 1.
3 Pr ess Apply.
NOTE Confidence int er vals ar e r eliable only for nonover lapping sect ions.
Printing Spectrum Data
You can pr int all of t he spect r um dat a t hat you can display and manipulat e in
t he Spect r um Viewer . Your pr int out will always cont ain:
The plot s of one or mor e spect r a, as displayed in t he main axes ar ea
A legend displayed in t he main axes ar ea t o label each spect r um by name,
line color /st yle, met hod, and FFT lengt h
The r uler measur ement s of t he cur r ent ly select ed spect r um will be displayed
at t he bot t om of t he figur e, unless you suppr ess t hem wit h t he Rule rs check
5 Interactive Tools
5-108
box in t he Spectrum Vi ewer pr efer ences panel of t he Pre fe rence s dialog box
in SPTool (see Spect r um Viewer Set t ings on page 5-24).
You can pr eview your pr int out by choosing Pri nt Previ ew... fr om t he Fi le
menu in t he Spect r um Viewer window. This opens t he Spectrum Vi e wer
Pri nt Previ ew window, shown below wit h default set t ings for t he spect r um
mtlbse.
The Clos e but t on on t he Spectrum Vi e wer Pri nt Previ ew window closes t he
pr int pr eview window and r et ur ns you t o t he Spect r um Viewer .
The Pri nt... but t on on t he Spectrum Vi ewe r Pri nt Previ ew window opens t he
st andar d pr int dialog box, fr om which you can pr int t he cont ent s of your pr int
pr eview window.
If you choose t o pr int fr om t he pr int dialog, bot h t hat dialog and t he Spe ctrum
Vi ewer Pri nt Previ ew window will close, and t he cont ent s of t he pr int pr eview
will pr int .
If you choose not t o pr int , t he pr int dialog and t he Spectrum Vi ewer Pri nt
Previ ew window will close, and you will r et ur n t o t he Spect r um Viewer .
Any changes you make, pr ior t o opening t he pr int pr eview window, t hat affect
t he display of dat a in t he Spect r um Viewer (see Cont r olling and Manipulat ing
Plot s on page 5-102) will affect t he display of dat a in t he Spectrum Vi e wer
Using the Spectrum Viewer: Interactive PSD Analysis
5-109
Pri nt Previ ew window in exact ly t he same way. For example, in t he pr int
pr eview shown below:
Dat a fr om t hr ee differ ent sample spect r a have been select ed for display in
t he same main axes ar ea (see Opening t he Filt er Viewer on page 5-84).
Using t he t ools in t he Edi t Li ne pop-up menu (see Ruler and Line Display
Cont r ols on page 5-101), t he spect r um lines have all been changed t o black
and t heir line st yles have been differ ent iat ed, as is r eflect ed in t he legend.
The plot s of all t hr ee spect r a have been zoomed t o an int er val bet ween t heir
r uler s (see Zoom Cont r ols on page 5-101). Not e t hat t he r uler
measur ement s displayed ar e for t he trainse spect r um, which is t he
cur r ent ly select ed spect r um.
Changes you make in t he Preferences dialog box in SPTool will also affect t he
Spectrum Vi e we r Pri nt Pre vi e w window in t he same way t hat t hey affect t he
Spect r um Viewer it self. For example, in t he pr int pr eview shown below, t he
5 Interactive Tools
5-110
r uler measur ement s have been suppr essed by changes in t he Spect r um Viewer
pr efer ences (see Spect r um Viewer Set t ings on page 5-24).
NOTE The HandleVisibility pr oper t y of t he Pri nt Previ ew figur e window is
set t o 'on'. This allows you t o modify t he pr eview using Handle Gr aphics
commands fr om t he MATLAB command line or t he Plot Edit or t ools (see Using
MATLAB Graphics for mor e infor mat ion). For example, you can dr ag t he
legend t o a differ ent posit ion wit hin t he figur e, as has been done in t he figur e
shown above
Changes t hat you make in t he pr eview window pr int exact ly as t hey appear on
t he scr een; however, t hey ar e not saved when t he Pri nt Previ ew figur e
window is closed.
Saving Spectrum Data
Aft er cr eat ing a spect r um in SPTool, you can expor t spect r um infor mat ion t o
t he wor kspace or t o disk using Export... fr om t he Fi le menu in SPTool. The
spect r um infor mat ion is st or ed in a st r uct ur e t hat you can access t o r et r ieve t he
spect r al power and fr equency dat a. The spect r um st r uct ur e also cont ains a
number of fields t hat ar e used int er nally by SPTool.
Using the Spectrum Viewer: Interactive PSD Analysis
5-111
To see t he fields of t he spect r um st r uct ur e, t r y expor t ing a spect r um t o t he
wor kspace:
1 Cr eat e a new spect r um if none ar e cur r ent ly loaded. Label t he spect r um
spect1.
2 In SPTool, select Export... fr om t he Fi le menu.
3 In t he Export dialog box, select spect1 and pr ess t he Export to Workspace
but t on.
4 Type who at t he MATLAB command line t o look at t he var iables in t he
wor kspace. The var iable called spect1 is t he spect r um st r uct ur e you
expor t ed fr om SPTool.
5 Type spect1 t o list t he fields of t he spect r um st r uct ur e.
The following st r uct ur e fields descr ibe t he spect r um.
Field Description
P The spect r al power vect or.
f The spect r al fr equency vect or.
confid A st r uct ur e cont aining t he confidence int er vals dat a:
The confid.level field cont ains t he chosen
confidence level.
The confid.Pc field cont ains t he spect r al power
dat a for t he confidence int er vals.
The confid.enable field cont ains a 1 if confidence
levels ar e enabled for t he spect r um.
signalLabel The name of t he signal fr om which t he spect r um was
gener at ed.
Fs The associat ed signals sample r at e.
5 Interactive Tools
5-112
The ot her fields ar e used int er nally by SPTool, and ar e subject t o change in
fut ur e r eleases.
Example: Generation of Bandlimited Noise
5-113
Example: Generation of Bandlimited Noise
This sect ion pr ovides a complet e example of using t he GUI-based int er act ive
t ools t o design and implement an FIR digit al filt er , apply it t o a signal, and
display signals and spect r a. The st eps include:
Impor t ing and naming a signal using SPTool
Designing a filt er using t he Filt er Designer
In SPTool, applying t he filt er t o t he signal t o cr eat e anot her signal
Viewing t he t ime domain infor mat ion of t he or iginal and filt er ed signals
using t he Signal Br owser
Compar ing t he spect r a of bot h signals using t he Spect r um Viewer
Create, Import, and Name a Signal
You can impor t an exist ing signal int o SPTool, or you can cr eat e a new signal
and edit and name it in SPTool. In t his st ep, youll cr eat e a new signal at t he
command line and t hen impor t it int o SPTool.
1 At t he command line, cr eat e a r andom signal by t yping:
x = randn(5000,1);
2 Act ivat e SPTool by t yping:
sptool
The SPTool window is displayed.
5 Interactive Tools
5-114
3 Select Import... fr om t he Fi le menu:
The Import to SPTool window is displayed.
Not ice t hat t he var iable x is displayed in t he Workspace Conte nts list . (If
it is not , click t he From Workspace r adio but t on t o display t he cont ent s of
t he wor kspace.)
4 Name t he signal and impor t it int o SPTool:
a Make sur e t hat Si gnal is select ed in t he Import As pop-up menu.
b Click in t he Data field and t ype x.
You can also move t he var iable x int o t he Data field by clicking on x in
t he Workspace Contents list and t hen clicking on t he ar r ow t o t he left of
t he Data field.
c Click in t he Sampli ng Fre quency field and t ype 5000.
d Name t he signal by clicking in t he Name field and t yping noise.
e Pr ess OK.
The SPTool window is r eact ivat ed, and t he signal noise[vector] is select ed
in t he Si gnals list .
Example: Generation of Bandlimited Noise
5-115
Design a Filter
You can impor t an exist ing filt er int o SPTool, or you can design and edit a new
filt er using t he Filt er Designer . In t his st ep, youll cr eat e a default filt er and
cust omize it in t he Filt er Designer .
1 Pr ess New De si gn in SPTool t o act ivat e t he Filt er Designer and gener at e a
default filt er .
The Filt er Designer window is displayed wit h t he default filt er filt1.
2 Change t he filt er sampling fr equency t o 5000 by ent er ing t his value in t he
Sampli ng Frequency t ext box in t he Filt er Designer .
3 Specify t he filt er par amet er s shown at left :
a Make sur e Equi ri pple FIR is select ed in t he Algori thm pop-up menu.
b Select bandpass fr om t he Type pop-up menu.
c Set t he passband edge fr equencies by ent er ing 750 for Fp1 and 1250 for
Fp2.
d Set t he st opband edge fr equencies by ent er ing 500 for Fs1 and 1500 for
Fs2.
e Type .01 int o t he Rp field and 75 int o t he Rs field.
Rp set s t he maximum passband r ipple and Rs set s t he st opband
at t enuat ion for t he filt er .
f Pr ess t he Apply but t on t o comput e t he new filt er .
5 Interactive Tools
5-116
When t he new filt er is comput ed, t he magnit ude r esponse of t he filt er is
displayed wit h a solid line in t he main axes display ar ea.
The r esult ing filt er is an or der 78 bandpass equir ipple filt er .
Apply the Filter to a Signal
In t his st ep, you apply t he filt er t o t he signal in SPTool. The new, filt er ed signal
is aut omat ically cr eat ed in SPTool.
Example: Generation of Bandlimited Noise
5-117
1 Act ivat e SPTool fr om t he Wi ndow menu in t he Filt er Designer .
2 Click t o select t he signal noise[vector] fr om t he Si gnals list and click t o
select t he filt er (named filt1[design]) fr om t he Fi lters list , as shown
below.
3 Pr ess Apply t o apply t he filt er filt1 t o t he signal noise.
The Apply Fi lte r dialog box is displayed.
4 Name t he new signal by clicking in t he Output Si gnal field and t yping
blnoise.
5 Pr ess OK.
The filt er is applied t o t he select ed signal. The new, filt er ed signal
blnoise[vector] is displayed in t he Si gnals list .
View, Play, and Print the Signals
You can view and pr int t he t ime domain infor mat ion of t he signals using t he
Signal Br owser . You can also play t he signals, if your comput er has audio
out put capabilit ies. In t his st ep, youll display bot h signals in t he Signal
Br owser , select and play each signal, and pr int bot h signals.
5 Interactive Tools
5-118
1 Shi ft-click on t he noise and blnoise signals in t he Si gnals list of SPTool t o
select bot h signals.
2 Pr ess Vi ew in t he Si gnals panel.
The Signal Br owser is act ivat ed and bot h signals ar e displayed in t he main
axes display ar ea. Init ially, t he noise signal cover s up t he bandlimit ed
blnoise signal, but you can see t hat bot h signals ar e displayed because t he
names of bot h signals ar e shown above t he main axes display ar ea.
3 Click-and-dr ag in t he Selecti on pop-up menu t o select t he blnoise signal.
The main axes display ar ea is r edisplayed. Now you can see t he blnoise
signal super imposed on t op of t he noise signal. The signals ar e displayed in
differ ent color s in bot h t he main axes display ar ea and t he panner . Not ice
Example: Generation of Bandlimited Noise
5-119
t hat t he color of t he line in t he Se lecti on display changes t o cor r espond t o
t he color of t he signal t hat youve select ed.
The signal t hat s displayed in t he Se le cti on pop-up menu and in t he
Se lecti on display is t he act ive signal. When you select Play, or use t he
r uler s, t he act ive signal is t he one t hat is played or measur ed.
4 To hear t he act ive signal, select Play fr om t he Opti ons menu.
5 To hear t he ot her signal, select it as in st ep 3 above (you can also select t he
signal by clicking on it in t he main axes display ar ea). Select Play fr om t he
Opti ons menu again.
6 Befor e pr int ing t he t wo signals t oget her , use t he line cont r ols t o maximize
t he visual cont r ast bet ween t he signals by set t ing t he line color for noise t o
5 Interactive Tools
5-120
gr ay and t he line color for blnoise t o whit e. (See Ruler Cont r ols on page
5-33 for det ails on using t hese cont r ols.)
Use t he Signal Br owser panel in t he Preferences dialog box in SPTool t o
suppr ess pr int ing of bot h t he panner and t he r uler set t ings. (See Signal
Br owser Set t ings on page 5-23 for det ails on t hese pr efer ences.)
To pr int bot h signals, as seen in t he pict ur e below, select Pri nt... fr om t he
Fi le menu in t he Signal Br owser .
Compare Spectra of Both Signals
You can get an idea of t he fr equency cont ent of t he t wo signals by displaying
t heir power spect r a using t he Spect r um Viewer , as descr ibed below.
1 React ivat e SPTool by select ing it fr om t he Wi ndow menu of t he Signal
Br owser .
2 Click on t he noise[vector] signal in t he Si gnals list of SPTool t o select it .
Example: Generation of Bandlimited Noise
5-121
3 Pr ess Create in t he Spectra panel.
The Spect r um Viewer is act ivat ed, and a spect r um object (spect1)
cor r esponding t o t he noise signal is cr eat ed in t he Spe ctra list . The
spect r um is not comput ed or displayed yet .
4 Pr ess Apply in t he Spect r um Viewer t o comput e and display spect1. The
spect r um of t he noise signal is displayed in t he main axes display ar ea.
Not ice t hat t he spect r ums signal ident ificat ion infor mat ion including it s
name, it s t ype, and it s sampling fr equency is displayed above t he
Parameters panel, and t he spect r ums name is displayed bot h above t he
main axes display ar ea and in t he Se le cti on pop-up menu.
The spect r um est imat e is wit hin 2 or 3 dB of 0, so t he noise has a fair ly flat
spect r um.
5 React ivat e SPTool by select ing it fr om t he Wi ndow menu in t he Spect r um
Viewer .
6 Click on t he blnoise signal in t he Si gnals list of SPTool t o select it .
5 Interactive Tools
5-122
7 Pr ess Cre ate in t he Spectra panel.
The Spect r um Viewer is again act ivat ed, and a spect r um object (spect2)
cor r esponding t o t he blnoise signal is cr eat ed in t he Spectra list . The
spect r um is not comput ed or displayed yet .
8 Pr ess Apply in t he Spect r um Viewer t o display spect2.
The spect r um of t he blnoise signal is displayed in t he main axes display
ar ea.
The new spect r ums signal ident ificat ion infor mat ion including it s name,
it s t ype, and it s sampling fr equency is displayed above t he Parame te rs
panel, and t he spect r ums name is displayed bot h above t he main axes
display ar ea and in t he Selecti on pop-up menu.
This spect r um is flat bet ween 750 and 1250 Hz and has 75 dB less power in
t he st opband r egions of filt1.
9 React ivat e SPTool again, as in st ep 5 above.
Example: Generation of Bandlimited Noise
5-123
10 Shi ft-click on spect1 and spect2 in t he Spe ctra list t o select t hem bot h.
11 Pr ess Vi e w in t he Spe ctra panel t o r eact ivat e t he Spect r um Viewer and
display bot h spect r a t oget her .
12 To select one of t he spect r a for measur ing or edit ing, use t he Selecti on
pop-up menu, or click on t he spect r um in t he main axes display ar ea.
The color of t he line in t he Se lecti on display changes t o cor r espond t o t he
color of t he spect r um t hat youve select ed.
The spect r um t hat s displayed in t he Se lecti on pop-up menu and in t he
Se lecti on display is t he act ive spect r um. When you use t he r uler s or change
par amet er s, t he act ive spect r um is t he one t hat is measur ed or modified.
13 Befor e pr int ing t he t wo spect r a t oget her , use t he select ion and r uler cont r ols
t o differ ent iat e t he t wo plot s by line st yle, r at her t han by color . Dr ag t he
r uler s t o demar k t he st opband edge fr equencies and change t he r uler s fr om
5 Interactive Tools
5-124
Track t o Verti cal. (See Ruler Cont r ols on page 5-33 for det ails on using
t hese cont r ols.)
Select Pri nt Previ ew... fr om t he Fi le menu in t he Spect r um Viewer . Fr om
t he Spectrum Vi e wer Pri nt Previ ew window, dr ag t he legend out of t he
axes display ar ea so t hat it doesnt obscur e par t of t he plot .
To pr int bot h signals, as seen in t he pict ur e below, select t he Pri nt... but t on
on t he Spe ctrum Vi ewer Pri nt Previ ew window.
6
Refer ence
6 Reference
6-2
This chapt er cont ains det ailed descr ipt ions of all Signal Pr ocessing Toolbox
funct ions. It begins wit h a list of funct ions gr ouped by subject ar ea and
cont inues wit h t he r efer ence ent r ies in alphabet ical or der . For mor e
infor mat ion, see t he online MATLAB Function Reference.
Waveform Generation and Plotting
chirp Swept -fr equency cosine gener at or.
diric Dir ichlet or per iodic sinc funct ion.
gauspuls Gaussian-modulat ed sinusoidal pulse gener at or.
pulstran Pulse t r ain gener at or.
rectpuls Sampled aper iodic r ect angle gener at or.
sawtooth Sawt oot h or t r iangle wave gener at or.
sinc Sinc funct ion.
square Squar e wave gener at or.
strips St r ip plot .
tripuls Sampled aper iodic t r iangle gener at or.
Filter Analysis and Implementation
abs Absolut e value (magnit ude).
angle Phase angle.
conv Convolut ion and polynomial mult iplicat ion.
conv2 Two-dimensional convolut ion.
fftfilt FFT-based FIR filt er ing using t he over lap-add met hod.
filter Filt er dat a wit h a r ecur sive (IIR) or nonr ecur sive (FIR)
filt er.
6-3
filter2 Two-dimensional digit al filt er ing.
filtfilt Zer o-phase digit al filt er ing.
filtic Find init ial condit ions for a t r ansposed dir ect for m II filt er
implement at ion.
freqs Fr equency r esponse of analog filt er s.
freqspace Fr equency spacing for fr equency r esponse.
freqz Fr equency r esponse of digit al filt er s.
grpdelay Aver age filt er delay (gr oup delay).
impz Impulse r esponse of digit al filt er s.
latcfilt Lat t ice and lat t ice-ladder filt er implement at ion.
sgolayfilt Savit zky-Golay filt er ing.
sosfilt Second-or der (biquadr at ic) IIR filt er ing.
unwrap Unwr ap phase angles.
zplane Zer o-pole plot .
Linear System Transformations
ac2poly Conver sion of aut ocor r elat ion sequence t o pr edict ion
polynomial.
ac2rc Conver sion of aut ocor r elat ion sequence t o r eflect ion
coefficient s.
convmtx Convolut ion mat r ix.
latc2tf Lat t ice filt er t o t r ansfer funct ion conver sion.
Filter Analysis and Implementation
6 Reference
6-4
poly2ac Conver sion of pr edict ion polynomial t o aut ocor r elat ion
sequence.
poly2rc Conver sion of pr edict ion polynomial t o r eflect ion
coefficient s.
rc2ac Conver sion of r eflect ion coefficient s t o aut ocor r elat ion
sequence.
rc2poly Conver sion of r eflect ion coefficient s t o pr edict ion
polynomial.
residuez z-t r ansfor m par t ial-fr act ion expansion.
sos2ss
Conver sion of second-or der sect ions t o st at e-space.
sos2tf Conver sion of second-or der sect ions t o t r ansfer funct ion.
sos2zp Conver sion of second-or der sect ions t o zer o-pole-gain.
ss2sos Conver sion of st at e-space t o second-or der sect ions.
ss2tf Conver sion of st at e-space t o t r ansfer funct ion.
ss2zp Conver sion of st at e-space t o zer o-pole-gain.
tf2latc Conver sion of t r ansfer funct ion t o lat t ice filt er.
tf2sos Conver sion of t r ansfer funct ion t o second-or der sect ions.
tf2ss Conver sion of t r ansfer funct ion t o st at e-space.
tf2zp Conver sion of t r ansfer funct ion t o zer o-pole-gain.
zp2sos Conver sion of zer o-pole-gain t o second-or der sect ions.
zp2ss Conver sion of zer o-pole-gain t o st at e-space.
zp2tf Conver sion of zer o-pole-gain t o t r ansfer funct ion.
Linear System Transformations
6-5
IIR Filter DesignClassical and Direct
besself Bessel analog filt er design.
butter But t er wor t h analog and digit al filt er design.
cheby1 Chebyshev t ype I filt er design (passband r ipple).
cheby2 Chebyshev t ype II filt er design (st opband r ipple).
ellip Ellipt ic (Cauer ) filt er design.
maxflat Gener alized digit al But t er wor t h filt er design.
yulewalk Recur sive digit al filt er design.
IIR Filter Order Selection
buttord But t er wor t h filt er or der select ion.
cheb1ord Chebyshev t ype I filt er or der select ion.
cheb2ord Chebyshev t ype II filt er or der select ion.
ellipord Ellipt ic filt er or der select ion.
FIR Filter Design
cremez Complex and nonlinear-phase equir ipple FIR filt er design.
fir1 Window-based finit e impulse r esponse filt er design
st andar d r esponse.
fir2 Window-based finit e impulse r esponse filt er design
ar bit r ar y r esponse.
fircls Const r ained least squar e FIR filt er design for mult iband
filt er s.
6 Reference
6-6
fircls1 Const r ained least squar e filt er design for lowpass and
highpass linear phase FIR filt er s.
firls Least squar e linear-phase FIR filt er design.
firrcos Raised cosine FIR filt er design.
intfilt Int er polat ion FIR filt er design.
kaiserord Est imat e par amet er s for an FIR filt er design wit h Kaiser
window.
remez Par ks-McClellan opt imal FIR filt er design.
remezord Par ks-McClellan opt imal FIR filt er or der est imat ion.
sgolay Savit zky-Golay filt er design.
Transforms
czt Chir p z-t r ansfor m.
dct Discr et e cosine t r ansfor m (DCT).
dftmtx Discr et e Four ier t r ansfor m mat r ix.
fft One-dimensional fast Four ier t r ansfor m.
fft2 Two-dimensional fast Four ier t r ansfor m.
fftshift Rear r ange t he out put s of t he FFT funct ions.
hilbert Hilber t t r ansfor m.
idct Inver se discr et e cosine t r ansfor m.
ifft One-dimensional inver se fast Four ier t r ansfor m.
ifft2 Two-dimensional inver se fast Four ier t r ansfor m.
FIR Filter Design
6-7
Statistical Signal Processing
cohere Est imat e magnit ude squar ed coher ence funct ion bet ween
t wo signals.
corrcoef Cor r elat ion coefficient mat r ix.
cov Covar iance mat r ix.
csd Est imat e t he cr oss spect r al densit y (CSD) of t wo signals.
pburg Power spect r um est imat e using t he Bur g met hod.
pcov Power spect r um est imat e using t he covar iance met hod.
pmcov Power spect r um est imat e using t he modified covar iance
met hod.
pmtm Power spect r um est imat e using t he mult it aper met hod
(MTM).
pmusic Power spect r um est imat e using MUSIC eigenvect or
met hod.
pwelch Est imat e t he power spect r al densit y (PSD) of a signal using
Welchs met hod.
pyulear Power spect r um est imat e using Yule-Walker AR met hod.
tfe Tr ansfer funct ion est imat e fr om input and out put .
xcorr Cr oss-cor r elat ion funct ion est imat e.
xcorr2 Two-dimensional cr oss-cor r elat ion.
xcov Cr oss-covar iance funct ion est imat e (equal t o
mean-r emoved cr oss-cor r elat ion).
6 Reference
6-8
Windows
bartlett Bar t let t window.
blackman Blackman window.
boxcar Rect angular window.
chebwin Chebyshev window.
hamming Hamming window.
hanning Hanning window.
kaiser Kaiser window.
triang Tr iangular window.
Parametric Modeling
arburg Comput e an est imat e of AR model par amet er s using t he
Bur g met hod.
arcov Comput e an est imat e of AR model par amet er s using t he
covar iance met hod.
armcov Comput e an est imat e of AR model par amet er s using t he
modified covar iance met hod.
aryule Comput e an est imat e of AR model par amet er s using t he
Yule-Walker met hod.
invfreqs Cont inuous-t ime (analog) filt er ident ificat ion fr om
fr equency dat a.
invfreqz Discr et e-t ime filt er ident ificat ion fr om fr equency dat a.
levinson Levinson-Dur bin r ecur sion.
lpc Linear pr edict ion coefficient s.
prony Pr onys met hod for t ime domain IIR filt er design.
6-9
rlevinson Rever se Levinson-Dur bin r ecur sion.
stmcb Linear model using St eiglit z-McBr ide it er at ion.
Specialized Operations
buffer Buffer a signal vect or int o a mat r ix of dat a fr ames.
cceps Complex cepst r al analysis.
cplxpair Gr oup complex number s int o complex conjugat e pair s.
decimate Decr ease t he sampling r at e for a sequence (decimat ion).
deconv Deconvolut ion and polynomial division.
demod Demodulat ion for communicat ions simulat ion.
dpss Discr et e pr olat e spher oidal sequences (Slepian sequences).
dpssclear Remove discr et e pr olat e spher oidal sequences fr om
dat abase.
dpssdir Discr et e pr olat e spher oidal sequences dat abase dir ect or y.
dpssload Load discr et e pr olat e spher oidal sequences fr om dat abase.
dpsssave Save discr et e pr olat e spher oidal sequences in dat abase.
icceps Inver se complex cepst r um.
interp Incr ease sampling r at e by an int eger fact or (int er polat ion).
medfilt1 One-dimensional median filt er ing.
modulate Modulat ion for communicat ions simulat ion.
polystab St abilize polynomial.
rceps Real cepst r um and minimum phase r econst r uct ion.
Parametric Modeling
6 Reference
6-10
resample Change sampling r at e by any r at ional fact or.
specgram Time-dependent fr equency analysis (spect r ogr am).
upfirdn Upsample, apply an FIR filt er, and downsample.
vco Volt age cont r olled oscillat or.
Analog Prototype Design
besselap Bessel analog lowpass filt er pr ot ot ype.
buttap But t er wor t h analog lowpass filt er pr ot ot ype.
cheb1ap Chebyshev t ype I analog lowpass filt er pr ot ot ype.
cheb2ap Chebyshev t ype II analog lowpass filt er pr ot ot ype.
ellipap Ellipt ic analog lowpass filt er pr ot ot ype.
Frequency Translation
lp2bp Lowpass t o bandpass analog filt er t r ansfor mat ion.
lp2bs Lowpass t o bandst op analog filt er t r ansfor mat ion.
lp2hp Lowpass t o highpass analog filt er t r ansfor mat ion.
lp2lp Lowpass t o lowpass analog filt er t r ansfor mat ion.
Specialized Operations
6-11
Filter Discretization
bilinear Bilinear t r ansfor mat ion met hod of analog-t o-digit al filt er
conver sion.
impinvar Impulse invar iance met hod of analog-t o-digit al filt er
conver sion.
Interactive Tools
sptool Int er act ive digit al signal pr ocessing t ool (SPTool).
abs
6-12
6abs
Purpose Absolut e value (magnit ude).
Syntax y = abs(x)
Description y = abs(x) r et ur ns t he absolut e value of t he element s of x. If x is complex, abs
r et ur ns t he complex modulus (magnit ude):
abs(x) = sqrt(real(x).^2 + imag(x).^2)
If x is a MATLAB st r ing, abs r et ur ns t he numer ic values of t he ASCII
char act er s in t he st r ing. The display for mat of t he st r ing changes; t he int er nal
r epr esent at ion does not .
The abs funct ion is par t of t he st andar d MATLAB language.
Example Calculat e t he magnit ude of t he 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
Plot t he magnit ude:
f = (0:length(y)1)'/length(y)*100; % frequency vector
plot(f,m)
See Also
angle Phase angle.
ac2poly
6-13
6ac2poly
Purpose Conver sion of aut ocor r elat ion sequence t o pr edict ion polynomial.
Syntax a = ac2poly(r)
[a,efinal] = ac2poly(r)
Description a = ac2poly(r) finds t he pr edict ion polynomial, a, cor r esponding t o t he
aut ocor r elat ion sequence r. a is t he same lengt h as r, and a(1) = 1.
[a,efinal] = ac2poly(r) r et ur ns t he final pr edict ion er r or , efinal.
Example Consider t he aut ocor r elat ion sequence
r = [5.0000 1.5450 3.9547 3.9331 1.4681 4.7500];
The equivalent pr edict ion polynomial is
a = ac2poly(r)
a =
1.0000 0.6147 0.9898 0.0004 0.0034 0.0077
See Also
References [1] Kay, S.M. Modern S pectral Estimation. Englewood Cliffs, NJ :
Pr ent ice-Hall, 1988.
ac2rc Conver sion of aut ocor r elat ion sequence t o r eflect ion
coefficient s.
poly2ac Conver sion of pr edict ion polynomial t o
aut ocor r elat ion sequence.
rc2poly Conver sion of pr edict ion polynomial t o r eflect ion
coefficient s.
ac2rc
6-14
6ac2rc
Purpose Conver sion of aut ocor r elat ion sequence t o r eflect ion coefficient s.
Syntax [k,r0] = ac2rc(r)
Description [k,r0] = ac2rc(r) finds t he r eflect ion coefficient s, k, cor r esponding t o t he
aut ocor r elat ion sequence r. r0 cont ains t he zer o-lag aut ocor r elat ion.
See Also
References [1] Kay, S.M. Modern S pectral Estimation. Englewood Cliffs, NJ :
Pr ent ice-Hall, 1988.
ac2poly Conver sion of aut ocor r elat ion sequence t o pr edict ion
polynomial.
poly2rc Conver sion of pr edict ion polynomial t o r eflect ion
coefficient s.
rc2ac Conver sion of r eflect ion coefficient s t o
aut ocor r elat ion sequence.
angle
6-15
6angle
Purpose Phase angle.
Syntax p = angle(h)
Description p = angle(h) r et ur ns t he phase angles, in r adians, of t he element s of complex
vect or or ar r ay h. The phase angles lie bet ween - and .
For complex sequence h = x + iy = me
ip
, t he magnit ude and phase ar e given by
m = abs(h)
p = angle(h)
To conver t t o t he or iginal h fr om it s magnit ude and phase:
i = sqrt(1)
h = m.*exp(i*p)
The angle funct ion is par t of t he st andar d MATLAB language.
Example Calculat e t he phase of t he 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
Plot t he phase:
f = (0:length(y)1)'/length(y)*100; % frequency vector
plot(f,p)
Algorithm angle can be expr essed as:
angle(x) = imag(log(x)) = atan2(imag(x),real(x))
See Also
abs Absolut e value (magnit ude).
arburg
6-16
6ar bur g
Purpose Comput e an est imat e of AR model par amet er s using t he Bur g met hod.
Syntax a = arburg(x,p)
[a,e] = arburg(x,p)
[a,e,k] = arburg(x,p)
Description a = arburg(x,p) uses t he Bur g met hod t o fit a p-t h or der aut or egr essive (AR)
model t o t he input signal, x, by minimizing (least squar es) t he for war d and
backwar d pr edict ion er r or s while const r aining t he AR par amet er s t o sat isfy
t he Levinson-Dur bin r ecur sion. x is assumed t o be t he out put of an AR syst em
dr iven by whit e noise. Vect or a cont ains t he nor malized est imat e of t he AR
syst em par amet er s, A(z), in descending power s of z.
Since t he met hod char act er izes t he input dat a using an all-pole model, t he
cor r ect choice of t he model or der p is impor t ant .
[a,e] = arburg(x,p) r et ur ns t he var iance est imat e, e, of t he whit e noise
input t o t he AR model.
[a,e,k] = arburg(x,p) r et ur ns a vect or , k, of r eflect ion coefficient s.
See Also
H z ( )
e
A z ( )
------------
e
1 a
2
z
1
a
p 1 + ( )
z
p
+ + +
---------------------------------------------------------------------- = =
arcov Comput e an est imat e of AR model par amet er s using
t he covar iance met hod.
armcov Comput e an est imat e of AR model par amet er s using
t he modified covar iance met hod.
aryule Comput e an est imat e of AR model par amet er s using
t he Yule-Walker met hod.
lpc Linear pr edict ion coefficient s.
pburg Power spect r um est imat e using t he Bur g met hod.
prony Pr onys met hod for t ime domain IIR filt er design.
arcov
6-17
6ar cov
Purpose Comput e an est imat e of AR model par amet er s using t he covar iance met hod.
Syntax a = arcov(x,p)
[a,e] = arcov(x,p)
Description a = arcov(x,p) uses t he covar iance met hod t o fit a p-t h or der aut or egr essive
(AR) model t o t he input signal, x, which is assumed t o be t he out put of an AR
syst em dr iven by whit e noise. This met hod minimizes t he for war d pr edict ion
er r or in t he least -squar es sense. Vect or a cont ains t he nor malized est imat e of
t he AR syst em par amet er s, A(z), in descending power s of z.
Because t he met hod char act er izes t he input dat a using an all-pole model, t he
cor r ect choice of t he model or der p is impor t ant .
[a,e] = arcov(x,p) r et ur ns t he var iance est imat e, e, of t he whit e noise input
t o t he AR model.
See Also
H z ( )
e
A z ( )
------------
e
1 a
2
z
1
a
p 1 + ( )
z
p
+ + +
---------------------------------------------------------------------- = =
arburg Comput e an est imat e of AR model par amet er s using
t he Bur g met hod.
armcov Comput e an est imat e of AR model par amet er s using
t he modified covar iance met hod.
aryule Comput e an est imat e of AR model par amet er s using
t he Yule-Walker met hod.
lpc Linear pr edict ion coefficient s.
pcov Power spect r um est imat e using t he covar iance
met hod.
prony Pr onys met hod for t ime domain IIR filt er design.
armcov
6-18
6ar mcov
Purpose Comput e an est imat e of AR model par amet er s using t he modified covar iance
met hod.
Syntax a = armcov(x,p)
[a,e] = armcov(x,p)
Description a = armcov(x,p) uses t he modified covar iance met hod t o fit a p-t h or der
aut or egr essive (AR) model t o t he input signal, x, which is assumed t o be t he
out put of an AR syst em dr iven by whit e noise. This met hod minimizes t he
for war d and backwar d pr edict ion er r or s in t he least -squar es sense. Vect or a
cont ains t he nor malized est imat e of t he AR syst em par amet er s, A(z), in
descending power s of z.
Because t he met hod char act er izes t he input dat a using an all-pole model, t he
cor r ect choice of t he model or der p is impor t ant .
[a,e] = armcov(x,p) r et ur ns t he var iance est imat e, e, of t he whit e noise
input t o t he AR model.
See Also
H z ( )
e
A z ( )
------------
e
1 a
2
z
1
a
p 1 + ( )
z
p
+ + +
---------------------------------------------------------------------- = =
arburg Comput e an est imat e of AR model par amet er s using
t he Bur g met hod.
arcov Comput e an est imat e of AR model par amet er s using
t he covar iance met hod.
aryule Comput e an est imat e of AR model par amet er s using
t he Yule-Walker met hod.
lpc Linear pr edict ion coefficient s.
pmcov Power spect r um est imat e using t he modified
covar iance met hod.
prony Pr onys met hod for t ime domain IIR filt er design.
aryule
6-19
6ar yule
Purpose Comput e an est imat e of AR model par amet er s using t he Yule-Walker met hod.
Syntax a = aryule(x,p)
[a,e] = aryule(x,p)
[a,e,k] = aryule(x,p)
Description a = aryule(x,p) uses t he Yule-Walker met hod, also called t he
aut ocor r elat ion met hod, t o fit a p-t h or der aut or egr essive (AR) model t o t he
windowed input signal, x, by minimizing t he for war d pr edict ion er r or in t he
least -squar es sense. This for mulat ion leads t o t he Yule-Walker equat ions,
which ar e solved by t he Levinson-Dur bin r ecur sion. x is assumed t o be t he
out put of an AR syst em dr iven by whit e noise. Vect or a cont ains t he nor malized
est imat e of t he AR syst em par amet er s, A(z), in descending power s of z.
Because t he met hod char act er izes t he input dat a using an all-pole model, t he
cor r ect choice of t he model or der p is impor t ant .
[a,e] = aryule(x,p) r et ur ns t he var iance est imat e, e, of t he whit e noise
input t o t he AR model.
[a,e,k] = aryule(x,p) r et ur ns a vect or , k, of r eflect ion coefficient s.
See Also
H z ( )
e
A z ( )
------------
e
1 a
2
z
1
a
p 1 + ( )
z
p
+ + +
---------------------------------------------------------------------- = =
arburg Comput e an est imat e of AR model par amet er s using
t he Bur g met hod.
arcov Comput e an est imat e of AR model par amet er s using
t he covar iance met hod.
armcov Comput e an est imat e of AR model par amet er s using
t he modified covar iance met hod.
lpc Linear pr edict ion coefficient s.
prony Pr onys met hod for t ime domain IIR filt er design.
pyulear Power spect r um est imat e using Yule-Walker AR
met hod.
bartlett
6-20
6bar t let t
Purpose Bar t let t window.
Syntax w = bartlett(n)
Description w = bartlett(n) r et ur ns an n-point Bar t let t window in t he column vect or w.
The coefficient s of a Bar t let t window ar e:
For n odd
For n even
The Bar t let t window is ver y similar t o a t r iangular window as r et ur ned by t he
triang funct ion. The Bar t let t window always ends wit h zer os at samples 1 and
n, however , while t he t r iangular window is nonzer o at t hose point s. For n odd,
t he cent er n2 point s of bartle9tt(n) ar e equivalent t o triang(n2).
See Also
References [1] Oppenheim, A.V., and R.W. Schafer . Discrete-Time S ignal Processing.
Englewood Cliffs, NJ : Pr ent ice-Hall, 1989.
w k [ ]
2 k 1 ( )
n 1
--------------------- 1 k
n 1 +
2
------------- ,
2
2 k 1 ( )
n 1
---------------------
n 1 +
2
------------- k n ,

'

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

'

=
blackman Blackman window.
boxcar Rect angular window.
chebwin Chebyshev window.
hamming Hamming window.
hanning Hanning window.
kaiser Kaiser window.
triang Tr iangular window.
besselap
6-21
6besselap
Purpose Bessel analog lowpass filt er pr ot ot ype.
Syntax [z,p,k] = besselap(n)
Description [z,p,k] = besselap(n) r et ur ns t he zer os, poles, and gain of an or der n Bessel
analog lowpass filt er pr ot ot ype. It r et ur ns t he poles in t he lengt h n column
vect or p and t he gain in scalar k. z is an empt y mat r ix, because t her e ar e no
zer os. n must be less t han or equal t o 25. The t r ansfer funct ion is
besselap nor malizes t he poles and gain so t hat at low fr equency and high
fr equency t he Bessel pr ot ot ype is asympt ot ically equivalent t o t he But t er wor t h
pr ot ot ype of t he same or der [1]. The magnit ude of t he filt er is less t han
sqrt(1/2) at t he unit y cut off fr equency
c
= 1.
Analog Bessel filt er s ar e char act er ized by a gr oup delay t hat is maximally flat
at zer o fr equency and almost const ant t hr oughout t he passband. The gr oup
delay at zer o fr equency is
Algorithm besselap finds t he filt er r oot s fr om a look-up t able const r uct ed using t he
Symbolic Mat h Toolbox.
See Also
Also see t he S ymbolic Math Toolbox Users Guide.
References [1] Rabiner , L.R., and B. Gold. Theory and Application of Digital S ignal
Processing. Englewood Cliffs, NJ : Pr ent ice-Hall, 1975. Pgs. 228-230.
H s ( )
k
s p 1 ( ) ( ) s p 2 ( ) ( )Ls p n ( ) ( )
----------------------------------------------------------------------------- =
2n ( )!
2
n
n!
--------------
,
_
1 n
besself Bessel analog filt er design.
buttap But t er wor t h analog lowpass filt er pr ot ot ype.
cheb1ap Chebyshev t ype I analog lowpass filt er pr ot ot ype.
cheb2ap Chebyshev t ype II analog lowpass filt er pr ot ot ype.
ellipap Ellipt ic analog lowpass filt er pr ot ot ype.
besself
6-22
6besself
Purpose Bessel analog filt er design.
Syntax [b,a] = besself(n,Wn)
[b,a] = besself(n,Wn,'ftype')
[z,p,k] = besself(...)
[A,B,C,D] = besself(...)
Description besself designs lowpass, bandpass, highpass, and bandst op analog Bessel
filt er s. Analog Bessel filt er s ar e char act er ized by almost const ant gr oup delay
acr oss t he ent ir e passband, t hus pr eser ving t he wave shape of filt er ed signals
in t he passband. Digit al Bessel filt er s do not r et ain t his qualit y, and besself
t her efor e does not suppor t t he design of digit al Bessel filt er s.
[b,a] = besself(n,Wn) designs an or der n lowpass analog filt er wit h cut off
fr equency Wn. It r et ur ns t he filt er coefficient s in t he lengt h n+1 r ow vect or s b
and a, wit h coefficient s in descending power s of s:
Cutoff frequency is t he fr equency at which t he magnit ude r esponse of t he filt er
begins t o decr ease significant ly. For besself, t he cut off fr equency Wn must be
gr eat er t han 0. The magnit ude r esponse of a Bessel filt er designed by besself
is always less t han sqrt(1/2) at t he cut off fr equency, and it decr eases as t he
or der n incr eases.
If Wn is a t wo-element vect or , Wn = [w1 w2] wit h w1 < w2, besself(n,Wn)
r et ur ns an or der 2*n bandpass analog filt er wit h passband w1 < < w2.
[b,a] = besself(n,Wn,'ftype') designs a highpass or bandst op filt er , wher e
ftype is
high for a highpass analog filt er wit h cut off fr equency Wn
stop for an or der 2*n bandst op analog filt er if Wn is a t wo-element vect or ,
Wn = [w1 w2]
The st opband is w1 < < w2.
Wit h differ ent number s of out put ar gument s, besself dir ect ly obt ains ot her
r ealizat ions of t he analog filt er . To obt ain zer o-pole-gain for m, use t hr ee out put
ar gument s:
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 + ( ) + + +
---------------------------------------------------------------------------------- = =
besself
6-23
[z,p,k] = besself(n,Wn) or
[z,p,k] = besself(n,Wn,'ftype')
besself r et ur ns t he zer os and poles in lengt h n or 2*n column vect or s z and p
and t he gain in t he scalar k.
To obt ain st at e-space for m, use four out put ar gument s:
[A,B,C,D] = besself(n,Wn) or
[A,B,C,D] = besself(n,Wn,'ftype') wher e A, B, C, and D ar e
and u is t he input , x is t he st at e vect or , and y is t he out put .
Example Design a fift h-or der analog lowpass Bessel filt er t hat suppr esses fr equencies
gr eat er t han 10,000 r ad/sec and plot t he fr equency r esponse of t he filt er using
freqs:
[b,a] = besself(5,10000);
freqs(b,a) % plot frequency response
x

Ax Bu + =
y Cx Du + =
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
besself
6-24
Limitations Lowpass Bessel filt er s have a monot onically decr easing magnit ude r esponse,
as do lowpass But t er wor t h filt er s. Compar ed t o t he But t er wor t h, Chebyshev,
and ellipt ic filt er s, t he Bessel filt er has t he slowest r olloff and r equir es t he
highest or der t o meet an at t enuat ion specificat ion.
For high or der filt er s, t he st at e-space for m is t he most numer ically accur at e,
followed by t he zer o-pole-gain for m. The t r ansfer funct ion coefficient for m is
t he least accur at e; numer ical pr oblems can ar ise for filt er or der s as low as 15.
Algorithm besself per for ms a four -st ep algor it hm:
1 It finds lowpass analog pr ot ot ype poles, zer os, and gain using t he besselap
funct ion.
2 It conver t s t he poles, zer os, and gain int o st at e-space for m.
3 It t r ansfor ms t he lowpass filt er int o a bandpass, highpass, or bandst op filt er
wit h desir ed cut off fr equencies, using a st at e-space t r ansfor mat ion.
4 It conver t s t he st at e-space filt er back t o t r ansfer funct ion or zer o-pole-gain
for m, as r equir ed.
See Also
besselap Bessel analog lowpass filt er pr ot ot ype.
butter But t er wor t h analog and digit al filt er design.
cheby1 Chebyshev t ype I filt er design (passband r ipple).
cheby2 Chebyshev t ype II filt er design (st opband r ipple).
ellip Ellipt ic (Cauer ) filt er design.
bilinear
6-25
6bilinear
Purpose Bilinear t r ansfor mat ion met hod of analog-t o-digit al filt er conver sion.
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 is a mat hemat ical mapping of var iables. In digit al
filt er ing, it is a st andar d met hod of mapping t he s or analog plane int o t he z or
digit al plane. It t r ansfor ms analog filt er s, designed using classical filt er design
t echniques, int o t heir discr et e equivalent s.
The bilinear t r ansfor mat ion maps t he s-plane int o t he z-plane by
This t r ansfor mat ion maps t he j axis (fr om = - t o +) r epeat edly ar ound
t he unit cir cle (exp(j), fr om = t o ) by
bilinear can accept an opt ional par amet er Fp t hat specifies pr ewar ping. Fp, in
Her t z, indicat es a mat ch fr equency, t hat is, a fr equency for which t he
fr equency r esponses befor e and aft er mapping mat ch exact ly. In pr ewar ped
mode, t he bilinear t r ansfor mat ion maps t he s-plane int o t he z-plane wit h
H z ( ) H s ( )
s 2 f
s
z 1
z 1 +
------------ =
=
2t an
1

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

f
p
f
s
----
,
_
t an
------------------------
z 1 ( )
z 1 + ( )
----------------- =
=
bilinear
6-26
Wit h t he pr ewar ping opt ion, bilinear maps t he j axis (fr om = - t o +)
r epeat edly ar ound t he unit cir cle (exp(j), fr om = t o ) by
In pr ewar ped mode, bilinear mat ches t he fr equency 2f
p
(in r adians per
second) in t he s-plane t o t he nor malized fr equency 2f
p
/f
s
(in r adians per
second) in t he z-plane.
The bilinear funct ion wor ks wit h t hr ee differ ent linear syst em
r epr esent at ions: zer o-pole-gain, t r ansfer funct ion, and st at e-space for m.
Zero-Pole-Gain
[zd,pd,kd] = bilinear(z,p,k,Fs) and
[zd,pd,kd] = bilinear(z,p,k,Fs,Fp) conver t t he s-domain t r ansfer
funct ion specified by z, p, and k t o a discr et e equivalent . Input s z and p ar e
column vect or s cont aining t he zer os and poles, and k is a scalar gain. Fs is t he
sampling fr equency in Her t z. bilinear r et ur ns t he discr et e equivalent in
column vect or s zd and pd and scalar kd. Fp is t he opt ional mat ch fr equency, in
Her t z, for pr ewar ping.
Transfer Function
[numd,dend] = bilinear(num,den,Fs) and
[numd,dend] = bilinear(num,den,Fs,Fp) conver t an s-domain t r ansfer
funct ion given by num and den t o a discr et e equivalent . Row vect or s num and den
specify t he coefficient s of t he numer at or and denominat or , r espect ively, in
descending power s of s
2t an
1

f
p
f
s
----
,
_
t an
2f
p
-----------------------------
,



_
=
n u m s ( )
d en s ( )
--------------------
n u m 1 ( )s
n n
L n u m n n ( )s n u m n n 1 + ( ) + + +
d en 1 ( )s
n d
L d en n d ( )s d en n d 1 + ( ) + + +
------------------------------------------------------------------------------------------------------------------- =
bilinear
6-27
Fs is t he sampling fr equency in Her t z. bilinear r et ur ns t he discr et e
equivalent in r ow vect or s numd and dend in descending power s of z (ascending
power s of z
-1
). Fp is t he opt ional mat ch fr equency, in Her t z, for pr ewar ping.
State-Space
[Ad,Bd,Cd,Dd] = bilinear(A,B,C,D,Fs) and
[Ad,Bd,Cd,Dd] = bilinear(A,B,C,D,Fs,Fp) conver t t he cont inuous-t ime
st at e-space syst em in mat r ices A, B, C, D,
t o t he discr et e-t ime syst em
Fs is t he sampling fr equency in Her t z. bilinear r et ur ns t he discr et e
equivalent in mat r ices Ad, Bd, Cd, Dd. Fp is t he opt ional mat ch fr equency, in
Her t z, for pr ewar ping.
Algorithm bilinear uses one of t wo algor it hms, depending on t he for mat of t he input
linear syst em you supply. One algor it hm wor ks on t he zer o-pole-gain for mat
and t he ot her on t he st at e-space for mat . For t r ansfer funct ion r epr esent at ions,
bilinear conver t s t o st at e-space for m, per for ms t he t r ansfor mat ion, and
conver t s t he r esult ing st at e-space syst em back t o t r ansfer funct ion for m.
Zero-Pole-Gain Algorithm
For a syst em in zer o-pole-gain for m, bilinear per for ms four st eps:
1 If Fp is pr esent , k = 2*pi*Fp/tan(pi*Fp/Fs); ot her wise k = 2*Fs.
2 It st r ips any zer os at plus or minus infinit y using
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
6-28
3 It t r ansfor ms t he zer os, poles, and gain using
pd = (1+p/k)./(1p/k);
zd = (1+z/k)./(1z/k);
kd = real(k*prod(fsz)./prod(fsp));
4 It adds ext r a zer os at -1 so t he r esult ing syst em has equivalent numer at or
and denominat or or der .
State-Space Algorithm
For a syst em in st at e-space for m, bilinear per for ms t wo st eps:
1 If Fp is pr esent , k = 2*pi*Fp/tan(pi*Fp/Fs); else k = 2*Fs.
2 It comput es Ad, Bd, Cd, and Dd in t er ms of A, B, C, and D using
bilinear implement s t hese r elat ions using convent ional MATLAB
st at ement s. The scalar r is ar bit r ar y; bilinear uses sqrt(2/k) t o ensur e good
quant izat ion noise pr oper t ies in t he r esult ing syst em.
Diagnostics bilinear r equir es t hat t he numer at or or der be no gr eat er t han t he
denominat or or der . If t his is not t he case, bilinear displays:
Numerator cannot be higher order than denominator.
For bilinear t o dist inguish bet ween t he zer o-pole-gain and t r ansfer funct ion
linear syst em for mat s, t he fir st t wo input par amet er s must be vect or s wit h t he
same or ient at ion in t hese cases. If t his is not t he case, bilinear displays:
First two arguments must have the same orientation.
A
d
I
1
k
---
,
_
A +
,
_
I
1
k
---
,
_
A
,
_
1
=
B
d
2k
r
------ - I
1
k
---
,
_
A
,
_
1
B =
C
d
r C I
1
k
---
,
_
A
,
_
1
=
D
d
1
k
---
,
_
C I
1
k
---
,
_
A
,
_
1
B D + =
bilinear
6-29
See Also
References [1] Par ks, T.W., and C.S. Bur r us. Digital Filter Design. New Yor k: J ohn Wiley
& Sons, 1987. Pgs. 209-213.
[2] Oppenheim, A.V., and R.W. Schafer . Discrete-Time S ignal Processing.
Englewood Cliffs, NJ : Pr ent ice-Hall, 1989. Pgs. 415-430.
impinvar Impulse invar iance met hod of analog-t o-digit al filt er
conver sion.
lp2bp Lowpass t o bandpass analog filt er t r ansfor mat ion.
lp2bs Lowpass t o bandst op analog filt er t r ansfor mat ion.
lp2hp Lowpass t o highpass analog filt er t r ansfor mat ion.
lp2lp Lowpass t o lowpass analog filt er t r ansfor mat ion.
blackman
6-30
6blackman
Purpose Blackman window.
Syntax w = blackman(n)
w = blackman(n,sflag)
Description w = blackman(n) r et ur ns t he n-point symmet r ically sampled Blackman
window in t he column vect or w. n should be a nonnegat ive int eger . The
equat ion for a Blackman window is
Blackman windows have slight ly wider cent r al lobes and less sideband leakage
t han equivalent lengt h Hamming and Hanning windows.
w = blackman(n,sflag) r et ur ns an n-point Blackman window using t he
window sampling specified by sflag, which can be eit her 'periodic' or
'symmetric' (t he default ). When 'periodic' is specified, blackman comput es
a lengt h n+1 window and r et ur ns t he fir st n point s.
Algorithm w = (0.42 0.5*cos(2*pi*(0:N1)/(N1)) + ...
0.08*cos(4*pi*(0:N1)/(N1)))';
Diagnostics An er r or message is displayed when incor r ect ar gument s ar e used:
Order cannot be less than zero.
Sampling must be either 'symmetric' or 'periodic'.
A war ning message is displayed for nonint eger n:
Warning: Rounding order to nearest integer.
w k [ ] 0.42 0.5 2
k 1
n 1
------------ -
,
_
cos 0.08 4
k 1
n 1
-------------
,
_
cos + k 1 = n , , , =
blackman
6-31
See Also
References [1] Oppenheim, A.V., and R.W. Schafer . Discrete-Time S ignal Processing.
Englewood Cliffs, NJ : Pr ent ice-Hall, 1989.
bartlett Bar t let t window.
boxcar Rect angular window.
chebwin Chebyshev window.
hamming Hamming window.
hanning Hanning window.
kaiser Kaiser window.
triang Tr iangular window.
boxcar
6-32
6boxcar
Purpose Rect angular window.
Syntax w = boxcar(n)
Description w = boxcar(n) r et ur ns a r ect angular window of lengt h n in t he column vect or
w. This funct ion is pr ovided for complet eness; a r ect angular window is
equivalent t o no window at all.
Algorithm w = ones(n,1);
See Also
References [1] Oppenheim, A.V., and R.W. Schafer . Discrete-Time S ignal Processing.
Englewood Cliffs, NJ : Pr ent ice-Hall, 1989.
bartlett Bar t let t window.
blackman Blackman window.
chebwin Chebyshev window.
hamming Hamming window.
hanning Hanning window.
kaiser Kaiser window.
triang Tr iangular window.
buffer
6-33
6buffer
Purpose Buffer a signal vect or int o a mat r ix of dat a fr ames.
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) par t it ions a lengt h-L signal vect or x int o nonover lapping
dat a segment s (fr ames) of lengt h n. Each dat a fr ame occupies one column of
mat r ix out put y, which has n r ows and ceil(L/n) columns. If L is not evenly
divisible by n, t he last column is zer o-padded t o lengt h n.
y = buffer(x,n,p) over laps or under laps successive fr ames in t he out put
mat r ix by p samples:
For 0<p<n (over lap), buffer r epeat s t he final p samples of each fr ame at t he
beginning of t he following fr ame. For example, if x=1:30 and n=7, an over lap
of p=3 looks like t his:
The fir st fr ame st ar t s wit h p zer os (t he default init ial condit ion), and t he
number of columns in y is ceil(L/(np)).
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
6-34
For p<0 (under lap), buffer skips p samples bet ween consecut ive fr ames. For
example, if x=1:30 and n=7, a buffer wit h under lap of p=3 looks like t his:
The number of columns in y is ceil(L/(np)).
y = buffer(x,n,p,opt) specifies a vect or of samples t o pr ecede x(1) in an
over lapping buffer , or t he number of init ial samples t o skip in an under lapping
buffer :
For 0<p<n (over lap), opt specifies a lengt h-p vect or t o inser t befor e x(1) in
t he buffer . This vect or can be consider ed an initial condition, which is needed
when t he cur r ent buffer ing oper at ion is one in a sequence of consecut ive
buffer ing oper at ions. To maint ain t he desir ed fr ame over lap fr om one buffer
t o t he next , opt should cont ain t he final p samples of t he pr evious buffer in
t he sequence. See Cont inuous Buffer ing below.
By default , opt is zeros(p,1) for an over lapping buffer . Set opt t o
'nodelay' t o skip t he init ial condit ion and begin filling t he buffer
immediat ely wit h x(1). In t his case, L must be length(p) or longer . For
example, if x=1:30 and n=7, a buffer wit h over lap of p=3 looks like t his:
For p<0 (under lap), opt is an int eger value in t he r ange [0,p] specifying t he
number of init ial input samples, x(1:opt), t o skip befor e adding samples t o
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
6-35
t he buffer . The fir st value in t he buffer is t her efor e x(opt+1). By default , opt
is zer o for an under lapping buffer .
This opt ion is especially useful when t he cur r ent buffer ing oper at ion is one
in a sequence of consecut ive buffer ing oper at ions. To maint ain t he desir ed
fr ame under lap fr om one buffer t o t he next , opt should equal t he differ ence
bet ween t he t ot al number of point s t o skip bet ween fr ames (p) and t he
number of point s t hat wer e available t o be skipped in t he pr evious input t o
buffer. If t he pr evious input had fewer t han p point s t hat could be skipped
aft er filling t he final fr ame of t hat buffer , t he r emaining opt point s need t o
be r emoved fr om t he fir st fr ame of t he cur r ent buffer . See Cont inuous
Buffer ing below for an example of how t his wor ks in pr act ice.
[y,z] = buffer(...) par t it ions t he lengt h-L signal vect or x int o fr ames of
lengt h n, and out put s only t he full fr ames in y. If y is an over lapping buffer , it
has n r ows and m columns, wher e
m = floor(L/(np)) % when length(opt) = p
or
m = floor((Ln)/(np))+1 % when opt = 'nodelay'
If y is an under lapping buffer , it has n r ows and m columns, wher e
m = floor((Lopt)/(np)) + (rem((Lopt),(np)) >= n)
If t he number of samples in t he input vect or (aft er t he appr opr iat e over lapping
or under lapping oper at ions) exceeds t he number of places available in t he
n-by-m buffer , t he r emaining samples in x ar e out put in vect or z, which for an
over lapping buffer has lengt h
length(z) = L m*(np) % when length(opt) = p
or
length(z) = L ((m1)*(np)+n) % when opt = 'nodelay'
and for an under lapping buffer has lengt h
length(z) = (Lopt) m*(np)
buffer
6-36
Out put z shar es t he same or ient at ion (r ow or column) as x. If t her e ar e no
r emaining samples in t he input aft er t he buffer wit h t he specified over lap or
under lap is filled, z is an empt y vect or .
[y,z,opt] = buffer(...) r et ur ns t he last p samples of a over lapping buffer
in out put opt. In an under lapping buffer , opt is t he differ ence bet ween t he t ot al
number of point s t o skip bet ween fr ames (p) and t he number of point s in x t hat
wer e available t o be skipped aft er filling t he last fr ame:
For 0<p<n (over lap), opt (as an out put ) cont ains t he final p samples in t he
last fr ame of t he buffer . This vect or can be used as t he initial condition for a
subsequent buffer ing oper at ion in a sequence of consecut ive buffer ing
oper at ions. This allows t he desir ed fr ame over lap t o be maint ained fr om one
buffer t o t he next . See Cont inuous Buffer ing below.
For p<0 (under lap), opt (as an out put ) is t he differ ence bet ween t he t ot al
number of point s t o skip bet ween fr ames (p) and t he number of point s in x
t hat wer e available t o be skipped aft er filling t he last fr ame.
opt = m*(np) + opt L % for z = empty vector
wher e opt on t he r ight -hand side is t he input ar gument t o buffer, and opt
on t he left -hand side is t he out put ar gument . Her e m is t he number of
columns in t he buffer , which is
m = floor((Lopt)/(np)) + (rem((Lopt),(np)) >= n)
Not e t hat for an under lapping buffer out put opt is always zer o when out put
z cont ains dat a.
The opt out put for an under lapping buffer is especially useful when t he
cur r ent buffer ing oper at ion is one in a sequence of consecut ive buffer ing
oper at ions. The opt out put fr om each buffer ing oper at ion specifies t he
number of samples t hat need t o be skipped at t he st ar t of t he next buffer ing
oper at ion t o maint ain t he desir ed fr ame under lap fr om one buffer t o t he
next . If fewer t han p point s wer e available t o be skipped aft er filling t he final
fr ame of t he cur r ent buffer , t he r emaining opt point s need t o be r emoved
fr om t he fir st fr ame of t he next buffer .
In a sequence of buffer ing oper at ions, t he opt out put fr om each oper at ion
should be used as t he opt input t o t he subsequent buffer ing oper at ion. This
ensur es t hat t he desir ed fr ame over lap or under lap is maint ained fr om buffer
buffer
6-37
t o buffer , as well as fr om fr ame t o fr ame wit hin t he same buffer . See
Cont inuous Buffer ing below for an example of how t his wor ks in pr act ice.
Continuous Buffering
In a cont inuous buffer ing oper at ion, t he vect or input t o t he buffer funct ion
r epr esent s one fr ame in a sequence of fr ames t hat make up a discr et e signal.
These signal fr ames can or iginat e in a fr ame-based dat a acquisit ion pr ocess, or
wit hin a fr ame-based algor it hm like t he FFT.
As an example, you might acquir e dat a fr om an A/D car d in fr ames of 64
samples. In t he simplest case, you could r ebuffer t he dat a int o fr ames of 16
samples; buffer wit h n=16 cr eat es a buffer of four fr ames fr om each
64-element input fr ame. The r esult is t hat t he signal of fr ame size 64 has been
conver t ed t o a signal of fr ame size 16; no samples wer e added or r emoved.
In t he gener al case wher e t he or iginal signal fr ame size, L, is not equally
divisible by t he new fr ame size, n, t he over flow fr om t he last fr ame needs t o be
capt ur ed and r ecycled int o t he following buffer . You can do t his by it er at ively
calling buffer on input x wit h t he t wo-out put -ar gument synt ax:
[y,z] = buffer([z;x],n) % for column vector x
[y,z] = buffer([z,x],n) % for row vector x
This simply capt ur es any buffer over flow in z, and pr epends t he dat a t o t he
subsequent input in t he next call t o buffer. Again, t he input signal, x, of fr ame
size L, has been conver t ed t o a signal of fr ame size n wit hout any inser t ion or
delet ion of samples.
Not e t hat cont inuous buffer ing cannot be done wit h t he single-out put synt ax
y = buffer(...), because t he last fr ame of y in t his case is zer o padded, which
adds new samples t o t he signal.
Cont inuous buffer ing in t he pr esence of over lap and under lap is handled wit h
t he opt par amet er , which is used as bot h an input and out put t o buffer. The
following t wo examples demonst r at e how t he opt par amet er should be used.
Examples Example 1: Continuous Overlapping Buffers
Fir st cr eat e a buffer cont aining 100 fr ames, each wit h 11 samples.
data = buffer(1:1100,11); % 11 samples per frame
buffer
6-38
Imagine t hat t he fr ames (columns) in t he mat r ix called data ar e t he sequent ial
out put s of a dat a acquisit ion boar d sampling a physical signal: data(:,1) is
t he fir st D/A out put , cont aining t he fir st 11 signal samples; data(:,2) is t he
second out put , cont aining t he next 11 signal samples, and so on.
You want t o r ebuffer t his signal fr om t he acquir ed fr ame size of 11 t o a fr ame
size of 4 wit h an over lap of 1. To do t his, you will r epeat edly call buffer t o
oper at e on each successive input fr ame, using t he opt par amet er t o maint ain
consist ency in t he over lap fr om one buffer t o t he next .
Set t he buffer par amet er s.
n = 4; % new frame size
p = 1; % overlap
opt = 5; % value of y(1)
z = []; % initialize the carry-over vector
Now r epeat edly call buffer, each t ime passing in a new signal fr ame fr om
data. Not e t hat over flow samples (r et ur ned in z) ar e car r ied over and
pr epended t o t he input in t he subsequent call t o 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); % Do something with the buffer of data
pause
end
buffer
6-39
Her es what happens dur ing t he fir st four it er at ions.
Not e t hat t he size of t he out put mat r ix, y, can var y by a single column fr om one
it er at ion t o t he next . This is t ypical for buffer ing oper at ions wit h over lap or
under lap.
Example 2: Continuous Underlapping Buffers
Again cr eat e a buffer cont aining 100 fr ames, each wit h 11 samples.
data = buffer(1:1100,11); % 11 samples per frame
Again, imagine t hat data(:,1) is t he fir st D/A out put , cont aining t he fir st 11
signal samples; data(:,2) is t he second out put , cont aining t he next 11 signal
samples, and so on.
You want t o r ebuffer t his signal fr om t he acquir ed fr ame size of 11 t o a fr ame
size of 4 wit h an under lap of 2. To do t his, you will r epeat edly call buffer t o
oper at e on each successive input fr ame, using t he opt par amet er t o maint ain
consist ency in t he under lap fr om one buffer t o t he next .
[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
6-40
Set t he buffer par amet er s:
n = 4; % new frame size
p = 2; % underlap
opt = 1; % skip the first input element, x(1)
z = []; % initialize the carry-over vector
Now r epeat edly call buffer, each t ime passing in a new signal fr ame fr om
data. Not e t hat over flow samples (r et ur ned in z) ar e car r ied over and
pr epended t o t he input in t he subsequent call t o 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); % Do something with the buffer of data
pause
end
buffer
6-41
Her es what happens dur ing t he fir st t hr ee it er at ions.
Diagnostics Er r or messages ar e displayed when pn or length(opt)length(p) in an
over lapping 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
[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
reshape Reshape ar r ay.
buttap
6-42
6but t ap
Purpose But t er wor t h analog lowpass filt er pr ot ot ype.
Syntax [z,p,k] = buttap(n)
Description [z,p,k] = buttap(n) r et ur ns t he zer os, poles, and gain of an or der n
But t er wor t h analog lowpass filt er pr ot ot ype. It r et ur ns t he poles in t he lengt h
n column vect or p and t he gain in scalar k. z is an empt y mat r ix, because t her e
ar e no zer os. The t r ansfer funct ion is
But t er wor t h filt er s ar e char act er ized by a magnit ude r esponse t hat is
maximally flat in t he passband and monot onic over all. In t he lowpass case, t he
fir st 2n1 der ivat ives of t he squar ed magnit ude r esponse ar e zer o at = 0. The
squar ed magnit ude r esponse funct ion is
cor r esponding t o a t r ansfer funct ion wit h poles equally spaced ar ound a cir cle
in t he left half plane. The magnit ude r esponse at t he cut off fr equency
0
is
always 1/sqrt(2), r egar dless of t he filt er or der . buttap set s
0
t o 1 for a
nor malized r esult .
Algorithm z = [];
p = exp(sqrt(1)*(pi*(1:2:2*n1)/(2*n)+pi/2)).';
k = real(prod(p));
See Also
References [1] Par ks, T.W., and C.S. Bur r us. Digital Filter Design. New Yor k: J ohn Wiley
& Sons, 1987. Chapt er 7.
H s ( )
z s ( )
p s ( )
----------
k
s p 1 ( ) ( ) s p 2 ( ) ( )Ls p n ( ) ( )
----------------------------------------------------------------------------- = =
H ( )
2
1
1
0
( )
2n
+
----------------------------------- - =
besselap Bessel analog lowpass filt er pr ot ot ype.
butter But t er wor t h analog and digit al filt er design.
cheb1ap Chebyshev t ype I analog lowpass filt er pr ot ot ype.
cheb2ap Chebyshev t ype II analog lowpass filt er pr ot ot ype.
ellipap Ellipt ic analog lowpass filt er pr ot ot ype.
butter
6-43
6but t er
Purpose But t er wor t h analog and digit al filt er design.
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 designs lowpass, bandpass, highpass, and bandst op digit al and analog
But t er wor t h filt er s. But t er wor t h filt er s ar e char act er ized by a magnit ude
r esponse t hat is maximally flat in t he passband and monot onic over all.
But t er wor t h filt er s sacr ifice r olloff st eepness for monot onicit y in t he pass- and
st opbands. Unless t he smoot hness of t he But t er wor t h filt er is needed, an
ellipt ic or Chebyshev filt er can gener ally pr ovide st eeper r olloff char act er ist ics
wit h a lower filt er or der .
Digital Domain
[b,a] = butter(n,Wn) designs an or der n lowpass digit al But t er wor t h filt er
wit h cut off fr equency Wn. It r et ur ns t he filt er coefficient s in lengt h n + 1 r ow
vect or s b and a, wit h coefficient s in descending power s of z:
Cutoff frequency is t hat fr equency wher e t he magnit ude r esponse of t he filt er
is sqrt(1/2). For butter, t he cut off fr equency Wn must be a number bet ween 0
and 1, wher e 1 cor r esponds t o half t he sampling fr equency (t he Nyquist
fr equency).
If Wn is a t wo-element vect or , Wn = [w1 w2], butter r et ur ns an or der 2*n digit al
bandpass filt er wit h passband w1 < < w2.
[b,a] = butter(n,Wn,'ftype') designs a highpass or bandst op filt er , wher e
ftype is
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
+ + +
--------------------------------------------------------------------------------- = =

butter
6-44
high for a highpass digit al filt er wit h cut off fr equency Wn
stop for an or der 2*n bandst op digit al filt er if Wn is a t wo-element vect or ,
Wn = [w1 w2]
The st opband is w1 < < w2.
Wit h differ ent number s of out put ar gument s, butter dir ect ly obt ains ot her
r ealizat ions of t he filt er . To obt ain zer o-pole-gain for m, use t hr ee out put
ar gument s:
[z,p,k] = butter(n,Wn) or
[z,p,k] = butter(n,Wn,'ftype')
butter r et ur ns t he zer os and poles in lengt h n column vect or s z and p, and t he
gain in t he scalar k.
To obt ain st at e-space for m, use four out put ar gument s:
[A,B,C,D] = butter(n,Wn) or
[A,B,C,D] = butter(n,Wn,'ftype') wher e A, B, C, and D ar e
and u is t he input , x is t he st at e vect or , and y is t he out put .
Analog Domain
[b,a] = butter(n,Wn,'s') designs an or der n lowpass analog But t er wor t h
filt er wit h cut off fr equency Wn. It r et ur ns t he filt er coefficient s in t he lengt h
n + 1 r ow vect or s b and a, in descending power s of s:
butters cut off fr equency Wn must be gr eat er t han 0.
If Wn is a t wo-element vect or wit h w1 < w2, butter(n,Wn,'s') r et ur ns an or der
2*n bandpass analog filt er wit h 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
6-45
[b,a] = butter(n,Wn,'ftype','s') designs a highpass or bandst op filt er ,
wher e ftype is
high for a highpass analog filt er wit h cut off fr equency Wn
stop for an or der 2*n bandst op analog filt er if Wn is a t wo-element vect or ,
Wn = [w1 w2]
The st opband is w1 < < w2.
Wit h differ ent number s of out put ar gument s, butter dir ect ly obt ains ot her
r ealizat ions of t he analog filt er . To obt ain zer o-pole-gain for m, use t hr ee out put
ar gument s:
[z,p,k] = butter(n,Wn,'s') or
[z,p,k] = butter(n,Wn,'ftype','s') r et ur ns t he zer os and poles in lengt h
n or 2*n column vect or s z and p and t he gain in t he scalar k.
To obt ain st at e-space for m, use four out put ar gument s:
[A,B,C,D] = butter(n,Wn,'s') or
[A,B,C,D] = butter(n,Wn,'ftype','s') wher e A, B, C, and D ar e
and u is t he input , x is t he st at e vect or , and y is t he out put .
Examples For dat a sampled at 1000 Hz, design a 9t h-or der highpass But t er wor t h filt er
wit h cut off fr equency of 300 Hz:
[b,a] = butter(9,300/500,'high');
x

Ax Bu + =
y Cx Du + =
butter
6-46
The filt er s fr equency r esponse is
freqz(b,a,128,1000)
Design a 10t h-or der bandpass But t er wor t h filt er wit h a passband fr om 100 t o
200 Hz and plot it s impulse r esponse, 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 100 200 300 400 500
800
600
400
200
0
200
Frequency (Hz)
P
h
a
s
e

(
d
e
g
r
e
e
s
)
0 100 200 300 400 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
6-47
Limitations For high or der filt er s, t he st at e-space for m is t he most numer ically accur at e,
followed by t he zer o-pole-gain for m. The t r ansfer funct ion coefficient for m is
t he least accur at e; numer ical pr oblems can ar ise for filt er or der s as low as 15.
Algorithm butter uses a five-st ep algor it hm:
1 It finds t he lowpass analog pr ot ot ype poles, zer os, and gain using t he buttap
funct ion.
2 It conver t s t he poles, zer os, and gain int o st at e-space for m.
3 It t r ansfor ms t he lowpass filt er int o a bandpass, highpass, or bandst op filt er
wit h desir ed cut off fr equencies, using a st at e-space t r ansfor mat ion.
4 For digit al filt er design, butter uses bilinear t o conver t t he analog filt er
int o a digit al filt er t hr ough a bilinear t r ansfor mat ion wit h fr equency
pr ewar ping. Car eful fr equency adjust ment guar ant ees t hat t he analog
filt er s and t he digit al filt er s will have t he same fr equency r esponse
magnit ude at Wn or w1 and w2.
5 It conver t s t he st at e-space filt er back t o t r ansfer funct ion or zer o-pole-gain
for m, as r equir ed.
See Also
besself Bessel analog filt er design.
buttap But t er wor t h analog lowpass filt er pr ot ot ype.
buttord But t er wor t h filt er or der select ion.
cheby1 Chebyshev t ype I filt er design (passband r ipple).
cheby2 Chebyshev t ype II filt er design (st opband r ipple).
ellip Ellipt ic (Cauer ) filt er design.
maxflat Gener alized digit al But t er wor t h filt er design.
buttord
6-48
6but t or d
Purpose But t er wor t h filt er or der select ion.
Syntax [n,Wn] = buttord(Wp,Ws,Rp,Rs)
[n,Wn] = buttord(Wp,Ws,Rp,Rs,'s')
Description buttord select s t he minimum or der digit al or analog But t er wor t h filt er
r equir ed t o meet a set of filt er design specificat ions:
Digital Domain
[n,Wn] = buttord(Wp,Ws,Rp,Rs) r et ur ns t he or der n of t he lowest or der
digit al But t er wor t h filt er t hat loses no mor e t han Rp dB in t he passband and
has at least Rs dB of at t enuat ion in t he st opband. The passband r uns fr om 0 t o
Wp and t he st opband r uns fr om Ws t o 1, t he Nyquist fr equency. buttord also
r et ur ns Wn, t he But t er wor t h cut off fr equency t hat allows butter t o achieve t he
given specificat ions (t he -3 dB fr equency).
Use buttord for highpass, bandpass, and bandst op filt er s. For highpass filt er s,
Wp is gr eat er t han Ws. For bandpass and bandst op filt er s, Wp and Ws ar e
t wo-element vect or s t hat specify t he cor ner fr equencies at bot h edges of t he
filt er , lower fr equency edge fir st . For t he band filt er s, buttord r et ur ns Wn as a
t wo-element r ow vect or for input t o butter.
If filt er specificat ions call for a bandpass or bandst op filt er wit h unequal r ipple
in each of t he passbands or st opbands, design t he filt er as separ at e lowpass and
highpass sect ions and cascade t he t wo filt er s t oget her .
Wp Passband cor ner fr equency. Wp, t he cut off fr equency, has a value
bet ween 0 and 1, wher e 1 cor r esponds t o half t he sampling
fr equency (t he Nyquist fr equency).
Ws St opband cor ner fr equency. Ws is in t he same unit s as Wp; it has
a value bet ween 0 and 1, wher e 1 cor r esponds t o half t he
sampling fr equency (t he Nyquist fr equency).
Rp Passband r ipple, in decibels. This value is t he maximum
permissible passband loss in decibels. The passband is 0 < w < Wp.
Rs St opband at t enuat ion, in decibels. This value is t he number of
decibels t he st opband is down fr om t he passband. The st opband
is Ws < w < 1.
buttord
6-49
Analog Domain
[n,Wn] = buttord(Wp,Ws,Rp,Rs,'s') finds t he minimum or der n and cut off
fr equencies Wn for an analog filt er . In t his case t he fr equencies in Wp and Ws ar e
in r adians per second and may be gr eat er t han 1.
Use buttord for highpass, bandpass, and bandst op filt er s, as descr ibed under
Digit al Domain.
Examples For dat a sampled at 1000 Hz, design a lowpass filt er wit h less t han 3 dB of
at t enuat ion fr om 0 t o 100 Hz, and at t enuat ion at least 15 dB fr om 150 Hz t o
t he Nyquist fr equency. Plot t he filt er s fr equency r esponse:
Wp = 100/500; Ws = 150/500;
[n,Wn] = buttord(Wp,Ws,3,15)
n =
4
Wn =
0.2042
[b,a] = butter(n,Wn);
freqz(b,a,512,1000); title('n=4 Butterworth Lowpass Filter')
0 50 100 150 200 250 300 350 400 450 500
-400
-300
-200
-100
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 = 4 Butterworth Lowpass Filter
buttord
6-50
Next design a bandpass filt er wit h passband of 100 Hz t o 200 Hz, less t han
3 dB of at t enuat ion at t he passband cor ner s, and at t enuat ion down 30 dB by
50 Hz out on bot h sides of t he passband:
Wp = [100 200]/500; Ws = [50 250]/500;
Rp = 3; Rs = 30;
[n,Wn] = buttord(Wp,Ws,Rp,Rs); [b,a] = butter(n,Wn);
freqz(b,a,128,1000)
Algorithm buttords or der pr edict ion for mula is descr ibed in [1]. It oper at es in t he analog
domain for bot h analog and digit al cases. For t he digit al case, it conver t s t he
fr equency par amet er s t o t he s-domain befor e est imat ing t he or der and nat ur al
fr equency, t hen conver t s back t o t he z-domain.
buttord init ially develops a lowpass filt er pr ot ot ype by t r ansfor ming t he
passband fr equencies of t he desir ed filt er t o 1 r ad/sec (for low- and highpass
filt er s) and t o -1 and 1 r ad/sec (for bandpass and bandst op filt er s). It t hen
comput es t he minimum or der r equir ed for a lowpass filt er t o meet t he st opband
specificat ion.
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
)
0 50 100 150 200 250 300 350 400 450 500
-1000
-500
0
500
Frequency (Hertz)
P
h
a
s
e

(
d
e
g
r
e
e
s
)
buttord
6-51
See Also
References [1] Rabiner , L.R., and B. Gold. Theory and Application of Digital S ignal
Processing. Englewood Cliffs, NJ : Pr ent ice-Hall, 1975. Pg. 227.
butter But t er wor t h analog and digit al filt er design.
cheb1ord Chebyshev t ype I filt er or der select ion.
cheb2ord Chebyshev t ype II filt er or der select ion.
ellipord Ellipt ic filt er or der select ion.
kaiserord Est imat e par amet er s for an FIR filt er design wit h
Kaiser window.
cceps
6-52
6cceps
Purpose Complex cepst r al analysis.
Syntax xhat = cceps(x)
[xhat,nd] = cceps(x)
[xhat,nd,xhat1] = cceps(x)
[...] = cceps(x,n)
Description Cepst r al analysis is a nonlinear signal pr ocessing t echnique t hat is applied
most commonly in speech pr ocessing and homomor phic filt er ing [1].
xhat = cceps(x) r et ur ns t he complex cepst r um of t he (assumed r eal)
sequence x. The input is alt er ed, by t he applicat ion of a linear phase t er m, t o
have no phase discont inuit y at t r adians. That is, it is cir cular ly shift ed (aft er
zer o padding) by some samples, if necessar y, t o have zer o phase at r adians.
[xhat,nd] = cceps(x) r et ur ns t he number of samples nd of (cir cular ) delay
added t o x pr ior t o finding t he complex cepst r um.
[xhat,nd,xhat1] = cceps(x) r et ur ns a second complex cepst r um, comput ed
using an alt er nat e r oot ing algor it hm, in xhat1. The alt er nat e met hod
([1] p.795) is useful for shor t sequences t hat can be r oot ed and do not have zer os
on t he unit cir cle. For t hese signals, xhat1 can pr ovide a ver ificat ion of xhat.
[...] = cceps(x,n) zer o pads x t o lengt h n and r et ur ns t he lengt h n complex
cepst r um of x.
Algorithm cceps, in it s basic for m, is an M-file implement at ion of algor it hm 7.1 in [2]. A
lengt hy For t r an pr ogr am r educes t o t hr ee lines of MATLAB code:
h = fft(x);
logh = log(abs(h)) + sqrt(1)*rcunwrap(angle(h));
y = real(ifft(logh));
rcunwrap is a special ver sion of unwrap t hat subt r act s a st r aight line fr om t he
phase.
cceps
6-53
See Also
References [1] Oppenheim, A.V., and R.W. Schafer . Discrete-Time S ignal Processing.
Englewood Cliffs, NJ : Pr ent ice-Hall, 1989.
[2] IEEE. Programs for Digital S ignal Processing. IEEE Pr ess. New Yor k: J ohn
Wiley & Sons, 1979.
icceps Inver se complex cepst r um.
hilbert Hilber t t r ansfor m.
rceps Real cepst r um and minimum phase r econst r uct ion.
unwrap Unwr ap phase angles.
cheb1ap
6-54
6cheb1ap
Purpose Chebyshev t ype I analog lowpass filt er pr ot ot ype.
Syntax [z,p,k] = cheb1ap(n,Rp)
Description [z,p,k] = cheb1ap(n,Rp) r et ur ns t he zer os, poles, and gain of an or der n
Chebyshev t ype I analog lowpass filt er pr ot ot ype wit h Rp dB of r ipple in t he
passband. It r et ur ns t he poles in t he lengt h n column vect or p and t he gain in
scalar k. z is an empt y mat r ix, because t her e ar e no zer os. The t r ansfer funct ion
is
Chebyshev t ype I filt er s ar e equir ipple in t he passband and monot onic in t he
st opband. The poles ar e evenly spaced about an ellipse in t he left half plane.
The Chebyshev t ype I cut off fr equency is set t o 1.0 for a nor malized r esult .
This is t he fr equency at which t he passband ends and t he filt er has magnit ude
r esponse of 10
-Rp/20
.
See Also
References [1] Par ks, T.W., and C.S. Bur r us. Digital Filter Design. New Yor k: J ohn Wiley
& Sons, 1987. Chapt er 7.
H s ( )
z s ( )
p s ( )
----------
k
s p 1 ( ) ( ) s p 2 ( ) ( )Ls p n ( ) ( )
----------------------------------------------------------------------------- = =

0
besselap Bessel analog lowpass filt er pr ot ot ype.
buttap But t er wor t h analog and digit al filt er design.
cheb2ap Chebyshev t ype I analog lowpass filt er pr ot ot ype.
cheby1 Chebyshev t ype I filt er design (passband r ipple).
ellipap Ellipt ic analog lowpass filt er pr ot ot ype.
cheb1ord
6-55
6cheb1or d
Purpose Chebyshev t ype I filt er or der select ion.
Syntax [n,Wn] = cheb1ord(Wp,Ws,Rp,Rs)
[n,Wn] = cheb1ord(Wp,Ws,Rp,Rs,'s')
Description cheb1ord select s t he minimum or der digit al or analog Chebyshev t ype I filt er
r equir ed t o meet a set of filt er design specificat ions:
Digital Domain
[n,Wn] = cheb1ord(Wp,Ws,Rp,Rs) r et ur ns t he or der n of t he lowest or der
Chebyshev filt er t hat loses no mor e t han Rp dB in t he passband and has at
least Rs dB of at t enuat ion in t he st opband. The passband r uns fr om 0 t o Wp and
t he st opband r uns fr om Ws t o 1, t he Nyquist fr equency. cheb1ord also r et ur ns
Wn, t he Chebyshev t ype I cut off fr equency t hat allows cheby1 t o achieve t he
given specificat ions.
Use cheb1ord for lowpass, highpass, bandpass, and bandst op filt er s. For
highpass filt er s, Wp > Ws. For bandpass and bandst op filt er s, Wp and Ws ar e
t wo-element vect or s t hat specify t he cor ner fr equencies at bot h edges of t he
filt er , lower fr equency edge fir st . For t he band filt er s, cheb1ord r et ur ns Wn as
a t wo-element r ow vect or for input t o cheby1.
If filt er specificat ions call for a bandpass or bandst op filt er wit h unequal r ipple
in each of t he passbands or st opbands, design t he filt er as separ at e lowpass and
highpass sect ions and cascade t he t wo filt er s t oget her .
Wp Passband cor ner fr equency. Wp, t he cut off fr equency, has a value
bet ween 0 and 1, wher e 1 cor r esponds t o half t he sampling
fr equency (t he Nyquist fr equency).
Ws St opband cor ner fr equency. Ws is in t he same unit s as Wp; it has
a value bet ween 0 and 1, wher e 1 cor r esponds t o half t he
sampling fr equency (t he Nyquist fr equency).
Rp Passband r ipple, in decibels. This value is t he maximum
per missible passband loss in decibels. The passband is 0 < w < Wp.
Rs St opband at t enuat ion, in decibels. This value is t he number of
decibels t he st opband is down fr om t he passband. The st opband
is Ws < w < 1.
cheb1ord
6-56
Analog Domain
[n,Wn] = cheb1ord(Wp,Ws,Rp,Rs,'s') finds t he minimum or der n and cut off
fr equencies Wn for an analog filt er . In t his case t he fr equencies in Wp and Ws ar e
in r adians per second and may be gr eat er t han 1.
Use cheb1ord for lowpass, highpass, bandpass, and bandst op filt er s, as
descr ibed under Digit al Domain.
Examples For dat a sampled at 1000 Hz, design a lowpass filt er wit h less t han 3 dB of
at t enuat ion fr om 0 t o 100 Hz and at t enuat ion at least 15 dB fr om 150 Hz t o t he
Nyquist fr equency:
Wp = 100/500; Ws = 150/500;
Rp = 3; Rs = 15;
[n,Wn] = cheb1ord(Wp,Ws,Rp,Rs)
n =
3
Wn =
0.2000
[b,a] = cheby1(n,Rp,Wn);
freqz(b,a,512,1000); title('n=3 Chebyshev Type I Lowpass Filter')
0 50 100 150 200 250 300 350 400 450 500
-300
-200
-100
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
-200
-150
-100
-50
0
50
Frequency (Hertz)
M
a
g
n
i
t
u
d
e

R
e
s
p
o
n
s
e

(
d
B
)
n = 3 Chebyshev Type I Lowpass Filter
cheb1ord
6-57
Next design a bandpass filt er wit h a passband of 100 Hz t o 200 Hz, less t han
3 dB of at t enuat ion t hr oughout t he passband, and 30 dB st opbands 50 Hz out
on bot h sides of t he passband:
Wp = [100 200]/500; Ws = [50 250]/500;
Rp = 3; Rs = 30;
[n,Wn] = cheb1ord(Wp,Ws,Rp,Rs)
n =
4
Wn =
0.2000 0.4000
[b,a] = cheby1(n,Rp,Wn);
freqz(b,a,512,1000);
title('n=4 Chebyshev Type I Bandpass Filter')
Algorithm cheb1ord uses t he Chebyshev lowpass filt er or der pr edict ion for mula descr ibed
in [1]. The funct ion per for ms it s calculat ions in t he analog domain for bot h
analog and digit al cases. For t he digit al case, it conver t s t he fr equency
par amet er s t o t he s-domain befor e t he or der and nat ur al fr equency est imat ion
pr ocess, t hen conver t s t hem back t o t he z-domain.
0 50 100 150 200 250 300 350 400 450 500
-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
Frequency (Hertz)
M
a
g
n
i
t
u
d
e

R
e
s
p
o
n
s
e

(
d
B
)
n = 4 Chebyshev Type I Bandpass Filter
cheb1ord
6-58
cheb1ord init ially develops a lowpass filt er pr ot ot ype by t r ansfor ming t he
passband fr equencies of t he desir ed filt er t o 1 r ad/sec (for low- or highpass
filt er s) or t o -1 and 1 r ad/sec (for bandpass or bandst op filt er s). It t hen
comput es t he minimum or der r equir ed for a lowpass filt er t o meet t he st opband
specificat ion.
See Also
References [1] Rabiner , L.R., and B. Gold. Theory and Application of Digital S ignal
Processing. Englewood Cliffs, NJ : Pr ent ice-Hall, 1975. Pg. 241.
buttord But t er wor t h filt er or der select ion.
cheby1 Chebyshev t ype I filt er design (passband r ipple).
cheb2ord Chebyshev t ype II filt er or der select ion.
ellipord Ellipt ic filt er or der select ion.
kaiserord Est imat e par amet er s for an FIR filt er design wit h
Kaiser window.
cheb2ap
6-59
6cheb2ap
Purpose Chebyshev t ype II analog lowpass filt er pr ot ot ype.
Syntax [z,p,k] = cheb2ap(n,Rs)
Description [z,p,k] = cheb2ap(n,Rs) finds t he zer os, poles, and gain of an or der n
Chebyshev t ype II analog lowpass filt er pr ot ot ype wit h st opband r ipple Rs dB
down fr om t he passband peak value. cheb2ap r et ur ns t he zer os and poles in
lengt h n column vect or s z and p and t he gain in scalar k. If n is odd, z is lengt h
n1. The t r ansfer funct ion is
Chebyshev t ype II filt er s ar e monot onic in t he passband and equir ipple in t he
st opband. The pole locat ions ar e t he inver se of t he pole locat ions of cheb1ap,
whose poles ar e evenly spaced about an ellipse in t he left half plane. The
Chebyshev t ype II cut off fr equency
0
is set t o 1 for a nor malized r esult . This
is t he fr equency at which t he st opband begins and t he filt er has magnit ude
r esponse of 10
-Rs/20
.
Algorithm Chebyshev t ype II filt er s ar e somet imes called inverse Chebyshev filt er s
because of t heir r elat ionship t o Chebyshev t ype I filt er s. The cheb2ap funct ion
is a modificat ion of t he Chebyshev t ype I pr ot ot ype algor it hm:
1 cheb2ap r eplaces t he fr equency var iable wit h 1/, t ur ning t he lowpass
filt er int o a highpass filt er while pr eser ving t he per for mance at = 1.
2 cheb2ap subt r act s t he filt er t r ansfer funct ion fr om unit y.
See Also
References [1] Par ks, T.W., and C.S. Bur r us. Digital Filter Design. New Yor k: J ohn Wiley
& Sons, 1987. Chapt er 7.
H s ( )
z s ( )
p s ( )
---------- k
s z 1 ( ) ( ) s z 2 ( ) ( )Ls z n ( ) ( )
s p 1 ( ) ( ) s p 2 ( ) ( )Ls p n ( ) ( )
----------------------------------------------------------------------------- = =
besselap Bessel analog lowpass filt er pr ot ot ype.
buttap But t er wor t h analog lowpass filt er pr ot ot ype.
cheb1ap Chebyshev t ype I analog lowpass filt er pr ot ot ype.
cheby2 Chebyshev t ype II filt er design (st opband r ipple).
ellipap Ellipt ic analog lowpass filt er pr ot ot ype.
cheb2ord
6-60
6cheb2or d
Purpose Chebyshev t ype II filt er or der select ion.
Syntax [n,Wn] = cheb2ord(Wp,Ws,Rp,Rs)
[n,Wn] = cheb2ord(Wp,Ws,Rp,Rs,'s')
Description cheb2ord select s t he minimum or der digit al or analog Chebyshev t ype II filt er
r equir ed t o meet a set of filt er design specificat ions:
Digital Domain
[n,Wn] = cheb2ord(Wp,Ws,Rp,Rs) r et ur ns t he or der n of t he lowest or der
Chebyshev filt er t hat loses no mor e t han Rp dB in t he passband and has at
least Rs dB of at t enuat ion in t he st opband. The passband r uns fr om 0 t o Wp and
t he st opband r uns fr om Ws t o 1, t he Nyquist fr equency. cheb2ord also r et ur ns
Wn, t he Chebyshev t ype II cut off fr equency t hat allows cheby2 t o achieve t he
given specificat ions.
Use cheb2ord for lowpass, highpass, bandpass, and bandst op filt er s. For
highpass filt er s, Wp is gr eat er t han Ws. For bandpass and bandst op filt er s, Wp
and Ws ar e t wo-element vect or s t hat specify t he cor ner fr equencies at bot h
edges of t he filt er , lower fr equency edge fir st . For t he band filt er s, cheb2ord
r et ur ns Wn as a t wo-element r ow vect or for input t o cheby2.
If filt er specificat ions call for a bandpass or bandst op filt er wit h unequal r ipple
in each of t he passbands or st opbands, design t he filt er as separ at e lowpass and
highpass sect ions and cascade t he t wo filt er s t oget her .
Wp Passband cor ner fr equency. Wp, t he cut off fr equency, has a value
bet ween 0 and 1, wher e 1 cor r esponds t o half t he sampling
fr equency (t he Nyquist fr equency).
Ws St opband cor ner fr equency. Ws is in t he same unit s as Wp; it has
a value bet ween 0 and 1, wher e 1 cor r esponds t o half t he
sampling fr equency (t he Nyquist fr equency).
Rp Passband r ipple, in decibels. This value is t he maximum
permissible passband loss in decibels. The passband is 0 < w < Wp.
Rs St opband at t enuat ion, in decibels. This value is t he number of
decibels t he st opband is down fr om t he passband. The st opband
is Ws < w < 1.
cheb2ord
6-61
Analog Domain
[n,Wn] = cheb2ord(Wp,Ws,Rp,Rs,'s') finds t he minimum or der n and cut off
fr equencies Wn for an analog filt er . In t his case t he fr equencies in Wp and Ws ar e
in r adians per second and may be gr eat er t han 1.
Use cheb2ord for lowpass, highpass, bandpass, and bandst op filt er s, as
descr ibed under Digit al Domain.
Examples For dat a sampled at 1000 Hz, design a lowpass filt er wit h less t han 3 dB of
at t enuat ion fr om 0 t o 100 Hz, and at t enuat ion at least 15 dB fr om 150 Hz t o
t he Nyquist fr equency:
Wp = 100/500; Ws = 150/500;
Rp = 3; Rs = 15;
[n,Wn] = cheb2ord(Wp,Ws,Rp,Rs)
n =
3
Wn =
0.2609
[b,a] = cheby2(n,Rs,Wn);
freqz(b,a,512,1000);
title('n=3 Chebyshev Type II Lowpass Filter')
0 50 100 150 200 250 300 350 400 450 500
-200
-150
-100
-50
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
-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 = 3 Chebyshev Type II Lowpass Filter
cheb2ord
6-62
Next design a bandpass filt er wit h a passband of 100 Hz t o 200 Hz, less t han
3 dB of at t enuat ion t hr oughout t he passband, and 30 dB st opbands 50 Hz out
on bot h sides of t he passband:
Wp = [100 200]/500; Ws = [50 250]/500;
Rp = 3; Rs = 30;
[n,Wn] = cheb2ord(Wp,Ws,Rp,Rs)
n =
4
Wn =
0.1633 0.4665
[b,a] = cheby2(n,Rs,Wn);
freqz(b,a,512,1000)
title('n=4 Chebyshev Type II Bandpass Filter')
Algorithm cheb2ord uses t he Chebyshev lowpass filt er or der pr edict ion for mula descr ibed
in [1]. The funct ion per for ms it s calculat ions in t he analog domain for bot h
analog and digit al cases. For t he digit al case, it conver t s t he fr equency
par amet er s t o t he s-domain befor e t he or der and nat ur al fr equency est imat ion
pr ocess, t hen conver t s t hem back t o t he z-domain.
0 50 100 150 200 250 300 350 400 450 500
-400
-200
0
200
400
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
Frequency (Hertz)
M
a
g
n
i
t
u
d
e

R
e
s
p
o
n
s
e

(
d
B
)
n = 4 Chebyshev Type II Bandpass Filter
cheb2ord
6-63
cheb2ord init ially develops a lowpass filt er pr ot ot ype by t r ansfor ming t he
st opband fr equencies of t he desir ed filt er t o 1 r ad/sec (for low- and highpass
filt er s) and t o -1 and 1 r ad/sec (for bandpass and bandst op filt er s). It t hen
comput es t he minimum or der r equir ed for a lowpass filt er t o meet t he
passband specificat ion.
See Also
References [1] Rabiner , L.R., and B. Gold. Theory and Application of Digital S ignal
Processing. Englewood Cliffs, NJ : Pr ent ice-Hall, 1975. Pg. 241.
buttord But t er wor t h filt er or der select ion.
cheb1ord Chebyshev t ype I filt er or der select ion.
cheby2 Chebyshev t ype II filt er design (st opband r ipple).
ellipord Ellipt ic filt er or der select ion.
kaiserord Est imat e par amet er s for an FIR filt er design wit h
Kaiser window.
chebwin
6-64
6chebwin
Purpose Chebyshev window.
Syntax w = chebwin(n,r)
Description w = chebwin(n,r) r et ur ns t he column vect or w, cont aining t he lengt h n
Chebyshev window whose Four ier t r ansfor m magnit ude sidelobe r ipple is r dB
below t he mainlobe magnit ude.
See Also
References [1] IEEE. Programs for Digital S ignal Processing. IEEE Pr ess. New Yor k: J ohn
Wiley & Sons, 1979. Pr ogr am 5.2.
bartlett Bar t let t window.
blackman Blackman window.
boxcar Rect angular window.
hamming Hamming window.
hanning Hanning window.
kaiser Kaiser window.
triang Tr iangular window.
cheby1
6-65
6cheby1
Purpose Chebyshev t ype I filt er design (passband r ipple).
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 designs lowpass, bandpass, highpass, and bandst op digit al and analog
Chebyshev t ype I filt er s. Chebyshev t ype I filt er s ar e equir ipple in t he
passband and monot onic in t he st opband. Type I filt er s r oll off fast er t han t ype
II filt er s, but at t he expense of gr eat er deviat ion fr om unit y in t he passband.
Digital Domain
[b,a] = cheby1(n,Rp,Wn) designs an or der n lowpass digit al Chebyshev filt er
wit h cut off fr equency Wn and Rp dB of r ipple in t he passband. It r et ur ns t he
filt er coefficient s in t he lengt h n+1 r ow vect or s b and a, wit h coefficient s in
descending power s of z:
Cutoff frequency is t he fr equency at which t he magnit ude r esponse of t he filt er
is equal t o Rp dB. For cheby1, t he cut off fr equency Wn is a number bet ween 0
and 1, wher e 1 cor r esponds t o half t he sampling fr equency (t he Nyquist
fr equency). Smaller values of passband r ipple Rp lead t o wider t r ansit ion
widt hs (shallower r olloff char act er ist ics).
If Wn is a t wo-element vect or , Wn = [w1 w2], cheby1 r et ur ns an or der 2*n
bandpass filt er wit h passband w1 < < w2.
[b,a] = cheby1(n,Rp,Wn,'ftype') designs a highpass or bandst op filt er ,
wher e ftype is
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
6-66
high for a highpass digit al filt er wit h cut off fr equency Wn
stop for an or der 2*n bandst op digit al filt er if Wn is a t wo-element vect or ,
Wn = [w1 w2]
The st opband is w1 < < w2.
Wit h differ ent number s of out put ar gument s, cheby1 dir ect ly obt ains ot her
r ealizat ions of t he filt er . To obt ain zer o-pole-gain for m, use t hr ee out put
ar gument s:
[z,p,k] = cheby1(n,Rp,Wn) or
[z,p,k] = cheby1(n,Rp,Wn,'ftype') r et ur ns t he zer os and poles in lengt h n
column vect or s z and p and t he gain in t he scalar k.
To obt ain st at e-space for m, use four out put ar gument s:
[A,B,C,D] = cheby1(n,Rp,Wn) or
[A,B,C,D] = cheby1(n,Rp,Wn,'ftype') wher e A, B, C, and D ar e
and u is t he input , x is t he st at e vect or , and y is t he out put .
Analog Domain
[b,a] = cheby1(n,Rp,Wn,'s') designs an or der n lowpass analog Chebyshev
t ype I filt er wit h cut off fr equency Wn. It r et ur ns t he filt er coefficient s in lengt h
n + 1 r ow vect or s b and a, in descending power s of s:
Cutoff frequency is t he fr equency at which t he magnit ude r esponse of t he filt er
is Rp dB. For cheby1, t he cut off fr equency Wn must be gr eat er t han 0.
If Wn is a t wo-element vect or , Wn = [w1 w2], wit h w1 < w2, t hen
cheby1(n,Rp,Wn,'s') r et ur ns an or der 2*n bandpass analog filt er wit h
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 + ( ) + + +
---------------------------------------------------------------------------------- = =
cheby1
6-67
[b,a] = cheby1(n,Rp,Wn,'ftype','s') designs a highpass or bandst op
filt er , wher e ftype is
high for a highpass analog filt er wit h cut off fr equency Wn
stop for an or der 2*n bandst op analog filt er if Wn is a t wo-element vect or ,
Wn = [w1 w2]
The st opband is w1 < < w2.
You can supply differ ent number s of out put ar gument s for cheby1 t o dir ect ly
obt ain ot her r ealizat ions of t he analog filt er . To obt ain zer o-pole-gain for m, use
t hr ee out put ar gument s:
[z,p,k] = cheby1(n,Rp,Wn,'s') or
[z,p,k] = cheby1(n,Rp,Wn,'ftype','s') r et ur ns t he zer os and poles in
lengt h n or 2*n column vect or s z and p and t he gain in t he scalar k.
To obt ain st at e-space for m, use four out put ar gument s:
[A,B,C,D] = cheby1(n,Rp,Wn,'s') or
[A,B,C,D] = cheby1(n,Rp,Wn,'ftype','s') wher e A, B, C, and D ar e defined
as
and u is t he input , x is t he st at e vect or , and y is t he out put .
Examples For dat a sampled at 1000 Hz, design a 9t h-or der lowpass Chebyshev t ype I
filt er wit h 0.5 dB of r ipple in t he passband and a cut off fr equency of 300 Hz:
[b,a] = cheby1(9,0.5,300/500);
x

Ax Bu + =
y Cx Du + =
cheby1
6-68
The fr equency r esponse of t he filt er is
freqz(b,a,512,1000)
Design a 10t h-or der bandpass Chebyshev t ype I filt er wit h a passband fr om
100 t o 200 Hz and plot it s impulse r esponse:
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
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
cheby1
6-69
Limitations For high or der filt er s, t he st at e-space for m is t he most numer ically accur at e,
followed by t he zer o-pole-gain for m. The t r ansfer funct ion for m is t he least
accur at e; numer ical pr oblems can ar ise for filt er or der s as low as 15.
Algorithm cheby1 uses a five-st ep algor it hm:
1 It finds t he lowpass analog pr ot ot ype poles, zer os, and gain using t he
cheb1ap funct ion.
2 It conver t s t he poles, zer os, and gain int o st at e-space for m.
3 It t r ansfor ms t he lowpass filt er int o a bandpass, highpass, or bandst op filt er
wit h desir ed cut off fr equencies, using a st at e-space t r ansfor mat ion.
4 For digit al filt er design, cheby1 uses bilinear t o conver t t he analog filt er
int o a digit al filt er t hr ough a bilinear t r ansfor mat ion wit h fr equency
pr ewar ping. Car eful fr equency adjust ment guar ant ees t hat t he analog
filt er s and t he digit al filt er s will have t he same fr equency r esponse
magnit ude at Wn or w1 and w2.
5 It conver t s t he st at e-space filt er back t o t r ansfer funct ion or zer o-pole-gain
for m, as r equir ed.
See Also
besself Bessel analog filt er design.
butter But t er wor t h analog and digit al filt er design.
cheb1ap Chebyshev t ype I analog lowpass filt er pr ot ot ype.
cheb1ord Chebyshev t ype I filt er or der select ion.
cheby2 Chebyshev t ype II filt er design (st opband r ipple).
ellip Ellipt ic (Cauer ) filt er design.
cheby2
6-70
6cheby2
Purpose Chebyshev t ype II filt er design (st opband r ipple).
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 designs lowpass, highpass, bandpass, and bandst op digit al and analog
Chebyshev t ype II filt er s. Chebyshev t ype II filt er s ar e monot onic in t he
passband and equir ipple in t he st opband. Type II filt er s do not r oll off as fast
as t ype I filt er s, but ar e fr ee of passband r ipple.
Digital Domain
[b,a] = cheby2(n,Rs,Wn) designs an or der n lowpass digit al Chebyshev t ype
II filt er wit h cut off fr equency Wn and st opband r ipple Rs dB down fr om t he peak
passband value. It r et ur ns t he filt er coefficient s in t he lengt h n + 1 r ow vect or s
b and a, wit h coefficient s in descending power s of z:
Cutoff frequency is t he beginning of t he st opband, wher e t he magnit ude
r esponse of t he filt er is equal t o Rs dB. For cheby2, t he cut off fr equency Wn is
a number bet ween 0 and 1, wher e 1 cor r esponds t o half t he sampling fr equency
(t he Nyquist fr equency). Lar ger values of st opband at t enuat ion Rs lead t o
wider t r ansit ion widt hs (shallower r olloff char act er ist ics).
If Wn is a t wo-element vect or , Wn = [w1 w2], cheby2 r et ur ns an or der 2*n
bandpass filt er wit h passband w1 < < w2.
[b,a] = cheby2(n,Rs,Wn,'ftype') designs a highpass or bandst op filt er ,
wher e ftype is
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
6-71
high for a highpass digit al filt er wit h cut off fr equency Wn
stop for an or der 2*n bandst op digit al filt er if Wn is a t wo-element vect or ,
Wn = [w1 w2].
The st opband is w1 < < w2.
Wit h differ ent number s of out put ar gument s, cheby2 dir ect ly obt ains ot her
r ealizat ions of t he filt er . To obt ain zer o-pole-gain for m, use t hr ee out put
ar gument s:
[z,p,k] = cheby2(n,Rs,Wn) or
[z,p,k] = cheby2(n,Rs,Wn,'ftype') r et ur ns t he zer os and poles in lengt h n
column vect or s z and p and t he gain in t he scalar k.
To obt ain st at e-space for m, use four out put ar gument s:
[A,B,C,D] = cheby2(n,Rs,Wn) or
[A,B,C,D] = cheby2(n,Rs,Wn,'ftype') wher e A, B, C, and D ar e
and u is t he input , x is t he st at e vect or , and y is t he out put .
Analog Domain
[b,a] = cheby2(n,Rs,Wn,'s') designs an or der n lowpass analog Chebyshev
t ype II filt er wit h cut off fr equency Wn. It r et ur ns t he filt er coefficient s in t he
lengt h n + 1 r ow vect or s b and a, wit h coefficient s in descending power s of s:
Cutoff frequency is t he fr equency at which t he magnit ude r esponse of t he filt er
is equal t o Rs dB. For cheby2, t he cut off fr equency Wn must be gr eat er t han 0.
If Wn is a t wo-element vect or , Wn = [w1 w2], wit h w1 < w2, t hen
cheby2(n,Rs,Wn,'s') r et ur ns an or der 2*n bandpass analog filt er wit h
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 + ( ) + + +
---------------------------------------------------------------------------------- = =
cheby2
6-72
[b,a] = cheby2(n,Rs,Wn,'ftype','s') designs a highpass or bandst op
filt er , wher e ftype is
high for a highpass analog filt er wit h cut off fr equency Wn
stop for an or der 2*n bandst op analog filt er if Wn is a t wo-element vect or ,
Wn = [w1 w2]
The st opband is w1 < < w2.
Wit h differ ent number s of out put ar gument s, cheby2 dir ect ly obt ains ot her
r ealizat ions of t he analog filt er . To obt ain zer o-pole-gain for m, use t hr ee out put
ar gument s:
[z,p,k] = cheby2(n,Rs,Wn,'s') or
[z,p,k] = cheby2(n,Rs,Wn,'ftype','s') r et ur ns t he zer os and poles in
lengt h n or 2*n column vect or s z and p and t he gain in t he scalar k.
To obt ain st at e-space for m, use four out put ar gument s:
[A,B,C,D] = cheby2(n,Rs,Wn,'s') or
[A,B,C,D] = cheby2(n,Rs,Wn,'ftype','s') wher e A, B, C, and D ar e
and u is t he input , x is t he st at e vect or , and y is t he out put .
Examples For dat a sampled at 1000 Hz, design a nint h-or der lowpass Chebyshev t ype II
filt er wit h st opband at t enuat ion 20 dB down fr om t he passband and a cut off
fr equency of 300 Hz:
[b,a] = cheby2(9,20,300/500);
x

Ax Bu + =
y Cx Du + =
cheby2
6-73
The fr equency r esponse of t he filt er is
freqz(b,a,512,1000)
Design a fift h-or der bandpass Chebyshev t ype II filt er wit h passband fr om 100
t o 200 Hz and plot t he impulse r esponse of t he filt er :
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
6-74
Limitations For high or der filt er s, t he st at e-space for m is t he most numer ically accur at e,
followed by t he zer o-pole-gain for m. The t r ansfer funct ion coefficient for m is
t he least accur at e; numer ical pr oblems can ar ise for filt er or der s as low as 15.
Algorithm cheby2 uses a five-st ep algor it hm:
1 It finds t he lowpass analog pr ot ot ype poles, zer os, and gain using t he
cheb2ap funct ion.
2 It conver t s poles, zer os, and gain int o st at e-space for m.
3 It t r ansfor ms t he lowpass filt er int o a bandpass, highpass, or bandst op filt er
wit h desir ed cut off fr equencies, using a st at e-space t r ansfor mat ion.
4 For digit al filt er design, cheby2 uses bilinear t o conver t t he analog filt er
int o a digit al filt er t hr ough a bilinear t r ansfor mat ion wit h fr equency
pr ewar ping. Car eful fr equency adjust ment guar ant ees t hat t he analog
filt er s and t he digit al filt er s will have t he same fr equency r esponse
magnit ude at Wn or w1 and w2.
5 It conver t s t he st at e-space filt er back t o t r ansfer funct ion or zer o-pole-gain
for m, as r equir ed.
See Also
besself Bessel analog filt er design.
butter But t er wor t h analog and digit al filt er design.
cheb2ap Chebyshev t ype II analog lowpass filt er pr ot ot ype.
cheb2ord Chebyshev t ype II filt er or der select ion.
cheby1 Chebyshev t ype I filt er design (passband r ipple).
ellip Ellipt ic (Cauer ) filt er design.
chirp
6-75
6chir p
Purpose Swept -fr equency cosine gener at or .
Syntax y = chirp(t,f0,t1,f1)
y = chirp(t,f0,t1,f1,'method')
y = chirp(t,f0,t1,f1,'method',phi)
Description y = chirp(t,f0,t1,f1) gener at es samples of a linear swept -fr equency cosine
signal at t he t ime inst ances defined in ar r ay t, wher e f0 is t he inst ant aneous
fr equency at t ime 0, and f1 is t he inst ant aneous fr equency at t ime t1. f0 and
f1 ar e bot h in Her t z. If unspecified, f0 is 0, t1 is 1, and f1 is 100.
y = chirp(t,f0,t1,f1,'method') specifies alt er nat ive sweep met hod
opt ions, wher e method can be
linear, which specifies an inst ant aneous fr equency sweep f
i
(t) given by
wher e
ensur es t hat t he desir ed fr equency br eakpoint f
1
at t ime t
1
is maint ained.
quadratic, which specifies an inst ant aneous fr equency sweep f
i
(t) given by
wher e
logarithmic specifies an inst ant aneous fr equency sweep f
i
(t) given by
wher e
For a log-sweep, f1 must be gr eat er t han f0.
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
=
f
i
t ( ) f
0
10
t
+ =
log
10
f
1
f
0
( ) [ ] t
1
=
chirp
6-76
y = chirp(t,f0,t1,f1,'method',phi) allows an init ial phase phi t o be
specified in degr ees. If unspecified, phi is 0. Default values ar e subst it ut ed for
empt y or omit t ed t r ailing input ar gument s.
Examples Comput e t he spect r ogr am of a chir p wit h linear inst ant aneous fr equency
deviat ion:
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
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
6-77
Comput e t he spect r ogr am of a chir p wit h quadr at ic inst ant aneous fr equency
deviat ion:
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
0 0.5 1 1.5 2 2.5 3 3.5
0
50
100
150
200
250
300
350
400
450
500
chirp
6-78
See Also
cos Cosine of vect or /mat r ix element s (see t he online
MATLAB Function Reference).
diric Dir ichlet or per iodic sinc funct ion.
gauspuls Gaussian-modulat ed sinusoidal pulse gener at or.
pulstran Pulse t r ain gener at or.
rectpuls Sampled aper iodic r ect angle gener at or.
sawtooth Sawt oot h or t r iangle wave gener at or.
sin Sine of vect or /mat r ix element s (see t he online
MATLAB Function Reference).
sinc Sinc funct ion.
square Squar e wave gener at or.
tripuls Sampled aper iodic t r iangle gener at or.
cohere
6-79
6coher e
Purpose Est imat e magnit ude squar ed coher ence funct ion bet ween t wo signals.
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,noverlap)
Cxy = cohere(x,y,...,'dflag')
cohere(x,y)
Description Cxy = cohere(x,y) finds t he magnit ude squar ed coher ence bet ween lengt h n
signal vect or s x and y. The coher ence is a funct ion of t he power spect r a of x and
y and t he cr oss spect r um of x and y:
x and y must be t he same lengt h. Cxy = cohere(x,y) uses t he following default
values:
nfft = min(256,length(x))
Fs = 2
window = hanning(nfft)
noverlap = 0
nfft specifies t he FFT lengt h t hat cohere uses. This value det er mines t he
fr equencies at which t he coher ence is est imat ed. Fs is a scalar t hat specifies t he
sampling fr equency. window specifies a windowing funct ion and t he number of
samples cohere uses in it s sect ioning of t he x and y vect or s. noverlap is t he
number of samples by which t he sect ions over lap. Any ar gument s t hat you omit
fr om t he end of t he par amet er list use t he default values shown above.
If x is r eal, cohere est imat es t he coher ence funct ion at posit ive fr equencies
only; in t his case, t he out put Cxy is a column vect or of lengt h nfft/2 + 1 for
nfft even and (nfft + 1)/2 for n odd. If x or y is complex, cohere est imat es
t he coher ence funct ion at bot h posit ive and negat ive fr equencies, and Cxy has
lengt h nfft.
C
xy
f ( )
P
x y
f ( )
2
P
x x
f ( )P
y y
f ( )
------------------------------- =
cohere
6-80
Cxy = cohere(x,y,nfft) uses t he FFT lengt h nfft in est imat ing t he power
spect r um for x. Specify nfft as a power of 2 for fast est execut ion.
[Cxy,f] = cohere(x,y,nfft,Fs) r et ur ns a vect or f of fr equencies at which
t he funct ion evaluat es t he coher ence. Fs is t he sampling fr equency. f is t he
same size as Cxy, so plot(f,Cxy) plot s t he coher ence funct ion ver sus pr oper ly
scaled fr equency. Fs has no effect on t he out put Cxy; it is a fr equency scaling
mult iplier .
Cxy = cohere(x,y,nfft,Fs,window) specifies a windowing funct ion and t he
number of samples per sect ion of t he vect or s x and y. If you supply a scalar for
window, cohere uses a Hanning window of t hat lengt h. The lengt h of t he
window must be less t han or equal t o nfft; cohere zer o pads t he sect ions if t he
window lengt h exceeds nfft.
Cxy = cohere(x,y,nfft,Fs,window,noverlap) over laps t he sect ions of x by
noverlap samples.
You can use t he empt y mat r ix [] t o specify t he default value for any input
ar gument except x or y. For example,
Cxy = cohere(x,y,[],[],kaiser(128,5));
uses 256 as t he value for nfft and 2 as t he value for Fs.
Cxy = cohere(x,y,...,'dflag') specifies a det r end opt ion, wher e dflag is
linear, t o r emove t he best st r aight -line fit fr om t he pr ewindowed sect ions of
x and y
mean, t o r emove t he mean fr om t he pr ewindowed sect ions of x and y
none, for no det r ending (default )
The dflag par amet er must appear last in t he list of input ar gument s. cohere
r ecognizes a dflag st r ing no mat t er how many int er mediat e ar gument s ar e
omit t ed.
cohere wit h no out put ar gument s plot s t he coher ence est imat e ver sus
fr equency in t he cur r ent figur e window.
cohere
6-81
Example Comput e and plot t he coher ence est imat e bet ween t wo color ed noise sequences
x and y:
h = fir1(30,0.2,boxcar(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 appr opr iat e diagnost ic message is displayed when incor r ect ar gument s ar e
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.
Algorithm cohere est imat es t he magnit ude squar ed coher ence funct ion [1] using Welchs
met hod of power spect r um est imat ion (see r efer ences [2] and [3]), as follows:
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
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 Estimate
cohere
6-82
1 It divides t he signals x and y int o over lapping sect ions, det r ends each
sect ion, and mult iplies each sect ion by window.
2 It calculat es t he lengt h nfft fast Four ier t r ansfor m of each sect ion.
3 It aver ages t he squar es of t he spect r a of t he x sect ions t o for m Pxx, aver ages
t he squar es of t he spect r a of t he y sect ions t o for m Pyy, and aver ages t he
pr oduct s of t he spect r a of t he x and y sect ions t o for m Pxy. It calculat es Cxy
by
Cxy = abs(Pxy).^2/(Pxx.*Pyy)
See Also
References [1] Kay, S.M. Modern S pectral Estimation. Englewood Cliffs, NJ :
Pr ent ice-Hall, 1988. Pg. 454.
[2] Rabiner , L.R., and B. Gold. Theory and Application of Digital S ignal
Processing. Englewood Cliffs, NJ : Pr ent ice-Hall, 1975.
[3] Welch, P.D. The Use of Fast Four ier Tr ansfor m for t he Est imat ion of Power
Spect r a: A Met hod Based on Time Aver aging Over Shor t , Modified
Per iodogr ams. IEEE Trans. Audio Electroacoust. Vol. AU-15 (J une 1967).
Pgs. 70-73.
csd Est imat e t he cr oss spect r al densit y (CSD) of t wo
signals.
pwelch Est imat e t he power spect r al densit y (PSD) of a signal
using Welchs met hod.
tfe Tr ansfer funct ion est imat e fr om input and out put .
conv
6-83
6conv
Purpose Convolut ion and polynomial mult iplicat ion.
Syntax c = conv(a,b)
Description conv(a,b) convolves vect or s a and b. The convolut ion sum is
wher e N is t he maximum sequence lengt h. The ser ies is indexed fr om n + 1 and
k + 1 inst ead of t he usual n and k because MATLAB vect or s r un fr om 1 t o n
inst ead of fr om 0 t o n-1.
The conv funct ion is par t of t he st andar d MATLAB language.
Example The convolut ion of a = [1 2 3] and b = [4 5 6] is
c = conv(a,b)
c =
4 13 28 27 18
Algorithm The conv funct ion is an M-file t hat uses t he filter pr imit ive. conv comput es
t he convolut ion oper at ion as FIR filt er ing wit h an appr opr iat e number of zer os
appended t o t he input .
See Also
c n 1 + ( ) a k 1 + ( )b n k ( )
k 0 =
N 1

=
conv2 Two-dimensional convolut ion.
convmtx Convolut ion mat r ix.
convn N-dimensional convolut ion (see t he online MATLAB
Function Reference).
deconv Deconvolut ion and polynomial division.
filter Filt er dat a wit h a r ecur sive (IIR) or nonr ecur sive
(FIR) filt er.
residuez z-t r ansfor m par t ial fr act ion expansion.
xcorr Cr oss-cor r elat ion funct ion est imat e.
conv2
6-84
6conv2
Purpose Two-dimensional convolut ion.
Syntax C = conv2(A,B)
C = conv2(A,B,'shape')
Description C = conv2(A,B) comput es t he t wo-dimensional convolut ion of mat r ices A and
B. If one of t hese mat r ices descr ibes a t wo-dimensional FIR filt er , t he ot her
mat r ix is filt er ed in t wo dimensions.
Each dimension of t he out put mat r ix C is equal in size t o t he sum of t he
cor r esponding dimensions of t he input mat r ices minus 1. For
[ma,na] = size(A) and [mb,nb] = size(B), t hen
size(C) = [ma+mb1,na+nb1]
C = conv2(A,B,'shape') r et ur ns a subsect ion of t he t wo-dimensional
convolut ion wit h size specified by shape, wher e:
full r et ur ns t he full t wo-dimensional convolut ion (default )
same r et ur ns t he cent r al par t of t he convolut ion t hat is t he same size as A
valid r et ur ns only t hose par t s of t he convolut ion t hat ar e comput ed wit hout
t he zer o-padded edges. Using t his opt ion, size(C) = [mamb+1,nanb+1]
when size(A) > size(B)
conv2 execut es most quickly when size(A) > size(B).
The conv2 funct ion is par t of t he st andar d MATLAB language.
Examples In image pr ocessing, t he Sobel edge-finding oper at ion is a t wo-dimensional
convolut ion of an input ar r ay wit h t he special mat r ix
s = [1 2 1; 0 0 0; 1 2 1];
Given any image, t he following line ext r act s t he hor izont al edges:
h = conv2(I,s);
The lines below ext r act fir st t he ver t ical edges, t hen bot h hor izont al and
ver t ical edges combined:
v = conv2(I,s');
v2 = (sqrt(h.^2 + v.^2))
conv2
6-85
See Also
conv Convolut ion and polynomial mult iplicat ion.
convn N-dimensional convolut ion (see t he online MATLAB
Function Reference).
deconv Deconvolut ion and polynomial division.
filter2 Two-dimensional digit al filt er ing.
xcorr Cr oss-cor r elat ion funct ion est imat e.
xcorr2 Two-dimensional cr oss-cor r elat ion.
convmtx
6-86
6convmt x
Purpose Convolut ion mat r ix.
Syntax A = convmtx(c,n)
A = convmtx(r,n)
Description A convolution matrix is a mat r ix, for med fr om a vect or , whose inner pr oduct
wit h anot her vect or is t he convolut ion of t he t wo vect or s.
A = convmtx(c,n) wher e c is a lengt h m column vect or r et ur ns a mat r ix A of
size (m + n1)-by-n. The pr oduct of A and anot her column vect or x of lengt h n
is t he convolut ion of c wit h x.
A = convmtx(r,n) wher e r is a lengt h m r ow vect or r et ur ns a mat r ix A of size
n-by-(m + n1). The pr oduct of A and anot her r ow vect or x of lengt h n is t he
convolut ion of r wit h x.
Example Gener at e a simple convolut ion mat r ix:
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
Not e t hat convmtx handles edge condit ions by zer o padding.
In pr act ice, it is mor e efficient t o comput e convolut ion using
y = conv(c,x)
t han by using a convolut ion mat r ix:
n = length(x);
y = convmtx(c,n)*x
Algorithm convmtx uses t he funct ion toeplitz t o gener at e t he convolut ion mat r ix.
convmtx
6-87
See Also
conv Convolut ion and polynomial mult iplicat ion.
convn N-dimensional convolut ion (see t he online MATLAB
Function Reference).
conv2 Two-dimensional convolut ion.
dftmtx Discr et e Four ier t r ansfor m mat r ix.
corrcoef
6-88
6cor r coef
Purpose Cor r elat ion coefficient mat r ix.
Syntax C = corrcoef(X)
C = corrcoef(X,Y)
Description corrcoef r et ur ns a mat r ix of cor r elat ion coefficient s calculat ed fr om an input
mat r ix whose r ows ar e obser vat ions and whose columns ar e var iables. If
C = cov(X), t hen corrcoef(X) is t he mat r ix whose element (i, j) is
C = corrcoef(X) is t he zer ot h lag of t he covar iance funct ion, t hat is, t he
zer ot h lag of xcov(x,'coeff') packed int o a squar e ar r ay.
C = corrcoef(X,Y) is t he same as corrcoef([X Y]), t hat is, it concat enat es X
and Y in t he r ow dir ect ion befor e it s comput at ion.
corrcoef r emoves t he mean fr om each column befor e calculat ing t he r esult s.
See t he xcorr funct ion for cr oss-cor r elat ion opt ions.
The corrcoef funct ion is par t of t he st andar d MATLAB language.
See Also
cor r coef i j , ( )
C i j , ( )
C i i , ( )C j j , ( )
---------------------------------- - =
cov Covar iance mat r ix.
mean Aver age value (see t he online MATLAB Function
Reference).
median Median value (see t he online MATLAB Function
Reference).
std St andar d deviat ion (see t he online MATLAB
Function Reference).
xcorr Cr oss-cor r elat ion funct ion est imat e.
xcov Cr oss-covar iance funct ion est imat e (equal t o
mean-r emoved cr oss-cor r elat ion).
cov
6-89
6cov
Purpose Covar iance mat r ix.
Syntax c = cov(x)
c = cov(x,y)
Description cov comput es t he covar iance mat r ix. If x is a vect or , c is a scalar cont aining t he
var iance. For an ar r ay wher e each r ow is an obser vat ion and each column a
var iable, cov(X) is t he covar iance mat r ix. diag(cov(X)) is a vect or of
var iances for each column, and sqrt(diag(cov(X))) is a vect or of st andar d
deviat ions.
cov(x) is t he zer ot h lag of t he covar iance funct ion, t hat is, t he zer ot h lag of
xcov(x)/(n1) packed int o a squar e ar r ay.
cov(x,y) wher e x and y ar e column vect or s of equal lengt h is equivalent t o
cov([x y])), t hat is, it concat enat es x and y in t he r ow dir ect ion befor e it s
comput at ion.
cov r emoves t he mean fr om each column befor e calculat ing t he r esult s.
The cov funct ion is par t of t he st andar d MATLAB language.
Algorithm [n,p] = size(x);
x = xones(n,1)*(sum(x)/n);
y = x'*x/(n1);
See Also
corrcoef Cor r elat ion coefficient mat r ix.
mean Aver age value (see t he online MATLAB Function
Reference).
median Median value (see t he online MATLAB Function
Reference).
std St andar d deviat ion (see t he online MATLAB
Function Reference).
xcorr Cr oss-cor r elat ion funct ion est imat e.
xcov Cr oss-covar iance funct ion est imat e (equal t o
mean-r emoved cr oss-cor r elat ion).
cplxpair
6-90
6cplxpair
Purpose Gr oup complex number s int o complex conjugat e pair s.
Syntax y = cplxpair(x)
y = cplxpair(x,tol)
Description y = cplxpair(x) r et ur ns x wit h complex conjugat e pair s gr ouped t oget her .
cplxpair or der s t he conjugat e pair s by incr easing r eal par t . Wit hin a pair , t he
element wit h negat ive imaginar y par t comes fir st . The funct ion r et ur ns all
pur ely r eal values following all t he complex pair s.
y = cplxpair(x,tol) includes a t oler ance, tol, for det er mining which
number s ar e r eal and which ar e pair ed complex conjugat es. By default ,
cplxpair uses a t oler ance of 100*eps r elat ive t o abs(x(i)). cplxpair for ces
t he complex conjugat e pair s t o be exact complex conjugat es.
The cplxpair funct ion is par t of t he st andar d MATLAB language.
Example Or der five poles evenly spaced ar ound t he unit cir cle int o complex pair s:
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 If t her e is an odd number of complex number s, or if t he complex number s
cannot be gr ouped int o complex conjugat e pair s wit hin t he t oler ance, cplxpair
gener at es t he er r or message:
Complex numbers can't be paired.
cremez
6-91
6cr emez
Purpose Complex and nonlinear -phase equir ipple FIR filt er design.
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 allows ar bit r ar y fr equency-domain const r aint s t o be specified for t he
design of a possibly complex FIR filt er . The Chebyshev (or minimax) filt er er r or
is opt imized, pr oducing equir ipple FIR filt er designs.
b = cremez(n,f,'fresp') r et ur ns a lengt h n+1 FIR filt er wit h t he best
appr oximat ion t o t he desir ed fr equency r esponse as r et ur ned by funct ion
fresp. f is a vect or of fr equency band edge pair s, specified in t he r ange
-1 and 1, wher e 1 cor r esponds t o half t he sampling fr equency (t he Nyquist
fr equency). The fr equencies must be in incr easing or der , and f must have even
lengt h. The fr equency bands span f(k) t o f(k+1) for k odd; t he int er vals
f(k+1) t o f(k+2) for k odd ar e t r ansit ion bands or dont car e r egions dur ing
opt imizat ion.
b = cremez(n,f,'fresp',w) uses t he r eal, non-negat ive weight s in vect or w t o
weight t he fit in each fr equency band. The lengt h of w is half t he lengt h of f, so
t her e is exact ly one weight per band.
b = cremez(n,f,{'fresp',p1,p2,...},...) supplies opt ional par amet er s
p1, p2, ..., t o t he fr equency r esponse funct ion fresp. Pr edefined 'fresp'
fr equency r esponse funct ions ar e included for a number of common filt er
designs, as descr ibed below. For all of t he pr edefined fr equency r esponse
funct ions, t he symmet r y opt ion 'sym' default s t o 'even' if no negat ive
fr equencies ar e cont ained in f and d = 0; ot her wise 'sym' default s t o 'none'.
(See t he 'sym' opt ion below for det ails.) For all of t he pr edefined fr equency
r esponse funct ions, d specifies a gr oup-delay offset such t hat t he filt er r esponse
cremez
6-92
has a gr oup delay of n/2+d in unit s of t he sample int er val. Negat ive values
cr eat e less delay; posit ive values cr eat e mor e delay. By default , d = 0.
lowpass, highpass, bandpass, bandstop
These funct ions shar e a common synt ax, exemplified her e by 'lowpass':
b = cremez(n,f,'lowpass',...) and
b = cremez(n,f,{'lowpass',d},...) design a linear -phase (n/2+d delay)
filt er .
multiband designs a linear -phase fr equency r esponse filt er wit h ar bit r ar y
band amplit udes.
b = cremez(n,f,{'multiband',a},...) and
b = cremez(n,f,{'multiband',a,d},...) specify vect or a cont aining t he
desir ed amplit udes at t he band edges in f. The desir ed amplit ude at
fr equencies bet ween pair s of point s f(k) and f(k+1) for k odd is t he line
segment connect ing t he point s (f(k),a(k)) and (f(k+1),a(k+1)).
differentiator designs a linear -phase differ ent iat or . For t hese designs,
zer o-fr equency must be in a t r ansit ion band, and band weight ing is set t o be
inver sely pr opor t ional t o fr equency.
b = cremez(n,f,{'differentiator',Fs},...) and
b = cremez(n,f,{'differentiator',Fs,d},...) specify t he sample r at e Fs
used t o det er mine t he slope of t he differ ent iat or r esponse. If omit t ed, Fs
default s t o 1.
hilbfilt designs a linear -phase Hilber t t r ansfor m filt er r esponse. For
Hilber t designs, zer o-fr equency must be in a t r ansit ion band.
b = cremez(n,f,'hilbfilt',...) and
b = cremez(N,F,{'hilbfilt',d},...) design a linear -phase (n/2+d delay)
Hilber t t r ansfor m filt er .
b = cremez(n,f,a,w) is a synonym for
b = cremez(n,f,{'multiband',a},w).
b = cremez(...,'sym') imposes a symmet r y const r aint on t he impulse
r esponse of t he design, wher e 'sym' may be one of t he following:
cremez
6-93
'none' indicat es no symmet r y const r aint
This is t he default if any negat ive band edge fr equencies ar e passed, or if
'fresp' does not supply a default .
'even' indicat es a r eal and even impulse r esponse
This is t he default for highpass, lowpass, bandpass, bandst op, and
mult iband designs.
'odd' indicat es a r eal and odd impulse r esponse
This is t he default for Hilber t and differ ent iat or designs.
'real' indicat es conjugat e symmet r y for t he fr equency r esponse
If any 'sym' opt ion ot her t han 'none' is specified, t he band edges should only
be specified over posit ive fr equencies; t he negat ive fr equency r egion is filled in
fr om symmet r y. If a 'sym' opt ion is not specified, t he 'fresp' funct ion is
quer ied for a default set t ing.
b = cremez(...,'skip_stage2') disables t he second-st age opt imizat ion
algor it hm, which execut es only when cremez det er mines t hat an opt imal
solut ion has not been r eached by t he st andar d Remez er r or -exchange.
Disabling t his algor it hm may incr ease t he speed of comput at ion, but may incur
a r educt ion in accur acy. By default , t he second-st age opt imizat ion is enabled.
b = cremez(...,'debug') enables t he display of int er mediat e r esult s dur ing
t he filt er design, wher e 'debug' may be one of 'trace', 'plots', 'both', or
'off'. By default , it is set t o 'off'.
b = cremez(...,{lgrid}) uses t he int eger lgrid t o cont r ol t he densit y of t he
fr equency gr id, which has r oughly 2^nextpow2(lgrid*n) fr equency point s.
The default value for lgrid is 25. Not e t hat t he {lgrid} ar gument must be a
1-by-1 cell ar r ay.
Any combinat ion of t he 'sym', 'skip_stage2', 'debug', and {lgrid} opt ions
may be specified.
[b,delta] = cremez(...) r et ur ns t he maximum r ipple height delta.
cremez
6-94
[b,delta,opt] = cremez(...) r et ur ns a st r uct ur e opt of opt ional r esult s
comput ed by cremez and cont ains t he following fields:
Examples Example 1
Design a 31-t ap, linear -phase, lowpass filt er :
b = cremez(30,[1 0.5 0.4 0.7 0.8 1],'lowpass');
freqz(b,1,512,'whole');
opt.fgrid Fr equency gr id vect or used for t he filt er design opt imizat ion
opt.des Desir ed fr equency r esponse for each point in opt.fgrid
opt.wt Weight ing for each point in opt.fgrid
opt.H Act ual fr equency r esponse for each point in opt.fgrid
opt.error Er r or at each point in opt.fgrid
opt.iextr Vect or of indices int o opt.fgrid for ext r emal fr equencies
opt.fextr Vect or of ext r emal fr equencies
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
4000
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
100
50
0
50
Normalized Angular Frequency ( rads/sample)
M
a
g
n
i
t
u
d
e

(
d
B
)
cremez
6-95
Example 2
Design a nonlinear -phase allpass FIR filt er .
Fir st select (or cr eat e) t he funct ion fresp t hat r et ur ns t he desir ed fr equency
r esponse. For t his example, fresp is t he allpass.m funct ion in t he
signal/signal/private dir ect or y which r et ur ns t he fr equency r esponse of a
nonlinear -phase allpass filt er . Copy allpass.m t o anot her locat ion on t he
MATLAB pat h befor e t r ying t he example.
Befor e using cremez wit h allpass.m t o gener at e t he filt er coefficient s, call
allpass alone t o cr eat e t he desired r esponse.
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
Vect or d now cont ains t he complex fr equency r esponse t hat we desir e for t he
FIR filt er comput ed by cremez.
Now comput e t he FIR filt er t hat best appr oximat es t his r esponse:
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
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
)
cremez
6-96
The freqz plot shows t he fr equency r esponse of t he filt er comput ed by cremez
t o appr oximat e t he desir ed r esponse. Check t he accur acy of t he appr oximat ion
by over laying t he desired fr equency r esponse on t he plot .
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')
Remarks User -definable funct ions may be used, inst ead of t he pr edefined fr equency
r esponse funct ions for 'fresp'. The funct ion is called fr om wit hin cremez using
t he following synt ax:
[dh,dw] = fresp(n,f,gf,w,p1,p2,...) wher e
n is t he filt er or der .
f is t he vect or of fr equency band edges t hat appear monot onically bet ween
-1 and 1, wher e 1 is t he Nyquist fr equency.
gf is a vect or of gr id point s t hat have been linear ly int er polat ed over each
specified fr equency band by cremez. gf det er mines t he fr equency gr id at
which t he r esponse funct ion must be evaluat ed. This is t he same dat a
r et ur ned by cremez in t he fgrid field of t he opt st r uct ur e.
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
6-97
w is a vect or of r eal, posit ive weight s, one per band, used dur ing opt imizat ion.
w is opt ional in t he call t o cremez; if not specified, it is set t o unit y weight ing
befor e being passed t o 'fresp'.
dh and dw ar e t he desir ed complex fr equency r esponse and band weight
vect or s, r espect ively, evaluat ed at each fr equency in gr id gf.
p1, p2, ..., ar e opt ional par amet er s t hat may be passed t o 'fresp'.
Addit ionally, a pr eliminar y call is made t o 'fresp' t o det er mine t he default
symmet r y pr oper t y 'sym'. This call is made using t he synt ax:
sym = fresp('defaults',{n,f,[],w,p1,p2,...})
The ar gument s may be used in det er mining an appr opr iat e symmet r y default
as necessar y. The funct ion private/lowpass.m may be useful as a t emplat e for
gener at ing new fr equency r esponse funct ions.
Algorithm An ext ended ver sion of t he Remez exchange met hod is implement ed for t he
complex case. This exchange met hod obt ains t he opt imal filt er when t he
equir ipple nat ur e of t he filt er is r est r ict ed t o have n+2 ext r emals. When it does
not conver ge, t he algor it hm swit ches t o an ascent -descent algor it hm t hat t akes
over t o finish t he conver gence t o t he opt imal solut ion. See t he r efer ences for
fur t her det ails.
cremez
6-98
Diagnostics The following diagnost ic messages ar ise fr om incor r ect usage of cremez:
Not enough input arguments.
F must contain an even number of band edge entries.
Band edges must be monotonically increasing.
Expecting a string argument.
Invalid argument arg specified.
Invalid default symmetry option sym returned from response
function fresp. Must be one of 'none', 'real', 'even', or 'odd'.
Frequency band edges must be in the range [1,+1] for designs with
SYM = 'sym'.
Frequency band edges must be in the range [0,+1] for designs with
SYM = 'sym'.
Incorrect size of results from response function fresp. Sizes must
be the same size as the frequency grid GF.
Both 1 and 1 have been specified as frequencies in F, and the
frequency spacing is too close to move either of them toward its
neighbor.
Internal error: Grid frequencies out of range.
Internal error: domain must be "whole" or "half".
Internal error: obtained a negative bandwidth.
Internal error: two extremal frequecies at the same grid point.
Internal error: dBrange must be > 0.
cremez
6-99
See Also
References [1] Kar am, L.J ., and J .H. McClellan. Complex Chebyshev Appr oximat ion for
FIR Filt er Design. IEEE Trans. on Circuits and S ystems II. Mar ch 1995.
Pgs. 207-216.
[2] Kar am, L.J . Design of Complex Digital FIR Filters in the Chebyshev S ense.
Ph.D. Thesis, Geor gia Inst it ut e of Technology, Mar ch 1995.
[3] Demjanjov, V.F., and V.N. Malozemov. Introduction to Minimax. New Yor k:
J ohn Wiley & Sons, 1974.
fir1 Window-based finit e impulse r esponse filt er design
st andar d r esponse.
fir2 Window-based finit e impulse r esponse filt er design
ar bit r ar y r esponse.
firls Least squar e linear -phase FIR filt er design.
remez Par ks-McClellan opt imal FIR filt er design.
private/bandpass Bandpass filt er design funct ion.
private/bandstop Bandst op filt er design funct ion.
private/different
iator
Differ ent iat or filt er design funct ion.
private/highpass Highpass filt er design funct ion.
private/hilbfilt Hilber t filt er design funct ion.
private/lowpass Lowpass filt er design funct ion.
private/multiband Mult iband filt er design funct ion.
csd
6-100
6csd
Purpose Est imat e t he cr oss spect r al densit y (CSD) of t wo signals.
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,noverlap)
Pxy = csd(x,y,...,'dflag')
[Pxy,Pxyc,f] = csd(x,y,nfft,Fs,window,noverlap,p)
csd(x,y,...)
Description Pxy = csd(x,y) est imat es t he cr oss spect r al densit y of t he lengt h n sequences
x and y using t he Welch met hod of spect r al est imat ion. Pxy = csd(x,y) uses
t he following default values:
nfft = min(256,length(x))
Fs = 2
window = hanning(nfft)
noverlap = 0
nfft specifies t he FFT lengt h t hat csd uses. This value det er mines t he
fr equencies at which t he cr oss spect r um is est imat ed. Fs is a scalar t hat
specifies t he sampling fr equency. window specifies a windowing funct ion and
t he number of samples csd uses in it s sect ioning of t he x and y vect or s.
noverlap is t he number of samples by which t he sect ions over lap. Any
ar gument s omit t ed fr om t he end of t he par amet er list use t he default values
shown above.
If x and y ar e r eal, csd est imat es t he cr oss spect r al densit y at posit ive
fr equencies only; in t his case, t he out put Pxy is a column vect or of lengt h
nfft/2 + 1 for nfft even and (nfft + 1)/2 for nfft odd. If x or y is complex,
csd est imat es t he cr oss spect r al densit y at bot h posit ive and negat ive
fr equencies and Pxy has lengt h nfft.
Pxy = csd(x,y,nfft) uses t he FFT lengt h nfft in est imat ing t he cr oss
spect r al densit y of x and y. Specify nfft as a power of 2 for fast est execut ion.
[Pxy,f] = csd(x,y,nfft,Fs) r et ur ns a vect or f of fr equencies at which t he
funct ion evaluat es t he CSD. f is t he same size as Pxy, so plot(f,Pxy) plot s t he
csd
6-101
spect r um ver sus pr oper ly scaled fr equency. Fs has no effect on t he out put Pxy;
it is a fr equency scaling mult iplier .
Pxy = csd(x,y,nfft,Fs,window) specifies a windowing funct ion and t he
number of samples per sect ion of t he x vect or . If you supply a scalar for window,
csd uses a Hanning window of t hat lengt h. The lengt h of t he window must be
less t han or equal t o nfft; csd zer o pads t he sect ions if t he lengt h of t he window
is less t han nfft. csd r et ur ns an er r or if t he lengt h of t he window is gr eat er
t han nfft.
Pxy = csd(x,y,nfft,Fs,window,noverlap) over laps t he sect ions of x and y
by noverlap samples.
You can use t he empt y mat r ix [] t o specify t he default value for any input
ar gument except x or y. For example,
csd(x,y,[],10000)
is equivalent t o
csd(x)
but wit h a sampling fr equency of 10,000 Hz inst ead of t he default of 2 Hz.
Pxy = csd(x,y,...,'dflag') specifies a det r end opt ion, wher e dflag is:
linear, t o r emove t he best st r aight -line fit fr om t he pr ewindowed sect ions of
x and y
mean, t o r emove t he mean fr om t he pr ewindowed sect ions of x and y
none, for no det r ending (default )
The dflag par amet er must appear last in t he list of input ar gument s. csd
r ecognizes a dflag st r ing no mat t er how many int er mediat e ar gument s ar e
omit t ed.
[Pxy,Pxyc,f] = csd(x,y,nfft,Fs,window,noverlap,p) wher e p is a posit ive
scalar bet ween 0 and 1 r et ur ns a vect or Pxyc t hat cont ains an est imat e of t he
p*100 per cent confidence int er val for Pxy. Pxyc is a t wo-column mat r ix t he
same lengt h as Pxy. The int er val [Pxyc(:,1), Pxyc(:,2)] cover s t he t r ue
CSD wit h pr obabilit y p. plot(f,[Pxy Pxyc]) plot s t he cr oss spect r um inside
t he p*100 per cent confidence int er val. If unspecified, p default s t o 0.95.
csd
6-102
csd(x,y,...) plot s t he CSD ver sus fr equency in t he cur r ent figur e window. If
t he p par amet er is specified, t he plot includes t he confidence int er val.
Example Gener at e t wo color ed noise signals and plot t heir CSD wit h a confidence
int er val of 95%. Specify a lengt h 1024 FFT, a 500 point t r iangular window wit h
no over lap, and a sampling fr equency of 10 Hz:
h = fir1(30,0.2,boxcar(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 implement s t he Welch met hod of spect r al densit y est imat ion (see
r efer ences [1] and [2]):
1 It applies t he window specified by t he window vect or t o each successive
det r ended sect ion.
2 It t r ansfor ms each sect ion wit h an nfft-point FFT.
3 It for ms t he per iodogr am of each sect ion by scaling t he pr oduct of t he
t r ansfor m of t he y sect ion and t he conjugat e of t he t r ansfor med x sect ion.
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
6-103
4 It aver ages t he per iodogr ams of t he successive over lapping sect ions t o for m
Pxy, t he cr oss spect r al densit y of x and y.
The number of sect ions t hat csd aver ages is k, wher e k is
fix((length(x)noverlap)/(length(window)noverlap))
Diagnostics An appr opr iat e diagnost ic message is displayed when incor r ect ar gument s t o
csd ar e 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
References [1] Rabiner , L.R., and B. Gold. Theory and Application of Digital S ignal
Processing. Englewood Cliffs, NJ : Pr ent ice-Hall, 1975. Pgs. 414-419.
[2] Welch, P.D. The Use of Fast Four ier Tr ansfor m for t he Est imat ion of Power
Spect r a: A Met hod Based on Time Aver aging Over Shor t , Modified
Per iodogr ams. IEEE Trans. Audio Electroacoust. Vol. AU-15 (J une 1967).
Pgs. 70-73.
cohere Est imat e magnit ude squar ed coher ence funct ion
bet ween t wo signals.
pburg Power spect r um est imat e using t he Bur g met hod.
pmtm Power spect r um est imat e using t he mult it aper
met hod (MTM).
pmusic Power spect r um est imat e using MUSIC eigenvect or
met hod.
pwelch Est imat e t he power spect r al densit y (PSD) of a signal
using Welchs met hod.
pyulear Power spect r um est imat e using Yule-Walker AR
met hod.
tfe Tr ansfer funct ion est imat e fr om input and out put .
csd
6-104
[3] Oppenheim, A.V., and R.W. Schafer . Discrete-Time S ignal Processing.
Englewood Cliffs, NJ : Pr ent ice-Hall, 1989. Pg. 737.
czt
6-105
6czt
Purpose Chir p z-t r ansfor m.
Syntax y = czt(x,m,w,a)
y = czt(x)
Description y = czt(x,m,w,a) r et ur ns t he chir p z-t r ansfor m of signal x. The chir p
z-t r ansfor m is t he z-t r ansfor m of x along a spir al cont our defined by w and a. m
is a scalar t hat specifies t he lengt h of t he t r ansfor m, w is t he r at io bet ween
point s along t he z-plane spir al cont our of int er est , and scalar a is t he complex
st ar t ing point on t hat cont our . The cont our , a spir al or chir p in t he z-plane, is
given by
z = a*(w.^(0:m1))
y = czt(x) uses t he following default values:
m = length(x)
w = exp(j*2*pi/m)
a = 1
Wit h t hese default s, czt r et ur ns t he z-t r ansfor m of x at m equally spaced point s
ar ound t he unit cir cle. This is equivalent t o t he discr et e Four ier t r ansfor m of
x, or fft(x). The empt y mat r ix [] specifies t he default value for a par amet er .
If x is a mat r ix, czt(x,m,w,a) t r ansfor ms t he columns of x.
Examples Cr eat e a r andom vect or x of lengt h 1013 and comput e it s DFT using czt. This
is fast er t han t he fft funct ion on t he same sequence.
x = randn(1013,1);
y = czt(x);
Use czt t o zoom in on a nar r ow-band sect ion (100 t o 150 Hz) of a filt er s
fr equency r esponse. Fir st design t he filt er :
h = fir1(30,125/500,boxcar(31)); % filter
czt
6-106
Est ablish fr equency and CZT par amet er s:
Fs = 1000; f1 = 100; f2 = 150; % in Hertz
m = 1024;
w = exp(j*2*pi*(f2f1)/(m*Fs));
a = exp(j*2*pi*f1/Fs);
Comput e bot h t he DFT and CZT of t he filt er :
y = fft(h,1000);
z = czt(h,m,w,a);
Cr eat e fr equency vect or s and compar e t he r esult s:
fy = (0:length(y)1)'*1000/length(y);
fz = ((0:length(z)1)'*(f2f1)/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 t he next power -of-2 lengt h FFT t o per for m a fast convolut ion when
comput ing t he z-t r ansfor m on a specified chir p cont our [1]. czt can be
significant ly fast er t han fft for lar ge, pr ime-lengt h sequences.
Diagnostics If m, w, or a is not a scalar , czt gives t he following er r or message:
Inputs M, W, and A must be scalars.
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
6-107
See Also
References [1] Rabiner , L.R., and B. Gold. Theory and Application of Digital S ignal
Processing. Englewood Cliffs, NJ : Pr ent ice-Hall, 1975. Pgs. 393-399.
fft One-dimensional fast Four ier t r ansfor m.
freqz Fr equency r esponse of digit al filt er s.
dct
6-108
6dct
Purpose Discr et e cosine t r ansfor m (DCT).
Syntax y = dct(x)
y = dct(x,n)
Description y = dct(x) r et ur ns t he unit ar y discr et e cosine t r ansfor m of x
wher e
N is t he lengt h of x, and x and y ar e t he same size. If x is a mat r ix, dct
t r ansfor ms it s columns. The ser ies is indexed fr om n = 1 and k = 1 inst ead of
t he usual n = 0 and k = 0 because MATLAB vect or s r un fr om 1 t o N inst ead of
fr om 0 t o N- 1.
y = dct(x,n) pads or t r uncat es x t o lengt h n befor e t r ansfor ming.
The DCT is closely r elat ed t o t he discr et e Four ier t r ansfor m. You can oft en
r econst r uct a sequence ver y accur at ely fr om only a few DCT coefficient s, a
useful pr oper t y for applicat ions r equir ing dat a r educt ion.
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
6-109
Example Find how many DCT coefficient s r epr esent 99% of t he ener gy in 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,100i)])/norm(X)<.99)
i = i + 1;
end
i =
3
See Also
References [1] J ain, A.K. Fundamentals of Digital Image Processing. Englewood Cliffs, NJ :
Pr ent ice-Hall, 1989.
[2] Pennebaker , W.B., and J .L. Mit chell. J PEG S till Image Data Compression
S tandard. New Yor k, NY: Van Nost r and Reinhold, 1993. Chapt er 4.
fft One-dimensional fast Four ier t r ansfor m.
idct Inver se discr et e cosine t r ansfor m.
dct2 Two-dimensional DCT (see Image Processing Toolbox
Users Guide).
idct2 Two-dimensional inver se DCT (see Image Processing
Toolbox Users Guide).
decimate
6-110
6decimat e
Purpose Decr ease t he sampling r at e for a sequence (decimat ion).
Syntax y = decimate(x,r)
y = decimate(x,r,n)
y = decimate(x,r,'fir')
y = decimate(x,r,n,'fir')
Description Decimat ion r educes t he or iginal sampling r at e for a sequence t o a lower r at e.
It is t he opposit e of int er polat ion. The decimat ion pr ocess filt er s t he input dat a
wit h a lowpass filt er and t hen r esamples t he r esult ing smoot hed signal at a
lower r at e.
y = decimate(x,r) r educes t he sample r at e of x by a fact or r. The decimat ed
vect or y is r t imes shor t er in lengt h t han t he input vect or x. By default ,
decimate employs an eight h-or der lowpass Chebyshev t ype I filt er . It filt er s
t he input sequence in bot h t he for war d and r ever se dir ect ions t o r emove all
phase dist or t ion, effect ively doubling t he filt er or der .
y = decimate(x,r,n) uses an or der n Chebyshev filt er . Or der s above 13 ar e
not r ecommended because of numer ical inst abilit y. MATLAB displays a
war ning in t his case.
y = decimate(x,r,'fir') uses a 30-point FIR filt er , inst ead of t he Chebyshev
IIR filt er . Her e decimate filt er s t he input sequence in only one dir ect ion. This
t echnique conser ves memor y and is useful for wor king wit h long sequences.
y = decimate(x,r,n,'fir') uses a lengt h n FIR filt er .
Example Decimat e a signal by a fact or of four :
t = 0:.00025:1; % time vector
x = sin(2*pi*30*t) + sin(2*pi*60*t);
y = decimate(x,4);
decimate
6-111
View t he or iginal and decimat ed signals:
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 decimat ion algor it hms 8.2 and 8.3 fr om [1]:
1 It designs a lowpass filt er . By default , decimate uses a Chebyshev t ype I
filt er wit h nor malized cut off fr equency 0.8/r and 0.05 dB of passband r ipple.
For t he fir opt ion, decimate designs a lowpass FIR filt er wit h cut off
fr equency 1/r using fir1.
2 For t he FIR filt er , decimate applies t he filt er t o t he input vect or in one
dir ect ion. In t he IIR case, decimate applies t he filt er in for war d and r ever se
dir ect ions wit h filtfilt.
3 decimate r esamples t he filt er ed dat a by select ing ever y r-t h point .
Diagnostics If r is not an int eger , decimate gives t he following er r or message:
Resampling rate R must be an integer.
If n specifies an IIR filt er wit h or der gr eat er t han 13, decimate gives t he
following war ning:
Warning: IIR filters above order 13 may be unreliable.
0 50 100
-2
-1
0
1
2
Original Signal
0 10 20 30
-2
-1
0
1
2
Decimated Signal
decimate
6-112
See Also
References [1] IEEE. Programs for Digital S ignal Processing. IEEE Pr ess. New Yor k: J ohn
Wiley & Sons, 1979. Chapt er 8.
interp Incr ease sampling r at e by an int eger fact or (int er polat ion).
resample Change sampling r at e by any r at ional fact or.
spline Cubic spline int er polat ion (see t he online MATLAB
Function Reference).
upfirdn Upsample, apply an FIR filt er, and downsample.
deconv
6-113
6deconv
Purpose Deconvolut ion and polynomial division.
Syntax [q,r] = deconv(b,a)
Description [q,r] = deconv(b,a) deconvolves vect or a out of vect or b, using long division.
The r esult (quot ient ) is r et ur ned in vect or q and t he r emainder in vect or r such
t hat b = conv(q,a) + r.
If a and b ar e vect or s of polynomial coefficient s, convolving t hem is equivalent
t o polynomial mult iplicat ion, and deconvolut ion is equivalent t o polynomial
division. The r esult of dividing b by a is quot ient q and r emainder r.
The deconv funct ion is par t of t he st andar d MATLAB language.
Example The convolut ion of a = [1 2 3] and b = [4 5 6] is
c = conv(a,b)
c =
4 13 28 27 18
Use deconv t o divide b back out :
[q,r] = deconv(c,a)
q =
4 5 6
r =
0 0 0 0 0
Algorithm This funct ion calls filter t o comput e t he deconvolut ion as t he impulse
r esponse of an IIR filt er .
See Also
conv Convolut ion and polynomial mult iplicat ion.
filter Filt er dat a wit h a r ecur sive (IIR) or nonr ecur sive
(FIR) filt er.
residuez z-t r ansfor m par t ial fr act ion expansion.
demod
6-114
6demod
Purpose Demodulat ion for communicat ions simulat ion.
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 per for ms demodulat ion, t hat is, it obt ains t he or iginal signal fr om a
modulat ed ver sion of t he signal. demod undoes t he oper at ion per for med by
modulate.
x = demod(y,Fc,Fs,'method') and
x = demod(y,Fc,Fs,'method',opt) demodulat e t he r eal car r ier signal y wit h
a car r ier fr equency Fc and sampling fr equency Fs, using one of t he opt ions
list ed below for method. (Not e t hat some met hods accept an opt ion, opt.)
amdsbsc
or
am
Ampli tude demodulati on, double s i deband, suppres se d
carri er. Mult iplies y by a sinusoid of fr equency Fc and applies a
fift h-or der But t er wor t h lowpass filt er using filtfilt:
x = y.*cos(2*pi*Fc*t);
[b,a] = butter(5,Fc*2/Fs);
x = filtfilt(b,a,x);
amdsbtc Ampli tude demodulati on, double s i deband, transmi tte d
carri er. Mult iplies y by a sinusoid of fr equency Fc, and applies a
fift h-or der But t er wor t h lowpass filt er using filtfilt:
x = y.*cos(2*pi*Fc*t);
[b,a] = butter(5,Fc*2/Fs);
x = filtfilt(b,a,x);
If you specify opt, demod subt r act s scalar opt fr om x. The default
value for opt is 0.
amssb Ampli tude demodulati on, si ngle s i deband. Mult iplies y by a
sinusoid of fr equency Fc and applies a fift h-or der But t er wor t h
lowpass filt er using filtfilt:
x = y.*cos(2*pi*Fc*t);
[b,a] = butter(5,Fc*2/Fs);
x = filtfilt(b,a,x);
demod
6-115
The default met hod is 'am'. Except for t he 'ptm' and 'pwm' cases, x is t he
same size as y.
If y is a mat r ix, demod demodulat es it s columns.
x = demod(y,Fc,Fs,'pwm','centered') finds t he pulse widt hs assuming
t hey ar e cent er ed at t he beginning of each per iod. x is lengt h
length(y)*Fc/Fs.
fm Frequency de modulati on. Demodulat es t he FM wavefor m by
modulat ing t he Hilber t t r ansfor m of y by a complex exponent ial
of fr equency Fc Hz and obt ains t he inst ant aneous fr equency of
t he r esult .
pm Phase demodulati on. Demodulat es t he PM wavefor m by
modulat ing t he Hilber t t r ansfor m of y by a complex exponent ial
of fr equency Fc Hz and obt ains t he inst ant aneous phase of t he
r esult .
ptm Puls e-ti me de modulati on. Finds t he pulse t imes of a pulse-t ime
modulat ed signal y. For cor r ect demodulat ion, t he pulses cannot
over lap. x is lengt h length(t)*Fc/Fs.
pwm Pulse-wi dth demodulati on. Finds t he pulse widt hs of a
pulse-widt h modulat ed signal y. demod r et ur ns in x a vect or whose
element s specify t he widt h of each pulse in fr act ions of a per iod.
The pulses in y should st ar t at t he beginning of each car r ier
per iod, t hat is, t hey should be left just ified.
qam Quadrature ampli tude de modulati on.
[x1,x2] = demod(y,Fc,Fs,'qam') mult iplies y by a cosine and a
sine of fr equency Fc and applies a fift h-or der But t er wor t h
lowpass filt er using 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);
demod
6-116
See Also
modulate Modulat ion for communicat ions simulat ion.
vco Volt age cont r olled oscillat or.
dftmtx
6-117
6dft mt x
Purpose Discr et e Four ier t r ansfor m mat r ix.
Syntax A = dftmtx(n)
Description A discrete Fourier transform matrix is a complex mat r ix of values ar ound t he
unit cir cle, whose mat r ix pr oduct wit h a vect or comput es t he discr et e Four ier
t r ansfor m of t he vect or .
A = dftmtx(n) r et ur ns t he n-by-n complex mat r ix A t hat , when mult iplied int o
a lengt h n column vect or x:
y = A*x
comput es t he discr et e Four ier t r ansfor m of x.
The inver se discr et e Four ier t r ansfor m mat r ix is
Ai = conj(dftmtx(n))/n
Example In pr act ice, t he discr et e Four ier t r ansfor m is comput ed mor e efficient ly and
uses less memor y wit h an FFT algor it hm
x = 1:256;
y1 = fft(x);
t han by using t he Four ier t r ansfor m mat r ix:
n = length(x);
y2 = x*dftmtx(n);
norm(y1y2)
ans =
1.8297e-009
Algorithm dftmtx uses an out er pr oduct t o gener at e t he t r ansfor m mat r ix.
See Also
convmtx Convolut ion mat r ix.
fft One-dimensional fast Four ier t r ansfor m.
diric
6-118
6dir ic
Purpose Dir ichlet or per iodic sinc funct ion.
Syntax y = diric(x,n)
Description y = diric(x,n) r et ur ns a vect or or ar r ay y t he same size as x. The element s
of y ar e t he Dir ichlet funct ion of t he element s of x. n must be a posit ive int eger .
The Dir ichlet funct ion, or per iodic sinc funct ion, is
for any nonzer o int eger n. This funct ion has per iod 2 for n odd and per iod 4
for n even. It s peak value is 1, and it s minimum value is -1 for n even. The
magnit ude of t his funct ion is (1/n) t imes t he magnit ude of t he discr et e-t ime
Four ier t r ansfor m of t he n-point r ect angular window.
Diagnostics If n is not a posit ive int eger , diric gives t he following er r or message:
Requires n to be a positive integer.
See Also
dir ic x n , ( )
1
x
2
------- n 1 ( )
x 0 2 t 4 t , , , =
n x 2 ( ) sin
n x 2 ( ) sin
----------------------------
else

'

=
cos Cosine of vect or /mat r ix element s (see t he online
MATLAB Function Reference).
gauspuls Gaussian-modulat ed sinusoidal pulse gener at or.
pulstran Pulse t r ain gener at or.
rectpuls Sampled aper iodic r ect angle gener at or.
sawtooth Sawt oot h or t r iangle wave gener at or.
sin Sine of vect or /mat r ix element s (see t he online
MATLAB Function Reference).
sinc Sinc or sin(t )/t funct ion.
square Squar e wave gener at or.
tripuls Sampled aper iodic t r iangle gener at or.
dpss
6-119
6dpss
Purpose Discr et e pr olat e spher oidal sequences (Slepian 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,'spline')
[e,v] = dpss(n,nw,'spline',Ni)
[e,v] = dpss(n,nw,'linear')
[e,v] = dpss(n,nw,'linear',Ni)
[e,v] = dpss(...,'trace')
[e,v] = dpss(...,'int','trace')
Description [e,v] = dpss(n,nw) gener at es t he fir st 2*nw discrete prolate spheroidal
sequences (DPSS) of lengt h n in t he columns of e, and t heir cor r esponding
concent r at ions in vect or v. They ar e also gener at ed in t he DPSS MAT-file
dat abase dpss.mat. nw must be less t han n/2.
[e,v] = dpss(n,nw,k) r et ur ns t he k most band-limit ed sequences of t he 2*nw
discr et e pr olat e spher oidal sequences calculat ed. k must be bet ween 0 and
2*nw.
[e,v] = dpss(n,nw,[k1 k2]) r et ur ns t he k1-t h t hr ough t he k2-t h sequences
fr om t he 2*nw discr et e pr olat e spher oidal sequences calculat ed, wher e
1 k1 k2 (2*nw).
For all of t he above for ms,
The Slepian sequences ar e calculat ed dir ect ly.
The sequences ar e gener at ed in t he fr equency band || (2W), wher e
W = nw/n is t he half-bandwidt h and is in r adians.
e(:,1) is t he lengt h n signal most concent r at ed in t he fr equency band
|| (2W) r adians, e(:,2) is t he signal or t hogonal t o e(:,1) t hat is most
concent r at ed in t his band, e(:,3) is t he signal or t hogonal t o bot h e(:,1)
and e(:,2) t hat is most concent r at ed in t his band, et c.
For mult it aper spect r al analysis, t ypical choices for nw ar e 2, 5/2, 3, 7/2, or 4.
[e,v] = dpss(n,nw,'spline') uses spline int er polat ion t o comput e e and v
fr om t he sequences in dpss.mat wit h lengt h closest t o n.
dpss
6-120
[e,v] = dpss(n,nw,'spline',Ni) int er polat es fr om exist ing lengt h Ni
sequences.
[e,v] = dpss(n,nw,'linear') and
[e,v] = dpss(n,nw,'linear',Ni) use linear int er polat ion, which is much
fast er but less accur at e t han spline int er polat ion. 'linear' r equir es Ni > n.
[e,v] = dpss(...,'trace') and
[e,v] = dpss(...,'int','trace') use a t r ailing 'trace' ar gument t o find
out which met hod DPSS uses, wher e 'int' is eit her 'spline' or 'linear'.
See Also
References [1] Per cival, D.B., and A.T. Walden. S pectral Analysis for Physical
Applications: Multitaper and Conventional Univariate Techniques. Cambr idge:
Cambr idge Univer sit y Pr ess, 1993.
dpssclear Remove discr et e pr olat e spher oidal sequences fr om
dat abase.
dpssdir Discr et e pr olat e spher oidal sequences dat abase
dir ect or y.
dpssload Load discr et e pr olat e spher oidal sequences fr om
dat abase.
dpsssave Save discr et e pr olat e spher oidal sequences in
dat abase.
pmtm Power spect r um est imat e using t he mult it aper
met hod (MTM).
dpssclear
6-121
6dpssclear
Purpose Remove discr et e pr olat e spher oidal sequences fr om dat abase.
Syntax dpssclear(n,nw)
Description dpssclear(n,nw) r emoves sequences wit h lengt h n and t ime-bandwidt h
pr oduct nw fr om t he DPSS MAT-file dat abase dpss.mat.
See Also
dpss Discr et e pr olat e spher oidal sequences (Slepian
sequences).
dpssdir Discr et e pr olat e spher oidal sequences dat abase
dir ect or y.
dpssload Load discr et e pr olat e spher oidal sequences fr om
dat abase.
dpsssave Save discr et e pr olat e spher oidal sequences in
dat abase.
dpssdir
6-122
6dpssdir
Purpose Discr et e pr olat e spher oidal sequences dat abase dir ect or y.
Syntax dpssdir
dpssdir(n)
dpssdir(nw,'nw')
dpssdir(n,nw)
index = dpssdir
Description dpssdir manages t he dat abase dir ect or y t hat cont ains t he gener at ed DPSS
samples in t he DPSS MAT-file dat abase dpss.mat.
dpssdir list s t he dir ect or y of saved sequences in dpss.mat.
dpssdir(n) list s t he sequences saved wit h lengt h n.
dpssdir(nw,'nw') list s t he sequences saved wit h t ime-bandwidt h pr oduct nw.
dpssdir(n,nw) list s t he sequences saved wit h lengt h n and t ime-bandwidt h
pr oduct nw.
index = dpssdir is a st r uct ur e ar r ay descr ibing t he DPSS dat abase. Pass n
and nw opt ions as for t he no out put case t o get a filt er ed index.
See Also
dpss Discr et e pr olat e spher oidal sequences (Slepian
sequences).
dpssclear Remove discr et e pr olat e spher oidal sequences fr om
dat abase.
dpssload Load discr et e pr olat e spher oidal sequences fr om
dat abase.
dpsssave Save discr et e pr olat e spher oidal sequences in
dat abase.
dpssload
6-123
6dpssload
Purpose Load discr et e pr olat e spher oidal sequences fr om dat abase.
Syntax [e,v] = dpssload(n,nw)
Description [e,v] = dpssload(n,nw) loads all sequences wit h lengt h n and
t ime-bandwidt h pr oduct nw in t he columns of e and t heir cor r esponding
concent r at ions in vect or v fr om t he DPSS MAT-file dat abase dpss.mat.
See Also
dpss Discr et e pr olat e spher oidal sequences (Slepian
sequences).
dpssclear Remove discr et e pr olat e spher oidal sequences fr om
dat abase.
dpssdir Discr et e pr olat e spher oidal sequences dat abase
dir ect or y.
dpsssave Save discr et e pr olat e spher oidal sequences in
dat abase.
dpsssave
6-124
6dpsssave
Purpose Save discr et e pr olat e spher oidal sequences in dat abase.
Syntax dpsssave(nw,e,v)
status = dpsssave(nw,e,v)
Description dpsssave(nw,e,v) saves t he sequences in t he columns of e and t heir
cor r esponding concent r at ions in vect or v in t he DPSS MAT-file dat abase
dpss.mat.
It is not necessar y t o specify sequence lengt h, because t he lengt h of t he
sequence is det er mined by t he number of r ows of e.
nw is t he time-bandwidth product t hat was specified when t he sequence was
cr eat ed using dpss.
status = dpsssave(nw,e,v) r et ur ns 0 if t he save was successful and 1 if t her e
was an er r or .
See Also
dpss Discr et e pr olat e spher oidal sequences (Slepian
sequences).
dpssclear Remove discr et e pr olat e spher oidal sequences fr om
dat abase.
dpssdir Discr et e pr olat e spher oidal sequences dat abase
dir ect or y.
dpssload Load discr et e pr olat e spher oidal sequences fr om
dat abase.
ellip
6-125
6ellip
Purpose Ellipt ic (Cauer ) filt er design.
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 designs lowpass, bandpass, highpass, and bandst op digit al and analog
ellipt ic filt er s. Ellipt ic filt er s offer st eeper r olloff char act er ist ics t han
But t er wor t h or Chebyshev filt er s, but ar e equir ipple in bot h t he pass- and
st opbands. In gener al, ellipt ic filt er s meet given per for mance specificat ions
wit h t he lowest or der of any filt er t ype.
Digital Domain
[b,a] = ellip(n,Rp,Rs,Wn) designs an or der n lowpass digit al ellipt ic filt er
wit h cut off fr equency Wn, Rp dB of r ipple in t he passband, and a st opband Rs dB
down fr om t he peak value in t he passband. It r et ur ns t he filt er coefficient s in t he
lengt h n + 1 r ow vect or s b and a, wit h coefficient s in descending power s of z:
The cutoff frequency is t he edge of t he passband, at which t he magnit ude
r esponse of t he filt er is Rp dB. For ellip, t he cut off fr equency Wn is a number
bet ween 0 and 1, wher e 1 cor r esponds t o half t he sample fr equency (Nyquist
fr equency). Smaller values of passband r ipple Rp and lar ger values of st opband
at t enuat ion Rs bot h lead t o wider t r ansit ion widt hs (shallower r olloff
char act er ist ics).
If Wn is a t wo-element vect or , Wn = [w1 w2], ellip r et ur ns an or der 2*n
bandpass filt er wit h passband w1 < < w2.
[b,a] = ellip(n,Rp,Rs,Wn,'ftype') designs a highpass or bandst op filt er ,
wher e ftype is:
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
6-126
high for a highpass digit al filt er wit h cut off fr equency Wn
stop for an or der 2*n bandst op digit al filt er if Wn is a t wo-element vect or ,
Wn = [w1 w2]
The st opband is w1 < < w2.
Wit h differ ent number s of out put ar gument s, ellip dir ect ly obt ains ot her
r ealizat ions of t he filt er . To obt ain zer o-pole-gain for m, use t hr ee out put
ar gument s:
[z,p,k] = ellip(n,Rp,Rs,Wn) or
[z,p,k] = ellip(n,Rp,Rs,Wn,'ftype') r et ur ns t he zer os and poles in lengt h
n column vect or s z and p and t he gain in t he scalar k.
To obt ain st at e-space for m, use four out put ar gument s:
[A,B,C,D] = ellip(n,Rp,Rs,Wn) or
[A,B,C,D] = ellip(n,Rp,Rs,Wn,'ftype') wher e A, B, C, and D ar e
and u is t he input , x is t he st at e vect or , and y is t he out put .
Analog Domain
[b,a] = ellip(n,Rp,Rs,Wn,'s') designs an or der n lowpass analog ellipt ic
filt er wit h cut off fr equency Wn and r et ur ns t he filt er coefficient s in t he lengt h
n + 1 r ow vect or s b and a, in descending power s of s:
The cutoff frequency is t he edge of t he passband, at which t he magnit ude
r esponse of t he filt er is Rp dB. For ellip, t he cut off fr equency Wn must be
gr eat er t han 0.
If Wn is a t wo-element vect or wit h w1 < w2, t hen ellip(n,Rp,Rs,Wn,'s')
r et ur ns an or der 2*n bandpass analog filt er wit h 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 + ( ) + + +
---------------------------------------------------------------------------------- = =
ellip
6-127
[b,a] = ellip(n,Rp,Rs,Wn,'ftype','s') designs a highpass or bandst op
filt er , wher e ftype is:
high for a highpass analog filt er wit h cut off fr equency Wn
stop for an or der 2*n bandst op analog filt er . Wn is a t wo-element vect or ,
[w1 w2], specifying t he st opband w1 < < w2.
Wit h differ ent number s of out put ar gument s, ellip dir ect ly obt ains ot her
r ealizat ions of t he analog filt er . To obt ain zer o-pole-gain for m, use t hr ee out put
ar gument s:
[z,p,k] = ellip(n,Rp,Rs,Wn,'s') or
[z,p,k] = ellip(n,Rp,Rs,Wn,'ftype','s') r et ur ns t he zer os and poles in
lengt h n or 2*n column vect or s z and p and t he gain in t he scalar k.
To obt ain st at e-space for m, use four out put ar gument s:
[A,B,C,D] = ellip(n,Rp,Rs,Wn,'s') or
[A,B,C,D] = ellip(n,Rp,Rs,Wn,'ftype','s') wher e A, B, C, and D ar e
and u is t he input , x is t he st at e vect or , and y is t he out put .
Examples For dat a sampled at 1000 Hz, design a sixt h-or der lowpass ellipt ic filt er wit h a
cut off fr equency of 300 Hz, 3 dB of r ipple in t he passband, and 50 dB of
at t enuat ion in t he st opband:
[b,a] = ellip(6,3,50,300/500);
x

Ax Bu + =
y Cx Du + =
ellip
6-128
The filt er s fr equency r esponse is
freqz(b,a,512,1000)
title('n=6 Lowpass Elliptic Filter')
0 50 100 150 200 250 300 350 400 450 500
-600
-400
-200
0
200
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
-100
-80
-60
-40
-20
0
Frequency (Hertz)
M
a
g
n
i
t
u
d
e

R
e
s
p
o
n
s
e

(
d
B
)
n = 6 Lowpass Elliptic Filter
ellip
6-129
Design a 20t h-or der bandpass ellipt ic filt er wit h a passband fr om 100 t o 200 Hz
and plot it s impulse r esponse:
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')
Limitations For high or der filt er s, t he st at e-space for m is t he most numer ically accur at e,
followed by t he zer o-pole-gain for m. The t r ansfer funct ion for m is t he least
accur at e; numer ical pr oblems can ar ise for filt er or der s as low as 15.
Algorithm The design of ellipt ic filt er s is t he most difficult and comput at ionally int ensive
of t he But t er wor t h, Chebyshev t ype I and II, and ellipt ic designs. ellip uses a
five-st ep algor it hm:
1 It finds t he lowpass analog pr ot ot ype poles, zer os, and gain using t he
ellipap funct ion.
2 It conver t s t he poles, zer os, and gain int o st at e-space for m.
3 It t r ansfor ms t he lowpass filt er t o a bandpass, highpass, or bandst op filt er
wit h t he desir ed cut off fr equencies using a st at e-space t r ansfor mat ion.
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
6-130
4 For digit al filt er design, ellip uses bilinear t o conver t t he analog filt er
int o a digit al filt er t hr ough a bilinear t r ansfor mat ion wit h fr equency
pr ewar ping. Car eful fr equency adjust ment guar ant ees t hat t he analog
filt er s and t he digit al filt er s will have t he same fr equency r esponse
magnit ude at Wn or w1 and w2.
5 It conver t s t he st at e-space filt er back t o t r ansfer funct ion or zer o-pole-gain
for m, as r equir ed.
See Also
besself Bessel analog filt er design.
butter But t er wor t h analog and digit al filt er design.
cheby1 Chebyshev t ype I filt er design (passband r ipple).
cheby2 Chebyshev t ype II filt er design (st opband r ipple).
ellipap Ellipt ic analog lowpass filt er pr ot ot ype.
ellipord Ellipt ic filt er or der select ion.
ellipap
6-131
6ellipap
Purpose Ellipt ic analog lowpass filt er pr ot ot ype.
Syntax [z,p,k] = ellipap(n,Rp,Rs)
Description [z,p,k] = ellipap(n,Rp,Rs) r et ur ns t he zer os, poles, and gain of an or der n
ellipt ic analog lowpass filt er pr ot ot ype, wit h Rp dB of r ipple in t he passband,
and a st opband Rs dB down fr om t he peak value in t he passband. The zer os and
poles ar e r et ur ned in lengt h n column vect or s z and p and t he gain in scalar k.
If n is odd, z is lengt h n 1. The t r ansfer funct ion is
Ellipt ic filt er s ar e equir ipple in bot h t he passband and st opband. They offer
st eeper r olloff char act er ist ics t han But t er wor t h and Chebyshev filt er s, but
t hey ar e equir ipple in bot h t he passband and t he st opband. Of t he four classical
filt er t ypes, ellipt ic filt er s usually meet a given set of filt er per for mance
specificat ions wit h t he lowest filt er or der .
ellip set s t he cut off fr equency of t he ellipt ic filt er t o 1 for a nor malized
r esult . The cutoff frequency is t he fr equency at which t he passband ends and
t he filt er has a magnit ude r esponse of 10
-Rp/20
.
Algorithm ellipap uses t he algor it hm out lined in [1]. It employs t he M-file ellipk t o
calculat e t he complet e ellipt ic int egr al of t he fir st kind and t he M-file ellipj
t o calculat e J acobi ellipt ic funct ions.
See Also
References [1] Par ks, T.W., and C.S. Bur r us. Digital Filter Design. New Yor k: J ohn Wiley
& Sons, 1987. Chapt er 7.
H s ( )
z s ( )
p s ( )
---------- k
s z 1 ( ) ( ) s z 2 ( ) ( )Ls z n ( ) ( )
s p 1 ( ) ( ) s p 2 ( ) ( )Ls p n ( ) ( )
----------------------------------------------------------------------------- = =

0
besselap Bessel analog lowpass filt er pr ot ot ype.
buttap But t er wor t h analog lowpass filt er pr ot ot ype.
cheb1ap Chebyshev t ype I analog lowpass filt er pr ot ot ype.
cheb2ap Chebyshev t ype II analog lowpass filt er pr ot ot ype.
ellip Ellipt ic (Cauer ) filt er design.
ellipord
6-132
6ellipord
Purpose Ellipt ic filt er or der select ion.
Syntax [n,Wn] = ellipord(Wp,Ws,Rp,Rs)
[n,Wn] = ellipord(Wp,Ws,Rp,Rs,'s')
Description ellipord select s t he minimum or der digit al or analog ellipt ic filt er r equir ed t o
meet a set of lowpass filt er design specificat ions:
Digital Domain
[n,Wn] = ellipord(Wp,Ws,Rp,Rs) r et ur ns t he or der n of t he lowest or der
ellipt ic filt er t hat loses no mor e t han Rp dB in t he passband and has at least
Rs dB of at t enuat ion in t he st opband. The passband r uns fr om 0 t o Wp and t he
st opband ext ends fr om Ws t o 1, t he Nyquist fr equency. ellipord also r et ur ns
Wn, t he cut off fr equency t hat allows ellip t o achieve t he given specificat ions.
Use ellipord for lowpass, highpass, bandpass, and bandst op filt er s. For
highpass filt er s, Wp is gr eat er t han Ws. For bandpass and bandst op filt er s, Wp
and Ws ar e t wo-element vect or s t hat specify t he cor ner fr equencies at bot h
edges of t he filt er , lower fr equency edge fir st . For t he band filt er s, ellipord
r et ur ns Wn as a t wo-element r ow vect or for input t o ellip.
If filt er specificat ions call for a bandpass or bandst op filt er wit h unequal r ipple
in each of t he passbands or st opbands, design t he filt er as separ at e lowpass and
highpass sect ions and cascade t he t wo filt er s t oget her .
Wp Passband cor ner fr equency. Wp, t he cut off fr equency, has a value
bet ween 0 and 1, wher e 1 cor r esponds t o half t he sampling
fr equency (t he Nyquist fr equency).
Ws St opband cor ner fr equency. Ws is in t he same unit s as Wp; it has a
value bet ween 0 and 1, wher e 1 cor r esponds t o half t he sampling
fr equency (t he Nyquist fr equency).
Rp Passband r ipple, in decibels. This value is t he maximum
per missible passband loss in decibels. The passband is 0 < w < Wp.
Rs St opband at t enuat ion, in decibels. This value is t he number of
decibels t he st opband is down fr om t he passband. The st opband
is Ws < w < 1.
ellipord
6-133
Analog Domain
[n,Wn] = ellipord(Wp,Ws,Rp,Rs,'s') finds t he minimum or der n and cut off
fr equencies Wn for an analog filt er . In t his case t he fr equencies in Wp and Ws ar e
in r adians per second and may be gr eat er t han 1.
Use ellipord for lowpass, highpass, bandpass, and bandst op filt er s as
descr ibed under Digit al Domain.
ellipord
6-134
Examples For 1000 Hz dat a, design a lowpass filt er wit h less t han 3 dB of at t enuat ion
fr om 0 t o 100 Hz and at least 15 dB of at t enuat ion fr om 150 Hz t o t he Nyquist
fr equency:
Wp = 100/500; Ws = 150/500;
Rp = 3; Rs = 15;
[n,Wn] = ellipord(Wp,Ws,Rp,Rs)
n =
2
Wn =
0.2000
[b,a] = ellip(n,Rp,Rs,Wn);
freqz(b,a,512,1000);
title('n=2 Elliptic Lowpass Filter')
0 50 100 150 200 250 300 350 400 450 500
-200
-150
-100
-50
0
50
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
Frequency (Hertz)
M
a
g
n
i
t
u
d
e

R
e
s
p
o
n
s
e

(
d
B
)
n = 2 Elliptic Lowpass Filter
ellipord
6-135
Now design a bandpass filt er wit h a passband fr om 90 Hz t o 200 Hz, less t han
3 dB of r ipple t hr oughout t he passband, and 30 dB st opbands 50 Hz out on bot h
sides of t he passband:
Wp = [90 200]/500; Ws = [50 250]/500;
Rp = 3; Rs = 30;
[n,Wn] = ellipord(Wp,Ws,Rp,Rs)
n =
3
Wn =
0.1800 0.4000
[b,a] = ellip(n,Rp,Rs,Wn);
freqz(b,a,512,1000);
title('n=3 Elliptic Bandpass Filter')
Algorithm ellipord uses t he ellipt ic lowpass filt er or der pr edict ion for mula descr ibed in
[1]. The funct ion per for ms it s calculat ions in t he analog domain for bot h t he
analog and digit al cases. For t he digit al case, it conver t s t he fr equency
0 50 100 150 200 250 300 350 400 450 500
-400
-200
0
200
400
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
Frequency (Hertz)
M
a
g
n
i
t
u
d
e

R
e
s
p
o
n
s
e

(
d
B
)
n = 3 Elliptic Bandpass Filter
ellipord
6-136
par amet er s t o t he s-domain befor e t he or der and nat ur al fr equency est imat ion
pr ocess, t hen conver t s t hem back t o t he z-domain.
ellipord init ially develops a lowpass filt er pr ot ot ype by t r ansfor ming t he
passband fr equencies of t he desir ed filt er t o 1 r ad/sec (for low- and highpass
filt er s) and t o -1 and 1 r ad/sec (for bandpass and bandst op filt er s). It t hen
comput es t he minimum or der r equir ed for a lowpass filt er t o meet t he st opband
specificat ion.
See Also
References [1] Rabiner , L.R., and B. Gold. Theory and Application of Digital S ignal
Processing. Englewood Cliffs, NJ : Pr ent ice-Hall, 1975. Pg. 241.
buttord But t er wor t h filt er or der select ion.
cheb1ord Chebyshev t ype I filt er or der select ion.
cheb2ord Chebyshev t ype II filt er or der select ion.
ellip Ellipt ic (Cauer ) filt er design.
fft
6-137
6fft
Purpose One-dimensional fast Four ier t r ansfor m.
Syntax y = fft(x)
y = fft(x,n)
Description fft comput es t he discr et e Four ier t r ansfor m of a vect or or mat r ix. This
funct ion implement s t he t r ansfor m given by
wher e W
N
= e
-j(2/N)
and N = length(x). Not e t hat t he ser ies is indexed as
n + 1 and k + 1 inst ead of t he usual n and k because MATLAB vect or s r un fr om
1 t o N inst ead of fr om 0 t o N-1.
y = fft(x) is t he discr et e Four ier t r ansfor m of vect or x, comput ed wit h a fast
Four ier t r ansfor m (FFT) algor it hm. If x is a mat r ix, y is t he FFT of each column
of t he mat r ix. The fft funct ion employs a r adix-2 fast Four ier t r ansfor m
algor it hm if t he lengt h of t he sequence is a power of t wo, and a slower
algor it hm if it is not ; see t he Algor it hm sect ion for det ails.
y = fft(x,n) is t he n-point FFT. If t he lengt h of x is less t han n, fft pads x
wit h t r ailing zer os t o lengt h n. If t he lengt h of x is gr eat er t han n, fft t r uncat es
t he sequence x. If x is an ar r ay, fft adjust s t he lengt h of t he columns in t he
same manner .
The fft funct ion is par t of t he st andar d MATLAB language.
Example A common use of t he Four ier t r ansfor m is t o find t he fr equency component s of
a t ime-domain signal bur ied in noise. Consider dat a sampled at 1000 Hz. For m
X k 1 + ( ) x n 1 + ( )W
n
k n
n 0 =
N 1

=
fft
6-138
a signal consist ing of 50 Hz and 120 Hz sinusoids and cor r upt t he signal wit h
zer o-mean r andom noise:
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))
It is difficult t o ident ify t he fr equency component s by st udying t he or iginal
signal. Conver t t o t he fr equency domain by t aking t he discr et e Four ier
t r ansfor m of t he noisy signal y using a 512-point fast Four ier t r ansfor m (FFT):
Y = fft(y,512);
The power spect r al densit y, a measur ement of t he ener gy at var ious
fr equencies, is
Pyy = Y.*conj(Y) / 512;
0 5 10 15 20 25 30 35 40 45 50
-6
-5
-4
-3
-2
-1
0
1
2
3
4
fft
6-139
Gr aph t he fir st 256 point s (t he ot her 256 point s ar e symmet r ic) on a
meaningful fr equency axis:
f = 1000*(0:255)/512;
plot(f,Pyy(1:256))
See t he pwelch funct ion for det ails on calculat ing spect r al densit y.
Somet imes it is useful t o nor malize t he out put of fft so t hat a unit sinusoid in
t he t ime domain cor r esponds t o unit amplit ude in t he fr equency domain. To
pr oduce a nor malized discr et e-t ime Four ier t r ansfor m in t his manner , use
Pn = abs(fft(x))*2/length(x)
Algorithm fft is a built -in MATLAB funct ion. When t he sequence lengt h is a power of
t wo, fft uses a high-speed r adix-2 fast Four ier t r ansfor m algor it hm. The
r adix-2 FFT r out ine is opt imized t o per for m a r eal FFT if t he input sequence is
pur ely r eal; ot her wise it comput es t he complex FFT. This causes a r eal
power -of-t wo FFT t o be about 40% fast er t han a complex FFT of t he same
lengt h.
When t he sequence lengt h is not an exact power of t wo, a separ at e algor it hm
finds t he pr ime fact or s of t he sequence lengt h and comput es t he mixed-r adix
discr et e Four ier t r ansfor ms of t he shor t er sequences.
0 100 200 300 400 500
0
10
20
30
40
50
60
70
fft
6-140
The execut ion t ime for fft depends on t he sequence lengt h. If t he lengt h of a
sequence has many pr ime fact or s, t he funct ion comput es t he FFT quickly; if
t he lengt h has few pr ime fact or s, execut ion is slower . For sequences whose
lengt hs ar e pr ime number s, fft uses t he r aw (and slow) DFT algor it hm. For
t his r eason it is usually bet t er t o use power -of-t wo FFTs, if t his is suppor t ed by
your applicat ion. For example, on one machine a 4096-point r eal FFT t akes 2.1
seconds and a complex FFT of t he same lengt h t akes 3.7 seconds. The FFTs of
neighbor ing sequences of lengt h 4095 and 4097, however , t ake 7 seconds and
58 seconds, r espect ively.
Suppose a sequence x of N point s is obt ained at a sample fr equency of . Then,
for up t o t he Nyquist fr equency, or point n =N/ 2 +1, t he r elat ionship bet ween
t he act ual fr equency and t he index k int o x (out of N possible indices) is
See Also
f
s
f k 1 ( ) f
s
N =
dct Discr et e cosine t r ansfor m (DCT).
dftmtx Discr et e Four ier t r ansfor m mat r ix.
fft2 Two-dimensional fast Four ier t r ansfor m.
fftshift Rear r ange t he out put s of fft and fft2.
filter Filt er dat a wit h a r ecur sive (IIR) or nonr ecur sive
(FIR) filt er.
freqz Fr equency r esponse of digit al filt er s.
ifft One-dimensional inver se fast Four ier t r ansfor m.
pwelch Est imat e t he power spect r al densit y (PSD) of a signal
using Welchs met hod.
fft2
6-141
6fft 2
Purpose Two-dimensional fast Four ier t r ansfor m.
Syntax Y = fft2(X)
Y = fft2(X,m,n)
Description Y = fft2(X) per for ms a t wo-dimensional FFT, pr oducing a r esult Y t he same
size as X. If X is a vect or , Y has t he same or ient at ion as X.
Y = fft2(X,m,n) t r uncat es or zer o pads X, if necessar y, t o cr eat e an m-by-n
ar r ay befor e per for ming t he FFT. The r esult Y is also m-by-n.
The fft2 funct ion is par t of t he st andar d MATLAB language.
Algorithm fft2(x) is simply
fft(fft(x).').'
This comput es t he one-dimensional fft of each column of x, t hen of each r ow
of t he r esult . The t ime r equir ed t o comput e fft2(x) depends on t he number of
pr ime fact or s in [m,n] = size(x). fft2 is fast est when m and n ar e power s of 2.
See Also
fft One-dimensional fast Four ier t r ansfor m.
fftshift Rear r ange t he out put s of fft and fft2.
ifft One-dimensional inver se fast Four ier t r ansfor m.
ifft2 Two-dimensional inver se fast Four ier t r ansfor m.
fftfilt
6-142
6fft filt
Purpose FFT-based FIR filt er ing using t he over lap-add met hod.
Syntax y = fftfilt(b,x)
y = fftfilt(b,x,n)
Description fftfilt filt er s dat a using t he efficient FFT-based met hod of overlap-add, a
fr equency domain filt er ing t echnique t hat wor ks only for FIR filt er s.
y = fftfilt(b,x) filt er s t he dat a in vect or x wit h t he filt er descr ibed by
coefficient vect or b. It r et ur ns t he dat a vect or y. The oper at ion per for med by
fftfilt is descr ibed in t he time domain by t he differ ence equat ion
An equivalent r epr esent at ion is t he z-t r ansfor m or frequency domain descr ipt ion
By default , fftfilt chooses an FFT lengt h and dat a block lengt h t hat
guar ant ee efficient execut ion t ime.
y = fftfilt(b,x,n) uses an FFT lengt h of nfft = 2^nextpow2(n) and a dat a
block lengt h of nfft length(b) + 1.
fftfilt wor ks for bot h r eal and complex input s.
Example Show t hat t he r esult s fr om fftfilt and filter ar e ident ical:
b = [1 2 3 4];
x = [1 zeros(1,99)]';
norm(fftfilt(b,x) filter(b,1,x))
ans =
9.5914e15
Algorithm fftfilt uses fft t o implement t he overlap-add method [1], a t echnique t hat
combines successive fr equency domain filt er ed blocks of an input sequence.
fftfilt br eaks an input sequence x int o lengt h L dat a blocks:
y n ( ) b 1 ( )x n ( ) b 2 ( )x n 1 ( ) L b n b 1 + ( )x n n b ( ) + + + =
Y z ( ) b 1 ( ) b 2 ( )z
1
L b n b 1 + ( )z
n b
+ + + ( )X z ( ) =
x
L 2L 3L ceil(nx/L)*L
. . .
fftfilt
6-143
and convolves each block wit h t he filt er b by
y = ifft(fft(x(i:i+L1),nfft).*fft(b,nfft));
wher e nfft is t he FFT lengt h. fftfilt over laps successive out put sect ions by
nb1 point s, wher e nb is t he lengt h of t he filt er , and sums t hem:
fftfilt chooses t he key par amet er s L and nfft in differ ent ways, depending
on whet her you supply an FFT lengt h n and on t he lengt hs of t he filt er and
signal. If you do not specify a value for n (which det er mines FFT lengt h),
fftfilt chooses t hese key par amet er s aut omat ically:
If length(x) > length(b), fftfilt chooses values t hat minimize t he
number of blocks t imes t he number of flops per FFT.
If length(b) >= length(x), fftfilt uses a single FFT of lengt h
2^nextpow2(length(b) + length(x) 1)
This essent ially comput es
y = ifft(fft(B,nfft).*fft(X,nfft))
If you supply a value for n, fftfilt chooses an FFT lengt h, nfft, of
2^nextpow2(n)and a dat a block lengt h of nfft length(b) + 1. If n is less
t han length(b), fftfilt set s n t o length(b).
See Also
References [1] Oppenheim, A.V., and R.W. Schafer . Discrete-Time S ignal Processing.
Englewood Cliffs, NJ : Pr ent ice Hall, 1989.
nb1
L
nb1 2L
nb1 3L
. . .
conv Convolut ion and polynomial mult iplicat ion.
filter Filt er dat a wit h a r ecur sive (IIR) or nonr ecur sive
(FIR) filt er.
filtfilt Zer o-phase digit al filt er ing.
fftshift
6-144
6fft shift
Purpose Rear r ange t he out put s of t he FFT funct ions.
Syntax y = fftshift(x)
Description y = fftshift(x) r ear r anges t he out put s of fft and fft2 by moving t he zer o
fr equency component t o t he cent er of t he spect r um, which is somet imes a mor e
convenient for m.
For vect or s, fftshift(x) r et ur ns a vect or wit h t he left and r ight halves
swapped.
For ar r ays, fftshift(x) swaps quadr ant s one and t hr ee wit h quadr ant s t wo
and four .
The fftshift funct ion is par t of t he st andar d MATLAB language.
Example For any ar r ay X,
Y = fft2(x)
has Y(1,1) = sum(sum(X)); t he DC component of t he signal is in t he upper -left
cor ner of t he t wo-dimensional FFT. For
Z = fftshift(Y)
t he DC component is near t he cent er of t he mat r ix.
See Also
fft One-dimensional fast Four ier t r ansfor m.
fft2 Two-dimensional fast Four ier t r ansfor m.
filter
6-145
6filt er
Purpose Filt er dat a wit h a r ecur sive (IIR) or nonr ecur sive (FIR) filt er .
Syntax y = filter(b,a,x)
[y,zf] = filter(b,a,x)
[...] = filter(b,a,x,zi)
[...] = filter(b,a,x,zi,dim)
Description filter filt er s r eal or complex dat a using a digit al filt er . The filt er r ealizat ion
is t he transposed direct form II st r uct ur e [1], which can handle bot h FIR and
IIR filt er s.
If a(1) 1, filter nor malizes t he filt er coefficient s by a(1). If a(1) = 0, t he input
is in er r or .
y = filter(b,a,x) filt er s t he dat a in vect or x wit h t he filt er descr ibed by
coefficient vect or s a and b t o cr eat e t he filt er ed dat a vect or y. When x is a
mat r ix, filt er oper at es on t he columns of x. When x is an N-dimensional ar r ay,
filt er oper at es on t he fir st non-singlet on dimension.
[y,zf] = filter(b,a,x) r et ur ns t he final values of t he st at es in t he vect or
zf.
[...] = filter(b,a,x,zi) specifies init ial st at e condit ions in t he vect or zi.
The size of t he init ial/final condit ion vect or is max(length(b),length(a))1.
zi or zf can also be an ar r ay of such vect or s, one for each column of x if x is a
mat r ix. If x is a mult idimensional ar r ay, filter wor ks acr oss t he fir st
nonsinglet on dimension of x by default .
[...] = filter(b,a,x,zi,dim) wor ks acr oss t he dimension dim of x. Set zi
t o empt y t o get t he default init ial condit ions.
The filter funct ion is par t of t he st andar d MATLAB language.
filter
6-146
Example Find and gr aph t he 100-point unit impulse r esponse of a digit al filt er :
x = [1 zeros(1,100)];
[b,a] = butter(12,400/1000);
y = filter(b,a,x);
stem(y)
Algorithm filter is implement ed as a t r ansposed dir ect for m II st r uct ur e
wher e n-1 is t he filt er or der .
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
6-147
The oper at ion of filter at sample m is given by t he t ime domain differ ence
equat ions for y and t he st at es z
i
:
You can use filtic t o gener at e t he st at e vect or z
i
(0) fr om past input s and
out put s.
The input -out put descr ipt ion of t his filt er ing oper at ion in t he z-t r ansfor m
domain is a r at ional t r ansfer funct ion:
Diagnostics If a(1) = 0, filter gives t he following er r or message:
First denominator coefficient must be nonzero.
If t he lengt h of t he init ial condit ion vect or is not t he gr eat er of na and nb,
filter gives t he following er r or message:
Initial condition vector has incorrect dimensions.
See Also
References [1] Oppenheim, A.V., and R.W. Schafer . Discrete-Time S ignal Processing.
Englewood Cliffs, NJ : Pr ent ice Hall, 1989. Pgs. 311-312.
y m ( ) b 1 ( )x m ( ) z
1
m 1 ( ) a 1 ( )y m ( ) + =
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 n b 1 + ( )z
n b
+ + +
a 1 ( ) a 2 ( )z
1
L a n a 1 + ( )z
n a
+ + +
---------------------------------------------------------------------------------------- -X z ( ) =
fftfilt FFT-based FIR filt er ing using t he over lap-add
met hod.
filter2 Two-dimensional digit al filt er ing.
filtfilt Zer o-phase digit al filt er ing.
filtic Make init ial condit ions for filter funct ion.
filter2
6-148
6filt er 2
Purpose Two-dimensional digit al filt er ing.
Syntax Y = filter2(B,X)
Y = filter2(B,X,'shape')
Description Y = filter2(B,X) filt er s t he t wo-dimensional dat a in X wit h t he
t wo-dimensional FIR filt er in t he mat r ix B. The r esult , Y, is comput ed using
t wo-dimensional convolut ion and is t he same size as X.
Y = filter2(B,X,'shape') r et ur ns Y comput ed wit h size specified by shape:
same r et ur ns t he cent r al par t of t he convolut ion t hat is t he same size as X
(default ).
full r et ur ns t he full t wo-dimensional convolut ion, size(Y) > size(X).
valid r et ur ns only t hose par t s of t he convolut ion t hat ar e comput ed wit hout
t he zer o-padded edges, size(Y) < size(X).
The filter2 funct ion is par t of t he st andar d MATLAB language.
Algorithm The filter2 funct ion uses conv2 t o comput e t he full t wo-dimensional
convolut ion of t he FIR filt er wit h t he input mat r ix. By default , filter2
ext r act s and r et ur ns t he cent r al par t of t he convolut ion t hat is t he same size as
t he input mat r ix. Use t he shape par amet er t o specify an alt er nat e par t of t he
convolut ion for r et ur n.
See Also
conv2 Two-dimensional convolut ion.
filter Filt er dat a wit h a r ecur sive (IIR) or nonr ecur sive
(FIR) filt er.
filtfilt
6-149
6filt filt
Purpose Zer o-phase digit al filt er ing.
Syntax y = filtfilt(b,a,x)
Description y = filtfilt(b,a,x) per for ms zer o-phase digit al filt er ing by pr ocessing t he
input dat a in bot h t he for war d and r ever se dir ect ions (see pr oblem 5.39 in [1]).
Aft er filt er ing in t he for war d dir ect ion, it r ever ses t he filt er ed sequence and
r uns it back t hr ough t he filt er . The r esult ing sequence has pr ecisely zer o-phase
dist or t ion and double t he filt er or der . filtfilt minimizes st ar t -up and ending
t r ansient s by mat ching init ial condit ions, and wor ks for bot h r eal and complex
input s.
Not e t hat filtfilt should not be used wit h differ ent iat or and Hilber t FIR
filt er s, since t he oper at ion of t hese filt er s depends heavily on t heir phase
r esponse.
Algorithm filtfilt is an M-file t hat uses t he filter funct ion. In addit ion t o t he
for war d-r ever se filt er ing, it at t empt s t o minimize st ar t up t r ansient s by
adjust ing init ial condit ions t o mat ch t he DC component of t he signal and by
pr epending sever al filt er lengt hs of a flipped, r eflect ed copy of t he input signal.
See Also
References [1] Oppenheim, A.V., and R.W. Schafer . Discrete-Time S ignal Processing.
Englewood Cliffs, NJ : Pr ent ice Hall, 1989. Pgs. 311-312.
fftfilt FFT-based FIR filt er ing using t he over lap-add
met hod.
filter Filt er dat a wit h a r ecur sive (IIR) or nonr ecur sive
(FIR) filt er.
filter2 Two-dimensional digit al filt er ing.
filtic
6-150
6filt ic
Purpose Find init ial condit ions for a t r ansposed dir ect for m II filt er implement at ion.
Syntax z = filtic(b,a,y,x)
z = filtic(b,a,y)
Description z = filtic(b,a,y,x) finds t he init ial condit ions z for t he delays in t he
transposed direct form II filt er implement at ion given past out put s y and input s
x. The vect or s b and a r epr esent t he numer at or and denominat or coefficient s,
r espect ively, of t he filt er s t r ansfer funct ion.
The vect or s x and y cont ain t he most r ecent input or out put fir st , and oldest
input or out put last :
wher e nb is length(b)1 (t he numer at or or der ) and na is length(a)1 (t he
denominat or or der ). If length(x) is less t han nb, filtic pads it wit h zer os t o
lengt h nb; if length(y) is less t han na, filtic pads it wit h zer os t o lengt h na.
Element s of x beyond x(nb1) and element s of y beyond y(na1) ar e
unnecessar y so filtic ignor es t hem.
Out put z is a column vect or of lengt h equal t o t he lar ger of nb and na.
z descr ibes t he st at e of t he delays given past input s x and past out put s y.
z = filtic(b,a,y) assumes t hat t he input x is 0 in t he past .
The t r ansposed dir ect for m II st r uct ur e is
wher e n-1 is t he filt er or der .
filtic wor ks for bot h r eal and complex input s.
x x 1 ( ) x 2 ( ) x 3 ( ) x n b ( ) , , , , , { } =
y y 1 ( ) y 2 ( ) y 3 ( ) y n a ( ) , , , , , { } =
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
6-151
Algorithm filtic per for ms a r ever se differ ence equat ion t o obt ain t he delay st at es z.
Diagnostics If any of t he input ar gument s y, x, b, or a is not a vect or (t hat is, if any
ar gument is a scalar or ar r ay), filtic gives t he following er r or message:
Requires vector inputs.
See Also
References [1] Oppenheim, A.V., and R.W. Schafer . Discrete-Time S ignal Processing.
Englewood Cliffs, NJ : Pr ent ice Hall, 1989. Pgs. 296, 301-302.
filter Filt er dat a wit h a r ecur sive (IIR) or nonr ecur sive
(FIR) filt er.
filtfilt Zer o-phase digit al filt er ing.
fir1
6-152
6fir 1
Purpose Window-based finit e impulse r esponse filt er design st andar d r esponse.
Syntax b = fir1(n,Wn)
b = fir1(n,Wn,'ftype')
b = fir1(n,Wn,window)
b = fir1(n,Wn,'ftype',window)
b = fir1(...,'noscale')
Description fir1 implement s t he classical met hod of windowed linear -phase FIR digit al
filt er design [1]. It designs filt er s in st andar d lowpass, bandpass, highpass, and
bandpass configur at ions. (For windowed filt er s wit h ar bit r ar y fr equency
r esponse, use fir2.)
b = fir1(n,Wn) r et ur ns r ow vect or b cont aining t he n+1 coefficient s of an
or der n lowpass FIR filt er . This is a Hamming-windowed, linear -phase filt er
wit h cut off fr equency Wn. The out put filt er coefficient s, b, ar e or der ed in
descending power s of z:
Wn, t he cut off fr equency, is a number bet ween 0 and 1, wher e 1 cor r esponds t o
half t he sampling fr equency (t he Nyquist fr equency).
If Wn is a t wo-element vect or , Wn = [w1 w2], fir1 r et ur ns a bandpass filt er wit h
passband w1 < < w2.
If Wn is a mult i-element vect or , Wn = [w1 w2 w3 w4 w5 ... wn], fir1 r et ur ns
an or der n mult iband filt er wit h bands 0 < < w1, w1 < < w2, ..., wn < < 1.
By default , t he filt er is scaled so t hat t he cent er of t he fir st passband has
magnit ude exact ly 1 aft er windowing.
b = fir1(n,Wn,'ftype') specifies a filt er t ype, wher e ftype is
high for a highpass filt er wit h cut off fr equency Wn
stop for a bandst op filt er , if Wn = [w1 w2]
The st opband is w1 < < w2.
'DC-1' t o make t he fir st band of a mult iband filt er a passband
'DC-0' t o make t he fir st band of a mult iband filt er a st opband
B z ( ) b 1 ( ) b 2 ( )z
1
L b n 1 + ( )z
n
+ + + =
fir1
6-153
fir1 always uses an even filt er or der for t he highpass and bandst op
configur at ions. This is because for odd or der s, t he fr equency r esponse at t he
Nyquist fr equency is 0, which is inappr opr iat e for highpass and bandst op
filt er s. If you specify an odd-valued n, fir1 incr ement s it by 1.
b = fir1(n,Wn,window) uses t he window specified in column vect or window
for t he design. The vect or window must be n+1 element s long. If no window is
specified, fir1 employs a Hamming window.
b = fir1(n,Wn,'ftype',window) accept s bot h ftype and window par amet er s.
b = fir1(...,'noscale') t ur ns off t he default scaling.
The gr oup delay of t he FIR filt er designed by fir1 is n/2.
Algorithm fir1 uses t he window met hod of FIR filt er design [1]. If w(n) denot es a window,
wher e 1 n N, and t he impulse r esponse of t he ideal filt er is h(n), wher e
h(n) is t he inver se Four ier t r ansfor m of t he ideal fr equency r esponse, t hen t he
windowed digit al filt er coefficient s ar e given by
b n ( ) w n ( )h n ( ) 1 n N , =
fir1
6-154
Examples Example 1
Design a 48t h-or der FIR bandpass filt er wit h passband 0.35 w 0.65:
b = fir1(48,[0.35 0.65]);
freqz(b,1,512)
Example 2
The chirp.mat file cont ains a signal, y, t hat has most of it s power above Fs/4,
or half t he Nyquist fr equency. Design a 34t h-or der FIR highpass filt er t o
at t enuat e t he component s of t he signal below Fs/4. Use a cut off fr equency of
0.48 and a Chebyshev window wit h 30 dB of r ipple:
load chirp % loads y and Fs
b = fir1(34,0.48,'high',chebwin(35,30));
yfilt = filter(b,1,y);
0 0.2 0.4 0.6 0.8 1
2500
2000
1500
1000
500
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
100
50
0
50
Normalized Angular Frequency ( rads/sample)
M
a
g
n
i
t
u
d
e

(
d
B
)
fir1
6-155
Check t he spect r a of t he or iginal and filt er ed signals.
[Py,fy] = pburg(y,10,512,Fs);
[Pyfilt,fyfilt] = pburg(yfilt,10,512,Fs);
plot(fy,10*log10(Py),':',fyfilt,10*log10(Pyfilt)); grid
ylabel('Magnitude (dB)'); xlabel('Frequency (Hz)');
legend('Chirp','Filtered Chirp')
Play t he t wo signals using sound.
sound(y,Fs);
sound(yfilt,Fs);
Diagnostics If n is odd and you specify a bandst op or highpass filt er , fir1 gives t he
following war ning message:
For highpass and bandstop filters, N must be even.
Order is being increased by 1.
0 500 1000 1500 2000 2500 3000 3500 4000 4500
140
130
120
110
100
90
80
70
60
50
40
M
a
g
n
i
t
u
d
e

(
d
B
)
Frequency (Hz)
Chirp
Filtered Chirp
fir1
6-156
See Also
References [1] IEEE. Programs for Digital S ignal Processing. IEEE Pr ess. New Yor k: J ohn
Wiley & Sons, 1979. Algor it hm 5.2.
filter Filt er dat a wit h a r ecur sive (IIR) or nonr ecur sive
(FIR) filt er.
fir2 Window-based finit e impulse r esponse filt er
designar bit r ar y r esponse.
fircls Const r ained least squar e FIR filt er design for
mult iband filt er s.
fircls1 Const r ained least squar e filt er design for lowpass
and highpass linear phase FIR filt er s.
firls Least squar e linear-phase FIR filt er design.
freqz Fr equency r esponse of digit al filt er s.
kaiserord Est imat e par amet er s for fir1 wit h Kaiser window.
remez Par ks-McClellan opt imal FIR filt er design.
fir2
6-157
6fir 2
Purpose Window-based finit e impulse r esponse filt er design ar bit r ar y r esponse.
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 designs windowed digit al FIR filt er s wit h ar bit r ar ily shaped fr equency
r esponse. (For st andar d lowpass, bandpass, highpass, and bandst op
configur at ions, use fir1.)
b = fir2(n,f,m) r et ur ns r ow vect or b cont aining t he n+1 coefficient s of an
or der n FIR filt er . The fr equency-magnit ude char act er ist ics of t his filt er mat ch
t hose given by vect or s f and m:
f is a vect or of fr equency point s in t he r ange fr om 0 t o 1, wher e 1 cor r esponds
t o half t he sampling fr equency (t he Nyquist fr equency). The fir st point of f
must be 0 and t he last point 1. The fr equency point s must be in incr easing
or der .
m is a vect or cont aining t he desir ed magnit ude r esponse at t he point s
specified in f.
f and m must be t he same lengt h.
Duplicat e fr equency point s ar e allowed, cor r esponding t o st eps in t he
fr equency r esponse.
Use plot(f,m) t o view t he filt er shape.
The out put filt er coefficient s, b, ar e or der ed in descending power s of z:
b = fir2(n,f,m,window) uses t he window specified in column vect or window
for t he filt er design. The vect or window must be n+1 element s long. If no window
is specified, fir2 employs a Hamming window.
b z ( ) b 1 ( ) b 2 ( )z
1
L b n 1 + ( )z
n
+ + + =
fir2
6-158
b = fir2(n,f,m,npt) and
b = fir2(n,f,m,npt, window) specify t he number of point s npt for t he gr id
ont o which fir2 int er polat es t he fr equency r esponse, wit h or wit hout a window
specificat ion.
b = fir2(n,f,m,npt,lap) and
b = fir2(n,f,m,npt,lap,window) specify t he size of t he r egion, lap, t hat
fir2 inser t s ar ound duplicat e fr equency point s, wit h or wit hout a window
specificat ion.
See t he Algor it hm sect ion for mor e on npt and lap.
Algorithm The desir ed fr equency r esponse is int er polat ed ont o a dense, evenly spaced gr id
of lengt h npt. npt is 512 by default . If t wo successive values of f ar e t he same,
a r egion of lap point s is set up ar ound t his fr equency t o pr ovide a smoot h but
st eep t r ansit ion in t he r equest ed fr equency r esponse. By default , lap is 25. The
filt er coefficient s ar e obt ained by applying an inver se fast Four ier t r ansfor m t o
t he gr id and mult iplying by a window; by default , t his is a Hamming window.
fir2
6-159
Example Design a 30t h-or der lowpass filt er and over plot t he desir ed fr equency r esponse
wit h t he act ual fr equency r esponse:
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))
See Also
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
butter But t er wor t h analog and digit al filt er design.
cheby1 Chebyshev t ype I filt er design (passband r ipple).
cheby2 Chebyshev t ype II filt er design (st opband r ipple).
ellip Ellipt ic (Cauer ) filt er design.
fir1 Window-based finit e impulse r esponse filt er design
st andar d r esponse.
maxflat Gener alized digit al But t er wor t h filt er design.
remez Par ks-McClellan opt imal FIR filt er design.
yulewalk Recur sive digit al filt er design.
fircls
6-160
6fir cls
Purpose Const r ained least squar e FIR filt er design for mult iband filt er s.
Syntax b = fircls(n,f,amp,up,lo)
fircls(n,f,amp,up,lo,'design_flag')
Description b = fircls(n,f,amp,up,lo) gener at es a lengt h n+1 linear phase FIR filt er b.
The fr equency-magnit ude char act er ist ics of t his filt er mat ch t hose given by
vect or s f and amp:
f is a vect or of t r ansit ion fr equencies in t he r ange fr om 0 t o 1, wher e 1
cor r esponds t o half t he sampling fr equency (t he Nyquist fr equency). The fir st
point of f must be 0 and t he last point 1. The fr equency point s must be in
incr easing or der .
amp is a vect or descr ibing t he piecewise const ant desir ed amplit ude of t he
fr equency r esponse. The lengt h of amp is equal t o t he number of bands in t he
r esponse and should be equal t o length(f)1.
up and lo ar e vect or s wit h t he same lengt h as amp. They define t he upper and
lower bounds for t he fr equency r esponse in each band.
fircls(n,f,amp,up,lo,'design_flag') enables you t o monit or t he filt er
design, wher e design_flag can be:
trace, for a t ext ual display of t he design er r or at each it er at ion st ep.
plots, for a collect ion of plot s showing t he filt er s full-band magnit ude
r esponse and a zoomed view of t he magnit ude r esponse in each sub-band. All
plot s ar e updat ed at each it er at ion st ep.
both, for bot h t he t ext ual display and plot s.
fircls
6-161
Example Design an or der 50 bandpass filt er :
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'); % plots magnitude response
NOTE Nor mally, t he lower value in t he st opband will be specified as
negat ive. By set t ing lo equal t o 0 in t he st opbands, a nonnegat ive fr equency
r esponse amplit ude can be obt ained. Such filt er s can be spect r ally fact or ed t o
obt ain minimum phase filt er s.
Algorithm The algor it hm is a mult iple exchange algor it hm t hat uses Lagr ange
mult iplier s and Kuhn-Tucker condit ions on each it er at ion.
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
6-162
See Also
References [1] Selesnick, I.W., M. Lang, and C.S. Bur r us. Const r ained Least Squar e
Design of FIR Filt er s wit hout Specified Tr ansit ion Bands. Proceedings of the
IEEE Int. Conf. Acoust., S peech, S ignal Processing. Vol. 2 (May 1995).
Pgs. 1260-1263.
[2] Selesnick, I.W., M. Lang, and C.S. Bur r us. Const r ained Least Squar e
Design of FIR Filt er s wit hout Specified Tr ansit ion Bands. IEEE Transactions
on S ignal Processing, Vol. 44, No. 8 (August 1996).
fircls1 Const r ained least squar e filt er design for lowpass
and highpass linear phase FIR filt er s.
firls Least squar e linear-phase FIR filt er design.
remez Par ks-McClellan opt imal FIR filt er design.
fircls1
6-163
6fir cls1
Purpose Const r ained least squar e filt er design for lowpass and highpass linear phase
FIR filt er s.
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) gener at es a lowpass FIR filt er b. n+1 is t he filt er
lengt h, wo is t he nor malized cut off fr equency in t he r ange bet ween 0 and 1
(wher e 1 cor r esponds t o half t he sampling fr equency, t hat is, t he Nyquist
fr equency), dp is t he maximum passband deviat ion fr om 1 (passband r ipple),
and ds is t he maximum st opband deviat ion fr om 0 (st opband r ipple).
b = fircls1(n,wo,dp,ds,'high') gener at es a highpass FIR filt er b.
b = fircls1(n,wo,dp,ds,wt) and
b = fircls1(n,wo,dp,ds,wt,'high') specify a fr equency wt above which (for
wt>wo) or below which (for wt<wo) t he filt er is guar ant eed t o meet t he given
band cr it er ion. This will help you design a filt er t hat meet s a passband or
st opband edge r equir ement . Ther e ar e four cases:
Lowpass:
- 0<wt<wo<1: t he amplit ude of t he filt er is wit hin dp of 1 over t he fr equency
r ange 0 < < wt.
- 0<wo<wt<1: t he amplit ude of t he filt er is wit hin ds of 0 over t he fr equency
r ange wt < < 1.
Highpass:
- 0<wt<wo<1: t he amplit ude of t he filt er is wit hin ds of 0 over t he fr equency
r ange 0 < < wt.
- 0<wo<wt<1: t he amplit ude of t he filt er is wit hin dp of 1 over t he fr equency
r ange wt < < 1.

fircls1
6-164
b = fircls1(n,wo,dp,ds,wp,ws,k) gener at es a lowpass FIR filt er b wit h a
weight ed funct ion. n+1 is t he filt er lengt h, wo is t he nor malized cut off fr equency,
dp is t he maximum passband deviat ion from 1 (passband r ipple), and ds is t he
maximum st opband deviat ion from 0 (st opband r ipple). wp is t he passband edge
of t he L2 weight funct ion and ws is t he st opband edge of t he L2 weight funct ion,
wher e wp < wo < ws. k is t he r at io (passband L2 er r or )/(st opband L2 er r or ):
b = fircls1(n,wo,dp,ds,wp,ws,k,'high') gener at es a highpass FIR filt er b
wit h a weight ed funct ion, wher e ws < wo < wp.
b = fircls1(n,wo,dp,ds,,'design_flag') enables you t o monit or t he filt er
design, wher e design_flag can be
trace, for a t ext ual display of t he design t able used in t he design
plots, for plot s of t he filt er s magnit ude, gr oup delay, and zer os and poles
both, for bot h t he t ext ual display and plot s
NOTE In t he design of ver y nar r ow band filt er s wit h small dp and ds, t her e
may not exist a filt er of t he given lengt h t hat meet s t he specificat ions.
A ( ) D ( )
2
d
0
w
p

A ( ) D ( )
2
d
w
s

------------------------------------------------------ k =
fircls1
6-165
Example Design an or der 55 lowpass filt er wit h a cut off fr equency 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 algor it hm is a mult iple exchange algor it hm t hat uses Lagr ange
mult iplier s and Kuhn-Tucker condit ions on each it er at ion.
See Also
References [1] Selesnick, I.W., M. Lang, and C.S. Bur r us. Const r ained Least Squar e
Design of FIR Filt er s wit hout Specified Tr ansit ion Bands. Proceedings of the
IEEE Int . Conf. Acoust., S peech, S ignal Processing. Vol. 2 (May 1995).
Pgs. 1260-1263.
[2] Selesnick, I.W., M. Lang, and C.S. Bur r us. Const r ained Least Squar e
Design of FIR Filt er s wit hout Specified Tr ansit ion Bands. IEEE Transactions
on S ignal 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
fircls Const r ained least squar e FIR filt er design for
mult iband filt er s.
firls Least squar e linear-phase FIR filt er design.
remez Par ks-McClellan opt imal FIR filt er design.
firls
6-166
6fir ls
Purpose Least squar e linear -phase FIR filt er design.
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 designs a linear -phase FIR filt er t hat minimizes t he weight ed,
int egr at ed squar ed er r or bet ween an ideal piecewise linear funct ion and t he
magnit ude r esponse of t he filt er over a set of desir ed fr equency bands.
b = firls(n,f,a) r et ur ns r ow vect or b cont aining t he n+1 coefficient s of t he
or der n FIR filt er whose fr equency-amplit ude char act er ist ics appr oximat ely
mat ch t hose given by vect or s f and a. The out put filt er coefficient s, or t aps,
in b obey t he symmet r y r elat ion
These ar e t ype I (n odd) and t ype II (n even) linear -phase filt er s. Vect or s f and
a specify t he fr equency-amplit ude char act er ist ics of t he filt er :
f is a vect or of pair s of fr equency point s, specified in t he r ange bet ween 0 and
1, wher e 1 cor r esponds t o half t he sampling fr equency (t he Nyquist
fr equency). The fr equencies must be in incr easing or der . Duplicat e fr equency
point s ar e allowed and, in fact , can be used t o design a filt er exact ly t he same
as t hose r et ur ned by t he fir1 and fir2 funct ions wit h a r ect angular or
boxcar window.
a is a vect or cont aining t he desir ed amplit ude at t he point s specified in f.
The desir ed amplit ude funct ion at fr equencies bet ween pair s of point s (f(k),
f(k+1)) for k odd is t he line segment connect ing t he point s (f(k), a(k)) and
(f(k+1), a(k+1)).
The desir ed amplit ude funct ion at fr equencies bet ween pair s of point s (f(k),
f(k+1)) for k even is unspecified. These ar e t r ansit ion or dont car e r egions.
f and a ar e t he same lengt h. This lengt h must be an even number .
b k ( ) b n 2 k + ( ) k 1 = n 1 + , , , =
firls
6-167
The r elat ionship bet ween t he f and a vect or s in defining a desir ed amplit ude
r esponse is
b = firls(n,f,a,w) uses t he weight s in vect or w t o weight t he fit in each
fr equency band. The lengt h of w is half t he lengt h of f and a, so t her e is exact ly
one weight per band.
b = firls(n,f,a,'ftype') and
b = firls(n,f,a,w,'ftype') specify a filt er t ype, wher e ftype is
hilbert for linear -phase filt er s wit h odd symmet r y (t ype III and t ype IV)
The out put coefficient s in b obey t he r elat ion b(k) = -b(n + 2 - k),
k = 1, ..., n + 1. This class of filt er s includes t he Hilber t t r ansfor mer , which
has a desir ed amplit ude of 1 acr oss t he ent ir e band.
differentiator for t ype III and t ype IV filt er s, using a special weight ing
t echnique
For nonzer o amplit ude bands, t he int egr at ed squar ed er r or has a weight of
(1/f)
2
so t hat t he er r or at low fr equencies is much smaller t han at high
fr equencies. For FIR differ ent iat or s, which have an amplit ude char act er ist ic
pr opor t ional t o fr equency, t he filt er s minimize t he r elat ive int egr at ed
squar ed er r or (t he int egr al of t he squar e of t he r at io of t he er r or t o t he
desir ed amplit ude).
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
6-168
Examples Design an or der 255 lowpass filt er wit h t r ansit ion band:
b = firls(255,[0 0.25 0.3 1],[1 1 0 0]);
Design a 31 coefficient differ ent iat or :
b = firls(30,[0 0.9],[0 0.9],'differentiator');
Design a 24t h-or der ant i-symmet r ic filt er wit h piecewise linear passbands and
plot t he desir ed and act ual fr equency r esponse:
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
Algorithm Refer ence [1] descr ibes t he t heor et ical appr oach t hat firls t akes. The funct ion
solves a syst em of linear equat ions involving an inner pr oduct mat r ix of size
r oughly n/2 using MATLABs \ oper at or .
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
firls
6-169
This funct ion designs t ype I, II, III, and IV linear -phase filt er s. Type I and II
ar e t he default s for n even and odd r espect ively, while t he 'hilbert' and
'differentiator' flags pr oduce t ype III (n even) and IV (n odd) filt er s. The
var ious filt er t ypes have differ ent symmet r ies and const r aint s on t heir
fr equency r esponses (see [2] for det ails).
Diagnostics An appr opr iat e diagnost ic message is displayed when incor r ect ar gument s ar e
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 mor e ser ious war ning message is
Warning: Matrix is close to singular or badly scaled.
This t ends t o happen when t he filt er lengt h t imes t he t r ansit ion widt h gr ows
lar ge. In t his case, t he filt er coefficient s b might not r epr esent t he desir ed filt er .
You can check t he filt er by looking at it s fr equency r esponse.
Linear
Phase
Filter Type
Filter
Order n Symmetry of Coefficients
Response H(f),
f = 0
Response H(f),
f = 1 (Nyquist)
Type I Even even: No r est r ict ion No r est r ict ion
Type II Odd No r est r ict ion H(1) = 0
Type III Even odd: H(0) = 0 H(1) = 0
Type IV Odd H(0) = 0 No r est r ict ion
b k ( ) b n 2 k + ( ) k 1 = n 1 + , , , =
b k ( ) b n 2 k + ( ) k 1 = n 1 + , , , =
firls
6-170
See Also
References [1] Par ks, T.W., and C.S. Bur r us. Digital Filter Design. New Yor k: J ohn Wiley
& Sons, 1987. Pgs. 54-83.
[2] Oppenheim, A.V., and R.W. Schafer . Discrete-Time S ignal Processing.
Englewood Cliffs, NJ : Pr ent ice Hall, 1989. Pgs. 256-266.
fir1 Window-based finit e impulse r esponse filt er design
st andar d r esponse.
fir2 Window-based finit e impulse r esponse filt er design
ar bit r ar y r esponse.
firrcos Raised cosine FIR filt er design.
remez Par ks-McClellan opt imal FIR filt er design.
firrcos
6-171
6fir r cos
Purpose Raised cosine FIR filt er design.
b = firrcos(n,F0,df,Fs)
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 firrcos(n,F0,df,Fs) r et ur ns an or der n lowpass linear -phase FIR filt er wit h
a r aised cosine t r ansit ion band. The filt er has cut off fr equency F0, t r ansit ion
bandwidt h df, and sampling fr equency Fs, all in Her t z. df must be small
enough so t hat F0 t df/2 is bet ween 0 and Fs/2. The coefficient s in b ar e
nor malized so t hat t he nominal passband gain is always equal t o one.
firrcos(n,F0,df) uses a default sampling fr equency of Fs = 2.
b = firrcos(n,F0,r,Fs,'rolloff') int er pr et s t he t hir d ar gument , r, as t he
r olloff fact or inst ead of t he t r ansit ion bandwidt h, df. r must be in t he r ange
[0,1].
b = firrcos(...,'type') designs eit her a nor mal r aised cosine filt er or a
squar e r oot r aised cosine filt er depending on t he type specificat ion, which can
be
normal, for a r egular r aised cosine filt er . This is t he default , and is also in
effect when t he 'type' ar gument is left empt y, [].
sqrt, for a squar e r oot r aised cosine filt er .
b = firrcos(...,'type',delay) specifies an int eger delay in t he r ange
[0,n+1]. The default is n/2 for even n and (n+1)/2 for odd n.
b = firrcos(...,'type',delay,window) applies a lengt h n+1 window t o t he
designed filt er t o r educe t he r ipple in t he fr equency r esponse. window must be
a n+1 long column vect or . If no window is specified, a boxcar (r ect angular )
window is used. Car e must be exer cised when using a window wit h a delay
ot her t han t he default .
[b,a] = firrcos(...) always r et ur ns a = 1.
firrcos
6-172
Example Design an or der 20 r aised cosine FIR filt er wit h cut off fr equency 0.25 of t he
Nyquist fr equency and a t r ansit ion bandwidt h of 0.25:
h = firrcos(20,0.25,0.25);
freqz(h,1,'Fs',2,'phase','no')
See Also
0 0.2 0.4 0.6 0.8 1
120
100
80
60
40
20
0
20
Frequency (Hz)
M
a
g
n
i
t
u
d
e

(
d
B
)
fir1 Window-based finit e impulse r esponse filt er design
st andar d r esponse.
fir2 Window-based finit e impulse r esponse filt er design
ar bit r ar y r esponse.
firls Least squar e linear-phase FIR filt er design.
remez Par ks-McClellan opt imal FIR filt er design.
freqs
6-173
6freqs
Purpose Fr equency r esponse of analog filt er s.
Syntax h = freqs(b,a,w)
[h,w] = freqs(b,a)
[h,w] = freqs(b,a,n)
freqs(b,a)
Description freqs r et ur ns t he complex fr equency r esponse H(jw) (Laplace t r ansfor m) of an
analog filt er :
given t he numer at or and denominat or coefficient s in vect or s b and a.
h = freqs(b,a,w) r et ur ns t he complex fr equency r esponse of t he analog filt er
specified by coefficient vect or s b and a. freqs evaluat es t he fr equency r esponse
along t he imaginar y axis in t he complex plane at t he fr equencies specified in
r eal vect or w.
[h,w] = freqs(b,a) aut omat ically picks a set of 200 fr equency point s w on
which t o comput e t he fr equency r esponse h.
[h,w] = freqs(b,a,n) picks n fr equencies on which t o comput e t he fr equency
r esponse h.
freqs wit h no out put ar gument s plot s t he magnit ude and phase r esponse
ver sus fr equency in t he cur r ent figur e window.
freqs wor ks only for r eal input syst ems and posit ive fr equencies.
H s ( )
B s ( )
A s ( )
---------- -
b 1 ( )s
n b
b 2 ( )s
n b 1
L b n b 1 + ( ) + + +
a 1 ( )s
n a
a 2 ( )s
n a 1
L a n a 1 + ( ) + + +
---------------------------------------------------------------------------------------------- = =
freqs
6-174
Example Find and gr aph t he fr equency r esponse of t he t r ansfer funct ion given by
a = [1 0.4 1];
b = [0.2 0.3 1];
w = logspace(1,1);
freqs(b,a,w)
You can also cr eat e t he plot wit h
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 conver t t o Her t z, degr ees, and decibels, use
f = w/(2*pi);
mag = 20*log10(mag);
phase = phase*180/pi;
H s ( )
0.2s
2
0.3s 1 + +
s
2
0.4s 1 + +
----------------------------------------- =
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
)
freqs
6-175
Algorithm freqs evaluat es t he polynomials at each fr equency point , t hen divides t he
numer at or r esponse by t he denominat or r esponse:
s = i*w;
h = polyval(b,s)./polyval(a,s);
See Also
abs Absolut e value (magnit ude).
angle Phase angle.
freqz Fr equency r esponse of digit al filt er s.
invfreqs Cont inuous-t ime (analog) filt er ident ificat ion fr om
fr equency dat a.
logspace Gener at e logar it hmically spaced vect or s (see t he
online MATLAB Function Reference).
polyval Polynomial evaluat ion (see t he online MATLAB
Function Reference).
freqspace
6-176
6fr eqspace
Purpose Fr equency spacing for fr equency r esponse.
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 r et ur ns t he implied fr equency r ange for equally spaced fr equency
r esponses. This is useful when cr eat ing fr equency vect or s for use wit h freqz.
f = freqspace(n) r et ur ns t he fr equency vect or f assuming n evenly spaced
point s ar ound t he unit cir cle. For n even or odd, f is (0:2/n:1). For n even,
freqspace r et ur ns (n + 2)/2 point s. For N odd, it r et ur ns (n + 1)/2 point s.
f = freqspace(n,'whole') r et ur ns n evenly spaced point s ar ound t he whole
unit cir cle. In t his case, f is 0:2/n:2*(n1)/n.
[f1,f2] = freqspace(n) r et ur ns t he t wo-dimensional fr equency vect or s f1
and f2 for an n-by-n mat r ix. For n odd, bot h f1 and f2 ar e [1 + 1/n:2/n:1
1/n]. For n even, bot h f1 and f2 ar e [1:2/n:12/n].
[f1,f2] = freqspace([m n]) r et ur ns t he t wo-dimensional fr equency vect or s
f1 and f2 for an m-by-n mat r ix.
[x1,y1] = freqspace(n,'meshgrid') and
[x1,y1] = freqspace([m n],'meshgrid') ar e equivalent t o
[f1,f2] = freqspace(...);
[x1,y1] = meshgrid(f1,f2);
See t he online MATLAB Function Reference for det ails on t he meshgrid
funct ion.
See Also
freqz Fr equency r esponse of digit al filt er s.
invfreqz Discr et e-t ime filt er ident ificat ion fr om fr equency
dat a.
freqz
6-177
6freqz
Purpose Fr equency r esponse of digit al filt er s.
Syntax [h,w] = freqz(b,a,n)
[h,f] = freqz(b,a,n,Fs)
[h,w] = freqz(b,a,n,'whole')
[h,f] = freqz(b,a,n,'whole',Fs)
h = freqz(b,a,w)
h = freqz(b,a,f,Fs)
freqz(...)
Description freqz r et ur ns t he complex fr equency r esponse H(e
j
) of a digit al filt er , given
t he (r eal or complex) numer at or and denominat or coefficient s in vect or s b
and a.
[h,w] = freqz(b,a,n) r et ur ns t he n-point complex fr equency r esponse of t he
digit al filt er
evaluat ed at z=e
j
given t he coefficient vect or s b and a. freqz r et ur ns bot h h,
t he complex fr equency r esponse, and w, a vect or cont aining t he n fr equency
point s in unit s of r ads/sample. freqz evaluat es t he fr equency r esponse at n
point s equally spaced ar ound t he upper half of t he unit cir cle, so w cont ains n
point s bet ween 0 and .
It is best , alt hough not necessar y, t o choose a value for n t hat is an exact power
of t wo, because t his allows fast comput at ion using an FFT algor it hm. If you do
not specify a value for n, it default s t o 512.
[h,f] = freqz(b,a,n,Fs) specifies a posit ive sampling fr equency Fs, in
Her t z. The default for Fs is 1. It r et ur ns a vect or f cont aining t he act ual
fr equency point s bet ween 0 and Fs/2 (t he Nyquist fr equency) at which it
calculat ed t he fr equency r esponse. f is of lengt h n.
[h,w] = freqz(b,a,n,'whole') uses n point s ar ound t he whole unit cir cle, so
w has r ange [0,2).
[h,f] = freqz(b,a,n,'whole',Fs) uses n point s ar ound t he whole unit
cir cle, so f has r ange [0,Fs).
H z ( )
B z ( )
A z ( )
-----------
b 1 ( ) b 2 ( )z
1
L b n b 1 + ( )z
n b
+ + +
a 1 ( ) a 2 ( )z
1
L a n a 1 + ( )z
n a
+ + +
----------------------------------------------------------------------------------------- = =
freqz
6-178
h = freqz(b,a,w) r et ur ns t he fr equency r esponse at t he fr equencies in vect or
w (specified in r ads/sample).
h = freqz(b,a,f,Fs) r et ur ns t he fr equency r esponse at t he fr equencies in
vect or f (specified in Hz).
freqz(...) wit h no out put ar gument s plot s t he magnit ude and phase
r esponse ver sus fr equency in t he cur r ent figur e window.
Examples Plot t he magnit ude and phase r esponse of an FIR filt er .
b = fir1(80,0.5,kaiser(81,8));
freqz(b,1);
Algorithm freqz uses an FFT algor it hm when ar gument n is pr esent . It comput es t he
fr equency r esponse as t he r at io of t he t r ansfor med numer at or and denominat or
coefficient s, padded wit h zer os t o t he desir ed lengt h:
h = fft(b,n)./fft(a,n)
If n is not a power of t wo, t he FFT algor it hm is not as efficient and may cause
long comput at ion t imes.
When a fr equency vect or w or f is pr esent , or if n is less t han
max(length(b),length(a)), freqz evaluat es t he polynomials at each
fr equency point using Hor ner s met hod of polynomial evaluat ion and t hen
divides t he numer at or r esponse by t he denominat or r esponse.
0 0.2 0.4 0.6 0.8 1
5000
4000
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
150
100
50
0
50
Normalized Angular Frequency ( rads/sample)
M
a
g
n
i
t
u
d
e

(
d
B
)
freqz
6-179
See Also
abs Absolut e value (magnit ude).
angle Phase angle.
fft One-dimensional fast Four ier t r ansfor m.
filter Filt er dat a wit h a r ecur sive (IIR) or nonr ecur sive
(FIR) filt er.
freqs Fr equency r esponse of analog filt er s.
impz Impulse r esponse of digit al filt er s.
invfreqz Discr et e-t ime filt er ident ificat ion fr om fr equency
dat a.
logspace Gener at e logar it hmically spaced vect or s (see t he
online MATLAB Function Reference).
gauspuls
6-180
6gauspuls
Purpose Gaussian-modulat ed sinusoidal pulse gener at or .
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 gener at es Gaussian-modulat ed sinusoidal pulses.
yi = gauspuls(t,fc,bw) r et ur ns a unit y-amplit ude Gaussian RF pulse at t he
t imes indicat ed in ar r ay t, wit h a cent er fr equency fc in Her t z and a fr act ional
bandwidt h bw, which must be gr eat er t han 0. The default value for fc is
1000 Hz and for bw is 0.5.
yi = gauspuls(t,fc,bw,bwr) r et ur ns a unit y-amplit ude Gaussian RF pulse
wit h a fr act ional bandwidt h of bw as measur ed at a level of bwr dB wit h r espect
t o t he nor malized signal peak. The fr act ional bandwidt h r efer ence level bwr
must be less t han 0, because it indicat es a r efer ence level less t han t he peak
(unit y) envelope amplit ude. The default value for bwr is -6 dB.
[yi,yq] = gauspuls() r et ur ns bot h t he in-phase and quadr at ur e pulses.
[yi,yq,ye] = gauspuls() r et ur ns t he RF signal envelope.
tc = gauspuls('cutoff',fc,bw,bwr,tpe) r et ur ns t he cut off t ime tc (gr eat er
t han or equal t o 0) at which t he t r ailing pulse envelope falls below tpe dB wit h
r espect t o t he peak envelope amplit ude. The t r ailing pulse envelope level tpe
must be less t han 0, because it indicat es a r efer ence level less t han t he peak
(unit y) envelope amplit ude. The default value for tpe is -60 dB.
Remarks Default values ar e subst it ut ed for empt y or omit t ed t r ailing input ar gument s.
gauspuls
6-181
Example Plot a 50 kHz Gaussian RF pulse wit h 60% bandwidt h, sampled at a r at e of
1 MHz. Tr uncat e t he pulse wher e t he envelope falls 40 dB below t he peak:
tc = gauspuls('cutoff',50e3,0.6,[],40);
t = tc : 1e6 : tc;
yi = gauspuls(t,50e3,0.6);
plot(t,yi)
See Also
-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
chirp Swept -fr equency cosine gener at or.
cos Cosine of vect or /mat r ix element s (see t he online
MATLAB Function Reference).
diric Dir ichlet or per iodic sinc funct ion.
pulstran Pulse t r ain gener at or.
rectpuls Sampled aper iodic r ect angle gener at or.
sawtooth Sawt oot h or t r iangle wave gener at or.
sin Sine of vect or /mat r ix element s (see t he online
MATLAB Function Reference).
sinc Sinc or sin(t )/t funct ion.
square Squar e wave gener at or.
tripuls Sampled aper iodic t r iangle gener at or.
grpdelay
6-182
6grpdelay
Purpose Aver age filt er delay (gr oup delay).
Syntax [gd,w] = grpdelay(b,a,n)
[gd,f] = grpdelay(b,a,n,Fs)
[gd,w] = grpdelay(b,a,n,'whole')
[gd,f] = grpdelay(b,a,n,'whole',Fs)
gd = grpdelay(b,a,w)
gd = grpdelay(b,a,f,Fs)
grpdelay(b,a)
Description The group delay of a filt er is a measur e of t he aver age delay of t he filt er as a
funct ion of fr equency. It is t he negat ive fir st der ivat ive of t he phase r esponse
of t he filt er . If t he complex fr equency r esponse of a filt er is H(e
j
), t hen t he
gr oup delay is
wher e is fr equency and is t he phase angle of H(e
j
).
[gd,w] = grpdelay(b,a,n) r et ur ns t he n-point gr oup delay, , of t he
digit al filt er
given t he numer at or and denominat or coefficient s in vect or s b and a. grpdelay
r et ur ns bot h gd, t he gr oup delay, and w, a vect or cont aining t he n fr equency
point s in r adians. grpdelay evaluat es t he gr oup delay at n point s equally
spaced ar ound t he upper half of t he unit cir cle, so w cont ains n point s bet ween
0 and . A value for n t hat is an exact power of t wo allows fast comput at ion
using an FFT algor it hm.
[gd,f] = grpdelay(b,a,n,Fs) specifies a posit ive sampling fr equency Fs in
Her t z. It r et ur ns a lengt h n vect or f cont aining t he act ual fr equency point s at
which t he gr oup delay is calculat ed, also in Her t z. f cont ains n point s bet ween
0 and Fs/2.

g
( )
d ( )
d
--------------- =

g
( )
H z ( )
B z ( )
A z ( )
-----------
b 1 ( ) b 2 ( )z
1
L b n b 1 + ( )z
n b
+ + +
a 1 ( ) a 2 ( )z
1
L a n a 1 + ( )z
n a
+ + +
----------------------------------------------------------------------------------------- = =
grpdelay
6-183
[gd,w] = grpdelay(b,a,n,'whole') and
[gd,f] = grpdelay(b,a,n,'whole',Fs) use n point s ar ound t he whole unit
cir cle (fr om 0 t o 2, or fr om 0 t o Fs).
gd = grpdelay(b,a,w) and
gd = grpdelay(b,a,f,Fs) r et ur n t he gr oup delay evaluat ed at t he point s in w
(in r adians) or f (in Her t z), r espect ively, wher e Fs is t he sampling fr equency in
Her t z.
grpdelay wit h no out put ar gument s plot s t he gr oup delay ver sus fr equency in
t he cur r ent figur e window.
grpdelay wor ks for bot h r eal and complex input syst ems.
Examples Plot t he gr oup delay of But t er wor t h filt er b(z)/a(z):
[b,a] = butter(6,0.2);
grpdelay(b,a,128)
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
0
2
4
6
8
10
12
Normalized frequency (Nyquist == 1)
G
r
o
u
p

d
e
l
a
y

(
i
n

s
a
m
p
l
e
s
)
grpdelay
6-184
Plot bot h t he gr oup and phase delays of a syst em on t he same gr aph:
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 (rads/sec)'); grid;
legend('Group Delay','Phase Delay');
Algorithm grpdelay mult iplies t he filt er coefficient s by a unit r amp. Aft er Four ier
t r ansfor mat ion, t his pr ocess cor r esponds t o differ ent iat ion.
See Also
0 0.5 1 1.5 2 2.5 3 3.5
8
6
4
2
0
2
4
6
8
10
12
Frequency (rads/sec)
Group Delay
Phase Delay
cceps Complex cepst r al analysis.
fft One-dimensional fast Four ier t r ansfor m.
freqz Fr equency r esponse of digit al filt er s.
hilbert Hilber t t r ansfor m.
icceps Inver se complex cepst r um.
rceps Real cepst r um and minimum phase r econst r uct ion.
hamming
6-185
6hamming
Purpose Hamming window.
Syntax w = hamming(n)
w = hamming(n,sflag)
Description w = hamming(n) r et ur ns an n-point symmet r ically sampled Hamming window
in t he column vect or w. n should be a nonnegat ive int eger . The coefficient s of a
Hamming window ar e
w = hamming(n,sflag) r et ur ns an n-point Hamming window using t he
window sampling specified by sflag, which can be eit her 'periodic' or
'symmetric' (t he default ). When 'periodic' is specified, hamming comput es a
lengt h n+1 window and r et ur ns t he fir st n point s.
Diagnostics An er r or message is displayed when incor r ect ar gument s ar e used:
Order cannot be less than zero.
Sampling must be either 'symmetric' or 'periodic'.
A war ning message is displayed for nonint eger n:
Warning: Rounding order to nearest integer.
See Also
References [1] Oppenheim, A.V., and R.W. Schafer , Discrete-Time S ignal Processing.
Englewood Cliffs, NJ : Pr ent ice-Hall, 1989.
w k 1 + [ ] 0.54 0.46 2
k
n 1
------------ -
,
_
cos k 0 = n 1 , , , =
bartlett Bar t let t window.
blackman Blackman window.
boxcar Rect angular window.
chebwin Chebyshev window.
hanning Hanning window.
kaiser Kaiser window.
triang Tr iangular window.
hanning
6-186
6hanning
Purpose Hanning window.
Syntax w = hanning(n)
w = hanning(n,sflag)
Description w = hanning(n) r et ur ns an n-point symmet r ically sampled Hanning window
in t he column vect or w. n should be a nonnegat ive int eger . The coefficient s of a
Hanning window ar e
w = hanning(n,sflag) r et ur ns an n-point Hanning window using t he window
sampling specified by sflag, which can be eit her 'periodic' or 'symmetric'
(t he default ). When 'periodic' is specified, hanning comput es a lengt h n+1
window and r et ur ns t he fir st n point s.
Diagnostics An er r or message is displayed when incor r ect ar gument s ar e used:
Order cannot be less than zero.
Sampling must be either 'symmetric' or 'periodic'.
A war ning message is displayed for nonint eger n:
Warning: Rounding order to nearest integer.
See Also
References [1] Oppenheim, A.V., and R.W. Schafer , Discrete-Time S ignal Processing.
Englewood Cliffs, NJ : Pr ent ice-Hall, 1989.
w k [ ] 0.5 1 2
k
n 1 +
-------------
,
_
cos
,
_
k 1 = n , , , =
bartlett Bar t let t window.
blackman Blackman window.
boxcar Rect angular window.
chebwin Chebyshev window.
hamming Hamming window.
kaiser Kaiser window.
triang Tr iangular window.
hilbert
6-187
6hilber t
Purpose Hilber t t r ansfor m.
Syntax y = hilbert(x)
Description y = hilbert(x) r et ur ns a complex helical sequence, somet imes called t he
analytic signal, fr om a r eal dat a sequence. The analyt ic signal has a r eal par t ,
which is t he or iginal dat a, and an imaginar y par t , which cont ains t he Hilber t
t r ansfor m. The imaginar y par t is a ver sion of t he or iginal r eal sequence wit h a
90 phase shift . Sines ar e t her efor e t r ansfor med t o cosines and vice ver sa. The
Hilber t t r ansfor med ser ies has t he same amplit ude and fr equency cont ent as
t he or iginal r eal dat a and includes phase infor mat ion t hat depends on t he
phase of t he or iginal dat a.
If x is a mat r ix, y = hilbert(x) oper at es columnwise on t he mat r ix, finding
t he Hilber t t r ansfor m of each column.
The Hilber t t r ansfor m is useful in calculat ing inst ant aneous at t r ibut es of a
t ime ser ies, especially t he amplit ude and fr equency. The inst ant aneous
amplit ude is t he amplit ude of t he complex Hilber t t r ansfor m; t he
inst ant aneous fr equency is t he t ime r at e of change of t he inst ant aneous phase
angle. For a pur e sinusoid, t he inst ant aneous amplit ude and fr equency ar e
const ant . The inst ant aneous phase, however , is a sawt oot h, r eflect ing t he way
in which t he local phase angle var ies linear ly over a single cycle. For mixt ur es
of sinusoids, t he at t r ibut es ar e shor t t er m, or local, aver ages spanning no mor e
t han t wo or t hr ee point s.
Refer ence [1] descr ibes t he Kolmogor ov met hod for minimum phase
r econst r uct ion, which involves t aking t he Hilber t t r ansfor m of t he logar it hm of
t he spect r um of a t ime ser ies. The t oolbox funct ion rceps per for ms t his
r econst r uct ion.
Algorithm The analyt ic signal for a sequence x has a one-sided Fourier transform, t hat is,
negat ive fr equencies ar e 0. To appr oximat e t he analyt ic signal, hilbert
calculat es t he FFT of t he input sequence, r eplaces t hose FFT coefficient s t hat
cor r espond t o negat ive fr equencies wit h zer os, and calculat es t he inver se FFT
of t he r esult .
In det ail, hilbert uses a four -st ep algor it hm:
hilbert
6-188
1 It calculat es t he FFT of t he input sequence, st or ing t he r esult in a vect or y.
Befor e t r ansfor ming, it zer o pads t he input sequence so it s lengt h n is t he
closest power of t wo, if necessar y. This ensur es t he most efficient FFT
comput at ion.
2 It cr eat es a vect or h whose element s h(i) have t he values
- 1 for i = 1, (n/2) + 1
- 2 for i = 2, 3, ..., (n/2)
- 0 for i = (n/2) + 2, ... , n
3 It calculat es t he element -wise pr oduct of y and h.
4 It calculat es t he inver se FFT of t he sequence obt ained in st ep 3 and r et ur ns
t he fir st n element s of t he r esult .
If t he input dat a x is a mat r ix, hilbert oper at es in a similar manner , ext ending
each st ep above t o handle t he mat r ix case.
See Also
References [1] Claer bout , J .F. Fundamentals of Geophysical Data Processing. New Yor k:
McGr aw-Hill, 1976. Pgs. 59-62.
fft One-dimensional fast Four ier t r ansfor m.
ifft One-dimensional inver se fast Four ier t r ansfor m.
rceps Real cepst r um and minimum phase r econst r uct ion.
icceps
6-189
6icceps
Purpose Inver se complex cepst r um.
Syntax x = icceps(xhat,nd)
Description x = icceps(xhat,nd) r et ur ns t he inver se complex cepst r um of t he (assumed
r eal) sequence xhat, r emoving nd samples of delay. If xhat was obt ained wit h
cceps(x), t hen t he amount of delay t hat was added t o x was t he element of
round(unwrap(angle(fft(x)))/pi) cor r esponding t o r adians.
See Also
References [1] Oppenheim, A.V., and R.W. Schafer . Digital S ignal Processing. Englewood
Cliffs, NJ : Pr ent ice Hall, 1975.
cceps Complex cepst r al analysis.
hilbert Hilber t t r ansfor m.
rceps Real cepst r um and minimum phase r econst r uct ion.
unwrap Unwr ap phase angles.
idct
6-190
6idct
Purpose Inver se discr et e cosine t r ansfor m.
Syntax x = idct(y)
x = idct(y,n)
Description The inver se discr et e cosine t r ansfor m r econst r uct s a sequence fr om it s discr et e
cosine t r ansfor m (DCT) coefficient s. The idct funct ion is t he inver se of t he dct
funct ion.
x = idct(y) r et ur ns t he inver se discr et e cosine t r ansfor m of y
wher e
and N = length(x), which is t he same as length(y). The ser ies is indexed
fr om n = 1 and k = 1 inst ead of t he usual n = 0 and k = 0 because MATLAB
vect or s r un fr om 1 t o N inst ead of fr om 0 t o N-1.
x = idct(y,n) appends zer os or t r uncat es t he vect or y t o lengt h n befor e
t r ansfor ming.
If y is a mat r ix, idct t r ansfor ms it s columns.
See Also
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 ,

'

=
dct Discr et e cosine t r ansfor m (DCT).
dct2 Two-dimensional DCT (see Image Processing Toolbox Users
Guide).
idct2 Two-dimensional inver se DCT (see Image Processing Toolbox
Users Guide).
ifft One-dimensional inver se fast Four ier t r ansfor m.
idct
6-191
References [1] J ain, A.K. Fundamentals of Digital Image Processing. Englewood Cliffs, NJ :
Pr ent ice-Hall, 1989.
[2] Pennebaker , W.B., and J .L. Mit chell. J PEG S till Image Data Compression
S tandard. New Yor k, NY: Van Nost r and Reinhold, 1993. Chapt er 4.
ifft
6-192
6ifft
Purpose One-dimensional inver se fast Four ier t r ansfor m.
Syntax y = ifft(x)
y = ifft(x,n)
Description ifft comput es t he inver se Four ier t r ansfor m of a vect or or ar r ay. This funct ion
implement s t he inver se t r ansfor m given by
wher e W
N
= e
-j(2p/N)
and N = length(x). Not e t hat t he ser ies is indexed as n + 1
and k + 1 inst ead of t he usual n and k because MATLAB vect or s r un fr om 1 t o N
inst ead of fr om 0 t o N-1.
y = ifft(x) is t he inver se Four ier t r ansfor m of vect or x. If x is an ar r ay, y is
t he inver se FFT of each column of t he mat r ix.
y = ifft(x,n) is t he n-point inver se FFT. If t he lengt h of x is less t han n, ifft
pads x wit h t r ailing zer os t o lengt h n. If t he lengt h of x is gr eat er t han n, ifft
t r uncat es t he sequence x. When x is an ar r ay, ifft adjust s t he lengt h of t he
columns in t he same manner .
The ifft funct ion is par t of t he st andar d MATLAB language.
Algorithm The ifft funct ion is an M-file. The algor it hm for ifft is t he same as t hat for
fft, except for a sign change and a scale fact or of n = length(x). The execut ion
t ime is fast est when n is a power of t wo and slowest when n is a lar ge pr ime.
See Also
x n 1 + ( )
1
N
---- X k 1 + ( )W
n
k n
k 0 =
N 1

=
fft One-dimensional fast Four ier t r ansfor m.
fft2 Two-dimensional fast Four ier t r ansfor m.
fftshift Rear r ange t he out put s of fft and fft2.
ifft2 Two-dimensional inver se fast Four ier t r ansfor m.
ifft2
6-193
6ifft 2
Purpose Two-dimensional inver se fast Four ier t r ansfor m.
Syntax Y = ifft2(X)
Y = ifft2(X,m,n)
Description Y = ifft2(X) r et ur ns t he t wo-dimensional inver se fast Four ier t r ansfor m
(FFT) of t he ar r ay X. If X is a vect or , Y has t he same or ient at ion as X.
Y = ifft2(X,m,n) t r uncat es or zer o pads X, if necessar y, t o cr eat e an m-by-n
ar r ay befor e per for ming t he inver se FFT. The r esult Y is also m-by-n.
For any X, ifft2(fft2(X)) equals X t o wit hin r oundoff er r or . If X is r eal,
ifft2(fft2(X)) may have small imaginar y par t s.
The ifft2 funct ion is par t of t he st andar d MATLAB language.
Algorithm The algor it hm for ifft2 is t he same as t hat for fft2, except for a sign change
and scale fact or s of [m n]= size(X). The execut ion t ime is fast est when m and
n ar e power s of t wo and slowest when t hey ar e lar ge pr imes.
See Also
fft One-dimensional fast Four ier t r ansfor m.
fft2 Two-dimensional fast Four ier t r ansfor m.
fftn N-dimensional fast Four ier t r ansfor m (see t he online
MATLAB Function Reference).
fftshift Rear r ange t he out put s of fft and fft2.
ifft One-dimensional inver se fast Four ier t r ansfor m.
ifftn N-dimensional inver se fast Four ier t r ansfor m (see
t he online MATLAB Function Reference).
impinvar
6-194
6impinvar
Purpose Impulse invar iance met hod of analog-t o-digit al filt er conver sion.
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) cr eat es a digit al filt er wit h numer at or and
denominat or coefficient s bz and az, r espect ively, whose impulse r esponse is
equal t o t he impulse r esponse of t he analog filt er wit h coefficient s b and a,
scaled by 1/Fs.
[bz,az] = impinvar(b,a) uses t he default value of 1 Hz for Fs.
[bz,az] = impinvar(b,a,Fs,tol) uses t he t oler ance specified by tol t o
det er mine whet her poles ar e r epeat ed. A lar ger t oler ance incr eases t he
likelihood t hat impinvar will consider near by poles t o be r epeat ed. The default
is 0.001, or 0.1% of a poles magnit ude. Not e t hat t he accur acy of t he pole values
is st ill limit ed t o t he accur acy obt ainable by t he roots funct ion.
Example Conver t an analog lowpass filt er t o a digit al filt er using impinvar wit h a
sampling fr equency 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
Algorithm impinvar per for ms t he impulse-invar iant met hod of analog-t o-digit al t r ansfer
funct ion conver sion discussed in r efer ence [1]:
1 It finds t he par t ial fr act ion expansion of t he syst em r epr esent ed by b and a.
2 It r eplaces t he poles p by t he poles exp(p/Fs).
impinvar
6-195
3 It finds t he t r ansfer funct ion coefficient s of t he syst em fr om t he r esidues
fr om st ep 1 and t he poles fr om st ep 2.
See Also
References [1] Par ks, T.W., and C.S. Bur r us. Digital Filter Design. New Yor k: J ohn Wiley
& Sons, 1987. Pgs. 206-209.
bilinear Bilinear t r ansfor mat ion met hod of analog-t o-digit al
filt er conver sion.
lp2bp Lowpass t o bandpass analog filt er t r ansfor mat ion.
lp2bs Lowpass t o bandst op analog filt er t r ansfor mat ion.
lp2hp Lowpass t o highpass analog filt er t r ansfor mat ion.
lp2lp Lowpass t o lowpass analog filt er t r ansfor mat ion.
impz
6-196
6impz
Purpose Impulse r esponse of digit al filt er s.
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) comput es t he impulse r esponse of t he filt er wit h
numer at or coefficient s b and denominat or coefficient s a. impz chooses t he
number of samples and r et ur ns t he r esponse in column vect or h and t imes (or
sample int er vals) in column vect or t (wher e t = (0:n1)' and n is t he
comput ed impulse r esponse lengt h).
[h,t] = impz(b,a,n) comput es n samples of t he impulse r esponse. If n is a
vect or of int eger s, impz comput es t he impulse r esponse at t hose int eger
locat ions wher e 0 is t he st ar t ing point of t he filt er .
[h,t] = impz(b,a,n,Fs) comput es n samples and scales t so t hat samples ar e
spaced 1/Fs unit s apar t . Fs is 1 by default . Leave n empt y, [], t o let impz select
t he number of samples.
impz wit h no out put ar gument s plot s t he impulse r esponse in t he cur r ent
figur e window using stem(t,h).
impz wor ks for bot h r eal and complex input syst ems.
impz
6-197
Example Plot t he fir st 50 samples of t he impulse r esponse of a four t h-or der lowpass
ellipt ic filt er wit h cut off fr equency of 0.4 t imes t he Nyquist fr equency:
[b,a] = ellip(4,0.5,20,0.4);
impz(b,a,50)
Algorithm impz filt er s a lengt h n impulse sequence using
filter(b,a,[1 zeros(1,n1)])
To comput e n in t he aut o-lengt h case, impz eit her uses n = length(b) for t he
FIR case or fir st finds t he poles using p = roots(a), if length(a) is gr eat er
t han 1.
If t he filt er is unst able, n is chosen t o be t he point at which t he t er m fr om t he
lar gest pole r eaches 10^6 t imes it s or iginal value.
If t he filt er is st able, n is chosen t o be t he point at which t he t er m due t o t he
lar gest amplit ude pole is 5*10^5 of it s or iginal amplit ude.
If t he filt er is oscillat or y (poles on t he unit cir cle only), impz comput es five
per iods of t he slowest oscillat ion.
If t he filt er has bot h oscillat or y and damped t er ms, n is chosen t o equal five
per iods of t he slowest oscillat ion or t he point at which t he t er m due t o t he
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
6-198
lar gest (nonunit y) amplit ude pole is 5*10^5 of it s or iginal amplit ude,
whichever is gr eat er .
impz also allows for delay in t he numer at or polynomial, which it adds t o t he
r esult ing n.
See Also
impulse Unit impulse r esponse (see Control S ystem Toolbox
Users Guide).
stem Plot discr et e sequence dat a (see t he online MATLAB
Function Reference).
interp
6-199
6int er p
Purpose Incr ease sampling r at e by an int eger fact or (int er polat ion).
Syntax y = interp(x,r)
y = interp(x,r,l,alpha)
[y,b] = interp(x,r,l,alpha)
Description Int er polat ion incr eases t he or iginal sampling r at e for a sequence t o a higher
r at e. interp per for ms lowpass int er polat ion by inser t ing zer os int o t he or iginal
sequence and t hen applying a special lowpass filt er .
y = interp(x,r) incr eases t he sampling r at e of x by a fact or of r. The
int er polat ed vect or y is r t imes longer t han t he or iginal input x.
y = interp(x,r,l,alpha) specifies l (filt er lengt h) and alpha (cut -off
fr equency). The default value for l is 4 and t he default value for alpha is 0.5.
[y,b] = interp(x,r,l,alpha) r et ur ns vect or b cont aining t he filt er
coefficient s used for t he int er polat ion.
Example Int er polat e a signal by a fact or 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');
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
interp
6-200
Algorithm interp uses t he lowpass int er polat ion Algor it hm 8.1 descr ibed in [1]:
1 It expands t he input vect or t o t he cor r ect lengt h by inser t ing zer os bet ween
t he or iginal dat a values.
2 It designs a special symmet r ic FIR filt er t hat allows t he or iginal dat a t o pass
t hr ough unchanged and int er polat es bet ween so t hat t he mean-squar e
er r or s bet ween t he int er polat ed point s and t heir ideal values ar e minimized.
3 It applies t he filt er t o t he input vect or t o pr oduce t he int er polat ed out put
vect or .
The lengt h of t he FIR lowpass int er polat ing filt er is 2*l*r+1. The number of
or iginal sample values used for int er polat ion is 2*l. Or dinar ily, l should be
less t han or equal t o 10. The or iginal signal is assumed t o be band limit ed wit h
nor malized cut off fr equency 0 alpha 1, wher e 1 is half t he or iginal
sampling fr equency (t he Nyquist fr equency). The default value for l is 4 and
t he default value for alpha is 0.5.
Diagnostics If r is not an int eger , interp gives t he following er r or message:
Resampling rate R must be an integer.
See Also
References [1] IEEE. Programs for Digital S ignal Processing. IEEE Pr ess. New Yor k: J ohn
Wiley & Sons, 1979. Algor it hm 8.1.
decimate Decr ease t he sampling r at e for a sequence
(decimat ion).
interp1 One-dimensional dat a int er polat ion (t able lookup)
(see t he online MATLAB Function Reference).
resample Change sampling r at e by any r at ional fact or.
spline Cubic spline int er polat ion (see t he online MATLAB
Function Reference).
upfirdn Upsample, apply an FIR filt er, and downsample.
intfilt
6-201
6int filt
Purpose Int er polat ion FIR filt er design.
Syntax b = intfilt(r,l,alpha)
b = intfilt(r,n,'Lagrange')
Description b = intfilt(r,l,alpha) designs a linear phase FIR filt er t hat per for ms ideal
bandlimit ed int er polat ion using t he near est 2*l nonzer o samples, when used
on a sequence int er leaved wit h r1 consecut ive zer os ever y r samples. It
assumes an or iginal bandlimit edness of alpha t imes t he Nyquist fr equency.
The r et ur ned filt er is ident ical t o t hat used by interp.
b = intfilt(r,n,'Lagrange') or b = intfilt(r,n,'l') designs an FIR
filt er t hat per for ms nt h-or der Lagr ange polynomial int er polat ion on a sequence
int er leaved wit h r1 consecut ive zer os ever y r samples. b has lengt h (n + 1)*r
for n even, and lengt h (n + 1)*r1 for n odd.
Bot h t ypes of filt er s ar e basically lowpass and ar e int ended for int er polat ion
and decimat ion.
Examples Design a digit al int er polat ion filt er t o upsample a signal by four , using t he
bandlimit ed met hod:
alpha = 0.5; % "bandlimitedness" factor
h1 = intfilt(4,2,alpha); % bandlimited interpolation
The filt er h1 wor ks best when t he or iginal signal is bandlimit ed t o alpha t imes
t he Nyquist fr equency. Cr eat e a bandlimit ed noise signal:
randn('seed',0)
x = filter(fir1(40,0.5),1,randn(200,1)); % bandlimit
Now zer o pad t he signal wit h t hr ee zer os bet ween ever y sample. The r esult ing
sequence is four t imes t he lengt h of x:
xr = reshape([x zeros(length(x),3)]',4*length(x),1);
Int er polat e using t he filter command:
y = filter(h1,1,xr);
intfilt
6-202
y is an int er polat ed ver sion of x, delayed by seven samples (t he gr oup-delay of
t he filt er ). Zoom in on a sect ion t o see t his:
plot(100:200,y(100:200),7+(101:4:196),x(26:49),'o')
intfilts ot her t ype of filt er per for ms Lagr ange polynomial int er polat ion of
t he or iginal signal. For example, fir st -or der polynomial int er polat ion is just
linear int er polat ion, which is accomplished wit h a t r iangular filt er :
h2 = intfilt(4,1,'l') % Lagrange interpolation
h2 =
0.2500 0.5000 0.7500 1.0000 0.7500 0.5000 0.2500
Algorithm The bandlimit ed met hod uses firls t o design an int er polat ion FIR equivalent
t o t hat pr esent ed in [1]. The polynomial met hod uses Lagr anges polynomial
int er polat ion for mula on equally spaced samples t o const r uct t he appr opr iat e
filt er .
See Also
References [1] Oet ken, Par ks, and Schler . New Result s in t he Design of Digit al
Int er polat or s. IEEE Trans. Acoust., S peech, S ignal Processing. Vol. ASSP-23
(J une 1975). Pgs. 301-309.
100 110 120 130 140 150 160 170 180 190 200
-1.5
-1
-0.5
0
0.5
1
1.5
Sample Number
Solid = interpolated, o = original
decimate Decr ease t he sampling r at e for a sequence
(decimat ion).
interp Incr ease sampling r at e by an int eger fact or
(int er polat ion).
resample Change sampling r at e by any r at ional fact or.
invfreqs
6-203
6invfr eqs
Purpose Cont inuous-t ime (analog) filt er ident ificat ion fr om fr equency dat a.
Syntax [b,a] = invfreqs(h,w,nb,na)
[b,a] = invfreqs(h,w,nb,na,wt)
[b,a] = invfreqs(h,w,nb,na,wt,iter)
[b,a] = invfreqs(h,w,nb,na,wt,iter,tol)
[b,a] = invfreqs(h,w,nb,na,wt,iter,tol,'trace')
[b,a] = invfreqs(h,w,'complex',nb,na,...)
Description invfreqs is t he inver se oper at ion of freqs; it finds a cont inuous-t ime t r ansfer
funct ion t hat cor r esponds t o a given complex fr equency r esponse. Fr om a
labor at or y analysis st andpoint , invfreqs is useful in conver t ing magnit ude
and phase dat a int o t r ansfer funct ions.
[b,a] = invfreqs(h,w,nb,na) r et ur ns t he r eal numer at or and denominat or
coefficient vect or s b and a of t he t r ansfer funct ion
whose complex fr equency r esponse is given in vect or h at t he fr equency point s
specified in vect or w. Scalar s nb and na specify t he desir ed or der s of t he
numer at or and denominat or polynomials.
Fr equency is specified in r adians bet ween 0 and , and t he lengt h of h must be
t he same as t he lengt h of w. invfreqs uses conj(h) at w t o ensur e t he pr oper
fr equency domain symmet r y for a r eal filt er .
[b,a] = invfreqs(h,w,nb,na,wt) weight s t he fit -er r or s ver sus fr equency. wt
is a vect or of weight ing fact or s t he same lengt h as w.
invfreqs(h,w,nb,na,wt,iter) and
invfreqs(h,w,nb,na,wt,iter,tol) pr ovide a super ior algor it hm t hat
guar ant ees st abilit y of t he r esult ing linear syst em and sear ches for t he best fit
using a numer ical, it er at ive scheme. The iter par amet er t ells invfreqs t o end
t he it er at ion when t he solut ion has conver ged, or aft er iter it er at ions,
whichever comes fir st . invfreqs defines conver gence as occur r ing when t he
H s ( )
B s ( )
A s ( )
---------- -
b 1 ( )s
n b
b 2 ( )s
n b 1
L b n b 1 + ( ) + + +
a 1 ( )s
n a
a 2 ( )s
n a 1
L a n a 1 + ( ) + + +
---------------------------------------------------------------------------------------------- = =
invfreqs
6-204
nor m of t he (modified) gr adient vect or is less t han tol. tol is an opt ional
par amet er t hat default s t o 0.01. To obt ain a weight vect or of all ones, use
invfreqs(h,w,nb,na,[],iter,tol)
invfreqs(h,w,nb,na,wt,iter,tol,'trace') displays a t ext ual pr ogr ess
r epor t of t he it er at ion.
invfreqs(h,w,'complex',nb,na,...) cr eat es a complex filt er . In t his case no
symmet r y is enfor ced, and t he fr equency is specified in r adians bet ween - and
.
Remarks When building higher or der models using high fr equencies, it is impor t ant t o
scale t he fr equencies, dividing by a fact or such as half t he highest fr equency
pr esent in w, so as t o obt ain well condit ioned values of a and b. This cor r esponds
t o a r escaling of t ime.
Examples Conver t a simple t r ansfer funct ion t o fr equency r esponse dat a and t hen back
t o t he or iginal filt er coefficient s:
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
6-205
Not ice t hat bb and aa ar e equivalent t o b and a, r espect ively. However , aa has
poles in t he left half-plane and t hus t he syst em is unst able. Use invfreqss
it er at ive algor it hm t o find a st able appr oximat ion t o t he syst em:
[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
Suppose you have t wo vect or s, mag and phase, t hat cont ain magnit ude and
phase dat a gat her ed in a labor at or y, and a t hir d vect or w of fr equencies. You
can conver t t he dat a int o a cont inuous-t ime t r ansfer funct ion using invfreqs:
[b,a] = invfreqs(mag.*exp(j*phase),w,2,3);
Algorithm By default , invfreqs uses an equat ion er r or met hod t o ident ify t he best model
fr om t he dat a. This finds b and a in
by cr eat ing a syst em of linear equat ions and solving t hem wit h MATLABs \
oper at or . Her e A(w(k)) and B(w(k)) ar e t he Four ier t r ansfor ms of t he
polynomials a and b, r espect ively, at t he fr equency w(k), and n is t he number
of fr equency point s (t he lengt h of h and w). This algor it hm is based on Levi [1].
Sever al var iant s have been suggest ed in t he lit er at ur e, wher e t he weight ing
funct ion wt gives less at t ent ion t o high fr equencies.
The super ior (out put -er r or ) algor it hm uses t he damped Gauss-Newt on met hod
for it er at ive sear ch [2], wit h t he out put of t he fir st algor it hm as t he init ial
est imat e. This solves t he dir ect pr oblem of minimizing t he weight ed sum of t he
squar ed er r or bet ween t he act ual and t he desir ed fr equency r esponse point s:
min
b a ,
wt k ( ) h k ( )A w k ( ) ( ) B w k ( ) ( )
2
k 1 =
n

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

invfreqs
6-206
See Also
References [1] Levi, E.C. Complex-Cur ve Fit t ing. IRE Trans. on Automatic Control.
Vol. AC-4 (1959). Pgs. 37-44.
[2] Dennis, J .E., J r ., and R.B. Schnabel. Numerical Methods for Unconstrained
Optimization and Nonlinear Equations. Englewood Cliffs, NJ : Pr ent ice Hall,
1983.
freqs Fr equency r esponse of analog filt er s.
freqz Fr equency r esponse of digit al filt er s.
invfreqz Discr et e-t ime filt er ident ificat ion fr om fr equency
dat a.
prony Pr onys met hod for t ime domain IIR filt er design.
invfreqz
6-207
6invfr eqz
Purpose Discr et e-t ime filt er ident ificat ion fr om fr equency dat a.
Syntax [b,a] = invfreqz(h,w,nb,na)
[b,a] = invfreqz(h,w,nb,na,wt)
[b,a] = invfreqz(h,w,nb,na,wt,iter)
[b,a] = invfreqz(h,w,nb,na,wt,iter,tol)
[b,a] = invfreqz(h,w,nb,na,wt,iter,tol,'trace')
[b,a] = invfreqz(h,w,'complex',nb,na,...)
Description invfreqz is t he inver se oper at ion of freqz; it finds a discr et e-t ime t r ansfer
funct ion t hat cor r esponds t o a given complex fr equency r esponse. Fr om a
labor at or y analysis st andpoint , invfreqz can be used t o conver t magnit ude
and phase dat a int o t r ansfer funct ions.
[b,a] = invfreqz(h,w,nb,na) r et ur ns t he r eal numer at or and denominat or
coefficient s in vect or s b and a of t he t r ansfer funct ion
whose complex fr equency r esponse is given in vect or h at t he fr equency point s
specified in vect or w. Scalar s nb and na specify t he desir ed or der s of t he
numer at or and denominat or polynomials.
Fr equency is specified in r adians bet ween 0 and , and t he lengt h of h must be
t he same as t he lengt h of w. invfreqz uses conj(h) at w t o ensur e t he pr oper
fr equency domain symmet r y for a r eal filt er .
[b,a] = invfreqz(h,w,nb,na,wt) weight s t he fit -er r or s ver sus fr equency. wt
is a vect or of weight ing fact or s t he same lengt h as w.
invfreqz(h,w,nb,na,wt,iter) and
invfreqz(h,w,nb,na,wt,iter,tol) pr ovide a super ior algor it hm t hat
guar ant ees st abilit y of t he r esult ing linear syst em and sear ches for t he best fit
using a numer ical, it er at ive scheme. The iter par amet er t ells invfreqz t o end
t he it er at ion when t he solut ion has conver ged, or aft er iter it er at ions,
whichever comes fir st . invfreqz defines conver gence as occur r ing when t he
H z ( )
B z ( )
A z ( )
-----------
b 1 ( ) b 2 ( )z
1
L b n b 1 + ( )z
n b
+ + +
a 1 ( ) a 2 ( )z
1
L a n a 1 + ( )z
n a
+ + +
----------------------------------------------------------------------------------------- = =
invfreqz
6-208
nor m of t he (modified) gr adient vect or is less t han tol. tol is an opt ional
par amet er t hat default s t o 0.01. To obt ain a weight vect or of all ones, use
invfreqz(h,w,nb,na,[],iter,tol)
invfreqz(h,w,nb,na,wt,iter,tol,'trace') displays a t ext ual pr ogr ess
r epor t of t he it er at ion.
invfreqz(h,w,'complex',nb,na,...) cr eat es a complex filt er . In t his case no
symmet r y is enfor ced, and t he fr equency is specified in r adians bet ween - and
.
Example Conver t a simple t r ansfer funct ion t o fr equency r esponse dat a and t hen back
t o t he or iginal filt er coefficient s:
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
Not ice t hat bb and aa ar e equivalent t o b and a, r espect ively. However , aa has
poles out side t he unit cir cle and t hus t he syst em is unst able. Use invfreqzs
it er at ive algor it hm t o find a st able appr oximat ion t o t he syst em:
[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
Algorithm By default , invfreqz uses an equat ion er r or met hod t o ident ify t he best model
fr om t he dat a. This finds b and a in
invfreqz
6-209
by cr eat ing a syst em of linear equat ions and solving t hem wit h MATLABs \
oper at or . Her e A(w(k)) and B(w(k)) ar e t he Four ier t r ansfor ms of t he
polynomials a and b, r espect ively, at t he fr equency w(k), and n is t he number
of fr equency point s (t he lengt h of h and w). This algor it hm is a based on Levi [1].
The super ior (out put -er r or ) algor it hm uses t he damped Gauss-Newt on
met hod for it er at ive sear ch [2], wit h t he out put of t he fir st algor it hm as t he
init ial est imat e. This solves t he dir ect pr oblem of minimizing t he weight ed sum
of t he squar ed er r or bet ween t he act ual and t he desir ed fr equency r esponse
point s:
See Also
References [1] Levi, E.C. Complex-Cur ve Fit t ing. IRE Trans. on Automatic Control.
Vol. AC-4 (1959). Pgs. 37-44.
[2] Dennis, J .E., J r ., and R.B. Schnabel. Numerical Methods for Unconstrained
Optimization and Nonlinear Equations. Englewood Cliffs, NJ : Pr ent ice Hall,
1983.
min
b a ,
wt k ( ) h k ( )A w k ( ) ( ) B w k ( ) ( )
2
k 1 =
n

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

freqs Fr equency r esponse of analog filt er s.


freqz Fr equency r esponse of digit al filt er s.
invfreqs Cont inuous-t ime (analog) filt er ident ificat ion fr om
fr equency dat a.
prony Pr onys met hod for t ime domain IIR filt er design.
kaiser
6-210
6kaiser
Purpose Kaiser window.
Syntax w = kaiser(n,beta)
Description w = kaiser(n,beta) r et ur ns an n-point Kaiser ( - sinh) window in t he
column vect or w. beta is t he Kaiser window par amet er t hat affect s t he
sidelobe at t enuat ion of t he Four ier t r ansfor m of t he window.
To obt ain a Kaiser window t hat designs an FIR filt er wit h sidelobe height
- dB, use t he following :
Incr easing beta widens t he mainlobe and decr eases t he amplit ude of t he
sidelobes (incr eases t he at t enuat ion).
See Also
References [1] Kaiser , J .F. Nonr ecur sive Digit al Filt er Design Using t he - sinh Window
Funct ion. Proc. 1974 IEEE S ymp. Circuits and S yst. (Apr il 1974). Pgs. 20-23.
[2] IEEE. Digital S ignal Processing II. IEEE Pr ess. New Yor k: J ohn Wiley &
Sons, 1975.
I
0

0.1102 8.7 ( ), 50 >


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

'

=
bartlett Bar t let t window.
blackman Blackman window.
boxcar Rect angular window.
chebwin Chebyshev window.
hamming Hamming window.
hanning Hanning window.
kaiserord Est imat e par amet er s for fir1 wit h Kaiser window.
triang Tr iangular window.
I
0
kaiserord
6-211
6kaiser or d
Purpose Est imat e par amet er s for an FIR filt er design wit h Kaiser window.
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 r et ur ns a filt er or der n and beta par amet er t o specify a Kaiser
window for use wit h t he fir1 funct ion. Given a set of specificat ions in t he
fr equency domain, kaiserord est imat es t he minimum FIR filt er or der t hat will
appr oximat ely meet t he specificat ions. kaiserord conver t s t he given filt er
specificat ions int o passband and st opband r ipples and conver t s cut off
fr equencies int o t he for m needed for windowed FIR filt er design.
NOTE If t he band r ipples ar e specified as unequal, t he smallest one is used,
since t he Kaiser window met hod is const r ained t o give filt er s wit h equal r ipple
height s in all t he passbands and st opbands.
[n,Wn,beta,ftype] = kaiserord(f,a,dev) finds t he appr oximat e or der n,
nor malized fr equency band edges Wn, and weight s t hat meet input
specificat ions f, a, and dev. f is a vect or of band edges and a is a vect or
specifying t he desir ed amplit ude on t he bands defined by f. The lengt h of f is
t wice t he lengt h of a, minus 2. Toget her , f and a define a desir ed piecewise
const ant r esponse funct ion. dev is a vect or t he same size as a t hat specifies t he
maximum allowable er r or or deviat ion bet ween t he fr equency r esponse of t he
out put filt er and it s desir ed amplit ude, for each band.
fir1 can use t he r esult ing or der n, fr equency vect or Wn, mult iband magnit ude
t ype ftype, and t he Kaiser window par amet er beta. The ftype st r ing is
int ended for use wit h fir1; it is equal t o 'high' for a highpass filt er and 'stop'
for a bandst op filt er . For mult iband filt er s, it can be equal t o 'dc0' when t he
fir st band is a st opband (st ar t ing at f = 0) or 'dc1' when t he fir st band is a
passband.
To design a filt er b t hat appr oximat ely meet s t he specificat ions given by kaiser
par amet er s f, a, and dev:
b = fir1(n,Wn,kaiser(n+1,beta),ftype,'noscale')
kaiserord
6-212
[n,Wn,beta,ftype] = kaiserord(f,a,dev,Fs) specifies a sampling
fr equency Fs. If not pr esent , Fs default s t o 2 Hz, implying a Nyquist fr equency
of 1 Hz. You can t her efor e specify band edges scaled t o a par t icular
applicat ions sampling fr equency.
c = kaiserord(f,a,dev,Fs,'cell') is a cell-ar r ay whose element s ar e t he
par amet er s t o fir1.
NOTE In some cases, kaiserord under est imat es or over est imat es t he or der n.
If t he filt er does not meet t he specificat ions, t r y a higher or der such as n+1, n+2,
and so on, or a lower or der .
Result s ar e inaccur at e if t he cut off fr equencies ar e near 0 or t he Nyquist
fr equency, or if dev is lar ge (gr eat er t han 10%).
Algorithm kaiserord uses empir ically der ived for mulas for est imat ing t he or der s of
lowpass filt er s, as well as differ ent iat or s and Hilber t t r ansfor mer s. Est imat es
for mult iband filt er s (such as bandpass filt er s) ar e der ived fr om t he lowpass
design for mulas.
The design for mulas t hat under lie t he Kaiser window and it s applicat ion t o
FIR filt er design ar e
wher e = -20log
10
is t he st opband at t enuat ion expr essed in decibels (r ecall
t hat
p
=
s
is r equir ed). The design for mula is:
wher e n is t he filt er or der and is t he widt h of t he smallest t r ansit ion r egion.

0.1102 8.7 ( ), 50 >


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

'

=
n
7.95
2.285 ( )
---------------------------- =
kaiserord
6-213
Examples Design a lowpass filt er wit h passband fr om 0 t o 1 kHz and st opband fr om
1500 Hz t o 4 kHz. Specify passband r ipple of 5% and st opband at t enuat ion of
40 dB:
fsamp = 8000;
fcuts = [1000 1500];
mags = [1 0];
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)
0 0.2 0.4 0.6 0.8 1
1500
1000
500
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
150
100
50
0
50
Normalized Angular Frequency ( rads/sample)
M
a
g
n
i
t
u
d
e

(
d
B
)
kaiserord
6-214
Design an odd-lengt h bandpass filt er (not e t hat odd lengt h means even or der ,
so t he input t o fir1 must be an even int eger ):
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
Design a lowpass filt er wit h a passband cut off of 1500 Hz, a st opband cut off of
2000 Hz, passband r ipple of 0.01, st opband r ipple of 0.1, and a sampling
fr equency 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');
This is equivalent t o
c = kaiserord([1500 2000],[1 0],[0.01 0.1],8000,'cell');
b = fir1(c{:});
0 500 1000 1500 2000 2500 3000 3500 4000
0
0.2
0.4
0.6
0.8
1
1.2
1.4
kaiserord
6-215
Remarks Be car eful t o dist inguish bet ween t he meanings of filt er lengt h and filt er or der .
The filt er length is t he number of impulse r esponse samples in t he FIR filt er .
Gener ally, t he impulse r esponse is indexed fr om n = 0 t o n = L-1, wher e L is t he
filt er lengt h. The filt er order is t he highest power in a z-t r ansfor m
r epr esent at ion of t he filt er . For an FIR t r ansfer funct ion, t his r epr esent at ion is
a polynomial in z, wher e t he highest power is z
L-1
and t he lowest power is z
0
.
The filt er or der is 1 less t han t he lengt h (L-1) and is also equal t o t he number
of zer os of t he z polynomial.
Diagnostics The lengt hs of t he fr equency, magnit ude, and deviat ion vect or s must mat ch;
ot her wise, kaiserord gives t he following er r or message:
Requires M and DEV to be the same length.
Length of F must be 2*length(M)2.
When magnit udes ar e not specified cor r ect ly, kaiserord gives t he following
er r or messages:
Stopbands must be zero.
All passbands must have the same height.
If t he band edges ar e not st r ict ly incr easing, kaiserord gives t he following
er r or message:
Bandedges must be strictly increasing.
See Also
References [1] Kaiser , J .F. Nonr ecur sive Digit al Filt er Design Using t he - sinh Window
Funct ion. Proc. 1974 IEEE S ymp. Circuits and S yst. (Apr il 1974). Pgs. 20-23.
[2] IEEE. Digital S ignal Processing II. IEEE Pr ess. New Yor k: J ohn Wiley &
Sons, 1975. Pgs. 123-126.
fir1 Window-based finit e impulse r esponse filt er design
st andar d r esponse.
kaiser Kaiser window.
remezord Par ks-McClellan opt imal FIR filt er or der est imat ion.
I
0
latc2tf
6-216
6lat c2t f
Purpose Lat t ice filt er t o t r ansfer funct ion conver sion.
Syntax [num,den] = latc2tf(k,v)
[num,den] = latc2tf(k,'iir')
num = latc2tf(k,'fir')
num = latc2tf(k)
Description [num,den] = latc2tf(k,v) finds t he t r ansfer funct ion numer at or num and
denominat or den fr om t he IIR lat t ice coefficient s k and ladder coefficient s v.
[num,den] = latc2tf(k,'iir') assumes t hat k is associat ed wit h an all-pole
IIR lat t ice filt er .
num = latc2tf(k,'fir') and
num = latc2tf(k) find t he t r ansfer funct ion numer at or s fr om t he FIR lat t ice
coefficient s specified by k.
See Also
latcfilt Lat t ice and lat t ice-ladder filt er implement at ion.
tf2latc Conver sion of t r ansfer funct ion t o lat t ice filt er.
latcfilt
6-217
6lat cfilt
Purpose Lat t ice and lat t ice-ladder filt er implement at ion.
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 [f,g] = latcfilt(k,x) filt er s x wit h t he FIR lat t ice coefficient s in vect or k. f
is t he for war d lat t ice filt er r esult and g is t he backwar d filt er r esult .
If k and x ar e vect or s, t he r esult is a (signal) vect or .
Mat r ix ar gument s ar e per mit t ed under t he following r ules:
If x is a mat r ix and k is a vect or , each column of x is pr ocessed t hr ough t he
lat t ice filt er specified by k.
If x is a vect or and k is a mat r ix, each column of k is used t o filt er x, and a
signal mat r ix is r et ur ned.
If x and k ar e bot h mat r ices wit h t he same number of columns, t hen t he i-t h
column of k is used t o filt er t he i-t h column of x. A signal mat r ix is r et ur ned.
[f,g] = latcfilt(k,v,x) filt er s x wit h t he IIR lat t ice coefficient s k and
ladder coefficient s v. k and v must be vect or s, while x may be a signal mat r ix.
[f,g] = latcfilt(k,1,x) filt er s x wit h t he IIR all-pole lat t ice specified by k.
k and x may be vect or s or mat r ices accor ding t o t he r ules given for t he FIR
lat t ice.
[f,g,zf] = latcfilt(...,'ic',zi) accept s a lengt h-k vect or zi specifying
t he init ial condit ion of t he lat t ice st at es. Out put zf is a lengt h-k vect or
specifying t he final condit ion of t he lat t ice st at es.
See Also
filter Filt er dat a wit h a r ecur sive (IIR) or nonr ecur sive
(FIR) filt er.
latc2tf Lat t ice filt er t o t r ansfer funct ion conver sion.
tf2latc Conver sion of t r ansfer funct ion t o lat t ice filt er.
levinson
6-218
6levinson
Purpose Levinson-Dur bin r ecur sion.
Syntax a = levinson(r,p)
Description The Levinson-Dur bin r ecur sion is an algor it hm for finding an all-pole IIR filt er
wit h a pr escr ibed det er minist ic aut ocor r elat ion sequence. It has applicat ions in
filt er design, coding, and spect r al est imat ion. The filt er t hat levinson pr oduces
is minimum phase.
a = levinson(r,p) finds t he coefficient s of an pt h-or der aut or egr essive linear
pr ocess which has r as it s aut ocor r elat ion sequence. r is a r eal or complex
det er minist ic aut ocor r elat ion sequence (a vect or ), and p is t he or der of
denominat or polynomial A(z); t hat is, a = [1 a(2) ... a(p+1)]. The filt er
coefficient s ar e or der ed in descending power s of z:
Algorithm levinson solves t he symmet r ic Toeplit z syst em of linear equat ions.
wher e r = [r(1) ... r(p+1)] is t he input aut ocor r elat ion vect or , and r(i)
*
denot es
t he complex conjugat e of r(i). The algor it hm r equir es O(p
2
) flops and is t hus
much mor e efficient t han t he MATLAB \ command for lar ge p. However , t he
levinson funct ion uses \ for low or der s t o pr ovide t he fast est possible
execut ion.
See Also
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 + ( )
=
lpc Linear pr edict ion coefficient s.
prony Pr onys met hod for t ime domain IIR filt er design.
rlevinson Rever se Levinson-Dur bin r ecur sion.
stmcb Linear model using St eiglit z-McBr ide it er at ion.
levinson
6-219
References [1] Ljung, L. S ystem Identification: Theory for the User. Englewood Cliffs, NJ :
Pr ent ice Hall, 1987. Pgs. 278-280.
lp2bp
6-220
6lp2bp
Purpose Lowpass t o bandpass analog filt er t r ansfor mat ion.
Syntax [bt,at] = lp2bp(b,a,Wo,Bw)
[At,Bt,Ct,Dt] = lp2bp(A,B,C,D,Wo,Bw)
Description lp2bp t r ansfor ms analog lowpass filt er pr ot ot ypes wit h a cut off fr equency of
1 r ad/sec int o bandpass filt er s wit h desir ed bandwidt h and cent er fr equency.
The t r ansfor mat ion is one st ep in t he digit al filt er design pr ocess for t he
butter, cheby1, cheby2, and ellip funct ions.
lp2bp can per for m t he t r ansfor mat ion on t wo differ ent linear syst em
r epr esent at ions: t r ansfer funct ion for m and st at e-space for m. In bot h cases, t he
input syst em must be an analog filt er pr ot ot ype.
Transfer Function Form (Polynomial)
[bt,at] = lp2bp(b,a,Wo,Bw) t r ansfor ms an analog lowpass filt er pr ot ot ype
given by polynomial coefficient s int o a bandpass filt er wit h cent er fr equency Wo
and bandwidt h Bw. Row vect or s b and a specify t he coefficient s of t he numer at or
and denominat or of t he pr ot ot ype in descending power s of s:
Scalar s Wo and Bw specify t he cent er fr equency and bandwidt h in unit s of
r adians/second. For a filt er wit h lower band edge w1 and upper band edge w2,
use Wo = sqrt(w1*w2) and Bw = w2w1.
lp2bp r et ur ns t he fr equency t r ansfor med filt er in r ow vect or s bt and at.
State-Space Form
[At,Bt,Ct,Dt] = lp2bp(A,B,C,D,Wo,Bw) conver t s t he cont inuous-t ime
st at e-space lowpass filt er pr ot ot ype in mat r ices A, B, C, D:
b s ( )
a s ( )
----------
b 1 ( )s
n b
L b n b ( )s b n b 1 + ( ) + + +
a 1 ( )s
n a
L a n a ( )s a n a 1 + ( ) + + +
------------------------------------------------------------------------------------ =
x

Ax Bu + =
y Cx Du + =
lp2bp
6-221
int o a bandpass filt er wit h cent er fr equency Wo and bandwidt h Bw. For a filt er
wit h lower band edge w1 and upper band edge w2, use Wo = sqrt(w1*w2) and
Bw = w2w1.
The bandpass filt er is r et ur ned in mat r ices At, Bt, Ct, Dt.
Algorithm lp2bp is a highly accur at e st at e-space for mulat ion of t he classic analog filt er
fr equency t r ansfor mat ion. Consider t he st at e-space syst em:
wher e u is t he input , x is t he st at e vect or , and y is t he out put . The Laplace
t r ansfor m of t he fir st equat ion (assuming zer o init ial condit ions) is
Now if a bandpass filt er is t o have cent er fr equency
0
and bandwidt h B
w
, t he
st andar d s-domain t r ansfor mat ion is
wher e Q =
0
/B
w
and p = s/
0
. Subst it ut ing t his for s in t he Laplace
t r ansfor med st at e-space equat ion, and consider ing t he oper at or p as d/dt:
or
Now define
which, when subst it ut ed, leads t o
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 B u + + =
lp2bp
6-222
The last t wo equat ions give equat ions of st at e. Wr it e t hem in st andar d for m
and mult iply t he differ ent ial equat ions by
0
t o r ecover t he t ime/fr equency
scaling r epr esent ed by p and find st at e mat r ices for t he bandpass filt er :
Q = Wo/Bw; [ma,na] = size(A);
At = Wo*[A/Q eye(ma,na);eye(ma,na) zeros(ma,na)];
Bt = Wo*[B/Q; zeros(ma,nb)];
Ct = [C zeros(mc,ma)];
Dt = d;
If t he input t o lp2bp is in t r ansfer funct ion for m, t he funct ion t r ansfor ms it int o
st at e-space for m befor e applying t his algor it hm.
See Also
bilinear Bilinear t r ansfor mat ion met hod of analog-t o-digit al
filt er conver sion.
impinvar Impulse invar iance met hod of analog-t o-digit al filt er
conver sion.
lp2bs Lowpass t o bandst op analog filt er t r ansfor mat ion.
lp2hp Lowpass t o highpass analog filt er t r ansfor mat ion.
lp2lp Lowpass t o lowpass analog filt er t r ansfor mat ion.
lp2bs
6-223
6lp2bs
Purpose Lowpass t o bandst op analog filt er t r ansfor mat ion.
Syntax [bt,at] = lp2bs(b,a,Wo,Bw)
[At,Bt,Ct,Dt] = lp2bs(A,B,C,D,Wo,Bw)
Description lp2bs t r ansfor ms analog lowpass filt er pr ot ot ypes wit h a cut off fr equency of
1 r ad/sec int o bandst op filt er s wit h desir ed bandwidt h and cent er fr equency.
The t r ansfor mat ion is one st ep in t he digit al filt er design pr ocess for t he
butter, cheby1, cheby2, and ellip funct ions.
lp2bs can per for m t he t r ansfor mat ion on t wo differ ent linear syst em
r epr esent at ions: t r ansfer funct ion for m and st at e-space for m. In bot h cases, t he
input syst em must be an analog filt er pr ot ot ype.
Transfer Function Form (Polynomial)
[bt,at] = lp2bs(b,a,Wo,Bw) t r ansfor ms an analog lowpass filt er pr ot ot ype
given by polynomial coefficient s int o a bandst op filt er wit h cent er fr equency Wo
and bandwidt h Bw. Row vect or s b and a specify t he coefficient s of t he numer at or
and denominat or of t he pr ot ot ype in descending power s of s:
Scalar s Wo and Bw specify t he cent er fr equency and bandwidt h in unit s of
r adians/second. For a filt er wit h lower band edge w1 and upper band edge w2,
use Wo = sqrt(w1*w2) and Bw = w2w1.
lp2bs r et ur ns t he fr equency t r ansfor med filt er in r ow vect or s bt and at.
State-Space Form
[At,Bt,Ct,Dt] = lp2bs(A,B,C,D,Wo,Bw) conver t s t he cont inuous-t ime
st at e-space lowpass filt er pr ot ot ype in mat r ices A, B, C, D:
b s ( )
a s ( )
----------
b 1 ( )s
n b
L b n b ( )s b n b 1 + ( ) + + +
a 1 ( )s
n a
L a n a ( )s a n a 1 + ( ) + + +
------------------------------------------------------------------------------------ =
x

Ax Bu + =
y Cx Du + =
lp2bs
6-224
int o a bandst op filt er wit h cent er fr equency Wo and bandwidt h Bw. For a filt er
wit h lower band edge w1 and upper band edge w2, use Wo = sqrt(w1*w2) and
Bw = w2w1.
The bandst op filt er is r et ur ned in mat r ices At, Bt, Ct, Dt.
Algorithm lp2bs is a highly accur at e st at e-space for mulat ion of t he classic analog filt er
fr equency t r ansfor mat ion. If a bandst op filt er is t o have cent er fr equency
0
and bandwidt h B
w
, t he st andar d s-domain t r ansfor mat ion is
wher e Q =
0
/B
w
and p = s/
0
. The st at e-space ver sion of t his t r ansfor mat ion is
Q = Wo/Bw;
At = [Wo/Q*inv(A) Wo*eye(ma);Wo*eye(ma) zeros(ma)];
Bt = [Wo/Q*(A B); zeros(ma,nb)];
Ct = [C/A zeros(mc,ma)];
Dt = D C/A*B;
See lp2bp for a der ivat ion of t he bandpass ver sion of t his t r ansfor mat ion.
See Also
s
p
Q p
2
1 + ( )
------------------------ =
bilinear Bilinear t r ansfor mat ion met hod of analog-t o-digit al
filt er conver sion.
impinvar Impulse invar iance met hod of analog-t o-digit al filt er
conver sion.
lp2bp Lowpass t o bandpass analog filt er t r ansfor mat ion.
lp2hp Lowpass t o highpass analog filt er t r ansfor mat ion.
lp2lp Lowpass t o lowpass analog filt er t r ansfor mat ion.
lp2hp
6-225
6lp2hp
Purpose Lowpass t o highpass analog filt er t r ansfor mat ion.
Syntax [bt,at] = lp2hp(b,a,Wo)
[At,Bt,Ct,Dt] = lp2hp(A,B,C,D,Wo)
Description lp2hp t r ansfor ms analog lowpass filt er pr ot ot ypes wit h a cut off fr equency of
1 r ad/sec int o highpass filt er s wit h desir ed cut off fr equency. The
t r ansfor mat ion is one st ep in t he digit al filt er design pr ocess for t he butter,
cheby1, cheby2, and ellip funct ions.
The lp2hp funct ion can per for m t he t r ansfor mat ion on t wo differ ent linear
syst em r epr esent at ions: t r ansfer funct ion for m and st at e-space for m. In bot h
cases, t he input syst em must be an analog filt er pr ot ot ype.
Transfer Function Form (Polynomial)
[bt,at] = lp2hp(b,a,Wo) t r ansfor ms an analog lowpass filt er pr ot ot ype
given by polynomial coefficient s int o a highpass filt er wit h cut off fr equency Wo.
Row vect or s b and a specify t he coefficient s of t he numer at or and denominat or
of t he pr ot ot ype in descending power s of s:
Scalar Wo specifies t he cut off fr equency in unit s of r adians/second. The
fr equency t r ansfor med filt er is r et ur ned in r ow vect or s bt and at.
State-Space Form
[At,Bt,Ct,Dt] = lp2hp(A,B,C,D,Wo) conver t s t he cont inuous-t ime
st at e-space lowpass filt er pr ot ot ype in mat r ices A, B, C, D:
int o a highpass filt er wit h cut off fr equency Wo. The highpass filt er is r et ur ned
in mat r ices At, Bt, Ct, Dt.
b s ( )
a s ( )
----------
b 1 ( )s
n b
L b n b ( )s b n b 1 + ( ) + + +
a 1 ( )s
n a
L a n a ( )s a n a 1 + ( ) + + +
------------------------------------------------------------------------------------ =
x

Ax Bu + =
y Cx Du + =
lp2hp
6-226
Algorithm lp2hp is a highly accur at e st at e-space for mulat ion of t he classic analog filt er
fr equency t r ansfor mat ion. If a highpass filt er is t o have cut off fr equency
0
, t he
st andar d s-domain t r ansfor mat ion is
The st at e-space ver sion of t his t r ansfor mat ion is
At = Wo*inv(A);
Bt = Wo*(A\B);
Ct = C/A;
Dt = D C/A*B;
See lp2bp for a der ivat ion of t he bandpass ver sion of t his t r ansfor mat ion.
See Also
s

0
p
------ - =
bilinear Bilinear t r ansfor mat ion met hod of analog-t o-digit al
filt er conver sion.
impinvar Impulse invar iance met hod of analog-t o-digit al filt er
conver sion.
lp2bp Lowpass t o bandpass analog filt er t r ansfor mat ion.
lp2bs Lowpass t o bandst op analog filt er t r ansfor mat ion.
lp2lp Lowpass t o lowpass analog filt er t r ansfor mat ion.
lp2lp
6-227
6lp2lp
Purpose Lowpass t o lowpass analog filt er t r ansfor mat ion.
Syntax [bt,at] = lp2lp(b,a,Wo)
[At,Bt,Ct,Dt] = lp2lp(A,B,C,D,Wo)
Description lp2lp t r ansfor ms an analog lowpass filt er pr ot ot ype wit h a cut off fr equency of
1 r ad/sec int o a lowpass filt er wit h any specified cut off fr equency. The
t r ansfor mat ion is one st ep in t he digit al filt er design pr ocess for t he butter,
cheby1, cheby2, and ellip funct ions.
The lp2lp funct ion can per for m t he t r ansfor mat ion on t wo differ ent linear
syst em r epr esent at ions: t r ansfer funct ion for m and st at e-space for m. In bot h
cases, t he input syst em must be an analog filt er pr ot ot ype.
Transfer Function Form (Polynomial)
[bt,at] = lp2lp(b,a,Wo) t r ansfor ms an analog lowpass filt er pr ot ot ype
given by polynomial coefficient s int o a lowpass filt er wit h cut off fr equency Wo.
Row vect or s b and a specify t he coefficient s of t he numer at or and denominat or
of t he pr ot ot ype in descending power s of s:
Scalar Wo specifies t he cut off fr equency in unit s of r adians/second. lp2lp
r et ur ns t he fr equency t r ansfor med filt er in r ow vect or s bt and at.
State-Space Form
[At,Bt,Ct,Dt] = lp2lp(A,B,C,D,Wo) conver t s t he cont inuous-t ime
st at e-space lowpass filt er pr ot ot ype in mat r ices A, B, C, D:
int o a lowpass filt er wit h cut off fr equency Wo. lp2lp r et ur ns t he lowpass filt er
in mat r ices At, Bt, Ct, Dt.
b s ( )
a s ( )
----------
b 1 ( )s
n b
L b n b ( )s b n b 1 + ( ) + + +
a 1 ( )s
n a
L a n a ( )s a n a 1 + ( ) + + +
------------------------------------------------------------------------------------ =
x

Ax Bu + =
y Cx Du + =
lp2lp
6-228
Algorithm lp2lp is a highly accur at e st at e-space for mulat ion of t he classic analog filt er
fr equency t r ansfor mat ion. If a lowpass filt er is t o have cut off fr equency
0
, t he
st andar d s-domain t r ansfor mat ion is
The st at e-space ver sion of t his t r ansfor mat ion is
At = Wo*A;
Bt = Wo*B;
Ct = C;
Dt = D;
See lp2bp for a der ivat ion of t he bandpass ver sion of t his t r ansfor mat ion.
See Also
s p
0
=
bilinear Bilinear t r ansfor mat ion met hod of analog-t o-digit al
filt er conver sion.
impinvar Impulse invar iance met hod of analog-t o-digit al filt er
conver sion.
lp2bp Lowpass t o bandpass analog filt er t r ansfor mat ion.
lp2bs Lowpass t o bandst op analog filt er t r ansfor mat ion.
lp2hp Lowpass t o highpass analog filt er t r ansfor mat ion.
lpc
6-229
6lpc
Purpose Linear pr edict ion coefficient s.
Syntax a = lpc(x,p)
Description lpc det er mines t he coefficient s of a for war d linear pr edict or by minimizing t he
pr edict ion er r or in t he least -squar es sense. It has applicat ions in filt er design
and speech coding.
a = lpc(x,p) finds t he coefficient s of a pt h-or der linear pr edict or (FIR filt er )
t hat pr edict s t he cur r ent value of t he r eal t ime ser ies x based on past samples:
p is t he or der of t he pr edict ion polynomial, a = [1 a(2) ... a(p+1)].
If p is unspecified, lpc uses as a default p = length(x)1. If x is a mat r ix
cont aining a separ at e signal in each column, lpc r et ur ns a model est imat e for
each column in t he r ows of mat r ix a.
Example Est imat e a dat a ser ies using a 3r d-or der for war d pr edict or , and compar e t o t he
or iginal signal.
Fir st , cr eat e t he signal dat a as t he out put of an aut or egr essive pr ocess dr iven
by whit e noise. Use t he last 4096 samples of t he AR pr ocess out put t o avoid
st ar t -up t r ansient s.
noise = randn(50000,1); % Normalized white Gaussian noise
x = filter(1,[1 1/2 1/3 1/4],noise);
x = x(45904:50000);
Comput e t he pr edict or coefficient s, est imat ed signal, pr edict ion er r or , and
aut ocor r elat ion sequence of t he pr edict ion er r or .
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
6-230
The pr edict ion er r or , e(n), can be viewed as t he out put of t he pr edict ion er r or
filt er A(z) shown below, wher e H(z) is t he opt imal linear pr edict or , x(n) is t he
input signal, and is t he pr edict ed signal.
Compar e t he pr edict ed signal t o t he or iginal signal.
plot(1:97,x(4001:4097),1:97,est_x(4001:4097),'--');
title('Original Signal vs. LPC Estimate');
xlabel('Samples'); ylabel('Amplitude'); grid;
legend('Original Signal','LPC Estimate')
Look at t he aut ocor r elat ion of t he pr edict ion er r or .
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 Filter
A z ( )
0 20 40 60 80 100
4
3
2
1
0
1
2
3
Original Signal vs. LPC Estimate
Samples
A
m
p
l
i
t
u
d
e
Original Signal
LPC Estimate
lpc
6-231
The pr edict ion er r or is appr oximat ely whit e Gaussian noise, as expect ed for a
3r d-or der AR input pr ocess.
Algorithm lpc uses t he aut ocor r elat ion met hod of aut or egr essive (AR) modeling t o find
t he filt er coefficient s. The gener at ed filt er might not model t he pr ocess exact ly
even if t he dat a sequence is t r uly an AR pr ocess of t he cor r ect or der . This is
because t he aut ocor r elat ion met hod implicit ly windows t he dat a, t hat is, it
assumes t hat signal samples beyond t he lengt h of x ar e 0.
lpc comput es t he least -squar es solut ion t o
wher e
5000 0 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 Ox 1 ( )
0 x m ( ) Ox 2 ( )
M O O M
0 L 0 x m ( )
= a
1
a 2 ( )
M
a p 1 + ( )
= b
1
0
M
0
= , ,
lpc
6-232
and m is t he lengt h of x. Solving t he least -squar es pr oblem via t he nor mal
equat ions
leads t o t he Yule-Walker equat ions
wher e r = [r(1) r(2) ... r(p+1)] is an aut ocor r elat ion est imat e for x comput ed
using xcorr. The Yule-Walker equat ions ar e solved in O(p
2
) flops by t he
Levinson-Dur bin algor it hm (see levinson).
See Also
References [1] J ackson, L.B. Digital Filters and S ignal Processing. Second Ed. Bost on:
Kluwer Academic Publisher s, 1989. Pgs. 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 + ( )
=
aryule Comput e an est imat e of AR model par amet er s using
t he Yule-Walker met hod.
levinson Levinson-Dur bin r ecur sion.
prony Pr onys met hod for t ime domain IIR filt er design.
pyulear Power spect r um est imat e using Yule-Walker AR
met hod.
stmcb Linear model using St eiglit z-McBr ide it er at ion.
maxflat
6-233
6maxflat
Purpose Gener alized digit al But t er wor t h filt er design.
Syntax [b,a,] = maxflat(nb,na,Wn)
b = maxflat(nb,'sym',Wn)
[b,a,b1,b2] = maxflat(nb,na,Wn)
[...] = maxflat(nb,na,Wn,'design_flag')
Description [b,a,] = maxflat(nb,na,Wn) is a lowpass But t er wor t h filt er wit h numer at or
and denominat or coefficient s b and a of or der s nb and na r espect ively. Wn is t he
cut off fr equency at which t he magnit ude r esponse of t he filt er is equal t o
(appr ox. -3 dB). Wn must be bet ween 0 and 1, wher e 1 cor r esponds t o half
t he sampling fr equency (t he Nyquist fr equency).
b = maxflat(nb,'sym',Wn) is a symmet r ic FIR But t er wor t h filt er . nb must be
even, and Wn is r est r ict ed t o a subint er val of [0,1]. The funct ion r aises an er r or
if Wn is specified out side of t his subint er val.
[b,a,b1,b2] = maxflat(nb,na,Wn) r et ur ns t wo polynomials b1 and b2 whose
pr oduct is equal t o t he numer at or polynomial b (t hat is, b = conv(b1,b2)). b1
cont ains all t he zer os at z = 1, and b2 cont ains all t he ot her zer os.
[...] = maxflat(nb,na,Wn,'design_flag') enables you t o monit or t he filt er
design, wher e design_flag is
trace, for a t ext ual display of t he design t able used in t he design
plots, for plot s of t he filt er s magnit ude, gr oup delay, and zer os and poles
both, for bot h t he t ext ual display and plot s
maxflat
6-234
Examples nb = 10; na = 2; Wn = 0.2*pi;
[b,a,b1,b2] = maxflat(nb,na,Wn,'plots')
Algorithm The met hod consist s of t he use of for mulae, polynomial r oot finding, and a
t r ansfor mat ion of polynomial r oot s.
See Also
References [1] Selesnick, I.W., and C.S. Bur r us. Gener alized Digit al But t er wor t h Filt er
Design. Proceedings of the IEEE Int. Conf. Acoust., S peech, S ignal Processing.
Vol. 3 (May 1996).
0 0.2 0.4 0.6 0.8 1
0
0.5
1
w/p
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
Pole-zero plot
<- deg 4
0 0.5 1
0
1
2
3
4
5
w/p
S
a
m
p
l
e
s
Group delay
butter But t er wor t h analog and digit al filt er design.
filter Filt er dat a wit h a r ecur sive (IIR) or nonr ecur sive
(FIR) filt er.
freqz Fr equency r esponse of digit al filt er s.
medfilt1
6-235
6medfilt 1
Purpose One-dimensional median filt er ing.
Syntax y = medfilt1(x,n)
y = medfilt1(x,n,blksz)
Description y = medfilt1(x,n) applies an or der n, one-dimensional median filt er t o vect or
x. y is t he same lengt h as x; t he funct ion t r eat s t he signal as if it is 0 beyond
t he end point s.
For n odd, y(k) is t he median of x(k(n1)/2:k+(n1)/2).
For n even, y(k) is t he median of x(kn/2), x(k(n/2)+1), ..., x(k+(n/2)1).
In t his case, medfilt1 sor t s t he number s, t hen t akes t he aver age of t he (n
1)/2 and ((n1)/2)+1 element s.
The default for n is 3.
y = medfilt1(x,n,blksz) uses a for-loop t o comput e blksz (block size)
out put samples at a t ime. Use blksz << length(x) if you ar e low on memor y,
since medfilt1 uses a wor king mat r ix of size n-by-blksz. By default ,
blksz = length(x); t his is t he fast est execut ion if you have sufficient memor y.
If x is a mat r ix, medfilt1 median filt er s it s columns using
y(:,i) = medfilt1(x(:,i),n,blksz)
in a loop over t he columns of x.
See Also
References [1] Pr at t , W.K. Digital Image Processing. New Yor k: J ohn Wiley & Sons, 1978.
Pgs. 330-333.
filter Filt er dat a wit h a r ecur sive (IIR) or nonr ecur sive
(FIR) filt er.
medfilt2 Two-dimensional median filt er ing (see Image
Processing Toolbox Users Guide).
median Median value (see t he online MATLAB Function
Reference).
modulate
6-236
6modulat e
Purpose Modulat ion for communicat ions simulat ion.
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) modulat e t he r eal message signal x
wit h a car r ier fr equency Fc and sampling fr equency Fs, using one of t he opt ions
list ed below for method. Not e t hat some met hods accept an opt ion, opt.
amdsbsc
or
am
Ampli tude modulati on, double s i deband, s uppres se d carri er.
Mult iplies x by a sinusoid of fr equency Fc:
y = x.*cos(2*pi*Fc*t)
amdsbtc Ampli tude modulati on, double s i deband, transmi tted carri er.
Subt r act s scalar opt fr om x and mult iplies t he r esult by a sinusoid
of fr equency Fc:
y = (xopt).*cos(2*pi*Fc*t)
If t he opt par amet er is not pr esent , modulate uses a default of
min(min(x)) so t hat t he message signal (xopt) is ent ir ely
non-negat ive and has a minimum value of 0.
amssb Ampli tude modulati on, si ngle s i deband. Mult iplies x by a
sinusoid of frequency Fc and adds t he result t o t he Hilbert t ransform
of x mult iplied by a phase shift ed sinusoid of frequency Fc:
y =
x.*cos(2*pi*Fc*t)+imag(hilbert(x)).*sin(2*pi*Fc*t)
This effect ively r emoves t he upper sideband.
modulate
6-237
fm Fre quency modulati on. Cr eat es a sinusoid wit h inst ant aneous
fr equency t hat var ies wit h t he message signal x:
y = cos(2*pi*Fc*t + opt*cumsum(x))
cumsum is a r ect angular appr oximat ion t o t he int egr al of x.
modulate uses opt as t he const ant of fr equency modulat ion. If opt
is not pr esent , modulate uses a default of
opt = (Fc/Fs)*2*pi/(max(max(x)))
so t he maximum fr equency excur sion fr om Fc is Fc Hz.
pm Phase modulat i on. Cr eat es a sinusoid of fr equency Fc whose
phase var ies wit h t he message signal x:
y = cos(2*pi*Fc*t + opt*x)
modulate uses opt as t he const ant of phase modulat ion. If opt is
not pr esent , modulate uses a default of
opt = pi/(max(max(x)))
so t he maximum phase excur sion is r adians.
pwm Puls e-wi dth modulati on. Cr eat es a pulse-widt h modulat ed
signal fr om t he pulse widt hs in x. The element s of x must be
bet ween 0 and 1, specifying t he widt h of each pulse in fr act ions of
a per iod. The pulses st ar t at t he beginning of each per iod, t hat is,
t hey ar e left just ified.
modulate(x,Fc,Fs,'pwm','centered')
yields pulses cent er ed at t he beginning of each per iod. y is lengt h
length(x)*Fs/Fc.
ptm Puls e ti me modulati on. Cr eat es a pulse t ime modulat ed signal
fr om t he pulse t imes in x. The element s of x must be bet ween 0
and 1, specifying t he left edge of each pulse in fr act ions of a per iod.
opt is a scalar bet ween 0 and 1 t hat specifies t he lengt h of each
pulse in fr act ions of a per iod. The default for opt is 0.1. y is lengt h
length(x)*Fs/Fc.
qam Quadrature ampli tude modulati on. Cr eat es a quadr at ur e
amplit ude modulat ed signal fr om signals x and opt:
y = x.*cos(2*pi*Fc*t) + opt.*sin(2*pi*Fc*t)
opt must be t he same size as x.
modulate
6-238
If you do not specify method, t hen modulate assumes am. Except for t he pwm and
ptm cases, y is t he same size as x.
If x is an ar r ay, modulate modulat es it s columns.
[y,t] = modulate(x,Fc,Fs) r et ur ns t he int er nal t ime vect or t t hat modulate
uses in it s comput at ions.
See Also
demod Demodulat ion for communicat ions simulat ion.
vco Volt age cont r olled oscillat or.
pburg
6-239
6pburg
Purpose Power spect r um est imat e using t he Bur g met hod.
Syntax Pxx = pburg(x,p,nfft)
[Pxx,freq] = pburg(x,p,nfft)
[Pxx,freq] = pburg(x,p,nfft,Fs)
[Pxx,freq] = pburg(x,p,nfft,Fs,'range')
pburg(...)
pburg(...,'squared')
Description pburg est imat es t he power spect r al densit y (PSD) of t he signal vect or x[n]
using t he Bur g met hod. This met hod fit s an aut or egr essive (AR) model t o t he
signal by minimizing (least squar es) t he for war d and backwar d pr edict ion
er r or s while const r aining t he AR par amet er s t o sat isfy t he Levinson-Dur bin
r ecur sion. The spect r al est imat e r et ur ned by pburg is t he magnit ude squar ed
fr equency r esponse of t his AR model. The cor r ect choice of t he model or der p is
impor t ant .
Pxx = pburg(x,p,nfft) r et ur ns Pxx, t he power spect r um est imat e. x is t he
input signal, p is t he model or der for t he all-pole filt er , and nfft is t he FFT
lengt h (default s t o 256 if not specified). Pxx has lengt h (nfft/2+1) for nfft
even, (nfft+1)/2 for nfft odd, and nfft if x is complex.
[Pxx,freq] = pburg(x,p,nfft) r et ur ns Pxx, t he power spect r um est imat e,
and freq, a vect or of fr equencies at which t he PSD was est imat ed. If t he input
signal is r eal-valued, t he r ange of freq is [0,). If t he input signal is complex,
t he r ange of freq is [0,2).
[Pxx,freq] = pburg(x,p,nfft,Fs) uses t he signals sampling fr equency, Fs,
t o scale bot h t he PSD vect or (Pxx) and t he fr equency vect or (freq). Pxx is scaled
by 1/Fs. If t he input signal is r eal-valued, t he r ange of freq is [0,Fs/2). If t he
input signal is complex, t he r ange of freq is [0,Fs). Fs default s t o 1 if left
empt y, [].
[Pxx,freq] = pburg(x,p,nfft,Fs,'range') specifies t he r ange of fr equency
values t o include in freq. range can be:
half, t o comput e t he PSD over t he r ange [0,Fs/2) for r eal x, and [0,Fs) for
complex x. If Fs is left blank, [], t he r ange is [0,1/2) for r eal x, and [0,1)
pburg
6-240
for complex x. If Fs is omit t ed ent ir ely, t he r ange is [0,pi) for r eal x, and
[0,2*pi) for complex x. half is t he default r ange.
whole, t o comput e t he PSD over t he r ange [0,Fs) for all x. If Fs is left
blank, [], t he r ange is [0,1) for all x. If Fs is omit t ed ent ir ely, t he r ange is
[0,2*pi) for all x.
pburg(...) plot s t he power spect r al densit y in t he cur r ent figur e window. The
fr equency r ange on t he plot is t he same as t he r ange of out put freq for a given
set of par amet er s.
pburg(...,'squared') plot s t he magnit ude of Pxx dir ect ly, r at her t han
conver t ing t he values t o dB.
Example Because t he met hod est imat es t he spect r um by fit t ing an AR model t o t he
signal, fir st define t he AR syst em (all-pole filt er ) t hat gener at es t he input .
Check t he magnit ude r esponse of t he pr ocess wit h freqz.
a = [1 2.2137 2.9403 2.1697 0.9606]; % AR system coefficients
freqz(1,a,'phase','no') % AR system magnitude response
title('AR System Magnitude Response')
0 0.2 0.4 0.6 0.8 1
20
10
0
10
20
30
40
Normalized Angular Frequency ( rads/sample)
M
a
g
n
i
t
u
d
e

(
d
B
)
AR System Magnitude Response
pburg
6-241
Now gener at e t he input signal x by filt er ing whit e noise t hr ough t he AR
syst em. Est imat e t he PSD of x based on a four t h-or der AR model (since we
know t hat t he or iginal AR syst em, a, has or der 4).
x = filter(1,a,randn(150,1)); % AR system output
pburg(x,4) % 4th order estimate
Diagnostics The fir st input ar gument must be a full vect or ; ot her wise pburg gener at es t he
following er r or message:
Input signal cannot be sparse.
If you specify an empt y mat r ix for t he second ar gument , pburg gener at es t he
following er r or message:
Model order must be an integer.
0 0.2 0.4 0.6 0.8 1
20
10
0
10
20
30
40
Normalized Angular Frequency ( rads/sample)
P
o
w
e
r

S
p
e
c
t
r
a
l

D
e
n
s
i
t
y

(
d
B
)
Burg Spectral Estimate P
xx
()
pburg
6-242
See Also
References [1] Mar ple, S.L. Digital S pectral Analysis. Englewood Cliffs, NJ : Pr ent ice Hall,
1987. Chapt er 7.
arburg Comput e an est imat e of AR model par amet er s using
t he Bur g met hod.
lpc Linear pr edict ion coefficient s.
pcov Power spect r um est imat e using t he covar iance
met hod.
pmcov Power spect r um est imat e using t he modified
covar iance met hod.
pmtm Power spect r um est imat e using t he mult it aper
met hod (MTM).
pmusic Power spect r um est imat e using MUSIC eigenvect or
met hod.
prony Pr onys met hod for t ime domain IIR filt er design.
pwelch Est imat e t he power spect r al densit y (PSD) of a signal
using Welchs met hod.
pyulear Power spect r um est imat e using Yule-Walker AR
met hod.
pcov
6-243
6pcov
Purpose Power spect r um est imat e using t he covar iance met hod.
Syntax Pxx = pcov(x,p,nfft)
[Pxx,freq] = pcov(x,p,nfft)
[Pxx,freq] = pcov(x,p,nfft,Fs)
[Pxx,freq] = pcov(x,p,nfft,Fs,'range')
pcov(...)
pcov(...,'squared')
Description pcov est imat es t he power spect r al densit y (PSD) of t he signal vect or x[n] using
t he covar iance met hod. This met hod fit s an aut or egr essive (AR) model t o t he
signal by minimizing t he for war d pr edict ion er r or in t he least -squar es sense.
The spect r al est imat e r et ur ned by pcov is t he magnit ude squar ed fr equency
r esponse of t his AR model. The cor r ect choice of t he model or der p is impor t ant .
Pxx = pcov(x,p,nfft) r et ur ns Pxx, t he power spect r um est imat e. x is t he
input signal, p is t he model or der for t he all-pole filt er , and nfft is t he FFT
lengt h (default s t o 256 if not specified). Pxx has lengt h (nfft/2+1) for nfft
even, (nfft+1)/2 for nfft odd, and nfft if x is complex.
[Pxx,freq] = pcov(x,p,nfft) r et ur ns Pxx, t he power spect r um est imat e,
and freq, a vect or of fr equencies at which t he PSD was est imat ed. If t he input
signal is r eal-valued, t he r ange of freq is [0,). If t he input signal is complex,
t he r ange of freq is [0,2).
[Pxx,freq] = pcov(x,p,nfft,Fs) uses t he signals sampling fr equency, Fs,
t o scale bot h t he PSD vect or (Pxx) and t he fr equency vect or (freq). Pxx is scaled
by 1/Fs. If t he input signal is r eal-valued, t he r ange of freq is [0,Fs/2). If t he
input signal is complex, t he r ange of freq is [0,Fs). Fs default s t o 1 if left
empt y, [].
[Pxx,freq] = pcov(x,p,nfft,Fs,'range') specifies t he r ange of fr equency
values t o include in freq. range can be:
half, t o comput e t he PSD over t he r ange [0,Fs/2) for r eal x, and [0,Fs) for
complex x. If Fs is left blank, [], t he r ange is [0,1/2) for r eal x, and [0,1)
pcov
6-244
for complex x. If Fs is omit t ed ent ir ely, t he r ange is [0,pi) for r eal x, and
[0,2*pi) for complex x. half is t he default r ange.
whole, t o comput e t he PSD over t he r ange [0,Fs) for all x. If Fs is left
blank, [], t he r ange is [0,1) for all x. If Fs is omit t ed ent ir ely, t he r ange is
[0,2*pi) for all x.
pcov(...) plot s t he power spect r al densit y in t he fir st available figur e window.
The fr equency r ange on t he plot is t he same as t he r ange of out put freq for a
given set of par amet er s.
pcov(...,'squared') plot s t he magnit ude of Pxx dir ect ly, r at her t han
conver t ing t he values t o dB.
Example Because t he met hod est imat es t he spect r um by fit t ing an AR model t o t he
signal, fir st define t he AR syst em (all-pole filt er ) t hat gener at es t he input .
Check t he magnit ude r esponse of t he pr ocess wit h freqz.
a = [1 2.2137 2.9403 2.1697 0.9606]; % AR system coefficients
freqz(1,a,'phase','no') % AR system magnitude response
title('AR System Magnitude Response')
0 0.2 0.4 0.6 0.8 1
20
10
0
10
20
30
40
Normalized Angular Frequency ( rads/sample)
M
a
g
n
i
t
u
d
e

(
d
B
)
AR System Magnitude Response
pcov
6-245
Now gener at e t he input signal x by filt er ing whit e noise t hr ough t he AR
syst em. Est imat e t he PSD of x based on a four t h-or der AR model (since we
know t hat t he or iginal AR syst em, a, has or der 4).
x = filter(1,a,randn(150,1)); % AR system output
pcov(x,4) % 4th order estimate
Diagnostics The fir st input ar gument must be a full vect or ; ot her wise pcov gener at es t he
following er r or message:
Input signal cannot be sparse.
If you specify an empt y mat r ix for t he second ar gument , pcov gener at es t he
following er r or message:
Model order must be an integer.
0 0.2 0.4 0.6 0.8 1
20
10
0
10
20
30
40
Normalized Angular Frequency ( rads/sample)
P
o
w
e
r

S
p
e
c
t
r
a
l

D
e
n
s
i
t
y

(
d
B
)
Covariance Spectral Estimate P
xx
()
pcov
6-246
See Also
References [1] Mar ple, S.L. Digital S pectral Analysis. Englewood Cliffs, NJ : Pr ent ice Hall,
1987. Chapt er 7.
arcov Comput e an est imat e of AR model par amet er s using
t he covar iance met hod.
lpc Linear pr edict ion coefficient s.
pburg Power spect r um est imat e using t he Bur g met hod.
pmcov Power spect r um est imat e using t he modified
covar iance met hod.
pmtm Power spect r um est imat e using t he mult it aper
met hod (MTM).
pmusic Power spect r um est imat e using MUSIC eigenvect or
met hod.
prony Pr onys met hod for t ime domain IIR filt er design.
pwelch Est imat e t he power spect r al densit y (PSD) of a signal
using Welchs met hod.
pyulear Power spect r um est imat e using Yule-Walker AR
met hod.
pmcov
6-247
6pmcov
Purpose Power spect r um est imat e using t he modified covar iance met hod.
Syntax Pxx = pmcov(x,p,nfft)
[Pxx,freq] = pmcov(x,p,nfft)
[Pxx,freq] = pmcov(x,p,nfft,Fs)
[Pxx,freq] = pmcov(x,p,nfft,Fs,'range')
pmcov(...)
pmcov(...,'squared')
Description pmcov est imat es t he power spect r al densit y (PSD) of t he signal vect or x[n]
using t he modified covar iance met hod. This met hod fit s an aut or egr essive (AR)
model t o t he signal by minimizing t he for war d and backwar d pr edict ion er r or s
in t he least -squar es sense. The spect r al est imat e r et ur ned by pmcov is t he
magnit ude squar ed fr equency r esponse of t his AR model. The cor r ect choice of
t he model or der p is impor t ant .
Pxx = pmcov(x,p,nfft) r et ur ns Pxx, t he power spect r um est imat e. x is t he
input signal, p is t he model or der for t he all-pole filt er , and nfft is t he FFT
lengt h (default s t o 256 if not specified). Pxx has lengt h (nfft/2+1) for nfft
even, (nfft+1)/2 for nfft odd, and nfft if x is complex.
[Pxx,freq] = pmcov(x,p,nfft) r et ur ns Pxx, t he power spect r um est imat e,
and freq, a vect or of fr equencies at which t he PSD was est imat ed. If t he input
signal is r eal-valued, t he r ange of freq is [0,). If t he input signal is complex,
t he r ange of freq is [0,2).
[Pxx,freq] = pmcov(x,p,nfft,Fs) uses t he signals sampling fr equency, Fs,
t o scale bot h t he PSD vect or (Pxx) and t he fr equency vect or (freq). Pxx is scaled
by 1/Fs. If t he input signal is r eal-valued, t he r ange of freq is [0,Fs/2). If t he
input signal is complex, t he r ange of freq is [0,Fs). Fs default s t o 1 if left
empt y, [].
[Pxx,freq] = pmcov(x,p,nfft,Fs,'range') specifies t he r ange of fr equency
values t o include in freq. range can be:
half, t o comput e t he PSD over t he r ange [0,Fs/2) for r eal x, and [0,Fs) for
complex x. If Fs is left blank, [], t he r ange is [0,1/2) for r eal x, and [0,1)
pmcov
6-248
for complex x. If Fs is omit t ed ent ir ely, t he r ange is [0,pi) for r eal x, and
[0,2*pi) for complex x. half is t he default r ange.
whole, t o comput e t he PSD over t he r ange [0,Fs) for all x. If Fs is left
blank, [], t he r ange is [0,1) for all x. If Fs is omit t ed ent ir ely, t he r ange is
[0,2*pi) for all x.
pmcov(...) plot s t he power spect r al densit y in t he fir st available figur e
window. The fr equency r ange on t he plot is t he same as t he r ange of out put
freq for a given set of par amet er s.
pmcov(...,'squared') plot s t he magnit ude of Pxx dir ect ly, r at her t han
conver t ing t he values t o dB.
Example Because t he met hod est imat es t he spect r um by fit t ing an AR model t o t he
signal, fir st cr eat e t he AR syst em (all-pole filt er ) t hat gener at es t he input .
Check t he magnit ude r esponse of t he pr ocess wit h freqz.
a = [1 2.2137 2.9403 2.1697 0.9606]; % AR system coefficients
freqz(1,a,'phase','no') % AR system magnitude response
title('AR System Magnitude Response')
0 0.2 0.4 0.6 0.8 1
20
10
0
10
20
30
40
Normalized Angular Frequency ( rads/sample)
M
a
g
n
i
t
u
d
e

(
d
B
)
AR System Magnitude Response
pmcov
6-249
Now gener at e t he input signal x by filt er ing whit e noise t hr ough t he AR
syst em. Est imat e t he PSD of x based on a four t h-or der AR model (since we
know t hat t he or iginal AR syst em, a, has or der 4).
x = filter(1,a,randn(150,1)); % AR system output
pmcov(x,4) % 4th order estimate
Diagnostics The fir st input ar gument must be a full vect or ; ot her wise pmcov gener at es t he
following er r or message:
Input signal cannot be sparse.
If you specify an empt y mat r ix for t he second ar gument , pmcov gener at es t he
following er r or message:
Model order must be an integer.
0 0.2 0.4 0.6 0.8 1
30
20
10
0
10
20
30
40
Normalized Angular Frequency ( rads/sample)
P
o
w
e
r

S
p
e
c
t
r
a
l

D
e
n
s
i
t
y

(
d
B
)
Modified Covariance Spectral Estimate P
xx
()
pmcov
6-250
See Also
References [1] Mar ple, S.L. Digital S pectral Analysis. Englewood Cliffs, NJ : Pr ent ice Hall,
1987. Chapt er 7.
armcov Comput e an est imat e of AR model par amet er s using
t he modified covar iance met hod.
lpc Linear pr edict ion coefficient s.
pburg Power spect r um est imat e using t he Bur g met hod.
pcov Power spect r um est imat e using t he covar iance
met hod.
pmtm Power spect r um est imat e using t he mult it aper
met hod (MTM).
pmusic Power spect r um est imat e using MUSIC eigenvect or
met hod.
prony Pr onys met hod for t ime domain IIR filt er design.
pwelch Est imat e t he power spect r al densit y (PSD) of a signal
using Welchs met hod.
pyulear Power spect r um est imat e using Yule-Walker AR
met hod.
pmtm
6-251
6pmt m
Purpose Power spect r um est imat e using t he mult it aper met hod (MTM).
Syntax Pxx = pmtm(x,nw)
Pxx = pmtm(x,nw,nfft)
[Pxx,f] = pmtm(x,nw,nfft,Fs)
[Pxx,f] = pmtm(x,nw,nfft,Fs,'method')
[Pxx,Pxxc,f] = pmtm(x,nw,nfft,Fs,'method')
[Pxx,Pxxc,f] = pmtm(x,nw,nfft,Fs,'method',p)
[Pxx,Pxxc,f] = pmtm(x,e,v,nfft,Fs,'method',p)
[Pxx,Pxxc,f] = pmtm(x,dpss_params,nfft,Fs,'method',p)
Description pmtm est imat es t he power spect r al densit y (PSD) of t he r eal t ime ser ies x using
t he mult it aper met hod (MTM), descr ibed in [1].
Pxx = pmtm(x,nw) est imat es t he PSD using nw as t he t ime-bandwidt h pr oduct
for t he discr et e pr olat e spher oidal sequences (Slepian sequences) t hat ar e used
as dat a windows. The default for nw is 4; ot her t ypical choices ar e
2, 5/2, 3, 7/2. The number of sequences used t o for m Pxx is 2*nw1.
Pxx = pmtm(x,nw,nfft) defines t he fr equency gr id as lengt h nfft. When x is
r eal, Pxx is lengt h (nfft/2+1) for nfft even and (nfft+1)/2 for nfft odd;
when x is complex, Pxx is lengt h nfft. The default for nfft is 256 or t he next
power of 2 gr eat er t han t he lengt h of x, whichever is lar ger .
[Pxx,f] = pmtm(x,nw,nfft,Fs) r et ur ns f, t he vect or of fr equencies at which
t he PSD is est imat ed, for t he sampling fr equency Fs. The default for Fs is 1 Hz.
[Pxx,f] = pmtm(x,nw,nfft,Fs,'method') specifies t he algor it hm used for
combining t he individual spect r al est imat es, wher e met hod is:
adapt, t o specify Thomsons adapt ive nonlinear combinat ion (default )
unity, t o specify a linear combinat ion wit h unit y weight s
eigen, t o specify a linear combinat ion wit h eigenvalue weight s
[Pxx,Pxxc,f] = pmtm(x,nw,nfft,Fs,'method') r et ur ns Pxxc, t he 95%
confidence int er val for Pxx, and
[Pxx,Pxxc,f] = pmtm(x,nw,nfft,Fs,'method',p) r et ur ns Pxxc, t he p*100%
confidence int er val for Pxx, wher e p is a scalar bet ween 0 and 1. Confidence
pmtm
6-252
int er vals ar e comput ed using a chi-squar ed appr oach, wher e Pxxc(:,1) is t he
lower bound and Pxxc(:,2) is t he upper bound of t he confidence int er val.
[Pxx,Pxxc,f] = pmtm(x,e,v,nfft,Fs,'method',p) r et ur ns t he PSD
est imat e Pxx, t he confidence int er val Pxxc, and t he fr equency vect or f fr om t he
dat a t aper s in e and t heir concent r at ions v.
[Pxx,Pxxc,f] = pmtm(x,dpss_params,nfft,Fs,'method',p) r et ur ns t he
PSD est imat e Pxx, t he confidence int er val Pxxc, and t he fr equency vect or f
fr om t he dat a t aper s comput ed using dpss wit h par amet er s fr om t he cell ar r ay
dpss_params, whose fir st element is t he second input t o dpss. The fir st dpss
par amet er (n) is det er mined by t he lengt h of x. For example,
pmtm(x,{3.5,'trace'},512,Fs) calculat es t he Slepian sequences for nw = 3.5,
and displays t he met hod t hat dpss uses. See dpss for ot her opt ions.
Remarks pmtm wit h no out put ar gument s plot s t he PSD in t he cur r ent or next available
figur e, wit h confidence int er vals.
To use default par amet er s for any ar gument in an expr ession, inser t an empt y
mat r ix []. For example, pmtm(x,[],[],1000) uses default s for t he second and
t hir d element s, in t his case, nw and nfft.
pmtm
6-253
Example This example analyzes a sinusoid in whit e noise:
Fs = 1000; t = 0:1/Fs:0.3;
x = cos(2*pi*t*200) + randn(size(t));
[Pxx,Pxxc,f] = pmtm(x,3.5,512,Fs,[],0.99);
plot(f,10*log10([Pxx Pxxc]))
See Also
0 100 200 300 400 500
-10
-5
0
5
10
15
20
dpss Discr et e pr olat e spher oidal sequences (Slepian
sequences).
pburg Power spect r um est imat e using t he Bur g met hod.
pcov Power spect r um est imat e using t he covar iance
met hod.
pmcov Power spect r um est imat e using t he modified
covar iance met hod.
pmusic Power spect r um est imat e using MUSIC eigenvect or
met hod.
pwelch Est imat e t he power spect r al densit y (PSD) of a signal
using Welchs met hod.
pyulear Power spect r um est imat e using Yule-Walker AR
met hod.
pmtm
6-254
References [1] Per cival, D.B., and A.T. Walden. S pectral Analysis for Physical
Applications: Multitaper and Conventional Univariate Techniques. Cambr idge:
Cambr idge Univer sit y Pr ess, 1993.
[2] Thomson, D.J . Spect r um est imat ion and har monic analysis. In
Proceedings of the IEEE. Vol. 70 (1982). Pgs. 1055-1096.
pmusic
6-255
6pmusic
Purpose Power spect r um est imat e using MUSIC eigenvect or met hod.
Syntax [Pxx,f] = pmusic(x,p)
[Pxx,f] = pmusic(x,[p thresh])
[Pxx,f] = pmusic(x,[p thresh],nfft,Fs,window,noverlap)
[Pxx,f] = pmusic(x,...,'corr')
[Pxx,f] = pmusic(x,...,'ev')
[Pxx,f,evects,svals] = pmusic(x,...)
Description pmusic est imat es t he power spect r al densit y (PSD) of a signal or cor r elat ion
mat r ix using Schmidt s eigen-analysis met hod [1]. The name MUSIC is an
acr onym for MUlt iple SIgnal Classificat ion. The eigenvector method, which
uses eigenvalue weight ing, is also suppor t ed [2]. The calling synt ax is similar
t o t hat of pwelch, which also per for ms spect r um est imat ion. pwelch uses t he
classical FFT-based appr oach while pmusic per for ms eigen-analysis of t he
signals cor r elat ion mat r ix.
[Pxx,f] = pmusic(x,p) and
[Pxx,f] = pmusic(x,[p thresh]) r et ur n Pxx, t he power spect r um est imat e,
and f, a vect or of fr equencies at which t he PSD is est imat ed. x is t he input
signal, wher e:
A r ow or column vect or r epr esent s one obser vat ion of t he pr ocess out put (for
example, one signal)
A r ect angular (possibly squar e) ar r ay assumes t hat each column of x is a
separ at e obser vat ion of t he pr ocess out put (for example, each column is one
out put of an ar r ay of sensor s, as in ar r ay pr ocessing)
A squar e mat r ix, given t he t r ailing ar gument 'corr', r epr esent s a
cor r elat ion mat r ix
The second ar gument is a one- or t wo-element vect or , eit her p or [p thresh].
If only p is specified, t he signal subspace dimension is p. If [p thresh] is
specified, thresh is mult iplied by
min
, t he smallest eigenvalue; eigenvalues
below t he t hr eshold
min
*thresh ar e assigned t o t he noise subspace. In t his
case, p is t he maximum dimension of t he signal subspace.
pmusic
6-256
NOTE pmusic must assign eigenvect or s t o t he noise and signal subspaces,
but t his is ver y difficult t o do in pr act ice. The t wo par amet er s p and thresh
ar e pr ovided for flexibilit y and cont r ol.
[Pxx,f] = pmusic(x,[p thresh],nfft,Fs,window,noverlap) specifies t he
FFT lengt h nfft (default is 256) and t he sampling fr equency for t he signal Fs
(default is 1). If Fs is specified, t he out put fr equency vect or f is scaled by t his
value. If t he input signal is r eal-valued, t he fr equency r ange is 0 t o Fs/2; for
t he complex case, it is 0 t o Fs. window is a scalar specifying t he r ect angular
window lengt h, or a vect or giving t he act ual window coefficient s. noverlap,
used in conjunct ion wit h window, is a scalar t hat gives t he number of point s by
which t o over lap successive windows.
[Pxx,f] = pmusic(x,...,'corr') for ces x t o be t aken as a cor r elat ion
mat r ix. In t his case, t he ar gument s window and noverlap ar e ignor ed.
[Pxx,f] = pmusic(x,...,'ev') select s t he eigenvect or var iant of t he MUSIC
est imat or . See t he Algor it hm sect ion below for an explanat ion of how t his is
differ ent fr om t he MUSIC met hod.
[Pxx,f,evects,svals] = pmusic(x,...) r et ur ns t wo addit ional ar gument s.
evects is a mat r ix of eigenvect or s spanning t he noise subspace (one per
column). svals is eit her a vect or of singular values (squar ed) fr om svd or a
vect or of eigenvalues of t he cor r elat ion mat r ix when t he 'corr' opt ion is
pr esent .
Remarks The input x can be a vect or or a mat r ix. x can be int er pr et ed as signal dat a or
as a cor r elat ion mat r ix, in one of t hr ee ways:
x is a vect or of signal values (r ow or column). In t his case, t he dimension of
t he eigenvect or s must be given. This is done eit her by t aking t he default
value of 2*p or by specifying a window lengt h using window.
x is a r ect angular (m-by-n, possibly squar e) mat r ix. In t his case, each column
of x is a separ at e obser vat ion signal t hat ent er s int o t he SVD analysis, n is
pmusic
6-257
t he number of obser vat ions, and t he dimension of t he eigenvect or s is equal
t o m, t he lengt h of a column.
x is a squar e mat r ix and t he t r ailing 'corr' is pr esent . x is t r eat ed as a
cor r elat ion mat r ix. In t his case, t he mat r ix must have only r eal, nonnegat ive
eigenvalues.
The input s p and thresh can det er mine t he number of noise eigenvect or s in one
of four ways:
If thresh < 1, or if it is unspecified, t he number of eigenvect or s spanning t he
signal subspace will be equal t o p. p must be an int eger sat isfying 0 p < n,
wher e n is t he dimension of t he eigenvect or s. This dimension n is t he column
lengt h in t he dat a mat r ix case, t he mat r ix size in t he cor r elat ion mat r ix case,
or t he window lengt h for signal vect or s. The value of thresh is unused.
If p n, thresh must be at least 1. thresh is used as t he mult iplier t o
det er mine an absolut e t hr eshold for split t ing t he eigenvalues bet ween t he
signal and noise subspaces:
If thresh < 1, t her e will be no noise eigenvect or s. This case is not allowed
and gives t he following er r or message:
Noise subspace dimension cannot be zero.
When p < n and thresh 1, p specifies t he maximum number of signal
eigenvect or s. However , t he t hr eshold t est specified by thresh can also t ake
eigenvect or s fr om t he signal subspace and assign t hem t o t he noise subspace.
Examples This example analyzes a signal vect or xx, assuming t hat t wo r eal signals ar e
pr esent in t he signal subspace. In t his case, t he dimension of t he signal
subspace is 4 because each r eal sinusoid is t he sum of t wo complex
exponent ials:
nn = 0:199;
xx = cos(0.257*pi*nn) + sin(0.2*pi*nn) + 0.01*randn(size(nn));
[PP,ff] = pmusic(xx,4);
This example analyzes t he same signal vect or xx wit h an eigenvalue cut off of
10% above t he minimum. Set t ing p = Inf for ces t he signal/noise subspace

k
thresh ( )mi n
k
( )
k
v
k
{ , } belong t o noise subspace
pmusic
6-258
decision t o be based on thresh. Use eigenvect or s of dimension 7 and a sampling
fr equency Fs of 8 kHz:
[PP,ff] = pmusic(xx,[Inf,1.1],[],8000,7); % window length = 7
Wit h t he t hir d and four t h out put s, by plot t ing t he zer os of t he noise-eigenvect or
polynomials, it is possible t o cr eat e a Root -MUSIC algor it hm, as t he following
zplane plot illust r at es:
[PP,ff,v_noise] = pmusic(xx,4);
for kk = 1:size(v_noise,2)
rr(:,kk) = roots(v_noise(:,kk));
end
zplane(rr)
Assume t hat RR is a squar e cor r elat ion mat r ix (for example, 7-by-7):
RR = toeplitz(cos(0.1*pi*[0:6])) + 0.1*eye(7);
[PP,ff] = pmusic(RR,4,'corr');
Make an obser vat ion mat r ix xx t hat is r ect angular (100-by-7):
xx = reshape(cos(0.257*pi*(0:699)),7,100) + 0.1*randn(7,100);
[PP,ff] = pmusic(xx,4);
Use t he same signal, but let pmusic for m t he 100-by-7 dat a mat r ix using it s
window and over lap input s. In addit ion, use a longer FFT:
yy = xx(:);
[PP,ff] = pmusic(yy,4,512,[],7,0);
If we set p = 0, all t he eigenvect or s ar e assigned t o t he noise subspace. 'ev'
specifies t he eigenvect or weight ing. This t ur ns out t o be equivalent t o MVDL
(Capons MLM):
[PP,ff] = pmusic(RR,0,'ev','corr');
Algorithm The MUSIC est imat e is given by t he for mula
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

------------------------------------------- = =
pmusic
6-259
wher e N is t he dimension of t he eigenvect or s and v
k
is t he k-t h eigenvect or of
t he cor r elat ion mat r ix of t he input signal. The int eger p is t he dimension of t he
signal subspace, so t he eigenvect or s v
k
used in t he sum cor r espond t o t he
smallest eigenvalues and also span t he noise subspace. The vect or e (f) consist s
of complex exponent ials, so t he inner pr oduct
amount s t o a Four ier t r ansfor m. The second for m is pr efer r ed for comput at ion
because t he FFT is comput ed for each v
k
and t hen t he squar ed magnit udes ar e
summed.
In t he eigenvect or met hod, t he summat ion is weight ed by t he eigenvalues
k
of
t he cor r elat ion mat r ix:
The funct ion r elies on t he svd mat r ix decomposit ion in t he signal case, and it
uses t he eig funct ion for analyzing t he cor r elat ion mat r ix. If SVD is used, t he
cor r elat ion mat r ix is never explicit ly comput ed, but t he singular values ar e
t he
k
.
Diagnostics Ther e must be at least one out put ar gument and at least t wo input s; ot her wise,
pmusic st ops and gives one of t he following er r or messages:
Must have at least 1 output argument.
Must have at least 2 input arguments.
The fir st ar gument must be a full mat r ix, ot her wise pmusic gives t he following
er r or message:
Input signal or correlation cannot be sparse.
v
k
H
e f ( )
P
ev
f ( )
1
v
k
H
e f ( )
2
k p 1 + =
N

,


_

----------------------------------------------------------- =
pmusic
6-260
If t he second ar gument was ent er ed as an empt y mat r ix, or if it has mor e t han
t wo element s, or if it has negat ive or non-int eger element s, pmusic gives one of
t he following er r or messages:
P cannot be empty.
Second input must have only 1 or 2 elements.
P must be an integer.
Second input must contain non-negative entries.
If t he value of p is t oo lar ge wit h r espect t o t he eigenvect or dimension, and
thresh is less t han 1, no eigenvect or s can be assigned t o t he noise subspace and
t he algor it hm fails. In t his case, pmusic gives t he following er r or message:
Noise subspace dimension cannot be zero.
If t he 'corr' par amet er is used, t hen t he fir st input must be a squar e
cor r elat ion mat r ix. If it is not , pmusic gives t he following er r or message:
Correlation matrix (R) is not square.
The cor r elat ion mat r ix is t hen checked for validit y; if it fails, pmusic gives t he
following er r or message:
Correlation matrix (R) has negative or complex eigenvalue.
See Also
lpc Linear pr edict ion coefficient s.
pburg Power spect r um est imat e using t he Bur g met hod.
pcov Power spect r um est imat e using t he covar iance
met hod.
pmcov Power spect r um est imat e using t he modified
covar iance met hod.
pmtm Power spect r um est imat e using t he mult it aper
met hod (MTM).
prony Pr onys met hod for t ime domain IIR filt er design.
pwelch Est imat e t he power spect r al densit y (PSD) of a signal
using Welchs met hod.
pyulear Power spect r um est imat e using Yule-Walker AR
met hod.
pmusic
6-261
References [1] Schmidt , R.O. Mult iple Emit t er Locat ion and Signal Par amet er
Est imat ion. IEEE Trans. Antennas Propagation. Vol. AP-34 (Mar ch 1986).
Pgs. 276-280.
[2] Mar ple, S.L. Digital S pectral Analysis. Englewood Cliffs, NJ : Pr ent ice Hall,
1987. Pgs. 373-378.
poly2ac
6-262
6poly2ac
Purpose Conver sion of pr edict ion polynomial t o aut ocor r elat ion sequence.
Syntax r = poly2ac(a,efinal)
Description r = poly2ac(a,efinal) finds t he aut ocor r elat ion sequence cor r esponding t o
pr edict ion polynomial a and final pr edict ion er r or efinal. If a(1) is not equal
t o 1, poly2ac nor malizes t he pr edict ion polynomial by a(1). a(1) cannot be 0.
See Also
References [1] Kay, S.M. Modern S pectral Estimation. Englewood Cliffs, NJ :
Pr ent ice-Hall, 1988.
ac2poly Conver sion of aut ocor r elat ion sequence t o pr edict ion
polynomial.
poly2rc Conver sion of pr edict ion polynomial t o r eflect ion
coefficient s.
rc2ac Conver sion of r eflect ion coefficient s t o
aut ocor r elat ion sequence.
poly2rc
6-263
6poly2r c
Purpose Conver sion of pr edict ion polynomial t o r eflect ion coefficient s.
Syntax k = poly2rc(a)
[k,r0] = poly2rc(a,efinal)
Description k = poly2rc(a) finds t he r eflect ion coefficient s of t he AR lat t ice st r uct ur e
cor r esponding t o pr edict ion polynomial a. a must be r eal, and a(1) cannot be 0.
If a(1) is not equal t o 1, poly2rc nor malizes t he pr edict ion polynomial by a(1).
k is a r ow vect or of size length(a)1.
[k,r0] = poly2rc(a,efinal) r et ur ns t he zer o-lag aut ocor r elat ion, r0, based
on t he final pr edict ion er r or , efinal.
A simple, fast way t o check if a has all of it s r oot s inside t he unit cir cle is t o
check if each of t he element s of k has magnit ude less t han 1:
stable = all(abs(poly2rc(a))<1)
Example Consider an IIR filt er given by
a = [1.0000 0.6149 0.9899 0.0000 0.0031 0.0082];
It s r eflect ion coefficient r epr esent at ion is
k = poly2rc(a)
k =
0.3090
0.9801
0.0031
0.0081
0.0082
Limitations If abs(k(i)) == 1 for any i, finding t he r eflect ion coefficient s is an
ill-condit ioned pr oblem. poly2rc will r et ur n some NaNs and pr ovide a war ning
message in t his case.
Algorithm poly2rc implement s t he r ecur sive r elat ionship:
poly2rc
6-264
This r elat ionship is based on Levinsons r ecur sion [1]. To implement it ,
poly2rc loops t hr ough a in r ever se or der aft er discar ding it s fir st element . For
each loop it er at ion i, t he funct ion
1 set s k(i) equal t o a(i)
2 applies t he second r elat ionship above t o element s 1 t hr ough i of t he vect or a:
a = (ak(i)*fliplr(a))/(1k(i)^2);
See Also
References [1] Kay, S.M. Modern S pectral Estimation: Theory and Application . Englewood
Cliffs, NJ : Pr ent ice Hall, 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 , , , , =
ac2rc Conver sion of aut ocor r elat ion sequence t o r eflect ion
coefficient s.
latc2tf Lat t ice filt er t o t r ansfer funct ion conver sion.
latcfilt Lat t ice and lat t ice-ladder filt er implement at ion.
poly2ac Conver sion of pr edict ion polynomial t o
aut ocor r elat ion sequence.
rc2poly Conver sion of r eflect ion coefficient s t o pr edict ion
polynomial.
tf2latc Conver sion of t r ansfer funct ion t o lat t ice filt er.
polystab
6-265
6polyst ab
Purpose St abilize polynomial.
Syntax b = polystab(a)
Description polystab st abilizes a polynomial wit h r espect t o t he unit cir cle; it r eflect s r oot s
wit h magnit udes gr eat er t han 1 inside t he unit cir cle.
b = polystab(a) wher e a is a vect or of polynomial coefficient s nor mally in t he
z-domain:
r et ur ns a r ow vect or cont aining t he st abilized polynomial.
Example polystab can conver t a linear -phase filt er int o a minimum-phase filt er wit h
t he same magnit ude r esponse:
h = fir1(25,0.4);
hmin = polystab(h)*norm(h)/norm(polystab(h));
Algorithm polystab finds t he r oot s of t he polynomial and maps t hose r oot s found out side
t he unit cir cle t o t he inside of t he unit cir cle:
v = roots(a);
vs = 0.5*(sign(abs(v)1)+1);
v = (1vs).*v + vs./conj(v);
b = a(1)*poly(v);
See Also
a z ( ) a 1 ( ) a 2 ( )z
1
L a n a 1 + ( )z
n a
+ + + =
roots Polynomial r oot s (see t he online MATLAB Function
Reference).
prony
6-266
6pr ony
Purpose Pr onys met hod for t ime domain IIR filt er design.
Syntax [b,a] = prony(h,nb,na)
Description Pr onys met hod is an algor it hm for finding an IIR filt er wit h a pr escr ibed t ime
domain impulse r esponse. It has applicat ions in filt er design, exponent ial
signal modeling, and syst em ident ificat ion (par amet r ic modeling).
[b,a] = prony(h,nb,na) finds a filt er wit h numer at or or der nb, denominat or
or der na, and t he t ime domain impulse r esponse in h. prony r et ur ns t he filt er
coefficient s in r ow vect or s b and a, of lengt h nb + 1 and na + 1, r espect ively.
The filt er coefficient s ar e in descending power s of z:
Example Recover t he coefficient s of a But t er wor t h filt er fr om it s impulse r esponse:
[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 implement s t he met hod descr ibed in r efer ence [1]. This met hod uses a
var iat ion of t he covar iance met hod of AR modeling t o find t he denominat or
coefficient s a and t hen finds t he numer at or coefficient s b for which t he impulse
r esponse of t he out put filt er mat ches exact ly t he fir st nb + 1 samples of x. The
filt er is not necessar ily st able, but pot ent ially can r ecover t he coefficient s
H z ( )
B z ( )
A z ( )
-----------
b 1 ( ) b 2 ( )z
1
L b n b 1 + ( )z
n b
+ + +
a 1 ( ) a 2 ( )z
1
L a n a 1 + ( )z
n a
+ + +
----------------------------------------------------------------------------------------- = =
prony
6-267
exact ly if t he dat a sequence is t r uly an aut or egr essive moving aver age (ARMA)
pr ocess of t he cor r ect or der .
See Also
References [1] Par ks, T.W., and C.S. Bur r us. Digital Filter Design. New Yor k: J ohn Wiley
& Sons, 1987. Pgs. 226-228.
butter But t er wor t h analog and digit al filt er design.
cheby1 Chebyshev t ype I filt er design (passband r ipple).
cheby2 Chebyshev t ype II filt er design (st opband r ipple).
ellip Ellipt ic (Cauer ) filt er design.
invfreqz Discr et e-t ime filt er ident ificat ion fr om fr equency
dat a.
levinson Levinson-Dur bin r ecur sion.
lpc Linear pr edict ion coefficient s.
stmcb Linear model using St eiglit z-McBr ide it er at ion.
psd
6-268
6psd
Superseded The psd funct ion for spect r al est imat ion by Welchs met hod has been
super seded by pwelch.
The pwelch funct ion impr oves upon psd in t hr ee ways:
The magnit ude of t he spect r um is scaled by 1/Fs
The default value of Fs is 1
No det r ending is per for med
The psd funct ion will cont inue t o be included in t he Signal Pr ocessing Toolbox
for backwar ds compat ibilit y.
pulstran
6-269
6pulst r an
Purpose Pulse t r ain gener at or .
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 gener at es pulse t r ains fr om cont inuous funct ions or sampled
pr ot ot ype pulses.
y = pulstran(t,d,'func') gener at es a pulse t r ain based on samples of a
cont inuous funct ion, 'func', wher e func is:
gauspuls, for Gaussian-modulat ed sinusoidal pulse gener at or
rectpuls, for sampled aper iodic r ect angle gener at or
tripuls, for sampled aper iodic t r iangle gener at or
pulstran is evaluat ed length(d) t imes and r et ur ns t he sum of t he evaluat ions
y = func(td(1)) + func(td(2)) + ...
The funct ion is evaluat ed over t he r ange of ar gument values specified in ar r ay
t, aft er r emoving a scalar ar gument offset t aken fr om t he vect or d. Not e t hat
func must be a vect or ized funct ion t hat can t ake an ar r ay t as an ar gument .
An opt ional gain fact or may be applied t o each delayed evaluat ion by specifying
d as a t wo-column mat r ix, wit h t he offset defined in column 1 and associat ed
gain in column 2 of d. Not e t hat a r ow vect or will be int er pr et ed as specifying
delays only.
pulstran(t,d,'func',p1,p2,...) allows addit ional par amet er s t o be passed
t o 'func' as necessar y. For example,
func(td(1),p1,p2,...) + func(td(2),p1,p2,...) + ...
pulstran(t,d,p,Fs) gener at es a pulse t r ain t hat is t he sum of mult iple
delayed int er polat ions of t he pr ot ot ype pulse in vect or p, sampled at t he r at e
Fs, wher e p spans t he t ime int er val [0,(length(p)1)/Fs], and it s samples
ar e ident ically 0 out side t his int er val. By default , linear int er polat ion is used
for gener at ing delays.
pulstran
6-270
pulstran(t,d,p) assumes t hat t he sampling r at e Fs is equal t o 1 Hz.
pulstran(...,'func') specifies alt er nat ive int er polat ion met hods. See
interp1 for a list of available met hods.
Examples This example gener at es an asymmet r ic sawt oot h wavefor m wit h a r epet it ion
fr equency of 3 Hz and a sawt oot h widt h of 0.1 sec. It has a signal lengt h of 1 sec
and a 1 kHz sample r at e:
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)
This example gener at es a per iodic Gaussian pulse signal at 10 kHz, wit h 50%
bandwidt h. The pulse r epet it ion fr equency is 1 kHz, sample r at e is 50 kHz, and
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
6-271
pulse t r ain lengt h is 10 msec. The r epet it ion amplit ude should at t enuat e by 0.8
each t ime:
t = 0 : 1/50E3 : 10e3;
d = [0 : 1/1E3 : 10e3 ; 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
6-272
This example gener at es a t r ain of 10 Hamming windows:
p = hamming(32);
t = 0:320; d = (0:9)'*32;
y = pulstran(t,d,p);
plot(t,y)
See Also
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
chirp Swept -fr equency cosine gener at or.
cos Cosine of vect or /mat r ix element s (see t he online
MATLAB Function Reference).
diric Dir ichlet or per iodic sinc funct ion.
gauspuls Gaussian-modulat ed sinusoidal pulse gener at or.
rectpuls Sampled aper iodic r ect angle gener at or.
sawtooth Sawt oot h or t r iangle wave gener at or.
sin Sine of vect or /mat r ix element s (see t he online
MATLAB Function Reference).
sinc Sinc or sin(t )/t funct ion.
square Squar e wave gener at or.
tripuls Sampled aper iodic t r iangle gener at or.
pwelch
6-273
6pwelch
Purpose Est imat e t he power spect r al densit y (PSD) of a signal using Welchs met hod.
Syntax Pxx = pwelch(x)
Pxx = pwelch(x,nfft)
[Pxx,w] = pwelch(x,nfft)
[Pxx,f] = pwelch(x,nfft,Fs)
[Pxx,f] = pwelch(x,nfft,Fs,window)
[Pxx,f] = pwelch(x,nfft,Fs,window,noverlap)
[Pxx,Pxxc,f] = pwelch(x,nfft,Fs,window,noverlap,p)
[Pxx,Pxxc,f] = pwelch(...,'range')
pwelch(...)
pwelch(...,'magunits')
Description Pxx = pwelch(x) est imat es t he power spect r um of t he sequence x using t he
Welch met hod of spect r al est imat ion. If x is r eal, pwelch est imat es t he
spect r um at posit ive fr equencies only; in t his case, out put Pxx is a column
vect or of lengt h nfft/2+1 for nfft even and (nfft+1)/2 for nfft odd. If x is
complex, pwelch est imat es t he spect r um at bot h posit ive and negat ive
fr equencies and Pxx has lengt h nfft.
Pxx = pwelch(x,nfft) uses t he specified FFT lengt h nfft in est imat ing t he
power spect r um for x. This value det er mines t he number of differ ent
fr equencies at which t he power spect r um is est imat ed. Specify nfft as a power
of 2 for fast est execut ion. Specify an empt y mat r ix for nfft, [], t o use t he
default value of min(256,length(x)).
[Pxx,w] = pwelch(x,nfft) r et ur ns a vect or w of nor malized angular
fr equencies (in r ads/sample) at which t he funct ion evaluat es t he PSD. The
r ange of w is [0,) for r eal x and [0,2) for complex x. Since t he fr equency vect or
w is t he same size as Pxx, plot(w,Pxx) plot s t he power spect r um ver sus t he
nor malized angular fr equency.
[Pxx,f] = pwelch(x,nfft,Fs) r et ur ns a vect or f of linear fr equencies (in Hz)
at which t he funct ion evaluat es t he PSD. Fs is a scalar t hat specifies t he
sampling fr equency of x, and Pxx is scaled by 1/Fs. The r ange of f is [0,Fs/2)
for r eal x and [0,Fs) for complex x. Since t he fr equency vect or f is t he same
size as Pxx, plot(f,Pxx) plot s t he power spect r um ver sus t he linear fr equency.
Specify an empt y mat r ix for Fs, [], t o use t he default value of 1 Hz.
pwelch
6-274
[Pxx,f] = pwelch(x,nfft,Fs,window) specifies a windowing funct ion and
t he number of samples per windowed sect ion of t he x vect or (e.g., kaiser(64)).
The lengt h of t he window must be less t han or equal t o nfft; pwelch zer o pads
t he sect ions if t he lengt h of t he window is less t han nfft. Specify a scalar for
window t o use a Hanning window of t hat lengt h; specify an empt y mat r ix, [],
t o use t he default value of hanning(nfft).
[Pxx,f] = pwelch(x,nfft,Fs,window,noverlap) over laps t he windowed
sect ions of x by noverlap samples. Specify an empt y mat r ix for noverlap, [],
t o use t he default value of 0.
[Pxx,Pxxc,f] = pwelch(x,nfft,Fs,window,noverlap,p) wher e p is a
posit ive scalar bet ween 0 and 1 r et ur ns a vect or Pxxc t hat cont ains an est imat e
of t he p*100 per cent confidence int er val for Pxx. Pxxc is a t wo-column mat r ix
t hat is t he same lengt h as Pxx. The int er val [Pxxc(:,1),Pxxc(:,2)] cover s t he
t r ue PSD wit h pr obabilit y p. plot(f,[Pxx Pxxc]) plot s t he power spect r um
inside t he p*100 per cent confidence int er val. Specify an empt y mat r ix for p, [],
t o use t he default value of 0.95.
[Pxx,Pxxc,f] = pwelch(...,'range') specifies t he r ange of fr equency
values t o include in f. range can be:
half, t o comput e t he PSD over t he r ange [0,) for r eal or complex x. If Fs is
specified, t he r ange is [0,Fs/2) for r eal or complex x. If Fs is specified by an
empt y mat r ix, [], t he default value of 1 is used, and t he r ange is [0,1/2) for
r eal or complex x.
whole, t o comput e t he PSD over t he r ange [0,2) for r eal or complex x. If Fs
is specified, t he r ange is [0,Fs) for r eal or complex x. If Fs is specified by an
empt y mat r ix, [], t he default value of 1 is used, and t he r ange is [0,1) for r eal
or complex x.
pwelch(x,...) wit h no out put ar gument s plot s t he PSD against fr equency in
t he cur r ent figur e window. If p is specified, t he plot includes t he confidence
int er val.
pwelch(...,'magunits') specifies t he unit s in which t o expr ess t o t he
magnit ude axis of t he PSD plot . The opt ions ar e:
pwelch
6-275
'db', t o expr ess t he PSD dat a in decibels (dB). This is t he default .
'squared', t o expr ess t he PSD in linear unit s (magnit ude squar ed).
Example Gener at e a color ed noise signal and plot it s PSD wit h a confidence int er val of
95%. Specify a lengt h 1024 FFT, a 512-point Kaiser window wit h no over lap,
and a sampling fr equency of 10 kHz:
h = fir1(30,0.2,boxcar(31)); % design a lowpass filter
r = randn(16384,1); % white noise
x = filter(h,1,r); % color the noise
pwelch(x,1024,10000,kaiser(512,5),0,0.95)
Algorithm pwelch calculat es t he power spect r al densit y using Welchs met hod (see
r efer ences [1] and [2]):
1 It applies t he window specified by t he window vect or t o each successive
sect ion of input x.
2 It t r ansfor ms each sect ion wit h an nfft-point FFT.
3 It for ms t he per iodogr am of each sect ion by scaling t he magnit ude squar ed
of each t r ansfor med sect ion.
0 1000 2000 3000 4000 5000
110
100
90
80
70
60
50
40
30
Welchs Spectral Estimate P
xx
(f) / f
s
Frequency (Hz)
P
o
w
e
r

S
p
e
c
t
r
a
l

D
e
n
s
i
t
y

(
d
B
)
pwelch
6-276
4 It aver ages t he per iodogr ams of t he over lapping sect ions t o for m Pxx(f).
5 It scales Pxx(f) by 1/Fs t o for m Pxx(f)/Fs, t he power spect r um of x.
The number of sect ions t hat pwelch aver ages is
k = fix((length(x)noverlap)/(length(window)noverlap))
Diagnostics An appr opr iat e diagnost ic message is displayed when incor r ect ar gument s t o
pwelch ar e used:
Requires windows length to be no greater than FFT length.
Requires NOVERLAP to be strictly less than the window length.
Requires positive integer values for NFFT and NOVERLAP.
Requires confidence parameter to be a scalar between 0 and 1.
Requires vector input.
See Also
cohere Est imat e magnit ude squar ed coher ence funct ion
bet ween t wo signals.
csd Est imat e t he cr oss spect r al densit y (CSD) of t wo
signals.
pburg Power spect r um est imat e using t he Bur g met hod.
pcov Power spect r um est imat e using t he covar iance
met hod.
pmcov Power spect r um est imat e using t he modified
covar iance met hod.
pmtm Power spect r um est imat e using t he mult it aper
met hod (MTM).
pmusic Power spect r um est imat e using MUSIC eigenvect or
met hod.
pyulear Power spect r um est imat e using Yule-Walker AR
met hod.
specgram Time-dependent fr equency analysis (spect r ogr am).
tfe Tr ansfer funct ion est imat e fr om input and out put .
pwelch
6-277
References [1] Rabiner , L.R., and B. Gold. Theory and Application of Digital S ignal
Processing. Englewood Cliffs, NJ : Pr ent ice Hall, 1975. Pgs. 399-419.
[2] Welch, P.D. The Use of Fast Four ier Tr ansfor m for t he Est imat ion of Power
Spect r a: A Met hod Based on Time Aver aging Over Shor t , Modified
Per iodogr ams. IEEE Trans. Audio Electroacoust. Vol. AU-15 (J une 1967).
Pgs. 70-73.
[3] Oppenheim, A.V., and R.W. Schafer . Discrete-Time S ignal Processing.
Englewood Cliffs, NJ : Pr ent ice Hall, 1989. Pgs. 311-312.
pyulear
6-278
6pyulear
Purpose Power spect r um est imat e using Yule-Walker AR met hod.
Syntax Pxx = pyulear(x,p,nfft)
[Pxx,freq] = pyulear(x,p,nfft)
[Pxx,freq] = pyulear(x,p,nfft,Fs)
[Pxx,freq] = pyulear(x,p,nfft,Fs,'range')
pyulear(...)
pyulear(...,'squared')
Description pyulear est imat es t he power spect r al densit y (PSD) of t he signal vect or x[n]
using t he Yule-Walker AR met hod. This met hod, also called t he
aut ocor r elat ion met hod, fit s an aut or egr essive (AR) model t o t he signal by
minimizing t he for war d pr edict ion er r or in t he least -squar es sense. This
for mulat ion leads t o t he Yule-Walker equat ions, which ar e solved by t he
Levinson-Dur bin r ecur sion. The spect r al est imat e r et ur ned by pyulear is t he
magnit ude squar ed fr equency r esponse of t his AR model. The cor r ect choice of
t he model or der p is impor t ant .
Pxx = pyulear(x,p,nfft) r et ur ns Pxx, t he power spect r um est imat e. x is t he
input signal, p is t he model or der for t he all-pole filt er , and nfft is t he FFT
lengt h (default s t o 256 if not specified). Pxx has lengt h (nfft/2+1) for nfft
even, (nfft+1)/2 for nfft odd, and nfft if x is complex.
[Pxx,freq] = pyulear(x,p,nfft) r et ur ns Pxx, t he power spect r um
est imat e, and freq, a vect or of fr equencies at which t he PSD was est imat ed. If
t he input signal is r eal-valued, t he r ange of freq is [0,). If t he input signal is
complex, t he r ange of freq is [0,2).
[Pxx,freq] = pyulear(x,p,nfft,Fs) uses t he signals sampling fr equency,
Fs, t o scale bot h t he PSD vect or (Pxx) and t he fr equency vect or (freq). Pxx is
scaled by 1/Fs. If t he input signal is r eal-valued, t he r ange of freq is [0,Fs/2).
If t he input signal is complex, t he r ange of freq is [0,Fs). Fs default s t o 1 if
left empt y, [].
[Pxx,freq] = pyulear(x,p,nfft,Fs,'range') specifies t he r ange of
fr equency values t o include in freq. range can be:
half, t o comput e t he PSD over t he r ange [0,Fs/2) for r eal x, and [0,Fs) for
complex x. If Fs is left blank, [], t he r ange is [0,1/2) for r eal x, and [0,1)
pyulear
6-279
for complex x. If Fs is omit t ed ent ir ely, t he r ange is [0,pi) for r eal x, and
[0,2*pi) for complex x. half is t he default r ange.
whole, t o comput e t he PSD over t he r ange [0,Fs) for all x. If Fs is left
blank, [], t he r ange is [0,1) for all x. If Fs is omit t ed ent ir ely, t he r ange is
[0,2*pi) for all x.
pyulear(...) plot s t he power spect r al densit y in t he fir st available figur e
window. The fr equency r ange on t he plot is t he same as t he r ange of out put
freq for a given set of par amet er s.
pyulear(...,'squared') plot s t he magnit ude of Pxx dir ect ly, r at her t han
comnver t ing t he values t o dB.
Example Since t he met hod est imat es t he spect r um by fit t ing an AR model t o t he signal,
fir st define t he AR syst em (all-pole filt er ) t hat gener at es t he input . Check t he
magnit ude r esponse of t he pr ocess wit h freqz.
a = [1 2.2137 2.9403 2.1697 0.9606]; % AR system coefficients
freqz(1,a,'phase','no') % AR system magnitude response
title('AR System Magnitude Response')
0 0.2 0.4 0.6 0.8 1
20
10
0
10
20
30
40
Normalized Angular Frequency ( rads/sample)
M
a
g
n
i
t
u
d
e

(
d
B
)
AR System Magnitude Response
pyulear
6-280
Now gener at e t he input signal x by filt er ing whit e noise t hr ough t he AR
syst em. Est imat e t he PSD of x based on a four t h-or der AR model (since we
know t hat t he or iginal AR syst em, a, has or der 4).
x = filter(1,a,randn(150,1)); % AR system output
pyulear(x,4) % 4th order estimate
Diagnostics The fir st input ar gument must be a full vect or ; ot her wise pyulear gener at es
t he following er r or message:
Input signal cannot be sparse.
If you specify an empt y mat r ix for t he second ar gument , pyulear gener at es t he
following er r or message:
Model order must be an integer.
0 0.2 0.4 0.6 0.8 1
10
5
0
5
10
15
20
25
Normalized Angular Frequency ( rads/sample)
P
o
w
e
r

S
p
e
c
t
r
a
l

D
e
n
s
i
t
y

(
d
B
)
YuleWalker Spectral Estimate P
xx
()
pyulear
6-281
See Also
References [1] Mar ple, S.L. Digital S pectral Analysis. Englewood Cliffs, NJ : Pr ent ice Hall,
1987. Chapt er 7.
aryule Comput e an est imat e of AR model par amet er s using
t he Yule-Walker met hod.
lpc Linear pr edict ion coefficient s.
pburg Power spect r um est imat e using t he Bur g met hod.
pcov Power spect r um est imat e using t he covar iance
met hod.
pmcov Power spect r um est imat e using t he modified
covar iance met hod.
pmtm Power spect r um est imat e using t he mult it aper
met hod (MTM).
pmusic Power spect r um est imat e using MUSIC eigenvect or
met hod.
prony Pr onys met hod for t ime domain IIR filt er design.
pwelch Est imat e t he power spect r al densit y (PSD) of a signal
using Welchs met hod.
rc2ac
6-282
6rc2ac
Purpose Conver sion of r eflect ion coefficient s t o aut ocor r elat ion sequence.
Syntax r = rc2ac(k,r0)
Description r = rc2ac(k,r0) finds t he aut ocor r elat ion coefficient s, r, of t he discr et e filt er
wit h r eflect ion coefficient s k and zer o-lag aut ocor r elat ion r0.
See Also
References [1] Kay, S.M. Modern S pectral Estimation. Englewood Cliffs, NJ :
Pr ent ice-Hall, 1988.
ac2rc Conver sion of aut ocor r elat ion sequence t o r eflect ion
coefficient s.
poly2ac Conver sion of pr edict ion polynomial t o
aut ocor r elat ion sequence.
rc2poly Conver sion of r eflect ion coefficient s t o pr edict ion
polynomial.
rc2poly
6-283
6rc2poly
Purpose Conver sion of r eflect ion coefficient s t o pr edict ion polynomial.
Syntax a = rc2poly(k)
[a,efinal] = rc2poly(k,r0)
Description a = rc2poly(k) finds t he pr edict ion polynomial a, wit h a(1) = 1, fr om t he
r eflect ion coefficient s k of t he cor r esponding lat t ice st r uct ur e. Out put a is r ow
vect or of lengt h k + 1.
[a,efinal] = rc2poly(k,r0) r et ur ns t he final pr edict ion er r or , efinal,
based on t he zer o-lag aut ocor r elat ion, r0.
Example Consider an IIR filt er given by r eflect ion coefficient s k:
k = [0.3090 0.9800 0.0031 0.0082 0.0082];
It s polynomial r epr esent at ion is
a = rc2poly(k)
a =
1.0000 0.6148 0.9899 0.0000 0.0032 0.0082
Algorithm rc2poly comput es out put a using Levinsons r ecur sion [1]. The funct ion:
1 Set s t he out put vect or a t o t he fir st element of k
2 Loops t hr ough t he r emaining element s of k
For each loop it er at ion i, a = [a + a(i1:1:1)*k(i) k(i)].
3 Implement s a = [1 a]
rc2poly
6-284
See Also
References [1] Kay, S.M. Modern S pectral Estimation. Englewood Cliffs, NJ :
Pr ent ice-Hall, 1988.
ac2poly Conver sion of aut ocor r elat ion sequence t o pr edict ion
polynomial.
latc2tf Lat t ice filt er t o t r ansfer funct ion conver sion.
latcfilt Lat t ice and lat t ice-ladder filt er implement at ion.
poly2rc Conver sion of pr edict ion polynomial t o r eflect ion
coefficient s.
rc2ac Conver sion of r eflect ion coefficient s t o
aut ocor r elat ion sequence.
tf2latc Conver sion of t r ansfer funct ion t o lat t ice filt er.
rceps
6-285
6rceps
Purpose Real cepst r um and minimum phase r econst r uct ion.
Syntax y = rceps(x)
[y,ym] = rceps(x)
Description The real cepstrum is t he inver se Four ier t r ansfor m of t he r eal logar it hm of t he
magnit ude of t he Four ier t r ansfor m of a sequence.
rceps(x) r et ur ns t he r eal cepst r um of t he r eal sequence x. The r eal cepst r um
is a r eal-valued funct ion.
[y,ym] = rceps(x) r et ur ns bot h t he r eal cepst r um y and a minimum phase
r econst r uct ed ver sion ym of t he input sequence.
Algorithm rceps is an M-file implement at ion of algor it hm 7.2 in [2], t hat is:
y = real(ifft(log(abs(fft(x)))));
Appr opr iat e windowing in t he cepst r al domain for ms t he r econst r uct ed
minimum phase signal:
w = [1; 2*ones(n/21,1); ones(1 rem(n,2),1); zeros(n/21,1)];
ym = real(ifft(exp(fft(w.*y))));
See Also
References [1] Oppenheim, A.V., and R.W. Schafer . Digital S ignal Processing. Englewood
Cliffs, NJ : Pr ent ice Hall, 1975.
[2] IEEE. Programs for Digital S ignal Processing. IEEE Pr ess. New Yor k: J ohn
Wiley & Sons, 1979.
cceps Complex cepst r al analysis.
fft One-dimensional fast Four ier t r ansfor m.
hilbert Hilber t t r ansfor m.
icceps Inver se complex cepst r um.
unwrap Unwr ap phase angles.
rectpuls
6-286
6rect puls
Purpose Sampled aper iodic r ect angle gener at or .
Syntax y = rectpuls(t)
y = rectpuls(t,w)
Description y = rectpuls(t) r et ur ns a cont inuous, aper iodic, unit y-height r ect angular
pulse at t he sample t imes indicat ed in ar r ay t, cent er ed about t = 0 and wit h
a default widt h of 1. Not e t hat t he int er val of non-zer o amplit ude is defined t o
be open on t he r ight , t hat is, rectpuls(0.5) = 1 while rectpuls(0.5) = 0.
y = rectpuls(t,w) gener at es a r ect angle of widt h w.
rectpuls is t ypically used in conjunct ion wit h t he pulse t r ain gener at ing
funct ion, pulstran.
See Also
chirp Swept -fr equency cosine gener at or.
cos Cosine of vect or /mat r ix element s (see t he online
MATLAB Function Reference).
diric Dir ichlet or per iodic sinc funct ion.
gauspuls Gaussian-modulat ed sinusoidal pulse gener at or.
pulstran Pulse t r ain gener at or.
sawtooth Sawt oot h or t r iangle wave gener at or.
sin Sine of vect or /mat r ix element s (see t he online
MATLAB Function Reference).
sinc Sinc or sin(t )/t funct ion.
square Squar e wave gener at or.
tripuls Sampled aper iodic t r iangle gener at or.
remez
6-287
6remez
Purpose Par ks-McClellan opt imal FIR filt er design.
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 designs a linear -phase FIR filt er using t he Par ks-McClellan
algor it hm [1]. The Par ks-McClellan algor it hm uses t he Remez exchange
algor it hm and Chebyshev appr oximat ion t heor y t o design filt er s wit h an
opt imal fit bet ween t he desir ed and act ual fr equency r esponses. The filt er s ar e
opt imal in t he sense t hat t he maximum er r or bet ween t he desir ed fr equency
r esponse and t he act ual fr equency r esponse is minimized. Filt er s designed t his
way exhibit an equir ipple behavior in t heir fr equency r esponses and hence ar e
somet imes called equiripple filt er s.
b = remez(n,f,a) r et ur ns r ow vect or b cont aining t he n+1 coefficient s of t he
or der n FIR filt er whose fr equency-amplit ude char act er ist ics mat ch t hose
given by vect or s f and a.
The out put filt er coefficient s (t aps) in b obey t he symmet r y r elat ion
Vect or s f and a specify t he fr equency-magnit ude char act er ist ics of t he filt er :
b k ( ) b n 2 k + ( ) k 1 = n 1 + , , , =
remez
6-288
f is a vect or of pair s of fr equency point s, specified in t he r ange bet ween 0 and
1, wher e 1 cor r esponds t o half t he sampling fr equency (t he Nyquist
fr equency). The fr equencies must be in incr easing or der .
a is a vect or cont aining t he desir ed amplit udes at t he point s specified in f.
The desir ed amplit ude at fr equencies bet ween pair s of point s (f(k), f(k+1)) for
k odd is t he line segment connect ing t he point s (f(k), a(k)) and (f(k+1),
a(k+1)).
The desir ed amplit ude at fr equencies bet ween pair s of point s (f(k), f(k+1)) for
k even is unspecified. The ar eas bet ween such point s ar e t r ansit ion or dont
car e r egions.
f and a must be t he same lengt h. The lengt h must be an even number .
The r elat ionship bet ween t he f and a vect or s in defining a desir ed fr equency
r esponse is shown below:
remez(n,f,a,w) uses t he weight s in vect or w t o weight t he fit in each fr equency
band. The lengt h of w is half t he lengt h of f and a, so t her e is exact ly one weight
per band.
b = remez(n,f,a,'ftype') and
b = remez(n,f,a,w,'ftype') specify a filt er t ype, wher e ftype is
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
6-289
hilbert, for linear -phase filt er s wit h odd symmet r y (t ype III and t ype IV)
The out put coefficient s in b obey t he r elat ion b(k) =-b(n +2 -k), k = 1,...,n + 1.
This class of filt er s includes t he Hilber t t r ansfor mer , which has a desir ed
amplit ude of 1 acr oss t he ent ir e band.
For example,
h = remez(30,[0.1 0.9],[1 1],'hilbert');
designs an appr oximat e FIR Hilber t t r ansfor mer of lengt h 31.
differentiator, for t ype III and IV filt er s, using a special weight ing
t echnique
For nonzer o amplit ude bands, it weight s t he er r or by a fact or of 1/f so t hat
t he er r or at low fr equencies is much smaller t han at high fr equencies. For
FIR differ ent iat or s, which have an amplit ude char act er ist ic pr opor t ional t o
fr equency, t hese filt er s minimize t he maximum r elat ive er r or (t he maximum
of t he r at io of t he er r or t o t he desir ed amplit ude).
b = remez(...,{lgrid}) uses t he int eger lgrid t o cont r ol t he densit y of t he
fr equency gr id, which has r oughly (lgrid*n)/(2*bw) fr equency point s, wher e
bw is t he fr act ion of t he t ot al fr equency band int er val [0,1] cover ed by f.
Incr easing lgrid oft en r esult s in filt er s t hat ar e mor e exact ly equir ipple, but
which t ake longer t o comput e. The default value of 16 is t he minimum value
t hat should be specified for lgrid. Not e t hat t he {lgrid} ar gument must be a
1-by-1 cell ar r ay.
b = remez(n,f,'fresp',w) r et ur ns r ow vect or b cont aining t he n+1
coefficient s of t he or der n FIR filt er whose fr equency-amplit ude char act er ist ics
best appr oximat e t he r esponse specified by funct ion fresp. The funct ion is
called fr om wit hin remez wit h t he following synt ax:
[dh,dw] = fresp(n,f,gf,w)
The ar gument s ar e similar t o t hose for remez:
n is t he filt er or der .
f is t he vect or of fr equency band edges t hat appear monot onically bet ween
0 and 1, wher e 1 is t he Nyquist fr equency.
gf is a vect or of gr id point s t hat have been linear ly int er polat ed over each
specified fr equency band by remez. gf det er mines t he fr equency gr id at
remez
6-290
which t he r esponse funct ion must be evaluat ed, and cont ains t he same dat a
r et ur ned by cremez in t he fgrid field of t he opt st r uct ur e.
w is a vect or of r eal, posit ive weight s, one per band, used dur ing opt imizat ion.
w is opt ional in t he call t o remez; if not specified, it is set t o unit y weight ing
befor e being passed t o 'fresp'.
dh and dw ar e t he desir ed complex fr equency r esponse and band weight
vect or s, r espect ively, evaluat ed at each fr equency in gr id gf.
The pr edefined fr equency r esponse funct ion (fresp) t hat remez calls is
remezfrf in t he signal/private dir ect or y.
b = remez(n,f,{'fresp',p1,p2,...},w) allows you t o specify addit ional
par amet er s (p1, p2, et c.) t o pass t o fresp. Not e t hat b = remez(n,f,a,w) is a
synonym for b = remez(n,f,{'remezfrf',a},w), wher e a is a vect or
cont aining t he desir ed amplit udes at t he point s specified in f.
b = remez(n,f,'fresp',w,'ftype') and
b = remez(n,f,{'fresp',p1,p2,...},w,'ftype') design ant isymmet r ic
(odd) r at her t han symmet r ic (even) filt er s, wher e 'ftype' is eit her 'd' for a
differ ent iat or or 'h' for a Hilber t t r ansfor mer .
In t he absence of a specificat ion for ftype, a pr eliminar y call is made t o fresp
t o det er mine t he default symmet r y pr oper t y sym. This call is made using t he
synt ax:
sym = fresp('defaults',{n,f,[],w,p1,p2,...})
The ar gument s n, f, w, et c., may be used as necessar y in det er mining an
appr opr iat e value for sym, which remez expect s t o be eit her 'even' or 'odd'. If
t he fresp funct ion does not suppor t t his calling synt ax, remez default s t o even
symmet r y.
[b,delta] = remez(...) r et ur ns t he maximum r ipple height in delta.
remez
6-291
[b,delta,opt] = remez(...) r et ur ns a st r uct ur e, opt, of opt ional r esult s
wit h t he following fields.
Example Gr aph t he desir ed and act ual fr equency r esponses of a 17t h-or der
Par ks-McClellan bandpass filt er :
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))
opt.fgrid Fr equency gr id vect or used for t he filt er design opt imizat ion
opt.des Desir ed fr equency r esponse for each point in opt.fgrid
opt.wt Weight ing for each point in opt.fgrid
opt.H Act ual fr equency r esponse for each point in opt.fgrid
opt.error Er r or at each point in opt.fgrid (opt.desopt.H)
opt.iextr Vect or of indices int o opt.fgrid for ext r emal fr equencies
opt.fextr Vect or of ext r emal fr equencies
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
remez
6-292
Algorithm remez is a MEX-file ver sion of t he or iginal For t r an code fr om [1], alt er ed t o
design ar bit r ar ily long filt er s wit h ar bit r ar ily many linear bands.
remez designs t ype I, II, III, and IV linear -phase filt er s. Type I and Type II ar e
t he default s for n even and n odd, r espect ively, while Type III (n even) and
Type IV (n odd) ar e obt ained wit h t he 'hilbert' and 'differentiator' flags.
The differ ent t ypes of filt er s have differ ent symmet r ies and cer t ain const r aint s
on t heir fr equency r esponses (see [5] for mor e det ails).
Diagnostics An appr opr iat e diagnost ic message is displayed if incor r ect ar gument s ar e
used:
Filter order must be 3 or more.
There should be one weight per band.
Frequency and amplitude vectors must be the same length.
The number of frequency points must be even.
Frequencies must lie between 0 and 1.
Frequencies must be specified in bands.
Frequencies must be nondecreasing.
Adjacent bands not allowed.
A mor e ser ious war ning message is
Failure to Converge
Probable cause is machine rounding error.
In t he r ar e event t hat you see t his message, it is possible t hat t he filt er design
may st ill be cor r ect . Ver ify t he design by checking it s fr equency r esponse.
Linear
Phase
Filter Type
Filter
Order n Symmetry of Coefficients
Response H(f),
f = 0
Response H(f),
f = 1 (Nyquist)
Type I Even even: No r est r ict ion No r est r ict ion
Type II Odd No r est r ict ion H(1) = 0
Type III Even odd: H(0) = 0 H(1) = 0
Type IV Odd H(0) = 0 No r est r ict ion
b k ( ) b n 2 k + ( ) k 1 = n 1 + , , , =
b k ( ) b n 2 k + ( ) k 1 = n 1 + , , , =
remez
6-293
See Also
References [1] IEEE. Programs for Digital S ignal Processing. IEEE Pr ess. New Yor k: J ohn
Wiley & Sons, 1979. Algor it hm 5.1.
[2] IEEE. S elected Papers in Digital S ignal Processing, II. IEEE Pr ess. New
Yor k: J ohn Wiley & Sons, 1979.
[3] Par ks, T.W., and C.S. Bur r us. Digital Filter Design. New Yor k: J ohn Wiley
& Sons, 1987. Pg. 83.
[4] Rabiner , L.R., J .H. McClellan, and T.W. Par ks. FIR Digit al Filt er Design
Techniques Using Weight ed Chebyshev Appr oximat ions. Proc. IEEE 63
(1975).
[5] Oppenheim, A.V., and R.W. Schafer . Discrete-Time S ignal Processing.
Englewood Cliffs, NJ : Pr ent ice Hall, 1989. Pgs. 256-266.
butter But t er wor t h analog and digit al filt er design.
cheby1 Chebyshev t ype I filt er design (passband r ipple).
cheby2 Chebyshev t ype II filt er design (st opband r ipple).
cremez Complex and nonlinear-phase equir ipple FIR filt er
design.
ellip Ellipt ic (Cauer ) filt er design.
fir1 Window-based finit e impulse r esponse filt er design
st andar d r esponse.
fir2 Window-based finit e impulse r esponse filt er design
ar bit r ar y r esponse.
fircls Const r ained least squar e FIR filt er design for
mult iband filt er s.
fircls1 Const r ained least squar e filt er design for lowpass
and highpass linear phase FIR filt er s.
firls Least squar e linear-phase FIR filt er design.
firrcos Raised cosine FIR filt er design.
remezord Par ks-McClellan opt imal FIR filt er or der est imat ion.
yulewalk Recur sive digit al filt er design.
remezord
6-294
6remezor d
Purpose Par ks-McClellan opt imal FIR filt er or der est imat ion.
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) finds t he appr oximat e or der , nor malized
fr equency band edges, fr equency band amplit udes, and weight s t hat meet
input specificat ions f, a, and dev, t o use wit h t he remez command.
f is a vect or of fr equency band edges (bet ween 0 and Fs/2, wher e Fs is t he
sampling fr equency), and a is a vect or specifying t he desir ed amplit ude on
t he bands defined by f. The lengt h of f is t wice t he lengt h of a, minus 2. The
desir ed funct ion is piecewise const ant .
dev is a vect or t he same size as a t hat specifies t he maximum allowable
deviat ion or r ipples bet ween t he fr equency r esponse and t he desir ed
amplit ude of t he out put filt er , for each band.
Use remez wit h t he r esult ing or der n, fr equency vect or fo, amplit ude r esponse
vect or ao, and weight s w t o design t he filt er b which appr oximat ely meet s t he
specificat ions given by remezord input par amet er s f, a, and dev:
b = remez(n,fo,ao,w)
[n,fo,ao,w] = remezord(f,a,dev,Fs) specifies a sampling fr equency Fs.
Fs default s t o 2 Hz, implying a Nyquist fr equency of 1 Hz. You can t her efor e
specify band edges scaled t o a par t icular applicat ions sampling fr equency.
In some cases remezord under est imat es t he or der n. If t he filt er does not meet
t he specificat ions, t r y a higher or der such as n+1 or n+2.
c = remezord(f,a,dev,Fs,'cell') specifies a cell-ar r ay whose element s ar e
t he par amet er s t o remez.
Examples Design a minimum-or der lowpass filt er wit h a 500 Hz passband cut off
fr equency and 600 Hz st opband cut off fr equency, wit h a sampling fr equency of
remezord
6-295
2000 Hz), at least 40 dB at t enuat ion in t he st opband, and less t han 3 dB of
r ipple in t he passband:
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);
[h,f] = freqz(b,1,1024,Fs);
plot(f,20*log10(abs(h)));
title('Lowpass Filter Designed to Specifications');
xlabel('Frequency (Hz)'); ylabel('Magnitude (dB)'); grid;
Not e t hat t he filt er falls slight ly shor t of meet ing t he st opband at t enuat ion and
passband r ipple specificat ions. Using n+1 in t he call t o remez inst ead of n
achieves t he desir ed amplit ude char act er ist ics.
0 100 200 300 400 500 600 700 800 900 1000
-60
-50
-40
-30
-20
-10
0
10
Frequency (Hz)
M
a
g
n
i
t
u
d
e

(
d
B
)
Lowpass Filter Designed to Specifications
remezord
6-296
Design a lowpass filt er wit h a 1500 Hz passband cut off fr equency and 2000 Hz
st opband cut off fr equency, wit h a sampling fr equency of 8000 Hz, a maximum
st opband amplit ude of 0.1, and a maximum passband er r or (r ipple) of 0.01:
[n,fo,ao,w] = remezord( [1500 2000], [1 0], [0.01 0.1], 8000 );
b = remez(n,fo,ao,w);
This is equivalent t o
c = remezord( [1500 2000], [1 0], [0.01 0.1], 8000, 'cell');
b = remez(c{:});
NOTE In some cases, remezord under est imat es or over est imat es t he or der n.
If t he filt er does not meet t he specificat ions, t r y a higher or der such as n+1
or n+2.
Result s ar e inaccur at e if t he cut off fr equencies ar e near 0 or t he Nyquist
fr equency.
Algorithm remezord uses t he algor it hm suggest ed in [1]. This met hod is inaccur at e for
band edges close t o eit her 0 or t he Nyquist fr equency (Fs/2).
Diagnostics If t he input par amet er lengt hs ar e not consist ent , remezord gives t he following
er r or messages:
Requires M and DEV to be the same length.
Length of F must be length(M)2.
See Also
buttord But t er wor t h filt er or der select ion.
cheb1ord Chebyshev t ype I filt er or der select ion.
cheb2ord Chebyshev t ype II filt er or der select ion.
ellipord Ellipt ic filt er or der select ion.
kaiserord Est imat e par amet er s for an FIR filt er design wit h
Kaiser window.
remez Par ks-McClellan opt imal FIR filt er design.
remezord
6-297
References [1] Rabiner , L.R., and O. Her r mann. The Pr edict abilit y of Cer t ain Opt imum
Finit e Impulse Response Digit al Filt er s. IEEE Trans. on Circuit Theory.
Vol. CT-20, No. 4 (J uly 1973). Pgs. 401-408.
[2] Rabiner , L.R., and B. Gold. Theory and Application of Digital S ignal
Processing. Englewood Cliffs, NJ : Pr ent ice Hall, 1975. Pgs. 156-157.
resample
6-298
6resample
Purpose Change sampling r at e by any r at ional fact or .
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) r esamples t he sequence in vect or x at p/q t imes t he
or iginal sampling r at e, using a polyphase filt er implement at ion. The lengt h of
y is equal t o ceil(length(x)*p/q). p and q must be posit ive int eger s. If x is a
mat r ix, resample wor ks down t he columns of x.
resample applies an ant i-aliasing (lowpass) FIR filt er t o x dur ing t he
r esampling pr ocess. It designs t he filt er using firls wit h a Kaiser window.
y = resample(x,p,q,n) uses n t er ms on eit her side of t he cur r ent sample,
x(k), t o per for m t he r esampling. The lengt h of t he FIR filt er resample uses is
pr opor t ional t o n; lar ger values of n pr ovide bet t er accur acy at t he expense of
mor e comput at ion t ime. The default for n is 10. If you let n = 0, resample
per for ms a near est -neighbor int er polat ion:
y(k) = x(round((k-1)*q/p)+1)
wher e y(k) = 0 if t he index t o x is gr eat er t han length(x).
y = resample(x,p,q,n,beta) uses beta as t he design par amet er for t he
Kaiser window t hat resample employs in designing t he lowpass filt er . The
default for beta is 5.
y = resample(x,p,q,b) filt er s x wit h b, a vect or of filt er coefficient s.
[y,b] = resample(x,p,q) r et ur ns t he vect or b, which cont ains t he
coefficient s of t he filt er applied t o x dur ing t he r esampling pr ocess.
resample
6-299
Examples Resample a simple linear sequence at 3/2 t he or iginal r at e:
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')
Not ice t hat t he last few point s of t he out put y ar e inaccur at e. In it s filt er ing
pr ocess, resample assumes t he samples at t imes befor e and aft er t he given
samples in x ar e equal t o zer o. Thus lar ge deviat ions fr om zer o at t he end
0.5 0 0.5 1 1.5
0.5
0
0.5
1
1.5
Time
original
resampled
resample
6-300
point s of t he sequence x can cause inaccur acies in y at it s end point s. The
following t wo plot s illust r at e t his side 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');
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');
Diagnostics If p or q ar e not posit ive int eger s, resample gives t he appr opr iat e er r or
message:
P must be a positive integer.
Q must be a positive integer.
If x is not a vect or , resample gives t he following er r or message:
Input X must be a vector.
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
resample
6-301
See Also
decimate Decr ease t he sampling r at e for a sequence
(decimat ion).
firls Least squar e linear-phase FIR filt er design.
interp Incr ease sampling r at e by an int eger fact or
(int er polat ion).
interp1 One-dimensional dat a int er polat ion (t able lookup)
(see t he online MATLAB Function Reference).
intfilt Int er polat ion FIR filt er design.
kaiser Kaiser window.
spline Cubic spline int er polat ion (see t he online MATLAB
Function Reference).
upfirdn Upsample, apply an FIR filt er, and downsample.
residuez
6-302
6residuez
Purpose z-t r ansfor m par t ial-fr act ion expansion.
Syntax [r,p,k] = residuez(b,a)
[b,a] = residuez(r,p,k)
Description residuez conver t s a discr et e t ime syst em, expr essed as t he r at io of t wo
polynomials, t o par t ial fr act ion expansion, or r esidue, for m. It also conver t s t he
par t ial fr act ion expansion back t o t he or iginal polynomial coefficient s.
[r,p,k] = residuez(b,a) finds t he r esidues, poles, and dir ect t er ms of a
par t ial fr act ion expansion of t he r at io of t wo polynomials, b(z) and a(z). Vect or s
b and a specify t he coefficient s of t he polynomials of t he discr et e-t ime syst em
b(z)/ a(z) in descending power s of z:
If t her e ar e no mult iple r oot s and a > n1,
The r et ur ned column vect or r cont ains t he r esidues, column vect or p cont ains
t he pole locat ions, and r ow vect or k cont ains t he dir ect t er ms. The number of
poles is
n = length(a)1 = length(r) = length(p)
The dir ect t er m coefficient vect or k is empt y if length(b) < length(a);
ot her wise
length(k) = length(b) length(a) + 1
If p(j) = ... = p(j+s1) is a pole of mult iplicit y s, t hen t he expansion
includes t er ms of t he for m
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
6-303
[b,a] = residuez(r,p,k) wit h t hr ee input ar gument s and t wo out put
ar gument s, conver t s t he par t ial fr act ion expansion back t o polynomials wit h
coefficient s in r ow vect or s b and a.
The residue funct ion in t he st andar d MATLAB language is ver y similar t o
residuez. It comput es t he par t ial fr act ion expansion of cont inuous-t ime
syst ems in t he Laplace domain (see r efer ence [1]), r at her t han discr et e-t ime
syst ems in t he z-domain as does residuez.
Algorithm residuez applies st andar d MATLAB funct ions and par t ial fr act ion t echniques
t o find r, p, and k fr om b and a. It finds:
1 The dir ect t er ms a using deconv (polynomial long division) when
length(b)>length(a)1.
2 The poles using p = roots(a). mpoles finds r epeat ed poles and r eor der s t he
poles accor ding t o t heir mult iplicit ies.
3 The r esidue for each nonr epeat ing pole p
i
by mult iplying b(z)/ a(z) by
1/(1-p
i
z
-1
) and evaluat ing t he r esult ing r at ional funct ion at z = p
i
.
4 The r esidues for t he r epeat ed poles by solving
S2*r2 = h S1*r1
for r2 using \. h is t he impulse r esponse of t he r educed b(z)/ a(z), S1 is a
mat r ix whose columns ar e impulse r esponses of t he fir st -or der syst ems
made up of t he nonr epeat ing r oot s, and r1 is a column cont aining t he
r esidues for t he nonr epeat ing r oot s. Each column of mat r ix S2 is an impulse
r esponse. For each r oot p
j
of mult iplicit y s
j
, S2 cont ains s
j
columns
r epr esent ing t he impulse r esponses of each of t he following syst ems:
The vect or h and mat r ices S1 and S2 have n + xtra r ows, wher e n is t he t ot al
number of r oot s and t he int er nal par amet er xtra, set t o 1 by default ,
det er mines t he degr ee of over det er minat ion of t he syst em of equat ions.
Diagnostics If a(1) == 0 while comput ing t he par t ial fr act ion decomposit ion using
[r,p,k] = residuez(b,a), residuez gives t he following er r or message:
First coefficient in A vector must be nonzero.
1
1 pj z
1

-----------------------
1
1 pj z
1
( )
2
------------------------------- L
1
1 pj z
1
( )
s
j
-------------------------------- , , ,
residuez
6-304
If t he number of r esidues r and poles p is not t he same, residuez gives t he
following er r or message:
R and P vectors must be the same size.
See Also
References [1] Oppenheim, A.V., and R.W. Schafer . Digital S ignal Processing. Englewood
Cliffs, NJ : Pr ent ice Hall, 1975. Pgs. 166-170.
convmtx Convolut ion mat r ix.
deconv Deconvolut ion and polynomial division (see t he
online MATLAB Function Reference).
poly Polynomial wit h specified r oot s (see t he online
MATLAB Function Reference).
prony Pr onys met hod for t ime domain IIR filt er design.
residue Par t ial fr act ion expansion (see t he online MATLAB
Function Reference).
roots Polynomial r oot s (see t he online MATLAB Function
Reference).
ss2tf Conver sion of st at e-space t o zer o-pole-gain.
tf2ss Conver sion of t r ansfer funct ion t o st at e-space.
tf2zp Conver sion of t r ansfer funct ion t o zer o-pole-gain.
zp2ss Conver sion of zer o-pole-gain t o st at e-space.
rlevinson
6-305
6rlevinson
Purpose Rever se Levinson-Dur bin r ecur sion.
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 r ever se Levinson-Dur bin r ecur sion implement s t he st ep-down algor it hm
for solving t he following symmet r ic Toeplit z syst em of linear equat ions for r,
wher e r = [r(1) ... r(p+1)] and r(i)
*
denot es t he complex conjugat e of r(i).
r = rlevinson(a,efinal) solves t he above syst em of equat ions for r given
vect or a, wher e a = [1 a(2) ... a(p+1)]. In linear pr edict ion applicat ions, r
r epr esent s t he aut ocor r elat ion sequence of t he input t o t he pr edict ion er r or
filt er , wher e r(1) is t he zer o-lag element . The figur e below shows t he t ypical
filt er of t his t ype, wher e H(z) is t he opt imal linear pr edict or , x(n) is t he input
signal, is t he pr edict ed signal, and e(n) is t he pr edict ion er r or .
Input vect or a r epr esent s t he polynomial coefficient s of t his pr edict ion er r or
filt er in descending power s 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 Filter
A z ( )
A z ( ) 1 a 2 ( )z
1
L a n 1 + ( )z
p
+ + + =
rlevinson
6-306
The filt er must be minimum phase t o gener at e a valid aut ocor r elat ion
sequence. efinal is t he scalar pr edict ion er r or power , which is equal t o t he
var iance of t he pr edict ion er r or signal,
2
(e).
[r,u] = rlevinson(a,efinal) r et ur ns upper t r iangular mat r ix U fr om t he
UDU
*
decomposit ion
wher e
and E is a diagonal mat r ix wit h element s r et ur ned in out put e (see below). This
decomposit ion per mit s t he efficient evaluat ion of t he inver se of t he
aut ocor r elat ion mat r ix, R
-1
.
Out put mat r ix u cont ains t he pr edict ion polynomial, a, fr om each it er at ion of
t he r ever se Levinson-Dur bin r ecur sion
wher e a
i
(j) is t he jt h coefficient of t he it h or der pr edict ion polynomial (i.e., st ep
i in t he r ecur sion). For example, t he 5t h or der pr edict ion polynomial is
a5 = u(5:-1:1,5)'
Not e t hat u(p+1:-1:1,p+1)' is t he input polynomial coefficient vect or 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 ( )

La
p 1 +
p 1 + ( )

0 a
2
1 ( )

O a
p 1 +
p ( )

0 0 Oa
p 1 +
p 1 ( )

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

=
rlevinson
6-307
[r,u,k] = rlevinson(a,efinal) r et ur ns a vect or k of lengt h (p+1) cont aining
t he r eflect ion coefficient s. The r eflect ion coefficient s ar e t he conjugat es of t he
values in t he fir st r ow of u
k = conj(u(1,2:end))
[r,u,k,e] = rlevinson(a,efinal) r et ur ns a vect or of lengt h (p+1)
cont aining t he pr edict ion er r or s fr om each it er at ion of t he r ever se
Levinson-Dur bin r ecur sion: e(1) is t he pr edict ion er r or fr om t he fir st -or der
model, e(2) is t he pr edict ion er r or fr om t he second-or der model, and so on.
These pr edict ion er r or values for m t he diagonal of t he mat r ix E in t he UDU
*
decomposit ion of R
-1
,
.
See Also
References [1] Kay, S.M. Modern S pectral Estimation: Theory and Application . Englewood
Cliffs, NJ : Pr ent ice Hall, 1988.
R
1
UE
1
U

=
levinson Levinson-Dur bin r ecur sion.
lpc Linear pr edict ion coefficient s.
prony Pr onys met hod for t ime domain IIR filt er design.
stmcb Linear model using St eiglit z-McBr ide it er at ion.
sawtooth
6-308
6sawt oot h
Purpose Sawt oot h or t r iangle wave gener at or .
Syntax x = sawtooth(t)
x = sawtooth(t,width)
Description sawtooth(t) gener at es a sawt oot h wave wit h per iod 2 for t he element s of
t ime vect or t. sawtooth(t) is similar t o sin(t), but it cr eat es a sawt oot h wave
wit h peaks of -1 and 1 inst ead of a sine wave. The sawt oot h wave is defined t o
be -1 at mult iples of 2 and t o incr ease linear ly wit h t ime wit h a slope of 1/ at
all ot her t imes.
sawtooth(t,width) gener at es a modified t r iangle wave wher e width, a scalar
par amet er bet ween 0 and 1, det er mines t he fr act ion bet ween 0 and 2 at which
t he maximum occur s. The funct ion incr eases fr om -1 t o 1 on t he int er val 0 t o
2*width, t hen decr eases linear ly fr om 1 t o -1 on t he int er val 2*width t o 2.
Thus a par amet er of 0.5 specifies a st andar d t r iangle wave, symmet r ic about
t ime inst ant wit h peak-t o-peak amplit ude of 1. sawtooth(t,1) is equivalent
t o sawtooth(t).
Diagnostics If t he width par amet er is not a scalar , sawtooth gives t he following er r or
message:
Requires WIDTH parameter to be a scalar.
See Also
chirp Swept -fr equency cosine gener at or.
cos Cosine of vect or /mat r ix element s (see t he online
MATLAB Function Reference).
diric Dir ichlet or per iodic sinc funct ion.
gauspuls Gaussian-modulat ed sinusoidal pulse gener at or.
pulstran Pulse t r ain gener at or.
rectpuls Sampled aper iodic r ect angle gener at or.
sin Sine of vect or /mat r ix element s (see t he online
MATLAB Function Reference).
sinc Sinc or sin(t )/t funct ion.
square Squar e wave gener at or.
tripuls Sampled aper iodic t r iangle gener at or.
sgolay
6-309
6sgolay
Purpose Savit zky-Golay filt er design.
Syntax b = sgolay(k,f)
b = sgolay(k,f,w)
Description b = sgolay(k,f) designs a Savit zky-Golay FIR smoot hing filt er b. The
polynomial or der k must be less t han t he fr ame size, f, which must be odd. If
k = f1, t he designed filt er pr oduces no smoot hing. The out put , b, is an f-by-f
mat r ix whose r ows r epr esent t he t ime-var ying FIR filt er coefficient s. In a
smoot hing filt er implement at ion (for example, sgolayfilt), t he last (f1)/2
r ows (each an FIR filt er ) ar e applied t o t he signal dur ing t he st ar t up t r ansient ,
and t he fir st (f1)/2 r ows ar e applied t o t he signal dur ing t he t er minal
t r ansient . The cent er r ow is applied t o t he signal in t he st eady st at e.
b = sgolay(k,f,w) specifies a weight ing vect or w wit h lengt h f, which
cont ains t he r eal, posit ive-valued weight s t o be used dur ing t he least -squar es
minimizat ion.
Remarks Savit zky-Golay smoot hing filt er s (also called digit al smoot hing polynomial
filt er s or least squar es smoot hing filt er s) ar e t ypically used t o smoot h out a
noisy signal whose fr equency span (wit hout noise) is lar ge. In t his t ype of
applicat ion, Savit zky-Golay smoot hing filt er s per for m much bet t er t han
st andar d aver aging FIR filt er s, which t end t o filt er out a significant por t ion of
t he signals high fr equency cont ent along wit h t he noise. Alt hough
Savit zky-Golay filt er s ar e mor e effect ive at pr eser ving t he per t inent high
fr equency component s of t he signal, t hey ar e less successful t han st andar d
aver aging FIR filt er s at r eject ing noise.
Savit zky-Golay filt er s ar e opt imal in t he sense t hat t hey minimize t he
least -squar es er r or in fit t ing a polynomial t o each fr ame of noisy dat a.
See Also
fir1 Window-based finit e impulse r esponse filt er design
st andar d r esponse.
firls Least squar e linear-phase FIR filt er design.
filter Filt er dat a wit h a r ecur sive (IIR) or nonr ecur sive
(FIR) filt er.
sgolayfilt Savit zky-Golay filt er ing.
sgolay
6-310
References [1] Or fanidis, S.J . Introduction to S ignal Processing. Englewood Cliffs, NJ :
Pr ent ice Hall, 1996.
sgolayfilt
6-311
6sgolayfilt
Purpose Savit zky-Golay filt er ing.
Syntax y = sgolayfilt(x,k,f)
y = sgolayfilt(x,k,f,w)
Description y = sgolayfilt(x,k,f) applies a Savit zky-Golay FIR smoot hing filt er t o t he
dat a in vect or x. If x is a mat r ix, sgolayfilt oper at es on each column. The
polynomial or der k must be less t han t he fr ame size, f, which must be odd. If
k = f1, t he filt er pr oduces no smoot hing.
y = sgolayfilt(x,k,f,w) specifies a weight ing vect or w wit h lengt h f, which
cont ains t he r eal, posit ive-valued weight s t o be used dur ing t he least -squar es
minimizat ion.
Remarks Savit zky-Golay smoot hing filt er s (also called digit al smoot hing polynomial
filt er s or least -squar es smoot hing filt er s) ar e t ypically used t o smoot h out a
noisy signal whose fr equency span (wit hout noise) is lar ge. In t his t ype of
applicat ion, Savit zky-Golay smoot hing filt er s per for m much bet t er t han
st andar d aver aging FIR filt er s, which t end t o filt er out a significant por t ion of
t he signals high fr equency cont ent along wit h t he noise. Alt hough
Savit zky-Golay filt er s ar e mor e effect ive at pr eser ving t he per t inent high
fr equency component s of t he signal, t hey ar e less successful t han st andar d
aver aging FIR filt er s at r eject ing noise.
Savit zky-Golay filt er s ar e opt imal in t he sense t hat t hey minimize t he
least -squar es er r or in fit t ing a polynomial t o fr ames of noisy dat a.
sgolayfilt
6-312
Example Smoot h t he mtlb signal by applying a cubic Savit zky-Golay filt er t o dat a
fr ames of lengt h 41.
load mtlb % load the data
smtlb = sgolayfilt(mtlb,3,41); % apply the 3rd-order filter
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
References [1] Or fanidis, S.J . Introduction to S ignal Processing. Englewood Cliffs, NJ :
Pr ent ice Hall, 1996.
0 500 1000 1500 2000
4
2
0
2
4
mtlb
0 500 1000 1500 2000
4
2
0
2
4
smtlb
medfilt1 One-dimensional median filt er ing.
filter Filt er dat a wit h a r ecur sive (IIR) or nonr ecur sive
(FIR) filt er.
sgolay Savit zky-Golay filt er design.
sosfilt Second-or der (biquadr at ic) IIR filt er ing.
sinc
6-313
6sinc
Purpose Sinc funct ion.
Syntax y = sinc(x)
Description sinc comput es t he sinc funct ion of an input vect or or ar r ay, wher e t he sinc
funct ion is
This funct ion is t he cont inuous inver se Four ier t r ansfor m of t he r ect angular
pulse of widt h 2 and height 1:
y = sinc(x) r et ur ns an ar r ay y t he same size as x, whose element s ar e t he
sinc funct ion of t he element s of x.
The space of funct ions bandlimit ed in t he fr equency band is spanned
by t he infinit e (yet count able) set of sinc funct ions shift ed by int eger s. Thus any
such bandlimit ed funct ion g(t) can be r econst r uct ed fr om it s samples at int eger
spacings:
sinc t ( )
1 t 0 = ,
t ( ) sin
t
------------------- t 0 ,

'

=
sinc t ( )
1
2
------ e
j t
d

=
[ , ]
g t ( ) g n ( )sinc t n ( )
n =

=
sinc
6-314
Example Per for m ideal bandlimit ed int er polat ion by assuming t hat t he signal t o be
int er polat ed is 0 out side of t he given t ime int er val and t hat it has been sampled
at exact ly t he Nyquist fr equency:
t = (1:10)'; % a column vector of time samples
randn('seed',0);
x = randn(size(t)); % a column vector of data
% ts is times at which to interpolate data
ts = linspace(5,15,600)';
y = sinc(ts(:,ones(size(t))) t(:,ones(size(ts)))')*x;
plot(t,x,'o',ts,y)
-5 0 5 10 15
-1
-0.5
0
0.5
1
1.5
2
sinc
6-315
See Also
chirp Swept -fr equency cosine gener at or.
cos Cosine of vect or /mat r ix element s (see t he online
MATLAB Function Reference).
diric Dir ichlet or per iodic sinc funct ion.
gauspuls Gaussian-modulat ed sinusoidal pulse gener at or.
pulstran Pulse t r ain gener at or.
rectpuls Sampled aper iodic r ect angle gener at or.
sawtooth Sawt oot h or t r iangle wave gener at or.
sin Sine of vect or /mat r ix element s (see t he online
MATLAB Function Reference).
square Squar e wave gener at or.
tripuls Sampled aper iodic t r iangle gener at or.
sos2ss
6-316
6sos2ss
Purpose Conver sion of second-or der sect ions t o st at e-space.
Syntax [A,B,C,D] = sos2ss(sos)
[A,B,C,D] = sos2ss(sos,g)
Description sos2ss conver t s a second-or der sect ion r epr esent at ion of a given syst em t o an
equivalent st at e-space r epr esent at ion.
[A,B,C,D] = sos2ss(sos) conver t s t he syst em sos, in second-or der sect ion
for m, t o a single-input , single-out put st at e-space r epr esent at ion:
The discr et e t r ansfer funct ion in second-or der sect ion for m is given by
sos is a L-by-6 mat r ix or ganized as
The ent r ies of sos must be r eal for pr oper conver sion t o st at e space. The
r et ur ned mat r ix A is size N-by-N, wher e N = 2L-1, B is a lengt h N-1 column
vect or , C is a lengt h N-1 r ow vect or , and D is a scalar .
[A,B,C,D] = sos2ss(sos,g) conver t s t he syst em sos in second-or der sect ion
for m wit h gain 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
2 k
z
2
+ +
1 a
1k
z
1
a
2k
z
2
+ +
--------------------------------------------------------- -
k 1 =
L

= =
s os
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
1 L
b
2L
1 a
1L
a
2L
=
H z ( ) g H
k
z ( )
k 1 =
L

=
sos2ss
6-317
Example Comput e t he st at e-space r epr esent at ion of a simple second-or der sect ion
syst em wit h a gain 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 fir st conver t s fr om second-or der sect ions t o t r ansfer funct ion using
sos2tf, and t hen fr om t r ansfer funct ion t o st at e-space using tf2ss.
See Also
sos2tf Conver sion of second-or der sect ions t o t r ansfer
funct ion.
sos2zp Conver sion of second-or der sect ions t o zer o-pole-gain.
ss2sos Conver sion of st at e-space t o second-or der sect ions.
tf2ss Conver sion of t r ansfer funct ion t o st at e-space.
zp2ss Conver sion of zer o-pole-gain t o st at e-space.
sos2tf
6-318
6sos2t f
Purpose Conver sion of second-or der sect ions t o t r ansfer funct ion.
Syntax [b,a] = sos2tf(sos)
[b,a] = sos2tf(sos,g)
Description sos2tf conver t s a second-or der sect ion r epr esent at ion of a given syst em t o an
equivalent t r ansfer funct ion r epr esent at ion.
[b,a] = sos2tf(sos) r et ur ns t he numer at or coefficient s b and denominat or
coefficient s a of t he t r ansfer funct ion t hat descr ibes a discr et e-t ime syst em
given by sos in second-or der sect ion for m. The second-or der sect ion for mat of
H(z) is given by
sos is an L-by-6 mat r ix t hat cont ains t he coefficient s of each second-or der
sect ion st or ed in it s r ows:
Row vect or s b and a cont ain t he numer at or and denominat or coefficient s of
H(z) st or ed in descending power s of z:
[b,a] = sos2tf(sos,g) r et ur ns t he t r ansfer funct ion t hat descr ibes a
discr et e-t ime syst em given by sos in second-or der sect ion for m wit h gain g:
H z ( ) H
k
z ( )
k 1 =
L

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

= =
s os
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
1 L
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
6-319
Algorithm sos2tf uses t he conv funct ion t o mult iply all of t he numer at or and
denominat or second-or der polynomials t oget her .
Example Comput e t he t r ansfer funct ion r epr esent at ion of a simple second-or der sect ion
syst em:
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
See Also
latc2tf Lat t ice filt er t o t r ansfer funct ion conver sion.
sos2ss Conver sion of second-or der sect ions t o st at e-space.
sos2zp Conver sion of second-or der sect ions t o zer o-pole-gain.
ss2tf Conver sion of st at e-space t o t r ansfer funct ion.
tf2sos Conver sion of t r ansfer funct ion t o second-or der
sect ions.
zp2tf Conver sion of zer o-pole-gain t o t r ansfer funct ion.
sos2zp
6-320
6sos2zp
Purpose Conver sion of second-or der sect ions t o zer o-pole-gain.
Syntax [z,p,k] = sos2zp(sos)
[z,p,k] = sos2zp(sos,g)
Description sos2zp conver t s a second-or der sect ion r epr esent at ion of a given syst em t o an
equivalent zer o-pole-gain r epr esent at ion.
[z,p,k] = sos2zp(sos) r et ur ns t he zer os z, poles p, and gain k of t he syst em
given by sos in second-or der sect ion for m. The second-or der sect ion for mat of
H(z) is given by
sos is an L-by-6 mat r ix t hat cont ains t he coefficient s of each second-or der
sect ion st or ed in it s r ows:
Column vect or s z and p cont ain t he zer os and poles of t he t r ansfer
funct ion H(z):
wher e t he or der s n and m ar e det er mined by t he mat r ix sos.
[z,p,k] = sos2zp(sos,g) r et ur ns t he zer os z, poles p, and gain k of t he
syst em given by sos in second-or der sect ion for m wit h gain g:
H z ( ) H
k
z ( )
k 1 =
L

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

= =
s os
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
1 L
b
2L
1 a
1L
a
2L
=
H z ( ) k
z z
1
( ) z z
2
( )Lz z
n
( )
p p
1
( ) p p
2
( )Lp p
m
( )
------------------------------------------------------------------- =
H z ( ) g H
k
z ( )
k 1 =
L

=
sos2zp
6-321
Example Comput e t he poles, zer os, and gain of a simple syst em in second-or der sect ion
for m:
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 finds t he poles and zer os of each second-or der sect ion by r epeat edly
calling tf2zp.
See Also
sos2ss Conver sion of second-or der sect ions t o st at e-space.
sos2tf Conver sion of second-or der sect ions t o t r ansfer
funct ion.
ss2zp Conver sion of st at e-space t o zer o-pole-gain.
tf2zp Conver sion of t r ansfer funct ion t o zer o-pole-gain.
zp2sos Conver sion of zer o-pole-gain t o second-or der sect ions.
sosfilt
6-322
6sosfilt
Purpose Second-or der (biquadr at ic) IIR filt er ing.
Syntax y = sosfilt(sos,x)
Description y = sosfilt(sos,x) applies t he second-or der sect ion filt er sos t o vect or x.
The out put , y, is t he same lengt h as x.
sos r epr esent s t he second-or der sect ion filt er H(z)
by an L-by-6 mat r ix cont aining t he coefficient s of each second-or der sect ion in
it s r ows
If x is a mat r ix, sosfilt applies t he filt er t o each column of x independent ly.
Out put y is a mat r ix of t he same size, cont aining t he filt er ed dat a
cor r esponding t o each column of x.
See Also
References [1] Or fanidis, S.J . Introduction to S ignal Processing. Englewood Cliffs, NJ :
Pr ent ice Hall, 1996.
H z ( ) H
k
z ( )
k 1 =
L

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

= =
s os
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
1 L
b
2L
1 a
1L
a
2L
=
filter Filt er dat a wit h a r ecur sive (IIR) or nonr ecur sive
(FIR) filt er.
medfilt1 One-dimensional median filt er ing.
sgolayfilt Savit zky-Golay filt er ing.
specgram
6-323
6specgr am
Purpose Time-dependent fr equency analysis (spect r ogr am).
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,noverlap)
specgram(a)
B = specgram(a,f,Fs,window,noverlap)
Description specgram comput es t he windowed discr et e-t ime Four ier t r ansfor m of a signal
using a sliding window. The spect r ogr am is t he magnit ude of t his funct ion.
B = specgram(a) calculat es t he spect r ogr am for t he signal in vect or a. This
synt ax uses t he default values:
nfft = min(256,length(a))
Fs = 2
window = hanning(nfft)
noverlap = length(window)/2
nfft specifies t he FFT lengt h t hat specgram uses. This value det er mines t he
fr equencies at which t he discr et e-t ime Four ier t r ansfor m is comput ed. Fs is a
scalar t hat specifies t he sampling fr equency. window specifies a windowing
funct ion and t he number of samples specgram uses in it s sect ioning of vect or a.
noverlap is t he number of samples by which t he sect ions over lap. Any
ar gument s t hat you omit fr om t he end of t he input par amet er list use t he
default values shown above.
If a is r eal, specgram comput es t he discr et e-t ime Four ier t r ansfor m at posit ive
fr equencies only. If n is even, specgram r et ur ns nfft/2+1 r ows (including t he
zer o and Nyquist fr equency t er ms). If n is odd, specgram r et ur ns nfft/2 r ows.
The number of columns in B is
k = fix((nnoverlap)/(length(window)noverlap))
If a is complex, specgram comput es t he discr et e-t ime Four ier t r ansfor m at bot h
posit ive and negat ive fr equencies. In t his case, B is a complex mat r ix wit h nfft
specgram
6-324
r ows. Time incr eases linear ly acr oss t he columns of B, st ar t ing wit h sample 1
in column 1. Fr equency incr eases linear ly down t he r ows, st ar t ing at 0.
B = specgram(a,nfft) uses t he specified FFT lengt h nfft in it s calculat ions.
Specify nfft as a power of 2 for fast est execut ion.
[B,f] = specgram(a,nfft,Fs) r et ur ns a vect or f of fr equencies at which t he
funct ion comput es t he discr et e-t ime Four ier t r ansfor m. Fs has no effect on t he
out put B; it is a fr equency scaling mult iplier .
[B,f,t] = specgram(a,nfft,Fs) r et ur ns fr equency and t ime vect or s f and t
r espect ively. t is a column vect or of scaled t imes, wit h lengt h equal t o t he
number of columns of B. t(j) is t he ear liest t ime at which t he j-t h window
int er sect s a. t(1) is always equal t o 0.
B = specgram(a,nfft,Fs,window) specifies a windowing funct ion and t he
number of samples per sect ion of t he x vect or . If you supply a scalar for window,
specgram uses a Hanning window of t hat lengt h. The lengt h of t he window
must be less t han or equal t o nfft; specgram zer o pads t he sect ions if t he lengt h
of t he window exceeds nfft.
B = specgram(a,nfft,Fs,window,noverlap) over laps t he sect ions of x by
noverlap samples.
You can use t he empt y mat r ix [] t o specify t he default value for any input
ar gument . For example,
B = specgram(x,[],10000)
is equivalent t o
B = specgram(x)
but wit h a sampling fr equency of 10,000 Hz inst ead of t he default 2 Hz.
specgram wit h no out put ar gument s displays t he scaled logar it hm of t he
spect r ogr am in t he cur r ent figur e window using
imagesc(t,f,20*log10(abs(b))),axis xy,colormap(jet)
specgram
6-325
The axis xy mode displays t he low-fr equency cont ent of t he fir st por t ion of t he
signal in t he lower -left cor ner of t he axes. specgram uses Fs t o label t he axes
accor ding t o t r ue t ime and fr equency.
B = specgram(a,f,Fs,window,noverlap) comput es t he spect r ogr am at t he
fr equencies specified in f, using eit her t he chir p z-t r ansfor m (for mor e t han 20
evenly spaced fr equencies) or a polyphase decimat ion filt er bank. f is a vect or
of fr equencies in Her t z; it must have at least t wo element s.
Algorithm specgram calculat es t he spect r ogr am for a given signal as follows:
1 It split s t he signal int o over lapping sect ions and applies t he window
specified by t he window par amet er t o each sect ion.
2 It comput es t he discr et e-t ime Four ier t r ansfor m of each sect ion wit h a
lengt h nfft FFT t o pr oduce an est imat e of t he shor t -t er m fr equency cont ent
of t he signal; t hese t r ansfor ms make up t he columns of B. specgram zer o
pads t he windowed sect ions if nfft > length(window), so t he quant it y
(length(window) noverlap) specifies by how many samples specgram
shift s t he window.
3 For r eal input , specgram t r uncat es t he spect r ogr am t o t he fir st nfft/2 + 1
point s for nfft even and (nfft + 1)/2 for nfft odd.
specgram
6-326
Example Plot t he spect r ogr am of a digit ized speech signal:
load mtlb
specgram(mtlb,512,Fs,kaiser(500,5),475)
title('Spectrogram')
Diagnostics An appr opr iat e diagnost ic message is displayed when incor r ect ar gument s ar e
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
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
cohere Est imat e magnit ude squar ed coher ence funct ion
bet ween t wo signals.
csd Est imat e t he cr oss spect r al densit y (CSD) of t wo
signals.
pwelch Est imat e t he power spect r al densit y (PSD) of a signal
using Welchs met hod.
tfe Tr ansfer funct ion est imat e fr om input and out put .
specgram
6-327
References [1] Oppenheim, A.V., and R.W. Schafer . Discrete-Time S ignal Processing.
Englewood Cliffs, NJ : Pr ent ice Hall, 1989. Pgs. 713-718.
[2] Rabiner , L.R., and R.W. Schafer . Digital Processing of S peech S ignals.
Englewood Cliffs, NJ : Pr ent ice Hall, 1978.
sptool
6-328
6spt ool
Purpose Int er act ive digit al signal pr ocessing t ool (SPTool).
Syntax sptool
Description The sptool command invokes a suit e of gr aphical user int er face (GUI) t ools
t hat pr ovides access t o many of t he signal, filt er , and spect r al analysis
funct ions in t he t oolbox in a power ful, easy-t o-use int er act ive signal display
and explor at ion envir onment .
Using SPTool, you can impor t , expor t , and manage signals, filt er s, and spect r a.
Fr om SPTool, you can act ivat e it s four int egr at ed signal pr ocessing t ools:
The S ignal Browser, for viewing, measur ing, and analyzing t he t ime-domain
infor mat ion of one or mor e signals.
sptool
6-329
The Filter Designer, for designing and edit ing FIR and IIR filt er s of var ious
lengt hs and t ypes, wit h st andar d (lowpass, highpass, bandpass, bandst op,
and mult iband) configur at ions.
sptool
6-330
The Filter Viewer, for viewing t he char act er ist ics of a designed or impor t ed
filt er , including it s magnit ude r esponse, phase r esponse, gr oup delay,
pole-zer o plot , impulse r esponse, and st ep r esponse.
sptool
6-331
The S pectrum Viewer, for gr aphical analysis of fr equency-domain dat a using
a var iet y of met hods of spect r al densit y est imat ion, including t he Bur g
met hod, t he FFT met hod, t he mult it aper met hod (MTM), t he MUSIC
eigenvect or met hod, Welchs met hod, and t he Yule-Walker AR met hod.
See Chapt er 5, Int er act ive Tools for a full discussion of how t o use SPTool.
square
6-332
6square
Purpose Squar e wave gener at or .
Syntax x = square(t)
x = square(t,duty)
Description x = square(t) gener at es a squar e wave wit h per iod 2 for t he element s of
t ime vect or t. square(t) is similar t o sin(t), but it cr eat es a squar e wave wit h
peaks of 1 inst ead of a sine wave.
x = square(t,duty) gener at es a squar e wave wit h specified dut y cycle, duty.
The duty cycle is t he per cent of t he per iod in which t he signal is posit ive.
See Also
chirp Swept -fr equency cosine gener at or.
cos Cosine of vect or /mat r ix element s (see t he online
MATLAB Function Reference).
diric Dir ichlet or per iodic sinc funct ion.
gauspuls Gaussian-modulat ed sinusoidal pulse gener at or.
pulstran Pulse t r ain gener at or.
rectpuls Sampled aper iodic r ect angle gener at or.
sawtooth Sawt oot h or t r iangle wave gener at or.
sin Sine of vect or /mat r ix element s (see t he online
MATLAB Function Reference).
sinc Sinc or sin(t )/t funct ion.
tripuls Sampled aper iodic t r iangle gener at or.
ss2sos
6-333
6ss2sos
Purpose Conver sion of st at e-space t o second-or der sect ions.
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 conver t s a st at e-space r epr esent at ion of a given syst em t o an
equivalent second-or der sect ion r epr esent at ion.
[sos,g] = ss2sos(A,B,C,D) finds a mat r ix sos in second-or der sect ion for m
wit h gain g t hat is equivalent t o t he st at e-space syst em r epr esent ed by input
ar gument s A, B, C and D. The input syst em must be single out put and r eal. sos
is an L-by-6 mat r ix
whose r ows cont ain t he numer at or and denominat or coefficient s b
ik
and a
ik
of
t he second-or der sect ions of H(z):
[sos,g] = ss2sos(A,B,C,D,iu) specifies a scalar iu t hat det er mines which
input of t he st at e-space syst em A, B, C, D is used in t he conver sion. The default
for iu is 1.
[sos,g] = ss2sos(A,B,C,D,'order') and
[sos,g] = ss2sos(A,B,C,D,iu,'order') specify t he or der of t he r ows in sos,
wher e order is:
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
2 k
z
2
+ +
1 a
1 k
z
1
a
2k
z
2
+ +
--------------------------------------------------------- -
k 1 =
L

= =
ss2sos
6-334
down, t o or der t he sect ions so t he fir st r ow of sos cont ains t he poles closest t o
t he unit cir cle
up, t o or der t he sect ions so t he fir st r ow of sos cont ains t he poles far t hest
fr om t he unit cir cle (default )
The zer os ar e always pair ed wit h t he poles closest t o t hem.
[sos,g] = ss2sos(A,B,C,D,iu,'order','scale') specifies t he desir ed
scaling of t he gain and t he numer at or coefficient s of all second-or der sect ions,
wher e scale is:
none, t o apply no scaling (default )
inf, t o apply infinit y-nor m scaling
two, t o apply 2-nor m scaling
Using infinit y-nor m scaling in conjunct ion wit h up-or der ing minimizes t he
pr obabilit y of over flow in t he r ealizat ion. Using 2-nor m scaling in conjunct ion
wit h down-or der ing minimizes t he peak r ound-off noise.
sos = ss2sos(...) embeds t he over all syst em gain, g, in t he fir st sect ion,
H
1
(z), so t hat :
Example Find a second-or der sect ion for m of a But t er wor t h lowpass filt er :
[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
Algorithm ss2sos uses a four -st ep algor it hm t o det er mine t he second-or der sect ion
r epr esent at ion for an input st at e-space syst em:
H z ( ) H
k
z ( )
k 1 =
L

=
ss2sos
6-335
1 It finds t he poles and zer os of t he syst em given by A, B, C and D.
2 It uses t he funct ion zp2sos, which fir st gr oups t he zer os and poles int o
complex conjugat e pair s using t he cplxpair funct ion. zp2sos t hen for ms t he
second-or der sect ions by mat ching t he pole and zer o pair s accor ding t o t he
following r ules:
a Mat ch t he poles closest t o t he unit cir cle wit h t he zer os closest t o t hose
poles.
b Mat ch t he poles next closest t o t he unit cir cle wit h t he zer os closest t o
t hose poles.
c Cont inue unt il all of t he poles and zer os ar e mat ched.
ss2sos gr oups r eal poles int o sect ions wit h t he r eal poles closest t o t hem in
absolut e value. The same r ule holds for r eal zer os.
3 It or der s t he sect ions accor ding t o t he pr oximit y of t he pole pair s t o t he unit
cir cle. ss2sos nor mally or der s t he sect ions wit h poles closest t o t he unit
cir cle last in t he cascade. You can t ell ss2sos t o or der t he sect ions in t he
r ever se or der by specifying t he 'down' flag.
4 ss2sos scales t he sect ions by t he nor m specified in t he 'scale' ar gument .
For ar bit r ar y H(), t he scaling is defined by:
wher e p can be eit her or 2. See t he r efer ences for det ails on t he scaling.
This scaling is an at t empt t o minimize over flow or peak r ound-off noise in
fixed point filt er implement at ions.
Diagnostics If t her e is mor e t han one input t o t he syst em, ss2sos gives t he following er r or
message:
Statespace system must have only one input.
H
p
1
2
------ H ( )
p
d
0
2

1
p
---
=
ss2sos
6-336
See Also
References [1] J ackson, L.B. Digital Filters and S ignal Processing. 3r d ed. Bost on: Kluwer
Academic Publisher s, 1996. Chapt er 11.
[2] Mit r a, S.K. Digital S ignal Processing: A Computer-Based Approach. New
Yor k: McGr aw-Hill, 1998. Chapt er 9.
[3] Vaidyanat han, P.P. Robust Digit al Filt er St r uct ur es. Handbook for
Digital S ignal Processing. S.K. Mit r a and J .F. Kaiser , ed. Chapt er 7. New Yor k:
J ohn Wiley & Sons, 1993.
cplxpair Gr oup complex number s int o complex conjugat e
pair s.
sos2ss Conver sion of second-or der sect ions t o st at e-space.
ss2tf Conver sion of st at e-space t o t r ansfer funct ion.
ss2zp Conver sion of st at e-space t o zer o-pole-gain.
tf2sos Conver sion of t r ansfer funct ion t o second-or der
sect ions.
zp2sos Conver sion of zer o-pole-gain t o second-or der sect ions.
ss2tf
6-337
6ss2t f
Purpose Conver sion of st at e-space t o t r ansfer funct ion.
Syntax [b,a] = ss2tf(A,B,C,D,iu)
Description ss2tf conver t s a st at e-space r epr esent at ion of a given syst em t o an equivalent
t r ansfer funct ion r epr esent at ion.
[b,a] = ss2tf(A,B,C,D,iu) r et ur ns t he t r ansfer funct ion
of t he syst em
fr om t he iu-t h input . Vect or a cont ains t he coefficient s of t he denominat or in
descending power s of s. The numer at or coefficient s ar e r et ur ned in ar r ay b wit h
as many r ows as t her e ar e out put s y. ss2tf also wor ks wit h syst ems in discr et e
t ime, in which case it r et ur ns t he z-t r ansfor m r epr esent at ion.
The ss2tf funct ion is par t of t he st andar d MATLAB language.
Algorithm The ss2tf funct ion uses poly t o find t he char act er ist ic polynomial det (sI-A)
and t he equalit y
See Also
H s ( )
B s ( )
A s ( )
---------- - C sI A ( )
1
B D + = =
x

Ax Bu + =
y Cx Du + =
H s ( ) C s I A ( )
1
B
det s I A BC + ( ) det s I A ( )
det s I A ( )
------------------------------------------------------------------------------ = =
latc2tf Lat t ice filt er t o t r ansfer funct ion conver sion.
sos2tf Conver sion of second-or der sect ions t o t r ansfer
funct ion.
ss2sos Conver sion of st at e-space t o second-or der sect ions.
ss2zp Conver sion of st at e-space t o zer o-pole-gain.
tf2ss Conver sion of t r ansfer funct ion t o st at e-space.
zp2tf Conver sion of zer o-pole-gain t o t r ansfer funct ion.
ss2zp
6-338
6ss2zp
Purpose Conver sion of st at e-space t o zer o-pole-gain.
Syntax [z,p,k] = ss2zp(A,B,C,D,iu)
Description ss2zp conver t s a st at e-space r epr esent at ion of a given syst em t o an equivalent
zer o-pole-gain r epr esent at ion. The zer os, poles, and gains of st at e-space
syst ems r epr esent t he t r ansfer funct ion in fact or ed for m.
[z,p,k] = ss2zp(A,B,C,D,iu) calculat es t he t r ansfer funct ion in fact or ed
for m
of t he syst em
fr om t he iu-t h input . Ret ur ned column vect or p cont ains t he pole locat ions of
t he denominat or coefficient s of t he t r ansfer funct ion. Mat r ix z cont ains t he
numer at or zer os in it s columns, wit h as many columns as t her e ar e out put s y.
Column vect or k cont ains t he gains for each numer at or t r ansfer funct ion.
ss2zp also wor ks wit h syst ems in discr et e t ime, in which case it r et ur ns t he
z-t r ansfor m r epr esent at ion. The input st at e-space syst em must be r eal.
The ss2zp funct ion is par t of t he st andar d MATLAB language.
H s ( )
Z s ( )
P s ( )
---------- k
s z
1
( ) s z
2
( )Ls z
n
( )
s p
1
( ) s p
2
( )Ls p
n
( )
--------------------------------------------------------------- = =
x

Ax Bu + =
y Cx Du + =
ss2zp
6-339
Example Her e ar e t wo ways of finding t he zer os, poles, and gains of a syst em:
b = [2 3];
a = [1 0.4 1];
[z,p,k] = tf2zp(b,a)
z =
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 =
1.5000
p =
0.2000 + 0.9798i
0.2000 0.9798i
k =
2
Algorithm ss2zp finds t he poles fr om t he eigenvalues of t he A ar r ay. The zer os ar e t he
finit e solut ions t o a gener alized eigenvalue pr oblem:
z = eig([A B;C D], diag([ones(1,n) 0]);
In many sit uat ions t his algor it hm pr oduces spur ious lar ge, but finit e, zer os.
ss2zp int er pr et s t hese lar ge zer os as infinit e.
ss2zp finds t he gains by solving for t he fir st nonzer o Mar kov par amet er s.
ss2zp
6-340
See Also
References [1] Laub, A.J ., and B.C. Moor e. Calculat ion of Tr ansmission Zer os Using QZ
Techniques. Automatica 14 (1978). Pg. 557.
pzmap Pole-zer o map of LTI syst em (Control S ystem Toolbox
Users Guide).
sos2zp Conver sion of second-or der sect ions t o zer o-pole-gain.
ss2sos Conver sion of st at e-space t o second-or der sect ions.
ss2tf Conver sion of st at e-space t o t r ansfer funct ion.
tf2zp Conver sion of t r ansfer funct ion t o zer o-pole-gain.
zp2ss Conver sion of zer o-pole-gain t o st at e-space.
stmcb
6-341
6st mcb
Purpose Linear model using St eiglit z-McBr ide it er at ion.
Syntax [b,a] = stmcb(x,nb,na)
[b,a] = stmcb(x,u,nb,na)
[b,a] = stmcb(x,nb,na,niter)
[b,a] = stmcb(x,u,nb,na,niter)
[b,a] = stmcb(x,nb,na,niter,ai)
[b,a] = stmcb(x,u,nb,na,niter,ai)
Description St eiglit z-McBr ide it er at ion is an algor it hm for finding an IIR filt er wit h a
pr escr ibed t ime domain impulse r esponse. It has applicat ions in bot h filt er
design and syst em ident ificat ion (par amet r ic modeling).
[b,a] = stmcb(x,nb,na) finds t he coefficient s b and a of t he syst em b(z)/ a(z)
wit h appr oximat e impulse r esponse x, exact ly nb zer os, and exact ly na poles.
[b,a] = stmcb(x,u,nb,na) finds t he syst em coefficient s b and a of t he syst em
t hat , given u as input , has x as out put . x and u must be t he same lengt h.
[b,a] = stmcb(x,nb,na,niter) and
[b,a] = stmcb(x,u,nb,na,niter) use niter it er at ions. The default for niter
is 5.
[b,a] = stmcb(x,nb,na,niter,ai) and
[b,a] = stmcb(x,u,nb,na,niter,ai) use t he vect or ai as t he init ial est imat e
of t he denominat or coefficient s. If ai is not specified, stmcb uses t he out put
ar gument fr om [b,ai] = prony(x,0,na) as t he vect or ai.
stmcb r et ur ns t he IIR filt er coefficient s in lengt h nb+1 and na+1 r ow vect or s b
and a. The filt er coefficient s ar e or der ed in descending power s of z:
H z ( )
B z ( )
A z ( )
-----------
b 1 ( ) b 2 ( )z
1
L b n b 1 + ( )z
n b
+ + +
a 1 ( ) a 2 ( )z
1
L a n a 1 + ( )z
n a
+ + +
----------------------------------------------------------------------------------------- = =
stmcb
6-342
Example Appr oximat e t he impulse r esponse of a But t er wor t h filt er wit h a syst em of
lower or der :
[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.2 0.4 0.6 0.8 1
600
400
200
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
300
200
100
0
Normalized Angular Frequency ( rads/sample)
M
a
g
n
i
t
u
d
e

(
d
B
)
0 0.2 0.4 0.6 0.8 1
800
600
400
200
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
60
40
20
0
20
Normalized Angular Frequency ( rads/sample)
M
a
g
n
i
t
u
d
e

(
d
B
)
stmcb
6-343
Algorithm stmcb at t empt s t o minimize t he squar ed er r or bet ween t he impulse r esponse x'
of b(z)/ a(z) and t he input signal x:
stmcb it er at es using t wo st eps:
1 It pr efilt er s x and u using 1/a(z).
2 It solves a syst em of linear equat ions for b and a using \ .
stmcb r epeat s t his pr ocess niter t imes. No checking is done t o see if t he b and
a coefficient s have conver ged in fewer t han niter it er at ions.
Diagnostics If x and u have differ ent lengt hs, stmcb gives t he following er r or message:
X and U must have same length.
See Also
References [1] St eiglit z, K., and L.E. McBr ide. A Technique for t he Ident ificat ion of Linear
Syst ems. IEEE Trans. Automatic Control. Vol. AC-10 (1965). Pgs. 461-464.
[2] Ljung, L. S ystem Identification: Theory for the User. Englewood Cliffs, NJ :
Pr ent ice Hall, 1987. Pg. 297.
min
a b ,
x i ( ) x' i ( )
2
i 0 =

levinson Levinson-Dur bin r ecur sion.


lpc Linear pr edict ion coefficient s.
aryule Comput e an est imat e of AR model par amet er s using
t he Yule-Walker met hod.
prony Pr onys met hod for t ime domain IIR filt er design.
strips
6-344
6st r ips
Purpose St r ip plot .
Syntax strips(x)
strips(x,n)
strips(x,sd,Fs)
strips(x,sd,Fs,scale)
Description strips(x) plot s vect or x in hor izont al st r ips of lengt h 250. If x is a mat r ix,
strips(x) plot s each column of x. The left -most column (column 1) is t he t op
hor izont al st r ip.
strips(x,n) plot s vect or x in st r ips t hat ar e each n samples long.
strips(x,sd,Fs) plot s vect or x in st r ips of dur at ion sd seconds, given a
sampling fr equency of Fs samples per second.
strips(x,sd,Fs,scale) scales t he ver t ical axes.
If x is a mat r ix, strips(x,n), strips(x,sd,Fs), and strips(x,sd,Fs,scale)
plot t he differ ent columns of x on t he same st r ip plot .
strips ignor es t he imaginar y par t of x if it is complex.
strips
6-345
Example Plot t wo seconds of a fr equency modulat ed sinusoid in 0.25 second st r ips:
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)
See Also
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
plot Linear t wo-dimensional plot (see t he online MATLAB
Function Reference).
stem Plot discr et e sequence dat a (see t he online MATLAB
Function Reference).
tf2latc
6-346
6t f2lat c
Purpose Conver sion of t r ansfer funct ion t o lat t ice filt er .
Syntax [k,v] = tf2latc(b,a)
k = tf2latc(1,a)
[k,v] = tf2latc(1,a)
k = tf2latc(b)
Description [k,v] = tf2latc(b,a) finds t he lat t ice par amet er s k and t he ladder
par amet er s v for an IIR (ARMA) lat t ice-ladder filt er , nor malized by a(1). Not e
t hat an er r or is gener at ed if one or mor e of t he lat t ice par amet er s ar e exact ly
equal t o 1.
k = tf2latc(1,a) finds t he lat t ice par amet er s k for an IIR all-pole (AR) lat t ice
filt er .
[k,v] = tf2latc(1,a) r et ur ns t he scalar ladder coefficient at t he cor r ect
posit ion in vect or v. All ot her element s of v ar e zer o.
k = tf2latc(b) finds t he lat t ice par amet er s k for an FIR (MA) lat t ice filt er ,
nor malized by b(1).
See Also
latc2tf Lat t ice filt er t o t r ansfer funct ion conver sion.
latcfilt Lat t ice and lat t ice-ladder filt er implement at ion.
tf2sos Conver sion of t r ansfer funct ion t o second-or der
sect ions.
tf2ss Conver sion of t r ansfer funct ion t o st at e-space.
tf2zp Conver sion of t r ansfer funct ion t o zer o-pole-gain.
tf2sos
6-347
6t f2sos
Purpose Conver sion of t r ansfer funct ion t o second-or der sect ions.
Syntax [sos,g] = tf2sos(b,a)
[sos,g] = tf2sos(b,a,'order')
[sos,g] = tf2sos(b,a,'order','scale')
sos = tf2sos(...)
Description tf2sos conver t s a t r ansfer funct ion r epr esent at ion of a given syst em t o an
equivalent second-or der sect ion r epr esent at ion.
[sos,g] = tf2sos(b,a) finds a mat r ix sos in second-or der sect ion for m wit h
gain g t hat is equivalent t o t he syst em r epr esent ed by t r ansfer funct ion
coefficient vect or s a and b.
sos is an L-by-6 mat r ix
whose r ows cont ain t he numer at or and denominat or coefficient s b
ik
and a
ik
of
t he second-or der sect ions of H(z):
[sos,g] = tf2sos(b,a,'order') specifies t he or der of t he r ows in sos, wher e
order is:
H z ( )
B z ( )
A z ( )
-----------
b
1
b
2
z
1
L b
n b 1 +
z
n b
+ + +
a
1
a
2
z
1
L a
n a 1 +
z
n a
+ + +
------------------------------------------------------------------------- = =
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
2 k
z
2
+ +
1 a
1 k
z
1
a
2k
z
2
+ +
--------------------------------------------------------- -
k 1 =
L

= =
tf2sos
6-348
down, t o or der t he sect ions so t he fir st r ow of sos cont ains t he poles closest t o
t he unit cir cle
up, t o or der t he sect ions so t he fir st r ow of sos cont ains t he poles far t hest
fr om t he unit cir cle (default )
[sos,g] = tf2sos(b,a,'order','scale') specifies t he desir ed scaling of t he
gain and numer at or coefficient s of all second-or der sect ions, wher e scale is:
none, t o apply no scaling (default )
inf, t o apply infinit y-nor m scaling
two, t o apply 2-nor m scaling
Using infinit y-nor m scaling in conjunct ion wit h up-or der ing minimizes t he
pr obabilit y of over flow in t he r ealizat ion. Using 2-nor m scaling in conjunct ion
wit h down-or der ing minimizes t he peak r ound-off noise.
sos = tf2sos(...) embeds t he over all syst em gain, g, in t he fir st sect ion,
H
1
(z), so t hat
See Also
H z ( ) H
k
z ( )
k 1 =
L

=
cplxpair Gr oup complex number s int o complex conjugat e
pair s.
sos2tf Conver sion of second-or der sect ions t o t r ansfer
funct ion.
ss2sos Conver sion of st at e-space t o second-or der sect ions.
tf2ss Conver sion of t r ansfer funct ion t o st at e-space.
tf2zp Conver sion of t r ansfer funct ion t o zer o-pole-gain.
zp2sos Conver sion of zer o-pole-gain t o second-or der sect ions.
tf2sos
6-349
References [1] J ackson, L.B. Digital Filters and S ignal Processing. 3r d ed. Bost on: Kluwer
Academic Publisher s, 1996. Chapt er 11.
[2] Mit r a, S.K. Digital S ignal Processing: A Computer-Based Approach. New
Yor k: McGr aw-Hill, 1998. Chapt er 9.
[3] Vaidyanat han, P.P. Robust Digit al Filt er St r uct ur es. Handbook for
Digital S ignal Processing. S.K. Mit r a and J .F. Kaiser , ed. Chapt er 7. New Yor k:
J ohn Wiley & Sons, 1993.
tf2ss
6-350
6t f2ss
Purpose Conver sion of t r ansfer funct ion t o st at e-space.
Syntax [A,B,C,D] = tf2ss(b,a)
Description tf2ss conver t s a t r ansfer funct ion r epr esent at ion of a given syst em t o an
equivalent st at e-space r epr esent at ion.
[A,B,C,D] = tf2ss(b,a) finds a st at e-space r epr esent at ion:
given a syst em in t r ansfer funct ion for m:
fr om a single input . Input vect or a cont ains t he denominat or coefficient s in
descending power s of s. Mat r ix b cont ains t he numer at or coefficient s wit h as
many r ows as t her e ar e out put s y. tf2ss r et ur ns t he A, B, C, and D mat r ices in
cont r oller canonical for m.
tf2ss also wor ks for discr et e syst ems, but you must pad t he numer at or wit h
t r ailing zer os t o make it t he same lengt h as t he denominat or .
The tf2ss funct ion is par t of t he st andar d MATLAB language.
Example Consider t he syst em
x

Ax Bu + =
y Cx Du + =
H s ( )
B s ( )
A s ( )
---------- - C s I A ( )
1
B D + = =
H s ( )
2s 3 +
s
2
2s 1 + +
s
2
0.4s 1 + +
--------------------------------- =
tf2ss
6-351
To conver t t his syst em t o st at e-space:
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
Ther e is disagr eement in t he lit er at ur e on naming convent ions for t he
canonical for ms. It is easy, however , t o gener at e similar it y t r ansfor mat ions
t hat conver t t o ot her for ms. For example:
T = fliplr(eye(n));
A = T\A*T;
Algorithm tf2ss wr it es t he out put in cont r oller canonical for m by inspect ion.
See Also
sos2ss Conver sion of second-or der sect ions t o st at e-space.
ss2tf Conver sion of st at e-space t o t r ansfer funct ion.
tf2sos Conver sion of t r ansfer funct ion t o second-or der
sect ions.
tf2zp Conver sion of t r ansfer funct ion t o zer o-pole-gain.
zp2ss Conver sion of zer o-pole-gain t o st at e-space.
tf2zp
6-352
6t f2zp
Purpose Conver sion of t r ansfer funct ion t o zer o-pole-gain.
Syntax [z,p,k] = tf2zp(b,a)
Description tf2zp finds t he zer os, poles, and gains of a syst em in polynomial t r ansfer
funct ion for m.
[z,p,k] = tf2zp(b,a) finds t he single-input , mult i-out put (SIMO) fact or ed
t r ansfer funct ion for m:
given a SIMO syst em in polynomial t r ansfer funct ion for m:
Vect or a specifies t he coefficient s of t he denominat or in descending power s of
s. Mat r ix b indicat es t he numer at or coefficient s wit h as many r ows as t her e ar e
out put s. The zer o locat ions ar e r et ur ned in t he columns of mat r ix z, wit h as
many columns as t her e ar e r ows in b. The pole locat ions ar e r et ur ned in column
vect or p and t he gains for each numer at or t r ansfer funct ion in vect or k.
The tf2zp funct ion also wor ks for discr et e syst ems, and is par t of t he st andar d
MATLAB language.
H s ( )
Z s ( )
P s ( )
---------- k
s Z
1
( ) s Z
2
( )Ls Z
m
( )
s p
1
( ) s p
2
( )Ls p
n
( )
------------------------------------------------------------------ = =
B s ( )
A s ( )
---------- -
b
1
s
n b 1 ( )
L b
n b 1 ( )
s b
n b ( )
+ + +
a
1
s
n a 1 ( )
L a
n a 1 ( )
s a
n a ( )
+ + +
-------------------------------------------------------------------------------------- - =
tf2zp
6-353
Example Find t he zer os, poles, and gains of t he syst em
b = [2 3];
a = [1 0.4 1];
[z,p,k] = tf2zp(b,a)
z =
1.5000
p =
0.2000 + 0.9798i
0.2000 0.9798i
k =
2
Algorithm The syst em is conver t ed t o st at e-space using tf2ss and t hen t o zer os, poles,
and gains using ss2zp.
See Also
H s ( )
2s 3 +
s
2
0.4s 1 + +
--------------------------------- =
sos2zp Conver sion of second-or der sect ions t o zer o-pole-gain.
ss2zp Conver sion of st at e-space t o zer o-pole-gain.
tf2sos Conver sion of t r ansfer funct ion t o second-or der
sect ions.
tf2ss Conver sion of t r ansfer funct ion t o st at e-space.
zp2tf Conver sion of zer o-pole-gain t o t r ansfer funct ion.
tfe
6-354
6t fe
Purpose Tr ansfer funct ion est imat e fr om input and out put .
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,noverlap)
Txy = tfe(x,y,...,'dflag')
tfe(x,y)
Description Txy = tfe(x,y) finds a t r ansfer funct ion est imat e Txy given input signal
vect or x and out put signal vect or y. The transfer function is t he quot ient of t he
cr oss spect r um of x and y and t he power spect r um of x:
The r elat ionship bet ween t he input x and out put y is modeled by t he linear ,
t ime-invar iant t r ansfer funct ion Txy.
Vect or s x and y must be t he same lengt h. Txy = tfe(x,y) uses t he following
default values:
nfft = min(256,(length(x))
Fs = 2
window = hanning(nfft)
noverlap = 0
nfft specifies t he FFT lengt h t hat tfe uses. This value det er mines t he
fr equencies at which t he power spect r um is est imat ed. Fs is a scalar t hat
specifies t he sampling fr equency. window specifies a windowing funct ion and
t he number of samples tfe uses in it s sect ioning of t he x and y vect or s.
noverlap is t he number of samples by which t he sect ions over lap. Any
ar gument s t hat ar e omit t ed fr om t he end of t he par amet er list use t he default
values shown above.
If x is r eal, tfe est imat es t he t r ansfer funct ion at posit ive fr equencies only; in
t his case, t he out put Txy is a column vect or of lengt h nfft/2+1 for nfft even
and (nfft+1)/2 for nfft odd. If x or y is complex, tfe est imat es t he t r ansfer
funct ion for bot h posit ive and negat ive fr equencies and Txy has lengt h nfft.
T
xy
f ( )
P
xy
f ( )
P
xx
f ( )
--------------- =
tfe
6-355
Txy = tfe(x,y,nfft) uses t he specified FFT lengt h nfft in est imat ing t he
t r ansfer funct ion. Specify nfft as a power of 2 for fast est execut ion.
[Txy,f] = tfe(x,y,nfft,Fs) r et ur ns a vect or f of fr equencies at which tfe
est imat es t he t r ansfer funct ion. Fs is t he sampling fr equency. f is t he same size
as Txy, so plot(f,Txy) plot s t he t r ansfer funct ion est imat e ver sus pr oper ly
scaled fr equency. Fs has no effect on t he out put Txy; it is a fr equency scaling
mult iplier .
Txy = tfe(x,y,nfft,Fs,window) specifies a windowing funct ion and t he
number of samples per sect ion of t he x vect or . If you supply a scalar for window,
Txy uses a Hanning window of t hat lengt h. The lengt h of t he window must be
less t han or equal t o nfft; tfe zer o pads t he sect ions if t he lengt h of t he window
exceeds nfft.
Txy = tfe(x,y,nfft,Fs,window,noverlap) over laps t he sect ions of x by
noverlap samples.
You can use t he empt y mat r ix [] t o specify t he default value for any input
ar gument except x or y. For example,
Txy = tfe(x,y,[],[],kaiser(128,5))
uses 256 as t he value for nfft and 2 as t he value for Fs.
Txy = tfe(x,y,...,'dflag') specifies a det r end opt ion, wher e dflag is:
linear, t o r emove t he best st r aight -line fit fr om t he pr ewindowed sect ions of
x and y
mean, t o r emove t he mean fr om t he pr ewindowed sect ions of x and y
none, for no det r ending (default )
The dflag par amet er must appear last in t he list of input ar gument s. tfe
r ecognizes a dflag st r ing no mat t er how many int er mediat e ar gument s ar e
omit t ed.
tfe(...) wit h no out put ar gument s plot s t he magnit ude of t he t r ansfer
funct ion est imat e in decibels ver sus fr equency in t he cur r ent figur e window.
tfe
6-356
Example Comput e and plot t he t r ansfer funct ion est imat e bet ween t wo color ed noise
sequences x and y:
h = fir1(30,0.2,boxcar(31));
x = randn(16384,1);
y = filter(h,1,x);
tfe(x,y,1024,[],[],512)
title('Transfer Function Estimate')
Algorithm tfe uses a four -st ep algor it hm:
1 It mult iplies t he det r ended sect ions by window.
2 It t akes t he lengt h nfft FFT of each sect ion.
3 It aver ages t he squar es of t he spect r a of t he x sect ions t o for m Pxx and
aver ages t he pr oduct s of t he spect r a of t he x and y sect ions t o for m Pxy.
4 It calculat es 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
6-357
Diagnostics An appr opr iat e diagnost ic message is displayed when incor r ect ar gument s ar e
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 Comput e empir ical t r ansfer funct ion est imat e and
per iodogr am (see S ystem Identification Toolbox
Users Guide).
cohere Est imat e magnit ude squar ed coher ence funct ion
bet ween t wo signals.
csd Est imat e t he cr oss spect r al densit y (CSD) of t wo
signals.
pwelch Est imat e t he power spect r al densit y (PSD) of a signal
using Welchs met hod.
spa Per for m spect r al analysis for input -out put dat a (see
S ystem Identification Toolbox Users Guide).
triang
6-358
6t riang
Purpose Tr iangular window.
Syntax w = triang(n)
Description triang(n) r et ur ns an n-point t r iangular window in t he column vect or w. The
coefficient s of a t r iangular window ar e
For n odd:
For n even:
The t r iangular window is ver y similar t o a Bar t let t window. The Bar t let t
window always ends wit h zer os at samples 1 and n, while t he t r iangular
window is nonzer o at t hose point s. For n odd, t he cent er n2 point s of
triang(n2) ar e equivalent t o bartlett(n).
See Also
References [1] Oppenheim, A.V., and R.W. Schafer , Discrete-Time S ignal Processing.
Englewood Cliffs, NJ : Pr ent ice-Hall, 1989.
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 ,

'

=
bartlett Bar t let t window.
blackman Blackman window.
boxcar Rect angular window.
chebwin Chebyshev window.
hamming Hamming window.
hanning Hanning window.
kaiser Kaiser window.
tripuls
6-359
6t r ipuls
Purpose Sampled aper iodic t r iangle gener at or .
Syntax y = tripuls(T)
y = tripuls(T,w)
y = tripuls(T,w,s)
Description y = tripuls(T) r et ur ns a cont inuous, aper iodic, symmet r ic, unit y-height
t r iangular pulse at t he t imes indicat ed in ar r ay T, cent er ed about T=0 and wit h
a default widt h of 1.
y = tripuls(T,w) gener at es a t r iangular pulse of widt h w.
y = tripuls(T,w,s) gener at es a t r iangular pulse wit h skew s, wher e 1<s<1.
When s is 0, a symmet r ic t r iangular pulse is gener at ed.
See Also
chirp Swept -fr equency cosine gener at or.
cos Cosine of vect or /mat r ix element s (see t he online
MATLAB Function Reference).
diric Dir ichlet or per iodic sinc funct ion.
gauspuls Gaussian-modulat ed sinusoidal pulse gener at or.
pulstran Pulse t r ain gener at or.
rectpuls Sampled aper iodic r ect angle gener at or.
sawtooth Sawt oot h or t r iangle wave gener at or.
sin Sine of vect or /mat r ix element s (see t he online
MATLAB Function Reference).
sinc Sinc or sin(t )/t funct ion.
square Squar e wave gener at or.
unwrap
6-360
6unwr ap
Purpose Unwr ap phase angles.
Syntax p = unwrap(p)
Description p = unwrap(p) cor r ect s t he phase angles in vect or p by adding mult iples of
, wher e needed, t o smoot h t he t r ansit ions acr oss br anch cut s. When p is a
mat r ix, unwrap cor r ect s t he phase angles down each column. The phase must
be in r adians.
The unwrap funct ion is par t of t he st andar d MATLAB language.
Limitations unwrap t r ies t o det ect br anch cut cr ossings, but it can be fooled by spar se,
r apidly changing phase values.
See Also
2 t
abs Absolut e value (magnit ude).
angle Phase angle.
upfirdn
6-361
6upfirdn
Purpose Upsample, apply an FIR filt er , and downsample.
Syntax yout = upfirdn(xin,h)
yout = upfirdn(xin,h,p)
yout = upfirdn(xin,h,p,q)
Description upfirdn per for ms a cascade of t hr ee oper at ions:
1 Upsampling by p (zer o inser t ing)
2 FIR filt er ing wit h t he impulse r esponse given in h
3 Downsampling by q (t hr owing away samples)
upfirdn has been implement ed as a MEX-file for maximum speed, so only t he
out put s act ually needed ar e comput ed. The FIR filt er is usually a lowpass
filt er , which you must design using anot her funct ion such as remez or fir1.
NOTE The funct ion resample per for ms an FIR design using firls, followed
by r at e changing implement ed wit h upfirdn.
yout = upfirdn(xin,h) r et ur ns t he out put signal yout. If yout is a r ow or
column vect or , t hen it r epr esent s one signal; if yout is an ar r ay, t hen each
column is a separ at e out put . xin is t he input signal. If xin is a r ow or column
vect or , t hen it r epr esent s one signal; if xin is an ar r ay, t hen each column is
filt er ed. h is t he impulse r esponse of t he FIR filt er . If h is a r ow or column
vect or , t hen it r epr esent s one filt er ; if h is an ar r ay, t hen each column is a
separ at e impulse r esponse.
yout = upfirdn(xin,h,p) specifies t he upsampling fact or p. p is an int eger
wit h a default of 1.
yout = upfirdn(xin,h,p,q) specifies t he downsampling fact or q. q is an
int eger wit h a default of 1.
upfirdn
6-362
NOTE Since upfirdn per for ms convolut ion and r at e changing, t he yout
signals have a differ ent lengt h t han xin. The lengt h of y[n] is appr oximat ely
p/q t imes t he lengt h of x[n].
Remarks Usually t he input s xin and t he filt er h ar e vect or s, in which case only one
out put signal is pr oduced. However , when t hese ar gument s ar e ar r ays, each
column is t r eat ed as a separ at e signal or filt er . Valid combinat ions ar e
1 xin is a vect or and h is a vect or .
Ther e is one filt er and one signal, so t he funct ion convolves xin wit h h. The
out put signal yout is a r ow vect or if xin is a r ow; ot her wise, it is a column
vect or .
2 xin is an ar r ay and h is a vect or .
Ther e is one filt er and many signals, so t he funct ion convolves h wit h each
column of xin. The r esult ing yout will be an ar r ay wit h t he same number of
columns as xin.
3 xin is a vect or and h is an ar r ay.
Ther e ar e many filt er s and one signal, so t he funct ion convolves each column
of h wit h xin. The r esult ing yout will be an ar r ay wit h t he same number of
columns as h.
4 xin is an ar r ay and h is an ar r ay, bot h wit h t he same number of columns.
Ther e ar e many filt er s and many signals, so t he funct ion convolves
cor r esponding columns of xin and h. The r esult ing yout is an ar r ay wit h t he
same number of columns as xin and h.
Examples If bot h p and q ar e equal t o 1 (t hat is, t her e is no r at e changing), t he r esult is
or dinar y convolut ion of t wo signals (equivalent t o conv):
yy = upfirdn(xx,hh);
This example implement s a seven-channel filt er bank by convolving seven
differ ent filt er s wit h one input signal, t hen downsamples by five:
% Assume that hh is an L-by-7 array of filters.
yy = upfirdn(xx,hh,1,5);
upfirdn
6-363
Implement a r at e change fr om 44.1 kHz (CD sampling r at e) t o 48 kHz (DAT
r at e), a r at io of 160/147. This r equir es a lowpass filt er wit h cut off fr equency 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);
In t his example, t he filt er design and r esampling ar e separ at e st eps. Not e t hat
resample would do bot h st eps as one.
Algorithm upfirdn uses a polyphase int er polat ion st r uct ur e. The number of mult iply-add
oper at ions in t he polyphase st r uct ur e is appr oximat ely (L
h
L
x
-pL
x
)/q wher e L
h
and L
x
ar e t he lengt hs of h[n] and x[n], r espect ively.
A mor e accur at e flops count is comput ed in t he pr ogr am, but t he act ual count
is st ill appr oximat e. For long signals x[n], t he for mula is quit e oft en exact .
Diagnostics Ther e must be one out put ar gument and at least t wo input ar gument s. If eit her
of t hese condit ions ar e violat ed, upfirdn gives t he appr opr iat e er r or message:
UPFIRDN needs at least two input arguments.
UPFIRDN should have exactly one output argument.
If t he ar r ays ar e spar se, upfirdn gives t he er r or message
H must be full numeric matrix.
When t he input signals ar e in t he columns of a mat r ix and t her e ar e mult iple
filt er s also in t he columns of a mat r ix, t he number of signals and filt er s must
be t he same. If t hey ar e not , upfirdn gives t he er r or message
X and H must have the same number of columns, if more than one.
The ar gument s p and q must be int eger s. If t hey ar e not , upfirdn gives t he
er r or message
P and/or Q must be greater than zero
If t he ar gument s p and q ar e not r elat ively pr ime, upfirdn gives t he war ning
message
WARNING (upfirdn) p & q have common factor
upfirdn
6-364
See Also
References [1] Cr ochier e, R.E., and L.R. Rabiner . Multi-Rate S ignal Processing.
Englewood Cliffs, NJ : Pr ent ice Hall, 1983. Pgs. 88-91.
[2] Cr ochier e, R.E. A Gener al Pr ogr am t o Per for m Sampling Rat e Conver sion
of Dat a by Rat ional Rat ios. In Programs for Digital S ignal Processing. IEEE
Pr ess. New Yor k: J ohn Wiley & Sons, 1979. Pgs. 8.2-1 t o 8.2-7.
conv Convolut ion and polynomial mult iplicat ion.
decimate Decr ease t he sampling r at e for a sequence
(decimat ion).
filter Filt er dat a wit h a r ecur sive (IIR) or nonr ecur sive
(FIR) filt er.
interp Incr ease sampling r at e by an int eger fact or
(int er polat ion).
intfilt Int er polat ion FIR filt er design.
resample Change sampling r at e by any r at ional fact or.
vco
6-365
6vco
Purpose Volt age cont r olled oscillat or .
Syntax y = vco(x,Fc,Fs)
y = vco(x,[Fmin Fmax],Fs)
Description y = vco(x,Fc,Fs) cr eat es a signal t hat oscillat es at a fr equency det er mined
by t he r eal input vect or or ar r ay x wit h sampling fr equency Fs. Fc is t he car r ier
or r efer ence fr equency; when x is 0, y is an Fc Hz cosine wit h amplit ude 1
sampled at Fs Hz. x r anges fr om -1 t o 1, wher e -1 cor r esponds t o a 0 fr equency
out put , 0 t o Fc, and 1 t o 2*Fc. y is t he same size as x.
y = vco(x,[Fmin Fmax],Fs) scales t he fr equency modulat ion r ange so t hat -1
and 1 values of x yield oscillat ions of Fmin Hz and Fmax Hz r espect ively. For
best r esult s, Fmin and Fmax should be in t he r ange 0 t o Fs/2.
By default , Fs is 1 and Fc is Fs/4.
If x is a mat r ix, vco pr oduces a mat r ix whose columns oscillat e accor ding t o t he
columns of x.
Example Gener at e t wo seconds of a signal sampled at 10,000 samples/second whose
inst ant aneous fr equency is a t r iangle funct ion of t ime:
Fs = 10000;
t = 0:1/Fs:2;
x = vco(sawtooth(2*pi*t,0.75),[.1 0.4]*Fs,Fs);
vco
6-366
Plot t he spect r ogr am of t he gener at ed signal.
specgram(x,512,Fs,kaiser(256,5),220)
Algorithm vco per for ms FM modulat ion using t he modulate funct ion.
Diagnostics If any values of x lie out side [-1,1], vco gives t he following er r or message:
X outside of range [1,1].
See Also
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
demod Demodulat ion for communicat ions simulat ion.
modulate Modulat ion for communicat ions simulat ion.
xcorr
6-367
6xcor r
Purpose Cr oss-cor r elat ion funct ion est imat e.
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 est imat es t he cr oss-cor r elat ion sequence of a r andom pr ocess.
Aut ocor r elat ion is handled as a special case.
The t r ue cr oss-cor r elat ion sequence is
wher e x
n
and y
n
ar e st at ionar y r andom pr ocesses, , and E {}is t he
expect ed value oper at or . xcorr must est imat e t he sequence because, in
pr act ice, only a finit e segment of t he infinit e-lengt h r andom pr ocess is
available.
c = xcorr(x,y) r et ur ns t he cr oss-cor r elat ion sequence in a lengt h 2N-1
vect or , wher e x and y ar e lengt h N vect or s (N>1). If x and y ar e not t he same
lengt h, t he shor t er vect or is zer o-padded t o t he lengt h of t he longer vect or .
By default , xcorr comput es r aw cor r elat ions wit h no nor malizat ion:
The out put vect or c has element s given by c(m) = c
xy
(m-N), m=1, ..., 2N-1.
In gener al, t he cor r elat ion funct ion r equir es nor malizat ion t o pr oduce an
accur at e est imat e (see below).

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

m 0
c
yx
*
m ( ) m 0 <

'

=
xcorr
6-368
c = xcorr(x) is t he aut ocor r elat ion sequence for t he vect or x. If x is an N-by-P
mat r ix, c is a mat r ix wit h 2N-1 r ows whose P
2
columns cont ain t he
cr oss-cor r elat ion sequences for all combinat ions of t he columns of x.
c = xcorr(x,y,'option') specifies a nor malizat ion opt ion for t he
cr oss-cor r elat ion, wher e 'option' is:
biased, for biased est imat es of t he cr oss-cor r elat ion funct ion
unbiased, for unbiased est imat es of t he cr oss-cor r elat ion funct ion
coeff, t o nor malize t he sequence so t he aut ocor r elat ions at zer o lag ar e
ident ically 1.0
none, t o use t he r aw, unscaled cr oss-cor r elat ions (default )
See r efer ence [1] for mor e infor mat ion on t he pr oper t ies of biased and unbiased
cor r elat ion est imat es.
c = xcorr(x,'option') specifies one of t he above nor malizat ion opt ions for
t he aut ocor r elat ion.
c = xcorr(x,y,maxlags) r et ur ns t he cr oss-cor r elat ion sequence over t he lag
r ange [maxlags:maxlags]. Out put c has lengt h 2*maxlags+1.
c = xcorr(x,maxlags) r et ur ns t he aut ocor r elat ion sequence over t he lag
r ange [maxlags:maxlags]. Out put c has lengt h 2*maxlags+1. If x is an
N-by-P mat r ix, c is a mat r ix wit h 2*maxlags+1 r ows whose P
2
columns cont ain
t he aut ocor r elat ion sequences for all combinat ions of t he columns of x.
c = xcorr(x,y,maxlags,'option') specifies bot h a maximum number of lags
and a scaling opt ion for t he cr oss-cor r elat ion.
c = xcorr(x,maxlags,'option') specifies bot h a maximum number of lags
and a scaling opt ion for t he aut ocor r elat ion.
c
xy biased ,
m ( )
1
N
----c
x y
m ( ) =
c
xy unbiased ,
m ( )
1
N m
-------------------c
xy
m ( ) =
xcorr
6-369
[c,lags] = xcorr(...) r et ur ns a vect or of t he lag indices at which c was
est imat ed, wit h t he r ange [maxlags:maxlags]. When maxlags is not
specified, t he r ange of lags is [N+1:N1].
In all cases, t he cr oss-cor r elat ion or aut ocor r elat ion comput ed by xcorr has t he
0-t h lag in t he middle of t he sequence, at element or r ow maxlags+1 (element
or r ow N if maxlags is not specified).
Examples The second out put , lags, is useful for plot t ing t he cr oss-cor r elat ion or
aut ocor r elat ion. For example, t he est imat ed aut ocor r elat ion of zer o-mean
Gaussian whit e noise c
ww
(m) can be displayed for -10 m 10 using
ww = randn(1000,1);
[c_ww,lags] = xcorr(ww,10,'coeff');
stem(lags,c_ww)
Swapping t he x and y input ar gument s r ever ses (and conjugat es) t he out put
cor r elat ion sequence. For r ow vect or s, t he r esult ing sequences ar e r ever sed left
t o r ight ; for column vect or s, up and down. The following example illust r at es
t his pr oper t y (mat2str is used for a compact display of complex number s).
x = [1,2i,3]; y = [4,5,6];
[c1,lags] = xcorr(x,y);
c1 = mat2str(c1,2), lags
c1 =
[12i*8.9e016 15i*8 22i*10 5i*12 6+i*8.9e016]
lags =
2 1 0 1 2
c2 = conj(fliplr(xcorr(y,x)));
c2 = mat2str(c2,2)
c2 =
[12i*8.9e016 15i*8 22i*10 5i*12 6+i*8.9e016]
For t he case wher e input ar gument x is a mat r ix, t he out put columns ar e
ar r anged so t hat ext r act ing a r ow and r ear r anging it int o a squar e ar r ay
xcorr
6-370
pr oduces t he cr oss-cor r elat ion mat r ix cor r esponding t o t he lag of t he chosen
r ow. For example, t he cr oss-cor r elat ion at zer o lag can be r et r ieved by
randn('seed',0)
X = randn(2,2);
[M,P] = size(X);
c = xcorr(X);
c0 = zeros(P); c0(:) = c(M,:) % Extract zero-lag row
c0 =
1.7500 0.3079
0.3079 0.1293
You can calculat e t he mat r ix of cor r elat ion coefficient s t hat t he MATLAB
funct ion corrcoef gener at es by subst it ut ing
c = xcov(X,'coef')
in t he last example. The funct ion xcov subt r act s t he mean and t hen calls
xcorr.
Use fftshift t o move t he second half of t he sequence st ar t ing at t he zer ot h lag
t o t he fr ont of t he sequence. fftshift swaps t he fir st and second halves of a
sequence.
Algorithm For mor e infor mat ion on est imat ing covar iance and cor r elat ion funct ions, see
[1] and [2].
Diagnostics Ther e must be at least one vect or input ar gument ; ot her wise, xcorr gives t he
following er r or message:
1st arg must be a vector or matrix.
The st r ing 'option' must be t he last ar gument ; ot her wise, xcorr gives t he
following er r or message:
Argument list not in correct order.
If t he second ar gument was ent er ed as a scalar , it is t aken t o be maxlags and
no succeeding input can be a scalar . When t he second ar gument is a vect or , t he
fir st must also be a signal vect or . The t hir d ar gument , when pr esent , must be
xcorr
6-371
a scalar or a st r ing. If t hey ar e not , xcorr gives t he appr opr iat e er r or
message(s):
3rd arg is maxlag, 2nd arg cannot be scalar.
When b is a vector, a must be a vector.
Maxlag must be a scalar.
Nor mally t he lengt hs of t he vect or input s should be t he same; if t hey ar e not ,
t hen t he only allowable scaling opt ion is 'none'. If it is not , xcorr gives t he
following er r or message:
OPTION must be 'none' for different length vectors A and B.
See Also
References [1] Bendat , J .S., and A.G. Pier sol. Random Data: Analysis and Measurement
Procedures. New Yor k: J ohn Wiley & Sons, 1971. Pg. 332.
[2] Oppenheim, A.V., and R.W. Schafer . Digital S ignal Processing. Englewood
Cliffs, NJ : Pr ent ice Hall, 1975. Pgs. 63-67, 746-747, 839-842.
conv Convolut ion and polynomial mult iplicat ion.
corrcoef Cor r elat ion coefficient mat r ix.
cov Covar iance mat r ix.
xcorr2 Two-dimensional cr oss-cor r elat ion.
xcov Cr oss-covar iance funct ion est imat e (equal t o
mean-r emoved cr oss-cor r elat ion).
xcorr2
6-372
6xcor r 2
Purpose Two-dimensional cr oss-cor r elat ion.
Syntax C = xcorr2(A)
C = xcorr2(A,B)
Description C = xcorr2(A,B) r et ur ns t he cr oss-cor r elat ion of mat r ices A and B wit h no
scaling. xcorr2 is t he t wo-dimensional ver sion of xcorr. It has it s maximum
value when t he t wo mat r ices ar e aligned so t hat t hey ar e shaped as similar ly
as possible.
xcorr2(A) is t he aut ocor r elat ion mat r ix of input mat r ix A. It is ident ical t o
xcorr2(A,A).
See Also
conv2 Two-dimensional convolut ion.
filter2 Two-dimensional digit al filt er ing.
xcorr Cr oss-cor r elat ion funct ion est imat e.
xcov
6-373
6xcov
Purpose Cr oss-covar iance funct ion est imat e (equal t o mean-r emoved cr oss-cor r elat ion).
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 est imat es t he cr oss-covar iance sequence of r andom pr ocesses.
Aut ocovar iance is handled as a special case.
The t r ue cr oss-covar iance sequence is t he mean-r emoved cr oss-cor r elat ion
sequence
wher e m
x
and m
y
ar e t he mean values of t he t wo st at ionar y r andom pr ocesses,
and E{}is t he expect ed value oper at or . xcov est imat es t he sequence because, in
pr act ice, access is available t o only a finit e segment of t he infinit e-lengt h
r andom pr ocess.
v = xcov(x,y) r et ur ns t he cr oss-covar iance sequence in a lengt h 2N-1 vect or ,
wher e x and y ar e lengt h N vect or s.
v = xcov(x) is t he aut ocovar iance sequence for t he vect or x. Wher e x is an
N-by-P ar r ay, v = xcov(X) r et ur ns am ar r ay wit h 2N-1 r ows whose P
2
columns
cont ain t he cr oss-covar iance sequences for all combinat ions of t he columns of X.
By default , xcov comput es r aw covar iances wit h no nor malizat ion. For a lengt h
N vect or :
The out put vect or c has element s given by c(m) = c
xy
(m-N), m=1,...,2N-1.

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

,


_
y
n m +
*
1
N
---- y
i
*
=

,


_
n 0 =
N m 1

m 0
c
yx
*
m ( ) m 0 <

'

=
xcov
6-374
The covar iance funct ion r equir es nor malizat ion t o est imat e t he funct ion
pr oper ly.
v = xcov(x,'option') specifies a scaling opt ion, wher e option is:
biased, for biased est imat es of t he cr oss-covar iance funct ion
unbiased, for unbiased est imat es of t he cr oss-covar iance funct ion
coeff, t o nor malize t he sequence so t he aut o-covar iances at zer o lag ar e
ident ically 1.0
none, t o use t he r aw, unscaled cr oss-covar iances (default )
See [1] for mor e infor mat ion on t he pr oper t ies of biased and unbiased
cor r elat ion and covar iance est imat es.
[c,lags] = xcov(x,y,maxlags) wher e x and y ar e lengt h m vect or s, r et ur ns
t he cr oss-covar iance sequence in a lengt h 2*maxlags+1 vect or c. lags is a
vect or of t he lag indices wher e c was est imat ed, t hat is, [maxlags:maxlags].
[c,lags] = xcov(x,maxlags) is t he aut ocovar iance sequence over t he r ange
of lags [maxlags:maxlags].
[c,lags] = xcov(x,maxlags) wher e x is an m-by-p ar r ay, r et ur ns ar r ay c wit h
2*maxlags+1 r ows whose P
2
columns cont ain t he cr oss-covar iance sequences
for all combinat ions of t he columns of x.
[c,lags] = xcov(x,y,maxlags,'option') specifies a scaling opt ion, wher e
option is t he last input ar gument .
In all cases, xcov gives an out put such t hat t he zer ot h lag of t he covar iance
vect or is in t he middle of t he sequence, at element or r ow maxlag+1 or at m.
Examples The second out put lags is useful when plot t ing. For example, t he est imat ed
aut ocovar iance of unifor m whit e noise c
ww
(m) can be displayed for -10 m 10
using
ww = randn(1000,1); % generate uniform noise with mean = 1/2
[cov_ww,lags] = xcov(ww,10,'coeff');
stem(lags,cov_ww)
xcov
6-375
Algorithm xcov comput es t he mean of it s input s, subt r act s t he mean, and t hen calls
xcorr. For mor e infor mat ion on est imat ing covar iance and cor r elat ion
funct ions, see [1] and [2].
Diagnostics xcov does not check for any er r or s ot her t han t he cor r ect number of input
ar gument s. Inst ead, it r elies on t he er r or checking in xcorr, which it calls.
See Also
References [1] Bendat , J .S., and A.G. Pier sol. Random Data: Analysis and Measurement
Procedures. New Yor k: J ohn Wiley & Sons, 1971. Pg. 332.
[2] Oppenheim, A.V., and R.W. Schafer . Digital S ignal Processing. Englewood
Cliffs, NJ : Pr ent ice Hall, 1975. Pgs. 63-67, 746-747, 839-842.
conv Convolut ion and polynomial mult iplicat ion.
corrcoef Cor r elat ion coefficient mat r ix.
cov Covar iance mat r ix.
xcorr Cr oss-cor r elat ion funct ion est imat e.
xcorr2 Two-dimensional cr oss-cor r elat ion.
yulewalk
6-376
6yulewalk
Purpose Recur sive digit al filt er design.
Syntax [b,a] = yulewalk(n,f,m)
Description yulewalk designs r ecur sive IIR digit al filt er s using a least -squar es fit t o a
specified fr equency r esponse.
[b,a] = yulewalk(n,f,m) r et ur ns r ow vect or s b and a cont aining t he n+1
coefficient s of t he or der n IIR filt er whose fr equency-magnit ude char act er ist ics
appr oximat ely mat ch t hose given in vect or s f and m:
f is a vect or of fr equency point s, specified in t he r ange bet ween 0 and 1,
wher e 1 cor r esponds t o half t he sample fr equency (t he Nyquist fr equency).
The fir st point of f must be 0 and t he last point 1, wit h all int er mediat e
point s in incr easing or der . Duplicat e fr equency point s ar e allowed,
cor r esponding t o st eps in t he fr equency r esponse.
m is a vect or cont aining t he desir ed magnit ude r esponse at t he point s
specified in f.
f and m must be t he same lengt h.
plot(f,m) displays t he filt er shape.
The out put filt er coefficient s ar e or der ed in descending power s of z,
When specifying t he fr equency r esponse, avoid excessively shar p t r ansit ions
fr om passband t o st opband. You may need t o exper iment wit h t he slope of t he
t r ansit ion r egion t o get t he best filt er design.
Example Design an 8t h-or der lowpass filt er and over plot t he desir ed fr equency r esponse
wit h t he act ual fr equency r esponse:
f = [0 0.6 0.6 1];
m = [1 1 0 0];
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
6-377
[b,a] = yulewalk(8,f,m);
[h,w] = freqz(b,a,128);
plot(f,m,w/pi,abs(h),'--')
Algorithm yulewalk per for ms a least -squar es fit in t he t ime domain. It comput es t he
denominat or coefficient s using modified Yule-Walker equat ions, wit h
cor r elat ion coefficient s comput ed by inver se Four ier t r ansfor mat ion of t he
specified fr equency r esponse. To comput e t he numer at or , yulewalk t akes t he
following st eps:
1 Comput es a numer at or polynomial cor r esponding t o an addit ive
decomposit ion of t he power fr equency r esponse.
2 Evaluat es t he complet e fr equency r esponse cor r esponding t o t he numer at or
and denominat or polynomials.
3 Uses a spect r al fact or izat ion t echnique t o obt ain t he impulse r esponse of t he
filt er .
4 Obt ains t he numer at or polynomial by a least -squar es fit t o t his impulse
r esponse.
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
yulewalk
6-378
See Also
References [1] Fr iedlander , B., and B. Por at . The Modified Yule-Walker Met hod of ARMA
Spect r al Est imat ion. IEEE Transactions on Aerospace Electronic S ystems.
AES-20, No. 2 (Mar ch 1984). Pgs. 158-173.
butter But t er wor t h analog and digit al filt er design.
cheby1 Chebyshev t ype I filt er design (passband r ipple).
cheby2 Chebyshev t ype II filt er design (st opband r ipple).
ellip Ellipt ic (Cauer ) filt er design.
fir2 Window-based finit e impulse r esponse filt er design
ar bit r ar y r esponse.
firls Least squar e linear-phase FIR filt er design.
maxflat Gener alized digit al But t er wor t h filt er design.
remez Par ks-McClellan opt imal FIR filt er design.
zp2sos
6-379
6zp2sos
Purpose Conver sion of zer o-pole-gain t o second-or der sect ions.
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 conver t s a zer o-pole-gain r epr esent at ion of a given syst em t o an
equivalent second-or der sect ion r epr esent at ion.
[sos,g] = zp2sos(z,p,k) finds a mat r ix sos in second-or der sect ion for m
wit h gain g equivalent t o t he zer o-pole-gain syst em r epr esent ed by input
ar gument s z, p, and k. Vect or s z and p cont ain t he zer os and poles of t he syst em
H(z), not necessar ily in any or der :
wher e n and m ar e t he lengt hs of z and p, r espect ively, and k is a scalar gain.
The zer os and poles must be r eal or complex conjugat e pair s. sos is an L-by-6
mat r ix:
whose r ows cont ain t he numer at or and denominat or coefficient s b
ik
and a
ik
of
t he second-or der sect ions of H(z):
The number of r ows L of mat r ix sos is t he maximum of t he ceiling of n/2 and
t he ceiling of m/2.
H z ( ) k
z z
1
( ) z z
2
( )Lz z
n
( )
z p
1
( ) z p
2
( )Lz 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
2 k
z
2
+ +
1 a
1 k
z
1
a
2k
z
2
+ +
--------------------------------------------------------- -
k 1 =
L

= =
zp2sos
6-380
[sos,g] = zp2sos(z,p,k,'order') specifies t he or der of t he r ows in sos,
wher e order is:
down, t o or der t he sect ions so t he fir st r ow of sos cont ains t he poles closest t o
t he unit cir cle
up, t o or der t he sect ions so t he fir st r ow of sos cont ains t he poles far t hest
fr om t he unit cir cle (default )
[sos,g] = zp2sos(z,p,k,'order','scale') specifies t he desir ed scaling of
t he gain and t he numer at or coefficient s of all second-or der sect ions, wher e
scale is:
none, t o apply no scaling (default )
inf, t o apply infinit y-nor m scaling
two, t o apply 2-nor m scaling
Using infinit y-nor m scaling in conjunct ion wit h up-or der ing minimizes t he
pr obabilit y of over flow in t he r ealizat ion. Using 2-nor m scaling in conjunct ion
wit h down-or der ing minimizes t he peak r ound-off noise.
sos = zp2sos(...) embeds t he over all syst em gain, g, in t he fir st sect ion,
H
1
(z), so t hat
Example Find a second-or der sect ion for m of a But t er wor t h lowpass filt er :
[z,p,k] = butter(5,0.2);
sos = zp2sos(z,p,k);
Algorithm zp2sos uses a four -st ep algor it hm t o det er mine t he second-or der sect ion
r epr esent at ion for an input zer o-pole-gain syst em:
1 It gr oups t he zer os and poles int o complex conjugat e pair s using t he
cplxpair funct ion.
2 It for ms t he second-or der sect ion by mat ching t he pole and zer o pair s
accor ding t o t he following r ules:
H z ( ) H
k
z ( )
k 1 =
L

=
zp2sos
6-381
a Mat ch t he poles closest t o t he unit cir cle wit h t he zer os closest t o t hose
poles.
b Mat ch t he poles next closest t o t he unit cir cle wit h t he zer os closest t o
t hose poles.
c Cont inue unt il all of t he poles and zer os ar e mat ched.
zp2sos gr oups r eal poles int o sect ions wit h t he r eal poles closest t o t hem in
absolut e value. The same r ule holds for r eal zer os.
3 It or der s t he sect ions accor ding t o t he pr oximit y of t he pole pair s t o t he unit
cir cle. zp2sos nor mally or der s t he sect ions wit h poles closest t o t he unit
cir cle last in t he cascade. You can t ell zp2sos t o or der t he sect ions in t he
r ever se or der by specifying t he down flag.
4 zp2sos scales t he sect ions by t he nor m specified in t he 'scale' ar gument .
For ar bit r ar y H(), t he scaling is defined by:
wher e p can be eit her or 2. See t he r efer ences for det ails on t he scaling.
This scaling is an at t empt t o minimize over flow or peak r ound-off noise in
fixed point filt er implement at ions.
See Also
H
p
1
2
------ H ( )
p
d
0
2

1
p
---
=
cplxpair Gr oup complex number s int o complex conjugat e
pair s.
sos2zp Conver sion of second-or der sect ions t o zer o-pole-gain.
ss2sos Conver sion of st at e-space t o second-or der sect ions.
tf2sos Conver sion of t r ansfer funct ion t o second-or der
sect ions.
zp2ss Conver sion of zer o-pole-gain t o st at e-space.
zp2tf Conver sion of zer o-pole-gain t o t r ansfer funct ion.
zp2sos
6-382
References [1] J ackson, L.B. Digital Filters and S ignal Processing. 3r d ed. Bost on: Kluwer
Academic Publisher s, 1996. Chapt er 11.
[2] Mit r a, S.K. Digital S ignal Processing: A Computer-Based Approach. New
Yor k: McGr aw-Hill, 1998. Chapt er 9.
[3] Vaidyanat han, P.P. Robust Digit al Filt er St r uct ur es. Handbook for
Digital S ignal Processing. S.K. Mit r a and J .F. Kaiser , ed. Chapt er 7. New Yor k:
J ohn Wiley & Sons, 1993.
zp2ss
6-383
6zp2ss
Purpose Conver sion of zer o-pole-gain t o st at e-space.
Syntax [A,B,C,D] = zp2ss(z,p,k)
Description zp2ss conver t s a zer o-pole-gain r epr esent at ion of a given syst em t o an
equivalent st at e-space r epr esent at ion.
[A,B,C,D] = zp2ss(z,p,k) finds a single input , mult iple out put , st at e-space
r epr esent at ion
given a syst em in fact or ed t r ansfer funct ion for m
Column vect or p specifies t he pole locat ions, and mat r ix z t he zer o locat ions
wit h as many columns as t her e ar e out put s. The gains for each numer at or
t r ansfer funct ion ar e in vect or k. The A, B, C, and D mat r ices ar e r et ur ned in
cont r oller canonical for m.
Inf values may be used as place holder s in z if some columns have fewer zer os
t han ot her s.
Algorithm zp2ss, for single-input syst ems, gr oups complex pair s t oget her int o t wo-by-t wo
blocks down t he diagonal of t he A mat r ix. This r equir es t he zer os and poles t o
be r eal or complex conjugat e pair s.
See Also
x

Ax Bu + =
y Cx Du + =
H s ( )
Z s ( )
P s ( )
---------- k
s z
1
( ) s z
2
( )Ls z
n
( )
s p
1
( ) s p
2
( )Ls p
n
( )
--------------------------------------------------------------- = =
sos2ss Conver sion of second-or der sect ions t o st at e-space.
ss2zp Conver sion of st at e-space t o zer o-pole-gain.
tf2ss Conver sion of t r ansfer funct ion t o st at e-space.
zp2sos Conver sion of zer o-pole-gain t o second-or der sect ions.
zp2tf Conver sion of zer o-pole-gain t o t r ansfer funct ion.
zp2tf
6-384
6zp2t f
Purpose Conver sion of zer o-pole-gain t o t r ansfer funct ion.
Syntax [b,a] = zp2tf(z,p,k)
Description zp2tf for ms t r ansfer funct ion polynomials fr om t he zer os, poles, and gains of a
syst em in fact or ed for m.
[b,a] = zp2tf(z,p,k) finds a r at ional t r ansfer funct ion:
given a syst em in fact or ed t r ansfer funct ion for m:
Column vect or p specifies t he pole locat ions, and mat r ix z t he zer o locat ions,
wit h as many columns as t her e ar e out put s. The gains for each numer at or
t r ansfer funct ion ar e in vect or k. The zer os and poles must be r eal or come in
complex conjugat e pair s. The polynomial coefficient s ar e r et ur ned in vect or s:
t he denominat or coefficient s in r ow vect or a and t he numer at or coefficient s in
mat r ix b, wit h as many r ows as t her e ar e columns of z.
Inf values can be used as place holder s in z if some columns have fewer zer os
t han ot her s.
Algorithm The syst em is conver t ed t o t r ansfer funct ion for m using poly wit h p and t he
columns of Z.
See Also
B s ( )
A s ( )
---------- -
b
1
s
n b 1 ( )
L b
n b 1 ( )
s b
n b
+ + +
a
1
s
n a 1 ( )
L a
n a 1 ( )
s a
n a
+ + +
---------------------------------------------------------------------------------- - =
H s ( )
Z s ( )
P s ( )
---------- k
s z
1
( ) s z
2
( )Ls z
m
( )
s p
1
( ) s p
2
( )Ls p
n
( )
--------------------------------------------------------------- = =
sos2tf Conver sion of second-or der sect ions t o t r ansfer
funct ion.
ss2tf Conver sion of st at e-space t o t r ansfer funct ion.
tf2zp Conver sion of t r ansfer funct ion t o zer o-pole-gain.
zp2sos Conver sion of zer o-pole-gain t o second-or der sect ions.
zp2ss Conver sion of zer o-pole-gain t o st at e-space.
zplane
6-385
6zplane
Purpose Zer o-pole plot .
Syntax zplane(z,p)
zplane(b,a)
[hz,hp,ht] = zplane(z,p)
Description This funct ion displays t he poles and zer os of discr et e-t ime syst ems.
zplane(z,p) plot s t he zer os specified in column vect or z and t he poles specified
in column vect or p in t he cur r ent figur e window. The symbol 'o' r epr esent s a
zer o and t he symbol 'x' r epr esent s a pole. The plot includes t he unit cir cle for
r efer ence. If z and p ar e ar r ays, zplane plot s t he poles and zer os in t he columns
of z and p, r espect ively, in differ ent color s.
You can over r ide t he aut omat ic scaling of zplane using
axis([xmin xmax ymin ymax])
or
set(gca,'ylim',[ymin ymax])
or
set(gca,'xlim',[xmin xmax])
aft er calling zplane. This is useful in t he case wher e one or a few of t he zer os
or poles have such a lar ge magnit ude t hat t he ot her s ar e gr ouped t ight ly
ar ound t he or igin and ar e har d t o dist inguish.
zplane(b,a) wher e b and a ar e r ow vect or s, fir st uses roots t o find t he zer os
and poles of t he t r ansfer funct ion r epr esent ed by numer at or coefficient s b and
denominat or coefficient s a.
[hz,hp,ht] = zplane(z,p) r et ur ns vect or s of handles t o t he zer o lines, hz,
and t he pole lines, hp. ht is a vect or of handles t o t he axes/unit cir cle line and
t o t ext object s, which ar e pr esent when t her e ar e mult iple zer os or poles. If
t her e ar e no zer os or no poles, hz or hp is set t o t he empt y mat r ix [].
zplane
6-386
Examples Plot t he poles and zer os of a 5t h-or der But t er wor t h lowpass digit al filt er wit h
cut off fr equency of 0.2:
[z,p,k] = butter(5,0.2);
zplane(z,p);
title('5th-Order Butterworth Lowpass Digital Filter');
To gener at e t he same plot wit h a t r ansfer funct ion r epr esent at ion of t he filt er :
[b,a] = butter(5,0.2); % transfer function
zplane(b,a)
See Also
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
5
Real Part
I
m
a
g
i
n
a
r
y

P
a
r
t
5thOrder Butterworth Lowpass Digital Filter
freqz Fr equency r esponse of digit al filt er s.
I-1
Index
A
abs 6-2, 6-12
ac2poly 6-3, 6-13
ac2rc 6-3, 6-14
algor it hm, filt er ing in SPTool 5-18
aliased sinc funct ion. S ee Dir ichlet funct ion
aliasing
and impulse invar iance 2-42
pr event ing dur ing r esampling 4-21
r educing wit h analyt ic signal 4-38
all-pole filt er . S ee IIR filt er
all-zer o filt er . S ee FIR filt er
am 4-29
AM. S ee amplit ude modulat ion
amdsbsc 4-29, 6-236
amdsbtc 4-29, 6-236
amplit ude demodulat ion
double side-band, suppr essed car r ier 6-114
double side-band, t r ansmit t ed car r ier 6-114
single side-band 6-114
amplit ude modulat ion 4-29
double side-band, suppr essed car r ier 6-236
double side-band, t r ansmit t ed car r ier 6-236
single side-band 6-236
amssb 4-30, 6-236
analog filt er
Bessel 6-22
But t er wor t h 6-44
Chebyshev t ype I 6-66
Chebyshev t ype II 6-71
conver t ing t o digit al 2-41, 6-194
design 2-7
Bessel 2-11, 6-22
But t er wor t h 6-43
Chebyshev t ype I 6-65
Chebyshev t ype II 6-71
ellipt ic 6-125, 6-126
inver se 6-203
fr equency r esponse 1-26, 6-173
or der est imat ion
But t er wor t h 6-49
Chebyshev t ype I 6-56
Chebyshev t ype II 6-61
ellipt ic 6-133
r epr esent at ional models 1-40
analog fr equency xvii
analog pr ot ot ype 2-38
Bessel filt er 2-11, 6-21
But t er wor t h filt er 2-8, 6-42
Chebyshev t ype I filt er 2-9, 6-54
Chebyshev t ype II filt er 2-10, 6-59
conver sion t o bandpass 6-220
conver sion t o bandst op 6-223
conver sion t o highpass 6-225
conver sion t o lowpass 6-227
ellipt ic filt er 6-131
fr equency r esponse 2-12
plot t ing 2-12
analog pr ot ot ype design
Bessel 2-38
bilinear t r ansfor mat ion 2-43
But t er wor t h 2-38
Chebyshev 2-38
ellipt ic 2-38
filt er discr et izat ion 2-41
fr equency t r ansfor mat ion 2-38
impulse invar iance 2-42
Index
I-2
S ee also IIR filt er design
analog signal. S ee signal
analyt ic signal 2-26, 6-187
applicat ions 4-38
pr oper t ies 4-38
angle 6-2, 6-15
ant i-symmet r ic filt er 2-25
Apply but t on, Spect r um Viewer 5-97
Apply Filt er but t on 5-18
applying par amet er s wit h Apply but t on 5-100
arburg 4-11, 6-16
arcov 4-11, 6-17
ARMA filt er 1-15
S ee also IIR filt er
ARMA model 4-13, 4-15
Pr onys met hod 4-13
St eiglit z-McBr ide met hod 4-15
armcov 4-11, 6-18
ar r ay
display in Signal Br owser 5-47, 5-51
in SPTool 5-14
Ar r ay Signals but t on, Signal Br owser 5-47, 5-51
ARX model 4-13
aryule 4-11, 6-19
ASCII file, impor t ing 1-13
at t enuat ion, st opband 5-70
at t r ibut es, inst ant aneous 6-187
aut ocor r elat ion 6-368
mult iple channels 3-4
t wo-dimensional 6-372
aut ocor r elat ion sequence
conver t ing fr om filt er coefficient s 6-262
conver t ing fr om r eflect ion coefficient s 6-282
conver t ing t o filt er coefficient s 6-13
conver t ing t o r eflect ion coefficient s 6-14
aut ocovar iance 6-373
mult iple channels 3-4
aut or egr essive (AR) filt er 1-15
S ee also IIR filt er
aut or egr essive (AR) model
via Bur g met hod 6-16, 6-239
via covar iance met hod 6-17, 6-243
via modified covar iance met hod 6-18, 6-247
via Yule-Walker AR met hod 6-19, 6-278
aut or egr essive moving aver age (ARMA) filt er 1-15
S ee also IIR filt er
aut o-spect r um, in SPTool 5-15
aver aging filt er 1-14
axis labels, in Signal Br owser 5-20, 5-23
axis par amet er s
in Filt er Viewer 5-20
in Spect r um Viewer 5-20
axis scaling r ange
in Filt er Viewer 5-25, 5-87
in Spect r um Viewer 5-24, 5-100, 5-102
axis scaling unit s
in Filt er Viewer 5-25, 5-87
in Spect r um Viewer 5-24, 5-100, 5-102
B
band edges, pr ewar ping 2-44
bandlimit ed int er polat ion 6-314
bandpass filt er
analog pr ot ot ype design 2-6
and impulse invar iance 2-42
Bessel 6-22
But t er wor t h 6-43, 6-44
Chebyshev t ype I 6-65, 6-66
Chebyshev t ype II 6-70, 6-71
ellipt ic 6-125, 6-126
example, Chebyshev t ype I 2-40
FIR design, wit h window met hod 2-21, 6-154
t r ansfor mat ion fr om lowpass t o 6-220
Index
I-3
bandst op filt er
analog pr ot ot ype design 2-6
Bessel 6-22
But t er wor t h 6-44, 6-45
Chebyshev t ype I 6-66, 6-67
Chebyshev t ype II 6-71, 6-72
ellipt ic 6-126, 6-127
FIR design, wit h window met hod 2-21, 6-153
t r ansfor mat ion fr om lowpass t o 6-223
bandwidt h 2-40
bartlett 4-2, 6-8, 6-20
compar ed t o triang 6-20
example 4-2
Bar t let t window 4-2
coefficient s 6-20
Bessel filt er
analog 6-22
analog pr ot ot ype 2-11, 2-38, 6-21
bandpass configur at ion, analog 6-22
bandst op configur at ion, analog 6-22
char act er ist ics 2-11
highpass configur at ion, analog 6-22
limit at ions 6-24
lowpass configur at ion, analog 6-22
besselap 2-5, 6-10, 6-21
example 2-11
besself 2-5, 2-6, 6-5, 6-22
bet a par amet er , of Kaiser window 5-75
bias
cor r elat ion 3-3, 4-12
power spect r al densit y 3-12
spect r al densit y 3-12
var iance t r ade-off 3-4
bilinear 2-5, 2-42, 2-43, 6-11, 6-25
bilinear t r ansfor mat ion 2-43, 6-25
defined 2-43
out put r epr esent at ion 6-26
pr ewar ping 2-44, 6-25
blackman 4-2, 6-8, 6-30
Blackman window 4-4, 6-30
defined 4-4
boxcar 4-2, 6-8, 6-32
example 4-2
boxcar window. S ee r ect angular window
br acket s, indicat ing closed int er val xvii
buffer ing 6-33
Bur g met hod 3-5, 3-6, 3-20
compar ed t o Welchs met hod 3-22
defined 3-20
example 3-21
in Spect r um Viewer 5-104
buttap 2-5, 6-10, 6-42
example 2-8
butter 2-5, 2-6, 6-5, 6-43
But t er wor t h filt er
analog 6-44
analog pr ot ot ype 2-8, 2-38, 6-42
bandpass configur at ion
analog 6-44
digit al 6-43
bandst op configur at ion
analog 6-45
digit al 6-44
char act er ist ics 2-8
design 6-43
digit al 6-43
gener alized 2-14
highpass configur at ion
analog 6-45
digit al 6-44
limit at ions 6-47
lowpass configur at ion
analog 6-44
digit al 6-43
Index
I-4
or der est imat ion 2-7, 6-48
buttord 2-5, 6-5, 6-48
C
canonical for ms 1-17, 6-351
car r ier fr equency 4-29, 6-236, 6-365
car r ier signal 4-29, 6-114
cascade, digit al filt er 1-37
Cauer filt er . S ee ellipt ic filt er
cceps 4-23, 6-9, 6-52
example 4-23
cent er fr equency 2-40
cent r al feat ur es 1-2
cepst r um
applicat ions 4-23
complex 4-23
inver se 4-23, 4-25
over view 4-23
r eal 4-23
S ee also r eal cepst r um, complex cepst r um
cepst r um analysis 4-23
cheb1ap 2-5, 6-10, 6-54
example 2-9, 2-40
cheb1ord 2-5, 6-5, 6-55
cheb2ap 2-5, 6-10, 6-59
example 2-10
cheb2ord 2-5, 6-5, 6-60
chebwin 4-2, 6-8, 6-64
cheby1 2-5, 2-6, 6-5, 6-65
example 2-45
cheby2 2-5, 2-6, 6-5, 6-70
Chebyshev er r or minimizat ion 2-22, 6-287
Chebyshev t ype I filt er
analog 6-66
analog pr ot ot ype 2-9, 2-38, 6-54
bandpass configur at ion
analog 6-66
digit al 6-65
bandst op configur at ion
analog 6-67
digit al 6-66
char act er ist ics 2-9
design 6-65
digit al 6-65
highpass configur at ion
analog 6-67
digit al 6-66
lowpass configur at ion
analog 6-66
digit al 6-65
or der est imat ion 2-7, 6-55
Chebyshev t ype II filt er
analog 6-71
analog pr ot ot ype 2-38, 6-59
bandpass configur at ion
analog 6-71
digit al 6-70
bandst op configur at ion
analog 6-72
digit al 6-71
char act er ist ics 2-10
design 6-70
digit al 6-70
highpass configur at ion
analog 6-72
digit al 6-71
limit at ions 6-69
lowpass configur at ion
analog 6-71
digit al 6-70
or der est imat ion 2-7, 6-60
Chebyshev window 4-9, 6-64
Index
I-5
fr equency r esponse 4-9
chirp 1-9, 6-2, 6-75
chir p signal 1-9
chir p z-t r ansfor m (CZT) 4-34, 6-105
compar ed t o discr et e Four ier t r ansfor m 4-34
execut ion t ime 4-35
for nar r owband fr equency analysis 6-105
classical IIR filt er design 2-8
click-and-dr ag panning, in Signal Br owser 5-48
coefficient s
cor r elat ion 6-88
filt er 1-15, 5-79, 6-13, 6-262, 6-263, 6-283
linear pr edict ion 6-229
r eflect ion 1-37, 6-14, 6-263, 6-282, 6-283
sequence 6-282
cohere 3-6, 3-16, 6-7, 6-79
coher ence 3-15, 6-79
defined 3-15
coher ence funct ion 3-15
Color but t on 5-35
color or der
in Signal Br owser 5-22
in Spect r um Viewer 5-22
Color Or der t ext box 5-22
color , cust omizing in SPTool 5-20
column index vect or , ent er ing in Signal Br owser
5-47
column, ar r ay 5-47
communicat ions 4-10
communicat ions simulat ion 4-29, 6-114, 6-236
S ee also modulat ion, demodulat ion, volt age
cont r olled oscillat ion
Compact Disc st andar d 4-20
complex cepst r um, defined 4-23
complex conjugat e 6-90
Complex Display mode 5-47
complex envelope 4-38
complex number s, gr ouping by conjugat e 6-90
complex signals, in Signal Br owser 5-47
comput at ion par amet er s, in Spect r um Viewer
5-103, 5-104
Conf. Int . check box 5-107
confidence int er val
for cr oss spect r al densit y 3-14
for power spect r al densit y 3-14, 5-107
set t ing in Spect r um Viewer 5-107
conser vat ion of t ot al power , using pmtm 3-19
cont ext sensit ive help in SPTool 5-7
cont inuous signal. S ee signal
cont inuous-t ime filt er . S ee analog filt er
cont r ol syst ems 1-35
Cont r ol Syst ems Toolbox 1-35, 6-198
conv 1-14, 1-20, 6-2, 6-83
conv2 1-14, 6-2, 6-84
conver sion
aut ocor r elat ion sequence t o filt er coefficient s
6-13
aut ocor r elat ion sequence t o r eflect ion
coefficient s 6-14
filt er coefficient s t o aut ocor r elat ion sequence
6-262
filt er coefficient s t o r eflect ion coefficient s 6-263,
6-283
r eflect ion coefficient s t o aut ocor r elat ion
sequence 6-282
second-or der sect ions t o st at e-space 6-316
second-or der sect ions t o t r ansfer funct ion
6-318
second-or der sect ions t o zer o-pole-gain 6-320
st at e-space t o second-or der sect ions 6-333
st at e-space t o zer o-pole-gain 6-338
t r ansfer funct ion t o lat t ice 6-346
t r ansfer funct ion t o second-or der sect ions
6-347
Index
I-6
t r ansfer funct ion t o st at e-space 6-350
zer o-pole-gain t o second-or der sect ion 6-379
zer o-pole-gain t o st at e-space 6-383
convmtx 1-39, 1-42, 6-3, 6-86
convolut ion
and cr oss-cor r elat ion 3-3
and filt er ing 1-14, 6-148
convolut ion mat r ix 1-39, 6-86
defined 6-83
example 1-14
t wo-dimensional 6-84
obt aining subsect ion 6-84
convolut ion mat r ix 1-42, 6-86
defined 1-39
example 6-86
corrcoef 6-7, 6-88
cor r elat ion 3-2
coefficient mat r ix 6-88
S ee also aut ocor r elat ion, cr oss-cor r elat ion
cosine window 4-4
cov 6-7, 6-89
covar iance 3-2
mat r ix 6-89
S ee also aut ocovar iance, cr oss-covar iance
covar iance met hod 3-6, 3-22
defined 3-22
example 3-23
covar iance met hod, in Spect r um Viewer 5-105
cplxpair 6-9, 6-90
Cr eat e but t on, in Spect r a panel 5-19, 5-97
cremez 2-17, 6-5, 6-91
cr oss spect r al densit y 3-14, 6-100
confidence int er val 3-14
defined 3-5
cr oss-cor r elat ion 6-367
biased 3-3
mult iple channels 3-4
nor malizat ion 3-4
t wo-dimensional 6-372
unbiased 3-3
cr oss-covar iance 6-373
mult iple channels 3-4
csd 3-6, 3-14, 6-7, 6-100
CSD. S ee cr oss spect r al densit y
cut off fr equency 2-38
defined 6-22
for Kaiser window filt er 5-75
czt 4-35, 6-6, 6-105
CZT. S ee chir p z-t r ansfor m
D
dat a
duplicat ing in SPTool 5-16
edit ing in SPTool 5-13, 5-15
ent er ing 1-13
expor t ing fr om SPTool 5-6
impor t ing 1-13
impor t ing int o SPTool 5-3, 5-6, 5-7
measur ing in SPTool 5-31
mult ichannel 1-4, 1-7
viewing in SPTool 5-31
dat a compr ession 4-10
dat a mat r ix 1-4, 1-7
dat a vect or 1-4
dct 4-36, 6-6, 6-108
example 4-37
decimate 6-9, 6-110
decimat ion 6-110
FIR filt er for 6-201
deconv 4-33, 6-9, 6-113
example 4-33
deconvolut ion 4-33, 6-113
default plot , in Spect r um Viewer 5-102
Index
I-7
Default Session check box, in Pr efer ences dialog
box 5-28
Default SPTool session file 5-20, 5-28
default values, using empt y mat r ix 3-11
delay
adding t o signal 2-25
gr oup 1-28
nonint eger 2-26
phase 1-28
demod 4-29, 4-30, 6-9, 6-114
example 4-30
demodulat ion 4-30, 6-114
example 4-30
met hods 4-30, 6-114
design, gener alized filt er 2-5
designed filt er , in SPTool 5-14
DFT. S ee discr et e Four ier t r ansfor m
dftmtx 6-6, 6-117
differ ence equat ion, r elat ion t o t r ansfer funct ion
1-32
differ ent iat or 2-26, 6-167, 6-289
Digit al Audio Tape st andar d 4-20
digit al filt er
ant i-causal 1-20
as convolut ion mat r ix 1-40
But t er wor t h 6-43
cascade 1-37
Chebyshev t ype I 6-65
Chebyshev t ype II 6-70
coefficient s 1-15
design 2-2
ellipt ic 6-125
FIR 2-16
compar ed t o IIR 2-16
fixed-point implement at ion 1-37
fr equency r esponse 1-24
gr oup delay 1-28, 6-182
ident ificat ion fr om fr equency dat a 6-207
IIR 2-4
compar ed t o FIR 2-4
implement at ion 1-14, 6-142, 6-145
FFT-based (FIR) 6-142
over lap-add met hod 1-22
using convolut ion 1-14
using filter funct ion 1-16
impulse r esponse 1-14, 1-23, 6-196
init ial condit ions 1-17
linear syst em models 1-32
names 1-15
or der 1-15
in st at e-space r epr esent at ion 1-34
or der est imat ion
But t er wor t h 6-48
Chebyshev t ype I 6-55
Chebyshev t ype II 6-60
ellipt ic 6-132
equir ipple FIR 6-294
phase delay 1-28, 6-182
poles 1-30, 1-33
r epr esent at ional models 1-32
r epr esent ing in MATLAB 1-32
second-or der sect ions 1-37
specificat ions 2-7
st ar t up t r ansient s 1-21, 1-22
st r uct ur e
lat t ice 1-37
t r ansposed dir ect for m II 1-17
t ime-domain r epr esent at ion 1-16
t r ansfer funct ion r epr esent at ion 1-15
t wo-dimensional 6-148
zer o-phase 1-20, 6-149
zer os 1-30, 1-33
zer os and poles 1-33
S ee also FIR filt er , IIR filt er
Index
I-8
digit al filt er design
FIR 2-16
IIR 2-4
digit al fr equency xvii
dir ect design 2-13
descr ibed 2-13
summar y 2-5
diric 6-2, 6-118
Dir ichlet funct ion 1-11, 6-118
defined 1-11
example 1-12
discr et e cosine t r ansfor m (DCT) 6-108
applicat ions 4-36
ener gy compact ion pr oper t y 4-37
example 4-37
inver se 4-36, 6-190
r econst r uct ing signal fr om few coefficient s
4-37
discr et e Four ier t r ansfor m (DFT) 1-2, 1-43
algor it hms 1-45
and IIR filt er implement at ion 1-22
and spect r al analysis 3-6
applicat ions 6-137
dependence on signal lengt h 1-45
example 1-44
execut ion t ime, using chir p z-t r ansfor m 4-35
inver se 1-43, 6-192
mat r ix 6-117
t wo-dimensional 1-45, 6-193
mat r ix 6-117
t wo-dimensional 1-45, 6-141
S ee also fast Four ier t r ansfor m (FFT), fft
discr et e pr olat e spher oidal sequences (DPSSs)
3-19
discr et e-t ime Four ier t r ansfor m 3-5
discr et izat ion 2-41, 6-194
bilinear t r ansfor mat ion 2-43
pr ewar ping 2-44
impulse invar iance 2-42
disk, loading var iables fr om 5-8
dpss 6-9, 6-119
dpss.mat 3-19
dpssclear 3-19, 6-9, 6-121
dpssdir 3-19, 6-9, 6-122
dpssload 3-19, 6-9, 6-123
DPSSs. S ee discr et e pr olat e spher oidal sequences
dpsssave 3-19, 6-9, 6-124
dut y cycle, specifying 1-8
E
echo det ect ion 4-23
edge effect s 1-22
edge fr equencies, set t ing in Filt er Designer 5-70
Edit Design but t on 5-18, 5-59
eig, in pmusic funct ion 3-25
eigenanalysis
defined 3-24
fr equency est imat or funct ions 3-24
eigenvect or met hod 3-5, 3-23
S ee also mult iple signal classificat ion met hod
ellip 2-5, 2-6, 6-5, 6-125
ellipap 2-5, 6-10, 6-131
example 2-10
ellipord 2-5, 6-5, 6-132
ellipt ic filt er
analog 6-126
analog pr ot ot ype 2-38, 6-131
bandpass configur at ion
analog 6-126
digit al 6-125
Index
I-9
bandst op configur at ion
analog 6-127
digit al 6-126
char act er ist ics 2-10
design 6-125
digit al 6-125
highpass configur at ion
analog 6-127
digit al 6-126
limit at ions 6-129
lowpass configur at ion
analog 6-126
digit al 6-125
or der est imat ion 2-7, 6-132
ener gy compact ion 4-37
equir ipple char act er ist ics
Chebyshev t ype I filt er (passband) 2-9
Chebyshev t ype II filt er (st opband) 2-10
Chebyshev window 4-9
ellipt ic filt er 2-10, 6-125, 6-131
fr om Par ks-McClellan design 6-287
equir ipple filt er 2-22
er r or minimizat ion
bet ween desir ed and act ual r esponse 2-22
for equir ipple filt er 5-75
for least squar es filt er 5-75
int egr al of squar e 2-22
minimax 2-22
weight ing in fr equency bands 2-24
est imat ion
cr oss spect r um 3-14
power spect r um 3-6
t r ansfer funct ion 3-14
S ee also par amet r ic modeling
est imat ion met hods
in Spect r um Viewer 5-103, 5-104
nonpar amet r ic
FFT met hod 5-105
mult iple signal classificat ion met hod
(MUSIC) 3-5, 5-106
mult it aper met hod (MTM) 3-5, 5-105
Welchs met hod 3-5, 5-106
par amet r ic 3-5
Bur g met hod 5-104, 6-16
covar iance met hod 6-17
modified covar iance met hod 6-18
Yule-Walker AR met hod 5-107
Yule-Walker met hod 6-19
Expor t Filt er s as TF object s check box, in
Pr efer ences dialog box 5-29
Expor t menu it em 5-6
Expor t ing Component s check box, in Pr efer ences
dialog box 5-29
expor t ing dat a fr om MATLAB 1-13
ext ensions t o SPTool 5-30
F
Fact or y Set t ings but t on, in Pr efer ences dialog box
5-30
fast Four ier t r ansfor m (FFT) 1-22, 1-43
and fr equency r esponse 1-24
fft 1-22
pr ime fact or algor it hm 1-45, 6-139
r adix-2 algor it hm 1-45, 6-139
r ole in signal pr ocessing 1-43
t wo-dimensional 6-141
fft 1-2, 1-22, 1-43, 6-6, 6-137
complex input s 1-45
example 1-44
execut ion t ime 1-45, 6-140
pr ime fact or algor it hm 1-45, 6-139
r adix-2 algor it hm 1-45, 6-139
Index
I-10
r eal input s 1-45
r ear r anging out put 1-45, 6-144
specifying number of point s 1-44
FFT lengt h
in Filt er Designer 5-20, 5-27
in Filt er Viewer 5-25
FFT Lengt h edit box, in Pr efer ences dialog box
5-25, 5-27
FFT met hod, in Spect r um Viewer 5-105
FFT. S ee fast Four ier t r ansfor m
fft2 1-45, 6-6, 6-141
r ear r anging out put 1-45
FFT-based filt er ing 1-22
fftfilt 1-19, 6-2, 6-142
compar ed t o filter 6-142
fftshift 1-45, 6-6, 6-144
File Cont ent s list 5-8
filt er
analog pr ot ot ype 2-8, 2-11, 6-21, 6-42, 6-54,
6-59, 6-131
analyzing in Filt er Viewer 5-17
applying t o a signal 5-18
But t er wor t h 2-7, 6-43
gener alized 2-14
Chebyshev 2-7
Chebyshev t ype I 6-65
Chebyshev t ype II 6-70
coefficient s 1-15, 2-17, 5-79
design
FIR 6-287
gener alized 2-5
IIR 2-5
inver se 6-203, 6-207
discr et izat ion 2-41
ellipt ic 2-7, 6-125
equir ipple 2-22
expor t ing as TF object s for Cont r ol Syst em
Toolbox 5-29
gr oup delay 5-17
ident ificat ion fr om fr equency dat a 6-203
implement at ion 1-22, 6-142, 6-145
impor t ing int o SPTool 5-7, 5-8, 5-11
impulse r esponse 5-17
linear t ime-invar iant digit al 1-2
magnit ude r esponse 5-17
measur ement s 5-37
median 4-28, 6-235
minimax 2-22
minimum phase 6-265
mult iband FIR 2-22
names 1-15
naming in SPTool 5-16
or der 1-15, 2-7, 6-48, 6-55, 6-60, 6-132
or der select ion 2-7
phase r esponse 5-17
pr incipal suppor t ed 1-2
Savit zky-Golay 6-309, 6-311
second-or der sect ions 6-322
single band FIR 2-20
specificat ions 2-7
st ep r esponse 5-17
t r ansposed dir ect for m II st r uct ur e 1-17
t wo-dimensional 6-148
t ypes 2-17
viewing in Filt er Viewer 5-17
zer os and poles 5-17
S ee also FIR filt er , IIR filt er , digit al filt er ,
analog filt er
filter 1-2, 1-16, 1-20, 6-2, 6-145
compar ed t o fftfilt 6-142
compar ed t o filtfilt 1-21
final condit ion par amet er s 1-17
implement at ion 1-17
Index
I-11
init ial condit ion par amet er s 1-17
init ial condit ions 6-150
filt er coefficient s
conver t ing fr om aut ocor r elat ion sequence
6-13
conver t ing t o aut ocor r elat ion sequence 6-262
conver t ing t o r eflect ion coefficient s 6-263,
6-283
filt er design
in Filt er Designer 5-59, 5-73, 5-76
st andar d band configur at ions 5-59
using specificat ion lines 5-70
Filt er Designer 5-2, 5-17, 5-59, 6-329
act ivat ing 5-17, 5-59
changing plot pr oper t ies 5-27
classical IIR filt er design 5-76
closing 5-60
cust omizing 5-20
magnit ude plot 5-63, 5-69, 5-78
measur ing r esponse char act er ist ics 5-70
saving dat a t o wor kspace 5-79, 5-110
set t ing edge fr equencies 5-70
set t ing passband r ipple 5-70
set t ing st opband at t enuat ion 5-70
single band FIR filt er design 5-73
window 5-60
filt er par amet er s, in Filt er Viewer 5-20
filt er r esponse, peaks and valleys 5-37
filt er t ype
design 5-14
impor t ed 5-14, 5-18
Filt er Viewer 5-2, 5-17, 5-84, 6-330
act ivat ing 5-17, 5-84
cust omizing 5-20
default plot 5-85
plot s 5-86
pr efer ences 5-86
set t ings 5-86
subplot s 5-86
viewing fr equency r esponse 5-82
viewing gr oup delay 5-93
viewing impulse r esponse 5-94
viewing magnit ude r esponse 5-89
viewing phase r esponse 5-91
viewing st ep r esponse 5-95
viewing zer o-pole plot 5-94
window 5-85
filter2 6-3, 6-148
filt er ing
and convolut ion 1-14
ant i-causal 1-20
fr equency domain 1-22
init ial condit ions 1-17
gener at ing 1-18
zer o-phase 1-20
filt er ing algor it hm 5-18
filtfilt 1-19, 1-20, 2-4, 6-3, 6-149
compar ed t o filter 1-21
example 1-20
init ial condit ions 1-21
filtic 1-18, 6-3, 6-150
FIR filt er
ar bit r ar y fr equency r esponse 6-157
compar ed t o IIR 2-16
design 2-16
decimat ion 6-201
int er polat ion 6-201
least squar es met hod 6-166
linear phase 6-166
mult iband fr equency r esponse 6-157
Par ks-McClellan met hod 6-287
window met hod 6-152
differ ent iat or 2-26, 6-167, 6-289
Hilber t t r ansfor mer 2-25, 6-167, 6-289
Index
I-12
implement at ion 1-17, 6-145
FFT-based 1-22, 6-142
over lap-add met hod 1-22, 6-142
linear phase 2-17, 6-287
or der est imat ion, remez funct ion 6-294
t ypes 6-169, 6-292
FIR filt er design 2-16
ant i-symmet r ic 2-25
ar bit r ar y r esponses 2-31
complex filt er s 2-17, 6-91
nonlinear phase 2-17, 6-91
r educed delay 2-34
const r ained least squar es 2-16, 2-27
linear phase 2-28
mult iband 2-28, 2-29
weight ed 2-30
equir ipple 2-16, 2-22, 2-23, 5-73, 5-75
example 5-73, 5-113
in Filt er Designer 5-59, 5-73
Kaiser window 5-73, 5-75
least squar es 2-16, 2-22, 2-23, 5-73, 5-75
least squar es compar ed t o equir ipple 2-23
linear phase filt er s 2-17, 2-22
mult iband 2-16, 2-21, 2-22
or der select ion 5-75
par amet er s in Filt er Designer 5-75
Par ks-McClellan met hod 2-22
r aised cosine met hod 2-17
r ole of Kaiser window 4-7
st andar d band 2-20
windowing met hod 2-16, 2-18
FIR filt er ing, in fr equency domain 1-19
FIR lat t ice filt er , implement at ion 1-38
fir1 2-16, 2-20, 6-5, 6-152
accessing fr om Filt er Designer 5-73, 5-75
fir2 2-16, 2-20, 6-5, 6-157
example 2-21
fircls 2-16, 6-5, 6-160
fircls1 2-16, 6-6, 6-163
firls 2-16, 2-22, 6-6, 6-166
accessing fr om Filt er Designer 5-73, 5-75
compar ed t o remez 2-23
filt er char act er ist ics 6-169
for differ ent iat or design 2-26
weight vect or 2-24
firrcos 2-17, 6-6, 6-171
fixed-point implement at ion, digit al filt er 1-37
fm 4-30
FM. S ee fr equency modulat ion
fopen 1-13
Four ier t r ansfor m, eigenvect or equivalent 3-24
Four ier t r ansfor m, t ime dependent . S ee
t ime-dependent Four ier t r ansfor m
Four ier t r ansfor m. S ee discr et e Four ier t r ansfor m,
fast Four ier t r ansfor m
fread 1-13
freqs 1-26, 6-3, 6-173
freqspace 6-176
fr equency 6-287
analog xvii
angular 2-2
car r ier 4-29, 6-236, 6-365
cent er 2-40
cut off 2-38
digit al xvii
nor malizat ion 2-2
Nyquist xvii, 2-2
pr ewar ping 6-25
t r ansfor mat ion 6-220, 6-223, 6-225, 6-227
vect or 2-24, 6-157, 6-160, 6-376
fr equency analysis
in Filt er Viewer 5-84
t ime-dependent 6-323
Index
I-13
Fr equency Axis Range pop-up menu, in
Pr efer ences dialog box 5-24, 5-25
Fr equency Axis Scaling pop-up menu, in
Pr efer ences dialog box 5-24, 5-25
fr equency axis scaling, in Spect r um Viewer 5-100
fr equency demodulat ion 6-115
fr equency domain
dualit y wit h t ime domain 1-22
FIR filt er ing 1-19
for filt er implement at ion 1-22
fr equency domain based modeling. S ee par amet r ic
modeling
fr equency est imat or funct ions, in eigenanalysis
3-24
fr equency est imat or t echniques
eigenvect or (EV) met hod 3-23
mult iple signal classificat ion (MUSIC) met hod
3-23
fr equency modulat ion 6-237
fr equency point s
freqz 1-24, 1-26
r ange 1-26
spacing 1-26
Fr equency Range pop-up menu, Spect r um Viewer
5-100
fr equency r esponse 1-24
ar bit r ar y 2-13, 6-157
example 1-25
in Filt er Viewer 5-82, 5-84, 5-89
inver se 6-203
Kaiser window 4-6
linear phase 2-17
magnit ude 1-26
minimized er r or bet ween desir ed and act ual
2-22
monot onic 2-9
mult iband 2-13
of Bessel pr ot ot ype 2-11
of But t er wor t h pr ot ot ype 2-8
of Chebyshev t ype I pr ot ot ype 2-9
of Chebyshev t ype II pr ot ot ype 2-10
of Chebyshev window 4-9
of ellipt ic pr ot ot ype 2-10
phase 1-26
unwr apping 1-27
plot t ing 1-25
point s at which evaluat ed 1-24
spacing 6-176
specifying sampling fr equency 1-24
Fr equency Scale pop-up menu, Spect r um Viewer
5-100
fr equency t r ansfor mat ion 2-38
example 2-40
lowpass t o bandpass 6-220
lowpass t o bandst op 6-223
lowpass t o highpass 6-225
lowpass t o lowpass 6-227
fr equency vect or 6-287
freqz 1-24, 6-3, 6-177
fr equency point s 1-24
sampling fr equency 1-24
spacing 6-176
Fr om Disk r adio but t on, in Impor t dialog box 5-8
Fr om Wor kspace r adio but t on, in Impor t dialog
box 5-8
fscanf 1-13
Full View but t on 5-32
G
gauspuls 1-8, 1-10, 6-2, 6-180
Gauss-Newt on met hod 6-205, 6-209
gener alized But t er wor t h filt er 2-14
gener alized cosine window 4-4
Index
I-14
Gibbs effect 2-19
r educed by window 4-2
gr aphical user int er face (GUI) xii, 1-3
gr id lines, in Filt er Designer 5-20, 5-27
gr oup delay 1-28, 5-17, 6-182
defined 1-28
example 1-29
of linear r esponse filt er 2-17
passband 2-11
viewing in Filt er Viewer 5-93
Gr oup Delay check box, Filt er Viewer 5-86
gr oup delay plot 5-86, 5-93
grpdelay 1-28, 6-3, 6-182
GUI. S ee gr aphical user int er face
GUI-based t ools. S ee int er act ive t ools
H
hamming 4-2, 6-8, 6-185
Hamming window 2-20, 4-4, 6-185
HandleVisibility pr oper t y 5-57, 5-110
hanning 4-2, 6-8, 6-186
Hanning window 4-4, 6-186
highpass filt er
analog pr ot ot ype design 2-6
Bessel 6-22
But t er wor t h 6-44, 6-45
Chebyshev t ype I 6-66, 6-67
Chebyshev t ype II 6-71, 6-72
ellipt ic 6-126, 6-127
FIR design
wit h window met hod 2-21, 6-154
t r ansfor mat ion fr om lowpass t o 6-225
hilbert 2-26, 4-38, 6-6, 6-187
example 4-39
Hilber t t r ansfor m 4-34, 4-38, 6-187
and analyt ic signal 2-26
and inst ant aneous at t r ibut es 4-39
example 4-39
Hilber t t r ansfor mer 6-167, 6-289
homomor phic syst ems 4-23
Hor izont al but t on, for r uler s 5-36, 5-38, 5-39
I
icceps 4-23, 4-25, 6-9, 6-189
example 4-26
idct 4-36, 6-6, 6-190
ideal lowpass filt er 2-18
ifft 1-43, 6-6, 6-192
specifying number of point s 1-45
ifft2 1-45, 6-6, 6-193
IIR filt er
ar bit r ar y fr equency r esponse 2-13
Bessel 2-11
But t er wor t h 2-8
Chebyshev t ype I 2-9
Chebyshev t ype II 2-10
compar ed t o FIR 2-4
design 2-4
dir ect 2-13
Levinson-Dur bin r ecur sion 6-218
mult iband 2-13
Pr onys met hod 6-266
St eiglit z-McBr ide it er at ion 6-341
Yule-Walker 6-376
ellipt ic 2-10
implement at ion 6-145
fr equency domain 1-22
zer o-phase 1-20
IIR filt er design 2-4, 2-5
analog pr ot ot ype 2-5
But t er wor t h 2-7, 2-8, 5-76, 5-77
Chebyshev 2-7, 2-9, 2-10, 5-76, 5-77
Index
I-15
classical (analog pr ot ot ype) 2-5, 2-8
compar ison of filt er t ypes 2-8
gener al st eps 2-37
illust r at ion 2-37
in Filt er Designer 5-76
or der est imat ion 2-7
plot t ing pr ot ot ypes 2-12
single st ep 2-6
single st ep or der est imat ion 2-7
syst em model 2-7
dir ect met hods 2-13
Yule-Walker 2-13
ellipt ic 2-7, 2-10, 5-76, 5-77
example 5-76, 5-77
gener alized But t er wor t h 2-14
in Filt er Designer 5-59, 5-76
maximally flat 2-14
par amet er s in Filt er Designer 5-77
t o specificat ions 2-7
S ee also dir ect design, par amet r ic modeling
IIR lat t ice filt er , implement at ion 1-38
image pr ocessing 6-84
wit h fft2 and ifft2 1-45
impinvar 2-5, 2-42, 6-11, 6-194
Impor t As pop-up menu, in Impor t dialog box 5-9
Impor t menu it em 5-4, 5-6
impor t ed filt er , in SPTool 5-14
impulse invar iance 2-42, 6-194
limit at ions 2-42
impulse r esponse 1-23, 5-17, 6-196
and impulse invar iance 2-42
comput ing wit h filter 1-23
comput ing wit h impz 1-23
defined 1-23
example 1-23
of ideal lowpass filt er 2-18
viewing in Filt er Viewer 5-94
Impulse Response check box, Filt er Viewer 5-86
impulse r esponse plot 5-86, 5-94
impz 6-3, 6-196
example 1-23
indexing, of vect or s 1-15
Inher it fr om pop-up menu, Spect r um Viewer
5-100
inher it ing par amet er s 5-100
init ial condit ions 1-17, 1-21, 6-150
gener at ing 1-18
Init ial Type pop-up menu, in Pr efer ences dialog
box 5-21
inst ant aneous at t r ibut es 4-39, 6-187
int er act ive t ools 5-2
ext ended example 5-113
Filt er Designer 5-2, 5-59, 6-329
Filt er Viewer 5-2, 5-84, 6-330
Signal Br owser 5-2, 5-43, 6-328
Spect r um Viewer 5-2, 5-97, 6-331
SPTool 5-2, 6-328
interp 6-9, 6-199
int er polat ion 6-199
FIR filt er design 6-201
int er val not at ion xvii
intfilt 6-6, 6-201
inver se complex cepst r um 4-25
inver se discr et e cosine t r ansfor m 6-190
accur acy of signal r econst r uct ion 4-38
inver se discr et e Four ier t r ansfor m 1-43, 6-192
ifft 1-43
mat r ix 6-117
t wo-dimensional 1-45, 6-193
inver se filt er design 6-207, 6-266
analog 6-203
digit al 6-207
inver se Four ier t r ansfor m, cont inuous. S ee sinc
funct ion
Index
I-16
invfreqs 2-5, 4-11, 4-16, 6-8, 6-203
invfreqz 2-5, 4-11, 4-16, 6-8, 6-207
K
kaiser 4-2, 6-8, 6-210
accessing fr om Filt er Designer 5-73
example 4-5
Kaiser window 4-4, 6-210
and FIR filt er design 4-7, 5-73
bet a par amet er 4-4, 6-210
example 4-5
fr equency r esponse 4-6
kaiserord 2-16, 6-6, 6-211
accessing fr om Filt er Designer 5-75
L
ladder coefficient s 1-38
Lagr ange int er polat ion filt er 6-201
Laplace t r ansfor m 1-41
equivalent t o st at e-space r epr esent at ion 1-41
latc2tf 1-39, 1-42, 6-3, 6-216
latcfilt 1-19, 1-39, 6-3, 6-217
lat t ice coefficient s 1-38
lat t ice filt er 1-42
implement at ion 1-38
implement at ion wit h latcfilt 1-39
lat t ice for m
conver t ing fr om t r ansfer funct ion 6-346
lat t ice st r uct ur e 1-37
lat t ice/ladder filt er
implement at ion 1-38
implement at ion wit h latcfilt 1-39
least squar es met hod, FIR filt er design 6-166
filt er char act er ist ics 6-169
levinson 4-11, 6-8, 6-218, 6-305
and par amet r ic modeling 4-12
Levinson-Dur bin r ecur sion 4-12, 6-218, 6-305
line color
in Filt er Viewer 5-35
in Signal Br owser 5-35
in Spect r um Viewer 5-35
line select ion
in Filt er Viewer 5-34, 5-35
in Signal Br owser 5-34, 5-35
in Spect r um Viewer 5-34, 5-35
line st yle
cust omizing in SPTool 5-20
in Filt er Viewer 5-22, 5-35
in Signal Br owser 5-22, 5-35
in Spect r um Viewer 5-22, 5-35
Line St yle Or der edit box, in Pr efer ences dialog box
5-22
linear phase 2-16, 2-17, 6-166
filt er design 6-287
r elat ed char act er ist ics 2-17
linear pr edict ion coefficient s 6-229
linear pr edict ion modeling 4-12
linear pr edict ive coding
linear swept -fr equency cosine. S ee chir p
linear syst em models 1-32
linear syst em t r ansfor mat ions 1-41
conver sion char t 1-41
linear t ime-invar iant differ ent ial equat ions,
r epr esent ed in st at e-space for m 1-40
load 1-13
lowpass filt er
analog pr ot ot ype design 2-6
and impulse invar iance 2-42
Bessel 6-22
But t er wor t h 6-43, 6-44
Chebyshev t ype I 6-65, 6-66
Chebyshev t ype II 6-70, 6-71
Index
I-17
ellipt ic 6-125, 6-126
FIR design, wit h window met hod 2-21
for decimat ion 6-110
for int er polat ion 6-199
ideal impulse r esponse 2-18
t r anslat ion of cut off fr equency 6-227
lp2bp 2-5, 2-39, 6-10, 6-220
example 2-40
lp2bs 2-5, 2-39, 6-10, 6-223
lp2hp 2-5, 2-39, 6-10, 6-225
lp2lp 2-5, 2-39, 6-10, 6-227
lpc 2-5, 4-11, 6-8, 6-229
S ee also linear pr edict ive coding, Pr onys
met hod
LPC. S ee linear pr edict ion coefficient s
M
magnit ude
of Four ier t r ansfor m of sequence 1-44
of fr equency r esponse 1-26
viewing in Filt er Viewer 5-89
of t r ansfer funct ion est imat e 3-15
vect or 2-24, 6-157, 6-160, 6-376
Magnit ude Axis Scaling pop-up menu, in
Pr efer ences dialog box 5-24, 5-25
Magnit ude check box, Filt er Viewer 5-86
magnit ude plot 5-78
magnit ude plot , in Filt er Designer 5-69, 5-78
magnit ude r esponse 5-17
magnit ude r esponse plot 5-86, 5-89
in Filt er Designer 5-63
Magnit ude Scale pop-up menu, Spect r um Viewer
5-100
magnit ude scale, in Spect r um Viewer 5-100
manufact ur ing 4-10
Mar ker Size edit box, in Pr efer ences dialog box
5-21
mat ch fr equency (for pr ewar ping) 6-25
MAT-file
dpss.mat 3-19
impor t ing 1-13
impor t ing int o SPTool 5-4, 5-6
loading int o SPTool 5-8
MAT-file for mat , conver t ing t o 1-13
mat r ices
convolut ion 1-39, 6-86
cor r elat ion coefficient 6-88
covar iance 6-89
dat a 1-4, 1-7
discr et e Four ier t r ansfor m 6-117
for second-or der sect ions for m 1-37
inver se discr et e Four ier t r ansfor m 6-117
mat r ix for m. S ee st at e-space for m
maxflat 2-5, 2-14, 6-5, 6-233
maxima, local 5-37
maximally flat 2-14
measur ement lines 5-70
measur ement s
in Filt er Viewer 5-37
in Signal Br owser 5-37
in Spect r um Viewer 5-37, 5-101
saving in Filt er Viewer 5-37
saving in Signal Br owser 5-37
saving in Spect r um Viewer 5-37
medfilt1 4-28, 6-9, 6-235
median filt er 4-28, 6-235
message signal 4-29, 6-236
Met hod pop-up menu, Spect r um Viewer 5-103
MEX-file 1-13
M-files 1-3
cr eat ing xii, 1-3
modifying xii
Index
I-18
viewing xii
minima, local 5-37
minimax met hod, FIR filt er design 2-22
S ee also Par ks-McClellan met hod
minimum phase filt er 6-265
models
aut or egr essive 6-16, 6-17, 6-18, 6-19
via Bur g met hod 6-239
via covar iance met hod 6-243
via modified covar iance met hod 6-247
via Yule-Walker AR met hod 6-278
models, syst em r epr esent at ion 1-32
modified covar iance met hod 3-6, 3-22
defined 3-22
example 3-23
modified per iodogr am 3-9
modulate 4-29, 6-9
example 4-30
met hod flags 4-29
modulat ion 6-236
amplit ude
defined 4-29
example 4-30
fr equency
met hods 4-29, 6-236
phase 4-30
pulse t ime 4-30
pulse widt h 4-30
quadr at ur e amplit ude 4-30
mouse zoom 5-32
in Filt er Designer 5-20
in Filt er Viewer 5-20, 5-88
in Signal Br owser 5-20
in Spect r um Viewer 5-20
t ur ning off 5-33
Mouse Zoom but t on 5-32
moving aver age (MA) filt er 1-15
S ee also FIR filt er
MTM. S ee mult it aper met hod
mult iband filt er
FIR 2-21
FIR, wit h t r ansit ion bands 2-22
IIR 2-13
mult ichannel dat a 1-4, 1-7
mult ichannel signal 3-4
mult iple signal classificat ion met hod (MUSIC) 3-5,
3-6, 3-23
defined 3-23
in Spect r um Viewer 5-106
mult iplicit y, of zer os and poles 5-71
mult ir at e filt er bank, implement at ion 1-19
mult ir at e filt er ing 1-19
mult it aper met hod (MTM) 3-5, 3-6, 3-16
compar ed t o Welchs met hod 3-19
defined 3-16
example 3-17
in Spect r um Viewer 5-105
MUSIC. S ee mult iple signal classificat ion met hod
N
New Design but t on 5-17, 5-59
nonint eger delay 2-26
nonr ecur sive filt er . S ee FIR filt er
nor malizat ion 3-3
cor r elat ion 3-4, 6-367, 6-368
power spect r al densit y 3-12
Nyquist fr equency xvii, 2-2
O
object s, edit ing in SPTool 5-15
one-t ime mouse zooming 5-32
Open Session menu it em 5-6
Index
I-19
or der est imat ion 2-7, 6-294
But t er wor t h 6-48
Chebyshev t ype I 6-55
Chebyshev t ype II 6-60
ellipt ic 6-132
in Filt er Designer 5-75, 5-78
or der select ion 2-7
in Filt er Designer 5-75, 5-78
or der , of filt er 1-15, 2-7
or t hogonal windows, in PSD est imat es 3-16
oscillat or , volt age cont r olled 6-365
over lap-add met hod, FIR filt er implement at ion
1-22, 6-142
P
Page Set up dialog box 5-45, 5-99
panner 5-52
in Signal Br owser 5-20, 5-23, 5-48
Panner check box, in Pr efer ences dialog box 5-23
par amet er s
in Spect r um Viewer 5-99, 5-100, 5-103
inher it ing in Spect r um Viewer 5-100
par amet r ic modeling 4-10, 6-207
applicat ions 4-10
fr equency domain based 4-16
summar y 2-5
t echniques 4-10
t ime domain based
linear pr edict ive coding 4-12, 4-13
St eiglit z-McBr ide met hod 4-15
t ime-domain based 4-11
Bur g met hod 6-16
covar iance met hod 6-17
modified covar iance met hod 6-18
Yule-Walker met hod 6-19
par ent heses, indicat ing open int er val xvii
Par ks-McClellan met hod, FIR filt er design 2-22,
6-287
par t ial fr act ion 1-42
par t ial fr act ion expansion 1-40
defined 1-35
det er mining wit h residue 1-41
example 1-35
par t ial fr act ion for m 1-35, 6-302
passband
equir ipple 2-9, 2-10
gr oup delay 2-11
passband r ipple, set t ing in Filt er Designer 5-70
passband zoom 5-33
Passband Zoom but t on 5-33
pburg 3-6, 3-21, 6-7, 6-239
example 3-21
pcov 3-6, 3-22, 6-7, 6-243
example 3-23
Peaks but t on, Signal Br owser 5-37
per iodic sinc funct ion 6-118
S ee also Dir ichlet funct ion
per iodogr am 3-7
modified 3-9
per sist ent mouse zooming 5-32
phase
comput ing wit h angle 6-15
of Four ier t r ansfor m of sequence 1-44
of fr equency r esponse 1-26
viewing in Filt er Viewer 5-91
of t r ansfer funct ion est imat e 3-15
unwr apping 1-27, 6-360
Phase check box, Filt er Viewer 5-86
phase delay 1-28, 6-182
defined 1-28
example 1-29
of linear r esponse filt er 2-17
phase demodulat ion 6-115
Index
I-20
phase dist or t ion
eliminat ing
dur ing filt er ing 1-19
example 1-20
using filtfilt 1-20
in FIR filt er s 1-20
nonlinear
in IIR filt er s 1-20
phase modificat ion
dat a dependent , using >cceps 4-25
phase modulat ion 4-30, 6-237
phase r esponse 5-17
phase r esponse plot 5-86, 5-91
Phase Unit s pop-up menu, in Pr efer ences dialog
box 5-25
phase unit s, in Filt er Viewer 5-25
Play menu it em, Signal Br owser 5-46
playing a signal 5-46
plot
analog pr ot ot ypes 2-12
coher ence funct ion 3-16
complex cepst r um 4-24
DFT 1-44
fr equency r esponse 1-25
magnit ude 1-26
phase 1-26
gr oup delay 1-29, 5-86, 5-93
impulse r esponse 5-86, 5-94
in Filt er Viewer 5-84, 5-86, 5-88, 5-89
magnit ude r esponse 5-78, 5-86, 5-89
modified per iodogr am 3-10
mult it aper est imat e 3-17, 3-18
per iodogr am 3-7
phase delay 1-29
phase r esponse 5-86, 5-91
power spect r al densit y 3-11
spect r al densit y 5-101
st ep r esponse 5-86, 5-95
st r ip plot 6-344
t iling in Filt er Viewer 5-88
t r ansfer funct ion 3-15
zer o-pole 1-30, 5-86, 5-94, 6-385
plug-ins 5-20, 5-30
pm 4-30
pmcov 3-6, 3-22, 6-7, 6-247
example 3-23
p-model. S ee par amet r ic modeling
pmtm 3-6, 6-7, 6-251
example 3-17
pmusic 3-6, 3-23, 6-7, 6-255
pole-zer o filt er . S ee IIR filt er
poly 1-33, 1-42
poly2ac 6-4, 6-262
poly2rc 6-4, 6-263
polynomial
division 4-33, 6-113
mult iplicat ion 6-83
r oot s 1-33
st abilizat ion 6-265
polyphase filt er ing t echniques 1-19
polystab 6-9, 6-265
power spect r al densit y 6-273
bias 3-12
comput at ion par amet er s 5-103, 5-104
confidence int er val 3-14
default plot 5-102
defined 3-5
est imat ion by Bur g met hod 3-6, 3-20, 5-104,
6-239
est imat ion by covar iance met hod 3-6, 3-22,
5-105, 6-243
est imat ion by FFT met hod 5-105
est imat ion by modified covar iance met hod 3-6,
6-247
Index
I-21
est imat ion by mult it aper met hod 3-6, 3-16,
5-105
est imat ion by MUSIC met hod 3-6, 3-23, 5-106
est imat ion by Welchs met hod 3-6, 3-10, 5-106
est imat ion by Yule-Walker AR met hod 3-6,
3-19, 5-107, 6-278
est imat ion met hods 5-103, 5-104
in SPTool 5-13
nor malizat ion 3-12
unit s of 3-11
viewing in Spect r um Viewer 5-97, 5-102,
5-104
pr efer ences
r uler s 5-21
saving in Signal Br owser 5-45
pr efer ences file
in SPTool 5-31
sigprefs.mat 5-31
Pr efer ences menu it em 5-6, 5-20, 5-30
pr ewar ping 6-25
Pr int dialog box 5-45, 5-55, 5-99, 5-108, 5-120,
5-124
Pr int Pr eview window
Handle Gr aphics 5-57, 5-110
Signal Br owser 5-45, 5-55, 5-56
pr efer ences 5-56, 5-120
Spect r um Viewer 5-99, 5-108, 5-124
pr efer ences 5-109
pr int ing
fr om Signal Br owser 5-2, 5-21, 5-22, 5-31, 5-33,
5-38, 5-117
fr om Spect r um Viewer 5-2, 5-21, 5-22, 5-31,
5-33, 5-38, 5-98
pr olat e-spher oidal window 4-4
prony 2-5, 4-11, 4-13, 6-8, 6-266
Pr onys met hod 4-13, 6-266
modeling 4-13
pr ot ot ype
Bessel filt er 2-11, 6-21
But t er wor t h filt er 2-8, 6-42
Chebyshev t ype I filt er 6-54
Chebyshev t ype II filt er 6-59
ellipt ic filt er 6-131
PSD. S ee power spect r al densit y
psd. S ee pwelch 6-268
ptm 4-30
pulse t ime demodulat ion 6-115
pulse t ime modulat ion 4-30, 6-237
pulse t r ain gener at or 6-269
pulse t r ains
gener at ing 1-9
pulstran 1-9
pulse widt h demodulat ion 6-115
pulse widt h modulat ion 4-30, 6-237
pulstran 1-9, 6-2, 6-75, 6-119, 6-121, 6-122, 6-123,
6-124, 6-269, 6-286, 6-346, 6-359
pwelch 3-6, 3-10, 6-7, 6-273
example 3-12
pwm 4-30
pyulear 3-6, 3-20, 6-7, 6-278
example 3-20, 3-21
Q
qam 4-30
quadr at ur e amplit ude demodulat ion 6-115
quadr at ur e amplit ude modulat ion 4-30, 6-237
R
r adar applicat ions 4-27
r adix-2 algor it hm 1-45
r aised cosine filt er design 6-171
randn xiv
Index
I-22
r andom number , gener at ion xiv
r ange not at ion xvii
Range pop-up menu, Filt er Viewer 5-87
rc2poly 6-4, 6-283
rceps 4-23, 4-25, 6-9, 6-285
r eal cepst r um 6-285
defined 4-24
r econst r uct ing signal (minimum-phase) 4-25
r ebuffer ing 6-33
r ect angular window 2-18, 4-2, 6-32
rectpuls 6-2, 6-286
r ecur sive filt er . S ee IIR filt er
r efer ences 1-46, 3-27, 4-40
r eflect ion coefficient s 1-37, 1-39
conver t ing fr om aut ocor r elat ion sequence
6-14
conver t ing fr om filt er coefficient s 6-263,
6-283
conver t ing t o aut ocor r elat ion sequence 6-282
remez 2-16, 2-22, 6-6, 6-287
accessing fr om Filt er Designer 5-73, 5-75
compar ed t o firls 2-23
filt er char act er ist ics 6-292
for differ ent iat or design 2-26
for Hilber t t r ansfor mer design 2-25
or der est imat ion 6-294
weight vect or 2-24
Remez exchange algor it hm 2-22, 6-287
remezord 2-16, 6-6, 6-294
accessing fr om Filt er Designer 5-75
resample 6-10, 6-298
r esampling 4-20, 6-298
in FIR filt er ing 1-19
S ee also decimat ion, int er polat ion
residue 1-41, 1-42
r esidue for m. S ee par t ial fr act ion for m
residuez 1-42, 6-4, 6-302
Rever t panel 5-31
r ipple, passband 5-70
rlevinson 6-9, 6-305
r oot s
of Bessel filt er 6-21
polynomial 1-33
roots 1-33, 1-42
r uler color 5-21
Ruler Color edit box, in Pr efer ences dialog box
5-21
Ruler Mar ker pop-up menu, in Pr efer ences dialog
box 5-21
r uler mar ker s 5-21, 5-36
r uler t ype
in Signal Br owser 5-21
in Spect r um Viewer 5-21
r uler s
br inging t o cent er 5-35
cust omizing in SPTool 5-20
dr agging 5-36
find r uler but t ons 5-35
hor izont al 5-36
hor izont al mode 5-40
in Filt er Viewer 5-26, 5-33
in Signal Br owser 5-20, 5-21, 5-23, 5-33
in Spect r um Viewer 5-20, 5-21, 5-24, 5-33
par amet er s 5-36
posit ioning 5-38
pr efer ences 5-21
saving measur ement s 5-37
slope 5-36
slope mode 5-42
t r ack 5-36
t r ack mode 5-41
ver t ical 5-36
ver t ical mode 5-39
Index
I-23
Ruler s check box, in Pr efer ences dialog box 5-23,
5-24, 5-26
S
sampling fr equency
changing in SPTool 5-9
in SPTool 5-16
Sampling Fr equency edit box, in Impor t dialog box
5-4, 5-9
Sampling Fr equency menu it em 5-16
sampling r at e
changing by nonint eger fact or 4-20, 6-298
changing for ir r egular ly spaced dat a 4-22
changing wit h upfirdn 1-19
decr easing by int eger fact or 6-110
incr easing by int eger fact or 6-199
Save Ruler s but t on 5-37
Save Session menu it em 5-6
saving changes in SPTool 5-30
saving dat a
fr om Filt er Designer 5-79, 5-110
fr om Signal Br owser 5-57
saving dat a, fr om Filt er Designer 5-79, 5-110
saving dat a, fr om Signal Br owser 5-57
saving set t ings, in Filt er Viewer 5-86
Savit zky-Golay
filt er design 6-309
filt er ing 6-311
sawtooth 1-8, 6-2, 6-308
sawt oot h wave 1-8
scalar
for st at e-space for m 1-34
r epr esent ing gain 1-33
Scale pop-up menu, Filt er Viewer 5-87
Sear ch for Plug-Ins at st ar t -up check box, in
Pr efer ences dialog box 5-30
second-or der sect ion for m
conver t ing fr om t r ansfer funct ion 6-347
conver t ing fr om zer o-pole-gain 6-379
second-or der sect ions 1-42
second-or der sect ions for m 1-36
conver t ing fr om st at e-space for m 6-333
conver t ing t o st at e-space 6-316
conver t ing t o t r ansfer funct ion 6-318
conver t ing t o zer o-pole-gain 6-320
defined 1-36
filt er ing 6-322
specifying in SPTool 5-12
select ing dat a object s in SPTool 5-15
sequence
aut ocor r elat ion 6-13, 6-14, 6-262
set t ings
r est or ing in SPTool 5-30
r uler s 5-21
saving in Signal Br owser 5-45
saving in SPTool 5-31
sgolay 6-309, 6-311
sgolayfilt 6-311
signal
adding noise 1-6
analyt ic 4-38, 6-187
buffer ing 6-33
car r ier 4-29, 6-114
complex 5-47
cont inuous (analog) 1-2
differ ent iat ion 2-26
discr et e (digit al) 1-2
gener at ing 1-7
impor t ing int o SPTool 5-3, 5-7, 5-8, 5-10
linking t o spect r um 5-100
measur ement s 5-37
measur ement s in Signal Br owser 5-36
message 4-29, 6-236
Index
I-24
mult ichannel 3-4
naming in SPTool 5-16
peaks 5-37
playing 5-46
plot t ing 1-6
r ebuffer ing 6-33
r econst r uct ion
fr om DCT coefficient s 4-37
minimum phase 4-25, 6-285
r epr esent ing
in MATLAB 1-4
mult ichannel 1-4
single channel 1-4
select ing in Signal Br owser 5-48
valleys 5-37
viewing in Signal Br owser 5-17, 5-48
S ee also wavefor m
Signal Br owser 5-2, 5-17, 5-43, 6-328
act ivat ing 5-17, 5-43
cust omizing 5-20
pr int ing fr om 5-23, 5-43, 5-44, 5-54
saving dat a t o wor kspace 5-57
window 5-44
Signal Pr ocessing Toolbox 1-2
signal t ype
ar r ay 5-14
vect or 5-14
sigprefs.mat 5-31
sinc 1-10, 6-2, 6-313
bandlimit ed int er polat ion example 6-314
sinc funct ion 1-10, 6-313
and bandlimit ed int er polat ion 6-314
basic example 1-10
defined 1-10
sinusoidal wave 1-8
Slepian sequences. S ee discr et e pr olat e
spher oidal sequences
Slope but t on, for r uler s 5-36
Slope cont r ol 5-38, 5-41
sonar applicat ions 4-27
sos2ss 1-42, 6-4, 6-316
sos2tf 1-42, 6-4, 6-318
sos2zp 1-42, 6-4, 6-320
specgram 4-27, 6-10, 6-323
example 4-27, 6-365
specificat ion lines 5-78
dr agging t o edit filt er 5-70
specificat ions for filt er design 2-7
spect r al analysis 3-5
cr oss spect r al densit y 3-14
defined 3-5
power spect r al densit y 3-5
using Spect r um Viewer 5-97
spect r al densit y 3-5
S ee also power spect r al densit y, cr oss spect r al
densit y
spect r al densit y plot
in Spect r um Viewer 5-101
spect r ogr am 4-27, 6-323
example 4-27, 6-365
spect r um
comput ing in SPTool 5-19
impor t ing int o SPTool 5-7, 5-8, 5-13
linking t o signal 5-100
measur ement s 5-37
measur ement s in Spect r um Viewer 5-36, 5-101
naming in SPTool 5-16
peaks 5-37
updat ing in SPTool 5-19
valleys 5-37
viewing in Spect r um Viewer 5-97
viewing in SPTool 5-19
spect r um t ype, aut o 5-15
Spect r um Viewer 5-2, 5-19, 5-97, 6-331
Index
I-25
act ivat ing 5-19, 5-97
changing plot pr oper t ies 5-102
cust omizing 5-20
default plot 5-102
pr int ing fr om 5-24, 5-97, 5-98, 5-107, 5-108
set t ing confidence int er vals 5-107
viewing power spect r al densit y plot s 5-102
window 5-98
speech pr ocessing 4-10, 4-21
spline 4-22
spt ext ension 5-6
SPTool 5-2, 6-328
act ivat ing fr om Signal Br owser 5-54
closing 5-6
cust omizing 5-6, 5-20
loading 5-3
pr efer ences 5-6
window 5-5
sptool command 6-11, 6-328
square 1-8, 6-2, 6-332
squar e wave 1-8
ss2sos 1-42, 6-4, 6-333
ss2tf 1-42, 6-337
ss2zp 1-42, 6-4, 6-338
st abilizat ion, polynomial 6-265
st andar ds
Compact Disc 4-20
Digit al Audio Tape 4-20
st ar t up t r ansient s 1-22
r educing 1-21, 6-149
st at e-space for m 1-40, 1-42
conver t ing fr om second-or der sect ions 6-316
conver t ing fr om t r ansfer funct ion 6-350
conver t ing fr om zer o-pole-gain 6-383
conver t ing t o second-or der sect ion 6-333
conver t ing t o zer o-pole-gain 6-338
defined 1-34
r epr esent ing in MATLAB 1-34
specifying in SPTool 5-11
st at ist ical oper at ions 3-2
St ay in Zoom-mode Aft er Zoom check box, in
Pr efer ences dialog box 5-23, 5-24, 5-26,
5-27
St eiglit z-McBr ide met hod 4-15, 6-341
st ep r esponse 5-17
viewing in Filt er Viewer 5-95
St ep Response check box, Filt er Viewer 5-86
st ep r esponse plot 5-86, 5-95
stmcb 2-5, 4-11, 4-15, 6-9, 6-341
st opband
at t enuat ion, set t ing in Filt er Designer 5-70
equir ipple 2-10
st r ip plot 6-344
defined 6-344
strips 6-2, 6-344
st r uct ur e, digit al filt er
lat t ice 1-37
t r ansposed dir ect for m II 1-17
subplot s 5-84
in Filt er Viewer 5-86
subspace t hr esholds, cont r olling in pmusic
funct ion 3-25
svd, in pmusic funct ion 3-25
swept -fr equency cosine gener at or . S ee chir p
syst em ident ificat ion 4-13
syst em models 1-32
and bilinear t r ansfor mat ion 2-44
and filt er design funct ions 2-7
and fr equency t r ansfor mat ion funct ions 2-39
T
t aper s, in PSD est imat es 3-16
t aps 2-17
Index
I-26
t ext s, r elat ed 1-46
tf2latc 1-39, 1-42, 6-4, 6-346
tf2ss 1-42, 6-4, 6-350
tf2zp 1-42, 6-339, 6-352
tfe 3-6, 3-14, 6-7, 6-354
thresh 3-25
t iling 5-88
t iling display, in Filt er Viewer 5-26
t iling pr efer ences, in Filt er Viewer 5-20
Time Response Lengt h edit box, in Pr efer ences
dialog box 5-25
t ime r esponse lengt h, in Filt er Viewer 5-25
t ime vect or 1-6
r et ur ned by modulate 4-30
t ime-dependent Four ier t r ansfor m 4-27
t ime-domain analysis, in Filt er Viewer 5-84
t ime-domain based modeling. S ee par amet r ic
modeling
t oolbox
Cont r ol Syst ems Toolbox 1-35, 6-198, 6-340
Image Pr ocessing Toolbox 6-109, 6-190, 6-235
Signal Pr ocessing Toolbox 1-2
Symbolic Mat h Toolbox 6-21
Syst em Ident ificat ion Toolbox 6-357
Tr ack but t on, for r uler s 5-36, 5-38, 5-40
t r ansfer funct ion 1-32, 1-35, 1-40, 1-42
coefficient s 1-15, 5-79
defined 1-15
der ivat ion 1-15
est imat e fr om input and out put 6-354
est imat ing using Welchs met hod 3-14
expor t ing fr om SPTool 5-79
fact or ed for m 1-33
for analog filt er 1-41
r epr esent ing in MATLAB 1-32
zer o-pole-gain for m 1-33
t r ansfer funct ion for m
conver t ing fr om second-or der sect ions 6-318
conver t ing t o lat t ice 6-346
conver t ing t o second-or der sect ions 6-347
conver t ing t o st at e-space 6-350
specifying in SPTool 5-11
t r ansfor m 4-34
chir p z-t r ansfor m (CZT) 4-34, 6-105
discr et e cosine 6-108
discr et e Four ier 1-43
Hilber t 4-38, 6-187
inver se discr et e cosine 4-36, 6-190
inver se discr et e Four ier 6-192
t r ansfor mat ions
bet ween syst em models 1-41
bilinear 2-43, 6-25
fr equency 2-38, 6-220, 6-223, 6-225, 6-227
t r ansit ion band 2-23
t r ansposed dir ect for m II 6-145
init ial condit ions 6-150
triang 4-2, 6-8, 6-358
compar ed t o bartlett 6-20
example 4-2
t r iangular window 6-358
tripuls 6-2, 6-359
t wo-dimensional oper at ions
aut ocor r elat ion 6-372
convolut ion 6-84
obt aining subsect ion 6-84
cr oss-cor r elat ion 6-372
discr et e Four ier t r ansfor m 1-45, 6-141
filt er ing 6-148
inver se discr et e Four ier t r ansfor m 1-45, 6-193
t wo-dimensional signal pr ocessing, wit h fft2 and
ifft2 1-45
Index
I-27
U
unit cir cle 6-265
unit impulse funct ion 1-7
unit r amp funct ion 1-7
unit sample, mult ichannel r epr esent at ion 1-7
unit st ep funct ion 1-7
unit s of power spect r al densit y (PSD) funct ion
3-11
unwrap 1-27, 6-3, 6-360
Updat e but t on 5-19, 5-97
upfirdn 1-19, 4-22, 6-10, 6-361
V
Valleys but t on, Signal Br owser 5-37
var iance
of cor r elat ion sequence est imat e 3-4
of power spect r um est imat e 3-8
vco 4-29, 4-31, 6-10, 6-365
vect or
dat a 1-4
display, in Signal Br owser 5-50
for filt er coefficient s 1-16, 1-32
fr equency 2-24, 6-157, 6-160, 6-287, 6-376
in SPTool 5-14
indexing xvii, 1-15
magnit ude 2-24, 6-157, 6-160, 6-376
t ime 1-6
weight ing 2-24, 6-167, 6-288
Ver t ical but t on, for r uler s 5-36, 5-38
View but t on 5-17, 5-19
volt age cont r olled oscillat or 4-31, 6-365
W
wavefor m
aper iodic 1-8
chir p 1-9
chir p, example 1-9
fr om sinusoids 1-6
gener at ing wit h diric funct ion 1-11
gener at ing wit h pulstran 1-9
gener at ing wit h sinc funct ion 1-10
linear swept -fr equency cosine. S ee chir p
per iodic 1-7
sawt oot h 1-8, 6-308
example 1-8
sinusoidal pulse, Gaussian-modulat ed 1-8
squar e 1-8, 6-332
t r iangle 6-308
Welchs met hod 3-6
bias 3-12
compar ed t o t he Bur g met hod 3-22
compar ed t o t he MTM met hod 3-19
compar ed t o t he Yule-Walker AR met hod 3-20
for cr oss spect r al densit y est imat ion 3-14,
6-102
for nonpar amet r ic syst em ident ificat ion 3-14
for power spect r al densit y est imat ion 3-5, 3-10,
6-81, 6-275
in Spect r um Viewer 5-106
nor malizat ion 3-12
whit e noise 1-6
window
applied t o per iodogr am 3-9
Bar t let t 4-2, 6-20
Blackman 4-4, 6-30
boxcar 2-18
Chebyshev 4-9, 6-64
for filt er design 2-18
gener alized cosine 4-4
Hamming 2-20, 4-4, 6-185
Hanning 4-4, 6-186
Kaiser 4-4, 6-210
Index
I-28
r ect angular 2-18, 6-32
shapes, over view 4-2
specifying for fir1 2-21
t r iangular 6-358
window met hod
FIR filt er design 2-18
mult iband design 2-21
single band design 2-20
window met hod, FIR filt er design
bandpass configur at ion 6-152
bandst op configur at ion 6-152
highpass configur at ion 6-152
lowpass configur at ion 6-152
Wor kspace Cont ent s list , in Impor t dialog box
5-7
wor kspace, loading var iables fr om 5-7
X
X Label edit box, in Pr efer ences dialog box 5-23
xcorr 3-2, 6-7, 6-367
and par amet r ic modeling 4-12
xcorr2 6-7, 6-372
xcov 3-2, 6-7, 6-373
Y
Y Label edit box, in Pr efer ences dialog box 5-23
yulewalk 2-5, 2-13, 6-5, 6-376
example 2-14
Yule-Walker AR met hod 3-5, 3-6, 3-19
compar ed t o Welchs met hod 3-20
defined 3-19
example 3-20, 3-21
Yule-Walker AR met hod, in Spect r um Viewer
5-107
Yule-Walker equat ions 2-13
Yule-Walker filt er design 6-376
Z
zer o fr equency component , cent er ing wit h fftshift
1-45
zer o-or der hold. S ee aver aging filt er
zer o-phase filt er ing 6-149
zer o-pole analysis
example 1-30
zer o-pole plot s 6-385
zer o-pole gain 1-42
zer o-pole plot 5-86, 5-94
viewing in Filt er Viewer 5-94
zer o-pole-gain for m 1-40
conver t ing fr om second-or der sect ions 6-320
conver t ing fr om st at e-space for m 6-338
conver t ing t o second-or der sect ion 6-379
conver t ing t o st at e-space 6-383
defined 1-33
r epr esent ing in MATLAB 1-33
specifying in SPTool 5-11
zer os and poles 5-17
in t r ansfer funct ion 1-33
mult iplicit y of 5-71
Zer os and Poles check box, Filt er Viewer 5-86
zoom cont r ols
in Filt er Designer 5-31
in Filt er Viewer 5-31
in Signal Br owser 5-31
in Spect r um Viewer 5-31
in SPTool 5-31
Zoom In-X but t on 5-32
Zoom In-Y but t on 5-32
Zoom Out -X but t on 5-32
Zoom Out -Y but t on 5-32
zoom per sist ence 5-32
Index
I-29
changing 5-32
in Filt er Designer 5-27
in Filt er Viewer 5-26, 5-87
in Signal Br owser 5-23, 5-46
in Spect r um Viewer 5-24
zooming
in Filt er Designer 5-77
in Filt er Viewer 5-87
in Signal Br owser 5-46
in Spect r um Viewer 5-103
one-t ime 5-32
per sist ent 5-32
zp2sos 1-42, 6-4, 6-379
zp2ss 1-42, 6-4, 6-383
zp2tf 1-42, 6-384
zplane 1-30, 6-3, 6-385
z-t r ansfor m 1-15, 1-32
chir p z-t r ansfor m (CZT) 4-34, 6-105
discr et e Four ier t r ansfor m 1-43
Index
I-30

Vous aimerez peut-être aussi