You are on page 1of 872

Computation

Visualization
Programming
For Use with MATLAB

Users Guide
Version 5
Signal Processing
Toolbox
How to Contact The MathWorks:
508-647-7000 Phone
508-647-7001 Fax
TheMathWorks, I nc. Mail
3 AppleHill Drive
Natick, MA 01760-2098
ht t p: / / www. mat hwor ks. com Web
f t p. mat hwor ks. com Anonymous FTP server
comp. sof t - sys. mat l ab Newsgroup
suppor t @mat hwor ks. com Technical support
suggest @mat hwor ks. com Product enhancement suggestions
bugs@mat hwor ks. com Bugreports
doc@mat hwor ks. com Documentation error reports
subscr i be@mat hwor ks. com Subscribinguser registration
ser vi ce@mat hwor ks. com Order status, licenserenewals, passcodes
i nf o@mat hwor ks. com Sales, pricing, and general information
Signal ProcessingToolbox Users Guide
COPYRI GHT 1988 - 2000 by TheMathWorks, I nc.
Thesoftwaredescribed in this document is furnishedunder a licenseagreement. Thesoftwaremay beused
or copiedonly under theterms of thelicenseagreement. Nopart of this manual may bephotocopiedor repro-
duced in any formwithout prior written consent fromTheMathWorks, I nc.
FEDERAL ACQUI SI TI ON: This provision applies toall acquisitions of theProgramandDocumentation by
or for thefederal government of theUnited States. By acceptingdelivery of theProgram, thegovernment
hereby agrees that this softwarequalifies as "commercial" computer softwarewithin themeaningof FAR
Part 12.212, DFARS Part 227.7202-1, DFARS Part 227.7202-3, DFARS Part 252.227-7013, andDFARS Part
252.227-7014. Theterms and conditions of TheMathWorks, I nc. SoftwareLicenseAgreement shall pertain
tothegovernments useand disclosureof theProgramand Documentation, and shall supersedeany
conflictingcontractual terms or conditions. I f this licensefails tomeet thegovernments minimumneeds or
is inconsistent in any respect with federal procurement law, thegovernment agrees toreturn theProgram
and Documentation, unused, toMathWorks.
MATLAB, Simulink, Stateflow, HandleGraphics, and Real-TimeWorkshop areregisteredtrademarks, and
Target LanguageCompiler is a trademark of TheMathWorks, I nc.
Other product or brand names aretrademarks or registered trademarks of their respectiveholders.
Printing History: J anuary 1997 First printing New for MATLAB 5.1
J anuary 1998 Second printingRevised for MATLAB 5.2
J anuary 1999 (OnlineOnly) Revised for Version 4.2 (Release11)
August 1999 (OnlineOnly) Revised for Version 4.3 (Release11)
September 2000 Third printing Revised for Version 5.0 (Release12)
i
Contents
Preface
Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
What Is theSignal ProcessingToolbox? . . . . . . . . . . . . . . . . . . 23
R12Related Products List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
HowtoUseThis Manual . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
I f You Area NewUser . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
I f You Arean Experienced Toolbox User . . . . . . . . . . . . . . . . . . . 27
All Toolbox Users . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
InstallingtheSignal ProcessingToolbox . . . . . . . . . . . . . . . . . 28
Technical Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Typographical Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
1
Signal ProcessingBasics
Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2
Signal ProcessingToolbox Central Features . . . . . . . . . . . . 1-3
Filteringand FFTs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-3
Signals and Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-3
Key Areas: Filter Design and Spectral Analysis . . . . . . . . . . . . 1-3
I nteractiveTools: SPTool and FDATool . . . . . . . . . . . . . . . . . . . 1-4
Extensibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-4
ii Contents
RepresentingSignals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-5
Vector Representation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-5
WaveformGeneration: TimeVectors and Sinusoids . . . . . . 1-7
Common Sequences: Unit I mpulse, Unit Step, and Unit Ramp 1-8
Multichannel Signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-8
Common Periodic Waveforms . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-9
Common Aperiodic Waveforms . . . . . . . . . . . . . . . . . . . . . . . . . 1-10
Thepulstran Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-11
TheSinc Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-12
TheDirichlet Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-13
Workingwith Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-14
Filter Implementation and Analysis . . . . . . . . . . . . . . . . . . . 1-15
Convolution and Filtering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-15
Filters and Transfer Functions . . . . . . . . . . . . . . . . . . . . . . . . . 1-16
Filter Coefficients and Filter Names . . . . . . . . . . . . . . . . . . 1-16
Filteringwith thefilter Function . . . . . . . . . . . . . . . . . . . . . . . 1-17
Thefilter Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-18
Other Functions for Filtering . . . . . . . . . . . . . . . . . . . . . . . . . 1-20
MultirateFilter Bank I mplementation . . . . . . . . . . . . . . . . . . 1-20
Anti-Causal, Zero-PhaseFilter I mplementation . . . . . . . . . . . 1-21
Frequency Domain Filter I mplementation . . . . . . . . . . . . . . . . 1-23
ImpulseResponse . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-24
Frequency Response . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-25
Digital Domain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-25
AnalogDomain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-27
Magnitudeand Phase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-27
Delay . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-29
Zero-PoleAnalysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-31
Linear SystemModels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-33
Discrete-TimeSystemModels . . . . . . . . . . . . . . . . . . . . . . . . . . 1-33
iii
Transfer Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-33
Zero-Pole-Gain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-34
State-Space . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-35
Partial Fraction Expansion (ResidueForm) . . . . . . . . . . . . 1-36
Second-Order Sections (SOS) . . . . . . . . . . . . . . . . . . . . . . . . 1-38
LatticeStructure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-38
Convolution Matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-41
Continuous-TimeSystemModels . . . . . . . . . . . . . . . . . . . . . . . 1-42
Linear SystemTransformations . . . . . . . . . . . . . . . . . . . . . . . . 1-43
DiscreteFourier Transform . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-45
Selected Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-48
2
Filter Design
Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-2
Filter Requirements and Specification . . . . . . . . . . . . . . . . . . 2-3
IIR Filter Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-5
Classical I I R Filter Design UsingAnalogPrototyping . . . . . . . 2-7
CompleteClassical I I R Filter Design . . . . . . . . . . . . . . . . . . . 2-7
DesigningI I R Filters toFrequency Domain Specifications . 2-8
Comparison of Classical I I R Filter Types . . . . . . . . . . . . . . . . . . 2-9
Butterworth Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-9
Chebyshev TypeI Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-10
Chebyshev TypeI I Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-11
Elliptic Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-11
Bessel Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-12
Direct I I R Filter Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-14
Generalized Butterworth Filter Design . . . . . . . . . . . . . . . . 2-15
FIR Filter Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-17
Linear PhaseFilters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-18
WindowingMethod . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-19
iv Contents
Standard Band FI R Filter Design: fir1 . . . . . . . . . . . . . . . . 2-21
Multiband FI R Filter Design: fir2 . . . . . . . . . . . . . . . . . . . . 2-22
Multiband FI R Filter Design with Transition Bands . . . . . . . 2-23
Basic Configurations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-23
TheWeight Vector . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-26
Anti-Symmetric Filters / Hilbert Transformers . . . . . . . . . . 2-26
Differentiators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-27
Constrained Least Squares FI R Filter Design . . . . . . . . . . . . . 2-28
Basic Lowpass and Highpass CLS Filter Design . . . . . . . . . 2-29
Multiband CLS Filter Design . . . . . . . . . . . . . . . . . . . . . . . . 2-30
Weighted CLS Filter Design . . . . . . . . . . . . . . . . . . . . . . . . . 2-31
Arbitrary-ResponseFilter Design . . . . . . . . . . . . . . . . . . . . . . . 2-32
Multiband Filter Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-33
Filter Design with Reduced Delay . . . . . . . . . . . . . . . . . . . . 2-35
Special Topics in IIR Filter Design . . . . . . . . . . . . . . . . . . . . 2-38
AnalogPrototypeDesign . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-39
Frequency Transformation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-39
Filter Discretization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-42
I mpulseI nvariance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-42
Bilinear Transformation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-43
Selected Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-46
3
Statistical Signal Processing
Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-2
Correlation and Covariance . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-3
Bias and Normalization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-4
MultipleChannels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-5
Spectral Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-6
Spectral Estimation Method Overview . . . . . . . . . . . . . . . . . . . . 3-8
Nonparametric Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-10
ThePeriodogram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-10
v
Performanceof thePeriodogram3-12
TheModified Periodogram . . . . . . . . . . . . . . . . . . . . . . . . . . 3-18
Welchs Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-20
Bias and Normalization in Welchs Method . . . . . . . . . . . . . 3-23
Multitaper Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-24
Cross-Spectral Density Function . . . . . . . . . . . . . . . . . . . . . 3-27
ConfidenceI ntervals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-27
Transfer Function Estimate . . . . . . . . . . . . . . . . . . . . . . . . . 3-28
CoherenceFunction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-29
Parametric Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-30
Yule-Walker AR Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-32
BurgMethod . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-33
Covarianceand Modified CovarianceMethods . . . . . . . . . . 3-36
MUSI C and Eigenvector Analysis Methods . . . . . . . . . . . . . 3-36
Eigenanalysis Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-37
Selected Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-39
4
Special Topics
Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-2
Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-3
Basic Shapes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-3
Generalized CosineWindows . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-5
Kaiser Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-5
Kaiser Windows in FI R Design . . . . . . . . . . . . . . . . . . . . . . . . 4-7
Chebyshev Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-9
Parametric Modeling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-11
Time-Domain Based Modeling . . . . . . . . . . . . . . . . . . . . . . . . . 4-13
Linear Prediction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-13
Pronys Method (ARMA Modeling) . . . . . . . . . . . . . . . . . . . . 4-14
Steiglitz-McBrideMethod (ARMA Modeling) . . . . . . . . . . . 4-16
Frequency-Domain Based Modeling . . . . . . . . . . . . . . . . . . . . . 4-18
vi Contents
Resampling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-21
CepstrumAnalysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-24
I nverseComplex Cepstrum . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-26
FFT-Based Time-Frequency Analysis . . . . . . . . . . . . . . . . . . 4-28
Median Filtering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-29
Communications Applications . . . . . . . . . . . . . . . . . . . . . . . . . 4-30
Deconvolution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-34
Specialized Transforms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-35
Chirp z-Transform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-35
DiscreteCosineTransform . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-37
Hilbert Transform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-39
Selected Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-41
5
Filter Design and Analysis Tool
Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-2
Filter Design Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-2
UsingtheFilter Design and Analysis Tool . . . . . . . . . . . . . . . . . 5-3
AnalyzingFilter Responses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-3
Filter Design and Analysis Tool Modes . . . . . . . . . . . . . . . . . . . 5-3
GettingHelp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-4
OpeningtheFilter Design and Analysis Tool . . . . . . . . . . . . 5-5
GettingHelp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-6
Context-SensitiveHelp: TheWhats This? Button . . . . . . . . . . 5-6
Choosinga Filter Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-7
vii
Choosinga Filter Design Method . . . . . . . . . . . . . . . . . . . . . . . 5-8
SettingtheFilter Design Specifications . . . . . . . . . . . . . . . . . 5-9
Bandpass Filter Frequency Specifications . . . . . . . . . . . . . . . . . 5-9
Bandpass Filter MagnitudeSpecifications . . . . . . . . . . . . . . . . 5-10
Filter Order . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-11
ComputingtheFilter Coefficients . . . . . . . . . . . . . . . . . . . . . 5-12
AnalyzingtheFilter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-13
ConvertingtheFilter Structure . . . . . . . . . . . . . . . . . . . . . . . 5-14
Importinga Filter Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-16
Filter Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-17
Direct Form . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-17
Direct FormI I (Second-Order Sections) . . . . . . . . . . . . . . . . 5-17
State-Space . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-18
Lattice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-18
Quantized Filter (Qfilt Object) . . . . . . . . . . . . . . . . . . . . . . . 5-18
Exportinga Filter Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-19
ExportingFilter Coefficients totheWorkspace . . . . . . . . . . . . 5-19
ExportingFilter Coefficients toa Text File . . . . . . . . . . . . . . . 5-20
Savingand OpeningFilter Design Sessions . . . . . . . . . . . . . 5-21
6
SPTool: A Signal ProcessingGUI Suite
Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-2
SPTool: An InteractiveSignal ProcessingEnvironment . . 6-3
SPTool Data Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-4
OpeningSPTool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-5
viii Contents
Overviewof theSignal Browser: Signal Analysis . . . . . . . . . 6-6
OpeningtheSignal Browser . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-6
Overviewof theFilter Designer: Filter Design . . . . . . . . . . . 6-8
Filter Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-8
FI R Filter Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-8
I I R Filter Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-8
Pole/ZeroEditor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-9
Spectral Overlay Feature . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-9
OpeningtheFilter Designer . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-9
Overviewof theFilter Viewer: Filter Analysis . . . . . . . . . . 6-11
OpeningtheFilter Viewer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-11
Overviewof theSpectrumViewer: Spectral Analysis . . . . 6-14
OpeningtheSpectrumViewer . . . . . . . . . . . . . . . . . . . . . . . . . 6-14
GettingHelp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-17
Context-SensitiveHelp: TheWhats This? Button . . . . . . . . . 6-17
UsingSPTool: Filteringand Analysis of Noise . . . . . . . . . . 6-18
Importinga Signal into SPTool . . . . . . . . . . . . . . . . . . . . . . . . 6-19
Designinga Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-22
OpeningtheFilter Designer . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-22
SpecifyingtheBandpass Filter . . . . . . . . . . . . . . . . . . . . . . . . . 6-22
Applyinga Filter to a Signal . . . . . . . . . . . . . . . . . . . . . . . . . . 6-24
AnalyzingSignals: OpeningtheSignal Browser . . . . . . . . . 6-26
Playinga Signal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-27
Printinga Signal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-28
Spectral Analysis in theSpectrumViewer . . . . . . . . . . . . . . 6-29
Creatinga PSD Object Froma Signal . . . . . . . . . . . . . . . . . . . 6-29
OpeningtheSpectrumViewer with TwoSpectra . . . . . . . . . . 6-30
PrintingtheSpectra . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-31
ix
ExportingSignals, Filters, and Spectra . . . . . . . . . . . . . . . . 6-32
OpeningtheExport DialogBox . . . . . . . . . . . . . . . . . . . . . . . . . 6-32
Exportinga Filter totheMATLAB Workspace . . . . . . . . . . 6-33
Designinga Filter with thePole/Zero Editor . . . . . . . . . . . . 6-34
PositioningPoles and Zeros . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-35
Redesigninga Filter UsingtheMagnitudePlot . . . . . . . . . 6-37
AccessingFilter Parameters in a Saved Filter . . . . . . . . . . 6-38
Thetf Field: AccessingFilter Coefficients . . . . . . . . . . . . . . . . 6-38
TheFs Field: AccessingFilter SampleFrequency . . . . . . . . . . 6-38
Thespecs Field: Accessingother Filter Parameters . . . . . . . . 6-39
AccessingParameters in a Saved Spectrum . . . . . . . . . . . . 6-42
ImportingFilters and Spectra into SPTool . . . . . . . . . . . . . 6-43
I mportingFilters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-43
I mportingSpectra . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-45
LoadingVariables fromtheDisk . . . . . . . . . . . . . . . . . . . . . . 6-47
SelectingSignals, Filters, and Spectra in SPTool . . . . . . . . 6-48
EditingSignals, Filters, or Spectra in SPTool . . . . . . . . . . . 6-49
SettingPreferences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-50
MakingSignal Measurements: UsingMarkers . . . . . . . . . . 6-51
7
Function Reference
Function Category List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-3
abs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-16
ac2poly . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-17
x Contents
ac2rc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-18
angle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-19
arburg . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-20
arcov . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-21
armcov . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-22
aryule . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-23
bartlett . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-24
besselap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-26
besself . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-27
bilinear . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-31
blackman . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-36
boxcar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-38
buffer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-39
buttap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-48
butter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-49
buttord . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-54
cceps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-59
cell2sos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-61
cheb1ap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-62
cheb1ord . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-63
cheb2ap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-67
cheb2ord . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-68
chebwin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-73
cheby1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-75
cheby2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-80
chirp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-85
cohere . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-88
conv . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-92
conv2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-93
convmtx . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-95
corrcoef . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-97
corrmtx . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-98
cov . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-101
cplxpair . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-102
cremez . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-103
csd . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-111
czt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-116
dct . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-119
decimate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-121
deconv . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-124
xi
demod . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-125
dftmtx . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-127
diric . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-128
dpss . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-129
dpssclear . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-132
dpssdir . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-133
dpssload . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-134
dpsssave . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-135
ellip . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-136
ellipap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-142
ellipord . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-143
eqtflength . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-148
fdatool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-149
fft . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-151
fft2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-154
fftfilt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-155
fftshift . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-157
filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-158
filter2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-161
filtfilt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-162
filtic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-163
fir1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-165
fir2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-169
fircls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-172
fircls1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-175
firls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-178
firrcos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-183
freqs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-185
freqspace . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-188
freqz . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-189
freqzplot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-193
gauspuls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-196
gmonopuls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-198
grpdelay . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-200
hamming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-203
hann . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-205
hilbert . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-207
icceps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-210
idct . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-211
ifft . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-213
xii Contents
ifft2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-214
impinvar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-215
impz . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-217
interp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-220
intfilt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-223
invfreqs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-226
invfreqz . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-230
is2rc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-233
kaiser . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-234
kaiserord . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-236
lar2rc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-241
latc2tf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-242
latcfilt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-243
levinson . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-245
lp2bp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-247
lp2bs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-250
lp2hp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-252
lp2lp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-254
lpc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-256
lsf2poly . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-260
maxflat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-261
medfilt1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-263
modulate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-264
pburg . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-267
pcov . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-273
peig . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-279
periodogram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-287
pmcov . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-293
pmtm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-299
pmusic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-305
poly2ac . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-314
poly2lsf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-315
poly2rc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-316
polyscale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-318
polystab . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-319
prony . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-320
psdplot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-322
pulstran . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-324
pwelch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-328
pyulear . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-335
xiii
rc2ac . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-341
rc2is . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-342
rc2lar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-343
rc2poly . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-344
rceps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-346
rectpuls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-347
remez . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-348
remezord . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-356
resample . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-359
residuez . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-362
rlevinson . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-365
rooteig . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-368
rootmusic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-371
sawtooth . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-374
schurrc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-375
seqperiod . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-376
sgolay . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-378
sgolayfilt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-380
sinc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-382
sos2cell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-384
sos2ss . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-385
sos2tf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-387
sos2zp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-389
sosfilt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-391
specgram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-392
sptool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-396
square . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-402
ss2sos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-403
ss2tf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-407
ss2zp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-409
stmcb . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-412
strips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-415
tf2latc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-417
tf2sos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-418
tf2ss . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-422
tf2zp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-424
tfe . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-427
triang . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-431
tripuls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-433
udecode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-434
xiv Contents
uencode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-437
unwrap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-440
upfirdn . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-441
vco . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-445
xcorr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-447
xcorr2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-451
xcov . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-452
yulewalk . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-455
zp2sos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-458
zp2ss . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-462
zp2tf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-464
zplane . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-466
8
Filter Design and Analysis Tool Reference
Filter Design and Analysis GUI Overview . . . . . . . . . . . . . . . 8-2
Display Region . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-3
Display Region: Filter Specifications . . . . . . . . . . . . . . . . . . . 8-4
Display Region: MagnitudeResponse . . . . . . . . . . . . . . . . . . . 8-5
Display Region: PhaseResponse . . . . . . . . . . . . . . . . . . . . . . . 8-6
Display Region: Magnitudeand PhaseResponse . . . . . . . . . 8-7
Display Region: Group Delay . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-8
Display Region: ImpulseResponse . . . . . . . . . . . . . . . . . . . . . . 8-9
Display Region: Step Response . . . . . . . . . . . . . . . . . . . . . . . . 8-10
Display Region: Pole/Zero Plot . . . . . . . . . . . . . . . . . . . . . . . . 8-11
xv
Display Region: Filter Coefficients . . . . . . . . . . . . . . . . . . . . 8-12
Filter TypeRegion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-13
Lowpass Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-13
Highpass Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-14
Bandpass Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-14
Bandstop Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-15
Differentiator Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-15
Hilbert Transformer Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-15
Multiband Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-15
Arbitrary MagnitudeFilters . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-16
Arbitrary Group Delay Filters . . . . . . . . . . . . . . . . . . . . . . . . . . 8-16
Design Method Region . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-17
Current Filter Information Region . . . . . . . . . . . . . . . . . . . . 8-18
Convert StructureButton . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-19
Quantization Region . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-20
Frequency Specifications Region . . . . . . . . . . . . . . . . . . . . . . 8-21
Frequency Specifications Region: Lowpass Butterworth 8-23
Frequency Specifications Region:
Lowpass Chebyshev TypeI . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-24
Frequency Specifications Region:
Lowpass Chebyshev TypeII . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-25
Frequency Specifications Region: Lowpass Elliptic . . . . . 8-26
Frequency Specifications Region: Lowpass Equiripple . . 8-27
Frequency Specifications Region: Lowpass Least-Squares 8-28
Frequency Specifications Region: Lowpass Window . . . . . 8-29
xvi Contents
Frequency Specifications Region: Highpass Butterworth 8-30
Frequency Specifications Region:
Highpass Chebyshev TypeI . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-31
Frequency Specifications Region:
Highpass Chebyshev TypeII . . . . . . . . . . . . . . . . . . . . . . . . . . 8-32
Frequency Specifications Region: Highpass Elliptic . . . . . 8-33
Frequency Specifications Region: Highpass Equiripple. . 8-34
Frequency Specifications Region: Highpass Least-Squares 8-35
Frequency Specifications Region: Highpass Window . . . . 8-36
Frequency Specifications Region: Bandpass Butterworth 8-37
Frequency Specifications Region:
Bandpass Chebyshev TypeI . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-38
Frequency Specifications Region:
Bandpass Chebyshev TypeII . . . . . . . . . . . . . . . . . . . . . . . . . . 8-39
Frequency Specifications Region: Bandpass Elliptic . . . . 8-40
Frequency Specifications Region: Bandpass Equiripple . 8-41
Frequency Specifications Region: Bandpass Least-Squares 8-42
Frequency Specifications Region: Bandpass Window . . . . 8-43
Frequency Specifications Region: Bandstop Butterworth 8-44
Frequency Specifications Region:
Bandstop Chebyshev TypeI . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-45
Frequency Specifications Region:
Bandstop Chebyshev TypeII . . . . . . . . . . . . . . . . . . . . . . . . . . 8-46
xvii
Frequency Specifications Region: Bandstop Elliptic . . . . 8-47
Frequency Specifications Region: Bandstop Equiripple . 8-48
Frequency Specifications Region: Bandstop Least-Squares 8-49
Frequency Specifications Region: Bandstop Window . . . . 8-50
MagnitudeSpecifications Region . . . . . . . . . . . . . . . . . . . . . . 8-51
MagnitudeSpecifications Region: Lowpass Butterworth 8-53
MagnitudeSpecifications Region:
Lowpass Chebyshev TypeI . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-54
MagnitudeSpecifications Region:
Lowpass Chebyshev TypeII . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-55
MagnitudeSpecifications Region: Lowpass Elliptic . . . . . 8-56
MagnitudeSpecifications Region: Lowpass Equiripple . . 8-57
MagnitudeSpecifications Region: Lowpass Least-Squares 8-58
MagnitudeSpecifications Region: Lowpass Window . . . . . 8-59
MagnitudeSpecifications Region: Highpass Butterworth 8-60
MagnitudeSpecifications Region:
Highpass Chebyshev TypeI . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-61
MagnitudeSpecifications Region:
Highpass Chebyshev TypeII . . . . . . . . . . . . . . . . . . . . . . . . . . 8-62
MagnitudeSpecifications Region: Highpass Elliptic . . . . . 8-63
MagnitudeSpecifications Region: Highpass Equiripple . 8-64
MagnitudeSpecifications Region: Highpass Least-Squares 8-65
xviii Contents
MagnitudeSpecifications Region: Highpass Window . . . . 8-66
MagnitudeSpecifications Region: Bandpass Butterworth 8-67
MagnitudeSpecifications Region:
Bandpass Chebyshev TypeI . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-68
MagnitudeSpecifications Region:
Bandpass Chebyshev TypeII . . . . . . . . . . . . . . . . . . . . . . . . . . 8-69
MagnitudeSpecifications Region: Bandpass Elliptic . . . . 8-70
MagnitudeSpecifications Region: Bandpass Equiripple . 8-71
MagnitudeSpecifications Region: Bandpass Least-Squares 8-72
MagnitudeSpecifications Region: Bandpass Window . . . . 8-73
MagnitudeSpecifications Region: Bandstop Butterworth 8-74
MagnitudeSpecifications Region:
Bandstop Chebyshev TypeI . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-75
MagnitudeSpecifications Region:
Bandstop Chebyshev TypeII . . . . . . . . . . . . . . . . . . . . . . . . . . 8-76
MagnitudeSpecifications Region: Bandstop Elliptic . . . . 8-77
MagnitudeSpecifications Region: Bandstop Equiripple . 8-78
MagnitudeSpecifications Region: Bandstop Least-Squares 8-79
MagnitudeSpecifications Region: Bandstop Window . . . . 8-80
Frequency and MagnitudeSpecifications Region:
Differentiator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-81
Frequency and MagnitudeSpecifications Region:
Hilbert Transformer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-82
xix
Frequency and MagnitudeSpecifications Region:
Multiband . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-83
Frequency and MagnitudeSpecifications Region:
Arbitrary Magnitude . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-84
Frequency and MagnitudeSpecifications Region:
Arbitrary Group Delay . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-85
Filter Order Region . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-86
WindowSpecification Region . . . . . . . . . . . . . . . . . . . . . . . . . 8-87
Import Filter Tab . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-88
Import Filter Coefficients Region . . . . . . . . . . . . . . . . . . . . . . 8-89
Import Filter Coefficients: Direct Form . . . . . . . . . . . . . . . . 8-90
Import Filter Coefficients:
Direct FormII (Second-Order Sections) . . . . . . . . . . . . . . . . 8-91
Import Filter Coefficients: State-Space . . . . . . . . . . . . . . . . . 8-92
Import Filter Coefficients: Lattice . . . . . . . . . . . . . . . . . . . . . 8-93
Import Filter Coefficients: Quantized Filter (Qfilt Object) 8-94
Design Filter Tab . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-95
Import Filter Button . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-96
Design Filter Button . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-97
xx Contents
Preface
Overview . . . . . . . . . . . . . . . . . . . . . 5-22
What Is theSignal ProcessingToolbox? . . . . . . . 5-23
R12Related Products List . . . . . . . . . . . . . . 5-24
HowtoUseThis Manual . . . . . . . . . . . . . . 5-26
I f You Area NewUser . . . . . . . . . . . . . . . . 5-26
I f You Arean Experienced Toolbox User . . . . . . . . . 5-27
All Toolbox Users . . . . . . . . . . . . . . . . . . 5-27
InstallingtheSignal ProcessingToolbox . . . . . . . 5-28
Technical Conventions . . . . . . . . . . . . . . . 5-29
Typographical Conventions . . . . . . . . . . . . . 5-30
Preface
-22
Overview
This chapter providesanintroductiontotheSignal ProcessingToolboxandthe
documentation. I t contains thefollowingsections:
What I s theSignal ProcessingToolbox?
R12 Related Products List
HowtoUseThis Manual
I nstallingtheSignal ProcessingToolbox
Technical Conventions
Typographical Conventions
What Is the Signal Processing Toolbox?
-23
What Is the Signal Processing Toolbox?
TheSignal ProcessingToolbox is a collection of tools built on theMATLAB

numeric computingenvironment. Thetoolbox supports a widerangeof signal


processingoperations, fromwaveformgeneration tofilter design and
implementation, parametric modeling, and spectral analysis. Thetoolbox
provides twocategories of tools:
Signal processingcommand linefunctions
A suiteof graphical user interfaces for:
- I nteractivefilter design
- Signal plottingand analysis
- Spectral analysis
- Filteringsignals
- Analyzingfilter designs
Preface
-24
R12 Related Products List
TheMathWorks provides several products that areespecially relevant tothe
kinds of tasks you can performwith theSignal ProcessingToolbox.
For moreinformation about any of theseproducts, seeeither:
Theonlinedocumentation for that product if it is installed or if you are
readingthedocumentation fromtheCD
TheMathWorksWebsite, at ht t p: / / www. mat hwor ks. com; seetheproducts
section
Note Thetoolboxes listed belowall includefunctions that extend MATLABs
capabilities. Theblocksets all includeblocks that extend Simulinks
capabilities.
Product Description
Communications
Blockset
Simulink block libraries for modelingthe
physical layer of communications systems
Communications Toolbox MATLAB functions for modelingthephysical
layer of communications systems
DataAcquisition Toolbox MATLAB functions for direct access tolive,
measured data fromMATLAB
DatabaseToolbox Tool for connectingto, and interactingwith,
most ODBC/J DBC databases fromwithin
MATLAB
DSP Blockset Simulink block libraries for thedesign,
simulation, and prototypingof digital signal
processingsystems
Fuzzy Logic Toolbox Tool tohelp master fuzzy logic techniques and
their application topractical control problems
R12 Related Products List
-25
I mageProcessing
Toolbox
Completesuiteof digital imageprocessingand
analysis tools for MATLAB
Neural Network Toolbox Comprehensiveenvironment for neural
network research, design, and simulation
within MATLAB
Optimization Toolbox Tool for general andlarge-scaleoptimization of
nonlinear problems, as well as for linear
programming, quadratic programming,
nonlinear least squares, and solvingnonlinear
equations
Simulink I nteractive, graphical environment for
modeling, simulating, and prototyping
dynamic systems
Statistics Toolbox Tool for analyzinghistorical data, modeling
systems, developingstatistical algorithms, and
learningand teachingstatistics
SystemI dentification
Toolbox
Tool for buildingaccurate, simplifiedmodels of
complex systems fromnoisy time-series data
Wavelet Toolbox Tool for signal and imageanalysis,
compression, and de-noising
Product Description
Preface
-26
How to Use This Manual
Thissectionexplainshowtousethedocumentationtoget helpabout theSignal
ProcessingToolbox. Read thetopic that best fits your skill level:
I f You Area NewUser
I f You Arean Experienced Toolbox User
All Toolbox Users
If You Are a New User
Begin with Chapter 1, Signal ProcessingBasics.This chapter introduces the
MATLAB signal processingenvironment through thetoolbox functions. I t
describes thebasic functions of theSignal ProcessingToolbox, reviewingits
usein basicwaveformgeneration, filter implementation andanalysis, impulse
and frequency response, zero-poleanalysis, linear systemmodels, and the
discreteFourier transform.
When you feel comfortablewith thebasicfunctions, moveon toChapter 2and
Chapter 3 for a morein-depth introduction tousingtheSignal Processing
Toolbox:
Chapter 2, Filter Design, for a detailed explanation of usingtheSignal
ProcessingToolbox in infiniteimpulseresponse(I I R) and finiteimpulse
response(FI R) filter design and implementation, includingspecial topics in
I I R filter design.
Chapter 3, Statistical Signal Processing,for howtousethecorrelation,
covariance, and spectral analysis tools toestimateimportant functions of
discreterandomsignals.
Onceyou understand thegeneral principles and applications of thetoolbox,
learn howtousetheinteractivetools:
Chapter 5, Filter Design and Analysis Tool,and Chapter 6, SPTool: A
Signal ProcessingGUI Suite, for an overviewof theinteractiveGUI
environments and examples of howtousethemfor signal exploration, filter
design and implementation, and spectral analysis.
Finally, seethefollowingchapter:
How to Use This Manual
-27
Chapter 4, Special Topics, for specialized functions, includingfilter
windows, parametric modeling, resampling, cepstrumanalysis,
time-dependent Fourier transforms and spectrograms, median filtering,
communications applications, deconvolution, and specialized transforms.
If You Are an Experienced Toolbox User
SeeChapter 5, Filter Design and Analysis Tool,and Chapter 6, SPTool: A
Signal ProcessingGUI Suite,for an overviewof theinteractiveGUI
environmentsandexamples of howtousethemfor signal viewing, filter design
and implementation, and spectral analysis.
All Toolbox Users
UseChapter 7, Function Reference, for locatinginformation on specific
functions. Referencedescriptionsincludeasynopsisof thefunctionssyntax, as
well as a completeexplanation of options and operations. Many reference
descriptions alsoincludehelpful examples, a description of thefunctions
algorithm, and references toadditional readingmaterial.
Usethis manual in conjunction with thesoftwaretolearn about thepowerful
features that MATLAB provides. Each chapter provides numerous examples
that apply thetoolbox torepresentativesignal processingtasks.
Someexamples useMATLABs randomnumber generation function r andn. I n
thesecases, toduplicatetheresults in theexample, type
r andn( ' st at e' , 0)
beforerunningtheexample.
Preface
-28
Installing the Signal Processing Toolbox
Todetermineif theSignal ProcessingToolboxis installedon your system, type
this command at theMATLAB prompt.
ver
When you enter this command, MATLAB displays information about the
version of MATLAB you arerunning, includinga list of all toolboxes installed
on your systemand their version numbers.
For information about installingthetoolbox, seetheMATLAB I nstallation
Guidefor your platform.
Technical Conventions
-29
Technical Conventions
This manual and theSignal ProcessingToolbox functions usethefollowing
technical notations.
Nyquist frequency One-half thesamplingfrequency. Some
toolbox functions normalizethis valueto1.
x( 1) Thefirst element of a data sequenceor
filter, correspondingtozerolag.
or w Analogfrequency in radians per second.
or w Digital frequency in radians per sample.
f Digital frequency in hertz.
[x, y) Theinterval fromx toy, includingx but not
includingy.
. . . Ellipses in theargument list for a given
syntax on a function referencepage
indicateall possibleargument lists for that
function appearingprior tothegiven
syntax arevalid.
Preface
-30
Typographical Conventions
This manual uses someor all of theseconventions.
Item Convention to Use Example
Examplecode Monospace font Toassign thevalue5 toA,
enter
A = 5
Function names/syntax Monospace font Thecos function finds the
cosineof each array element.
Syntax lineexampleis
MLGet Var ML_var _name
Keys Boldfacewith an initial
capital letter
Press theReturn key.
Literal strings (in syntax
descriptions in Reference
chapters)
Monospacebol dfor literals f = f r eqspace( n, ' whol e' )
Mathematical expressions I talics for variables
Standard text font for
functions, operators, and
constants
This vector represents the
polynomial
MATLAB output Monospace font MATLAB responds with
A =
5
Menu names, menu items, and
controls
Boldfacewith an initial
capital letter
ChoosetheFilemenu.
Newterms I talics An array is an ordered
collection of information.
Stringvariables (froma finite
list)
Monospace i t al i cs sysc = d2c( sysd, ' met hod' )
p x
2
2x 3 + + =
1
Signal ProcessingBasics
Signal ProcessingToolbox Central Features . . . . . 1-2
RepresentingSignals . . . . . . . . . . . . . . . . 1-4
WaveformGeneration: TimeVectors and Sinusoids . . 1-6
Workingwith Data . . . . . . . . . . . . . . . . . 1-13
Filter Implementation and Analysis . . . . . . . . . 1-14
Thefilter Function . . . . . . . . . . . . . . . . . 1-17
Other Functions for Filtering . . . . . . . . . . . . 1-19
ImpulseResponse . . . . . . . . . . . . . . . . . 1-23
Frequency Response . . . . . . . . . . . . . . . . 1-24
Zero-PoleAnalysis . . . . . . . . . . . . . . . . . 1-30
Linear SystemModels . . . . . . . . . . . . . . . 1-32
DiscreteFourier Transform . . . . . . . . . . . . . 1-44
Selected Bibliography . . . . . . . . . . . . . . . 1-47
1 Signal Processing Basics
1-2
Overview
This chapter describes howtobegin usingMATLAB andtheSignal Processing
Toolbox for your signal processingapplications. I t assumes a basicknowledge
and understandingof signals and systems, includingsuch topics as filter and
linear systemtheory and basic Fourier analysis. Thechapter covers the
followingtopics:
Signal ProcessingToolbox Central Features
RepresentingSignals
WaveformGeneration: TimeVectors and Sinusoids
Workingwith Data
Filter I mplementation and Analysis
Thefilter Function
Other Functions for Filtering
I mpulseResponse
Frequency Response
Zero-PoleAnalysis
Linear SystemModels
DiscreteFourier Transform
Selected Bibliography
Many examples throughout thechapter demonstratehowtoapply toolbox
functions. I f you arenot already familiar with MATLABs signal processing
capabilities, usethis chapter in conjunction with thesoftwaretotry examples
and learn about thepowerful features availabletoyou.
Signal Processing Toolbox Central Features
1-3
Signal Processing Toolbox Central Features
TheSignal ProcessingToolbox functions arealgorithms, expressed mostly in
M-files, that implement a variety of signal processingtasks. Thesetoolbox
functions area specialized extension of theMATLAB computational and
graphical environment.
Filtering and FFTs
Twoof themost important functions for signal processingarenot in theSignal
ProcessingToolbox at all, but arebuilt-in MATLAB functions:
f i l t er applies a digital filter toa data sequence.
f f t calculates thediscreteFourier transformof a sequence.
Theoperations thesefunctions performarethemain computational
workhorses of classical signal processing. Both aredescribed in this chapter.
TheSignal ProcessingToolbox uses many other standard MATLAB functions
and languagefeatures, includingpolynomial root finding, complex arithmetic,
matrix inversion and manipulation, and graphics tools.
Signals and Systems
Thebasic entities that toolbox functions work with aresignals and systems.
Thefunctions emphasizedigital, or discrete, signals and filters, as opposed to
analog, or continuous, signals. Theprincipal filter typethetoolbox supports is
thelinear, time-invariant digital filter with asingleinput andasingleoutput.
You can represent linear time-invariant systems usingoneof several models
(such as transfer function, state-space, zero-pole-gain, and second-order
section) and convert between representations.
Key Areas: Filter Design and Spectral Analysis
I nadditiontoitscorefunctions, thetoolboxprovidesrich, customizablesupport
for thekey areas of filter design and spectral analysis. I t is easy toimplement
adesign techniquethat suits your application, design digital filters directly, or
createanalogprototypes and discretizethem. Toolbox functions alsoestimate
power spectral density and cross spectral density, usingeither parametric or
nonparametric techniques. Filter Designon page2-1and Statistical Signal
Processingon page3-1 respectively detail toolbox functions for filter design
and spectral analysis.
1 Signal Processing Basics
1-4
Therearefunctions for computation and graphical display of frequency
response, as well as functions for systemidentification; generatingsignals;
discretecosine, chirp-z, and Hilbert transforms; latticefilters; resampling;
time-frequency analysis; and basic communication systems simulation.
Interactive Tools: SPTool and FDATool
Thepower of theSignal ProcessingToolbox is greatly enhanced by its
easy-to-useinteractivetools. SPTool provides arich graphical environment for
signal viewing, filter design, and spectral analysis. TheFilter Design and
Analysis Tool (FDATool) provides a morecomprehensivecollection of features
for addressingtheproblemof filter design. TheFDATool alsooffers seamless
access totheadditional filter design methods and quantization features of the
Filter Design Toolbox when that product is installed.
Extensibility
Perhaps themost important featureof theMATLAB environment is that it is
extensible: MATLAB lets you createyour own M-files tomeet numeric
computation needs for research, design, or engineeringof signal processing
systems. Simply copy theM-files provided with theSignal ProcessingToolbox
andmodifythemasneeded, or createnewfunctionstoexpandthefunctionality
of thetoolbox.
Representing Signals
1-5
Representing Signals
Thecentral data construct in MATLAB is thenumeric array, an ordered
collection of real or complex numeric data with twoor moredimensions. The
basic data objects of signal processing(one-dimensional signals or sequences,
multichannel signals, and two-dimensional signals) areall naturally suited to
array representation.
Vector Representation
MATLAB represents ordinary one-dimensional sampled data signals, or
sequences, as vectors. Vectors are1-by-n or n-by-1 arrays, wheren is the
number of samples in thesequence. Oneway tointroducea sequenceinto
MATLAB is toenter it as a list of elements at thecommand prompt. The
statement
x = [ 4 3 7 - 9 1]
creates a simplefive-element real sequencein a rowvector. Transposition
turns thesequenceintoa column vector
x = x'
resultingin
x =
4
3
7
- 9
1
Column orientation is preferablefor singlechannel signals becauseit extends
naturally tothemultichannel case. For multichannel data, each column of a
matrix represents onechannel. Each rowof such a matrix then corresponds to
a samplepoint. A three-channel signal that consists of x, 2x, and x/ is
y = [ x 2*x x/ pi ]
1 Signal Processing Basics
1-6
This results 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
WaveformGeneration: Time Vectors and Sinusoids
1-7
Waveform Generation: Time Vectors and Sinusoids
A variety of toolbox functions generatewaveforms. Most requireyou tobegin
with a vector representinga timebase. Consider generatingdata with a 1000
Hz samplefrequency, for example. An appropriatetimevector is
t = ( 0: 0. 001: 1) ' ;
whereMATLABs colon operator creates a 1001-element rowvector that
represents timerunningfromzerotoonesecond in steps of onemillisecond.
Thetransposeoperator ( ' ) changes therowvector intoa column; the
semicolon (; ) tells MATLAB tocomputebut not display theresult.
Given t you can createa samplesignal y consistingof twosinusoids, oneat 50
Hz and oneat 120 Hz with twicetheamplitude.
y = si n( 2*pi *50*t ) + 2*si n( 2*pi *120*t ) ;
Thenewvariabley, formed fromvector t , is also1001elements long. You can
add normally distributed whitenoisetothesignal and graph thefirst fifty
points using
r andn( ' st at e' , 0) ;
yn = y + 0. 5*r andn( si ze( t ) ) ;
pl ot ( t ( 1: 50) , yn( 1: 50) )
0 0.01 0.02 0.03 0.04 0.05
3
2
1
0
1
2
3
4
1 Signal Processing Basics
1-8
Common Sequences: Unit Impulse, Unit Step, and
Unit Ramp
SinceMATLAB is a programminglanguage, an endless variety of different
signals is possible. Herearesomestatements that generateseveral commonly
usedsequences, includingtheunit impulse, unit step, andunit rampfunctions.
t = ( 0: 0. 001: 1) ' ;
y = [ 1; zer os( 99, 1) ] ; %i mpul se
y = ones( 100, 1) ; %st ep ( f i l t er assumes 0 i ni t i al cond. )
y = t ; %r amp
y = t . ^2;
y = squar e( 4*t ) ;
All of thesesequences arecolumn vectors. Thelast threeinherit their shapes
fromt .
Multichannel Signals
Usestandard MATLAB array syntax towork with multichannel signals. For
example, a multichannel signal consistingof thelast threesignals generated
aboveis
z = [ t t . ^2 squar e( 4*t ) ] ;
You can generateamultichannel unit samplefunction usingtheouter product
operator. For example, asix-element column vector whosefirst element is one,
and whoseremainingfiveelements arezeros, is
a = [ 1 zer os( 1, 5) ] ' ;
Toduplicatecolumn vector a intoa matrix without performingany
multiplication, useMATLABs colon operator and the ones function.
c = a( : , ones( 1, 3) ) ;
WaveformGeneration: Time Vectors and Sinusoids
1-9
Common Periodic Waveforms
Thetoolbox provides functions for generatingwidely used periodicwaveforms:
sawt oot h generatesasawtoothwavewithpeaksat 1andaperiodof . An
optional wi dt h parameter specifies a fractional multipleof at which the
signals maximumoccurs.
squar e generates asquarewavewith a periodof . An optional parameter
specifies dutycycle, thepercent of theperiod for which thesignal is positive.
Togenerate1.5seconds of a50Hz sawtooth wavewith asamplerateof 10kHz
and plot 0.2 seconds of thegenerated waveform, use
f s = 10000;
t = 0: 1/ f s: 1. 5;
x = sawt oot h( 2*pi *50*t ) ;
pl ot ( t , x) , axi s( [ 0 0. 2 - 1 1] )
2
2
2
0 0.02 0.04 0.06 0.08 0.1 0.12 0.14 0.16 0.18 0.2
-1
-0.5
0
0.5
1
1 Signal Processing Basics
1-10
Common Aperiodic Waveforms
Thetoolbox alsoprovides functions for generatingseveral widely used
aperiodic waveforms:
gauspul s generates aGaussian-modulatedsinusoidal pulsewith aspecified
time, center frequency, and fractional bandwidth. Optional parameters
return in-phaseand quadraturepulses, theRF signal envelope, and the
cutoff timefor thetrailingpulseenvelope.
chi r p generates a linear swept-frequency cosinesignal. An optional
parameter specifies alternativesweep methods. An optional parameter phi
allows initial phasetobespecified in degrees.
Tocompute2 seconds of a linear chirpsignal with a samplerateof 1 kHz, that
starts at DC and crosses 150 Hz at 1 second, use
t = 0: 1/ 1000: 2;
y = chi r p( t , 0, 1, 150) ;
Toplot thespectrogram, use
specgr am( y, 256, 1000, 256, 250)
Time
F
r
e
q
u
e
n
c
y
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6
0
50
100
150
200
250
300
350
400
450
500
WaveformGeneration: Time Vectors and Sinusoids
1-11
The pulstran Function
Thepul st r an function generates pulsetrains fromeither continuous or
sampled prototypepulses. Thefollowingexamplegenerates a pulsetrain
consistingof thesumof multipledelayed interpolations of a Gaussian pulse.
Thepulsetrain is definedtohaveasamplerateof 50 kHz, apulsetrain length
of 10 ms, andapulserepetitionrateof 1 kHz; Dspecifiesthedelaytoeachpulse
repetition in column 1 and an optional attenuation for each repetition in
column 2. Thepulsetrain is constructed by passingthenameof thegauspul s
function topul st r an, alongwith additional parameters that specify a 10 kHz
Gaussian pulsewith 50%bandwidth.
T = 0: 1/ 50E3: 10E- 3;
D = [ 0: 1/ 1E3: 10E- 3; 0. 8. ^( 0: 10) ] ' ;
Y = pul st r an( T, D, ' gauspul s' , 10E3, 0. 5) ;
pl ot ( T, Y)
0 0.001 0.002 0.003 0.004 0.005 0.006 0.007 0.008 0.009 0.01
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
1 Signal Processing Basics
1-12
The Sinc Function
Thesi nc functioncomputesthemathematical sincfunction for aninput vector
or matrix x. Thesinc function is thecontinuous inverseFourier transformof
therectangular pulseof width and height 1.
Thesinc function has a valueof 1 wherex is zero, and a valueof
for all other elements of x.
Toplot thesincfunction for a linearly spaced vector with values rangingfrom
-5 to5, usethefollowingcommands.
x = l i nspace( - 5, 5) ;
y = si nc( x) ;
pl ot ( x, y)
2
x ( ) sin
x
--------------------
-5 -4 -3 -2 -1 0 1 2 3 4 5
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
WaveformGeneration: Time Vectors and Sinusoids
1-13
The Dirichlet Function
Thetoolbox function di r i c computes theDirichlet function, sometimes called
theperiodic sinc or aliased sinc function, for an input vector or matrix x. The
Dirichlet function is
wheren is a user-specified positiveinteger. For n odd, theDirichlet function
has a period of ; for n even, its period is . Themagnitudeof this function
is (1/n) times themagnitudeof thediscrete-timeFourier transformof the
n-point rectangular window.
Toplot theDirichlet function over therange0 to4 for n =7 and n =8, use
x = l i nspace( 0, 4*pi , 300) ;
pl ot ( x, di r i c( x, 7) )
pl ot ( x, di r i c( x, 8) )
diric x ( )
1
k n 1 ( )
x 2k k 0 1 2 , , , = , =
nx 2 ( ) sin
n x 2 ( ) sin
---------------------------- otherwise




=
2 4
0 5 10 15
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
n = 7
0 5 10 15
-1
-0.5
0
0.5
1
n = 8
1 Signal Processing Basics
1-14
Working with Data
Theexamples in theprecedingsections obtain data in oneof twoways:
By direct input, that is, enteringthedata manually at thekeyboard
ByusingaMATLAB or toolboxfunction, suchassi n, cos, sawt oot h, squar e,
or si nc
Someapplications, however, may need toimport data fromoutsideMATLAB.
Dependingon your data format, you can dothis in thefollowingways:
Load data froman ASCI I fileor MAT-filewith MATLABs l oad command.
ReadthedataintoMATLAB withalow-level fileI /Ofunction, such as f open,
f r ead, and f scanf .
Develop a MEX-filetoread thedata.
Other resources arealsouseful, such as a high-level languageprogram(in
Fortran or C, for example) that converts your data intoMAT-fileformat see
theMATLAB External I nterfaces/API Referencefor details. MATLAB reads
such files usingthel oad command.
Similar techniques areavailablefor exportingdata generated within
MATLAB. SeetheMATLAB documentation for moredetails on importingand
exportingdata.
Filter Implementation and Analysis
1-15
Filter Implementation and Analysis
This section describes howtofilter discretesignals usingMATLABs f i l t er
function andother functions in theSignal ProcessingToolbox. I t alsodiscusses
howtousethetoolbox functions toanalyzefilter characteristics, including
impulseresponse, magnitudeand phaseresponse, group delay, and zero-pole
locations.
Convolution and Filtering
Themathematical foundation of filteringis convolution. MATLABs conv
function performs standard one-dimensional convolution, convolvingone
vector with another.
conv( [ 1 1 1] , [ 1 1 1] )
ans =
1 2 3 2 1
Note Convolverectangular matrices for two-dimensional signal processing
usingtheconv2 function.
A digital filters output y(n) is related toits input x(n) by convolution with its
impulseresponseh(n).
I f a digital filters impulseresponseh(n) is finitelength, and theinput x(n) is
alsofinitelength, youcanimplement thefilter usingconv. Storex(n) inavector
x, h(n) in a vector h, and convolvethetwo.
x = r andn( 5, 1) ; %A r andomvect or of l engt h 5
h = [ 1 1 1 1] / 4; %Lengt h 4 aver agi ng f i l t er
y = conv( h, x) ;
y n ( ) h n ( ) x n ( ) h n m ( )x m ( )
m =

= =
1 Signal Processing Basics
1-16
Filters and Transfer Functions
I n general, thez-transformY(z) of a digital filters output y(n) is related tothe
z-transformX(z) of theinput by
whereH(z) is thefilters transfer function. Here, theconstants b(i) anda(i) are
thefilter coefficients and theorder of thefilter is themaximumof na and nb.
Note Thefilter coefficients start with subscript 1, rather than 0. This reflects
MATLABs standard indexingschemefor vectors.
MATLAB stores thecoefficients in twovectors, onefor thenumerator and one
for thedenominator. By convention, MATLAB uses rowvectors for filter
coefficients.
Filter Coefficients and Filter Names
Many standard names for filters reflect thenumber of a and b coefficients
present:
When nb =0(that is, b is ascalar), thefilter is an I nfiniteI mpulseResponse
(I I R), all-pole, recursive, or autoregressive(AR) filter.
When na =0 (that is, a is a scalar), thefilter is a FiniteI mpulseResponse
(FI R), all-zero, nonrecursive, or movingaverage(MA) filter.
I f both na and nb aregreater than zero, thefilter is an I I R, pole-zero,
recursive, or autoregressivemovingaverage(ARMA) filter.
Theacronyms AR, MA, and ARMA areusually applied tofilters associated
with filtered stochastic processes.
Y z ( ) H z ( )X z ( )
b 1 ( ) b 2 ( )z
1
L b nb 1 + ( )z
nb
+ + +
a 1 ( ) a 2 ( )z
1
L a na 1 + ( )z
na
+ + +
--------------------------------------------------------------------------------------------X z ( ) = =
Filter Implementation and Analysis
1-17
Filtering with the filter Function
I t is simpletowork back toadifferenceequation fromthez-transformrelation
shown earlier. Assumethat a(1) =1. Movethedenominator totheleft-hand
sideand taketheinversez-transform.
I n terms of current and past inputs, and past outputs, y(n) is
This is thestandard time-domain representation of a digital filter, computed
startingwith y(1) and assumingzeroinitial conditions. This representations
progression is
A filter in this formis easy toimplement with thef i l t er function. For
example, a simplesingle-polefilter (lowpass) is
b = 1; %Numer at or
a = [ 1 - 0. 9] ; %Denomi nat or
wherethevectors b and a represent thecoefficients of a filter in transfer
function form. Toapply this filter toyour data, use
y = f i l t er ( b, a, x) ;
f i l t er gives you as many output samples as thereareinput samples, that is,
thelength of y is thesameas thelength of x. I f thefirst element of a is not 1,
f i l t er divides thecoefficients by a( 1) beforeimplementingthedifference
equation.
y n ( ) a
2
y n 1 ( ) L a
na 1 +
y n na ( ) + + +
b
1
x n ( ) b
2
x n 1 ( ) L b
nb 1 +
x n nb ( ) + + +
=
y n ( ) b
1
x n ( ) b
2
x n 1 ( ) L b
nb 1 +
x n nb ( ) a
2
y n 1 ( ) L a
na 1 +
y n na ( ) + + + =
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 ( ) + + =
=
1 Signal Processing Basics
1-18
The filter Function
f i l t er isimplementedasthetransposeddirect-formI I structureshownbelow,
wheren-1 is thefilter order. This is a canonical formthat has theminimum
number of delay elements.
At samplem, f i l t er computes thedifferenceequations
I n its most basic form, f i l t er initializes thedelay outputs z
i
(1), i =1, ..., n-1
to0. This is equivalent toassumingboth past inputs and outputs arezero. Set
theinitial delay outputs usinga fourth input parameter tof i l t er , or access
thefinal delay outputs usinga second output parameter.
[ y, zf ] = f i l t er ( b, a, x, zi )
Access toinitial and final conditions is useful for filteringdata in sections,
especially if memory limitations area consideration. Supposeyou have
collected data in twosegments of 5000 points each.
x1 = r andn( 5000, 1) ; %Gener at e t wo r andomdat a sequences.
x2 = r andn( 5000, 1) ;
Perhaps thefirst sequence, x1, corresponds tothefirst 10minutes of data and
thesecond, x2, toanadditional 10minutes. Thewholesequenceisx =[ x1; x2] .
I f thereis not sufficient memory tohold thecombined sequence, filter the
z
-1
z
-1
x(m)
y(m)
b( 3) b( 2) b(1)
a( 3) a( 2)
z
1
(m) z
2
(m)
z
-1
b(n)
a(n)
z
n-1
(m)
...
...
...
y m ( ) b 1 ( )x m ( ) z
1
m 1 ( ) + =
z
1
m ( ) b 2 ( )x m ( ) z
2
m 1 ( ) a 2 ( )y m ( ) + =
=
z
n 2
m ( ) b n 1 ( )x m ( ) z
n 1
m 1 ( ) a n 1 ( )y m ( ) + =
z
n 1
m ( ) b n ( )x m ( ) a n ( )y m ( ) =
The filter Function
1-19
subsequences x1 and x2 oneat a time. Toensurecontinuity of thefiltered
sequences, usethefinal conditions fromx1 as initial conditions tofilter x2.
[ y1, zf ] = f i l t er ( b, a, x1) ;
y2 = f i l t er ( b, a, x2, zf ) ;
Thef i l t i c function generates initial conditions for f i l t er . f i l t i c computes
thedelay vector tomakethebehavior of thefilter reflect past inputs and
outputs that you specify. Toobtain thesameoutput delay values zf as above
usingf i l t i c, use
zf = f i l t i c( b, a, f l i pud( y1) , f l i pud( x1) ) ;
This can beuseful when filteringshort data sequences, as appropriateinitial
conditions help reducetransient startup effects.
1 Signal Processing Basics
1-20
Other Functions for Filtering
I n addition tof i l t er , several other functions in theSignal ProcessingToolbox
performthebasic filteringoperation. Thesefunctions includeupf i r dn, which
performs FI R filteringwith resampling, f i l t f i l t , which eliminates phase
distortion in thefilteringprocess, f f t f i l t , which performs theFI R filtering
operation in thefrequency domain, and l at cf i l t , which filters usinga lattice
implementation.
Multirate Filter Bank Implementation
Thefunction upf i r dn alters thesamplingrateof a signal by an integer ratio
P/Q. I t computes theresult of a cascadeof threesystems that performs the
followingtasks:
Upsampling(zeroinsertion) by integer factor p
Filteringby FI R filter h
Downsamplingby integer factor q
For example, tochangethesamplerateof asignal from44.1 kHz to48 kHz, we
first find thesmallest integer conversion ratiop/ q. Set
d = gcd( 48000, 44100) ;
p = 48000/ d;
q = 44100/ d;
I n this example, p =160 and q =147. Samplerateconversion is then
accomplished by typing
y = upf i r dn( x, h, p, q)
This cascadeof operations is implemented in an efficient manner using
polyphasefilteringtechniques, andit is acentral concept of multiratefiltering
(seereference[1] for details on multiratefilter theory). Notethat thequalityof
theresamplingresult relies on thequality of theFI R filter h.
P
x(n) y(n)
FIR
H
Q
Other Functions for Filtering
1-21
Filter banks may beimplemented using upf i r dn by allowingthefilter h tobe
a matrix, with oneFI R filter per column. A signal vector is passed
independently through each FI R filter, resultingin a matrix of output signals.
Other functions that performmultiratefiltering(with fixed filter) include
r esampl e, i nt er p, and deci mat e.
Anti-Causal, Zero-Phase Filter Implementation
I n thecaseof FI R filters, it is possibletodesign linear phasefilters that, when
applied todata (usingf i l t er or conv), simply delay theoutput by a fixed
number of samples. For I I R filters, however, thephasedistortion is usually
highly nonlinear. Thef i l t f i l t function uses theinformation in thesignal at
points beforeand after thecurrent point, in essencelookingintothefuture,
toeliminatephasedistortion.
Toseehowf i l t f i l t does this, recall that if thez-transformof a real sequence
x(n) is X(z), thez-transformof thetimereversed sequencex(n) is X(1/z).
Consider theprocessingscheme
When | z| =1, that is z =e
j
, theoutput reduces toX(e
j
)| H(e
j
)|
2
. Given all
thesamples of thesequencex(n), a doubly filtered version of x that has
zero-phasedistortion is possible.
For example, a 1-second duration signal sampled at 100 Hz, composed of two
sinusoidal components at 3 Hz and 40 Hz, is
f s = 100;
t = 0: 1/ f s: 1;
x = si n( 2*pi *t *3) +. 25*si n( 2*pi *t *40) ;
H(z) X(z)
X(z)H(z) X(1/z)H(1/z) X(1/z)H(1/z)H(z)
X(z)H(1/z)H(z) H(z)
Time
Reverse
Time
Reverse
1 Signal Processing Basics
1-22
Nowcreatea 10-point averagingFI R filter, and filter x usingboth f i l t er and
f i l t f i l t for comparison.
b = ones( 1, 10) / 10; %10 poi nt aver agi ng f i l t er
y = f i l t f i l t ( b, 1, x) ; %Noncausal f i l t er i ng
yy = f i l t er ( b, 1, x) ; %Nor mal f i l t er i ng
pl ot ( t , x, t , y, ' - - ' , t , yy, ' : ' )
Both filtered versions eliminatethe40 Hz sinusoid evident in theoriginal,
solid line. Theplot alsoshows how f i l t er and f i l t f i l t differ; thedashed
(f i l t f i l t ) lineis in phasewith theoriginal 3 Hz sinusoid, whilethedotted
(f i l t er ) lineis delayed by about fivesamples. Also, theamplitudeof the
dashed lineis smaller duetothemagnitudesquared effects of f i l t f i l t .
f i l t f i l t reduces filter startup transients by carefully choosinginitial
conditions, and by prependingontotheinput sequencea short, reflected piece
of theinput sequence. For best results, makesurethesequenceyou are
filteringhas length at least threetimes thefilter order and tapers tozeroon
both edges.
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
-1.5
-1
-0.5
0
0.5
1
1.5
Other Functions for Filtering
1-23
Frequency Domain Filter Implementation
Duality between thetimedomain and thefrequency domain makes it possible
toperformany operation in either domain. Usually onedomain or theother is
moreconvenient for a particular operation, but you can always accomplish a
given operation in either domain.
Toimplement general I I R filteringin thefrequency domain, multiply the
discreteFourier transform(DFT) of theinput sequencewiththequotient of the
DFT of thefilter.
n = l engt h( x) ;
y = i f f t ( f f t ( x) . *f f t ( b, n) . / f f t ( a, n) ) ;
This computes results that areidentical tof i l t er , but with different startup
transients (edgeeffects). For longsequences, this computation is very
inefficient becauseof thelargezero-padded FFT operations on thefilter
coefficients, and becausetheFFT algorithmbecomes less efficient as the
number of points n increases.
For FI R filters, however, it is possibletobreak longer sequences intoshorter,
computationally efficient FFT lengths. Thefunction
y = f f t f i l t ( b, x)
uses theoverlap add method (seereference[1] at theend of this chapter) to
filter a longsequencewith multiplemedium-length FFTs. I ts output is
equivalent tof i l t er ( b, 1, x) .
1 Signal Processing Basics
1-24
Impulse Response
Theimpulseresponseof a digital filter is theoutput arisingfromtheunit
impulseinput sequencedefined as
I n MATLAB, you can generatean impulsesequencea number of ways; one
straightforward way is
i mp = [ 1; zer os( 49, 1) ] ;
Theimpulseresponseof thesimplefilter b =1 and a =[ 1 - 0. 9] is
h = f i l t er ( b, a, i mp) ;
Thei mpz functionin thetoolboxsimplifiesthisoperation, choosingthenumber
of points togenerateand then makinga stemplot (usingthest emfunction).
i mpz( b, a)
Theplot shows theexponential decay h( n) =0. 9n of thesinglepolesystem.
x n ( )
1 n 1 = ,
0 n 1 ,


=
0 10 20 30 40 50 60 70 80 90
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
Frequency Response
1-25
Frequency Response
TheSignal ProcessingToolbox enables you toperformfrequency domain
analysis of both analogand digital filters.
Digital Domain
f r eqz uses an FFT-based algorithmtocalculatethez-transformfrequency
responseof a digital filter. Specifically, thestatement
[ h, w] = f r eqz( b, a, n)
returns then-point complex frequency response, , of thedigital filter.
I n its simplest form, f r eqz accepts thefilter coefficient vectors b anda, andan
integer n specifyingthenumber of points at which tocalculatethefrequency
response. f r eqz returns thecomplex frequency responsein vector h, and the
actual frequency points in vector win rad/s.
f r eqz can accept other parameters, such as asamplingfrequency or avector of
arbitrary frequency points. Theexamplebelowfinds the256-point frequency
responsefor a 12th-order Chebyshev typeI filter. Thecall tof r eqz specifies a
samplingfrequency f s of 1000 Hz.
[ b, a] = cheby1( 12, 0. 5, 200/ 500) ;
[ h, f ] = f r eqz( b, a, 256, 1000) ;
Becausetheparameter list includes a samplingfrequency, f r eqz returns a
vector f that contains the256frequencypoints between 0andf s/ 2 usedin the
frequency responsecalculation.
H e
j
( )
H e
j
( )
b 1 ( ) b 2 ( )e
j
L b nb 1 + ( )e
j nb ( )
+ + +
a 1 ( ) a 2 ( )e
j
L a na 1 + ( )e
j na ( )
+ + +
------------------------------------------------------------------------------------------------------- =
1 Signal Processing Basics
1-26
Frequency Normalization This toolbox uses theconvention that unit
frequency is theNyquist frequency, defined as half thesamplingfrequency.
Thecutoff frequency parameter for all basic filter design functions is
normalized by theNyquist frequency. For a systemwith a 1000 Hz sampling
frequency, for example, 300 Hz is 300/500 =0.6. Toconvert normalized
frequency toangular frequency around theunit circle, multiply by . To
convert normalized frequency back tohertz, multiply by half thesample
frequency.
I f you call f r eqz with nooutput arguments, it automatically plots both
magnitudeversus frequency and phaseversus frequency. For example, a
ninth-order Butterworthlowpassfilter withacutoff frequencyof 400Hz, based
on a 2000 Hz samplingfrequency, is
[ b, a] = but t er ( 9, 400/ 1000) ;
Nowcalculatethe256-point complexfrequencyresponsefor thisfilter, andplot
themagnitudeand phasewith a call tof r eqz.
f r eqz( b, a, 256, 2000)
0 100 200 300 400 500 600 700 800 900 1000
-1000
-800
-600
-400
-200
0
Frequency (Hertz)
P
h
a
s
e

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

R
e
s
p
o
n
s
e

(
d
B
)
Frequency Response
1-27
f r eqz can alsoaccept a vector of arbitrary frequency points for usein the
frequency responsecalculation. For example,
w = l i nspace( 0, pi ) ;
h = f r eqz( b, a, w) ;
calculates thecomplex frequency responseat thefrequency points in wfor the
filter defined by vectors b and a. Thefrequency points can rangefrom0to .
Tospecifyafrequencyvector that rangesfromzerotoyour samplingfrequency,
includeboth thefrequency vector and thesamplingfrequency valuein the
parameter list.
Analog Domain
f r eqs evaluates frequency responsefor an analogfilter defined by twoinput
coefficient vectors, b and a. I ts operation is similar tothat of f r eqz; you can
specify a number of frequency points touse, supply a vector of arbitrary
frequency points, and plot themagnitudeand phaseresponseof thefilter.
Magnitude and Phase
MATLAB provides functions toextract magnitudeandphasefromafrequency
responsevector h. Thefunction abs returns themagnitudeof theresponse;
angl e returns thephaseanglein radians. Toextract and plot themagnitude
and phaseof a Butterworth filter.
[ b, a] = but t er ( 6, 300/ 500) ;
[ h, w] = f r eqz( b, a, 512, 1000) ;
m= abs( h) ; p = angl e( h) ;
semi l ogy( w, m) ; t i t l e( ' Magni t ude' ) ;
f i gur e; pl ot ( w, p*180/ pi ) ; t i t l e( ' Phase' ) ;
2
0 100 200 300 400 500
10
15
10
10
10
5
10
0
Magnitude
0 100 200 300 400 500
200
150
100
50
0
50
100
150
200
Phase
1 Signal Processing Basics
1-28
Theunwr ap function is alsouseful in frequency analysis. unwr ap unwraps the
phasetomakeit continuous across 360 phasediscontinuities by adding
multiples of 360, as needed. Toseehowunwr ap is useful, design a25th-order
lowpass FI R filter.
h = f i r 1( 25, 0. 4) ;
Obtain thefilters frequency responsewith f r eqz, and plot thephasein
degrees.
[ H, f ] = f r eqz( h, 1, 512, 2) ;
pl ot ( f , angl e( H) *180/ pi ) ; gr i d
I t is difficult todistinguish the360 jumps (an artifact of thearctangent
function insideangl e) fromthe180 jumps that signify zeros in thefrequency
response.
Useunwr ap toeliminatethe360 jumps.
pl ot ( f , unwr ap( angl e( H) ) *180/ pi ) ; gr i d
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
-200
-150
-100
-50
0
50
100
150
200
Frequency Response
1-29
Delay
Thegroup delay of a filter is a measureof theaveragedelay of thefilter as a
function of frequency. I t is defined as thenegativefirst derivativeof a filters
phaseresponse. I f thecomplex frequency responseof a filter is , then
thegroup delay is
where is thephaseangleof . Computegroup delay with
[ gd, w] = gr pdel ay( b, a, n)
which returns then-point groupdelay, , of thedigital filter specifiedby b
and a, evaluated at thefrequencies in vector w.
Thephasedelay of a filter is thenegativeof phasedivided by frequency
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
-1400
-1200
-1000
-800
-600
-400
-200
0
H e
j
( )

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

g
( )

p
( )
( )

----------- =
1 Signal Processing Basics
1-30
Toplot both thegroup and phasedelays of a systemon thesamegraph, type
[ b, a] = but t er ( 10, 200/ 1000) ;
gd = gr pdel ay( b, a, 128) ;
[ h, f ] = f r eqz( b, a, 128, 2000) ;
pd = - unwr ap( angl e( h) ) *( 2000/ ( 2*pi ) ) . / f ;
pl ot ( f , gd, ' - ' , f , pd, ' - - ' )
axi s( [ 0 1000 - 30 30] )
l egend( ' Gr oup Del ay' , ' Phase Del ay' )
0 200 400 600 800 1000
30
20
10
0
10
20
30
Group Delay
Phase Delay
Zero-Pole Analysis
1-31
Zero-Pole Analysis
Thezpl ane function plots poles and zeros of a linear system. For example, a
simplefilter with a zeroat -1/2 and a complex polepair at and
is
zer = - 0. 5;
pol = 0. 9*exp( j *2*pi *[ - 0. 3 0. 3] ' ) ;
Thezero-poleplot for thefilter is
zpl ane( zer , pol )
For a systemin zero-poleform, supply column vector arguments z and p to
zpl ane.
zpl ane( z, p)
For a systemin transfer function form, supply rowvectors b and a as
arguments tozpl ane.
zpl ane( b, a)
0.9e
j 2 0.3 ( )
0.9e
j 2 0.3 ( )
-1 -0.5 0 0.5 1
-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
Real part
I
m
a
g
i
n
a
r
y

p
a
r
t
1 Signal Processing Basics
1-32
I n this casezpl ane finds theroots of b anda usingther oot s function andplots
theresultingzeros and poles.
SeeLinear SystemModelson page1-33for details on zero-poleand transfer
function representation of systems.
Linear SystemModels
1-33
Linear System Models
TheSignal ProcessingToolbox provides several models for representinglinear
time-invariant systems. This flexibility lets you choosetherepresentational
schemethat best suits your application and, within thebounds of numeric
stability, convert freely toandfrommost other models. This section provides a
brief overviewof supported linear systemmodels and describes howtowork
with thesemodels in MATLAB.
Discrete-Time System Models
Thediscrete-timesystemmodels arerepresentational schemes for digital
filters. MATLAB supports several discrete-timesystemmodels, which are
described in thefollowingsections:
Transfer Function
Zero-Pole-Gain
State-Space
Partial Fraction Expansion (ResidueForm)
Second-Order Sections (SOS)
LatticeStructure
Convolution Matrix
Transfer Function
Thetransfer function is a basic z-domain representation of a digital filter,
expressingthefilter as a ratioof twopolynomials. I t is theprincipal
discrete-timemodel for this toolbox. Thetransfer function model description
for thez-transformof a digital filters differenceequation is
Here, theconstants b(i) and a(i) arethefilter coefficients, and theorder of the
filter is themaximumof naandnb. I n MATLAB, you storethesecoefficients in
twovectors (rowvectors by convention), onerowvector for thenumerator and
onefor thedenominator. SeeFilters andTransfer Functionson page1-16for
moredetails on thetransfer function form.
Y z ( )
b 1 ( ) b 2 ( )z
1
L b nb 1 + ( )z
nb
+ + +
a 1 ( ) a 2 ( )z
1
L a na 1 + ( )z
na
+ + +
--------------------------------------------------------------------------------------------X z ( ) =
1 Signal Processing Basics
1-34
Zero-Pole-Gain
Thefactored or zero-pole-gain formof a transfer function is
By convention, MATLAB stores polynomial coefficients in rowvectors and
polynomial roots in column vectors. I n zero-pole-gain form, therefore, thezero
and polelocations for thenumerator and denominator of a transfer function
residein column vectors. Thefactored transfer function gain k is a MATLAB
scalar.
Thepol y and r oot s functions convert between polynomial and zero-pole-gain
representations. For example, a simpleI I R filter is
b = [ 2 3 4] ;
a = [ 1 3 3 1] ;
Thezeros and poles of this filter are
q = r oot s( b)
q =
- 0. 7500 + 1. 1990i
- 0. 7500 - 1. 1990i
p = r oot s( a)
p =
- 1. 0000
- 1. 0000 + 0. 0000i
- 1. 0000 - 0. 0000i
k = b( 1) / a( 1)
k =
2
Returningtotheoriginal polynomials,
bb = k*pol y( q)
bb =
2. 0000 3. 0000 4. 0000
H z ( )
q z ( )
p z ( )
---------- k
z q 1 ( ) ( ) z q 2 ( ) ( )L z q n ( ) ( )
z p 1 ( ) ( ) z p 2 ( ) ( )L z p n ( ) ( )
-------------------------------------------------------------------------------- = =
Linear SystemModels
1-35
aa = pol y( p)
aa =
1. 0000 3. 0000 3. 0000 1. 0000
Notethat b and a in this caserepresent thetransfer function
For b =[ 2 3 4] , ther oot s function misses thezerofor z equal to0. I n fact, it
missespolesandzerosfor zequal to0whenever theinput transfer functionhas
morepoles than zeros, or viceversa. This is acceptablein most cases. To
circumvent theproblem, however, simplyappendzerostomakethevectors the
samelength beforeusingther oot s function; for example, b =[ b 0] .
State-Space
I t is always possibletorepresent a digital filter, or a systemof difference
equations, as a set of first-order differenceequations. I n matrix or state-space
form, you can writetheequations as
whereu is theinput, x is thestatevector, and y is theoutput. For
single-channel systems, A is an m-by-mmatrix wheremis theorder of thefilter,
Bis a column vector, Cis arowvector, andDis ascalar. State-spacenotation is
especially convenient for multichannel systems whereinput u and output y
becomevectors, and B, C, and Dbecomematrices.
State-spacerepresentation extends easily totheMATLAB environment. I n
MATLAB, A, B, C, and Darerectangular arrays; MATLAB treats themas
individual variables.
Takingthez-transformof thestate-spaceequationsandcombiningthemshows
theequivalenceof state-spaceand transfer function forms.
Dont beconcerned if you arenot familiar with thestate-spacerepresentation
of linear systems. Someof thefilter design algorithms usestate-spaceform
internallybut donot requireanyknowledgeof state-spaceconceptstousethem
H z ( )
2 3z
1
4z
2
+ +
1 3z
1
3z
2
z
3
+ + +
------------------------------------------------------
2z
3
3z
2
4z + +
z
3
3z
2
3z 1 + + +
-------------------------------------------- = =
x n 1 + ( ) Ax n ( ) Bu n ( ) + =
y n ( ) Cx n ( ) Du n ( ) + =
Y z ( ) H z ( )U z ( ) = where H z ( ) C zI A ( )
1
B D + = ,
1 Signal Processing Basics
1-36
successfully. I f your applications usestate-spacebased signal processing
extensively, however, consult theContr ol SystemToolboxfor acomprehensive
library of state-spacetools.
Partial Fraction Expansion (Residue Form)
Each transfer function alsohas a correspondingpartial fraction expansion or
residueformrepresentation, given by
provided H(z) has norepeated poles. Here, n is thedegreeof thedenominator
polynomial of therational transfer functionb(z)/a(z). I f r isapoleof multiplicity
s
r
, then H(z) has terms of theform
Ther esi duez function in theSignal ProcessingToolbox converts transfer
functions toandfromthepartial fraction expansion form. Thezon theendof
r esi duez stands for z-domain, or discretedomain. r esi duez returns thepoles
in a column vector p, theresidues correspondingtothepoles in a column
vector r , and any improper part of theoriginal transfer function in a row
vector k. r esi duez determines that twopoles arethesameif themagnitudeof
their differenceis smaller than 0.1 percent of either of thepoles magnitudes.
Partial fraction expansion arises in signal processingas onemethodof finding
theinversez-transformof atransfer function. For example, thepartial fraction
expansion of
is
b = [ - 4 8] ;
a = [ 1 6 8] ;
[ r , p, k] = r esi duez( b, a)
b z ( )
a z ( )
----------
r 1 ( )
1 p 1 ( )z
1

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

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

---------------------------
r j 1 + ( )
1 p j ( )z
1
( )
2
----------------------------------- L
r j s
r
1 + ( )
1 p j ( )z
1
( )
s
r
------------------------------------ + + +
H z ( )
4 8z
1
+
1 6z
1
8z
2
+ +
---------------------------------------- =
Linear SystemModels
1-37
r =
- 12
8
p =
- 4
- 2
k =
[ ]
which corresponds to
Tofindtheinversez-transformof H(z), findthesumof theinversez-transforms
of thetwoaddends of H(z), givingthecausal impulseresponse
Toverify this in MATLAB, type
i mp = [ 1 0 0 0 0] ;
r espt f = f i l t er ( b, a, i mp)
r espt f =
- 4 32 - 160 704 - 2944
r espr es = f i l t er ( r ( 1) , [ 1 - p( 1) ] , i mp) + f i l t er ( r ( 2) , [ 1 - p( 2) ] , i mp)
r espr es =
- 4 32 - 160 704 - 2944
H z ( )
12
1 4z
1
+
---------------------
8
1 2z
1
+
--------------------- + =
h n ( ) 12 4 ( )
n
8 2 ( )
n
+ n 0 1 2 , , , = , =
1 Signal Processing Basics
1-38
Second-Order Sections (SOS)
Any transfer function H(z) has a second-order sections representation
whereL is thenumber of second-order sections that describethesystem.
MATLAB representsthesecond-order sectionformof adiscrete-timesystemas
an L-by-6 array sos. Each rowof sos contains a singlesecond-order section,
wheretherowelements arethethreenumerator and threedenominator
coefficients that describethesecond-order section.
Therearean uncountablenumber of ways torepresent a filter in second-order
section form. Through careful pairingof thepoleandzeropairs, orderingof the
sections in thecascade, andmultiplicativescalingof thesections, it is possible
toreducequantization noisegain and avoid overflowin somefixed-point filter
implementations. Thefunctions zp2sos and ss2sos, described in Linear
SystemTransformations on page1-43, performpole-zeropairing, section
scaling, and section ordering.
Note I n theSignal ProcessingToolbox, all second-order section
transformations apply only todigital filters.
Lattice Structure
For a discreteNth order all-poleor all-zerofilter described by thepolynomial
coefficients a(n), n =1, 2, , N+1, thereareN correspondinglatticestructure
coefficients k(n), n =1, 2, , N. Theparameters k(n) arealsocalled the
reflection coefficients of thefilter. Given thesereflection coefficients, you can
implement a discretefilter as shown below.
H z ( ) H
k
z ( )
k 1 =
L

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

= =
sos
b
01
b
11
b
21
a
01
a
11
a
21
b
02
b
12
b
22
a
02
a
12
a
22
M M M M M M
b
0L
b
1L
b
2L
a
0L
a
1L
a
2L
=
Linear SystemModels
1-39
For a general pole-zeroI I R filter described by polynomial coefficients a and b,
thereareboth latticecoefficients k(n) for thedenominator a and ladder
coefficients v(n) for thenumerator b. Thelattice/ladder filter may be
implemented as
Thetoolbox function t f 2l at c accepts an FI R or I I R filter in polynomial form
and returns thecorrespondingreflection coefficients. An exampleFI R filter in
polynomial formis
b = [ 1. 0000 0. 6149 0. 9899 0. 0000 0. 0031 - 0. 0082] ;

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

k(n)
k(n)
. . .
. . .
z
-1
FI R Lattice Filter
x(m)
x(m)

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

k(n)
k(n)
. . .
. . .
z
-1
z
-1
I I R Lattice Filter
Minimum-phaseoutput
All-poleoutput
Maximum-phaseoutput
Allpass output
z
-1
+
+
x(m)
g(m)
+
k(N)
k(N)
z
-1
+
+
k(2)
k(2)
z
-1
+
+
k(1)
k(1)
+ + +
v(N+1) v(N) v(3) v(2) v(1)
f(m)
ARMAoutput
1 Signal Processing Basics
1-40
This filters lattice(reflection coefficient) representation is
k = t f 2l at c( b)
k =
0. 3090
0. 9801
0. 0031
0. 0081
- 0. 0082
For I I R filters, themagnitudeof thereflection coefficients provides an easy
stability check. I f all thereflection coefficients correspondingtoa polynomial
havemagnitudeless than 1, all of that polynomials roots areinsidetheunit
circle. For example, consider an I I R filter with numerator polynomial b from
aboveand denominator polynomial
a = [ 1 1/ 2 1/ 3] ;
Thefilters latticerepresentation is
[ k, v] = t f 2l at c( b, a)
k =
0. 3750
0. 3333
0
0
0
v =
0. 6252
0. 1212
0. 9879
- 0. 0009
0. 0072
- 0. 0082
Becauseabs( k) <1 for all reflection coefficients in k, thefilter is stable.
Linear SystemModels
1-41
Thefunction l at c2t f calculates thepolynomial coefficients for afilter fromits
lattice(reflection) coefficients. Given thereflection coefficient vector k( above),
thecorrespondingpolynomial formis
b = l at c2t f ( k)
b =
1. 0000 0. 6149 0. 9899 - 0. 0000 0. 0031 - 0. 0082
Thelatticeor lattice/ladder coefficients can beused toimplement thefilter
usingthefunction l at cf i l t .
Convolution Matrix
I n signal processing, convolvingtwovectors or matrices is equivalent to
filteringoneof theinput operands by theother. This relationship permits the
representation of a digital filter as a convolution matrix.
Givenanyvector, thetoolboxfunction convmt x generatesamatrixwhoseinner
product with another vector is equivalent totheconvolution of thetwovectors.
Thegenerated matrix represents a digital filter that you can apply toany
vector of appropriatelength; theinner dimension of theoperands must agree
tocomputetheinner product.
Theconvolution matrix for a vector b, representingthenumerator coefficients
for a digital filter, is
b = [ 1 2 3] ; x = r andn( 3, 1) ;
C = convmt x( b' , 3)
C =
1 0 0
2 1 0
3 2 1
0 3 2
0 0 3
Twoequivalent ways toconvolveb with x areas follows.
y1 = C*x;
y2 = conv( b, x) ;
1 Signal Processing Basics
1-42
Continuous-Time System Models
Thecontinuous-timesystemmodels arerepresentational schemes for analog
filters. Many of thediscrete-timesystemmodels described earlier arealso
appropriatefor therepresentation of continuous-timesystems:
State-spaceform
Partial fraction expansion
Transfer function
Zero-pole-gain form
I t is possibletorepresent any systemof linear time-invariant differential
equations as a set of first-order differential equations. I n matrix or state-space
form, you can express theequations as
whereuisavector of nuinputs, xisannx-element statevector, andyisavector
of ny outputs. I n MATLAB, storeA, B, C, and Din separaterectangular arrays.
An equivalent representation of thestate-spacesystemis theLaplace
transformtransfer function description
where
For single-input, single-output systems, this formis given by
Given thecoefficients of a Laplacetransformtransfer function, r esi due
determines thepartial fraction expansion of thesystem. Seethedescription of
r esi due in theMATLAB documentation for details.
Thefactored zero-pole-gain formis
x

Ax Bu + =
y Cx Du + =
Y s ( ) H s ( )U s ( ) =
H s ( ) C sI A ( )
1
B D + =
H s ( )
b s ( )
a s ( )
----------
b 1 ( )s
nb
b 2 ( )s
nb 1
b nb 1 + ( ) + + +
a 1 ( )s
na
a 2 ( )s
na 1
a na 1 + ( ) + + +
------------------------------------------------------------------------------------------------- = =
H s ( )
z s ( )
p s ( )
---------- k
s z 1 ( ) ( ) s z 2 ( ) ( ) s z n ( ) ( )
s p 1 ( ) ( ) s p 2 ( ) ( ) s p n ( ) ( )
-------------------------------------------------------------------------------- = =
Linear SystemModels
1-43
As in thediscrete-timecase, MATLAB stores polynomial coefficients in row
vectors in descendingpowers of s. MATLAB stores polynomial roots, or zeros
and poles, in column vectors.
Linear System Transformations
TheSignal ProcessingToolbox provides a number of functions that convert
between thevarious linear systemmodels; seeChapter 7, Function
Reference,for a completedescription of each. You can usethefollowingchart
tofind an appropriatetransfer function: find therowof themodel toconvert
fromon theleft sideof thechart and thecolumn of themodel toconvert toon
thetopof thechart andreadthefunction name(s) at theintersection of therow
and column.
Many of thetoolbox filter design functions usethesefunctions internally. For
example, thezp2ss function converts thepoles and zeros of an analog
prototypeintothestate-spaceformrequired for creation of a Butterworth,
Chebyshev, or ellipticfilter. Oncein state-spaceform, thefilter design function
performs any required frequency transformation, that is, it transforms the
initial lowpass design intoa bandpass, highpass, or bandstop filter, or a
lowpass filter with thedesired cutoff frequency. Seethedescriptions of the
Transfer
function
State-
space
Zero-
pole-
gain
Partial
fraction
Lattice
filter
Second-
order
sections
Convolution
matrix
Transfer
function
t f 2ss t f 2zp
r oot s
r esi duez
r esi due
t f 2l at c convmt x
State-space ss2t f ss2zp ss2sos
Zero-pole-
gain
zp2t f
pol y
zp2ss zp2sos
Partial
fraction
r esi duez
r esi due
Lattice filter l at c2t f
SOS sos2t f sos2ss sos2zp
Convolution
matrix
1 Signal Processing Basics
1-44
individual filter design functions in Chapter 7, Function Reference,for more
details.
Note I n theSignal ProcessingToolbox, all second-order section
transformations apply only todigital filters.
Discrete Fourier Transform
1-45
Discrete Fourier Transform
ThediscreteFourier transform, or DFT, is theprimary tool of digital signal
processing. Thefoundation of theSignal ProcessingToolbox is thefast Fourier
transform(FFT), a method for computingtheDFT with reduced execution
time. Many of thetoolbox functions (including z-domain frequency response,
spectrumand cepstrumanalysis, and somefilter design and implementation
functions) incorporatetheFFT.
MATLAB provides thefunctions f f t andi f f t tocomputethediscreteFourier
transformand its inverse, respectively. For theinput sequencex and its
transformed version X (thediscrete-timeFourier transformat equally spaced
frequencies around theunit circle), thetwofunctions implement the
relationships
I n theseequations, theseries subscripts begin with 1 instead of 0 becauseof
MATLABs vector indexingscheme, and
Note MATLAB uses a negativej for thef f t function. This is an engineering
convention; physics and puremathematics typically usea positive j.
f f t , with a singleinput argument x, computes theDFT of theinput vector or
matrix. I f x isavector, f f t computes theDFT of thevector; if x is arectangular
array, f f t computes theDFT of each array column.
X k 1 + ( ) x n 1 + ( )W
n
kn
n 0 =
N 1

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

=
W
N
e
j
2
N
-------


=
1 Signal Processing Basics
1-46
For example, createa timevector and signal.
t = ( 0: 1/ 99: 1) ; %Ti me vect or
x = si n( 2*pi *15*t ) + si n( 2*pi *40*t ) ; %Si gnal
TheDFT of thesignal, and themagnitudeand phaseof thetransformed
sequence, arethen
y = f f t ( x) ; %Comput e DFT of x
m= abs( y) ; p = unwr ap( angl e( y) ) ; %Magni t ude and phase
Toplot themagnitudeand phase, typethefollowingcommands.
f = ( 0: l engt h( y) - 1) *99/ l engt h( y) ; %Fr equency vect or
pl ot ( f , m) ; t i t l e( ' Magni t ude' ) ;
set ( gca, ' XTi ck' , [ 15 40 60 85] ) ;
f i gur e; pl ot ( f , p*180/ pi ) ; t i t l e( ' Phase' ) ;
set ( gca, ' XTi ck' , [ 15 40 60 85] ) ;
A second argument tof f t specifies a number of points n for thetransform,
representingDFT length.
y = f f t ( x, n) ;
I n this case, f f t pads theinput sequencewith zeros if it is shorter than n, or
truncates thesequenceif it is longer than n. I f n is not specified, it defaults to
thelength of theinput sequence. Execution timefor f f t depends on the
length, n, of theDFT it performs; seethef f t referencepagein theMATLAB
documentation for details about thealgorithm.
15 40 60 85
0
5
10
15
20
25
30
35
40
45
50
Magnitude
15 40 60 85
1200
1000
800
600
400
200
0
Phase
Discrete Fourier Transform
1-47
TheinversediscreteFourier transformfunction i f f t alsoaccepts an input
sequenceand, optionally, thenumber of desired points for thetransform. Try
theexamplebelow; theoriginal sequencex andthereconstructedsequenceare
identical (within roundingerror).
t = ( 0: 1/ 255: 1) ;
x = si n( 2*pi *120*t ) ;
y = r eal ( i f f t ( f f t ( x) ) ) ;
This toolbox alsoincludes functions for thetwo-dimensional FFT and its
inverse, f f t 2 andi f f t 2. Thesefunctions areuseful for two-dimensional signal
or imageprocessing; seethedescriptions in Chapter 7, Function Reference,
for details.
I t is sometimes convenient torearrangetheoutput of thef f t or f f t 2 function
sothezerofrequencycomponent isat thecenter of thesequence. TheMATLAB
functionf f t shi f t movesthezerofrequencycomponent tothecenter of avector
or matrix.
1 Signal Processing Basics
1-48
Selected Bibliography
Algorithmdevelopment for theSignal ProcessingToolbox has drawn heavily
upon thereferences listedbelow. All arerecommendedtotheinterestedreader
whoneeds toknowmoreabout signal processingthan is covered in this
manual.
[1] Crochiere, R.E., and L.R. Rabiner. Multi-RateSignal Processing.
Englewood Cliffs, NJ : PrenticeHall, 1983. Pgs. 88-91.
[2] I EEE. Programsfor Digital Signal Processing. I EEE Press. NewYork: J ohn
Wiley & Sons, 1979.
[3] J ackson, L.B. Digital Filters and Signal Processing. Third Ed. Boston:
Kluwer Academic Publishers, 1989.
[4] Kay, S.M. ModernSpectral Estimation. EnglewoodCliffs, NJ : PrenticeHall,
1988.
[5] Oppenheim, A.V., and R.W. Schafer. Discrete-TimeSignal Processing.
Englewood Cliffs, NJ : PrenticeHall, 1989.
[6] Parks, T.W., and C.S. Burrus. Digital Filter Design. NewYork: J ohn Wiley
& Sons, 1987.
[7] Pratt,W.K. Digital I mageProcessing. NewYork: J ohn Wiley & Sons, 1991.
[8] Percival, D.B., and A.T. Walden. Spectral Analysis for Physical
Applications: Multitaper andConventional UnivariateTechniques. Cambridge:
CambridgeUniversity Press, 1993.
[9] Proakis, J .G., and D.G. Manolakis. Digital Signal Processing: Principles,
Algorithms, and Applications. Upper SaddleRiver, NJ : PrenticeHall, 1996.
[10] Rabiner, L.R., and B. Gold. Theory and Application of Digital Signal
Processing. Englewood Cliffs, NJ : PrenticeHall, 1975.
[11] Welch, P.D. TheUseof Fast Fourier Transformfor theEstimation of
Power Spectra: A Method Based on TimeAveragingOver Short, Modified
Periodograms. I EEE Trans. AudioElectroacoust. Vol. AU-15 (J une1967).
Pgs. 70-73.
2
Filter Design
Filter Requirements and Specification . . . . . . . . 2-2
IIR Filter Design . . . . . . . . . . . . . . . . . . 2-4
Classical I I R Filter Design UsingAnalogPrototyping . . . . 2-6
Comparison of Classical I I R Filter Types . . . . . . . . . 2-8
FIR Filter Design . . . . . . . . . . . . . . . . . . 2-16
Linear PhaseFilters . . . . . . . . . . . . . . . . . 2-17
WindowingMethod . . . . . . . . . . . . . . . . . . 2-18
Multiband FI R Filter Design with Transition Bands . . . . 2-22
Constrained Least Squares FI R Filter Design . . . . . . . 2-27
Arbitrary-ResponseFilter Design . . . . . . . . . . . . 2-31
Special Topics in IIR Filter Design . . . . . . . . . . 2-37
AnalogPrototypeDesign . . . . . . . . . . . . . . . 2-38
Frequency Transformation . . . . . . . . . . . . . . . 2-38
Filter Discretization . . . . . . . . . . . . . . . . . 2-41
Selected Bibliography . . . . . . . . . . . . . . . 2-45
2 Filter Design
2-2
Overview
TheSignal ProcessingToolbox provides functions that support arangeof filter
design methodologies. Thefollowingsections explain howtoapply thefilter
design tools toI nfiniteI mpulseResponse(I I R) and FiniteI mpulseResponse
(FI R) filter design problems:
Filter Requirements and Specification
I I R Filter Design
FI R Filter Design
Special Topics in I I R Filter Design
Selected Bibliography
Filter Requirements and Specification
2-3
Filter Requirements and Specification
Thegoal of filter design is toperformfrequency dependent alteration of a data
sequence. A possiblerequirement might betoremovenoiseabove30 Hz from
adatasequencesampledat 100Hz. A morerigorousspecificationmight call for
a specific amount of passband ripple, stopband attenuation, or transition
width. A very precisespecification could ask toachievetheperformancegoals
with theminimumfilter order, or it could call for an arbitrary magnitude
shape, or it might requirean FI R filter.
Filter design methods differ primarily in howperformanceis specified. For
loosely specified requirements, as in thefirst caseabove, a Butterworth I I R
filter is often sufficient. Todesign a fifth-order 30 Hz lowpass Butterworth
filter and apply it tothedata in vector x,
[ b, a] = but t er ( 5, 30/ 50) ;
y = f i l t er ( b, a, x) ;
Thesecond input argument tobut t er specifies thecutoff frequency,
normalized tohalf thesamplingfrequency (theNyquist frequency).
Frequency Normalization in the Signal Processing Toolbox All of the
filter design functions operatewith normalized frequencies, sothey donot
requirethesystemsamplingrateas an extra input argument. This toolbox
uses theconvention that unit frequency is theNyquist frequency, defined as
half thesamplingfrequency. Thenormalizedfrequency, therefore, is always in
theinterval 0 f 1. For asystemwith a1000 Hz samplingfrequency, 300 Hz
is 300/500 =0.6. Toconvert normalized frequency toangular frequency
around theunit circle, multiply by . Toconvert normalized frequency back to
hertz, multiply by half thesamplefrequency.
Morerigorous filter requirements traditionally includepassbandripple(Rp, in
decibels), stopband attenuation (Rs, in decibels), and transition width (Ws- Wp,
in hertz).
2 Filter Design
2-4
You can design Butterworth, Chebyshev typeI , Chebyshev typeI I , andelliptic
filters that meet this typeof performancespecification. Thetoolbox order
selection functions estimatetheminimumfilter order that meets agiven set of
requirements.
Tomeet specifications with morerigid constraints likelinear phaseor
arbitrary filter shape, usetheFI R and direct I I R filter design routines.
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-5
IIR Filter Design
Theprimaryadvantageof I I R filtersover FI R filters isthat theytypicallymeet
agivenset of specificationswithamuchlower filter order thanacorresponding
FI R filter. Although I I R filters havenonlinear phase, data processingwithin
MATLAB is commonly performedoff-line,that is, theentiredatasequenceis
availableprior tofiltering. This allows for a noncausal, zero-phasefiltering
approach (via thef i l t f i l t function), which eliminates thenonlinear phase
distortion of an I I R filter.
Theclassical I I R filters, Butterworth, Chebyshev types I and I I , elliptic, and
Bessel, all approximatetheideal brick wallfilter in different ways. This
toolboxprovidesfunctionstocreateall thesetypesof classical I I R filtersinboth
theanalogand digital domains (except Bessel, for which only theanalogcase
is supported), and in lowpass, highpass, bandpass, and bandstop
configurations. For most filter types, you can alsofind thelowest filter order
that fits a given filter specification in terms of passband and stopband
attenuation, and transition width(s).
Thedirect filter design function yul ewal k finds a filter with magnitude
responseapproximatinga desired function. This is oneway tocreatea
multiband bandpass filter.
You can alsousetheparametricmodelingor systemidentification functions to
design I I R filters. Thesefunctions arediscussed in Parametric Modelingon
page4-11.
Thegeneralized Butterworth design function maxf l at is discussed in the
section Generalized Butterworth Filter Designon page2-14.
Thefollowingtablesummarizes thevarious filter methods in thetoolbox and
lists thefunctions availabletoimplement thesemethods.
2 Filter Design
2-6
Method Description Functions
Analog
Prototyping
Usingthepoles andzeros of
a classical lowpass
prototypefilter in the
continuous (Laplace)
domain, obtain a digital
filter through frequency
transformation and filter
discretization.
Completedesign functions:
bessel f , but t er , cheby1, cheby2, el l i p
Order estimation functions:
but t or d, cheb1or d, cheb2or d, el l i por d
Lowpass analogprototypefunctions:
bessel ap, but t ap, cheb1ap, cheb2ap,
el l i pap
Frequency transformation functions:
l p2bp, l p2bs, l p2hp, l p2l p
Filter discretization functions:
bi l i near , i mpi nvar
Direct Design Design digital filter directly
in thediscretetime-domain
by approximatinga
piecewiselinear magnitude
response.
yul ewal k
Generalized
Butterworth
Design
Design lowpass
Butterworth filters with
morezeros than poles.
maxf l at
Parametric
Modeling
Find a digital filter that
approximates a prescribed
timeor frequency domain
response. (SeetheSystem
I dentificationToolboxfor an
extensivecollection of
parametric modelingtools.)
Time-domain modelingfunctions:
l pc, pr ony, st mcb
Frequency-domain modelingfunctions:
i nvf r eqs, i nvf r eqz
IIR Filter Design
2-7
Classical IIR Filter Design Using Analog Prototyping
Theprincipal I I R digital filter design techniquethis toolbox provides is based
ontheconversionof classical lowpassanalogfilterstotheir digital equivalents.
Thefollowingsections describehowtodesign filters and summarizethe
characteristics of thesupported filter types. SeeSpecial Topics in I I R Filter
Design on page2-38 for detailed steps on thefilter design process.
Complete Classical IIR Filter Design
You can easily createa filter of any order with a lowpass, highpass, bandpass,
or bandstop configuration usingthefilter design functions.
By default, each of thesefunctions returns a lowpass filter; you need only
specify thedesired cutoff frequency Wn in normalized frequency (Nyquist
frequency =1 Hz). For a highpass filter, append thestring' hi gh' tothe
functions parameter list. For a bandpass or bandstop filter, specify Wn as a
two-element vector containingthepassband edgefrequencies, appendingthe
string' st op' for thebandstop configuration.
Filter Type Design Function
Bessel (analogonly) [ b, a] = bessel f ( n, Wn, opt i ons)
[ z, p, k] = bessel f ( n, Wn, opt i ons)
[ A, B, C, D] = bessel f ( n, Wn, opt i ons)
Butterworth [ b, a] = but t er ( n, Wn, opt i ons)
[ z, p, k] = but t er ( n, Wn, opt i ons)
[ A, B, C, D] = but t er ( n, Wn, opt i ons)
Chebyshev typeI [ b, a] = cheby1( n, Rp, Wn, opt i ons)
[ z, p, k] = cheby1( n, Rp, Wn, opt i ons)
[ A, B, C, D] = cheby1( n, Rp, Wn, opt i ons)
Chebyshev typeI I [ b, a] = cheby2( n, Rs, Wn, opt i ons)
[ z, p, k] = cheby2( n, Rs, Wn, opt i ons)
[ A, B, C, D] = cheby2( n, Rs, Wn, opt i ons)
Elliptic [ b, a] = el l i p( n, Rp, Rs, Wn, opt i ons)
[ z, p, k] = el l i p( n, Rp, Rs, Wn, opt i ons)
[ A, B, C, D] = el l i p( n, Rp, Rs, Wn, opt i ons)
2 Filter Design
2-8
Herearesomeexampledigital filters.
[ b, a] = but t er ( 5, 0. 4) ; %Lowpass But t er wor t h
[ b, a] = cheby1( 4, 1, [ 0. 4 0. 7] ) ; %Bandpass Chebyshev t ype I
[ b, a] = cheby2( 6, 60, 0. 8, ' hi gh' ) ; %Hi ghpass Chebyshev t ype I I
[ b, a] = el l i p( 3, 1, 60, [ 0. 4 0. 7] , ' st op' ) ; %Bandst op el l i pt i c
Todesign an analogfilter, perhaps for simulation, usea trailing' s' and
specify cutoff frequencies in rad/s.
[ b, a] = but t er ( 5, . 4, ' s' ) ; %Anal og But t er wor t h f i l t er
All filter design functions return a filter in thetransfer function,
zero-pole-gain, or state-spacelinear systemmodel representation, depending
on howmany output arguments arepresent.
Note All classical I I R lowpass filters areill-conditioned for extremely low
cut-off frequencies. Therefore, instead of designinga lowpass I I R filter with a
very narrowpassband, it can bebetter todesign a wider passband and
decimatetheinput signal.
Designing IIR Filters to Frequency Domain Specifications
This toolbox provides order selection functions that calculatetheminimum
filter order that meets a given set of requirements.
Theseareuseful in conjunction with thefilter design functions. Supposeyou
want a bandpass filter with a passband from1000 to2000 Hz, stopbands
starting500Hzawayoneither side, a10kHzsamplingfrequency, at most 1 dB
Filter Type Order Estimation Function
Butterworth [ n, Wn] = but t or d( Wp, Ws, Rp, Rs)
Chebyshev typeI [ n, Wn] = cheb1or d( Wp, Ws, Rp, Rs)
Chebyshev typeI I [ n, Wn] = cheb2or d( Wp, Ws, Rp, Rs)
Elliptic [ n, Wn] = el l i por d( Wp, Ws, Rp, Rs)
IIR Filter Design
2-9
of passband ripple, and at least 60 dB of stopband attenuation. You can meet
thesespecifications by usingthebut t er function as follows.
[ n, Wn] = but t or d( [ 1000 2000] / 5000, [ 500 2500] / 5000, 1, 60)
n =
12
Wn =
0. 1951 0. 4080
[ b, a] = but t er ( n, Wn) ;
An elliptic filter that meets thesamerequirements is given by
[ n, Wn] = el l i por d( [ 1000 2000] / 5000, [ 500 2500] / 5000, 1, 60)
n =
5
Wn =
0. 2000 0. 4000
[ b, a] = el l i p( n, 1, 60, Wn) ;
Thesefunctionsalsowork withtheother standardbandconfigurations, aswell
as for analogfilters; seeChapter 7, Function Reference, for details.
Comparison of Classical IIR Filter Types
Thetoolbox provides fivedifferent types of classical I I R filters, each optimal in
someway. This section shows thebasic analogprototypeformfor each and
summarizes major characteristics.
Butterworth Filter
TheButterworth filter provides thebest Taylor Series approximation tothe
ideal lowpass filter responseat analogfrequencies and ; for any
order N, themagnitudesquared responsehas 2N-1 zeroderivatives at these
locations(maximallyflat at and ). Responseismonotonicoverall,
decreasingsmoothly from to . at .
0 = =
0 = =
0 = = H j ( ) 1 2 = 1 =
2 Filter Design
2-10
Chebyshev Type I Filter
TheChebyshev typeI filter minimizes theabsolutedifferencebetween the
ideal andactual frequency responseover theentirepassbandby incorporating
an equal rippleof Rp dB in thepassband. Stopbandresponseis maximallyflat.
Thetransition frompassband tostopband is morerapid than for the
Butterworth filter. at .
10
-1
10
0
10
1
0
0.2
0.4
0.6
0.8
1
Frequency(rad/sec)
M
a
g
n
i
t
u
d
e
H j ( ) 10
Rp 20
= 1 =
10
-1
10
0
10
1
0
0.2
0.4
0.6
0.8
1
Frequency(rad/sec)
M
a
g
n
i
t
u
d
e
IIR Filter Design
2-11
Chebyshev Type II Filter
TheChebyshev typeI I filter minimizes theabsolutedifferencebetween the
ideal and actual frequency responseover theentirestopband by incorporating
an equal rippleof Rs dB in thestopband. Passband responseis maximally flat.
Thestopband does not approach zeroas quickly as thetypeI filter (and does
not approach zeroat all for even-valuedfilter order n). Theabsenceof ripplein
thepassband, however, is often an important advantage.
at .
Elliptic Filter
Elliptic filters areequiripplein both thepassband and stopband. They
generallymeet filter requirementswiththelowest order of anysupportedfilter
type. Givenafilter order n, passbandrippleRpindecibels, andstopbandripple
Rsindecibels, ellipticfiltersminimizetransitionwidth. at
.
H j ( ) 10
Rs 20
=
1 =
10
-1
10
0
10
1
0
0.2
0.4
0.6
0.8
1
Frequency(rad/sec)
M
a
g
n
i
t
u
d
e
H j ( ) 10
Rp 20
=
1 =
2 Filter Design
2-12
Bessel Filter
AnalogBessel lowpass filters havemaximally flat group delay at zero
frequency and retain nearly constant group delay across theentirepassband.
Filtered signals thereforemaintain their waveshapes in thepassband
frequency range. Frequency mappedanddigital Bessel filters, however, donot
havethis maximally flat property; this toolbox supports only theanalogcase
for thecompleteBessel filter design function.
Bessel filters generally requirea higher filter order than other filters for
satisfactory stopbandattenuation. at anddecreases as
filter order n increases.
10
-1
10
0
10
1
0
0.2
0.4
0.6
0.8
1
Frequency(rad/sec)
M
a
g
n
i
t
u
d
e
H j ( ) 1 2 < 1 =
IIR Filter Design
2-13
Note Thelowpass filters shown abovewerecreated with theanalog
prototypefunctions bessel ap, but t ap, cheb1ap, cheb2ap, and el l i pap. These
functions find thezeros, poles, and gain of an order n analogfilter of the
appropriatetypewith cutoff frequency of 1 rad/s. Thecompletefilter design
functions (bessel f , but t er, cheby1, cheby2, and el l i p) call theprototyping
functions as a first step in thedesign process. SeeSpecial Topics in I I R Filter
Design on page2-37 for details.
Tocreatesimilar plots, usen =5 and, as needed, Rp =0. 5 and Rs =20. For
example, tocreatetheelliptic filter plot:
[ z, p, k] = el l i pap( 5, 0. 5, 20) ;
w = l ogspace( - 1, 1, 1000) ;
h = f r eqs( k*pol y( z) , pol y( p) , w) ;
semi l ogx( w, abs( h) ) , gr i d
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-14
Direct IIR Filter Design
This toolboxuses thetermdirect methods todescribetechniques for I I R design
that find a filter based on specifications in thediscretedomain. Unlikethe
analogprototypingmethod, direct design methods arenot constrained tothe
standard lowpass, highpass, bandpass, or bandstop configurations. Rather,
thesefunctions design filters with an arbitrary, perhaps multiband, frequency
response. This section discusses theyul ewal k function, which is intended
specifically for filter design; Parametric Modeling on page4-11 discusses
other methods that may alsobeconsidered direct, such as Pronys method,
Linear Prediction, theSteiglitz-McBridemethod, and inversefrequency
design.
Theyul ewal k function designsrecursiveI I R digital filtersbyfittingaspecified
frequency response. yul ewal ks namereflects its methodfor findingthefilters
denominator coefficients: it finds theinverseFFT of theideal desired power
spectrumandsolves themodifiedYule-Walker equationsusingtheresulting
autocorrelation function samples. Thestatement
[ b, a] = yul ewal k( n, f , m)
returns rowvectors b and a containingthen+1 numerator and denominator
coefficients of theorder n I I R filter whosefrequency-magnitudecharacteristics
approximatethosegiven in vectors f and m. f is a vector of frequency points
rangingfrom0 to1, where1 represents theNyquist frequency. mis a vector
containingthedesired magnituderesponseat thepoints in f . f and mcan
describeany piecewiselinear shapemagnituderesponse, includinga
multiband response. TheFI R counterpart of this function is f i r 2, which also
designsafilter basedonanarbitrarypiecewiselinear magnituderesponse. See
FI R Filter Designon page2-16 for details.
Notethat yul ewal k does not accept phaseinformation, and nostatements are
madeabout theoptimality of theresultingfilter.
Design a multiband filter with yul ewal k, and plot thedesired and actual
frequency response.
m= [ 0 0 1 1 0 0 1 1 0 0] ;
f = [ 0 0. 1 0. 2 0. 3 0. 4 0. 5 0. 6 0. 7 0. 8 1] ;
[ b, a] = yul ewal k( 10, f , m) ;
[ h, w] = f r eqz( b, a, 128) ;
pl ot ( f , m, w/ pi , abs( h) )
IIR Filter Design
2-15
Generalized Butterworth Filter Design
Thetoolbox function maxf l at enables you todesign generalized Butterworth
filters, that is, Butterworth filters with differingnumbers of zeros and poles.
This is desirablein someimplementations wherepoles aremoreexpensive
computationally than zeros. maxf l at is just likethebut t er function, except
that it you can specify two orders (onefor thenumerator and onefor the
denominator) instead of just one. Thesefilters aremaximallyflat. This means
that theresultingfilter is optimal for any numerator and denominator orders,
withthemaximumnumber of derivativesat 0andtheNyquist frequency =
both set to0.
For example, when thetwoordersarethesame, maxf l at isthesameas but t er .
[ b, a] = maxf l at ( 3, 3, 0. 25)
b =
0. 0317 0. 0951 0. 0951 0. 0317
a =
1. 0000 - 1. 4590 0. 9104 - 0. 1978
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
0
0.2
0.4
0.6
0.8
1
1.2
2 Filter Design
2-16
[ b, a] = but t er ( 3, 0. 25)
b =
0. 0317 0. 0951 0. 0951 0. 0317
a =
1. 0000 - 1. 4590 0. 9104 - 0. 1978
However, maxf l at ismoreversatilebecauseit allowsyou todesign afilter with
morezeros than poles.
[ b, a] = maxf l at ( 3, 1, 0. 25)
b =
0. 0950 0. 2849 0. 2849 0. 0950
a =
1. 0000 - 0. 2402
Thethird input tomaxflat is thehalf-power frequency, a frequency between
0 and 1 with a desired magnituderesponseof .
You can alsodesign linear phasefilters that havethemaximally flat property
usingthe' sym' option.
maxf l at ( 4, ' sym' , 0. 3)
ans =
0. 0331 0. 2500 0. 4337 0. 2500 0. 0331
For completedetails of themaxf l at algorithm, seeSelesnick and Burrus [2].
1 2
FIR Filter Design
2-17
FIR Filter Design
Digital filters with finite-duration impulseresponse(all-zero, or FI R filters)
haveboth advantages and disadvantages compared toinfinite-duration
impulseresponse(I I R) filters.
FI R filters havethefollowingprimary advantages:
They can haveexactly linear phase.
They arealways stable.
Thedesign methods aregenerally linear.
They can berealized efficiently in hardware.
Thefilter startup transients havefiniteduration.
Theprimary disadvantageof FI R filters is that they often requirea much
higher filter order than I I R filters toachievea given level of performance.
Correspondingly, thedelay of thesefilters is often much greater than for an
equal performanceI I R filter.
Method Description Functions
Windowing Apply windowtotruncated
inverseFourier transformof
desired brick wall filter
f i r 1, f i r 2,
kai ser or d
Multibandwith
Transition
Bands
Equirippleor least squares
approach over sub-bands of the
frequency range
f i r l s, r emez,
r emezor d
Constrained
Least Squares
Minimizesquared integral
error over entirefrequency
rangesubject tomaximum
error constraints
f i r cl s, f i r cl s1
Arbitrary
Response
Arbitrary responses, including
nonlinear phaseand complex
filters
cr emez
Raised Cosine Lowpass responsewith
smooth, sinusoidal transition
f i r r cos
2 Filter Design
2-18
Linear Phase Filters
Except for cr emez, all of theFI R filter design functions design linear phase
filters only. Thefilter coefficients, or taps,of such filters obey either an even
or odd symmetry relation. Dependingon this symmetry, and on whether the
order n of thefilter is even or odd, a linear phasefilter (stored in length n+1
vector b) has certain inherent restrictions on its frequency response.
Thephasedelay and group delay of linear phaseFI R filters areequal and
constant over thefrequency band. For an order n linear phaseFI R filter, the
group delay is n/2, and thefiltered signal is simply delayed by n/2 timesteps
(andthemagnitudeof its Fourier transformis scaledby thefilters magnitude
response). This property preserves thewaveshapeof signals in thepassband;
that is, thereis nophasedistortion.
Thefunctions f i r 1, f i r 2, f i r l s, r emez, f i r cl s, f i r cl s1, and f i r r cos all
design typeI and I I linear phaseFI R filters by default. Both f i r l s and r emez
design typeI I I and I V linear phaseFI R filters given a ' hi l ber t ' or
' di f f er ent i at or ' flag. cr emez can design any typeof linear phasefilter, and
nonlinear phasefilters as well.
Note Becausethefrequency responseof a typeI I filter is zeroat theNyquist
frequency (high frequency), f i r 1 does not design typeI I highpass and
bandstop filters. For odd-valued n in thesecases, f i r 1 adds 1 totheorder and
returns a typeI filter.
Linear Phase
Filter Type
Filter
Order Symmetry of Coefficients
Response H(f),
f = 0
Response H(f),
f = 1 (Nyquist)
TypeI Even even: Norestriction Norestriction
TypeI I Odd Norestriction H(1) = 0
TypeI I I Even odd: H(0) = 0 H(1) = 0
TypeI V Odd H(0) = 0 Norestriction
b k ( ) b n 2 k + ( ) k 1 = n 1 + , , , =
b k ( ) b n 2 k + ( ) k 1 = n 1 + , , , =
FIR Filter Design
2-19
Windowing Method
Consider theideal, or brick wall,digital lowpass filter with acutoff frequency
of
0
rad/s. This filter has magnitude1 at all frequencies with magnitudeless
than
0
, andmagnitude0at frequencies with magnitudebetween
0
and . I ts
impulseresponsesequenceh(n) is
This filter is not implementablesinceits impulseresponseis infiniteand
noncausal. Tocreatea finite-duration impulseresponse, truncateit by
applyingawindow. Byretainingthecentral section of impulseresponsein this
truncation, you obtain alinear phaseFI R filter. For example, alength 51filter
with a lowpass cutoff frequency
0
of rad/s is
b = 0. 4*si nc( 0. 4*( - 25: 25) ) ;
Thewindowapplied hereis a simplerectangular or boxcarwindow. By
Parsevals theorem, this is thelength 51filter that best approximates theideal
lowpass filter, in theintegrated least squares sense. Thefollowingcommands
display thefilters frequency response.
[ H, w] = f r eqz( b, 1, 512, 2) ;
s. xuni t s = ' r ad/ sampl e' ;
s. yuni t s = ' squar ed' ;
s. pl ot = ' mag' ; %Pl ot magni t ude onl y.
f r eqzpl ot ( H, w, s)
t i t l e( ' Tr uncat ed Si nc Lowpass FI R Fi l t er ' ) ;
h n ( )
1
2
------ H ( )e
j n
d

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

------ -sinc

------ -n ( ) = = =
0.4
2 Filter Design
2-20
Notetheringingand ripples in theresponse, especially near theband edge.
This Gibbs effectdoes not vanish as thefilter length increases, but a
nonrectangular windowreduces its magnitude. Multiplication by a windowin
thetimedomain causes a convolution or smoothingin thefrequency domain.
Apply a length 51 Hammingwindowtothefilter.
b = 0. 4*si nc( 0. 4*( - 25: 25) ) ;
b = b. *hammi ng( 51) ' ;
[ H, w] = f r eqz( b, 1, 512, 2) ;
s. xuni t s = ' r ad/ sampl e' ;
s. yuni t s = ' squar ed' ;
s. pl ot = ' mag' ;
f r eqzpl ot ( H, w, s)
t i t l e( ' Hammi ng- Wi ndowed Tr uncat ed Si nc LP FI R Fi l t er ' ) ;
0 0.05 0.1 0.15 0.2 0.25 0.3
0
0.2
0.4
0.6
0.8
1
1.2
1.4
Normalized Frequency ( rad/sample)
M
a
g
n
i
t
u
d
e

s
q
u
a
r
e
d
Truncated Sinc Lowpass FIR Filter
FIR Filter Design
2-21
As you can see, this greatly reduces theringing. This improvement is at the
expenseof transition width (thewindowed version takes longer toramp from
passband tostopband) and optimality (thewindowed version does not
minimizetheintegrated squared error).
Thefunctions f i r 1 and f i r 2 arebased on this windowingprocess. Given a
filter order and description of an ideal desired filter, thesefunctions return a
windowed inverseFourier transformof that ideal filter. Both usea Hamming
windowby default, but they accept any windowfunction. SeeOverview on
page4-2 for an overviewof windows and their properties.
Standard Band FIR Filter Design: fir1
f i r 1 implements theclassical method of windowed linear phaseFI R digital
filter design. I t resemblestheI I R filter design functionsinthat it isformulated
todesignfilters instandardbandconfigurations: lowpass, bandpass, highpass,
and bandstop.
Thestatements
n = 50;
Wn = 0. 4;
b = f i r 1( n, Wn) ;
0 0.05 0.1 0.15 0.2 0.25 0.3
0
0.2
0.4
0.6
0.8
1
1.2
1.4
Normalized Frequency ( rad/sample)
M
a
g
n
i
t
u
d
e

s
q
u
a
r
e
d
HammingWindowed Truncated Sinc LP FIR Filter
2 Filter Design
2-22
createrowvector b containingthecoefficients of theorder n
Hamming-windowedfilter. Thisisalowpass, linear phaseFI R filter withcutoff
frequency Wn. Wn is a number between 0 and 1, where1 corresponds tothe
Nyquist frequency, half thesamplingfrequency. (Unlikeother methods, here
Wn corresponds tothe6 dB point.) For a highpass filter, simply append the
string' hi gh' tothefunctions parameter list. For a bandpass or bandstop
filter, specify Wn as a two-element vector containingthepassband edge
frequencies; append thestring' st op' for thebandstop configuration.
b = f i r 1( n, Wn, wi ndow) usesthewindowspecifiedincolumnvector wi ndowfor
thedesign. Thevector wi ndowmust ben+1 elements long. I f you donot specify
a window, f i r 1 applies a Hammingwindow.
Kaiser Window Order Estimation. Thekai ser or d function estimates thefilter
order, cutoff frequency, and Kaiser windowbeta parameter needed tomeet a
given set of specifications. Given a vector of frequency band edges and a
correspondingvector of magnitudes, as well as maximumallowableripple,
kai ser or d returns appropriateinput parameters for thef i r 1 function.
Multiband FIR Filter Design: fir2
Thef i r 2 function alsodesigns windowed FI R filters, but with an arbitrarily
shaped piecewiselinear frequency response. This is in contrast tof i r 1, which
only designs filters in standard lowpass, highpass, bandpass, and bandstop
configurations.
Thecommands
n = 50;
f = [ 0 . 4 . 5 1] ;
m= [ 1 1 0 0] ;
b = f i r 2( n, f , m) ;
return rowvector b containingthen+1 coefficients of theorder n FI R filter
whosefrequency-magnitudecharacteristics match thosegiven by vectors f
and m. f is a vector of frequency points rangingfrom0to1, where1represents
theNyquist frequency. misavector containingthedesiredmagnituderesponse
at thepoints specified in f . (TheI I R counterpart of this function is yul ewal k,
which alsodesigns filters based on arbitrary piecewiselinear magnitude
responses. SeeI I R Filter Designon page2-5 for details.)
FIR Filter Design
2-23
Multiband FIR Filter Design with Transition Bands
Thef i r l s andr emez functions provideamoregeneral means of specifyingthe
ideal desired filter than thef i r 1 and f i r 2 functions. Thesefunctions design
Hilbert transformers, differentiators, and other filters with odd symmetric
coefficients (typeI I I and typeI V linear phase). They alsolet you include
transition or dont careregions in which theerror is not minimized, and
performband dependent weightingof theminimization.
Thef i r l s function is an extension of thef i r 1 and f i r 2 functions in that it
minimizestheintegral of thesquareof theerror betweenthedesiredfrequency
responseand theactual frequency response.
Ther emez function implements theParks-McClellan algorithm, which uses
theRemez exchangealgorithmandChebyshevapproximation theorytodesign
filters with optimal fits between thedesired and actual frequency responses.
Thefilters areoptimal in thesensethat they minimizethemaximumerror
between thedesired frequency responseand theactual frequency response;
they aresometimes calledminimaxfilters. Filters designedin this way exhibit
an equiripplebehavior in their frequency response, and hencearealsoknown
as equiripplefilters. TheParks-McClellan FI R filter design algorithmis
perhaps themost popular and widely used FI R filter design methodology.
Thesyntax for f i r l s and r emez is thesame; theonly differenceis their
minimization schemes. Thenext exampleshows howfilters designed with
f i r l s and r emez reflect thesedifferent schemes.
Basic Configurations
Thedefault modeof operation of f i r l s and r emez is todesign typeI or typeI I
linear phasefilters, dependingon whether theorder you desireis even or odd,
respectively. A lowpass examplewith approximateamplitude1 from0 to
0.4 Hz, and approximateamplitude0 from0.5 to1.0 Hz is
n = 20; %Fi l t er or der
f = [ 0 0. 4 0. 5 1] ; %Fr equency band edges
a = [ 1 1 0 0] ; %Desi r ed ampl i t udes
b = r emez( n, f , a) ;
From0.4 to0.5 Hz, r emez performs noerror minimization; this is a transition
band or dont careregion. A transition band minimizes theerror morein the
bands that you docareabout, at theexpenseof aslower transition rate. I n this
2 Filter Design
2-24
way, thesetypes of filters havean inherent trade-off similar toFI R design by
windowing.
Tocompareleast squares toequiripplefilter design, use f i r l s tocreatea
similar filter. Type
bb = f i r l s( n, f , a) ;
and comparetheir frequency responses.
[ H, w] = f r eqz( b) ;
[ HH, w] = f r eqz( bb) ;
pl ot ( w/ pi , abs( H) , w/ pi , abs( HH) , ' - - ' ) , gr i d
You can seethat thefilter designed with r emez exhibits equiripplebehavior.
Alsonotethat thef i r l s filter has abetter responseover most of thepassband
and stopband, but at theband edges (f =0. 4 and f =0. 5), theresponseis
further away fromtheideal than ther emez filter. This shows that ther emez
filters maximumerror over thepassbandandstopbandis smaller and, in fact,
it is thesmallest possiblefor this band edgeconfiguration and filter length.
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
0
0.2
0.4
0.6
0.8
1
1.2
1.4
FIR Filter Design
2-25
Think of frequency bands as lines over short frequency intervals. r emez and
f i r l s usethis schemetorepresent any piecewiselinear desired function with
any transition bands. f i r l s and r emez design lowpass, highpass, bandpass,
and bandstop filters; a bandpass exampleis
f = [ 0 0. 3 0. 4 0. 7 0. 8 1] ; %Band edges i n pai r s
a = [ 0 0 1 1 0 0] ; %Bandpass f i l t er ampl i t ude
Technically, thesef and a vectors definefivebands:
Twostopbands, from0.0 to0.3 and from0.8 to1.0
A passband from0.4 to0.7
Twotransition bands, from0.3 to0.4 and from0.7 to0.8
Examplehighpass and bandstop filters are
f = [ 0 0. 7 0. 8 1] ; %Band edges i n pai r s
a = [ 0 0 1 1] ; %Hi ghpass f i l t er ampl i t ude
f = [ 0 0. 3 0. 4 0. 5 0. 8 1] ; %Band edges i n pai r s
a = [ 1 1 0 0 1 1] ; %Bandst op f i l t er ampl i t ude
An examplemultiband bandpass filter 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] ;
Another possibilityisafilter that hasasatransition region thelineconnecting
thepassband with thestopband; this can help control runaway magnitude
responsein widetransition regions.
f = [ 0 0. 4 0. 42 0. 48 0. 5 1] ;
a =[ 1 1 0. 8 0. 2 0 0] ; %Passband, l i near t r ansi t i on, st opband
2 Filter Design
2-26
The Weight Vector
Both f i r l s andr emez allowyou toplacemoreor less emphasis on minimizing
theerror in certain frequency bands relativetoothers. Todothis, specify a
weight vector followingthefrequency and amplitudevectors. An example
lowpass equiripplefilter with 10 times less ripplein thestopband than the
passband is
n = 20; %Fi l t er or der
f = [ 0 0. 4 0. 5 1] ; %Fr equency band edges
a = [ 1 1 0 0] ; %Desi r ed ampl i t udes
w = [ 1 10] ; %Wei ght vect or
b = r emez( n, f , a, w) ;
A legal weight vector isalwayshalf thelengthof thef anda vectors; theremust
beexactly oneweight per band.
Anti-Symmetric Filters / Hilbert Transformers
When called with a trailing' h' or ' Hi l ber t ' option, r emez and f i r l s design
FI R filters with odd symmetry, that is, typeI I I (for even order) or typeI V (for
odd order) linear phasefilters. An ideal Hilbert transformer has this
anti-symmetry property and an amplitudeof 1 across theentirefrequency
range. Try thefollowingapproximateHilbert transformers.
b = r emez( 21, [ 0. 05 1] , [ 1 1] , ' h' ) ; %Hi ghpass Hi l ber t
bb = r emez( 20, [ 0. 05 0. 95] , [ 1 1] , ' h' ) ; %Bandpass Hi l ber t
0 0.25 0.5 0.75 1
0
0.2
0.4
0.6
0.8
1
Frequency (Normalized)

Bandpass Hilbert
0 0.25 0.5 0.75 1
0
0.2
0.4
0.6
0.8
1
Frequency (Normalized)
Highpass Hilbert
FIR Filter Design
2-27
You can find thedelayed Hilbert transformof a signal x by passingit through
thesefilters.
f s = 1000; %Sampl i ng f r equency
t = ( 0: 1/ f s: 2) ' ; %Two second t i me vect or
x = si n( 2*pi *300*t ) ; %300 Hz si ne wave exampl e si gnal
xh = f i l t er ( bb, 1, x) ; %Hi l ber t t r ansf or mof x
Theanalytic signal correspondingtox is thecomplex signal that has x as its
real part and theHilbert transformof x as its imaginary part. For this FI R
method (an alternativetothehi l ber t function), you must delay x by half the
filter order tocreatetheanalytic signal.
xd = [ zer os( 10, 1) ; x( 1: l engt h( x) - 10) ] ; %Del ay 10 sampl es
xa = xd + j *xh; %Anal yt i c si gnal
This method does not work directly for filters of odd order, which requirea
noninteger delay. I n this case, thehi l ber t function, described in Specialized
Transformson page4-35, estimatestheanalyticsignal. Alternatively, usethe
r esampl e function todelay thesignal by a noninteger number of samples.
Differentiators
Differentiation of asignal in thetimedomain is equivalent tomultiplication of
thesignals Fourier transformby an imaginary ramp function. That is, to
differentiatea signal, pass it through a filter that has a responseH() = j.
Approximatetheideal differentiator (with a delay) using r emez or f i r l s with
a ' d' or ' di f f er ent i at or ' option.
b = r emez( 21, [ 0 1] , [ 0 pi *f s] , ' d' ) ;
Toobtain thecorrect derivative, scaleby pi *f s rad/s, wheref s is thesampling
frequency in hertz. For a typeI I I filter, thedifferentiation band should stop
short of theNyquist frequency, and theamplitudevector must reflect that
changetoensurethecorrect slope.
bb = r emez( 20, [ 0 0. 9] , [ 0 0. 9*pi *f s] , ' d' ) ;
I n the' d' mode, r emez weights theerror by 1/ in nonzeroamplitudebands to
minimizethemaximumrelativeerror. f i r l s weights theerror by (1/)
2
in
nonzeroamplitudebands in the' d' mode.
2 Filter Design
2-28
Thefollowingplots showthemagnituderesponsefor thedifferentiators above.
Constrained Least Squares FIR Filter Design
TheConstrainedLeast Squares (CLS) FI R filter design functions implement a
techniquethat enables you todesign FI R filters without explicitly definingthe
transition bands for themagnituderesponse. Theability toomit the
specification of transition bands is useful in several situations. For example, it
may not beclear wherearigidly definedtransition bandshouldappear if noise
andsignal information appear together in thesamefrequencyband. Similarly,
it may makesensetoomit thespecification of transition bands if they appear
only tocontrol theresults of Gibbs phenomena that appear in thefilters
response. SeeSelesnick, Lang, and Burrus [2] for discussion of this method.
I nstead of definingpassbands, stopbands, and transition regions, theCLS
method accepts a cutoff frequency (for thehighpass, lowpass, bandpass, or
bandstopcases), or passbandandstopbandedges (for multibandcases), for the
desired response. I n this way, theCLS method defines transition regions
implicitly, rather than explicitly.
Thekey featureof theCLS method is that it enables you todefineupper and
lower thresholds that contain themaximumallowableripplein themagnitude
response. Given this constraint, thetechniqueapplies theleast squareerror
minimization techniqueover thefrequency rangeof thefilters response,
instead of over specific bands. Theerror minimization includes any areas of
0 100 200 300 400 500
0
500
1000
1500
2000
2500
3000
3500
Differentiator, odd order
Frequency (Normalized)
0 100 200 300 400 500
0
500
1000
1500
2000
2500
3000
3500
Differentiator, even order
Frequency (Normalized)
FIR Filter Design
2-29
discontinuity in theideal, brick wall response. An additional benefit is that
thetechniqueenables you tospecify arbitrarily small peaks resultingfrom
Gibbs phenomena.
Therearetwotoolbox functions that implement this design technique.
For details on thecallingsyntax for thesefunctions, seetheir reference
descriptions in Chapter 7, Function Reference.
Basic Lowpass and Highpass CLS Filter Design
Themost basic of theCLS design functions, f i r cl s1, uses this techniqueto
design lowpass and highpass FI R filters. As an example, consider designinga
filter with order 61impulseresponseand cutoff frequency of 0.3(normalized).
Further, definetheupper and lower bounds that constrain thedesign process
as:
Maximumpassband deviation from1 (passband ripple) of 0.02.
Maximumstopband deviation from0 (stopband ripple) of 0.008.
Toapproach this design problemusingf i r cl s1, usethefollowingcommands.
n = 61;
wo = 0. 3;
dp = 0. 02;
ds = 0. 008;
h = f i r cl s1( n, wo, dp, ds, ' pl ot ' ) ;
Description Function
Constrained least squaremultiband FI R filter design f i r cl s
Constrained least squarefilter design for lowpass and
highpass linear phasefilters
f i r cl s1
0
ds = 0. 008
1
dp = 0. 02
2 Filter Design
2-30
Multiband CLS Filter Design
f i r cl s uses thesametechniquetodesign FI R filters with a desired piecewise
constant magnituderesponse. I n this case, you can specify a vector of band
edges and a correspondingvector of band amplitudes. I n addition, you can
specify themaximumamount of ripplefor each band.
For example, assumethespecifications for a filter call for:
From0 to0.3 (normalized): amplitude0, upper bound 0.005, lower
bound -0.005
From0.3 to0.5: amplitude0.5, upper bound 0.51, lower bound 0.49
From0.5 to0.7: amplitude0, upper bound 0.03, lower bound -0.03
From0.7 to0.9: amplitude1, upper bound 1.02, lower bound 0.98
From0.9 to1: amplitude0, upper bound 0.05, lower bound -0.05
Design a CLS filter with impulseresponseorder 129 that meets these
specifications.
n = 129;
f = [ 0 0. 3 0. 5 0. 7 0. 9 1] ;
a = [ 0 0. 5 0 1 0] ;
up = [ 0. 005 0. 51 0. 03 1. 02 0. 05] ;
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
-0.2
0
0.2
0.4
0.6
0.8
1
FIR Filter Design
2-31
l o = [ - 0. 005 0. 49 - 0. 03 0. 98 - 0. 05] ;
h = f i r cl s( n, f , a, up, l o, ' pl ot ' ) ;
Weighted CLS Filter Design
WeightedCLS filter designletsyoudesignlowpassor highpassFI R filterswith
relativeweightingof theerror minimization in each band. Thef i r cl s1
function enables you tospecify thepassband and stopband edges for theleast
squares weightingfunction, as well as a constant k that specifies theratioof
thestopband topassband weighting.
For example, consider specifications that call for an FI R filter with impulse
responseorder of 55 and cutoff frequency of 0.3 (normalized). Alsoassume
maximumallowablepassbandrippleof 0.02andmaximumallowablestopband
rippleof 0.004. I n addition, add weightingrequirements:
Passband edgefor theweight function of 0.28 (normalized)
Stopband edgefor theweight function of 0.32
Weight error minimization 10 times as much in thestopband as in the
passband
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
-0.2
0
0.2
0.4
0.6
0.8
1
1.2
2 Filter Design
2-32
Toapproach this usingf i r cl s1, type
n = 55;
wo = 0. 3;
dp = 0. 02;
ds = 0. 004;
wp = 0. 28;
ws = 0. 32;
k = 10;
h = f i r cl s1( n, wo, dp, ds, wp, ws, k, ' pl ot ' ) ;
Arbitrary-Response Filter Design
Thecr emez filter design function provides a tool for designingFI R filters with
arbitrary complex responses. I t differs fromtheother filter design functions in
howthefrequency responseof thefilter is specified: it accepts thenameof a
function which returns thefilter responsecalculatedover agridof frequencies.
This capability makes cr emez a highly versatileand powerful techniquefor
filter design.
This design techniquemay beused toproducenonlinear-phaseFI R filters,
asymmetric frequency-responsefilters (with complex coefficients), or more
symmetric filters with customfrequency responses.
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
-0.2
0
0.2
0.4
0.6
0.8
1
FIR Filter Design
2-33
Thedesign algorithmoptimizes theChebyshev (or minimax) error usingan
extended Remez-exchangealgorithmfor an initial estimate. I f this exchange
method fails toobtain theoptimal filter, thealgorithmswitches toan
ascent-descent algorithmthat takes over tofinish theconvergencetothe
optimal solution.
For details on thesyntax for cr emez, seethedescription in Chapter 7,
Function Reference.
Multiband Filter Design
Consider a multiband filter with thefollowingspecial frequency-domain
characteristics.
A linear-phasemultiband filter may bedesigned usingthepredefined
frequency-responsefunction mul t i band, as follows.
b = cr emez( 38, [ - 1 - 0. 5 - 0. 4 0. 3 0. 4 0. 8] , . . .
{' mul t i band' , [ 5 1 2 2 2 1] }, [ 1 10 5] ) ;
For thespecificcaseof a multiband filter, wecan usea shorthandfilter design
notation similar tothesyntax for r emez.
b = cr emez( 38, [ - 1 - 0. 5 - 0. 4 0. 3 0. 4 0. 8] , . . .
[ 5 1 2 2 2 1] , [ 1 10 5] ) ;
As with r emez, a vector of band edges is passed tocr emez. This vector defines
thefrequency bands over which optimization is performed; notethat thereare
twotransition bands, from-0.5 to-0.4 and from0.3 to0.4.
Band Amplitude Optimization
Weighting
[-1 -0.5] [5 1] 1
[-0.4 +0.3] [2 2] 10
[+0.4 +0.8] [2 1] 5
2 Filter Design
2-34
I n either case, thefrequency responseis obtained and plotted usinglinear
scale.
[ h, w] = f r eqz( b, 1, 512, ' whol e' ) ;
pl ot ( w/ pi - 1, f f t shi f t ( abs( h) ) ) ; gr i d;
xl abel ( ' Nor mal i zed Fr equency' ) ;
yl abel ( ' Magni t ude Response' ) ;
Notethat thefrequency responsehas been calculated over theentire
normalizedfrequency range[-1 +1] bypassingtheoption ' whol e' tof r eqz. I n
order toplot thenegativefrequencyinformation in anatural way, theresponse
has been wrapped,just as FFT data is, usingf f t shi f t .
Thefilter responsefor this multiband filter is complex, which is expected
becauseof theasymmetry in thefrequency domain.
-1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1
1
1.5
2
2.5
3
3.5
4
4.5
5
Normalized Frequency
M
a
g
n
i
t
u
d
e

R
e
s
p
o
n
s
e
FIR Filter Design
2-35
Filter Design with Reduced Delay
Consider thedesign of a 62-tap lowpass filter with a half-Nyquist cutoff. I f we
specify a negativeoffset valuetothel owpass filter design function, thegroup
delayoffset for thedesignissignificantlylessthanthat obtainedfor astandard
linear-phasedesign. This filter design may becomputed as follows.
b = cr emez( 61, [ 0 0. 5 0. 55 1] , {' l owpass' , - 16}) ;
Theresultingmagnituderesponseis
[ h, w] = f r eqz( b, 1, 512, ' whol e' ) ;
pl ot ( w/ pi - 1, f f t shi f t ( abs( h) ) ) ; gr i d;
xl abel ( ' Nor mal i zed Fr equency' ) ;
yl abel ( ' Magni t ude Response' ) ;
0 5 10 15 20 25 30 35 40
-0.5
0
0.5
1
1.5
2
2.5
R
e
a
l

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

P
a
r
t
2 Filter Design
2-36
Thegroup delay of thefilter reveals that theoffset has been reduced fromN/ 2
toN/ 2- 16 (i.e., from30. 5 to14. 5). Now, however, thegroup delay is nolonger
flat in thepassband region (plotted over thenormalized frequency range0 to
0.5 for clarity).
-1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1
0
0.2
0.4
0.6
0.8
1
1.2
1.4
Normalized Frequency
M
a
g
n
i
t
u
d
e

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

d
e
l
a
y

(
i
n

s
a
m
p
l
e
s
)
FIR Filter Design
2-37
I f wecomparethis nonlinear-phasefilter toa linear-phasefilter that has
exactly14.5samplesof groupdelay, theresultingfilter isof order 2*14.5, or 29.
Usingb = cr emez( 29, [ 0 0. 5 0. 55 1] , ' l owpass' ) , thepassband and
stopband rippleis much greater for theorder 29filter. Thesecomparisons can
assist you in decidingwhich filter is moreappropriatefor aspecificapplication.
2 Filter Design
2-38
Special Topics in IIR Filter Design
TheclassicI I R filter designtechniquefindsananaloglowpassfilter withcutoff
frequency of 1, translates this prototypefilter tothedesired band
configuration, then transforms thefilter tothedigital domain. Thetoolbox
provides functions for each step of this process.
Thebut t er , cheby1, cheby2, and el l i p functions aresufficient for many
design problems, andthelower level functions aregenerally not needed. But if
you dohavean application whereyou need totransformtheband edges of an
analogfilter, or discretizea rational transfer function, this section describes
thetools with which todoso.
Classical IIR Filter Design
Analog Lowpass Prototype Creation Frequency Transformation Discretization
but t ap
el l i pap
cheb1ap
cheb2ap
bessel ap l p2l p
l p2bp
l p2hp
l p2bs
bi l i near
i mpi nvar
but t er cheby1 cheby2 el l i p bessel f
Minimum Order Computation for Classical IIR Filter Design
but t or d cheb1or d cheb2or d el l i por d
Complete Design
Special Topics in IIR Filter Design
2-39
Analog Prototype Design
This toolboxprovides anumber of functions tocreatelowpass analogprototype
filters with cutoff frequency of 1, thefirst step in theclassical approach toI I R
filter design. Thetablebelowsummarizes theanalogprototypedesign
functions for each supported filter type; plots for each typeareshown in I I R
Filter Design on page2-5.
Frequency Transformation
Thesecond step in theanalogprototypingdesign techniqueis thefrequency
transformation of a lowpass prototype. Thetoolbox provides a set of functions
totransformanaloglowpass prototypes (with cutoff frequency of 1 rad/s) into
bandpass, highpass, bandstop, and lowpass filters of thedesired cutoff
frequency.
Filter Type Analog Prototype Function
Bessel [ z, p, k] = bessel ap( n)
Butterworth [ z, p, k] = but t ap( n)
Chebyshev typeI [ z, p, k] = cheb1ap( n, Rp)
Chebyshev typeI I [ z, p, k] = cheb2ap( n, Rs)
Elliptic [ z, p, k] = el l i pap( n, Rp, Rs)
2 Filter Design
2-40
As shown, all of thefrequency transformation functions can accept twolinear
systemmodels: transfer function and state-spaceform. For thebandpass and
bandstop cases
and
where
1
is thelower band edgeand
2
is theupper band edge.
Thefrequency transformation functions performfrequency variable
substitution. I n thecaseof l p2bp and l p2bs, this is a second-order
substitution, sotheoutput filter is twicetheorder of theinput. For l p2l p and
l p2hp, theoutput filter is thesameorder as theinput.
Tobegin designingan order 10 bandpass Chebyshev typeI filter with a value
of 3 dB for passband ripple, enter
[ z, p, k] = cheb1ap( 5, 3) ;
Freq. Transformation Transformation Function
Lowpass tolowpass [ numt , dent ] = l p2l p( num, den, Wo)
[ At , Bt , Ct , Dt ] = l p2l p( A, B, C, D, Wo)
Lowpass tohighpass [ numt , dent ] = l p2hp( num, den, Wo)
[ At , Bt , Ct , Dt ] = l p2hp( A, B, C, D, Wo)
Lowpass tobandpass [ numt , dent ] = l p2bp( num, den, Wo, Bw)
[ At , Bt , Ct , Dt ] = l p2bp( A, B, C, D, Wo, Bw)
Lowpass tobandstop [ numt , dent ] = l p2bs( num, den, Wo, Bw)
[ At , Bt , Ct , Dt ] = l p2bs( 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
=
Special Topics in IIR Filter Design
2-41
Outputs z, p, and k contain thezeros, poles, andgain of a lowpass analogfilter
with cutoff frequency
c
equal to1 rad/s. Usethel p2bp function totransform
this lowpass prototypetoa bandpass analogfilter with band edges
and . First, convert thefilter tostate-spaceformsothel p2bp function
can accept it.
[ A, B, C, D] = zp2ss( z, p, k) ; %Conver t t o st at e- space f or m.
Now, find thebandwidth and center frequency, and call l p2bp.
u1 = 0. 1*2*pi ; u2 = 0. 5*2*pi ; %I n r adi ans per second
Bw = u2- u1;
Wo = sqr t ( u1*u2) ;
[ At , Bt , Ct , Dt ] = l p2bp( A, B, C, D, Wo, Bw) ;
Finally, calculatethefrequency responseand plot its magnitude.
[ b, a] = ss2t f ( At , Bt , Ct , Dt ) ; %Conver t t o TF f or m.
w = l i nspace( 0. 01, 1, 500) *2*pi ; %Gener at e f r equency vect or .
h = f r eqs( b, a, w) ; %Comput e f r equency r esponse.
semi l ogy( w/ 2/ pi , abs( h) ) , gr i d %Pl ot l og magni t ude vs. f r eq.
xl abel ( ' Fr equency ( Hz) ' ) ;
.

1
5 =

2
=
0 0.2 0.4 0.6 0.8 1
10
7
10
6
10
5
10
4
10
3
10
2
10
1
10
0
Frequency (Hz)
2 Filter Design
2-42
Filter Discretization
Thethirdstepin theanalogprototypingtechniqueis thetransformation of the
filter tothediscrete-timedomain. Thetoolbox provides twomethods for this:
theimpulseinvariant andbilinear transformations. Thefilter designfunctions
but t er , cheby1, cheby2, and el l i p usethebilinear transformation for
discretization in this step.
Impulse Invariance
Thetoolbox function i mpi nvar creates a digital filter whoseimpulseresponse
is thesamples of thecontinuous impulseresponseof an analogfilter. This
function works only on filters in transfer function form. For best results, the
analogfilter shouldhavenegligiblefrequency content abovehalf thesampling
frequency, becausesuch high frequency content is aliased intolower bands
upon sampling. I mpulseinvarianceworks for somelowpass and bandpass
filters, but is not appropriatefor highpass and bandstop filters.
Design a Chebyshev typeI filter and plot its frequency response.
[ bz, az] = i mpi nvar ( b, a, 2) ;
[ H, w] = f r eqz( bz, az) ;
f r eqzpl ot ( H, w)
Analog to Digital
Transformation
Transformation Function
I mpulseinvariance [ numd, dend] = i mpi nvar ( num, den, f s)
Bilinear transform [ zd, pd, kd] = bi l i near ( z, p, k, f s, Fp)
[ numd, dend] = bi l i near ( num, den, f s, Fp)
[ Ad, Bd, Cd, Dd] = bi l i near ( At , Bt , Ct , Dt , f s, Fp)
Special Topics in IIR Filter Design
2-43
I mpulseinvarianceretains thecutoff frequencies of 0.1 Hz and 0.5 Hz.
Bilinear Transformation
Thebilinear transformation is a nonlinear mappingof thecontinuous domain
tothediscretedomain; it maps thes-planeintothez-planeby
Bilinear transformationmapsthe -axisof thecontinuousdomain totheunit
circleof thediscretedomain accordingto
Thetoolboxfunctionbi l i near implementsthisoperation, wherethefrequency
warpingconstant k is equal totwicethesamplingfrequency (2*f s) by default,
and equal to if you givebi l i near a trailingargument that
represents a matchfrequency Fp. I f a match frequency Fp (in hertz) is
present, bi l i near maps thefrequency (in rad/s) tothesame
frequency in thediscretedomain, normalized tothesamplingrate:
(alsoin rad/s).
0 0.2 0.4 0.6 0.8 1
800
600
400
200
0
200
Normalized Frequency ( rad/sample)
P
h
a
s
e

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

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

k
----
'

=
2f
p
f
p
f
s
( ) tan
2f
p
=
2f
p
f
s
=
2 Filter Design
2-44
Thebi l i near function can performthis transformation on threedifferent
linear systemrepresentations: zero-pole-gain, transfer function, and
state-spaceform. Try callingbi l i near with thestate-spacematrices that
describetheChebyshevtypeI filter fromtheprevioussection, usingasampling
frequency of 2 Hz, and retainingthelower band edgeof 0.1 Hz.
[ Ad, Bd, Cd, Dd] = bi l i near ( At , Bt , Ct , Dt , 2, 0. 1) ;
Thefrequency responseof theresultingdigital filter is
[ bz, az] = ss2t f ( Ad, Bd, Cd, Dd) ; %conver t t o TF
f r eqz( bz, az)
Thelower band edgeis at 0.1 Hz as expected. Notice, however, that theupper
band edgeis slightly less than 0.5 Hz, although in theanalogdomain it was
exactly 0.5 Hz. This illustrates thenonlinear natureof thebilinear
transformation. Tocounteract thisnonlinearity, it isnecessarytocreateanalog
domainfilterswithprewarpedbandedges, whichmaptothecorrect locations
upon bilinear transformation. Heretheprewarped frequencies u1 and u2
generateBwand Wo for thel p2bp function.
f s = 2; %Sampl i ng f r equency ( her t z)
u1 = 2*f s*t an( 0. 1*( 2*pi / f s) / 2) ; %Lower band edge ( r ad/ s)
u2 = 2*f s*t an( 0. 5*( 2*pi / f s) / 2) ; %Upper band edge ( r ad/ s)
Bw = u2 - u1; %Bandwi dt h
Wo = sqr t ( u1*u2) ; %Cent er f r equency
[ At , Bt , Ct , Dt ] = l p2bp( A, B, C, D, Wo, Bw) ;
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
-1000
-500
0
500
Normalized frequency (Nyquist == 1)
P
h
a
s
e

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

R
e
s
p
o
n
s
e

(
d
B
)
Special Topics in IIR Filter Design
2-45
A digital bandpass filter with correct bandedges 0.1and0.5times theNyquist
frequency is
[ Ad, Bd, Cd, Dd] = bi l i near ( At , Bt , Ct , Dt , f s) ;
Theexamplebandpass filters fromthelast twosections could alsobecreated
in onestatement usingthecompleteI I R design function cheby1. For instance,
an analogversion of theexampleChebyshev filter is
[ b, a] = cheby1( 5, 3, [ 0. 1 0. 5] *2*pi , ' s' ) ;
Notethat theband edges arein rad/s for analogfilters, whereas for thedigital
case, frequency is normalized (theNyquist frequency is equal to1 Hz).
[ bz, az] = cheby1( 5, 3, [ 0. 1 0. 5] ) ;
All of thecompletedesignfunctionscall bi l i near internally. Theyprewarpthe
band edges as needed toobtain thecorrect digital filter. SeeChapter 7,
Function Reference,for moreon thesefunctions.
2 Filter Design
2-46
Selected Bibliography
[1] Karam, L.J ., and J .H. McClellan. Complex Chebyshev Approximation for
FI R Filter Design.I EEE Trans. on Circuits and Systems I I . March 1995.
[2] Selesnick, I .W., and C.S. Burrus. Generalized Digital Butterworth Filter
Design.Proceedingsof theI EEE I nt. Conf. Acoust., Speech, Signal Processing.
Vol. 3 (May 1996).
[3] Selesnick, I .W., M. Lang, and C.S. Burrus. Constrained Least Square
Design of FI R Filters without Specified Transition Bands.Proceedings of the
I EEE I nt. Conf. Acoust., Speech, Signal Processing. Vol. 2 (May 1995).
Pgs. 1260-1263.
3
Statistical Signal
Processing
Overview . . . . . . . . . . . . . . . . . . . . . 3-2
Correlation and Covariance . . . . . . . . . . . . . 3-3
Bias and Normalization . . . . . . . . . . . . . . . . 3-4
MultipleChannels . . . . . . . . . . . . . . . . . . 3-5
Spectral Analysis . . . . . . . . . . . . . . . . . . 3-6
Spectral Estimation Method Overview . . . . . . . . . . 3-8
Nonparametric Methods . . . . . . . . . . . . . . . . 3-10
Parametric Methods . . . . . . . . . . . . . . . . . 3-30
Selected Bibliography . . . . . . . . . . . . . . . 3-39
3 Statistical Signal Processing
3-2
Overview
TheSignal ProcessingToolbox provides tools for estimatingimportant
functions of randomsignals. I n particular, therearetools toestimate
correlationandcovariancesequencesandspectral densityfunctionsof discrete
signals. Thefollowingsectionsexplainthecorrelationandcovariancefunctions
and discuss themathematically related functions for estimatingthepower
spectrum:
Correlation and Covariance
Spectral Analysis
Selected Bibliography
Correlation and Covariance
3-3
Correlation and Covariance
Thefunctions xcor r and xcov estimatethecross-correlation and
cross-covariancesequences of randomprocesses. They alsohandle
autocorrelation and autocovarianceas special cases.
Thetruecross-correlation sequenceis a statistical quantity defined as
wherex
n
and y
n
arestationary randomprocesses, , and E{}is the
expected valueoperator. Thecovariancesequenceis themean-removed
cross-correlation sequence
or, in terms of thecross-correlation,
I n practice, you must estimatethesesequences, becauseit is possibletoaccess
onlyafinitesegment of theinfinite-lengthrandomprocess. A commonestimate
basedon N samples of x
n
andy
n
is thedeterministiccross-correlation sequence
(alsocalled thetime-ambiguity function)
whereweassumefor this discussion that x
n
and y
n
areindexed from0toN-1,
and from-(N-1) toN-1. Thexcor r function evaluates this sumwith an
efficient FFT-based algorithm, given inputs x
n
and y
n
stored in length N
vectors x and y. I ts operation is equivalent toconvolution with oneof thetwo
subsequences reversed in time.
For example,
x = [ 1 1 1 1 1] ' ;
y = x;
R
xy
m ( ) E{x
n m +
y
*
n
} E{x
n
y
*
n m
} = =
n < <
C
xy
m ( ) E{x
n m +

x
( ) y
n

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

*
y
=
R

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

m 0
R

yx
*
m ( ) m 0 <






=
R

xy m ( )
3 Statistical Signal Processing
3-4
xyc = xcor r ( x, y)
xyc =
1. 0000
2. 0000
3. 0000
4. 0000
5. 0000
4. 0000
3. 0000
2. 0000
1. 0000
Noticethat theresultingsequencelength is oneless than twicethelength of
theinput sequence. Thus, theNth element is thecorrelation at lag0. Also
noticethetriangular pulseof theoutput that results when convolvingtwo
squarepulses.
Thexcov function estimates autocovarianceand cross-covariancesequences.
This function has thesameoptions and evaluates thesamesumas xcor r , but
first removes themeans of x and y.
Bias and Normalization
An estimateof a quantity is biased if its expected valueis not equal tothe
quantity it estimates. Theexpected valueof theoutput of xcor r is
xcor r providestheunbiasedestimate, dividingbyN-| m| , whenyouspecifyan
' unbi ased' flagafter theinput sequences.
xcor r ( x, y, ' unbi ased' )
Although this estimateis unbiased, theendpoints (near -(N-1) andN-1) suffer
fromlargevariancebecausexcor r computesthemusingonlyafewdatapoints.
A possibletrade-off is tosimply divideby N usingthe' bi ased' flag.
xcor r ( x, y, ' bi ased' )
E{R

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

N m ( )R
xy
m ( ) = =
Correlation and Covariance
3-5
With thisscheme, onlythesampleof thecorrelationat zerolag(theNth output
element) is unbiased. This estimateis often moredesirablethan theunbiased
onebecauseit avoids randomlargevariations at theend points of the
correlation sequence.
xcor r provides oneother normalization scheme. Thesyntax
xcor r ( x, y, ' coef f ' )
divides theoutput by nor m( x) *nor m( y) sothat, for autocorrelations, the
sampleat zerolagis 1.
Multiple Channels
For a multichannel signal, xcor r and xcov estimatetheautocorrelation and
cross-correlation and covariancesequences for all of thechannels at once. I f S
is an M-by-N signal matrix representingN channels in its columns, xcor r ( S)
returnsa(2M-1)-by-N
2
matrixwiththeautocorrelationsandcross-correlations
of thechannels of S in its N
2
columns. I f S is a three-channel signal
S = [ s1 s2 s3]
then theresult of xcor r ( S) is organized as
R = [ Rs1s1 Rs1s2 Rs1s3 Rs2s1 Rs2s2 Rs2s3 Rs3s1 Rs3s2 Rs3s3]
Tworelated functions, cov and cor r coef , areavailablein thestandard
MATLAB environment. They estimatecovarianceand normalized covariance
respectively between thedifferent channels at lag0 and arrangethemin a
squarematrix.
3 Statistical Signal Processing
3-6
Spectral Analysis
Thegoal of spectral estimation is todescribethedistribution (over frequency)
of thepower contained in a signal, based on a finiteset of data. Estimation of
power spectra is useful in a variety of applications, includingthedetection of
signals buried in wide-band noise.
Thepower spectrumof a stationary randomprocess x
n
is mathematically
related tothecorrelation sequenceby thediscrete-timeFourier transform. I n
terms of normalized frequency, this is given by
Thiscanbewrittenasafunction of physical frequency f (e.g., inhertz) byusing
therelation =2f/f
s
, wheref
s
is thesamplingfrequency.
Thecorrelation sequencecan bederivedfromthepower spectrumbyuseof the
inversediscrete-timeFourier transform.
Theaveragepower of thesequencex
n
over theentireNyquist interval is
represented by
S
xx
( ) R
xx
m ( )e
j m
m =

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

m =

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

S
xx
f ( )e
2j fm f
s

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

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

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

= =
Spectral Analysis
3-7
Thequantities
fromtheaboveexpression aredefined as thepower spectral density (PSD) of
thestationary randomsignal x
n
.
Theaveragepower of a signal over a particular frequency band ,
, can befound by integratingthePSD over that band.
Youcanseefromtheaboveexpressionthat P
xx
() representsthepower content
of asignal inaninfinitesimal frequencyband, whichiswhywecall it thepower
spectral density.
Theunits of thePSD arepower (e.g., watts) per unit of frequency. I n thecase
of P
xx
(), this is watts/rad/sampleor simply watts/rad. I n thecaseof P
xx
(f), the
units arewatts/hertz. I ntegration of thePSD with respect tofrequency yields
units of watts, as expected for theaveragepower .
For real signals, thePSD is symmetricabout DC, andthus P
xx
() for
is sufficient tocompletely characterizethePSD. However, in order toobtain
theaveragepower over theentireNyquist interval it is necessary tointroduce
theconcept of theone-sided PSD.
Theone-sided PSD is given by
Theaveragepower of asignal over thefrequencyband , ,
can becomputed usingtheone-sided PSD as
P
xx
( )
S
xx
( )
2
----------------- =
P
xx
f ( )
S
xx
f ( )
f
s
--------------- = and

2
[ , ]
0
1

2
<
P

1

2
, [ ]
P
xx
( ) d

P
xx
( ) d

2

1

+ =
P

1

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

2
[ , ] 0
1

2
<
P

1

2
, [ ]
P
onesi ded
( ) d

=
3 Statistical Signal Processing
3-8
Spectral Estimation Method Overview
Thevariousmethodsof spectrumestimation availableintheSignal Processing
Toolbox can becategorized as follows:
Nonparametric methods
Parametric methods
Subspacemethods
Nonparametric methods arethosein which theestimateof thePSD is made
directly fromthesignal itself. Thesimplest such method is theperiodogram.
An improvedversion of theperiodogramis Welchs method [8]. A moremodern
nonparametric techniqueis themultitaper method (MTM).
Parametric methods arethosein which thesignal whosePSD wewant to
estimateis assumed tobeoutput of a linear systemdriven by whitenoise.
Examples aretheYule-Walker autoregressive(AR) method and theBurg
method. Thesemethods estimatethePSD by first estimatingtheparameters
(coefficients) of thelinear systemthat hypothetically generatesthesignal.
They tend toproducebetter results than classical nonparametric methods
when thedata length of theavailablesignal is relatively short.
Subspacemethods, alsoknown as high-resolution methods or super-resolution
methods, generatefrequency component estimates for a signal based on an
eigenanalysis or eigendecomposition of thecorrelation matrix. Examples are
themultiplesignal classification (MUSI C) method or theeigenvector (EV)
method. Thesemethods arebest suited for linespectra that is, spectra of
sinusoidal signals and areeffectivein thedetection of sinusoids buried in
noise, especially when thesignal tonoiseratios arelow.
All threecategories of methods arelisted in thetablebelowwith the
correspondingtoolbox function names. Thenumber beloweach method name
indicates thepagethat describesthemethodin greater detail. SeeParametric
Modelingon page4-11for details about l pc and other parametricestimation
functions.
Spectral Analysis
3-9
Method Description Functions
Periodogram
(3-10)
Power spectral density estimate per i odogr am
Welch
(3-20)
Averaged periodograms of
overlapped, windowed signal sections
pwel ch, csd,
t f e, coher e
Multitaper
(3-24)
Spectral estimatefromcombination
of multipleorthogonal windows (or
tapers)
pmt m
Yule-Walker AR
(3-32)
Autoregressive(AR) spectral
estimateof a time-series fromits
estimated autocorrelation function
pyul ear
Burg
(3-33)
Autoregressive(AR) spectral
estimation of a time-series by
minimization of linear prediction
errors
pbur g
Covariance
(3-36)
Autoregressive(AR) spectral
estimation of a time-series by
minimization of theforward
prediction errors
pcov
Modified
Covariance
(3-36)
Autoregressive(AR) spectral
estimation of a time-series by
minimization of theforward and
backward prediction errors
pmcov
MUSI C
(3-36)
Multiplesignal classification pmusi c
Eigenvector
(3-36)
Pseudospectrumestimate pei g
3 Statistical Signal Processing
3-10
Nonparametric Methods
Thefollowingsections discuss theperiodogram, modifiedperiodogram, Welch,
and multitaper methods of nonparametric estimation, alongwith therelated
CSD function, transfer function estimate, and coherencefunction.
The Periodogram
Oneway of estimatingthepower spectrumof a process is tosimply find the
discrete-timeFourier transformof thesamples of theprocess (usually doneon
a grid with an FFT) and takethemagnitudesquared of theresult. This
estimateis called theperiodogram.
Theperiodogramestimateof thePSD of a length-L signal x
L
[n] is
where
Theactual computation of X
L
(f) can beperformed only at a finitenumber of
frequency points, N, and usually employs theFFT. I n practice, most
implementations of theperiodogrammethod computetheN-point PSD
estimate
where
I t is wisetochooseN >L sothat N is thenext power of twolarger than L. To
evaluateX
L
[f
k
], wesimply pad x
L
[n] with zeros tolength N. I f L >N, wemust
wrap x
L
[n] modulo-N prior tocomputingX
L
[f
k
].
P

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

n 0 =
L 1

=
P

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

=
Spectral Analysis
3-11
As an example, consider thefollowing1001-element signal xn, which consists
of twosinusoids plus noise.
r andn( ' st at e' , 0) ;
f s = 1000; %Sampl i ng f r equency
t = ( 0: f s) / f s; %One second wor t h of sampl es
A = [ 1 2] ; %Si nusoi d ampl i t udes ( r ow vect or )
f = [ 150; 140] ; %Si nusoi d f r equenci es ( col umn vect or )
xn = A*si n( 2*pi *f *t ) + 0. 1*r andn( si ze( t ) ) ;
Note Thethreelast lines illustratea convenient and general way toexpress
thesumof sinusoids. Together they areequivalent to
xn = si n( 2*pi *150*t ) + 2*si n( 2*pi *140*t ) + 0. 1*r andn( si ze( t ) ) ;
Theperiodogramestimateof thePSD can becomputed by
Pxx = per i odogr am( xn, [ ] , ' t wosi ded' , 1024, f s) ;
and a plot of theestimatecan bedisplayed by simply omittingtheoutput
argument, as below.
per i odogr am( xn, [ ] , ' t wosi ded' , 1024, f s) ;
0 100 200 300 400 500 600 700 800 900
90
80
70
60
50
40
30
20
10
0
Frequency (Hz)
P
o
w
e
r

S
p
e
c
t
r
a
l

D
e
n
s
i
t
y

(
d
B
/
H
z
)
Periodogram PSD Estimate
3 Statistical Signal Processing
3-12
Theaveragepower can becomputed by approximatingtheintegral with the
followingsum.
Pow = ( f s/ l engt h( Pxx) ) * sum( Pxx)
Pow =
2. 5028
You can alsocomputetheaveragepower fromtheone-sided PSD estimate.
Pxxo = per i odogr am( xn, [ ] , 1024, f s) ;
Pow = ( f s/ ( 2*l engt h( Pxxo) ) ) * sum( Pxxo)
Pow =
2. 4979
Performance of the Periodogram
Thefollowingsections discusstheperformanceof theperiodogramwith regard
totheissues of leakage, resolution, bias, and variance.
Spectral Leakage. Consider thepower spectrumor PSD of a finite-length signal
x
L
[n], as discussed in ThePeriodogram on page3-10. I t is frequently useful
tointerpret x
L
[n] as theresult of multiplyingan infinitesignal, x[n], by a
finite-length rectangular window, w
R
[n].
Becausemultiplication in thetimedomain corresponds toconvolution in the
frequency domain, theFourier transformof theexpression aboveis
Theexpression developed earlier for theperiodogram,
illustrates that theperiodogramis alsoinfluenced by this convolution.
x
L
n [ ] x n [ ] w
R
n [ ] =
X
L
f ( )
1
f
s
---- X ( )W
R
f ( ) d
f
s
2
f
s
2

=
P

xx
f ( )
X
L
f ( )
2
f
s
L
-------------------- =
Spectral Analysis
3-13
Theeffect of theconvolution is best understood for sinusoidal data. Suppose
that x[n] is composed of a sumof M complex sinusoids.
I ts spectrumis
which for a finite-length sequencebecomes
Soin thespectrumof thefinite-length signal, theDirac deltas havebeen
replaced by terms of theform , which corresponds tothefrequency
responseof a rectangular windowcentered on thefrequency f
k
.
Thefrequency responseof arectangular windowhas theshapeof asincsignal,
as shown below.
x n [ ] A
k
e
j
k
n
k 1 =
M

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

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





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

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

= =
W
R
f f
k
( )
0.5 0 0.5
90
80
70
60
50
40
30
20
10
0
3 Statistical Signal Processing
3-14
Theplot displays a main lobeand several sidelobes, thelargest of which is
approximately 13.5 dB belowthemainlobepeak. Theselobes account for the
effect known as spectral leakage. Whiletheinfinite-length signal has its power
concentrated exactly at thediscretefrequency points f
k
, thewindowed (or
truncated) signal has a continuumof power leaked around thediscrete
frequency points f
k
.
Becausethefrequencyresponseof ashort rectangular windowisamuchpoorer
approximation totheDirac delta function than that of a longer window,
spectral leakageisespeciallyevident whendatarecordsareshort. Consider the
followingsequenceof 100 samples.
r andn( ' st at e' , 0)
f s = 1000; %Sampl i ng f r equency
t = ( 0: f s/ 10) / f s; %One- t ent h of a second wor t h of sampl es
A = [ 1 2] ; %Si nusoi d ampl i t udes
f = [ 150; 140] ; %Si nusoi d f r equenci es
xn = A*si n( 2*pi *f *t ) + 0. 1*r andn( si ze( t ) ) ;
per i odogr am( xn, [ ] , 1024, f s) ;
I t is important tonotethat theeffect of spectral leakageis contingent solely on
thelength of thedata record. I t is not a consequenceof thefact that the
periodogramis computed at a finitenumber of frequency samples.
0 100 200 300 400 500
80
70
60
50
40
30
20
10
0
Frequency (Hz)
P
o
w
e
r

S
p
e
c
t
r
a
l

D
e
n
s
i
t
y

(
d
B
/
H
z
)
Periodogram PSD Estimate
Spectral Analysis
3-15
Resolution. Resolutionreferstotheabilitytodiscriminatespectral features, and
is a key concept on theanalysis of spectral estimator performance.
I norder toresolvetwosinusoidsthat arerelativelyclosetogether in frequency,
it isnecessaryfor thedifferencebetween thetwofrequenciestobegreater than
thewidthof themainlobeof theleakedspectrafor either oneof thesesinusoids.
Themainlobewidth is defined tobethewidth of themainlobeat thepoint
wherethepower is half thepeak mainlobepower (i.e., 3 dB width). This width
is approximately equal tof
s
/ L.
I n other words, for twosinusoids of frequencies f
1
and f
2
, theresolvability
condition requires that
I n theexampleabove, wheretwosinusoids areseparated by only 10 Hz, the
data record must begreater than 100 samples toallowresolution of two
distinct sinusoids by a periodogram.
Consider a casewherethis criterion is not met, as for thesequenceof 67
samples below.
r andn( ' st at e' , 0)
f s = 1000; %Sampl i ng f r equency
t = ( 0: f s/ 15) . / f s; %67 sampl es
A = [ 1 2] ; %Si nusoi d ampl i t udes
f = [ 150; 140] ; %Si nusoi d f r equenci es
xn = A*si n( 2*pi *f *t ) + 0. 1*r andn( si ze( t ) ) ;
per i odogr am( xn, [ ] , 1024, f s) ;
f f
1
f
2
( )
f
s
L
---- > =
3 Statistical Signal Processing
3-16
Theabovediscussionabout resolutiondidnot consider theeffectsof noisesince
thesignal-to-noiseratio(SNR) has been relatively high thus far. When the
SNR is low, truespectral features aremuch harder todistinguish, and noise
artifacts appear in spectral estimates based on theperiodogram. Theexample
belowillustrates this.
r andn( ' st at e' , 0)
f s = 1000; %Sampl i ng f r equency
t = ( 0: f s/ 10) . / f s; %One- t ent h of a second wor t h of sampl es
A = [ 1 2] ; %Si nusoi d ampl i t udes
f = [ 150; 140] ; %Si nusoi d f r equenci es
xn = A*si n( 2*pi *f *t ) + 2*r andn( si ze( t ) ) ;
per i odogr am( xn, [ ] , 1024, f s) ;
0 100 200 300 400 500
70
60
50
40
30
20
10
0
Frequency (Hz)
P
o
w
e
r

S
p
e
c
t
r
a
l

D
e
n
s
i
t
y

(
d
B
/
H
z
)
Periodogram PSD Estimate
Spectral Analysis
3-17
Bias of the Periodogram. Theperiodogramis a biased estimator of thePSD. I ts
expected valuecan beshown tobe
which is similar tothefirst expression for X
L
(f) in Spectral Leakage on
page3-12, except that theexpression hereis in terms of averagepower rather
than magnitude. This suggests that theestimates produced by the
periodogramcorrespond toa leaky PSD rather than thetruePSD.
Notethat essentially yields a triangular Bartlett window(which
is apparent fromthefact that theconvolution of tworectangular pulses is a
triangular pulse). This results in a height for thelargest sidelobes of theleaky
power spectrathat isabout 27 dB belowthemainlobepeak; i.e., about twicethe
frequency separation relativetothenon-squared rectangular window.
Theperiodogramis asymptotically unbiased, which is evident fromtheearlier
observation that as thedata record length tends toinfinity, thefrequency
responseof therectangular windowmoreclosely approximates theDiracdelta
function (alsotruefor a Bartlett window). However, in somecases the
periodogramis a poor estimator of thePSD even when thedata record is long.
This is duetothevarianceof theperiodogram, as explained below.
0 100 200 300 400 500
55
50
45
40
35
30
25
20
15
10
5
Frequency (Hz)
P
o
w
e
r

S
p
e
c
t
r
a
l

D
e
n
s
i
t
y

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



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

=
W
R
f ( )
2
3 Statistical Signal Processing
3-18
Variance of the Periodogram. Thevarianceof theperiodogramcan beshown tobe
approximately
which indicates that thevariancedoes not tend tozeroas thedata length L
tends toinfinity. I n statistical terms, theperiodogramis not a consistent
estimator of thePSD. Nevertheless, theperiodogramcan bea useful tool for
spectral estimation in situations wheretheSNR is high, and especially if the
data record is long.
The Modified Periodogram
Themodified periodogramwindowsthetime-domain signal prior tocomputing
theFFT in order tosmooth theedges of thesignal. This has theeffect of
reducingtheheight of thesidelobes or spectral leakage. This phenomenon
gives risetotheinterpretation of sidelobes as spurious frequencies introduced
intothesignal by theabrupt truncation that occurs when a rectangular
windowis used. For nonrectangular windows, theend points of thetruncated
signal areattenuatedsmoothly, andhencethespuriousfrequenciesintroduced
aremuchlesssevere. Ontheother hand, nonrectangular windowsalsobroaden
themainlobe, which results in a net reduction of resolution.
Theper i odogr amfunction allows you tocomputea modified periodogramby
specifyingthewindowtobeused on thedata. For example, comparea
rectangular windowand a Hammingwindow.
r andn( ' st at e' , 0)
f s = 1000; %Sampl i ng f r equency
t = ( 0: f s/ 10) . / f s; %One- t ent h of a second wor t h of sampl es
A = [ 1 2] ; %Si nusoi d ampl i t udes
f = [ 150; 140] ; %Si nusoi d f r equenci es
xn = A*si n( 2*pi *f *t ) + 0. 1*r andn( si ze( t ) ) ;
per i odogr am( xn, boxcar ( l engt h( xn) ) , 1024, f s) ;
var
X
L
f ( )
2
f
s
L
--------------------
)


P
xx
2
f ( ) 1
2L f f
s
( ) sin
L 2f f
s
( ) sin
------------------------------------


2
+
Spectral Analysis
3-19
per i odogr am( xn, hammi ng( l engt h( xn) ) , 1024, f s) ;
You can verify that although thesidelobes aremuch less evident in the
Hamming-windowed periodogram, thetwomain peaks arewider. I n fact, the
3 dB width of themainlobecorrespondingtoa Hammingwindowis
approximately twicethat of a rectangular window. Hence, for a fixed data
length, thePSD resolution attainablewith a Hammingwindowis
0 100 200 300 400 500
80
70
60
50
40
30
20
10
0
Frequency (Hz)
P
o
w
e
r

S
p
e
c
t
r
a
l

D
e
n
s
i
t
y

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

S
p
e
c
t
r
a
l

D
e
n
s
i
t
y

(
d
B
/
H
z
)
Periodogram PSD Estimate
3 Statistical Signal Processing
3-20
approximately half that attainablewith arectangular window. Thecompeting
interests of mainlobewidth andsidelobeheight can beresolvedtosomeextent
by usingvariablewindows such as theKaiser window.
Nonrectangular windowingaffects theaveragepower of asignal becausesome
of thetimesamples areattenuated when multiplied by thewindow. To
compensatefor this, theper i odogr amfunction normalizes thewindowtohave
an averagepower of unity. This way thechoiceof windowdoes not affect the
averagepower of thesignal.
Themodified periodogramestimateof thePSD is
whereU is thewindownormalization constant
which is independent of thechoiceof window. Theaddition of U as a
normalization constant ensures that themodified periodogramis
asymptotically unbiased.
Welchs Method
An improved estimator of thePSD is theoneproposed by Welch [8]. The
method consists of dividingthetimeseries data into(possibly overlapping)
segments, computinga modified periodogramof each segment, and then
averagingthePSD estimates. Theresult is Welchs PSD estimate.
WelchsmethodisimplementedintheSignal ProcessingToolboxbythepwel ch
function. By default, thedata is divided intoeight segments with 50%overlap
between them. A Hammingwindowis used tocomputethemodified
periodogramof each segment.
Theaveragingof modified periodograms tends todecreasethevarianceof the
estimaterelativetoa singleperiodogramestimateof theentiredata record.
Althoughoverlapbetweensegmentstendstointroduceredundant information,
this effect is diminishedby theuseof anonrectangular window, which reduces
P

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

=
Spectral Analysis
3-21
theimportanceor weight given totheend samples of segments (thesamples
that overlap).
However, as mentioned above, thecombined useof short data records and
nonrectangular windows results in reduced resolution of theestimator. I n
summary, thereis a tradeoff between variancereduction and resolution. One
can manipulatetheparameters in Welchs method toobtain improved
estimates relativetotheperiodogram, especially when theSNR is low. This is
illustrated in thefollowingexample.
Consider an original signal consistingof 301 samples.
r andn( ' st at e' , 1)
f s = 1000; %Sampl i ng f r equency
t = ( 0: 0. 3*f s) . / f s; %301 sampl es
A = [ 2 8] ; %Si nusoi d ampl i t udes ( r ow vect or )
f = [ 150; 140] ; %Si nusoi d f r equenci es ( col umn vect or )
xn = A*si n( 2*pi *f *t ) + 5*r andn( si ze( t ) ) ;
per i odogr am( xn, boxcar ( l engt h( xn) ) , 1024, f s) ;
0 100 200 300 400 500
60
50
40
30
20
10
0
10
Frequency (Hz)
P
o
w
e
r

S
p
e
c
t
r
a
l

D
e
n
s
i
t
y

(
d
B
/
H
z
)
Periodogram PSD Estimate
3 Statistical Signal Processing
3-22
Wecan obtain Welchs spectral estimatefor 3segments with 50%overlap with
pwel ch( xn, boxcar ( 150) , 75, 512, f s) ;
I n theperiodogramabove, noiseand theleakagemakeoneof thesinusoids
essentially indistinguishablefromtheartificial peaks. I n contrast, although
thePSDproducedbyWelchsmethodhaswider peaks, youcanstill distinguish
thetwosinusoids, which stand out fromthenoisefloor.
However, if wetry toreducethevariancefurther, theloss of resolution causes
oneof thesinusoids tobelost altogether.
pwel ch( xn, hammi ng( 100) , 75, 512, f s) ;
0 100 200 300 400 500
25
20
15
10
5
0
5
10
Frequency (Hz)
P
o
w
e
r

S
p
e
c
t
r
a
l

D
e
n
s
i
t
y

(
d
B
/
H
z
)
Welch PSD Estimate
Spectral Analysis
3-23
For a moredetailed discussion of Welchs method of PSD estimation, see
Kay [2] and Welch [8].
Bias and Normalization in Welchs Method
Welchs method yields a biased estimator of thePSD. Theexpected valuecan
befound tobe
whereL
s
is thelength of thedata segments and U is thesamenormalization
constant present in thedefinition of themodified periodogram. As is thecase
for all periodograms, Welchs estimator is asymptotically unbiased. For afixed
length data record, thebias of Welchs estimateis larger than that of the
periodogrambecauseL
s
<L.
Thevarianceof Welchs estimator is difficult tocomputebecauseit depends on
both thewindowusedandtheamount of overlapbetween segments. Basically,
thevarianceis inversely proportional tothenumber of segments whose
modified periodograms arebeingaveraged.
0 100 200 300 400 500
20
15
10
5
0
5
Frequency (Hz)
P
o
w
e
r

S
p
e
c
t
r
a
l

D
e
n
s
i
t
y

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

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

=
3 Statistical Signal Processing
3-24
Multitaper Method
Theperiodogramcan beinterpreted as filteringa length L signal, x
L
[n],
through a filter bank (a set of filters in parallel) of L FI R bandpass filters. The
3 dB bandwidth of each of thesebandpass filters can beshown tobe
approximately equal tof
s
/ L. Themagnituderesponseof each oneof these
bandpass filters resembles that of therectangular windowdiscussed in
Spectral Leakageon page3-12. Theperiodogramcan thus beviewed as a
computation of thepower of each filtered signal (i.e., theoutput of each
bandpass filter) that uses just onesampleof each filtered signal and assumes
that thePSD of x
L
[n] is constant over thebandwidth of each bandpass filter.
As thelength of thesignal increases, thebandwidth of each bandpass filter
decreases, makingit a moreselectivefilter, and improvingtheapproximation
of constant PSD over thebandwidth of thefilter. This provides another
interpretation of why thePSD estimateof theperiodogramimproves as the
length of thesignal increases. However, therearetwofactors apparent from
this standpoint that compromisetheaccuracy of theperiodogramestimate.
First, therectangular windowyields a poor bandpass filter. Second, the
computationof thepower at theoutput of eachbandpassfilter reliesonasingle
sampleof theoutput signal, producinga very crudeapproximation.
Welchs method can begiven a similar interpretation in terms of a filter bank.
I n Welchs implementation, several samples areused tocomputetheoutput
power, resultingin reduced varianceof theestimate. On theother hand, the
bandwidth of each bandpass filter is larger than that correspondingtothe
periodogrammethod, which results in a loss of resolution. Thefilter bank
model thus provides anewinterpretation of thecompromisebetween variance
and resolution.
Thompsons multitaper method (MTM) builds on theseresults toprovidean
improved PSD estimate. I nstead of usingbandpass filters that areessentially
rectangular windows (as in theperiodogrammethod), theMTM methoduses a
bank of optimal bandpass filters tocomputetheestimate. Theseoptimal FI R
filters arederivedfromaset of sequences known as discreteprolatespheroidal
sequences (DPSSs, alsoknown as Slepian sequences).
I n addition, theMTM method provides a time-bandwidth parameter with
which tobalancethevarianceand resolution. This parameter is given by the
time-bandwidth product, NWand it is directly related tothenumber of tapers
used tocomputethespectrum. Therearealways 2*NW-1 tapers used toform
theestimate. This means that, as NWincreases, therearemoreestimates of
Spectral Analysis
3-25
thepower spectrum, and thevarianceof theestimatedecreases. However, the
bandwidth of each taper is alsoproportional toNW, soas NWincreases, each
estimateexhibits morespectral leakage(i.e., wider peaks) and theoverall
spectral estimateis morebiased. For each dataset, thereis usually avaluefor
NWthat allows an optimal trade-off between bias and variance.
TheSignal ProcessingToolbox function that implements theMTM method is
called pmt m. Usepmt mtocomputethePSD of xn fromtheprevious examples.
r andn( ' st at e' , 0)
f s = 1000; %Sampl i ng f r equency
t = ( 0: f s) / f s; %One second wor t h of sampl es
A = [ 1 2] ; %Si nusoi d ampl i t udes
f = [ 150; 140] ; %Si nusoi d f r equenci es
xn = A*si n( 2*pi *f *t ) + 0. 1*r andn( si ze( t ) ) ;
[ P, F] = pmt m( xn, 4, 1024, f s) ;
pl ot ( F, 10*l og10( P) ) %Pl ot i n dB/ Hz
xl abel ( ' Fr equency ( Hz) ' ) ;
yl abel ( ' Power Spect r al Densi t y ( dB/ Hz) ' ) ;
0 100 200 300 400 500
55
50
45
40
35
30
25
20
15
10
5
Frequency (Hz)
P
o
w
e
r

S
p
e
c
t
r
a
l

D
e
n
s
i
t
y

(
d
B
/
H
z
)
3 Statistical Signal Processing
3-26
Byloweringthetime-bandwidthproduct, youcanincreasetheresolutionat the
expenseof larger variance.
[ P1, f ] = pmt m( xn, 3/ 2, 1024, f s) ;
pl ot ( f , 10*l og10( P1) ) %Pl ot i n dB/ Hz
xl abel ( ' Fr equency ( Hz) ' ) ;
yl abel ( ' Power Spect r al Densi t y ( dB/ Hz) ' ) ;
Notethat theaveragepower is conserved in both cases.
Pow = ( f s/ 1024) * sum( P)
Pow =
2. 4926
Pow1 = ( f s/ 1024) * sum( P1)
Pow1 =
2. 4927
This method is morecomputationally expensivethan Welchs method dueto
thecost of computingthediscreteprolatespheroidal sequences. For longdata
series (10,000points or more), it is useful tocomputetheDPSSs onceandsave
themin a MAT-file. TheM-files dpsssave, dpssl oad, dpssdi r , and dpsscl ear
areprovided tokeep a databaseof saved DPSSs in theMAT-filedpss. mat .
0 100 200 300 400 500
80
70
60
50
40
30
20
10
0
Frequency (Hz)
P
o
w
e
r

S
p
e
c
t
r
a
l

D
e
n
s
i
t
y

(
d
B
/
H
z
)
Spectral Analysis
3-27
Cross-Spectral Density Function
ThePSD is a special caseof thecross spectral density (CSD) function, defined
between twosignals x
n
and y
n
as
As is thecasefor thecorrelation and covariancesequences, thetoolbox
estimates thePSD and CSD becausesignal lengths arefinite.
Toestimatethecross-spectral densityof twoequal length signals x andy using
Welchs method, thecsd function forms theperiodogramas theproduct of the
FFT of x and theconjugateof theFFT of y. Unlikethereal-valued PSD, the
CSD is acomplex function. csd handles thesectioningandwindowingof x and
y in thesameway as thepwel ch function.
Sxy = csd( x, y, nf f t , f s, wi ndow, numover l ap)
Confidence Intervals
You can computeconfidenceintervals usingthecsd function by includingan
additional input argument p that specifies thepercentageof theconfidence
interval, and settingthenumover l ap argument to0.
[ Sxy, Sxyc, f ] = csd( x, y, nf f t , f s, wi ndow, 0, p)
p must bea scalar between 0 and 1. This function assumes chi-squared
distributed periodograms of thenonoverlappingsections of windowed data in
computingtheconfidenceintervals. This assumption is valid when thesignal
is a Gaussian distributed randomprocess. Provided theseassumptions are
correct, theconfidenceinterval
[ Sxy- Sxyc( : , 1) Sxy+Sxyc( : , 2) ]
covers thetrueCSD with probability p. I f you set numover l ap toany value
other than 0, you generatea warningindicatingthat thesections overlap and
theconfidenceinterval is not reliable.
S
xy
( ) R
xy
m ( )e
j m
m =

=
3 Statistical Signal Processing
3-28
Transfer Function Estimate
Oneapplication of Welchs method is nonparametric systemidentification.
Assumethat H is a linear, timeinvariant system, and x(n) and y(n) arethe
input toand output of H, respectively. Then thepower spectrumof x(n) is
related totheCSD of x(n) and y(n) by
An estimateof thetransfer function between x(n) and y(n) is
This method estimates both magnitudeand phaseinformation. Thet f e
function uses Welchs method tocomputetheCSD and power spectrum, and
then forms their quotient for thetransfer function estimate. Uset f e thesame
way that you usethecsd function.
Filter thesignal xn with an FI R filter, then plot theactual magnituderesponse
and theestimated response.
h = ones( 1, 10) / 10; %Movi ng aver age f i l t er
yn = f i l t er ( h, 1, xn) ;
[ HEST, f ] = t f e( xn, yn, 256, f s, 256, 128, ' none' ) ;
H = f r eqz( h, 1, f , f s) ;
subpl ot ( 2, 1, 1) ; pl ot ( f , abs( H) ) ;
t i t l e( ' Act ual Tr ansf er Funct i on Magni t ude' ) ;
subpl ot ( 2, 1, 2) ; pl ot ( f , abs( HEST) ) ;
t i t l e( ' Tr ansf er Funct i on Magni t ude Est i mat e' ) ;
xl abel ( ' Fr equency ( Hz) ' ) ;
S
xy
( ) H ( )S
xx
( ) =
H

( )
S

xy
( )
S

xx
( )
----------------- =
Spectral Analysis
3-29
Coherence Function
Themagnitude-squared coherencebetween twosignals x(n) and y(n) is
This quotient is a real number between 0and 1that measures thecorrelation
between x(n) and y(n) at thefrequency .
Thecoher e function takes sequences x and y, computes their power spectra
and CSD, and returns thequotient of themagnitudesquared of theCSD and
theproduct of thepower spectra. I ts options and operation aresimilar tothe
csd and t f e functions.
Thecoherencefunction of xn and thefilter output yn versus frequency is
coher e( xn, yn, 256, f s, 256, 128, ' none' )
0 100 200 300 400 500
0
0.2
0.4
0.6
0.8
1
Actual Transfer Function Magnitude
0 100 200 300 400 500
0
0.2
0.4
0.6
0.8
1
Transfer Function Magnitude Estimate
Frequency (Hz)
C
xy
( )
S
xy
( )
2
S
xx
( )S
yy
( )
----------------------------------- =
3 Statistical Signal Processing
3-30
I f theinput sequencelength nf f t , windowlength wi ndow, and thenumber of
overlappingdata points in a windownumover l ap, aresuch that coher e
operates on only a singlerecord, thefunction returns all ones. This is because
thecoherencefunction for linearly dependent data is one.
Parametric Methods
Parametricmethods can yieldhigher resolutions than nonparametricmethods
in cases when thesignal length is short. Thesemethods usea different
approach tospectral estimation; insteadof tryingtoestimatethePSD directly
fromthedata, they model thedata as theoutput of a linear systemdriven by
whitenoise, and then attempt toestimatetheparameters of that linear
system.
Themost commonly used linear systemmodel is theall-polemodel, a filter
with all of its zeroes at theorigin in thez-plane. Theoutput of such a filter for
whitenoiseinput is an autoregressive(AR) process. For this reason, these
methods aresometimes referred toas AR methods of spectral estimation.
TheAR methods tend toadequately describespectra of data that is peaky,
that is, data whosePSD is largeat certain frequencies. Thedata in many
practical applications(suchasspeech) tendstohavepeakyspectrasothat AR
models areoften useful. I n addition, theAR models lead toa systemof linear
equations which is relatively simpletosolve.
TheSignal ProcessingToolbox offers thefollowingAR methods for spectral
estimation:
Yule-Walker AR method (autocorrelation method)
Burgmethod
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-31
Covariancemethod
Modified covariancemethod
All AR methods yield a PSD estimategiven by
Thedifferent AR methods estimatetheAR parameters a
p
(k) slightly
differently, yieldingdifferent PSD estimates. Thefollowingtableprovides a
summary of thedifferent AR methods.
P

AR
f ( )
1
f
s
----

p
1 a
p
k ( )e
2j kf f
s

k 1 =
p

+
2
------------------------------------------------------------------- =
Burg Covariance Modified Covariance Yule-Walker
Characteristics Does not apply
window todata
Does not apply
windowtodata
Does not apply
window todata
Applies windowto
data
Minimizes the
forwardandbackward
prediction errors in
theleast squares
sense, with theAR
coefficients
constrained tosatisfy
theL-D recursion
Minimizes the
forward prediction
error in theleast
squares sense
Minimizes the
forwardandbackward
prediction errors in
theleast squares
sense
Minimizes the
forward prediction
error in theleast
squares sense
(alsocalled
Autocorrelation
method)
Advantages High resolution for
short data records
Better resolutionthan
Y-W for short data
records (more
accurateestimates)
High resolution for
short data records
Performs as well as
other methods for
largedata records
Always produces a
stablemodel
Abletoextract
frequencies fromdata
consistingof por more
puresinusoids
Abletoextract
frequencies fromdata
consistingof por more
puresinusoids
Always produces a
stablemodel
Does not suffer
spectral line-splitting
3 Statistical Signal Processing
3-32
Yule-Walker AR Method
TheYule-Walker AR method of spectral estimation computes theAR
parameters by forminga biased estimateof thesignals autocorrelation
function, and solvingtheleast squares minimization of theforward prediction
error. This results in theYule-Walker equations
Theuseof a biased estimateof theautocorrelation function ensures that the
autocorrelation matrix aboveis positivedefinite. Hence, thematrix is
invertibleand a solution is guaranteed toexist. Moreover, theAR parameters
thus computed always result in a stableall-polemodel. TheYule-Walker
equations can besolved efficiently via Levinsons algorithm, which takes
advantageof theToeplitz structureof theautocorrelation matrix.
Thetoolbox function pyul ear implements theYule-Walker AR method.
Disadvantages Peak locations highly
dependent on initial
phase
May produceunstable
models
Mayproduceunstable
models
Performs relatively
poorly for short data
records
May suffer spectral
line-splitting for
sinusoids in noise, or
when order is very
large
Frequency bias for
estimates of sinusoids
in noise
Peak locations
slightly dependent on
initial phase
Frequency bias for
estimates of sinusoids
in noise
Frequency bias for
estimates of sinusoids
in noise
Minor frequency bias
for estimates of
sinusoids in noise
Conditions for
Nonsingularity
Order must beless
than or equal tohalf
theinput framesize
Order must beless
than or equal to2/3
theinput framesize
Becauseof thebiased
estimate, the
autocorrelation
matrix is guaranteed
topositive-definite,
hencenonsingular
Burg Covariance Modified Covariance Yule-Walker
r 1 ( ) r 2 ( )
*
L r p ( )
*
r 2 ( ) r 1 ( ) L r p 1 ( )
*

r p ( ) L r 2 ( ) r 1 ( )
a 2 ( )
a 3 ( )

a p 1 + ( )
r 2 ( )
r 3 ( )

r p 1 + ( )
=
Spectral Analysis
3-33
For example, comparethespectrumof a speech signal usingWelchs method
and theYule-Walker AR method.
l oad mt l b
[ P1, f ] = pwel ch( mt l b, hammi ng( 256) , 128, 1024, f s) ;
[ P2, f ] = pyul ear ( mt l b, 14, 1024, f s) ;
pl ot ( f , 10*l og10( P1) , ' : ' , f , 10*l og10( P2) ) ; gr i d
yl abel ( ' PSD Est i mat es ( dB/ Hz) ' ) ;
xl abel ( ' Fr equency ( Hz) ' ) ;
l egend( ' Wel ch' , ' Yul e- Wal ker AR' )
Thesolid-lineYule-Walker AR spectrumis smoother than theperiodogram
becauseof thesimpleunderlyingall-polemodel.
Burg Method
TheBurgmethod for AR spectral estimation is based on minimizingthe
forward and backward prediction errors whilesatisfyingtheLevinson-Durbin
recursion (seeMarple[3], Chapter 7, and Proakis [6], Section 12.3.3). I n
contrast toother AR estimation methods, theBurgmethod avoids calculating
theautocorrelation function, and instead estimates thereflection coefficients
directly.
Theprimary advantages of theBurgmethod areresolvingclosely spaced
sinusoidsinsignals with lownoiselevels, andestimatingshort datarecords, in
0 100 200 300 400 500 600
70
60
50
40
30
20
10
P
S
D

E
s
t
i
m
a
t
e
s

(
d
B
/
H
z
)
Frequency (Hz)
Welch
YuleWalker AR
3 Statistical Signal Processing
3-34
which casetheAR power spectral density estimates arevery closetothetrue
values. I n addition, theBurgmethod ensures a stableAR model and is
computationally efficient.
Theaccuracy of theBurgmethod is lower for high-order models, longdata
records, and high signal-to-noiseratios (which can causelinesplitting, or the
generationof extraneouspeaksinthespectrumestimate). Thespectral density
estimatecomputed by theBurgmethod is alsosusceptibletofrequency shifts
(relativetothetruefrequency) resultingfromtheinitial phaseof noisy
sinusoidal signals. This effect is magnified when analyzingshort data
sequences.
Thetoolbox function pbur g implements theBurgmethod. Comparethe
spectrumof thespeech signal generated by both theBurgmethod and the
Yule-Walker AR method. They arevery similar for largesignal lengths.
l oad mt l b
[ P1, f ] = pbur g( mt l b( 1: 512) , 14, 1024, f s) ; %14t h or der model
[ P2, f ] = pyul ear ( mt l b( 1: 512) , 14, 1024, f s) ; %14t h or der model
pl ot ( f , 10*l og10( P1) , ' : ' , f , 10*l og10( P2) ) ; gr i d
yl abel ( ' Magni t ude ( dB) ' ) ; xl abel ( ' Fr equency ( Hz) ' ) ;
l egend( ' Bur g' , ' Yul e- Wal ker AR' )
0 100 200 300 400 500 600
80
70
60
50
40
30
20
10
M
a
g
n
i
t
u
d
e

(
d
B
)
Frequency (Hz)
Burg
YuleWalker AR
Spectral Analysis
3-35
Comparethespectrumof a noisy signal computed usingtheBurgmethod and
theWelch method.
r andn( ' st at e' , 0)
f s = 1000; %Sampl i ng f r equency
t = ( 0: f s) / f s; %One second wor t h of sampl es
A = [ 1 2] ; %Si nusoi d ampl i t udes
f = [ 150; 140] ; %Si nusoi d f r equenci es
xn = A*si n( 2*pi *f *t ) + 0. 1*r andn( si ze( t ) ) ;
[ P1, f ] = pwel ch( xn, hammi ng( 256) , 128, 1024, f s) ;
[ P2, f ] = pbur g( xn, 14, 1024, f s) ;
pl ot ( f , 10*l og10( P1) , ' : ' , f , 10*l og10( P2) ) ; gr i d
yl abel ( ' PSD Est i mat es ( dB/ Hz) ' ) ;
xl abel ( ' Fr equency ( Hz) ' ) ;
l egend( ' Wel ch' , ' Bur g' )
Notethat, as themodel order for theBurgmethodis reduced, afrequency shift
duetotheinitial phaseof thesinusoids will becomeapparent.
0 100 200 300 400 500 600
60
50
40
30
20
10
0
P
S
D

E
s
t
i
m
a
t
e
s

(
d
B
/
H
z
)
Frequency (Hz)
Welch
Burg
3 Statistical Signal Processing
3-36
Covariance and Modified Covariance Methods
Thecovariancemethod for AR spectral estimation is based on minimizingthe
forward prediction error. Themodified covariancemethod is based on
minimizingtheforwardandbackwardprediction errors. Thetoolboxfunctions
pcov and pmcov implement therespectivemethods.
Comparethespectrumof thespeech signal generated by both thecovariance
method and themodified covariancemethod. They arenearly identical, even
for a short signal length.
l oad mt l b
[ P1, f ] = pcov( mt l b( 1: 64) , 14, 1024, f s) ; %14t h or der model
[ P2, f ] = pmcov( mt l b( 1: 64) , 14, 1024, f s) ; %14t h or der model
pl ot ( f , 10*l og10( P1) , ' : ' , f , 10*l og10( P2) ) ; gr i d
yl abel ( ' Magni t ude ( dB) ' ) ; xl abel ( ' Fr equency ( Hz) ' ) ;
l egend( ' Covar i ance' , ' Modi f i ed Covar i ance' )
MUSIC and Eigenvector Analysis Methods
Thepmusi c and pei g functions providetworelated spectral analysis methods:
pmusi c provides themultiplesignal classification (MUSI C) method
developed by Schmidt
pei g provides theeigenvector (EV) method developed by J ohnson
SeeMarple[3] (pgs. 373-378) for a summary of thesemethods.
0 500 1000 1500 2000 2500 3000 3500 4000
100
90
80
70
60
50
40
M
a
g
n
i
t
u
d
e

(
d
B
)
Frequency (Hz)
Covariance
Modified Covariance
Spectral Analysis
3-37
Both of thesemethods arefrequency estimator techniques based on
eigenanalysis of theautocorrelation matrix. This typeof spectral analysis
categorizes theinformation in a correlation or data matrix, assigning
information toeither a signal subspaceor a noisesubspace.
Eigenanalysis Overview
Consider a number of complex sinusoids embedded in whitenoise. You can
writetheautocorrelation matrix R for this systemas thesumof thesignal
autocorrelation matrix (S) and thenoiseautocorrelation matrix (W).
Thereis a closerelationship between theeigenvectors of thesignal
autocorrelation matrix andthesignal and noisesubspaces. Theeigenvectors v
of S span thesamesignal subspaceasthesignal vectors. I f thesystemcontains
M complex sinusoids and theorder of theautocorrelation matrix is p,
eigenvectors v
M+1
through v
p+1
span thenoisesubspaceof theautocorrelation
matrix.
Frequency Estimator Functions. Togeneratetheir frequency estimates,
eigenanalysismethodscalculatefunctionsof thevectorsinthesignal andnoise
subspaces. Both theMUSI C and EV techniques choosea function that goes to
infinity (denominator goes tozero) at oneof thesinusoidal frequencies in the
input signal. Usingdigital technology, theresultingestimatehas sharp peaks
at thefrequencies of interest; this means that theremight not beinfinity
values in thevectors.
TheMUSI C estimateis given by theformula
whereN is thesizeof theeigenvectors ande(f) is a vector of complex sinusoids.
v represents theeigenvectors of theinput signals correlation matrix; v
k
is the
k
th
eigenvector. H is theconjugatetransposeoperator. Theeigenvectors used
R S W + =
P
music
f ( )
1
e
H
f ( ) v
k
v
k
H
k p 1 + =
N

'



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

------------------------------------------- = =
e f ( ) 1 exp j 2f ( ) exp j 2f 2 ( ) exp j 2f 4 ( ) exp j 2f n 1 ( ) ( ) [ ]
H
=
3 Statistical Signal Processing
3-38
in thesumcorrespondtothesmallest eigenvalues andspan thenoisesubspace
(p is thesizeof thesignal subspace).
Theexpression is equivalent toa Fourier transform(thevector e(f)
consists of complex exponentials). This formis useful for numericcomputation
becausetheFFT canbecomputedfor eachv
k
andthenthesquaredmagnitudes
can besummed.
TheEV method weights thesummation by theeigenvalues of thecorrelation
matrix.
Thepmusi c and pei g functions in this toolbox usethesvd (singular value
decomposition) function in thesignal caseand theei g function for analyzing
thecorrelation matrix and assigningeigenvectors tothesignal or noise
subspaces. When svd is used, pmusi c and pei g never computethecorrelation
matrix explicitly, but thesingular values aretheeigenvalues.
v
k
H
e f ( )
P
ev
f ( )
1
v
k
H
e f ( )
2
k p 1 + =
N

'


----------------------------------------------------------- =
Selected Bibliography
3-39
Selected Bibliography
[1] Hayes, M.H. Statistical Digital Signal Processingand Modeling. NewYork:
J ohn Wiley & Sons, 1996.
[2] Kay, S.M. ModernSpectral Estimation. EnglewoodCliffs, NJ : PrenticeHall,
1988.
[3] Marple, S.L. Digital Spectral Analysis. EnglewoodCliffs, NJ : PrenticeHall,
1987.
[4] Orfanidis, S.J . I ntroduction toSignal Processing. Upper SaddleRiver, NJ :
PrenticeHall, 1996.
[5] Percival, D.B., and A.T. Walden. Spectral Analysis for Physical
Applications: Multitaper andConventional UnivariateTechniques. Cambridge:
CambridgeUniversity Press, 1993.
[6] Proakis, J .G., and D.G. Manolakis. Digital Signal Processing: Principles,
Algorithms, and Applications. Englewood Cliffs, NJ : PrenticeHall, 1996.
[7] Stoica, P., and R. Moses. I ntroduction toSpectral Analysis. Upper Saddle
River, NJ : PrenticeHall, 1997.
[8] Welch, P.D. TheUseof Fast Fourier Transformfor theEstimationof Power
Spectra: A Method Based on TimeAveragingOver Short, Modified
Periodograms. I EEE Trans. AudioElectroacoust. Vol. AU-15 (J une1967).
Pgs. 70-73.
3 Statistical Signal Processing
3-40
4
Special Topics
Overview . . . . . . . . . . . . . . . . . . . . . 4-2
Windows . . . . . . . . . . . . . . . . . . . . . . 4-3
Basic Shapes . . . . . . . . . . . . . . . . . . . . 4-3
Generalized CosineWindows . . . . . . . . . . . . . . 4-5
Kaiser Window . . . . . . . . . . . . . . . . . . . 4-5
Chebyshev Window . . . . . . . . . . . . . . . . . . 4-9
Parametric Modeling . . . . . . . . . . . . . . . . 4-11
Time-Domain Based Modeling . . . . . . . . . . . . . 4-13
Frequency-Domain Based Modeling . . . . . . . . . . . 4-18
Resampling . . . . . . . . . . . . . . . . . . . . 4-21
CepstrumAnalysis . . . . . . . . . . . . . . . . . 4-24
I nverseComplex Cepstrum . . . . . . . . . . . . . . 4-26
FFT-Based Time-Frequency Analysis . . . . . . . . . 4-28
Median Filtering . . . . . . . . . . . . . . . . . . 4-29
Communications Applications . . . . . . . . . . . . 4-30
Deconvolution . . . . . . . . . . . . . . . . . . . 4-34
Specialized Transforms . . . . . . . . . . . . . . . 4-35
Chirp z-Transform . . . . . . . . . . . . . . . . . . 4-35
DiscreteCosineTransform . . . . . . . . . . . . . . . 4-37
Hilbert Transform . . . . . . . . . . . . . . . . . . 4-39
Selected Bibliography . . . . . . . . . . . . . . . 4-41
4 Special Topics
4-2
Overview
TheSignal ProcessingToolbox provides functions that allowyou toapply a
variety of signal processingtechniques. Thefollowingsections describehowto
usesomeof thesefunctions:
Windows
Parametric Modeling
Resampling
CepstrumAnalysis
FFT-Based Time-Frequency Analysis
Median Filtering
Communications Applications
Deconvolution
Specialized Transforms
Selected Bibliography
Windows
4-3
Windows
I n both digital filter design and power spectrumestimation, thechoiceof a
windowingfunction can play an important rolein determiningthequality of
overall results. Themain roleof thewindowis todamp out theeffects of the
Gibbs phenomenon that results fromtruncation of an infiniteseries.
Thetoolbox windowfunctions areshown in thetablebelow.
Basic Shapes
Thebasicwindowistherectangular window, avector of onesof theappropriate
length. A rectangular windowof length 50 is
n = 50;
w = boxcar ( n) ;
This toolbox stores windows in column vectors by convention, soan equivalent
expression is
w = ones( 50, 1) ;
TheBartlett (or triangular) windowis theconvolution of tworectangular
windows. Thefunctions bar t l et t and t r i ang computesimilar triangular
windows, with threeimportant differences. Thebar t l et t function always
Window Function
Bartlett window bar t l et t
Blackman window bl ackman
Chebyshev window chebwi n
Hammingwindow hammi ng
Hann window hann
Kaiser window kai ser
Rectangular window boxcar
Triangular window t r i ang
4 Special Topics
4-4
returns awindowwith twozeros on theends of thesequence, sothat for n odd,
thecenter section of bar t l et t ( n+2) is equivalent tot r i ang( n) .
bar t l et t ( 7)
ans =
0
0. 3333
0. 6667
1. 0000
0. 6667
0. 3333
0
t r i ang( 5)
ans =
0. 3333
0. 6667
1. 0000
0. 6667
0. 3333
For n even, bar t l et t is still theconvolution of tworectangular sequences.
Thereis nostandarddefinition for thetriangular windowfor n even; theslopes
of thelinesegments of thet r i ang result areslightly steeper than thoseof
bar t l et t in this case.
w = bar t l et t ( 8) ;
[ w( 2: 7) t r i ang( 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
Thefinal differencebetween theBartlett andtriangular windows is evident in
theFourier transforms of thesefunctions. TheFourier transformof a Bartlett
Windows
4-5
windowis negativefor n even. TheFourier transformof a triangular window,
however, is always nonnegative.
This differencecan beimportant when choosinga windowfor somespectral
estimationtechniques, suchastheBlackman-Tukeymethod. Blackman-Tukey
forms thespectral estimateby calculatingtheFourier transformof the
autocorrelation sequence. Theresultingestimatemight benegativeat some
frequencies if thewindows Fourier transformis negative(seeKay [1], pg. 80).
Generalized Cosine Windows
Blackman, Hamming, Hann, and rectangular windows areall special cases of
thegeneralized cosinewindow. Thesewindows arecombinations of sinusoidal
sequences with frequencies 0, , and , whereN is the
windowlength. Oneway togeneratethemis
i nd = ( 0: n- 1) ' *2*pi / ( n- 1) ;
w = A - B*cos( i nd) + C*cos( 2*i nd) ;
whereA, B, and Careconstants you define. Theconcept behind thesewindows
is that bysummingtheindividual termstoformthewindow, thelowfrequency
peaks in thefrequency domain combinein such a way as todecreasesidelobe
height. This has thesideeffect of increasingthemainlobewidth.
TheHammingand Hann windows aretwo-termgeneralized cosinewindows,
given by A =0. 54, B =0. 46 for Hammingand A =0. 5, B =0. 5 for Hann (C=0
in both cases). Thehammi ng and hann functions, respectively, computethese
windows.
Notethat thedefinition of thegeneralized cosinewindowshown in theearlier
MATLAB codeyields zeros at samples 1 and n for A =0. 5 and B =0. 5.
TheBlackman windowis a popular three-termwindow, given by A =0. 42,
B =0. 5, C=0. 08. Thebl ackman function computes this window.
Kaiser Window
TheKaiser windowis an approximation totheprolate-spheroidal window, for
whichtheratioof themainlobeenergytothesidelobeenergyismaximized. For
a Kaiser windowof a particular length, theparameter controls thesidelobe
height. For agiven, thesidelobeheight isfixedwithrespect towindowlength.
Thestatement kai ser ( n, bet a) computes a length n Kaiser windowwith
parameter bet a.
2 N 1 ( ) 4 N 1 ( )
4 Special Topics
4-6
Examples of Kaiser windows with length 50 and various values for thebet a
parameter are
n = 50;
w1 = kai ser ( n, 1) ;
w2 = kai ser ( n, 4) ;
w3 = kai ser ( n, 9) ;
[ W1, f ] = f r eqz( w1/ sum( w1) , 1, 512, 2) ;
[ W2, f ] = f r eqz( w2/ sum( w2) , 1, 512, 2) ;
[ W3, f ] = f r eqz( w3/ sum( w3) , 1, 512, 2) ;
pl ot ( f , 20*l og10( abs( [ W1 W2 W3] ) ) ) ; gr i d;
l egend( ' bet a = 1' , ' bet a = 4' , ' bet a = 9' , 3)
t i t l e( ' Thr ee Kai ser Wi ndow Responses' )
xl abel ( ' Nor mal i zed Fr equency ( Nyqui st = 1) ' )
yl abel ( ' Nor mal i zed Magni t ude ( dB) ' )
As increases, thesidelobeheight decreasesandthemainlobewidthincreases.
Toseehowthesidelobeheight stays thesamefor a fixed parameter as the
length is varied, try
w1 = kai ser ( 50, 4) ;
w2 = kai ser ( 20, 4) ;
w3 = kai ser ( 101, 4) ;
[ W1, f ] = f r eqz( w1/ sum( w1) , 1, 512, 2) ;
[ W2, f ] = f r eqz( w2/ sum( w2) , 1, 512, 2) ;
0 0.2 0.4 0.6 0.8 1
180
160
140
120
100
80
60
40
20
0
Three Kaiser Window Responses
Normalized Frequency (Nyquist = 1)
N
o
r
m
a
l
i
z
e
d

M
a
g
n
i
t
u
d
e

(
d
B
)
beta = 1
beta = 4
beta = 9
Windows
4-7
[ W3, f ] = f r eqz( w3/ sum( w3) , 1, 512, 2) ;
pl ot ( f , 20*l og10( abs( [ W1 W2 W3] ) ) ) ; gr i d;
l egend( ' l engt h = 50' , ' l engt h = 20' , ' l engt h = 101' )
t i t l e( ' Thr ee Kai ser Wi ndow Responses, Bet a Fi xed' )
xl abel ( ' Nor mal i zed Fr equency ( Nyqui st = 1) ' )
yl abel ( ' Nor mal i zed Magni t ude ( dB) ' )
Kaiser Windows in FIR Design
Therearetwodesign formulas that can help you design FI R filters tomeet a
set of filter specifications usinga Kaiser window. Toachievea sidelobeheight
of dB, thebet a parameter is
For a transition width of rad/s, usethelength
Filters designed usingtheseheuristics will meet thespecifications
approximately, but youshouldverifythis. Todesignalowpassfilter withcutoff
0 0.2 0.4 0.6 0.8 1
120
100
80
60
40
20
0
20
Three Kaiser Window Responses, Beta Fixed
Normalized Frequency (Nyquist = 1)
N
o
r
m
a
l
i
z
e
d

M
a
g
n
i
t
u
d
e

(
d
B
)
length = 50
length = 20
length = 101

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
frequency rad/s, transition width rad/s, and40 dB of attenuation in
thestopband, try
[ n, wn, bet a] = kai ser or d( [ 0. 4 0. 6] *pi , [ 1 0] , [ 0. 01 0. 01] , 2*pi ) ;
h = f i r 1( n, wn, kai ser ( n+1, bet a) , ' noscal e' ) ;
Thekai ser or d functionestimates thefilter order, cutoff frequency, andKaiser
windowbeta parameter needed tomeet a given set of frequency domain
specifications.
Theripplein thepassband is roughly thesameas theripplein thestopband.
As you can seefromthefrequency response, this filter nearly meets the
specifications.
[ H, f ] = f r eqz( h, 1, 512, 2) ;
pl ot ( f , 20*l og10( abs( H) ) ) , gr i d
For details on kai ser or d, seethedescription in Chapter 7, Function
Reference.
0.5 0.2
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
TheChebyshev windowminimizes themainlobewidth, given a particular
sidelobeheight. I t is characterized by an equiripplebehavior, that is, its
sidelobes all havethesameheight. Thechebwi n function, with length and
sidelobeheight parameters, computes a Chebyshev window.
n = 51;
Rs = 40; %Si del obe hei ght i n deci bel s
w = chebwi n( n, Rs) ;
st em( w) ; t i t l e( ' Lengt h 51 Chebyshev Wi ndow' ) ;
xl abel ( ' Sampl e Number ' ) ;
As shown in theplot, theChebyshev windowhas largespikes at its outer
samples. Plot thefrequency responsetoseetheequiripples at -40 dB.
[ W, f ] = f r eqz( w, 1, 512, 2) ;
pl ot ( f , 20*l og10( abs( W) / sum( w) ) ) , gr i d
t i t l e( ' Chebyshev Wi ndow Magni t ude Response' ) ;
xl abel ( ' Nor mal i zed Fr equency ( Nyqui st = 1) ' ) ;
yl abel ( ' Nor mal i zed Magni t ude ( dB) ' ) ;
0 5 10 15 20 25 30 35 40 45 50
0
0.2
0.4
0.6
0.8
1
Sample Number
Length 51 Chebyshev Window
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
-80
-60
-40
-20
0
Normalized Frequency (Nyquist == 1)
N
o
r
m
a
i
l
z
e
d

M
a
g
n
i
t
u
d
e

(
d
B
)
Chebyshev Window Magnitude Response
4 Special Topics
4-10
For a detailed discussion of thecharacteristics and applications of thevarious
windowtypes, seeOppenheimand Schafer [2], pgs. 444-462, and Parks and
Burrus [3], pgs. 71-73.
Parametric Modeling
4-11
Parametric Modeling
Parametricmodelingtechniquesfindtheparametersfor amathematical model
describinga signal, system, or process. Thesetechniques useknown
information about thesystemtodeterminethemodel. Applications for
parametric modelingincludespeech and music synthesis, data compression,
high-resolution spectral estimation, communications, manufacturing, and
simulation.
Thetoolbox parametric modelingfunctions operatewith therational transfer
function model. Given appropriateinformation about an unknown system
(impulseor frequency responsedata, or input and output sequences), these
functions find thecoefficients of a linear systemthat models thesystem.
Oneimportant application of theparametric modelingfunctions is in the
design of filters that havea prescribed timeor frequency response. These
functions providea data-oriented alternativetotheI I R and FI R filter design
functions discussed in Chapter 2, Filter Design.
4 Special Topics
4-12
Hereis a summary of theparametric modelingfunctions in this toolbox. Note
that theSystemI dentification Toolbox provides a moreextensivecollection of
parametric modelingfunctions.
Becauseyul ewal k is geared explicitly toward ARMA filter design, it is
discussed in Chapter 2, Filter Design.pbur g and pyul ear arediscussed in
Chapter 3, Statistical Signal Processing,alongwith theother
(nonparametric) spectral estimation methods.
Domain Functions Description
Time ar bur g Generateall-polefilter coefficients that model an input data
sequenceusingtheLevinson-Durbin algorithm.
ar cov Generateall-polefilter coefficients that model an input data
sequenceby minimizingtheforward prediction error.
ar mcov Generateall-polefilter coefficients that model an input data
sequenceby minimizingtheforward and backward prediction
errors.
ar yul e Generateall-polefilter coefficients that model an input data
sequenceusingan estimateof theautocorrelation function.
l pc,
l evi nson
Linear PredictiveCoding. Generateall-polerecursivefilter whose
impulseresponsematches a given sequence.
pr ony GenerateI I R filter whoseimpulseresponsematches a given
sequence.
st mcb Find I I R filter whoseoutput, given a specified input sequence,
matches a given output sequence.
Frequency i nvf r eqz,
i nvf r eqs
Generatedigital or analogfilter coefficients given complex
frequency responsedata.
Parametric Modeling
4-13
Time-Domain Based Modeling
Thel pc, pr ony, and st mcb functions find thecoefficients of a digital rational
transfer function that approximates a given time-domain impulseresponse.
Thealgorithms differ in complexity and accuracy of theresultingmodel.
Linear Prediction
Linear prediction modelingassumes that each output sampleof asignal, x( k) ,
is a linear combination of thepast n outputs (that is, it can belinearly
predicted fromtheseoutputs), and that thecoefficients areconstant from
sampletosample.
An nth-order all-polemodel of a signal x is
a = l pc( x, n)
Toillustratel pc, createa samplesignal that is theimpulseresponseof an
all-polefilter with additivewhitenoise.
r andn( ' st at e' , 0) ;
x = i mpz( 1, [ 1 0. 1 0. 1 0. 1 0. 1] , 10) + r andn( 10, 1) / 10;
Thecoefficients for a fourth-order all-polefilter that models thesystemare
a = l pc( x, 4)
a =
1. 0000 0. 2574 0. 1666 0. 1203 0. 2598
l pc first calls xcor r tofind a biased estimateof thecorrelation function of x,
and then uses theLevinson-Durbin recursion, implemented in thel evi nson
function, tofind themodel coefficients a. TheLevinson-Durbin recursion is a
fast algorithmfor solvinga systemof symmetric Toeplitz linear equations.
l pcs entirealgorithmfor n =4 is
r = xcor r ( x) ;
r ( 1: l engt h( x) - 1) = [ ] ; %Remove cor r . at negat i ve l ags
a = l evi nson( r , 4)
a =
1. 0000 0. 2574 0. 1666 0. 1203 0. 2598
x k ( ) a 2 ( )x k 1 ( ) a 3 ( )x k 2 ( ) a n 1 + ( )x k n ( ) =
4 Special Topics
4-14
You could formthelinear prediction coefficients with other assumptions by
passinga different correlation estimatetol evi nson, such as thebiased
correlation estimate.
r = xcor r ( x, ' bi ased' ) ;
r ( 1: l engt h( x) - 1) = [ ] ; %Remove cor r . at negat i ve l ags
a = l evi nson( r , 4)
a =
1. 0000 0. 2574 0. 1666 0. 1203 0. 2598
Pronys Method (ARMA Modeling)
Thepr ony functionmodelsasignal usingaspecifiednumber of polesandzeros.
Given a sequencex and numerator and denominator orders nb and na,
respectively, thestatement
[ b, a] = pr ony( x, nb, na)
finds thenumerator and denominator coefficients of an I I R filter whose
impulseresponseapproximates thesequencex.
Thepr ony function implements themethod described in [3] Parks andBurrus
(pgs. 226-228). This method uses a variation of thecovariancemethod of AR
modelingtofind thedenominator coefficients a, and then finds thenumerator
coefficients b for which theresultingfilters impulseresponsematches exactly
thefirst nb +1 samples of x. Thefilter is not necessarily stable, but it can
potentially recover thecoefficients exactly if thedata sequenceis truly an
autoregressivemovingaverage(ARMA) process of thecorrect order.
Note Thefunctions pr ony and st mcb (described next) aremoreaccurately
described as ARX models in systemidentification terminology. ARMA
modelingassumes noiseonly at theinputs, whileARX assumes an external
input. pr ony and st mcb knowtheinput signal: it is an impulsefor pr ony and
is arbitrary for st mcb.
Parametric Modeling
4-15
A model for thetest sequencex (fromtheearlier l pc example) usinga
third-order I I R filter is
[ b, a] = pr ony( x, 3, 3)
b =
0. 9567 - 0. 3351 0. 1866 - 0. 3782
a =
1. 0000 - 0. 0716 0. 2560 - 0. 2752
Thei mpz command shows howwell this filters impulseresponsematches the
original sequence.
f or mat l ong
[ x i mpz( b, a, 10) ]
ans =
0. 95674351884718 0. 95674351884718
- 0. 26655843782381 - 0. 26655843782381
- 0. 07746676935252 - 0. 07746676935252
- 0. 05223235796415 - 0. 05223235796415
- 0. 18754713506815 - 0. 05726777015121
0. 15348154656430 - 0. 01204969926150
0. 13986742016521 - 0. 00057632797226
0. 00609257234067 - 0. 01271681570687
0. 03349954614087 - 0. 00407967053863
0. 01086719328209 0. 00280486049427
Noticethat thefirst four samples match exactly. For an exampleof exact
recovery, recover thecoefficients of a Butterworth filter fromits impulse
response.
[ b, a] = but t er ( 4, . 2) ;
h = i mpz( b, a, 26) ;
[ bb, aa] = pr ony( h, 4, 4) ;
Try this example; youll seethat bb andaa match theoriginal filter coefficients
towithin a toleranceof 10
-13
.
4 Special Topics
4-16
Steiglitz-McBride Method (ARMA Modeling)
Thest mcb function determinesthecoefficientsfor thesystemb(z)/a(z) given an
approximateimpulseresponsex, as well as thedesired number of zeros and
poles. This function identifies an unknown systembased on both input and
output sequences that describethesystems behavior, or just theimpulse
responseof thesystem. I n its default mode, st mcb works likepr ony.
[ b, a] = st mcb( x, 3, 3)
b =
0. 9567 - 0. 5181 0. 5702 - 0. 5471
a =
1. 0000 - 0. 2384 0. 5234 - 0. 3065
st mcb alsofinds systems that match given input and output sequences.
y = f i l t er ( 1, [ 1 1] , x) ; %Cr eat e an out put si gnal .
[ b, a] = st mcb( y, x, 0, 1)
b =
1. 0000
a =
1 1
I n this example, st mcb correctly identifies thesystemused tocreatey fromx.
TheSteiglitz-McBridemethod is a fast iterativealgorithmthat solves for the
numerator and denominator coefficients simultaneously in an attempt to
minimizethesignal error between thefilter output and thegiven output
signal. This algorithmusually converges rapidly, but might not convergeif the
model order is toolarge. As for pr ony, st mcbs resultingfilter is not necessarily
stableduetoits exact modelingapproach.
st mcb provides control over several important algorithmicparameters; modify
theseparameters if you arehavingtroublemodelingthedata. Tochangethe
number of iterations fromthedefault of fiveandprovidean initial estimatefor
thedenominator coefficients
n = 10; %Number of i t er at i ons
a = l pc( x, 3) ; %I ni t i al est i mat es f or denomi nat or
[ b, a] = st mcb( x, 3, 3, n, a) ;
Parametric Modeling
4-17
Thefunction uses an all-polemodel created with pr ony as an initial estimate
when you donot provideoneof your own.
Tocomparethefunctions l pc, pr ony, and st mcb, computethesignal error in
each case.
a1 = l pc( x, 3) ;
[ b2, a2] = pr ony( x, 3, 3) ;
[ b3, a3] = st mcb( x, 3, 3) ;
[ x- i mpz( 1, a1, 10) x- i mpz( b2, a2, 10) x- i mpz( b3, a3, 10) ]
ans =
- 0. 0433 0 - 0. 0000
- 0. 0240 0 0. 0234
- 0. 0040 0 - 0. 0778
- 0. 0448 - 0. 0000 0. 0498
- 0. 2130 - 0. 1303 - 0. 0742
0. 1545 0. 1655 0. 1270
0. 1426 0. 1404 0. 1055
0. 0068 0. 0188 0. 0465
0. 0329 0. 0376 0. 0530
0. 0108 0. 0081 - 0. 0162
sum( ans. ^2)
ans =
0. 0953 0. 0659 0. 0471
I n comparingmodelingcapabilities for a given order I I R model, thelast result
shows that for this example, st mcb performs best, followedby pr ony, then l pc.
This relativeperformanceis typical of themodelingfunctions.
4 Special Topics
4-18
Frequency-Domain Based Modeling
Thei nvf r eqs and i nvf r eqz functions implement theinverseoperations of
f r eqs and f r eqz; they find an analogor digital transfer function of a specified
order that matches a given complex frequency response. Though thefollowing
examples demonstratei nvf r eqz, thediscussion alsoapplies toi nvf r eqs.
Torecover theoriginal filter coefficients fromthefrequency responseof a
simpledigital filter
[ b, a] = but t er ( 4, 0. 4) %Desi gn But t er wor t h l owpass
b =
0. 0466 0. 1863 0. 2795 0. 1863 0. 0466
a =
1. 0000 - 0. 7821 0. 6800 - 0. 1827 0. 0301
[ h, w] = f r eqz( b, a, 64) ; %Comput e f r equency r esponse
[ bb, aa] = i nvf r eqz( 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
Thevector of frequencies whas theunits in rad/sample, and thefrequencies
need not beequally spaced. i nvf r eqz finds a filter of any order tofit the
frequency data; a third-order exampleis
[ bb, aa] = i nvf r eqz( h, w, 3, 3) %Fi nd t hi r d- or der I I R
bb =
0. 0464 0. 1785 0. 2446 0. 1276
aa =
1. 0000 - 0. 9502 0. 7382 - 0. 2006
Both i nvf r eqs and i nvf r eqz design filters with real coefficients; for a data
point at positivefrequency f , thefunctions fit thefrequency responseat both f
and - f .
Parametric Modeling
4-19
By default i nvf r eqz uses an equation error method toidentify thebest model
fromthedata. This finds b and a in
by creatinga systemof linear equations and solvingthemwith MATLABs \
operator. HereA(w(k)) and B(w(k)) aretheFourier transforms of the
polynomials a andb respectively at thefrequency w(k), and n is thenumber of
frequency points (thelength of h and w). wt(k) weights theerror relativetothe
error at different frequencies. Thesyntax
i nvf r eqz( h, w, nb, na, wt )
includes aweightingvector. I n this mode, thefilter resultingfromi nvf r eqz is
not guaranteed tobestable.
i nvf r eqz provides a superior (output-error) algorithmthat solves thedirect
problemof minimizingtheweighted sumof thesquared error between the
actual frequency responsepoints and thedesired response
Tousethis algorithm, specify a parameter for theiteration count after the
weight vector parameter
wt = ones( si ze( w) ) ; %Cr eat e uni t y wei ght i ng vect or
[ bbb, aaa] = i nvf r eqz( h, w, 3, 3, wt , 30) %30 i t er at i ons
bbb =
0. 0464 0. 1829 0. 2572 0. 1549
aaa =
1. 0000 - 0. 8664 0. 6630 - 0. 1614
Theresultingfilter is always stable.
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

4 Special Topics
4-20
Graphically comparetheresults of thefirst and second algorithms tothe
original Butterworth filter.
[ H1, w] = f r eqz( b, a) ;
[ H2] = f r eqz( bb, aa) ;
[ H3] = f r eqz( bbb, aaa) ;
s. pl ot = ' mag' ;
s. xuni t s = ' r ad/ sampl e' ;
s. yuni t s = ' l i near ' ;
f r eqzpl ot ( [ H1 H2 H3] , w) ;
l egend( ' Or i gi nal ' , ' Fi r st Est i mat e' , ' Second Est i mat e' , 3) ;
gr i d on
Toverify thesuperiority of thefit numerically, type
sum( abs( h- f r eqz( bb, aa, w) ) . ^2) %Tot al er r or , al gor i t hm1
ans =
0. 0200
sum( abs( h- f r eqz( bbb, aaa, w) ) . ^2) %Tot al er r or , al gor i t hm2
ans =
0. 0096
0 0.2 0.4 0.6 0.8 1
600
400
200
0
Normalized Frequency ( rad/sample)
P
h
a
s
e

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

(
d
B
)
Original
First Estimate
Second Estimate
Resampling
4-21
Resampling
Thetoolbox provides a number of functions that resamplea signal at a higher
or lower rate.
Ther esampl e function changes thesamplingratefor a sequencetoany rate
that is a ratioof twointegers. Thebasic syntax for r esampl e is
y = r esampl e( x, p, q)
wherethefunction resamples thesequencex at p/ q times theoriginal
samplingrate. Thelength of theresult y is p/ q times thelength of x.
Oneresamplingapplication is theconversion of digitized audiosignals from
onesamplingratetoanother, such as from48 kHz (thedigital audiotape
standard) to44.1 kHz (thecompact disc standard). I n thenext example, the
samplingrates aredifferent but theidea is thesame.
Theexamplefilecontains a length 4001 vector of speech sampled at 7418 Hz.
cl ear
l oad mt l b
whos
Name Si ze Byt es Cl ass
Fs 1x1 8 doubl e ar r ay
mt l b 4001x1 32008 doubl e ar r ay
Gr and t ot al i s 4002 el ement s usi ng 32016 byt es
Operation Function
Apply FI R filter with resampling upf i r dn
Cubic splineinterpolation spl i ne
Decimation deci mat e
I nterpolation i nt er p
Other 1-D interpolation i nt er p1
Resampleat newrate r esampl e
4 Special Topics
4-22
Fs
Fs =
7418
Toplay this speech signal on a workstation that can only play sound at
8192 Hz, usether at function tofind integers p and q that yield thecorrect
resamplingfactor.
[ p, q] = r at ( 8192/ Fs, 0. 0001)
p =
127
q =
115
Sincep/ q*Fs = 8192. 05 Hz, thetoleranceof 0.0001is acceptable; toresample
thesignal at very closeto8192 Hz.
y = r esampl e( mt l b, p, q) ;
r esampl e applies a lowpass filter totheinput sequencetoprevent aliasing
duringresampling. I t designs this filter usingthef i r l s function with aKaiser
window. Thesyntax
r esampl e( x, p, q, l , bet a)
controls thefilters length and thebeta parameter of theKaiser window.
Alternatively, usethefunction i nt f i l t todesign an interpolation filter b and
useit with
r esampl e( x, p, q, b)
Thedeci mat e and i nt er p functions dothesamethingas r esampl e with p =1
and q =1, respectively. Thesefunctions providedifferent anti-alias filtering
options, and they incur a slight signal delay duetofiltering. Thei nt er p
function is significantly less efficient than the r esampl e function with q =1.
Thetoolbox alsocontains a function, upf i r dn, that applies an FI R filter toan
input sequenceand outputs thefiltered sequenceat a different samplerate
than its original rate. SeeMultirateFilter Bank I mplementation on page
1-20 and thedescription of upf i r dn in Chapter 7, Function Reference, for
moredetails.
Resampling
4-23
Thestandard MATLAB environment contains a function, spl i ne, that works
with irregularly spaced data. TheMATLAB function i nt er p1 performs
interpolation, or tablelookup, usingvarious methods includinglinear and
cubic interpolation. SeetheMATLAB documentation for information on
spl i ne and i nt er p1.
4 Special Topics
4-24
Cepstrum Analysis
Cepstrumanalysis is a nonlinear signal processingtechniquewith avariety of
applications in areas such as speech and imageprocessing. TheSignal
ProcessingToolbox provides threefunctions for cepstrumanalysis.
Thecomplex cepstrumfor a sequencex is calculated by findingthecomplex
natural logarithmof theFourier transformof x, then theinverseFourier
transformof theresultingsequence.
Thetoolbox function cceps performs this operation, estimatingthecomplex
cepstrumfor an input sequence. I t returns areal sequencethesamesizeasthe
input sequence.
xhat = cceps( x)
Thecomplex cepstrumtransformation is central tothetheory and application
of homomorphic systems, that is, systems that obey certain general rules of
superposition. SeeOppenheimand Schafer [2] for a discussion of thecomplex
cepstrumandhomomorphictransformations, withdetailsonspeechprocessing
applications.
Try usingcceps in an echodetection application. First, createa 45 Hz sine
wavesampled at 100 Hz.
t = 0: 0. 01: 1. 27;
s1 = si n( 2*pi *45*t ) ;
Operation Function
Complex cepstrum cceps
I nversecomplex cepstrum i cceps
Real cepstrum r ceps
x

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

=
CepstrumAnalysis
4-25
Add an echoof thesignal, with half theamplitude, 0.2 seconds after the
beginningof thesignal.
s2 = s1 + 0. 5*[ zer os( 1, 20) s1( 1: 108) ] ;
Thecomplex cepstrumof this newsignal is
c = cceps( s2) ;
pl ot ( t , c)
Notethat thecomplex cepstrumshows a peak at 0.2 seconds, indicatingthe
echo.
Thereal cepstrumof a signal x, sometimes called simply thecepstrum, is
calculated by determiningthenatural logarithmof magnitudeof theFourier
transformof x, then obtainingtheinverseFourier transformof theresulting
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

=
4 Special Topics
4-26
Thetoolbox function r ceps performs this operation, returningthereal
cepstrumfor a sequencex. Thereturned sequenceis a real-valued vector the
samesizeas theinput vector.
y = r ceps( x)
By definition, you cannot reconstruct theoriginal sequencefromits real
cepstrumtransformation, as thereal cepstrumis basedonly on themagnitude
of theFourier transformfor thesequence(seeOppenheimandSchafer [2]). The
r ceps function, however, can reconstruct a minimum-phaseversion of the
original sequenceby applyingawindowingfunction in thecepstral domain. To
obtain both thereal cepstrumand theminimumphasereconstruction for a
sequence, use
[ y, ym] = r ceps( x)
wherey is thereal cepstrumand ymis theminimumphasereconstruction of x.
Inverse Complex Cepstrum
Toinvert thecomplex cepstrum, usethei cceps function. I nversion is
complicated by thefact that thecceps function performs a data dependent
phasemodification sothat theunwrapped phaseof its input is continuous at
zerofrequency. Thephasemodification is equivalent toan integer delay. This
delay termis returned by cceps if you ask for a second output. For example,
x = 1: 10;
[ xh, nd] = cceps( x)
xh =
Col umns 1 t hr ough 7
2. 2428 - 0. 0420 - 0. 0210 0. 0045 0. 0366 0. 0788 0. 1386
Col umns 8 t hr ough 10
0. 2327 0. 4114 0. 9249
nd =
1
CepstrumAnalysis
4-27
Toinvert thecomplex cepstrum, usei cceps with theoriginal delay parameter.
i cceps( xh, nd)
ans =
Col umns 1 t hr ough 7
1. 0000 2. 0000 3. 0000 4. 0000 5. 0000 6. 0000 7. 0000
Col umns 8 t hr ough 10
8. 0000 9. 0000 10. 0000
Note With any modification of thecomplex cepstrum, theoriginal delay term
may nolonger bevalid. Usethei cceps function with care.
4 Special Topics
4-28
FFT-Based Time-Frequency Analysis
TheSignal ProcessingToolbox provides a function, specgr am, that returns the
time-dependent Fourier transformfor asequence, or displays this information
as a spectrogram. Thetime-dependent Fourier transformis thediscrete-time
Fourier transformfor asequence, computedusingaslidingwindow. This form
of theFourier transform, alsoknown as theshort-timeFourier transform
(STFT), hasnumerousapplicationsinspeech, sonar, andradar processing. The
spectrogramof a sequenceis themagnitudeof thetime-dependent Fourier
transformversus time.
Todisplay thespectrogramof a linear FM signal
f s = 10000;
t = 0: 1/ f s: 2;
x = vco( sawt oot h( 2*pi *t , . 75) , [ 0. 1 0. 4] *f s, f s) ;
specgr am( x, 512, f s, kai ser ( 256, 5) , 220)
Notethat thespectrogramdisplay 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
Median Filtering
4-29
Median Filtering
Thefunction medf i l t 1 implements one-dimensional median filtering, a
nonlinear techniquethat applies a slidingwindowtoa sequence. Themedian
filter replaces thecenter valuein thewindowwith themedian valueof all the
points within thewindow[4]. I n computingthis median, medf i l t 1 assumes
zeros beyond theinput points.
When thenumber of elements n in thewindowis even, medf i l t 1 sorts the
numbers, then takes theaverageof the( n- 1) / 2 and ( n- 1) / 2 +1 elements.
Twosimpleexamples with fourth- and third-order median filters are
medf i l t 1( [ 4 3 5 2 8 9 1] , 4)
ans =
1. 500 3. 500 3. 500 4. 000 6. 500 5. 000 4. 500
medf i l t 1( [ 4 3 5 2 8 9 1] , 3)
ans =
3 4 3 5 8 8 1
SeetheI mageProcessingToolbox Users Guidefor information on
two-dimensional median filtering.
4 Special Topics
4-30
Communications Applications
Thetoolbox provides threefunctions for communications simulation.
Modulation varies theamplitude, phase, or frequency of a carrier signal with
referencetoa messagesignal. Themodul at e function modulates a message
signal with a specified modulation method.
Thebasic syntax for themodul at e function is
y = modul at e( x, f c, f s, ' met hod' , opt )
where:
x is themessagesignal.
f c is thecarrier frequency.
f s is thesamplingfrequency.
met hod is a flagfor thedesired modulation method.
opt is any additional argument that themethod requires. (Not all
modulation methods requirean option argument.)
Thetablebelowsummarizes themodulation methods provided; seethe
documentation for modul at e, demod, and vco for completedetails on each.
Operation Function
Modulation modul at e
Demodulation demod
Voltagecontrolled oscillation vco
Method Description
amdsb- sc or am Amplitudemodulation, doubleside-band, suppressed
carrier
amdsb- t c Amplitudemodulation, doubleside-band, transmitted
carrier
Communications Applications
4-31
I f theinput x is an array rather than a vector, modul at e modulates each
column of thearray.
Toobtain thetimevector that modul at e uses tocomputethemodulatedsignal,
specify a second output parameter.
[ y, t ] = modul at e( x, f c, f s, ' met hod' , opt )
Thedemod function performs demodulation, that is, it obtains theoriginal
messagesignal fromthemodulated signal.
Thesyntax for demod is
x = demod( y, f c, f s, ' met hod' , opt )
demod uses any of themethods shown for modul at e, but thesyntax for
quadratureamplitudedemodulation requires twooutput parameters.
[ X1, X2] = demod( y, f c, f s, ' qam' )
I f theinput y is an array, demod demodulates all columns.
Try modulatingand demodulatinga signal. A 50 Hz sinewavesampled at
1000 Hz is
t = ( 0: 1/ 1000: 2) ;
x = si n( 2*pi *50*t ) ;
amssb Amplitudemodulation, singleside-band
f m Frequency modulation
pm Phasemodulation
pt m Pulsetimemodulation
pwm Pulsewidth modulation
qam Quadratureamplitudemodulation
Method Description
4 Special Topics
4-32
With a carrier frequency of 200 Hz, themodulated and demodulated versions
of this signal are
y = modul at e( x, 200, 1000, ' am' ) ;
z = demod( y, 200, 1000, ' am' ) ;
Toplot portions of theoriginal, modulated, and demodulated signal
f i gur e; pl ot ( t ( 1: 150) , x( 1: 150) ) ; t i t l e( ' Or i gi nal Si gnal ' ) ;
f i gur e; pl ot ( t ( 1: 150) , y( 1: 150) ) ; t i t l e( ' Modul at ed Si gnal ' ) ;
f i gur e; pl ot ( t ( 1: 150) , z( 1: 150) ) ; t i t l e( ' Demodul at ed Si gnal ' ) ;
Thevoltagecontrolledoscillator function vco creates asignal that oscillates at
a frequency determined by theinput vector. Thebasic syntax for vco is
y = vco( x, f c, f s)
wheref c is thecarrier frequency and f s is thesamplingfrequency.
0 0.02 0.04 0.06 0.08 0.1 0.12 0.14 0.16
1
0.8
0.6
0.4
0.2
0
0.2
0.4
0.6
0.8
1
Original Signal
0 0.02 0.04 0.06 0.08 0.1 0.12 0.14 0.16
1
0.8
0.6
0.4
0.2
0
0.2
0.4
0.6
0.8
1
Modulated Signal
0 0.02 0.04 0.06 0.08 0.1 0.12 0.14 0.16
0.8
0.6
0.4
0.2
0
0.2
0.4
0.6
Demodulated Signal
Communications Applications
4-33
Toscalethefrequency modulation range, use
y = vco( x, [ Fmi n Fmax] , f s)
I n this case, vco scales thefrequency modulation rangesovalues of x on the
interval [ - 1 1] map tooscillations of frequency on [ Fmi n Fmax] .
I f theinput x is an array, vco produces an array whosecolumns oscillate
accordingtothecolumns of x.
SeeFFT-Based Time-Frequency Analysison page4-28for an exampleusing
thevco function.
4 Special Topics
4-34
Deconvolution
Deconvolution, or polynomial division, is theinverseoperation of convolution.
Deconvolution is useful in recoveringtheinput toa known filter, given the
filtered output. This method is very sensitivetonoisein thecoefficients,
however, sousecaution in applyingit.
Thesyntax for deconv is
[ q, r ] = deconv( b, a)
whereb is thepolynomial dividend, a is thedivisor, q is thequotient, and r is
theremainder.
Totry deconv, first convolvetwosimplevectors a andb (seeChapter 1, Signal
ProcessingBasics, for a description of theconvolution function).
a = [ 1 2 3] ;
b = [ 4 5 6] ;
c = conv( a, b)
c =
4 13 28 27 18
Nowusedeconv todeconvolveb fromc.
[ q, r ] = deconv( c, a)
q =
4 5 6
r =
0 0 0 0 0
SeetheSystemI dentification Toolbox Users Guidefor advanced applications
of signal deconvolution.
Specialized Transforms
4-35
Specialized Transforms
I n addition tothediscreteFourier transform(DFT) described in Chapter 1,
Signal ProcessingBasics, theSignal ProcessingToolbox and theMATLAB
environment together providethefollowingtransformfunctions:
Thechirp z-transform(CZT), useful in evaluatingthez-transformalong
contours other than theunit circle. Thechirp z-transformis alsomore
efficient than theDFT algorithmfor thecomputation of prime-length
transforms, andit is useful in computinga subset of theDFT for a sequence.
Thediscretecosinetransform(DCT), closely related totheDFT. TheDCTs
energy compaction properties areuseful for applications likesignal coding.
TheHilbert transform, which facilitates theformation of theanalyticsignal.
Theanalytic signal is useful in thearea of communications, particularly in
bandpass signal processing.
Chirp z-Transform
Thechirpz-transform, or CZT, computes thez-transformalongspiral contours
in thez-planefor an input sequence. UnliketheDFT, theCZT is not
constrained tooperatealongtheunit circle, but can evaluatethe z-transform
alongcontours described by
whereA is thecomplex startingpoint, Wis a complex scalar describingthe
complex ratiobetween points on thecontour, and M is thelength of the
transform.
Onepossiblespiral is
A = 0. 8*exp( j *pi / 6) ;
W= 0. 995*exp( - j *pi *. 05) ;
M = 91;
z = A*( W. ^( - ( 0: M- 1) ) ) ;
zpl ane( [ ] , z. ' )
z
l
AW
l
l 0 M 1 , , = , =
4 Special Topics
4-36
czt ( x, M, W, A) computes thez-transformof x on thesepoints.
An interestinganduseful spiral set is mevenlyspacedsamples aroundtheunit
circle, parameterizedbyA = 1andW= exp( - j *pi / M) . Thez-transformonthis
contour is simply theDFT, obtained by
y = czt ( x)
czt may befaster than thef f t function for computingtheDFT of sequences
with certain odd lengths, particularly longprime-length sequences.
-1.5 -1 -0.5 0 0.5 1 1.5
-1
-0.5
0
0.5
1
Real part
I
m
a
g
i
n
a
r
y

p
a
r
t
Specialized Transforms
4-37
Discrete Cosine Transform
Thetoolbox function dct computes theunitary discretecosinetransform, or
DCT, for an input vector or matrix. Mathematically, theunitary DCT of an
input sequencex is
where
TheDCT is closely related tothediscreteFourier transform; theDFT is
actually onestep in thecomputation of theDCT for a sequence. TheDCT,
however, has better energy compaction properties, with just a fewof the
transformcoefficients representingthemajority of theenergy in thesequence.
Theenergy compaction properties of theDCT makeit useful in applications
such as data communications.
Thefunction i dct computes theinverseDCT for an input sequence,
reconstructinga signal froma completeor partial set of DCT coefficients. The
inversediscretecosinetransformis
where
y k ( ) w k ( ) x n ( )
2n 1 ( ) k 1 ( )
2N
------------------------------------------ - cos
n 1 =
N

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






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

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






=
4 Special Topics
4-38
Becauseof theenergycompactionmentionedabove, it ispossibletoreconstruct
a signal fromonly a fraction of its DCT coefficients. For example, generatea
25 Hz sinusoidal sequence, sampled at 1000 Hz.
t = ( 0: 1/ 999: 1) ;
x = si n( 2*pi *25*t ) ;
ComputetheDCT of this sequenceandreconstruct thesignal usingonly those
components with valuegreater than 0.1 (64 of theoriginal 1000 DCT
coefficients).
y = dct ( x) %Comput e DCT
y2 = f i nd( abs( y) < 0. 9) ; %Use 17 coef f i ci ent s
y( y2) = zer os( si ze( y2) ) ; %Zer o out poi nt s < 0. 9
z = i dct ( y) ; %Reconst r uct si gnal usi ng i nver se DCT
Plot theoriginal and reconstructed sequences.
subpl ot ( 2, 1, 1) ; pl ot ( t , x) ;
t i t l e( ' Or i gi nal Si gnal ' )
subpl ot ( 2, 1, 2) ; pl ot ( t , z) , axi s( [ 0 1 - 1 1] )
t i t l e( ' Reconst r uct ed Si gnal ' )
0 0.2 0.4 0.6 0.8 1
1
0.5
0
0.5
1
Original Signal
0 0.2 0.4 0.6 0.8 1
1
0.5
0
0.5
1
Reconstructed Signal
Specialized Transforms
4-39
Onemeasureof theaccuracy of thereconstruction is
nor m( x- z) / nor m( x)
that is, thenormof thedifferencebetween theoriginal and reconstructed
signals, divided by thenormof theoriginal signal. I n this case, therelative
error of reconstruction is 0.1443. Thereconstructed signal retains
approximately 85%of theenergy in theoriginal signal.
Hilbert Transform
Thetoolbox function hi l ber t computes theHilbert transformfor a real input
sequencex and returns a complex result of thesamelength
y = hi l ber t ( x)
wherethereal part of y is theoriginal real data and theimaginary part is the
actual Hilbert transform. y issometimescalledtheanalyticsignal, inreference
tothecontinuous-timeanalytic signal. A key property of thediscrete-time
analytic signal is that its z-transformis 0 on thelower half of theunit circle.
Many applications of theanalytic signal arerelated tothis property; for
example, theanalyticsignal is useful in avoidingaliasingeffects for bandpass
samplingoperations. Themagnitudeof theanalytic signal is thecomplex
envelopeof theoriginal signal.
TheHilbert transformis related totheactual data by a 90 phaseshift; sines
becomecosines and viceversa. Toplot a portion of data (solid line) and its
Hilbert transform(dotted line)
t = ( 0: 1/ 1023: 1) ;
x = si n( 2*pi *60*t ) ;
y = hi l ber t ( x) ;
pl ot ( t ( 1: 50) , r eal ( y( 1: 50) ) ) , hol d on
pl ot ( t ( 1: 50) , i mag( y( 1: 50) ) , ' : ' ) , hol d of f
4 Special Topics
4-40
Theanalytic signal is useful in calculatinginstantaneous attributes of a time
series, theattributes of theseries at any point in time. Theinstantaneous
amplitudeof theinput sequenceis theamplitudeof theanalytic signal. The
instantaneous phaseangleof theinput sequenceis the(unwrapped) angl e of
theanalytic signal; theinstantaneous frequency is thetimerateof changeof
theinstantaneous phaseangle. You can calculatetheinstantaneous frequency
usingdi f f , as described in theMATLAB documentation.
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
Selected Bibliography
4-41
Selected Bibliography
[1] Kay, S.M. ModernSpectral Estimation. EnglewoodCliffs, NJ : PrenticeHall,
1988.
[2] Oppenheim, A.V., and R.W. Schafer. Discrete-TimeSignal Processing.
Englewood Cliffs, NJ : PrenticeHall, 1989.
[3] Parks, T.W., and C.S. Burrus. Digital Filter Design. NewYork: J ohn Wiley
& Sons, 1987.
[4] Pratt,W.K. Digital I mageProcessing. NewYork: J ohn Wiley & Sons, 1991.
4 Special Topics
4-42
5
Filter DesignandAnalysis
Tool
Overview . . . . . . . . . . . . . . . . . . . . . 5-2
OpeningtheFilter Design and Analysis Tool . . . . . 5-5
GettingHelp . . . . . . . . . . . . . . . . . . . . 5-6
Choosinga Filter Type . . . . . . . . . . . . . . . 5-7
Choosinga Filter Design Method . . . . . . . . . . 5-8
SettingtheFilter Design Specifications . . . . . . . 5-9
ComputingtheFilter Coefficients . . . . . . . . . . 5-12
AnalyzingtheFilter . . . . . . . . . . . . . . . . 5-13
ConvertingtheFilter Structure . . . . . . . . . . . 5-14
Importinga Filter Design . . . . . . . . . . . . . . 5-16
Exportinga Filter Design . . . . . . . . . . . . . . 5-19
Savingand OpeningFilter Design Sessions . . . . . . 5-21
5 Filter Design and Analysis Tool
5-2
Overview
You can usetheFilter Design and Analysis Tool (FDATool) as a convenient
alternativetothecommand linefilter design functions. This chapter contains
thefollowingsections, which walk you through a typical filter design session
usingtheFDATool:
OpeningtheFilter Design and Analysis Tool
GettingHelp
Choosinga Filter Type
Choosinga Filter Design Method
SettingtheFilter Design Specifications
ComputingtheFilter Coefficients
AnalyzingtheFilter
ConvertingtheFilter Structure
I mportinga Filter Design
Exportinga Filter Design
Savingand OpeningFilter Design Sessions
Belowis a brief introduction totheFDATool that will giveyou a better
understandingof howit can beused.
Filter Design Methods
Thetool gives you access toall of thefilter design methods in theSignal
ProcessingToolbox:
Butterworth (but t er )
Chebyshev typeI (cheby1)
Chebyshev typeI I (cheby2)
Elliptic (el l i p)
Equiripple(r emez)
Least squares (f i r l s)
Windows
- Bartlett (bar t l et t , f i r 2)
- Blackman (bl ackman, f i r 2)
5-3
- Boxcar (boxcar , f i r 2)
- Chebyshev (chebwi n, f i r 2)
- Hamming(hammi ng, f i r 2)
- Hann (hann, f i r 2)
- Kaiser (kai ser , f i r 1)
- Triangular (t r i ang, f i r 1)
Additional filter design methods areavailabletousers of theFilter Design
Toolbox.
Using the Filter Design and Analysis Tool
Therearedifferent waysthat youcandesignfiltersusingtheFilter Designand
Analysis Tool. For example:
Youcan first chooseafilter type, suchas bandpass, andthen choosefromthe
availableFI R or I I R filter design methods.
You can specify thefilter by its typealone, alongwith certain frequency- or
time-domain specifications such as passband frequencies and stopband
frequencies. Thefilter you design is then computed usingthedefault filter
design method and filter order.
Analyzing Filter Responses
Onceyou havedesigned your filter, you can analyzedifferent filter responses:
Magnituderesponse(f r eqz)
Phaseresponse(f r eqz)
Pole-zeroplots (zpl ane)
I mpulseresponse(i mpz)
Group delay (gr pdel ay)
Step response
You can alsodisplay thefilter coefficients.
Filter Design and Analysis Tool Modes
TheFilter Design and Analysis Tool operates in twomodes:
5 Filter Design and Analysis Tool
5-4
Design mode. I n this mode, you can:
- Design filters fromscratch.
- Modify existingfilters designed by FDATool.
- Analyzefilters.
I mport mode. I n this mode, you can:
- I mport previouslysavedfilters or filter coefficients that you havestoredin
theMATLAB workspace.
- Analyzeimported filters.
Thereis onemoremodeavailabletoyou if you alsohavetheFilter Design
Toolbox: thequantizemode. Usethis modeto:
Quantizedouble-precision filters that you design in FDATool.
Quantizedouble-precision filters that you import intoFDATool.
Analyzequantized filters.
Getting Help
At any time, you can right-click or press theWhats this? button, , toget
information on thedifferent parts of theGUI .
Opening the Filter Design and Analysis Tool
5-5
Opening the Filter Design and Analysis Tool
Toopen theFilter Design and Analysis Tool, type
f dat ool
TheFilter Design and Analysis Tool opens in thedefault design mode.
Chooseananalysis methodfor
analyzingthefilter design.
Choosethetypeof filter
to design.
Choosethefilter design
methodto use
PressDesignFilter to
computethefilter
coefficients.
Select theWhats this? buttonandclick ona region
of theGUI toaccess context-sensitivehelp.
Set quantization
parameters for theFilter
DesignToolbox.
Set filter specifications. Thesedependon
thetypeof filter youaredesigning, as
well asthedesignmethodyouspecify.
Specify a filter order or
allowit to beestimated.
Zoomin/out.
UsetheFilter menuto
choosebetweenimporting
filter coefficients fromthe
MATLABworkspaceand
designingthefilter inthe
GUI.
Set windowspecifications
for theFIRWindow
design.
Quantizethecurrent filter
usingtheFilter Design
Toolbox.
5 Filter Design and Analysis Tool
5-6
Getting Help
UsetheWhats this? button tofind out moreinformation about a particular
region of FDATool.
Context-Sensitive Help: The Whats This? Button
Tofind information on a particular region of theGUI :
1 Select theWhats this? button with your mouse.
2 Click on theregion of theGUI you want information on.
You can alsoright-click a region of theGUI or select Whats this? fromthe
Help menu tolaunch context-sensitivehelp.
Choosing a Filter Type
5-7
Choosing a Filter Type
You can choosefromseveral filter types:
Lowpass
Highpass
Bandpass
Bandstop
Differentiator
Hilbert transformer
Multiband
Arbitrary magnitude
Todesign a bandpass filter, select theradiobutton next toBandpass in the
Filter Typeregion of theGUI .
Note Not all filter design methods areavailablefor all filter types. Onceyou
chooseyour filter type, this may restrict thefilter design methods availableto
you. Filter design methods that arenot availablefor a selected filter typeare
dimmed in theMethod menu, and removed fromtheDesign Method region
of theGUI .
You can alsousetheTypemenu toselect a filter type.
5 Filter Design and Analysis Tool
5-8
Choosing a Filter Design Method
You can usethedefault filter design method for thefilter typethat youve
selected, or youcanselect afilter designmethodfromtheavailableFI R andI I R
methods listed in theGUI .
Toselect theRemez algorithmtocomputeFI R filter coefficients, select theFIR
radiobutton and chooseEqui r i ppl e fromthelist of methods.
You can alsousetheMethod menu toselect a filter design method.
Setting the Filter Design Specifications
5-9
Setting the Filter Design Specifications
Thefilter designspecificationsthat youcanset varyaccordingtofilter typeand
design method. For example, todesign a bandpass filter, you can enter:
Frequency specifications
Magnitudespecifications
Filter order
Thedisplay region illustrates filter specifications when you select Filter
Specifications fromtheAnalysis menu.
Bandpass Filter Frequency Specifications
For a bandpass filter, you can set:
Units of frequency:
- Hz
- kHz
- MHz
- Normalized (0 to1)
Samplingfrequency
Passband frequencies
Stopband frequencies
5 Filter Design and Analysis Tool
5-10
You specifythepassbandwith twofrequencies. Thefirst frequencydetermines
thelower edgeof thepassband, andthesecondfrequencydeterminestheupper
edgeof thepassband.
Similarly, you specify thestopband with twofrequencies. Thefirst frequency
determines theupper edgeof thefirst stopband, and thesecond frequency
determines thelower edgeof thesecond stopband.
For this example:
Keep theunits in Hz (default).
Set thesamplingfrequency (Fs) to2000 Hz.
Set theend of thefirst stopband (Fstop1) to200 Hz.
Set thebeginningof thepassband (Fpass1) to300 Hz.
Set theend of thepassband (Fpass2) to700 Hz.
Set thebeginningof thesecond stopband (Fstop2) to800 Hz.
Bandpass Filter Magnitude Specifications
For a bandpass filter, you can specify thefollowingmagnituderesponse
characteristics:
Units for themagnituderesponse(dB or linear)
Passband ripple
Stopband attenuation
Setting the Filter Design Specifications
5-11
For this example:
Keep theunits in dB (default).
Set thepassband ripple(Apass) to0. 1 dB.
Set thestopband attenuation for both stopbands (Astop1, Astop2) to75 dB.
Filter Order
You havetwomutually exclusiveoptions for determiningthefilter order when
you design an equiripplefilter:
Minimumorder: Thefilter design method determines theminimumorder
filter.
Specify order: You enter thefilter order in a text box.
Select theMinimumorder radiobutton for this example.
Notethat filter order specification options depend on thefilter design method
you choose. Somefilter methods may not haveboth options available.
5 Filter Design and Analysis Tool
5-12
Computing the Filter Coefficients
Nowthat youvespecified thefilter design, select theDesign Filter button to
computethefilter coefficients.
Noticethat theDesign Filter button is dimmed onceyouvecomputed the
coefficients for your filter design. This button is enabled again onceyou make
any changes tothefilter specifications.
Analyzing the Filter
5-13
Analyzing the Filter
Onceyouvedesigned thefilter, you can viewthefollowingfilter response
characteristics in thedisplay region:
Magnituderesponse
Phaseresponse
Overlaid magnitudeand phaseresponses
Group delay
I mpulseresponse
Step response
Pole-zeroplot
You can alsodisplay thefilter coefficients in this region.
You can access theanalysis methods as items in theAnalysis menu, or by
usingthetoolbar buttons.
For example, tolook at thefilters magnituderesponse, select theMagnitude
Responsebutton on thetoolbar.
5 Filter Design and Analysis Tool
5-14
Converting the Filter Structure
YoucanusetheConvert structurebuttontoconvert thecurrent filter toanew
structure. All filters can beconverted tothefollowingrepresentations:
Di r ect f or mI
Di r ect f or mI I
Di r ect f or mI t r ansposed
Di r ect f or mI I t r ansposed
St at e- space
Lat t i ce ARMA
I n addition, thefollowingconversions areavailablefor particular classes of
filters:
MinimumphaseFI R filters can beconverted toLat t i ce MA ( mi n. phase)
MaximumphaseFI R filters can beconverted toLat t i ce MA ( max. phase)
Allpass filters can beconverted toLat t i ce al l pass
I I R filters can beconverted toLat t i ce ARMA
When selected, theUsesecond-order sections check box instructs thetool to
storetheconverted filter structureas a collection of second-order sections
rather than as a monolithic higher-order structure. Thesubordinate Scale
menu lets you select fromthefollowingoptions.
None (default)
L- 2 (L
2
norm)
L- i nf i ni t y (L

norm)
Theorderingof thesecond-order sections is optimized for theselected scaling
option. (Thet f 2sos function that performs theconversion is calledwith option
' down' for L
2
normscaling, and with option ' up' for L

normscaling.)
For example:
Press theConvert structurebutton toopen theConvert structuredialog
box.
Select Di r ect f or mI in thelist of filter structures.
Converting the Filter Structure
5-15
Select theUsesecond-order sections check box.
Select L- i nf i ni t y fromtheScalemenu for L

normscaling.
5 Filter Design and Analysis Tool
5-16
Importing a Filter Design
TheImport Filter region allows you toimport a filter by specifyingthefilter
coefficients, either by enteringthemexplicitly or by referringtovariables in
theMATLAB workspace. You can accessthisregion byselectingImport Filter
fromtheFilter menu, or by pressingCtrl+I.
Theimported filter can bein any of therepresentations listed in theFilter
Structuremenu, and described in Filter Structuresbelow:
Di r ect f or mI
Di r ect f or mI I
Di r ect f or mI t r ansposed
Di r ect f or mI I t r ansposed
Di r ect f or mI I ( Second- or der sect i ons)
St at e- space
Lat t i ce al l pass
Lat t i ce MA mi n. phase
Lat t i ce MA max. phase
Lat t i ce ARMA
Quant i zed f i l t er ( Qf i l t obj ect ) availableonly when Filter Design
Toolbox is installed
Select thefrequencyunitsfromamongthefollowingoptionsintheUnitsmenu,
and specify thevalueof thesamplingfrequency in theFs field.
Toimport thefilter, press theImport Filter button. TheDisplay Region is
automatically updated when thenewfilter has been imported.
Importing a Filter Design
5-17
Filter Structures
Thestructurethat you choosedetermines thetypeof coefficients that you need
tospecify in thetext fields totheright:
Direct Form
For Di r ect For mI , Di r ect For mI I , Di r ect For mI t r ansposed, and Di r ect
For mI I t r ansposed, specify thefilter by its transfer function representation:
TheNumerator field specifies a variablenameor valuefor thenumerator
coefficient vector b, which containsm+1 coefficientsindescendingpowersof z.
TheDenominator field specifies a variablenameor valuefor the
denominator coefficient vector a, which contains n+1 coefficients in
descendingpowers of z. For FI R filters, theDenominator is 1.
Filtersintransfer functionformcanbeproducedbyall of theSignal Processing
Toolbox filter design functions (e.g., f i r 1, f i r 2, r emez, but t er , yul ewal k). See
Transfer Functionon page1-33 for moreinformation.
Direct Form II (Second-Order Sections)
For Di r ect f or mI I ( Second- or der sect i ons) , specify thefilter by its
second-order section representation:
TheGain fieldspecifies avariablenameor avaluefor thegain g, andtheSOS
Matrix field specifies a variablenameor a valuefor theL-by-6 SOS matrix
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
+ + +
--------------------------------------------------------------------------------------- = =
H z ( ) g H
k
z ( )
k 1 =
L

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

= =
SOS
b
01
b
11
b
21
1 a
11
a
21
b
02
b
12
b
22
1 a
12
a
22

b
0L
b
1L
b
2L
1 a
1L
a
2L
=
5 Filter Design and Analysis Tool
5-18
whoserows contain thenumerator and denominator coefficients b
ik
and a
ik
of
thesecond-order sections of H(z).
Filters in second-order section formcan beproduced by functions such as
t f 2sos, zp2sos, ss2sos, and sosf i l t . SeeSecond-Order Sections (SOS) on
page1-38 for moreinformation.
State-Space
For St at e- Space, specify thefilter by its state-spacerepresentation:
TheA, B, C, and D fields each specify a variablenameor a valuefor the
matrices in this system.
Filters in state-spaceformcan beproduced by functions such as t f 2ss and
zp2ss. SeeState-Spaceon page1-35 for moreinformation.
Lattice
For Lat t i ce al l pass, Lat t i ce MA, and Lat t i ce ARMA filters, specify thefilter
by its latticerepresentation:
For Lat t i ce al l pass, theLatticecoeff field specifies thelattice(reflection)
coefficients, k( 1) tok( N) , wereNis thefilter order.
For Lat t i ce MA (minimumor maximumphase), theLatticecoeff field
specifies thelattice(reflection) coefficients, k( 1) tok( N) , wereNis thefilter
order.
For Lat t i ce ARMA, theLatticecoeff field specifies thelattice(reflection)
coefficients, k( 1) tok( N) , and theLadder coeff field specifies theladder
coefficients, v( 1) tov( N+1) , wereNis thefilter order.
Filters in latticeformcan beproduced by t f 2l at c. SeeLatticeStructureon
page1-38 for moreinformation.
Quantized Filter (Qfilt Object)
For Quant i zedf i l t er , specifythefilter asaQfilt object. Seeqf i l t intheFilter
Design Toolbox for moreinformation.
x

Ax Bu + =
y Cx Du + =
Exporting a Filter Design
5-19
Exporting a Filter Design
You can saveyour filter design by:
Exportingthefilter coefficients totheMATLAB workspace
Exportingthefilter coefficients toa text file
Exportingthefilter coefficients toa MAT-file
Tosaveyour filter coefficients toa fileor theworkspace, select Export under
theFilemenu.
Lets export thefilter coefficients totheworkspace.
Exporting Filter Coefficients to the Workspace
Tosavefilter coefficients as variables in theMATLAB workspace:
Select Export fromtheFilemenu. TheExport dialogbox appears.
Select WorkspacefromtheExport To menu.
Assign variablenames usingthetext boxes in theVariableNames region.
Press theOK button.
5 Filter Design and Analysis Tool
5-20
Exporting Filter Coefficients to a Text File
Tosavefilter coefficients toa text file:
Select Export fromtheFile menu. TheExport dialogbox appears.
Select Text-filefromtheExport To menu.
Press theOK button. TheExport Filter Coefficients to a Text-filedialog
box appears.
Choosea filenameand press Save.
Thecoefficients aresaved in thetext filethat you specified, and theMATLAB
Editor opens todisplay thefile.
Saving and Opening Filter Design Sessions
5-21
Saving and Opening Filter Design Sessions
You can saveyour filter design session as a MAT-fileand return tothesame
session another time.
Select theSavesessionbutton tosaveyour sessionasaMAT-file. Thefirst
timeyou savea session, a SaveFilter Design Filebrowser opens, prompting
you for a session name.
For example, savethis design session as Test Fi l t er . f da in your current
workingdirectory by typingTest Fi l t er in theFilename field.
The. f da extension is addedautomaticallytoall filter design sessions you save.
Note You can alsousetheSavesession and Savesession as menu items in
theFilemenu tosavea session. This dialogopens every timeyou select the
SaveAs menu item.
You can load existingsessions intotheFilter Design and Analysis Tool by
selectingtheOpen session button, . A Load Filter Design Filebrowser
opens that allows you toselect fromyour previously saved filter design
sessions.
5 Filter Design and Analysis Tool
5-22
6
SPTool: A Signal
ProcessingGUI Suite
Overview . . . . . . . . . . . . . . . . . . . . . 6-2
SPTool: An InteractiveSignal ProcessingEnvironment 6-3
OpeningSPTool . . . . . . . . . . . . . . . . . . 6-5
Overviewof theSignal Browser: Signal Analysis . . . 6-6
Overviewof theFilter Designer: Filter Design . . . . 6-8
Overviewof theFilter Viewer: Filter Analysis . . . . 6-11
Overviewof theSpectrumViewer: Spectral Analysis . 6-14
GettingHelp . . . . . . . . . . . . . . . . . . . . 6-17
UsingSPTool: Filteringand Analysis of Noise . . . . . 6-18
Importinga Signal into SPTool . . . . . . . . . . . 6-19
Designinga Filter . . . . . . . . . . . . . . . . . 6-22
Applyinga Filter to a Signal . . . . . . . . . . . . . 6-24
AnalyzingSignals: OpeningtheSignal Browser . . . . 6-26
Spectral Analysis in theSpectrumViewer . . . . . . 6-29
ExportingSignals, Filters, and Spectra . . . . . . . . 6-32
Designinga Filter with thePole/Zero Editor . . . . . 6-34
Redesigninga Filter UsingtheMagnitudePlot . . . . 6-37
6 SPTool: A Signal Processing GUI Suite
6-2
Overview
SPTool is a graphical user interface(GUI ) for analyzingand manipulating
digital signals, filters, and spectra. Thefirst fewsections of this chapter give
an overviewof SPTool and its associated GUI s:
SPTool: An I nteractiveSignal ProcessingEnvironment
OpeningSPTool
Overviewof theSignal Browser: Signal Analysis
Overviewof theFilter Designer: Filter Design
Overviewof theFilter Viewer: Filter Analysis
Overviewof theSpectrumViewer: Spectral Analysis
GettingHelp
Therest of this chapter illustrates in detail howtousetheGUI -based
interactivetools by walkingthrough someexamples:
UsingSPTool: Filteringand Analysis of Noise
I mportinga Signal intoSPTool
Designinga Filter
Applyinga Filter toa Signal
AnalyzingSignals: OpeningtheSignal Browser
Spectral Analysis in theSpectrumViewer
ExportingSignals, Filters, and Spectra
Designinga Filter with thePole/ZeroEditor
Redesigninga Filter UsingtheMagnitudePlot
AccessingFilter Parameters in a Saved Filter
AccessingParameters in a Saved Spectrum
I mportingFilters and Spectra intoSPTool
LoadingVariables fromtheDisk
SelectingSignals, Filters, and Spectra in SPTool
EditingSignals, Filters, or Spectra in SPTool
SettingPreferences
MakingSignal Measurements: UsingMarkers
SPTool: An Interactive Signal Processing Environment
6-3
SPTool: An Interactive Signal Processing Environment
SPTool is an interactiveGUI for digital signal processingthat can beused to:
Analyzesignals.
Design filters.
Analyze(view) filters.
Filter signals.
Analyzesignal spectra.
You can accomplish thesetasks usingfour GUI s that you access fromwithin
SPTool:
TheSignal Browser is for analyzingsignals. You can alsoplay portions of
signals usingyour computers audiohardware.
TheFilter Designer is for designingor editingthefollowingtypes of FI R and
I I R digital filters:
- Lowpass
- Highpass
- Bandpass
- Bandstop
Most of theSignal ProcessingToolbox filter design methods availableat the
commandlinearealsoavailablein theFilter Designer. Additionally, you can
design a filter by usingthePole-ZeroEditor tographically placepoles and
zeros on thez-plane.
TheFilter Viewer is for analyzingfilter characteristics. You can analyzea
filters:
- Magnituderesponse
- Phaseresponse
- Group delay
- Pole/zeroplot
- I mpulseresponse
- Step response
6 SPTool: A Signal Processing GUI Suite
6-4
TheSpectrumViewer is for spectral analysis. You can usetheSignal
ProcessingToolbox spectral estimation methods toestimatethepower
spectral density of a signal.
SPTool Data Structures
You can useSPTool toanalyzesignals, filters, or spectrathat you createat the
MATLAB command line.
You can bringsignals, filters, or spectrafromtheMATLAB workspaceintothe
SPTool workspaceusingtheImport itemunder theFilemenu. Signals, filters,
or spectra that you createin (or import into) theSPTool workspaceexist as
MATLAB structures. SeetheMATLAB documentationfor moreinformationon
MATLAB structures.
WhenyouusetheExport itemunder theFilemenutosavesignals, filters, and
spectra that you createor modify in SPTool, thesearealsosaved as MATLAB
structures.
Opening SPTool
6-5
Opening SPTool
Toopen SPTool, type
spt ool
TheSPTool interfaceis shown below.
When you first open SPTool, it contains a collection of default signals, filters,
andspectra. You can specifyyour own preferences for what signals, filters, and
spectra you want toseewhen SPTool opens. SeeSettingPreferenceson page
6-50 for moredetails.
You can access four other GUI s fromSPTool:
Signal Browser fromtheSignals list Viewbutton
Filter Designer fromtheFilters list NewDesign or Edit Design button
Filter Viewer fromtheFilters list Viewbutton
SpectrumViewer fromtheSpectra list View, Create, or Updatebutton
OpentheFilter Viewer to
analyzeselectedfilters.
OpentheFilter
Designer.
Apply a selected
filter to a selected
signal.
OpentheSpectrum
Viewer to analyze
selectedspectra.
OpentheSpectrum
Viewer without
computinga spectral
estimate.
Select oneor moreitems inany
of thethreelists for usewith
most SPTool operations.
OpentheSignal Browser.
OpentheSpectrum
Viewer andcreatethe
power spectral
density estimateof
theselectedsignal.
OpentheFilter
Designer to edit any
selectedfilters.
6 SPTool: A Signal Processing GUI Suite
6-6
Overview of the Signal Browser: Signal Analysis
You can usetheSignal Browser todisplay and analyzesignals listed in the
Signals list box in SPTool.
UsingtheSignal Browser you can:
Analyzeand comparevector or array (matrix) signals.
Zoomin on portions of signal data.
Measurea variety of characteristics of signal data.
Comparemultiplesignals.
Play portions of signal data on audiohardware.
Print signal plots.
Opening the Signal Browser
You can open theSignal Browser fromSPTool by:
1 Selectingoneor moresignals in theSignals list in SPTool
2 PressingtheViewbutton under theSignals list
TheSignal Browser has thefollowingcomponents:
A display region for analyzingsignals, includingmarkers for measuring,
comparing, or playingsignals
A toolbar providingconvenient access tofrequently used functions:
- Zoombuttons for gettinga closer look at signal features
- A button for printingsignal plots
- A button for playingportions of aselectedsignal through audioequipment
A panner that displays theentiresignal length, highlightingtheportion
currently activein thedisplay region
Overview of the Signal Browser: Signal Analysis
6-7
Togglemarkersonor off
Marker measurements
Panner
Display region
Context-sensitivehelp
Play buttonfor
audio signals
Signal Display
buttons
Print button
Choosethedisplay color andline
styleof a selectedsignal.
Select oneof several
loadedsignals.
Zoombuttons
6 SPTool: A Signal Processing GUI Suite
6-8
Overview of the Filter Designer: Filter Design
TheFilter Designer provides an interactivegraphical environment for the
design of digital I I R and FI R filters basedon specifications that you enter on a
magnitudeor pole-zeroplot.
Note You can alsousetheFilter Design and Analysis Tool (FDATool)
describedin Chapter 5, Filter Design and Analysis Tool,for filter design and
analysis.
Filter Types
You can design filters of thefollowingtypes usingtheFilter Designer:
Bandpass
Lowpass
Bandstop
Highpass
FIR Filter Methods
You can usethefollowingfilter methods todesign FI R filters:
Equiripple
Least squares
Window
IIR Filter Methods
You can usethefollowingfilter methods todesign I I R filters:
Butterworth
Chebyshev typeI
Chebyshev typeI I
Elliptic
Overview of the Filter Designer: Filter Design
6-9
Pole/ Zero Editor
You can usethePole/ZeroEditor todesign arbitrary FI R and I I R filters by
placingand movingpoles and zeros on thecomplex z-plane.
Spectral Overlay Feature
You can alsosuperimposespectra on a filters magnituderesponsetoseeif the
filteringrequirements aremet.
Opening the Filter Designer
Open theFilter Designer fromSPTool by either:
PressingtheNewDesign button in theFilterslist in SPTool
Selectinga filter you want toedit fromtheFilters list in SPTool, and then
pressingtheEdit Design button
Automaticdesigncheckbox
Zoombuttons
Specifications regionfor
settingfilter parameters
Magnituderesponseandpole-zero display area
Measurements regiondisplays
filter characteristics
Apply thespecifications,
or revert to theprevious
specifications.
Zoomonpassband
Overlay existingspectra ontop
of filter response.
6 SPTool: A Signal Processing GUI Suite
6-10
TheFilter Designer has thefollowingcomponents:
A menu for selectingfilters fromthelist in SPTool
A menu for selectingdifferent filter design methods (algorithms)
A plot display region for graphically adjustingfilter magnituderesponses
Measurement lines for measuringthemagnituderesponseparameters of a
filter
A pole-zeroplot display region for graphically editingfilter designs by
manipulatingtransfer function poles and zeros
Zoombuttons for navigatingthedisplays
A Specificationsregion for viewingandmodifyingthedesign parameters or
pole-zerolocations of thecurrent filter
A Measurements region for viewingtheresponsecharacteristics and
stability of thecurrent filter
Overview of the Filter Viewer: Filter Analysis
6-11
Overview of the Filter Viewer: Filter Analysis
You can usetheFilter Viewer toanalyzethefollowingresponsecharacteristics
of selected filters:
Magnituderesponse
Phaseresponse
I mpulseresponse
Step response
Group delay
Poleand zerolocations
TheFilter Viewer can display uptosix different responsecharacteristics plots
for a selected filter at any time. TheFilter Viewer provides features for:
Zooming
Measuringfilter responses
Overlayingfilter responses
Modifyingdisplay parameters such as frequency ranges or magnitudeunits
Opening the Filter Viewer
You can open theFilter Viewer fromSPTool by:
1 Selectingoneor morefilters in theFilters list in SPTool
2 PressingtheViewbutton under theFilterslist
Whenyoufirst opentheFilter Viewer, it displaysthedefault plot configuration
for theselected filter(s).
6 SPTool: A Signal Processing GUI Suite
6-12
Thefilters magnitudeand phaseplots aredisplayed by default. I n addition,
thefrequency is displayed with a linear scaleon theinterval [ 0, Fs/ 2] .
TheFilter Viewer has thefollowingcomponents:
A Plots region for selectingtheresponseplots you want todisplay in the
display area, and for specifyingsomefrequency responsedisplay
characteristics
A Frequency Axisregion for specifyingfrequencyscalingin thedisplayarea
Marker buttons for makingfilter responsemeasurements and comparisons
A filter identification region that displays information about thecurrently
selected filter(s)
Context-sensitive
help
Plots region, including
menusfor modifying
display characteristics
Frequency Axis region
Filter IDregion
Markers region
Marker
buttons
Zoombuttons
Linedisplay
preferencesbuttons
Check upto six boxes
todisplay different
filter responseplots.
Togglemarkers
onor off.
Select oneof several
loadedsignals.
Overview of the Filter Viewer: Filter Analysis
6-13
A display area for analyzingoneor morefrequency responseplots for the
selected filter(s)
Zoombuttons tonavigatethedisplays
6 SPTool: A Signal Processing GUI Suite
6-14
Overview of the Spectrum Viewer: Spectral Analysis
You can usetheSpectrumViewer for estimatingand analyzinga signals
power spectral density (PSD). You can usethePSD estimates tounderstand a
signals frequency content.
UsingtheSpectrumViewer you can:
Analyzeand comparespectral density plots.
Usedifferent spectral estimation methods tocreatespectra:
- Burg(pbur g)
- Covariance(pcov)
- FFT (f f t )
- Modified covariance(pmcov)
- MTM (multitaper method) (pmt m)
- MUSI C (pmusi c)
- Welch (pwel ch)
- Yule-Walker AR (pyul ear )
Modifypower spectral densityparameters such as FFT length, windowtype,
and samplefrequency.
Print spectral plots.
Opening the Spectrum Viewer
Toopen theSpectrumViewer and createa PSD estimatefromSPTool:
1 Select a signal fromtheSignal list box in SPTool.
2 Press theCreatebutton in theSpectra list.
3 Press theApply button in theSpectrumViewer.
Toopen theSpectrumViewer with a PSD estimatealready listed in SPTool:
1 Select a PSD estimatefromtheSpectra list box in SPTool.
2 Press theViewbutton in theSpectra list.
Overview of the SpectrumViewer: Spectral Analysis
6-15
For example:
1 Select mt l b in thedefault Signals list in SPTool.
2 Press theCreatebutton in SPTool toopen theSpectrumViewer.
3 Press theApply button in theSpectrumViewer toplot thespectrum.
TheSpectrumViewer has thefollowingcomponents:
A signal identification region that provides information about thesignal
whosepower spectral density estimateis displayed
A Parameters region for modifyingthePSD parameters
A display region for analyzingspectra
Zoombuttons for navigatingplotted spectra
Display region
Signal ID Zoombuttons
Parameters
region
Linedisplay buttons Context-sensitivehelp
Inherit PSD
estimation
parameters
fromother
PSDs.
Discardany
changes.
Createor
modify a PSD
estimate.
Select oneof several
loadedsignals.
6 SPTool: A Signal Processing GUI Suite
6-16
Marker buttons andline-display buttons for makingspectral measurements
and comparisons
Spectrummanagement controls:
- Inherit frommenu toinherit PSD specifications fromanother PSD object
listed in themenu
- Revert button torevert tothenamed PSDs original specifications
- Apply button for creatingor updatingPSD estimates
Menu options for modifyingplot display characteristics
Menu options and buttons for printingPSD plots
Getting Help
6-17
Getting Help
UsetheWhats this? button tofind out moreinformation about a particular
region of theGUI .
Context-Sensitive Help: The Whats This? Button
Tofind information on a particular region of theSignal Browser, Filter
Designer, Filter Viewer, or SpectrumViewer:
1 Press theWhats this? button, .
2 Click on theregion of theGUI you want information on.
You can alsousetheWhats this? menu itemin theHelp menu tolaunch
context-sensitivehelp.
6 SPTool: A Signal Processing GUI Suite
6-18
Using SPTool: Filtering and Analysis of Noise
Thefollowingsections providean exampleof usingtheGUI -based interactive
tools to:
Design and implement an FI R bandpass digital filter.
Apply thefilter toa noisy signal.
Analyzesignals and their spectra.
Thesteps include:
Creatinga noisy signal in theMATLAB workspaceand importingit into
SPTool
Designinga bandpass filter usingtheFilter Designer
Applyingthefilter totheoriginal noisesignal tocreatea bandlimited noise
signal
Comparingthetimedomain information of theoriginal and filtered signals
usingtheSignal Browser
Comparingthespectra of both signals usingtheSpectrumViewer
Exportingthefilter design totheMATLAB workspaceas a structure
Accessingthefilter coefficients fromtheexported MATLAB structure
Using SPTool: Filtering and Analysis of Noise
6-19
Importing a Signal into SPTool
Toimport a signal intoSPTool fromtheworkspaceor disk, thesignal must be
either:
A special MATLAB signal structure, such as that saved froma previous
SPTool session
A signal created as a variable(vector or matrix) in theMATLAB workspace
For this example, createa newsignal at thecommand lineand then import it
as a structureintoSPTool.
1 Createa randomsignal in theMATLAB workspaceby typing
r andn( ' st at e' , 0) ;
x = r andn( 5000, 1) ;
2 I f SPTool is not already open, open SPTool by typing
spt ool
TheSPTool windowis displayed.
3 Select Import fromtheFilemenu in SPTool. TheImport toSPTool dialog
opens.
6 SPTool: A Signal Processing GUI Suite
6-20
Noticethat thevariablex is displayed in theWorkspaceContents list. (I f
it is not, select theFromWorkspaceradiobutton todisplay thecontents of
theworkspace.)
4 Select thesignal and import it intotheData field:
a Makesurethat Signal is selected in theImport As pull-down menu.
b Select thesignal variablex in theWorkspaceContents list.
c Click on thearrowtotheleft of theDatafield or typex in theDatafield.
d Type5000 in theSamplingFrequency field.
e Namethesignal by typingnoi se in theName field.
f Press OK.
At this point, thesignal noi se[ vect or ] is selected in SPTools Signals list.
Select FromWorkspace todisplay all MATLAB
workspacevariables
Select FromDisk to loadthe
contents of a MAT-fileinto the
FileContents list.
Workspace Contents
(or File Contents) list
Import signals,
filters, or spectra
SPTool structures appear in
squarebrackets. Vectorsand
matrices arenot inbrackets.
Moveselecteditemsfromthe
Workspace Contents or File
Contents list to theData field.
Edit thesampling
frequency.
Edit thesignal
name.
Using SPTool: Filtering and Analysis of Noise
6-21
Note You can import filtersandspectraintoSPTool in much thesamewayas
you import signals. SeeI mportingFilters and Spectra intoSPToolon page
6-43 for specific details.
You can alsoimport signals fromMAT-files on your disk, rather than fromthe
workspace. SeeLoadingVariables fromtheDiskon page6-47 for more
information.
Typehel p spt ool for information about importingfromthecommand line.
6 SPTool: A Signal Processing GUI Suite
6-22
Designing a Filter
You can import an existingfilter intoSPTool, or you can design andedit a new
filter usingtheFilter Designer.
I n this example:
1 Open a default filter in theFilter Designer.
2 Specify an equiripplebandpass FI R filter.
Opening the Filter Designer
Toopen theFilter Designer, press theNewDesign button in SPTool. This
opens theFilter Designer with a default filter named f i l t 1.
Specifying the Bandpass Filter
Design an equiripplebandpass FI R filter with thefollowingcharacteristics:
Samplingfrequency of 5000 Hz
Stopband frequency ranges of [0 500] Hz and [1500 2500] Hz
Passband frequency rangeof [750 1250] Hz
Ripplein thepassband of 0.01 dB
Stopband attenuation of 75 dB
Tomodify your filter in theFilter Designer tomeet thesespecifications:
1 Changethefilter samplingfrequency to5000 by enteringthis valuein the
SamplingFrequency text box.
2 Select Equi r i ppl e FI R fromtheAlgorithmlist.
3 Select bandpass fromtheTypelist.
4 Set thepassbandedgefrequencies by entering750 for Fp1and1250 for Fp2.
5 Set thestopband edgefrequencies by entering500 for Fs1and 1500 for Fs2.
Designing a Filter
6-23
6 Type0. 01 intotheRp field and 75 intotheRs field.
RpsetsthemaximumpassbandrippleandRssetsthestopbandattenuation
for thefilter.
7 Press theApply button todesign thenewfilter.
When thenewfilter is designed, themagnituderesponseof thefilter is
displayed with a solid linein thedisplay region.
Theresultingfilter is an order-78 bandpass equiripplefilter.
Note You can usethesolidlinetomodify your filter design. SeeRedesigning
a Filter UsingtheMagnitudePlot on page6-37 for moreinformation.
6 SPTool: A Signal Processing GUI Suite
6-24
Applying a Filter to a Signal
When you apply a filter toa signal, you createa newsignal in SPTool
representingthefiltered signal.
Toapply thefilter f i l t 1 you just created tothesignal noi se:
1 Select SPTool fromtheWindowmenu in theFilter Designer.
2 Select thesignal noi se[ vect or ] fromtheSignals list and select thefilter
(named f i l t 1[ desi gn] ) fromtheFilters list, as shown below.
3 Press Apply toapply thefilter f i l t 1 tothesignal noi se.
TheApply Filter dialogbox is displayed.
TheAlgorithmlist providesa
choiceof several filter structures.
Typea newsignal namehere.
Applying a Filter to a Signal
6-25
4 Keep thedefault filter structureselected in theAlgorithmlist. Namethe
newsignal by typingbl noi se in theOutput Signal field in this dialogbox.
5 Press OK toclosetheApply Filter dialogbox.
Thefilter is applied totheselected signal and thefiltered signal
bl noi se[ vect or ] is listed in theSignals list in SPTool.
6 SPTool: A Signal Processing GUI Suite
6-26
Analyzing Signals: Opening the Signal Browser
You can analyzeandprint signals usingtheSignal Browser. You can alsoplay
thesignals if your computer has audiooutput capabilities.
For example, comparethesignal noi se tothefiltered signal bl noi se:
1 Shift+click on thenoi se andbl noi se signals in theSignalslist of SPTool to
select both signals.
2 Press theViewbutton under theSignals list.
TheSignal Browser is activated and both signals aredisplayed in the
display region. (Thenames of both signals areshown abovethedisplay
region.) I nitially, theoriginal noi se signal covers up thebandlimited
bl noi se signal.
3 Push theselection button on thetoolbar, , toselect thebl noi se signal.
Thedisplay area is updated. Nowyou can seethebl noi se signal
superimposed on top of thenoi se signal. Thesignals aredisplayed in
different colors in both thedisplay region and thepanner. You can change
thecolor of theselected signal usingtheLineProperties button on the
toolbar, .
Analyzing Signals: Opening the Signal Browser
6-27
Playing a Signal
When you press thePlay button in theSignal Browser toolbar, , theactive
signal is played on thecomputers audiohardware.
1 Tohear a portion of theactive(selected) signal:
a Usethevertical markerstoselect aportionof thesignal youwant toplay.
Vertical markers areenabled by the and buttons.
b Press thePlay button.
2 Tohear theother signal:
a Select thesignal as in step3above. You can alsoselect thesignal directly
in thedisplay region.
b Press thePlay button again.
6 SPTool: A Signal Processing GUI Suite
6-28
Printing a Signal
You can print fromtheSignal Browser usingthePrint button, .
You can usethelinedisplay buttons tomaximizethevisual contrast between
thesignals by settingthelinecolor for noi se togray and thelinecolor for
bl noi se towhite. Dothis beforeprintingtwosignals together.
Note You can followthesamerules toprint spectra, but you cant print filter
responses directly fromSPTool.
UsetheSignal Browser region in thePreferences dialogbox in SPTool to
suppress printingof both thepanner and themarker settings.
Toprint both signals, press thePrint button in theSignal Browser toolbar.
Spectral Analysis in the SpectrumViewer
6-29
Spectral Analysis in the Spectrum Viewer
You can analyzethefrequency content of a signal usingtheSpectrumViewer,
which estimates and displays a signals power spectral density.
For example, toanalyzeand comparethespectra of noi se and bl noi se:
1 Createa power spectral density object, spect 1, that is associated with the
signal noi se, and a second power spectral density object, spect 2, that is
associated with thesignal bl noi se.
2 Open theSpectrumViewer toanalyzeboth of thesespectra.
3 Print both spectra.
Creating a PSD Object From a Signal
1 Click onSPTool, or select SPTool fromtheWindowmenu of anyactiveopen
GUI . SPTool is nowtheactivewindow.
2 Select thenoi se[ vect or ] signal in theSignals list of SPTool.
3 Press Createin theSpectra list.
TheSpectrumViewer is activated, and a power spectral density object
(spect 1) correspondingtothenoi se signal is created in theSpectra list.
Thepower spectral density is not computed or displayed yet.
4 Press Apply in theSpectrumViewer tocomputeand display thepower
spectral density estimatespect 1 usingthedefault parameters.
Thepower spectral density of thenoi se signal is displayed in thedisplay
region. Theidentifyinginformation for thepower spectral densitys
associated signal (noi se) is displayed abovethe Parameters region.
Thepower spectral density estimatespect 1 is within 2 or 3 dB of 0, sothe
noisehas a fairly flatpower spectral density.
6 SPTool: A Signal Processing GUI Suite
6-30
5 Followsteps 1through 4for thebandlimited noisesignal bl noi se tocreate
a second power spectral density estimatespect 2.
Thepower spectral densityestimatespect 2 isflat between750and1250 Hz
and has 75 dB less power in thestopband regions of f i l t 1.
Opening the Spectrum Viewer with Two Spectra
1 ReactivateSPTool again, as in step 1 above.
2 Shift+click on spect 1 and spect 2 in theSpectra list toselect themboth.
3 Press Viewin theSpectra list toreactivatetheSpectrumViewer and
display both spectra together.
Spectral Analysis in the SpectrumViewer
6-31
Printing the Spectra
Beforeprintingthetwospectra together, usethecolor and linestyleselection
button, , todifferentiatethetwoplots by linestyle, rather than by color.
Toprint both spectra:
1 Press thePrint Previewbutton, , in thetoolbar on theSpectrum
Viewer.
2 FromtheSpectrumViewer Print Previewwindow, dragthelegendout of
thedisplay region sothat it doesnt obscurepart of theplot.
3 Press thePrint button in theSpectrumViewer Print Previewwindow.
6 SPTool: A Signal Processing GUI Suite
6-32
Exporting Signals, Filters, and Spectra
You can export SPTool signals, filters, and spectra as structures tothe
MATLAB workspaceor toyour disk.
I n each caseyou:
1 Select theitems in SPTool you want toexport.
2 Select Export fromtheFile menu.
Opening the Export Dialog Box
Tosavethefilter f i l t 1 you just created in this example, open theExport
dialogbox with f i l t 1 preselected:
1 Select f i l t 1 in theSPTool Filters list.
2 Select Export fromtheFile menu.
TheExport dialogbox opens with f i l t 1 preselected.
Select items to export from
theExport List.
Export filtersasobjects that
canbeusedwiththeControl
SystemToolbox.
Exporting Signals, Filters, and Spectra
6-33
Exporting a Filter to the MATLAB Workspace
Toexport thefilter f i l t 1 totheMATLAB workspace:
1 Select f i l t 1 and deselect all other items usingCtrl+click.
2 Press theExport to Workspacebutton.
6 SPTool: A Signal Processing GUI Suite
6-34
Designing a Filter with the Pole/ Zero Editor
Todesign afilter transfer function usingtheFilter Designers Pole/ZeroEditor:
1 Select thePol e/ Zer o Edi t or option fromthe
Algorithmlist.
This opens thePole/ZeroEditor in theFilter
Designer display.
2 Enter thedesired filter gain in theGain edit box.
3 Select a poleor zero(or conjugatepair) by selectingoneof the (pole) or
(zero) symbols on theplot.
4 Choosethecoordinates towork in by specifyingPol ar or Rect angul ar from
theCoordinates list.
5 Specify thenewlocation(s) of theselected pole, zero, or conjugatepair by
typingvalues intotheMagand Angle fields (for angular coordinates) or X
and Y (for rectangular coordinates) fields. Alternatively, position thepoles
and zeros by draggingthe and symbols.
6 UsetheConjugatepair check boxtocreateaconjugatepair fromalonepole
or zero, or tobreak a conjugatepair intotwoindividual poles or zeros.
Design a newfilter or edit an existingfilter in thesameway.
Tip Keep theFilter Viewer open whiledesigninga filter with thePole/Zero
Editor. Any changes that you maketothefilter transfer function in the
Pole/ZeroEditor arethen simultaneously reflected in theresponseplots of the
Filter Viewer.
Designing a Filter with the Pole/ Zero Editor
6-35
Positioning Poles and Zeros
You can useyour mousetomovepoles and zeros around thepole/zeroplot and
modify your filter design:
Addpolesor zerosusingthetoolbar buttonsfor poleplacement, , andzero
placement, .
Erasepoles and zeros usingtheeraser button, .
Movebothmembersof aconjugatepair simultaneouslybymanipulatingjust
oneof thepoles or zeros.
Toungroupconjugates, select thedesiredpair anduncheck Conjugatepair in
theSpecifications region on theFilter Designer.
When you placetwoor morepoles (or twoor morezeros) directly on topof each
other, a number is displayed next tothesymbols (on theleft for poles, and on
theright for zeros) indicatingthenumber of polesor zerosat that location (e.g.,
for threezeros). This number makes it easy tokeep track of all thepoles
and zeros in theplot area, even when several aresuperimposed on each other
and arenot visually differentiable. Note, however, that this number does not
indicatethemultiplicity of thepoles or zeros towhich it is attached.
Polebuttonfor
addingpoles
Zero buttonfor
addingzeros
Eraser buttonfor deleting
poles or zeros
Dragbuttonfor
movingpoles
andzerosaround
ontheplot.
6 SPTool: A Signal Processing GUI Suite
6-36
Todetect whether or not aset of polesor zerosaretrulymultiples, usethezoom
tools tomagnify theregion around thepoles or zeros in question. Because
numerical limitations usually prevent any set of poles or zeros fromsharing
exactly thesamevalue, at a high enough zoomlevel even truly multiplepoles
or zeros appear distinct fromeach other.
A common way toassess whether a particular group of poles or zeros contains
multiples is by comparingthemutual proximity of thegroupmembers against
aselectedthresholdvalue. Asanexample, ther esi duez functiondefinesapole
or zeroas beinga multipleof another poleor zeroif theabsolutedistance
separatingthemis less than 0.1%of thelarger poleor zeros magnitude.
Redesigning a Filter Using the Magnitude Plot
6-37
Redesigning a Filter Using the Magnitude Plot
After designinga filter in theFilter Designer, you can redesign it by dragging
thespecification lines on themagnitudeplot. Usethespecification lines to
changepassband ripple, stopband attenuation, and edgefrequencies.
I n thefollowingexample, createa Chebyshev filter and modify it by dragging
thespecification lines:
1 Select Chebyshev Type I I I R fromtheAlgorithmmenu.
2 Select hi ghpass fromtheType menu.
3 Type2000 in theSamplingFrequency field.
4 Set thefollowingparameters:
a Fp =800
b Fs =700
c Rp =2. 5
d Rs =35
5 Check MinimumOrder sotheFilter Designer cancalculatethelowest filter
order that produces thedesired characteristics.
6 Press Apply tocomputethefilter and updatetheresponseplot.
7 Position thecursor over thehorizontal filter specification linefor the
stopband. This is thefirst (leftmost) horizontal specification lineyou see.
Thecursor changes totheup/down dragindicator.
8 Dragthelineuntil theRs (stopband attenuation) field reads 100.
Note TheOrder valuein theMeasurements region changes becausea
higher filter order is needed tomeet thenewspecifications.
6 SPTool: A Signal Processing GUI Suite
6-38
Accessing Filter Parameters in a Saved Filter
TheMATLAB structures created by SPTool haveseveral associated fields,
many of which arealsoMATLAB structures. SeetheMATLAB documentation
for general information about MATLAB structures.
For example, after exportinga filter f i l t 1 totheMATLAB workspace, type
f i l t 1
todisplay thefields of theMATLAB filter structure. Thet f , Fs, and specs
fields of thestructurecontain theinformation that describes thefilter.
The tf Field: Accessing Filter Coefficients
Thet f field is a structurecontainingthetransfer function representation of
thefilter. Usethis field toobtain thefilter coefficients:
f i l t 1. t f . numcontains thenumerator coefficients.
f i l t 1. t f . den contains thedenominator coefficients.
Thevectors containedin thesestructures represent polynomials in descending
powers of z. Thenumerator and denominator polynomials areused tospecify
thetransfer function
where:
b is a vector containingthecoefficients fromthet f . numfield.
a is a vector containingthecoefficients fromthet f . den field.
mis thenumerator order.
n is thedenominator order.
You can changethefilter representation fromthedefault transfer function to
another formby usingthet f 2ss or t f 2zp functions.
The Fs Field: Accessing Filter Sample Frequency
TheFs field contains thesamplingfrequency of thefilter in hertz.
H z ( )
B z ( )
A z ( )
-----------
b 1 ( ) b 2 ( )z
1
L b nb 1 + ( )z
m
+ + +
a 1 ( ) a 2 ( )z
1
L a na 1 + ( )z
n
+ + +
----------------------------------------------------------------------------------------- = =
Accessing Filter Parameters in a Saved Filter
6-39
The specs Field: Accessing other Filter Parameters
Thespecs field is a structurecontainingparameters that you specified for the
filter design. Thefirst field, specs. cur r ent Modul e, contains a string
representingthemost recent designmethodselectedfromtheFilter Designers
Algorithmlist beforeyou exported thefilter. Thepossiblecontents of the
cur r ent Modul e field and thecorrespondingdesign methods areshown below.
Followingthespecs. cur r ent Modul e field, theremay beuptoseven additional
fields, with labels such as specs. f dr emez, specs. f df i r l s, etc. Thedesign
specifications for themost recently exported filter arecontained in thefield
whoselabel matches thecur r ent Modul e string. For example, if thespecs
structureis
f i l t 1. specs
ans
cur r ent Modul e: ' f dr emez'
f dr emez: [ 1x1 st r uct ]
thefilter specificationsarecontainedin thef dr emez field, whichisitself adata
structure.
Thespecifications includetheparameter values fromtheSpecifications
region of theFilter Designer, such as bandedges andfilter order. For example,
Table 6-1: Filter Specifications currentModule Field Values
Contents of the currentModule field Design Method
f dbut t er Butterworth I I R
f dcheby1 Chebyshev TypeI I I R
f dcheby2 Chebyshev TypeI I I I R
f del l i p Elliptic I I R
f df i r l s Least Squares FI R
f dkai ser Kaiser WindowFI R
f dr emez EquirippleFI R
6 SPTool: A Signal Processing GUI Suite
6-40
thefilter abovehas thefollowingspecifications stored in
f i l t 1. specs. f dr emez.
f i l t 1. specs. f dr emez
ans =
set Or der Fl ag: 0
t ype: 3
f : [ 0 0. 2000 0. 3000 0. 5000 0. 6000 1]
m: [ 6x1 doubl e]
Rp: 0. 0100
Rs: 75
wt : [ 3. 2371 1 3. 2371]
or der : 78
Becausecertain filter parameters areuniquetoa particular design, this
structurehas a different set of fields for each filter design.
Thetablebelowdescribes thepossiblefields associated with thefilter design
specification field (thespecs field) that can appear in theexported structure.
Table 6-2: SPTool Structure Specifications for Filters
Parameter Description
Bet a Kaiser window parameter.
f Contains avector of band-edgefrequencies, normalizedso
that 1 Hz corresponds tohalf thesamplefrequency.
Fpass Passband cutoff frequencies. Scalar for lowpass and
highpass designs, two-element vector for bandpass and
bandstop designs.
Fst op Stopband cutoff frequencies. Scalar for lowpass and
highpass designs, two-element vector for bandpass and
bandstop designs.
m Theresponsemagnitudes correspondingtotheband-edge
frequencies in f .
or der Filter order.
Accessing Filter Parameters in a Saved Filter
6-41
Rp Passband ripple(dB)
Rs Stopband attenuation (dB)
set Or der Fl ag Contains 1 if thefilter order was specified manually (i.e.,
theMinimumOrder box in theSpecifications region
was not checked). Contains 0 if thefilter order was
computed automatically.
t ype Contains 1 for lowpass, 2 for highpass, 3 for bandpass, or
4 for bandstop.
w3db -3 dB frequency for Butterworth I I R designs.
wi nd Vector of Kaiser windowcoefficients.
Wn Cutoff frequency for theKaiser windowFI R filter when
set Or der Fl ag = 1.
wt Vector of weights, oneweight per frequency band.
Table 6-2: SPTool Structure Specifications for Filters (Continued)
Parameter Description
6 SPTool: A Signal Processing GUI Suite
6-42
Accessing Parameters in a Saved Spectrum
Thefollowingstructurefields describethespectra saved by SPTool.
You can access theinformation in thesefields as you dowith every MATLAB
structure.
For example, if you export an SPTool PSD estimatespect 1 totheworkspace,
type
spect 1. P
toobtain thevector of associated power values.
Field Description
P Thespectral power vector.
f Thespectral frequency vector.
conf i d A structurecontainingtheconfidenceintervals data:
Theconf i d. l evel field contains thechosen
confidencelevel.
Theconf i d. Pc field contains thespectral power
data for theconfidenceintervals.
Theconf i d. enabl e field contains a 1 if confidence
levels areenabled for thepower spectral density.
si gnal Label Thenameof thesignal fromwhich thepower spectral
density was generated.
Fs Theassociated signals samplerate.
Importing Filters and Spectra into SPTool
6-43
Importing Filters and Spectra into SPTool
I n addition toimportingsignals intoSPTool, you can import filters or spectra
intoSPTool fromeither theworkspaceor froma file.
Theprocedures arevery similar tothoseexplained in:
I mportingaSignal intoSPToolon page6-19for loadingvariables fromthe
workspace
LoadingVariables fromtheDiskon page6-47 for loadingvariables from
your disk
Importing Filters
When you import filters, first select theappropriatefilter formfromtheForm
list.
Select a filter
structure.
6 SPTool: A Signal Processing GUI Suite
6-44
Each filter formrequires different variables:
For Tr ansf er Funct i on, you specify thefilter by its transfer function
representation:
- TheNumerator fieldspecifies avariablenameor valuefor thenumerator
coefficient vector b, which contains m+1coefficients in descendingpowers
of z.
- TheDenominator field specifies a variablenameor valuefor the
denominator coefficient vector a, which contains n+1 coefficients in
descendingpowers of z.
For St at e Space, you specify thefilter by its state-spacerepresentation:
TheA-Matrix, B-Matrix, C-Matrix, and D-Matrix fields specify a variable
nameor a valuefor each matrix in this system.
For Zer os, Pol es, Gai n, you specify thefilter by its zero-pole-gain
representation:
- TheZeros field specifies a variablenameor valuefor thezeros vector z,
which contains thelocations of mzeros.
- ThePoles field specifies a variablenameor valuefor thezeros vector p,
which contains thelocations of n poles.
- TheGain field specifies a variablenameor valuefor thegain k.
For 2nd Or der Sect i ons you specify thefilter by its second-order section
representation:
H z ( )
B z ( )
A z ( )
-----------
b 1 ( ) b 2 ( )z
1
L b m 1 + ( )z
m
+ + +
a 1 ( ) a 2 ( )z
1
L a n 1 + ( )z
n
+ + +
--------------------------------------------------------------------------------------- = =
x

Ax Bu + =
y Cx Du + =
H z ( )
Z z ( )
P z ( )
---------- k
z z 1 ( ) ( ) z z 2 ( ) ( )L z z m ( ) ( )
z p 1 ( ) ( ) z p 2 ( ) ( )L z p n ( ) ( )
------------------------------------------------------------------------------------ = =
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

= =
Importing Filters and Spectra into SPTool
6-45
TheSOSMatrixfieldspecifiesavariablenameor avaluefor theL-by-6SOS
matrix
whoserows contain thenumerator and denominator coefficients b
ik
and a
ik
of thesecond-order sections of H(z).
For every filter you specify a variablenameor a valuefor thefilters
samplingfrequency in theSamplingFrequency field.
Note I f you import a filter that was not created in SPTool, you can only edit
that filter usingthePole/ZeroEditor.
Importing Spectra
When you import a power spectral density (PSD), you specify:
A variablenameor a valuefor thePSD vector in thePSD field
A variablenameor a valuefor thefrequency vector in theFreq. Vector field
sos
b
01
b
11
b
21
1 a
11
a
21
b
02
b
12
b
22
1 a
12
a
22

b
0L
b
1L
b
2L
1 a
1L
a
2L
=
6 SPTool: A Signal Processing GUI Suite
6-46
ThePSD values in thePSD vector correspond tothefrequencies contained
in theFreq. Vector vector; thetwovectors must havethesamelength.
Loading Variables fromthe Disk
6-47
Loading Variables from the Disk
Toimport variables representingsignals, filters, or spectrafromaMAT-fileon
your disk:
1 Select theFromDisk radiobutton and doeither of thefollowing:
- Typethenameof thefileyou want toimport intotheMAT-fileNamefield
and press either theTab or theEnter key on your keyboard.
- Select Browse, and then find and select thefileyou want toimport using
theSelect Fileto Open dialog. Press OK toclosethat dialog.
I n either case, all variables in theMAT-fileyou selectedaredisplayedin the
FileContents list.
2 Select thevariables tobeimported intoSPTool.
You can nowimport oneor morevariables fromtheFileContentslist into
SPTool, as longas thesevariables arescalars, vectors, or matrices.
6 SPTool: A Signal Processing GUI Suite
6-48
Selecting Signals, Filters, and Spectra in SPTool
All signals, filters, or spectra listed in SPTool exist as special MATLAB
structures. You can bringdata representingsignals, filters, or spectra into
SPTool fromtheMATLAB workspace. I n general, you can select oneor several
items in a given list box. An itemis selected when it is highlighted.
TheSignals list shows all vector and array signals in thecurrent SPTool
session.
TheFilters list shows all designed and imported filters in thecurrent SPTool
session.
TheSpectra list shows all spectra in thecurrent SPTool session.
You can select a singledata object in a list, a rangeof data objects in a list, or
multipleseparatedata objects in a list. You can alsohavedata objects
simultaneously selected in different lists:
Toselect a singleitem, click on it. All other items in that list box become
deselected.
Toadd or removea rangeof items, Shift+click on theitems at thetop and
bottomof thesection of thelist that you want toadd. You can alsodragyour
mousepointer toselect theseitems.
Toadd a singledata object toa selection or removea singledata object from
a multipleselection, Ctrl+click on theobject.
Editing Signals, Filters, or Spectra in SPTool
6-49
Editing Signals, Filters, or Spectra in SPTool
You can edit selected items in SPTool by:
1 Selectingthenames of thesignals, filters, or spectra you want toedit.
2 SelectingtheappropriateEdit menu item:
- Duplicate tocopy an itemin an SPTool list
- Clear todeletean itemin an SPTool list
- Nametorenamean itemin an SPTool list
- SamplingFrequency tomodify thesamplingfrequency associated with
either a signal (and its associated spectra) or filter in an SPTool list
Thepull-down menu next toeach menu itemshowsthenamesof all selected
items.
You can alsoedit thefollowingsignal characteristics by right-clickingin the
display region of theSignal Browser, theFilter Viewer, or theSpectrum
Viewer:
Thesignal name
Thesamplingfrequency
Thelinestyleproperties
Note I f you modify thesamplingfrequency associated with a signals
spectrumusingtheright-click menu on theSpectrumViewer display region,
thesamplingfrequency of theassociated signal is automatically updated.
6 SPTool: A Signal Processing GUI Suite
6-50
Setting Preferences
UsePreferencesfromtheSPTool Filemenu tocustomizedisplaysandcertain
parameters for SPTool and its four component GUI s. Thenewsettings are
saved on disk and areused when you restart SPTool fromMATLAB.
I n thePreferences regions, you can:
Select colors and markers for all displays.
Select colors and linestyles for displayed signals.
Configurelabels, and enable/disablemarkers, panner, and zoomin the
Signal Browser.
Configuredisplay parameters, and enable/disablemarkers and zoomin the
SpectrumViewer.
Configurefilter and display parameters, and enable/disablezoomin the
Filter Viewer.
Configuretilingpreferences in theFilter Viewer.
Specify FFT length, and enable/disablemousezoomand grid in theFilter
Designer.
Enable/disableuseof a default session file.
Export filters for usewith theControl SystemToolbox.
Enable/disablesearch for plug-ins at start-up.
When you first select Preferences, thePreferences dialogbox opens with
Markers selected by default. You can:
Changethesettings for markers fromthis panel of thePreferences dialog.
Chooseany of theother categories listed tocustomizeits settings.
Click onceon any listed category in theleft paneof thePreferences dialogto
select it.
Making Signal Measurements: Using Markers
6-51
Making Signal Measurements: Using Markers
You can usethemarkers on theSignal Browser, theFilter Viewer, or the
SpectrumViewer tomakemeasurements on any of thefollowing:
A signal in theSignal Browser
A filter responsein theFilter Viewer
A power spectral density plotted in theSpectrumViewer
Tomakea measurement:
1 Select a linetomeasure(or play, if you arein theSignal Browser).
2 Select oneof themarker buttons, , , , , , , toapply a
marker tothedisplayed signal.
3 Position a marker in themain display area by grabbingit with your mouse
and dragging:
a Select a marker setting. I f you choosetheVertical, Track, or Slope
buttons, you can draga marker totheright or left. I f you choosethe
Horizontal button, you can draga marker up or down.
b Movethemouseover themarker (1 or 2) that you want todrag.
Thehand cursor with themarker number insideit is displayed when
your mousepasses over a marker.
c Dragthemarker towhereyou want it on thesignal.
As you draga marker, thebottomof theSignal Browser shows thecurrent
position of both markers. Dependingon which marker settingyou select,
someor all of thefollowingfields aredisplayed: x1, y1, x2, y2, dx, dy, m.
Thesefields arealsodisplayed when you print fromtheSignal Browser,
unless you suppress them.
You can alsoposition a marker by typingits x1and x2or y1and y2values in
theregion at thebottom.
6 SPTool: A Signal Processing GUI Suite
6-52
7
Function Reference
Function Category List . . . . . . . . . . . . . . . 7-3
Alphabetical Listingof Functions . . . . . . . . . . 7-16
7 Function Reference
7-2
This chapter contains detailed descriptions of all Signal ProcessingToolbox
functions. I t is divided intotwosections:
Function Category List a list of functions, grouped by subject area
Alphabetical List of Functions referencepages in alphabetical order
Function Category List
7-3
Function Category List
Thetables belowlist all of theSignal ProcessingToolbox functions by category.
Filter Analysis
abs Absolutevalue(magnitude).
angl e Phaseangle.
f r eqs Frequency responseof analogfilters.
f r eqspace Frequency spacingfor frequency response.
f r eqz Computethefrequency responseof digital filters.
f r eqzpl ot Plot frequency responsedata.
gr pdel ay Computetheaveragefilter delay (group delay).
i mpz Computetheimpulseresponseof digital filters.
unwr ap Unwrap phaseangles.
zpl ane Zero-poleplot.
Filter Implementation
conv Convolution and polynomial multiplication.
conv2 Two-dimensional convolution.
deconv Deconvolution and polynomial division.
f f t f i l t FFT-based FI R filteringusingtheoverlap-add method.
f i l t er Filter data with a recursive(I I R) or nonrecursive(FI R)
filter.
f i l t er 2 Two-dimensional digital filtering.
7 Function Reference
7-4
f i l t f i l t Zero-phasedigital filtering.
f i l t i c Find initial conditions for a transposed direct formI I filter
implementation.
l at cf i l t Latticeand lattice-ladder filter implementation.
medf i l t 1 One-dimensional median filtering.
sgol ayf i l t Savitzky-Golay filtering.
sosf i l t Second-order (biquadratic) I I R digital filtering.
upf i r dn Upsample, apply an FI R filter, and downsample.
FIR Digital Filter Design
convmt x Convolution matrix.
cr emez Complex and nonlinear-phaseequirippleFI R filter design.
f i r 1 Design a window-based finiteimpulseresponsefilter.
f i r 2 Design afrequency sampling-basedfiniteimpulseresponse
filter.
f i r cl s Constrained least squareFI R filter design for multiband
filters.
f i r cl s1 Constrained least squarefilter design for lowpass and
highpass linear phaseFI R filters.
f i r l s Least squarelinear-phaseFI R filter design.
f i r r cos Raised cosineFI R filter design.
i nt f i l t I nterpolation FI R filter design.
kai ser or d Estimateparameters for an FI R filter design with Kaiser
window.
Filter Implementation (Continued)
Function Category List
7-5
r emez ComputetheParks-McClellan optimal FI R filter design.
r emezor d Parks-McClellan optimal FI R filter order estimation.
sgol ay Savitzky-Golay filter design.
IIR Digital Filter DesignClassical and Direct
but t er Butterworth analogand digital filter design.
cheby1 Chebyshev typeI filter design (passband ripple).
cheby2 Chebyshev typeI I filter design (stopband ripple).
el l i p Elliptic (Cauer) filter design.
maxf l at Generalized digital Butterworth filter design.
pr ony Pronys method for time-domain I I R filter design.
st mcb Computea linear model usingSteiglitz-McBrideiteration.
yul ewal k Recursivedigital filter design.
IIR Filter Order Estimation
but t or d Calculatetheorder and cutoff frequency for a Butterworth
filter.
cheb1or d Calculatetheorder for a Chebyshev typeI filter.
cheb2or d Calculatetheorder for a Chebyshev typeI I filter.
el l i por d Calculatetheminimumorder for elliptic filters.
FIR Digital Filter Design (Continued)
7 Function Reference
7-6
Analog Lowpass Filter Prototypes
bessel ap Bessel analoglowpass filter prototype.
but t ap Butterworth analoglowpass filter prototype.
cheb1ap Chebyshev typeI analoglowpass filter prototype.
cheb2ap Chebyshev typeI I analoglowpass filter prototype.
el l i pap Elliptic analoglowpass filter prototype.
Analog Filter Design
bessel f Bessel analogfilter design.
but t er Butterworth analogand digital filter design.
cheby1 Chebyshev typeI filter design (passband ripple).
cheby2 Chebyshev typeI I filter design (stopband ripple).
el l i p Elliptic (Cauer) filter design.
Analog Filter Transformation
l p2bp Transformlowpass analogfilters tobandpass.
l p2bs Transformlowpass analogfilters tobandstop.
l p2hp Transformlowpass analogfilters tohighpass.
l p2l p Changethecut-off frequency for a lowpass analogfilter.
Function Category List
7-7
Filter Discretization
bi l i near Bilinear transformation method for analog-to-digital filter
conversion.
i mpi nvar I mpulseinvariancemethod for analog-to-digital filter
conversion.
Linear System Transformations
l at c2t f Convert latticefilter parameters totransfer function form.
pol yst ab Stabilizea polynomial.
pol yscal e Scaletheroots of a polynomial.
r esi duez z-transformpartial-fraction expansion.
sos2ss
Convert digital filter second-order section parameters to
state-spaceform.
sos2t f Convert digital filter second-order section data totransfer
function form.
sos2zp Convert digital filter second-order sections parameters to
zero-pole-gain form.
ss2sos Convert digital filter state-spaceparameters to
second-order sections form.
ss2t f Convert state-spacefilter parameters totransfer function
form.
ss2zp Convert state-spacefilter parameters tozero-pole-gain
form.
t f 2l at c Convert transfer function filter parameters tolatticefilter
form.
7 Function Reference
7-8
t f 2sos Convert digital filter transfer function data tosecond-order
sections form.
t f 2ss Convert transfer function filter parameters tostate-space
form.
t f 2zp Convert transfer function filter parameters to
zero-pole-gain form.
zp2sos Convert digital filter zero-pole-gain parameters to
second-order sections form.
zp2ss Convert zero-pole-gain filter parameters tostate-space
form.
zp2t f Convert zero-pole-gain filter parameters totransfer
function form.
Windows
bar t l et t Computea Bartlett window.
bl ackman Computea Blackman window.
boxcar Computea rectangular window.
chebwi n Computea Chebyshev window.
hammi ng Computea Hammingwindow.
hann ComputetheHann (Hanning) window.
kai ser Computea Kaiser window.
t r i ang Computea triangular window.
Linear System Transformations (Continued)
Function Category List
7-9
Transforms
czt Chirp z-transform.
dct Discretecosinetransform(DCT).
df t mt x DiscreteFourier transformmatrix.
f f t Computetheone-dimensional fast Fourier transform.
f f t 2 Computethetwo-dimensional fast Fourier transform.
f f t shi f t Rearrangetheoutputs of theFFT functions.
hi l ber t Computethediscrete-timeanalyticsignal usingtheHilbert
transform.
i dct I nversediscretecosinetransform.
i f f t One-dimensional inversefast Fourier transform.
i f f t 2 Two-dimensional inversefast Fourier transform.
Cepstral Analysis
cceps Complex cepstral analysis.
i cceps I nversecomplex cepstrum.
r ceps Real cepstrumand minimumphasereconstruction.
Statistical Signal Processing and Spectral Analysis
coher e Estimatemagnitudesquared coherencefunction between
twosignals.
cor r coef Computethecorrelation coefficient matrix.
7 Function Reference
7-10
cor r mt x Computea data matrix for autocorrelation matrix
estimation.
cov Computethecovariancematrix.
csd Estimatethecross spectral density (CSD) of twosignals.
pbur g Estimatethepower spectral density usingtheBurg
method.
pcov Estimatethepower spectral density usingthecovariance
method.
pei g Estimatethepseudospectrumusingtheeigenvector
method.
per i odogr am Estimatethepower spectral density (PSD) of asignal using
a periodogram.
pmcov Estimatethepower spectral density usingthemodified
covariancemethod.
pmt m Estimatethepower spectral density usingthemultitaper
method (MTM).
pmusi c Estimatethepower spectral density usingMUSI C
algorithm.
psdpl ot Plot power spectral density (PSD) data.
pwel ch Estimatethepower spectral density (PSD) of asignal using
Welchs method.
pyul ear Estimatethepower spectral density usingtheYule-Walker
AR method.
r oot ei g Estimatefrequency and power content usingthe
eigenvector method.
r oot musi c Estimatefrequency and power content usingtheroot
MUSI C algorithm.
Statistical Signal Processing and Spectral Analysis (Continued)
Function Category List
7-11
t f e Estimatethetransfer function frominput and output.
xcor r Estimatethecross-correlation function.
xcor r 2 Estimatethetwo-dimensional cross-correlation.
xcov Estimatethecross-covariancefunction (equal to
mean-removed cross-correlation).
Parametric Modeling
ar bur g Computean estimateof AR model parameters usingthe
Burgmethod.
ar cov Computean estimateof AR model parameters usingthe
covariancemethod.
ar mcov Computean estimateof AR model parameters usingthe
modified covariancemethod.
ar yul e Computean estimateof AR model parameters usingthe
Yule-Walker method.
i dent SeetheSystemI dentification Toolbox documentation.
i nvf r eqs I dentify continuous-timefilter parameters fromfrequency
responsedata.
i nvf r eqz I dentify discrete-timefilter parameters fromfrequency
responsedata.
pr ony Pronys method for timedomain I I R filter design.
st mcb Computea linear model usingSteiglitz-McBrideiteration.
Statistical Signal Processing and Spectral Analysis (Continued)
7 Function Reference
7-12
Linear Prediction
ac2pol y Convert an autocorrelation sequencetoprediction
polynomial.
ac2r c Convert an autocorrelation sequencetoreflection
coefficients.
i s2r c Convert inversesineparameters toreflection coefficients.
l ar 2r c Convert logarea ratioparameters toreflection coefficients.
l evi nson ComputetheLevinson-Durbin recursion.
l pc Computelinear prediction filter coefficients.
l sf 2pol y Convert linespectral frequencies toa prediction filter
coefficients.
pol y2ac Convert aprediction filter polynomial toan autocorrelation
sequence.
pol y2l sf Convert prediction filter coefficients tolinespectral
frequencies.
pol y2r c Convert a prediction filter polynomial toreflection
coefficients.
r c2ac Convert reflection coefficients toan autocorrelation
sequence.
r c2i s Convert reflection coefficients toinversesineparameters.
r c2l ar Convert reflection coefficients tologarea ratioparameters.
r c2pol y Convert reflection coefficients toa prediction filter
polynomial.
r l evi nson ComputethereverseLevinson-Durbin recursion.
schur r c Computereflection coefficients froman autocorrelation
sequence.
Function Category List
7-13
Multirate Signal Processing
deci mat e Decreasethesamplingratefor a sequence(decimation).
i nt er p I ncreasesamplingrateby an integer factor (interpolation).
i nt er p1 One-dimensional data interpolation (tablelookup).
r esampl e Changesamplingrateby any rational factor.
spl i ne Cubic splineinterpolation.
upf i r dn Upsample, apply an FI R filter, and downsample.
Waveform Generation
chi r p Generatea swept-frequency cosine.
di r i c ComputetheDirichlet or periodic sinc function.
gauspul s Generatea Gaussian-modulated sinusoidal pulse.
gmonopul s Generatea Gaussian monopulse.
pul st r an Generatea pulsetrain.
r ect pul s Generatea sampled aperiodic rectangle.
sawt oot h Generatea sawtooth or trianglewave.
si nc Sinc function.
squar e Generatea squarewave.
t r i pul s Generatea sampled aperiodic triangle.
vco Voltagecontrolled oscillator.
7 Function Reference
7-14
Specialized Operations
buf f er Buffer a signal vector intoa matrix of data frames.
cel l 2sos Convert a cell array for second-order sections toa
second-order section matrix.
cpl xpai r Group complex numbers intocomplex conjugatepairs.
demod Demodulation for communications simulation.
dpss Discreteprolatespheroidal sequences (Slepian sequences).
dpsscl ear Removediscreteprolatespheroidal sequences from
database.
dpssdi r Discreteprolatespheroidal sequences databasedirectory.
dpssl oad Load discreteprolatespheroidal sequences fromdatabase.
dpsssave Savediscreteprolatespheroidal sequences in database.
eqt f l engt h Makethelengths of a transfer function's numerator and
denominator equal.
modul at e Modulation for communications simulation.
seqper i od Computetheperiod of a sequence.
sos2cel l Convert a second-order section matrix tocell arrays.
specgr am Time-dependent frequency analysis (spectrogram).
st em Plot discretesequencedata.
st r i ps Strip plot.
udecode Decode2
n
-level quantized integer inputs tofloating-point
outputs.
uencode Quantizeand encodefloating-point inputs tointeger
outputs.
Function Category List
7-15
Graphical User Interfaces
f dat ool Open theFilter Design and Analysis Tool.
spt ool I nteractivedigital signal processingtool (SPTool).
abs
7-16
7abs
Purpose Absolutevalue(magnitude).
Syntax y = abs( x)
Description y =abs( x) returns theabsolutevalueof theelements of x. I f x is complex, abs
returns thecomplex modulus (magnitude).
abs( x) = sqr t ( r eal ( x) . ^2 + i mag( x) . ^2)
I f x is a MATLAB string, abs returns thenumeric values of theASCI I
characters in thestring. Thedisplay format of thestringchanges; theinternal
representation does not.
Theabs function is part of thestandard MATLAB language.
Example Calculatethemagnitudeof theFFT of a sequence.
t = ( 0: 99) / 100; %t i me vect or
x = si n( 2*pi *15*t ) + si n( 2*pi *40*t ) ; %si gnal
y = f f t ( x) ; %comput e DFT of x
m= abs( y) ; %magni t ude
Plot themagnitude.
f = ( 0: l engt h( y) - 1) ' / l engt h( y) *100; %f r equency vect or
pl ot ( f , m)
See Also angl e Phaseangle.
ac2poly
7-17
7ac2poly
Purpose Convert an autocorrelation sequencetoa prediction filter polynomial.
Syntax a = ac2pol y( r )
[ a, ef i nal ] = ac2pol y( r )
Description a =ac2pol y( r ) finds theprediction filter polynomial a correspondingtothe
autocorrelation sequencer . a is thesamelength as r , and a( 1) =1. The
prediction filter polynomial represents thecoefficients of theprediction filter
whoseoutput produces a signal whoseautocorrelation sequenceis
approximately thesameas thegiven autocorrelation sequencer .
[ a, ef i nal ] =ac2pol y( r ) returns thefinal prediction error ef i nal ,
determined by runningthefilter for l engt h( r ) steps.
Remarks You can apply this function toreal or complex data.
Example Consider theautocorrelation sequence
r = [ 5. 0000 - 1. 5450 - 3. 9547 3. 9331 1. 4681 - 4. 7500] ;
Theequivalent prediction filter polynomial is
[ a, ef i nal ] = ac2pol y( r )
a =
1. 0000 0. 6147 0. 9898 0. 0004 0. 0034 - 0. 0077
ef i nal =
0. 1791
See Also
References [1] Kay, S.M. Modern Spectral Estimation. Englewood Cliffs, NJ :
Prentice-Hall, 1988.
ac2r c Convert an autocorrelation sequencetoreflection
coefficients.
pol y2ac Convert a prediction filter polynomial toan
autocorrelation sequence.
r c2pol y Convert reflection coefficients toa prediction filter
polynomial.
ac2rc
7-18
7ac2rc
Purpose Convert an autocorrelation sequencetoreflection coefficients.
Syntax [ k, r 0] = ac2r c( r )
Description [ k, r 0] =ac2r c( r ) finds thereflection coefficients k correspondingtothe
autocorrelation sequencer . r 0 contains theinitial zero-lagautocorrelation.
Thesereflection coefficients can beused tospecify thelatticeprediction filter
that produces a sequencewith approximately thesameautocorrelation
sequenceas thegiven sequencer .
Remarks You can apply this function toreal or complex data.
See Also
References [1] Kay, S.M. Modern Spectral Estimation. Englewood Cliffs, NJ :
Prentice-Hall, 1988.
ac2pol y Convert an autocorrelation sequencetoa prediction
filter polynomial.
pol y2r c Convert a prediction filter polynomial toreflection
coefficients.
r c2ac Convert reflection coefficients toan autocorrelation
sequence.
angle
7-19
7angle
Purpose Phaseangle.
Syntax p = angl e( h)
Description p =angl e( h) returns thephaseangles, in radians, of theelements of complex
vector or array h. Thephaseangles liebetween - and .
For complex sequenceh =x +iy =me
ip
, themagnitudeand phasearegiven by
m= abs( h)
p = angl e( h)
Toconvert totheoriginal h fromits magnitudeand phase, type
i = sqr t ( - 1)
h = m. *exp( i *p)
Theangl e function is part of thestandard MATLAB language.
Example Calculatethephaseof theFFT of a sequence.
t = ( 0: 99) / 100; %t i me vect or
x = si n( 2*pi *15*t ) + si n( 2*pi *40*t ) ; %si gnal
y = f f t ( x) ; %comput e DFT of x
p = unwr ap( angl e( y) ) ; %phase
Plot thephase.
f = ( 0: l engt h( y) - 1) ' / l engt h( y) *100; %f r equency vect or
pl ot ( f , p)
Algorithm angl e can beexpressed as
angl e( x) = i mag( l og( x) ) = at an2( i mag( x) , r eal ( x) )
See Also abs Absolutevalue(magnitude).
arburg
7-20
7arburg
Purpose Computean estimateof AR model parameters usingtheBurgmethod.
Syntax a = ar bur g( x, p)
[ a, e] = ar bur g( x, p)
[ a, e, k] = ar bur g( x, p)
Description a =ar bur g( x, p) uses theBurgmethod tofit a pth order autoregressive(AR)
model totheinput signal, x, by minimizing(least squares) theforward and
backward prediction errors whileconstrainingtheAR parameters tosatisfy
theLevinson-Durbin recursion. x is assumedtobetheoutput of an AR system
driven by whitenoise. Vector a contains thenormalized estimateof theAR
systemparameters, A(z), in descendingpowers of z.
Sincethemethod characterizes theinput data usingan all-polemodel, the
correct choiceof themodel order p is important.
[ a, e] =ar bur g( x, p) returnsthevarianceestimate, e, of thewhitenoiseinput
totheAR model.
[ a, e, k] =ar bur g( x, p) returns a vector, k, of reflection coefficients.
See Also
H z ( )
e
A z ( )
------------
e
1 a
2
z
1
a
p 1 + ( )
z
p
+ + +
---------------------------------------------------------------------- = =
ar cov Computean estimateof AR model parameters using
thecovariancemethod.
ar mcov Computean estimateof AR model parameters using
themodified covariancemethod.
ar yul e Computean estimateof AR model parameters using
theYule-Walker method.
l pc Computelinear predictiverecursion coefficients.
pbur g Computethepower spectrumestimateusingthe
Burgmethod.
pr ony Pronys method for time-domain I I R filter design.
arcov
7-21
7arcov
Purpose Computean estimateof AR model parameters usingthecovariancemethod.
Syntax a = ar cov( x, p)
[ a, e] = ar cov( x, p)
Description a =ar cov( x, p) uses thecovariancemethod tofit a pth order autoregressive
(AR) model totheinput signal, x, which is assumed tobetheoutput of an AR
systemdriven by whitenoise. This method minimizes theforward prediction
error in theleast-squares sense. Vector a contains thenormalized estimateof
theAR systemparameters, A(z), in descendingpowers of z.
Becausethemethod characterizes theinput data usingan all-polemodel, the
correct choiceof themodel order p is important.
[ a, e] =ar cov( x, p) returns thevarianceestimate, e, of thewhitenoiseinput
totheAR model.
See Also
H z ( )
e
A z ( )
------------
e
1 a
2
z
1
a
p 1 + ( )
z
p
+ + +
---------------------------------------------------------------------- = =
ar bur g Computean estimateof AR model parameters using
theBurgmethod.
ar mcov Computean estimateof AR model parameters using
themodified covariancemethod.
ar yul e Computean estimateof AR model parameters using
theYule-Walker method.
l pc Computelinear predictiverecursion coefficients.
pcov Estimatethepower spectrumusingthecovariance
method.
pr ony Pronys method for I I R filter design.
armcov
7-22
7armcov
Purpose Computean estimateof AR model parameters usingthemodified covariance
method.
Syntax a = ar mcov( x, p)
[ a, e] = ar mcov( x, p)
Description a =ar mcov( x, p) uses themodified covariancemethod tofit a pth order
autoregressive(AR) model totheinput signal, x, which is assumed tobethe
output of an AR systemdriven by whitenoise. This method minimizes the
forward and backward prediction errors in theleast-squares sense. Vector a
contains thenormalized estimateof theAR systemparameters, A(z), in
descendingpowers of z.
Becausethemethod characterizes theinput data usingan all-polemodel, the
correct choiceof themodel order p is important.
[ a, e] =ar mcov( x, p) returnsthevarianceestimate, e, of thewhitenoiseinput
totheAR model.
See Also
H z ( )
e
A z ( )
------------
e
1 a
2
z
1
a
p 1 + ( )
z
p
+ + +
---------------------------------------------------------------------- = =
ar bur g Computean estimateof AR model parameters using
theBurgmethod.
ar cov Computean estimateof AR model parameters using
thecovariancemethod.
ar yul e Computean estimateof AR model parameters using
theYule-Walker method.
l pc Computelinear predictiverecursion coefficients.
pmcov Estimatethepower spectrumusingthemodified
covariancemethod.
pr ony Pronys method for I I R filter design.
aryule
7-23
7aryule
Purpose Computean estimateof AR model parameters usingtheYule-Walker method.
Syntax a = ar yul e( x, p)
[ a, e] = ar yul e( x, p)
[ a, e, k] = ar yul e( x, p)
Description a =ar yul e( x, p) uses theYule-Walker method, alsocalledtheautocorrelation
method, tofit a pth order autoregressive(AR) model tothewindowed input
signal, x, by minimizingtheforward prediction error in theleast-squares
sense. This formulation leads totheYule-Walker equations, which aresolved
by theLevinson-Durbin recursion. x is assumed tobetheoutput of an AR
systemdriven by whitenoise. Vector a contains thenormalizedestimateof the
AR systemparameters, A(z), in descendingpowers of z.
Becausethemethod characterizes theinput data usingan all-polemodel, the
correct choiceof themodel order p is important.
[ a, e] =ar yul e( x, p) returnsthevarianceestimate, e, of thewhitenoiseinput
totheAR model.
[ a, e, k] =ar yul e( x, p) returns a vector, k, of reflection coefficients.
See Also
H z ( )
e
A z ( )
------------
e
1 a
2
z
1
a
p 1 + ( )
z
p
+ + +
---------------------------------------------------------------------- = =
ar bur g Computean estimateof AR model parameters using
theBurgmethod.
ar cov Computean estimateof AR model parameters using
thecovariancemethod.
ar mcov Computean estimateof AR model parameters using
themodified covariancemethod.
l pc Computelinear predictiverecursion coefficients.
pr ony Pronys method for I I R filter design.
pyul ear Estimatethepower spectrumusingtheYule-Walker
autoregressiveapproach.
bartlett
7-24
7bartlett
Purpose Computea Bartlett window.
Syntax w = bar t l et t ( n)
Description w=bar t l et t ( n) returns an n-point Bartlett windowin thecolumn vector w,
wheren must bea positiveinteger. Thecoefficients of a Bartlett windoware
computed as follows:
For n odd
For n even
TheBartlett windowis very similar toa triangular windowas returned by the
t r i ang function. TheBartlett windowalwaysendswithzerosat samples1and
n, however, whilethetriangular windowis nonzeroat thosepoints. For n odd,
thecenter n- 2 points of bar t l et t ( n) areequivalent tot r i ang( n- 2) .
Note I f you specify a one-point window(set n=1), thevalue1 is returned.
Example w = bar t l et t ( 64) ;
pl ot ( w)
t i t l e( ' Bar t l et t Wi ndow' )
w k 1 + [ ]
2k
n 1
------------ - 0 k
n 1
2
------------ - ,
2
2 k ( )
n 1
-------------
n 1
2
------------ - k n 1 ,




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




=
bartlett
7-25
See Also
References [1] Oppenheim, A.V., and R.W. Schafer. Discrete-TimeSignal Processing.
Englewood Cliffs, NJ : Prentice-Hall, 1989, pp. 447-448.
0 10 20 30 40 50 60 70
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
Bartlett Window
bl ackman Computea Blackman window.
boxcar Computea rectangular window.
chebwi n Computea Chebyshev window.
hammi ng Computea Hammingwindow.
hann Computea Hann window.
kai ser Computea Kaiser Window.
t r i ang Computea triangular window.
besselap
7-26
7besselap
Purpose Bessel analoglowpass filter prototype.
Syntax [ z, p, k] = bessel ap( n)
Description [ z, p, k] =bessel ap( n) returns thepoles andgain of an order n Bessel analog
lowpass filter prototype. n must beless than or equal to25. Thefunction
returns thepoles in thelength n column vector p and thegain in scalar k. z is
an empty matrix becausetherearenozeros. Thetransfer function is
bessel ap normalizes thepoles and gain sothat at lowfrequency and high
frequencytheBessel prototypeisasymptoticallyequivalent totheButterworth
prototypeof thesameorder [1]. Themagnitudeof thefilter is less than
at theunity cutoff frequency
c
=1.
AnalogBessel filters arecharacterized by a groupdelay that is maximally flat
at zerofrequency and almost constant throughout thepassband. Thegroup
delay at zerofrequency is
Algorithm bessel ap finds thefilter roots froma look-up tableconstructed usingthe
Symbolic Math Toolbox.
See Also
AlsoseetheSymbolic Math Toolbox documentation.
References [1] Rabiner, L.R., and B. Gold. Theory and Application of Digital Signal
Processing. Englewood Cliffs, NJ : Prentice-Hall, 1975. Pgs. 228-230.
H s ( )
k
s p 1 ( ) ( ) s p 2 ( ) ( )L s p n ( ) ( )
-------------------------------------------------------------------------------- =
1 2
2n ( )!
2
n
n!
--------------


1 n
bessel f Bessel analogfilter design.
but t ap Butterworth analoglowpass filter prototype.
cheb1ap Chebyshev typeI analoglowpass filter prototype.
cheb2ap Chebyshev typeI I analoglowpass filter prototype.
el l i pap Elliptic analoglowpass filter prototype.
besself
7-27
7besself
Purpose Bessel analogfilter design.
Syntax [ b, a] = bessel f ( n, Wn)
[ b, a] = bessel f ( n, Wn, ' f t ype' )
[ z, p, k] = bessel f ( . . . )
[ A, B, C, D] = bessel f ( . . . )
Description bessel f designs lowpass, bandpass, highpass, and bandstop analogBessel
filters. AnalogBessel filters arecharacterized by almost constant group delay
across theentirepassband, thus preservingthewaveshapeof filtered signals
in thepassband. Digital Bessel filters donot retain this quality, and bessel f
thereforedoes not support thedesign of digital Bessel filters.
[ b, a] =bessel f ( n, Wn) designs an order n lowpass analogfilter with cutoff
frequency Wn. I t returns thefilter coefficients in thelength n+1 rowvectors b
and a, with coefficients in descendingpowers of s, derived fromthetransfer
function
Cutoff frequencyis thefrequency at which themagnituderesponseof thefilter
begins todecreasesignificantly. For bessel f , thecutoff frequency Wn must be
greater than 0. Themagnituderesponseof a Bessel filter designedby bessel f
is always less than at thecutoff frequency, and it decreases as theorder
n increases.
I f Wn is a two-element vector, Wn =[ w1 w2] with w1 <w2, then bessel f ( n, Wn)
returns an order 2*n bandpass analogfilter with passband w1 < <w2.
[ b, a] =bessel f ( n, Wn, ' f t ype' ) designs a highpass or bandstop filter, where
thestring' f t ype' is:
' hi gh' for a highpass analogfilter with cutoff frequency Wn
' st op' for an order 2*n bandstop analogfilter if Wn is a two-element vector,
Wn = [ w1 w2]
Thestopband is w1 < <w2.
H s ( )
B s ( )
A s ( )
---------- -
b 1 ( )s
n
b 2 ( )s
n 1
L b n 1 + ( ) + + +
s
n
a 2 ( )s
n 1
L a n 1 + ( ) + + +
------------------------------------------------------------------------------------- = =
1 2
besself
7-28
With different numbers of output arguments, bessel f directly obtains other
realizationsof theanalogfilter. Toobtainzero-pole-gainform, usethreeoutput
arguments as shown below.
[ z, p, k] = bessel f ( n, Wn) or
[ z, p, k] = bessel f ( n, Wn, ' f t ype' ) returns thezeros andpoles in length n or
2*n column vectors z and p and thegain in thescalar k.
Toobtain state-spaceform, usefour output arguments as shown below.
[ A, B, C, D] = bessel f ( n, Wn) or
[ A, B, C, D] = bessel f ( n, Wn, ' f t ype' ) whereA, B, C, and Dare
and u is theinput, x is thestatevector, and y is theoutput.
Example Design a fifth-order analoglowpass Bessel filter that suppresses frequencies
greater than 10,000 rad/s and plot thefrequency responseof thefilter using
f r eqs.
[ b, a] = bessel f ( 5, 10000) ;
f r eqs( b, a) %Pl ot f r equency r esponse
x

Ax Bu + =
y Cx Du + =
besself
7-29
Limitations Lowpass Bessel filters havea monotonically decreasingmagnituderesponse,
as dolowpass Butterworth filters. Compared totheButterworth, Chebyshev,
and elliptic filters, theBessel filter has theslowest rolloff and requires the
highest order tomeet an attenuation specification.
For high order filters, thestate-spaceformis themost numerically accurate,
followed by thezero-pole-gain form. Thetransfer function coefficient formis
theleast accurate; numerical problems can arisefor filter orders as lowas 15.
Algorithm bessel f performs a four-step algorithm:
1 I t finds lowpass analogprototypepoles, zeros, and gain usingthebessel ap
function.
2 I t converts thepoles, zeros, and gain intostate-spaceform.
3 I t transformsthelowpass filter intoabandpass, highpass, or bandstopfilter
with desired cutoff frequencies usinga state-spacetransformation.
4 I t converts thestate-spacefilter back totransfer function or zero-pole-gain
form, as required.
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
7-30
See Also
bessel ap Bessel analoglowpass filter prototype.
but t er Butterworth analogand digital filter design.
cheby1 Chebyshev typeI filter design (passband ripple).
cheby2 Chebyshev typeI I filter design (stopband ripple).
el l i p Elliptic (Cauer) filter design.
bilinear
7-31
7bilinear
Purpose Bilinear transformation method for analog-to-digital filter conversion.
Syntax [ zd, pd, kd] = bi l i near ( z, p, k, f s)
[ zd, pd, kd] = bi l i near ( z, p, k, f s, Fp)
[ numd, dend] = bi l i near ( num, den, f s)
[ numd, dend] = bi l i near ( num, den, f s, Fp)
[ Ad, Bd, Cd, Dd] = bi l i near ( A, B, C, D, f s)
[ Ad, Bd, Cd, Dd] = bi l i near ( A, B, C, D, f s, Fp)
Description Thebilinear transformation is amathematical mappingof variables. I n digital
filtering, it is a standard method of mappingthes or analogplaneintothez or
digital plane. I t transformsanalogfilters, designedusingclassical filter design
techniques, intotheir discreteequivalents.
Thebilinear transformation maps thes-planeintothez-planeby
This transformation maps thej axis (from =- to+) repeatedly around
theunit circle( , from = to) by
bi l i near can accept anoptional parameter Fp that specifiesprewarping. Fp, in
hertz, indicates a match frequency, that is, a frequency for which the
frequency responses beforeand after mappingmatch exactly. I n prewarped
mode, thebilinear transformation maps thes-planeintothez-planewith
H z ( ) H s ( )
s 2f
s
z 1
z 1 +
------------ =
=
e
j
2tan
1

2f
s
--------
'

=
H z ( ) H s ( )
s
2f
p

f
p
f
s
----


tan
------------------------
z 1 ( )
z 1 + ( )
----------------- =
=
bilinear
7-32
With theprewarpingoption, bi l i near maps thej axis (from =- to+)
repeatedly around theunit circle( , from = to) by
I n prewarped mode, bi l i near matches thefrequency 2f
p
(in radians per
second) in thes-planetothenormalized frequency 2f
p
/f
s
(in radians per
second) in thez-plane.
Thebi l i near function works with threedifferent linear system
representations: zero-pole-gain, transfer function, and state-spaceform.
Zero-Pole-Gain
[ zd, pd, kd] =bi l i near ( z, p, k, f s) and
[ zd, pd, kd] =bi l i near ( z, p, k, f s, Fp) convert thes-domaintransfer function
specified by z, p, and k toa discreteequivalent. I nputs z and p arecolumn
vectorscontainingthezerosandpoles, k isascalar gain, andf s isthesampling
frequency in hertz. bi l i near returns thediscreteequivalent in column vectors
zd and pd and scalar kd. Fp is theoptional match frequency, in hertz, for
prewarping.
Transfer Function
[ numd, dend] =bi l i near ( num, den, f s) and
[ numd, dend] =bi l i near ( num, den, f s, Fp) convert an s-domain transfer
functiongivenbynumandden toadiscreteequivalent. Rowvectorsnumandden
specify thecoefficients of thenumerator and denominator, respectively, in
descendingpowers of s.
e
j
2tan
1

f
p
f
s
----
'

tan
2f
p
-----------------------------
'




=
num s ( )
den s ( )
--------------------
num 1 ( )s
nn
L numnn ( )s num nn 1 + ( ) + + +
den 1 ( )s
nd
L den nd ( )s den nd 1 + ( ) + + +
---------------------------------------------------------------------------------------------------------------------- =
bilinear
7-33
f s isthesamplingfrequencyinhertz. bi l i near returnsthediscreteequivalent
in rowvectors numd and dend in descendingpowers of z (ascendingpowers
of z
-1
). Fp is theoptional match frequency, in hertz, for prewarping.
State-Space
[ Ad, Bd, Cd, Dd] =bi l i near ( A, B, C, D, f s) and
[ Ad, Bd, Cd, Dd] =bi l i near ( A, B, C, D, f s, Fp) convert thecontinuous-time
state-spacesystemin matrices A, B, C, D,
tothediscrete-timesystem
f s isthesamplingfrequencyinhertz. bi l i near returnsthediscreteequivalent
in matrices Ad, Bd, Cd, Dd. Fp is theoptional match frequency, in hertz, for
prewarping.
Algorithm bi l i near uses oneof twoalgorithms dependingon theformat of theinput
linear systemyou supply. Onealgorithmworks on thezero-pole-gain format
andtheother on thestate-spaceformat. For transfer function representations,
bi l i near converts tostate-spaceform, performs thetransformation, and
converts theresultingstate-spacesystemback totransfer function form.
Zero-Pole-Gain Algorithm
For a systemin zero-pole-gain form, bi l i near performs four steps:
1 I f Fp is present, k =2*pi *Fp/ t an( pi *Fp/ f s) ; otherwisek =2*f s.
2 I t strips any zeros at using
z = z( f i nd( f i ni t e( z) ) ) ;
x

Ax Bu + =
y Cx Du + =
x n 1 + [ ] A
d
x n [ ] B
d
u n [ ] + =
y n [ ] C
d
x n [ ] D
d
u n [ ] + =
bilinear
7-34
3 I t transforms thezeros, poles, and gain using
pd = ( 1+p/ k) . / ( 1- p/ k) ;
zd = ( 1+z/ k) . / ( 1- z/ k) ;
kd = r eal ( k*pr od( f s- z) . / pr od( f s- p) ) ;
4 I t adds extra zeros at -1 sotheresultingsystemhas equivalent numerator
and denominator order.
State-Space Algorithm
For a systemin state-spaceform, bi l i near performs twosteps:
1 I f Fp is present, k =2*pi *Fp/ t an( pi *Fp/ f s) ; elsek =2*f s.
2 I t computes Ad, Bd, Cd, and Dd in terms of A, B, C, and Dusing
bi l i near implements theserelations usingconventional MATLAB
statements. Thescalar r is arbitrary; bi l i near uses toensuregood
quantization noiseproperties in theresultingsystem.
Diagnostics bi l i near requires that thenumerator order benogreater than the
denominator order. I f this is not thecase, bi l i near displays
Numer at or cannot be hi gher or der t han denomi nat or .
For bi l i near todistinguish between thezero-pole-gain and transfer function
linear systemformats, thefirst twoinput parameters must bevectors with the
sameorientation in thesecases. I f this is not thecase, bi l i near displays
Fi r st t wo ar gument s must have t he same or i ent at i on.
A
d
I
1
k
---
'

A +
'

I
1
k
---
'

A
'

1
=
B
d
2k
r
------- I
1
k
---
'

A
'

1
B =
C
d
rC I
1
k
---
'

A
'

1
=
D
d
1
k
---
'

C I
1
k
---
'

A
'

1
B D + =
r 2 k =
bilinear
7-35
See Also
References [1] Parks, T.W., and C.S. Burrus. Digital Filter Design. NewYork: J ohn Wiley
& Sons, 1987. Pgs. 209-213.
[2] Oppenheim, A.V., and R.W. Schafer. Discrete-TimeSignal Processing.
Englewood Cliffs, NJ : Prentice-Hall, 1989. Pgs. 415-430.
i mpi nvar Analogtodigital conversion usingtheimpulse
invariancemethod.
l p2bp Transformlowpass analogfilters tobandpass.
l p2bs Transformlowpass analogfilters tobandstop.
l p2hp Transformlowpass analogfilters tohighpass.
l p2l p Changethecut-off frequency for lowpass analog
filters.
blackman
7-36
7blackman
Purpose Computea Blackman window.
Syntax w = bl ackman( n)
w = bl ackman( n, ' sf l ag' )
Description w=bl ackman( n) returns then-point symmetric Blackman windowin the
column vector w, wheren is a positiveinteger.
w=bl ackman( n, ' sf l ag' ) returns an n-point Blackman windowusingthe
windowsamplingspecified by ' sf l ag' , which can beeither ' per i odi c' or
' symmet r i c' (thedefault). When ' per i odi c' is specified, bl ackman computes
a length n+1 windowand returns thefirst n points.
Note I f you specify a one-point window(set n=1), thevalue1 is returned.
Algorithm Theequation for computingthecoefficients of a Blackman windowis
Blackmanwindowshaveslightlywider central lobesandlesssidebandleakage
than equivalent length Hammingand Hann windows.
Examples w = bl ackman( 64) ;
pl ot ( w)
t i t l e( ' Bl ackman Wi ndow' )
w k 1 + [ ] 0.42 0.5 2
k
n 1
------------ -
'

cos 0.08 4
k
n 1
------------ -
'

cos + k 0 = n 1 , , , =
blackman
7-37
See Also
References [1] Oppenheim, A.V., and R.W. Schafer. Discrete-TimeSignal Processing.
Englewood Cliffs, NJ : Prentice-Hall, 1989, pp. 447-448.
0 10 20 30 40 50 60 70
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
Blackman Window
bar t l et t Computea Bartlett window.
boxcar Computea rectangular window.
chebwi n Computea Chebyshev window.
hammi ng Computea Hammingwindow.
hann Computea Hann window.
kai ser Computea Kaiser window.
t r i ang Computea triangular window.
boxcar
7-38
7boxcar
Purpose Computea rectangular window.
Syntax w = boxcar ( n)
Description w=boxcar ( n) returnsarectangular windowof lengthninthecolumnvector w.
This function is providedfor completeness; arectangular windowis equivalent
tonowindowat all.
Algorithm w = ones( n, 1) ;
See Also
References [1] Oppenheim, A.V., and R.W. Schafer. Discrete-TimeSignal Processing.
Englewood Cliffs, NJ : Prentice-Hall, 1989, pp. 447-448.
bar t l et t Computea Bartlett window.
bl ackman Computea Blackman window.
chebwi n Computea Chebyshev window.
hammi ng Computea Hammingwindow.
hann Computea Hann window.
kai ser Computea Kaiser window.
t r i ang Computea triangular window.
buffer
7-39
7buffer
Purpose Buffer a signal vector intoa matrix of data frames.
Syntax y = buf f er ( x, n)
y = buf f er ( x, n, p)
y = buf f er ( x, n, p, opt )
[ y, z] = buf f er ( . . . )
[ y, z, opt ] = buf f er ( . . . )
Description y =buf f er ( x, n) partitionsalength-L signal vector x intononoverlappingdata
segments (frames) of length n. Each data frameoccupies onecolumn of matrix
output y, which has n rows and cei l ( L/ n) columns. I f L is not evenly divisible
by n, thelast column is zero-padded tolength n.
y =buf f er ( x, n, p) overlaps or underlaps successiveframes in theoutput
matrix by p samples:
For 0 <p <n (overlap), buf f er repeats thefinal p samples of each frameat
thebeginningof thefollowingframe. For example, if x =1: 30 and n =7, an
overlap of p =3 looks likethis.
Thefirst framestarts with p zeros (thedefault initial condition), and the
number of columns in y is cei l ( L/ ( n- p) ) .
y =
0 2 6 10 14 18 22 26
0 3 7 11 15 19 23 27
0 4 8 12 16 20 24 28
1 5 9 13 17 21 25 29
2 6 10 14 18 22 26 30
3 7 11 15 19 23 27 0
4 8 12 16 20 24 28 0
buffer
7-40
For p <0 (underlap), buf f er skips p samples between consecutiveframes.
For example, if x =1: 30 andn =7, abuffer with underlapof p =- 3 looks like
this.
Thenumber of columns in y is cei l ( L/ ( n- p) ) .
y =buf f er ( x, n, p, opt ) specifies a vector of samples toprecedex( 1) in an
overlappingbuffer, or thenumber of initial samples toskipin an underlapping
buffer:
For 0 <p <n (overlap), opt specifies alength-p vector toinsert beforex( 1) in
thebuffer. Thisvector canbeconsideredaninitial condition, whichisneeded
when thecurrent bufferingoperation is onein a sequenceof consecutive
bufferingoperations. Tomaintain thedesiredframeoverlapfromonebuffer
tothenext, opt should contain thefinal p samples of theprevious buffer in
thesequence. SeeContinuous Buffering below.
By default, opt is zer os( p, 1) for an overlappingbuffer. Set opt to
' nodel ay' toskip theinitial condition and begin fillingthebuffer
immediately with x( 1) . I n this case, L must bel engt h( p) or longer. For
example, if x =1: 30 and n =7, a buffer with overlap of p =3 looks likethis.
For p <0 (underlap), opt is an integer valuein therange[ 0, - p] specifying
thenumber of initial input samples, x( 1: opt ) , toskipbeforeaddingsamples
y =
1 11 21
2 12 22
3 13 23
4 14 24
5 15 25
6 16 26
7 17 27
8 18 28
9 19 29
10 20 30
skipped
y =
1 5 9 13 17 21 25
2 6 10 14 18 22 26
3 7 11 15 19 23 27
4 8 12 16 20 24 28
5 9 13 17 21 25 29
6 10 14 18 22 26 30
7 11 15 19 23 27 0
buffer
7-41
tothebuffer. Thefirst valuein thebuffer is thereforex( opt +1) . By default,
opt is zerofor an underlappingbuffer.
This option is especially useful when thecurrent bufferingoperation is one
in a sequenceof consecutivebufferingoperations. Tomaintain thedesired
frameunderlap fromonebuffer tothenext, opt should equal thedifference
between thetotal number of points toskip between frames (p) and the
number of points that wereavailabletobeskipped in theprevious input to
buf f er . I f theprevious input had fewer than p points that could beskipped
after fillingthefinal frameof that buffer, theremainingopt points need to
beremoved fromthefirst frameof thecurrent buffer. SeeContinuous
Buffering belowfor an exampleof howthis works in practice.
[ y, z] =buf f er ( . . . ) partitions thelength-L signal vector x intoframes of
length n, and outputs only thefull frames in y. I f y is an overlappingbuffer, it
has n rows and mcolumns, where
m= f l oor ( L/ ( n- p) ) %When l engt h( opt ) =p
or
m= f l oor ( ( L- n) / ( n- p) ) +1 %When opt =' nodel ay'
I f y is an underlappingbuffer, it has n rows and mcolumns, where
m= f l oor ( ( L- opt ) / ( n- p) ) + ( r em( ( L- opt ) , ( n- p) ) >= n)
I f thenumber of samples in theinput vector (after theappropriateoverlapping
or underlappingoperations) exceeds thenumber of places availablein the
n-by-mbuffer, theremainingsamples in x areoutput in vector z, which for an
overlappingbuffer has length
l engt h( z) = L - m*( n- p) %When l engt h( opt ) =p
or
l engt h( z) = L - ( ( m- 1) *( n- p) +n) %When opt =' nodel ay'
and for an underlappingbuffer has length
l engt h( z) = ( L- opt ) - m*( n- p)
buffer
7-42
Output z shares thesameorientation (rowor column) as x. I f thereareno
remainingsamples in theinput after thebuffer with thespecified overlap or
underlap is filled, z is an empty vector.
[ y, z, opt ] =buf f er ( . . . ) returns thelast p samples of aoverlappingbuffer in
output opt . I n an underlappingbuffer, opt is thedifferencebetween thetotal
number of pointstoskipbetweenframes(- p) andthenumber of pointsinx that
wereavailabletobeskipped after fillingthelast frame:
For 0 <p <n (overlap), opt (as an output) contains thefinal p samples in the
last frameof thebuffer. This vector can beused as theinitial condition for a
subsequent bufferingoperation in a sequenceof consecutivebuffering
operations. This allows thedesiredframeoverlaptobemaintainedfromone
buffer tothenext. SeeContinuous Buffering below.
For p <0 (underlap), opt (as an output) is thedifferencebetween thetotal
number of points toskip between frames (- p) and thenumber of points in x
that wereavailabletobeskipped after fillingthelast frame.
opt = m*( n- p) + opt - L %z i s t he empt y vect or .
whereopt on theright-hand sideis theinput argument tobuf f er , and opt
on theleft-hand sideis theoutput argument. Heremis thenumber of
columns in thebuffer, which is
m= f l oor ( ( L- opt ) / ( n- p) ) + ( r em( ( L- opt ) , ( n- p) ) >=n)
Notethat for an underlappingbuffer output opt is always zerowhen
output z contains data.
Theopt output for an underlappingbuffer is especially useful when the
current bufferingoperation is onein a sequenceof consecutivebuffering
operations. Theopt output fromeach bufferingoperation specifies the
number of samples that need tobeskipped at thestart of thenext buffering
operation tomaintain thedesired frameunderlap fromonebuffer tothe
next. I f fewer than p points wereavailabletobeskippedafter fillingthefinal
frameof thecurrent buffer, theremainingopt points need toberemoved
fromthefirst frameof thenext buffer.
I n a sequenceof bufferingoperations, theopt output fromeach operation
should beused as theopt input tothesubsequent bufferingoperation. This
ensures that thedesired frameoverlap or underlap is maintained frombuffer
buffer
7-43
tobuffer, as well as fromframetoframewithin thesamebuffer. See
Continuous Bufferingbelowfor an exampleof howthis works in practice.
Continuous Buffering
I n a continuous bufferingoperation, thevector input tothebuf f er function
represents oneframein a sequenceof frames that makeup a discretesignal.
Thesesignal framescanoriginatein aframe-baseddataacquisition process, or
within a frame-based algorithmliketheFFT.
As an example, you might acquiredata froman A/D card in frames of 64
samples. I n thesimplest case, you could rebuffer thedata intoframes of 16
samples; buf f er with n =16 creates a buffer of four frames fromeach
64-element input frame. Theresult is that thesignal of framesize64has been
converted toa signal of framesize16; nosamples wereadded or removed.
I n thegeneral casewheretheoriginal signal framesize, L, is not equally
divisibleby thenewframesize, n, theoverflowfromthelast frameneeds tobe
captured and recycled intothefollowingbuffer. You can dothis by iteratively
callingbuf f er on input x with thetwo-output-argument syntax.
[ y, z] = buf f er ( [ z; x] , n) %x i s a col umn vect or .
[ y, z] = buf f er ( [ z, x] , n) %x i s a r ow vect or .
This simply captures any buffer overflowin z, and prepends thedata tothe
subsequent input in thenext call tobuf f er . Again, theinput signal, x, of frame
sizeL, has been converted toa signal of framesizen without any insertion or
deletion of samples.
Notethat continuous bufferingcannot bedonewith thesingle-output syntax
y = buf f er ( . . . ) , becausethelast frameof y inthiscaseiszeropadded, which
adds newsamples tothesignal.
Continuous bufferingin thepresenceof overlap and underlap is handled with
theopt parameter, which is used as both an input and output tobuf f er . The
followingtwoexamples demonstratehowtheopt parameter should beused.
buffer
7-44
Examples Example 1: Continuous Overlapping Buffers
First createa buffer containing100 frames, each with 11 samples.
dat a = buf f er ( 1: 1100, 11) ; %11 sampl es per f r ame
I maginethat theframes (columns) in thematrixcalleddat a arethesequential
outputs of a data acquisition board samplinga physical signal: dat a( : , 1) is
thefirst D/A output, containingthefirst 11 signal samples; dat a( : , 2) is the
second output, containingthenext 11 signal samples, and soon.
You want torebuffer this signal fromtheacquired framesizeof 11 toa frame
sizeof 4 with an overlap of 1. Todothis, you will repeatedly call buf f er to
operateon each successiveinput frame, usingtheopt parameter tomaintain
consistency in theoverlap fromonebuffer tothenext.
Set thebuffer parameters.
n = 4; %New f r ame si ze
p = 1; %Over l ap
opt = - 5; %Val ue of y( 1)
z = [ ] ; %I ni t i al i ze t he car r y- over vect or .
Nowrepeatedly call buf f er , each timepassingin a newsignal framefrom
dat a. Notethat overflowsamples (returned in z) arecarried over and
prepended totheinput in thesubsequent call tobuf f er .
f or i =1: si ze( dat a, 2) , %Loop over each sour ce f r ame ( col umn) .
x = dat a( : , i ) ; %A si ngl e f r ame of t he D/ A out put
[ y, z, opt ] = buf f er ( [ z; x] , n, p, opt ) ;
di sp( y) ; %Di spl ay t he buf f er of dat a.
pause
end
buffer
7-45
Heres what happens duringthefirst four iterations.
Notethat thesizeof theoutput matrix, y, can varybyasinglecolumn fromone
iteration tothenext. This is typical for bufferingoperations with overlap or
underlap.
[ 1: 11] i =1
5 3 6
1 4 7
2 5 8
3 6 9
Iteration Input frame[ z; x] ' opt (input) opt (output) Output buffer ( y) Overflow ( z)
[ 10 11] 5 9
i =2 [ 10 11 12: 22] 9 21
9 12 15 18
10 13 16 19
11 14 17 20
12 15 18 21
[ 22]
i =3 [ 22 23: 33] 21 33
21 24 27 30
22 25 28 31
23 26 29 32
24 27 30 33
[ ]
33 36 39
34 37 40
35 38 41
36 39 42
[ 43 44] 42 [ 34: 44]
i =4
33
buffer
7-46
Example 2: Continuous Underlapping Buffers
Again createa buffer containing100 frames, each with 11 samples.
dat a = buf f er ( 1: 1100, 11) ; %11 sampl es per f r ame
Again, imaginethat dat a( : , 1) is thefirst D/A output, containingthefirst 11
signal samples; dat a( : , 2) is thesecond output, containingthenext 11 signal
samples, and soon.
You want torebuffer this signal fromtheacquired framesizeof 11 toa frame
sizeof 4 with an underlap of 2. Todothis, you will repeatedly call buf f er to
operateon each successiveinput frame, usingtheopt parameter tomaintain
consistency in theunderlap fromonebuffer tothenext.
Set thebuffer parameters.
n = 4; %New f r ame si ze
p = - 2; %Under l ap
opt = 1; %Ski p t he f i r st i nput el ement , x( 1) .
z = [ ] ; %I ni t i al i ze t he car r y- over vect or .
Nowrepeatedly call buf f er , each timepassingin a newsignal framefrom
dat a. Notethat overflowsamples (returned in z) arecarried over and
prepended totheinput in thesubsequent call tobuf f er .
f or i =1: si ze( dat a, 2) , %Loop over each sour ce f r ame ( col umn) .
x = dat a( : , i ) ; %A si ngl e f r ame of t he D/ A out put
[ y, z, opt ] = buf f er ( [ z; x] , n, p, opt ) ;
di sp( y) ; %Di spl ay t he buf f er of dat a.
pause
end
buffer
7-47
Heres what happens duringthefirst threeiterations.
Diagnostics Error messages aredisplayed when p n or l engt h( opt ) l engt h( p) in an
overlappingbuffer case.
Fr ame over l ap P must be l ess t han t he buf f er si ze N.
I ni t i al condi t i ons must be speci f i ed as a l engt h- P vect or .
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
r eshape Reshapearray.
buttap
7-48
7buttap
Purpose Butterworth analoglowpass filter prototype.
Syntax [ z, p, k] = but t ap( n)
Description [ z, p, k] =but t ap( n) returns thepoles and gain of an order n Butterworth
analoglowpass filter prototype. Thefunction returns thepoles in thelength n
column vector p and thegain in scalar k. z is an empty matrix becausethere
arenozeros. Thetransfer function is
Butterworth filters arecharacterized by a magnituderesponsethat is
maximally flat in thepassbandandmonotonicoverall. I n thelowpass case, the
first 2n1derivatives of thesquaredmagnituderesponsearezeroat =0. The
squared magnituderesponsefunction is
correspondingtoa transfer function with poles equally spaced around a circle
in theleft half plane. Themagnituderesponseat thecutoff frequency
0
is
always regardlessof thefilter order. but t ap sets
0
to1for anormalized
result.
Algorithm z = [ ] ;
p = exp( sqr t ( - 1) *( pi *( 1: 2: 2*n- 1) / ( 2*n) +pi / 2) ) . ' ;
k = r eal ( pr od( - p) ) ;
See Also
References [1] Parks, T.W., and C.S. Burrus. Digital Filter Design. NewYork: J ohn Wiley
& Sons, 1987. Chapter 7.
H s ( )
z s ( )
p s ( )
----------
k
s p 1 ( ) ( ) s p 2 ( ) ( )L s p n ( ) ( )
-------------------------------------------------------------------------------- = =
H ( )
2
1
1
0
( )
2n
+
----------------------------------- - =
1 2
bessel ap Bessel analoglowpass filter prototype.
but t er Butterworth analogand digital filter design.
cheb1ap Chebyshev typeI analoglowpass filter prototype.
cheb2ap Chebyshev typeI I analoglowpass filter prototype.
el l i pap Elliptic analoglowpass filter prototype.
butter
7-49
7butter
Purpose Butterworth analogand digital filter design.
Syntax [ b, a] = but t er ( n, Wn)
[ b, a] = but t er ( n, Wn, ' f t ype' )
[ b, a] = but t er ( n, Wn, ' s' )
[ b, a] = but t er ( n, Wn, ' f t ype' , ' s' )
[ z, p, k] = but t er ( . . . )
[ A, B, C, D] = but t er ( . . . )
Description but t er designs lowpass, bandpass, highpass, and bandstop digital and analog
Butterworth filters. Butterworth filters arecharacterized by a magnitude
responsethat is maximally flat in thepassband and monotonic overall.
Butterworth filters sacrificerolloff steepness for monotonicity in thepass- and
stopbands. Unless thesmoothness of theButterworth filter is needed, an
ellipticor Chebyshev filter can generally providesteeper rolloff characteristics
with a lower filter order.
Digital Domain
[ b, a] =but t er ( n, Wn) designs an order n lowpass digital Butterworth filter
with cutoff frequency Wn. I t returns thefilter coefficients in length n+1 row
vectors b and a, with coefficients in descendingpowers of z.
Cutoff frequency is that frequency wherethemagnituderesponseof thefilter
is . For but t er , thenormalized cutoff frequency Wn must bea number
between 0 and 1, where1 corresponds totheNyquist frequency, radians per
sample.
I f Wn is atwo-element vector, Wn =[ w1 w2] , but t er returns an order 2*n digital
bandpass filter with passband w1 < <w2.
H z ( )
B z ( )
A z ( )
-----------
b 1 ( ) b 2 ( )z
1
L b n 1 + ( )z
n
+ + +
1 a 2 ( )z
1
L a n 1 + ( )z
n
+ + +
------------------------------------------------------------------------------------ = =
1 2
butter
7-50
[ b, a] =but t er ( n, Wn, ' f t ype' ) designs a highpass or bandstop filter, where
thestring' f t ype' is either:
' hi gh' for a highpass digital filter with cutoff frequency Wn
' st op' for an order 2*n bandstop digital filter if Wn is a two-element vector,
Wn =[ w1 w2] . Thestopband is w1 < <w2.
With different numbers of output arguments, but t er directly obtains other
realizations of thefilter. Toobtain zero-pole-gain form, usethreeoutput
arguments as shown below.
[ z, p, k] =but t er ( n, Wn) or
[ z, p, k] = but t er ( n, Wn, ' f t ype' ) returns thezeros and poles in length n
column vectors z and p, and thegain in thescalar k.
Toobtain state-spaceform, usefour output arguments as shown below.
[ A, B, C, D] =but t er ( n, Wn) or
[ A, B, C, D] = but t er ( n, Wn, ' f t ype' ) whereA, B, C, and Dare
and u is theinput, x is thestatevector, and y is theoutput.
Analog Domain
[ b, a] =but t er ( n, Wn, ' s' ) designs an order n lowpass analogButterworth
filter withcutoff frequencyWn. I t returnsthefilter coefficientsinthelengthn+1
rowvectors b and a, in descendingpowers of s, derived fromthetransfer
function
but t er s cutoff frequency Wn must begreater than 0.
I f Wn is a two-element vector with w1 <w2, but t er ( n, Wn, ' s' ) returns an order
2*n bandpass analogfilter with passband w1 < <w2.
x n 1 + [ ] Ax n [ ] Bu n [ ] + =
y n [ ] Cx n [ ] Du n [ ] + =
H s ( )
B s ( )
A s ( )
---------- -
b 1 ( )s
n
b 2 ( )s
n 1
L b n 1 + ( ) + + +
s
n
a 2 ( )s
n 1
L a n 1 + ( ) + + +
------------------------------------------------------------------------------------- = =
butter
7-51
[ b, a] =but t er ( n, Wn, ' f t ype' , ' s' ) designs a highpass or bandstop filter.
With different numbers of output arguments, but t er directly obtains other
realizationsof theanalogfilter. Toobtainzero-pole-gainform, usethreeoutput
arguments as shown below.
[ z, p, k] =but t er ( n, Wn, ' s' ) or
[ z, p, k] = but t er ( n, Wn, ' f t ype' , ' s' ) returns thezeros and poles in length
n or 2*n column vectors z and p and thegain in thescalar k.
Toobtain state-spaceform, usefour output arguments as shown below.
[ A, B, C, D] =but t er ( n, Wn, ' s' ) or
[ A, B, C, D] = but t er ( n, Wn, ' f t ype' , ' s' ) whereA, B, C, and Dare
and u is theinput, x is thestatevector, and y is theoutput.
Examples Example 1
For data sampled at 1000 Hz, design a 9th-order highpass Butterworth filter
with cutoff frequency of 300 Hz.
[ b, a] = but t er ( 9, 300/ 500, ' hi gh' ) ;
Thefilters frequency responseis
f r eqz( b, a, 128, 1000)
x

Ax Bu + =
y Cx Du + =
butter
7-52
Example 2
Design a 10th-order bandpass Butterworth filter with a passband from100to
200 Hz and plot its impulseresponse, or unit sampleresponse.
n = 5; Wn = [ 100 200] / 500;
[ b, a] = but t er ( n, Wn) ;
[ y, t ] = i mpz( b, a, 101) ;
st em( t , y)
0 50 100 150 200 250 300 350 400 450 500
800
600
400
200
0
200
Frequency (Hz)
P
h
a
s
e

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

(
d
B
)
0 10 20 30 40 50 60 70 80 90 100
0.25
0.2
0.15
0.1
0.05
0
0.05
0.1
0.15
0.2
butter
7-53
Limitations For high order filters, thestate-spaceformis themost numerically accurate,
followed by thezero-pole-gain form. Thetransfer function coefficient formis
theleast accurate; numerical problems can arisefor filter orders as lowas 15.
Algorithm but t er uses a five-step algorithm:
1 I t findsthelowpassanalogprototypepoles, zeros, andgainusingthebut t ap
function.
2 I t converts thepoles, zeros, and gain intostate-spaceform.
3 I t transformsthelowpass filter intoabandpass, highpass, or bandstopfilter
with desired cutoff frequencies, usinga state-spacetransformation.
4 For digital filter design, but t er uses bi l i near toconvert theanalogfilter
intoa digital filter through a bilinear transformation with frequency
prewarping. Careful frequency adjustment guarantees that theanalog
filters and thedigital filters will havethesamefrequency response
magnitudeat Wn or w1 and w2.
5 I t converts thestate-spacefilter back totransfer function or zero-pole-gain
form, as required.
See Also
bessel f Bessel analogfilter design.
but t ap Butterworth analoglowpass filter prototype.
but t or d Calculatetheorder of a Butterworth filter.
cheby1 Chebyshev typeI filter design (passband ripple).
cheby2 Chebyshev typeI I filter design (stopband ripple).
el l i p Elliptic (Cauer) filter design.
maxf l at Generalized Butterworth filter design.
buttord
7-54
7buttord
Purpose Calculatetheorder and cutoff frequency for a Butterworth filter.
Syntax [ n, Wn] = but t or d( Wp, Ws, Rp, Rs)
[ n, Wn] = but t or d( Wp, Ws, Rp, Rs, ' s' )
Description but t or d calculates theminimumorder of adigital or analogButterworth filter
required tomeet a set of filter design specifications.
Digital Domain
[ n, Wn] =but t or d( Wp, Ws, Rp, Rs) returns thelowest order, n, of thedigital
Butterworth filter that loses nomorethan Rp dB in thepassband and has at
least Rs dB of attenuation in thestopband. Thescalar (or vector) of
correspondingcutoff frequencies, Wn, is alsoreturned. Usetheoutput
arguments n and Wn in but t er .
Choosetheinput argumentstospecifythestopbandandpassbandaccordingto
thefollowingtable.
Table 7-1: Description of Stopband and Passband Filter Parameters
Wp Passband corner frequency Wp, thecutoff frequency, is a scalar
or a two-element vector with values between 0 and 1, with 1
correspondingtothenormalized Nyquist frequency, radians
per sample.
Ws Stopband corner frequency Ws, is a scalar or a two-element
vector with values between 0 and 1, with 1 correspondingto
thenormalized Nyquist frequency.
Rp Passband ripple, in decibels. This valueis themaximum
permissiblepassband loss in decibels.
Rs Stopband attenuation, in decibels. This valueis thenumber of
decibels thestopband is down fromthepassband.
buttord
7-55
Usethefollowingguidetospecify filters of different types.
I f your filter specifications call for a bandpass or bandstop filter with unequal
ripplein each of thepassbands or stopbands, design separatelowpass and
highpass filters accordingtothespecifications in this table, and cascadethe
twofilters together.
Analog Domain
[ n, Wn] =but t or d( Wp, Ws, Rp, Rs, ' s' ) finds theminimumorder n and cutoff
frequencies Wn for an analogButterworth filter. You specify thefrequencies Wp
and Ws similar toTable7-1, Description of Stopband and Passband Filter
Parameters, only in this caseyou specify thefrequency in radians per second,
and thepassband or thestopband can beinfinite.
Usebut t or dfor lowpass, highpass, bandpass, andbandstopfiltersasdescribed
in Table7-2, Filter TypeStopband and Passband Specifications.
Table 7-2: Filter Type Stopband and Passband Specifications
Filter Type Stopband and Passband Conditions Stopband Passband
Lowpass Wp <Ws, both scalars ( Ws, 1) ( 0, Wp)
Highpass Wp >Ws, both scalars ( 0, Ws) ( Wp, 1)
Bandpass Theinterval specified by Ws contains
theonespecified by Wp
(Ws( 1) < Wp( 1) < Wp( 2) < Ws( 2) ).
( 0, Ws( 1) )
and
( Ws( 2) , 1)
( Wp( 1) , Wp( 2) )
Bandstop Theinterval specified by Wp contains
theonespecified by Ws
(Wp( 1) < Ws( 1) < Ws( 2) < Wp( 2) ).
( 0, Wp( 1) )
and
( Wp( 2) , 1)
( Ws( 1) , Ws( 2) )
buttord
7-56
Examples Example 1
For data sampled at 1000 Hz, design a lowpass filter with less than 3 dB of
ripplein thepassband, defined from0 to40 Hz, and at least 60 dB of
attenuation in thestopband, defined from150 Hz totheNyquist frequency
(500 Hz). Plot thefilters frequency response.
Wp = 40/ 500; Ws = 150/ 500;
[ n, Wn] = but t or d( Wp, Ws, 3, 60)
n =
5
Wn =
0. 0810
[ b, a] = but t er ( n, Wn) ;
f r eqz( b, a, 512, 1000) ; t i t l e( ' n=5 But t er wor t h Lowpass Fi l t er ' )
0 50 100 150 200 250 300 350 400 450 500
500
400
300
200
100
0
Frequency (Hz)
P
h
a
s
e

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

(
d
B
)
n=5 Butterworth Lowpass Filter
buttord
7-57
Example 2
Next design abandpass filter with passbandof 60 Hz to200 Hz, with less than
3 dB of rippleinthepassband, and40 dB attenuationinthestopbandsthat are
50 Hz wideon both sides of thepassband.
Wp = [ 60 200] / 500; Ws = [ 50 250] / 500;
Rp = 3; Rs = 40;
[ n, Wn] = but t or d( Wp, Ws, Rp, Rs)
n =
16
Wn =
0. 1198 0. 4005
[ b, a] = but t er ( n, Wn) ;
f r eqz( b, a, 128, 1000)
t i t l e( ' n=16 But t er wor t h Bandpass Fi l t er ' )
0 50 100 150 200 250 300 350 400 450 500
2500
2000
1500
1000
500
0
500
Frequency (Hz)
P
h
a
s
e

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

(
d
B
)
n=16 Butterworth Bandpass Filter
buttord
7-58
Algorithm but t or ds order prediction formulais describedin [1]. I t operates in theanalog
domain for both analogand digital cases. For thedigital case, it converts the
frequency parameters tothes-domain beforeestimatingtheorder andnatural
frequency, and then converts back tothez-domain.
but t or d initially develops a lowpass filter prototypeby transformingthe
passband frequencies of thedesired filter to1 rad/s (for lowpass and highpass
filters) and to-1 and 1 rad/s (for bandpass and bandstop filters). I t then
computestheminimumorder requiredfor alowpassfilter tomeet thestopband
specification.
See Also
References [1] Rabiner, L.R., and B. Gold. Theory and Application of Digital Signal
Processing. Englewood Cliffs, NJ : Prentice-Hall, 1975. Pg. 227.
but t er Design a Butterworth analogor digital filter.
cheb1or d Calculatetheorder for a Chebyshev typeI filter.
cheb2or d Calculatetheorder for a Chebyshev typeI I filter.
el l i por d Calculatetheorder for an ellipticfilter.
kai ser or d EstimateKaiser windowFI R filter parameters.
cceps
7-59
7cceps
Purpose Complex cepstral analysis.
Syntax xhat = cceps( x)
[ xhat , nd] = cceps( x)
[ xhat , nd, xhat 1] = cceps( x)
[ . . . ] = cceps( x, n)
Description Cepstral analysis is a nonlinear signal processingtechniquethat is applied
most commonly in speech processingand homomorphic filtering[1].
xhat =cceps( x) returns thecomplex cepstrumof the(assumed real)
sequencex. Theinput is altered, by theapplication of a linear phaseterm, to
havenophasediscontinuity at radians. That is, it is circularly shifted(after
zeropadding) by somesamples, if necessary, tohavezerophaseat radians.
[ xhat , nd] =cceps( x) returns thenumber of samples nd of (circular) delay
added tox prior tofindingthecomplex cepstrum.
[ xhat , nd, xhat 1] =cceps( x) returns a second complex cepstrum, computed
usingan alternaterootingalgorithm, in xhat 1. Thealternatemethod
([1] p.795) isuseful for short sequencesthat canberootedanddonot havezeros
on theunit circle. For thesesignals, xhat 1 can providea verification of xhat .
[ . . . ] =cceps( x, n) zeropads x tolength n and returns thelength n complex
cepstrumof x.
Algorithm cceps, in its basic form, is an M-fileimplementation of algorithm7.1 in [2]. A
lengthy Fortran programreduces tothreelines of MATLAB code:
h = f f t ( x) ;
l ogh = l og( abs( h) ) +sqr t ( - 1) *r cunwr ap( angl e( h) ) ;
y = r eal ( i f f t ( l ogh) ) ;
r cunwr ap is a special version of unwr ap that subtracts a straight linefromthe
phase.
cceps
7-60
See Also
References [1] Oppenheim, A.V., and R.W. Schafer. Discrete-TimeSignal Processing.
Englewood Cliffs, NJ : Prentice-Hall, 1989.
[2] I EEE. Programsfor Digital Signal Processing. I EEE Press. NewYork: J ohn
Wiley & Sons, 1979.
i cceps I nversecomplex cepstrum.
hi l ber t Hilbert transform.
r ceps Real cepstrumand minimumphasereconstruction.
unwr ap Unwrap phaseangles.
cell2sos
7-61
7cell2sos
Purpose Convert a cell array for second-order sections toa second-order section matrix.
Syntax m= cel l 2sos( c)
Description m= cel l 2sos( c) changes a 1-by-L cell array c consistingof 1-by-2cell arrays
intoan L-by-6second-order section matrix m. Matrix mtakes thesameformas
thematrix generated by t f 2sos. You can usem= cel l 2sos( c) toinvert the
results of c =sos2cel l ( m) .
c must bea cell array of theform
c = { {b1 a1} {b2 a2} . . . {bL aL} }
wherebothbi andai arerowvectorsof at most length3, andi =1, 2, ..., L. The
resultingmatrix mis given by
m= [ b1 a1; b2 a2; . . . ; bL aL]
See Also
sos2cel l Convert second-order section matrices tocell arrays.
t f 2sos Convert transfer functions tosecond-order sections.
cheb1ap
7-62
7cheb1ap
Purpose Chebyshev typeI analoglowpass filter prototype.
Syntax [ z, p, k] = cheb1ap( n, Rp)
Description [ z, p, k] =cheb1ap( n, Rp) returns thepoles and gain of an order n Chebyshev
typeI analoglowpassfilter prototypewith Rp dB of ripplein thepassband. The
function returns thepoles in thelength n column vector p and thegain in
scalar k. z is an empty matrix, becausetherearenozeros. Thetransfer
function is
Chebyshev typeI filters areequiripplein thepassband and monotonic in the
stopband. Thepoles areevenly spaced about an ellipsein theleft half plane.
TheChebyshev typeI cutoff frequency is set to1.0for a normalized result.
This is thefrequency at which thepassbandends andthefilter has magnitude
responseof 10
-Rp/20
.
See Also
References [1] Parks, T.W., and C.S. Burrus. Digital Filter Design. NewYork: J ohn Wiley
& Sons, 1987. Chapter 7.
H s ( )
z s ( )
p s ( )
----------
k
s p 1 ( ) ( ) s p 2 ( ) ( )L s p n ( ) ( )
-------------------------------------------------------------------------------- = =

0
bessel ap Bessel analoglowpass filter prototype.
but t ap Butterworth analogand digital filter design.
cheb2ap Chebyshev typeI analoglowpass filter prototype.
cheby1 Chebyshev typeI filter design (passband ripple).
el l i pap Elliptic analoglowpass filter prototype.
cheb1ord
7-63
7cheb1ord
Purpose Calculatetheorder for a Chebyshev typeI filter.
Syntax [ n, Wn] = cheb1or d( Wp, Ws, Rp, Rs)
[ n, Wn] = cheb1or d( Wp, Ws, Rp, Rs, ' s' )
Description cheb1or d calculatestheminimumorder of adigital or analogChebyshevtypeI
filter required tomeet a set of filter design specifications.
Digital Domain
[ n, Wn] =cheb1or d( Wp, Ws, Rp, Rs) returnsthelowest order n of theChebyshev
typeI filter that loses nomorethan Rp dB in thepassband and has at least
Rs dB of attenuation in thestopband. Thescalar (or vector) of corresponding
cutoff frequencies Wn, is alsoreturned. Usetheoutput arguments n andWn with
thecheby1 function.
Choosetheinput argumentstospecifythestopbandandpassbandaccordingto
thefollowingtable.
Table 7-3: Description of Stopband and Passband Filter Parameters
Wp Passband corner frequency Wp, thecutoff frequency, is a scalar
or a two-element vector with values between 0 and 1, with 1
correspondingtothenormalized Nyquist frequency, radians
per sample.
Ws Stopband corner frequency Ws, is a scalar or a two-element
vector with values between 0 and 1, with 1 correspondingto
thenormalized Nyquist frequency.
Rp Passband ripple, in decibels. This valueis themaximum
permissiblepassband loss in decibels.
Rs Stopband attenuation, in decibels. This valueis thenumber of
decibels thestopband is down fromthepassband.
cheb1ord
7-64
Usethefollowingguidetospecify filters of different types.
I f your filter specifications call for a bandpass or bandstop filter with unequal
ripplein each of thepassbands or stopbands, design separatelowpass and
highpass filters accordingtothespecifications in this table, and cascadethe
twofilters together.
Analog Domain
[ n, Wn] =cheb1or d( Wp, Ws, Rp, Rs, ' s' ) finds theminimumorder n and cutoff
frequencies Wn for an analogChebyshev typeI filter. You specify the
frequencies Wp and Ws similar toTable7-3, Description of Stopband and
Passband Filter Parameters, only in this caseyou specify thefrequency in
radians per second, and thepassband or thestopband can beinfinite.
Usecheb1or d for lowpass, highpass, bandpass, and bandstop filters as
described in Table7-4, Filter TypeStopband and Passband Specifications.
Examples For data sampled at 1000 Hz, design a lowpass filter with less than 3 dB of
ripplein thepassband defined from0 to40Hz and at least 60 dB of ripplein
thestopband defined from150 Hz totheNyquist frequency (500 Hz).
Wp = 40/ 500; Ws = 150/ 500;
Rp = 3; Rs = 60;
[ n, Wn] = cheb1or d( Wp, Ws, Rp, Rs)
Table 7-4: Filter Type Stopband and Passband Specifications
Filter Type Stopband and Passband Conditions Stopband Passband
Lowpass Wp <Ws, both scalars ( Ws, 1) ( 0, Wp)
Highpass Wp >Ws, both scalars ( 0, Ws) ( Wp, 1)
Bandpass Theinterval specified by Ws contains
theonespecified by Wp
(Ws( 1) < Wp( 1) < Wp( 2) < Ws( 2) ).
( 0, Ws( 1) )
and
( Ws( 2) , 1)
( Wp( 1) , Wp( 2) )
Bandstop Theinterval specified by Wp contains
theonespecified by Ws
(Wp( 1) < Ws( 1) < Ws( 2) < Wp( 2) ).
( 0, Wp( 1) )
and
( Wp( 2) , 1)
( Ws( 1) , Ws( 2) )
cheb1ord
7-65
n =
4
Wn =
0. 0800
[ b, a] = cheby1( n, Rp, Wn) ;
f r eqz( b, a, 512, 1000) ;
t i t l e( ' n=4 Chebyshev Type I Lowpass Fi l t er ' )
Next design a bandpass filter with a passband of 60 Hz to200 Hz, with less
than 3 dB of ripplein thepassband, and 40 dB attenuation in thestopbands
that are50 Hz wideon both sides of thepassband.
Wp = [ 60 200] / 500; Ws = [ 50 250] / 500;
Rp = 3; Rs = 40;
[ n, Wn] = cheb1or d( Wp, Ws, Rp, Rs)
n =
7
Wn =
0. 1200 0. 4000
[ b, a] = cheby1( n, Rp, Wn) ;
f r eqz( b, a, 512, 1000) ;
t i t l e( ' n=7 Chebyshev Type I Bandpass Fi l t er ' )
0 50 100 150 200 250 300 350 400 450 500
400
300
200
100
0
Frequency (Hz)
P
h
a
s
e

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

(
d
B
)
n=4 Chebyshev Type I Lowpass Filter
cheb1ord
7-66
Algorithm cheb1or d usestheChebyshevlowpassfilter order predictionformuladescribed
in [1]. Thefunction performs its calculations in theanalogdomain for both
analogand digital cases. For thedigital case, it converts thefrequency
parameters tothes-domain beforetheorder andnatural frequency estimation
process, and then converts themback tothez-domain.
cheb1or d initially develops a lowpass filter prototypeby transformingthe
passbandfrequenciesof thedesiredfilter to1rad/s(for low- or highpassfilters)
or to-1 and 1 rad/s (for bandpass or bandstop filters). I t then computes the
minimumorder requiredfor alowpassfilter tomeet thestopbandspecification.
See Also
References [1] Rabiner, L.R., and B. Gold. Theory and Application of Digital Signal
Processing. Englewood Cliffs, NJ : Prentice-Hall, 1975. Pg. 241.
0 50 100 150 200 250 300 350 400 450 500
1500
1000
500
0
500
Frequency (Hz)
P
h
a
s
e

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

(
d
B
)
n=7 Chebyshev Type I Bandpass Filter
but t or d Calculatetheorder for a Butterworth filter.
cheby1 Design a Chebyshev typeI filter (passband ripple).
cheb2or d Calculatetheorder for a Chebyshev typeI I filter.
el l i por d Calculatetheorder for an ellipticfilter.
kai ser or d EstimateKaiser windowFI R filter parameters.
cheb2ap
7-67
7cheb2ap
Purpose Chebyshev typeI I analoglowpass filter prototype.
Syntax [ z, p, k] = cheb2ap( n, Rs)
Description [ z, p, k] =cheb2ap( n, Rs) finds thezeros, poles, and gain of an order n
Chebyshev typeI I analoglowpass filter prototypewith stopband rippleRs dB
down fromthepassband peak value. cheb2ap returns thezeros and poles in
length n column vectors z and p andthegain in scalar k. I f n is odd, z is length
n- 1. Thetransfer function is
Chebyshev typeI I filters aremonotonic in thepassband and equiripplein the
stopband. Thepolelocations aretheinverseof thepolelocations of cheb1ap,
whosepoles areevenly spaced about an ellipsein theleft half plane. The
Chebyshev typeI I cutoff frequency
0
is set to1 for a normalized result. This
is thefrequency at which thestopband begins and thefilter has magnitude
responseof 10
-Rs/20
.
Algorithm Chebyshev typeI I filters aresometimes called inverseChebyshev filters
becauseof their relationshiptoChebyshev typeI filters. Thecheb2ap function
is a modification of theChebyshev typeI prototypealgorithm:
1 cheb2ap replaces thefrequency variable with 1/, turningthelowpass
filter intoa highpass filter whilepreservingtheperformanceat =1.
2 cheb2ap subtracts thefilter transfer function fromunity.
See Also
References [1] Parks, T.W., and C.S. Burrus. Digital Filter Design. NewYork: J ohn Wiley
& Sons, 1987. Chapter 7.
H s ( )
z s ( )
p s ( )
---------- k
s z 1 ( ) ( ) s z 2 ( ) ( )L s z n ( ) ( )
s p 1 ( ) ( ) s p 2 ( ) ( )L s p n ( ) ( )
-------------------------------------------------------------------------------- = =
bessel ap Bessel analoglowpass filter prototype.
but t ap Butterworth analoglowpass filter prototype.
cheb1ap Chebyshev typeI analoglowpass filter prototype.
cheby2 Chebyshev typeI I filter design (stopband ripple).
el l i pap Elliptic analoglowpass filter prototype.
cheb2ord
7-68
7cheb2ord
Purpose Calculatetheorder for a Chebyshev typeI I filter.
Syntax [ n, Wn] = cheb2or d( Wp, Ws, Rp, Rs)
[ n, Wn] = cheb2or d( Wp, Ws, Rp, Rs, ' s' )
Description cheb2or d calculates theminimumorder of a digital or analogChebyshev
typeI I filter required tomeet a set of filter design specifications.
Digital Domain
[ n, Wn] =cheb2or d( Wp, Ws, Rp, Rs) returnsthelowest order n of theChebyshev
typeI I filter that loses nomorethan Rp dB in thepassband and has at least
Rs dB of attenuation in thestopband. Thescalar (or vector) of corresponding
cutoff frequencies Wn, is alsoreturned. Usetheoutput arguments n and Wn in
cheby2.
Choosetheinput argumentstospecifythestopbandandpassbandaccordingto
thefollowingtable.
Table 7-5: Description of Stopband and Passband Filter Parameters
Wp Passband corner frequency Wp, thecutoff frequency, is a scalar
or a two-element vector with values between 0 and 1, with 1
correspondingtothenormalized Nyquist frequency, radians
per sample.
Ws Stopband corner frequency Ws, is a scalar or a two-element
vector with values between 0 and 1, with 1 correspondingto
thenormalized Nyquist frequency.
Rp Passband ripple, in decibels. This valueis themaximum
permissiblepassband loss in decibels.
Rs Stopband attenuation, in decibels. This valueis thenumber of
decibels thestopband is down fromthepassband.
cheb2ord
7-69
Usethefollowingguidetospecify filters of different types.
I f your filter specifications call for a bandpass or bandstop filter with unequal
ripplein each of thepassbands or stopbands, design separatelowpass and
highpass filters accordingtothespecifications in this table, and cascadethe
twofilters together.
Analog Domain
[ n, Wn] =cheb2or d( Wp, Ws, Rp, Rs, ' s' ) finds theminimumorder n and cutoff
frequencies Wn for an analogChebyshev typeI I filter. You specify the
frequencies Wp and Ws similar toTable7-5, Description of Stopband and
Passband Filter Parameters, only in this caseyou specify thefrequency in
radians per second, and thepassband or thestopband can beinfinite.
Usecheb2or d for lowpass, highpass, bandpass, and bandstop filters as
described in Table7-6, Filter TypeStopband and Passband Specifications.
Table 7-6: Filter Type Stopband and Passband Specifications
Filter Type Stopband and Passband Conditions Stopband Passband
Lowpass Wp <Ws, both scalars ( Ws, 1) ( 0, Wp)
Highpass Wp >Ws, both scalars ( 0, Ws) ( Wp, 1)
Bandpass Theinterval specified by Ws contains
theonespecified by Wp
(Ws( 1) < Wp( 1) < Wp( 2) < Ws( 2) ).
( 0, Ws( 1) )
and
( Ws( 2) , 1)
( Wp( 1) , Wp( 2) )
Bandstop Theinterval specified by Wp contains
theonespecified by Ws
(Wp( 1) < Ws( 1) < Ws( 2) < Wp( 2) ).
( 0, Wp( 1) )
and
( Wp( 2) , 1)
( Ws( 1) , Ws( 2) )
cheb2ord
7-70
Examples Example 1
For data sampled at 1000 Hz, design a lowpass filter with less than 3 dB of
ripplein thepassband defined from0 to40 Hz, and at least 60 dB of
attenuation in thestopband defined from150 Hz totheNyquist frequency
(500 Hz).
Wp = 40/ 500; Ws = 150/ 500;
Rp = 3; Rs = 60;
[ n, Wn] = cheb2or d( Wp, Ws, Rp, Rs)
n =
4
Wn =
0. 2597
[ b, a] = cheby2( n, Rs, Wn) ;
f r eqz( b, a, 512, 1000) ;
t i t l e( ' n=4 Chebyshev Type I I Lowpass Fi l t er ' )
0 50 100 150 200 250 300 350 400 450 500
400
300
200
100
0
100
Frequency (Hz)
P
h
a
s
e

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

(
d
B
)
n=4 Chebyshev Type II Lowpass Filter
cheb2ord
7-71
Example 2
Next design a bandpass filter with a passband of 60 Hz to200 Hz, with less
than 3 dB of ripplein thepassband, and 40 dB attenuation in thestopbands
that are50 Hz wideon both sides of thepassband.
Wp = [ 60 200] / 500; Ws = [ 50 250] / 500;
Rp = 3; Rs = 40;
[ n, Wn] = cheb2or d( Wp, Ws, Rp, Rs)
n =
7
Wn =
0. 1019 0. 4516
[ b, a] = cheby2( n, Rs, Wn) ;
f r eqz( b, a, 512, 1000)
t i t l e( ' n=7 Chebyshev Type I I Bandpass Fi l t er ' )
0 50 100 150 200 250 300 350 400 450 500
400
200
0
200
400
Frequency (Hz)
P
h
a
s
e

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

(
d
B
)
n=7 Chebyshev Type II Bandpass Filter
cheb2ord
7-72
Algorithm cheb2or d usestheChebyshevlowpassfilter order predictionformuladescribed
in [1]. Thefunction performs its calculations in theanalogdomain for both
analogand digital cases. For thedigital case, it converts thefrequency
parameters tothes-domain beforetheorder andnatural frequency estimation
process, and then converts themback tothez-domain.
cheb2or d initially develops a lowpass filter prototypeby transformingthe
stopband frequencies of thedesired filter to1 rad/s (for low- and highpass
filters) and to-1 and 1 rad/s (for bandpass and bandstop filters). I t then
computes theminimumorder required for a lowpass filter tomeet the
passband specification.
See Also
References [1] Rabiner, L.R., and B. Gold. Theory and Application of Digital Signal
Processing. Englewood Cliffs, NJ : Prentice-Hall, 1975. Pg. 241.
but t or d Calculatetheorder for a Butterworth filter.
cheb1or d Calculatetheorder for a Chebyshev typeI filter.
cheby2 Design a Chebyshev typeI I filter (stopband ripple).
el l i por d Calculatetheorder for an ellipticfilter.
kai ser or d EstimateKaiser windowFI R filter parameters.
chebwin
7-73
7chebwin
Purpose Computea Chebyshev window.
Syntax w = chebwi n( n, r )
Description w=chebwi n( n, r ) returns thecolumn vector wcontainingthelength n
ChebyshevwindowwhoseFourier transformsidelobemagnitudeis r dB below
themainlobemagnitude.
Note I f you specify a one-point window(set n=1), thevalue1 is returned.
Examples w = chebwi n( 64, 100) ;
pl ot ( w)
t i t l e( ' Chebyshev Wi ndow' )
0 10 20 30 40 50 60 70
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
Chebyshev Window
chebwin
7-74
See Also
References [1] I EEE. Programsfor Digital Signal Processing. I EEE Press. NewYork: J ohn
Wiley & Sons, 1979. Program5.2.
bar t l et t Computea Bartlett window.
bl ackman Computea Blackman window.
boxcar Computea rectangular window.
hammi ng Computea Hammingwindow.
hann Computea Hann window.
kai ser Computea Kaiser window.
t r i ang Computea triangular window.
cheby1
7-75
7cheby1
Purpose Chebyshev typeI filter design (passband ripple).
Syntax [ b, a] = cheby1( n, Rp, Wn)
[ b, a] = cheby1( n, Rp, Wn, ' f t ype' )
[ b, a] = cheby1( n, Rp, Wn, ' s' )
[ b, a] = cheby1( n, Rp, Wn, ' f t ype' , ' s' )
[ z, p, k] = cheby1( . . . )
[ A, B, C, D] = cheby1( . . . )
Description cheby1 designs lowpass, bandpass, highpass, and bandstop digital and analog
Chebyshev typeI filters. Chebyshev typeI filters areequiripplein the
passband and monotonic in thestopband. TypeI filters roll off faster than
typeI I filters, but at theexpenseof greater deviation fromunity in the
passband.
Digital Domain
[ b, a] =cheby1( n, Rp, Wn) designs an order n lowpass digital Chebyshev filter
with cutoff frequency Wn and Rp dB of ripplein thepassband. I t returns the
filter coefficients in thelength n+1 rowvectors b and a, with coefficients in
descendingpowers of z.
Cutoff frequencyis thefrequency at which themagnituderesponseof thefilter
is equal to- Rp dB. For cheby1, thecutoff frequency Wn is a number between 0
and 1, where1 corresponds totheNyquist frequency, radians per sample.
Smaller valuesof passbandrippleRp leadtowider transitionwidths(shallower
rolloff characteristics).
I f Wn is a two-element vector, Wn =[ w1 w2] , cheby1 returns an order 2*n
bandpass filter with passband w1 < <w2.
H z ( )
B z ( )
A z ( )
-----------
b 1 ( ) b 2 ( )z
1
L b n 1 + ( )z
n
+ + +
1 a 2 ( )z
1
L a n 1 + ( )z
n
+ + +
------------------------------------------------------------------------------------ = =

cheby1
7-76
[ b, a] =cheby1( n, Rp, Wn, ' f t ype' ) designs a highpass or bandstop filter,
wherethestring' f t ype' is either:
' hi gh' for a highpass digital filter with cutoff frequency Wn
' st op' for an order 2*n bandstop digital filter if Wn is a two-element vector,
Wn =[ w1 w2]
Thestopband is w1 < <w2.
With different numbers of output arguments, cheby1 directly obtains other
realizations of thefilter. Toobtain zero-pole-gain form, usethreeoutput
arguments as shown below.
[ z, p, k] =cheby1( n, Rp, Wn) or
[ z, p, k] =cheby1( n, Rp, Wn, ' f t ype' ) returns thezeros and poles in length n
column vectors z and p and thegain in thescalar k.
Toobtain state-spaceform, usefour output arguments as shown below.
[ A, B, C, D] =cheby1( n, Rp, Wn) or
[ A, B, C, D] =cheby1( n, Rp, Wn, ' f t ype' ) whereA, B, C, and Dare
and u is theinput, x is thestatevector, and y is theoutput.
Analog Domain
[ b, a] =cheby1( n, Rp, Wn, ' s' ) designs an order n lowpass analogChebyshev
typeI filter with cutoff frequency Wn. I t returns thefilter coefficients in length
n+1 rowvectors b and a, in descendingpowers of s, derived fromthetransfer
function
Cutoff frequencyis thefrequency at which themagnituderesponseof thefilter
is -Rp dB. For cheby1, thecutoff frequency Wn must begreater than 0.
x n 1 + [ ] Ax n [ ] Bu n [ ] + =
y n [ ] Cx n [ ] Du n [ ] + =
H s ( )
B s ( )
A s ( )
---------- -
b 1 ( )s
n
b 2 ( )s
n 1
L b n 1 + ( ) + + +
s
n
a 2 ( )s
n 1
L a n 1 + ( ) + + +
------------------------------------------------------------------------------------- = =
cheby1
7-77
I f Wn is a two-element vector Wn =[ w1 w2] with w1 <w2, then
cheby1( n, Rp, Wn, ' s' ) returns an order 2*n bandpass analogfilter with
passband w1 < <w2.
[ b, a] =cheby1( n, Rp, Wn, ' f t ype' , ' s' ) designs a highpass or bandstop filter.
You can supply different numbers of output arguments for cheby1 todirectly
obtain other realizationsof theanalogfilter. Toobtain zero-pole-gain form, use
threeoutput arguments as shown below.
[ z, p, k] =cheby1( n, Rp, Wn, ' s' ) or
[ z, p, k] = cheby1( n, Rp, Wn, ' f t ype' , ' s' ) returns thezeros and poles in
length n or 2*n column vectors z and p and thegain in thescalar k.
Toobtain state-spaceform, usefour output arguments as shown below.
[ A, B, C, D] =cheby1( n, Rp, Wn, ' s' ) or
[ A, B, C, D] =cheby1( n, Rp, Wn, ' f t ype' , ' s' ) whereA, B, C, and Daredefined
as
and u is theinput, x is thestatevector, and y is theoutput.
Examples For data sampled at 1000 Hz, design a 9th-order lowpass Chebyshev typeI
filter with 0.5 dB of ripplein thepassband and a cutoff frequency of 300 Hz.
[ b, a] = cheby1( 9, 0. 5, 300/ 500) ;
Thefrequency responseof thefilter is
f r eqz( b, a, 512, 1000)
x

Ax Bu + =
y Cx Du + =
cheby1
7-78
Design a 10th-order bandpass Chebyshev typeI filter with a passband from
100 to200 Hz and plot its impulseresponse.
n = 10; Rp = 0. 5;
Wn = [ 100 200] / 500;
[ b, a] = cheby1( n, Rp, Wn) ;
[ y, t ] = i mpz( b, a, 101) ; st em( 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
7-79
Limitations For high order filters, thestate-spaceformis themost numerically accurate,
followed by thezero-pole-gain form. Thetransfer function formis theleast
accurate; numerical problems can arisefor filter orders as lowas 15.
Algorithm cheby1 uses a five-step algorithm:
1 I t finds thelowpass analogprototypepoles, zeros, and gain usingthe
cheb1ap function.
2 I t converts thepoles, zeros, and gain intostate-spaceform.
3 I t transformsthelowpass filter intoabandpass, highpass, or bandstopfilter
with desired cutoff frequencies, usinga state-spacetransformation.
4 For digital filter design, cheby1 uses bi l i near toconvert theanalogfilter
intoa digital filter through a bilinear transformation with frequency
prewarping. Careful frequency adjustment guarantees that theanalog
filters and thedigital filters will havethesamefrequency response
magnitudeat Wn or w1 and w2.
5 I t converts thestate-spacefilter back totransfer function or zero-pole-gain
form, as required.
See Also
bessel f Bessel analogfilter design.
but t er Butterworth analogand digital filter design.
cheb1ap Chebyshev typeI analoglowpass filter prototype.
cheb1or d Calculatetheorder of a Chebyshev typeI filter.
cheby2 Chebyshev typeI I filter design (stopband ripple).
el l i p Elliptic (Cauer) filter design.
cheby2
7-80
7cheby2
Purpose Chebyshev typeI I filter design (stopband ripple).
Syntax [ b, a] = cheby2( n, Rs, Wn)
[ b, a] = cheby2( n, Rs, Wn, ' f t ype' )
[ b, a] = cheby2( n, Rs, Wn, ' s' )
[ b, a] = cheby2( n, Rs, Wn, ' f t ype' , ' s' )
[ z, p, k] = cheby2( . . . )
[ A, B, C, D] = cheby2( . . . )
Description cheby2 designs lowpass, highpass, bandpass, and bandstop digital and analog
Chebyshev typeI I filters. Chebyshev typeI I filters aremonotonic in the
passband and equiripplein thestopband. TypeI I filters donot roll off as fast
as typeI filters, but arefreeof passband ripple.
Digital Domain
[ b, a] =cheby2( n, Rs, Wn) designs an order n lowpass digital Chebyshev type
I I filter withcutoff frequencyWn andstopbandrippleRs dB downfromthepeak
passband value. I t returns thefilter coefficients in thelength n+1 rowvectors
b and a, with coefficients in descendingpowers of z.
Cutoff frequency is thebeginningof thestopband, wherethemagnitude
responseof thefilter is equal to- Rs dB. For cheby2, thenormalized cutoff
frequency Wn is anumber between 0and 1, where1corresponds totheNyquist
frequency. Larger values of stopband attenuation Rs lead towider transition
widths (shallower rolloff characteristics).
I f Wn is a two-element vector, Wn =[ w1 w2] , cheby2 returns an order 2*n
bandpass filter with passband w1 < <w2.
[ b, a] =cheby2( n, Rs, Wn, ' f t ype' ) designs a highpass or bandstop filter,
wherethestring' f t ype' is either:
' hi gh' for a highpass digital filter with cutoff frequency Wn
' st op' for an order 2*n bandstop digital filter if Wn is a two-element vector,
Wn =[ w1 w2] . Thestopband is w1 < <w2.
H z ( )
B z ( )
A z ( )
-----------
b 1 ( ) b 2 ( )z
1
L b n 1 + ( )z
n
+ + +
1 a 2 ( )z
1
L a n 1 + ( )z
n
+ + +
------------------------------------------------------------------------------------ = =
cheby2
7-81
With different numbers of output arguments, cheby2 directly obtains other
realizations of thefilter. Toobtain zero-pole-gain form, usethreeoutput
arguments as shown below.
[ z, p, k] =cheby2( n, Rs, Wn) or
[ z, p, k] =cheby2( n, Rs, Wn, ' f t ype' ) returns thezeros and poles in length n
column vectors z and p and thegain in thescalar k.
Toobtain state-spaceform, usefour output arguments as shown below.
[ A, B, C, D] =cheby2( n, Rs, Wn) or
[ A, B, C, D] =cheby2( n, Rs, Wn, ' f t ype' ) whereA, B, C, and Dare
and u is theinput, x is thestatevector, and y is theoutput.
Analog Domain
[ b, a] =cheby2( n, Rs, Wn, ' s' ) designs an order n lowpass analogChebyshev
typeI I filter with cutoff frequency Wn. I t returns thefilter coefficients in the
length n+1 rowvectors b and a, with coefficients in descendingpowers of s,
derived fromthetransfer function.
Cutoff frequencyis thefrequency at which themagnituderesponseof thefilter
is equal to- Rs dB. For cheby2, thecutoff frequency Wn must begreater than 0.
I f Wn is a two-element vector Wn =[ w1 w2] with w1 <w2, then
cheby2( n, Rs, Wn, ' s' ) returns an order 2*n bandpass analogfilter with
passband w1 < <w2.
[ b, a] =cheby2( n, Rs, Wn, ' f t ype' , ' s' ) designs a highpass or bandstop filter.
With different numbers of output arguments, cheby2 directly obtains other
realizationsof theanalogfilter. Toobtainzero-pole-gainform, usethreeoutput
arguments as shown below.
x n 1 + [ ] Ax n [ ] Bu n [ ] + =
y n [ ] Cx n [ ] Du n [ ] + =
H s ( )
B s ( )
A s ( )
---------- -
b 1 ( )s
n
b 2 ( )s
n 1
L b n 1 + ( ) + + +
s
n
a 2 ( )s
n 1
L a n 1 + ( ) + + +
------------------------------------------------------------------------------------- = =
cheby2
7-82
[ z, p, k] =cheby2( n, Rs, Wn, ' s' ) or
[ z, p, k] =cheby2( n, Rs, Wn, ' f t ype' , ' s' ) returns thezeros and poles in
length n or 2*n column vectors z and p and thegain in thescalar k.
Toobtain state-spaceform, usefour output arguments as shown below.
[ A, B, C, D] =cheby2( n, Rs, Wn, ' s' ) or
[ A, B, C, D] =cheby2( n, Rs, Wn, ' f t ype' , ' s' ) whereA, B, C, and Dare
and u is theinput, x is thestatevector, and y is theoutput.
Examples For data sampled at 1000 Hz, design a ninth-order lowpass Chebyshev typeI I
filter with stopband attenuation 20 dB down fromthepassband and a cutoff
frequency of 300 Hz.
[ b, a] = cheby2( 9, 20, 300/ 500) ;
Thefrequency responseof thefilter is
f r eqz( b, a, 512, 1000)
x

Ax Bu + =
y Cx Du + =
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
cheby2
7-83
Design afifth-order bandpass ChebyshevtypeI I filter with passbandfrom100
to200 Hz and plot theimpulseresponseof thefilter.
n = 5; r = 20;
Wn = [ 100 200] / 500;
[ b, a] = cheby2( n, r , Wn) ;
[ y, t ] = i mpz( b, a, 101) ; st em( t , y)
Limitations For high order filters, thestate-spaceformis themost numerically accurate,
followed by thezero-pole-gain form. Thetransfer function coefficient formis
theleast accurate; numerical problems can arisefor filter orders as lowas 15.
Algorithm cheby2 uses a five-step algorithm:
1 I t finds thelowpass analogprototypepoles, zeros, and gain usingthe
cheb2ap function.
2 I t converts poles, zeros, and gain intostate-spaceform.
3 I t transformsthelowpass filter intoabandpass, highpass, or bandstopfilter
with desired cutoff frequencies, usinga state-spacetransformation.
4 For digital filter design, cheby2 uses bi l i near toconvert theanalogfilter
intoa digital filter through a bilinear transformation with frequency
prewarping. Careful frequency adjustment guarantees that theanalog
0 10 20 30 40 50 60 70 80 90 100
-0.2
-0.15
-0.1
-0.05
0
0.05
0.1
0.15
0.2
Impulse Response of n = 5 Chebyshev Type II Filter
cheby2
7-84
filters and thedigital filters will havethesamefrequency response
magnitudeat Wn or w1 and w2.
5 I t converts thestate-spacefilter back totransfer function or zero-pole-gain
form, as required.
See Also
bessel f Bessel analogfilter design.
but t er Butterworth analogand digital filter design.
cheb2ap Chebyshev typeI I analoglowpass filter prototype.
cheb2or d Calculatetheorder of a Chebyshev typeI I filter.
cheby1 Chebyshev typeI filter design (passband ripple).
el l i p Elliptic (Cauer) filter design.
chirp
7-85
7chirp
Purpose Generatea swept-frequency cosine.
Syntax y = chi r p( t , f 0, t 1, f 1)
y = chi r p( t , f 0, t 1, f 1, ' met hod' )
y = chi r p( t , f 0, t 1, f 1, ' met hod' , phi )
Description y =chi r p( t , f 0, t 1, f 1) generates samples of a linear swept-frequency cosine
signal at thetimeinstances defined in array t , wheref 0 is theinstantaneous
frequency at time0, and f 1 is theinstantaneous frequency at timet 1. f 0 and
f 1 areboth in hertz. I f unspecified, f 0 is 0, t 1 is 1, and f 1 is 100.
y =chi r p( t , f 0, t 1, f 1, ' met hod' ) specifiesalternativesweepmethodoptions,
wheremet hod can be:
l i near , which specifies an instantaneous frequency sweep f
i
(t) given by
where
ensures that thedesired frequency breakpoint f
1
at timet
1
is maintained.
quadr at i c, which specifies an instantaneous frequency sweep f
i
(t) given by
where
l ogar i t hmi c specifies an instantaneous frequency sweep f
i
(t) given by
where
For a log-sweep, f 1 must begreater than f 0.
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
7-86
y =chi r p( t , f 0, t 1, f 1, ' met hod' , phi ) allows an initial phasephi tobe
specified in degrees. I f unspecified, phi is 0. Default values aresubstituted for
empty or omitted trailinginput arguments.
Examples Example 1
Computethespectrogramof a chirp with linear instantaneous frequency
deviation.
t = 0: 0. 001: 2; %2 secs @1kHz sampl e r at e
y = chi r p( t , 0, 1, 150) ; %St ar t @DC, cr oss 150Hz at t =1 sec
specgr am( y, 256, 1e3, 256, 250) %Di spl ay t he spect r ogr am
Example 2
Computethespectrogramof a chirp with quadratic instantaneous frequency
deviation.
t = - 2: 0. 001: 2; %2 secs @1kHz sampl e r at e
y = chi r p( t , 100, 1, 200, ' quadr at i c' ) ; %St ar t @100Hz, cr oss 200Hz
%at t =1 sec
specgr am( y, 128, 1e3, 128, 120) %Di spl ay t he spect r ogr am
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
7-87
See Also
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
cos Computethecosineof vector/matrix elements (see
theMATLAB documentation).
di r i c ComputetheDirichlet or periodic sinc function.
gauspul s Generatea Gaussian-modulated sinusoidal pulse.
pul st r an Generatea pulsetrain.
r ect pul s Generatea sampled aperiodic rectangle.
sawt oot h Generatea sawtooth or trianglewave.
si n Computethesineof vector/matrix elements (seethe
MATLAB documentation).
si nc Computethesinc function.
squar e Generatea squarewave.
t r i pul s Generatea sampled aperiodic triangle.
cohere
7-88
7cohere
Purpose Estimatemagnitudesquared coherencefunction between twosignals.
Syntax Cxy = coher e( x, y)
Cxy = coher e( x, y, nf f t )
[ Cxy, f ] = coher e( x, y, nf f t , f s)
Cxy = coher e( x, y, nf f t , f s, wi ndow)
Cxy = coher e( x, y, nf f t , f s, wi ndow, numover l ap)
Cxy = coher e( x, y, . . . , ' df l ag' )
coher e( x, y)
Description Cxy =coher e( x, y) finds themagnitudesquared coherencebetween length n
signal vectors x and y. Thecoherenceis a function of thepower spectra of x
and y and thecross spectrumof x and y.
x and y must bethesamelength.
nf f t specifies theFFT length that coher e uses. This valuedetermines the
frequenciesat whichthecoherenceisestimated. f s isascalar that specifiesthe
samplingfrequency. wi ndowspecifies a windowingfunction and thenumber of
samples coher e uses in its sectioningof thex and y vectors. numover l ap is the
number of samples by which thewindowsections overlapfor both x and y. Any
arguments that you omit fromtheend of theparameter list usethedefault
values shown below.
Cxy =coher e( x, y) uses thefollowingdefault values:
nf f t = mi n( 256, l engt h( x) )
f s = 2
wi ndow is a periodic Hann windowof length nf f t .
numover l ap = 0
I f x is real, coher e estimates thecoherencefunction at positivefrequencies
only; in this case, theoutput Cxy is a column vector of length nf f t / 2 +1 for
nf f t even and( nf f t +1) / 2 for n odd. I f x or y iscomplex, coher e estimatesthe
coherencefunction at both positiveand negativefrequencies, and Cxy has
length nf f t .
C
xy
f ( )
P
xy
f ( )
2
P
xx
f ( )P
yy
f ( )
------------------------------- =
cohere
7-89
Cxy = coher e( x, y, nf f t ) uses theFFT length nf f t in estimatingthepower
spectrumfor x. Specify nf f t as a power of 2 for fastest execution.
Cxy = coher e( x, y, nf f t , f s) returns a vector f of frequencies at which the
function evaluates thecoherence. f s is thesamplingfrequency. f is thesame
sizeasCxy, sopl ot ( f , Cxy) plotsthecoherencefunctionversusproperlyscaled
frequency. f s has noeffect on theoutput Cxy; it is a frequency scaling
multiplier.
coher e( x, y, nf f t , f s, wi ndow) specifies awindowingfunction andthenumber
of samples per section of thevectors x and y. I f you supply a scalar for wi ndow,
coher e uses a Hann windowof that length. Thelength of thewindowmust be
less than or equal tonf f t ; coher e zeropads thesections if thewindowlength
exceeds nf f t .
coher e( x, y, nf f t , f s, wi ndow, numover l ap) overlaps thesections of x by
numover l ap samples.
You can usetheempty matrix [ ] tospecify thedefault valuefor any input
argument except x or y. For example,
coher e( x, y, [ ] , [ ] , kai ser ( 128, 5) ) ;
uses 256 as thevaluefor nf f t and 2 as thevaluefor f s.
coher e( x, y, . . . , ' df l ag' ) specifies a detrend option, where' df l ag' is:
' l i near ' , toremovethebest straight-linefit fromtheprewindowedsections
of x and y
' mean' , toremovethemean fromtheprewindowed sections of x and y
' none' , for nodetrending(default)
The' df l ag' parameter must appear last inthelist of input arguments. coher e
recognizes a ' df l ag' stringnomatter howmany intermediatearguments are
omitted.
coher e with nooutput arguments plots thecoherenceestimateversus
frequency in thecurrent figurewindow.
cohere
7-90
Example Computeandplot thecoherenceestimatebetween twocolorednoisesequences
x and y.
r andn( ' st at e' , 0) ;
h = f i r 1( 30, 0. 2, boxcar ( 31) ) ;
h1 = ones( 1, 10) / sqr t ( 10) ;
r = r andn( 16384, 1) ;
x = f i l t er ( h1, 1, r ) ;
y = f i l t er ( h, 1, x) ;
coher e( x, y, 1024, [ ] , [ ] , 512)
Diagnostics An appropriatediagnosticmessageis displayedwhen incorrect arguments are
used.
Requi r es wi ndow' s l engt h t o be no gr eat er t han t he FFT l engt h.
Requi r es NOVERLAP t o be st r i ct l y l ess t han t he wi ndow l engt h.
Requi r es posi t i ve i nt eger val ues f or NFFT and NOVERLAP.
Requi r es vect or ( ei t her r ow or col umn) i nput .
Requi r es i nput s X and Y t o have t he same l engt h.
0 0.2 0.4 0.6 0.8 1
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
Frequency
C
o
h
e
r
e
n
c
e

F
u
n
c
t
i
o
n

E
s
t
i
m
a
t
e
cohere
7-91
Algorithm coher e estimates themagnitudesquaredcoherencefunction [1] usingWelchs
method of power spectrumestimation (seereferences [2] and [3]), as follows:
1 I t divides thesignals x and y intoseparateoverlappingsections, detrends
each section, and multiplies each section by wi ndow.
2 I t calculates thelength nf f t fast Fourier transformof each section.
3 I t averages thesquares of thespectraof thex sections toformPxx, averages
thesquares of thespectra of they sections toformPyy, and averages the
products of thespectra of thex and y sections toformPxy. I t calculates Cxy
by thefollowingformula.
Cxy = abs( Pxy) . ^2/ ( Pxx. *Pyy)
See Also
References [1] Kay, S.M. Modern Spectral Estimation. Englewood Cliffs, NJ :
Prentice-Hall, 1988. Pg. 454.
[2] Rabiner, L.R., and B. Gold. Theory and Application of Digital Signal
Processing. Englewood Cliffs, NJ : Prentice-Hall, 1975.
[3] Welch, P.D. TheUseof Fast Fourier Transformfor theEstimationof Power
Spectra: A Method Based on TimeAveragingOver Short, Modified
Periodograms. I EEE Trans. AudioElectroacoust. Vol. AU-15 (J une1967).
Pgs. 70-73.
csd Estimatethecross spectral density (CSD) of two
signals.
pwel ch Power spectral density estimateusingWelchs
method.
t f e Transfer function estimatefrominput and output.
conv
7-92
7conv
Purpose Convolution and polynomial multiplication.
Syntax c = conv( a, b)
Description c = conv( a, b) convolves vectors a and b. Theconvolution sumis
whereN isthemaximumsequencelength. Theseriesisindexedfromn +1and
k +1 instead of theusual n and k becauseMATLAB vectors run from1 ton
instead of from0 ton-1.
Theconv function is part of thestandard MATLAB language.
Example Theconvolution of a = [ 1 2 3] and b = [ 4 5 6] is
c = conv( a, b)
c =
4 13 28 27 18
Algorithm Theconv function is an M-filethat uses thef i l t er primitive. conv computes
theconvolution operation as FI R filteringwith an appropriatenumber of zeros
appended totheinput.
See Also
c n 1 + ( ) a k 1 + ( )b n k ( )
k 0 =
N 1

=
conv2 Two-dimensional convolution.
convmt x Convolution matrix.
convn N-dimensional convolution (seetheMATLAB
documentation).
deconv Deconvolution and polynomial division.
f i l t er Apply a filter todata.
r esi duez z-transformpartial fraction expansion.
xcor r Cross-correlation function estimate.
conv2
7-93
7conv2
Purpose Two-dimensional convolution.
Syntax C = conv2( A, B)
C = conv2( A, B, ' shape' )
Description C = conv2( A, B) computes thetwo-dimensional convolution of matrices A
and B. I f oneof thesematricesdescribesatwo-dimensional FI R filter, theother
matrix is filtered in twodimensions.
Each dimension of theoutput matrix Cis equal in sizetooneless than thesum
of thecorrespondingdimensions of theinput matrices. When
[ ma, na] =si ze( A) and [ mb, nb] =si ze( B) ,
si ze( C) = [ ma+mb- 1, na+nb- 1]
C = conv2( A, B, ' shape' ) returns a subsection of thetwo-dimensional
convolution with sizespecified by ' shape' , where:
' f ul l ' returns thefull two-dimensional convolution (default)
' same' returns thecentral part of theconvolution that is thesamesizeas A
' val i d' returns only thoseparts of theconvolution that arecomputed
without thezero-padded edges. Usingthis option,
si ze( C) = [ ma- mb+1, na- nb+1] when si ze( A) >si ze( B)
conv2 executes most quickly when si ze( A) >si ze( B) .
Theconv2 function is part of thestandard MATLAB language.
Examples I n imageprocessing, theSobel edge-findingoperation is a two-dimensional
convolution of an input array with thespecial matrix
s = [ 1 2 1; 0 0 0; - 1 - 2 - 1] ;
Given any image, thefollowingcodeextracts thehorizontal edges.
h = conv2( I , s) ;
Thefollowingcodeextracts thevertical edges first, and then extracts both
horizontal and vertical edges combined.
v = conv2( I , s' ) ;
v2 = ( sqr t ( h. ^2 + v. ^2) )
conv2
7-94
See Also
conv Convolution and polynomial multiplication.
convn N-dimensional convolution (seetheMATLAB
documentation).
deconv Deconvolution and polynomial division.
f i l t er 2 Apply a two-dimensional filter todata.
xcor r Cross-correlation function estimate.
xcor r 2 Two-dimensional cross-correlation.
convmtx
7-95
7convmtx
Purpose Convolution matrix.
Syntax A = convmt x( c, n)
A = convmt x( r , n)
Description A convolution matrix is a matrix, formed froma vector, whoseinner product
with another vector is theconvolution of thetwovectors.
A = convmt x( c, n) wherec is a length mcolumn vector returns a matrix A of
size( m+n- 1) -by-n. Theproduct of A and another column vector x of length n is
theconvolution of c with x.
A = convmt x( r , n) wherer is a length mrowvector returns a matrix A of size
n-by-( m+n- 1) . Theproduct of A and another rowvector x of length n is the
convolution of r with x.
Example Generatea simpleconvolution matrix.
h = [ 1 2 3 2 1] ;
convmt x( 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
Notethat convmt x handles edgeconditions by zeropadding.
I n practice, it is moreefficient tocomputeconvolution using
y = conv( c, x)
than by usinga convolution matrix.
n = l engt h( x) ;
y = convmt x( c, n) *x
Algorithm convmt x uses thefunction t oepl i t z togeneratetheconvolution matrix.
convmtx
7-96
See Also
conv Convolution and polynomial multiplication.
convn N-dimensional convolution (seetheMATLAB
documentation).
conv2 Two-dimensional convolution.
df t mt x DiscreteFourier transformmatrix.
corrcoef
7-97
7corrcoef
Purpose Computethecorrelation coefficient matrix.
Syntax C = cor r coef ( X)
C = cor r coef ( X, Y)
Description cor r coef returns a matrix of correlation coefficients calculated froman input
matrix whoserows areobservations and whosecolumns arevariables. I f
C = cov( X) , then cor r coef ( X) is thematrix whoseelement (i, j) is
C = cor r coef ( X) is thezeroth lagof thecovariancefunction, that is, the
zeroth lagof xcov( x, ' coef f ' ) packed intoa squarearray.
C = cor r coef ( X, Y) is thesameascor r coef ( [ X Y] ) ; that is, it concatenates X
and Y in therowdirection beforeits computation.
cor r coef removes themean fromeach column beforecalculatingtheresults.
Seethexcor r function for cross-correlation options.
Thecor r coef function is part of thestandard MATLAB language.
See Also
corrcoef i j , ( )
C i j , ( )
C i i , ( )C j j , ( )
----------------------------------- =
cov Covariancematrix.
mean Averagevalue(seetheMATLAB documentation).
medi an Median value(seetheMATLAB documentation).
st d Standard deviation (seetheMATLAB
documentation).
xcor r Cross-correlation function estimate.
xcov Cross-covariancefunction estimate(equal to
mean-removed cross-correlation).
corrmtx
7-98
7corrmtx
Purpose Computea data matrix for autocorrelation matrix estimation.
Syntax X = cor r mt x( x, m)
X = cor r mt x( x, m, ' met hod' )
[ X, R] = cor r mt x( . . . )
Description X = cor r mt x( x, m) returns an (n+m)-by-(m+1) rectangular Toeplitz matrix X,
such that X' X is a (biased) estimateof theautocorrelation matrix for the
length n data vector x.
X = cor r mt x( x, m, ' met hod' ) computes thematrix X accordingtothemethod
specified by thestring' met hod' :
' aut ocor r el at i on' : (default) X is the(n+m)-by-(m+1) rectangular Toeplitz
matrix that generates an autocorrelation estimatefor thelength n data
vector x, derived usingprewindowed and postwindowed data, based on an
mth order prediction error model.
' pr ewi ndowed' : X is then-by-(m+1) rectangular Toeplitz matrix that
generates an autocorrelation estimatefor thelength n datavector x, derived
usingprewindowed data, based on an mth order prediction error model.
' post wi ndowed' : X is then-by-(m+1) rectangular Toeplitz matrix that
generates an autocorrelation estimatefor thelength n datavector x, derived
usingpostwindowed data, based on an mth order prediction error model.
' covar i ance' : X is the(n-m)-by-(m+1) rectangular Toeplitz matrix that
generates an autocorrelation estimatefor thelength n datavector x, derived
usingnonwindowed data, based on an mth order prediction error model.
' modi f i ed' : X is the2(n-m)-by-(m+1) modified rectangular Toeplitz matrix
that generates an autocorrelation estimatefor thelength n data vector x,
derivedusingforwardandbackwardprediction error estimates, basedon an
mth order prediction error model.
[ X, R] = cor r mt x( . . . ) alsoreturns the(m+1)-by-(m+1) autocorrelation matrix
estimateR, calculated as X' *X.
Examples r andn( ' st at e' , 1) ; n=0: 99;
s=exp( i *pi / 2*n) +2*exp( i *pi / 4*n) +exp( i *pi / 3*n) +r andn( 1, 100) ;
X=cor r mt x( s, 12, ' mod' ) ;
corrmtx
7-99
Algorithm TheToeplitz data matrix computed by cor r mt x depends on themethod you
select. Thematrix determinedby theautocorrelation (default) methodis given
by thefollowingmatrix.
I n this matrix, mis thesameas theinput argument mtocor r mt x, and n is
l engt h( x) . Variationsof thismatrixareusedtoreturntheoutput Xof cor r mt x
for each method:
' aut ocor r el at i on' : (default) X =X, above.
' pr ewi ndowed' : X is then-by-(m+1) submatrix of X that is given by the
portion of X abovethelower gray line.
' post wi ndowed' : X is then-by-(m+1) submatrix of X that is given by the
portion of X belowtheupper gray line.
' covar i ance' : X is the(n-m)-by-(m+1) submatrix of X that is given by the
portion of X between thetwogray lines.
' modi f i ed' : X is the2(n-m)-by-(m+1) matrix X
mod
shown below.
X
x 1 ( ) L 0

x m 1 + ( ) L x1)

x n m ( ) L x m 1 + ( )

x n ( ) L x n m ( )

0 L x n ( )
=
corrmtx
7-100
See Also
References [1] Marple, S.L. Digital Spectral Analysis, EnglewoodCliffs, NJ , Prentice-Hall,
1987, pp. 216-223.
X
mod
x m 1 + ( ) L x1)

x n m ( ) L x m 1 + ( )

x n ( ) L x n m ( )
x

1 ( ) L x

m 1 + ( )

x

m 1 + ( ) L x

n m ( )

x

n m ( ) L x

n ( )
=
pei g Estimatethepseudospectrumusingtheeigenvector
method.
pmusi c EstimatethepseudospectrumusingtheMUSI C
algorithm.
r oot ei g Estimatefrequency content and signal power using
theroot eigenvector method.
r oot musi c Estimatefrequency content and signal power using
theroot MUSI C algorithm.
xcor r Computethecross-correlation.
cov
7-101
7cov
Purpose Computethecovariancematrix.
Syntax c = cov( x)
c = cov( x, y)
Description cov computesthecovariancematrix. I f x is avector, c isascalar containingthe
variance. For an array whereeach rowis an observation and each column a
variable, cov( X) is thecovariancematrix. di ag( cov( X) ) is a vector of
variances for each column, and sqr t ( di ag( cov( X) ) ) is a vector of standard
deviations.
cov( x) is thezeroth lagof thecovariancefunction, that is, thezeroth lagof
xcov( x) / ( n- 1) packed intoa squarearray.
cov( x, y) wherex and y arecolumn vectors of equal length is equivalent to
cov( [ x y] ) ) , that is, it concatenates x and y in therowdirection beforeits
computation.
cov removes themean fromeach column beforecalculatingtheresults.
Thecov function is part of thestandard MATLAB language.
Algorithm [ n, p] = si ze( x) ;
x = x- ones( n, 1) *( sum( x) / n) ;
y = x' *x/ ( n- 1) ;
See Also
cor r coef Correlation coefficient matrix.
mean Averagevalue(seetheMATLAB documentation).
medi an Median value(seetheMATLAB documentation).
st d Standard deviation (seetheMATLAB
documentation).
xcor r Cross-correlation function estimate.
xcov Cross-covariancefunction estimate(equal to
mean-removed cross-correlation).
cplxpair
7-102
7cplxpair
Purpose Group complex numbers intocomplex conjugatepairs.
Syntax y = cpl xpai r ( x)
y = cpl xpai r ( x, t ol )
Description y = cpl xpai r ( x) returns x with complex conjugatepairs grouped together.
cpl xpai r orders theconjugatepairs by increasingreal part. Within a pair, the
element with negativeimaginary part comes first. Thefunction returns all
purely real values followingall thecomplex pairs.
y = cpl xpai r ( x, t ol ) includes a tolerance, t ol , for determiningwhich
numbers arereal and which arepaired complex conjugates. By default,
cpl xpai r uses a toleranceof 100*eps relativetoabs( x( i ) ) . cpl xpai r forces
thecomplex conjugatepairs tobeexact complex conjugates.
Thecpl xpai r function is part of thestandard MATLAB language.
Example Order fivepoles evenly spaced around theunit circleintocomplex pairs.
cpl xpai r ( exp( 2*pi *sqr t ( - 1) *( 0: 4) / 5) ' )
ans =
- 0. 8090 - 0. 5878i
- 0. 8090 + 0. 5878i
0. 3090 - 0. 9511i
0. 3090 + 0. 9511i
1. 0000
Diagnostics I f thereis an odd number of complex numbers, or if thecomplex numbers
cannot begroupedintocomplexconjugatepairswithinthetolerance, cpl xpai r
generates theerror message.
Compl ex number s can' t be pai r ed.
cremez
7-103
7cremez
Purpose Complex and nonlinear-phaseequirippleFI R filter design.
Syntax b = cr emez( n, f , ' f r esp' )
b = cr emez( n, f , ' f r esp' , w)
b = cr emez( n, f , {' f r esp' , p1, p2, . . . }, w)
b = cr emez( n, f , a, w)
b = cr emez( . . . , ' sym' )
b = cr emez( . . . , ' ski p_stage2' )
b = cr emez( . . . , ' debug' )
b = cr emez( . . . , {l gr i d})
[ b, del t a, opt ] = cr emez( . . . )
Description cr emez allows arbitrary frequency-domain constraints tobespecified for the
designof apossiblycomplexFI R filter. TheChebyshev(or minimax) filter error
is optimized, producingequirippleFI R filter designs.
b = cr emez( n, f , ' f r esp' ) returns a length n+1 FI R filter with thebest
approximation tothedesired frequency responseas returned by function
f r esp. f is a vector of frequency band edgepairs, specified in therange-1
and 1, where1 corresponds tothenormalized Nyquist frequency. The
frequencies must bein increasingorder, and f must haveeven length. The
frequency bands span f ( k) tof ( k+1) for k odd; theintervals f ( k+1) tof ( k+2)
for k odd aretransition bands or dont careregions duringoptimization.
b = cr emez( n, f , ' f r esp' , w) usesthereal, non-negativeweightsinvector wto
weight thefit in each frequency band. Thelength of wis half thelength of f , so
thereis exactly oneweight per band.
b = cr emez( n, f , {' f r esp' , p1, p2, . . . }, . . . ) supplies optional parameters
p1, p2, . . . , tothefrequency responsefunction f r esp. Predefined ' f r esp'
frequency responsefunctions areincluded for a number of common filter
designs, as described below. For all of thepredefined frequency response
functions, thesymmetry option ' sym' defaults to' even' if nonegative
frequencies arecontained in f and d =0; otherwise' sym' defaults to' none' .
(Seethe' sym' option belowfor details.) For all of thepredefined frequency
responsefunctions, d specifiesagroup-delayoffset suchthat thefilter response
cremez
7-104
has a group delay of n/ 2+d in units of thesampleinterval. Negativevalues
createless delay; positivevalues createmoredelay. By default d =0:
l owpass, hi ghpass, bandpass, bandst op
Thesefunctions sharea common syntax, exemplified belowby thestring
' l owpass' .
b = cr emez( n, f , ' l owpass' , . . . ) and
b = cr emez( n, f , {' l owpass' , d}, . . . ) design a linear-phase
(n/ 2+d delay) filter.
mul t i band designs a linear-phasefrequency responsefilter with arbitrary
band amplitudes.
b = cr emez( n, f , {' mul t i band' , a}, . . . ) and
b = cr emez( n, f , {' mul t i band' , a, d}, . . . ) specify vector a containing
thedesired amplitudes at theband edges in f . Thedesired amplitudeat
frequencies between pairs of points f ( k) and f ( k+1) for k odd is theline
segment connectingthepoints ( f ( k) , a( k) ) and ( f ( k+1) , a( k+1) ) .
di f f er ent i at or designs a linear-phasedifferentiator. For thesedesigns,
zero-frequency must bein a transition band, andbandweightingis set tobe
inversely proportional tofrequency.
b = cr emez( n, f , {' di f f er ent i at or ' , f s}, . . . ) and
b = cr emez( n, f , {' di f f er ent i at or ' , f s, d}, . . . ) specifythesamplerate
f s usedtodeterminetheslopeof thedifferentiator response. I f omitted, f s
defaults to1.
hi l bf i l t designs a linear-phaseHilbert transformfilter response. For
Hilbert designs, zero-frequency must bein a transition band.
b = cr emez( n, f , ' hi l bf i l t ' , . . . ) and
b = cr emez( N, F, {' hi l bf i l t ' , d}, . . . ) design a linear-phase
(n/ 2+d delay) Hilbert transformfilter.
b = cr emez( n, f , a, w) is a synonymfor
b = cr emez( n, f , {' mul t i band' , a}, w) .
cremez
7-105
b = cr emez( . . . , ' sym' ) imposes a symmetry constraint on theimpulse
responseof thedesign, where' sym' may beoneof thefollowing:
' none' indicates nosymmetry constraint. This is thedefault if any negative
band edgefrequencies arepassed, or if f r esp does not supply a default.
' even' indicates a real and even impulseresponse. This is thedefault for
highpass, lowpass, bandpass, bandstop, and multiband designs.
' odd' indicates a real and odd impulseresponse. This is thedefault for
Hilbert and differentiator designs.
' r eal ' indicates conjugatesymmetry for thefrequency response
I f any ' sym' option other than ' none' is specified, theband edges should only
bespecifiedover positivefrequencies; thenegativefrequency region is filledin
fromsymmetry. I f a' sym' option is not specified, thef r esp function is queried
for a default setting.
b = cr emez( . . . , ' ski p_stage2' ) disables thesecond-stageoptimization
algorithm, which executes only when cr emez determines that an optimal
solution has not been reached by thestandard Remez error-exchange.
Disablingthisalgorithmmayincreasethespeedof computation, but mayincur
a reduction in accuracy. By default, thesecond-stageoptimization is enabled.
b = cr emez( . . . , ' debug' ) enables thedisplay of intermediateresults during
thefilter design, where' debug' may beoneof ' t r ace' , ' pl ot s' , ' bot h' , or
' of f ' . By default it is set to' of f ' .
b = cr emez( . . . , {l gr i d}) uses theinteger l gr i d tocontrol thedensity of the
frequency grid, which has roughly 2^next pow2( l gr i d*n) frequency points.
Thedefault valuefor l gr i d is 25. Notethat the{l gr i d} argument must bea
1-by-1 cell array.
Any combination of the' sym' , ' ski p_stage2' , ' debug' , and {l gr i d} options
may bespecified.
[ b, del t a] = cr emez( . . . ) returns themaximumrippleheight del t a.
cremez
7-106
[ b, del t a, opt ] = cr emez( . . . ) returns a structureopt of optional results
computed by cr emez and contains thefollowingfields.
User-definablefunctions may beused, instead of thepredefined frequency
responsefunctions for f r esp. Thefunction is called fromwithin cr emez using
thefollowingsyntax
[ dh, dw] = f r esp( n, f , gf , w, p1, p2, . . . )
where:
n is thefilter order.
f isthevector of frequencybandedges that appear monotonicallybetween -1
and 1, where1 corresponds totheNyquist frequency.
gf is a vector of grid points that havebeen linearly interpolated over each
specified frequency band by cr emez. gf determines thefrequency grid at
which theresponsefunction must beevaluated. This is thesamedata
returned by cr emez in thef gr i d field of theopt structure.
wisavector of real, positiveweights, oneper band, usedduringoptimization.
wis optional in thecall tocr emez; if not specified, it is set tounity weighting
beforebeingpassed tof r esp.
dh and dwarethedesired complex frequency responseand band weight
vectors, respectively, evaluated at each frequency in grid gf .
p1, p2, . . . , areoptional parameters that may bepassed to f r esp.
opt . f gr i d Frequency grid vector used for thefilter design optimization
opt . des Desired frequency responsefor each point in opt . f gr i d
opt . wt Weightingfor each point in opt . f gr i d
opt . H Actual frequency responsefor each point in opt . f gr i d
opt . er r or Error at each point in opt . f gr i d
opt . i ext r Vector of indices intoopt . f gr i d for extremal frequencies
opt . f ext r Vector of extremal frequencies
cremez
7-107
Additionally, a preliminary call is madetof r esp todeterminethedefault
symmetry property ' sym' . This call is madeusingthesyntax.
sym= f r esp( ' def aul t s' , {n, f , [ ] , w, p1, p2, . . . })
Thearguments may beused in determiningan appropriatesymmetry default
as necessary. Thefunction pr i vat e/ l owpass. mmaybeuseful asatemplatefor
generatingnewfrequency responsefunctions.
Examples Example 1
Design a 31-tap, linear-phase, lowpass filter.
b = cr emez( 30, [ - 1 - 0. 5 - 0. 4 0. 7 0. 8 1] , ' l owpass' ) ;
f r eqz( b, 1, 512, ' whol e' ) ;
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
3500
3000
2500
2000
1500
1000
500
0
Normalized Frequency ( rad/sample)
P
h
a
s
e

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

(
d
B
)
cremez
7-108
Example 2
Design a nonlinear-phaseallpass FI R filter.
First select (or create) thefunction f r esp that returns thedesired frequency
response. For this example, f r esp is theal l pass. mfunction in the
si gnal / si gnal / pr i vat e directory which returns thefrequency responseof a
nonlinear-phaseallpass filter. Copy al l pass. mtoanother location on the
MATLAB path beforetryingtheexample.
Beforeusingcr emez with al l pass. mtogeneratethefilter coefficients, call
al l pass alonetocreatethedesired response.
n = 22; %Fi l t er or der
f = [ - 1 1] ; %Fr equency band edges
w = [ 1 1] ; %Wei ght s f or opt i mi zat i on
gf = l i nspace( - 1, 1, 256) ; %Gr i d of f r equency poi nt s
d = al l pass( n, f , gf , w) ; %Desi r ed f r equency r esponse
Vector d nowcontains thecomplex frequency responsethat wedesirefor the
FI R filter computed by cr emez.
NowcomputetheFI R filter that best approximates this response.
b = cr emez( n, f , ' al l pass' , w, ' r eal ' ) ; %Appr oxi mat i on
f r eqz( b, 1, 256, ' whol e' ) ;
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
1500
1000
500
0
500
Normalized Frequency ( rad/sample)
P
h
a
s
e

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

(
d
B
)
cremez
7-109
Thef r eqz plot shows thefrequency responseof thefilter computedby cr emez
toapproximatethedesiredresponse. Check theaccuracy of theapproximation
by overlayingthedesired frequency responseon theplot.
subpl ot ( 2, 1, 1) ; hol d on
pl ot ( pi *( gf +1) , 20*l og10( abs( f f t shi f t ( d) ) ) , ' r - - ' )
subpl ot ( 2, 1, 2) ; hol d on
pl ot ( pi *( gf +1) , unwr ap( angl e( f f t shi f t ( d) ) ) *180/ pi , ' r - - ' )
l egend( ' Appr oxi mat i on' , ' Desi r ed' )
Algorithm An extended version of theRemez exchangemethod is implemented for the
complex case. This exchangemethod obtains theoptimal filter when the
equiripplenatureof thefilter is restrictedtohaven+2 extremals. When it does
not converge, thealgorithmswitches toan ascent-descent algorithmthat takes
over tofinish theconvergencetotheoptimal solution. Seethereferences for
further details.
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
3000
2000
1000
0
Normalized Angular Frequency ( rads/sample)
P
h
a
s
e

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

(
d
B
)
Approximation
Desired
cremez
7-110
See Also
References [1] Karam, L.J ., and J .H. McClellan. Complex Chebyshev Approximation for
FI R Filter Design. I EEE Trans. on Circuits and Systems I I . March 1995.
Pgs. 207-216.
[2] Karam, L.J . Design of Complex Digital FI R Filters in theChebyshev Sense.
Ph.D. Thesis, Georgia I nstituteof Technology, March 1995.
[3] Demjanjov, V.F., andV.N. Malozemov. I ntroductiontoMinimax. NewYork:
J ohn Wiley & Sons, 1974.
f i r 1 FI R filter design usingthewindowmethod.
f i r 2 FI R filter design with arbitrary filter shapeusingthe
windowmethod.
f i r l s Linear phaseFI R filter design usingthe
least-squares method.
r emez Parks-McClellan optimal FI R filter design.
csd
7-111
7csd
Purpose Estimatethecross spectral density (CSD) of twosignals.
Syntax Pxy = csd( x, y)
Pxy = csd( x, y, nf f t )
[ Pxy, f ] = csd( x, y, nf f t , f s)
Pxy = csd( x, y, nf f t , f s, wi ndow)
Pxy = csd( x, y, nf f t , f s, wi ndow, numover l ap)
Pxy = csd( x, y, . . . , ' df l ag' )
[ Pxy, Pxyc, f ] = csd( x, y, nf f t , f s, wi ndow, numover l ap, p)
csd( x, y, . . . )
Description Pxy = csd( x, y) estimates thecross spectral density of thelength n sequences
x and y usingtheWelch method of spectral estimation. Pxy = csd( x, y) uses
thefollowingdefault values:
nf f t = mi n( 256, l engt h( x) )
f s = 2
wi ndowis a periodic Hann windowof length nf f t .
numover l ap = 0
nf f t specifies theFFT length that csd uses. This valuedetermines the
frequencies at which thecross spectrumis estimated. f s is a scalar that
specifies thesamplingfrequency. wi ndowspecifies a windowingfunction and
thenumber of samples csd uses in its sectioningof thex and y vectors.
numover l ap is thenumber of samples by which thesections overlap. Any
arguments omitted fromtheend of theparameter list usethedefault values
shown above.
I f x and y arereal, csd estimates thecross spectral density at positive
frequencies only; in this case, theoutput Pxy is a column vector of length
nf f t / 2 +1 for nf f t even and ( nf f t +1) / 2 for nf f t odd. I f x or y is complex,
csd estimates thecross spectral density at both positiveand negative
frequencies and Pxy has length nf f t .
Pxy = csd( x, y, nf f t ) uses theFFT length nf f t in estimatingthecross
spectral density of x and y. Specify nf f t as a power of 2 for fastest execution.
[ Pxy, f ] = csd( x, y, nf f t , f s) returns a vector f of frequencies at which the
function evaluates theCSD. f is thesamesizeas Pxy, sopl ot ( f , Pxy) plots the
csd
7-112
spectrumversus properly scaled frequency. f s has noeffect on theoutput Pxy;
it is a frequency scalingmultiplier.
Pxy = csd( x, y, nf f t , f s, wi ndow) specifies a windowingfunction and the
number of samplesper section of thex vector. I f you supplyascalar for wi ndow,
csd uses aHann windowof that length. Thelength of thewindowmust beless
than or equal tonf f t ; csd zeropads thesections if thelength of thewindowis
less than nf f t . csd returns an error if thelength of thewindowis greater than
nf f t .
Pxy = csd( x, y, nf f t , f s, wi ndow, numover l ap) overlapsthesectionsof x andy
by numover l ap samples.
You can usetheempty matrix [ ] tospecify thedefault valuefor any input
argument except x or y. For example,
csd( x, y, [ ] , 10000)
is equivalent to
csd( x)
but with a samplingfrequency of 10,000 Hz instead of thedefault of 2 Hz.
Pxy = csd( x, y, . . . , ' df l ag' ) specifies a detrend option, wherethestring
' df l ag' is oneof thefollowing:
' l i near ' , toremovethebest straight-linefit fromtheprewindowedsections
of x and y
' mean' , toremovethemean fromtheprewindowed sections of x and y
' none' , for nodetrending(default)
Thedf l ag parameter must appear last in thelist of input arguments. csd
recognizes a df l ag stringnomatter howmany intermediatearguments are
omitted.
[ Pxy, Pxyc, f ] = csd( x, y, nf f t , f s, wi ndow, numover l ap, p) wherep is a
positivescalar between0and1returns avector Pxyc that contains an estimate
of thep*100 percent confidenceinterval for Pxy. Pxyc is a two-column matrix
thesamelength as Pxy. Theinterval [ Pxyc( : , 1) , Pxyc( : , 2) ] covers thetrue
csd
7-113
CSD with probability p. pl ot ( f , [ Pxy Pxyc] ) plots thecross spectruminside
thep*100 percent confidenceinterval. I f unspecified, p defaults to0.95.
csd( x, y, . . . ) plots theCSD versus frequency in thecurrent figurewindow. I f
thep parameter is specified, theplot includes theconfidenceinterval.
Example Generatetwocolored noisesignals and plot their CSD with a confidence
interval of 95%. Specifyalength1024FFT, a500point triangular windowwith
nooverlap, and a samplingfrequency of 10 Hz.
r andn( ' st at e' , 0) ;
h = f i r 1( 30, 0. 2, boxcar ( 31) ) ;
h1 = ones( 1, 10) / sqr t ( 10) ;
r = r andn( 16384, 1) ;
x = f i l t er ( h1, 1, r ) ;
y = f i l t er ( h, 1, x) ;
csd( x, y, 1024, 10000, t r i ang( 500) , 0, [ ] )
Algorithm csd implements theWelch method of spectral density estimation (see
references [1] and [2]):
1 I t applies thewindowspecified by thewi ndowvector toeach successive
detrended section.
2 I t transforms each section with an nf f t -point FFT.
0 1000 2000 3000 4000 5000
70
60
50
40
30
20
10
0
10
20
Frequency
C
r
o
s
s

S
p
e
c
t
r
u
m

M
a
g
n
i
t
u
d
e

(
d
B
)
csd
7-114
3 I t forms theperiodogramof each section by scalingtheproduct of the
transformof they section and theconjugateof thetransformed x section.
4 I t averages theperiodograms of thesuccessiveoverlappingsections toform
Pxy, thecross spectral density of x and y.
Thenumber of sections that csd averages is k, wherek is
f i x( ( l engt h( x) - numover l ap) / ( l engt h( wi ndow) - numover l ap) )
Diagnostics An appropriatediagnostic messageis displayed when incorrect arguments to
csd areused.
Requi r es wi ndow' s l engt h t o be no gr eat er t han t he FFT l engt h.
Requi r es NOVERLAP t o be st r i ct l y l ess t han t he wi ndow l engt h.
Requi r es posi t i ve i nt eger val ues f or NFFT and NOVERLAP.
Requi r es vect or ( ei t her r ow or col umn) i nput .
Requi r es i nput s X and Y t o have t he same l engt h.
Requi r es conf i dence par amet er t o be a scal ar bet ween 0 and 1.
See Also
References [1] Rabiner, L.R., and B. Gold. Theory and Application of Digital Signal
Processing. Englewood Cliffs, NJ : Prentice-Hall, 1975. Pgs. 414-419.
[2] Welch, P.D. TheUseof Fast Fourier Transformfor theEstimationof Power
Spectra: A Method Based on TimeAveragingOver Short, Modified
Periodograms.I EEE Trans. AudioElectroacoust. Vol. AU-15 (J une1967).
Pgs. 70-73.
coher e Estimatemagnitudesquared coherencefunction
between twosignals.
pbur g Estimatethepower spectrumusingtheBurg
method.
pmt m Estimatethepower spectrumusingthemultitaper
method (MTM).
pmusi c EstimatethepseudospectrumusingtheMUSI C
algorithm.
pwel ch Estimatethepower spectrumusingWelchs method.
pyul ear Estimatethepower spectrumusingtheYule-Walker
autoregressivemethod.
t f e Transfer function estimatefrominput and output.
csd
7-115
[3] Oppenheim, A.V., and R.W. Schafer. Discrete-TimeSignal Processing.
Englewood Cliffs, NJ : Prentice-Hall, 1989. Pg. 737.
czt
7-116
7czt
Purpose Chirp z-transform.
Syntax y = czt ( x, m, w, a)
y = czt ( x)
Description y =czt ( x, m, w, a) returns thechirp z-transformof signal x. Thechirp
z-transformis thez-transformof x alonga spiral contour defined by wand a.
mis a scalar that specifies thelength of thetransform, wis theratiobetween
points alongthez-planespiral contour of interest, and scalar a is thecomplex
startingpoint on that contour. Thecontour, aspiral or chirpin thez-plane, is
given by
z = a*( w. ^- ( 0: m- 1) )
y =czt ( x) uses thefollowingdefault values:
m=l engt h( x)
w=exp( j *2*pi / m)
a =1
Withthesedefaults, czt returns thez-transformof x at mequallyspacedpoints
aroundtheunit circle. This isequivalent tothediscreteFourier transformof x,
or f f t ( x) . Theempty matrix [ ] specifies thedefault valuefor a parameter.
I f x is a matrix, czt ( x, m, w, a) transforms thecolumns of x.
Examples Createa randomvector x of length 1013and computeits DFT usingczt . This
is faster than thef f t function on thesamesequence.
r andn( ' st at e' , 0) ;
x = r andn( 1013, 1) ;
y = czt ( x) ;
Useczt tozoomin on a narrow-band section (100 to150 Hz) of a filters
frequency response. First design thefilter.
h = f i r 1( 30, 125/ 500, boxcar ( 31) ) ; %f i l t er
czt
7-117
Establish frequency and CZT parameters.
f s = 1000; f 1 = 100; f 2 = 150; %i n her t z
m= 1024;
w = exp( - j *2*pi *( f 2- f 1) / ( m*f s) ) ;
a = exp( j *2*pi *f 1/ f s) ;
Computeboth theDFT and CZT of thefilter.
y = f f t ( h, 1000) ;
z = czt ( h, m, w, a) ;
Createfrequency vectors and comparetheresults.
f y = ( 0: l engt h( y) - 1) ' *1000/ l engt h( y) ;
f z = ( ( 0: l engt h( z) - 1) ' *( f 2- f 1) / l engt h( z) ) + f 1;
pl ot ( f y( 1: 500) , abs( y( 1: 500) ) ) ; axi s( [ 1 500 0 1. 2] )
t i t l e( ' FFT' )
f i gur e
pl ot ( f z, abs( z) ) ; axi s( [ f 1 f 2 0 1. 2] )
t i t l e( ' CZT' )
Algorithm czt uses thenext power-of-2 length FFT toperforma fast convolution when
computingthez-transformon a specified chirp contour [1]. czt can be
significantly faster than f f t for large, prime-length sequences.
Diagnostics I f m, w, or a is not a scalar, czt gives thefollowingerror message.
I nput s M, W, and A must be scal ar s.
100 200 300 400 500
0
0.2
0.4
0.6
0.8
1
FFT
100 110 120 130 140
0
0.2
0.4
0.6
0.8
1
CZT
czt
7-118
See Also
References [1] Rabiner, L.R., and B. Gold. Theory and Application of Digital Signal
Processing. Englewood Cliffs, NJ : Prentice-Hall, 1975. Pgs. 393-399.
f f t Computetheone-dimensional fast Fourier
Transform.
f r eqz Computethefrequency responsefor digital filters.
dct
7-119
7dct
Purpose Discretecosinetransform(DCT).
Syntax y = dct ( x)
y = dct ( x, n)
Description y =dct ( x) returns theunitary discretecosinetransformof x
where
N is thelength of x, and x and y arethesamesize. I f x is a matrix, dct
transforms its columns. Theseries is indexed fromn =1 and k =1 instead of
theusual n =0and k =0 becauseMATLAB vectors run from1 toN instead of
from0 toN- 1.
y =dct ( x, n) pads or truncates x tolength n beforetransforming.
TheDCT is closely related tothediscreteFourier transform. You can often
reconstruct a sequencevery accurately fromonly a fewDCT coefficients, a
useful property for applications requiringdata reduction.
y k ( ) w k ( ) x n ( )
2n 1 ( ) k 1 ( )
2N
------------------------------------------ - cos
n 1 =
N

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






=
dct
7-120
Example Find howmany DCT coefficients represent 99%of theenergy in a sequence.
x = ( 1: 100) + 50*cos( ( 1: 100) *2*pi / 40) ;
X = dct ( x) ;
[ XX, i nd] = sor t ( abs( X) ) ; i nd = f l i pl r ( i nd) ;
i = 1;
whi l e ( nor m( [ X( i nd( 1: i ) ) zer os( 1, 100- i ) ] ) / nor m( X) <. 99)
i = i + 1;
end
i =
3
See Also
References [1] J ain, A.K. Fundamentalsof Digital I mageProcessing. EnglewoodCliffs, NJ :
Prentice-Hall, 1989.
[2] Pennebaker, W.B., and J .L. Mitchell. J PEG Still I mageData Compression
Standard. NewYork, NY: Van Nostrand Reinhold, 1993. Chapter 4.
f f t Computetheone-dimensional fast Fourier
transform.
i dct Computetheinversediscretecosinetransform.
dct 2 Two-dimensional DCT (seeI mageProcessingToolbox
Users Guide).
i dct 2 Two-dimensional inverseDCT (seeI mageProcessing
Toolbox Users Guide).
decimate
7-121
7decimate
Purpose Decreasethesamplingratefor a sequence(decimation).
Syntax y = deci mat e( x, r )
y = deci mat e( x, r , n)
y = deci mat e( x, r , ' f i r' )
y = deci mat e( x, r , n, ' f i r' )
Description Decimation reduces theoriginal samplingratefor a sequencetoa lower rate,
theoppositeof interpolation. Thedecimationprocessfilterstheinput datawith
a lowpass filter and then resamples theresultingsmoothed signal at a lower
rate.
y =deci mat e( x, r ) reduces thesamplerateof x by a factor r . Thedecimated
vector y is r times shorter in length than theinput vector x. By default,
deci mat e employs an eighth-order lowpass Chebyshev typeI filter. I t filters
theinput sequencein both theforward and reversedirections toremoveall
phasedistortion, effectively doublingthefilter order.
y =deci mat e( x, r , n) usesanorder nChebyshevfilter. Ordersabove13arenot
recommended becauseof numerical instability. MATLAB displays a warning
in this case.
y =deci mat e( x, r , ' f i r' ) uses a30-point FI R filter, insteadof theChebyshev
I I R filter. Heredeci mat e filters theinput sequencein only onedirection. This
techniqueconserves memory and is useful for workingwith longsequences.
y =deci mat e( x, r , n, ' f i r' ) uses a length n FI R filter.
Example Decimatea signal by a factor of four.
t = 0: . 00025: 1; %Ti me vect or
x = si n( 2*pi *30*t ) + si n( 2*pi *60*t ) ;
y = deci mat e( x, 4) ;
decimate
7-122
Viewtheoriginal and decimated signals.
st em( x( 1: 120) ) , axi s( [ 0 120 - 2 2] ) %Or i gi nal si gnal
t i t l e( ' Or i gi nal Si gnal ' )
f i gur e
st em( y( 1: 30) ) %Deci mat ed si gnal
t i t l e( ' Deci mat ed Si gnal ' )
Algorithm deci mat e uses decimation algorithms 8.2 and 8.3 from[1]:
1 I t designs a lowpass filter. By default, deci mat e uses a Chebyshev typeI
filter with normalized cutoff frequency 0. 8/ r and 0.05 dB of passband
ripple. For thef i r option, deci mat e designs alowpass FI R filter with cutoff
frequency 1/ r usingf i r 1.
2 For theFI R filter, deci mat e applies thefilter totheinput vector in one
direction. I n theI I R case, deci mat e applies thefilter in forwardandreverse
directions with f i l t f i l t .
3 deci mat e resamples thefiltered data by selectingevery r th point.
Diagnostics I f r is not an integer, deci mat e gives thefollowingerror message.
Resampl i ng r at e R must be an i nt eger .
I f n specifies an I I R filter with order greater than 13, deci mat e gives the
followingwarning.
War ni ng: I I R f i l t er s above or der 13 may be unr el i abl e.
0 50 100
-2
-1
0
1
2
Original Signal
0 10 20 30
-2
-1
0
1
2
Decimated Signal
decimate
7-123
See Also
References [1] I EEE. Programsfor Digital Signal Processing. I EEE Press. NewYork: J ohn
Wiley & Sons, 1979. Chapter 8.
i nt er p Resampledata at a higher rateusinglowpass
interpolation.
r esampl e Changesamplingrateby any rational factor.
spl i ne Cubic splineinterpolation (seetheMATLAB
documentation).
upf i r dn Upsample, apply an FI R filter, and downsample.
deconv
7-124
7deconv
Purpose Deconvolution and polynomial division.
Syntax [ q, r ] = deconv( b, a)
Description [ q, r ] =deconv( b, a) deconvolves vector a out of vector b, usinglongdivision.
Theresult (quotient) is returnedin vector q andtheremainder in vector r such
that b =conv( q, a) +r .
I f a andb arevectors of polynomial coefficients, convolvingthemis equivalent
topolynomial multiplication, and deconvolution is equivalent topolynomial
division. Theresult of dividingb by a is quotient q and remainder r .
Thedeconv function is part of thestandard MATLAB language.
Example Theconvolution of a =[ 1 2 3] and b =[ 4 5 6] is
c = conv( a, b)
c =
4 13 28 27 18
Usedeconv todivideb back out.
[ q, r ] = deconv( c, a)
q =
4 5 6
r =
0 0 0 0 0
Algorithm This function calls f i l t er tocomputethedeconvolution as theimpulse
responseof an I I R filter.
See Also
conv Convolution and polynomial multiplication.
f i l t er Apply a filter todata.
r esi duez z-transformpartial fraction expansion.
demod
7-125
7demod
Purpose Demodulation for communications simulation.
Syntax x = demod( y, f c, f s, ' met hod' )
x = demod( y, f c, f s, ' met hod' , opt )
x = demod( y, f c, f s, ' pwm' , ' centered' )
[ x1, x2] = demod( y, f c, f s, ' qam' )
Description demod performs demodulation, that is, it obtains theoriginal signal froma
modulated version of thesignal. demod undoes theoperation performed by
modul at e.
x =demod( y, f c, f s, ' met hod' ) and
x =demod( y, f c, f s, ' met hod' , opt ) demodulatethereal carrier signal y witha
carrier frequency f c andsamplingfrequencyf s, usingoneof theoptions listed
belowfor met hod. (Notethat somemethods accept an option, opt .)
amdsb- sc
or
am
Amplitudedemodulation, doublesideband, suppressed
carrier. Multiplies y by a sinusoid of frequency f c and applies a
fifth-order Butterworth lowpass filter using f i l t f i l t .
x =y. *cos( 2*pi *f c*t ) ;
[ b, a] =but t er ( 5, f c*2/ f s) ;
x =f i l t f i l t ( b, a, x) ;
amdsb- t c Amplitudedemodulation, doublesideband, transmitted
carrier. Multiplies y by a sinusoid of frequency f c, and applies a
fifth-order Butterworth lowpass filter using f i l t f i l t .
x =y. *cos( 2*pi *f c*t ) ;
[ b, a] =but t er ( 5, f c*2/ f s) ;
x =f i l t f i l t ( b, a, x) ;
I f you specify opt , demod subtracts scalar opt fromx. Thedefault
valuefor opt is 0.
amssb Amplitudedemodulation, singlesideband. Multiplies y by a
sinusoid of frequency f c and applies a fifth-order Butterworth
lowpass filter using f i l t f i l t .
x =y. *cos( 2*pi *f c*t ) ;
[ b, a] =but t er ( 5, f c*2/ f s) ;
x =f i l t f i l t ( b, a, x) ;
demod
7-126
Thedefault method is ' am' . Except for the' pt m' and ' pwm' cases, x is the
samesizeas y.
I f y is a matrix, demod demodulates its columns.
x =demod( y, f c, f s, ' pwm' , ' centered' ) finds thepulsewidths assumingthey
arecentered at thebeginningof each period. x is length l engt h( y) *f c/ f s.
See Also
f m Frequency demodulation. Demodulates theFM waveformby
modulatingtheHilbert transformof y by a complex exponential
of frequency - f c Hz and obtains theinstantaneous frequency of
theresult.
pm Phasedemodulation. Demodulates thePM waveformby
modulatingtheHilbert transformof y by a complex exponential
of frequency f c Hz and obtains theinstantaneous phaseof the
result.
pt m Pulse-timedemodulation. Finds thepulsetimes of a pulse-time
modulated signal y. For correct demodulation, thepulses cannot
overlap. x is length l engt h( t ) *f c/ f s.
pwm Pulse-width demodulation. Finds thepulsewidths of a
pulse-width modulatedsignal y. demod returns in x avector whose
elements specify thewidth of each pulsein fractions of a period.
Thepulses in y should start at thebeginningof each carrier
period, that is, they should beleft justified.
qam Quadratureamplitudedemodulation.
[ x1, x2] =demod( y, f c, f s, ' qam' ) multiplies y by a cosineand a
sineof frequency f c and applies a fifth-order Butterworth
lowpass filter usingf i l t f i l t .
x1 =y. *cos( 2*pi *f c*t ) ;
x2 =y. *si n( 2*pi *f c*t ) ;
[ b, a] =but t er ( 5, f c*2/ f s) ;
x1 =f i l t f i l t ( b, a, x1) ;
x2 =f i l t f i l t ( b, a, x2) ;
modul at e Apply modulation methods tosignals.
vco Voltagecontrolled oscillator.
dftmtx
7-127
7dftmtx
Purpose DiscreteFourier transformmatrix.
Syntax A = df t mt x( n)
Description A discreteFourier transformmatrix is a complex matrix of values around the
unit circle, whosematrix product with a vector computes thediscreteFourier
transformof thevector.
A =df t mt x( n) returns then-by-n complex matrix Athat, when multiplied into
a length n column vector x.
y = A*x
computes thediscreteFourier transformof x.
TheinversediscreteFourier transformmatrix is
Ai = conj ( df t mt x( n) ) / n
Example I n practice, thediscreteFourier transformis computed moreefficiently and
uses less memory with an FFT algorithm
x = 1: 256;
y1 = f f t ( x) ;
than by usingtheFourier transformmatrix.
n = l engt h( x) ;
y2 = x*df t mt x( n) ;
nor m( y1- y2)
ans =
1. 8297e- 009
Algorithm df t mt x uses an outer product togeneratethetransformmatrix.
See Also
convmt x Convolution matrix.
f f t Computetheone-dimensional fast Fourier
transform.
diric
7-128
7diric
Purpose ComputetheDirichlet or periodic sinc function.
Syntax y = di r i c( x, n)
Description y =di r i c( x, n) returns a vector or array y thesamesizeas x. Theelements of
y aretheDirichlet function of theelements of x. n must bea positiveinteger.
TheDirichlet function, or periodic sinc function, is
for any nonzerointeger n. This function has period 2 for n odd and period 4
for n even. I ts peak valueis 1, and its minimumvalueis -1 for n even. The
magnitudeof this function is (1/ n) times themagnitudeof thediscrete-time
Fourier transformof then-point rectangular window.
Diagnostics I f n is not a positiveinteger, di r i c gives thefollowingerror message.
Requi r es n t o be a posi t i ve i nt eger .
See Also
diric x n , ( )
1
x
2
------- n 1 ( )
x 0 2 4 , , , =
nx 2 ( ) sin
n x 2 ( ) sin
----------------------------
else




=
cos Computethecosineof vector/matrix elements (see
theMATLAB documentation).
gauspul s Generatea Gaussian-modulated signal pulse.
pul st r an Generatea pulsetrain.
r ect pul s Generatea sampled aperiodic rectangle.
sawt oot h Generatea sawtooth or trianglewave.
si n Computethesineof vector/matrix elements (seethe
MATLAB documentation).
si nc Computethesincor sin(t)/t function.
squar e Generatea squarewave.
t r i pul s Generatea sampled aperiodic triangle.
dpss
7-129
7dpss
Purpose Discreteprolatespheroidal 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, ' i nt ' )
[ e, v] = dpss( n, nw, ' i nt ' , Ni )
[ e, v] = dpss( . . . , ' trace' )
Description [ e, v] =dpss( n, nw) generates thefirst 2*nwdiscreteprolatespheroidal
sequences (DPSS) of length n in thecolumns of e, and their corresponding
concentrations in vector v. They arealsogenerated in theDPSS MAT-file
databasedpss. mat . nwmust beless than n/ 2.
[ e, v] =dpss( n, nw, k) returns thek most band-limited discreteprolate
spheroidal sequences. k must bean integer such that 1 k n.
[ e, v] =dpss( n, nw, [ k1 k2] ) returns thek1st through thek2nd discrete
prolatespheroidal sequences, where1 k1 k2 n.
For all of theaboveforms:
TheSlepian sequences arecalculated directly.
Thesequences aregenerated in thefrequency band | | ( 2W) , where
W= nw/ n is thehalf-bandwidth and is in rad/sample.
e( : , 1) is thelength n signal most concentrated in thefrequency band
| | ( 2W) radians, e( : , 2) is thesignal orthogonal toe( : , 1) that is most
concentrated in this band, e( : , 3) is thesignal orthogonal toboth e( : , 1)
and e( : , 2) that is most concentrated in this band, etc.
For multitaper spectral analysis, typical choices for nware2, 5/2, 3, 7/2, or 4.
[ e, v] =dpss( n, nw, ' i nt ' ) uses theinterpolation method specified by the
string' i nt ' tocomputee and v fromthesequences in dpss. mat with length
closest ton. Thestring' i nt ' can beeither:
' spl i ne' : Usesplineinterpolation.
' l i near ' : Uselinear interpolation. This is much faster but less accurate
than splineinterpolation.
dpss
7-130
[ e, v] =dpss( n, nw, ' i nt ' , Ni ) interpolatesfromexistinglengthNi sequences.
Theinterpolation method ' l i near ' requires Ni >n.
[ e, v] =dpss( . . . , ' trace' ) uses thetrailingstring' trace' todisplay which
interpolation methodDPSS uses. I f you dont specifytheinterpolation method,
thedisplay indicates that you areusingthedirect method.
Examples Example 1: Using dpss, dpssave, and dpssdir
Createa catalogueof 16 DPSS functions with nw=4, and usespline
interpolation on 10 of thesefunctions whiledisplayingtheinterpolation
method you use. You can dothis usingdpss, dpsssave, and dpssdi r .
%Cr eat e t he cat al ogue of f unct i ons.
[ e, v] = dpss( 16, 4) ;
%Save e and v i n a MAT- f i l e.
dpsssave( 4, e, v) ;
%Fi nd nw = 4. Fi r st cr eat e a st r uct ur e cal l ed i ndex.
i ndex = dpssdi r ;
i ndex. wl i st s
ans =
NW: 4
key: 1
%Use spl i ne i nt er pol at i on on 10 of t he DPSS f unct i ons.
[ e1, v1] = dpss( 10, 4, ' spl i ne' , si ze( e, 1) , ' t r ace' ) ;
Example 2: Using dpss and dpssload
Createa set of DPSS functions usingdpss, and usethesplinemethod on a
subset of thesefunctions. Usedpssl oad toload theMAT-filecreated by dpss.
%Cr eat e t he cat al ogue of f unct i ons.
[ e, v] = dpss( 16, 4) ;
%Load dpss. mat , wher e e and v ar e saved.
[ e1, v1] = dpssl oad( 16, 4) ;
%Use spl i ne i nt er pol at i on on 10 of t he DPSS f unct i ons.
[ e1, v1] = dpss( 10, 4, ' spl i ne' ) ;
dpss
7-131
See Also
References [1] Percival, D.B., and A.T. Walden. Spectral Analysis for Physical
Applications: Multitaper andConventional UnivariateTechniques. Cambridge:
CambridgeUniversity Press, 1993.
dpsscl ear Removediscreteprolatespheroidal sequences from
database.
dpssdi r Discreteprolatespheroidal sequences database
directory.
dpssl oad Load discreteprolatespheroidal sequences from
database.
dpsssave Savediscreteprolatespheroidal sequences in
database.
pmt m Estimatethepower spectral density usingthe
multitaper method (MTM).
dpssclear
7-132
7dpssclear
Purpose Removediscreteprolatespheroidal sequences fromdatabase.
Syntax dpsscl ear ( n, nw)
Description dpsscl ear ( n, nw) removes sequences with length n and time-bandwidth
product nwfromtheDPSS MAT-filedatabasedpss. mat .
See Also
dpss Discreteprolatespheroidal sequences (Slepian
sequences).
dpssdi r Discreteprolatespheroidal sequences database
directory.
dpssl oad Load discreteprolatespheroidal sequences from
database.
dpsssave Savediscreteprolatespheroidal sequences in
database.
dpssdir
7-133
7dpssdir
Purpose Discreteprolatespheroidal sequences databasedirectory.
Syntax dpssdi r
dpssdi r ( n)
dpssdi r ( nw, ' nw' )
dpssdi r ( n, nw)
i ndex = dpssdi r
Description dpssdi r manages thedatabasedirectory that contains thegenerated DPSS
samples in theDPSS MAT-filedatabasedpss. mat .
dpssdi r lists thedirectory of saved sequences in dpss. mat .
dpssdi r ( n) lists thesequences saved with length n.
dpssdi r ( nw, ' nw' ) lists thesequences saved with time-bandwidth product nw.
dpssdi r ( n, nw) lists thesequences saved with length n and time-bandwidth
product nw.
i ndex =dpssdi r is a structurearray describingtheDPSS database. Pass n
and nwoptions as for thenooutput casetoget a filtered i ndex.
Examples SeeExample1: Usingdpss, dpssave, and dpssdir on page7-130.
See Also
dpss Discreteprolatespheroidal sequences (Slepian
sequences).
dpsscl ear Removediscreteprolatespheroidal sequences from
database.
dpssl oad Load discreteprolatespheroidal sequences from
database.
dpsssave Savediscreteprolatespheroidal sequences in
database.
dpssload
7-134
7dpssload
Purpose Load discreteprolatespheroidal sequences fromdatabase.
Syntax [ e, v] = dpssl oad( n, nw)
Description [ e, v] =dpssl oad( n, nw) loads all sequences with length n and
time-bandwidth product nwin thecolumns of e and their corresponding
concentrations in vector v fromtheDPSS MAT-filedatabasedpss. mat .
Examples SeeExample2: Usingdpss and dpssloadon page7-130.
See Also
dpss Discreteprolatespheroidal sequences (Slepian
sequences).
dpsscl ear Removediscreteprolatespheroidal sequences from
database.
dpssdi r Discreteprolatespheroidal sequences database
directory.
dpsssave Savediscreteprolatespheroidal sequences in
database.
dpsssave
7-135
7dpsssave
Purpose Savediscreteprolatespheroidal sequences in database.
Syntax dpsssave( nw, e, v)
st at us = dpsssave( nw, e, v)
Description dpsssave( nw, e, v) saves thesequences in thecolumns of e and their
correspondingconcentrations in vector v in theDPSS MAT-filedatabase
dpss. mat .
I t is not necessary tospecify sequencelength, becausethelength of the
sequenceis determined by thenumber of rows of e.
nwis thetime-bandwidth product that was specifiedwhen thesequencewas
created usingdpss.
st at us =dpsssave( nw, e, v) returns 0 if thesavewas successful and1 if there
was an error.
Examples SeeExample1: Usingdpss, dpssave, and dpssdir on page7-130.
See Also
dpss Discreteprolatespheroidal sequences (Slepian
sequences).
dpsscl ear Removediscreteprolatespheroidal sequences from
database.
dpssdi r Discreteprolatespheroidal sequences database
directory.
dpssl oad Load discreteprolatespheroidal sequences from
database.
ellip
7-136
7ellip
Purpose Elliptic (Cauer) filter design.
Syntax [ b, a] = el l i p( n, Rp, Rs, Wn)
[ b, a] = el l i p( n, Rp, Rs, Wn, ' f t ype' )
[ b, a] = el l i p( n, Rp, Rs, Wn, ' s' )
[ b, a] = el l i p( n, Rp, Rs, Wn, ' f t ype' , ' s' )
[ z, p, k] = el l i p( . . . )
[ A, B, C, D] = el l i p( . . . )
Description el l i p designs lowpass, bandpass, highpass, and bandstop digital and analog
elliptic filters. Elliptic filters offer steeper rolloff characteristics than
Butterworth or Chebyshev filters, but areequiripplein both thepass- and
stopbands. I n general, elliptic filters meet given performancespecifications
with thelowest order of any filter type.
Digital Domain
[ b, a] =el l i p( n, Rp, Rs, Wn) designs an order n lowpass digital elliptic filter
withcutoff frequencyWn, Rp dB of rippleinthepassband, andastopbandRs dB
downfromthepeak valueinthepassband. I t returnsthefilter coefficientsinthe
length n+1 rowvectors b and a, with coefficients in descendingpowers of z.
Thecutoff frequency is theedgeof thepassband, at which themagnitude
responseof thefilter is - Rp dB. For el l i p, thecutoff frequency Wn is a number
between 0and1, where1corresponds tohalf thesamplingfrequency (Nyquist
frequency). Smaller values of passbandrippleRp andlarger values of stopband
attenuation Rs both lead towider transition widths (shallower rolloff
characteristics).
I f Wn is a two-element vector, Wn =[ w1 w2] , el l i p returns an order 2*n
bandpass filter with passband w1 < <w2.
H z ( )
B z ( )
A z ( )
-----------
b 1 ( ) b 2 ( )z
1
L b n 1 + ( )z
n
+ + +
1 a 2 ( )z
1
L a n 1 + ( )z
n
+ + +
------------------------------------------------------------------------------------ = =
ellip
7-137
[ b, a] =el l i p( n, Rp, Rs, Wn, ' f t ype' ) designs a highpass or bandstop filter,
wherethestring' f t ype' is either:
' hi gh' for a highpass digital filter with cutoff frequency Wn
' st op' for an order 2*n bandstop digital filter if Wn is a two-element vector,
Wn =[ w1 w2] . Thestopband is w1 < <w2.
With different numbers of output arguments, el l i p directly obtains other
realizations of thefilter. Toobtain zero-pole-gain form, usethreeoutput
arguments as shown below.
[ z, p, k] =el l i p( n, Rp, Rs, Wn) or
[ z, p, k] = el l i p( n, Rp, Rs, Wn, ' f t ype' ) returnsthezerosandpolesinlength
n column vectors z and p and thegain in thescalar k.
Toobtain state-spaceform, usefour output arguments as shown below.
[ A, B, C, D] =el l i p( n, Rp, Rs, Wn) or
[ A, B, C, D] =el l i p( n, Rp, Rs, Wn, ' f t ype' ) whereA, B, C, and Dare
and u is theinput, x is thestatevector, and y is theoutput.
Analog Domain
[ b, a] =el l i p( n, Rp, Rs, Wn, ' s' ) designs an order n lowpass analogelliptic
filter with cutoff frequency Wn and returns thefilter coefficients in thelength
n+1 rowvectors b and a, in descendingpowers of s, derived fromthetransfer
function
Thecutoff frequencyis theedgeof thepassband, at which themagnitude
responseof thefilter is - Rp dB. For el l i p, thecutoff frequency Wn must be
greater than 0.
x n 1 + [ ] Ax n [ ] Bu n [ ] + =
y n [ ] Cx n [ ] Du n [ ] + =
H s ( )
B s ( )
A s ( )
---------- -
b 1 ( )s
n
b 2 ( )s
n 1
L b n 1 + ( ) + + +
s
n
a 2 ( )s
n 1
L a n 1 + ( ) + + +
------------------------------------------------------------------------------------- = =
ellip
7-138
I f Wn is a two-element vector with w1 <w2, then el l i p( n, Rp, Rs, Wn, ' s' )
returns an order 2*n bandpass analogfilter with passband w1 < <w2.
[ b, a] =el l i p( n, Rp, Rs, Wn, ' f t ype' , ' s' ) designs a highpass or bandstop
filter.
With different numbers of output arguments, el l i p directly obtains other
realizationsof theanalogfilter. Toobtainzero-pole-gainform, usethreeoutput
arguments as shown below.
[ z, p, k] =el l i p( n, Rp, Rs, Wn, ' s' ) or
[ z, p, k] =el l i p( n, Rp, Rs, Wn, ' f t ype' , ' s' ) returns thezeros and poles in
length n or 2*n column vectors z and p and thegain in thescalar k.
Toobtain state-spaceform, usefour output arguments as shown below.
[ A, B, C, D] =el l i p( n, Rp, Rs, Wn, ' s' ) or
[ A, B, C, D] =el l i p( n, Rp, Rs, Wn, ' f t ype' , ' s' ) whereA, B, C, and Dare
and u is theinput, x is thestatevector, and y is theoutput.
Examples Example 1
For datasampledat 1000 Hz, design asixth-order lowpass ellipticfilter with a
cutoff frequency of 300 Hz, 3 dB of ripplein thepassband, and 50 dB of
attenuation in thestopband.
[ b, a] = el l i p( 6, 3, 50, 300/ 500) ;
Thefilters frequency responseis
f r eqz( b, a, 512, 1000)
t i t l e( ' n=6 Lowpass El l i pt i c Fi l t er ' )
x

Ax Bu + =
y Cx Du + =
ellip
7-139
Example 2
Designa20th-order bandpassellipticfilter withapassbandfrom100to200 Hz
and plot its impulseresponse.
n = 10; Rp = 0. 5; Rs = 20;
Wn = [ 100 200] / 500;
[ b, a] = el l i p( n, Rp, Rs, Wn) ;
[ y, t ] = i mpz( b, a, 101) ; st em( t , y)
t i t l e( ' I mpul se Response of n=10 El l i pt i c Fi l t er ' )
0 50 100 150 200 250 300 350 400 450 500
500
400
300
200
100
0
100
Frequency (Hz)
P
h
a
s
e

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

(
d
B
)
n=6 Lowpass Elliptic Filter
ellip
7-140
Limitations For high order filters, thestate-spaceformis themost numerically accurate,
followed by thezero-pole-gain form. Thetransfer function formis theleast
accurate; numerical problems can arisefor filter orders as lowas 15.
Algorithm Thedesign of ellipticfilters is themost difficult andcomputationally intensive
of theButterworth, Chebyshev typeI andI I , andellipticdesigns. el l i p uses a
five-step algorithm:
1 I t finds thelowpass analogprototypepoles, zeros, and gain usingthe
el l i pap function.
2 I t converts thepoles, zeros, and gain intostate-spaceform.
3 I t transforms thelowpass filter toa bandpass, highpass, or bandstop filter
with thedesired cutoff frequencies usinga state-spacetransformation.
4 For digital filter design, el l i p uses bi l i near toconvert theanalogfilter
intoa digital filter through a bilinear transformation with frequency
prewarping. Careful frequency adjustment guarantees that theanalog
filters and thedigital filters will havethesamefrequency response
magnitudeat Wn or w1 and w2.
5 I t converts thestate-spacefilter back totransfer function or zero-pole-gain
form, as required.
0 10 20 30 40 50 60 70 80 90 100
-0.2
-0.15
-0.1
-0.05
0
0.05
0.1
0.15
0.2
Impulse Response of n = 10 Elliptic Filter
ellip
7-141
See Also
bessel f Design a Bessel analogfilter.
but t er Design a Butterworth analogor digital filter.
cheby1 Design a Chebyshev typeI filter (passband ripple).
cheby2 Design a Chebyshev typeI I filter (stopband ripple).
el l i pap Design an elliptic analoglowpass filter prototype.
el l i por d Calculatetheorder for an elliptic filter.
ellipap
7-142
7ellipap
Purpose Elliptic analoglowpass filter prototype.
Syntax [ z, p, k] = el l i pap( n, Rp, Rs)
Description [ z, p, k] =el l i pap( n, Rp, Rs) returns thezeros, poles, and gain of an order n
elliptic analoglowpass filter prototype, with Rp dB of ripplein thepassband,
andastopbandRs dB downfromthepeak valueinthepassband. Thezerosand
poles arereturned in length n column vectors z and p and thegain in scalar k.
I f n is odd, z is length n - 1. Thetransfer function is
Elliptic filters offer steeper rolloff characteristics than Butterworth and
Chebyshev filters, but they areequiripplein both thepassband and the
stopband. Of thefour classical filter types, ellipticfilters usually meet a given
set of filter performancespecifications with thelowest filter order.
el l i p sets thecutoff frequency of theelliptic filter to1 for a normalized
result. Thecutoff frequency is thefrequency at which thepassband ends and
thefilter has a magnituderesponseof 10
-Rp/20
.
Algorithm el l i pap uses thealgorithmoutlined in [1]. I t employs theM-fileel l i pk to
calculatethecompleteelliptic integral of thefirst kind and theM-fileel l i pj
tocalculateJ acobi elliptic functions.
See Also
References [1] Parks, T.W., and C.S. Burrus. Digital Filter Design. NewYork: J ohn Wiley
& Sons, 1987. Chapter 7.
H s ( )
z s ( )
p s ( )
---------- k
s z 1 ( ) ( ) s z 2 ( ) ( )L s z n ( ) ( )
s p 1 ( ) ( ) s p 2 ( ) ( )L s p n ( ) ( )
-------------------------------------------------------------------------------- = =

0
bessel ap Bessel analoglowpass filter prototype.
but t ap Butterworth analoglowpass filter prototype.
cheb1ap Chebyshev typeI analoglowpass filter prototype.
cheb2ap Chebyshev typeI I analoglowpass filter prototype.
el l i p Elliptic (Cauer) filter design.
ellipord
7-143
7ellipord
Purpose Calculatetheminimumorder for elliptic filters.
Syntax [ n, Wn] = el l i por d( Wp, Ws, Rp, Rs)
[ n, Wn] = el l i por d( Wp, Ws, Rp, Rs, ' s' )
Description el l i por d calculates theminimumorder of a digital or analogelliptic filter
required tomeet a set of filter design specifications.
Digital Domain
[ n, Wn] =el l i por d( Wp, Ws, Rp, Rs) returns thelowest order n of theelliptic
filter that loses nomorethan Rp dB in thepassband and has at least Rs dB of
attenuation in thestopband. Thescalar (or vector) of correspondingcutoff
frequencies Wn, is alsoreturned. Usetheoutput arguments n and Wn in el l i p.
Choosetheinput argumentstospecifythestopbandandpassbandaccordingto
thefollowingtable.
Table 7-7: Description of Stopband and Passband Filter Parameters
Wp Passband corner frequency Wp, thecutoff frequency, is a scalar
or a two-element vector with values between 0 and 1, with 1
correspondingtothenormalized Nyquist frequency, radians
per sample.
Ws Stopband corner frequency Ws, is a scalar or a two-element
vector with values between 0 and 1, with 1 correspondingto
thenormalized Nyquist frequency.
Rp Passband ripple, in decibels. Twicethis valuespecifies the
maximumpermissiblepassband width in decibels.
Rs Stopband attenuation, in decibels. This valueis thenumber of
decibels thestopband is attenuated with respect tothe
passband response.
ellipord
7-144
Usethefollowingguidetospecify filters of different types.
I f your filter specifications call for a bandpass or bandstop filter with unequal
ripplein each of thepassbands or stopbands, design separatelowpass and
highpass filters accordingtothespecifications in this table, and cascadethe
twofilters together.
Analog Domain
[ n, Wn] =el l i por d( Wp, Ws, Rp, Rs, ' s' ) finds theminimumorder n and cutoff
frequencies Wn for an analogfilter. You specify thefrequencies Wp and Ws
similar toTable7-7, Description of StopbandandPassbandFilter Parameters,
only in this caseyou specify thefrequency in radians per second, and the
passband or thestopband can beinfinite.
Useel l i por d for lowpass, highpass, bandpass, and bandstop filters as
described in Table7-8, Filter TypeStopband and Passband Specifications.
Table 7-8: Filter Type Stopband and Passband Specifications
Filter Type Stopband and Passband Conditions Stopband Passband
Lowpass Wp <Ws, both scalars ( Ws, 1) ( 0, Wp)
Highpass Wp >Ws, both scalars ( 0, Ws) ( Wp, 1)
Bandpass Theinterval specified by Ws contains
theonespecified by Wp
(Ws( 1) < Wp( 1) < Wp( 2) < Ws( 2) ).
( 0, Ws( 1) )
and
( Ws( 2) , 1)
( Wp( 1) , Wp( 2) )
Bandstop Theinterval specified by Wp contains
theonespecified by Ws
(Wp( 1) < Ws( 1) < Ws( 2) < Wp( 2) ).
( 0, Wp( 1) )
and
( Wp( 2) , 1)
( Ws( 1) , Ws( 2) )
ellipord
7-145
Examples Example 1
For 1000 Hz data, design a lowpass filter with less than 3 dB of ripplein the
passband defined from0 to40 Hz and at least 60 dB of ripplein thestopband
defined from150 Hz totheNyquist frequency (500 Hz).
Wp = 40/ 500; Ws = 150/ 500;
Rp = 3; Rs = 60;
[ n, Wn] = el l i por d( Wp, Ws, Rp, Rs)
n =
4
Wn =
0. 0800
[ b, a] = el l i p( n, Rp, Rs, Wn) ;
f r eqz( b, a, 512, 1000) ;
t i t l e( ' n=4 El l i pt i c Lowpass Fi l t er ' )
0 50 100 150 200 250 300 350 400 450 500
400
300
200
100
0
100
Frequency (Hz)
P
h
a
s
e

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

(
d
B
)
n=4 Elliptic Lowpass Filter
ellipord
7-146
Example 2
Nowdesign a bandpass filter with a passband from60 Hz to200 Hz, with less
than 3 dB of ripplein thepassband, and 40 dB attenuation in thestopbands
that are50 Hz wideon both sides of thepassband.
Wp = [ 60 200] / 500; Ws = [ 50 250] / 500;
Rp = 3; Rs = 40;
[ n, Wn] = el l i por d( Wp, Ws, Rp, Rs)
n =
5
Wn =
0. 1200 0. 4000
[ b, a] = el l i p( n, Rp, Rs, Wn) ;
f r eqz( b, a, 512, 1000) ;
t i t l e( ' n=5 El l i pt i c Bandpass Fi l t er ' )
0 50 100 150 200 250 300 350 400 450 500
500
0
500
Frequency (Hz)
P
h
a
s
e

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

(
d
B
)
n=5 Elliptic Bandpass Filter
ellipord
7-147
Algorithm el l i por d uses theelliptic lowpass filter order prediction formula described
in [1]. Thefunction performs its calculations in theanalogdomain for both the
analogand digital cases. For thedigital case, it converts thefrequency
parameters tothes-domain beforeestimatingtheorder and natural
frequencies, and then converts themback tothez-domain.
el l i por d initially develops a lowpass filter prototypeby transformingthe
passband frequencies of thedesired filter to1 rad/s (for low- and highpass
filters) and to-1 and 1 rad/s (for bandpass and bandstop filters). I t then
computestheminimumorder requiredfor alowpassfilter tomeet thestopband
specification.
See Also
References [1] Rabiner, L.R., and B. Gold. Theory and Application of Digital Signal
Processing. Englewood Cliffs, NJ : Prentice-Hall, 1975. Pg. 241.
but t or d Calculatetheorder for a Butterworth filter.
cheb1or d Calculatetheorder for a Chebyshev typeI filter.
cheb2or d Calculatetheorder for a Chebyshev typeI I filter.
el l i p Design an elliptic (Cauer) filter.
eqtflength
7-148
7eqtflength
Purpose Makethelengths of a transfer functions numerator and denominator equal.
Syntax [ b, a] = eqt f l engt h( num, den)
Description [ b, a] = eqt f l engt h( num, den) modifies thevector numand/or thevector den,
sothat theresultingoutput vectors b and a havethesamelength. Theinput
vectors numandden may havedifferent lengths. Thevector numrepresents the
numerator polynomial of agivendiscrete-timetransfer function, andthevector
den represents its numerator. Theresultingnumerator b and denominator a
represent thesamediscrete-timetransfer function, but thesevectors havethe
samelength.
Useeqt f l engt h toobtain anumerator anddenominator of equal length before
applyingtransfer function conversion functions such as t f 2ss and t f 2zp to
discrete-timemodels.
Examples num= [ 1 0. 5] ;
den = [ 1 0. 75 0. 6 0] ;
[ b, a] = eqt f l engt h( num, den)
b =
1. 0000 0. 5000 0
a =
1. 0000 0. 7500 0. 6000
Algorithm eqt f l engt h( num, den) appends zeros toeither numor den as necessary. I f both
numand den havetrailingzeros in common, theseareremoved.
See Also
t f 2ss Convert a transfer function tostate-spaceform.
t f 2zp Convert a transfer function tozero-pole-gain form.
fdatool
7-149
7fdatool
Purpose Open theFilter Design and Analysis Tool.
Syntax f dat ool
Description f dat ool opens theFilter Design andAnalysis Tool (FDATool). Usethis tool to:
Design filters
Analyzefilters
Modify existingfilter designs
SeeChapter 5, Filter Design and Analysis Tool,for moreinformation.
fdatool
7-150
Remarks TheFilter Design and Analysis Tool provides moredesign methods than the
SPTool Filter Designer.
See Also spt ool Open thesignal processingGUI .
fft
7-151
7fft
Purpose Computetheone-dimensional fast Fourier transform.
Syntax y = f f t ( x)
y = f f t ( x, n)
Description f f t computes thediscreteFourier transformof a vector or matrix. This
function implements thetransformgiven by
whereW
N
=e
-j(2/N)
and N = l engt h( x) . Notethat theseries is indexed as
n +1andk +1insteadof theusual n andk becauseMATLAB vectors run from
1 toN instead of from0 toN-1.
y = f f t ( x) is thediscreteFourier transformof vector x, computedwith a fast
Fourier transform(FFT) algorithm. I f x isamatrix, y istheFFT of eachcolumn
of thematrix.
y = f f t ( x, n) is then-point FFT. I f thelength of x is less than n, f f t pads x
withtrailingzeros tolength n. I f thelengthof x isgreater than n, f f t truncates
thesequencex. I f x is an array, f f t adjusts thelength of thecolumns in the
samemanner.
Thef f t function is part of thestandard MATLAB language.
Examples A common useof theFourier transformis tofind thefrequency components of
atime-domain signal buriedin noise. Consider datasampledat 1000 Hz. Form
a signal consistingof 50 Hz and 120 Hz sinusoids and corrupt thesignal with
zero-mean randomnoise.
r andn( ' st at e' , 0)
t = 0: 0. 001: 0. 6;
x = si n( 2*pi *50*t ) + si n( 2*pi *120*t ) ;
y = x + 2*r andn( 1, l engt h( t ) ) ;
pl ot ( y( 1: 50) )
X k 1 + ( ) x n 1 + ( )W
n
kn
n 0 =
N 1

=
fft
7-152
I t is difficult toidentify thefrequency components by studyingtheoriginal
signal. Convert tothefrequency domain by takingthediscreteFourier
transformof thenoisy signal y usinga 512-point fast Fourier transform(FFT).
Y = f f t ( y, 512) ;
Thepower spectral density, a measurement of theenergy at various
frequencies, is
Pyy = Y. *conj ( Y) / 512;
Graph thefirst 256 points (theother 256 points aresymmetric) on a
meaningful frequency axis.
f = 1000*( 0: 255) / 512;
pl ot ( f , Pyy( 1: 256) )
0 5 10 15 20 25 30 35 40 45 50
5
4
3
2
1
0
1
2
3
4
5
fft
7-153
Seethepwel ch function for details on estimatingthespectral density.
Sometimes it is useful tonormalizetheoutput of f f t sothat aunit sinusoid in
thetimedomain corresponds tounit amplitudein thefrequency domain. To
producea normalized discrete-timeFourier transformin this manner, use
Pn = abs( f f t ( x) ) *2/ l engt h( x)
Algorithm f f t isabuilt-in MATLAB function. Seethef f t referencepagein theMATLAB
documentation for details about thealgorithm.
See Also
0 100 200 300 400 500
0
10
20
30
40
50
60
70
dct I mplement thediscretecosinetransform(DCT).
df t mt x ComputethediscreteFourier transformmatrix.
f f t 2 Computethetwo-dimensional fast Fourier
transform.
f f t shi f t Rearrangetheoutputs of f f t and f f t 2.
f i l t er Filter data.
f r eqz Computethefrequency responseof digital filters.
i f f t Computetheone-dimensional inversefast Fourier
transform.
pwel ch Estimatethepower spectral density (PSD) of asignal
usingWelchs method.
fft2
7-154
7fft2
Purpose Computethetwo-dimensional fast Fourier transform.
Syntax Y = f f t 2( X)
Y = f f t 2( X, m, n)
Description Y = f f t 2( X) performs a two-dimensional FFT, producinga result Y with the
samesizeas X. I f X is a vector, Y has thesameorientation as X.
Y = f f t 2( X, m, n) truncates or zeropads X, if necessary, tocreatean m-by-n
array beforeperformingtheFFT. Theresult Y is alsom-by-n.
Thef f t 2 function is part of thestandard MATLAB language.
Algorithm f f t 2( x) is simply
f f t ( f f t ( x) . ' ) . '
This computes theone-dimensional f f t of each column of x, then of each row
of theresult. Thetimerequiredtocomputef f t 2( x) depends on thenumber of
primefactors in [ m, n] =si ze( x) . f f t 2 is fastest when mand n arepowers of 2.
See Also
f f t One-dimensional fast Fourier transform.
f f t shi f t Rearrangetheoutputs of f f t and f f t 2.
i f f t One-dimensional inversefast Fourier transform.
i f f t 2 Two-dimensional inversefast Fourier transform.
fftfilt
7-155
7fftfilt
Purpose FFT-based FI R filteringusingtheoverlap-add method.
Syntax y = f f t f i l t ( b, x)
y = f f t f i l t ( b, x, n)
Description f f t f i l t filters data usingtheefficient FFT-based method of overlap-add, a
frequency domain filteringtechniquethat works only for FI R filters.
y = f f t f i l t ( b, x) filters thedata in vector x with thefilter described by
coefficient vector b. I t returns thedata vector y. Theoperation performed by
f f t f i l t is described in thetimedomain by thedifferenceequation
Anequivalent representationisthez-transformor frequencydomaindescription
By default, f f t f i l t chooses an FFT length and data block length that
guaranteeefficient execution time.
y = f f t f i l t ( b, x, n) uses an FFT length of nf f t =2^next pow2( n) and a data
block length of nf f t - l engt h( b) +1.
f f t f i l t works for both real and complex inputs.
Examples Showthat theresults fromf f t f i l t and f i l t er areidentical.
b = [ 1 2 3 4] ;
x = [ 1 zer os( 1, 99) ] ' ;
nor m( f f t f i l t ( b, x) - f i l t er ( b, 1, x) )
ans =
9. 5914e- 15
Algorithm f f t f i l t uses f f t toimplement theoverlap-add method [1], a techniquethat
combines successivefrequency domain filtered blocks of an input sequence.
f f t f i l t breaks an input sequencex intolength L data blocks
y n ( ) b 1 ( )x n ( ) b 2 ( )x n 1 ( ) L b nb 1 + ( )x n nb ( ) + + + =
Y z ( ) b 1 ( ) b 2 ( )z
1
L b nb 1 + ( )z
nb
+ + + ( )X z ( ) =
x
L 2L 3L ceil(nx/L)*L
. . .
fftfilt
7-156
and convolves each block with thefilter b by
y = i f f t ( f f t ( x( i : i +L- 1) , nf f t ) . *f f t ( b, nf f t ) ) ;
wherenf f t is theFFT length. f f t f i l t overlaps successiveoutput sections by
nb- 1 points, wherenb is thelength of thefilter, and sums them.
f f t f i l t chooses thekey parameters L and nf f t in different ways, depending
on whether you supply an FFT length n and on thelengths of thefilter and
signal. I f you donot specify a valuefor n (which determines FFT length),
f f t f i l t chooses thesekey parameters automatically:
I f l engt h( x) is greater than l engt h( b) , f f t f i l t chooses values that
minimizethenumber of blocks times thenumber of flops per FFT.
I f l engt h( b) is greater than or equal tol engt h( x) , f f t f i l t uses a single
FFT of length
2^next pow2( l engt h( b) + l engt h( x) - 1)
This essentially computes
y = i f f t ( f f t ( B, nf f t ) . *f f t ( X, nf f t ) )
I f you supply a valuefor n, f f t f i l t chooses an FFT length, nf f t , of
2^next pow2( n) andadatablock length of nf f t - l engt h( b) +1. I f n is less than
l engt h( b) , f f t f i l t sets n tol engt h( b) .
See Also
References [1] Oppenheim, A.V., and R.W. Schafer, Discrete-TimeSignal Processing,
Prentice-Hall, 1989.
nb1
L
nb1 2L
nb1 3L
. . .
conv Convolution and polynomial multiplication.
f i l t er Filter data with a recursive(I I R) or nonrecursive
(FI R) filter.
f i l t f i l t Zero-phasedigital filtering.
fftshift
7-157
7fftshift
Purpose Rearrangetheoutputs of theFFT functions.
Syntax y = f f t shi f t ( x)
Description y = f f t shi f t ( x) rearranges theoutputs of f f t and f f t 2 by movingthezero
frequency component tothecenter of thespectral density, which is sometimes
a moreconvenient form.
For vectors, f f t shi f t ( x) returns a vector with theleft and right halves
swapped.
For arrays, f f t shi f t ( x) swaps quadrants oneand threewith quadrants two
and four.
Thef f t shi f t function is part of thestandard MATLAB language.
Examples For any array X
Y = f f t 2( x)
hasY( 1, 1) = sum( sum( X) ) ; theDC component of thesignal isintheupper-left
corner of thetwo-dimensional FFT. For
Z = f f t shi f t ( Y)
theDC component is near thecenter of thematrix.
See Also
f f t One-dimensional fast Fourier transform.
f f t 2 Two-dimensional fast Fourier transform.
filter
7-158
7filter
Purpose Filter data with a recursive(I I R) or nonrecursive(FI R) filter.
Syntax y = f i l t er ( b, a, x)
[ y, zf ] = f i l t er ( b, a, x)
[ . . . ] = f i l t er ( b, a, x, zi )
[ . . . ] = f i l t er ( b, a, x, zi , di m)
Description y = f i l t er ( b, a, x) filters thedata in vector x with thefilter described by
coefficient vectors a and b tocreatethefiltered data vector y. When x is a
matrix, filter operates on thecolumns of x. When x is an N-dimensional array,
filter operates on thefirst nonsingleton dimension. a( 1) cannot be0, and if
a( 1) 1, f i l t er normalizes thefilter coefficients by a( 1) .
[ y, zf ] = f i l t er ( b, a, x) returns thefinal values zf of thestatevector. When
x is a vector, thesizeof thefinal condition vector zf is
max( l engt h( b) , l engt h( a) ) - 1, thenumber of delays in thefilter. When x is a
multidimensional array, zf is an s-by-c matrix, where:
s is thenumber of delays in thefilter.
cispr od( si ze( x) ) / si ze( x, di m) , wheredi misthedimensionintowhichyou
arefiltering(thefirst nonsingleton dimension by default).
[ . . . ] = f i l t er ( b, a, x, zi ) specifies initial stateconditions in thevector zi .
Thesizeof theinitial condition vector zi must bethesameas
max( l engt h( b) , l engt h( a) ) - 1, thenumber of delays in thefilter.
[ . . . ] = f i l t er ( b, a, x, zi , di m) filters theinput data located alongthe
dimension di mof x. Set zi totheempty vector [ ] tousezeroinitial conditions.
Thef i l t er function is part of thestandard MATLAB language.
filter
7-159
Examples Find and graph the101-point unit impulseresponseof a digital filter.
x = [ 1 zer os( 1, 100) ] ;
[ b, a] = but t er ( 12, 400/ 1000) ;
y = f i l t er ( b, a, x) ;
st em( y)
Algorithm f i l t er is implemented as a transposed direct formI I structure[1], as shown
below
wheren-1 is thefilter order. Thestatevector z is a vector whosecomponents
arederived fromthevalues of theinputs toeach delay in thefilter.
0 20 40 60 80 100 120
-0.2
-0.1
0
0.1
0.2
0.3
0.4
z
-1
z
-1
x(m)
y(m)
b( 3) b( 2) b(1)
a( 3) a( 2)
z
1
(m) z
2
(m)
z
-1
b(n)
a(n)
z
n-1
(m)
...
...
...
filter
7-160
Theoperation of f i l t er at samplemis implemented usingthetransposed
direct formI I structure. This is calculated by thetimedomain difference
equations for y and thestates z
i
.
Notethedivision by a(1). For efficient computation, select this coefficient tobe
a power of 2.
You can usef i l t i c togeneratethestatevector z
i
(0) frompast inputs and
outputs.
Theinput-output description of this filteringoperation in thez-transform
domain is a rational transfer function.
See Also
References [1] Oppenheim, A.V., and R.W. Schafer, Discrete-TimeSignal Processing,
Prentice-Hall, 1989, pp. 311-312.
y m ( )
b 1 ( )x m ( ) z
1
m 1 ( ) + ( )
a 1 ( )
---------------------------------------------------------- =
z
1
m ( ) b 2 ( )x m ( ) z
2
m 1 ( ) a 2 ( )y m ( ) + =
=
z
n 2
m ( ) b n 1 ( )x m ( ) z
n 1
m 1 ( ) a n 1 ( )y m ( ) + =
z
n 1
m ( ) b n ( )x m ( ) a n ( )y m ( ) =
Y z ( )
b 1 ( ) b 2 ( )z
1
L b nb 1 + ( )z
nb
+ + +
a 1 ( ) a 2 ( )z
1
L a na 1 + ( )z
na
+ + +
--------------------------------------------------------------------------------------------X z ( ) =
f f t f i l t FFT-based FI R filteringusingtheoverlap-add
method.
f i l t er 2 Two-dimensional digital filtering.
f i l t f i l t Zero-phasedigital filtering.
f i l t i c Makeinitial conditions for f i l t er function.
filter2
7-161
7filter2
Purpose Two-dimensional digital filtering.
Syntax Y = f i l t er 2( B, X)
Y = f i l t er 2( B, X, ' shape' )
Description Y = f i l t er 2( B, X) filters thetwo-dimensional data in X with the
two-dimensional FI R filter in thematrix B. Theresult, Y, is computed using
two-dimensional convolution and is thesamesizeas X.
Y = f i l t er 2( B, X, ' shape' ) returns Y computed with sizespecified by
' shape' :
' same' returns thecentral part of theconvolution that is thesamesizeas X
(default).
' f ul l ' returns thefull two-dimensional convolution, when si ze( Y) exceeds
si ze( X) .
' val i d' returns only thoseparts of theconvolution that arecomputed
without thezero-padded edges, when si ze( Y) is less than si ze( X) .
Thef i l t er 2 function is part of thestandard MATLAB language.
Algorithm Thef i l t er 2 function uses conv2 tocomputethefull two-dimensional
convolution of theFI R filter with theinput matrix. By default, f i l t er 2
extractsandreturnsthecentral part of theconvolution that is thesamesizeas
theinput matrix. Usethe' shape' parameter tospecifyanalternatepart of the
convolution for return.
See Also
conv2 Two-dimensional convolution.
f i l t er Filter data with a recursive(I I R) or nonrecursive
(FI R) filter.
filtfilt
7-162
7filtfilt
Purpose Zero-phasedigital filtering.
Syntax y = f i l t f i l t ( b, a, x)
Description y = f i l t f i l t ( b, a, x) performs zero-phasedigital filteringby processingthe
input datain both theforwardandreversedirections (seeproblem5.39in [1]).
After filteringin theforward direction, it reverses thefiltered sequenceand
runsit back throughthefilter. Theresultingsequencehaspreciselyzero-phase
distortion anddoublethefilter order. f i l t f i l t minimizes start-upandending
transients by matchinginitial conditions, andworks for both real andcomplex
inputs.
Notethat f i l t f i l t should not beused with differentiator and Hilbert FI R
filters, sincetheoperation of thesefilters depends heavily on their phase
response.
Algorithm f i l t f i l t is an M-filethat uses thef i l t er function. I n addition tothe
forward-reversefiltering, it attempts tominimizestartup transients by
adjustinginitial conditions tomatch theDC component of thesignal and by
prependingseveral filter lengths of a flipped, reflectedcopy of theinput signal.
See Also
References [1] Oppenheim, A.V., and R.W. Schafer, Discrete-TimeSignal Processing,
Prentice-Hall, 1989, pp. 311-312.
f f t f i l t FFT-based FI R filteringusingtheoverlap-add
method.
f i l t er Filter data with a recursive(I I R) or nonrecursive
(FI R) filter.
f i l t er 2 Two-dimensional digital filtering.
filtic
7-163
7filtic
Purpose Find initial conditions for a transposed direct formI I filter implementation.
Syntax z = f i l t i c( b, a, y, x)
z = f i l t i c( b, a, y)
Description z = f i l t i c( b, a, y, x) finds theinitial conditions, z, for thedelays in the
transposed direct formI I filter implementation given past outputs y and
inputs x. Thevectors b and a represent thenumerator and denominator
coefficients, respectively, of thefilters transfer function.
Thevectors x and y contain themost recent input or output first, and oldest
input or output last.
wherenb is l engt h( b) - 1 (thenumerator order) and na is l engt h( a) - 1 (the
denominator order). I f l engt h( x) is less than nb, f i l t i c pads it with zeros to
length nb; if l engt h( y) is less than na, f i l t i c pads it with zeros tolength na.
Elements of x beyond x( nb- 1) and elements of y beyond y( na- 1) are
unnecessary sof i l t i c ignores them.
Output z is a column vector of length equal tothelarger of nb and na.
z describes thestateof thedelays given past inputs x and past outputs y.
z = f i l t i c( b, a, y) assumes that theinput x is 0 in thepast.
Thetransposed direct formI I structureis
wheren-1 is thefilter order.
f i l t i c works for both real and complex inputs.
x x 1 ( ) x 2 ( ) x 3 ( ) x nb ( ) , , , , , { } =
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
7-164
Algorithm f i l t i c performs a reversedifferenceequation toobtain thedelay states z.
Diagnostics I f any of theinput arguments y, x, b, or a is not a vector (that is, if any
argument is a scalar or array), f i l t i c gives thefollowingerror message.
Requi r es vect or i nput s.
See Also
References [1] Oppenheim, A.V., and R.W. Schafer, Discrete-TimeSignal Processing,
Prentice-Hall, 1989, pp. 296, 301-302.
f i l t er Filter data with a recursive(I I R) or nonrecursive
(FI R) filter.
f i l t f i l t Zero-phasedigital filtering.
fir1
7-165
7fir1
Purpose Design a window-based finiteimpulseresponsefilter.
Syntax b = f i r 1( n, Wn)
b = f i r 1( n, Wn, ' f t ype' )
b = f i r 1( n, Wn, wi ndow)
b = f i r 1( n, Wn, ' f t ype' , wi ndow)
b = f i r 1( . . . , ' nor mal i zat i on' )
Description f i r 1 implements theclassical method of windowed linear-phaseFI R digital
filter design[1]. I t designsfiltersinstandardlowpass, bandpass, highpass, and
bandpass configurations. By default thefilter is normalized sothat the
magnituderesponseof thefilter at thecenter frequency of thepassband is
0 dB.
Note Usef i r 2 for windowed filters with arbitrary frequency response.
b = f i r 1( n, Wn) returns rowvector b containingthen+1 coefficients of an
order n lowpass FI R filter. This is a Hamming-windowbased, linear-phase
filter with normalized cutoff frequency Wn. Theoutput filter coefficients, b, are
ordered in descendingpowers of z.
Wn is anumber between 0and1, where1corresponds totheNyquist frequency.
I f Wn is atwo-element vector, Wn =[ w1 w2] , f i r 1 returnsabandpassfilter with
passband w1 < <w2.
I f Wn is a multi-element vector, Wn =[ w1 w2 w3 w4 w5 . . . wn] , f i r 1 returns
an order n multiband filter with bands 0 < <w1, w1 < <w2, ..., wn < <1.
By default, thefilter is scaled sothat thecenter of thefirst passband has a
magnitudeof exactly 1 after windowing.
B z ( ) b 1 ( ) b 2 ( )z
1
L b n 1 + ( )z
n
+ + + =
fir1
7-166
b = f i r 1( n, Wn, ' f t ype' ) specifies a filter type, where' f t ype' is:
' hi gh' for a highpass filter with cutoff frequency Wn.
' st op' for a bandstop filter, if Wn =[ w1 w2] . Thestopband frequency range
is specified by this interval.
' DC- 1' tomakethefirst band of a multiband filter a passband.
' DC- 0' tomakethefirst band of a multiband filter a stopband.
f i r 1 always uses an even filter order for thehighpass and bandstop
configurations. This is becausefor odd orders, thefrequency responseat the
Nyquist frequency is 0, which is inappropriatefor highpass and bandstop
filters. I f you specify an odd-valued n, f i r 1 increments it by 1.
b = f i r 1( n, Wn, wi ndow) uses thewindowspecified in column vector wi ndow
for thedesign. Thevector wi ndowmust ben+1 elements long. I f nowindowis
specified, f i r 1 uses a Hammingwindow(seehammi ng) of length n+1.
b = f i r 1( n, Wn, ' f t ype' , wi ndow) accepts both ' f t ype' and wi ndow
parameters.
b = f i r 1( . . . , ' nor mal i zat i on' ) specifies whether or not thefilter
magnitudeis normalized. Thestring' nor mal i zat i on' can be:
' scal e' (default): Normalizethefilter sothat themagnituderesponseof the
filter at thecenter frequency of thepassband is 0 dB.
' noscal e' : Donot normalizethefilter.
Thegroup delay of theFI R filter designed by f i r 1 is n/ 2.
Algorithm f i r 1usesthewindowmethodof FI R filter design[1]. I f w(n) denotesawindow,
where1 n N, and theimpulseresponseof theideal filter is h(n), where
h(n) is theinverseFourier transformof theideal frequency response, then the
windowed digital filter coefficients aregiven by
b n ( ) w n ( )h n ( ) 1 n N , =
fir1
7-167
Examples Example 1
Design a 48th-order FI R bandpass filter with passband 0.35 w 0.65.
b = f i r 1( 48, [ 0. 35 0. 65] ) ;
f r eqz( b, 1, 512)
Example 2
Thechi r p. mat filecontains a signal, y, that has most of its power abovef s/ 4,
or half theNyquist frequency. Design a 34th-order FI R highpass filter to
attenuatethecomponents of thesignal belowf s/ 4. Usea cutoff frequency
of 0.48 and a Chebyshev windowwith 30 dB of ripple.
l oad chi r p %Load y and f s.
b = f i r 1( 34, 0. 48, ' hi gh' , chebwi n( 35, 30) ) ;
f r eqz( b, 1, 512)
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
2500
2000
1500
1000
500
0
Normalized Frequency ( rad/sample)
P
h
a
s
e

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

(
d
B
)
fir1
7-168
See Also
References [1] Programs for Digital Signal Processing, I EEE Press, NewYork, 1979.
Algorithm5.2.
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
2000
1500
1000
500
0
500
Normalized Frequency ( rad/sample)
P
h
a
s
e

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

(
d
B
)
f i l t er Filter data with a recursive(I I R) or nonrecursive
(FI R) filter.
f i r 2 Window-based finiteimpulseresponsefilter
design arbitrary response.
f i r cl s Constrained least squareFI R filter design for
multiband filters.
f i r cl s1 Constrained least squarefilter design for lowpass
and highpass linear phaseFI R filters.
f i r l s Least squarelinear-phaseFI R filter design.
f r eqz Frequency responseof digital filters.
kai ser or d Estimateparameters for f i r 1 with a Kaiser window.
r emez Parks-McClellan optimal FI R filter design.
fir2
7-169
7fir2
Purpose Design a frequency sampling-based finiteimpulseresponsefilter.
Syntax b = f i r 2( n, f , m)
b = f i r 2( n, f , m, wi ndow)
b = f i r 2( n, f , m, npt )
b = f i r 2( n, f , m, npt , wi ndow)
b = f i r 2( n, f , m, npt , l ap)
b = f i r 2( n, f , m, npt , l ap, wi ndow)
Description f i r 2 designs frequency sampling-based digital FI R filters with arbitrarily
shaped frequency response.
Note Usef i r 1 for windows-based standard lowpass, bandpass, highpass,
and bandstop configurations.
b = f i r 2( n, f , m) returns rowvector b containingthen+1 coefficients of an
order n FI R filter. Thefrequency-magnitudecharacteristics of this filter match
thosegiven by vectors f and m:
f isavector of frequencypointsintherangefrom0to1, where1corresponds
totheNyquist frequency. Thefirst point of f must be0 and thelast point 1.
Thefrequency points must bein increasingorder.
mis a vector containingthedesired magnituderesponseat thepoints
specified in f .
f and mmust bethesamelength.
Duplicatefrequency points areallowed, correspondingtosteps in the
frequency response.
Usepl ot ( f , m) toviewthefilter shape.
Theoutput filter coefficients, b, areordered in descendingpowers of z.
f i r 2 always uses an even filter order for configurations with apassbandat the
Nyquist frequency. This is becausefor odd orders, thefrequency responseat
b z ( ) b 1 ( ) b 2 ( )z
1
L b n 1 + ( )z
n
+ + + =
fir2
7-170
theNyquist frequency is necessarily 0. I f you specify an odd-valued n, f i r 2
increments it by 1.
b = f i r 2( n, f , m, wi ndow) uses thewindowspecified in thecolumn vector
wi ndow. Thevector wi ndowmust ben+1elementslong. I f nowindowisspecified,
f i r 2 uses a Hammingwindow(seehammi ng) of length n+1.
b = f i r 2( n, f , m, npt ) or
b = f i r 2( n, f , m, npt , wi ndow) specifies thenumber of points, npt , for thegrid
ontowhich f i r 2 interpolates thefrequencyresponse, without or with awi ndow
specification.
b = f i r 2( n, f , m, npt , l ap) and
b = f i r 2( n, f , m, npt , l ap, wi ndow) specify thesizeof theregion, l ap, that
f i r 2 inserts around duplicatefrequency points, with or without a wi ndow
specification.
SeetheAlgorithm section for moreon npt and l ap.
Algorithm Thedesiredfrequencyresponseisinterpolatedontoadense, evenlyspacedgrid
of length npt . npt is 512by default. I f twosuccessivevalues of f arethesame,
a region of l ap points is set up around this frequency toprovidea smooth but
steeptransition in therequestedfrequencyresponse. Bydefault, l ap is 25. The
filter coefficients areobtainedby applyingan inversefast Fourier transformto
thegrid and multiplyingby a window; by default, this is a Hammingwindow.
Examples Design a30th-order lowpass filter andoverplot thedesiredfrequencyresponse
with theactual frequency response.
f = [ 0 0. 6 0. 6 1] ; m= [ 1 1 0 0] ;
b = f i r 2( 30, f , m) ;
[ h, w] = f r eqz( b, 1, 128) ;
pl ot ( f , m, w/ pi , abs( h) )
l egend( ' I deal ' , ' f i r 2 Desi gned' )
t i t l e( ' Compar i son of Fr equency Response Magni t udes' )
fir2
7-171
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
1.4
Comparison of Frequency Response Magnitudes
Ideal
fir2 Designed
but t er Butterworth analogand digital filter design.
cheby1 Chebyshev typeI filter design (passband ripple).
cheby2 Chebyshev typeI I filter design (stopband ripple).
el l i p Elliptic (Cauer) filter design.
f i r 1 Window-based finiteimpulseresponsefilter design
standard response.
maxf l at Generalized digital Butterworth filter design.
r emez Parks-McClellan optimal FI R filter design.
yul ewal k Recursivedigital filter design.
fircls
7-172
7fircls
Purpose Constrained least squareFI R filter design for multiband filters.
Syntax b = f i r cl s( n, f , amp, up, l o)
f i r cl s( n, f , amp, up, l o, ' desi gn_f l ag' )
Description b = f i r cl s( n, f , amp, up, l o) generates alength n+1 linear phaseFI R filter b.
Thefrequency-magnitudecharacteristics of this filter match thosegiven by
vectors f and amp:
f is a vector of transition frequencies in therangefrom0 to1, where1
corresponds totheNyquist frequency. Thefirst point of f must be0 and the
last point 1. Thefrequency points must bein increasingorder.
amp is a vector describingthepiecewiseconstant desired amplitudeof the
frequencyresponse. Thelength of amp is equal tothenumber of bands in the
responseand should beequal tol engt h( f ) - 1.
up andl o arevectorswiththesamelength asamp. Theydefinetheupper and
lower bounds for thefrequency responsein each band.
f i r cl s always uses an even filter order for configurations with a passband at
theNyquist frequency. This is becausefor odd orders, thefrequency response
at theNyquist frequency is necessarily 0. I f you specify an odd-valued n,
f i r cl s increments it by 1.
f i r cl s( n, f , amp, up, l o, ' desi gn_f l ag' ) enables you tomonitor thefilter
design, where' desi gn_f l ag' can be:
' t r ace' , for a textual display of thedesign error at each iteration step.
' pl ot s' , for a collection of plots showingthefilters full-band magnitude
responseandazoomedviewof themagnituderesponsein eachsub-band. All
plots areupdated at each iteration step.
' bot h' , for both thetextual display and plots.
fircls
7-173
Examples Design an order 50 bandpass filter.
n = 50;
f = [ 0 0. 4 0. 8 1] ;
amp = [ 0 1 0] ;
up = [ 0. 02 1. 02 0. 01] ;
l o = [ - 0. 02 0. 98 - 0. 01] ;
b = f i r cl s( n, f , amp, up, l o, ' pl ot s' ) ; %Pl ot magni t ude r esponse
Note Normally, thelower valuein thestopband will bespecified as negative.
By settingl o equal to0 in thestopbands, a nonnegativefrequency response
amplitudecan beobtained. Such filters can bespectrally factored toobtain
minimumphasefilters.
Algorithm Thealgorithmis a multipleexchangealgorithmthat uses Lagrange
multipliers and Kuhn-Tucker conditions on each iteration.
0 0.2 0.4 0.6 0.8 1 1.2 1.4
-2
0
2
0 0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4
-0.02
0
0.02
B
a
n
d

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

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

#
3
Frequency
fircls
7-174
See Also
References [1] Selesnick, I .W., M. Lang, and C.S. Burrus, Constrained Least Square
Design of FI R Filters without Specified Transition Bands, Proceedings of the
I EEE I nt. Conf. Acoust., Speech, Signal Processing, Vol. 2 (May 1995),
pp. 1260-1263.
[2] Selesnick, I .W., M. Lang, and C.S. Burrus. Constrained Least Square
Design of FI R Filters without SpecifiedTransition Bands.I EEE Transactions
on Signal Processing, Vol. 44, No. 8 (August 1996).
f i r cl s1 Constrained least squarefilter design for lowpass
and highpass linear phaseFI R filters.
f i r l s Least squarelinear-phaseFI R filter design.
r emez Parks-McClellan optimal FI R filter design.
fircls1
7-175
7fircls1
Purpose Constrained least squarefilter design for lowpass and highpass linear phase
FI R filters.
Syntax b = f i r cl s1( n, wo, dp, ds)
b = f i r cl s1( n, wo, dp, ds, ' hi gh' )
b = f i r cl s1( n, wo, dp, ds, wt )
b = f i r cl s1( n, wo, dp, ds, wt , ' hi gh' )
b = f i r cl s1( n, wo, dp, ds, wp, ws, k)
b = f i r cl s1( n, wo, dp, ds, wp, ws, k, ' hi gh' )
b = f i r cl s1( n, wo, dp, ds, . . . , ' desi gn_f l ag' )
Description b = f i r cl s1( n, wo, dp, ds) generates a lowpass FI R filter b, wheren+1 is the
filter length, wo isthenormalizedcutoff frequencyintherangebetween0and 1
(where1corresponds totheNyquist frequency), dp is themaximumpassband
deviation from1(passbandripple), andds is themaximumstopbanddeviation
from0 (stopband ripple).
b = f i r cl s1( n, wo, dp, ds, ' hi gh' ) generatesahighpassFI R filter b. f i r cl s1
always uses an even filter order for thehighpass configuration. This is because
for odd orders, thefrequency responseat theNyquist frequency is
necessarily 0. I f you specify an odd-valued n, f i r cl s1 increments it by 1.
b = f i r cl s1( n, wo, dp, ds, wt ) and
b = f i r cl s1( n, wo, dp, ds, wt , ' hi gh' ) specifies a frequency wt abovewhich
(for wt >wo) or belowwhich (for wt <wo) thefilter is guaranteed tomeet the
given band criterion. This will help you design a filter that meets a passband
or stopband edgerequirement. Therearefour cases:
Lowpass:
- 0 <wt <wo <1: theamplitudeof thefilter is within dp of 1 over the
frequency range0 < <wt .
- 0 <wo <wt <1: theamplitudeof thefilter is within ds of 0 over the
frequency rangewt < <1.
fircls1
7-176
Highpass:
- 0 <wt <wo <1: theamplitudeof thefilter is within ds of 0 over the
frequency range0 < <wt .
- 0 <wo <wt <1: theamplitudeof thefilter is within dp of 1 over the
frequency rangewt < <1.
b = f i r cl s1( n, wo, dp, ds, wp, ws, k) generates a lowpass FI R filter b with a
weighted function, wheren+1 is thefilter length, wo is thenormalized cutoff
frequency, dp is themaximumpassbanddeviation from1(passbandripple), and
ds is themaximumstopband deviation from0(stopband ripple). wp is the
passband edgeof theL2weight function and ws is thestopband edgeof theL2
weight function, wherewp <wo <ws. k istheratio(passbandL2error)/(stopband
L2error)
b = f i r cl s1( n, wo, dp, ds, wp, ws, k, ' hi gh' ) generates ahighpass FI R filter b
with a weighted function, wherews <wo <wp.
b = f i r cl s1( n, wo, dp, ds, . . . , ' desi gn_f l ag' ) enables you tomonitor the
filter design, where' desi gn_f l ag' can be:
' t r ace' , for a textual display of thedesign tableused in thedesign
' pl ot s' , for plots of thefilters magnitude, group delay, and zeros and poles
' bot h' , for both thetextual display and plots
Note I n thedesign of very narrowband filters with small dp and ds, there
may not exist a filter of thegiven length that meets thespecifications.
k
A ( ) D ( )
2
d
0
w
p

A ( ) D ( )
2
d
w
s

------------------------------------------------------ =
fircls1
7-177
Examples Design an order 55 lowpass filter with a cutoff frequency at 0.3.
n = 55; wo = 0. 3;
dp = 0. 02; ds = 0. 008;
b = f i r cl s1( n, wo, dp, ds, ' pl ot s' ) ; %Pl ot magni t ude r esponse
Algorithm Thealgorithmis a multipleexchangealgorithmthat uses Lagrange
multipliers and Kuhn-Tucker conditions on each iteration.
See Also
References [1] Selesnick, I .W., M. Lang, and C.S. Burrus, Constrained Least Square
Design of FI R Filters without Specified Transition Bands,Proceedings of the
I EEE I nt. Conf. Acoust., Speech, Signal Processing, Vol. 2 (May 1995),
pp. 1260-1263.
[2] Selesnick, I .W., M. Lang, and C.S. Burrus, Constrained Least Square
Design of FI R Filters without SpecifiedTransition Bands,I EEE Transactions
on Signal Processing, Vol. 44, No. 8 (August 1996).
0 0.2 0.4 0.6 0.8 1
0
0.5
1
0 0.05 0.1 0.15 0.2 0.25
-0.04
-0.02
0
0.02
0.04
0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
-0.01
0
0.01
f i r cl s Constrained least squareFI R filter design for
multiband filters.
f i r l s Least squarelinear-phaseFI R filter design.
r emez Parks-McClellan optimal FI R filter design.
firls
7-178
7firls
Purpose Least squarelinear-phaseFI R filter design.
Syntax b = f i r l s( n, f , a)
b = f i r l s( n, f , a, w)
b = f i r l s( n, f , a, ' f t ype' )
b = f i r l s( n, f , a, w, ' f t ype' )
Description f i r l s designs a linear-phaseFI R filter that minimizes theweighted,
integrated squared error between an ideal piecewiselinear function and the
magnituderesponseof thefilter over a set of desired frequency bands.
b = f i r l s( n, f , a) returns rowvector b containingthen+1 coefficients of the
order n FI R filter whosefrequency-amplitudecharacteristics approximately
match thosegiven by vectors f and a. Theoutput filter coefficients, or taps,
in b obey thesymmetry relation.
ThesearetypeI (n odd) andtypeI I (n even) linear-phasefilters. Vectorsf and a
specify thefrequency-amplitudecharacteristics of thefilter:
f is a vector of pairs of frequency points, specified in therangebetween 0
and 1, where1corresponds totheNyquist frequency. Thefrequencies must
bein increasingorder. Duplicatefrequency points areallowed and, in fact,
can beusedtodesign a filter exactly thesameas thosereturned by thef i r 1
and f i r 2 functions with a rectangular or boxcar window.
a is a vector containingthedesired amplitudeat thepoints specified in f .
Thedesired amplitudefunction at frequencies between pairs of points
(f(k), f(k+1)) for k odd is thelinesegment connectingthepoints (f(k), a(k))
and (f(k+1), a(k+1)).
Thedesired amplitudefunction at frequencies between pairs of points
(f(k), f(k+1)) for k even is unspecified. Thesearetransition or dont care
regions.
f and a arethesamelength. This length must bean even number.
f i r l s always uses an even filter order for configurations with a passband at
theNyquist frequency. This is becausefor odd orders, thefrequency response
b k ( ) b n 2 k + ( ) k 1 = n 1 + , , , =
firls
7-179
at theNyquist frequency is necessarily 0. I f you specify an odd-valued n, f i r l s
increments it by 1.
Thefigurebelowillustrates therelationship between thef and a vectors in
defininga desired amplituderesponse.
b = f i r l s( n, f , a, w) uses theweights in vector wtoweight thefit in each
frequency band. Thelength of wis half thelength of f anda, sothereis exactly
oneweight per band.
b = f i r l s( n, f , a, ' f t ype' ) and
b = f i r l s( n, f , a, w, ' f t ype' ) specify a filter type, where' f t ype' is:
' hi l ber t ' for linear-phasefilters with oddsymmetry (typeI I I andtypeI V).
Theoutput coefficients in b obey therelation b(k) = -b(n+2-k),
k =1, ... , n +1. This class of filters includes theHilbert transformer, which
has a desired amplitudeof 1 across theentireband.
' di f f er ent i at or ' for typeI I I and typeI V filters, usinga special weighting
technique. For nonzeroamplitudebands, theintegratedsquarederror has a
weight of (1/f)
2
sothat theerror at lowfrequencies is much smaller than at
high frequencies. For FI R differentiators, which havean amplitude
characteristic proportional tofrequency, thefilters minimizetherelative
integrated squared error (theintegral of thesquareof theratioof theerror
tothedesired amplitude).
1.0
0.0
Desired amplitude
response (a)
Normalized
frequency (f )
0.5
"Don't care"/transition regions
f = [ 0 . 3 . 4 . 6 . 7 . 9]
a = [ 0 1 0 0 . 5 . 5]
0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.0 0.8 0.9 1.0 (Nyquist)
firls
7-180
Examples Example 1
Design an order 255 lowpass filter with transition band.
b = f i r l s( 255, [ 0 0. 25 0. 3 1] , [ 1 1 0 0] ) ;
Example 2
Design a 31 coefficient differentiator.
b = f i r l s( 30, [ 0 0. 9] , [ 0 0. 9] , ' di f f er ent i at or ' ) ;
Example 3
Design a24th-order anti-symmetricfilter with piecewiselinear passbands and
plot thedesired and actual frequency response.
F = [ 0 0. 3 0. 4 0. 6 0. 7 0. 9] ;
A = [ 0 1 0 0 0. 5 0. 5] ;
b = f i r l s( 24, F, A, ' hi l ber t ' ) ;
f or i =1: 2: 6,
pl ot ( [ F( i ) F( i +1) ] , [ A( i ) A( i +1) ] , ' - - ' ) , hol d on
end
[ H, f ] = f r eqz( b, 1, 512, 2) ;
pl ot ( f , abs( H) ) , gr i d on, hol d of f
l egend( ' I deal ' , ' f i r l s Desi gn' )
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
Ideal
firls Design
firls
7-181
Algorithm Reference[1] describes thetheoretical approach behind f i r l s. Thefunction
solves a systemof linear equations involvingan inner product matrix of size
roughly n/ 2 usingMATLABs \ operator.
This function designs typeI , I I , I I I , and I V linear-phasefilters. TypeI and I I
arethedefaults for n even and odd respectively, whilethe' hi l ber t ' and
' di f f er ent i at or ' flags producetypeI I I (n even) and I V (n odd) filters. The
various filter types havedifferent symmetries and constraints on their
frequency responses (see[2] for details).
Diagnostics An appropriatediagnosticmessageis displayedwhen incorrect arguments are
used.
F must be even l engt h.
F and A must be equal l engt hs.
Requi r es symmet r y t o be ' hi l ber t ' or ' di f f er ent i at or ' .
Requi r es one wei ght per band.
Fr equenci es i n F must be nondecr easi ng.
Fr equenci es i n F must be i n r ange [ 0, 1] .
A moreserious warningmessageis
War ni ng: Mat r i x i s cl ose t o si ngul ar or badl y scal ed.
Thistendstohappen when theproduct of thefilter lengthandtransitionwidth
grows large. I n this case, thefilter coefficients b might not represent the
desired filter. You can check thefilter by lookingat its frequency response.
Linear Phase
Filter Type
Filter
Order
Symmetry of Coefficients Response H(f),
f = 0
Response H(f),
f = 1 (Nyquist)
TypeI Even even: Norestriction Norestriction
TypeI I Odd Norestriction H(1) = 0
TypeI I I Even odd: H(0) = 0 H(1) = 0
TypeI V Odd H(0) = 0 Norestriction
b k ( ) b n 2 k + ( ) k 1 = n 1 + , , , =
b k ( ) b n 2 k + ( ) k 1 = n 1 + , , , =
firls
7-182
See Also
References [1] Parks, T.W., and C.S. Burrus, Digital Filter Design, J ohn Wiley & Sons,
1987, pp. 54-83.
[2] Oppenheim, A.V., and R.W. Schafer, Discrete-TimeSignal Processing,
Prentice-Hall, 1989, pp. 256-266.
f i r 1 Window-based finiteimpulseresponsefilter design
standard response.
f i r 2 Window-based finiteimpulseresponsefilter design
arbitrary response.
f i r r cos Raised cosineFI R filter design.
r emez Parks-McClellan optimal FI R filter design.
firrcos
7-183
7firrcos
Purpose Raised cosineFI R filter design.
b = f i r r cos( n, F0, df , f s)
b = f i r r cos( n, F0, df , f s, ' bandwi dth')
b = f i r r cos( n, F0, df )
b = f i r r cos( n, F0, r , f s, ' rol l of f ' )
b = f i r r cos( . . . , ' t ype' )
b = f i r r cos( . . . , ' t ype' , del ay)
b = f i r r cos( . . . , ' t ype' , del ay, wi ndow)
[ b, a] = f i r r cos( . . . )
Description b = f i r r cos( n, F0, df , f s) or, equivalently,
b = f i r r cos( n, F0, df , f s, ' bandwi dth' ) returns an order n lowpass
linear-phaseFI R filter with a raised cosinetransition band. Thefilter has
cutoff frequencyF0, transition bandwidthdf , andsamplingfrequencyf s, all in
hertz. df must besmall enough sothat F0 df / 2 is between 0 and f s/ 2. The
coefficients in b arenormalized sothat thenominal passband gain is always
equal to1. Specify f s as theempty vector [ ] tousethedefault valuef s =2.
b = f i r r cos( n, F0, df ) uses a default samplingfrequency of f s =2.
b = f i r r cos( n, F0, r , f s, ' rol l of f ' ) interprets thethird argument, r , as the
rolloff factor instead of thetransition bandwidth, df . r must bein therange
[ 0, 1] .
b = f i r r cos( . . . , ' t ype' ) designs either a normal raised cosinefilter or a
squareroot raised cosinefilter accordingtohowyou specify of thestring
' t ype' . Specify ' t ype' as:
' nor mal ' , for a regular raised cosinefilter. This is thedefault, and is alsoin
effect when the' t ype' argument is left empty, [ ] .
' sqr t ' , for a squareroot raised cosinefilter.
b = f i r r cos( . . . , ' t ype' , del ay) specifies an integer delay in therange
[ 0, n+1] . Thedefault is n/ 2 for even n and ( n+1) / 2 for odd n.
b = f i r r cos( . . . , ' t ype' , del ay, wi ndow) applies a length n+1windowtothe
designed filter toreducetheripplein thefrequency response. wi ndowmust be
a length n+1 column vector. I f nowindowis specified, a boxcar (rectangular)
firrcos
7-184
windowis used. Caremust beexercised when usinga windowwith a delay
other than thedefault.
[ b, a] = f i r r cos( . . . ) always returns a = 1.
Examples Design an order 20 raised cosineFI R filter with cutoff frequency 0.25 of the
Nyquist frequency and a transition bandwidth of 0.25.
h = f i r r cos( 20, 0. 25, 0. 25) ;
f r eqz( h, 1)
See Also
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
700
600
500
400
300
200
100
0
Normalized Frequency ( rad/sample)
P
h
a
s
e

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

(
d
B
)
f i r 1 Window-based finiteimpulseresponsefilter design
standard response.
f i r 2 Window-based finiteimpulseresponsefilter design
arbitrary response.
f i r l s Least squarelinear-phaseFI R filter design.
r emez Parks-McClellan optimal FI R filter design.
freqs
7-185
7freqs
Purpose Frequency responseof analogfilters.
Syntax h = f r eqs( b, a, w)
[ h, w] = f r eqs( b, a)
[ h, w] = f r eqs( b, a, n)
f r eqs( b, a)
Description f r eqs returns thecomplex frequency responseH(j) (Laplacetransform) of an
analogfilter
given thenumerator and denominator coefficients in vectors b and a.
h = f r eqs( b, a, w) returns thecomplex frequencyresponseof theanalogfilter
specifiedbycoefficient vectors b anda. f r eqs evaluates thefrequencyresponse
alongtheimaginary axis in thecomplex planeat thefrequencies specified in
real vector w.
[ h, w] = f r eqs( b, a) automatically picks a set of 200 frequency points won
which tocomputethefrequency responseh.
[ h, w] = f r eqs( b, a, n) picks n frequencieson which tocomputethefrequency
responseh.
f r eqs with nooutput arguments plots themagnitudeand phaseresponse
versus frequency in thecurrent figurewindow.
f r eqs works only for real input systems and positivefrequencies.
Examples Find and graph thefrequency responseof thetransfer function given by
a = [ 1 0. 4 1] ;
b = [ 0. 2 0. 3 1] ;
w = l ogspace( - 1, 1) ;
f r eqs( b, a, w)
H s ( )
B s ( )
A s ( )
---------- -
b 1 ( )s
nb
b 2 ( )s
nb 1
L b nb 1 + ( ) + + +
a 1 ( )s
na
a 2 ( )s
na 1
L a na 1 + ( ) + + +
------------------------------------------------------------------------------------------------- = =
H s ( )
0.2s
2
0.3s 1 + +
s
2
0.4s 1 + +
----------------------------------------- =
freqs
7-186
You can alsocreatetheplot with
h = f r eqs( b, a, w) ;
mag = abs( h) ;
phase = angl e( h) ;
subpl ot ( 2, 1, 1) , l ogl og( w, mag)
subpl ot ( 2, 1, 2) , semi l ogx( w, phase)
Toconvert tohertz, degrees, and decibels, use
f = w/ ( 2*pi ) ;
mag = 20*l og10( mag) ;
phase = phase*180/ pi ;
Algorithm f r eqs evaluates thepolynomials at each frequency point, then divides the
numerator responseby thedenominator response.
s = i *w;
h = pol yval ( b, s) . / pol yval ( a, s) ;
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
7-187
See Also
abs Absolutevalue(magnitude).
angl e Phaseangle.
f r eqz Frequency responseof digital filters.
i nvf r eqs Continuous-time(analog) filter identification from
frequency data.
l ogspace Generatelogarithmically spaced vectors (seethe
MATLAB documentation).
pol yval Polynomial evaluation (seetheMATLAB
documentation).
freqspace
7-188
7freqspace
Purpose Frequency spacingfor frequency response.
Syntax f = f r eqspace( n)
f = f r eqspace( n, ' whol e' )
[ f 1, f 2] = f r eqspace( n)
[ f 1, f 2] = f r eqspace( [ mn] )
[ x1, y1] = f r eqspace( n, ' meshgri d' )
[ x1, y1] = f r eqspace( [ mn] , ' meshgri d' )
Description f r eqspace returns theimplied frequency rangefor equally spaced frequency
responses. This is useful when creatingfrequency vectors for usewith f r eqz.
f = f r eqspace( n) returns thefrequency vector f assumingn evenly spaced
points around theunit circle. For n even or odd, f is ( 0: 2/ n: 1) . For n even,
f r eqspace returns ( n +2) / 2 points. For Nodd, it returns ( n +1) / 2 points.
f = f r eqspace( n, ' whol e' ) returns n evenly spaced points around thewhole
unit circle. I n this case, f is 0: 2/ n: 2*( n- 1) / n.
[ f 1, f 2] = f r eqspace( n) returns thetwo-dimensional frequency vectors f 1
and f 2 for an n-by-n matrix. For n odd, both f 1 and f 2 are
[ - 1 +1/ n: 2/ n: 1- 1/ n] . For n even, both f 1 and f 2 are[ - 1: 2/ n: 1- 2/ n] .
[ f 1, f 2] = f r eqspace( [ mn] ) returns thetwo-dimensional frequency vectors
f 1 and f 2 for an m-by-n matrix.
[ x1, y1] = f r eqspace( n, ' meshgri d' ) and
[ x1, y1] = f r eqspace( [ mn] , ' meshgri d' ) areequivalent to
[ f 1, f 2] = f r eqspace( . . . ) ;
[ x1, y1] = meshgr i d( f 1, f 2) ;
SeetheMATLAB documentation for details on themeshgr i d function.
See Also
f r eqz Computethefrequency responseof digital filters.
i nvf r eqz Discrete-timefilter identification fromfrequency
data.
freqz
7-189
7freqz
Purpose Computethefrequency responseof digital filters.
Syntax [ h, w] = f r eqz( b, a, n)
h = f r eqz( b, a, w)
[ h, w] = f r eqz( b, a, n, ' whol e' )
[ h, w, uni t s] = f r eqz( b, a, . . . )
[ h, f ] = f r eqz( b, a, n, f s)
h = f r eqz( b, a, f , f s)
[ h, f ] = f r eqz( b, a, n, ' whol e' , f s)
[ h, f , uni t s] = f r eqz( b, a, n, ' whol e' , f s)
f r eqz( b, a, . . . )
Description [ h, w] = f r eqz( b, a, n) returns thefrequency responsevector h and the
correspondingfrequency vector wfor thedigital filter whosetransfer function
is determined by the(real or complex) numerator and denominator
polynomials represented in thevectors b and a, respectively. Thevectors h
and wareboth of length n. Thefrequency vector whas values rangingfrom0to
radians per sample. When you dont specify theinteger n, or you specify it as
theempty vector [ ] , thefrequency responseis calculated usingthedefault
valueof 512 samples.
h = f r eqz( b, a, w) returns thefrequency responsevector h calculated at the
frequencies (in radians per sample) supplied by thevector w. Thevector wcan
haveany length.
[ h, w] = f r eqz( b, a, n, ' whol e' ) uses n samplepoints around theentireunit
circletocalculatethefrequency response. Thefrequency vector whas length n
and has values rangingfrom0 to2 radians per sample.
[ h, w, uni t s] = f r eqz( b, a, . . . ) returns theoptional stringargument uni t s,
specifyingtheunits for thefrequency vector w. Thestringreturned in uni t s is
' r ad/ sampl e' , denotingradians per sample.
[ h, f ] = f r eqz( b, a, n, f s) returns thefrequency responsevector h and the
correspondingfrequency vector f for thedigital filter whosetransfer function
is determined by the(real or complex) numerator and denominator
polynomials represented in thevectors b and a, respectively. Thevectors h
and f arebothof lengthn. For thissyntax, thefrequencyresponseiscalculated
freqz
7-190
usingthesamplingfrequency specified by thescalar f s (in hertz). The
frequency vector f is calculated in units of hertz (Hz). Thefrequency vector f
has values rangingfrom0 tof s/ 2 Hz.
h = f r eqz( b, a, f , f s) returns thefrequency responsevector h calculated at
thefrequencies (in Hz) suppliedin thevector f . Thevector f can beany length.
[ h, f ] = f r eqz( b, a, n, ' whol e' , f s) usesnpointsaroundtheentireunit circle
tocalculatethefrequency response. Thefrequency vector f has length n and
has values rangingfrom0 tof s Hz.
[ h, f , uni t s] = f r eqz( b, a, n, ' whol e' , f s) returns theoptional string
argument uni t s, specifyingtheunits for thefrequency vector f . Thestring
returned in uni t s is ' Hz' , denotinghertz.
f r eqz( b, a, . . . ) plots themagnitudeand unwrapped phaseof thefrequency
responseof thefilter. Theplot is displayed in thecurrent figurewindow.
Examples Plot themagnitudeand phaseresponseof an FI R filter.
b = f i r 1( 80, 0. 5, kai ser ( 81, 8) ) ;
f r eqz( b, 1) ;
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
5000
4000
3000
2000
1000
0
Normalized Frequency ( rad/sample)
P
h
a
s
e

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

(
d
B
)
freqz
7-191
Remarks I t isbest tochooseapower of twofor thethirdinput argument n, becausef r eqz
uses an FFT algorithmtocalculatethefrequency response. Seethereference
description of f f t for moreinformation.
Algorithm Thefrequency response[1] of a digital filter can beinterpreted as thetransfer
function evaluatedat z =e
j
. You can always writearational transfer function
in thefollowingform.
f r eqz determines thetransfer function fromthe(real or complex) numerator
and denominator polynomials you specify, and returns thecomplex frequency
responseH(e
j
) of a digital filter. Thefrequency responseis evaluated at
samplepoints determined by thesyntax that you use.
f r eqz generally uses an FFT algorithmtocomputethefrequency response
whenever you dont supply a vector of frequencies as an input argument. I t
computes thefrequency responseas theratioof thetransformed numerator
and denominator coefficients, padded with zeros tothedesired length.
When you dosupply a vector of frequencies as an input argument, then f r eqz
evaluates thepolynomials at each frequency point usingHorners method of
nested polynomial evaluation [1], dividingthenumerator responseby the
denominator response.
H z ( )
B z ( )
A z ( )
-----------
b 1 ( ) b 2 ( )z
1
L b nb 1 + ( )z
nb
+ + +
a 1 ( ) a 2 ( )z
1
L a na 1 + ( )z
na
+ + +
-------------------------------------------------------------------------------------------- = =
freqz
7-192
See Also
References [1] Oppenheim, A.V., and R.W. Schafer, Discrete-TimeSignal Processing,
Prentice-Hall, 1989, pp. 203-205.
abs Computetheabsolutevalue(magnitude).
angl e Computethephaseangle.
f f t Computetheone-dimensional fast Fourier
transform.
f i l t er Filter data.
f r eqs Computethefrequency responseof analogfilters.
f r eqzpl ot Plot thefrequency responseof a digital filter.
i mpz Computetheimpulseresponseof digital filters.
i nvf r eqz I dentify discrete-timefilter parameters from
frequency data.
l ogspace Generatelogarithmically spaced vectors (seethe
MATLAB documentation).
freqzplot
7-193
7freqzplot
Purpose Plot frequency responsedata.
Syntax f r eqzpl ot ( h, w)
f r eqzpl ot ( h, w, s)
Description f r eqzpl ot ( h, w) plots thefrequency responsedata contained in h at the
frequencies specifiedin thevector w, whereh can beeither avector or amatrix.
wmust bea vector whoselength is thenumber of rows in h. Thedata in h is
plotted versus frequency won twoplots:
Themagnitudeof h is plotted in dB.
Thephaseof h is plotted in degrees.
Theunits for frequency on theplots arein radians per sample. I f h is amatrix,
thefrequency responses of each column of h is plotted.
f r eqzpl ot ( h, w, s) specifies a structureof plottingoptions, s, with the
followingfields:
s. xuni t s a stringspecifyingthefrequency axis units. Thecontents of
s. xuni t s can beoneof thefollowing:
- ' r ad/ sampl e' (default)
- ' Hz'
- ' kHz'
- ' MHz'
- ' GHz'
- A user-specified string
s. yuni t s a stringspecifyingthevertical axis units. Thecontents of
s. yuni t s can beoneof thefollowing:
- ' dB' (default)
- ' l i near '
- ' squar ed'
freqzplot
7-194
s. pl ot a stringspecifyingthetypeof plot toproduce. Thecontents of
s. pl ot can beoneof thefollowing:
- ' bot h' (default)
- ' mag'
- ' phase'
Notethat thes structurecan beobtained as an output of f r eqz.
Examples nf f t = 512; Fs = 44. 1; %Fs i s i n kHz.
[ b1, a1] = cheby1( 5, 0. 4, 0. 5) ;
[ b2, a2] = cheby1( 5, 0. 5, 0. 5) ;
[ h1, f , s] = f r eqz( b1, a1, nf f t , Fs) ;
h2 = f r eqz( b2, a2, nf f t , Fs) ; %Use t he same nf f t and Fs.
h = [ h1 h2] ;
s. pl ot = ' mag' ; %Pl ot t he magni t ude onl y.
s. xuni t s = ' khz' ; %Label t he f r equency uni t s cor r ect l y.
s. yuni t s = ' squar ed' ; %Pl ot t he magni t ude squar ed.
f r eqzpl ot ( h, f , s) ; %Compar e t he t wo Chebyshev f i l t er s.
0 5 10 15 20
0
0.2
0.4
0.6
0.8
1
1.2
1.4
Frequency (kHz)
M
a
g
n
i
t
u
d
e

s
q
u
a
r
e
d
freqzplot
7-195
See Also
f r eqz Computeand plot thefrequency responseof a filter.
gr pdel ay Computetheaveragefilter delay.
psdpl ot Plot power spectral density (PSD) data.
gauspuls
7-196
7gauspuls
Purpose Generatea Gaussian-modulated sinusoidal pulse.
Syntax yi = gauspul s( t , f c, bw)
yi = gauspul s( t , f c, bw, bwr )
[ yi , yq] = gauspul s( . . . )
[ yi , yq, ye] = gauspul s( . . . )
t c = gauspul s( ' cutof f ' , f c, bw, bwr , t pe)
Description gauspul s generates Gaussian-modulated sinusoidal pulses.
yi = gauspul s( t , f c, bw) returnsaunity-amplitudeGaussianRF pulseat the
times indicatedin array t , with acenter frequency f c in hertz andafractional
bandwidth bw, which must begreater than 0. Thedefault valuefor f c is
1000 Hz and for bwis 0.5.
yi = gauspul s( t , f c, bw, bwr ) returns a unity-amplitudeGaussian RF pulse
with afractional bandwidth of bwas measuredat alevel of bwr dB with respect
tothenormalized signal peak. Thefractional bandwidth referencelevel bwr
must beless than 0, becauseit indicates a referencelevel less than thepeak
(unity) envelopeamplitude. Thedefault valuefor bwr is -6 dB.
[ yi , yq] = gauspul s( . . . ) returns both thein-phaseand quadraturepulses.
[ yi , yq, ye] = gauspul s( . . . ) returns theRF signal envelope.
t c = gauspul s( ' cutof f ' , f c, bw, bwr , t pe) returnsthecutoff timet c (greater
than or equal to0) at which thetrailingpulseenvelopefalls belowt pe dB with
respect tothepeak envelopeamplitude. Thetrailingpulseenvelopelevel t pe
must beless than 0, becauseit indicates a referencelevel less than thepeak
(unity) envelopeamplitude. Thedefault valuefor t pe is -60 dB.
Remarks Default values aresubstituted for empty or omitted trailinginput arguments.
gauspuls
7-197
Examples Plot a 50 kHz Gaussian RF pulsewith 60%bandwidth, sampled at a rateof
1 MHz. Truncatethepulsewheretheenvelopefalls 40 dB belowthepeak.
t c = gauspul s( ' cut of f ' , 50e3, 0. 6, [ ] , - 40) ;
t = - t c : 1e- 6 : t c;
yi = gauspul s( t , 50e3, 0. 6) ;
pl ot ( 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
chi r p Generatea swept-frequency cosine.
cos Computethecosineof vector/matrix elements (see
theMATLAB documentation).
di r i c ComputetheDirichlet or periodic sinc function.
pul st r an Generatea pulsetrain.
r ect pul s Generatea sampled aperiodic rectangle.
sawt oot h Generatea sawtooth or trianglewave.
si n Computethesineof vector/matrix elements (seethe
MATLAB documentation).
si nc Computethesinc or sin(t)/t function.
squar e Generatea squarewave.
t r i pul s Generatea sampled aperiodic triangle.
gmonopuls
7-198
7gmonopuls
Purpose Generatea Gaussian monopulse.
Syntax y = gmonopul s( t , f c)
t c = gmonopul s( ' cutof f ' , f c)
Description y = gmonopul s( t , f c) returns samples of theunity-amplitudeGaussian
monopulsewithcenter frequencyf c (inhertz) at thetimesindicatedinarray t .
By default, f c =1000 Hz.
t c = gmonopul s( ' cutof f ' , f c) returns thetimeduration between the
maximumand minimumamplitudes of thepulse.
Remarks Default values aresubstituted for empty or omitted trailinginput arguments.
Examples Example 1
Plot a 2 GHz Gaussian monopulsesampled at a rateof 100 GHz.
f c = 2E9; f s=100E9;
t c = gmonopul s( ' cut of f ' , f c) ;
t = - 2*t c : 1/ f s : 2*t c;
y = gmonopul s( t , f c) ; pl ot ( t , y)
4 3 2 1 0 1 2 3 4
x 10
10
1
0.8
0.6
0.4
0.2
0
0.2
0.4
0.6
0.8
1
gmonopuls
7-199
Example 2
Construct a pulsetrain fromthemonopulseof Example1 usinga spacingof
7.5 ns.
f c = 2E9; f s=100E9; %cent er f r eq, sampl e f r eq
D = [ 2. 5 10 17. 5] ' * 1e- 9; %pul se del ay t i mes
t c = gmonopul s( ' cut of f ' , f c) ; %wi dt h of each pul se
t = 0 : 1/ f s : 150*t c; %si gnal eval uat i on t i me
yp = pul st r an( t , D, @gmonopul s, f c) ;
pl ot ( t , yp)
See Also
0 0.5 1 1.5 2 2.5
x 10
8
1
0.8
0.6
0.4
0.2
0
0.2
0.4
0.6
0.8
1
chi r p Generatea swept-frequency cosine.
gauspul s Generatea Gaussian-modulated sinusoidal pulse.
pul st r an Generatea pulsetrain.
r ect pul s Generatea sampled aperiodic rectangle.
t r i pul s Generatea sampled aperiodic triangle.
grpdelay
7-200
7grpdelay
Purpose Computetheaveragefilter delay (group delay).
Syntax [ gd, w] = gr pdel ay( b, a, n)
[ gd, f ] = gr pdel ay( b, a, n, f s)
[ gd, w] = gr pdel ay( b, a, n, ' whol e' )
[ gd, f ] = gr pdel ay( b, a, n, ' whol e' , f s)
gd = gr pdel ay( b, a, w)
gd = gr pdel ay( b, a, f , f s)
gr pdel ay( b, a)
Description Thegroup delay of a filter is a measureof theaveragedelay of thefilter as a
function of frequency. I t is thenegativefirst derivativeof thephaseresponse
of thefilter. I f thecomplex frequency responseof a filter is , then the
group delay is
where is frequency and is thephaseangleof .
[ gd, w] = gr pdel ay( b, a, n) returns then-point group delay, , of the
digital filter
given thenumerator anddenominator coefficients in vectors b anda. gr pdel ay
returns both gd, thegroup delay, and w, a vector containingthen frequency
points in radians. gr pdel ay evaluates thegroup delay at n points equally
spaced around theupper half of theunit circle, sowcontains n points between
0 and .
[ gd, f ] = gr pdel ay( b, a, n, f s) specifies a positivesamplingfrequency f s in
hertz. I t returns a length n vector f containingtheactual frequency points at
which thegroup delay is calculated, alsoin hertz. f contains n points between
0 and f s/ 2.
H e
j
( )

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

g
( )
H z ( )
B z ( )
A z ( )
-----------
b 1 ( ) b 2 ( )z
1
L b nb 1 + ( )z
nb
+ + +
a 1 ( ) a 2 ( )z
1
L a na 1 + ( )z
na
+ + +
-------------------------------------------------------------------------------------------- = =
grpdelay
7-201
[ gd, w] = gr pdel ay( b, a, n, ' whol e' ) and
[ gd, f ] = gr pdel ay( b, a, n, ' whol e' , f s) usen points around thewholeunit
circle(from0 to2, or from0 tof s).
gd = gr pdel ay( b, a, w) and
gd = gr pdel ay( b, a, f , f s) return thegroupdelay evaluatedat thepoints in w
(in radians) or f (in hertz), respectively, wheref s is thesamplingfrequency in
hertz.
gr pdel ay with nooutput arguments plots thegroupdelay versus frequency in
thecurrent figurewindow.
gr pdel ay works for both real and complex input systems.
Examples Plot thegroup delay of Butterworth filter b(z)/a(z).
[ b, a] = but t er ( 6, 0. 2) ;
gr pdel ay( b, a, 128)
0 0.2 0.4 0.6 0.8 1
0
2
4
6
8
10
12
Normalized Frequency ( rad/sample)
G
r
o
u
p

d
e
l
a
y

(
s
a
m
p
l
e
s
)
grpdelay
7-202
Plot both thegroup and phasedelays of a systemon thesamegraph.
gd = gr pdel ay( b, a, 512) ;
gd( 1) = [ ] ; %Avoi d NaNs
[ h, w] = f r eqz( b, a, 512) ; h( 1) = [ ] ; w( 1) = [ ] ;
pd = - unwr ap( angl e( h) ) . / w;
pl ot ( w, gd, w, pd, ' : ' )
xl abel ( ' Fr equency ( r ad/ sec) ' ) ; gr i d;
l egend( ' Gr oup Del ay' , ' Phase Del ay' ) ;
Algorithm gr pdel ay multiplies thefilter coefficients by a unit ramp. After Fourier
transformation, this process corresponds todifferentiation.
See Also
0 0.5 1 1.5 2 2.5 3 3.5
6
4
2
0
2
4
6
8
10
12
Frequency (rad/sec)
Group Delay
Phase Delay
cceps I mplement complex cepstral analysis.
f f t Computethefrequency one-dimensional fast Fourier
transform.
f r eqz Computethefrequency responseof digital filters.
hi l ber t ComputetheHilbert transform.
i cceps Computetheinversecomplex cepstrum.
r ceps Real cepstrumand minimumphasereconstruction.
hamming
7-203
7hamming
Purpose Computea Hammingwindow.
Syntax w = hammi ng( n)
w = hammi ng( n, ' sf l ag' )
Description w = hammi ng( n) returns an n-point symmetric Hammingwindowin the
column vector w. n should bea positiveinteger. Thecoefficients of a Hamming
window arecomputed fromthefollowingequation.
w = hammi ng( n, ' sf l ag' ) returns an n-point Hammingwindowusingthe
windowsamplingspecified by ' sf l ag' , which can beeither ' per i odi c' or
' symmet r i c' (thedefault). When ' per i odi c' is specified, hammi ng computes a
length n+1 windowand returns thefirst n points.
Note I f you specify a one-point window(n=1), thevalue1 is returned.
Examples w = hammi ng( 64) ;
pl ot ( w) ; t i t l e( ' Hammi ng Wi ndow' )
w k 1 + [ ] 0.54 0.46 2
k
n 1
-------------
'

cos k 0 = n 1 , , , =
0 10 20 30 40 50 60 70
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
Hamming Window
hamming
7-204
See Also
References [1] Oppenheim, A.V., and R.W. Schafer, Discrete-TimeSignal Processing,
Prentice-Hall, 1989, pp. 447-448.
bar t l et t Computea Bartlett window.
bl ackman Computea Blackman window.
boxcar Computea rectangular window.
chebwi n Computea Chebyshev window.
hann Computea Hann window.
kai ser Computea Kaiser window.
t r i ang Computea triangular window.
hann
7-205
7hann
Purpose Computea Hann (Hanning) window.
Syntax w = hann( n)
w = hann( n, ' sf l ag' )
Description w = hann( n) returns an n-point symmetric Hann windowin thecolumn
vector w. n must bea positiveinteger. Thecoefficients of a Hann windoware
computed fromthefollowingequation.
w = hann( n, ' sf l ag' ) returns an n-point Hann windowusingthewindow
samplingspecified by ' sf l ag' , which can beeither ' per i odi c' or
' symmet r i c' (thedefault). When ' per i odi c' is specified, hann computes a
length n+1 windowand returns thefirst n points.
Note I f you specify a one-point window(n=1), thevalue1 is returned.
Examples w = hann( 64) ;
pl ot ( w) ; t i t l e( ' Hann Wi ndow' )
w k 1 + [ ] 0.5 1 2
k
n 1
------------ -
'

cos
'

k 0 = n 1 , , , =
0 10 20 30 40 50 60 70
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
Hann Window
hann
7-206
See Also
References [1] Oppenheim, A.V., and R.W. Schafer, Discrete-TimeSignal Processing,
Prentice-Hall, 1989, pp. 447-448.
bar t l et t Computea Bartlett window.
bl ackman Computea Blackman window.
boxcar Computea rectangular window.
chebwi n Computea Chebyshev window.
hammi ng Computea Hammingwindow.
kai ser Computea Kaiser window.
t r i ang Computea triangular window.
hilbert
7-207
7hilbert
Purpose Computethediscrete-timeanalytic signal usingtheHilbert transform.
Syntax x = hi l ber t ( xr )
x = hi l ber t ( xr , n)
Description x = hi l ber t ( xr ) returns a complex helical sequence, sometimes called the
analytic signal, froma real data sequence. Theanalytic signal x =xr +i *xi
has areal part, xr , which istheoriginal data, andan imaginarypart, xi , which
contains theHilbert transform. Theimaginary part is a version of theoriginal
real sequencewitha90phaseshift. Sinesarethereforetransformedtocosines
and viceversa. TheHilbert transformed series has thesameamplitudeand
frequencycontent astheoriginal real dataandincludesphaseinformationthat
depends on thephaseof theoriginal data.
I f xr is amatrix, x = hi l ber t ( xr ) operates columnwiseon thematrix, finding
theHilbert transformof each column.
x = hi l ber t ( xr , n) uses an n point FFT tocomputetheHilbert transform.
Theinput data xr is zero-padded or truncated tolength n, as appropriate.
TheHilbert transformis useful in calculatinginstantaneous attributes of a
timeseries, especially theamplitudeand frequency. Theinstantaneous
amplitudeis theamplitudeof thecomplex Hilbert transform; the
instantaneous frequency is thetimerateof changeof theinstantaneous phase
angle. For a puresinusoid, theinstantaneous amplitudeand frequency are
constant. Theinstantaneous phase, however, is a sawtooth, reflectingtheway
in which thelocal phaseanglevaries linearly over a singlecycle. For mixtures
of sinusoids, theattributes areshort term, or local, averages spanningnomore
than twoor threepoints.
Reference[1] describes theKolmogorov method for minimumphase
reconstruction, which involvestakingtheHilbert transformof thelogarithmof
thespectral density of a timeseries. Thetoolbox function r ceps performs this
reconstruction.
For a discrete-timeanalytic signal x, thelast half of f f t ( x) is zero, and the
first (DC) and center (Nyquist) elements of f f t ( x) arepurely real.
hilbert
7-208
Algorithm Theanalyticsignal for asequencex has aone-sided Fourier transform, that is,
negativefrequencies are0. Toapproximatetheanalytic signal, hi l ber t
calculates theFFT of theinput sequence, replaces thoseFFT coefficients that
correspond tonegativefrequencies with zeros, and calculates theinverseFFT
of theresult.
I n detail, hi l ber t uses a four-step algorithm:
1 I t calculates theFFT of theinput sequence, storingtheresult in a vector x.
2 I t creates a vector h whoseelements h( i ) havethevalues:
- 1 for i = 1, ( n/ 2) +1
- 2 for i = 2, 3, ... , ( n/ 2)
- 0 for i = ( n/ 2) +2, ... , n
3 I t calculates theelement-wiseproduct of x and h.
4 I t calculates theinverseFFT of thesequenceobtainedin step3andreturns
thefirst n elements of theresult.
I f theinput data xr is a matrix, hi l ber t operates in a similar manner,
extendingeach step abovetohandlethematrix case.
Example xr = [ 1 2 3 4] ;
x = hi l ber t ( xr )
x =
1. 0000+1. 0000i 2. 0000- 1. 0000i 3. 0000- 1. 0000i 4. 0000+1. 0000i
You can seethat theimaginary part, i mag( x) =[ 1 - 1 - 1 1] , is theHilbert
transformof xr , and thereal part, r eal ( x) =[ 1 2 3 4] , is simply xr itself.
Notethat thelast half of f f t ( x) =[ 10 - 4+4i - 2 0] is zero(in this example,
thelast half is just thelast element), andthat theDC andNyquist elements of
f f t ( x) , 10 and -2 respectively, arepurely real.
See Also
f f t One-dimensional fast Fourier transform.
i f f t One-dimensional inversefast Fourier transform.
r ceps Real cepstrumand minimumphasereconstruction.
hilbert
7-209
References [1] Claerbout, J .F., Fundamentals of Geophysical Data Processing,
McGraw-Hill, 1976, pp. 59-62.
[2] Marple, S.L., Computingthediscrete-timeanalyticsignal via FFT,I EEE
Transactions on Signal Processing, Vol. 47, No. 9 (September 1999),
pp. 2600-2603.
[3] Oppenheim, A.V., and R.W. Schafer, Discrete-TimeSignal Processing,
2nd ed., Prentice-Hall, 1998.
icceps
7-210
7icceps
Purpose I nversecomplex cepstrum.
Syntax x = i cceps( xhat , nd)
Description x = i cceps( xhat , nd) returns theinversecomplex cepstrumof the(assumed
real) sequencexhat , removingnd samples of delay. I f xhat was obtained with
cceps( x) , then theamount of delay that was added tox was theelement of
r ound( unwr ap( angl e( f f t ( x) ) ) / pi ) correspondingto radians.
See Also
References [1] Oppenheim, A.V., and R.W. Schafer, Discrete-TimeSignal Processing,
Prentice-Hall, 1989.
cceps Complex cepstral analysis.
hi l ber t Hilbert transform.
r ceps Real cepstrumand minimumphasereconstruction.
unwr ap Unwrap phaseangles.
idct
7-211
7idct
Purpose I nversediscretecosinetransform.
Syntax x = i dct ( y)
x = i dct ( y, n)
Description Theinversediscretecosinetransformreconstructs asequencefromits discrete
cosinetransform(DCT) coefficients. Thei dct function is theinverseof thedct
function.
x = i dct ( y) returns theinversediscretecosinetransformof y
where
and N = l engt h( x) , which is thesameas l engt h( y) . Theseries is indexed
fromn = 1andk = 1insteadof theusual n = 0andk = 0becauseMATLAB
vectors run from1 toN instead of from0 toN-1.
x = i dct ( y, n) appends zeros or truncates thevector y tolength n before
transforming.
I f y is a matrix, i dct transforms its 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 Discretecosinetransform(DCT).
dct 2 Two-dimensional DCT (seetheI mageProcessingToolbox
documentation).
i dct 2 Two-dimensional inverseDCT (seetheI mageProcessingToolbox
documentation).
i f f t One-dimensional inversefast Fourier transform.
idct
7-212
References [1] J ain, A.K., Fundamentals of Digital I mageProcessing, Prentice-Hall, 1989.
[2] Pennebaker, W.B., and J .L. Mitchell, J PEG Still I mageData Compression
Standard, Van Nostrand Reinhold, 1993, Chapter 4.
ifft
7-213
7ifft
Purpose One-dimensional inversefast Fourier transform.
Syntax y = i f f t ( x)
y = i f f t ( x, n)
Description i f f t computestheinverseFourier transformof avector or array. Thisfunction
implements theinversetransformgiven by
whereW
N
=e
-j(2/N)
and N = l engt h( x) . Notethat theseries is indexed as
n +1andk +1insteadof theusual n andk becauseMATLAB vectors run from
1 toN instead of from0 toN-1.
y = i f f t ( x) is theinverseFourier transformof vector x. I f x is an array, y is
theinverseFFT of each column of thematrix.
y = i f f t ( x, n) is then-point inverseFFT. I f thelength of x is lessthan n, i f f t
pads x with trailingzeros tolength n. I f thelength of x is greater than n, i f f t
truncates thesequencex. When x is an array, i f f t adjusts thelength of the
columns in thesamemanner.
Thei f f t function is part of thestandard MATLAB language.
Algorithm Thei f f t function is an M-file. Thealgorithmfor i f f t is thesameas that for
f f t , except for asign changeandascalefactor of n =l engt h( x) . Theexecution
timeis fastest when n is a power of twoand slowest when n is a largeprime.
See Also
x n 1 + ( )
1
N
---- X k 1 + ( )W
n
kn
k 0 =
N 1

=
f f t One-dimensional fast Fourier transform.
f f t 2 Two-dimensional fast Fourier transform.
f f t shi f t Rearrangetheoutputs of f f t and f f t 2.
i f f t 2 Two-dimensional inversefast Fourier transform.
ifft2
7-214
7ifft2
Purpose Two-dimensional inversefast Fourier transform.
Syntax Y = i f f t 2( X)
Y = i f f t 2( X, m, n)
Description Y = i f f t 2( X) returns thetwo-dimensional inversefast Fourier transform
(FFT) of thearray X. I f X is a vector, Y has thesameorientation as X.
Y = i f f t 2( X, m, n) truncates or zeropads X, if necessary, tocreatean m-by-n
array beforeperformingtheinverseFFT. Theresult Y is alsom-by-n.
For any X, i f f t 2( f f t 2( X) ) equals X towithin roundoff error. I f X is real,
i f f t 2( f f t 2( X) ) may havesmall imaginary parts.
Thei f f t 2 function is part of thestandard MATLAB language.
Algorithm Thealgorithmfor i f f t 2 is thesameas that for f f t 2, except for a sign change
and scalefactors of [ mn] =si ze( X) . Theexecution timeis fastest when m
and n arepowers of twoand slowest when they arelargeprimes.
See Also
f f t One-dimensional fast Fourier transform.
f f t 2 Two-dimensional fast Fourier transform.
f f t n N-dimensional fast Fourier transform(seethe
MATLAB documentation).
f f t shi f t Rearrangetheoutputs of f f t and f f t 2.
i f f t One-dimensional inversefast Fourier transform.
i f f t n N-dimensional inversefast Fourier transform(see
theMATLAB documentation).
impinvar
7-215
7impinvar
Purpose I mpulseinvariancemethod for analog-to-digital filter conversion.
Syntax [ bz, az] = i mpi nvar ( b, a, f s)
[ bz, az] = i mpi nvar ( b, a)
[ bz, az] = i mpi nvar ( b, a, f s, t ol )
Description [ bz, az] = i mpi nvar ( b, a, f s) creates a digital filter with numerator and
denominator coefficients bz and az, respectively, whoseimpulseresponseis
equal totheimpulseresponseof theanalogfilter with coefficients b and a,
scaled by 1/ f s. I f you leaveout theargument f s, or specify f s as theempty
vector [ ] , it takes thedefault valueof 1 Hz.
[ bz, az] = i mpi nvar ( b, a, f s, t ol ) uses thetolerancespecified by t ol to
determinewhether poles arerepeated. A larger toleranceincreases the
likelihood that i mpi nvar interprets closely located poles as multiplicities
(repeated ones). Thedefault is 0.001, or 0.1%of a poles magnitude. Notethat
theaccuracy of thepolevalues is still limitedtotheaccuracy obtainableby the
r oot s function.
Examples Convert an analoglowpass filter toa digital filter usingi mpi nvar with a
samplingfrequency of 10 Hz.
[ b, a] = but t er ( 4, 0. 3, ' s' ) ;
[ bz, az] = i mpi nvar ( b, a, 10)
bz =
1. 0e- 006 *
- 0. 0000 0. 1324 0. 5192 0. 1273 0
az =
1. 0000 - 3. 9216 5. 7679 - 3. 7709 0. 9246
impinvar
7-216
Algorithm i mpi nvar performs theimpulse-invariant method of analog-to-digital transfer
function conversion discussed in reference[1]:
1 I t finds thepartial fraction expansion of thesystemrepresented by b and a.
2 I t replaces thepoles p by thepoles exp( p/ f s) .
3 I t finds thetransfer function coefficients of thesystemfromtheresidues
fromstep 1 and thepoles fromstep 2.
See Also
References [1] Parks, T.W., and C.S. Burrus, Digital Filter Design, J ohn Wiley & Sons,
1987, pp. 206-209.
bi l i near Bilinear transformation method for analog-to-digital
filter conversion.
l p2bp Transformlowpass analogfilters tobandpass.
l p2bs Transformlowpass analogfilters tobandstop.
l p2hp Transformlowpass analogfilters tohighpass.
l p2l p Changethecut-off frequency for a lowpass analog
filter.
impz
7-217
7impz
Purpose Computetheimpulseresponseof digital filters.
Syntax [ h, t ] = i mpz( b, a)
[ h, t ] = i mpz( b, a, n)
[ h, t ] = i mpz( b, a, n, f s)
i mpz( b, a)
i mpz( . . . )
Description [ h, t ] = i mpz( b, a) computes theimpulseresponseof thefilter with
numerator coefficients b and denominator coefficients a. i mpz chooses the
number of samplesandreturnstheresponseinthecolumnvector h andsample
times in thecolumn vector t (wheret = [ 0: n- 1] ' , and n =l engt h( t ) is
computed automatically).
[ h, t ] = i mpz( b, a, n) computes n samples of theimpulseresponsewhen n is
an integer (t =[ 0: n- 1] ' ). I f n is a vector of integers, i mpz computes the
impulseresponseat thoseinteger locations, startingtheresponsecomputation
from0(andt =n or t =[ 0 n] ). I f, insteadof n, you includetheempty vector [ ]
for thesecondargument, thenumber of samples is computedautomatically by
default.
[ h, t ] = i mpz( b, a, n, f s) computes n samples and produces a vector t of
length n sothat thesamples arespaced 1/ f s units apart.
i mpz with nooutput arguments plots theimpulseresponsein thecurrent
figurewindowusing st em( t , h) .
i mpz works for both real and complex input systems.
Examples Plot thefirst 50 samples of theimpulseresponseof a fourth-order lowpass
elliptic filter with cutoff frequency of 0.4 times theNyquist frequency.
[ b, a] = el l i p( 4, 0. 5, 20, 0. 4) ;
i mpz( b, a, 50)
impz
7-218
Algorithm i mpz filters a length n impulsesequenceusing
f i l t er ( b, a, [ 1 zer os( 1, n- 1) ] )
and plots theresults usingst em.
Tocomputen in theauto-length case, i mpz either uses n = l engt h( b) for the
FI R caseor first finds thepoles using p = r oot s( a) , if l engt h( a) is greater
than 1.
I f thefilter is unstable, n is chosen tobethepoint at which thetermfromthe
largest polereaches 10^6 times its original value.
I f thefilter is stable, n is chosen tobethepoint at which thetermduetothe
largest amplitudepoleis 5*10^- 5 of its original amplitude.
I f thefilter is oscillatory (poles on theunit circleonly), i mpz computes five
periods of theslowest oscillation.
I f thefilter has both oscillatory and damped terms, n is chosen toequal five
periods of theslowest oscillation or thepoint at which thetermduetothe
largest (nonunity) amplitudepoleis 5*10^- 5 of its original amplitude,
whichever is greater.
0 5 10 15 20 25 30 35 40 45
-0.2
-0.1
0
0.1
0.2
0.3
0.4
0.5
impz
7-219
i mpz alsoallows for delays in thenumerator polynomial. Thenumber of delays
is incorporated intothecomputation for thenumber of samples.
See Also
i mpul se Unit impulseresponse(seetheControl SystemToolbox
documentation).
st em Plot discretesequencedata (seetheMATLAB
documentation).
interp
7-220
7interp
Purpose I ncreasesamplingrateby an integer factor (interpolation).
Syntax y = i nt er p( x, r )
y = i nt er p( x, r , l , al pha)
[ y, b] = i nt er p( x, r , l , al pha)
Description I nterpolation increases theoriginal samplingratefor a sequencetoa higher
rate. i nt er p performslowpassinterpolationbyinsertingzerosintotheoriginal
sequenceand then applyinga special lowpass filter.
y = i nt er p( x, r ) increases thesamplingrateof x by a factor of r . The
interpolated vector y is r times longer than theoriginal input x.
y = i nt er p( x, r , l , al pha) specifies l (filter length) and al pha (cut-off
frequency). Thedefault valuefor l is 4 and thedefault valuefor al pha is 0.5.
[ y, b] = i nt er p( x, r , l , al pha) returns vector b containingthefilter
coefficients used for theinterpolation.
Examples I nterpolatea signal by a factor of four.
t = 0: 0. 001: 1; %Ti me vect or
x = si n( 2*pi *30*t ) + si n( 2*pi *60*t ) ;
y = i nt er p( x, 4) ;
st em( x( 1: 30) ) ;
t i t l e( ' Or i gi nal Si gnal ' ) ;
f i gur e
st em( y( 1: 120) ) ;
t i t l e( ' I nt er pol at ed Si gnal ' ) ;
interp
7-221
Algorithm i nt er p uses thelowpass interpolation Algorithm8.1 described in [1]:
1 I t expands theinput vector tothecorrect length by insertingzeros between
theoriginal data values.
2 I t designsaspecial symmetricFI R filter that allowstheoriginal datatopass
through unchanged and interpolates between sothat themean-square
errorsbetween theinterpolatedpointsandtheir ideal values areminimized.
3 I t applies thefilter totheinput vector toproducetheinterpolated output
vector.
Thelength of theFI R lowpass interpolatingfilter is 2*l *r +1. Thenumber of
original samplevalues used for interpolation is 2*l . Ordinarily, l should be
less than or equal to10. Theoriginal signal is assumedtobebandlimitedwith
normalizedcutoff frequency0 al pha 1, where1ishalf theoriginal sampling
frequency (theNyquist frequency). Thedefault valuefor l is 4and thedefault
valuefor al pha is 0.5.
Diagnostics I f r is not an integer, i nt er p gives thefollowingerror message.
Resampl i ng r at e R must be an i nt eger .
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
7-222
See Also
References [1] Programs for Digital Signal Processing, I EEE Press, NewYork, 1979,
Algorithm8.1.
deci mat e Decreasethesamplingratefor a sequence
(decimation).
i nt er p1 One-dimensional data interpolation (tablelookup)
(seetheMATLAB documentation).
r esampl e Changesamplingrateby any rational factor.
spl i ne Cubic splineinterpolation (seetheMATLAB
documentation).
upf i r dn Upsample, apply an FI R filter, and downsample.
intfilt
7-223
7intfilt
Purpose I nterpolation FI R filter design.
Syntax b = i nt f i l t ( r , l , al pha)
b = i nt f i l t ( r , n, ' Lagrange' )
Description b = i nt f i l t ( r , l , al pha) designsalinear phaseFI R filter that performsideal
bandlimited interpolation usingthenearest 2*l nonzerosamples, when used
on a sequenceinterleaved with r - 1 consecutivezeros every r samples. I t
assumes an original bandlimitedness of al pha times theNyquist frequency.
Thereturned filter is identical tothat used by i nt er p.
b = i nt f i l t ( r , n, ' Lagrange' ) or
b = i nt f i l t ( r , n, ' l ' ) designs an FI R filter that performs nth-order
Lagrangepolynomial interpolation on a sequenceinterleaved with r - 1
consecutivezeroseveryr samples. bhaslength( n +1) *r for n even, andlength
( n +1) *r - 1 for n odd.
Both types of filters arebasically lowpass and areintended for interpolation
and decimation.
Examples Design a digital interpolation filter toupsamplea signal by four, usingthe
bandlimited method.
al pha = 0. 5; %" Bandl i mi t edness" f act or
h1 = i nt f i l t ( 4, 2, al pha) ; %Bandl i mi t ed i nt er pol at i on
Thefilter h1 works best when theoriginal signal is bandlimitedtoal pha times
theNyquist frequency. Createa bandlimited noisesignal.
r andn( ' st at e' , 0)
x = f i l t er ( f i r 1( 40, 0. 5) , 1, r andn( 200, 1) ) ; %Bandl i mi t
Nowzeropadthesignal with threezeros between every sample. Theresulting
sequenceis four times thelength of x.
xr = r eshape( [ x zer os( l engt h( x) , 3) ] ' , 4*l engt h( x) , 1) ;
I nterpolateusingthef i l t er command.
y = f i l t er ( h1, 1, xr ) ;
intfilt
7-224
y is an interpolated version of x, delayed by seven samples (thegroup-delay of
thefilter). Zoomin on a section toseethis.
pl ot ( 100: 200, y( 100: 200) , 7+( 101: 4: 196) , x( 26: 49) , ' o' )
i nt f i l t alsoperforms Lagrangepolynomial interpolation of theoriginal
signal. For example, first-order polynomial interpolation is just linear
interpolation, which is accomplished with a triangular filter.
h2 = i nt f i l t ( 4, 1, ' l ' ) %Lagr ange i nt er pol at i on
h2 =
0. 2500 0. 5000 0. 7500 1. 0000 0. 7500 0. 5000 0. 2500
Algorithm Thebandlimitedmethod uses f i r l s todesign an interpolation FI R equivalent
tothat presented in [1]. Thepolynomial method uses Lagranges polynomial
interpolation formula on equally spaced samples toconstruct theappropriate
filter.
See Also
100 110 120 130 140 150 160 170 180 190 200
1.2
1
0.8
0.6
0.4
0.2
0
0.2
0.4
0.6
0.8
deci mat e Decreasethesamplingratefor a sequence
(decimation).
i nt er p I ncreasesamplingrateby an integer factor
(interpolation).
r esampl e Changesamplingrateby any rational factor.
intfilt
7-225
References [1] Oetken, Parks, and Schler, NewResults in theDesign of Digital
I nterpolators,I EEE Trans. Acoust., Speech, Signal Processing, Vol. ASSP-23
(J une1975), pp. 301-309.
invfreqs
7-226
7invfreqs
Purpose I dentify continuous-timefilter parameters fromfrequency responsedata.
Syntax [ b, a] = i nvf r eqs( h, w, nb, na)
[ b, a] = i nvf r eqs( h, w, nb, na, wt )
[ b, a] = i nvf r eqs( h, w, nb, na, wt , i t er )
[ b, a] = i nvf r eqs( h, w, nb, na, wt , i t er , t ol )
[ b, a] = i nvf r eqs( h, w, nb, na, wt , i t er , t ol , ' trace' )
[ b, a] = i nvf r eqs( h, w, ' compl ex' , nb, na, . . . )
Description i nvf r eqs is theinverseoperation of f r eqs; it finds a continuous-timetransfer
function that corresponds toa given complex frequency response. Froma
laboratory analysis standpoint, i nvf r eqs is useful in convertingmagnitude
and phasedata intotransfer functions.
[ b, a] = i nvf r eqs( h, w, nb, na) returns thereal numerator and denominator
coefficient vectors b and a of thetransfer function
whosecomplex frequency responseis given in vector h at thefrequency points
specified in vector w. Scalars nb and na specify thedesired orders of the
numerator and denominator polynomials.
Frequency is specifiedin radians between 0and, andthelength of h must be
thesameas thelength of w. i nvf r eqs uses conj ( h) at - wtoensuretheproper
frequency domain symmetry for a real filter.
[ b, a] = i nvf r eqs( h, w, nb, na, wt ) weights thefit-errors versus frequency,
wherewt is a vector of weightingfactors thesamelength as w.
[ b, a] = i nvf r eqs( h, w, nb, na, wt , i t er ) and
[ b, a] = i nvf r eqs( h, w, nb, na, wt , i t er , t ol ) providea superior algorithm
that guarantees stability of theresultinglinear systemand searches for the
best fit usinga numerical, iterativescheme. Thei t er parameter tells
i nvf r eqs toend theiteration when thesolution has converged, or after i t er
iterations, whichever comes first. i nvf r eqs defines convergenceas occurring
when thenormof the(modified) gradient vector is less than t ol , wheret ol is
H s ( )
B s ( )
A s ( )
---------- -
b 1 ( )s
nb
b 2 ( )s
nb 1
L b nb 1 + ( ) + + +
a 1 ( )s
na
a 2 ( )s
na 1
L a na 1 + ( ) + + +
------------------------------------------------------------------------------------------------- = =
invfreqs
7-227
an optional parameter that defaults to0.01. Toobtain a weight vector of all
ones, use
i nvf r eqs( h, w, nb, na, [ ] , i t er , t ol )
[ b, a] = i nvf r eqs( h, w, nb, na, wt , i t er , t ol , ' trace' ) displays a textual
progress report of theiteration.
[ b, a] = i nvf r eqs( h, w, ' compl ex' , nb, na, . . . ) creates a complex filter. I n
this casenosymmetry is enforced, and thefrequency is specified in radians
between - and .
Remarks When buildinghigher order models usinghigh frequencies, it is important to
scalethefrequencies, dividingby a factor such as half thehighest frequency
present inw, soastoobtainwell conditionedvaluesof a andb. Thiscorresponds
toa rescalingof time.
Examples Example 1
Convert a simpletransfer function tofrequency responsedata and then back
totheoriginal filter coefficients.
a = [ 1 2 3 2 1 4] ; b = [ 1 2 3 2 3] ;
[ h, w] = f r eqs( b, a, 64) ;
[ bb, aa] = i nvf r eqs( h, w, 4, 5)
bb =
1. 0000 2. 0000 3. 0000 2. 0000 3. 0000
aa =
1. 0000 2. 0000 3. 0000 2. 0000 1. 0000 4. 0000
invfreqs
7-228
Noticethat bb and aa areequivalent tob and a, respectively. However, aa has
poles in theleft half-planeand thus thesystemis unstable. Usei nvf r eqss
iterativealgorithmtofind a stableapproximation tothesystem.
[ bbb, aaa] = i nvf r eqs( 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
Example 2
Supposeyou havetwovectors, mag and phase, that contain magnitudeand
phasedata gathered in a laboratory, and a third vector wof frequencies. You
can convert thedata intoa continuous-timetransfer function using i nvf r eqs.
[ b, a] = i nvf r eqs( mag. *exp( j *phase) , w, 2, 3) ;
Algorithm By default, i nvf r eqs uses an equation error methodtoidentify thebest model
fromthedata. This finds b and a in
by creatinga systemof linear equations and solvingthemwith MATLABs \
operator. HereA(w(k)) and B(w(k)) aretheFourier transforms of the
polynomials a and b, respectively, at thefrequency w(k), and n is thenumber
of frequency points (thelength of h and w). This algorithmis based on Levi [1].
Several variants havebeen suggested in theliterature, wheretheweighting
function wt gives less attention tohigh frequencies.
min
b a ,
wt k ( ) h k ( )A w k ( ) ( ) B w k ( ) ( )
2
k 1 =
n

invfreqs
7-229
Thesuperior (output-error) algorithmusesthedampedGauss-Newtonmethod
for iterativesearch [2], with theoutput of thefirst algorithmas theinitial
estimate. This solves thedirect problemof minimizingtheweighted sumof the
squared error between theactual and thedesired frequency responsepoints.
See Also
References [1] Levi, E.C., Complex-CurveFitting, I RE Trans. on Automatic Control,
Vol. AC-4 (1959), pp. 37-44.
[2] Dennis, J .E., J r., andR.B. Schnabel. Numerical Methodsfor Unconstrained
Optimization and Nonlinear Equations. Englewood Cliffs, NJ : Prentice-Hall,
1983.
min
b a ,
wt k ( ) h k ( )
B w k ( ) ( )
A w k ( ) ( )
--------------------
2
k 1 =
n

f r eqs Computethefrequency responseof analogfilters.


f r eqz Computethefrequency responseof digital filters.
i nvf r eqz I dentify a discrete-timefilter fromfrequency data.
pr ony I mplement Pronys methodfor timedomain I I R filter
design.
invfreqz
7-230
7invfreqz
Purpose I dentify discrete-timefilter parameters fromfrequency responsedata.
Syntax [ b, a] = i nvf r eqz( h, w, nb, na)
[ b, a] = i nvf r eqz( h, w, nb, na, wt )
[ b, a] = i nvf r eqz( h, w, nb, na, wt , i t er )
[ b, a] = i nvf r eqz( h, w, nb, na, wt , i t er , t ol )
[ b, a] = i nvf r eqz( h, w, nb, na, wt , i t er , t ol , ' trace' )
[ b, a] = i nvf r eqz( h, w, ' compl ex' , nb, na, . . . )
Description i nvf r eqz is theinverseoperation of f r eqz; it finds a discrete-timetransfer
function that corresponds toa given complex frequency response. Froma
laboratory analysis standpoint, i nvf r eqz can beused toconvert magnitude
and phasedata intotransfer functions.
[ b, a] = i nvf r eqz( h, w, nb, na) returns thereal numerator and denominator
coefficients in vectors b and a of thetransfer function
whosecomplex frequency responseis given in vector h at thefrequency points
specified in vector w. Scalars nb and na specify thedesired orders of the
numerator and denominator polynomials.
Frequency is specified in radians between 0and , and thelength of h must be
thesameas thelength of w. i nvf r eqz uses conj ( h) at - wtoensuretheproper
frequency domain symmetry for a real filter.
[ b, a] = i nvf r eqz( h, w, nb, na, wt ) weights thefit-errors versus frequency,
wherewt is a vector of weightingfactors thesamelength as w.
[ b, a] = i nvf r eqz( h, w, nb, na, wt , i t er ) and
[ b, a] = i nvf r eqz( h, w, nb, na, wt , i t er , t ol ) providea superior algorithm
that guarantees stability of theresultinglinear systemand searches for the
best fit usinga numerical, iterativescheme. Thei t er parameter tells
i nvf r eqz toend theiteration when thesolution has converged, or after i t er
iterations, whichever comes first. i nvf r eqz defines convergenceas occurring
when thenormof the(modified) gradient vector is less than t ol , wheret ol is
H z ( )
B z ( )
A z ( )
-----------
b 1 ( ) b 2 ( )z
1
L b nb 1 + ( )z
nb
+ + +
a 1 ( ) a 2 ( )z
1
L a na 1 + ( )z
na
+ + +
-------------------------------------------------------------------------------------------- = =
invfreqz
7-231
an optional parameter that defaults to0.01. Toobtain a weight vector of all
ones, use
i nvf r eqz( h, w, nb, na, [ ] , i t er , t ol )
[ b, a] = i nvf r eqz( h, w, nb, na, wt , i t er , t ol , ' trace' ) displays a textual
progress report of theiteration.
[ b, a] = i nvf r eqz( h, w, ' compl ex' , nb, na, . . . ) creates a complex filter. I n
this casenosymmetry is enforced, and thefrequency is specified in radians
between - and .
Examples Convert a simpletransfer function tofrequency responsedata and then back
totheoriginal filter coefficients.
a = [ 1 2 3 2 1 4] ; b = [ 1 2 3 2 3] ;
[ h, w] = f r eqz( b, a, 64) ;
[ bb, aa] = i nvf r eqz( 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
Noticethat bb and aa areequivalent tob and a, respectively. However, aa has
poles outsidetheunit circleand thus thesystemis unstable. Usei nvf r eqzs
iterativealgorithmtofind a stableapproximation tothesystem.
[ bbb, aaa] = i nvf r eqz( h, w, 4, 5, [ ] , 30)
bbb =
0. 2427 0. 2788 0. 0069 0. 0971 0. 1980
aaa =
1. 0000 - 0. 8944 0. 6954 0. 9997 - 0. 8933 0. 6949
invfreqz
7-232
Algorithm By default, i nvf r eqz uses an equation error methodtoidentify thebest model
fromthedata. This finds b and a in
by creatinga systemof linear equations and solvingthemwith MATLABs \
operator. HereA((k)) and B((k)) aretheFourier transforms of the
polynomials a and b, respectively, at thefrequency (k), and n is thenumber
of frequencypoints (thelength of h andw). This algorithmis abasedon Levi [1].
Thesuperior (output-error) algorithmuses thedamped Gauss-Newton
method for iterativesearch [2], with theoutput of thefirst algorithmas the
initial estimate. Thissolvesthedirect problemof minimizingtheweightedsum
of thesquared error between theactual and thedesired frequency response
points.
See Also
References [1] Levi, E.C., Complex-CurveFitting, I RE Trans. on Automatic Control,
Vol. AC-4 (1959), pp. 37-44.
[2] Dennis, J .E., J r., andR.B. Schnabel, Numerical Methodsfor Unconstrained
Optimization and Nonlinear Equations, Prentice-Hall, 1983.
min
b a ,
wt k ( ) h k ( )A k ( ) ( ) B k ( ) ( )
2
k 1 =
n

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

f r eqs Computethefrequency responseof analogfilters.


f r eqz Computethefrequency responseof digital filters.
i nvf r eqs Continuous-time(analog) filter identification from
frequency data.
pr ony Pronys method for timedomain I I R filter design.
is2rc
7-233
7is2rc
Purpose Convert inversesineparameters toreflection coefficients.
Syntax k = i s2r c( i si n)
Description k = i s2r c( i si n) returns a vector of reflection coefficients k froma vector of
inversesineparameters i si n.
Examples i si n = [ 0. 2000 0. 8727 0. 0020 0. 0052 - 0. 0052] ;
k = i s2r c( i si n)
k =
0. 3090 0. 9801 0. 0031 0. 0082 - 0. 0082
See Also
References [1] Deller, J .R., J .G. Proakis, and J .H.L. Hansen, Discrete-TimeProcessingof
Speech Signals, Prentice-Hall, 1993.
ac2r c Convert autocorrelation parameters toreflection
coefficients.
l ar 2r c Convert logarea ratioparameters toreflection
coefficients.
pol y2r c Convert prediction filter coefficients toreflection
coefficients.
r c2i s Convert reflection coefficients toinversesine
parameters.
kaiser
7-234
7kaiser
Purpose Computea Kaiser window.
Syntax w = kai ser ( n, bet a)
Description w = kai ser ( n, bet a) returns an n-point Kaiser (I
0
sinh) windowin the
column vector w. bet a is theKaiser window parameter that affects the
sidelobeattenuation of theFourier transformof thewindow.
Toobtain a Kaiser windowthat designs an FI R filter with sidelobeheight
- dB, usethefollowing.
I ncreasingbet a widens themain lobeand decreases theamplitudeof the
sidelobes (increases theattenuation).
Examples w = kai ser ( 200, 0. 5) ;
pl ot ( w)
t i t l e( ' Kai ser Wi ndow, bet a = . 5' )

0.1102 8.7 ( ), 50 >


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




=
0 20 40 60 80 100 120 140 160 180 200
0.94
0.95
0.96
0.97
0.98
0.99
1
Kaiser Window, beta = .5
kaiser
7-235
See Also
References [1] Kaiser, J .F., NonrecursiveDigital Filter Design Usingthe - sinh
WindowFunction,Proc. 1974I EEE Symp. CircuitsandSystems, (April 1974),
pp. 20-23.
[2] Selected Papers in Digital Signal ProcessingI I , I EEE Press, NewYork,
1975.
[3] Oppenheim, A.V., and R.W. Schafer, Discrete-TimeSignal Processing,
Prentice-Hall, 1989, p. 453.
bar t l et t Computea Bartlett window.
bl ackman Computea Blackman window.
boxcar Computea rectangular window.
chebwi n Computea Chebyshev window.
hammi ng Computea Hammingwindow.
hann Computea Hann window.
kai ser or d Estimateparameters for f i r 1 with a Kaiser window.
t r i ang Computea triangular window.
I
0
kaiserord
7-236
7kaiserord
Purpose Estimateparameters for an FI R filter design with a Kaiser window.
Syntax [ n, Wn, bet a, f t ype] = kai ser or d( f , a, dev)
[ n, Wn, bet a, f t ype] = kai ser or d( f , a, dev, f s)
c = kai ser or d( f , a, dev, f s, ' cel l ' )
Description kai ser or d returns a filter order n and bet a parameter tospecify a Kaiser
windowfor usewith thef i r 1 function. Given a set of specifications in the
frequencydomain, kai ser or d estimatestheminimumFI R filter order that will
approximately meet thespecifications. kai ser or d converts thegiven filter
specifications intopassband and stopband ripples and converts cutoff
frequencies intotheformneeded for windowed FI R filter design.
[ n, Wn, bet a, f t ype] = kai ser or d( f , a, dev) finds theapproximateorder n,
normalized frequency band edges Wn, and weights that meet input
specifications f , a, and dev. f is a vector of band edges and a is a vector
specifyingthedesired amplitudeon thebands defined by f . Thelength of f is
twicethelength of a, minus 2. Together, f and a definea desired piecewise
constant responsefunction. dev is avector thesamesizeas a that specifies the
maximumallowableerror or deviation between thefrequency responseof the
output filter and its desired amplitude, for each band. Theentries in dev
specify thepassband rippleand thestopband attenuation. You specify each
entry in dev as a positivenumber, representingabsolutefilter gain (not in
decibels).
Note I f, in thevector dev, you specify unequal deviations across bands, the
minimumspecified deviation is used, sincetheKaiser windowmethod is
constrained toproducefilters with minimumdeviation in all of thebands.
f i r 1 can usetheresultingorder n, frequency vector Wn, multiband magnitude
typef t ype, and theKaiser windowparameter bet a. Thef t ype stringis
intendedfor usewithf i r 1; it isequal to' hi gh' for ahighpassfilter and' st op'
for a bandstop filter. For multiband filters, it can beequal to' dc- 0' when the
first band is a stopband (startingat f =0) or ' dc- 1' when thefirst band is a
passband.
kaiserord
7-237
Todesign an FI R filter b that approximately meets thespecifications given by
kai ser parameters f , a, and dev, usethefollowingcommand.
b = f i r 1( n, Wn, kai ser ( n+1, bet a) , f t ype, ' noscal e' )
[ n, Wn, bet a, f t ype] = kai ser or d( f , a, dev, f s) usesasamplingfrequencyf s
in Hz. I f you dont specify theargument f s, or if you specify it as theempty
vector [ ] , it defaults to2 Hz, and theNyquist frequency is 1 Hz. You can use
this syntax tospecify band edges scaled toa particular applications sampling
frequency.
c = kai ser or d( f , a, dev, f s, ' cel l ' ) is a cell-array whoseelements arethe
parameters tof i r 1.
Note I n somecases, kai ser or d underestimates or overestimates theorder n.
I f thefilter doesnot meet thespecifications, tryahigher order suchas n+1, n+2,
and soon, or a try lower order.
Results areinaccurateif thecutoff frequencies arenear 0 or theNyquist
frequency, or if dev is large(greater than 10%).
Algorithm kai ser or d uses empirically derived formulas for estimatingtheorders of
lowpass filters, as well as differentiators and Hilbert transformers. Estimates
for multiband filters (such as bandpass filters) arederived fromthelowpass
design formulas.
Thedesign formulas that underlietheKaiser windowand its application to
FI R filter design are
where =-20log
10
is thestopband attenuation expressed in decibels (recall
that
p
=
s
is required).

0.1102 8.7 ( ), 50 >


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




=
kaiserord
7-238
Thedesign formula is
wheren is thefilter order and is thewidth of thesmallest transition region.
Examples Example 1
Design a lowpass filter with passband defined from0 to1 kHz and stopband
definedfrom1500 Hz to4kHz. Specifyapassbandrippleof 5%andastopband
attenuation of 40 dB.
f samp = 8000;
f cut s = [ 1000 1500] ;
mags = [ 1 0] ;
devs = [ 0. 05 0. 01] ;
[ n, Wn, bet a, f t ype] = kai ser or d( f cut s, mags, devs, f samp) ;
hh = f i r 1( n, Wn, f t ype, kai ser ( n+1, bet a) , ' noscal e' ) ;
f r eqz( hh)
n
7.95
2.285 ( )
---------------------------- =
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
1400
1200
1000
800
600
400
200
0
Normalized Frequency ( rad/sample)
P
h
a
s
e

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

(
d
B
)
kaiserord
7-239
Example 2
Design an odd-length bandpass filter (notethat odd length means even order,
sotheinput tof i r 1 must bean even integer).
f samp = 8000;
f cut s = [ 1000 1300 2210 2410] ;
mags = [ 0 1 0] ;
devs = [ 0. 01 0. 05 0. 01] ;
[ n, Wn, bet a, f t ype] = kai ser or d( f cut s, mags, devs, f samp) ;
n = n + r em( n, 2) ;
hh = f i r 1( n, Wn, f t ype, kai ser ( n+1, bet a) , ' noscal e' ) ;
[ H, f ] = f r eqz( hh, 1, 1024, f samp) ;
pl ot ( f , abs( H) ) , gr i d on
Example 3
Design a lowpass filter with a passband cutoff of 1500 Hz, a stopband cutoff of
2000 Hz, passband rippleof 0.01, stopband rippleof 0.1, and a sampling
frequency of 8000 Hz.
[ n, Wn, bet a, f t ype] = kai ser or d( [ 1500 2000] , [ 1 0] , . . .
[ 0. 01 0. 1] , 8000) ;
b = f i r 1( n, Wn, f t ype, kai ser ( n+1, bet a) , ' noscal e' ) ;
0 500 1000 1500 2000 2500 3000 3500 4000
0
0.2
0.4
0.6
0.8
1
1.2
1.4
kaiserord
7-240
This is equivalent to
c = kai ser or d( [ 1500 2000] , [ 1 0] , [ 0. 01 0. 1] , 8000, ' cel l ' ) ;
b = f i r 1( c{: }) ;
Remarks Becareful todistinguish between themeaningsof filter length andfilter order.
Thefilter length is thenumber of impulseresponsesamples in theFI R filter.
Generally, theimpulseresponseisindexedfromn =0ton =L-1, whereL isthe
filter length. Thefilter order is thehighest power in a z-transform
representation of thefilter. For an FI R transfer function, thisrepresentation is
a polynomial in z, wherethehighest power is z
L-1
and thelowest power is z
0
.
Thefilter order isonelessthan thelength (L-1) andisalsoequal tothenumber
of zeros of thez polynomial.
See Also
References [1] Kaiser, J .F., NonrecursiveDigital Filter Design Usingthe - sinh
WindowFunction,Proc. 1974I EEE Symp. Circuitsand Systems, (April 1974),
pp. 20-23.
[2] Selected Papers in Digital Signal ProcessingI I , I EEE Press, NewYork,
1975, pp. 123-126.
[3] Oppenheim, A.V., and R.W. Schafer, Discrete-TimeSignal Processing,
Prentice-Hall, 1989, pp. 458-562.
f i r 1 Window-based finiteimpulseresponsefilter design
standard response.
kai ser Kaiser window.
r emezor d Parks-McClellan optimal FI R filter order estimation.
I
0
lar2rc
7-241
7lar2rc
Purpose Convert logarea ratioparameters toreflection coefficients.
Syntax k = l ar 2r c( g)
Description k = l ar 2r c( g) returns a vector of reflection coefficients k froma vector of log
area ratioparameters g.
Examples g = [ 0. 6389 4. 5989 0. 0063 0. 0163 - 0. 0163] ;
k = l ar 2r c( g)
k =
0. 3090 0. 9801 0. 0031 0. 0081 - 0. 0081
See Also
References [1] Deller, J .R., J .G. Proakis, and J .H.L. Hansen, Discrete-TimeProcessingof
Speech Signals, Prentice-Hall, 1993.
ac2r c Convert autocorrelation parameters toreflection
coefficients.
i s2r c Convert inversesineparameters toreflection
coefficients.
pol y2r c Convert prediction filter coefficients toreflection
coefficients.
r c2l ar Convert reflection coefficients tologarea ratio
parameters.
latc2tf
7-242
7latc2tf
Purpose Convert latticefilter parameters totransfer function form.
Syntax [ num, den] = l at c2t f ( k, v)
[ num, den] = l at c2t f ( k, ' i i r opt i on' )
num= l at c2t f ( k, ' f i r opt i on' )
num= l at c2t f ( k)
Description [ num, den] = l at c2t f ( k, v) finds thetransfer function numerator numand
denominator den fromtheI I R latticecoefficients k and ladder coefficients v.
[ num, den] = l at c2t f ( k, ' i i r opt i on' ) produces an I I R filter transfer
function accordingtothevalueof thestring' i i r opt i on' :
' al l pol e' : Produces an all-polefilter transfer function fromtheassociated
all-poleI I R latticefilter coefficients k.
' al l pass' : Produces an allpass filter transfer function fromtheassociated
allpass I I R latticefilter coefficients k.
num= l at c2t f ( k, ' f i r opt i on' ) produces an FI R filter accordingtothevalue
of thestring' f i r opt i on' :
' mi n' : Produces aminimum-phaseFI R filter numerator fromtheassociated
minimum-phaseFI R latticefilter coefficients k.
' max' : Producesamaximum-phaseFI R filter numerator fromtheassociated
maximum-phaseFI R latticefilter coefficients k.
' FI R' : Produces a general FI R filter numerator fromthelatticefilter
coefficients k (default, if you leaveoff thestringaltogether).
See Also
l at cf i l t Latticeand lattice-ladder filter implementation.
t f 2l at c Convert transfer function filter parameters tolattice
filter form.
latcfilt
7-243
7latcfilt
Purpose Latticeand lattice-ladder filter implementation.
Syntax [ f , g] = l at cf i l t ( k, x)
[ f , g] = l at cf i l t ( k, v, x)
[ f , g] = l at cf i l t ( k, 1, x)
[ f , g, zf ] = l at cf i l t ( . . . , ' i c' , zi )
Description When filteringdata, latticecoefficients can beused torepresent:
FI R filters
All-poleI I R filters
Allpass I I R filters
General I I R filters
[ f , g] = l at cf i l t ( k, x) filters x with theFI R latticecoefficients in the
vector k. f is theforwardlatticefilter result andg is thebackwardfilter result.
I f , f correspondstotheminimum-phaseoutput, andgcorrespondstothe
maximum-phaseoutput.
I f k and x arevectors, theresult is a (signal) vector. Matrix arguments are
permitted under thefollowingrules:
I f x is a matrix and k is a vector, each column of x is processed through the
latticefilter specified by k.
I f x is a vector and k is a matrix, each column of k is used tofilter x, and a
signal matrix is returned.
I f x and k areboth matrices with thesamenumber of columns, then theith
column of k is used tofilter theith column of x. A signal matrix is returned.
[ f , g] = l at cf i l t ( k, v, x) filters x with theI I R latticecoefficients k and
ladder coefficients v. k and v must bevectors, whilex can bea signal matrix.
[ f , g] = l at cf i l t ( k, 1, x) filters x with theI I R latticespecifiedby k, wherek
andx can bevectors or matrices. f is theall-polelatticefilter result andg isthe
allpass filter result.
[ f , g, zf ] = l at cf i l t ( . . . , ' i c' , zi ) accepts a length-k vector zi specifying
theinitial condition of thelatticestates. Output zf is a length-k vector
specifyingthefinal condition of thelatticestates.
k 1
latcfilt
7-244
See Also
f i l t er Filter data with a recursive(I I R) or nonrecursive
(FI R) filter.
l at c2t f Convert latticefilter parameters totransfer function
form.
t f 2l at c Convert transfer function filter parameters tolattice
filter form.
levinson
7-245
7levinson
Purpose ComputetheLevinson-Durbin recursion.
Syntax a = l evi nson( r , p)
Description TheLevinson-Durbin recursion isanalgorithmfor findingan all-poleI I R filter
withaprescribeddeterministicautocorrelationsequence. I t hasapplicationsin
filter design, coding, andspectral estimation. Thefilter that l evi nsonproduces
is minimumphase.
a = l evi nson( r , p) finds thecoefficients of an pth-order autoregressivelinear
process which has r as its autocorrelation sequence. r is a real or complex
deterministic autocorrelation sequence(a vector), and p is theorder of
denominator polynomial A(z); that is, a = [ 1 a( 2) . . . a( p+1) ] . Thefilter
coefficients areordered in descendingpowers of z.
Algorithm l evi nson solves thesymmetric Toeplitz systemof linear equations
wherer = [ r(1) ... r(p+1)] is theinput autocorrelation vector, and r(i)
*
denotes thecomplexconjugateof r(i). ThealgorithmrequiresO(p
2
) flops andis
thus much moreefficient than theMATLAB \ command for largep. However,
thel evi nson function uses \ for loworders toprovidethefastest possible
execution.
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 ( )


r p ( ) L r 2 ( ) r 1 ( )
a 2 ( )
a 3 ( )

a p 1 + ( )
r 2 ( )
r 3 ( )

r p 1 + ( )
=
levinson
7-246
See Also
References [1] Ljung, L., SystemI dentification: Theory for theUser, Prentice-Hall, 1987,
pp. 278-280.
l pc Computelinear prediction filter coefficients.
pr ony Pronys method for timedomain I I R filter design.
r l evi nson ComputethereverseLevinson-Durbin recursion.
schur r c Computereflection coefficients usingSchurs
algorithm.
st mcb Computea linear model usingSteiglitz-McBride
iteration.
lp2bp
7-247
7lp2bp
Purpose Transformlowpass analogfilters tobandpass.
Syntax [ bt , at ] = l p2bp( b, a, Wo, Bw)
[ At , Bt , Ct , Dt ] = l p2bp( A, B, C, D, Wo, Bw)
Description l p2bp transforms analoglowpass filter prototypes with a cutoff frequency of
1 rad/sintobandpassfilterswithdesiredbandwidthandcenter frequency. The
transformation is onestep in thedigital filter design process for thebut t er ,
cheby1, cheby2, and el l i p functions.
l p2bp can performthetransformation on twodifferent linear system
representations: transfer functionformandstate-spaceform. I nbothcases, the
input systemmust bean analogfilter prototype.
Transfer Function Form (Polynomial)
[ bt , at ] = l p2bp( b, a, Wo, Bw) transforms an analoglowpass filter prototype
given bypolynomial coefficients intoabandpass filter with center frequencyWo
andbandwidthBw. Rowvectorsbanda specifythecoefficientsof thenumerator
and denominator of theprototypein descendingpowers of s.
Scalars Wo andBwspecifythecenter frequencyandbandwidth in units of rad/s.
For a filter with lower band edgew1 and upper band edgew2, use
Wo =sqr t ( w1*w2) and Bw=w2- w1.
l p2bp returns thefrequency transformed filter in rowvectors bt and at .
State-Space Form
[ At , Bt , Ct , Dt ] = l p2bp( A, B, C, D, Wo, Bw) converts thecontinuous-time
state-spacelowpass filter prototypein matrices A, B, C, Dshown below
b s ( )
a s ( )
----------
b 1 ( )s
nb
L b nb ( )s b nb 1 + ( ) + + +
a 1 ( )s
na
L a na ( )s a na 1 + ( ) + + +
--------------------------------------------------------------------------------------- =
x

Ax Bu + =
y Cx Du + =
lp2bp
7-248
intoa bandpass filter with center frequency Wo and bandwidth Bw. For a filter
with lower band edgew1 and upper band edgew2, useWo =sqr t ( w1*w2) and
Bw=w2- w1.
Thebandpass filter is returned in matrices At , Bt , Ct , Dt .
Algorithm l p2bp is a highly accuratestate-spaceformulation of theclassic analogfilter
frequency transformation. Consider thestate-spacesystem
whereu is theinput, x is thestatevector, and y is theoutput. TheLaplace
transformof thefirst equation (assumingzeroinitial conditions) is
Nowif a bandpass filter is tohavecenter frequency
0
and bandwidth B
w
, the
standard s-domain transformation is
whereQ =
0
/B
w
and p =s/
0
. Substitutingthis for s in theLaplace
transformed state-spaceequation, and consideringtheoperator p as d/dt
results in
or
Nowdefine
which, when substituted, leads to
x

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

Qx + A

x Bu

+ =
Qx

x B u

Qx =
Q

Qx =
Qx

Ax Q Bu + + =
lp2bp
7-249
Thelast twoequations giveequations of state. Writethemin standard form
and multiply thedifferential equations by
0
torecover thetime/frequency
scalingrepresented by p and find statematrices for thebandpass filter.
Q = Wo/ Bw; [ ma, na] = si ze( A) ;
At = Wo*[ A/ Q eye( ma, na) ; - eye( ma, na) zer os( ma, na) ] ;
Bt = Wo*[ B/ Q; zer os( ma, nb) ] ;
Ct = [ C zer os( mc, ma) ] ;
Dt = d;
I f theinput tol p2bp isintransfer functionform, thefunctiontransformsit into
state-spaceformbeforeapplyingthis algorithm.
See Also
bi l i near Bilinear transformation method for analog-to-digital
filter conversion.
i mpi nvar I mpulseinvariancemethodfor analog-to-digital filter
conversion.
l p2bs Transformlowpass analogfilters tobandstop.
l p2hp Transformlowpass analogfilters tohighpass.
l p2l p Changethecut-off frequency for a lowpass analog
filter.
lp2bs
7-250
7lp2bs
Purpose Transformlowpass analogfilters tobandstop.
Syntax [ bt , at ] = l p2bs( b, a, Wo, Bw)
[ At , Bt , Ct , Dt ] = l p2bs( A, B, C, D, Wo, Bw)
Description l p2bs transforms analoglowpass filter prototypes with a cutoff frequency of
1 rad/s intobandstopfilters with desiredbandwidth andcenter frequency. The
transformation is onestep in thedigital filter design process for thebut t er ,
cheby1, cheby2, and el l i p functions.
l p2bs can performthetransformation on twodifferent linear system
representations: transfer functionformandstate-spaceform. I nbothcases, the
input systemmust bean analogfilter prototype.
Transfer Function Form (Polynomial)
[ bt , at ] = l p2bs( b, a, Wo, Bw) transforms an analoglowpass filter prototype
given by polynomial coefficients intoabandstopfilter with center frequencyWo
andbandwidth Bw. Rowvectorsbanda specifythecoefficientsof thenumerator
and denominator of theprototypein descendingpowers of s.
Scalars Wo and Bwspecify thecenter frequency and bandwidth in units of
radians/second. For a filter with lower band edgew1 and upper band edgew2,
useWo =sqr t ( w1*w2) and Bw=w2- w1.
l p2bs returns thefrequency transformed filter in rowvectors bt and at .
State-Space Form
[ At , Bt , Ct , Dt ] = l p2bs( A, B, C, D, Wo, Bw) converts thecontinuous-time
state-spacelowpass filter prototypein matrices A, B, C, Dshown below
b s ( )
a s ( )
----------
b 1 ( )s
nb
L b nb ( )s b nb 1 + ( ) + + +
a 1 ( )s
na
L a na ( )s a na 1 + ( ) + + +
--------------------------------------------------------------------------------------- =
x

Ax Bu + =
y Cx Du + =
lp2bs
7-251
intoa bandstop filter with center frequency Wo and bandwidth Bw. For a filter
with lower band edgew1 and upper band edgew2, useWo =sqr t ( w1*w2) and
Bw=w2- w1.
Thebandstop filter is returned in matrices At , Bt , Ct , Dt .
Algorithm l p2bs is a highly accuratestate-spaceformulation of theclassic analogfilter
frequency transformation. I f a bandstop filter is tohavecenter frequency
0
and bandwidth B
w
, thestandard s-domain transformation is
whereQ =
0
/B
w
andp =s/
0
. Thestate-spaceversion of this transformation is
Q = Wo/ Bw;
At = [ Wo/ Q*i nv( A) Wo*eye( ma) ; - Wo*eye( ma) zer os( ma) ] ;
Bt = - [ Wo/ Q*( A B) ; zer os( ma, nb) ] ;
Ct = [ C/ A zer os( mc, ma) ] ;
Dt = D - C/ A*B;
Seel p2bp for a derivation of thebandpass version of this transformation.
See Also
s
p
Q p
2
1 + ( )
------------------------ =
bi l i near Bilinear transformation method of analog-to-digital
filter conversion.
i mpi nvar I mpulseinvariancemethod of analog-to-digital filter
conversion.
l p2bp Transformlowpass analogfilters tobandpass.
l p2hp Transformlowpass analogfilters tohighpass.
l p2l p Changethecut-off frequency for a lowpass filter.
lp2hp
7-252
7lp2hp
Purpose Transformlowpass analogfilters tohighpass.
Syntax [ bt , at ] = l p2hp( b, a, Wo)
[ At , Bt , Ct , Dt ] = l p2hp( A, B, C, D, Wo)
Description l p2hp transforms analoglowpass filter prototypes with a cutoff frequency of
1 rad/s intohighpass filters with desired cutoff frequency. Thetransformation
is onestep in thedigital filter design process for thebut t er , cheby1, cheby2,
and el l i p functions.
Thel p2hp function can performthetransformation on twodifferent linear
systemrepresentations: transfer function formand state-spaceform. I n both
cases, theinput systemmust bean analogfilter prototype.
Transfer Function Form (Polynomial)
[ bt , at ] = l p2hp( b, a, Wo) transforms an analoglowpass filter prototype
given by polynomial coefficients intoahighpass filter with cutoff frequency Wo.
Rowvectors b anda specify thecoefficients of thenumerator anddenominator
of theprototypein descendingpowers of s.
Scalar Wo specifies thecutoff frequency in units of radians/second. The
frequency transformed filter is returned in rowvectors bt and at .
State-Space Form
[ At , Bt , Ct , Dt ] = l p2hp( A, B, C, D, Wo) converts thecontinuous-time
state-spacelowpass filter prototypein matrices A, B, C, Dbelow
intoa highpass filter with cutoff frequency Wo. Thehighpass filter is returned
in matrices At , Bt , Ct , Dt .
b s ( )
a s ( )
----------
b 1 ( )s
nb
L b nb ( )s b nb 1 + ( ) + + +
a 1 ( )s
na
L a na ( )s a na 1 + ( ) + + +
--------------------------------------------------------------------------------------- =
x

Ax Bu + =
y Cx Du + =
lp2hp
7-253
Algorithm l p2hp is a highly accuratestate-spaceformulation of theclassic analogfilter
frequencytransformation. I f ahighpassfilter istohavecutoff frequency
0
, the
standard s-domain transformation is
Thestate-spaceversion of this transformation is
At = Wo*i nv( A) ;
Bt = - Wo*( A\ B) ;
Ct = C/ A;
Dt = D - C/ A*B;
Seel p2bp for a derivation of thebandpass version of this transformation.
See Also
s

0
p
------- =
bi l i near Bilinear transformation method for analog-to-digital
filter conversion.
i mpi nvar I mpulseinvariancemethodfor analog-to-digital filter
conversion.
l p2bp Transformlowpass analogfilters tobandpass.
l p2bs Transformlowpass analogfilters tobandstop.
l p2l p Changethecut-off frequency for lowpass analog
filters.
lp2lp
7-254
7lp2lp
Purpose Changethecut-off frequency for a lowpass analogfilter.
Syntax [ bt , at ] = l p2l p( b, a, Wo)
[ At , Bt , Ct , Dt ] = l p2l p( A, B, C, D, Wo)
Description l p2l p transforms an analoglowpass filter prototypewith a cutoff frequency of
1 rad/s intoa lowpass filter with any specified cutoff frequency. The
transformation is onestep in thedigital filter design process for thebut t er ,
cheby1, cheby2, and el l i p functions.
Thel p2l p function can performthetransformation on twodifferent linear
systemrepresentations: transfer function formand state-spaceform. I n both
cases, theinput systemmust bean analogfilter prototype.
Transfer Function Form (Polynomial)
[ bt , at ] = l p2l p( b, a, Wo) transforms an analoglowpass filter prototype
given by polynomial coefficients intoa lowpass filter with cutoff frequency Wo.
Rowvectors b anda specify thecoefficients of thenumerator anddenominator
of theprototypein descendingpowers of s.
Scalar Wo specifies thecutoff frequency in units of radians/second. l p2l p
returns thefrequency transformed filter in rowvectors bt and at .
State-Space Form
[ At , Bt , Ct , Dt ] = l p2l p( A, B, C, D, Wo) converts thecontinuous-time
state-spacelowpass filter prototypein matrices A, B, C, Dbelow
intoa lowpass filter with cutoff frequency Wo. l p2l p returns thelowpass filter
in matrices At , Bt , Ct , Dt .
b s ( )
a s ( )
----------
b 1 ( )s
nb
L b nb ( )s b nb 1 + ( ) + + +
a 1 ( )s
na
L a na ( )s a na 1 + ( ) + + +
--------------------------------------------------------------------------------------- =
x

Ax Bu + =
y Cx Du + =
lp2lp
7-255
Algorithm l p2l p is a highly accuratestate-spaceformulation of theclassic analogfilter
frequency transformation. I f alowpass filter is tohavecutoff frequency
0
, the
standard s-domain transformation is
Thestate-spaceversion of this transformation is
At = Wo*A;
Bt = Wo*B;
Ct = C;
Dt = D;
Seel p2bp for a derivation of thebandpass version of this transformation.
See Also
s p
0
=
bi l i near Bilinear transformation method for analog-to-digital
filter conversion.
i mpi nvar I mpulseinvariancemethodfor analog-to-digital filter
conversion.
l p2bp Transformlowpass analogfilters tobandpass.
l p2bs Transformlowpass analogfilters tobandstop.
l p2hp Transformlowpass analogfilters tohighpass.
lpc
7-256
7lpc
Purpose Computelinear prediction filter coefficients.
Syntax a = l pc( x, p)
Description l pc determines thecoefficients of aforwardlinear predictor by minimizingthe
prediction error in theleast squares sense. I t has applications in filter design
and speech coding.
a = l pc( x, p) finds thecoefficients of a pth-order linear predictor (FI R filter)
that predicts thecurrent valueof thereal-valued timeseries x based on past
samples.
p is theorder of theprediction filter polynomial, a =[ 1 a( 2) . . . a( p+1) ] . I f
p is unspecified, l pc uses as a default p =l engt h( x) - 1. I f x is a matrix
containinga separatesignal in each column, l pc returns a model estimatefor
each column in therows of matrix a.
Examples Estimatea data series usinga third-order forward predictor, and compareto
theoriginal signal.
First, createthesignal data as theoutput of an autoregressiveprocess driven
by whitenoise. Usethelast 4096 samples of theAR process output toavoid
start-up transients.
r andn( ' st at e' , 0) ;
noi se = r andn( 50000, 1) ; %Nor mal i zed whi t e Gaussi an noi se
x = f i l t er ( 1, [ 1 1/ 2 1/ 3 1/ 4] , noi se) ;
x = x( 45904: 50000) ;
Computethepredictor coefficients, estimated signal, prediction error, and
autocorrelation sequenceof theprediction error.
a = l pc( x, 3) ;
est _x = f i l t er ( [ 0 - a( 2: end) ] , 1, x) ; %Est i mat ed si gnal
e = x - est _x; %Pr edi ct i on er r or
[ acs, l ags] = xcor r ( e, ' coef f ' ) ; %ACS of pr edi ct i on er r or
x

n ( ) a 2 ( )x n 1 ( ) a 3 ( )x n 2 ( ) L a p 1 + ( )x n p ( ) =
lpc
7-257
Theprediction error, e(n), can beviewed as theoutput of theprediction error
filter A(z) shown below, whereH(z) is theoptimal linear predictor, x(n) is the
input signal, and is thepredicted signal.
Comparethepredicted signal totheoriginal signal.
pl ot ( 1: 97, x( 4001: 4097) , 1: 97, est _x( 4001: 4097) , ' - - ' ) ;
t i t l e( ' Or i gi nal Si gnal vs. LPC Est i mat e' ) ;
xl abel ( ' Sampl e Number ' ) ; yl abel ( ' Ampl i t ude' ) ; gr i d;
l egend( ' Or i gi nal Si gnal ' , ' LPC Est i mat e' )
Look at theautocorrelation of theprediction error.
pl ot ( l ags, acs) ;
t i t l e( ' Aut ocor r el at i on of t he Pr edi ct i on Er r or ' ) ;
xl abel ( ' Lags' ) ; yl abel ( ' Nor mal i zed Val ue' ) ; gr i d;
x

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

n ( )
x n ( )

+
e n ( )
PredictionError
A z ( )
0 10 20 30 40 50 60 70 80 90 100
3
2
1
0
1
2
3
4
5
Original Signal vs. LPC Estimate
Sample Number
A
m
p
l
i
t
u
d
e
Original Signal
LPC Estimate
lpc
7-258
Theprediction error is approximately whiteGaussian noise, as expected for a
third-order AR input process.
Algorithm l pc uses theautocorrelation method of autoregressive(AR) modelingtofind
thefilter coefficients. Thegeneratedfilter might not model theprocess exactly
even if thedata sequenceis truly an AR process of thecorrect order. This is
becausetheautocorrelation method implicitly windows thedata, that is, it
assumes that signal samples beyond thelength of x are0.
l pc computes theleast squares solution to
where
5000 4000 3000 2000 1000 0 1000 2000 3000 4000 5000
0.2
0
0.2
0.4
0.6
0.8
1
1.2
Autocorrelation of the Prediction Error
Lags
N
o
r
m
a
l
i
z
e
d

V
a
l
u
e
Xa b
X
x 1 ( ) 0 L 0
x 2 ( ) x 1 ( )
x 2 ( ) 0
x m ( ) x 1 ( )
0 x m ( ) x 2 ( )

0 L 0 x m ( )
= a
1
a 2 ( )

a p 1 + ( )
= b
1
0

0
= , ,
lpc
7-259
and mis thelength of x. Solvingtheleast squares problemvia thenormal
equations
leads totheYule-Walker equations
wherer = [ r(1) r(2) ... r(p+1)] is an autocorrelation estimatefor x computed
usingxcor r . TheYule-Walker equations aresolved in O(p
2
) flops by the
Levinson-Durbin algorithm(seel evi nson).
See Also
References [1] J ackson, L.B., Digital Filters and Signal Processing, Second Edition,
Kluwer Academic Publishers, 1989. pp. 255-257.
X
H
Xa X
H
b =
r 1 ( ) r 2 ( )* L r p ( )*
r 2 ( ) r 1 ( )
r 2 ( )*
r p ( ) L r 2 ( ) r 1 ( )
a 2 ( )
a 3 ( )

a p 1 + ( )
r 2 ( )
r 3 ( )

r p 1 + ( )
=
ar yul e Computean estimateof AR model parameters using
theYule-Walker method.
l evi nson ComputetheLevinson-Durbin recursion.
pr ony Pronys method for timedomain I I R filter design.
pyul ear Estimatethepower spectral density usingthe
Yule-Walker AR method.
st mcb Computea linear model usingSteiglitz-McBride
iteration.
lsf2poly
7-260
7lsf2poly
Purpose Convert linespectral frequencies toprediction filter coefficients.
Syntax a = l sf 2pol y( l sf )
Description a = l sf 2pol y( l sf ) returns a vector a containingtheprediction filter
coefficients froma vector l sf of linespectral frequencies (alsoknown as line
spectrumpairs).
Examples l sf = [ 0. 7842 1. 5605 1. 8776 1. 8984 2. 3593] ;
a = l sf 2pol y( l sf )
a =
1. 0000 0. 6148 0. 9899 0. 0001 0. 0031 - 0. 0081
See Also
References [1] Deller, J .R., J .G. Proakis, and J .H.L. Hansen, Discrete-TimeProcessingof
Speech Signals, Prentice-Hall, 1993.
[2] Rabiner, L.R., and R.W. Schafer, Digital Processingof Speech Signals,
Prentice-Hall, 1978.
ac2pol y Convert autocorrelation parameters toprediction
filter coefficients.
pol y2l sf Convert prediction filter coefficients tolinespectral
frequencies.
r c2pol y Convert reflection coefficients toprediction filter
coefficients.
maxflat
7-261
7maxflat
Purpose Generalized digital Butterworth filter design.
Syntax [ b, a, ] = maxf l at ( nb, na, Wn)
b = maxf l at ( nb, ' sym' , Wn)
[ b, a, b1, b2] = maxf l at ( nb, na, Wn)
[ . . . ] = maxf l at ( nb, na, Wn, ' desi gn_f l ag' )
Description [ b, a, ] = maxf l at ( nb, na, Wn) is alowpass Butterworth filter with numerator
anddenominator coefficients b anda of orders nb andna respectively. Wn is the
normalized cutoff frequency at which themagnituderesponseof thefilter is
equal to (approx. -3 dB). Wn must bebetween0and1, where1corresponds
totheNyquist frequency.
b = maxf l at ( nb, ' sym' , Wn) isasymmetricFI R Butterworthfilter. nb must be
even, and Wn is restricted toa subinterval of [0,1]. Thefunction raises an error
if Wn is specified outsideof this subinterval.
[ b, a, b1, b2] = maxf l at ( nb, na, Wn) returnstwopolynomialsb1 andb2whose
product is equal tothenumerator polynomial b (that is, b = conv( b1, b2) ).
b1 contains all thezeros at z =- 1, and b2 contains all theother zeros.
[ . . . ] = maxf l at ( nb, na, Wn, ' desi gn_f l ag' ) enablesyoutomonitor thefilter
design, where' desi gn_f l ag' is:
' t r ace' , for a textual display of thedesign tableused in thedesign
' pl ot s' , for plots of thefilters magnitude, group delay, and zeros and poles
' bot h' , for both thetextual display and plots
Examples nb = 10; na = 2; Wn = 0. 2;
[ b, a, b1, b2] = maxf l at ( nb, na, Wn, ' pl ot s' )
1 2
maxflat
7-262
Algorithm Themethod consists of theuseof formulae, polynomial root finding, and a
transformation of polynomial roots.
See Also
References [1] Selesnick, I .W., and C.S. Burrus, Generalized Digital Butterworth Filter
Design,Proceedingsof theI EEE I nt. Conf. Acoust., Speech, Signal Processing,
Vol. 3 (May 1996).
0 0.2 0.4 0.6 0.8 1
0
0.5
1
/
M
a
g
n
i
t
u
d
e
Frequency response
1 0 1
1
0.5
0
0.5
1
Real
I
m
a
g
i
n
a
r
y
Polezero plot
< deg 10
0 0.5 1
4
5
6
7
8
/
S
a
m
p
l
e
s
Group delay
but t er Butterworth analogand digital filter design.
f i l t er Filter data with a recursive(I I R) or nonrecursive
(FI R) filter.
f r eqz Computethefrequency responseof digital filters.
medfilt1
7-263
7medfilt1
Purpose One-dimensional median filtering.
Syntax y = medf i l t 1( x, n)
y = medf i l t 1( x, n, bl ksz)
Description y = medf i l t 1( x, n) applies an order n one-dimensional median filter to
vector x; thefunction considers thesignal tobe0 beyond theend points.
Output y has thesamelength as x.
For n odd, y( k) is themedian of x( k- ( n- 1) / 2: k+( n- 1) / 2) .
For n even, y( k) is themedian of x( k- n/ 2) , x( k- ( n/ 2) +1) , ..., x( k+( n/ 2) - 1) .
I n this case, medf i l t 1 sorts thenumbers, then takes theaverageof the
( n- 1) / 2 and ( ( n- 1) / 2) +1 elements.
Thedefault for n is 3.
y = medf i l t 1( x, n, bl ksz) uses a f or -loop tocomputebl ksz (block size)
output samples at a time. Usebl ksz <<l engt h( x) if you arelowon memory,
sincemedf i l t 1 uses a workingmatrix of sizen-by-bl ksz. By default,
bl ksz = l engt h( x) ; this provides thefastest execution if you havesufficient
memory.
I f x is a matrix, medf i l t 1 median filters its columns using
y( : , i ) = medf i l t 1( x( : , i ) , n, bl ksz)
in a loop over thecolumns of x.
See Also
References [1] Pratt, W.K., Digital I mageProcessing, J ohn Wiley & Sons, 1978,
pp. 330-333.
f i l t er Filter data with a recursive(I I R) or nonrecursive
(FI R) filter.
medf i l t 2 Two-dimensional median filtering(seetheI mage
ProcessingToolbox documentation).
medi an Median value(seetheMATLAB documentation).
modulate
7-264
7modulate
Purpose Modulation for communications simulation.
Syntax y = modul at e( x, f c, f s, ' met hod' )
y = modul at e( x, f c, f s, ' met hod' , opt )
[ y, t ] = modul at e( x, f c, f s)
Description y = modul at e( x, f c, f s, ' met hod' ) and
y = modul at e( x, f c, f s, ' met hod' , opt ) modulatethereal messagesignal x
withacarrier frequencyf c andsamplingfrequencyf s, usingoneof theoptions
listed belowfor ' met hod' . Notethat somemethods accept an option, opt .
amdsb- sc
or
am
Amplitudemodulation, doublesideband, suppressed carrier.
Multiplies x by a sinusoid of frequency f c.
y = x. *cos( 2*pi *f c*t )
amdsb- t c Amplitudemodulation, doublesideband, transmitted carrier.
Subtracts scalar opt fromx andmultiplies theresult by asinusoid
of frequency f c.
y = ( x- opt ) . *cos( 2*pi *f c*t )
I f theopt parameter is not present, modul at e uses a default of
mi n( mi n( x) ) sothat themessagesignal ( x- opt ) is entirely
nonnegativeand has a minimumvalueof 0.
amssb Amplitudemodulation, singlesideband. Multiplies x by a
sinusoidof frequencyf c andaddstheresult totheHilbert transform
of x multipliedby a phaseshifted sinusoidof frequency f c.
y =
x. *cos( 2*pi *f c*t ) +i mag( hi l ber t ( x) ) . *si n( 2*pi *f c*t )
This effectively removes theupper sideband.
modulate
7-265
f m Frequency modulation. Creates a sinusoid with instantaneous
frequency that varies with themessagesignal x.
y = cos( 2*pi *f c*t + opt *cumsum( x) )
cumsumis a rectangular approximation totheintegral of x.
modul at e uses opt as theconstant of frequency modulation. I f opt
is not present, modul at e uses a default of
opt = ( f c/ f s) *2*pi / ( max( max( x) ) )
sothemaximumfrequency excursion fromf c is f c Hz.
pm Phasemodulation. Creates a sinusoid of frequency f c whose
phasevaries with themessagesignal x.
y = cos( 2*pi *f c*t + opt *x)
modul at e uses opt as theconstant of phasemodulation. I f opt is
not present, modul at e uses a default of
opt = pi / ( max( max( x) ) )
sothemaximumphaseexcursion is radians.
pwm Pulse-width modulation. Creates a pulse-width modulated
signal fromthepulsewidths in x. Theelements of x must be
between 0 and 1, specifyingthewidth of each pulsein fractions of
a period. Thepulses start at thebeginningof each period, that is,
they areleft justified.
modul at e( x, f c, f s, ' pwm' , ' cent er ed' )
yields pulses centered at thebeginningof each period. y is length
l engt h( x) *f s/ f c.
pt m Pulsetimemodulation. Creates a pulsetimemodulated signal
fromthepulsetimes in x. Theelements of x must bebetween 0
and1, specifyingtheleft edgeof each pulsein fractions of aperiod.
opt is a scalar between 0 and 1 that specifies thelength of each
pulsein fractions of a period. Thedefault for opt is 0. 1. y is length
l engt h( x) *f s/ f c.
qam Quadratureamplitudemodulation. Creates a quadrature
amplitudemodulated signal fromsignals x and opt .
y = x. *cos( 2*pi *f c*t ) + opt . *si n( 2*pi *f c*t )
opt must bethesamesizeas x.
modulate
7-266
I f you donot specify ' met hod' , then modul at e assumes am. Except for thepwm
and pt mcases, y is thesamesizeas x.
I f x is an array, modul at e modulates its columns.
[ y, t ] = modul at e( x, f c, f s) returns theinternal timevector t that modul at e
uses in its computations.
See Also
demod Demodulation for communications simulation.
vco Voltagecontrolled oscillator.
pburg
7-267
7pburg
Purpose Estimatethepower spectral density usingtheBurgmethod.
Syntax Pxx = pbur g( x, p)
[ Pxx, w] = pbur g( x, p)
[ Pxx, w] = pbur g( x, p, nf f t )
[ Pxx, f ] = pbur g( x, p, nf f t , f s)
[ Pxx, f ] = pbur g( x, p, nf f t , f s, ' r ange' )
[ Pxx, w] = pbur g( x, p, nf f t , ' r ange' )
pbur g( . . . )
Description Pxx = pbur g( x, p) implements theBurgalgorithm, a parametric spectral
estimation method, andreturns Pxx, an estimateof thepower spectral density
(PSD) of thevector x. Theentries of x represent samples of a discrete-time
signal, and p is theinteger specifyingtheorder of an autoregressive(AR)
prediction model for thesignal, used in estimatingthePSD.
Thepower spectral density is calculated in units of power per radians per
sample. Real-valued inputs producefull power one-sided (in frequency) PSDs
(by default), whilecomplex-valued inputs producetwo-sided PSDs.
I n general, thelength of theFFT and thevalues of theinput x determinethe
length of Pxx and therangeof thecorrespondingnormalized frequencies. For
this syntax, the(default) FFT length is 256. Thefollowingtableindicates the
length of Pxx and therangeof thecorrespondingnormalized frequencies for
this syntax.
[ Pxx, w] = pbur g( x, p) alsoreturns w, a vector of frequencies at which the
PSD is estimated. Pxx andwhavethesamelength. Theunits for frequency are
rad/sample.
Table 7-9: PSD Vector Characteristics for an FFT Length of 256 (Default)
Real/ Complex
Input Data
Length of Pxx Range of the Corresponding
Normalized Frequencies
Real-valued 129 [0, ]
Complex-valued 256 [0, 2)
pburg
7-268
[ Pxx, w] = pbur g( x, p, nf f t ) usestheBurgmethodtoestimatethePSDwhile
specifyingthelength of theFFT with theinteger nf f t . I f you specify nf f t as
theempty vector [ ] , it takes thedefault valueof 256.
Thelength of Pxx andthefrequency rangefor wdependon nf f t andthevalues
of theinput x. Thefollowingtableindicates thelength of Pxx andthefrequency
rangefor win this syntax.
[ Pxx, f ] = pbur g( x, p, nf f t , f s) uses thesamplingfrequency f s specified as
aninteger in hertz (Hz) tocomputethePSDvector (Pxx) andthecorresponding
vector of frequencies (f ). I n this case, theunits for thefrequency vector are
in Hz. Thespectral density produced is calculated in units of power per Hz. I f
you specify f s as theempty vector [ ] , thesamplingfrequency defaults to1 Hz.
Thefrequency rangefor f depends on nf f t , f s, and thevalues of theinput x.
Thelength of Pxx is thesameas in thetableabove. Thefollowingtable
indicates thefrequency rangefor f for this syntax.
Table 7-10: PSD and Frequency Vector Characteristics
Real/ Complex
Input Data
nfft Even/ Odd Length of Pxx Range of w
Real-valued Even ( nf f t / 2 + 1) [0, ]
Real-valued Odd ( nf f t + 1) / 2 [0, )
Complex-valued Even or odd nf f t [0, 2)
Table 7-11: PSD and Frequency Vector Characteristics with fs Specified
Real/ Complex Input Data nfft Even/ Odd Range of f
Real-valued Even [ 0, f s/ 2]
Real-valued Odd [ 0, f s/ 2)
Complex-valued Even or odd [ 0, f s)
pburg
7-269
[ Pxx, f ] = pbur g( x, p, nf f t , f s, ' r ange' ) or
[ Pxx, w] = pbur g( x, p, nf f t , ' r ange' ) specifies therangeof frequency values
toincludein f or w. This syntax is useful when x is real. ' r ange' can beeither:
' t wosi ded' : Computethetwo-sided PSD over thefrequency range[ 0, f s) .
This is thedefault for determiningthefrequency rangefor complex-valued
x.
- I f you specify f s as theempty vector, [ ] , thefrequency rangeis [ 0, 1) .
- I f you dont specify f s, thefrequency rangeis [0, 2).
' onesi ded' : Computetheone-sidedPSDover thefrequencyrangesspecified
for real x. This is thedefault for determiningthefrequency rangefor
real-valued x.
Note You can put thestringargument ' r ange' anywherein theinput
argument list after p.
pbur g( . . . ) with nooutputs plots thepower spectral density in thecurrent
figurewindow. Thefrequency rangeon theplot is thesameas therangeof
output w(or f ) for a given set of parameters.
Examples BecausetheBurgmethod estimates thespectral density by fittingan AR
prediction model of a given order tothesignal, first generatea signal froman
AR (all-pole) model of agiven order. You can usef r eqz tocheck themagnitude
of thefrequency responseof your AR filter. This will giveyou an idea of what
toexpect when you estimatethePSD usingpbur g.
a = [ 1 - 2. 2137 2. 9403 - 2. 1697 0. 9606] ; %AR f i l t er coef f i ci ent s
f r eqz( 1, a) %AR f i l t er f r equency r esponse
t i t l e( ' AR Syst emFr equency Response' )
pburg
7-270
Nowgeneratetheinput signal x by filteringwhitenoisethrough theAR filter.
EstimatethePSDof x basedonafourth-order AR predictionmodel sinceinthis
caseweknowthat theoriginal AR systemmodel a has order 4.
r andn( ' st at e' , 1) ;
x = f i l t er ( 1, a, r andn( 256, 1) ) ; %AR syst emout put
pbur g( x, 4) %Four t h- or der est i mat e
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
200
150
100
50
0
50
100
Normalized Frequency ( rad/sample)
P
h
a
s
e

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

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

S
p
e
c
t
r
a
l

D
e
n
s
i
t
y

(
d
B
/

r
a
d
/
s
a
m
p
l
e
)
Burg PSD Estimate
pburg
7-271
Remarks Thepower spectral density is computed as thedistribution of power per unit
frequency.
This algorithmdepends on your selectingan appropriatemodel order for your
signal.
Algorithm Linear prediction filters can beused tomodel thesecond-order statistical
characteristicsof asignal. Theprediction filter output canbeusedtomodel the
signal when theinput is whitenoise.
TheBurgmethodfits an AR linear prediction filter model of thespecifiedorder
totheinput signal by minimizing(usingleast squares) thearithmeticmean of
theforward and backward prediction errors. Thespectral density is then
computed fromthefrequency responseof theprediction filter. TheAR filter
parameters areconstrained tosatisfy theLevinson-Durbin recursion.
See Also
ar bur g Computean estimateof AR model parameters using
theBurgmethod.
l pc Computelinear prediction filter coefficients.
pcov Estimatethepower spectral density usingthe
covariancemethod.
pei g Estimatethepseudospectrumusingtheeigenvector
method.
per i odogr am Estimatethepower spectral density usinga
periodogram.
pmcov Estimatethepower spectral density usingthe
modified covariancemethod.
pmt m Estimatethepower spectral density usingthe
multitaper method.
pmusi c EstimatethepseudospectrumusingtheMUSI C
algorithm.
pwel ch Estimatethepower spectral density usingWelchs
method.
psdpl ot Plot power spectral density data.
pyul ear Estimatethepower spectral density usingthe
Yule-Walker AR method.
pburg
7-272
References [1] Marple, S.L. Digital Spectral Analysis, EnglewoodCliffs, NJ , Prentice-Hall,
1987, Chapter 7.
[2] Stoica, P., andR.L. Moses, I ntroduction toSpectral Analysis, Prentice-Hall,
1997.
pcov
7-273
7pcov
Purpose Estimatethepower spectral density usingthecovariancemethod.
Syntax Pxx = pcov( x, p)
[ Pxx, w] = pcov( x, p)
[ Pxx, w] = pcov( x, p, nf f t )
[ Pxx, f ] = pcov( x, p, nf f t , f s)
[ Pxx, f ] = pcov( x, p, nf f t , f s, ' r ange' )
[ Pxx, w] = pcov( x, p, nf f t , ' r ange' )
pcov( . . . )
Description Pxx = pcov( x, p) implements thecovariancealgorithm, aparametricspectral
estimation method, andreturns Pxx, an estimateof thepower spectral density
(PSD) of thevector x. Theentries of x represent samples of a discrete-time
signal, andwherep istheinteger specifyingtheorder of anautoregressive(AR)
prediction model for thesignal, used in estimatingthePSD.
Thepower spectral density is calculated in units of power per radians per
sample. Real-valued inputs producefull power one-sided (in frequency) PSDs
(by default), whilecomplex-valued inputs producetwo-sided PSDs.
I n general, thelength of theFFT and thevalues of theinput x determinethe
length of Pxx and therangeof thecorrespondingnormalized frequencies. For
this syntax, the(default) FFT length is 256. Thefollowingtableindicates the
length of Pxx and therangeof thecorrespondingnormalized frequencies for
this syntax.
[ Pxx, w] = pcov( x, p) alsoreturns w, avector of frequencies at which thePSD
is estimated. Pxx and whavethesamelength. Theunits for frequency are
rad/sample.
Table 7-12: PSD Vector Characteristics for an FFT Length of 256 (Default)
Real/ Complex
Input Data
Length of Pxx Range of the Corresponding
Normalized Frequencies
Real-valued 129 [0, ]
Complex-valued 256 [0, 2)
pcov
7-274
[ Pxx, w] = pcov( x, p, nf f t ) uses thecovariancemethod toestimatethePSD
whilespecifyingthelengthof theFFT withtheinteger nf f t . I f youspecifynf f t
as theempty vector [ ] , it takes thedefault valueof 256.
Thelength of Pxx andthefrequency rangefor wdependon nf f t andthevalues
of theinput x. Thefollowingtableindicates thelength of Pxx andthefrequency
rangefor win this syntax.
[ Pxx, f ] = pcov( x, p, nf f t , f s) usesthesamplingfrequencyf s specifiedasan
integer in hertz (Hz) tocomputethePSD vector (Pxx) and thecorresponding
vector of frequencies (f ). I n this case, theunits for thefrequency vector are
in Hz. Thespectral density produced is calculated in units of power per Hz. I f
you specify f s as theempty vector [ ] , thesamplingfrequency defaults to1 Hz.
Thefrequency rangefor f depends on nf f t , f s, and thevalues of theinput x.
Thelength of Pxx is thesameas in thetableabove. Thefollowingtable
indicates thefrequency rangefor f for this syntax.
Table 7-13: PSD and Frequency Vector Characteristics
Real/ Complex
Input Data
nfft Even/ Odd Length of Pxx Range of w
Real-valued Even ( nf f t / 2 + 1) [0, ]
Real-valued Odd ( nf f t + 1) / 2 [0, )
Complex-valued Even or odd nf f t [0, 2)
Table 7-14: PSD and Frequency Vector Characteristics with fs Specified
Real/ Complex Input Data nfft Even/ Odd Range of f
Real-valued Even [ 0, f s/ 2]
Real-valued Odd [ 0, f s/ 2)
Complex-valued Even or odd [ 0, f s)
pcov
7-275
[ Pxx, f ] = pcov( x, p, nf f t , f s, ' r ange' ) or
[ Pxx, w] = pcov( x, p, nf f t , ' r ange' ) specifies therangeof frequency values
toincludein f or w. This syntax is useful when x is real. ' r ange' can beeither:
' t wosi ded' : Computethetwo-sided PSD over thefrequency range[ 0, f s) .
This is thedefault for determiningthefrequency rangefor
complex-valued x.
- I f you specify f s as theempty vector, [ ] , thefrequency rangeis [ 0, 1) .
- I f you dont specify f s, thefrequency rangeis [0, 2).
' onesi ded' : Computetheone-sidedPSDover thefrequencyrangesspecified
for real x. This is thedefault for determiningthefrequency rangefor
real-valued x.
Note You can put thestringargument ' r ange' anywherein theinput
argument list after p.
pcov( . . . ) with nooutputs plots thepower spectral density in thecurrent
figurewindow. Thefrequency rangeon theplot is thesameas therangeof
output w(or f ) for a given set of parameters.
Examples Becausethecovariancemethodestimates thespectral density byfittingan AR
prediction model of a given order tothesignal, first generatea signal froman
AR (all-pole) model of agiven order. You can usef r eqz tocheck themagnitude
of thefrequency responseof your AR filter. This will giveyou an idea of what
toexpect when you estimatethePSD usingpcov.
a = [ 1 - 2. 2137 2. 9403 - 2. 1697 0. 9606] ; %AR f i l t er coef f i ci ent s
f r eqz( 1, a) %AR f i l t er f r equency r esponse
t i t l e( ' AR Syst emFr equency Response' )
pcov
7-276
Nowgeneratetheinput signal x by filteringwhitenoisethrough theAR filter.
EstimatethePSDof x basedonafourth-order AR predictionmodel sinceinthis
caseweknowthat theoriginal AR systemmodel a has order 4.
r andn( ' st at e' , 1) ;
x = f i l t er ( 1, a, r andn( 256, 1) ) ; %Si gnal gener at ed f r omAR f i l t er
pcov( x, 4) %Four t h- or der est i mat e
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
200
150
100
50
0
50
100
Normalized Frequency ( rad/sample)
P
h
a
s
e

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

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

S
p
e
c
t
r
a
l

D
e
n
s
i
t
y

(
d
B
/

r
a
d
/
s
a
m
p
l
e
)
Covariance PSD Estimate
pcov
7-277
Remarks Thepower spectral density is computed as thedistribution of power per unit
frequency.
This algorithmdepends on your selectingan appropriatemodel order for your
signal.
Algorithm Linear prediction filters can beused tomodel thesecond-order statistical
characteristicsof asignal. Theprediction filter output canbeusedtomodel the
signal when theinput is whitenoise.
Thecovariancemethod estimates thePSD of a signal usingthecovariance
method. Thecovariance(or nonwindowed) methodfits an AR linear prediction
filter model tothesignal by minimizingtheforwardprediction error (basedon
causal observations of your input signal) in theleast squares sense. The
spectral estimatereturned by pcov is thesquared magnitudeof thefrequency
responseof this AR model.
pcov
7-278
See Also
References [1] Marple, S.L. Digital Spectral Analysis, EnglewoodCliffs, NJ , Prentice-Hall,
1987, Chapter 7.
[2] Stoica, P., andR.L. Moses, I ntroduction toSpectral Analysis, Prentice-Hall,
1997.
ar cov Computean estimateof AR model parameters using
thecovariancemethod.
l pc Linear prediction coefficients.
pbur g Estimatethepower spectral density usingtheBurg
method.
pei g Estimatethepseudospectrumusingtheeigenvector
method.
per i odogr am Estimatethepower spectral density usinga
periodogram.
pmcov Estimatethepower spectral density usingthe
modified covariancemethod.
pmt m Estimatethepower spectral density usingthe
multitaper method.
pmusi c EstimatethepseudospectrumusingtheMUSI C
algorithm.
pr ony Pronys method for timedomain I I R filter design.
psdpl ot Plot power spectral density data.
pwel ch Estimatethepower spectral density usingWelchs
method.
pyul ear Estimatethepower spectral density usingthe
Yule-Walker AR method.
peig
7-279
7peig
Purpose Estimatethepseudospectrumusingtheeigenvector method.
Syntax [ S, w] = pei g( x, p)
[ S, w] = pei g( . . . , nf f t )
[ S, f ] = pei g( x, p, nf f t , f s)
[ S, f ] = pei g( . . . , ' corr' )
[ S, f ] = pei g( x, p, nf f t , f s, nwi n, nover l ap)
[ . . . ] = pei g( . . . , ' r ange' )
[ . . . , v, e] = pei g( . . . )
pei g( . . . )
Description [ S, w] = pei g( x, p) implements theeigenvector spectral estimation method
and returns S, thepseudospectrumestimateof theinput signal x, and w, a
vector of normalizedfrequencies (in rad/sample) at which thepseudospectrum
is evaluated. Thepseudospectrumis calculated usingestimates of the
eigenvectors of a correlation matrix associated with theinput data x, wherex
is specified as either:
A rowor column vector representingoneobservation of thesignal
A rectangular array for which each rowof x represents a separate
observation of thesignal (for example, each rowis oneoutput of an array of
sensors, as in array processing), such that x' *x is an estimateof the
correlation matrix
Note You can usetheoutput of cor r mt x togeneratesuch an array x.
You can specify thesecond input argument p as either:
A scalar integer. I n this case, thesignal subspacedimension is p.
A two-element vector. I n this case, p( 2) , thesecondelement of p, represents
a threshold that is multiplied by
min
, thesmallest estimated eigenvalueof
thesignals correlation matrix. Eigenvalues belowthethreshold
min
*p( 2)
areassignedtothenoisesubspace. I n this case, p( 1) specifies themaximum
dimension of thesignal subspace.
peig
7-280
Theextra threshold parameter in thesecond entry in p provides you more
flexibility and control in assigningthenoiseand signal subspaces.
S andwhavethesamelength. I n general, thelength of theFFT andthevalues
of theinput x determinethelength of thecomputed S and therangeof the
correspondingnormalizedfrequencies. Thefollowingtableindicatesthelength
of S (andw) and therangeof thecorrespondingnormalizedfrequencies for this
syntax.
[ S, w] = pei g( . . . , nf f t ) specifies thelength of theFFT used toestimatethe
pseudospectrumwith theinteger nf f t . Thedefault valuefor nf f t (entered as
an empty vector [ ] ) is 256.
Thefollowingtableindicates thelength of S and w, and thefrequency range
for wfor this syntax.
[ S, f ] = pei g( x, p, nf f t , f s) ) returns thepseudospectrumin thevector S
evaluated at thecorrespondingvector of frequencies f (in Hz). You supply the
samplingfrequency f s in Hz. I f you specify f s with theempty vector [ ] , the
samplingfrequency defaults to1 Hz.
Table 7-15: S Characteristics for an FFT Length of 256 (Default)
Real/ Complex
Input Data
Length of S and w Range of the Corresponding
Normalized Frequencies
Real-valued 129 [0, ]
Complex-valued 256 [0, 2)
Table 7-16: S and Frequency Vector Characteristics
Real/ Complex
Input Data
nfft Even/ Odd Length of S
and w
Range of w
Real-valued Even ( nf f t / 2 + 1) [0, ]
Real-valued Odd ( nf f t + 1) / 2 [0, )
Complex-valued Even or odd nf f t [0, 2)
peig
7-281
Thefrequency rangefor f depends on nf f t , f s, and thevalues of theinput x.
Thelength of S (and f ) is thesameas in Table7-16. Thefollowingtable
indicates thefrequency rangefor f for this syntax.
[ S, f ] = pei g( . . . , ' corr' ) forces theinput argument x tobeinterpretedas a
correlation matrix rather than matrix of signal data. For this syntaxx must be
a squarematrix, and all of its eigenvalues must benonnegative.
[ S, f ] = pei g( x, p, nf f t , f s, nwi n, nover l ap) allows you tospecify nwi n, a
scalar integer indicatinga rectangular windowlength, or a real-valued vector
specifyingwindowcoefficients. Usethescalar integer nover l ap in conjunction
with nwi n tospecify thenumber of input samplepoints by which successive
windows overlap. nover l ap is not used if x is a matrix. Thedefault valuefor
nwi n is 2*p( 1) and nover l ap is nwi n- 1.
With this syntax, theinput data x is segmented and windowed beforethe
matrix used toestimatethecorrelation matrix eigenvalues is formulated. The
segmentation of thedata depends on nwi n, nover l ap, and theformof x.
Comments on theresultingwindowedsegments aredescribed in thefollowing
table.
Table 7-17: S and Frequency Vector Characteristics with fs Specified
Real/ Complex Input Data nfft Even/ Odd Range of f
Real-valued Even [ 0, f s/ 2]
Real-valued Odd [ 0, f s/ 2)
Complex-valued Even or odd [ 0, f s)
Table 7-18: Windowed Data Depending on x and nwin
Input data x Form of nwin Windowed Data
Data vector Scalar Length is nwi n
Data vector Vector of coefficients Length is l engt h( nwi n)
peig
7-282
SeeTable7-19 for related information on this syntax.
Note Thearguments nwi n and nover l ap areignored when you includethe
string' corr' in thesyntax.
[ . . . ] = pei g( . . . , ' r ange' ) specifiestherangeof frequencyvaluestoinclude
in f or w. This syntax is useful when x is real. ' r ange' can beeither:
' whol e' : Computethepseudospectrumover thefrequency range[ 0, f s) .
Thisisthedefault for determiningthefrequencyrangefor complex-valuedx.
- I f you specify f s as theempty vector, [ ] , thefrequency rangeis [ 0, 1) .
- I f you dont specify f s, thefrequency rangeis [0, 2).
' hal f ' : Computethepseudospectrumover thefrequency ranges specified
for real x. This is thedefault for determiningthefrequency rangefor
real-valued x.
Note You can put thestringarguments ' r ange' or ' corr' anywherein the
input argument list after p.
[ . . . , v, e] = pei g( . . . ) returnsthematrixv of noiseeigenvectors, alongwith
theassociated eigenvalues in thevector e. Thecolumns of v span thenoise
subspaceof dimension si ze( v, 2) . Thedimension of thesignal subspaceis
si ze( v, 1) - si ze( v, 2) . For this syntax, e is a vector of estimated eigenvalues
of thecorrelation matrix.
Data matrix Scalar Data is not windowed.
Data matrix Vector of coefficients l engt h( nwi n) must bethe
sameas thecolumn length of x,
and nover l ap is not used.
Table 7-18: Windowed Data Depending on x and nwin (Continued)
Input data x Form of nwin Windowed Data
peig
7-283
pei g( . . . ) with nooutput arguments plots thepseudospectrumin thecurrent
figurewindow.
Remarks I n theprocess of estimatingthepseudospectrum, pei g computes thenoiseand
signal subspaces fromtheestimated eigenvectors v
j
and eigenvalues
j
of the
signals correlation matrix. Thesmallest of theseeigenvalues is used in
conjunction with thethreshold parameter p( 2) toaffect thedimension of the
noisesubspacein somecases.
Thelengthnof theeigenvectorscomputedbypei g isthesumof thedimensions
of thesignal and noisesubspaces. This eigenvector length depends on your
input (signal data or correlation matrix) and thesyntax you use.
Thefollowingtablesummarizes thedependency of theeigenvector length on
theinput argument.
You shouldspecifynwi n >p( 1) or l engt h( nwi n) >p( 1) if youwant p( 2) >1 to
haveany effect.
Table 7-19: Eigenvector Length Depending on Input Data and Syntax
Form of Input Data x Comments on the Syntax Length n of
Eigenvectors
Rowor column vector nwi n is specified as a scalar
integer.
nwi n
Rowor column vector nwi n is specified as a vector. l engt h( nwi n)
Rowor column vector nwi n is not specified. 2*p( 1)
l-by-mmatrix I f nwi n is specified as a
scalar, it is not used. I f nwi n
is specified as a vector,
l engt h( nwi n) must equal
m.
m
m-by-mnonnegative
definitematrix
Thestring' corr' is
specified and nwi n is not
used.
m
peig
7-284
Examples I mplement theeigenvector method tofind thepseudospectrumof thesumof
threesinusoids in noise, usingthedefault FFT length of 256. Usethemodified
covariancemethod for thecorrelation matrix estimate.
r andn( ' st at e' , 1) ; n=0: 99;
s=exp( i *pi / 2*n) +2*exp( i *pi / 4*n) +exp( i *pi / 3*n) +r andn( 1, 100) ;
X=cor r mt x( s, 12, ' mod' ) ;
pei g( X, 3, ' whol e' ) %Uses t he def aul t NFFT of 256.
Algorithm Theeigenvector method estimates thepseudospectrumfroma signal or a
correlation matrix usinga weighted version of theMUSI C algorithmderived
fromSchmidts eigenspaceanalysis method [1][2]. Thealgorithmperforms
eigenspaceanalysis of thesignals correlation matrix in order toestimatethe
signals frequency content. Theeigenvalues and eigenvectors of thesignals
correlation matrix areestimated usingsvd if you dont supply thecorrelation
matrix. This algorithmis particularly suitablefor signals that arethesumof
sinusoids with additivewhiteGaussian noise.
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8
15
10
5
0
5
10
15
20
25
30
Normalized Frequency ( rad/sample)
d
B
Eigenvector Method Pseudospectrum
peig
7-285
Theeigenvector method produces a pseudospectrumestimategiven by
whereN is thedimension of theeigenvectors and v
k
is thekth eigenvector of
thecorrelation matrix of theinput signal. Theinteger pis thedimension of the
signal subspace, sotheeigenvectors v
k
used in thesumcorrespond tothe
smallest eigenvalues of thecorrelation matrix. Theeigenvectors usedin the
PSD estimatespan thenoisesubspace. Thevector e(f) consists of complex
exponentials, sotheinner product
amounts toa Fourier transform. This is used for computation of thePSD
estimate. TheFFT is computed for each v
k
and then thesquared magnitudes
aresummed and scaled.
P
ev
f ( )
1
v
k
H
e f ( )
2
k p 1 + =
N

'


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

k
v
k
H
e f ( )
peig
7-286
See Also
References [1] Marple, S.L. Digital Spectral Analysis, EnglewoodCliffs, NJ , Prentice-Hall,
1987, pp. 373-378.
[2] Schmidt, R.O, MultipleEmitter Location and Signal Parameter
Estimation,I EEE Trans. Antennas Propagation, Vol. AP-34 (March 1986),
pp. 276-280.
[3] Stoica, P., andR.L. Moses, I ntroduction toSpectral Analysis, Prentice-Hall,
1997.
cor r mt x Calculatea data vector for correlation matrix
estimation.
pbur g Estimatethepower spectral density usingtheBurg
method.
per i odogr am Estimatethepower spectral density usinga
periodogram.
pmt m Estimatethepower spectral density usingthe
multitaper method.
pmusi c EstimatethepseudospectrumusingtheMUSI C
algorithm.
pr ony Pronys method for timedomain I I R filter design.
psdpl ot Plot power spectral density data.
pwel ch Estimatethepower spectral density usingWelchs
method.
r oot ei g Estimatethefrequency and power content usingthe
root eigenvector method.
r oot musi c Estimatethefrequency and power content usingthe
root MUSI C algorithm.
periodogram
7-287
7periodogram
Purpose Estimatethepower spectral density (PSD) of a signal usinga periodogram.
Syntax [ Pxx, w] = per i odogr am( x)
[ Pxx, w] = per i odogr am( x, wi ndow)
[ Pxx, w] = per i odogr am( x, wi ndow, nf f t )
[ Pxx, f ] = per i odogr am( x, wi ndow, nf f t , f s)
[ Pxx, . . . ] = per i odogr am( x, . . . , ' r ange' )
per i odogr am( . . . )
Description [ Pxx, w] = per i odogr am( x) returns thepower spectral density (PSD)
estimatePxx of thesequencex usinga periodogram. Thepower spectral
density is calculated in units of power per radians per sample. The
correspondingvector of frequencies wis computed in radians per sample, and
has thesamelength as Pxx.
A real-valuedinput vector x producesafull power one-sided(infrequency) PSD
(by default), whilea complex-valued x produces a two-sided PSD.
I n general, thelength N of theFFT andthevalues of theinput x determinethe
length of Pxx and therangeof thecorrespondingnormalized frequencies. For
this syntax, the(default) length N of theFFT is thelarger of 256and thenext
power of twogreater than thelength of x. Thefollowingtableindicates the
length of Pxx and therangeof thecorrespondingnormalized frequencies for
this syntax.
[ Pxx, w] = per i odogr am( x, wi ndow) returns thePSD estimatePxx computed
usingthemodified periodogrammethod. Thevector wi ndowspecifies the
coefficients of thewindowused in computinga modified periodogramof the
input signal. Both input arguments must bevectors of thesamelength. When
you dont supply thesecond argument wi ndow, or set it totheempty vector [ ] ,
Table 7-20: PSD Vector Characteristics for an FFT Length of N (Default)
Real/ Complex
Input Data
Length of Pxx Range of the Corresponding
Normalized Frequencies
Real-valued (N/2) +1 [0, ]
Complex-valued N [0, 2)
periodogram
7-288
a rectangular window(boxcar ) is used by default. I n this casethestandard
periodogramis calculated.
[ Pxx, w] = per i odogr am( x, wi ndow, nf f t ) uses themodified periodogramto
estimatethePSD whilespecifyingthelength of theFFT with theinteger nf f t .
I f you set nf f t totheempty vector [ ] , it takes thedefault valuefor N listed in
theprevious syntax.
Thelength of Pxx andthefrequency rangefor wdependon nf f t andthevalues
of theinput x. Thefollowingtableindicates thelength of Pxx andthefrequency
rangefor wfor this syntax.
Note per i odogr amuses an nf f t -point FFT of thewindowed data
(x. *wi ndow) tocomputetheperiodogram. I f thevalueyou specify for nf f t is
less than thelength of x, then x. *wi ndowis wrappedmodulonf f t . I f thevalue
you specify for nf f t is greater than thelength of x, then x. *wi ndowis
zero-padded tocomputetheFFT.
[ Pxx, f ] = per i odogr am( x, wi ndow, nf f t , f s) uses thesamplingfrequencyf s
specified as an integer in hertz (Hz) tocomputethePSD vector (Pxx) and the
correspondingvector of frequencies (f ). I n this case, theunitsfor thefrequency
vector arein Hz. Thespectral density produced is calculated in units of power
per Hz. I f you specify f s as theempty vector [ ] , thesamplingfrequency
defaults to1 Hz.
Table 7-21: PSD and Frequency Vector Characteristics
Real/ Complex
Input Data
nfft Even/ Odd Length of Pxx Range of w
Real-valued Even ( nf f t / 2 + 1) [0, ]
Real-valued Odd ( nf f t + 1) / 2 [0, )
Complex-valued Even or odd nf f t [0, 2)
periodogram
7-289
Thefrequency rangefor f depends on nf f t , f s, and thevalues of theinput x.
Thelength of Pxx is thesameas in thetableabove. Thefollowingtable
indicates thefrequency rangefor f for this syntax.
[ Pxx, f ] = per i odogr am( x, wi ndow, nf f t , f s, ' r ange' ) or
[ Pxx, w] = per i odogr am( x, wi ndow, nf f t , ' r ange' ) specifies therangeof
frequency values toincludein f or w. This syntax is useful when x is real.
' r ange' can beeither:
' t wosi ded' : Computethetwo-sided PSD over thefrequency range[ 0, f s) .
This is thedefault for determiningthefrequency rangefor
complex-valued x.
- I f you specify f s as theempty vector, [ ] , thefrequency rangeis [ 0, 1) .
- I f you dont specify f s, thefrequency rangeis [0, 2).
' onesi ded' : Computetheone-sidedPSDover thefrequencyrangesspecified
for real x. This is thedefault for determiningthefrequency rangefor
real-valued x.
Note You can put thestringargument ' r ange' anywherein theinput
argument list after wi ndow.
per i odogr am( . . . ) with nooutputs plots thepower spectral density in dB per
unit frequency in thecurrent figurewindow. Thefrequency rangeon theplot
is thesameas therangeof output w(or f ) for thesyntax you use.
Table 7-22: PSD and Frequency Vector Characteristics with fs Specified
Real/ Complex Input Data nfft Even/ Odd Range of f
Real-valued Even [ 0, f s/ 2]
Real-valued Odd [ 0, f s/ 2)
Complex-valued Even or odd [ 0, f s)
periodogram
7-290
Examples Computetheperiodogramof a200Hz signal embeddedin additivenoiseusing
thedefault window.
r andn( ' st at e' , 0) ;
Fs = 1000;
t = 0: 1/ Fs: . 3;
x = cos( 2*pi *t *200) +0. 1*r andn( si ze( t ) ) ;
per i odogr am( x, [ ] , ' t wosi ded' , 512, Fs)
Algorithm Theperiodogramfor a sequence[x
1
, ... , x
n
] is given by thefollowingformula.
This expression forms an estimateof thepower spectrumof thesignal defined
by thesequence[x
1
, ... , x
n
].
0 100 200 300 400 500 600 700 800 900
70
60
50
40
30
20
10
Frequency (Hz)
P
o
w
e
r

S
p
e
c
t
r
a
l

D
e
n
s
i
t
y

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

2
=
periodogram
7-291
I f youweight your signal sequencebyawindow[w
1
, ... , w
n
], then theweighted
or modified periodogramis defined as
I n either case, per i odogr amuses an nf f t -point FFT tocomputethepower
spectral density as , whereF is:
2 when you donot supply thesamplingfrequency
f s when you supply thesamplingfrequency
See Also
S e
j
( )
1
n
--- w
l
x
l
e
j l
l 1 =
n

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

--------------------------------------------- =
S e
j
( ) F
pbur g Estimatethepower spectral density usingtheBurg
method.
pcov Estimatethepower spectral density usingthe
covariancemethod.
pei g Estimatethepseudospectrumusingtheeigenvector
method.
pmcov Estimatethepower spectral density usingthe
modified covariancemethod.
pmt m Estimatethepower spectral density usingthe
multitaper method.
pmusi c EstimatethepseudospectrumusingtheMUSI C
algorithm.
psdpl ot Plot power spectral density data.
pwel ch Estimatethepower spectral density usingWelchs
method.
pyul ear Estimatethepower spectral density usingthe
Yule-Walker AR method.
periodogram
7-292
References [1] Stoica, P., andR.L. Moses, I ntroduction toSpectral Analysis, Prentice-Hall,
1997, pp. 24-26.
[2] Welch, P.D, TheUseof Fast Fourier Transformfor theEstimationof Power
Spectra: A Method Based on TimeAveragingOver Short, Modified
Periodograms,I EEE Trans. AudioElectroacoustics, Vol. AU-15 (J une1967),
pp. 70-73.
[3] Oppenheim, A.V., and R.W. Schafer, Discrete-TimeSignal Processing,
Prentice-Hall, 1989, pp. 730-742.
pmcov
7-293
7pmcov
Purpose Estimatethepower spectral density usingthemodified covariancemethod.
Syntax Pxx = pmcov( x, p)
[ Pxx, w] = pmcov( x, p)
[ Pxx, w] = pmcov( x, p, nf f t )
[ Pxx, f ] = pmcov( x, p, nf f t , f s)
[ Pxx, f ] = pmcov( x, p, nf f t , f s, ' r ange' )
[ Pxx, w] = pmcov( x, p, nf f t , ' r ange' )
pmcov( . . . )
Description Pxx = pmcov( x, p) implements themodified covariancealgorithm, a
parametric spectral estimation method, and returns Pxx, an estimateof the
power spectral density(PSD) of thevector x. Theentriesof x represent samples
of a discrete-timesignal, and p is theinteger specifyingtheorder of an
autoregressive(AR) prediction model for thesignal, used in estimatingthe
PSD.
Thepower spectral density is calculated in units of power per radians per
sample. Real-valued inputs producefull power one-sided (in frequency) PSDs
(by default), whilecomplex-valued inputs producetwo-sided PSDs.
I n general, thelength of theFFT and thevalues of theinput x determinethe
length of Pxx and therangeof thecorrespondingnormalized frequencies. For
this syntax, the(default) FFT length is 256. Thefollowingtableindicates the
length of Pxx and therangeof thecorrespondingnormalized frequencies for
this syntax.
[ Pxx, w] = pmcov( x, p) alsoreturns w, a vector of frequencies at which the
PSD is estimated. Pxx andwhavethesamelength. Theunits for frequency are
rad/sample.
Table 7-23: PSD Vector Characteristics for an FFT Length of 256 (Default)
Real/ Complex
Input Data
Length of Pxx Range of the Corresponding
Normalized Frequencies
Real-valued 129 [0, ]
Complex-valued 256 [0, 2)
pmcov
7-294
[ Pxx, w] = pmcov( x, p, nf f t ) uses thecovariancemethodtoestimatethePSD
whilespecifyingthelengthof theFFT withtheinteger nf f t . I f youspecifynf f t
as theempty vector [ ] , it takes thedefault valueof 256.
Thelength of Pxx andthefrequency rangefor wdependon nf f t andthevalues
of theinput x. Thefollowingtableindicates thelength of Pxx andthefrequency
rangefor wfor this syntax.
[ Pxx, f ] = pmcov( x, p, nf f t , f s) uses thesamplingfrequency f s specified as
aninteger in hertz (Hz) tocomputethePSDvector (Pxx) andthecorresponding
vector of frequencies (f ). I n this case, theunits for thefrequency vector are
in Hz. Thespectral density produced is calculated in units of power per Hz. I f
you specify f s as theempty vector [ ] , thesamplingfrequency defaults to1 Hz.
Thefrequency rangefor f depends on nf f t , f s, and thevalues of theinput x.
Thelengthof Pxx isthesameasinTable7-24. Thefollowingtableindicatesthe
frequency rangefor f in this syntax.
Table 7-24: PSD and Frequency Vector Characteristics
Real/ Complex
Input Data
nfft Even/ Odd Length of Pxx Range of w
Real-valued Even ( nf f t / 2 + 1) [0, ]
Real-valued Odd ( nf f t + 1) / 2 [0, )
Complex-valued Even or odd nf f t [0, 2)
Table 7-25: PSD and Frequency Vector Characteristics with fs Specified
Real/ Complex Input Data nfft Even/ Odd Range of f
Real-valued Even [ 0, f s/ 2]
Real-valued Odd [ 0, f s/ 2)
Complex-valued Even or odd [ 0, f s)
pmcov
7-295
[ Pxx, f ] = pmcov( x, p, nf f t , f s, ' r ange' ) or
[ Pxx, w] = pmcov( x, p, nf f t , ' r ange' ) specifies therangeof frequency values
toincludein f or w. This syntax is useful when x is real. ' r ange' can beeither:
' t wosi ded' : Computethetwo-sided PSD over thefrequency range[ 0, f s) .
This is thedefault for determiningthefrequency rangefor
complex-valued x.
- I f you specify f s as theempty vector, [ ] , thefrequency rangeis [ 0, 1) .
- I f you dont specify f s, thefrequency rangeis [0, 2).
' onesi ded' : Computetheone-sidedPSDover thefrequencyrangesspecified
for real x. This is thedefault for determiningthefrequency rangefor
real-valued x.
Note You can put thestringargument ' r ange' anywherein theinput
argument list after p.
pmcov( . . . ) with nooutputs plots thepower spectral density in thecurrent
figurewindow. Thefrequency rangeon theplot is thesameas therangeof
output w(or f ) for a given set of parameters.
Examples Becausethemodified covariancemethod estimates thespectral density by
fittingan AR prediction model of a given order tothesignal, first generatea
signal froman AR (all-pole) model of agiven order. You can usef r eqz tocheck
themagnitudeof thefrequencyresponseof your AR filter. Thiswill giveyouan
idea of what toexpect when you estimatethePSD usingpmcov.
a = [ 1 - 2. 2137 2. 9403 - 2. 1697 0. 9606] ; %AR f i l t er coef f i ci ent s
f r eqz( 1, a) %AR f i l t er f r equency r esponse
t i t l e( ' AR Syst emFr equency Response' )
pmcov
7-296
Nowgeneratetheinput signal x by filteringwhitenoisethrough theAR filter.
EstimatethePSDof x basedonafourth-order AR predictionmodel sinceinthis
caseweknowthat theoriginal AR systemmodel a has order 4.
r andn( ' st at e' , 1) ;
x = f i l t er ( 1, a, r andn( 256, 1) ) ; %AR f i l t er out put
pmcov( x, 4) %Four t h- or der est i mat e
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
200
150
100
50
0
50
100
Normalized Frequency ( rad/sample)
P
h
a
s
e

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

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

S
p
e
c
t
r
a
l

D
e
n
s
i
t
y

(
d
B
/

r
a
d
/
s
a
m
p
l
e
)
Modified Covariance PSD Estimate
pmcov
7-297
Remarks Thepower spectral density is computed as thedistribution of power per unit
frequency.
This algorithmdepends on your selectingan appropriatemodel order for your
signal.
Algorithm Linear prediction filters can beused tomodel thesecond-order statistical
characteristicsof asignal. Theprediction filter output canbeusedtomodel the
signal when theinput is whitenoise.
pmcov estimates thePSD of thesignal vector usingthemodified covariance
method. This method fits an autoregressive(AR) linear prediction filter model
tothesignal by simultaneously minimizingtheforward and backward
prediction errors (based on causal observations of your input signal) in the
least squares sense. Thespectral estimatereturnedby pmcov is themagnitude
squared frequency responseof this AR model.
pmcov
7-298
See Also
References [1] Marple, S.L. Digital Spectral Analysis, EnglewoodCliffs, NJ , Prentice-Hall,
1987, Chapter 7.
[2] Stoica, P., andR.L. Moses, I ntroduction toSpectral Analysis, Prentice-Hall,
1997.
ar mcov Computean estimateof AR model parameters using
themodified covariancemethod.
l pc Linear prediction coefficients.
pbur g Estimatethepower spectral density usingtheBurg
method.
pcov Estimatethepower spectral density usingthe
covariancemethod.
pei g Estimatethepseudospectrumusingtheeigenvector
method.
per i odogr am Estimatethepower spectral density usinga
periodogram.
pmt m Estimatethepower spectral density usingthe
multitaper method.
pmusi c EstimatethepseudospectrumusingtheMUSI C
algorithm.
pr ony Pronys method for timedomain I I R filter design.
psdpl ot Plot power spectral density data.
pwel ch Estimatethepower spectral density usingWelchs
method.
pyul ear Estimatethepower spectral density usingthe
Yule-Walker AR method.
pmtm
7-299
7pmtm
Purpose Estimatethepower spectral density usingthemultitaper method (MTM).
Syntax [ Pxx, w] = pmt m( x, nw)
[ Pxx, w] = pmt m( x, nw, nf f t )
[ Pxx, f ] = pmt m( x, nw, nf f t , f s)
[ Pxx, Pxxc, f ] = pmt m( x, nw, nf f t , f s)
[ Pxx, Pxxc, f ] = pmt m( x, nw, nf f t , f s, p)
[ Pxx, Pxxc, f ] = pmt m( x, e, v, nf f t , f s, p)
[ Pxx, Pxxc, f ] = pmt m( x, dpss_par ams, nf f t , f s, p)
[ . . . ] = pmt m( . . . , ' met hod' )
[ . . . ] = pmt m( . . . , ' r ange' )
pmt m( . . . )
Description pmt mestimates thepower spectral density (PSD) of thetimeseries xusingthe
multitaper method (MTM) described in [1]. This method uses linear or
nonlinear combinations of modified periodograms toestimatethePSD. These
periodograms arecomputedusingasequenceof orthogonal tapers (windows in
thefrequencydomain) specifiedfromthediscreteprolatespheroidal sequences
(seedpss).
[ Pxx, w] = pmt m( x, nw) estimates thePSD Pxx for theinput signal x, using
2*nw- 1 discreteprolatespheroidal sequences as datatapers for themultitaper
estimation method. nwis thetime-bandwidth product for thediscreteprolate
spheroidal sequences. I f you specify nwas theempty vector [ ] , a default value
of 4 is used. Other typical choices are2, 5/2, 3, or 7/2. pmt malsoreturns w, a
vector of frequencies at which thePSD is estimated. Pxx and whavethesame
length. Theunits for frequency arerad/sample.
Thepower spectral density is calculated in units of power per radians per
sample. Real-valued inputs produce(by default) full power one-sided (in
frequency) PSDs, whilecomplex-valued inputs producetwo-sided PSDs.
I n general, thelength N of theFFT andthevalues of theinput x determinethe
length of Pxx and therangeof thecorrespondingnormalized frequencies. For
this syntax, the(default) length N of theFFT is thelarger of 256and thenext
power of twogreater than thelength of thesegment. Thefollowingtable
pmtm
7-300
indicates thelength of Pxx and therangeof thecorrespondingnormalized
frequencies for this syntax.
[ Pxx, w] = pmt m( x, nw, nf f t ) uses themultitaper methodtoestimatethePSD
whilespecifyingthelengthof theFFT withtheinteger nf f t . I f youspecifynf f t
as theempty vector [ ] , it adopts thedefault valuefor N described in the
previous syntax.
Thelength of Pxx andthefrequency rangefor wdependon nf f t andthevalues
of theinput x. Thefollowingtableindicates thelength of Pxx andthefrequency
rangefor wfor this syntax.
[ Pxx, f ] = pmt m( x, nw, nf f t , f s) uses thesamplingfrequency f s specified as
aninteger in hertz (Hz) tocomputethePSDvector (Pxx) andthecorresponding
vector of frequencies (f ). I n this case, theunits for thefrequency vector f are
in Hz. Thespectral density produced is calculated in units of power per Hz. I f
you specify f s as theempty vector [ ] , thesamplingfrequency defaults to1 Hz.
Table 7-26: PSD Vector Characteristics for an FFT Length of N (Default)
Real/ Complex
Input Data
Length of Pxx Range of the Corresponding
Normalized Frequencies
Real-valued (N/2) +1 [0, ]
Complex-valued N [0, 2)
Table 7-27: PSD and Frequency Vector Characteristics
Real/ Complex
Input Data
nfft Even/ Odd Length of Pxx Range of w
Real-valued Even (nf f t /2 +1) [0, ]
Real-valued Odd (nf f t +1)/2 [0, )
Complex-valued Even or odd nf f t [0, 2)
pmtm
7-301
Thefrequency rangefor f depends on nf f t , f s, and thevalues of theinput x.
Thelengthof Pxx isthesameasinTable7-27. Thefollowingtableindicatesthe
frequency rangefor f for this syntax.
[ Pxx, Pxxc, f ] = pmt m( x, nw, nf f t , f s) returns Pxxc, the95%confidence
interval for Pxx. Confidenceintervals arecomputed usinga chi-squared
approach. Pxxc is a two-column matrix with thesamenumber of rows as Pxx.
Pxxc( : , 1) is thelower bound of theconfidenceinterval and Pxxc( : , 2) is the
upper bound of theconfidenceinterval.
[ Pxx, Pxxc, f ] = pmt m( x, nw, nf f t , f s, p) returns Pxxc, thep*100%confidence
interval for Pxx, wherep is a scalar between 0 and 1. I f you dont specify p, or
if you specify p as theempty vector [ ] , thedefault 95%confidenceinterval is
used.
[ Pxx, Pxxc, f ] = pmt m( x, e, v, nf f t , f s, p) returns thePSD estimatePxx, the
confidenceinterval Pxxc, and thefrequency vector f fromthedata tapers
contained in thecolumns of thematrix e, and their concentrations in the
vector v. Thelength of v is thesameas thenumber of columns in e. You can
obtain thedata tosupply as thesearguments fromtheoutputs of dpss.
[ Pxx, Pxxc, f ] = pmt m( x, dpss_par ams, nf f t , f s, p) uses thecell array
dpss_par ams containingtheinput arguments todpss (listed in order, but
excludingthefirst argument) tocomputethedata tapers. For example,
pmt m( x, {3. 5, ' t r ace' }, 512, 1000) calculates theprolatespheroidal
sequences for nw=3. 5, usingnf f t =512, and f s =1000, and displays the
method that dpss uses for this calculation. Seedpss for other options.
Table 7-28: PSD and Frequency Vector Characteristics with fs Specified
Real/ Complex Input Data nfft Even/ Odd Range of f
Real-valued Even [ 0, f s/ 2]
Real-valued Odd [ 0, f s/ 2)
Complex-valued Even or odd [0, f s)
pmtm
7-302
[ . . . ] = pmt m( . . . , ' met hod' ) specifies thealgorithmused for combiningthe
individual spectral estimates. Thestring' met hod' can beoneof thefollowing:
' adapt ' : Thomsons adaptivenonlinear combination (default)
' uni t y' : A linear combination of theweighted periodograms with unity
weights
' ei gen' : A linear combination of theweighted periodograms with
eigenvalueweights
[ . . . ] = pmt m( . . . , ' r ange' ) specifiestherangeof frequencyvaluestoinclude
in f or w. This syntax is useful when x is real. ' r ange' can beeither:
' t wosi ded' : Computethetwo-sided PSD over thefrequency range[ 0, f s) .
This is thedefault for determiningthefrequency rangefor complex-valued
x.
- I f you specify f s as theempty vector, [ ] , thefrequency rangeis [ 0, 1) .
- I f you dont specify f s, thefrequency rangeis [0, 2).
' onesi ded' : Computetheone-sidedPSDover thefrequencyrangesspecified
for real x. This is thedefault for determiningthefrequency rangefor
real-valued x.
Note You can put thestringarguments ' r ange' or ' met hod' anywhereafter
theinput argument nwor v.
pmt m( . . . ) with nooutput arguments plots thePSD estimateand the
confidenceintervals in thecurrent figurewindow. I f you dont specify f s, the
95%confidenceinterval isplotted. I f you dospecifyf s, theconfidenceintervals
plotted depend on thevalueof p.
pmtm
7-303
Examples This exampleanalyzes a sinusoid in whitenoise.
r andn( ' st at e' , 0) ;
f s = 1000; t = 0: 1/ f s: 0. 3;
x = cos( 2*pi *t *200) + 0. 1*r andn( si ze( t ) ) ;
[ Pxx, Pxxc, f ] = pmt m( x, 3. 5, 512, f s, 0. 99) ;
psdpl ot ( [ Pxx Pxxc] , f , ' hz' , ' db' )
t i t l e( ' PMTM PSD Est i mat e wi t h 99%Conf i dence I nt er val s' )
0 50 100 150 200 250 300 350 400 450 500
70
60
50
40
30
20
10
Frequency (Hz)
P
o
w
e
r

S
p
e
c
t
r
a
l

D
e
n
s
i
t
y

(
d
B
/
H
z
)
PMTM PSD Estimate with 99% Confidence Intervals
pmtm
7-304
See Also
References [1] Percival, D.B., and A.T. Walden, Spectral Analysis for Physical
Applications: Multitaper and Conventional UnivariateTechniques, Cambridge
University Press, 1993.
[2] Thomson, D.J ., Spectrumestimation andharmonicanalysis,Proceedings
of theI EEE, Vol. 70 (1982), pp. 1055-1096.
dpss Computethediscreteprolatespheroidal sequences
(Slepian sequences).
pbur g Estimatethepower spectral density usingtheBurg
method.
pcov Estimatethepower spectral density usingthe
covariancemethod.
pei g Estimatethepseudospectrumusingtheeigenvector
method.
per i odogr am Estimatethepower spectral density usinga
periodogram.
pmcov Estimatethepower spectral density usingthe
modified covariancemethod.
pmusi c EstimatethepseudospectrumusingtheMUSI C
algorithm.
psdpl ot Plot power spectral density data.
pwel ch Estimatethepower spectral density usingWelchs
method.
pyul ear Estimatethepower spectral density usingthe
Yule-Walker AR method.
pmusic
7-305
7pmusic
Purpose EstimatethepseudospectrumusingtheMUSI C algorithm.
Syntax [ S, w] = pmusi c( x, p)
[ S, w] = pmusi c( . . . , nf f t )
[ S, f ] = pmusi c( x, p, nf f t , f s) )
[ S, f ] = pmusi c( . . . , ' corr' )
[ S, f ] = pmusi c( x, p, nf f t , f s, nwi n, nover l ap)
[ . . . ] = pmusi c( . . . , ' r ange' )
[ . . . , v, e] = pmusi c( . . . )
pmusi c( . . . )
Description [ S, w] = pmusi c( x, p) implementstheMUSI C(MultipleSignal Classification)
algorithmand returns S, thepseudospectrumestimateof theinput signal x,
and a vector wof normalized frequencies (in rad/sample) at which the
pseudospectrumis evaluated. Thepseudospectrumis calculated using
estimates of theeigenvectors of a correlation matrix associated with theinput
data x, wherex is specified as either:
A rowor column vector representingoneobservation of thesignal
A rectangular array for which each rowof x represents a separate
observation of thesignal (for example, each rowis oneoutput of an array of
sensors, as in array processing), such that x' *x is an estimateof the
correlation matrix
Note You can usetheoutput of cor r mt x togeneratesuch an array x.
You can specify thesecond input argument p as either:
A scalar integer. I n this case, thesignal subspacedimension is p.
A two-element vector. I n this case, p( 2) , thesecondelement of p, represents
a threshold that is multiplied by
min
, thesmallest estimated eigenvalueof
thesignals correlation matrix. Eigenvalues belowthethreshold
min
*p( 2)
areassignedtothenoisesubspace. I n this case, p( 1) specifies themaximum
dimension of thesignal subspace.
pmusic
7-306
Theextra threshold parameter in thesecond entry in p provides you more
flexibility and control in assigningthenoiseand signal subspaces.
S andwhavethesamelength. I n general, thelength of theFFT andthevalues
of theinput x determinethelength of thecomputed S and therangeof the
correspondingnormalizedfrequencies. Thefollowingtableindicatesthelength
of S (andw) and therangeof thecorrespondingnormalizedfrequencies for this
syntax.
[ S, w] = pmusi c( . . . , nf f t ) specifies thelength of theFFT used toestimate
thepseudospectrumwith theinteger nf f t . Thedefault valuefor nf f t (entered
as an empty vector [ ] ) is 256.
Thefollowingtableindicates thelength of S and w, andthefrequency rangefor
win this syntax.
[ S, f ] = pmusi c( x, p, nf f t , f s) returns thepseudospectrumin thevector S
evaluated at thecorrespondingvector of frequencies f (in Hz). You supply the
samplingfrequency f s in Hz. I f you specify f s with theempty vector [ ] , the
samplingfrequency defaults to1 Hz.
Table 7-29: S Characteristics for an FFT Length of 256 (Default)
Real/ Complex
Input Data
Length of S and w Range of the Corresponding
Normalized Frequencies
Real-valued 129 [0, ]
Complex-valued 256 [0, 2)
Table 7-30: S and Frequency Vector Characteristics
Real/ Complex
Input Data
nfft Even/ Odd Length of S
and w
Range of w
Real-valued Even ( nf f t / 2 + 1) [0, ]
Real-valued Odd ( nf f t + 1) / 2 [0, )
Complex-valued Even or odd nf f t [0, 2)
pmusic
7-307
Thefrequency rangefor f depends on nf f t , f s, and thevalues of theinput x.
Thelength of S (and f ) is thesameas in Table7-30. Thefollowingtable
indicates thefrequency rangefor f for this syntax.
[ S, f ] = pmusi c( . . . , ' corr' ) forcestheinput argument x tobeinterpretedas
a correlation matrix rather than matrix of signal data. For this syntax x must
bea squarematrix, and all of its eigenvalues must benonnegative.
[ S, f ] = pmusi c( x, p, nf f t , f s, nwi n, nover l ap) allows you tospecify nwi n, a
scalar integer indicatinga rectangular windowlength, or a real-valued vector
specifyingwindowcoefficients. Usethescalar integer nover l ap in conjunction
with nwi n tospecify thenumber of input samplepoints by which successive
windows overlap. nover l ap is not used if x is a matrix. Thedefault valuefor
nwi n is 2*p( 1) and nover l ap is nwi n- 1.
With this syntax, theinput data x is segmented and windowed beforethe
matrix used toestimatethecorrelation matrix eigenvalues is formulated. The
segmentation of thedata depends on nwi n, nover l ap, and theformof x.
Comments on theresultingwindowedsegments aredescribed in thefollowing
table.
Table 7-31: S and Frequency Vector Characteristics with fs Specified
Real/ Complex Input Data nfft Even/ Odd Range of f
Real-valued Even [ 0, f s/ 2]
Real-valued Odd [ 0, f s/ 2)
Complex-valued Even or odd [ 0, f s)
Table 7-32: Windowed Data Depending on x and nwin
Input data x Form of nwin Windowed Data
Data vector Scalar Length is nwi n
Data vector Vector of coefficients Length is l engt h( nwi n)
pmusic
7-308
SeeTable7-33 for related information on this syntax.
Note Thearguments nwi n and nover l ap areignored when you includethe
string' corr' in thesyntax.
[ . . . ] = pmusi c( . . . , ' r ange' ) specifies therangeof frequency values to
includein f or w. This syntax is useful when x is real. ' r ange' can beeither:
' whol e' : Computethepseudospectrumover thefrequency range[ 0, f s) .
Thisisthedefault for determiningthefrequencyrangefor complex-valuedx.
- I f you specify f s as theempty vector, [ ] , thefrequency rangeis [ 0, 1) .
- I f you dont specify f s, thefrequency rangeis [0, 2).
' hal f ' : Computethepseudospectrumover thefrequency ranges specified
for real x. This is thedefault for determiningthefrequency rangefor
real-valued x.
Note You can put thestringarguments ' r ange' or ' corr' anywherein the
input argument list after p.
[ . . . , v, e] = pmusi c( . . . ) returns thematrix v of noiseeigenvectors, along
withtheassociatedeigenvaluesinthevector e. Thecolumnsof v spanthenoise
subspaceof dimension si ze( v, 2) . Thedimension of thesignal subspaceis
si ze( v, 1) - si ze( v, 2) . For this syntax, e is a vector of estimated eigenvalues
of thecorrelation matrix.
Data matrix Scalar Data is not windowed.
Data matrix Vector of coefficients l engt h( nwi n) must bethe
sameas thecolumn length of x,
and nover l ap is not used.
Table 7-32: Windowed Data Depending on x and nwin (Continued)
Input data x Form of nwin Windowed Data
pmusic
7-309
pmusi c( . . . ) with nooutput arguments plots thepseudospectrumin the
current figurewindow.
Remarks I n theprocess of estimatingthepseudospectrum, pmusi c computes thenoise
and signal subspaces fromtheestimated eigenvectors v
j
and eigenvalues
j
of
thesignals correlation matrix. Thesmallest of theseeigenvalues is used in
conjunction with thethreshold parameter p( 2) toaffect thedimension of the
noisesubspacein somecases.
Thelength n of theeigenvectors computed by pmusi c is thesumof the
dimensions of thesignal andnoisesubspaces. This eigenvector length depends
on your input (signal data or correlation matrix) and thesyntax you use.
Thefollowingtablesummarizes thedependency of theeigenvector length on
theinput argument.
You shouldspecifynwi n >p( 1) or l engt h( nwi n) >p( 1) if youwant p( 2) >1 to
haveany effect.
Table 7-33: Eigenvector Length Depending on Input Data and Syntax
Form of Input Data x Comments on the Syntax Length n of
Eigenvectors
Rowor column vector nwi n is specified as a scalar
integer.
nwi n
Rowor column vector nwi n is specified as a vector. l engt h( nwi n)
Rowor column vector nwi n is not specified. 2*p( 1)
l-by-mmatrix I f nwi n is specified as a
scalar, it is not used. I f nwi n
is specified as a vector,
l engt h( nwi n) must equal
m.
m
m-by-mnonnegative
definitematrix
Thestring' corr' is
specified and nwi n is not
used.
m
pmusic
7-310
Examples Example 1: pmusic with no Sampling Specified
This exampleanalyzes a signal vector x, assumingthat tworeal sinusoidal
components arepresent in thesignal subspace. I n this case, thedimension of
thesignal subspaceis 4 becauseeach real sinusoid is thesumof twocomplex
exponentials.
r andn( ' st at e' , 0) ;
n = 0: 199;
x = cos( 0. 257*pi *n) + si n( 0. 2*pi *n) + 0. 01*r andn( si ze( n) ) ;
pmusi c( x, 4)
Example 2: Specifying Sampling Frequency and Subspace Dimensions
This exampleanalyzes thesamesignal vector x with an eigenvaluecutoff of
10%abovetheminimum. Settingp( 1) =I nf forces thesignal/noisesubspace
decision tobebasedon thethresholdparameter p( 2) . Specify theeigenvectors
of length 7 usingthenwi n argument, and set thesamplingfrequency f s to
8 kHz.
r andn( ' st at e' , 0) ;
n = 0: 199;
x = cos( 0. 257*pi *n) + si n( 0. 2*pi *n) + 0. 01*r andn( si ze( n) ) ;
[ P, f ] = pmusi c( x, [ I nf , 1. 1] , [ ] , 8000, 7) ; %Wi ndow l engt h = 7
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
10
0
10
20
30
40
50
60
Normalized Frequency ( rad/sample)
d
B
MUSIC Pseudospectrum
pmusic
7-311
Example 3: Entering a Correlation Matrix
Supply a positivedefinitecorrelation matrix R for estimatingthespectral
density. Usethedefault 256 samples.
R = t oepl i t z( cos( 0. 1*pi *[ 0: 6] ) ) + 0. 1*eye( 7) ;
[ P, f ] = pmusi c( R, 4, ' cor r ' ) ;
Example 4: Entering a Signal Data Matrix Generated from corrmtx
Enter a signal data matrix Xmgenerated fromdata usingcor r mt x.
r andn( ' st at e' , 0) ;
n = 0: 699;
x = cos( 0. 257*pi *( n) ) + 0. 1*r andn( si ze( n) ) ;
Xm= cor r mt x( x, 7, ' mod' ) ;
[ P, w] = pmusi c( Xm, 2) ;
Example 5: Using Windowing to Create the Effect of a Signal Data Matrix
Usethesamesignal, but let pmusi c formthe100-by-7 data matrix usingits
windowinginput arguments. I n addition, specify an FFT of length 512.
r andn( ' st at e' , 0) ;
n = 0: 699;
x = cos( 0. 257*pi *( n) ) + 0. 1*r andn( si ze( n) ) ;
[ PP, f f ] = pmusi c( x, 2, 512, [ ] , 7, 0) ;
Algorithm ThenameMUSI C is an acronymfor MUltipleSI gnal Classification. The
MUSI C algorithmestimates thepseudospectrumfromasignal or acorrelation
matrix usingSchmidts eigenspaceanalysis method [1]. Thealgorithm
performs eigenspaceanalysis of thesignals correlation matrix in order to
estimatethesignals frequencycontent. This algorithmis particularlysuitable
for signals that arethesumof sinusoids with additivewhiteGaussian noise.
Theeigenvalues and eigenvectors of thesignals correlation matrix are
estimated if you dont supply thecorrelation matrix.
TheMUSI C pseudospectrumestimateis given by
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
7-312
whereN is thedimension of theeigenvectors and v
k
is thek-th eigenvector of
thecorrelation matrix. Theinteger p is thedimension of thesignal subspace,
sotheeigenvectors v
k
used in thesumcorrespond tothesmallest eigenvalues
and alsospan thenoisesubspace. Thevector e(f) consists of complex
exponentials, sotheinner product
amounts toa Fourier transform. This is used for computation of the
pseudospectrumestimate. TheFFT is computed for each v
k
and then the
squared magnitudes aresummed.
See Also
References [1] Marple, S.L. Digital Spectral Analysis, EnglewoodCliffs, NJ , Prentice-Hall,
1987, pp. 373-378.
[2] Schmidt, R.O, MultipleEmitter Location and Signal Parameter
Estimation,I EEE Trans. Antennas Propagation, Vol. AP-34 (March 1986),
pp. 276-280.
v
k
H
e f ( )
cor r mt x Prepareinput data for a correlation matrix estimate.
pbur g Estimatethepower spectral density usingtheBurg
method.
pei g Estimatethepseudospectrumusingtheeigenvector
method.
per i odogr am Estimatethepower spectral density usinga
periodogram.
pmt m Estimatethepower spectral density usingthe
multitaper method.
pr ony Pronys method for timedomain I I R filter design.
psdpl ot Plot power spectral density data.
pwel ch Estimatethepower spectral density usingWelchs
method.
r oot ei g Estimatethefrequency and power content usingthe
root eigenvector method.
r oot musi c Estimatethefrequency and power content usingthe
root MUSI C algorithm.
pmusic
7-313
[3] Stoica, P., andR.L. Moses, I ntroduction toSpectral Analysis, Prentice-Hall,
Englewood Cliffs, NJ , 1997.
poly2ac
7-314
7poly2ac
Purpose Convert a prediction filter polynomial toan autocorrelation sequence.
Syntax r = pol y2ac( a, ef i nal )
Description r = pol y2ac( a, ef i nal ) finds theautocorrelation vector r correspondingto
theprediction filter polynomial a. Theautocorrelation sequenceproduced is
approximately thesameas that of theoutput of theautoregressiveprediction
filter whosecoefficients aredetermined by a. pol y2ac alsoproduces thefinal
l engt h( r ) step prediction error ef i nal . I f a( 1) is not equal to1, pol y2ac
normalizes theprediction filter polynomial by a( 1) . a( 1) cannot be0.
Remarks You can apply this function toboth real and complex polynomials.
Examples a = [ 1. 0000 0. 6147 0. 9898 0. 0004 0. 0034 - 0. 0077] ;
ef i nal = 0. 2;
r = pol y2ac( a, ef i nal )
r =
5. 5917
- 1. 7277
- 4. 4231
4. 3985
1. 6426
- 5. 3126
See Also
References [1] Kay, S.M. Modern Spectral Estimation, Englewood Cliffs, NJ ,
Prentice-Hall, 1988.
ac2pol y Convert an autocorrelation sequencetoa prediction
filter polynomial.
pol y2r c Convert a prediction filter polynomial toreflection
coefficients.
r c2ac Convert reflection coefficients toan autocorrelation
sequence.
poly2lsf
7-315
7poly2lsf
Purpose Convert prediction filter coefficients tolinespectral frequencies.
Syntax l sf = pol y2l sf ( a)
Description l sf = pol y2l sf ( a) returns a vector l sf of linespectral frequencies (also
known as linespectrumpairs) froma vector a of prediction filter coefficients.
Examples a = [ 1. 0000 0. 6149 0. 9899 0. 0000 0. 0031 - 0. 0082] ;
l sf = pol y2l sf ( a)
l sf =
0. 7842
1. 5605
1. 8776
1. 8984
2. 3593
See Also l sf 2pol y Convert linespectral frequencies toprediction filter
coefficients.
References [1] Deller, J .R., J .G. Proakis, and J .H.L. Hansen, Discrete-TimeProcessingof
Speech Signals, Prentice-Hall, 1993.
[2] Rabiner, L.R., and R.W. Schafer, Digital Processingof Speech Signals,
Prentice-Hall, 1978.
poly2rc
7-316
7poly2rc
Purpose Convert a prediction filter polynomial toreflection coefficients.
Syntax k = pol y2r c( a)
[ k, r 0] = pol y2r c( a, ef i nal )
Description k = pol y2r c( a) converts theprediction filter polynomial a tothereflection
coefficients of thecorrespondinglatticestructure. a can bereal or complex, and
a( 1) cannot be0. I f a( 1) is not equal to1, pol y2r c normalizes theprediction
filter polynomial by a( 1) . k is a rowvector of sizel engt h( a) - 1.
[ k, r 0] = pol y2r c( a, ef i nal ) returns thezero-lagautocorrelation, r 0, based
on thefinal prediction error, ef i nal .
A simple, fast way tocheck if a has all of its roots insidetheunit circleis to
check if each of theelements of k has magnitudeless than 1.
st abl e = al l ( abs( pol y2r c( a) ) <1)
Examples a = [ 1. 0000 0. 6149 0. 9899 0. 0000 0. 0031 - 0. 0082] ;
ef i nal = 0. 2;
[ k, r 0] = pol y2r c( a, ef i nal )
k =
0. 3090
0. 9801
0. 0031
0. 0081
- 0. 0082
r 0 =
5. 6032
Limitations I f abs( k( i ) ) == 1 for any i , findingthereflection coefficients is an
ill-conditioned problem. pol y2r c returns someNaNs and providea warning
messagein this case.
poly2rc
7-317
Algorithm pol y2r c implements therecursiverelationship
This relationship is based on Levinsons recursion [1]. Toimplement it,
pol y2r c loops through a in reverseorder after discardingits first element. For
each loop iteration i , thefunction:
1 Sets k( i ) equal toa( i )
2 Applies thesecond relationship abovetoelements 1 through i of the
vector a.
a = ( ak( i ) *f l i pl r ( a) ) / ( 1k( i ) ^2) ;
See Also
References [1] Kay, S.M. Modern Spectral Estimation, Englewood Cliffs, NJ ,
Prentice-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 , , , , =
ac2r c Convert an autocorrelation sequencetoreflection
coefficients.
l at c2t f Convert a latticefilter parameters totransfer
function form.
l at cf i l t Latticeand lattice-ladder filter implementation.
pol y2ac Convert a prediction filter polynomial toan
autocorrelation sequence.
r c2pol y Convert reflection coefficients toa prediction filter
polynomial.
t f 2l at c Convert transfer function filter parameters tolattice
filter form.
polyscale
7-318
7polyscale
Purpose Scaletheroots of a polynomial.
Syntax b = pol yscal e( a, al pha)
Description b = pol yscal e( a, al pha) scales theroots of a polynomial in thez-plane,
wherea is a vector containingthepolynomial coefficients and al pha is the
scalingfactor.
I f al pha isareal valueintherange[ 0 1] , thentherootsof a areradiallyscaled
toward theorigin in thez-plane. Complex values for al pha allowarbitrary
changes totheroot locations.
Remark By reducingtheradius of theroots in an autoregressivepolynomial, the
bandwidth of thespectral peaks in thefrequency responseis expanded
(flattened). This operation is often referred toas bandwidth expansion.
See Also pol yst ab Stabilizea polynomial.
r oot s Polynomial roots (seetheMATLAB documentation).
polystab
7-319
7polystab
Purpose Stabilizepolynomial.
Syntax b = pol yst ab( a)
Description pol yst ab stabilizesapolynomial with respect totheunit circle; it reflects roots
with magnitudes greater than 1 insidetheunit circle.
b = pol yst ab( a) returns a rowvector b containingthestabilizedpolynomial,
wherea is a vector of polynomial coefficients, normally in thez-domain.
Examples pol yst ab can convert a linear-phasefilter intoa minimum-phasefilter with
thesamemagnituderesponse.
h = f i r 1( 25, 0. 4) ;
hmi n = pol yst ab( h) * nor m( h) / nor m( pol yst ab( h) ) ;
Algorithm pol yst ab finds theroots of thepolynomial andmaps thoseroots found outside
theunit circletotheinsideof theunit circle.
v = r oot s( a) ;
vs = 0. 5*( si gn( abs( v) - 1) +1) ;
v = ( 1- vs) . *v + vs. / conj ( v) ;
b = a( 1) *pol y( v) ;
See Also
a z ( ) a 1 ( ) a 2 ( )z
1
L a na 1 + ( )z
na
+ + + =
r oot s Polynomial roots (seetheMATLAB documentation).
prony
7-320
7prony
Purpose Pronys method for timedomain I I R filter design.
Syntax [ b, a] = pr ony( h, nb, na)
Description Pronys method is an algorithmfor findingan I I R filter with a prescribedtime
domain impulseresponse. I t has applications in filter design, exponential
signal modeling, and systemidentification (parametric modeling).
[ b, a] = pr ony( h, nb, na) finds afilter with numerator order nb, denominator
order na, and thetimedomain impulseresponsein h. pr ony returns thefilter
coefficientsinrowvectors b anda, of length nb +1 andna +1, respectively. The
filter coefficients arein descendingpowers of z.
Examples Recover thecoefficients of a Butterworth filter fromits impulseresponse.
[ b, a] = but t er ( 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 = f i l t er ( b, a, [ 1 zer os( 1, 25) ] ) ;
[ bb, aa] = pr ony( 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 pr ony implements themethod described in reference[1]. This method uses a
variation of thecovariancemethod of AR modelingtofind thedenominator
coefficients a andthen findsthenumerator coefficients b for which theimpulse
responseof theoutput filter matches exactly thefirst nb +1 samples of x. The
filter is not necessarily stable, but potentially can recover thecoefficients
H z ( )
B z ( )
A z ( )
-----------
b 1 ( ) b 2 ( )z
1
L b nb 1 + ( )z
nb
+ + +
a 1 ( ) a 2 ( )z
1
L a na 1 + ( )z
na
+ + +
-------------------------------------------------------------------------------------------- = =
prony
7-321
exactlyif thedatasequenceistrulyan autoregressivemovingaverage(ARMA)
process of thecorrect order.
See Also
References [1] Parks, T.W., and C.S. Burrus, Digital Filter Design, J ohn Wiley & Sons,
1987, pp. 226-228.
but t er Butterworth analogand digital filter design.
cheby1 Chebyshev typeI filter design (passband ripple).
cheby2 Chebyshev typeI I filter design (stopband ripple).
el l i p Elliptic (Cauer) filter design.
i nvf r eqz I dentify discrete-timefilter parameters from
frequency responsedata.
l evi nson ComputetheLevinson-Durbin recursion.
l pc Computelinear prediction filter coefficients.
st mcb Computea linear model usingSteiglitz-McBride
iteration.
psdplot
7-322
7psdplot
Purpose Plot power spectral density (PSD) data.
Syntax psdpl ot ( Pxx, w)
psdpl ot ( Pxx, w, ' uni t s' )
psdpl ot ( Pxx, w, ' uni t s' , ' yscal e' )
psdpl ot ( Pxx, w, ' uni t s' , ' yscal e' , ' t i t l e' )
Description psdpl ot ( Pxx, w) plots thepower spectral density data contained in thevector
Pxx at thefrequencies specified in thevector w. Thevectors Pxx and wmust
havethesamelength. Themagnitudeof thedatavector Pxx isplottedindB per
radians per sampleversus frequency won oneplot. Theunits for frequency on
theplots arerad/sample.
psdpl ot ( Pxx, w, ' uni t s' ) displays thefrequency units accordingtothestring
' uni t s' . This stringcan beeither:
' r ad/ sampl e' (default)
' Hz'
psdpl ot ( Pxx, w, ' uni t s' , ' yscal e' ) displays thespectral density magnitude
units accordingtothestring ' yscal e' . This stringcan beeither:
' db' (default), for plottingthePSD in dB per units of frequency
' l i near ' , for plottingthePSD in units of power per units of frequency
psdpl ot ( Pxx, w, ' uni t s' , ' yscal e' , ' t i t l e' ) uses thecontents of thestring
' t i t l e' as thetitleof theplot.
Examples t = 0: 0. 001: 0. 3;
x = cos( 2*pi *t *200) + r andn( si ze( t ) ) ;
[ Pxx, w] = per i odogr am( x, [ ] , ' t wosi ded' , 512) ;
psdpl ot ( Pxx, w, ' ' , ' ' , ' Sampl e PSD Pl ot ' )
psdplot
7-323
See Also
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8
35
30
25
20
15
10
5
0
5
10
15
Normalized Frequency ( rad/sample)
P
o
w
e
r

S
p
e
c
t
r
a
l

D
e
n
s
i
t
y

(
d
B
/

r
a
d
/
s
a
m
p
l
e
)
Sample PSD Plot
f r eqzpl ot Plot frequency responsedata.
pbur g Estimatethepower spectral density usingtheBurg
method.
pcov Estimatethepower spectral density usingthe
covariancemethod.
pei g Estimatethepseudospectrumusingtheeigenvector
method.
per i odogr am Estimatethepower spectral density usinga
periodogram.
pmcov Estimatethepower spectral density usingthe
modified covariancemethod.
pmusi c Estimatethepseudospectrumwith theMUSI C
algorithm.
pwel ch Estimatethepower spectral density usingWelchs
method.
pyul ear Estimatethepower spectral density usingthe
Yule-Walker AR method.
pulstran
7-324
7pulstran
Purpose Generatea pulsetrain.
Syntax y = pul st r an( t , d, ' f unc' )
y = pul st r an( t , d, ' f unc' , p1, p2, . . . )
y = pul st r an( t , d, p, f s)
y = pul st r an( t , d, p)
Description pul st r an generates pulsetrains fromcontinuous functions or sampled
prototypepulses.
y = pul st r an( t , d, ' f unc' ) generates a pulsetrain based on samples of a
continuous function, ' f unc' , where' f unc' is:
' gauspul s' , for generatinga Gaussian-modulated sinusoidal pulse
' r ect pul s' , for generatinga sampled aperiodic rectangle
' t r i pul s' , for generatinga sampled aperiodic triangle
pul st r an is evaluatedl engt h( d) timesandreturns thesumof theevaluations
y = f unc( t - d( 1) ) + f unc( t - d( 2) ) + . . .
Thefunction is evaluated over therangeof argument values specified in
array t , after removinga scalar argument offset taken fromthevector d. Note
that f unc must bea vectorized function that can takean array t as an
argument.
Anoptional gainfactor maybeappliedtoeachdelayedevaluationbyspecifying
d as a two-column matrix, with theoffset defined in column 1 and associated
gain in column 2 of d. Notethat a rowvector will beinterpreted as specifying
delays only.
pul st r an( t , d, ' f unc' , p1, p2, . . . ) allows additional parameters tobepassed
to' f unc' as necessary. For example,
f unc( t - d( 1) , p1, p2, . . . ) + f unc( t - d( 2) , p1, p2, . . . ) + . . .
pul st r an( t , d, p, f s) generates a pulsetrain that is thesumof multiple
delayed interpolations of theprototypepulsein vector p, sampled at the
ratef s, wherep spans thetimeinterval [ 0, ( l engt h( p) - 1) / f s] , and its
samples areidentically 0outsidethis interval. By default, linear interpolation
is used for generatingdelays.
pulstran
7-325
pul st r an( t , d, p) assumes that thesamplingratef s is equal to1 Hz.
pul st r an( . . . , ' f unc' ) specifies alternativeinterpolation methods. See
i nt er p1 for a list of availablemethods.
Examples Example 1
This examplegenerates an asymmetric sawtooth waveformwith a repetition
frequency of 3 Hz andasawtooth width of 0.1s. I t has asignal length of 1s and
a 1 kHz samplerate.
t = 0 : 1/ 1e3 : 1; %1 kHz sampl e f r eq f or 1 sec
d = 0 : 1/ 3 : 1; %3 Hz r epet i t i on f r eq
y = pul st r an( t , d, ' t r i pul s' , 0. 1, - 1) ;
pl ot ( t , y)
0 0.2 0.4 0.6 0.8 1
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
pulstran
7-326
Example 2
This examplegenerates a periodicGaussian pulsesignal at 10 kHz, with 50%
bandwidth. Thepulserepetitionfrequencyis1 kHz, samplerateis50 kHz, and
pulsetrainlengthis10 msec. Therepetitionamplitudeshouldattenuateby 0.8
each time.
t = 0 : 1/ 50E3 : 10e- 3;
d = [ 0 : 1/ 1E3 : 10e- 3 ; 0. 8. ^( 0: 10) ] ' ;
y = pul st r an( t , d, ' gauspul s' , 10e3, 0. 5) ;
pl ot ( t , y)
0 0.002 0.004 0.006 0.008 0.01
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
pulstran
7-327
Example 3
This examplegenerates a train of 10 Hammingwindows.
p = hammi ng( 32) ;
t = 0: 320; d = ( 0: 9) ' *32;
y = pul st r an( t , d, p) ;
pl ot ( 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
chi r p Generatea swept-frequency cosine.
cos Computethecosineof vector/matrix elements (see
theMATLAB documentation).
di r i c ComputetheDirichlet or periodic sinc function.
gauspul s Generatea Gaussian-modulated sinusoidal pulse.
r ect pul s Generatea sampled aperiodic rectangle.
sawt oot h Generatea sawtooth or trianglewave.
si n Computethesineof vector/matrix elements (seethe
MATLAB documentation).
si nc Computethesinc or sin(t)/t function.
squar e Generatea squarewave.
t r i pul s Generatea sampled aperiodic triangle.
pwelch
7-328
7pwelch
Purpose Estimatethepower spectral density (PSD) of a signal usingWelchs method.
Syntax [ Pxx, w] = pwel ch( x)
[ Pxx, w] = pwel ch( x, nwi n)
[ Pxx, w] = pwel ch( x, nwi n, nover l ap)
[ Pxx, w] = pwel ch( x, nwi n, nover l ap, nf f t )
[ Pxx, f ] = pwel ch( x, nwi n, nover l ap, nf f t , f s)
[ . . . ] = pwel ch( x, nwi n, nover l ap, . . . , ' r ange' )
pwel ch( . . . )
Description [ Pxx, w] = pwel ch( x) estimates thepower spectral density Pxx of theinput
signal vector x using Welchs averaged modified periodogrammethod of
spectral estimation. With this syntax:
Thevector x is segmented intoeight sections of equal length, each with 50%
overlap.
Any remaining(trailing) entries in x that cannot beincluded in theeight
segments of equal length arediscarded.
Each segment is windowed with a Hammingwindow(seehammi ng) that is
thesamelength as thesegment.
Thepower spectral density is calculated in units of power per radians per
sample. Thecorrespondingvector of frequencies wis computed in radians per
sample, and has thesamelength as Pxx.
A real-valuedinput vector x producesafull power one-sided(infrequency) PSD
(by default), whilea complex-valued x produces a two-sided PSD.
I n general, thelength N of theFFT andthevalues of theinput x determinethe
length of Pxx and therangeof thecorrespondingnormalized frequencies. For
this syntax, the(default) length N of theFFT is thelarger of 256and thenext
power of twogreater than thelength of thesegment. Thefollowingtable
pwelch
7-329
indicates thelength of Pxx and therangeof thecorrespondingnormalized
frequencies for this syntax.
[ Pxx, w] = pwel ch( x, nwi n) calculates themodifiedperiodogramusingeither:
Thewindowlength nwi n for theHammingwindowwhen nwi n is a positive
integer
Thewindowweights specified in nwi n when nwi n is a vector
With this syntax, theinput vector x is divided intoan integer number of
segments with 50%overlap, and each segment is thesamelength as the
window. Entries in x that areleft over after it is divided intosegments are
discarded. I f you specify nwi n as theempty vector [ ] , then thesignal data is
divided intoeight segments, and a Hammingwindowis used on each one.
[ Pxx, w] = pwel ch( x, nwi n, nover l ap) divides x intosegments accordingto
nwi n, and uses theinteger nover l ap tospecify thenumber of signal samples
(elements of x) that arecommon totwoadjacent segments. nover l ap must be
less than thelength of thewindowyou specify. I f you specify nover l ap as the
emptyvector [ ] , then pwel chdeterminesthesegmentsof x sothat thereis50%
overlap (default).
[ Pxx, w] = pwel ch( x, nwi n, nover l ap, nf f t ) uses Welchs method toestimate
thePSDwhilespecifyingthelength of theFFT with theinteger nf f t . I f you set
nf f t totheempty vector [ ] , it adopts thedefault valuefor N listed in the
previous syntax.
Table 7-34: PSD Vector Characteristics for an FFT Length of N (Default)
Real/ Complex
Input Data
Length of Pxx Range of the Corresponding
Normalized Frequencies
Real-valued (N/2) +1 [0, ]
Complex-valued N [0, 2)
pwelch
7-330
Thelength of Pxx andthefrequency rangefor wdependon nf f t andthevalues
of theinput x. Thefollowingtableindicates thelength of Pxx andthefrequency
rangefor wfor this syntax.
[ Pxx, f ] = pwel ch( x, nwi n, nover l ap, nf f t , f s) uses thesamplingfrequency
f s specifiedasan integer in hertz (Hz) tocomputethePSDvector (Pxx) andthe
correspondingvector of frequencies (f ). I n this case, theunitsfor thefrequency
vector arein Hz. Thespectral density produced is calculated in units of power
per Hz. I f you specify f s as theempty vector [ ] , thesamplingfrequency
defaults to1 Hz.
Thefrequency rangefor f depends on nf f t , f s, and thevalues of theinput x.
Thelengthof Pxx isthesameasinTable7-35. Thefollowingtableindicatesthe
frequency rangefor f for this syntax.
Table 7-35: PSD and Frequency Vector Characteristics
Real/ Complex
Input Data
nfft Even/ Odd Length of Pxx Range of w
Real-valued Even ( nf f t / 2 + 1) [0, ]
Real-valued Odd ( nf f t + 1) / 2 [0, )
Complex-valued Even or odd nf f t [0, 2)
Table 7-36: PSD and Frequency Vector Characteristics with fs Specified
Real/ Complex Input Data nfft Even/ Odd Range of f
Real-valued Even [ 0, f s/ 2]
Real-valued Odd [ 0, f s/ 2)
Complex-valued Even or odd [ 0, f s)
pwelch
7-331
[ . . . ] = pwel ch( x, nwi n, nover l ap, . . . , ' r ange' ) specifies therangeof
frequency values. This syntax is useful when x is real. Thestring' r ange' can
beeither:
' t wosi ded' : Computethetwo-sided PSD over thefrequency range[ 0, f s) .
This is thedefault for determiningthefrequency rangefor
complex-valued x.
- I f you specify f s as theempty vector, [ ] , thefrequency rangeis [ 0, 1) .
- I f you dont specify f s, thefrequency rangeis [0, 2).
' onesi ded' : Computetheone-sidedPSDover thefrequencyrangesspecified
for real x. This is thedefault for determiningthefrequency rangefor
real-valued x.
Thestring' r ange' can appear anywherein thesyntax after nover l ap.
pwel ch( x, . . . ) with nooutput arguments plots thePSD estimatein dB per
unit frequency in thecurrent figurewindow.
Examples EstimatethePSD of a signal composed of a sinusoid plus noise, sampled at
1000Hz. Use33-samplewindowswith 32-sampleoverlap, andthedefault FFT
length, and display thetwo-sided PSD estimate.
r andn( ' st at e' , 0) ;
Fs = 1000; t = 0: 1/ Fs: . 3;
x = cos( 2*pi *t *200) + r andn( si ze( t ) ) ; %200Hz cosi ne pl us noi se
pwel ch( x, 33, 32, [ ] , Fs, ' t wosi ded' )
pwelch
7-332
Algorithm pwel ch calculates thepower spectral density usingWelchs method (see
references):
1 Theinput signal vector x is divided intok overlappingsegments according
tonwi n and nover l ap (or their default values).
2 Thespecified (or default) windowis applied toeach segment of x.
3 An nf f t -point FFT is applied tothewindowed data.
4 The(modified) periodogramof each windowed segment is computed.
5 Theset of modifiedperiodograms is averagedtoformthespectrumestimate
S(e
j
).
6 Theresultingspectrumestimateis scaled tocomputethepower spectral
density as , whereF is:
- 2 when you donot supply thesamplingfrequency
- f s when you supply thesamplingfrequency
0 100 200 300 400 500 600 700 800 900
34
32
30
28
26
24
22
Frequency (Hz)
P
o
w
e
r

S
p
e
c
t
r
a
l

D
e
n
s
i
t
y

(
d
B
/
H
z
)
Welch PSD Estimate
S e
j
( ) F
pwelch
7-333
Thenumber of segments k that x is divided intois calculated as:
Eight if you dont specify nwi n, or if you specify it as theempty vector [ ]
if you specify nwi n as a nonempty vector or a scalar
I n this equation, mis thelength of thesignal vector x, ois thenumber of
overlappingsamples (nover l ap), and l is thelength of each segment (the
windowlength).
See Also
References [1] Hayes, M., Statistical Digital Signal Processingand Modeling, J ohn Wiley
& Sons, 1996.
k
m o
l o
-------------- =
pbur g Estimatethepower spectral density usingtheBurg
method.
pcov Estimatethepower spectral density usingthe
covariancemethod.
pei g Estimatethepseudospectrumusingtheeigenvector
method.
per i odogr am Estimatethepower spectral density usinga
periodogram.
pmcov Estimatethepower spectral density usingthe
modified covariancemethod.
pmt m Estimatethepower spectral density usingthe
multitaper method.
pmusi c EstimatethepseudospectrumusingtheMUSI C
algorithm.
psdpl ot Plot power spectral density data.
pyul ear Estimatethepower spectral density usingthe
Yule-Walker AR method.
pwelch
7-334
[2] Stoica, P., andR.L. Moses, I ntroduction toSpectral Analysis, Prentice-Hall,
Englewood Cliffs, NJ , 1997, pp. 52-54.
[3] Welch, P.D, TheUseof Fast Fourier Transformfor theEstimationof Power
Spectra: A Method Based on TimeAveragingOver Short, Modified
Periodograms,I EEE Trans. AudioElectroacoustics, Vol. AU-15 (J une1967),
pp. 70-73.
pyulear
7-335
7pyulear
Purpose Estimatethepower spectral density usingtheYule-Walker AR method.
Syntax Pxx = pyul ear ( x, p)
[ Pxx, w] = pyul ear ( x, p, nf f t )
[ Pxx, f ] = pyul ear ( x, p, nf f t , f s)
[ Pxx, f ] = pyul ear ( x, p, nf f t , f s, ' r ange' )
[ Pxx, w] = pyul ear ( x, p, nf f t , ' r ange' )
pyul ear ( . . . )
Description Pxx = pyul ear ( x, p) implements theYule-Walker algorithm, a parametric
spectral estimation method, andreturns Pxx, anestimateof thepower spectral
density (PSD) of thevector x. Theentries of x represent samples of a
discrete-timesignal. p is theinteger specifyingtheorder of an autoregressive
(AR) prediction model for thesignal, used in estimatingthePSD.
Thepower spectral density is calculated in units of power per radians per
sample. Real-valued inputs producefull power one-sided (in frequency) PSDs
(by default), whilecomplex-valued inputs producetwo-sided PSDs.
I n general, thelength of theFFT and thevalues of theinput x determinethe
length of Pxx and therangeof thecorrespondingnormalized frequencies. For
this syntax, the(default) FFT length is 256. Thefollowingtableindicates the
length of Pxx and therangeof thecorrespondingnormalized frequencies for
this syntax.
[ Pxx, w] = pyul ear ( x, p) alsoreturns w, a vector of frequencies at which the
PSD is estimated. Pxx andwhavethesamelength. Theunits for frequency are
rad/sample.
Table 7-37: PSD Vector Characteristics for an FFT Length of 256 (Default)
Real/ Complex
Input Data
Length of Pxx Range of the Corresponding
Normalized Frequencies
Real-valued 129 [0, ]
Complex-valued 256 [0, 2)
pyulear
7-336
[ Pxx, w] = pyul ear ( x, p, nf f t ) uses theYule-walker method toestimatethe
PSDwhilespecifyingthelength of theFFT withtheinteger nf f t . I f youspecify
nf f t as theempty vector [ ] , it adopts thedefault valueof 256.
Thelength of Pxx andthefrequency rangefor wdependon nf f t andthevalues
of theinput x. Thefollowingtableindicates thelength of Pxx andthefrequency
rangefor wfor this syntax.
[ Pxx, f ] = pyul ear ( x, p, nf f t , f s) uses thesamplingfrequency f s specified
as an integer in hertz (Hz) tocomputethePSD vector (Pxx) and the
correspondingvector of frequencies (f ). I n this case, theunitsfor thefrequency
vector arein Hz. Thespectral density produced is calculated in units of power
per Hz. I f you specify f s as theempty vector [ ] , thesamplingfrequency
defaults to1 Hz.
Thefrequency rangefor f depends on nf f t , f s, and thevalues of theinput x.
Thelengthof Pxx isthesameasinTable7-38. Thefollowingtableindicatesthe
frequency rangefor f for this syntax.
Table 7-38: PSD and Frequency Vector Characteristics
Real/ Complex
Input Data
nfft Even/ Odd Length of Pxx Range of w
Real-valued Even ( nf f t / 2 + 1) [0, ]
Real-valued Odd ( nf f t + 1) / 2 [0, )
Complex-valued Even or odd nf f t [0, 2)
Table 7-39: PSD and Frequency Vector Characteristics with fs Specified
Real/ Complex Input Data nfft Even/ Odd Range of f
Real-valued Even [ 0, f s/ 2]
Real-valued Odd [ 0, f s/ 2)
Complex-valued Even or odd [ 0, f s)
pyulear
7-337
[ Pxx, f ] = pyul ear ( x, p, nf f t , f s, ' r ange' ) or
[ Pxx, w] = pyul ear ( x, p, nf f t , ' r ange' ) specifies therangeof frequency
values toincludein f or w. This syntax is useful when x is real. ' r ange' can be
either:
' t wosi ded' : Computethetwo-sided PSD over thefrequency range[ 0, f s) .
This is thedefault for determiningthefrequency rangefor
complex-valued x.
- I f you specify f s as theempty vector, [ ] , thefrequency rangeis [ 0, 1) .
- I f you dont specify f s, thefrequency rangeis [0, 2).
' onesi ded' : Computetheone-sidedPSDover thefrequencyrangesspecified
for real x. This is thedefault for determiningthefrequency rangefor
real-valued x.
Note You can put thestringargument ' r ange' anywherein theinput
argument list after p.
pyul ear ( . . . ) plots thepower spectral density in thecurrent figurewindow.
Thefrequency rangeon theplot is thesameas therangeof output w(or f ) for
a given set of parameters.
Examples BecausetheYule-walker method estimates thespectral density by fittingan
AR prediction model of a given order tothesignal, first generatea signal from
an AR (all-pole) model of a given order. You can usef r eqz tocheck the
magnitudeof thefrequency responseof your AR filter. This will giveyou an
idea of what toexpect when you estimatethePSD usingpyul ear .
a = [ 1 - 2. 2137 2. 9403 - 2. 1697 0. 9606] ; %AR f i l t er coef f i ci ent s
f r eqz( 1, a) %AR f i l t er f r equency r esponse
t i t l e( ' AR Syst emFr equency Response' )
pyulear
7-338
Nowgeneratetheinput signal x by filteringwhitenoisethrough theAR filter.
EstimatethePSD of x based on a fourth-order AR prediction model, sincein
this case, weknowthat theoriginal AR systemmodel a has order 4.
r andn( ' st at e' , 1) ;
x = f i l t er ( 1, a, r andn( 256, 1) ) ; %AR syst emout put
pyul ear ( x, 4) %Four t h- or der est i mat e
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
200
150
100
50
0
50
100
Normalized Frequency ( rad/sample)
P
h
a
s
e

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

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

S
p
e
c
t
r
a
l

D
e
n
s
i
t
y

(
d
B
/

r
a
d
/
s
a
m
p
l
e
)
YuleWalker PSD Estimate
pyulear
7-339
Remarks Thepower spectral density is computed as thedistribution of power per unit
frequency.
This algorithmdepends on your selectingan appropriatemodel order for your
signal.
Algorithm Linear prediction filters can beused tomodel thesecond-order statistical
characteristicsof asignal. Theprediction filter output canbeusedtomodel the
signal when theinput is whitenoise.
pyul ear estimatesthePSDof an input signal vector usingtheYule-Walker AR
method. This method, alsocalledtheautocorrelation or windowedmethod, fits
an autoregressive(AR) linear prediction filter model tothesignal by
minimizingtheforwardpredictionerror (basedonall observationsof theinput
sequence) in theleast squares sense. This formulation leads tothe
Yule-Walker equations, which aresolved by theLevinson-Durbin recursion.
Thespectral estimatereturned by pyul ear is thesquared magnitudeof the
frequency responseof this AR model.
pyulear
7-340
See Also
References [1] Marple, S.L., Digital Spectral Analysis, Prentice-Hall, 1987, Chapter 7.
[2] Stoica, P., andR.L. Moses, I ntroduction toSpectral Analysis, Prentice-Hall,
1997.
ar yul e Computean estimateof AR model parameters using
theYule-Walker method.
l pc Linear prediction coefficients.
pbur g Estimatethepower spectral density usingtheBurg
method.
pcov Estimatethepower spectral density usingthe
covariancemethod.
pei g Estimatethepseudospectrumusingtheeigenvector
method.
per i odogr am Estimatethepower spectral density usinga
periodogram.
pmcov Estimatethepower spectral density usingthe
modified covariancemethod.
pmt m Estimatethepower spectral density usingthe
multitaper method.
pmusi c EstimatethepseudospectrumusingtheMUSI C
algorithm.
pr ony Pronys method for timedomain I I R filter design.
psdpl ot Plot power spectral density data.
pwel ch Estimatethepower spectral density usingWelchs
method.
rc2ac
7-341
7rc2ac
Purpose Convert reflection coefficients toan autocorrelation sequence.
Syntax r = r c2ac( k, r 0)
Description r = r c2ac( k, r 0) finds theautocorrelation coefficients, r , of theoutput of the
discrete-timeprediction error filter fromthelattice-formreflection coefficients
k and initial zero-lagautocorrelation r 0.
Examples k = [ 0. 3090 0. 9800 0. 0031 0. 0082 - 0. 0082] ;
r 0 = 0. 1;
a = r c2ac( k, r 0)
a =
0. 1000
- 0. 0309
- 0. 0791
0. 0787
0. 0294
- 0. 0950
See Also
References [1] Kay, S.M., Modern Spectral Estimation, Prentice-Hall, Englewood Cliffs,
NJ , 1988.
ac2r c Convert an autocorrelation sequencetoreflection
coefficients.
pol y2ac Convert a prediction filter polynomial toan
autocorrelation sequence.
r c2pol y Convert reflection coefficients toa prediction filter
polynomial.
rc2is
7-342
7rc2is
Purpose Convert reflection coefficients toinversesineparameters.
Syntax i si n = r c2i s( k)
Description i si n = i s2r c( k) returns a vector of inversesineparameters i si n froma
vector of reflection coefficients k.
Examples k = [ 0. 3090 0. 9801 0. 0031 0. 0082 - 0. 0082] ;
i si n = r c2i s( k)
i si n =
0. 2000 0. 8728 0. 0020 0. 0052 - 0. 0052
See Also i s2r c Convert inversesineparameters toreflection
coefficients.
References [1] Deller, J .R., J .G. Proakis, and J .H.L. Hansen, Discrete-TimeProcessingof
Speech Signals, Prentice-Hall, 1993.
rc2lar
7-343
7rc2lar
Purpose Convert reflection coefficients tologarea ratioparameters.
Syntax g = r c2l ar ( k)
Description g = r c2l ar ( k) returns a vector of logarea ratioparameters g froma vector of
reflection coefficients k.
Examples k = [ 0. 3090 0. 9801 0. 0031 0. 0082 - 0. 0082] ;
g = r c2l ar ( k)
g =
0. 6389 4. 6002 0. 0062 0. 0164 - 0. 0164
See Also l ar 2r c Convert logarea ratioparameters toreflection
coefficients.
References [1] Deller, J .R., J .G. Proakis, and J .H.L. Hansen, Discrete-TimeProcessingof
Speech Signals, Prentice-Hall, 1993.
rc2poly
7-344
7rc2poly
Purpose Convert reflection coefficients toa prediction filter polynomial.
Syntax a = r c2pol y( k)
[ a, ef i nal ] = r c2pol y( k, r 0)
Description a = r c2pol y( k) converts thereflection coefficients k correspondingtothe
latticestructuretothepredictionfilter polynomial a, witha( 1) =1. Theoutput
a is rowvector of length l engt h( k) +1.
[ a, ef i nal ] = r c2pol y( k, r 0) returns thefinal prediction error ef i nal based
on thezero-lagautocorrelation, r 0.
Example Consider a latticeI I R filter given by reflection coefficients k.
k = [ 0. 3090 0. 9800 0. 0031 0. 0082 - 0. 0082] ;
I ts equivalent prediction filter representation is given by
a = r c2pol y( k)
a =
1. 0000 0. 6148 0. 9899 0. 0000 0. 0032 - 0. 0082
Algorithm r c2pol y computes output a usingLevinsons recursion [1]. Thefunction:
1 Sets theoutput vector a tothefirst element of k
2 Loops through theremainingelements of k
For each loop iteration i , a = [ a + a( i - 1: - 1: 1) *k( i ) k( i ) ] .
3 I mplements a = [ 1 a]
rc2poly
7-345
See Also
References [1] Kay, S.M., Modern Spectral Estimation, Prentice-Hall, Englewood Cliffs,
NJ , 1988.
ac2pol y Convert an autocorrelation sequencetoa prediction
filter polynomial.
l at c2t f Latticefilter totransfer function conversion.
l at cf i l t Latticeand lattice-ladder filter implementation.
pol y2r c Convert a prediction filter polynomial toreflection
coefficients.
r c2ac Convert reflection coefficients toan autocorrelation
sequence.
r c2i s Convert reflection coefficients toinversesine
parameters.
r c2l ar Convert reflection coefficients tologarea ratio
parameters.
t f 2l at c Convert transfer function tolatticefilter.
rceps
7-346
7rceps
Purpose Real cepstrumand minimumphasereconstruction.
Syntax y = r ceps( x)
[ y, ym] = r ceps( x)
Description Thereal cepstrumis theinverseFourier transformof thereal logarithmof the
magnitudeof theFourier transformof a sequence.
r ceps( x) returns thereal cepstrumof thereal sequencex. Thereal cepstrum
is a real-valued function.
[ y, ym] = r ceps( x) returns both thereal cepstrumy and a minimumphase
reconstructed version ymof theinput sequence.
Algorithm r ceps is an M-fileimplementation of algorithm7.2 in [2], that is,
y = r eal ( i f f t ( l og( abs( f f t ( x) ) ) ) ) ;
Appropriatewindowingin thecepstral domain forms thereconstructed
minimumphasesignal.
w = [ 1; 2*ones( n/ 2- 1, 1) ; ones( 1 - r em( n, 2) , 1) ; zer os( n/ 2- 1, 1) ] ;
ym= r eal ( i f f t ( exp( f f t ( w. *y) ) ) ) ;
See Also
References [1] Oppenheim, A.V., and R.W. Schafer, Digital Signal Processing, Englewood
Cliffs, NJ , Prentice-Hall, 1975.
[2] Programs for Digital Signal Processing, I EEE Press, NewYork, 1979.
cceps Complex cepstral analysis.
f f t One-dimensional fast Fourier transform.
hi l ber t Hilbert transform.
i cceps I nversecomplex cepstrum.
unwr ap Unwrap phaseangles.
rectpuls
7-347
7rectpuls
Purpose Generatea sampled aperiodic rectangle.
Syntax y = r ect pul s( t )
y = r ect pul s( t , w)
Description y = r ect pul s( t ) returns a continuous, aperiodic, unity-height rectangular
pulseat thesampletimes indicatedin arrayt , centeredabout t =0 andwith a
default width of 1. Notethat theinterval of non-zeroamplitudeis definedtobe
open on theright, that is, r ect pul s( - 0. 5) =1 whiler ect pul s( 0. 5) =0.
y = r ect pul s( t , w) generates a rectangleof width w.
r ect pul s is typically used in conjunction with thepulsetrain generating
function pul st r an.
See Also
chi r p Generatea swept-frequency cosine.
cos Computethecosineof vector/matrix elements (see
theMATLAB documentation).
di r i c ComputetheDirichlet or periodic sinc function.
gauspul s Generatea Gaussian-modulated sinusoidal pulse.
pul st r an Generatea pulsetrain.
sawt oot h Generatea sawtooth or trianglewave.
si n Computethesineof vector/matrix elements (seethe
MATLAB documentation).
si nc Computethesinc or sin(t)/t function.
squar e Generatea squarewave.
t r i pul s Generatea sampled aperiodic triangle.
remez
7-348
7remez
Purpose ComputetheParks-McClellan optimal FI R filter design.
Syntax b = r emez( n, f , a)
b = r emez( n, f , a, w)
b = r emez( n, f , a, ' f t ype' )
b = r emez( n, f , a, w, ' f t ype' )
b = r emez( . . . , {l gr i d})
b = r emez( n, f , ' f r esp' , w)
b = r emez( n, f , ' f r esp' , w, ' f t ype' )
b = r emez( n, f , {' f r esp' , p1, p2, . . . }, w)
b = r emez( n, f , {' f r esp' , p1, p2, . . . }, w, ' f t ype' )
[ b, del t a] = r emez( . . . )
[ b, del t a, opt ] = r emez( . . . )
Description r emez designs a linear-phaseFI R filter usingtheParks-McClellan
algorithm[1]. TheParks-McClellan algorithmuses theRemez exchange
algorithmand Chebyshev approximation theory todesign filters with an
optimal fit between thedesiredandactual frequencyresponses. Thefilters are
optimal in thesensethat themaximumerror between thedesired frequency
responseandtheactual frequencyresponseisminimized. Filtersdesignedthis
way exhibit an equiripplebehavior in their frequency responses and are
sometimes called equiripplefilters.
b = r emez( n, f , a) returns rowvector b containingthen+1 coefficients of the
order n FI R filter whosefrequency-amplitudecharacteristics match those
given by vectors f and a.
Theoutput filter coefficients (taps) in b obey thesymmetry relation
b k ( ) b n 2 k + ( ) k 1 = n 1 + , , , =
remez
7-349
Vectors f and a specify thefrequency-magnitudecharacteristics of thefilter:
f is a vector of pairs of normalized frequency points, specified in therange
between 0 and 1, where1 corresponds totheNyquist frequency. The
frequencies must bein increasingorder.
a is a vector containingthedesired amplitudes at thepoints specified in f .
Thedesiredamplitudeat frequenciesbetweenpairsof points(f(k), f(k+1)) for
k odd is thelinesegment connectingthepoints (f(k), a(k)) and
(f(k+1), a(k+1)).
Thedesiredamplitudeat frequenciesbetweenpairsof points(f(k), f(k+1)) for
k even is unspecified. Theareas between such points aretransition or dont
care regions.
f and a must bethesamelength. Thelength must bean even number.
Therelationship between thef and a vectors in defininga desired frequency
responseis shown in theexamplebelow.
r emez always uses an even filter order for configurations with a passband at
theNyquist frequency. This is becausefor odd orders, thefrequency response
at theNyquist frequency is necessarily 0. I f you specify an odd-valued n, r emez
increments it by 1.
1.0
0.0
Desired amplitude
response (a)
Normalized
frequency (f )
0.5
"Don't care"/transition regions
f = [ 0 . 3 . 4 . 6 . 7 . 9]
a = [ 0 1 0 0 . 5 . 5]
0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.0 0.8 0.9 1.0 (Nyquist)
remez
7-350
r emez( n, f , a, w) usestheweightsinvector wtoweight thefit ineachfrequency
band. Thelength of wis half thelength of f anda, sothereis exactlyoneweight
per band.
b = r emez( n, f , a, ' f t ype' ) and
b = r emez( n, f , a, w, ' f t ype' ) specify a filter type, where' f t ype' is
' hi l ber t ' , for linear-phasefilters with odd symmetry (typeI I I and typeI V)
Theoutput coefficients in b obey therelation b(k) =-b(n+2-k), k = 1, ...,
n +1. This class of filters includes theHilbert transformer, which has a
desired amplitudeof 1 across theentireband.
For example,
h = r emez( 30, [ 0. 1 0. 9] , [ 1 1] , ' hi l ber t ' ) ;
designs an approximateFI R Hilbert transformer of length 31.
' di f f er ent i at or ' , for typeI I I andtypeI V filters, usingaspecial weighting
technique
For nonzeroamplitudebands, it weights theerror by a factor of 1/f sothat
theerror at lowfrequencies is much smaller than at high frequencies. For
FI R differentiators, which havean amplitudecharacteristic proportional to
frequency, thesefiltersminimizethemaximumrelativeerror (themaximum
of theratioof theerror tothedesired amplitude).
b = r emez( . . . , {l gr i d}) uses theinteger l gr i d tocontrol thedensity of the
frequency grid, which has roughly ( l gr i d*n) / ( 2*bw) frequency points, where
bwis thefraction of thetotal frequency band interval [0,1] covered by f .
I ncreasingl gr i d often results in filters that moreexactly match an equiripple
filter, but that takelonger tocompute. Thedefault valueof 16 is theminimum
valuethat shouldbespecifiedfor l gr i d. Notethat the{l gr i d} argument must
bea 1-by-1 cell array.
b = r emez( n, f , ' f r esp' , w) returns rowvector b containingthe n+1
coefficients of theorder n FI R filter whosefrequency-amplitudecharacteristics
best approximatetheresponsespecified by function f r esp. Thefunction is
called fromwithin r emez with thefollowingsyntax.
[ dh, dw] = f r esp( n, f , gf , w)
remez
7-351
Thearguments aresimilar tothosefor r emez:
n is thefilter order.
f isthevector of normalizedfrequencybandedgesthat appear monotonically
between 0 and 1, where1 is theNyquist frequency.
gf is a vector of grid points that havebeen linearly interpolated over each
specified frequency band by r emez. gf determines thefrequency grid at
which theresponsefunction must beevaluated, and contains thesamedata
returned by cr emez in thef gr i d field of theopt structure.
wisavector of real, positiveweights, oneper band, usedduringoptimization.
wis optional in thecall tor emez; if not specified, it is set tounity weighting
beforebeingpassed tof r esp.
dh and dwarethedesired complex frequency responseand band weight
vectors, respectively, evaluated at each frequency in grid gf .
Thepredefinedfrequencyresponsefunction f r esp that r emez callsis r emezf r f
in thesi gnal / pr i vat e directory.
b = r emez( n, f , {' f r esp' , p1, p2, . . . }, w) allows you tospecify additional
parameters (p1, p2, etc.) topass tof r esp. Notethat b = r emez( n, f , a, w) is a
synonymfor b = r emez( n, f , {' r emezf r f ' , a}, w) , wherea is a vector
containingthedesired amplitudes at thepoints specified in f .
b = r emez( n, f , ' f r esp' , w, ' f t ype' ) and
b = r emez( n, f , {' f r esp' , p1, p2, . . . }, w, ' f t ype' ) design antisymmetric
(odd) rather than symmetric (even) filters, where' f t ype' is either ' d' for a
differentiator or ' h' for a Hilbert transformer.
I n theabsenceof a specification for f t ype, a preliminary call is madetof r esp
todeterminethedefault symmetry property sym. This call is madeusingthe
syntax.
sym= f r esp( ' def aul t s' , {n, f , [ ] , w, p1, p2, . . . })
Thearguments n, f , w, etc., may beused as necessary in determiningan
appropriatevaluefor sym, which r emez expects tobeeither ' even' or ' odd' . I f
thef r esp function does not support this callingsyntax, r emez defaults toeven
symmetry.
remez
7-352
[ b, del t a] = r emez( . . . ) returns themaximumrippleheight in del t a.
[ b, del t a, opt ] = r emez( . . . ) returns a structurewith thefollowingfields.
Example Graph thedesired and actual frequency responses of a 17th-order
Parks-McClellan bandpass filter.
f = [ 0 0. 3 0. 4 0. 6 0. 7 1] ; a = [ 0 0 1 1 0 0] ;
b = r emez( 17, f , a) ;
[ h, w] = f r eqz( b, 1, 512) ;
pl ot ( f , a, w/ pi , abs( h) )
l egend( ' I deal ' , ' r emez Desi gn' )
opt . f gr i d Frequency grid vector used for thefilter design optimization
opt . des Desired frequency responsefor each point in opt . f gr i d
opt . wt Weightingfor each point in opt . f gr i d
opt . H Actual frequency responsefor each point in opt . f gr i d
opt . er r or Error at each point in opt . f gr i d (opt . des- opt . H)
opt . i ext r Vector of indices intoopt . f gr i d for extremal frequencies
opt . f ext r Vector of extremal frequencies
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
0
0.2
0.4
0.6
0.8
1
1.2
1.4
Ideal
remez Design
remez
7-353
Algorithm r emez is a MEX-fileversion of theoriginal Fortran codefrom[1], altered to
design arbitrarily longfilters with arbitrarily many linear bands.
r emez designs typeI , I I , I I I , and I V linear-phasefilters. TypeI and typeI I are
thedefaults for n even and n odd, respectively, whiletypeI I I (n even) and
typeI V (n odd) areobtained with the' hi l ber t ' and' di f f er ent i at or ' flags.
Thedifferent types of filters havedifferent symmetries andcertain constraints
on their frequency responses (see[5] for moredetails).
Remarks I f you get thefollowingwarningmessage,
- Fai l ur e t o Conver ge -
Pr obabl e cause i s machi ne r oundi ng er r or .
it is possiblethat thefilter design may still becorrect. Verify thedesign by
checkingits frequency response.
Linear Phase
Filter Type
Filter
Order
Symmetry of Coefficients Response H(f),
f = 0
Response H(f),
f = 1 (Nyquist)
TypeI Even even: Norestriction Norestriction
TypeI I Odd Norestriction H(1) = 0
TypeI I I Even odd: H(0) = 0 H(1) = 0
TypeI V Odd H(0) = 0 Norestriction
b k ( ) b n 2 k + ( ) k 1 = n 1 + , , , =
b k ( ) b n 2 k + ( ) k 1 = n 1 + , , , =
remez
7-354
See Also
References [1] Programs for Digital Signal Processing, I EEE Press, NewYork, 1979,
Algorithm5.1.
[2] Selected Papers in Digital Signal Processing, I I , I EEE Press, NewYork,
1979.
[3] Parks, T.W., and C.S. Burrus, Digital Filter Design, J ohn Wiley & Sons,
NewYork:, 1987, p. 83.
[4] Rabiner, L.R., J .H. McClellan, and T.W. Parks, FI R Digital Filter Design
Techniques UsingWeighted Chebyshev Approximations, Proc. I EEE 63
(1975).
but t er Design a Butterworth analogand digital filter .
cheby1 Design a Chebyshev typeI filter (passband ripple).
cheby2 Design a Chebyshev typeI I filter (stopband ripple).
cr emez Design a complex and nonlinear-phaseequiripple
FI R filter.
el l i p Design an elliptic(Cauer) filter.
f i r 1 Design awindow-basedfiniteimpulseresponsefilter:
standard response.
f i r 2 Design awindow-basedfiniteimpulseresponsefilter:
arbitrary response.
f i r cl s Design a constrained least squareFI R filter for
multiband filters.
f i r cl s1 Design a constrained least squarefilter for lowpass
and highpass linear phaseFI R filters.
f i r l s Design a least squarelinear-phaseFI R filter.
f i r r cos Design a raised cosineFI R filter.
gr emez Design ageneralizedRemez optimal FI R filter design
(seetheFilter Design Toolbox documentation).
r emezor d EstimatetheParks-McClellan optimal FI R filter
order.
yul ewal k Design a recursivedigital filter.
remez
7-355
[5] Oppenheim, A.V., and R.W. Schafer, Discrete-TimeSignal Processing,
Prentice-Hall, Englewood Cliffs, NJ , 1989, pp. 256-266.
remezord
7-356
7remezord
Purpose Parks-McClellan optimal FI R filter order estimation.
Syntax [ n, f o, ao, w] = r emezor d( f , a, dev)
[ n, f o, ao, w] = r emezor d( f , a, dev, f s)
c = r emezor d( f , a, dev, f s, ' cel l ' )
Description [ n, f o, ao, w] = r emezor d( f , a, dev) finds theapproximateorder, normalized
frequency band edges, frequency band amplitudes, and weights that meet
input specifications f , a, and dev.
f is a vector of frequency band edges (between 0 and f
s
/2, wheref
s
is the
samplingfrequency), and a is a vector specifyingthedesired amplitudeon
thebands definedby f . Thelength of f is twoless than twicethelength of a.
Thedesired function is piecewiseconstant.
dev is a vector thesamesizeas a that specifies themaximumallowable
deviation or ripples between thefrequency responseand thedesired
amplitudeof theoutput filter for each band.
User emez with theresultingorder n, frequency vector f o, amplituderesponse
vector ao, and weights wtodesign thefilter b which approximately meets the
specifications given by r emezor d input parameters f , a, and dev.
b = r emez( n, f o, ao, w)
[ n, f o, ao, w] = r emezor d( f , a, dev, f s) specifies a samplingfrequency f s.
f s defaults to2 Hz, implyinga Nyquist frequency of 1 Hz. You can therefore
specify band edges scaled toa particular applications samplingfrequency.
I n somecases r emezor d underestimates theorder n. I f thefilter does not meet
thespecifications, try a higher order such as n+1 or n+2.
c = r emezor d( f , a, dev, f s, ' cel l ' ) generates a cell-array whoseelements
aretheparameters tor emez.
Examples Example 1
Design a minimum-order lowpass filter with a 500 Hz passband cutoff
frequency and600 Hz stopbandcutoff frequency, with asamplingfrequency of
2000 Hz, at least 40 dB attenuation in thestopband, and less than 3 dB of
ripplein thepassband.
remezord
7-357
r p = 3; %Passband r i ppl e
r s = 40; %St opband r i ppl e
f s = 2000; %Sampl i ng f r equency
f = [ 500 600] ; %Cut of f f r equenci es
a = [ 1 0] ; %Desi r ed ampl i t udes
%Comput e devi at i ons
dev = [ ( 10^( r p/ 20) - 1) / ( 10^( r p/ 20) +1) 10^( - r s/ 20) ] ;
[ n, f o, ao, w] = r emezor d( f , a, dev, f s) ;
b = r emez( n, f o, ao, w) ;
f r eqz( b, 1, 1024, f s) ;
t i t l e( ' Lowpass Fi l t er Desi gned t o Speci f i cat i ons' ) ;
Notethat thefilter fallsslightlyshort of meetingthestopbandattenuation and
passband ripplespecifications. Usingn+1 in thecall tor emez instead of n
achieves thedesired amplitudecharacteristics.
Example 2
Design alowpass filter with a1500 Hz passbandcutoff frequency and2000 Hz
stopband cutoff frequency, with a samplingfrequency of 8000 Hz, a maximum
stopband amplitudeof 0.1, and a maximumpassband error (ripple) of 0.01.
0 100 200 300 400 500 600 700 800 900 1000
1200
1000
800
600
400
200
0
Frequency (Hz)
P
h
a
s
e

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

(
d
B
)
Lowpass Filter Designed to Specifications
remezord
7-358
[ n, f o, ao, w] = r emezor d( [ 1500 2000] , [ 1 0] , [ 0. 01 0. 1] , 8000 ) ;
b = r emez( n, f o, ao, w) ;
This is equivalent to
c = r emezor d( [ 1500 2000] , [ 1 0] , [ 0. 01 0. 1] , 8000, ' cel l ' ) ;
b = r emez( c{: }) ;
Note I nsomecases, r emezor d underestimatesor overestimatestheorder n. I f
thefilter does not meet thespecifications, try a higher order such as n+1
or n+2.
Results areinaccurateif thecutoff frequencies arenear 0 or theNyquist
frequency.
Algorithm r emezor d uses thealgorithmsuggested in [1]. This method is inaccuratefor
band edges closetoeither 0 or theNyquist frequency (f s/ 2).
See Also
References [1] Rabiner, L.R., and O. Herrmann, ThePredictability of Certain Optimum
FiniteI mpulseResponseDigital Filters,I EEE Trans. on Circuit Theory,
Vol. CT-20, No. 4 (J uly 1973), pp. 401-408.
[2] Rabiner, L.R., and B. Gold. Theory and Application of Digital Signal
Processing. Englewood Cliffs, NJ : Prentice-Hall, 1975, pp. 156-157.
but t or d Butterworth filter order selection.
cheb1or d Chebyshev typeI filter order selection.
cheb2or d Chebyshev typeI I filter order selection.
el l i por d Elliptic filter order selection.
kai ser or d Estimateparameters for an FI R filter design with
Kaiser window.
r emez Parks-McClellan optimal FI R filter design.
resample
7-359
7resample
Purpose Changesamplingrateby any rational factor.
Syntax y = r esampl e( x, p, q)
y = r esampl e( x, p, q, n)
y = r esampl e( x, p, q, n, bet a)
y = r esampl e( x, p, q, b)
[ y, b] = r esampl e( x, p, q)
Description y = r esampl e( x, p, q) resamples thesequencein vector x at p/ q times the
original samplingrate, usinga polyphasefilter implementation. p and q must
bepositiveintegers. Thelength of y is equal tocei l ( l engt h( x) *p/ q) . I f x is a
matrix, r esampl e works down thecolumns of x.
r esampl e applies an anti-aliasing(lowpass) FI R filter tox duringthe
resamplingprocess. I t designs thefilter usingf i r l s with a Kaiser window.
y = r esampl e( x, p, q, n) uses n terms on either sideof thecurrent sample,
x( k) , toperformtheresampling. Thelength of theFI R filter r esampl e uses is
proportional ton; larger values of n providebetter accuracy at theexpenseof
morecomputation time. Thedefault for n is 10. I f you let n =0, r esampl e
performs a nearest-neighbor interpolation
y( k) = x( r ound( ( k- 1) *q/ p) +1)
wherey( k) =0 if theindex tox is greater than l engt h( x) .
y = r esampl e( x, p, q, n, bet a) uses bet a as thedesign parameter for the
Kaiser windowthat r esampl e employs in designingthelowpass filter. The
default for bet a is 5.
y = r esampl e( x, p, q, b) filters x usingthevector of filter coefficients b.
[ y, b] = r esampl e( x, p, q) returns thevector b, which contains the
coefficients of thefilter applied tox duringtheresamplingprocess.
resample
7-360
Examples Resamplea simplelinear sequenceat 3/2 theoriginal rate.
f s1 = 10; %Or i gi nal sampl i ng f r equency i n Hz
t 1 = 0: 1/ f s1: 1; %Ti me vect or
x = t 1; %Def i ne a l i near sequence
y = r esampl e( x, 3, 2) ; %Now r esampl e i t
t 2 = ( 0: ( l engt h( y) - 1) ) *2/ ( 3*f s1) ; %New t i me vect or
pl ot ( t 1, x, ' *' , t 2, y, ' o' , - 0. 5: 0. 01: 1. 5, - 0. 5: 0. 01: 1. 5, ' : ' )
l egend( ' or i gi nal ' , ' r esampl ed' ) ; xl abel ( ' Ti me' )
Noticethat thelast fewpoints of theoutput y areinaccurate. I n its filtering
process, r esampl e assumes thesamples at times beforeand after thegiven
samples in x areequal tozero. Thus largedeviations fromzeroat theend
points of thesequencex can causeinaccuracies in y at its end points. The
followingtwoplots illustratethis sideeffect of r esampl e.
x = [ 1: 10 9: - 1: 1] ; y = r esampl e( x, 3, 2) ;
subpl ot ( 2, 1, 1) ;
pl ot ( 1: 19, x, ' *' , ( 0: 28) *2/ 3 + 1, y, ' o' ) ;
t i t l e( ' Edge Ef f ect s Not Not i ceabl e' ) ;
l egend( ' or i gi nal ' , ' r esampl ed' ) ;
0.5 0 0.5 1 1.5
0.5
0
0.5
1
1.5
Time
original
resampled
resample
7-361
x = [ 10: - 1: 1 2: 10] ; y = r esampl e( x, 3, 2) ;
subpl ot ( 2, 1, 2) ;
pl ot ( 1: 19, x, ' *' , ( 0: 28) *2/ 3 + 1, y, ' o' )
t i t l e( ' Edge Ef f ect s Ver y Not i ceabl e' ) ;
l egend( ' or i gi nal ' , ' r esampl ed' ) ;
See Also
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
deci mat e Decreasethesamplingratefor a sequence
(decimation).
f i r l s Least squarelinear-phaseFI R filter design.
i nt er p I ncreasesamplingrateby an integer factor
(interpolation).
i nt er p1 One-dimensional data interpolation (tablelookup)
(seetheMATLAB documentation).
i nt f i l t I nterpolation FI R filter design.
kai ser Kaiser window.
spl i ne Cubic splineinterpolation (seetheMATLAB
documentation).
upf i r dn Upsample, apply an FI R filter, and downsample.
residuez
7-362
7residuez
Purpose z-transformpartial-fraction expansion.
Syntax [ r , p, k] = r esi duez( b, a)
[ b, a] = r esi duez( r , p, k)
Description r esi duez converts a discretetimesystem, expressed as theratioof two
polynomials, topartial fraction expansion, or residue, form. I t alsoconvertsthe
partial fraction expansion back totheoriginal polynomial coefficients.
[ r , p, k] = r esi duez( b, a) finds theresidues, poles, and direct terms of a
partial fraction expansion of theratioof twopolynomials, b(z) and a(z).
Vectors b and a specify thecoefficients of thepolynomials of thediscrete-time
systemb(z)/ a(z) in descendingpowers of z.
I f therearenomultipleroots and a >n- 1,
Thereturned column vector r contains theresidues, column vector p contains
thepolelocations, and rowvector k contains thedirect terms. Thenumber of
poles is
n = l engt h( a) - 1 = l engt h( r ) = l engt h( p)
Thedirect termcoefficient vector k is empty if l engt h( b) is less than
l engt h( a) ; otherwise
l engt h( k) = l engt h( b) - l engt h( a) + 1
I f p( j ) = . . . = p( j +s- 1) is a poleof multiplicity s, then theexpansion
includes terms of theform
b z ( ) b
0
b
1
z
1
b
2
z
2
L b
m
z
m
+ + + + =
a z ( ) a
0
a
1
z
1
a
2
z
2
L a
n
z
n
+ + + + =
b z ( )
a z ( )
----------
r 1 ( )
1 p 1 ( )z
1

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

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

---------------------------
r j 1 + ( )
1 p j ( )z
1
( )
2
----------------------------------- L
r j s
r
1 + ( )
1 p j ( )z
1
( )
s
r
------------------------------------ + + +
residuez
7-363
[ b, a] = r esi duez( r , p, k) with threeinput arguments and twooutput
arguments, converts thepartial fraction expansion back topolynomials with
coefficients in rowvectors b and a.
Ther esi due function in thestandard MATLAB languageis very similar to
r esi duez. I t computes thepartial fraction expansion of continuous-time
systems in theLaplacedomain (seereference[1]), rather than discrete-time
systems in thez-domain as does r esi duez.
Algorithm r esi duez applies standardMATLAB functions andpartial fraction techniques
tofind r , p, and k fromb and a. I t finds:
1 Thedirect terms a usingdeconv (polynomial longdivision) when
l engt h( b) >l engt h( a) - 1.
2 Thepoles usingp =r oot s( a) .
3 Any repeated poles, reorderingthepoles accordingtotheir multiplicities.
4 Theresiduefor each nonrepeatingpolep
i
by multiplyingb(z)/a(z) by
1/(1 - p
i
z
-1
) and evaluatingtheresultingrational function at z =p
i
.
5 Theresidues for therepeated poles by solving
S2*r 2 = h - S1*r 1
for r 2 using\ . h is theimpulseresponseof thereduced b(z)/ a(z), S1 is a
matrix whosecolumns areimpulseresponses of thefirst-order systems
madeup of thenonrepeatingroots, and r 1 is a column containingthe
residues for thenonrepeatingroots. Each column of matrix S2 is an impulse
response. For each root p
j
of multiplicity s
j
, S2 contains s
j
columns
representingtheimpulseresponses of each of thefollowingsystems.
Thevector h andmatrices S1 andS2 haven +xt r a rows, wheren is thetotal
number of roots and theinternal parameter xt r a, set to1 by default,
determines thedegreeof overdetermination of thesystemof equations.
1
1 pj z
1

-----------------------
1
1 pj z
1
( )
2
------------------------------- L
1
1 pj z
1
( )
s
j
-------------------------------- , , ,
residuez
7-364
See Also
References [1] Oppenheim, A.V., and R.W. Schafer, Digital Signal Processing,
Prentice-Hall, Englewood Cliffs, NJ , 1975, pp. 166-170.
convmt x Convolution matrix.
deconv Deconvolution and polynomial division (seethe
MATLAB documentation).
pol y Polynomial with specified roots (seetheMATLAB
documentation).
pr ony Pronys method for timedomain I I R filter design.
r esi due Partial fraction expansion (seetheMATLAB
documentation).
r oot s Polynomial roots (seetheMATLAB documentation).
ss2t f Convert state-spacefilter parameters to
zero-pole-gain form.
t f 2ss Convert transfer function filter parameters to
state-spaceform.
t f 2zp Convert transfer function filter parameters to
zero-pole-gain form.
zp2ss Convert zero-pole-gain filter parameters to
state-spaceform.
rlevinson
7-365
7rlevinson
Purpose ComputethereverseLevinson-Durbin recursion.
Syntax r = r l evi nson( a, ef i nal )
[ r , u] = r l evi nson( a, ef i nal )
[ r , u, k] = r l evi nson( a, ef i nal )
[ r , u, k, e] = r l evi nson( a, ef i nal )
Description ThereverseLevinson-Durbin recursion implements thestep-down algorithm
for solvingthefollowingsymmetric Toeplitz systemof linear equations for r,
wherer =[ r(1) L r(p+1)] and r(i)
*
denotes thecomplex conjugateof r(i).
r = r l evi nson( a, ef i nal ) solves theabovesystemof equations for r given
vector a, wherea = [1 a(2) L a(p+1)]. I n linear prediction applications, r
represents theautocorrelation sequenceof theinput totheprediction error
filter, wherer ( 1) is thezero-lagelement. Thefigurebelowshows thetypical
filter of this type, whereH(z) is theoptimal linear predictor, x(n) is theinput
signal, is thepredicted signal, and e(n) is theprediction error.
I nput vector a represents thepolynomial coefficients of this prediction error
filter in descendingpowers of z.
r 1 ( ) r 2 ( )

L r p ( )

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


r p ( ) L r 2 ( ) r 1 ( )
a 2 ( )
a 3 ( )

a p 1 + ( )
r 2 ( )
r 3 ( )

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 ( )
PredictionError
A z ( )
A z ( ) 1 a 2 ( )z
1
L a n 1 + ( )z
p
+ + + =
rlevinson
7-366
Thefilter must beminimumphasetogeneratea valid autocorrelation
sequence. ef i nal is thescalar prediction error power, which is equal tothe
varianceof theprediction error signal,
2
(e).
[ r , u] = r l evi nson( a, ef i nal ) returns upper triangular matrix U fromthe
UDU
*
decomposition
where
andE isadiagonal matrixwithelementsreturnedin output e (seebelow). This
decomposition permits theefficient evaluation of theinverseof the
autocorrelation matrix, R
-1
.
Output matrix u contains theprediction filter polynomial, a, fromeach
iteration of thereverseLevinson-Durbin recursion
wherea
i
(j) isthejth coefficient of theith order predictionfilter polynomial (i.e.,
step i in therecursion). For example, the5th order prediction filter polynomial
is
a5 = u( 5: - 1: 1, 5) '
Notethat u( p+1: - 1: 1, p+1) ' is theinput polynomial coefficient vector a.
R
1
UE
1
U

=
R
r 1 ( ) r 2 ( )

L r p ( )

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


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

a
2
2 ( )

L a
p 1 +
p 1 + ( )

0 a
2
1 ( )

a
p 1 +
p ( )

0 0 a
p 1 +
p 1 ( )


0 L 0 a
p 1 +
1 ( )

=
rlevinson
7-367
[ r , u, k] = r l evi nson( a, ef i nal ) returnsavector k of length(p+1) containing
thereflection coefficients. Thereflection coefficients aretheconjugates of the
values in thefirst rowof u.
k = conj ( u( 1, 2: end) )
[ r , u, k, e] = r l evi nson( a, ef i nal ) returns a vector of length p+1containing
theprediction errors fromeach iteration of thereverseLevinson-Durbin
recursion: e( 1) is theprediction error fromthefirst-order model, e( 2) is the
prediction error fromthesecond-order model, and soon.
Theseprediction error values formthediagonal of thematrix E in theUDU
*
decomposition of R
-1
.
.
See Also
References [1] Kay, S.M., Modern Spectral Estimation: Theory and Application,
Prentice-Hall, Englewood Cliffs, NJ , 1988.
R
1
UE
1
U

=
l evi nson ComputetheLevinson-Durbin recursion.
l pc Computelinear prediction filter coefficients.
pr ony Pronys method for timedomain I I R filter design.
st mcb Computea linear model usingSteiglitz-McBride
iteration.
rooteig
7-368
7rooteig
Purpose Estimatefrequency and power content usingtheeigenvector method.
Syntax [ w, pow] = r oot ei g( x, p)
[ f , pow] = r oot ei g( . . . , f s)
[ w, pow] = r oot ei g( . . . , ' corr' )
Description [ w, pow] = r oot ei g( x, p) estimatesthefrequencycontent inthetimesamples
of a signal x, and returns w, a vector of frequencies in rad/sample, and the
correspondingsignal power in thevector powin dB per rad/sample. Theinput
signal x is specified either as:
A rowor column vector representingoneobservation of thesignal
A rectangular array for which each rowof x represents a separate
observation of thesignal (for example, each rowis oneoutput of an array of
sensors, as in array processing), such that x' *x is an estimateof the
correlation matrix
Note You can usetheoutput of cor r mt x togeneratesuch an array x.
You can specify thesecond input argument p as either:
A scalar integer. I n this case, thesignal subspacedimension is p.
A two-element vector. I n this case, p( 2) , thesecondelement of p, represents
a threshold that is multiplied by
min
, thesmallest estimated eigenvalueof
thesignals correlation matrix. Eigenvalues belowthethreshold
min
*p( 2)
areassignedtothenoisesubspace. I n this case, p( 1) specifies themaximum
dimension of thesignal subspace.
Theextra threshold parameter in thesecond entry in p provides you more
flexibility and control in assigningthenoiseand signal subspaces.
Thelength of thevector wis thecomputed dimension of thesignal subspace.
For real-valuedinput data x, thelength of thecorrespondingpower vector pow
is given by
l engt h( pow) = 0. 5*l engt h( w)
For complex-valued input data x, powand whavethesamelength.
rooteig
7-369
[ f , pow] = r oot ei g( . . . , f s) returns thevector of frequencies f calculated
in Hz. You supply thesamplingfrequency f s in Hz. I f you specify f s with the
empty vector [ ] , thesamplingfrequency defaults to1 Hz.
[ w, pow] = r oot ei g( . . . , ' corr' ) forces theinput argument x tobe
interpretedasacorrelationmatrixrather thanamatrixof signal data. For this
syntax, you must supply a squarematrix for x, and all of its eigenvalues must
benonnegative.
Note You can placethestring' corr' anywhereafter p.
Examples Findthefrequencycontent in asignal composedof threecomplex exponentials
in noise. Usethemodified covariancemethod toestimatethecorrelation
matrix used by theeigenvector method.
r andn( ' st at e' , 1) ; n=0: 99;
s = exp( i *pi / 2*n) +2*exp( i *pi / 4*n) +exp( i *pi / 3*n) +r andn( 1, 100) ;
%Est i mat e cor r el at i on mat r i x usi ng modi f i ed covar i ance met hod.
X=cor r mt x( s, 12, ' mod' ) ;
[ W, P] = r oot ei g( X, 3)
W=
0. 7811
1. 5767
1. 0554
P =
3. 9971
1. 1362
1. 4102
Algorithm Theeigenvector methodusedbyr oot ei g is thesameas that usedbypei g. The
algorithmperforms eigenspaceanalysis of thesignals correlation matrix in
order toestimatethesignals frequency content.
rooteig
7-370
Thedifferencebetween pei g and r oot ei g is:
pei g returns thepseudospectrumat all frequency samples.
r oot ei g returns theestimated discretefrequency spectrum, alongwith the
correspondingsignal power estimates.
r oot ei g is most useful for frequency estimation of signals madeup of a sumof
sinusoids embedded in additivewhiteGaussian noise.
See Also
cor r mt x Calculatea data matrix for correlation estimation.
pei g Estimatethepseudospectrumusingtheeigenvector
method.
pmusi c EstimatethepseudospectrumusingtheMUSI C
algorithm.
r oot musi c Estimatefrequency and power content usingtheroot
MUSI C algorithm.
rootmusic
7-371
7rootmusic
Purpose Estimatefrequency and power content usingtheroot MUSI C algorithm.
Syntax [ w, pow] = r oot musi c( x, p)
[ f , pow] = r oot musi c( . . . , f s)
[ w, pow] = r oot musi c( . . . , ' corr' )
Description [ w, pow] = r oot musi c( x, p) estimates thefrequency content in thetime
samples of a signal x, andreturns w, a vector of frequencies in rad/sample, and
thecorrespondingsignal power in thevector powin dB per rad/sample. The
input signal x is specified either as:
A rowor column vector representingoneobservation of thesignal
A rectangular array for which each rowof x represents a separate
observation of thesignal (for example, each rowis oneoutput of an array of
sensors, as in array processing), such that x' *x is an estimateof the
correlation matrix
Note You can usetheoutput of cor r mt x togeneratesuch an array x.
You can specify thesecond input argument p as either:
A scalar integer. I n this case, thesignal subspacedimension is p.
A two-element vector. I n this case, p( 2) , thesecondelement of p, represents
a threshold that is multiplied by
min
, thesmallest estimated eigenvalueof
thesignals correlation matrix. Eigenvalues belowthethreshold
min
*p( 2)
areassignedtothenoisesubspace. I n this case, p( 1) specifies themaximum
dimension of thesignal subspace.
Theextra threshold parameter in thesecond entry in p provides you more
flexibility and control in assigningthenoiseand signal subspaces.
Thelength of thevector wis thecomputed dimension of thesignal subspace.
For real-valuedinput data x, thelength of thecorrespondingpower vector pow
is given by
l engt h( pow) = 0. 5*l engt h( w)
For complex-valued input data x, powand whavethesamelength.
rootmusic
7-372
[ f , pow] = r oot musi c( . . . , f s) returns thevector of frequencies f calculated
in Hz. You supply thesamplingfrequency f s in Hz. I f you specify f s with the
empty vector [ ] , thesamplingfrequency defaults to1 Hz.
[ w, pow] = r oot musi c( . . . , ' corr' ) forces theinput argument x tobe
interpretedasacorrelation matrixrather than amatrixof signal data. For this
syntax, you must supply a squarematrix for x, and all of its eigenvalues must
benonnegative.
Note You can placethestring' corr' anywhereafter p.
Examples Findthefrequency content in asignal composedof threecomplexexponentials
in noise. Usethemodified covariancemethod toestimatethecorrelation
matrix used by theMUSI C algorithm.
r andn( ' st at e' , 1) ; n=0: 99;
s = exp( i *pi / 2*n) +2*exp( i *pi / 4*n) +exp( i *pi / 3*n) +r andn( 1, 100) ;
%Est i mat e cor r el at i on mat r i x usi ng modi f i ed covar i ance met hod.
X=cor r mt x( s, 12, ' mod' ) ;
[ W, P] = r oot musi c( X, 3)
W=
1. 5769
0. 7817
1. 0561
P =
1. 1358
3. 9975
1. 4102
Algorithm TheMUSI C algorithmused by r oot musi c is thesameas that used by pmusi c.
Thealgorithmperforms eigenspaceanalysis of thesignals correlation matrix
in order toestimatethesignals frequency content.
rootmusic
7-373
Thedifferencebetween pmusi c and r oot musi c is:
pmusi c returns thepseudospectrumat all frequency samples.
r oot musi c returns theestimated discretefrequency spectrum, alongwith
thecorrespondingsignal power estimates.
r oot musi c is most useful for frequency estimation of signals madeupof asum
of sinusoids embedded in additivewhiteGaussian noise.
See Also
cor r mt x Calculatea data matrix for correlation estimation.
pei g Estimatethepseudospectrumusingtheeigenvector
method.
pmusi c EstimatethepseudospectrumusingtheMUSI C
algorithm.
r oot ei g Estimatefrequency and power content usingtheroot
eigenvector method.
sawtooth
7-374
7sawtooth
Purpose Generatea sawtooth or trianglewave.
Syntax x = sawt oot h( t )
x = sawt oot h( t , wi dt h)
Description sawt oot h( t ) generates a sawtooth wavewith period 2 for theelements of
timevector t . sawt oot h( t ) is similar tosi n( t ) , but creates a sawtooth wave
with peaks of -1and 1 instead of a sinewave. Thesawtooth waveis defined to
be-1at multiples of 2 and toincreaselinearly with timewith aslopeof 1/ at
all other times.
sawt oot h( t , wi dt h) generates a modified trianglewavewherewi dt h, a scalar
parameter between 0 and 1, determines thepoint between 0 and 2 at which
themaximumoccurs. Thefunction increases from-1 to1 on theinterval 0 to
2*wi dt h, then decreases linearly from1 to-1 on theinterval 2*wi dt h to2.
Thus a parameter of 0.5 specifies a standard trianglewave, symmetric about
timeinstant with peak-to-peak amplitudeof 1. sawt oot h( t , 1) is equivalent
tosawt oot h( t ) .
See Also
chi r p Generatea swept-frequency cosine.
cos Computethecosineof vector/matrix elements (seethe
MATLAB documentation).
di r i c ComputetheDirichlet or periodic sinc function.
gauspul s Generatea Gaussian-modulated sinusoidal pulse.
pul st r an Generatea pulsetrain.
r ect pul s Generatea sampled aperiodic rectangle.
si n Computethesineof vector/matrix elements (seethe
MATLAB documentation).
si nc Computethesinc or sin(t)/t function.
squar e Generatea squarewave.
t r i pul s Generatea sampled aperiodic triangle.
schurrc
7-375
7schurrc
Purpose Computereflection coefficients froman autocorrelation sequence.
Syntax k = schur r c( r )
[ k, e] = schur r c( r )
Description k = schur r c( r ) uses theSchur algorithmtocomputea vector k of reflection
coefficients froma vector r representingan autocorrelation sequence. k and r
arethesamesize. Thereflection coefficients represent thelatticeparameters
of a prediction filter for a signal with thegiven autocorrelation sequence, r .
When r is a matrix, schur r c treats each column of r as an independent
autocorrelation sequence, and produces a matrix k, thesamesizeas r . Each
column of k represents thereflection coefficients for thelatticefilter for
predictingtheprocess with thecorrespondingautocorrelation sequencer .
[ k, e] = schur r c( r ) alsocomputesthescalar e, theprediction error variance.
When r is amatrix, e is arowvector. Thelength of e is thesameas thenumber
of columns of r .
Examples CreateanautocorrelationsequencefromtheMATLAB speechsignal contained
in mt l b. mat , andusetheSchur algorithmtocomputethereflection coefficients
of a latticeprediction filter for this autocorrelation sequence.
l oad mt l b
r = xcor r ( mt l b( 1: 5) , ' unbi ased' ) ;
k = schur r c( r ( 5: end) )
k =
- 0. 7583
0. 1384
0. 7042
- 0. 3699
See Also l evi nson Computea prediction filter usingtheLevinson
algorithm.
References [1] Proakis, J . and D. Manolakis, Digital Signal Processing: Principles,
Algorithms, and Applications, Third edition, Prentice-Hall, 1996, pp. 868-873.
seqperiod
7-376
7seqperiod
Purpose Computetheperiod of a sequence.
Syntax p = seqper i od( x)
[ p, num] = seqper i od( x)
Description p = seqper i od( x) returns theinteger p that corresponds totheperiod of the
sequencein a vector x. Theperiod p is computed as theminimumlength of a
subsequencex( 1: p) of x that repeats itself continuously every p samples in x.
Thelength of x does not havetobea multipleof p, sothat an incomplete
repetition is permitted at theend of x. I f thesequencex is not periodic, then
p =l engt h( x) .
I f x isamatrix, thenseqper i odchecksfor periodicityalongeachcolumnof x.
Theresultingoutput pis arowvector with thesamenumber of columns as x.
I f x is amultidimensional array, then seqper i od checks for periodicityalong
thefirst nonsingleton dimension of x. I n this case:
- p is a multidimensional array of integers with a leadingsingleton
dimension.
- Thelengths of theremainingdimensions of p correspond tothoseof the
dimensions of x after thefirst nonsingleton one.
[ p, num] = seqper i od( x) alsoreturnsthenumber numof repetitionsof x( 1: p)
in x. nummight not bean integer.
Examples x = [ 4 0 1 6;
2 0 2 7;
4 0 1 5;
2 0 5 6] ;
p = seqper i od( x)
p =
2 1 4 3
seqperiod
7-377
Theresult implies:
Thefirst column of x has period 2.
Thesecond column of x has period 1.
Thethird column of x is not periodic, sop( 3) is just thenumber of rows of x.
Thefourth column of x has period 3, although thelast (second) repetition of
theperiodic sequenceis incomplete.
sgolay
7-378
7sgolay
Purpose Savitzky-Golay filter design.
Syntax b = sgol ay( k, f )
b = sgol ay( k, f , w)
Description b = sgol ay( k, f ) designs a Savitzky-Golay FI R smoothingfilter b. The
polynomial order k must beless than theframesize, f , which must beodd. I f
k =f - 1, thedesigned filter produces nosmoothing. Theoutput, b, is an f -by-f
matrix whoserows represent thetime-varyingFI R filter coefficients. I n a
smoothingfilter implementation (for example, sgol ayf i l t ), thelast ( f - 1) / 2
rows (each an FI R filter) areappliedtothesignal duringthestartuptransient,
and thefirst ( f - 1) / 2 rows areapplied tothesignal duringtheterminal
transient. Thecenter rowis applied tothesignal in thesteady state.
b = sgol ay( k, f , w) specifies a weightingvector wwith length f , which
contains thereal, positive-valued weights tobeused duringtheleast-squares
minimization.
Remarks Savitzky-Golay smoothingfilters (alsocalled digital smoothingpolynomial
filters or least squares smoothingfilters) aretypically used tosmooth out a
noisy signal whosefrequency span (without noise) is large. I n this typeof
application, Savitzky-Golay smoothingfilters performmuch better than
standardaveragingFI R filters, which tend tofilter out a significant portion of
thesignals high frequency content alongwith thenoise. Although
Savitzky-Golay filters aremoreeffectiveat preservingthepertinent high
frequency components of thesignal, they areless successful than standard
averagingFI R filters at rejectingnoise.
Savitzky-Golay filters areoptimal in thesensethat they minimizethe
least-squares error in fittinga polynomial toeach frameof noisy data.
See Also f i r 1 Window-based finiteimpulseresponsefilter design
standard response.
f i r l s Least squarelinear-phaseFI R filter design.
f i l t er Filter data with a recursive(I I R) or nonrecursive
(FI R) filter.
sgol ayf i l t Savitzky-Golay filtering.
sgolay
7-379
References [1] Orfanidis, S.J ., I ntroductiontoSignal Processing, Prentice-Hall, Englewood
Cliffs, NJ , 1996.
sgolayfilt
7-380
7sgolayfilt
Purpose Savitzky-Golay filtering.
Syntax y = sgol ayf i l t ( x, k, f )
y = sgol ayf i l t ( x, k, f , w)
Description y = sgol ayf i l t ( x, k, f ) applies a Savitzky-Golay FI R smoothingfilter tothe
data in vector x. I f x is a matrix, sgol ayf i l t operates on each column. The
polynomial order k must beless than theframesize, f , which must beodd. I f
k =f - 1, thefilter produces nosmoothing.
y = sgol ayf i l t ( x, k, f , w) specifies a weightingvector wwith length f , which
contains thereal, positive-valued weights tobeused duringtheleast-squares
minimization.
Remarks Savitzky-Golay smoothingfilters (alsocalled digital smoothingpolynomial
filters or least-squares smoothingfilters) aretypically used tosmooth out a
noisy signal whosefrequency span (without noise) is large. I n this typeof
application, Savitzky-Golay smoothingfilters performmuch better than
standardaveragingFI R filters, which tend tofilter out a significant portion of
thesignals high frequency content alongwith thenoise. Although
Savitzky-Golay filters aremoreeffectiveat preservingthepertinent high
frequency components of thesignal, they areless successful than standard
averagingFI R filters at rejectingnoise.
Savitzky-Golay filters areoptimal in thesensethat they minimizethe
least-squares error in fittinga polynomial toframes of noisy data.
Example Smooth themt l b signal by applyinga cubic Savitzky-Golay filter todata
frames of length 41.
l oad mt l b %Load t he dat a.
smt l b = sgol ayf i l t ( mt l b, 3, 41) ; %Appl y t he 3r d- or der f i l t er .
subpl ot ( 2, 1, 1)
pl ot ( [ 1: 2000] , mt l b( 1: 2000) ) ; axi s( [ 0 2000 - 4 4] ) ;
t i t l e( ' mt l b' ) ; gr i d;
subpl ot ( 2, 1, 2)
pl ot ( [ 1: 2000] , smt l b( 1: 2000) ) ; axi s( [ 0 2000 - 4 4] ) ;
t i t l e( ' smt l b' ) ; gr i d;
sgolayfilt
7-381
See Also
References [1] Orfanidis, S.J ., I ntroductiontoSignal Processing, Prentice-Hall, Englewood
Cliffs, NJ , 1996.
0 500 1000 1500 2000
4
2
0
2
4
mtlb
0 500 1000 1500 2000
4
2
0
2
4
smtlb
medf i l t 1 One-dimensional median filtering.
f i l t er Filter data with a recursive(I I R) or nonrecursive
(FI R) filter.
sgol ay Savitzky-Golay filter design.
sosf i l t Second-order (biquadratic) I I R digital filtering.
sinc
7-382
7sinc
Purpose Sinc function.
Syntax y = si nc( x)
Description si nc computes thesinc function of an input vector or array, wherethesinc
function is
This function is thecontinuous inverseFourier transformof therectangular
pulseof width 2 and height 1.
y = si nc( x) returns an array y thesamesizeas x, whoseelements arethe
si nc function of theelements of x.
Thespaceof functions bandlimited in thefrequency range is
spannedby theinfinite(yet countable) set of sincfunctions shiftedby integers.
Thus any such bandlimitedfunction g(t) can bereconstructedfromits samples
at integer spacings.
Example Performideal bandlimited interpolation by assumingthat thesignal tobe
interpolatedis0outsideof thegiventimeinterval andthat it hasbeensampled
at exactly theNyquist frequency.
t = ( 1: 10) ' ; %A col umn vect or of t i me sampl es
r andn( ' st at e' , 0) ;
x = r andn( si ze( t ) ) ; %A col umn vect or of dat a
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
7-383
t s = l i nspace( - 5, 15, 600) ' ; %t i mes at whi ch t o i nt er pol at e dat a
y = si nc( t s( : , ones( si ze( t ) ) ) - t ( : , ones( si ze( t s) ) ) ' ) *x;
pl ot ( t , x, ' o' , t s, y)
See Also
5 0 5 10 15
2
1.5
1
0.5
0
0.5
1
1.5
2
chi r p Generatea swept-frequency cosine.
cos ComputetheCosineof vector/matrix elements (see
theMATLAB documentation).
di r i c ComputetheDirichlet or periodic sinc function.
gauspul s Generatea Gaussian-modulated sinusoidal pulse.
pul st r an Generatea pulsetrain.
r ect pul s Generatea sampled aperiodic rectangle.
sawt oot h Generatea sawtooth or trianglewave.
si n Computethesineof vector/matrix elements (seethe
MATLAB documentation).
squar e Generatea squarewave.
t r i pul s Generatea sampled aperiodic triangle.
sos2cell
7-384
7sos2cell
Purpose Convert a second-order section matrix tocell arrays.
Syntax c = sos2cel l ( m)
c = sos2cel l ( m, g)
Description c = sos2cel l ( m) changes an L-by-6 second-order section matrix mgenerated
by t f 2sos intoa 1-by-L cell array of 1-by-2 cell arrays c. You can usec to
specify a quantized filter with L cascaded second-order sections.
Thematrix mshould havetheform
m= [ b1 a1; b2 a2; . . . ; bL aL]
whereboth bi and ai , with i =1, ..., L, are1-by-3 rowvectors. Theresultingc
is a 1-by-L cell array of cells of theform
c = { {b1 a1} {b2 a2} . . . {bL aL} }
c = sos2cel l ( m, g) with theoptional gain termg, prepends theconstant
valueg toc. When you usetheadded gain termin thecommand, c is a 1-by-L
cell array of cells of theform
c = {{g, 1} {b1, a1} {b2, a2}. . . {bL, aL} }
Examples Usesos2cel l toconvert the2-by-6 second-order section matrix produced by
t f 2sos intoa 1-by-2 cell array c of cells. Display thesecond entry in thefirst
cell in c.
[ b, a] = el l i p( 4, 0. 5, 20, 0. 6) ;
m= t f 2sos( b, a) ;
c = sos2cel l ( m) ;
c{1}{2}
ans =
1. 0000 0. 1677 0. 2575
See Also
t f 2sos Convert transfer functions tosecond-order sections.
cel l 2sos Convert cell arrays for second-order sections toa
matrix.
sos2ss
7-385
7sos2ss
Purpose Convert digital filter second-order section parameters tostate-spaceform.
Syntax [ A, B, C, D] = sos2ss( sos)
[ A, B, C, D] = sos2ss( sos, g)
Description sos2ss converts a second-order section representation of a given digital filter
toan equivalent state-spacerepresentation.
[ A, B, C, D] = sos2ss( sos) converts thesystemsos, in second-order section
form, toa single-input, single-output state-spacerepresentation.
Thediscretetransfer function in second-order section formis given by
sos is a L-by-6 matrix organized as
Theentries of sos must bereal for proper conversion tostatespace. The
returned matrix A is sizeN-by-N, whereN =2L-1, B is a length N-1 column
vector, Cis a length N-1 rowvector, and Dis a scalar.
[ A, B, C, D] = sos2ss( sos, g) converts thesystemsos in second-order section
formwith 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
2k
z
2
+ +
1 a
1k
z
1
a
2k
z
2
+ +
--------------------------------------------------------- -
k 1 =
L

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

=
sos2ss
7-386
Example Computethestate-spacerepresentation of a simplesecond-order section
systemwith 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 first converts fromsecond-order sections totransfer function using
sos2t f , and then fromtransfer function tostate-spaceusingt f 2ss.
See Also
sos2t f Convert digital filter second-order section
parameters totransfer function form.
sos2zp Convert digital filter second-order section
parameters tozero-pole-gain form.
ss2sos Convert state-spacedata for a digital filter to
second-order sections form.
t f 2ss Convert transfer function data for a filter to
state-spaceform.
zp2ss Convert zero-pole-gain data for a filter tostate-space
form.
sos2tf
7-387
7sos2tf
Purpose Convert digital filter second-order section data totransfer function form.
Syntax [ b, a] = sos2t f ( sos)
[ b, a] = sos2t f ( sos, g)
Description sos2t f converts a second-order section representation of a given digital filter
toan equivalent transfer function representation.
[ b, a] = sos2t f ( sos) returns thenumerator coefficients b and denominator
coefficients a of thetransfer function that describes a discrete-timesystem
given by sos in second-order section form. Thesecond-order section format of
H(z) is given by
sos is an L-by-6 matrix that contains thecoefficients of each second-order
section stored in its rows.
Rowvectors b and a contain thenumerator and denominator coefficients of
H(z) stored in descendingpowers of z.
[ b, a] = sos2t f ( sos, g) returns thetransfer function that describes a
discrete-timesystemgiven by sos in second-order section formwith gain g.
H z ( ) H
k
z ( )
k 1 =
L

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

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

=
sos2tf
7-388
Algorithm sos2t f uses theconv function tomultiply all of thenumerator and
denominator second-order polynomials together.
Example Computethetransfer function representation of asimplesecond-order section
system.
sos = [ 1 1 1 1 0 - 1; - 2 3 1 1 10 1] ;
[ b, a] = sos2t f ( sos)
b =
- 2 1 2 4 1
a =
1 10 0 - 10 - 1
See Also
l at c2t f Latticefilter totransfer function conversion.
sos2ss Convert digital filter second-order sections data to
state-spaceform.
sos2zp Convert digital filter second-order sections data to
zero-pole-gain form.
ss2t f Convert state-spacedata for a filter totransfer
function form.
t f 2sos Convert transfer function data for a digital filter to
second-order sections form.
zp2t f Convert zero-pole-gain data for a filter totransfer
function form.
sos2zp
7-389
7sos2zp
Purpose Convert digital filter second-order section parameters tozero-pole-gain form.
Syntax [ z, p, k] = sos2zp( sos)
[ z, p, k] = sos2zp( sos, g)
Description sos2zp converts a second-order section representation of a given digital filter
toan equivalent zero-pole-gain representation.
[ z, p, k] = sos2zp( sos) returns thezeros z, poles p, and gain k of thesystem
given by sos in second-order section form. Thesecond-order section format of
H(z) is given by
sos is an L-by-6 matrix that contains thecoefficients of each second-order
section in its rows.
Column vectors z and p contain thezeros and poles of thetransfer
function H(z).
wheretheorders n and maredetermined by thematrix sos.
[ z, p, k] = sos2zp( sos, g) returns thezeros z, poles p, and gain k of the
systemgiven by sos in second-order section formwith gain g.
H z ( ) H
k
z ( )
k 1 =
L

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

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

=
sos2zp
7-390
Example Computethepoles, zeros, and gain of a simplesystemin second-order section
form.
sos = [ 1 1 1 1 0 - 1; - 2 3 1 1 10 1] ;
[ z, p, k] = sos2zp( sos)
z =
- 0. 5000 + 0. 8660i
- 0. 5000 - 0. 8660i
1. 7808
- 0. 2808
p =
- 1. 0000
1. 0000
- 9. 8990
- 0. 1010
k =
- 2
Algorithm sos2zp finds thepoles and zeros of each second-order section by repeatedly
callingt f 2zp.
See Also
sos2ss Convert digital filter second-order section
parameters tostate-spaceform.
sos2t f Convert digital filter second-order section
parameters totransfer function form.
ss2zp Convert state-spacefilter parameters to
zero-pole-gain form.
t f 2zp Convert transfer function filter parameters to
zero-pole-gain form.
zp2sos Convert digital filter zero-pole-gain parameters to
second-order sections form.
sosfilt
7-391
7sosfilt
Purpose Second-order (biquadratic) I I R digital filtering.
Syntax y = sosf i l t ( sos, x)
Description y = sosf i l t ( sos, x) applies thesecond-order section digital filter sos tothe
vector x. Theoutput, y, is thesamelength as x.
sos represents thesecond-order section digital filter H(z)
by an L-by-6matrix containingthecoefficients of each second-order section in
its rows.
I f x is a matrix, sosf i l t applies thefilter toeach column of x independently.
Output y is a matrix of thesamesize, containingthefiltered data
correspondingtoeach column of x.
See Also
References [1] Orfanidis, S.J ., I ntroductiontoSignal Processing, Prentice-Hall, Englewood
Cliffs, NJ , 1996.
H z ( ) H
k
z ( )
k 1 =
L

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

= =
sos
b
01
b
11
b
21
1 a
11
a
21
b
02
b
12
b
22
1 a
12
a
22
M M M M M M
b
0L
b
1L
b
2L
1 a
1L
a
2L
=
f i l t er Apply a filter todata.
medf i l t 1 One-dimensional median filtering.
sgol ayf i l t Savitzky-Golay filtering.
specgram
7-392
7specgram
Purpose Time-dependent frequency analysis (spectrogram).
Syntax B = specgr am( a)
B = specgr am( a, nf f t )
[ B, f ] = specgr am( a, nf f t , f s)
[ B, f , t ] = specgr am( a, nf f t , f s)
B = specgr am( a, nf f t , f s, wi ndow)
B = specgr am( a, nf f t , f s, wi ndow, numover l ap)
specgr am( a)
B = specgr am( a, f , f s, wi ndow, numover l ap)
Description specgr amcomputes thewindowed discrete-timeFourier transformof a signal
usinga slidingwindow. Thespectrogramis themagnitudeof this function.
B = specgr am( a) calculates thespectrogramfor thesignal in vector a. This
syntax uses thedefault values:
nf f t = mi n( 256, l engt h( a) )
f s = 2
wi ndowis a periodic Hann (Hanning) windowof length nf f t .
numover l ap = l engt h( wi ndow) / 2
nf f t specifies theFFT length that specgr amuses. This valuedetermines the
frequencies at which thediscrete-timeFourier transformis computed. f s is a
scalar that specifies thesamplingfrequency. wi ndowspecifies a windowing
function andthenumber of samples specgr amuses in its sectioningof vector a.
numover l ap is thenumber of samples by which thesections overlap. Any
arguments that you omit fromtheend of theinput parameter list usethe
default values shown above.
I f a is real, specgr amcomputes thediscrete-timeFourier transformat positive
frequencies only. I f n is even, specgr amreturns nf f t / 2+1 rows (includingthe
zeroand Nyquist frequency terms). I f n is odd, specgr amreturns nf f t / 2 rows.
Thenumber of columns in B is
k = f i x( ( n- numover l ap) / ( l engt h( wi ndow) - numover l ap) )
I f a iscomplex, specgr amcomputesthediscrete-timeFourier transformat both
positiveandnegativefrequencies. I n this case, Bis acomplexmatrix with nf f t
specgram
7-393
rows. Timeincreases linearly across thecolumns of B, startingwith sample1
in column 1. Frequency increases linearly down therows, startingat 0.
B = specgr am( a, nf f t ) uses thespecified FFT length nf f t in its calculations.
[ B, f ] = specgr am( a, nf f t , f s) returns a vector f of frequencies at which the
function computes thediscrete-timeFourier transform. f s has noeffect on the
output B; it is a frequency scalingmultiplier.
[ B, f , t ] = specgr am( a, nf f t , f s) returns frequency and timevectors f and t
respectively. t is a column vector of scaled times, with length equal tothe
number of columns of B. t ( j ) is theearliest timeat which thejth window
intersects a. t ( 1) is always equal to0.
B = specgr am( a, nf f t , f s, wi ndow) specifies a windowingfunction and the
number of samples per section of thex vector. I f you supplyascalar for wi ndow,
specgr amuses a Hann windowof that length. Thelength of thewindowmust
beless than or equal tonf f t .
B = specgr am( a, nf f t , f s, wi ndow, numover l ap) overlaps thesections of x by
numover l ap samples.
You can usetheempty matrix [ ] tospecify thedefault valuefor any input
argument. For example,
B = specgr am( x, [ ] , 10000)
is equivalent to
B = specgr am( x)
but with a samplingfrequency of 10,000 Hz instead of thedefault 2 Hz.
specgr am( . . . ) with nooutput argumentsdisplaysthescaledlogarithmof the
spectrogramin thecurrent figurewindowusing
i magesc( t , f , 20*l og10( abs( b) ) ) , axi s xy, col or map( j et )
Theaxi s xy modedisplays thelow-frequency content of thefirst portion of the
signal in thelower-left corner of theaxes. specgr amuses f s tolabel theaxes
accordingtotruetimeand frequency.
specgram
7-394
B = specgr am( a, f , f s, wi ndow, numover l ap) computes thespectrogramat the
frequencies specifiedin f , usingeither thechirpz-transform(for morethan 20
evenly spaced frequencies) or a polyphasedecimation filter bank. f is a vector
of frequencies in hertz; it must haveat least twoelements.
Algorithm specgr amcalculates thespectrogramfor a given signal as follows:
1 I t splits thesignal intooverlappingsections and applies thewindow
specified by thewi ndowparameter toeach section.
2 I t computes thediscrete-timeFourier transformof each section with a
length nf f t FFT toproducean estimateof theshort-termfrequencycontent
of thesignal; thesetransforms makeup thecolumns of B. Thequantity
( l engt h( wi ndow) - numover l ap) specifies by howmany samples specgr am
shifts thewindow.
3 For real input, specgr amtruncates thespectrogramtothefirst nf f t / 2 +1
points for nf f t even and ( nf f t +1) / 2 for nf f t odd.
Example Plot thespectrogramof a digitized speech signal.
l oad mt l b
specgr am( mt l b, 512, Fs, kai ser ( 500, 5) , 475)
t i t l e( ' Spect r ogr am' )
Time
F
r
e
q
u
e
n
c
y
Spectrogram
0 0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4 0.45
0
500
1000
1500
2000
2500
3000
3500
specgram
7-395
Diagnostics An appropriatediagnosticmessageis displayedwhen incorrect arguments are
used.
Requi r es wi ndow' s l engt h t o be no gr eat er t han t he FFT l engt h.
Requi r es NOVERLAP t o be st r i ct l y l ess t han t he wi ndow l engt h.
Requi r es posi t i ve i nt eger val ues f or NFFT and NOVERLAP.
Requi r es vect or i nput .
See Also
References [1] Oppenheim, A.V., and R.W. Schafer, Discrete-TimeSignal Processing,
Prentice-Hall, Englewood Cliffs, NJ , 1989, pp. 713-718.
[2] Rabiner, L.R., and R.W. Schafer, Digital Processingof Speech Signals,
Prentice-Hall, Englewood Cliffs, NJ , 1978.
coher e Estimatemagnitudesquared coherencefunction
between twosignals.
csd Estimatethecross spectral density (CSD) of two
signals.
pwel ch Estimatethepower spectral density (PSD) of asignal
usingWelchs method.
t f e Transfer function estimatefrominput and output.
sptool
7-396
7sptool
Purpose Open thedigital signal processingGUI (SPTool).
Syntax spt ool
Description spt ool opens SPTool, a graphical user interface(GUI ) that manages a suiteof
four other GUI s. TheseGUI s provideaccess tomany of thesignal, filter, and
spectral analysis functions in thetoolbox. When you typespt ool at the
command line, thefollowingGUI opens.
UsingSPTool you can:
Analyzesignals listed in theSignals list box with theSignal Browser
Design or edit filters with theFilter Designer (includes a Pole/ZeroEditor)
Analyzefilter responsesfor filterslistedintheFilterslist boxwiththeFilter
Viewer
Apply filters in theFilters list box tosignals in theSignals list box
Createand analyzesignal spectra with theSpectrumViewer
You can activatethefour integrated signal processingGUI s fromSPTool.
sptool
7-397
Signal Browser
TheSignal Browser allows you toview, measure, andanalyzethetime-domain
information of oneor moresignals. ToactivatetheSignal Browser, press the
Viewbutton under theSignals list box in SPTool.
Filter Designer
TheFilter Designer allows you todesign andedit FI R andI I R filters of various
lengths andtypes, with standard(lowpass, highpass, bandpass, bandstop, and
multiband) configurations. ToactivatetheFilter Designer, press either the
NewDesign button or theEdit Design button under theFilters list box in
SPTool.
sptool
7-398
TheFilter Designer hasaPole/ZeroEditor youcanaccessfromtheAlgorithms
menu.
sptool
7-399
Filter Viewer
TheFilter Viewer allows you toviewthecharacteristics of a designed or
importedfilter, includingitsmagnituderesponse, phaseresponse, groupdelay,
pole-zeroplot, impulseresponse, and step response. ToactivatetheFilter
Viewer, press theViewbutton under theFilters list box in SPTool.
You can analyzemultiplefilter responses by checkingseveral responseplot
options, as shown in thenext figure.
sptool
7-400
Spectrum Viewer
TheSpectrumViewer allowsyoutographicallyanalyzefrequency-domaindata
usinga variety of methods of spectral density estimation, includingtheBurg
method, theFFT method, themultitaper method (MTM), theMUSI C
eigenvector method, Welchs method, and theYule-Walker AR method. To
activatetheSpectrumViewer:
Press theCreatebutton under theSpectra list box tocomputethepower
spectral density for a signal selected in theSignals list box in SPTool.
Press theViewbutton toanalyzespectraselectedunder theSpectralist box
in SPTool.
Press theUpdatebutton under theSpectra list box in SPTool tomodify a
selected power spectral density signal.
sptool
7-401
I n addition, you can right-click in any plot display area of theGUI s tomodify
signal properties.
SeeChapter 6, SPTool: A Signal ProcessingGUI Suite,for afull discussion of
howtouseSPTool.
See Also f dat ool Open theFilter Design and Analysis Tool.
square
7-402
7square
Purpose Generatea squarewave.
Syntax x = squar e( t )
x = squar e( t , dut y)
Description x = squar e( t ) generates a squarewavewith period 2 for theelements of
timevector t . squar e( t ) is similar tosi n( t ) , but creates a squarewavewith
peaks of 1 instead of a sinewave.
x = squar e( t , dut y) generates a squarewavewith specifiedduty cycle, dut y.
Theduty cycleis thepercent of theperiod in which thesignal is positive.
See Also
chi r p Generatea swept-frequency cosine.
cos Computethecosineof vector/matrix elements (see
theMATLAB documentation).
di r i c ComputetheDirichlet or periodic sinc function.
gauspul s Generatea Gaussian-modulated sinusoidal pulse.
pul st r an Generatea Pulsetrain.
r ect pul s Generatea sampled aperiodic rectangle.
sawt oot h Generatea sawtooth or trianglewave.
si n Computethesineof vector/matrix elements (seethe
MATLAB documentation).
si nc Computethesinc or sin(t)/t function.
t r i pul s Generatea sampled aperiodic triangle.
ss2sos
7-403
7ss2sos
Purpose Convert digital filter state-spaceparameters tosecond-order sections form.
Syntax [ sos, g] = ss2sos( A, B, C, D)
[ sos, g] = ss2sos( A, B, C, D, i u)
[ sos, g] = ss2sos( A, B, C, D, ' or der ' )
[ sos, g] = ss2sos( A, B, C, D, i u, ' or der ' )
[ sos, g] = ss2sos( A, B, C, D, i u, ' or der ' , ' scal e' )
sos = ss2sos( . . . )
Description ss2sos converts a state-spacerepresentation of a given digital filter toan
equivalent second-order section representation.
[ sos, g] = ss2sos( A, B, C, D) finds a matrix sos in second-order section form
with gain g that is equivalent tothestate-spacesystemrepresented by input
arguments A, B, C, andD. Theinput systemmust besingleoutput andreal. sos
is an L-by-6 matrix
whoserows contain thenumerator and denominator coefficients b
ik
and a
ik
of
thesecond-order sections of H(z).
[ sos, g] = ss2sos( A, B, C, D, i u) specifies a scalar i u that determines which
input of thestate-spacesystemA, B, C, Dis used in theconversion. Thedefault
for i u is 1.
sos
b
01
b
11
b
21
1 a
11
a
21
b
02
b
12
b
22
1 a
12
a
22
M M M M M M
b
0L
b
1L
b
2L
1 a
1L
a
2L
=
H z ( ) g H
k
z ( )
k 1 =
L

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

= =
ss2sos
7-404
[ sos, g] = ss2sos( A, B, C, D, ' or der ' ) and
[ sos, g] = ss2sos( A, B, C, D, i u, ' or der ' ) specifytheorder of therows in sos,
where' or der ' is:
' down' , toorder thesections sothefirst rowof sos contains thepoles closest
totheunit circle
' up' , toorder thesections sothefirst rowof sos contains thepoles farthest
fromtheunit circle(default)
Thezeros arealways paired with thepoles closest tothem.
[ sos, g] = ss2sos( A, B, C, D, i u, ' or der ' , ' scal e' ) specifies thedesired
scalingof thegain and thenumerator coefficients of all second-order sections,
where' scal e' is:
' none' , toapply noscaling(default)
' i nf ' , toapply infinity-normscaling
' t wo' , toapply 2-normscaling
Usinginfinity-normscalingin conjunction with up-orderingminimizes the
probability of overflowin therealization. Using2-normscalingin conjunction
with down-orderingminimizes thepeak round-off noise.
sos = ss2sos( . . . ) embeds theoverall systemgain, g, in thefirst section,
H
1
(z), sothat
Example Find a second-order section formof a Butterworth lowpass filter.
[ A, B, C, D] = but t er ( 5, 0. 2) ;
sos = ss2sos( A, B, C, D)
sos =
0. 0013 0. 0013 0 1. 0000 - 0. 5095 0
1. 0000 2. 0008 1. 0008 1. 0000 - 1. 0966 0. 3554
1. 0000 1. 9979 0. 9979 1. 0000 - 1. 3693 0. 6926
H z ( ) H
k
z ( )
k 1 =
L

=
ss2sos
7-405
Algorithm ss2sos uses a four-step algorithmtodeterminethesecond-order section
representation for an input state-spacesystem:
1 I t finds thepoles and zeros of thesystemgiven by A, B, C, and D.
2 I t uses thefunction zp2sos, which first groups thezeros and poles into
complexconjugatepairsusingthecpl xpai r function. zp2sos thenformsthe
second-order sections by matchingthepoleand zeropairs accordingtothe
followingrules:
a Match thepoles closest totheunit circlewith thezeros closest tothose
poles.
b Match thepoles next closest totheunit circlewith thezeros closest to
thosepoles.
c Continueuntil all of thepoles and zeros arematched.
ss2sos groups real poles intosections with thereal poles closest tothemin
absolutevalue. Thesameruleholds for real zeros.
3 I t orders thesections accordingtotheproximity of thepolepairs totheunit
circle. ss2sos normally orders thesections with poles closest totheunit
circlelast in thecascade. You can tell ss2sos toorder thesections in the
reverseorder by specifyingthe' down' flag.
4 ss2sos scales thesections by thenormspecified in the' scal e' argument.
For arbitrary H(), thescalingis defined by
wherep can beeither or 2. Seethereferences for details. This scalingis
an attempt tominimizeoverflowor peak round-off noisein fixedpoint filter
implementations.
Diagnostics I f thereis morethan oneinput tothesystem, ss2sos gives thefollowingerror
message.
St at e- space syst emmust have onl y one i nput .
H
p
1
2
------ H ( )
p
d
0
2

1
p
---
=
ss2sos
7-406
See Also
References [1] J ackson, L.B., Digital Filters and Signal Processing, 3rd ed., Kluwer
Academic Publishers, Boston, 1996. Chapter 11.
[2] Mitra, S.K., Digital Signal Processing: A Computer-Based Approach,
McGraw-Hill, NewYork, 1998. Chapter 9.
[3] Vaidyanathan, P.P.,Robust Digital Filter Structures, Handbook for
Digital Signal Processing, S.K. Mitra and J .F. Kaiser, ed., J ohn Wiley & Sons,
NewYork, 1993, Chapter 7.
cpl xpai r Group complex numbers intocomplex conjugate
pairs.
sos2ss Convert digital filter second-order sections
parameters tostate-spaceform.
ss2t f Convert state-spacefilter parameters totransfer
function form.
ss2zp Convert state-spacefilter parameters to
zero-pole-gain form.
t f 2sos Convert digital filter transfer function parameters to
second-order sections form.
zp2sos Convert digital filter zero-pole-gain parameters to
second-order sections form.
ss2tf
7-407
7ss2tf
Purpose Convert state-spacefilter parameters totransfer function form.
Syntax [ b, a] = ss2t f ( A, B, C, D, i u)
Description ss2t f converts astate-spacerepresentation of agiven systemtoan equivalent
transfer function representation.
[ b, a] = ss2t f ( A, B, C, D, i u) returns thetransfer function
of thesystem
fromthei u-th input. Vector a contains thecoefficients of thedenominator in
descendingpowersof s. Thenumerator coefficientsarereturnedinarrayb with
as manyrowsas thereareoutputs y. ss2t f alsoworkswith systemsin discrete
time, in which caseit returns thez-transformrepresentation.
Thess2t f function is part of thestandard MATLAB language.
Algorithm Thess2t f function uses pol y tofind thecharacteristic polynomial det(sI -A)
and theequality
H s ( )
B s ( )
A s ( )
---------- - C sI A ( )
1
B D + = =
x

Ax Bu + =
y Cx Du + =
H s ( ) C sI A ( )
1
B
det sI A BC + ( ) det sI A ( )
det sI A ( )
------------------------------------------------------------------------------ = =
ss2tf
7-408
See Also
l at c2t f Latticefilter totransfer function conversion.
sos2t f Convert digital filter second-order section
parameters totransfer function form.
ss2sos Convert digital filter state-spaceparameters to
second-order sections form.
ss2zp Convert state-spacefilter parameters to
zero-pole-gain form.
t f 2ss Convert transfer function filter parameters to
state-spaceform.
zp2t f Convert zero-pole-gain filter parameters totransfer
function form.
ss2zp
7-409
7ss2zp
Purpose Convert state-spacefilter parameters tozero-pole-gain form.
Syntax [ z, p, k] = ss2zp( A, B, C, D, i )
Description ss2zp converts astate-spacerepresentation of agiven systemtoan equivalent
zero-pole-gain representation. Thezeros, poles, and gains of state-space
systems represent thetransfer function in factored form.
[ z, p, k] = ss2zp( A, B, C, D, i u) calculates thetransfer function in factored
form
of thecontinuous-timesystem
fromthei th input (usingthei th columns of B and D). Thecolumn vector p
contains thepolelocations of thedenominator coefficients of thetransfer
function. Thematrix z contains thenumerator zeros in its columns, with as
many columns as thereareoutputs y(rows in C). Thecolumn vector k contains
thegains for each numerator transfer function.
ss2zp alsoworks for discretetimesystems. Theinput state-spacesystemmust
bereal.
Thess2zp function is part of thestandard MATLAB language.
Example Herearetwoways of findingthezeros, poles, and gains of a discrete-time
transfer function
b = [ 2 3] ;
a = [ 1 0. 4 1] ;
[ b, a] = eqt f l engt h( b, a) ;
[ z, p, k] = t f 2zp( b, a)
H s ( )
Z s ( )
P s ( )
---------- k
s z
1
( ) s z
2
( )L s z
n
( )
s p
1
( ) s p
2
( )L s p
n
( )
------------------------------------------------------------------ = =
x

Ax Bu + =
y Cx Du + =
H z ( )
2 3z
1
+
1 0.4z
1
z
2
+ +
----------------------------------------- =
ss2zp
7-410
z =
0. 0000
- 1. 5000
p =
- 0. 2000 + 0. 9798i
- 0. 2000 - 0. 9798i
k =
2
[ A, B, C, D] = t f 2ss( b, a) ;
[ z, p, k] = ss2zp( A, B, C, D, 1)
z =
0. 0000
- 1. 5000
p =
- 0. 2000 + 0. 9798i
- 0. 2000 - 0. 9798i
k =
2
Algorithm ss2zp finds thepoles fromtheeigenvalues of theA array. Thezeros arethe
finitesolutions toa generalized eigenvalueproblem.
z = ei g( [ A B; C D] , di ag( [ ones( 1, n) 0] ) ;
I n many situations this algorithmproduces spurious large, but finite, zeros.
ss2zp interprets theselargezeros as infinite.
ss2zp finds thegains by solvingfor thefirst nonzeroMarkov parameters.
ss2zp
7-411
See Also
References [1] Laub, A.J ., and B.C. Moore, Calculation of Transmission Zeros UsingQZ
Techniques,Automatica 14 (1978), p. 557.
pzmap Pole-zeromap of LTI system(seetheControl System
Toolbox documentation).
sos2zp Convert digital filter second-order section parameters
tozero-pole-gain form.
ss2sos Convert digital filter state-spaceparameters to
second-order sections form.
ss2t f Convert state-spacefilter parameters totransfer
function form.
t f 2zp Convert transfer function filter parameters to
zero-pole-gain form.
zp2ss Convert zero-pole-gain filter parameters to
state-spaceform.
stmcb
7-412
7stmcb
Purpose Computea linear model usingSteiglitz-McBrideiteration.
Syntax [ b, a] = st mcb( x, nb, na)
[ b, a] = st mcb( x, u, nb, na)
[ b, a] = st mcb( x, nb, na, ni t er )
[ b, a] = st mcb( x, u, nb, na, ni t er )
[ b, a] = st mcb( x, nb, na, ni t er , ai )
[ b, a] = st mcb( x, u, nb, na, ni t er , ai )
Description Steiglitz-McBrideiteration is an algorithmfor findingan I I R filter with a
prescribed timedomain impulseresponse. I t has applications in both filter
design and systemidentification (parametric modeling).
[ b, a] = st mcb( x, nb, na) finds thecoefficients b anda of thesystemb(z)/ a(z)
with approximateimpulseresponsex, exactly nb zeros, and exactly na poles.
[ b, a] = st mcb( x, u, nb, na) findsthesystemcoefficients b anda of thesystem
that, given u as input, has x as output. x and u must bethesamelength.
[ b, a] = st mcb( x, nb, na, ni t er ) and
[ b, a] = st mcb( x, u, nb, na, ni t er ) useni t er iterations. Thedefault for ni t er
is 5.
[ b, a] = st mcb( x, nb, na, ni t er , ai ) and
[ b, a] = st mcb( x, u, nb, na, ni t er , ai ) usethevector ai astheinitial estimate
of thedenominator coefficients. I f ai is not specified, st mcb uses theoutput
argument from[ b, ai ] = pr ony( x, 0, na) as thevector ai .
st mcb returns theI I R filter coefficients in length nb+1 and na+1 rowvectors b
and a. Thefilter coefficients areordered in descendingpowers of z.
H z ( )
B z ( )
A z ( )
-----------
b 1 ( ) b 2 ( )z
1
L b nb 1 + ( )z
nb
+ + +
a 1 ( ) a 2 ( )z
1
L a na 1 + ( )z
na
+ + +
-------------------------------------------------------------------------------------------- = =
stmcb
7-413
Example Approximatetheimpulseresponseof a Butterworth filter with a systemof
lower order.
[ b, a] = but t er ( 6, 0. 2) ;
h = f i l t er ( b, a, [ 1 zer os( 1, 100) ] ) ;
f r eqz( b, a, 128)
[ bb, aa] = st mcb( h, 4, 4) ;
f r eqz( bb, aa, 128)
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
600
500
400
300
200
100
0
Normalized Frequency ( rad/sample)
P
h
a
s
e

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

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

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

(
d
B
)
stmcb
7-414
Algorithm st mcb attemptstominimizethesquarederror between theimpulseresponsex'
of b(z)/ a(z) and theinput signal x.
st mcb iterates usingtwosteps:
1 I t prefilters x and u using1/a(z).
2 I t solves a systemof linear equations for b and a using\ .
st mcb repeatsthisprocessni t er times. Nocheckingisdonetoseeif theb and a
coefficients haveconverged in fewer than ni t er iterations.
Diagnostics I f x and u havedifferent lengths, st mcb gives thefollowingerror message.
X and U must have same l engt h.
See Also
References [1] Steiglitz, K., andL.E. McBride, A Techniquefor theI dentificationof Linear
Systems,I EEE Trans. Automatic Control, Vol. AC-10 (1965), pp. 461-464.
[2] Ljung, L., SystemI dentification: Theory for theUser, Prentice-Hall,
Englewood Cliffs, NJ , 1987, p. 297.
min
a b ,
x i ( ) x' i ( )
2
i 0 =

l evi nson ComputetheLevinson-Durbin recursion.


l pc Computelinear prediction filter coefficients.
ar yul e Computean estimateof AR model parameters using
theYule-Walker method.
pr ony Pronys method for timedomain I I R filter design.
strips
7-415
7strips
Purpose Strip plot.
Syntax st r i ps( x)
st r i ps( x, n)
st r i ps( x, sd, f s)
st r i ps( x, sd, f s, scal e)
Description st r i ps( x) plots vector x in horizontal strips of length 250. I f x is a matrix,
st r i ps( x) plots each column of x. Theleft-most column (column 1) is thetop
horizontal strip.
st r i ps( x, n) plots vector x in strips that areeach n samples long.
st r i ps( x, sd, f s) plots vector x in strips of duration sd seconds, given a
samplingfrequency of f s samples per second.
st r i ps( x, sd, f s, scal e) scales thevertical axes.
I f x is a matrix, st r i ps( x, n) , st r i ps( x, sd, f s) , and st r i ps( x, sd, f s, scal e)
plot thedifferent columns of x on thesamestrip plot.
st r i ps ignores theimaginary part of complex-valued x.
Example Plot twoseconds of a frequency modulated sinusoid in 0.25 second strips.
f s = 1000; %Sampl i ng f r equency
t = 0: 1/ f s: 2; %Ti me vect or
x = vco( si n( 2*pi *t ) , [ 10 490] , f s) ; %FM wavef or m
st r i ps( x, 0. 25, f s)
strips
7-416
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
pl ot Linear two-dimensional plot (seetheMATLAB
documentation).
st em Plot discretesequencedata (seetheMATLAB
documentation).
tf2latc
7-417
7tf2latc
Purpose Convert transfer function filter parameters tolatticefilter form.
Syntax [ k, v] = t f 2l at c( b, a)
k = t f 2l at c( 1, a)
[ k, v] = t f 2l at c( 1, a)
k = t f 2l at c( b)
Description [ k, v] = t f 2l at c( b, a) finds thelatticeparameters k and theladder
parameters v for an I I R (ARMA) lattice-ladder filter, normalizedby a( 1) . Note
that an error is generated if oneor moreof thelatticeparameters areexactly
equal to1.
k = t f 2l at c( 1, a) finds thelatticeparameters k for an I I R all-pole(AR)
latticefilter.
[ k, v] = t f 2l at c( 1, a) returns thescalar ladder coefficient at thecorrect
position in vector v. All other elements of v arezero.
k = t f 2l at c( b) finds thelatticeparameters k for an FI R (MA) latticefilter,
normalized by b( 1) .
See Also
l at c2t f Convert latticefilter parameters totransfer function
form.
l at cf i l t Latticeand lattice-ladder filter implementation.
t f 2sos Convert transfer function digital filter parameters to
second-order sections form.
t f 2ss Convert transfer function filter parameters to
state-spaceform.
t f 2zp Convert transfer function filter parameters to
zero-pole-gain form.
tf2sos
7-418
7tf2sos
Purpose Convert digital filter transfer function data tosecond-order sections form.
Syntax [ sos, g] = t f 2sos( b, a)
[ sos, g] = t f 2sos( b, a, ' or der ' )
[ sos, g] = t f 2sos( b, a, ' or der ' , ' scal e' )
sos = t f 2sos( . . . )
Description t f 2sos convertsatransfer function representationof agiven digital filter toan
equivalent second-order section representation.
[ sos, g] = t f 2sos( b, a) finds a matrix sos in second-order section formwith
gain g that is equivalent tothedigital filter represented by transfer function
coefficient vectors a and b.
sos is an L-by-6 matrix
whoserows contain thenumerator and denominator coefficients b
ik
and a
ik
of
thesecond-order sections of H(z).
H z ( )
B z ( )
A z ( )
-----------
b
1
b
2
z
1
L b
nb 1 +
z
nb
+ + +
a
1
a
2
z
1
L a
na 1 +
z
na
+ + +
---------------------------------------------------------------------------- = =
sos
b
01
b
11
b
21
1 a
11
a
21
b
02
b
12
b
22
1 a
12
a
22

b
0L
b
1L
b
2L
1 a
1L
a
2L
=
H z ( ) g H
k
z ( )
k 1 =
L

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

= =
tf2sos
7-419
[ sos, g] = t f 2sos( b, a, ' or der ' ) specifies theorder of therows in sos, where
' or der ' is:
' down' , toorder thesections sothefirst rowof sos contains thepoles closest
totheunit circle
' up' , toorder thesections sothefirst rowof sos contains thepoles farthest
fromtheunit circle(default)
[ sos, g] = t f 2sos( b, a, ' or der ' , ' scal e' ) specifies thedesiredscalingof the
gain and numerator coefficients of all second-order sections, where' scal e' is:
' none' , toapply noscaling(default)
' i nf ' , toapply infinity-normscaling
' t wo' , toapply 2-normscaling
Usinginfinity-normscalingin conjunction with up-orderingminimizes the
probability of overflowin therealization. Using2-normscalingin conjunction
with down-orderingminimizes thepeak round-off noise.
sos = t f 2sos( . . . ) embeds theoverall systemgain, g, in thefirst section,
H
1
(z), sothat
Algorithm t f 2sos uses a four-step algorithmtodeterminethesecond-order section
representation for an input transfer function system:
1 I t finds thepoles and zeros of thesystemgiven by b and a.
2 I t uses thefunction zp2sos, which first groups thezeros and poles into
complexconjugatepairsusingthecpl xpai r function. zp2sos thenformsthe
second-order sections by matchingthepoleand zeropairs accordingtothe
followingrules:
a Match thepoles closest totheunit circlewith thezeros closest tothose
poles.
b Match thepoles next closest totheunit circlewith thezeros closest to
thosepoles.
H z ( ) H
k
z ( )
k 1 =
L

=
tf2sos
7-420
c Continueuntil all of thepoles and zeros arematched.
t f 2sos groups real poles intosections with thereal poles closest tothemin
absolutevalue. Thesameruleholds for real zeros.
3 I t orders thesections accordingtotheproximity of thepolepairs totheunit
circle. t f 2sos normally orders thesections with poles closest totheunit
circlelast in thecascade. You can tell t f 2sos toorder thesections in the
reverseorder by specifyingthe' down' flag.
4 t f 2sos scales thesections by thenormspecified in the' scal e' argument.
For arbitrary H(), thescalingis defined by
wherep can beeither or 2. Seethereferences for details on thescaling.
This scalingis an attempt tominimizeoverflowor peak round-off noisein
fixed point filter implementations.
See Also
References [1] J ackson, L.B., Digital Filters and Signal Processing, 3rd ed., Kluwer
Academic Publishers, Boston, 1996, Chapter 11.
[2] Mitra, S.K., Digital Signal Processing: A Computer-Based Approach,
McGraw-Hill, NewYork, 1998, Chapter 9.
H
p
1
2
------ H ( )
p
d
0
2

1
p
---
=
cpl xpai r Group complex numbers intocomplex conjugate
pairs.
sos2t f Convert digital filter second-order section
parameters totransfer function form.
ss2sos Convert digital filter state-spaceparameters to
second-order sections form.
t f 2ss Convert transfer function filter parameters to
state-spaceform.
t f 2zp Convert transfer function filter parameters to
zero-pole-gain form.
zp2sos Convert digital filter zero-pole-gain parameters to
second-order sections form.
tf2sos
7-421
[3] Vaidyanathan, P.P., Robust Digital Filter Structures, Handbook for
Digital Signal Processing, S.K. Mitra and J .F. Kaiser, ed., J ohn Wiley & Sons,
NewYork, 1993, Chapter 7.
tf2ss
7-422
7tf2ss
Purpose Convert transfer function filter parameters tostate-spaceform.
Syntax [ A, B, C, D] = t f 2ss( b, a)
Description t f 2ss converts theparameters of a transfer function representation of a given
systemtothoseof an equivalent state-spacerepresentation.
[ A, B, C, D] = t f 2ss( b, a) returns theA, B, C, and Dmatrices of a statespace
representation for thesingle-input transfer function
in controller canonical form
Theinput vector a contains thedenominator coefficients in descendingpowers
of s. Therowsof thematrixbcontainthevectorsof numerator coefficients(each
rowcorrespondstoanoutput). I nthediscrete-timecase, youmust supplyb and
a tocorrespond tothenumerator and denominator polynomials with
coefficients in descendingpowers of z.
For discrete-timesystems you must makeb havethesamenumber of columns
as thelength of a. You can dothis by paddingeach numerator representedin b
(and possibly thedenominator represented in thevector a) with trailingzeros.
You can usethefunction eqt f l engt h toaccomplish this if b and a arevectors
of unequal lengths.
Thet f 2ss function is part of thestandard MATLAB language.
Example Consider thesystem
H s ( )
B s ( )
A s ( )
---------- -
b
1
s
nb 1
L b
nb 1
s b
nb
+ + +
a
1
s
na 1
L a
na 1
s a
na
+ + +
------------------------------------------------------------------------------ C sI A ( )
1
B D + = = =
x

Ax Bu + =
y Cx Du + =
H s ( )
2s 3 +
s
2
2s 1 + +
s
2
0.4s 1 + +
--------------------------------- =
tf2ss
7-423
Toconvert this systemtostate-space, type
b = [ 0 2 3; 1 2 1] ;
a = [ 1 0. 4 1] ;
[ A, B, C, D] = t f 2ss( b, a)
A =
- 0. 4000 - 1. 0000
1. 0000 0
B =
1
0
C =
2. 0000 3. 0000
1. 6000 0
D =
0
1
Note Thereis disagreement in theliteratureon namingconventions for the
canonical forms. I t is easy, however, togeneratesimilarity transformations
that convert theseresults toother forms.
See Also
sos2ss Convert a digital filter second-order sections formto
state-spaceform.
ss2t f Convert state-spacefilter parameters totransfer
function form.
t f 2sos Convert digital filter transfer function parameters to
second-order sections form.
t f 2zp Convert transfer function filter parameters to
zero-pole-gain form.
zp2ss Convert zero-pole-gain filter parameters to
state-spaceform.
tf2zp
7-424
7tf2zp
Purpose Convert transfer function filter parameters tozero-pole-gain form.
Syntax [ z, p, k] = t f 2zp( b, a)
Description t f 2zp finds thezeros, poles, and gains of a transfer function.
[ z, p, k] = t f 2zp( b, a) finds thematrix of zeros z, thevector of poles p, and
theassociated vector of gains k fromthetransfer function parameters b and a:
Thenumerator polynomials arerepresented as columns of thematrix b.
Thedenominator polynomial is represented in thevector a.
Given a SI MO continuous-timesystemin polynomial transfer function form
or
you can usetheoutput of t f 2zp toproducethesingle-input, multioutput
(SI MO) factored transfer function form
or
H s ( )
B s ( )
A s ( )
---------- -
b
1
s
nb 1
L b
nb 1
s b
nb
+ + +
a
1
s
na 1
L a
na 1
s a
na
+ + +
------------------------------------------------------------------------------ = =
H z ( )
B z ( )
A z ( )
------------
b
1
b
2
z
1
L b
nb 1
z
nb
b
nb
z
nb 1
+ + +
a
1
a
2
z
1
L a
na 1
z
na
a
na
z
na 1
+ + +
---------------------------------------------------------------------------------------------------------- = =
H s ( )
Z s ( )
P s ( )
---------- k
s z
1
( ) s z
2
( )L s z
m
( )
s p
1
( ) s p
2
( )L s p
n
( )
------------------------------------------------------------------ = =
H z ( )
Z z ( )
P z ( )
---------- k
z z
1
( ) z z
2
( )L z z
m
( )
z p
1
( ) z p
2
( )L z p
n
( )
------------------------------------------------------------------- = =
tf2zp
7-425
Thefollowingdescribes theinput and output arguments for t f 2zp:
Thevector a specifies thecoefficients of thedenominator polynomial A(s)
(or A(z)) in descendingpowers of s (z
-1
).
Theith rowof thematrix b represents thecoefficients of theith numerator
polynomial (theith rowof B(s) or B(z)). Specify as many rows of b as there
areoutputs.
For continuous-timesystems, choosethenumber nbof columnsof b tobeless
than or equal tothelength na of thevector a.
For discrete-timesystems, choosethenumber nbof columns of b tobeequal
tothelength na of thevector a. You can usethefunction eqt f l engt h to
provideequal length vectors in thecasethat b and a arevectors of unequal
lengths. Otherwise, pad thenumerators in thematrix b (and, possibly, the
denominator vector a) with zeros.
Thezerolocations arereturnedin thecolumns of thematrixz, with as many
columns as therearerows in b.
Thepolelocations arereturnedin thecolumn vector p andthegains for each
numerator transfer function in thevector k.
Thet f 2zp function is part of thestandard MATLAB language.
Example Find thezeros, poles, and gains of thediscrete-timesystem
b = [ 2 3] ;
a = [ 1 0. 4 1] ;
[ b, a] = eqt f l engt h( b, a) ; %Make l engt hs equal .
[ z, p, k] = t f 2zp( b, a) %Obt ai n t he zer o- pol e- gai n f or m.
H z ( )
2 3z
1
+
1 0.4z
1
z
2
+ +
----------------------------------------- =
tf2zp
7-426
z =
0
- 1. 5000
p =
- 0. 2000 + 0. 9798i
- 0. 2000 - 0. 9798i
k =
2
See Also
sos2zp Convert digital filter second-order sections
parameters tozero-pole-gain form.
ss2zp Convert state-spacefilter parameters to
zero-pole-gain form.
t f 2sos Convert digital filter transfer function parameters to
second-order sections form.
t f 2ss Convert transfer function filter parameters to
state-spaceform.
zp2t f Convert zero-pole-gain filter parameters totransfer
function form.
tfe
7-427
7tfe
Purpose Estimatethetransfer function frominput and output.
Syntax Txy = t f e( x, y)
Txy = t f e( x, y, nf f t )
[ Txy, f ] = t f e( x, y, nf f t , f s)
Txy = t f e( x, y, nf f t , f s, wi ndow)
Txy = t f e( x, y, nf f t , f s, wi ndow, numover l ap)
Txy = t f e( x, y, . . . , ' df l ag' )
t f e( x, y)
Description Txy = t f e( x, y) finds a transfer function estimateTxy given input signal
vector x and output signal vector y. Thetransfer function is thequotient of the
cross spectrumof x and y and thepower spectrumof x.
Therelationship between theinput x and output y is modeled by thelinear,
time-invariant transfer function Txy.
Vectors x and y must bethesamelength. Txy = t f e( x, y) uses thefollowing
default values:
nf f t = mi n( 256, ( l engt h( x) )
f s = 2
wi ndow is a periodic Hann (Hanning) windowof length nf f t
numover l ap = 0
nf f t specifies theFFT length that t f e uses. This valuedetermines the
frequencies at which thepower spectrumis estimated. f s is a scalar that
specifies thesamplingfrequency. wi ndowspecifies a windowingfunction and
thenumber of samples t f e uses in its sectioningof thex and y vectors.
numover l ap is thenumber of samples by which thesections overlap. Any
arguments that areomitted fromtheend of theparameter list usethedefault
values shown above.
I f x is real, t f e estimates thetransfer function at positivefrequencies only; in
this case, theoutput Txy is a column vector of length nf f t / 2+1 for nf f t even
and ( nf f t +1) / 2 for nf f t odd. I f x or y is complex, t f e estimates thetransfer
function for both positiveand negativefrequencies and Txy has length nf f t .
T
xy
f ( )
P
xy
f ( )
P
xx
f ( )
--------------- =
tfe
7-428
Txy = t f e( x, y, nf f t ) uses thespecified FFT length nf f t in estimatingthe
transfer function.
[ Txy, f ] = t f e( x, y, nf f t , f s) returns a vector f of frequencies at which t f e
estimatesthetransfer function. f s isthesamplingfrequency. f isthesamesize
as Txy, sopl ot ( f , Txy) plots thetransfer function estimateversus properly
scaled frequency. f s has noeffect on theoutput Txy; it is a frequency scaling
multiplier.
Txy = t f e( x, y, nf f t , f s, wi ndow) specifies a windowingfunction and the
number of samplesper section of thex vector. I f you supplyascalar for wi ndow,
Txy uses aHann windowof that length. Thelength of thewindowmust beless
than or equal tonf f t ; t f e zeropads thesections if thelength of thewindow
exceeds nf f t .
Txy = t f e( x, y, nf f t , f s, wi ndow, numover l ap) overlaps thesections of x by
numover l ap samples.
You can usetheempty matrix [ ] tospecify thedefault valuefor any input
argument except x or y. For example,
Txy = t f e( x, y, [ ] , [ ] , kai ser ( 128, 5) )
uses 256 as thevaluefor nf f t and 2 as thevaluefor f s.
Txy = t f e( x, y, . . . , ' df l ag' ) specifies a detrend option, where' df l ag' is:
' l i near ' , toremovethebest straight-linefit fromtheprewindowedsections
of x and y
' mean' , toremovethemean fromtheprewindowed sections of x and y
' none' , for nodetrending(default)
The' df l ag' parameter must appear last in thelist of input arguments. t f e
recognizes a ' df l ag' stringnomatter howmany intermediatearguments are
omitted.
t f e( . . . ) with nooutput arguments plots themagnitudeof thetransfer
function estimateas decibels versus frequency in thecurrent figurewindow.
tfe
7-429
Example Computeand plot thetransfer function estimatebetween twocolored noise
sequences x and y.
h = f i r 1( 30, 0. 2, boxcar ( 31) ) ;
x = r andn( 16384, 1) ;
y = f i l t er ( h, 1, x) ;
t f e( x, y, 1024, [ ] , [ ] , 512)
t i t l e( ' Tr ansf er Funct i on Est i mat e' )
Algorithm t f e uses a four-step algorithm:
1 I t multiplies thedetrended sections by wi ndow.
2 I t takes thelength nf f t FFT of each section.
3 I t averages thesquares of thespectra of thex sections toformPxx and
averages theproducts of thespectra of thex and y sections toformPxy.
4 I t calculates Txy:
Txy = Pxy. / Pxx
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
-45
-40
-35
-30
-25
-20
-15
-10
-5
0
5
Frequency
T
r
a
n
f
e
r

F
u
n
c
t
i
o
n

E
s
t
i
m
a
t
e

(
d
B
)
Transfer Function Estimate
tfe
7-430
Diagnostics An appropriatediagnosticmessageis displayedwhen incorrect arguments are
used.
Requi r es wi ndow' s l engt h t o be no gr eat er t han t he FFT l engt h.
Requi r es NOVERLAP t o be st r i ct l y l ess t han t he wi ndow l engt h.
Requi r es posi t i ve i nt eger val ues f or NFFT and NOVERLAP.
Requi r es vect or ( ei t her r ow or col umn) i nput .
Requi r es i nput s X and Y t o have t he same l engt h.
See Also
et f e Computeempirical transfer function estimateand
periodogram(seetheSystemI dentification Toolbox
documentation).
coher e Estimatemagnitudesquared coherencefunction
between twosignals.
csd Estimatethecross spectral density (CSD) of two
signals.
pwel ch Estimatethepower spectral density (PSD) of asignal
usingWelchs method.
spa Performspectral analysis for input-output data (see
theSystemI dentification Toolbox documentation).
triang
7-431
7triang
Purpose Computea triangular window.
Syntax w = t r i ang( n)
Description t r i ang( n) returns an n-point triangular windowin thecolumn vector w. The
coefficients of a triangular windoware
For n odd:
For n even:
Thetriangular windowis very similar toa Bartlett window. TheBartlett
windowalways ends with zeros at samples 1 and n, whilethetriangular
windowis nonzeroat thosepoints. For n odd, thecenter n- 2 points of
t r i ang( n- 2) areequivalent tobar t l et t ( n) .
Example w = t r i ang( 200) ;
pl ot ( w)
t i t l e( ' Tr i angul ar Wi ndow' )
w k [ ]
2k
n 1 +
------------- 1 k
n 1 +
2
------------- ,
2 n k 1 + ( )
n 1 +
-------------------------------
n 1 +
2
------------- k n ,




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




=
triang
7-432
See Also
References [1] Oppenheim, A.V., and R.W. Schafer, Discrete-TimeSignal Processing,
Prentice-Hall, Englewood Cliffs, NJ , 1989, pp. 447-448.
0 20 40 60 80 100 120 140 160 180 200
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
Triangular Window
bar t l et t Computea Bartlett window.
bl ackman Computea Blackman window.
boxcar Computea rectangular window.
chebwi n Computea Chebyshev window.
hammi ng Computea Hammingwindow.
hann Computea Hann window.
kai ser Computea Kaiser window.
tripuls
7-433
7tripuls
Purpose Generatea sampled aperiodic triangle.
Syntax y = t r i pul s( T)
y = t r i pul s( T, w)
y = t r i pul s( T, w, s)
Description y = t r i pul s( T) returns a continuous, aperiodic, symmetric, unity-height
triangular pulseat thetimes indicatedin array T, centeredabout T=0 andwith
a default width of 1.
y = t r i pul s( T, w) generates a triangular pulseof width w.
y = t r i pul s( T, w, s) generates a triangular pulsewith skew s, where
- 1 <s <1. When s is 0, a symmetric triangular pulseis generated.
See Also
chi r p Generatea swept-frequency cosine.
cos Computethecosineof vector/matrix elements (seethe
MATLAB documentation).
di r i c ComputetheDirichlet or periodic sinc function.
gauspul s Generatea Gaussian-modulated sinusoidal pulse.
pul st r an Generatea pulsetrain.
r ect pul s Generatea sampled aperiodic rectangle.
sawt oot h Generatea sawtooth or trianglewave.
si n Computethesineof vector/matrix elements (seethe
MATLAB documentation).
si nc Computethesinc or sin(t)/t function.
squar e Generatea squarewave.
udecode
7-434
7udecode
Purpose Decode2
n
-level quantized integer inputs tofloating-point outputs.
Syntax y = udecode( u, n)
y = udecode( u, n, v)
y = udecode( u, n, v, ' sat ur at emode' )
Description y = udecode( u, n) inverts theoperation of uencode and reconstructs
quantized floating-point values froman encoded multidimensional array of
integers u. Theinput argument n must bean integer between 2 and 32. The
integer n specifies that thereare2
n
quantization levels for theinputs, sothat
entries in u must beeither:
Signed integers in therange[-2
n
/2, (2
n
/2) - 1]
Unsigned integers in therange[0, 2
n
-1]
I nputs can bereal or complex values of any integer data type(ui nt 8, ui nt 16,
ui nt 32, i nt 8, i nt 16, i nt 32). Overflows (entries in u outsideof theranges
specified above) aresaturated totheendpoints of therangeinterval. The
output y has thesamedimensions as u. I ts entries havevalues in therange
[ - 1, 1] .
y = udecode( u, n, v) decodes u such that theoutput y has values in therange
[ - v, v] , wherethedefault valuefor v is 1.
y = udecode( u, n, v, ' Sat ur at eMode' ) decodes u and treats input overflows
(entries in u outsideof [ - v, v] ) accordingtothestring' sat ur at emode' , which
can beoneof thefollowing:
' sat ur at e' : Saturateoverflows. This is thedefault method for treating
overflows.
- Entries in signed inputs u whosevalues areoutsideof therange
[-2
n
/2, (2
n
/2) - 1] areassignedthevaluedeterminedbytheclosest endpoint
of this interval.
- Entries in unsigned inputs u whosevalues areoutsideof therange
[0, 2
n
-1] areassigned thevaluedetermined by theclosest endpoint of this
interval.
udecode
7-435
' wr ap' : Wrap all overflows accordingtothefollowing:
- Entries in signed inputs u whosevalues areoutsideof therange
[-2
n
/2, (2
n
/2) - 1] arewrapped back intothat rangeusingmodulo2
n
arithmetic (calculated usingu =mod( u+2^n/ 2, 2^n) - ( 2^n/ 2) ).
- Entries in unsigned inputs u whosevalues areoutsideof therange
[0, 2
n
-1] arewrapped back intotherequired rangebeforedecodingusing
modulo2
n
arithmetic (calculated using u =mod( u, 2^n) ).
Examples u = i nt 8( [ - 1 1 2 - 5] ) ; %Cr eat e a si gned 8- bi t i nt eger st r i ng.
ysat = udecode( u, 3) %Decode wi t h 3 bi t s.
ysat =
- 0. 2500 0. 2500 0. 5000 - 1. 0000
Noticethelast entry in u saturates to1, thedefault peak input magnitude.
Changethepeak input magnitude.
ysat v = udecode( u, 3, 6) %Set t he peak i nput magni t ude t o 6.
ysat v =
- 1. 5000 1. 5000 3. 0000 - 6. 0000
Thelast input entry still saturates. Try wrappingtheoverflows.
ywr ap = udecode( u, 3, 6, ' wr ap' )
ywr ap =
- 1. 5000 1. 5000 3. 0000 4. 5000
Try addingmorequantization levels.
ypr ec = udecode( u, 5)
ypr ec =
- 0. 0625 0. 0625 0. 1250 - 0. 3125
Algorithm Thealgorithmadherestothedefinitionfor uniformdecodingspecifiedinI TU-T
Recommendation G.701. I nteger input values areuniquely mapped (decoded)
fromoneof 2
n
uniformly spaced integer values toquantized floating-point
values in therange[ - v, v] . Thesmallest integer input valueallowed is
mapped to-v and thelargest integer input valueallowed is mapped to v.
udecode
7-436
Values outsideof theallowableinput rangeareeither saturated or wrapped,
accordingtospecification.
Thereal and imaginary components of complex inputs aredecoded
independently.
See Also uencode Quantizeand encodefloating-point data.
References General Aspects of Digital Transmission Systems: Vocabulary of Digital
Transmission and Multiplexing, and PulseCodeModulation (PCM) Terms,
I nternational Telecommunication Union, I TU-T Recommendation G.701,
March, 1993.
uencode
7-437
7uencode
Purpose Quantizeand encodefloating-point inputs tointeger outputs.
Syntax y = uencode( u, n)
y = uencode( u, n, v)
y = uencode( u, n, v, ' Si gnFl ag' )
Description y = uencode( u, n) quantizes theentries in a multidimensional array of
floating-point numbers u and encodes themas integers using2
n
-level
quantization. n must bean integer between 2and32(inclusive). I nputs can be
real or complex, double- or single-precision. Theoutput y and theinput u are
arrays of thesamesize. Theelements of theoutput y areunsigned integers
with magnitudes in therange[0, 2
n
-1]. Elements of theinput u outsideof the
range[ - 1, 1] aretreated as overflows and aresaturated.
For entries in theinput u that areless than -1, thevalueof theoutput of
uencode is 0.
For entries in theinput u that aregreater than 1, thevalueof theoutput of
uencode is 2
n
-1.
y = uencode( u, n, v) allows theinput u tohaveentries with floating-point
valuesin therange[ - v, v] beforesaturatingthem(thedefault valuefor v is 1).
Elements of theinput u outsideof therange[ - v, v] aretreated as overflows
and aresaturated.
For input entries less than -v, thevalueof theoutput of uencode is 0.
For input entries greater than v, thevalueof theoutput of uencode is 2
n
-1.
y = uencode( u, n, v, ' Si gnFl ag' ) mapsentriesinamultidimensional arrayof
floating-point numbers u whoseentries havevalues in therange[- v, v] toan
integer output y. I nput entries outsidethis rangearesaturated. Theinteger
typeof theoutput depends on thestring' Si gnFl ag' and thenumber of
quantization levels 2
n
. Thestring' Si gnFl ag' can beoneof thefollowing:
' si gned' : Outputs aresigned integers with magnitudes in therange
[-2
n
/2, (2
n
/2) - 1].
' unsi gned' (default): Outputsareunsignedintegerswithmagnitudesin the
range[0, 2
n
-1].
uencode
7-438
Theoutput data types areoptimized for thenumber of bits as shown in the
tablebelow.
Examples Map floating-point scalars in [-1, 1] toui nt 8 (unsigned) integers, and produce
astaircaseplot. Notethat thehorizontal axis plots from-1to1andthevertical
axis plots from0 to7 (2^3- 1).
u = [ - 1: 0. 01: 1] ;
y = uencode( u, 3) ;
pl ot ( u, y, ' . ' )
n Unsigned Integer Signed Integer
2 to8 ui nt 8 i nt 8
9 to16 ui nt 16 i nt 16
17 to32 ui nt 32 i nt 32
1 0.8 0.6 0.4 0.2 0 0.2 0.4 0.6 0.8 1
0
1
2
3
4
5
6
7
uencode
7-439
Nowlook at saturation effects when you under specify thepeak valuefor the
input.
u = [ - 2: 0. 5: 2] ;
y = uencode( u, 5, 1)
y =
0 0 0 8 16 24 31 31 31
Nowlook at theoutput for
u = [ - 2: 0. 5: 2] ;
y = uencode( u, 5, 2, ' si gned' )
y =
- 8 - 4 0 4 8 12 16 20 23
Algorithm uencode maps thefloating-point input valuetoan integer valuedeterminedby
therequirement for 2
n
levels of quantization. This encodingadheres tothe
definition for uniformencodingspecified in I TU-T Recommendation G.701.
Theinput range[ - v, v] is divided into2
n
evenly spaced intervals. I nput
entries in therange[ - v, v] arefirst quantized accordingtothis subdivision of
theinput range, andthenmappedtooneof 2
n
integers. Therangeof theoutput
depends on whether or not you specify that you want signed integers.
See Also udecode Decode2
n
-level quantized integers tofloating-point.
References General Aspects of Digital Transmission Systems: Vocabulary of Digital
Transmission and Multiplexing, and PulseCodeModulation (PCM) Terms,
I nternational Telecommunication Union, I TU-T Recommendation G.701,
March, 1993.
unwrap
7-440
7unwrap
Purpose Unwrap phaseangles.
Syntax p = unwr ap( p)
Description p = unwr ap( p) corrects thephaseangles in vector p by addingmultiples of
, whereneeded, tosmooth thetransitions across branch cuts. When p is a
matrix, unwr ap corrects thephaseangles down each column. Thephasemust
bein radians.
Theunwr ap function is part of thestandard MATLAB language.
Limitations unwr ap tries todetect branch cut crossings, but it can befooled by sparse,
rapidly changingphasevalues.
See Also
2
abs Absolutevalue(magnitude).
angl e Phaseangle.
upfirdn
7-441
7upfirdn
Purpose Upsample, apply an FI R filter, and downsample.
Syntax yout = upf i r dn( xi n, h)
yout = upf i r dn( xi n, h, p)
yout = upf i r dn( xi n, h, p, q)
[ yout , zf ] = upf i r dn( xi n, h, . . . , zi )
Description upf i r dn performs a cascadeof threeoperations:
1 Upsamplingtheinput data in thematrix xi n by a factor of theinteger p
(insertingzeros)
2 FI R filteringtheupsampledsignal datawiththeimpulseresponsesequence
given in thevector or matrix h
3 Downsamplingtheresult by a factor of theinteger q (throwingaway
samples)
upf i r dn has been implemented as a MEX-filefor maximumspeed, soonly the
outputs actually needed arecomputed. TheFI R filter is usually a lowpass
filter, which you must design usinganother function such as r emez or f i r 1.
Note Thefunction r esampl e performs an FI R design usingf i r l s, followed
by ratechangingimplemented with upf i r dn.
yout = upf i r dn( xi n, h) filters theinput signal xi n with theFI R filter having
impulseresponseh. I f xi n is arowor column vector, then it represents asingle
signal. I f xi n is a matrix, then each column is filtered independently. I f h is a
rowor column vector, then it represents oneFI R filter. I f h is a matrix, then
each column is a separateFI R impulseresponsesequence. I f yout is a rowor
column vector, then it represents onesignal. I f yout is a matrix, then each
column is a separateoutput. Noupsamplingor downsamplingis implemented
with this syntax.
yout = upf i r dn( xi n, h, p) specifies theinteger upsamplingfactor p, wherep
has a default valueof 1.
upfirdn
7-442
yout = upf i r dn( xi n, h, p, q) specifies theinteger downsamplingfactor q,
whereq has a default valueof 1.
[ yout , zf ] = upf i r dn( xi n, h, . . . , zi ) specifies initial stateconditions in the
vector zi .
Thesizeof theinitial conditionvector zi must bethesameas l engt h( h) - 1, the
number of delays in theFI R filter.
When xi n is a vector, thesizeof thefinal condition vector zf is l engt h( h) - 1,
thenumber of delays in thefilter. When xi n is a matrix, zf is an matrix with
( l engt h( h) - 1) rows and ( si ze( xi n, 2) ) columns.
Note Sinceupf i r dn performs convolution and ratechanging, theyout
signals havea different length than xi n. Thenumber of rows of yout is
approximately p/ q times thenumber of rows of xi n.
Remarks Usually theinputs xi n and thefilter h arevectors, in which caseonly one
output signal is produced. However, when thesearguments arearrays, each
column is treated as a separatesignal or filter. Valid combinations are:
1 xi n is a vector and h is a vector.
Thereis onefilter and onesignal, sothefunction convolves xi n with h. The
output signal yout isarowvector if xi nisarow; otherwise, yout is acolumn
vector.
2 xi n is a matrix and h is a vector.
Thereis onefilter and many signals, sothefunction convolves h with each
column of xi n. Theresultingyout will bean matrix with thesamenumber
of columns as xi n.
3 xi n is a vector and h is a matrix.
Therearemanyfiltersandonesignal, sothefunctionconvolveseachcolumn
of h with xi n. Theresultingyout will bean matrix with thesamenumber of
columns as h.
upfirdn
7-443
4 xi n is a matrix and h is a matrix, both with thesamenumber of columns.
Therearemany filters and many signals, sothefunction convolves
correspondingcolumns of xi n and h. Theresultingyout is an matrix with
thesamenumber of columns as xi n and h.
Examples I f both p and q areequal to1 (that is, thereis noratechanging), theresult is
ordinary convolution of twosignals (equivalent toconv).
yy = upf i r dn( xx, hh) ;
This exampleimplements a seven-channel filter bank by convolvingseven
different filters with oneinput signal, then downsamples by five.
%Assume t hat hh i s an L- by- 7 ar r ay of f i l t er s.
yy = upf i r dn( xx, hh, 1, 5) ;
I mplement a ratechangefrom44.1 kHz (CD samplingrate) to48 kHz (DAT
rate), a ratioof 160/147. This requires a lowpass filter with cutoff frequency at

c
=2/160.
%Desi gn l owpass f i l t er wi t h cut of f at 1/ 160t h of f s.
hh = f i r 1( 300, 2/ 160) ; %Need a ver y l ong l owpass f i l t er
yy = upf i r dn( xx, hh, 160, 147) ;
I n this example, thefilter design andresamplingareseparatesteps. Notethat
r esampl e would doboth steps as one.
Algorithm upf i r dn uses apolyphaseinterpolation structure. Thenumber of multiply-add
operations in thepolyphasestructureis approximately (L
h
L
x
-pL
x
)/q whereL
h
and L
x
arethelengths of h[n] and x[n], respectively.
A moreaccurateflops count is computed in theprogram, but theactual count
is still approximate. For longsignals x[n], theformula is quiteoften exact.
upfirdn
7-444
See Also
References [1] Crochiere, R.E., and L.R. Rabiner, Multi-RateSignal Processing,
Prentice-Hall, Englewood Cliffs, NJ , 1983, pp. 88-91.
[2] Crochiere, R.E., A General ProgramtoPerformSamplingRateConversion
of Data by Rational Ratios,Programs for Digital Signal Processing, I EEE
Press, NewYork, 1979, pp. 8.2-1 to8.2-7.
conv Convolution and polynomial multiplication.
deci mat e Decreasethesamplingratefor a sequence
(decimation).
f i l t er Filter data with a recursive(I I R) or nonrecursive
(FI R) filter.
i nt er p I ncreasesamplingrateby an integer factor
(interpolation).
i nt f i l t I nterpolation FI R filter design.
r esampl e Changesamplingrateby any rational factor.
vco
7-445
7vco
Purpose Voltagecontrolled oscillator.
Syntax y = vco( x, f c, f s)
y = vco( x, [ Fmi n Fmax] , f s)
Description y = vco( x, f c, f s) creates a signal that oscillates at a frequency determined
bythereal input vector or arrayx with samplingfrequencyf s. f c is thecarrier
or referencefrequency; when x is 0, y is an f c Hz cosinewith amplitude1
sampled at f s Hz. x ranges from- 1 to1, wherex =- 1 corresponds to
0 frequency output, x =0 corresponds tof c, and x =1 corresponds to2*f c.
Output y is thesamesizeas x.
y = vco( x, [ Fmi n Fmax] , f s) scales thefrequency modulation rangesothat
1 values of x yield oscillations of Fmi n Hz and Fmax Hz respectively. For best
results, Fmi n and Fmax should bein therange0 tof s/ 2.
By default, f s is 1 and f c is f s/ 4.
I f x is amatrix, vco produces amatrixwhosecolumns oscillateaccordingtothe
columns of x.
Example Generatetwoseconds of a signal sampled at 10,000 samples/second whose
instantaneous frequency is a trianglefunction of time.
f s = 10000;
t = 0: 1/ f s: 2;
x = vco( sawt oot h( 2*pi *t , 0. 75) , [ 0. 1 0. 4] *f s, f s) ;
Plot thespectrogramof thegenerated signal.
specgr am( x, 512, f s, kai ser ( 256, 5) , 220)
vco
7-446
Algorithm vco performs FM modulation usingthemodul at e function.
Diagnostics I f any values of x lieoutside[-1, 1], vco gives thefollowingerror message.
X out si de of r ange [ - 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 Demodulation for communications simulation.
modul at e Modulation for communications simulation.
xcorr
7-447
7xcorr
Purpose Estimatethecross-correlation function.
Syntax c = xcor r ( x, y)
c = xcor r ( x)
c = xcor r ( x, y, ' opt i on' )
c = xcor r ( x, ' opt i on' )
c = xcor r ( x, y, maxl ags)
c = xcor r ( x, maxl ags)
c = xcor r ( x, y, maxl ags, ' opt i on' )
c = xcor r ( x, maxl ags, ' opt i on' )
[ c, l ags] = xcor r ( . . . )
Description xcor r estimates thecross-correlation sequenceof a randomprocess.
Autocorrelation is handled as a special case.
Thetruecross-correlation sequenceis
wherex
n
and y
n
arejointly stationary randomprocesses, , and E {}
is theexpected valueoperator. xcor r must estimatethesequencebecause, in
practice, only a finitesegment of onerealization of theinfinite-length random
process is available.
c = xcor r ( x, y) returns thecross-correlation sequencein a length 2*N-1
vector, wherex and y arelength N vectors (N>1). I f x and y arenot thesame
length, theshorter vector is zero-padded tothelength of thelonger vector.
By default, xcor r computes rawcorrelations with nonormalization.
Theoutput vector c has elements given by c(m) = c
xy
(m-N), m=1, ..., 2N-1.
I n general, thecorrelation function requires normalization toproducean
accurateestimate(seebelow).
R
xy
m ( ) E{x
n m +
y
*
n
} E{x
n
y
*
n m
} = =
n < <
R

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

m 0
R

yx
*
m ( ) m 0 <






=
xcorr
7-448
c = xcor r ( x) is theautocorrelation sequencefor thevector x. I f x isanN-by-P
matrix, c is a matrix with 2N-1 rows whoseP
2
columns contain the
cross-correlation sequences for all combinations of thecolumns of x.
c = xcor r ( x, y, ' opt i on' ) specifies a normalization option for the
cross-correlation, where' opt i on' is:
' bi ased' : Biased estimateof thecross-correlation function
' unbi ased' : Unbiased estimateof thecross-correlation function
' coef f ' : Normalizes thesequencesotheautocorrelations at zerolagare
identically 1.0
' none' , tousetheraw, unscaled cross-correlations (default)
Seereference[1] for moreinformation on thepropertiesof biasedandunbiased
correlation estimates.
c = xcor r ( x, ' opt i on' ) specifies oneof theabovenormalization options for
theautocorrelation.
c = xcor r ( x, y, maxl ags) returns thecross-correlation sequenceover thelag
range[ - maxl ags: maxl ags] . Output c has length 2*maxl ags+1.
c = xcor r ( x, maxl ags) returns theautocorrelation sequenceover thelag
range[ - maxl ags: maxl ags] . Output c has length 2*maxl ags+1. I f x is an
N-by-P matrix, c is amatrix with 2*maxl ags+1 rows whoseP
2
columns contain
theautocorrelation sequences for all combinations of thecolumns of x.
c = xcor r ( x, y, maxl ags, ' opt i on' ) specifiesbothamaximumnumber of lags
and a scalingoption for thecross-correlation.
c = xcor r ( x, maxl ags, ' opt i on' ) specifies both a maximumnumber of lags
and a scalingoption for theautocorrelation.
c
xy biased ,
m ( )
1
N
----c
xy
m ( ) =
c
xy unbiased ,
m ( )
1
N m
-------------------c
xy
m ( ) =
xcorr
7-449
[ c, l ags] = xcor r ( . . . ) returns a vector of thelagindices at which c was
estimated, with therange[ - maxl ags: maxl ags] . When maxl ags is not
specified, therangeof l ags is [ - N+1: N- 1] .
I nall cases, thecross-correlation or autocorrelationcomputedbyxcor r hasthe
zeroth lagin themiddleof thesequence, at element or rowmaxl ags+1 (element
or rowNif maxl ags is not specified).
Examples Thesecond output, l ags, is useful for plottingthecross-correlation or
autocorrelation. For example, theestimated autocorrelation of zero-mean
Gaussian whitenoisec
ww
(m) can bedisplayed for -10 m 10 using
ww = r andn( 1000, 1) ;
[ c_ww, l ags] = xcor r ( ww, 10, ' coef f ' ) ;
st em( l ags, c_ww)
Swappingthex and y input arguments reverses (and conjugates) theoutput
correlation sequence. For rowvectors, theresultingsequences arereversedleft
toright; for column vectors, up and down. Thefollowingexampleillustrates
this property (mat 2st r is used for a compact display of complex numbers).
x = [ 1, 2i , 3] ; y = [ 4, 5, 6] ;
[ c1, l ags] = xcor r ( x, y) ;
c1 = mat 2st r ( c1, 2) , l ags
c1 =
[ 6- i *8. 9e- 016 5+i *12 22+i *10 15+i *8 12+i *8. 9e- 016]
l ags =
- 2 - 1 0 1 2
c2 = conj ( f l i pl r ( xcor r ( y, x) ) ) ;
c2 = mat 2st r ( c2, 2)
c2 =
[ 6- i *8. 9e- 016 5+i *12 22+i *10 15+i *8 12+i *8. 9e- 016]
For thecasewhereinput argument x is a matrix, theoutput columns are
arranged sothat extractinga rowand rearrangingit intoa squarearray
produces thecross-correlation matrix correspondingtothelagof thechosen
row. For example, thecross-correlation at zerolagcan beretrieved by
r andn( ' st at e' , 0)
X = r andn( 2, 2) ;
[ M, P] = si ze( X) ;
c = xcor r ( X) ;
xcorr
7-450
c0 = zer os( P) ; c0( : ) = c( M, : ) %Ext r act zer o- l ag r ow
c0 =
2. 9613 - 0. 5334
- 0. 5334 0. 0985
You can calculatethematrix of correlation coefficients that theMATLAB
function cor r coef generates by substituting
c = xcov( X, ' coef ' )
in thelast example. Thefunction xcov subtracts themean and then calls
xcor r .
Usef f t shi f t tomovethesecondhalf of thesequencestartingat thezerothlag
tothefront of thesequence. f f t shi f t swaps thefirst and second halves of a
sequence.
Algorithm For moreinformation on estimatingcovarianceand correlation functions, see
[1].
See Also
References [1] Orfanidis, S.J ., OptimumSignal Processing. An I ntroduction. 2nd Edition,
Prentice-Hall, Englewood Cliffs, NJ , 1996.
conv Convolution and polynomial multiplication.
cor r coef Computea correlation coefficient matrix.
cov Computea covariancematrix.
xcor r 2 Estimatethetwo-dimensional cross-correlation.
xcov Estimatethecross-covariance.
xcorr2
7-451
7xcorr2
Purpose Estimatethetwo-dimensional cross-correlation.
Syntax C = xcor r 2( A)
C = xcor r 2( A, B)
Description C = xcor r 2( A, B) returns thecross-correlation of matrices A and B with no
scaling. xcor r 2 is thetwo-dimensional version of xcor r . I t has its maximum
valuewhen thetwomatrices arealigned sothat they areshaped as similarly
as possible.
xcor r 2( A) is theautocorrelation matrix of input matrix A. I t is identical to
xcor r 2( A, A) .
See Also
conv2 Computethetwo-dimensional convolution.
f i l t er 2 Filter two-dimensional data.
xcor r Estimatethecross-correlation function.
xcov
7-452
7xcov
Purpose Estimatethecross-covariancefunction (mean-removed cross-correlation).
Syntax v = xcov( x, y)
v = xcov( x)
v = xcov( x, ' opt i on' )
[ c, l ags] = xcov( x, y, maxl ags)
[ c, l ags] = xcov( x, maxl ags)
[ c, l ags] = xcov( x, y, maxl ags, ' opt i on' )
Description xcov estimates thecross-covariancesequenceof randomprocesses.
Autocovarianceis handled as a special case.
Thetruecross-covariancesequenceis thecross-correlation of mean-removed
sequences
where and arethemean values of thetwostationary randomprocesses,
and E{}is theexpected valueoperator. xcov estimates thesequencebecause,
in practice, access is availabletoonly a finitesegment of theinfinite-length
randomprocess.
v = xcov( x, y) returns thecross-covariancesequencein alength 2N-1vector,
wherex and y arelength N vectors.
v = xcov( x) is theautocovariancesequencefor thevector x. Wherex is an
N-by-P array, v = xcov( x) returnsanarraywith 2N-1rowswhoseP
2
columns
contain thecross-covariancesequences for all combinationsof thecolumns of x.
By default, xcov computes rawcovariances with nonormalization. For a
length N vector
Theoutput vector c has elements given by c( m) =c
xy
(m-N), m=1, ..., 2N-1.

xy
( ) E x
n m +

x
( ) y
n

y
( )
*
{ } =

x

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

'



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

'



n 0 =
N m 1

m 0
c
yx
*
m ( ) m 0 <







=
xcov
7-453
Thecovariancefunction requires normalization toestimatethefunction
properly.
v = xcov( x, ' opt i on' ) specifies a scalingoption, where' opt i on' is:
' bi ased' , for biased estimates of thecross-covariancefunction
' unbi ased' , for unbiased estimates of thecross-covariancefunction
' coef f ' , tonormalizethesequencesotheauto-covariances at zerolagare
identically 1.0
' none' , tousetheraw, unscaled cross-covariances (default)
See[1] for moreinformation on theproperties of biased and unbiased
correlation and covarianceestimates.
[ c, l ags] = xcov( x, y, maxl ags) wherex and y arelength mvectors, returns
thecross-covariancesequencein a length 2*maxl ags+1 vector c. l ags is a
vector of thelagindices wherec was estimated, that is, [ - maxl ags: maxl ags] .
[ c, l ags] = xcov( x, maxl ags) is theautocovariancesequenceover therange
of lags [ - maxl ags: maxl ags] .
[ c, l ags] = xcov( x, maxl ags) wherex isanm-by-p array, returnsarrayc with
2*maxl ags+1 rows whoseP
2
columns contain thecross-covariancesequences
for all combinations of thecolumns of x.
[ c, l ags] = xcov( x, y, maxl ags, ' opt i on' ) specifies a scalingoption, where
' opt i on' is thelast input argument.
I n all cases, xcov gives an output such that thezeroth lagof thecovariance
vector is in themiddleof thesequence, at element or row maxl ag+1 or at m.
Examples Thesecond output l ags is useful when plotting. For example, theestimated
autocovarianceof uniformwhitenoisec
ww
(m) can bedisplayedfor -10 m 10
using
ww = r andn( 1000, 1) ; %Gener at e uni f or mnoi se wi t h mean = 1/ 2.
[ cov_ww, l ags] = xcov( ww, 10, ' coef f ' ) ;
st em( l ags, cov_ww)
xcov
7-454
Algorithm xcov computes themean of its inputs, subtracts themean, and then calls
xcor r . For moreinformation on estimatingcovarianceand correlation
functions, see[1].
Diagnostics xcov does not check for any errors other than thecorrect number of input
arguments. I nstead, it relies on theerror checkingin xcor r .
See Also
References [1] Orfanidis, S.J ., OptimumSignal Processing. An I ntroduction. 2nd Edition,
Prentice-Hall, Englewood Cliffs, NJ , 1996.
conv I mplement convolution and polynomial
multiplication.
cor r coef Computethecorrelation coefficient matrix.
cov Computethecovariancematrix.
xcor r Estimatethecross-correlation function.
xcor r 2 Estimatethetwo-dimensional cross-correlation.
yulewalk
7-455
7yulewalk
Purpose Recursivedigital filter design.
Syntax [ b, a] = yul ewal k( n, f , m)
Description yul ewal k designs recursiveI I R digital filters usinga least-squares fit toa
specified frequency response.
[ b, a] = yul ewal k( n, f , m) returns rowvectors b and a containingthen+1
coefficients of theorder n I I R filter whosefrequency-magnitudecharacteristics
approximately match thosegiven in vectors f and m:
f is a vector of frequency points, specified in therangebetween 0 and 1,
where1 corresponds tohalf thesamplefrequency (theNyquist frequency).
Thefirst point of f must be0 and thelast point 1, with all intermediate
points in increasingorder. Duplicatefrequency points areallowed,
correspondingtosteps in thefrequency response.
mis a vector containingthedesired magnituderesponseat thepoints
specified in f .
f and mmust bethesamelength.
pl ot ( f , m) displays thefilter shape.
Theoutput filter coefficients areordered in descendingpowers of z.
When specifyingthefrequency response, avoid excessively sharp transitions
frompassband tostopband. You may need toexperiment with theslopeof the
transition region toget thebest filter design.
Example Design an 8th-order lowpass filter andoverplot thedesiredfrequencyresponse
with theactual frequency response.
f = [ 0 0. 6 0. 6 1] ;
m= [ 1 1 0 0] ;
[ b, a] = yul ewal k( 8, f , m) ;
[ h, w] = f r eqz( b, a, 128) ;
pl ot ( f , m, w/ pi , abs( h) , ' - - ' )
l egend( ' I deal ' , ' yul ewal k Desi gned' )
t i t l e( ' Compar i son of Fr equency Response Magni t udes' )
B z ( )
A z ( )
-----------
b 1 ( ) b 2 ( )z
1
L b n 1 + ( )z
n
+ + +
a 1 ( ) a 2 ( )z
1
L a n 1 + ( )z
n
+ + +
------------------------------------------------------------------------------------- =
yulewalk
7-456
Algorithm yul ewal k performs a least-squares fit in thetimedomain. I t computes the
denominator coefficients usingmodified Yule-Walker equations, with
correlation coefficients computed by inverseFourier transformation of the
specified frequency response. Tocomputethenumerator, yul ewal k takes the
followingsteps:
1 Computes a numerator polynomial correspondingtoan additive
decomposition of thepower frequency response.
2 Evaluates thecompletefrequency responsecorrespondingtothenumerator
and denominator polynomials.
3 Usesaspectral factorization techniquetoobtaintheimpulseresponseof the
filter.
4 Obtains thenumerator polynomial by a least-squares fit tothis impulse
response.
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
0
0.2
0.4
0.6
0.8
1
1.2
1.4
Comparison of Frequency Response Magnitudes
Ideal
yulewalk Designed
yulewalk
7-457
See Also
References [1] Friedlander, B., andB. Porat, TheModifiedYule-Walker Methodof ARMA
Spectral Estimation,I EEE Transactions on AerospaceElectronic Systems,
AES-20, No. 2 (March 1984), pp. 158-173.
but t er Butterworth analogand digital filter design.
cheby1 Chebyshev typeI filter design (passband ripple).
cheby2 Chebyshev typeI I filter design (stopband ripple).
el l i p Elliptic (Cauer) filter design.
f i r 2 Window-based finiteimpulseresponsefilter design
arbitrary response.
f i r l s Least squarelinear-phaseFI R filter design.
maxf l at Generalized digital Butterworth filter design.
r emez Parks-McClellan optimal FI R filter design.
zp2sos
7-458
7zp2sos
Purpose Convert digital filter zero-pole-gain parameters tosecond-order sections form.
Syntax [ sos, g] = zp2sos( z, p, k)
[ sos, g] = zp2sos( z, p, k, ' or der ' )
[ sos, g] = zp2sos( z, p, k, ' or der ' , ' scal e' )
sos = zp2sos( . . . )
Description zp2sos convertsadiscrete-timezero-pole-gain representationof agivendigital
filter toan equivalent second-order section representation.
Use[ sos, g] = zp2sos( z, p, k) toobtain a matrix sos in second-order section
formwith gain g equivalent tothediscrete-timezero-pole-gain filter
represented by input arguments z, p, and k. Vectors z and p contain thezeros
andpoles of thefilters transfer function H(z), not necessarilyin any particular
order.
wheren and marethelengths of z and p, respectively, and k is a scalar gain.
Thezeros and poles must bereal or complex conjugatepairs. sos is an L-by-6
matrix
whoserows contain thenumerator and denominator coefficients b
ik
and a
ik
of
thesecond-order sections of H(z).
Thenumber L of rows of thematrix sos is theclosest integer greater than or
equal tothemaximumof n/2 and m/2.
H z ( ) k
z z
1
( ) z z
2
( )L z z
n
( )
z p
1
( ) z p
2
( )L z p
m
( )
-------------------------------------------------------------------- =
sos
b
01
b
11
b
21
1 a
11
a
21
b
02
b
12
b
22
1 a
12
a
22

b
0L
b
1L
b
2L
1 a
1L
a
2L
=
H z ( ) g H
k
z ( )
k 1 =
L

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

= =
zp2sos
7-459
[ sos, g] = zp2sos( z, p, k, ' or der ' ) specifies theorder of therows in sos,
where' or der ' is:
' down' , toorder thesections sothefirst rowof sos contains thepoles closest
totheunit circle
' up' , toorder thesections sothefirst rowof sos contains thepoles farthest
fromtheunit circle(default)
[ sos, g] = zp2sos( z, p, k, ' or der ' , ' scal e' ) specifies thedesired scalingof
thegain and thenumerator coefficients of all second-order sections, where
' scal e' is:
' none' , toapply noscaling(default)
' i nf ' , toapply infinity-normscaling
' t wo' , toapply 2-normscaling
Usinginfinity-normscalingin conjunction with up-orderingminimizes the
probability of overflowin therealization. Using2-normscalingin conjunction
with down-orderingminimizes thepeak round-off noise.
sos = zp2sos( . . . ) embeds theoverall systemgain, g, in thefirst section,
H
1
(z), sothat
Example Find a second-order section formof a Butterworth lowpass filter.
[ z, p, k] = but t er ( 5, 0. 2) ;
sos = zp2sos( z, p, k) ;
H z ( ) H
k
z ( )
k 1 =
L

=
zp2sos
7-460
Algorithm zp2sos uses a four-step algorithmtodeterminethesecond-order section
representation for an input zero-pole-gain system:
1 I t groups thezeros and poles intocomplex conjugatepairs usingthe
cpl xpai r function.
2 I t forms thesecond-order section by matchingthepoleand zeropairs
accordingtothefollowingrules:
a Match thepoles closest totheunit circlewith thezeros closest tothose
poles.
b Match thepoles next closest totheunit circlewith thezeros closest to
thosepoles.
c Continueuntil all of thepoles and zeros arematched.
zp2sos groups real poles intosections with thereal poles closest tothemin
absolutevalue. Thesameruleholds for real zeros.
3 I t orders thesections accordingtotheproximity of thepolepairs totheunit
circle. zp2sos normally orders thesections with poles closest totheunit
circlelast in thecascade. You can tell zp2sos toorder thesections in the
reverseorder by specifyingthedown flag.
4 zp2sos scales thesections by thenormspecified in the' scal e' argument.
For arbitrary H(), thescalingis defined by
wherep can beeither or 2. Seethereferences for details on thescaling.
This scalingis an attempt tominimizeoverflowor peak round-off noisein
fixed point filter implementations.
H
p
1
2
------ H ( )
p
d
0
2

1
p
---
=
zp2sos
7-461
See Also
References [1] J ackson, L.B., Digital Filters and Signal Processing, 3rd ed., Kluwer
Academic Publishers, Boston, 1996, Chapter 11.
[2] Mitra, S.K., Digital Signal Processing: A Computer-Based Approach,
McGraw-Hill, NewYork, 1998, Chapter 9.
[3] Vaidyanathan, P.P., Robust Digital Filter Structures, Handbook for
Digital Signal Processing, S.K. Mitra and J .F. Kaiser, ed., J ohn Wiley & Sons,
NewYork, 1993, Chapter 7.
cpl xpai r Group complex numbers intocomplex conjugate
pairs.
sos2zp Convert digital filter second-order section
parameters tozero-pole-gain form.
ss2sos Convert digital filter state-spaceparameters to
second-order sections form.
t f 2sos Convert digital filter transfer function parameters to
second-order sections form.
zp2ss Convert zero-pole-gain filter parameters to
state-spaceform.
zp2t f Convert zero-pole-gain filter parameters totransfer
function form.
zp2ss
7-462
7zp2ss
Purpose Convert zero-pole-gain filter parameters tostate-spaceform.
Syntax [ A, B, C, D] = zp2ss( z, p, k)
Description zp2ss converts a zero-pole-gain representation of a given systemtoan
equivalent state-spacerepresentation.
[ A, B, C, D] = zp2ss( z, p, k) finds a singleinput, multipleoutput, state-space
representation
given a systemin factored transfer function form.
Column vector p specifies thepolelocations, and matrix z thezerolocations
with as many columns as thereareoutputs. Thegains for each numerator
transfer function arein vector k. TheA, B, C, and Dmatrices arereturned in
controller canonical form.
I nf values may beusedas placeholders in z if somecolumns havefewer zeros
than others.
Algorithm zp2ss, for single-input systems, groups complexpairs together intotwo-by-two
blocks down thediagonal of theA matrix. This requires thezeros and poles to
bereal or complex conjugatepairs.
x

Ax Bu + =
y Cx Du + =
H s ( )
Z s ( )
P s ( )
---------- k
s z
1
( ) s z
2
( )L s z
n
( )
s p
1
( ) s p
2
( )L s p
n
( )
------------------------------------------------------------------ = =
zp2ss
7-463
See Also
sos2ss Convert digital filter second-order section
parameters tostate-spaceform.
ss2zp Convert state-spacefilter parameters to
zero-pole-gain form.
t f 2ss Convert transfer function filter parameters to
state-spaceform.
zp2sos Convert digital filter zero-pole-gain parameters to
second-order sections form.
zp2t f Convert zero-pole-gain filter parameters totransfer
function form.
zp2tf
7-464
7zp2tf
Purpose Convert zero-pole-gain filter parameters totransfer function form.
Syntax [ b, a] = zp2t f ( z, p, k)
Description zp2t f forms transfer function polynomials fromthezeros, poles, andgains of a
systemin factored form.
[ b, a] = zp2t f ( z, p, k) finds a rational transfer function
given a systemin factored transfer function form
Column vector p specifies thepolelocations, and matrix z specifies thezero
locations, with as many columns as thereareoutputs. Thegains for each
numerator transfer function arein vector k. Thezeros and poles must bereal
or comein complex conjugatepairs. Thepolynomial denominator coefficients
arereturned in rowvector a and thepolynomial numerator coefficients are
returned in matrix b, which has as many rows as therearecolumns of z.
I nf values can beused as placeholders in z if somecolumns havefewer zeros
than others.
Algorithm Thesystemis converted totransfer function formusingpol y with p and the
columns of z.
B s ( )
A s ( )
---------- -
b
1
s
nb 1 ( )
L b
nb 1 ( )
s b
nb
+ + +
a
1
s
na 1 ( )
L a
na 1 ( )
s a
na
+ + +
------------------------------------------------------------------------------------- - =
H s ( )
Z s ( )
P s ( )
---------- k
s z
1
( ) s z
2
( )L s z
m
( )
s p
1
( ) s p
2
( )L s p
n
( )
------------------------------------------------------------------ = =
zp2tf
7-465
See Also
sos2t f Convert digital filter second-order section
parameters totransfer function form.
ss2t f Convert state-spacefilter parameters totransfer
function form.
t f 2zp Convert transfer function filter parameters to
zero-pole-gain form.
zp2sos Convert digital filter zero-pole-gain parameters to
second-order sections form.
zp2ss Convert zero-pole-gain filter parameters to
state-spaceform.
zplane
7-466
7zplane
Purpose Zero-poleplot.
Syntax zpl ane( z, p)
zpl ane( b, a)
[ hz, hp, ht ] = zpl ane( z, p)
Description This function displays thepoles and zeros of discrete-timesystems.
zpl ane( z, p) plotsthezerosspecifiedincolumnvector z andthepolesspecified
in column vector p in thecurrent figurewindow. Thesymbol ' o' represents a
zeroand thesymbol ' x' represents a pole. Theplot includes theunit circlefor
reference. I f z andp arearrays, zpl ane plots thepolesandzerosin thecolumns
of z and p in different colors.
You can overridetheautomatic scalingof zpl ane using
axi s( [ xmi n xmax ymi n ymax] )
or
set ( gca, ' yl i m' , [ ymi n ymax] )
or
set ( gca, ' xl i m' , [ xmi n xmax] )
after callingzpl ane. This is useful in thecasewhereoneor a fewof thezeros
or poles havesuch a largemagnitudethat theothers aregrouped tightly
around theorigin and arehard todistinguish.
zpl ane( b, a) whereb and a arerowvectors, first uses r oot s tofind thezeros
and poles of thetransfer function represented by numerator coefficients b and
denominator coefficients a.
[ hz, hp, ht ] = zpl ane( z, p) returns vectors of handles tothezerolines, hz,
and thepolelines, hp. ht is a vector of handles totheaxes/unit circlelineand
totext objects, which arepresent when therearemultiplezeros or poles. I f
therearenozeros or nopoles, hz or hp is theempty matrix [ ] .
zplane
7-467
Examples Plot thepoles and zeros of a 5th-order Butterworth lowpass digital filter with
cutoff frequency of 0.2.
[ z, p, k] = but t er ( 5, 0. 2) ;
zpl ane( z, p) ;
t i t l e( ' 5t h- Or der But t er wor t h Lowpass Di gi t al Fi l t er ' ) ;
Togeneratethesameplot with a transfer function representation of thefilter,
usethefollowingcommands.
[ b, a] = but t er ( 5, 0. 2) ; %Tr ansf er f unct i on
zpl ane( 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
f r eqz Frequency responseof digital filters.
zplane
7-468
8
Filter DesignandAnalysis
Tool Reference
8 Filter Design and Analysis Tool Reference
8-2
Filter Design and Analysis GUI Overview
Chooseananalysis methodfor
analyzingyour filter design.
Choosethetypeof filter
youwant to design.
Choosethefilter design
methodyouwant to use
PressDesignFilter to
computeyour filter
coefficients.
Select theWhats this? buttonandclick ona region
of theGUI toaccess context-sensitivehelp.
Set quantization
parameters for theFilter
DesignToolbox.
Set filter specifications. Thesedependon
thetypeof filter youaredesigning, as
well asthedesignmethodyouspecify.
Specify a filter order or
allowit to beestimated.
Zoomin/out.
UsetheFilter menuto
choosebetweenimporting
filter coefficients fromthe
MATLABworkspaceand
designingthefilter inthe
GUI.
Set windowspecifications
for theFIRWindow
design.
Check thisbox to quantize
thecurrent filter usingthe
Filter DesignToolbox.
Display Region
8-3
Display Region
Thefollowingaredisplayed in this region:
Thefilter specifications. Theseareinitially displayed when you open the
GUI .
Themagnituderesponseplot
Thephaseresponseplot
Thefrequency responseplots (both magnitudeand phase)
Thegroup delay responseplot
Theimpulseresponseplot
Thestep responseplot
Thepole-zeroplot
Thefilter coefficients
Theplot that is displayed depends on which of thefollowingbuttons youve
selected on thetoolbar.
8 Filter Design and Analysis Tool Reference
8-4
Display Region: Filter Specifications
TheFilter Specifications plot is displayed when theFilter Specifications
option is selected in theAnalysis menu, or when thecorrespondingtoolbar
button is selected.
Theplot displays a schematicof thefilter parameters (such as F
pass
andF
stop
)
that can bespecified in theDesign Filter region. Theaxes usetheunits
currently selected in theUnits menus of theFrequency Specifications and
MagnitudeSpecifications regions.
Theplot does not reflect theactual values of thefilter specifications.
Filter Specifications button
Display Region: Magnitude Response
8-5
Display Region: Magnitude Response
TheMagnitudeResponseplot is displayed when theMagnitudeResponse
option is selected in theAnalysis menu, or when thecorrespondingtoolbar
button is selected.
Theplot shows theactual magnituderesponseof thecurrent filter. Seef r eqz
and f r eqzpl ot for moreinformation.
Magnitude Responsebutton
8 Filter Design and Analysis Tool Reference
8-6
Display Region: Phase Response
ThePhaseResponseplot is displayed when thePhaseResponseoption is
selected in theAnalysis menu, or when thecorrespondingtoolbar button is
selected.
Theplot shows theactual phaseresponseof thecurrent filter. Seef r eqz and
f r eqzpl ot for moreinformation.
Phase Response button
Display Region: Magnitude and Phase Response
8-7
Display Region: Magnitude and Phase Response
TheMagnitudeand PhaseResponseplot is displayed when theMagnitude
andPhaseoption is selectedin theAnalysismenu, or when thecorresponding
toolbar button is selected.
Theplot superposes themagnituderesponseand thephaseresponseof the
current filter. Seef r eqz and f r eqzpl ot for moreinformation.
Magnitude andPhase Responsebutton
8 Filter Design and Analysis Tool Reference
8-8
Display Region: Group Delay
TheGroup Delay plot is displayedwhen theGroupDelay option is selectedin
theAnalysis menu, or when thecorrespondingtoolbar button is selected.
Theplot shows thegroup delay of thecurrent filter. Seegr pdel ay for more
information.
GroupDelay button
Display Region: Impulse Response
8-9
Display Region: Impulse Response
TheI mpulseResponseplot is displayedwhen theImpulseResponseoption is
selected in theAnalysis menu, or when thecorrespondingtoolbar button is
selected.
Theplot shows theimpulseresponseof thecurrent filter. Seei mpz for more
information.
Impulse Response button
8 Filter Design and Analysis Tool Reference
8-10
Display Region: Step Response
TheStepResponseplot isdisplayedwhentheStepResponseoptionisselected
in theAnalysis menu, or when thecorrespondingtoolbar button is selected.
Theplot shows thestep responseof thecurrent filter.
StepResponsebutton
Display Region: Pole/ Zero Plot
8-11
Display Region: Pole/ Zero Plot
ThePole/Zeroplot is displayed when thePole/Zero Plot option is selected in
theAnalysis menu, or when thecorrespondingtoolbar button is selected.
Theplot shows thepoleand zerolocations of thecurrent filter on thez-plane.
Seezpl ane for moreinformation.
Pole/ Zero Plot button
8 Filter Design and Analysis Tool Reference
8-12
Display Region: Filter Coefficients
TheFilter Coefficients viewer is displayed when ViewFilter Coefficients is
selected in theAnalysis menu, or when thecorrespondingtoolbar button is
selected.
Thetext box lists thecoefficients of thecurrent filter, which depend on the
filter structure(e.g., direct form, lattice, etc.). UsetheConvert structure
button totransforma filter fromonestructuretoanother, or usetheI mport
Filter Coefficients region todirectly import a filter with thedesired structure.
Filter Coefficients button
Filter Type Region
8-13
Filter Type Region
Choosea filter typefromthefivemutually exclusiveradiobuttons:
Lowpass
Highpass
Bandpass
Bandstop
A menu listingother filter types:
- Differentiator (r emez, f i r l s)
- Hilbert Transformer (r emez, f i r l s)
- Multiband (f i r l s, r emez)
- Arbitrary Magnitude(f i r l s, r emez, f i r l s)
- Arbitrary Group Delay (i i r gr pdel ay) availableonly when theFilter
Design Toolbox is installed
Thefilter typeyou chooseis reflected in theDisplay region, Frequency
Specifications region, and MagnitudeSpecifications region.
Lowpass Filters
When you select this option, alowpass filter is displayedin theDisplay region,
and theFrequency Specifications and MagnitudeSpecifications regions are
updated with theappropriateparameters.
Seebut t er , cheby1, cheby2, el l i p, r emez, f i r l s, or f i r 1 for moreinformation.
8 Filter Design and Analysis Tool Reference
8-14
Highpass Filters
Whenyouselect thisoption, ahighpassfilter isdisplayedintheDisplayregion,
and theFrequency Specifications and MagnitudeSpecifications regions are
updated with theappropriateparameters.
Seebut t er , cheby1, cheby2, el l i p, r emez, f i r l s, or f i r 1 for moreinformation.
Bandpass Filters
When you select this option, a bandpass filter is displayed in theDisplay
region, andtheFrequencySpecificationsandMagnitudeSpecificationsregions
areupdated with theappropriateparameters.
Seebut t er , cheby1, cheby2, el l i p, r emez, f i r l s, or f i r 1 for moreinformation.
Filter Type Region
8-15
Bandstop Filters
You can specify thefrequencies that determinethepass band and the
stopband. When you select this option, a bandstop filter is displayed in the
Display region, and theFrequency Specifications and Magnitude
Specifications regions areupdated with theappropriateparameters.
Seebut t er , cheby1, cheby2, el l i p, r emez, f i r l s, or f i r 1 for moreinformation.
Differentiator Filters
A differentiator filter generates thederivativeof theinput signal. See
Multiband FI R Filter Design with Transition Bands and r emez for more
information.
Hilbert Transformer Filters
A Hilbert transformer is a filter that generates an approximation of the
discreteHilbert transformof theinput signal. SeeMultiband FI R Filter
Design with Transition Bands and r emez for moreinformation.
Multiband Filters
A multiband filter has multiplepassbands interleaved with multiple
stopbands. SeeMultiband FI R Filter Design with Transition Bandsand
r emez for moreinformation.
8 Filter Design and Analysis Tool Reference
8-16
Arbitrary Magnitude Filters
An arbitrary magnitudefilter can bedesigned tohaveany desired magnitude
responseshape. SeeMultibandFI R Filter Design with Transition Bandsand
r emez for moreinformation.
Arbitrary Group Delay Filters
An arbitrary group delay filter is an allpass I I R filter which provides thebest
approximation tothespecified relativegroup-delay responsein theleast-pth
sense. This filter typeis availableonly when theFilter Design Toolbox is
installed. Seei i r gr pdel ay in theFilter Design Toolbox documentation for
moreinformation.
Design Method Region
8-17
Design Method Region
This region allows you toselect a filter design method:
IIR methods
- Butterworth (but t er )
- Chebyshev TypeI (cheby1)
- Chebyshev TypeII (cheby2)
- Elliptic (el l i p)
- Constrained least Pth-norm
- Least Pth-norm
FIR methods
- Equiripple(r emez)
- Least-Squares (f i r l s)
- Window(f i r 1)
Themethods that you seelisted depend on thecurrent selection in theFilter
Typeregion:
ThePth-normdesigns areonly availablefor theArbitrary Magnitudeand
Arbitrary Group Delay filter types.
TheWindowdesign is only availablefor theLowpass, Highpass,
Bandpass, and Bandstop filter type.
8 Filter Design and Analysis Tool Reference
8-18
Current Filter Information Region
This region displays important information about thecurrent filter structure
beingused by thetool:
Filter structureindicates which of thefollowinginternal representations is
beingused for thecurrent filter:
- Direct formI
- Direct formII
- Direct formI transposed
- Direct formII transposed
- State-space
- Latticeallpass
- LatticeMA min. phase
- LatticeMA max. phase
- LatticeARMA
Sourceindicates whether thecurrent filter was designed usingFDATool
(Designed) or imported fromanother source(Imported). Theterm
Quantized appears hereif thefilter has been quantized usingtheFilter
Design Toolbox.
Order reports theorder of thecurrent filter.
Stableindicates whether thefilter is asymptoticallystable(Yes) or unstable
(No). Filters that havepoles on or outsidetheunit circleareconsidered
unstable.
Sections reports thenumber of sections in thecurrent filter.
TheConvert structurebutton opens a dialogbox that allows you tochoosea
different structurefor theinternal filter representation.
Convert Structure Button
8-19
Convert Structure Button
This button opens a dialogbox whereyou can specify a newstructureto
represent thecurrent filter. All filters can beconverted tothefollowing
representations:
Direct formI
Direct formII
Direct formI transposed
Direct formII transposed
State-space
LatticeARMA
I n addition, thefollowingconversions areavailablefor particular classes of
filters:
MinimumphaseFI R filters can beconverted toLatticeMA min. phase
MaximumphaseFI R filters can beconverted to LatticeMA max. phase
Allpass filters can beconverted toLatticeallpass
SeeFilter Structuresfor moreinformation about any of these
representations.
When selected, theUsesecond-order sections check box instructs thetool to
storetheconverted filter structureas a collection of second-order sections
rather than as a monolithic higher-order structure. Thesubordinate Scale
menu lets you select fromthefollowingoptions:
None(default)
L-2(L
2
norm)
L-infinity (L

norm)
Theorderingof thesecond-order sections is optimized for theselected scaling
option. (Thet f 2sos function that performs theconversion is calledwith option
' down' for L
2
normscaling, and with option ' up' for L

normscaling.)
8 Filter Design and Analysis Tool Reference
8-20
Quantization Region
Select Turn quantization on toquantizethecurrent filter usingtheFilter
Design Toolbox.
Frequency Specifications Region
8-21
Frequency Specifications Region
TheFrequency Specifications region allows you toenter frequency parameters
for thefilter design. Theoptions availablevarywith theselections in theFilter
Typeand Design Method regions:
Lowpass
- Butterworth
- Chebyshev TypeI
- Chebyshev TypeI I
- Elliptic
- Equiripple
- Least-Squares
- Window
Highpass
- Butterworth
- Chebyshev TypeI
- Chebyshev TypeI I
- Elliptic
- Equiripple
- Least-Squares
- Window
Bandpass
- Butterworth
- Chebyshev TypeI
- Chebyshev TypeI I
- Elliptic
- Equiripple
- Least-Squares
- Window
Bandstop
- Butterworth
8 Filter Design and Analysis Tool Reference
8-22
- Chebyshev TypeI
- Chebyshev TypeI I
- Elliptic
- Equiripple
- Least-Squares
- Window
Differentiator
Hilbert Transformer
Multiband
Arbitrary Magnitude
Arbitrary Group Delay availableonly when theFilter Design Toolbox is
installed
Frequency Specifications Region: Lowpass Butterworth
8-23
Frequency Specifications Region: Lowpass Butterworth
Select theunits for frequency specifications fromtheUnits list:
Hz (default)
kHz
MHz
Normalized (0to 1), where1 corresponds totheNyquist frequency
I f Specify order is selected in theFilter Order region, specify thefollowing
frequencies in thetext boxes:
Samplingfrequency (Fs) required when Hz, kHz, or MHz is selected
Cutoff frequency(Fcor wc) thefrequencyat whichthemagnituderesponse
is 3 dB belowthepassband gain
I f Minimumorder is selected in theFilter Order region, specify thefollowing
frequencies in thetext boxes:
Samplingfrequency (Fs) required when Hz, kHz, or MHz is selected
End of thepassband (Fpass or wpass)
Beginningof thestopband (Fstop or wstop)
8 Filter Design and Analysis Tool Reference
8-24
Frequency Specifications Region:
Lowpass Chebyshev Type I
Select theunits for frequency specifications fromtheUnits list:
Hz (default)
kHz
MHz
Normalized (0to 1), where1 corresponds totheNyquist frequency
I f Specify order is selected in theFilter Order region, specify thefollowing
frequencies in thetext boxes:
Samplingfrequency (Fs) required when Hz, kHz, or MHz is selected
End of thepassband (Fpass or wpass)
I f Minimumorder is selected in theFilter Order region, specify thefollowing
frequencies in thetext boxes:
Samplingfrequency (Fs) required when Hz, kHz, or MHz is selected
End of thepassband (Fpass or wpass)
Beginningof thestopband (Fstop or wstop)
Frequency Specifications Region: Lowpass Chebyshev Type II
8-25
Frequency Specifications Region:
Lowpass Chebyshev Type II
Select theunits for frequency specifications fromtheUnits list:
Hz (default)
kHz
MHz
Normalized (0to 1), where1 corresponds totheNyquist frequency
I f Specify order is selected in theFilter Order region, specify thefollowing
frequencies in thetext boxes:
Samplingfrequency (Fs) required when Hz, kHz, or MHz is selected
Beginningof thestopband (Fstop or wstop)
I f Minimumorder is selected in theFilter Order region, specify thefollowing
frequencies in thetext boxes:
Samplingfrequency (Fs) required when Hz, kHz, or MHz is selected
End of thepassband (Fpass or wpass)
Beginningof thestopband (Fstop or wstop)
8 Filter Design and Analysis Tool Reference
8-26
Frequency Specifications Region: Lowpass Elliptic
Select theunits for frequency specifications fromtheUnits list:
Hz (default)
kHz
MHz
Normalized (0to 1), where1 corresponds totheNyquist frequency
I f Specify order is selected in theFilter Order region, specify thefollowing
frequencies in thetext boxes:
Samplingfrequency (Fs) required when Hz, kHz, or MHz is selected
End of thepassband (Fpass or wpass)
I f Minimumorder is selected in theFilter Order region, specify thefollowing
frequencies in thetext boxes:
Samplingfrequency (Fs) required when Hz, kHz, or MHz is selected
End of thepassband (Fpass or wpass)
Beginningof thestopband (Fstop or wstop)
Frequency Specifications Region: Lowpass Equiripple
8-27
Frequency Specifications Region: Lowpass Equiripple
Select theunits for frequency specifications fromtheUnits list:
Hz (default)
kHz
MHz
Normalized (0to 1), where1 corresponds totheNyquist frequency
I f Specify order is selected in theFilter Order region, specify thefollowing
frequencies in thetext boxes:
Samplingfrequency (Fs) required when Hz, kHz, or MHz is selected
End of thepassband (Fpass or wpass)
Beginningof thestopband (Fstop or wstop)
I f Minimumorder is selected in theFilter Order region, specify thefollowing
frequencies in thetext boxes:
Samplingfrequency (Fs) required when Hz, kHz, or MHz is selected
End of thepassband (Fpass or wpass)
Beginningof thestopband (Fstop or wstop)
8 Filter Design and Analysis Tool Reference
8-28
Frequency Specifications Region: Lowpass Least-Squares
Select theunits for frequency specifications fromtheUnits list:
Hz (default)
kHz
MHz
Normalized (0to 1), where1 corresponds totheNyquist frequency
Specify thefollowingfrequencies in thetext boxes:
Samplingfrequency (Fs) required when Hz, kHz, or MHz is selected
End of thepassband (Fpass or wpass)
Beginningof thestopband (Fstop or wstop)
Frequency Specifications Region: Lowpass Window
8-29
Frequency Specifications Region: Lowpass Window
Select theunits for frequency specifications fromtheUnits list:
Hz (default)
kHz
MHz
Normalized (0to 1), where1 corresponds totheNyquist frequency
I f Specify order is selected in theFilter Order region, specify thefollowing
frequencies in thetext boxes:
Samplingfrequency (Fs) required when Hz, kHz, or MHz is selected
Cutoff frequency(Fcor wc) thefrequencyat whichthemagnituderesponse
is 6 dB belowthepassband gain
I f Minimumorder is selected in theFilter Order region, specify thefollowing
frequencies in thetext boxes:
Samplingfrequency (Fs) required when Hz, kHz, or MHz is selected
End of thepassband (Fpass or wpass)
Beginningof thestopband (Fstop or wstop)
8 Filter Design and Analysis Tool Reference
8-30
Frequency Specifications Region: Highpass Butterworth
Select theunits for frequency specifications fromtheUnits list:
Hz (default)
kHz
MHz
Normalized (0to 1), where1 corresponds totheNyquist frequency
I f Specify order is selected in theFilter Order region, specify thefollowing
frequencies in thetext boxes:
Samplingfrequency (Fs) required when Hz, kHz, or MHz is selected
Cutoff frequency(Fcor wc) thefrequencyat whichthemagnituderesponse
is 3 dB belowthepassband gain
I f Minimumorder is selected in theFilter Order region, specify thefollowing
frequencies in thetext boxes:
Samplingfrequency (Fs) required when Hz, kHz, or MHz is selected
End of thestopband (Fstop or wstop)
Beginningof thepassband (Fpass or wpass)
Frequency Specifications Region: Highpass Chebyshev Type I
8-31
Frequency Specifications Region:
Highpass Chebyshev Type I
Select theunits for frequency specifications fromtheUnits list:
Hz (default)
kHz
MHz
Normalized (0to 1), where1 corresponds totheNyquist frequency
I f Specify order is selected in theFilter Order region, specify thefollowing
frequencies in thetext boxes:
Samplingfrequency (Fs) required when Hz, kHz, or MHz is selected
Beginningof thepassband (Fpass or wpass)
I f Minimumorder is selected in theFilter Order region, specify thefollowing
frequencies in thetext boxes:
Samplingfrequency (Fs) required when Hz, kHz, or MHz is selected
End of thestopband (Fstop or wstop)
Beginningof thepassband (Fpass or wpass)
8 Filter Design and Analysis Tool Reference
8-32
Frequency Specifications Region:
Highpass Chebyshev Type II
Select theunits for frequency specifications fromtheUnits list:
Hz (default)
kHz
MHz
Normalized (0to 1), where1 corresponds totheNyquist frequency
I f Specify order is selected in theFilter Order region, specify thefollowing
frequencies in thetext boxes:
Samplingfrequency (Fs) required when Hz, kHz, or MHz is selected
End of thestopband (Fstop or wstop)
I f Minimumorder is selected in theFilter Order region, specify thefollowing
frequencies in thetext boxes:
Samplingfrequency (Fs) required when Hz, kHz, or MHz is selected
End of thestopband (Fstop or wstop)
Beginningof thepassband (Fpass or wpass)
Frequency Specifications Region: Highpass Elliptic
8-33
Frequency Specifications Region: Highpass Elliptic
Select theunits for frequency specifications fromtheUnits list:
Hz (default)
kHz
MHz
Normalized (0to 1), where1 corresponds totheNyquist frequency
I f Specify order is selected in theFilter Order region, specify thefollowing
frequencies in thetext boxes:
Samplingfrequency (Fs) required when Hz, kHz, or MHz is selected
Beginningof thepassband (Fpass or wpass)
I f Minimumorder is selected in theFilter Order region, specify thefollowing
frequencies in thetext boxes:
Samplingfrequency (Fs) required when Hz, kHz, or MHz is selected
End of thestopband (Fstop or wstop)
Beginningof thepassband (Fpass or wpass)
8 Filter Design and Analysis Tool Reference
8-34
Frequency Specifications Region: Highpass Equiripple
Select theunits for frequency specifications fromtheUnits list:
Hz (default)
kHz
MHz
Normalized (0to 1), where1 corresponds totheNyquist frequency
I f Specify order is selected in theFilter Order region, specify thefollowing
frequencies in thetext boxes:
Samplingfrequency (Fs) required when Hz, kHz, or MHz is selected
End of thestopband (Fstop or wstop)
Beginningof thepassband (Fpass or wpass)
I f Minimumorder is selected in theFilter Order region, specify thefollowing
frequencies in thetext boxes:
Samplingfrequency (Fs) required when Hz, kHz, or MHz is selected
End of thestopband (Fstop or wstop)
Beginningof thepassband (Fpass or wpass)
Frequency Specifications Region: Highpass Least-Squares
8-35
Frequency Specifications Region: Highpass Least-Squares
Select theunits for frequency specifications fromtheUnits list:
Hz (default)
kHz
MHz
Normalized (0to 1), where1 corresponds totheNyquist frequency
Specify thefollowingfrequencies in thetext boxes:
Samplingfrequency (Fs) required when Hz, kHz, or MHz is selected
End of thestopband (Fstop or wstop)
Beginningof thepassband (Fpass or wpass)
8 Filter Design and Analysis Tool Reference
8-36
Frequency Specifications Region: Highpass Window
Select theunits for frequency specifications fromtheUnits list:
Hz (default)
kHz
MHz
Normalized (0to 1), where1 corresponds totheNyquist frequency
I f Specify order is selected in theFilter Order region, specify thefollowing
frequencies in thetext boxes:
Samplingfrequency (Fs) required when Hz, kHz, or MHz is selected
Cutoff frequency(Fcor wc) thefrequencyat whichthemagnituderesponse
is 6 dB belowthepassband gain
I f Minimumorder is selected in theFilter Order region, specify thefollowing
frequencies in thetext boxes:
Samplingfrequency (Fs) required when Hz, kHz, or MHz is selected
End of thestopband (Fstop or wstop)
Beginningof thepassband (Fpass or wpass)
Frequency Specifications Region: Bandpass Butterworth
8-37
Frequency Specifications Region: Bandpass Butterworth
Select theunits for frequency specifications fromtheUnits list:
Hz (default)
kHz
MHz
Normalized (0to 1), where1 corresponds totheNyquist frequency
I f Specify order is selected in theFilter Order region, specify thefollowing
frequencies in thetext boxes:
Samplingfrequency (Fs) required when Hz, kHz, or MHz is selected
First cutoff frequency (Fc1or wc1) thefrequency precedingthepassband
at which themagnituderesponseis 3 dB belowthepassband gain
Secondcutoff frequency(Fc2or wc2) thefrequencyfollowingthepassband
at which themagnituderesponseis 3 dB belowthepassband gain
I f Minimumorder is selected in theFilter Order region, specify thefollowing
frequencies in thetext boxes:
Samplingfrequency (Fs) required when Hz, kHz, or MHz is selected
End of thefirst stopband (Fstop1or wstop1)
Beginningof thepassband (Fpass1or wpass1)
End of thepassband (Fpass2or wpass2)
Beginningof thesecond stopband (Fstop2or wstop2)
8 Filter Design and Analysis Tool Reference
8-38
Frequency Specifications Region:
Bandpass Chebyshev Type I
Select theunits for frequency specifications fromtheUnits list:
Hz (default)
kHz
MHz
Normalized (0to 1), where1 corresponds totheNyquist frequency
I f Specify order is selected in theFilter Order region, specify thefollowing
frequencies in thetext boxes:
Samplingfrequency (Fs) required when Hz, kHz, or MHz is selected
Beginningof thepassband (Fpass1or wpass1)
End of thepassband (Fpass2or wpass2)
I f Minimumorder is selected in theFilter Order region, specify thefollowing
frequencies in thetext boxes:
Samplingfrequency (Fs) required when Hz, kHz, or MHz is selected
End of thefirst stopband (Fstop1or wstop1)
Beginningof thepassband (Fpass1or wpass1)
End of thepassband (Fpass2or wpass2)
Beginningof thesecond stopband (Fstop2or wstop2)
Frequency Specifications Region: Bandpass Chebyshev Type II
8-39
Frequency Specifications Region:
Bandpass Chebyshev Type II
Select theunits for frequency specifications fromtheUnits list:
Hz (default)
kHz
MHz
Normalized (0to 1), where1 corresponds totheNyquist frequency
I f Specify order is selected in theFilter Order region, specify thefollowing
frequencies in thetext boxes:
Samplingfrequency (Fs) required when Hz, kHz, or MHz is selected
End of thefirst stopband (Fstop1or wstop1)
Beginningof thesecond stopband (Fstop2or wstop2)
I f Minimumorder is selected in theFilter Order region, specify thefollowing
frequencies in thetext boxes:
Samplingfrequency (Fs) required when Hz, kHz, or MHz is selected
End of thefirst stopband (Fstop1or wstop1)
Beginningof thepassband (Fpass1or wpass1)
End of thepassband (Fpass2or wpass2)
Beginningof thesecond stopband (Fstop2or wstop2)
8 Filter Design and Analysis Tool Reference
8-40
Frequency Specifications Region: Bandpass Elliptic
Select theunits for frequency specifications fromtheUnits list:
Hz (default)
kHz
MHz
Normalized (0to 1), where1 corresponds totheNyquist frequency
I f Specify order is selected in theFilter Order region, specify thefollowing
frequencies in thetext boxes:
Samplingfrequency (Fs) required when Hz, kHz, or MHz is selected
Beginningof thepassband (Fpass1or wpass1)
End of thepassband (Fpass2or wpass2)
I f Minimumorder is selected in theFilter Order region, specify thefollowing
frequencies in thetext boxes:
Samplingfrequency (Fs) required when Hz, kHz, or MHz is selected
End of thefirst stopband (Fstop1or wstop1)
Beginningof thepassband (Fpass1or wpass1)
End of thepassband (Fpass2or wpass2)
Beginningof thesecond stopband (Fstop2or wstop2)
Frequency Specifications Region: Bandpass Equiripple
8-41
Frequency Specifications Region: Bandpass Equiripple
Select theunits for frequency specifications fromtheUnits list:
Hz (default)
kHz
MHz
Normalized (0to 1), where1 corresponds totheNyquist frequency
I f Specify order is selected in theFilter Order region, specify thefollowing
frequencies in thetext boxes:
Samplingfrequency (Fs) required when Hz, kHz, or MHz is selected
End of thefirst stopband (Fstop1or wstop1)
Beginningof thepassband (Fpass1or wpass1)
End of thepassband (Fpass2or wpass2)
Beginningof thesecond stopband (Fstop2or wstop2)
I f Minimumorder is selected in theFilter Order region, specify thefollowing
frequencies in thetext boxes:
Samplingfrequency (Fs) required when Hz, kHz, or MHz is selected
End of thefirst stopband (Fstop1or wstop1)
Beginningof thepassband (Fpass1or wpass1)
End of thepassband (Fpass2or wpass2)
Beginningof thesecond stopband (Fstop2or wstop2)
8 Filter Design and Analysis Tool Reference
8-42
Frequency Specifications Region: Bandpass Least-Squares
Select theunits for frequency specifications fromtheUnits list:
Hz (default)
kHz
MHz
Normalized (0to 1), where1 corresponds totheNyquist frequency
Specify thefollowingfrequencies in thetext boxes:
Samplingfrequency (Fs) required when Hz, kHz, or MHz is selected
End of thefirst stopband (Fstop1or wstop1)
Beginningof thepassband (Fpass1or wpass1)
End of thepassband (Fpass2or wpass2)
Beginningof thesecond stopband (Fstop2or wstop2)
Frequency Specifications Region: Bandpass Window
8-43
Frequency Specifications Region: Bandpass Window
Select theunits for frequency specifications fromtheUnits list:
Hz (default)
kHz
MHz
Normalized (0to 1), where1 corresponds totheNyquist frequency
I f Specify order is selected in theFilter Order region, specify thefollowing
frequencies in thetext boxes:
Samplingfrequency (Fs) required when Hz, kHz, or MHz is selected
First cutoff frequency (Fc1or wc1) thefrequency precedingthepassband
at which themagnituderesponseis 6 dB belowthepassband gain
Secondcutoff frequency(Fc2or wc2) thefrequencyfollowingthepassband
at which themagnituderesponseis 6 dB belowthepassband gain
I f Minimumorder is selected in theFilter Order region, specify thefollowing
frequencies in thetext boxes:
Samplingfrequency (Fs) required when Hz, kHz, or MHz is selected
End of thefirst stopband (Fstop1or wstop1)
Beginningof thepassband (Fpass1or wpass1)
End of thepassband (Fpass2or wpass2)
Beginningof thesecond stopband (Fstop2or wstop2)
8 Filter Design and Analysis Tool Reference
8-44
Frequency Specifications Region: Bandstop Butterworth
Select theunits for frequency specifications fromtheUnits list:
Hz (default)
kHz
MHz
Normalized (0to 1), where1 corresponds totheNyquist frequency
I f Specify order is selected in theFilter Order region, specify thefollowing
frequencies in thetext boxes:
Samplingfrequency (Fs) required when Hz, kHz, or MHz is selected
First cutoff frequency(Fc1or wc1) thefrequencyprecedingthestopbandat
which themagnituderesponseis 3 dB belowthepassband gain
Secondcutoff frequency (Fc2or wc2) thefrequency followingthestopband
at which themagnituderesponseis 3 dB belowthepassband gain
I f Minimumorder is selected in theFilter Order region, specify thefollowing
frequencies in thetext boxes:
Samplingfrequency (Fs) required when Hz, kHz, or MHz is selected
End of thefirst passband (Fpass1or wpass1)
Beginningof thestopband (Fstop1or wstop1)
End of thestopband (Fstop2or wstop2)
Beginningof thesecond passband (Fpass2or wpass2)
Frequency Specifications Region: Bandstop Chebyshev Type I
8-45
Frequency Specifications Region:
Bandstop Chebyshev Type I
Select theunits for frequency specifications fromtheUnits list:
Hz (default)
kHz
MHz
Normalized (0to 1), where1 corresponds totheNyquist frequency
I f Specify order is selected in theFilter Order region, specify thefollowing
frequencies in thetext boxes:
Samplingfrequency (Fs) required when Hz, kHz, or MHz is selected
End of thefirst passband (Fpass1or wpass1)
Beginningof thesecond passband (Fpass2or wpass2)
I f Minimumorder is selected in theFilter Order region, specify thefollowing
frequencies in thetext boxes:
Samplingfrequency (Fs) required when Hz, kHz, or MHz is selected
End of thefirst passband (Fpass1or wpass1)
Beginningof thestopband (Fstop1or wstop1)
End of thestopband (Fstop2or wstop2)
Beginningof thesecond passband (Fpass2or wpass2)
8 Filter Design and Analysis Tool Reference
8-46
Frequency Specifications Region:
Bandstop Chebyshev Type II
Select theunits for frequency specifications fromtheUnits list:
Hz (default)
kHz
MHz
Normalized (0to 1), where1 corresponds totheNyquist frequency
I f Specify order is selected in theFilter Order region, specify thefollowing
frequencies in thetext boxes:
Samplingfrequency (Fs) required when Hz, kHz, or MHz is selected
Beginningof thestopband (Fstop1or wstop1)
End of thestopband (Fstop2or wstop2)
I f Minimumorder is selected in theFilter Order region, specify thefollowing
frequencies in thetext boxes:
Samplingfrequency (Fs) required when Hz, kHz, or MHz is selected
End of thefirst passband (Fpass1or wpass1)
Beginningof thestopband (Fstop1or wstop1)
End of thestopband (Fstop2or wstop2)
Beginningof thesecond passband (Fpass2or wpass2)
Frequency Specifications Region: Bandstop Elliptic
8-47
Frequency Specifications Region: Bandstop Elliptic
Select theunits for frequency specifications fromtheUnits list:
Hz (default)
kHz
MHz
Normalized (0to 1), where1 corresponds totheNyquist frequency
I f Specify order is selected in theFilter Order region, specify thefollowing
frequencies in thetext boxes:
Samplingfrequency (Fs) required when Hz, kHz, or MHz is selected
End of thefirst passband (Fpass1or wpass1)
Beginningof thesecond passband (Fpass2or wpass2)
I f Minimumorder is selected in theFilter Order region, specify thefollowing
frequencies in thetext boxes:
Samplingfrequency (Fs) required when Hz, kHz, or MHz is selected
End of thefirst passband (Fpass1or wpass1)
Beginningof thestopband (Fstop1or wstop1)
End of thestopband (Fstop2or wstop2)
Beginningof thesecond passband (Fpass2or wpass2)
8 Filter Design and Analysis Tool Reference
8-48
Frequency Specifications Region: Bandstop Equiripple
Select theunits for frequency specifications fromtheUnits list:
Hz (default)
kHz
MHz
Normalized (0to 1), where1 corresponds totheNyquist frequency
I f Specify order is selected in theFilter Order region, specify thefollowing
frequencies in thetext boxes:
Samplingfrequency (Fs) required when Hz, kHz, or MHz is selected
End of thefirst passband (Fpass1or wpass1)
Beginningof thestopband (Fstop1or wstop1)
End of thestopband (Fstop2or wstop2)
Beginningof thesecond passband (Fpass2or wpass2)
I f Minimumorder is selected in theFilter Order region, specify thefollowing
frequencies in thetext boxes:
Samplingfrequency (Fs) required when Hz, kHz, or MHz is selected
End of thefirst passband (Fpass1or wpass1)
Beginningof thestopband (Fstop1or wstop1)
End of thestopband (Fstop2or wstop2)
Beginningof thesecond passband (Fpass2or wpass2)
Frequency Specifications Region: Bandstop Least-Squares
8-49
Frequency Specifications Region: Bandstop Least-Squares
Select theunits for frequency specifications fromtheUnits list:
Hz (default)
kHz
MHz
Normalized (0to 1), where1 corresponds totheNyquist frequency
Specify thefollowingfrequencies in thetext boxes:
Samplingfrequency (Fs) required when Hz, kHz, or MHz is selected
End of thefirst passband (Fpass1or wpass1)
Beginningof thestopband (Fstop1or wstop1)
End of thestopband (Fstop2or wstop2)
Beginningof thesecond passband (Fpass2or wpass2)
8 Filter Design and Analysis Tool Reference
8-50
Frequency Specifications Region: Bandstop Window
Select theunits for frequency specifications fromtheUnits list:
Hz (default)
kHz
MHz
Normalized (0to 1), where1 corresponds totheNyquist frequency
I f Specify order is selected in theFilter Order region, specify thefollowing
frequencies in thetext boxes:
Samplingfrequency (Fs) required when Hz, kHz, or MHz is selected
First cutoff frequency(Fc1or wc1) thefrequencyprecedingthestopbandat
which themagnituderesponseis 6 dB belowthepassband gain
Secondcutoff frequency (Fc2or wc2) thefrequency followingthestopband
at which themagnituderesponseis 6 dB belowthepassband gain
I f Minimumorder is selected in theFilter Order region, specify thefollowing
frequencies in thetext boxes:
Samplingfrequency (Fs) required when Hz, kHz, or MHz is selected
End of thefirst passband (Fpass1or wpass1)
Beginningof thestopband (Fstop1or wstop1)
End of thestopband (Fstop2or wstop2)
Beginningof thesecond passband (Fpass2or wpass2)
Magnitude Specifications Region
8-51
Magnitude Specifications Region
TheMagnitudeSpecifications region allows you toenter magnitude
parameters for thefilter design. Theoptions availablevary with theselections
in theFilter Typeand Design Method regions:
Lowpass
- Butterworth
- Chebyshev TypeI
- Chebyshev TypeI I
- Elliptic
- Equiripple
- Least-Squares
- Window
Highpass
- Butterworth
- Chebyshev TypeI
- Chebyshev TypeI I
- Elliptic
- Equiripple
- Least-Squares
- Window
Bandpass
- Butterworth
- Chebyshev TypeI
- Chebyshev TypeI I
- Elliptic
- Equiripple
- Least-Squares
- Window
Bandstop
- Butterworth
8 Filter Design and Analysis Tool Reference
8-52
- Chebyshev TypeI
- Chebyshev TypeI I
- Elliptic
- Equiripple
- Least-Squares
- Window
Differentiator
Hilbert Transformer
Multiband
Arbitrary Magnitude
Arbitrary Group Delay availableonly when theFilter Design Toolbox is
installed
Magnitude Specifications Region: Lowpass Butterworth
8-53
Magnitude Specifications Region: Lowpass Butterworth
I f Specify order is selected in theFilter Order region, theattenuation at the
cutoff frequency is fixed at 3 dB (half thepassband power).
I f Minimumorder is selected in theFilter Order region, select theunits for
magnituderesponsecharacteristics fromtheUnits list:
dB for magnituderesponsecharacteristics in decibels (default)
Squared for squared magnituderesponsecharacteristics
Specify thefollowingmagnituderesponsecharacteristics in thetext boxes:
Passband ripple(Apass or Epass)
Stopband attenuation (Astop or Estop)
8 Filter Design and Analysis Tool Reference
8-54
Magnitude Specifications Region:
Lowpass Chebyshev Type I
I f Specify order is selected in theFilter Order region, specify thepassband
ripple(Apass or Epass) in decibels.
I f Minimumorder is selected in theFilter Order region, select theunits for
magnituderesponsecharacteristics fromtheUnits list:
dB for magnituderesponsecharacteristics in decibels (default)
Squared for squared magnituderesponsecharacteristics
Specify thefollowingmagnituderesponsecharacteristics in thetext boxes:
Passband ripple(Apass or Epass)
Stopband attenuation (Astop or Estop)
Magnitude Specifications Region: Lowpass Chebyshev Type II
8-55
Magnitude Specifications Region:
Lowpass Chebyshev Type II
I f Specify order is selected in theFilter Order region, specify thestopband
attenuation (Astop or Estop) in decibels.
I f Minimumorder is selected in theFilter Order region, select theunits for
magnituderesponsecharacteristics fromtheUnits list:
dB for magnituderesponsecharacteristics in decibels (default)
Squared for squared magnituderesponsecharacteristics
Specify thefollowingmagnituderesponsecharacteristics in thetext boxes:
Passband ripple(Apass or Epass)
Stopband attenuation (Astop or Estop)
8 Filter Design and Analysis Tool Reference
8-56
Magnitude Specifications Region: Lowpass Elliptic
I f Specify order is selected in theFilter Order region, specify thefollowing
magnituderesponsecharacteristics (in dB) in thetext boxes:
Passband ripple(Apass or Epass)
Stopband attenuation (Astop or Estop)
I f Minimumorder is selected in theFilter Order region, select theunits for
magnituderesponsecharacteristics fromtheUnits list:
dB for magnituderesponsecharacteristics in decibels (default)
Squared for squared magnituderesponsecharacteristics
Specify thefollowingmagnituderesponsecharacteristics in thetext boxes:
Passband ripple(Apass or Epass)
Stopband attenuation (Astop or Estop)
Magnitude Specifications Region: Lowpass Equiripple
8-57
Magnitude Specifications Region: Lowpass Equiripple
I f Specify order is selected in theFilter Order region, specify thefollowing
relativeweights in thetext boxes:
Passband weighting(Wpass)
Stopband weighting(Wstop)
I f Minimumorder is selected in theFilter Order region, select theunits for
magnituderesponsecharacteristics fromtheUnits list:
dB for magnituderesponsecharacteristics in decibels (default)
Linear for linearly scaled magnituderesponsecharacteristics
Specify thefollowingmagnituderesponsecharacteristics in thetext boxes:
Passband ripple(Apass or Dpass)
Stopband attenuation (Astop or Dstop)
8 Filter Design and Analysis Tool Reference
8-58
Magnitude Specifications Region: Lowpass Least-Squares
Specify thefollowingrelativeweights in thetext boxes:
Passband weighting(Wpass)
Stopband weighting(Wstop)
Magnitude Specifications Region: Lowpass Window
8-59
Magnitude Specifications Region: Lowpass Window
I f Specify order is selected in theFilter Order region, theattenuation at the
cutoff frequency is fixed at 6 dB (half thepassband gain).
For theKaiser windowoption, if Minimumorder isselectedintheFilter Order
region, select theunits for magnituderesponsecharacteristics fromtheUnits
list:
dB for magnituderesponsecharacteristics in decibels (default)
Linear for linearly scaled magnituderesponsecharacteristics
Specify thefollowingmagnituderesponsecharacteristics in thetext boxes:
Passband ripple(Apass or Dpass)
Stopband attenuation (Astop or Dstop)
8 Filter Design and Analysis Tool Reference
8-60
Magnitude Specifications Region: Highpass Butterworth
I f Specify order is selected in theFilter Order region, theattenuation at the
cutoff frequency is fixed at 3 dB (half thepassband power).
I f Minimumorder is selected in theFilter Order region, select theunits for
magnituderesponsecharacteristics fromtheUnits list:
dB for magnituderesponsecharacteristics in decibels (default)
Squared for squared magnituderesponsecharacteristics
Specify thefollowingmagnituderesponsecharacteristics in thetext boxes:
Passband ripple(Apass or Epass)
Stopband attenuation (Astop or Estop)
Magnitude Specifications Region: Highpass Chebyshev Type I
8-61
Magnitude Specifications Region:
Highpass Chebyshev Type I
I f Specify order is selected in theFilter Order region, specify thepassband
ripple(Apass) in decibels.
I f Minimumorder is selected in theFilter Order region, select theunits for
magnituderesponsecharacteristics fromtheUnits list:
dB for magnituderesponsecharacteristics in decibels (default)
Squared for squared magnituderesponsecharacteristics
Specify thefollowingmagnituderesponsecharacteristics in thetext boxes:
Passband ripple(Apass or Epass)
Stopband attenuation (Astop or Estop)
8 Filter Design and Analysis Tool Reference
8-62
Magnitude Specifications Region:
Highpass Chebyshev Type II
I f Specify order is selected in theFilter Order region, specify thestopband
attenuation (Astop) in decibels.
I f Minimumorder is selected in theFilter Order region, select theunits for
magnituderesponsecharacteristics fromtheUnits list:
dB for magnituderesponsecharacteristics in decibels (default)
Squared for squared magnituderesponsecharacteristics
Specify thefollowingmagnituderesponsecharacteristics in thetext boxes:
Passband ripple(Apass or Epass)
Stopband attenuation (Astop or Estop)
Magnitude Specifications Region: Highpass Elliptic
8-63
Magnitude Specifications Region: Highpass Elliptic
I f Specify order is selected in theFilter Order region, specify thefollowing
magnituderesponsecharacteristics (in dB) in thetext boxes:
Passband ripple(Apass or Epass)
Stopband attenuation (Astop or Estop)
I f Minimumorder is selected in theFilter Order region, select theunits for
magnituderesponsecharacteristics fromtheUnits list:
dB for magnituderesponsecharacteristics in decibels (default)
Squared for squared magnituderesponsecharacteristics
Specify thefollowingmagnituderesponsecharacteristics in thetext boxes:
Passband ripple(Apass or Epass)
Stopband attenuation (Astop or Estop)
8 Filter Design and Analysis Tool Reference
8-64
Magnitude Specifications Region: Highpass Equiripple
I f Specify order is selected in theFilter Order region, specify thefollowing
relativeweights in thetext boxes:
Stopband weighting(Wstop)
Passband weighting(Wpass)
I f Minimumorder is selected in theFilter Order region, select theunits for
magnituderesponsecharacteristics fromtheUnits list:
dB for magnituderesponsecharacteristics in decibels (default)
Linear for linearly scaled magnituderesponsecharacteristics
Specify thefollowingmagnituderesponsecharacteristics in thetext boxes:
Passband ripple(Apass or Dpass)
Stopband attenuation (Astop or Dstop)
Magnitude Specifications Region: Highpass Least-Squares
8-65
Magnitude Specifications Region: Highpass Least-Squares
Specify thefollowingrelativeweights in thetext boxes:
Stopband weighting(Wstop)
Passband weighting(Wpass)
8 Filter Design and Analysis Tool Reference
8-66
Magnitude Specifications Region: Highpass Window
I f Specify order is selected in theFilter Order region, theattenuation at the
cutoff frequency is fixed at 6 dB (half thepassband gain).
I f Minimumorder is selected in theFilter Order region, select theunits for
magnituderesponsecharacteristics fromtheUnits list:
dB for magnituderesponsecharacteristics in decibels (default)
Linear for linearly scaled magnituderesponsecharacteristics
Specify thefollowingmagnituderesponsecharacteristics in thetext boxes:
Passband ripple(Apass or Dpass)
Stopband attenuation (Astop or Dstop)
Magnitude Specifications Region: Bandpass Butterworth
8-67
Magnitude Specifications Region: Bandpass Butterworth
I f Specify order is selected in theFilter Order region, theattenuation at the
cutoff frequencies is fixed at 3 dB (half thepassband power).
I f Minimumorder is selected in theFilter Order region, select theunits for
magnituderesponsecharacteristics fromtheUnits list:
dB for magnituderesponsecharacteristics in decibels (default)
Squared for squared magnituderesponsecharacteristics
Specify thefollowingmagnituderesponsecharacteristics in thetext boxes:
Attenuation in thefirst stopband (Astop1or Estop1)
Passband ripple(Apass or Epass)
Attenuation in thesecond stopband (Astop2or Estop2)
8 Filter Design and Analysis Tool Reference
8-68
Magnitude Specifications Region:
Bandpass Chebyshev Type I
I f Specify order is selected in theFilter Order region, specify thepassband
ripple(Apass) in decibels.
I f Minimumorder is selected in theFilter Order region, select theunits for
magnituderesponsecharacteristics fromtheUnits list:
dB for magnituderesponsecharacteristics in decibels (default)
Squared for squared magnituderesponsecharacteristics
Specify thefollowingmagnituderesponsecharacteristics in thetext boxes:
Attenuation in thefirst stopband (Astop1or Estop1)
Passband ripple(Apass or Epass)
Attenuation in thesecond stopband (Astop2or Estop2)
Magnitude Specifications Region: Bandpass Chebyshev Type II
8-69
Magnitude Specifications Region:
Bandpass Chebyshev Type II
I f Specify order is selected in theFilter Order region, specify thestopband
attenuation (Astop) in decibels.
I f Minimumorder is selected in theFilter Order region, select theunits for
magnituderesponsecharacteristics fromtheUnits list:
dB for magnituderesponsecharacteristics in decibels (default)
Squared for squared magnituderesponsecharacteristics
Specify thefollowingmagnituderesponsecharacteristics in thetext boxes:
Attenuation in thefirst stopband (Astop1or Estop1)
Passband ripple(Apass or Epass)
Attenuation in thesecond stopband (Astop2or Estop2)
8 Filter Design and Analysis Tool Reference
8-70
Magnitude Specifications Region: Bandpass Elliptic
I f Specify order is selected in theFilter Order region, specify thefollowing
magnituderesponsecharacteristics (in dB) in thetext boxes:
Stopband attenuation (Astop)
Passband ripple(Apass)
I f Minimumorder is selected in theFilter Order region, select theunits for
magnituderesponsecharacteristics fromtheUnits list:
dB for magnituderesponsecharacteristics in decibels (default)
Squared for squared magnituderesponsecharacteristics
Specify thefollowingmagnituderesponsecharacteristics in thetext boxes:
Attenuation in thefirst stopband (Astop1or Estop1)
Passband ripple(Apass or Epass)
Attenuation in thesecond stopband (Astop2or Estop2)
Magnitude Specifications Region: Bandpass Equiripple
8-71
Magnitude Specifications Region: Bandpass Equiripple
I f Specify order is selected in theFilter Order region, specify thefollowing
relativeweights in thetext boxes:
Weightingin thefirst stopband (Wstop1)
Passband weighting(Wpass)
Weightingin thesecond stopband (Wstop2)
I f Minimumorder is selected in theFilter Order region, select theunits for
magnituderesponsecharacteristics fromtheUnits list:
dB for magnituderesponsecharacteristics in decibels (default)
Linear for linearly scaled magnituderesponsecharacteristics
Specify thefollowingmagnituderesponsecharacteristics in thetext boxes:
Attenuation in thefirst stopband (Astop1or Dstop1)
Passband ripple(Apass or Dpass)
Attenuation in thesecond stopband (Astop2or Dstop2)
8 Filter Design and Analysis Tool Reference
8-72
Magnitude Specifications Region: Bandpass Least-Squares
Specify thefollowingrelativeweights in thetext boxes:
Weightingin thefirst stopband (Wstop1)
Passband weighting(Wpass)
Weightingin thesecond stopband (Wstop2)
Magnitude Specifications Region: Bandpass Window
8-73
Magnitude Specifications Region: Bandpass Window
I f Specify order is selected in theFilter Order region, theattenuation at the
cutoff frequencies is fixed at 6 dB (half thepassband gain).
I f Minimumorder is selected in theFilter Order region, select theunits for
magnituderesponsecharacteristics fromtheUnits list:
dB for magnituderesponsecharacteristics in decibels (default)
Linear for linearly scaled magnituderesponsecharacteristics
Specify thefollowingmagnituderesponsecharacteristics in thetext boxes:
Attenuation in thefirst stopband (Astop1or Dstop1)
Passband ripple(Apass or Dpass)
Attenuation in thesecond stopband (Astop2or Dstop2)
8 Filter Design and Analysis Tool Reference
8-74
Magnitude Specifications Region: Bandstop Butterworth
I f Specify order is selected in theFilter Order region, theattenuation at the
cutoff frequencies is fixed at 3 dB (half thepassband power).
I f Minimumorder is selected in theFilter Order region, select theunits for
magnituderesponsecharacteristics fromtheUnits list:
dB for magnituderesponsecharacteristics in decibels (default)
Squared for squared magnituderesponsecharacteristics
Specify thefollowingmagnituderesponsecharacteristics in thetext boxes:
Ripplein thefirst passband (Apass1or Epass1)
Stopband attenuation (Astop or Estop)
Ripplein thesecond passband (Apass2or Epass2)
Magnitude Specifications Region: Bandstop Chebyshev Type I
8-75
Magnitude Specifications Region:
Bandstop Chebyshev Type I
I f Specify order is selected in theFilter Order region, specify thepassband
ripple(Apass) in decibels.
I f Minimumorder is selected in theFilter Order region, select theunits for
magnituderesponsecharacteristics fromtheUnits list:
dB for magnituderesponsecharacteristics in decibels (default)
Squared for squared magnituderesponsecharacteristics
Specify thefollowingmagnituderesponsecharacteristics in thetext boxes:
Ripplein thefirst passband (Apass1or Epass1)
Stopband attenuation (Astop or Estop)
Ripplein thesecond passband (Apass2or Epass2)
8 Filter Design and Analysis Tool Reference
8-76
Magnitude Specifications Region:
Bandstop Chebyshev Type II
I f Specify order is selected in theFilter Order region, specify thestopband
attenuation (Astop) in decibels.
I f Minimumorder is selected in theFilter Order region, select theunits for
magnituderesponsecharacteristics fromtheUnits list:
dB for magnituderesponsecharacteristics in decibels (default)
Squared for squared magnituderesponsecharacteristics
Specify thefollowingmagnituderesponsecharacteristics in thetext boxes:
Ripplein thefirst passband (Apass1or Epass1)
Stopband attenuation (Astop or Estop)
Ripplein thesecond passband (Apass2or Epass2)
Magnitude Specifications Region: Bandstop Elliptic
8-77
Magnitude Specifications Region: Bandstop Elliptic
I f Specify order is selected in theFilter Order region, specify thefollowing
magnituderesponsecharacteristics (in dB) in thetext boxes:
Passband ripple(Apass or Epass)
Stopband attenuation (Astop or Estop)
I f Minimumorder is selected in theFilter Order region, select theunits for
magnituderesponsecharacteristics fromtheUnits list:
dB for magnituderesponsecharacteristics in decibels (default)
Squared for squared magnituderesponsecharacteristics
Specify thefollowingmagnituderesponsecharacteristics in thetext boxes:
Ripplein thefirst passband (Apass1or Epass1)
Stopband attenuation (Astop or Estop)
Ripplein thesecond passband (Apass2or Epass2)
8 Filter Design and Analysis Tool Reference
8-78
Magnitude Specifications Region: Bandstop Equiripple
I f Specify order is selected in theFilter Order region, specify thefollowing
relativeweights in thetext boxes:
Weightingin thefirst passband (Wpass1)
Stopband weighting(Wstop)
Weightingin thesecond passband (Wpass2)
I f Minimumorder is selected in theFilter Order region, select theunits for
magnituderesponsecharacteristics fromtheUnits list:
dB for magnituderesponsecharacteristics in decibels (default)
Linear for linearly scaled magnituderesponsecharacteristics
Specify thefollowingmagnituderesponsecharacteristics in thetext boxes:
Ripplein thefirst passband (Apass1or Dpass1)
Stopband attenuation (Astop or Dstop)
Ripplein thesecond passband (Apass2or Dpass2)
Magnitude Specifications Region: Bandstop Least-Squares
8-79
Magnitude Specifications Region: Bandstop Least-Squares
Specify thefollowingrelativeweights in thetext boxes:
Weightingin thefirst passband (Wpass1)
Stopband weighting(Wstop)
Weightingin thesecond passband (Wpass2)
8 Filter Design and Analysis Tool Reference
8-80
Magnitude Specifications Region: Bandstop Window
I f Specify order is selected in theFilter Order region, theattenuation at the
cutoff frequencies is fixed at 6 dB (half thepassband gain).
I f Minimumorder is selected in theFilter Order region, select theunits for
magnituderesponsecharacteristics fromtheUnits list:
dB for magnituderesponsecharacteristics in decibels (default)
Linear for linearly scaled magnituderesponsecharacteristics
Specify thefollowingmagnituderesponsecharacteristics in thetext boxes:
Ripplein thefirst passband (Apass1or Dpass1)
Stopband attenuation (Astop or Dstop)
Ripplein thesecond passband (Apass2or Dpass2)
Frequency and Magnitude Specifications Region: Differentiator
8-81
Frequency and Magnitude Specifications Region:
Differentiator
Select theunits for frequency specifications fromtheFrequency units list:
Hz
kHz
MHz
Normalized (0to 1), where1 corresponds totheNyquist frequency
For all units except Normalized, specify thesamplingfrequency, Fs.
Specify thefollowingparameters in thetext boxes:
Freq. vector A vector definingthefrequency points at which theresponse
magnitudeis specified, in ascendingorder. Must havean even length the
sameas Mag. vector.
Mag. vector A vector definingtheresponsemagnitudes at thespecified
frequencies. Must havean even length thesameas Freq. vector.
Weight vector A vector definingtherelativeweight that should begiven
toeach frequency band. Must behalf thelength of Freq. vector.
Each odd-indexed frequency-amplitudepair defines theleft endpoint of a line
segment representingthedesiredmagnituderesponsein that frequency band.
Thecorrespondingeven-indexed frequency-amplitudepair defines theright
endpoint. Between thefrequency bands specified by theseend-points, there
maybeundefinedsectionsof thespecifiedfrequencyresponse. Thesearecalled
dont careor transitionregions, andthemagnituderesponsein theseareas
is a by-product of theoptimization in theother (specified) frequency ranges.
TheWeight vector specifiestheemphasistobeplacedon minimizingtheerror
in certain frequency bands relativetoothers, oneweight per band. I n most
cases, differentiators haveonly a singleband, sotheweight is a scalar value
that does not affect thefinal filter.
SeeMultiband FI R Filter Design with Transition Bandsand r emez for more
information.
8 Filter Design and Analysis Tool Reference
8-82
Frequency and Magnitude Specifications Region:
Hilbert Transformer
Select theunits for frequency specifications fromtheFrequency units list:
Hz
kHz
MHz
Normalized (0to 1), where1 corresponds totheNyquist frequency
For all units except Normalized, specify thesamplingfrequency, Fs.
Specify thefollowingparameters in thetext boxes:
Freq. vector A vector definingthefrequency points at which theresponse
magnitudeis specified, in ascendingorder. Must havean even length the
sameas Mag. vector.
Mag. vector A vector definingtheresponsemagnitudes at thespecified
frequencies. Must havean even length thesameas Freq. vector.
Weight vector A vector definingtherelativeweight that should begiven
toeach frequency band. Must behalf thelength of Freq. vector.
Each odd-indexed frequency-amplitudepair defines theleft endpoint of a line
segment representingthedesiredmagnituderesponsein that frequency band.
Thecorrespondingeven-indexed frequency-amplitudepair defines theright
endpoint. Between thefrequency bands specified by theseend-points, there
maybeundefinedsectionsof thespecifiedfrequencyresponse. Thesearecalled
dont careor transitionregions, andthemagnituderesponsein theseareas
is a by-product of theoptimization in theother (specified) frequency ranges.
TheWeight vector specifiestheemphasis tobeplacedonminimizingtheerror
in certain frequency bands relativetoothers, oneweight per band. I n most
cases, Hilbert transformers haveonly a singleband, sotheweight is a scalar
valuethat does not affect thefinal filter. However, theWeight vector is useful
when designingan antisymmetric multiband filter, such as a Hilbert
transformer with stopbands.
SeeMultiband FI R Filter Design with Transition Bandsand r emez for more
information.
Frequency and Magnitude Specifications Region: Multiband
8-83
Frequency and Magnitude Specifications Region:
Multiband
Select theunits for frequency specifications fromtheFrequency units list:
Hz
kHz
MHz
Normalized (0to 1), where1 corresponds totheNyquist frequency
For all units except Normalized, specify thesamplingfrequency, Fs.
Specify thefollowingparameters in thetext boxes:
Freq. vector A vector definingthefrequency points at which theresponse
magnitudeis specified, in ascendingorder. Must havean even length the
sameas Mag. vector.
Mag. vector A vector definingtheresponsemagnitudes at thespecified
frequencies. Must havean even length thesameas Freq. vector.
Weight vector A vector definingtherelativeweight that should begiven
toeach frequency band. Must behalf thelength of Freq. vector.
Each frequency-magnitudepair specifies thejunction of twoadjacent
frequency bands. SeeMultiband FI R Filter Design with Transition Bands
and r emez for moreinformation.
8 Filter Design and Analysis Tool Reference
8-84
Frequency and Magnitude Specifications Region:
Arbitrary Magnitude
Select theunits for frequency specifications fromtheFrequency units list:
Hz
kHz
MHz
Normalized (0to 1), where1 corresponds totheNyquist frequency
For all units except Normalized, specify thesamplingfrequency, Fs.
Specify thefollowingparameters in thetext boxes:
Freq. vector A vector definingthefrequency points at which theresponse
magnitudeis specified, in ascendingorder. Must havean even length the
sameas Mag. vector.
Mag. vector A vector definingtheresponsemagnitudes at thespecified
frequencies. Must havean even length thesameas Freq. vector.
Weight vector A vector definingtherelativeweight that should begiven
toeach frequency band. Must behalf thelength of Freq. vector.
Each frequency-magnitudepair specifies thejunction of twoadjacent
frequency bands. Seer emez for moreinformation.
Frequency and Magnitude Specifications Region: Arbitrary Group Delay
8-85
Frequency and Magnitude Specifications Region:
Arbitrary Group Delay
Select theunits for frequency specifications fromtheFrequency units list:
Hz
kHz
MHz
Normalized (0to 1), where1 corresponds totheNyquist frequency
For all units except Normalized, specify thesamplingfrequency, Fs.
Specify thefollowingparameters in thetext boxes:
Freq. vector A vector definingthefrequency points at which theresponse
group delay is specified, in ascendingorder. Must havethesamelength as
Grp. Delay vector.
Freq. edges A vector definingtheband-edgefrequencies on theboundary
betweencareanddont careregions, in ascendingorder. TheFreq. edges
vector contains a subset of thepoints in theFreq. vector vector.
Grp. Delay vector A vector definingtheresponsegroup delay in samples
at thespecified frequencies. Must havethesamelength as Freq. vector.
Weight vector A vector definingtherelativeweight that should begiven
toeach frequency-group delay pair. Must havethesamelength as
Freq. vector.
Max poleradius A scalar in therange[0 1] specifyingthemaximum
allowablemagnitudefor any pole.
TheArbitrary Group Delay filter typeis availableonly when theFilter
Design Toolbox is installed. Seei i r gr pdel ay in theFilter Design Toolbox
documentation for moreinformation.
8 Filter Design and Analysis Tool Reference
8-86
Filter Order Region
Select a radiobutton tocomputeoneof thefollowing:
Filter of theorder you specify (Specify order)
Minimumorder filter (Minimumorder). Thecomputed filter has the
minimumorder estimated tomeet thespecifications.
For certain menu choices in theDesign Method region, only oneof theabove
order options is available.
For arbitrary magnitudeI I R filters (Filter Typeset to Arbitrary Magnitude
and Design Method set toIIR), independently specify thefollowing:
Order of thetransfer function numerator (Numerator order)
Order of thetransfer function denominator (Denominator order)
Window Specification Region
8-87
Window Specification Region
This region allows you tospecify thewindowtypetobeused when Windowis
selected fromtheFIR menu in theDesign Method region. Theoptions are:
Chebyshev (chebwi n)
Bartlett (bar t l et t )
Blackman (bl ackman)
Boxcar (boxcar )
Hamming(hammi ng)
Hann (hann)
Kaiser (kai ser )
Triangular (t r i ang)
When Chebyshev or Kaiser areselected, thesecondary Parameter field
allows you tospecify theChebyshev stopband ripplemagnitude(in dB) or the
Kaiser parameter, respectively. Seechebwi n and kai ser for more
information.
8 Filter Design and Analysis Tool Reference
8-88
Import Filter Tab
Select theImport Filter tab(or press Ctrl+I) toimport filter coefficients from
theMATLAB workspace, or toenter thefilter coefficients directly.
Import Filter Coefficients Region
8-89
Import Filter Coefficients Region
This region allows you toimport a filter by specifyingthefilter coefficients,
either by enteringthemexplicitly, or by referringtovariables in theMATLAB
workspace. (Access this region by selecting Import Filter fromtheFilter
menu.)
Select thedesired filter representation fromtheFilter Structuremenu:
Direct formI
Direct formII
Direct formI transposed
Direct formII transposed
Direct formII (Second-order sections)
State-space
Latticeallpass
LatticeMA min. phase
LatticeMA max. phase
LatticeARMA
Quantizedfilter (Qfilt object) availableonlywhen Filter Design Toolbox
is installed
Thestructurethat you choosedetermines thetypeof coefficients that you need
tospecify in thetext fields totheright. Followthelinks abovetolearn more
about specifyingthecoefficients.
Select thefrequencyunitsfromamongthefollowingoptionsintheUnitsmenu:
Hz (default)
kHz
MHz
Normalized (0to 1)
For Hz, kHz, and MHz, specify thevalueof thesamplingfrequency in theFs
field.
8 Filter Design and Analysis Tool Reference
8-90
Import Filter Coefficients: Direct Form
Specify theNumerator and Denominator polynomial coefficients usingany
valid MATLAB variableor expression. SeeFilter Structuresfor more
information.
Press Clear toerasethecoefficients.
Import Filter Coefficients: Direct FormII (Second-Order Sections)
8-91
Import Filter Coefficients:
Direct Form II (Second-Order Sections)
Specify theGain and SOS Matrix usingany valid MATLAB variableor
expression. SeeFilter Structuresfor moreinformation.
Press Clear toerasethecoefficients.
8 Filter Design and Analysis Tool Reference
8-92
Import Filter Coefficients: State-Space
Specify theA, B, C, and D matrices usingany valid MATLAB variableor
expression. SeeFilter Structures for moreinformation.
Press Clear toerasethematrices.
Import Filter Coefficients: Lattice
8-93
Import Filter Coefficients: Lattice
Specify theLatticecoeff and Ladder coeff coefficients usingany valid
MATLAB variableor expression. SeeFilter Structuresfor moreinformation.
Press Clear toerasethecoefficients.
8 Filter Design and Analysis Tool Reference
8-94
Import Filter Coefficients: Quantized Filter (Qfilt Object)
Specify a Qfilt object. Seeqf i l t in theFilter Design Toolbox for more
information.
Press Clear toerasethedata.
Design Filter Tab
8-95
Design Filter Tab
Select theDesign Filter tab (or press Ctrl+D) todesign a filter by specifying
thefilter requirements.
8 Filter Design and Analysis Tool Reference
8-96
Import Filter Button
Select this button toimport filter coefficients whilein theimport mode.
Design Filter Button
8-97
Design Filter Button
Select this button todesign thefilter that you specified in theGUI .
8 Filter Design and Analysis Tool Reference
8-98
I-1
Index
A
A/D conversion 7-437
abs 7-16
ac2pol y 7-17
ac2r c 7-18
aliased sinc functions 1-13
command for 7-128
aliasing
impulseinvariance2-42
preventing4-22
reducing4-39
all-polefilters. SeeI I R filters
all-zerofilters. SeeFI R filters
am4-30
AM. Seeamplitudemodulation
amdsbsc 4-30, 7-264
amdsbt c 4-30, 7-264
amplitudedemodulation
doubleside-band, suppressed carrier 7-125
doubleside-band, transmitted carrier 7-125
singleside-band 7-125
amplitudemodulation 4-30
doubleside-band, suppressed carrier 7-264
doubleside-band, transmitted carrier 7-264
quadrature4-31
singleside-band 7-264
amssb 4-31, 7-264
analogfilters 2-39
bandpass 7-247
bandstop 7-250
Bessel 2-12, 2-39, 7-26, 7-27
bilinear transformation 2-43
Butterworth 2-9, 2-39, 7-48, 7-49, 7-50
Chebyshev 2-39
Chebyshev typeI 2-10, 7-62, 7-75
Chebyshev typeI I 2-11, 7-81
convertingtodigital 2-42, 7-215
design 2-8
discretization 2-42
elliptic 2-39, 7-136
frequency response1-27, 2-13, 7-185
highpass 7-252
impulseinvariance2-42
inverse7-226
lowpass 7-254
order estimation
Butterworth 7-55
Chebyshev typeI 7-64, 7-69
Chebyshev typeI I 7-69
elliptic 7-144
plotting2-13
representational models 1-42
SeealsoI I R filters
analogfrequency 29
analogsignals. Seesignals
analytic signals 7-207
angl e 7-19
anti-symmetric filters 2-26
AR filters, stability check 7-316
AR models. Seeautoregressive(AR) models
ar bur g 4-12, 7-20
ar cov 4-12, 7-21
ARMA filters 1-16, 4-14, 4-16
Pronys method 4-14
Steiglitz-McBridemethod 4-16
SeealsoI I R filters
ar mcov 4-12, 7-22
ARX models 4-14
ar yul e 4-12, 7-23
ASCI I files, importing1-14
autocorrelation 7-314, 7-448
autocorrelation sequences
convertingfromreflection coefficients 7-341
Index
I-2
estimation, variance3-4
filter coefficients
convertingtoand from7-17, 7-18, 7-314
filters, multiplechannels 3-5
two-dimensional 7-451
autocovariance7-452
multiplechannels 3-5
autoregressive(AR) models 1-16
Burgmethod 7-20, 7-267, 7-271
covariancemethod 7-21, 7-273
modified covariancemethod 7-22, 7-293,
7-297
Yule-Walker AR method 7-23, 7-335, 7-339
SeealsoI I R filters
autoregressivemovingaverage(ARMA) filters.
SeeARMA filters
averagingfilters 1-15
axis labels 6-50
axis parameters
Filter Viewer 6-50
SpectrumViewer 6-50
B
band edges, prewarping2-44
bandlimited interpolation 7-382
bandpass filters 7-55, 7-64, 7-69, 7-144
Bessel 7-27
Butterworth 7-49
Chebyshev typeI 7-75, 7-77
Chebyshev typeI I 7-80
design 2-7
elliptic 7-136
example, Chebyshev typeI 2-40
FI R 2-22, 7-167
impulseinvariance2-42
transformation fromlowpass to7-247
bandstop filters 2-7, 7-55, 7-64, 7-69, 7-144
Bessel 7-27
Butterworth 7-50
Chebyshev typeI 7-76
Chebyshev typeI I 7-80
elliptic 7-137
FI R 2-22, 7-166
transformation fromlowpass to7-250
bandwidth 2-41
bar t l et t 4-3, 7-24
example4-3
t r i ang, comparison to7-24
Bartlett windows 4-3
coefficients 7-24
Bessel filters 2-12, 2-39, 7-26
bandpass 7-27
bandstop 7-27
characteristics 2-12
highpass 7-27
limitations 7-29
lowpass 7-27
roots 7-26
bessel ap 2-6, 7-26
example2-12
bessel f 2-6, 2-7, 7-27
bias
correlation 3-4, 4-13
power spectral density 3-17, 3-18, 3-23
variancetrade-off 3-4
bi l i near 2-6, 2-42, 2-43, 7-31
bilinear transformations 2-43, 2-44, 7-31
output representation 7-32
prewarping2-44, 7-31
bl ackman 4-3, 7-36
Blackman windows 4-5, 7-36
boxcar 4-3, 7-38
example4-3
Index
I-3
boxcar windows. Seerectangular windows
brackets, indicatingclosed interval 29
buffering7-39
Burgmethod 3-8, 3-9, 3-33
example3-34
Welchs method, comparison 3-35
but t ap 2-6, 7-48
example2-9
but t er 2-6, 2-7, 7-49
Butterworth filters 2-9, 2-39, 7-48
bandpass 7-49
bandstop 7-50
characteristics 2-9
design 7-49
generalized 2-15
highpass 7-50
limitations 7-53
lowpass 7-49
order estimation 2-8, 7-54
but t or d 2-6, 7-54
C
canonical forms 1-18, 7-423
carrier frequency 4-30, 7-264, 7-445
carrier signals 4-30, 7-125
cascade, filters 1-38
Cauer filters. Seeelliptic filters
cceps 4-24, 4-26, 7-59
example4-24
cel l 2sos 7-61
center frequency 2-41
central features 1-2
cepstrum
analysis 4-24
applications 4-24
complex 4-24
inverse4-24, 4-26
overview4-24
real 4-24, 4-25, 7-346
reconstructingsignals (minimum-phase) 4-26
cheb1ap 2-6, 7-62
example2-10, 2-40
cheb1or d 2-6, 7-63
cheb2ap 2-6, 7-67
example2-11
cheb2or d 2-6, 7-68
chebwi n 4-3, 7-73, 7-98
cheby1 2-6, 2-7, 7-75
example2-45
cheby2 2-6, 2-7, 7-80
Chebyshev error minimization 2-23, 7-348
Chebyshev typeI filters 2-10, 2-39, 7-62, 7-75
bandpass 7-75, 7-77
bandstop 7-76
characteristics 2-10
design 7-75
highpass 7-76
lowpass 7-75
order estimation 2-8, 7-63
Chebyshev typeI I filters 2-39, 7-80
bandpass 7-80
bandstop 7-80
characteristics 2-11
highpass 7-80
limitations 7-79
lowpass 7-80
order estimation 2-8
Chebyshev windows 4-9, 7-73
frequency response4-9
chi r p 1-10, 7-85
chirp signals 1-10
chirp z-transforms (CZT) 4-35, 7-116
discreteFourier transforms, comparison 4-35
Index
I-4
frequency analysis, narrowband 7-116
coding, PCM 7-437
coefficients
correlation 7-97
filter 1-16, 6-38, 7-17, 7-314, 7-316, 7-344
linear prediction 7-256
reflection 1-38, 7-18, 7-316, 7-341, 7-344
sequence7-341
coher e 3-9, 3-29, 7-88
linearly dependent data 3-30
coherence3-29, 7-88
linearly dependent data 3-30
colors, SPTool 6-50
communications 4-11, 4-30, 7-264
Seealsomodulation, demodulation, voltage
controlled oscillation
communications simulation 7-125
compact disc standards 4-21
compaction 4-38
complex conjugate7-102
complex envelope. SeeHilbert transforms
complex numbers, groupingby conjugate7-102
confidenceintervals
cross spectral density 3-27
power spectral density 3-27
warnings 3-27
context-sensitivehelp 5-6, 6-17
continuous signals. Seesignals
continuous-timefilters. Seeanalogfilters
control systems 1-36
Control Systems Toolbox 1-36, 7-219, 7-411
conv 1-15, 1-21, 7-92
conv2 1-15, 7-93
conventions in our documentation (table) 30
conversions
autocorrelation sequences toand fromfilter
coefficients 7-17
autocorrelation sequences toandfromreflection
coefficients 7-18
filter coefficients toautocorrelation sequences
7-314
filter coefficients toreflection coefficients 7-316,
7-344
functions (table) 1-43
reflection coefficients toautocorrelation
sequences 7-341
second-order section forms tostate-spaceforms
7-385
second-order section forms totransfer functions
7-387
second-order section forms tozero-pole-gain
forms 7-389
state-spaceforms tosecond-order section forms
7-403
state-spaceforms tozero-pole-gain forms 7-409
transfer functions tolatticeforms 7-417
transfer functions tosecond-order section forms
7-418
transfer functions tostate-spaceforms 7-422
zero-pole-gain forms tosecond-order section
forms 7-458
zero-pole-gain forms tostate-spaceforms 7-462
convmt x 1-41, 1-43, 7-95
convolution 7-92
cross-correlation 3-3
example1-15
filtering1-15, 7-161
matrices for 1-41, 1-43, 7-95
example7-95
two-dimensional 7-93
cor r coef 7-97
correlation 3-2
bias 3-4, 4-13
coefficient matrices 7-97
Index
I-5
cross-correlation 7-447
matrices
covariancemethod 7-98
modified covariancemethod 7-98
Seealsoautocorrelation sequences,
cross-correlation sequences
correlation matrices 7-98
cor r mt x 7-98
cosinewindows 4-5
cov 7-101
covariance3-2
matrices 7-101
Seealsoautocovariance, cross-covariance
covariancemethod 3-9, 3-36, 7-277
example3-36
Seealsomodified covariancemethod
cpl xpai r 7-102
cr emez 2-17, 7-103
cross spectral density 3-27, 7-111
confidenceintervals 3-27
Seealsopower spectral density, spectral
estimation
cross-correlation sequences 3-3
estimation 7-447
biased 3-4
unbiased 3-4
filters, multiplechannels 3-5
normalization 3-5
two-dimensional 7-451
cross-covariance3-3, 7-452
multiplechannels 3-5
csd 3-9, 3-27, 7-111
cutoff frequency 2-39, 7-27
czt 4-36, 7-116
CZT. Seechirp z-transforms
D
D.C. component suppression 1-47
data
multichannel 1-5, 1-8
vectors 1-7
data compression 4-11
data matrices 1-5, 1-8
data vectors 1-5
dct 4-37, 7-119
example4-38
deci mat e 7-121
decimation 7-121
FI R filter for 7-223
decoding7-434
deconv 4-34, 7-124
example4-34
deconvolution 4-34, 7-124
default session file6-50
delays
group 1-29
noninteger 2-27
phase1-29
signals 2-27
demod 4-30, 4-31, 7-125
example4-31
demodulation 4-31, 7-125
amplitude, quadrature7-126
example4-31
methods 4-31, 7-125
phase7-126
pulsetime7-126
pulsewidth 7-126
DFT. SeediscreteFourier transforms
df t mt x 7-127
differenceequations 1-33
differentiators 2-27, 7-179, 7-350
digital audiotapestandards 4-21
Index
I-6
digital filters
anti-causal 1-21
Butterworth 7-49
cascade1-38
Chebyshev typeI 7-75
Chebyshev typeI I 7-80
coefficients 1-16
convolution matrices 1-41
design 2-3
elliptic 7-136
FI R 2-17
I I R, comparison to2-17
fixed-point implementation 1-38
frequency data, identification from7-230
frequency response1-25
group delay 1-29, 7-200
I I R 2-5
FI R filters, comparison to2-5
implementation 1-15, 7-155, 7-158
convolution 1-15
FFT-based (FI R) 7-155
f i l t er 1-17
overlap-add method 1-23
impulseresponse1-15, 1-24, 7-217
initial conditions 1-18
linear models 1-33
models 1-33
names 1-16
order 1-16
state-spacerepresentation 1-35
order estimation
Butterworth 7-54, 7-63, 7-68
Chebyshev typeI 7-63, 7-68
Chebyshev typeI I 7-68
elliptic 7-143
equirippleFI R 7-356
phasedelays 1-29, 7-200
poles 1-31, 1-34
second-order sections 1-38
specifications 2-8
startup transients 1-22
structures
lattice/ladder 1-38
transposed direct formI I 1-18
time-domain representation 1-17
transfer functions representation 1-16
transients 1-23
two-dimensional 7-161
zero-phase1-21, 7-162
zeros 1-31, 1-34
SeealsoFI R filters, I I R filters
digital frequency 29
direct design 2-6
di r i c 7-128
Dirichlet functions 1-13
command for 7-128
discretecosinetransforms (DCT) 7-119
applications 4-37
energy compaction property 4-38
example4-38
inverse4-37, 7-211
signals, reconstructing4-38
discreteFourier transforms (DFT) 1-3, 1-45, 2-27,
7-151
algorithms 1-46
applications 7-151
eigenvector equivalent 3-38
example1-46
I I R filter implementation 1-23
inverse1-45, 7-213
matrices 7-127
two-dimensional 1-47, 7-214
magnitude1-46
matrices 7-127
Index
I-7
phase1-46
signal length dependencies 1-46
spectral analysis 3-6, 3-10
time-dependent 4-28
two-dimensional 1-47, 7-154
Seealsofast Fourier transforms (FFT), f f t
discreteprolatespheroidal sequences
See DPSS
discretization 7-215
bilinear transformations 2-43
prewarping2-44
impulseinvariance2-42
discretization, filters 2-42
disk, loadingvariables from6-47
division, polynomials 7-124
DPSS
direct method 7-130
interpolation 7-129
dpss 7-129
dpss. mat 3-26
dpsscl ear 3-26, 7-132
dpssdi r 3-26, 7-133
dpssl oad 3-26, 7-134
dpsssave 3-26, 7-135
duty cycles 1-9
E
echoes, detection 4-24
edgeeffects 1-23
eigenanalysis 3-37
frequency estimation 3-37
eigenvector method 3-8, 3-36, 7-279
root MUSI C 7-368
Seealsomultiplesignal classification method
el l i p 2-6, 2-7, 7-136
el l i pap 2-6, 7-142
example2-11
el l i por d 2-6, 7-143, 7-148
elliptic filters 2-39, 7-136
bandpass 7-136
bandstop 7-137
characteristics 2-11
highpass 7-137
limitations 7-140
lowpass 7-136
order estimation 2-8, 7-143, 7-148
encoding
PCM 7-437
uniform7-437
eqt f l engt h 7-148
equiripplecharacteristics
Chebyshev typeI filters (passband) 2-10
Chebyshev typeI I filters (stopband) 2-11
Chebyshev windows 4-9
elliptic filters 2-11, 7-136, 7-142
Parks-McClellan design 7-348
equiripplefilters 2-23
error minimization
desired and actual response, between 2-23
frequency bands, weighting2-26
minimax 2-23
estimation
cross spectral density 3-27
nonparametric
multiplesignal classification method
(MUSI C) 3-8
multitaper method (MTM) 3-8
Welchs method 3-8
parametric 3-8
Burgmethod 7-20
covariancemethod 7-21
modified covariancemethod 7-22
Yule-Walker method 7-23
Index
I-8
spectral density 3-8, 3-10
transfer functions 3-28
Seealsoparametric modeling
F
fast Fourier transforms (FFT) 1-23, 1-45
f f t 1-23
frequency response1-25
radix-2 algorithm7-153
signal processing, rolein 1-45
two-dimensional 7-154
f dat ool 5-1
context-sensitivehelp 5-6
help on 5-6, 6-17
opening5-5
f f t 1-3, 1-23, 1-45, 7-151
example1-46
execution time1-46
number of samples 1-46
output 1-47, 7-157
radix-2 algorithm7-153
FFT filtering1-23
FFT. Seefast Fourier transforms
f f t 2 1-47, 7-154
output 1-47
f f t f i l t 1-20, 7-155
f i l t er , comparison to7-155
f f t shi f t 1-47, 1-47, 7-157
filter
coefficients 1-16
median 4-29
order 1-16
f i l t er 1-3, 1-17, 1-21, 7-158
f f t f i l t , comparison to7-155
f i l t f i l t , comparison 1-22
final condition parameters 1-18
implementation 1-18
initial condition parameters 1-18
initial conditions 7-163
filter coefficients
reflection coefficients, conversions to7-316,
7-344
filter design graphical user interface. Seef dat ool
filter design GUI 5-2
analysis buttons 5-13
analysis functions 5-13
computingcoefficients 5-12
context-sensitivehelp 5-6
design methods 5-8
design sessions
opening5-21
saving5-21
exportingfilters 5-19
filter design specification 5-9
filter order specification 5-11
filter type5-7
filters
architecture5-14
implementation 5-14
realization 5-14
structure5-14
frequency responsespecification 5-9
group delay 5-13
help on 5-6
importingcoefficients 5-16
importingfilters 5-16
impulseresponse5-13
magnituderesponse5-13
magnituderesponsespecs 5-10
opening5-5
phasedelay 5-13
phaseresponse5-13
pole-zeroplots 5-13
Index
I-9
savingcoefficients 5-19
step response5-13
Filter Designer 6-8, 7-397
FFT length 6-50
filter types 6-8
filters
editing6-45
redesigning6-37
saving6-33
FI R filters 6-8
FI R methods 6-8
grid lines 6-50
I I R methods 6-8
opening6-9, 6-22
overview6-8
plots
customizing6-50
magnitude6-37
Pole/ZeroEditor 6-34
samplefrequency 6-38
spectra, overlaying6-9
zooming6-50
filter parameters 6-50
Filter Viewer 6-11, 7-399
axis parameters 6-50
filter parameters 6-50
measurements 6-51
opening6-11
overview6-11
preferences, tiling6-50
printing6-28
rulers 6-51
zooming6-50
f i l t er 2 7-161
filters 1-3
analog2-9, 2-12, 7-26, 7-48, 7-62
anti-causal 1-21
anti-symmetric 2-26
averaging1-15
bandpass
Butterworth 7-54
Chebyshev typeI 7-63
Chebyshev typeI I 7-68
elliptic 7-143
bandstop
Butterworth 7-54
Chebyshev typeI 7-63
Chebyshev typeI I 7-68
elliptic 7-143
Butterworth 2-8, 7-49
generalized 2-15
Chebyshev 2-8
typeI 7-75
typeI I 7-80
coefficients 1-17, 1-33, 2-18, 6-38
convertingtoautocorrelation sequence
7-314
convolution 1-15
creating2-8
design 6-8
Filter Designer 6-8
FI R 2-23
generalized 2-6
discretization 2-42
elliptic 2-8, 7-136
equiripple2-23
FI R 7-348
singleband 2-21
frequency data, identification from7-226
frequency domain 1-23
frequency transformation functions 2-39, 2-40
highpass
Butterworth 7-54
Chebyshev typeI 7-63
Index
I-10
Chebyshev typeI I 7-68
elliptic 7-143
implementation 1-23, 7-155, 7-158
initial conditions 1-18, 1-19
inverse7-226, 7-230
lattice/ladder 1-38
linear phase2-17, 2-18
linear time-invariant digital 1-3
lowpass
Butterworth 7-54
Chebyshev typeI 7-63
Chebyshev typeI I 7-68
elliptic 7-143
measurements 6-51
median 7-263
minimax 2-23
minimumphase7-319
names 1-16
order 1-16, 2-8, 7-54, 7-63, 7-143, 7-148
order estimation 2-8
phase, modulation 4-26
prediction 4-13
quantized, statevectors 7-159
Savitzky-Golay 7-378, 7-380
Schur realizations 7-375
second-order section forms 1-38, 1-44, 7-391
specifications 2-8
SPTool 6-43
transposed direct formI I structure1-18
two-dimensional 7-161
types 2-18
zero-phase1-21, 7-162
SeealsoFI R filters, I I R filters, digital filters,
analogfilters
f i l t f i l t 1-20, 1-21, 2-5, 7-162
example1-21
f i l t er , comparison 1-22
initial conditions 1-22
f i l t i c 1-19, 7-163
FI R filters 1-16, 2-17
decimation 7-223
differentiators 2-27, 7-179, 7-350
equiripple2-17, 2-23, 2-24
example6-18
Filter Designer 6-8
frequency domain 1-20
frequency response7-169
Hilbert transformers 2-26, 7-179, 7-350
I I R filters, comparison 2-17
implementation 1-18, 7-158
FFT-based 1-23, 7-155
overlap-add method 1-23, 7-155
interpolation 7-223
Kaiser windows 4-7
lattice/ladder 1-38
least squares 2-17, 2-24, 7-178
constrained 2-17, 2-28
equiripple, comparison 2-24
linear phase2-29
multiband 2-29, 2-30
weighted 2-31
linear phase2-18, 2-23, 7-178, 7-348
multiband 2-17, 2-22, 2-23
order estimation, r emez 7-356
overlap-add method 7-155
Parks-McClellan method 2-23, 7-348
raised cosinemethod 2-17
resampling1-20
responses 2-32
complex filters 2-17, 7-103
delays, reducing2-35
nonlinear phase2-17, 7-103
standard band 2-21
types 7-181, 7-353
Index
I-11
windowingmethod 2-17
windows 2-19, 7-165
f i r 1 2-17, 2-21
f i r 2 2-17, 2-21
f i r cl s 2-17, 7-172
f i r cl s1 2-17, 7-175
f i r l s 2-17, 2-23, 7-178
differentiators 2-27
filter characteristics 7-181
r emez, comparison to2-24
weight vectors 2-26
f i r r cos 2-17, 7-183
fixed-point implementation, digital filters 1-38
f m4-31
FM. Seefrequency modulation
f open 1-14
Fourier transforms. SeediscreteFourier
transforms, fast Fourier transforms
f r ead 1-14
f r eqs 1-27, 7-185
f r eqspace 7-188
frequency 7-349
analog29
angular 2-3
carrier 4-30, 7-264, 7-445
center 2-41
cutoff 2-39
digital 29
estimation
eigenanalysis 3-37
eigenvector (EV) method 3-37
multiplesignal classification (MUSI C)
method 3-37
normalization 2-3
Nyquist 29, 2-3
prewarping7-31
vectors 2-25, 7-169, 7-172, 7-455
frequency analysis, time-dependent 7-392
frequency demodulation 7-126
frequency domain
duality with time-domain 1-23
filters 1-23
FI R filtering1-20
transformation functions 2-39, 7-247, 7-250,
7-252, 7-254
example2-41
lowpass tobandpass 7-247
lowpass tobandstop 7-250
lowpass tohighpass 7-252
frequencydomainbasedmodeling. Seeparametric
modeling
frequency modulation 7-265
frequency response1-25, 2-14, 7-169
Bessel filters 2-12
Butterworth filters 2-9
Chebyshev typeI filters 2-10
Chebyshev typeI I filters 2-11
Chebyshev windows 4-9
elliptic filters 2-11
error minimization 2-23
evaluating1-25
example1-26
inverse7-226
Kaiser window4-6
linear phase2-18
magnitude1-27
monotonic 2-9
multiband 2-14
phase1-27
unwrapping1-28
plotting1-26, 7-193
samples, spacing7-188
samplingfrequency 1-25
frequency vectors 7-349
Index
I-12
f r eqz 1-25, 7-189
samplingfrequencies 1-25
samplingfrequency 1-25
spacing7-188
f r eqzpl ot 7-193
FromDisk radiobutton 6-47
f scanf 1-14
G
gains, scalar 1-34
gauspul s 1-10, 1-11, 7-196, 7-198, 7-199
Gauss-Newton method 7-229, 7-232
generalized Butterworth filters 2-15
generalized cosinewindows 4-5
generalized filters 2-6
Gibbs effect 2-20
reduced by window4-3
graphical user interface(GUI ) 1-4
Seealsointeractivetools, SPTool
grid lines 6-50
group delay 1-29, 2-18, 7-200
example1-30
passband 2-12
gr pdel ay 1-29, 7-200
GUI -based tools. Seeinteractivetools
H
hammi ng 4-3, 7-203
Hammingwindows 2-20, 3-18, 4-5, 7-203
hann 7-205
Hann windows 7-205
Hanningwindows 4-5, 7-205
hanni ng. Seehann
highpass filters 2-7, 7-55, 7-64, 7-69, 7-144
Bessel 7-27
Butterworth 7-50
Chebyshev typeI 7-76
Chebyshev typeI I 7-80
elliptic 7-137
FI R 2-22, 7-167
lowpass, transformation from7-252
hi l ber t 2-27, 4-39
example4-39
Hilbert transformers 7-179, 7-350
Hilbert transforms 4-35, 4-39, 7-207
analytic signals, of 2-27
example4-39
instantaneous attributes 4-40
homomorphic systems 4-24
Hz 7-268, 7-274, 7-294, 7-336
I
i cceps 4-24, 4-26, 7-210
example4-27
i dct 4-37, 7-211
ideal lowpass filters 2-19
Seealsolowpass filters
i f f t 1-45, 7-213
samples, specifying1-47
i f f t 2 1-47, 1-47, 7-214
I I R filters 2-5, 2-6, 2-8, 2-9, 2-14
Bessel 2-12
Butterworth 2-8, 2-9
Butterworth, generalized 2-15
Chebyshev 2-8, 2-10, 2-11
Chebyshev typeI 2-10
Chebyshev typeI I 2-11
design 2-7, 2-38
elliptic 2-8, 2-11
Filter Designer 6-8
filter types, comparison 2-9
Index
I-13
FI R filters, comparison to2-5
frequency response2-14
implementation 7-158
frequency domain 1-23
zero-phase1-21
lattice/ladder 1-38
Levinson-Durbin recursion 7-245
maximally flat 2-15
multiband 2-14
order estimation 2-8
plottingresponses 2-13
Pronys method 7-320
specifications 2-8
Steiglitz-McBrideiteration 7-412
Yule-Walker 2-14, 7-455
Seealsodirect design
imageprocessing1-47, 7-93
i mpi nvar 2-6, 2-42, 7-215
I mport dialogbox
FromDisk radiobutton 6-47
WorkspaceContents list 6-19
impulseinvariance2-42, 7-215
limitations 2-42
impulseresponse1-24, 7-217
computingwith f i l t er 1-24
computingwith i mpz 1-24
example1-24
impulseinvariance2-42
lowpass filters, ideal 2-19
i mpz 7-217
example1-24
indexing1-16
initial conditions 1-18, 1-19, 1-22, 7-163
instantaneous attributes 4-40
interactivetools 1-4, 6-3
example6-18
Filter Design and Analysis Tool 5-2
Filter Designer 6-8, 7-397
Filter Viewer 7-399
Signal Browser 7-397
SpectrumViewer 6-14, 7-400
SPTool 7-396
i nt er p 7-220
interpolation 7-220
bandlimited 7-382
FI R filters 7-223
interval notation 29
i nt f i l t 7-223
inversecepstrum, complex 4-26
inversediscretecosinetransforms 7-211
accuracy of signal reconstruction 4-39
inversediscreteFourier transforms 1-45, 7-213
i f f t 1-45
matrices 7-127
two-dimensional 1-47, 7-214
inversefilters 7-230, 7-320
analog7-226
digital 7-230
inverseFourier transforms, continuous. Seesi nc
inverse-sineparameters
reflection coefficients, transformations from
7-233
reflection coefficients, transformations to
7-342
i nvf r eqs 2-6, 4-12, 4-18, 7-226
i nvf r eqz 2-6, 4-12, 4-18, 7-230
i s2r c 7-233
K
kai ser 4-3, 7-234
example4-6
Kaiser window3-20
Kaiser windows 4-5, 7-234
Index
I-14
beta parameter 4-5, 7-234
example4-6
FI R filters 4-7
frequency response4-6
kai ser or d 2-17, 7-236
L
ladder filters. Seelattice/ladder filters
Lagrangeinterpolation filter 7-223
Laplacetransforms 1-42
state-spaceforms 1-42
l ar 2r c 7-241
l at c2t f 1-41, 1-43, 7-242
l at cf i l t 1-20, 1-41, 7-243
lattice/ladder filters 1-38, 1-39, 1-43
coefficients 1-39
l at cf i l t 1-41
Schur algorithm7-375
transfer functions, conversions from7-417
least squares method, FI R filters 7-178, 7-181
l evi nson 4-12, 7-245, 7-365
parametric modeling4-13
Levinson-Durbin recursion 4-13, 7-245, 7-365
linespectral frequencies
prediction polynomial coefficients,
transformation from7-315
prediction polynomial coefficients,
transformation to7-260
linestyle, SPTool 6-50
linear models. Seemodels
linear phase2-17, 2-18, 7-178
characteristics 2-18
filters 7-348
linear prediction coefficients 7-256
linear prediction modeling4-13
linear predictivecoding4-13
linear systemtransformations. Seeconversions
l oad 1-14
logarea ration parameters
reflection coefficients, transformations from
7-241
reflection coefficients, transformations to7-343
lowpass filters 2-7, 7-55, 7-64, 7-69, 7-144
Bessel 7-27
Butterworth 7-49
Chebyshev typeI 7-75
Chebyshev typeI I 7-80
cutoff frequency, translation of 7-254
decimation 7-121
elliptic 7-136
FI R 2-22
ideal 2-19
impulseinvariance2-42
impulseresponse2-19
interpolation 7-220
l p2bp 2-6, 2-40, 7-247
example2-41
l p2bs 2-6, 2-40, 7-250
l p2hp 2-6, 2-40, 7-252
l p2l p 2-6, 2-40, 7-254
l pc 2-6, 4-12, 7-256
Seealsolinear predictivecoding, Pronys
method
LPC. Seelinear prediction coefficients
l sf 2pol y 7-260
M
magnitude
Fourier transforms 1-46
frequency response1-27
plots 6-37
transfer functions 3-28
Index
I-15
vectors 2-25, 7-169, 7-172, 7-455
manufacturing4-11
match frequency (for prewarping) 7-31
MAT-files
dpss. mat 3-26
format, convertingto1-14
importing1-14
SPTool 6-47
matrices
convolution 1-41, 7-95
correlation coefficient 7-97
covariance7-101
data 1-5, 1-8
discreteFourier transforms 7-127
inversediscreteFourier transforms 7-127
matrix forms. Seestate-spaceforms
maxf l at 2-6, 2-15, 7-261
maximally flat filters 2-15
medf i l t 1 4-29, 7-263
median filters 4-29, 7-263
MEX-files 1-14
M-files 1-4
minimax method, FI R filters 2-23
SeealsoParks-McClellan method
minimumphase7-319
models 1-33
autoregressive7-20, 7-21, 7-22, 7-23
Burgmethod 7-267, 7-271
covariancemethod 7-273
modified covariancemethod 7-293, 7-297
Yule-Walker AR method 7-335, 7-339
bilinear transformations 2-44
transformations, discrete/continuous 2-44
modified covariancemethod 3-36
example3-36
modul at e 4-30, 4-31, 7-264
example4-31
method flags 4-30
modulation 4-30, 7-264
amplitude4-30
Seealsoamplitudemodulation
example4-31
frequency 4-31
phase4-31
pulsetime4-31
pulsewidth 4-31
quadratureamplitude4-31
results of 4-31
signals 4-30, 7-264
movingaverage(MA) filters 1-16
SeealsoFI R filters
MTM. Seemultitaper method
multiband filters
FI R 2-22
FI R, with transition bands 2-23
I I R 2-14
multichannel data 1-8
multiplesignal classification method (MUSI C)
3-8, 3-9, 3-36, 7-305, 7-311
correlation matrices 7-98
eigenvector method 7-279, 7-284
root music 7-371
multiplication, polynomials 7-92
multiplicity, of zeros and poles 6-35
multiratefilters 1-20
banks 1-20
multitaper method (MTM) 3-8, 3-9, 3-24
averagepower, conservation of 3-26
example3-25
Welchs method, comparison to3-26
MUSI C algorithm. Seemultiplesignal
classification method
Index
I-16
N
nonrecursivefilters. SeeFI R filters
normalization 3-4
correlation 3-5, 7-447, 7-448
power spectral density 3-17, 3-18, 3-23
Nyquist frequency 29, 2-3, 7-136
Nyquist interval 7-136
O
order
estimation 2-8, 7-356
Butterworth 7-54
Chebyshev typeI 7-63
elliptic 7-143, 7-148
filters, of 1-16, 2-8
oscillators, voltagecontrolled 7-445
overlap-add method
FI R filter implementation 1-23
FI R filters 7-155
P
Panner check box, Signal Browser 6-50
parametric modeling4-11, 7-230
applications 4-11
frequency domain based 4-18
summary 2-6
techniques 4-11
time-domain based 4-13
Burgmethod 7-20
covariancemethod 7-21
linear predictivecoding4-13, 4-14
modified covariancemethod 7-22
Steiglitz-McBridemethod 4-16
Yule-Walker method 7-23
parentheses, indicatingopen interval 29
Parks-McClellan method 2-23, 7-348
partial fraction expansion 1-36, 1-42, 1-43, 7-362
determiningwith r esi due 1-42
example1-36
passband 7-54, 7-63, 7-68, 7-143
equiripple2-10, 2-11
group delay 2-12
pbur g 3-9, 3-34, 7-267
example3-34
PCM 7-437
pcov 3-9, 3-36, 7-273
example3-36
pei g 3-36
pei g 7-279
period, findingin a sequence7-376
periodic sinc functions 7-128
SeealsoDirichlet functions
per i odogr am7-287
periodograms 3-10, 7-287, 7-291
phase
computing7-19
delays 1-29, 2-18, 7-200
example1-30
demodulation 7-126
distortion
eliminating1-20, 1-21
FI R filters 1-21
I I R filters 1-21
Fourier transforms 1-46
frequency response1-27
modulation 4-31, 7-265
filters 4-26
transfer functions, of 3-28
unwrapping1-28, 7-440
plots
analogfilters 2-13
cepstrum, complex 4-25
Index
I-17
coherencefunction 3-29
DFT 1-46
frequency response1-26
functions for 7-322
group delay 1-30
magnitude1-27, 6-37
phase1-27
delays 1-30
strip plots 7-415
transfer functions 3-28
zero-pole1-31, 7-466
plottingfunctions 7-193
plug-ins 6-50
pm4-31
pmcov 3-9, 3-36, 7-293
example3-36
p-model. Seeparametric modeling
pmt m3-9, 7-299
example3-25
pmusi c 3-9, 3-36, 7-305
Pole/ZeroEditor 6-34
pole-zerofilters. SeeI I R filters
pol y 1-34, 1-43
pol y2ac 7-314
pol y2l sf 7-315
pol y2r c 7-316
polynomials
division 4-34, 7-124
multiplication 7-92
roots 1-34, 1-43
scaling7-319
stability check 7-316
stabilization 7-318
polyphasefilteringtechniques 1-20
pol yst ab 7-318, 7-319
power spectral density 3-6
bias 3-17, 3-18, 3-23
confidenceintervals 3-27
estimation
Burgmethod 3-9, 3-33, 7-267
covariancemethod 3-9, 3-36, 7-273
modified covariancemethod 3-9, 7-293
multitaper method 3-24, 7-299
MUSI C method 3-37, 7-305
root music 7-368, 7-371
Welchs method 3-9, 3-20, 3-23
Yule-Walker AR method 3-9, 3-32, 7-335
multitaper method 3-9
MUSI C method 3-9
normalization 3-17, 3-18, 3-23
plots 6-14
SpectrumViewer 6-14
SPTool 6-45
units of 3-7
prediction filters 4-13
prediction polynomials
linespectral frequencies, transformations from
7-260
linespectral frequencies, transformations to
7-315
Preferences menu item6-50
prewarping7-31
Print dialogbox 6-28, 6-31
Print Previewwindow
Signal Browser preferences 6-28
SpectrumViewer 6-31
printing, SpectrumViewer 6-51
prolate-spheroidal windows 4-5
pr ony 2-6, 4-12, 4-14, 7-320
Pronys method 4-14, 7-320
modeling4-14
psdpl ot 7-322
pseudospectrum7-311
eigenvector method 7-279, 7-284
Index
I-18
MUSI C algorithm7-311
pt m4-31
pulsetimedemodulation 7-126
pulsetimemodulation 4-31, 7-265
pulsetrain generator 7-324
pulsetrains
generating1-11
pul st r an 1-11
pulsewidth demodulation 7-126
pulsewidth modulation 4-31, 7-265
pul st r an 1-11, 7-324
pwel ch 3-9, 3-20, 7-328
pwm4-31
pyul ear 3-9, 3-32, 7-335
example3-33, 3-34
Q
qam4-31
quadratureamplitudedemodulation 7-126
quadratureamplitudemodulation 4-31, 7-265
quantization 7-434, 7-437
PCM 7-437
quantized filters 7-159
second-order sections
coefficients in a cell array 7-384
coefficients in a matrix 7-61
R
radar applications 4-28
raised cosinefilters 7-183
r andn 27
randomnumber, generation 27
rangenotation 29
r c2i s 7-342
r c2l ar 7-343
r c2pol y 7-344
r ceps 4-24, 4-26, 7-346
rebuffering7-39
rectangular windows 2-19, 4-3, 7-38
r ect pul s 7-347
recursivefilters. SeeI I R filters
references 1-48, 3-39, 4-41
reflection coefficients 1-38, 1-39
convertingtoautocorrelation sequence7-341
filter coefficients, conversions from7-316,
7-344
inversesineparameters, transformation from
7-342
inversesineparameters, transformation to
7-233
logarea ratioparameters, transformation from
7-343
logarea ratioparameters, transformation to
7-241
Schur algorithm7-375
r emez 2-17, 2-23, 7-348
differentiators 2-27
filter characteristics 7-353
f i r l s, comparison to2-24
Hilbert transformers 2-26
order estimation 7-356
weight vectors 2-26
Remez exchangealgorithm2-23, 7-348
r emezor d 2-17, 7-356
r esampl e 7-359
resampling4-21, 7-359
FI R filters 1-20
Seealsodecimation, interpolation
r esi due 1-42, 1-43, 1-43
residueforms. Seepartial fraction expansion
r esi duez 1-43, 7-362
r l evi nson 7-365
Index
I-19
root MUSI C 7-371
eigenvector method 7-368
r oot ei g 7-368
r oot musi c 7-371
roots 1-34, 1-43
polynomials 1-34
rulers
positioning6-51
Signal Browser 6-50
SpectrumViewer 6-50
S
samplingfrequency
changing
noninteger resamplingfactors 4-21, 7-359
with upf i r dn 1-20
decreasingby integer factor 7-121
FI R filters 1-20
f r eqz 1-27
increasing7-220
irregularly spaced data 4-23
Nyquist interval 7-136
range1-27
spacing1-27
savingdata
SpectrumViewer 6-42
Savitzky-Golay filters 7-378, 7-380
sawt oot h 1-9, 7-368, 7-374
sawtooth wave1-9
scaling7-318
schur 7-375
Schur algorithm7-375
schur r c 7-375
second-order section forms 1-38, 1-43
filters 7-391
matrices 1-38
SPTool 6-44
state-spaceforms, conversions from7-403
state-spaceforms, conversions to7-385
transfer functions, conversions from7-387,
7-418
zero-pole-gain forms, conversions from7-458
zero-pole-gain forms, conversions to7-389
second-order sections
coefficients in cell arrays 7-384
coefficients in matrices 7-61
seqper i od 7-376
sgol ay 7-378, 7-380
sgol ayf i l t 7-380
Signal Browser 6-6, 7-397
axis labels 6-50
markers, preferences 6-50
opening6-6
overview6-6
Panner, preferences 6-50
Print Previewwindow6-28
printing6-6, 6-26, 6-28, 6-51
signals, measuring6-51
zooming, preferences 6-50
Signal ProcessingToolbox 1-3
signals 2-27
addingnoise1-7
analytic 4-39, 7-207
aperiodic 1-10
applications 4-39
array 6-6
buffering7-39
carrier 4-30, 7-125
chirp 1-10
continuous (analog) 1-3
differentiators 2-27
di r i c 1-13
discrete(digital) 1-3
Index
I-20
generating1-8
linear swept-frequency cosine. Seechirp
measurements 6-51
modulation 4-30, 7-264
multichannel 3-5
periodic 1-9
plotting1-7
properties 4-39
pul st r an 1-11
rebuffering7-39
reconstruction
DCT coefficients, from4-38
minimumphase4-26, 7-346
representing1-5
multichannel 1-5
singlechannel 1-5
sawtooth 1-9, 7-374
example1-9
si nc 1-12
sinusoidal 1-7, 1-10
pulse, Gaussian-modulated 1-10
squarewave1-9, 7-402
triangle7-374
si nc 1-12, 7-382
bandlimited interpolation example7-382
sinc functions 1-12, 7-382
basic example1-12
Slepian sequences. Seediscreteprolate
spheroidal sequences
sonar applications 4-28
sos2cel l 7-384
sos2ss 1-43, 7-385
sos2t f 1-43, 7-387
sos2zp 1-43, 7-389
specgr am4-28, 7-392
example4-28, 7-445
specification lines. SeeFilter Designer
specifications, filters 2-8
spectra. Seespectrum
spectral analysis 3-6
cross spectral density 3-27
power spectrum3-6
SpectrumViewer 6-14
Seealsospectral estimation
spectral density 3-6
measurements 6-51
plottingfunctions 7-322
SpectrumViewer 6-14
units of 3-7
Seealsopower spectral density, cross spectral
density
spectral density plots 6-14
spectral estimation 3-10
Burgmethod 3-9, 3-33, 7-267, 7-268
covariancemethod 7-273, 7-277
eigenvector method 7-279, 7-280, 7-284
modified covariancemethod 3-9, 7-293
multitaper method 3-9, 7-299
MUSI C algorithm7-305, 7-311
MUSI C method 3-9, 7-306
nonparametric
multiplesignal classification method
(MUSI C) 3-8
multitaper method (MTM) 3-8
Welchs method 3-8
parametric
Burgmethod 7-20
covariancemethod 7-21
modified covariancemethod 7-22
Yule-Walker method 7-23
periodograms 7-291
root MUSI C 7-368, 7-371
Welchs method 3-8, 3-9, 3-20, 3-23, 3-27, 7-91,
7-113, 7-328, 7-332
Index
I-21
Yule-Walker AR method 2-14, 3-8, 3-9, 3-32,
3-33, 7-335, 7-336
spectrogram4-28, 7-392
example4-28, 7-445
SpectrumViewer 6-14, 7-400
activating6-14
axis parameters 6-50
markers, preferences 6-50
measurements 6-51
opening6-14
overview6-14
Print Preview6-31
printing6-14, 6-28, 6-51
rulers 6-51
spectra structures 6-42
spectral density plots 6-14
windows 6-15
zooming6-50
speech processing4-11, 4-22
spl i ne 4-23
SPTool 6-3, 7-396
colors, customizing6-50
context-sensitivehelp 6-17
customizing6-50
data
entering1-14
objects 6-48
selecting6-48
data structures 6-4
editing6-49
example6-18
exportingdata 1-14, 6-32
filter design 6-22
filtering6-24
filters 6-43
coefficients 6-38
importing6-21, 6-43
parameters 6-38
specifications 6-39
filters, saving6-33
help on 6-17
I mport dialog6-19
importing1-14, 6-19, 6-21, 6-43
items, selecting6-48
linestyle, customizing6-50
MAT-files 6-47
MATLAB workspace6-4
multiselection of items 6-48
operation 6-4
Pole/ZeroEditor 6-34
preferences 6-50
Preferences menu item6-50
Print dialogbox 6-28, 6-31
printing6-28
filters 6-28
spectra 6-28
right-click edit menu 6-49
rulers 6-51
samplefrequency 6-38
saving6-32
second-order section forms 6-44
Signal Browser 6-26
signals
analysis 6-26
measurements 6-51
playing6-27
sound 6-27
spectra
analyzing6-29
importing6-21
spectral densities
importing6-43, 6-45
plots 6-45
SpectrumViewer 6-29
Index
I-22
state-spaceforms 6-44
transfer functions
exporting6-38
specifying6-44
workspace6-4
zero-pole-gain forms 6-44
spt ool 7-396
squar e 1-9, 7-402
squarewave1-9
ss2sos 1-43, 7-403
ss2t f 1-43, 7-407
ss2zp 1-43, 7-409
stability check, polynomials 7-316
stabilization 7-319
standards, digital audiotape4-21
startup transients, reducing1-22, 7-162
statevectors 7-159
state-spaceforms 1-35, 1-42, 1-43
scalar 1-35
second-order section forms, conversions from
7-385
second-order section forms, conversions to
7-403
SPTool 6-44
transfer functions, conversions to7-422
zero-pole-gain forms, conversions from7-462
zero-pole-gain forms, convertions to7-409
statistical operations 3-3
Seealsoautocorrelation sequences,
cross-correlation sequences,
cross-covariance
Steiglitz-McBridemethod 4-16, 7-412
st mcb 2-6, 4-12, 4-16, 7-412
stopband 7-54, 7-63, 7-68, 7-143
equiripple2-11
strip plots 7-415
st r i ps 7-415
structures
lattice/ladder 1-38
transposed direct formI I 7-159
structures, digital filters
lattice/ladder 1-38
transposed direct formI I 1-18
swept-frequency cosinegenerator. Seechirp
systemidentification 4-14
systemmodels. Seemodels
T
tapers, PSD estimates 3-24
taps 2-18
t f 2l at c 1-39, 1-43, 7-417
t f 2ss 1-43, 7-422
t f 2zp 1-43, 7-409, 7-424
t f e 3-9, 3-28, 7-427
tilingpreferences 6-50
timeseries attributes 4-40
time-domain based modeling. Seeparametric
modeling
toolboxes
Control Systems Toolbox 1-36, 7-219, 7-411
I mageProcessingToolbox 7-120, 7-211, 7-263
Signal ProcessingToolbox 1-3
Symbolic Math Toolbox 7-26
SystemI dentification Toolbox 7-430
transfer functions 1-16, 1-33, 1-36, 1-43
coefficients 1-16, 6-38
estimation 7-427
usingWelchs method 3-28
factoring1-34
latticeforms, conversions to7-417
second-order section forms, conversions from
7-387
Index
I-23
second-order section forms, conversions to
7-418
SPTool 6-44
state-spaceforms, conversions to7-422
zero-pole-gain forms 1-34
transformations
bilinear 2-43, 7-31
discrete/continuous 2-44
frequency 2-39, 7-247, 7-250, 7-252, 7-254
models, between 1-43
transforms 4-35
chirp z-transforms (CZT) 4-35, 7-116
discretecosine7-119
discreteFourier 1-45, 7-151
Hilbert 4-39, 7-207
inversediscretecosine4-37, 7-211
inversediscreteFourier 7-213
transients, filters 1-23
transition band 2-23
transposed direct formI I 7-159
initial conditions 7-163
t r i ang 4-3, 7-431
bar t l et t , comparison to7-24
example4-3
triangular windows 7-431
t r i pul s 7-433
two-dimensional operations
discreteFourier transforms 1-47, 7-154
inversediscreteFourier transforms 1-47,
7-214
Seealsofilters, two-dimensional
two-dimensional signal processing1-47
U
udecode 7-434
uencode 7-437
uniformencoding7-437
unit circle7-319
unit impulsefunction 1-8
unit ramp function 1-8
unit sample, multichannel representation 1-8
unit step function 1-8
units of power spectral density (PSD) 3-7
unwr ap 1-28, 7-440
upf i r dn 1-20, 4-22, 7-441
V
variance, correlation sequenceestimate3-4
vco 4-30, 4-32, 7-445
vectors
data 1-5, 1-7
frequency 2-25, 7-169, 7-172, 7-349, 7-455
indexing29, 1-16
magnitude2-25, 7-169, 7-172, 7-455
weighting7-179
voltagecontrolled oscillators 4-32, 7-445
W
waveforms. Seesignals
Welchs method 3-9, 3-20
bias 3-23
Burgmethod, comparison to3-35
MTM method, comparison to3-26
normalization 3-23
power spectral density estimation 3-8, 3-23,
3-27, 7-91, 7-113, 7-332
systemidentification, nonparametric 3-28
Yule-Walker AR method, comparison to3-33
whitenoise1-7
windows
Bartlett 4-3, 7-24
Index
I-24
Blackman 4-5, 7-36
boxcar 2-19
Chebyshev 4-9, 7-73
cosine, generalized 4-5
filters 2-19
FI R filters 2-19
bandpass 7-165
bandstop 7-166
highpass 7-166
lowpass 7-165
multiband filters 2-22
singleband design 2-21
f i r 1 2-22
generalized cosine4-5
Hamming2-20, 3-18, 4-5, 7-203
Hann 7-205
Hanning4-5, 7-205
Kaiser 3-20, 4-5, 7-234
periodograms 3-12, 3-18
prolate-spheroidal 4-5
rectangular 2-19, 7-38
shapes 4-3
triangular 7-431
WorkspaceContents list 6-19
X
xcor r 3-3, 7-447
parametric modeling4-13
xcor r 2 7-451
xcov 3-3, 7-452
Y
yul ewal k 2-6, 2-14, 7-455
example2-14
Yule-Walker AR method 3-8, 3-9, 3-32, 7-455
example3-33, 3-34
Welchs method, comparison to3-33
Yule-Walker equations 2-14
Z
zerofrequency component, centering1-47
zero-order hold. Seeaveragingfilters
zero-phasefiltering7-162
zero-poleanalysis 7-466
zero-poleplots 1-31, 7-466
zero-pole-gain forms 1-34, 1-42, 1-43
example1-31
second-order section forms, conversions from
7-389
second-order section forms, conversions to
7-458
SPTool 6-44
state-spaceforms, conversions from7-409
state-spaceforms, conversions to7-462
zeros and poles
multiplicity of 6-35
transfer functions 1-34
zooming6-50
zp2sos 1-43, 7-458
zp2ss 1-43, 7-462
zp2t f 1-43, 7-464
zpl ane 1-31, 7-466
z-transforms 1-16, 1-33
chirp z-transforms (CZT) 4-35, 7-116
discreteFourier transforms 1-45, 7-151

You might also like