720
Computation Visualization Programming For Use with MATLAB ® User’s Guide Version 4.2 Signal Processing Toolbox

MATLAB Signal Processing Toolbox user manual

Embed Size (px)

DESCRIPTION

MATLAB Signal Processing Toolbox user manual

Citation preview

Page 1: MATLAB Signal Processing Toolbox user manual

Computation

Visualization

Programming

For Use with MATLAB®

User’s GuideVersion 4.2

Signal ProcessingToolbox

Page 2: MATLAB Signal Processing Toolbox user manual

How to Contact The MathWorks:

508-647-7000 Phone

508-647-7001 Fax

The MathWorks, Inc. Ma il24 Pr ime Park WayNat ick, MA 01760-1500

http://www.mathworks.com Webftp.mathworks.com Anonymous FTP servercomp.soft-sys.matlab Newsgroup

[email protected] Technica l suppor [email protected] Product enhancement suggest [email protected] Bug repor t [email protected] Documenta t ion er ror repor t [email protected] Subscr ibing user regist ra t [email protected] Order sta tus, license renewals, [email protected] Sa les, pr icing, and genera l informat ion

S ignal Processing Toolbox User’s Guide COPYRIGHT 1988 - 1999 by The MathWorks, Inc. All Righ ts Reserved.The software descr ibed in th is document is furn ished under a licen se agreemen t . The software may be usedor copied only under the terms of the licen se agreement . No par t of th is manua l may be photocopied or repro-duced in any form without pr ior wr it t en consent from The MathWorks, Inc.U.S. GOVERNMENT: If Licensee is acquir ing the Programs on beha lf of any unit or agency of the U.S.Government , the following sha ll apply: (a) For unit s of t he Depar tment of Defen se: the Government sha llhave only the r igh ts specified in the license under which the commercia l computer software or commercia lsoftware documentat ion was obt a ined, a s set for th in subpa ragraph (a ) of the Rights in Commercia lComputer Software or Commercia l Software Documenta t ion Clause at DFARS 227.7202-3, therefore ther igh ts set for th herein sha ll apply; and (b) For any other un it or agency: NOTICE: Notwith st anding anyother lease or license agreement tha t may per ta in to, or accompany the delivery of, th e compu ter softwareand accompanying documentat ion , the r igh ts of the Government rega rding it s u se, r eproduct ion , and disclo-sure a re as set for th in Clause 52.227-19 (c)(2) of the FAR.MATLAB, Simulink, Sta teflow, Handle Graphics, and Rea l-Time Workshop are registered t rademarks, andTarget Language Compiler is a t rademark of The MathWorks, Inc.Other product or brand names a re t r ademarks or registered t r ademarks of their respect ive holder s.

P r in t ing History: December 1996 Fir st pr in t ing New for MATLAB 5.0J anuary 1998 Second pr in t ing Revised for MATLAB 5.2J anuary 1999 (On line only) Revised for Version 4.2 (Release 11)

☎PHONE

FAX

✉MAIL

INTERNET

@

Page 3: MATLAB Signal Processing Toolbox user manual

i

Contents

Before You Begin

What Is the Signal P rocess in g Toolbox? . . . . . . . . . . . . . . . . . . . xi i

How to Use Th is Manual . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xii i

In sta lla t ion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv

Typograph ica l Conven tions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv iTechnica l Nota t ions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvi i

1Signal P roce ss ing Basics

Signal P roce ss ing Toolbox Cen tra l Features . . . . . . . . . . . . . . 1-2Filter ing and FFTs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2Signals and Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2Key Areas: F ilter Design and Spect ra l Ana lysis . . . . . . . . . . . . 1-3Graphica l User Int er face (GUI) . . . . . . . . . . . . . . . . . . . . . . . . . 1-3Extensibilit y . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-3

Repre sen ting Signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-4Vector Represen ta t ion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-4

Wave form Generation : Time Vectors and Sinusoids . . . . . . . 1-6Common Sequences: Unit Impulse, Unit Step, and Unit Ramp 1-7Mult ichannel Signa ls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-7Common Per iodic Waveforms . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-7Common Aper iodic Waveforms . . . . . . . . . . . . . . . . . . . . . . . . . . 1-8The pulst ran Funct ion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-9The Sinc Funct ion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-10The Dir ich let Funct ion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-11

Page 4: MATLAB Signal Processing Toolbox user manual

i i Contents

Working w ith Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-13

Filte r Implemen tation and Analys is . . . . . . . . . . . . . . . . . . . . . . 1-14Convolu t ion and Filt er ing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-14Filter s and Transfer Funct ions . . . . . . . . . . . . . . . . . . . . . . . . . 1-15Filter Coefficien ts and Filter Names . . . . . . . . . . . . . . . . . . 1-15

Filter ing with the filt er Funct ion . . . . . . . . . . . . . . . . . . . . . . . 1-16

fi lter Function Implementation and In itia l Condit ion s . . . 1-17

Other Functions for Filte ring . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-19Mult ira t e F ilt er Bank Implementa t ion . . . . . . . . . . . . . . . . . . 1-19Anti-Causa l, Zero-Phase Filter Implementa t ion . . . . . . . . . . . 1-20Frequency Domain F ilt er Implementa t ion . . . . . . . . . . . . . . . . 1-22

Impu lse Re sponse . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-23

Frequency Respon se . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-24Digita l Domain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-24Analog Domain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-26Magnitude and Phase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-26Delay . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-28

Zero-Pole Analys is . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-30

Lin ear System Mode ls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-32Discrete-Time System Models . . . . . . . . . . . . . . . . . . . . . . . . . . 1-32Transfer Funct ion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-32Zero-Pole-Gain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-33Sta te-Space . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-34Par t ia l Fract ion Expansion (Residue Form) . . . . . . . . . . . . 1-35Second-Order Sect ions (SOS) . . . . . . . . . . . . . . . . . . . . . . . . 1-36Lat t ice St ructure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-37Convolu t ion Matr ix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-39

Cont inuous-Time System Models . . . . . . . . . . . . . . . . . . . . . . . 1-40Linear System Transformat ions . . . . . . . . . . . . . . . . . . . . . . . . 1-41

Page 5: MATLAB Signal Processing Toolbox user manual

i i i

Discre te Fourie r Transform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-43

Re ference s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-46

2Filte r Des ign

Filte r Requ iremen ts and Spec ification . . . . . . . . . . . . . . . . . . . . 2-2

IIR Filte r De s ign . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-4Classica l IIR Filt er Design Using Analog Prototyping . . . . . . . 2-6Complete Classica l IIR Filter Design . . . . . . . . . . . . . . . . . . . 2-6Designing IIR Filter s to Frequency Domain Specifica t ions . 2-7

Compar ison of Classica l IIR Filt er Types . . . . . . . . . . . . . . . . . . 2-8But terwor th Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-8Chebyshev Type I F ilt er . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-9Chebyshev Type II F ilter . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-10Ellipt ic Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-10Bessel F ilt er . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-11Direct IIR Filter Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-13Genera lized But t erwor th F ilt er Design . . . . . . . . . . . . . . . . 2-14

FIR Filte r Des ign . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-16Linear Phase F ilt er s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-17Windowing Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-18Standa rd Band FIR Filter Design : fir1 . . . . . . . . . . . . . . . . 2-20Mult iband FIR Filt er Design : fir2 . . . . . . . . . . . . . . . . . . . . 2-21

Mult iband FIR Filt er Design with Transit ion Bands . . . . . . . 2-22Basic Configura t ions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-22The Weight Vector . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-24Ant i-Symmetr ic Filter s / Hilber t Transformers . . . . . . . . . . 2-25Differen t ia tors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-26

Const ra ined Least Squa res FIR Filter Design . . . . . . . . . . . . . 2-27Basic Lowpass and Highpass CLS Filt er Design . . . . . . . . . 2-28Mult iband CLS Filter Design . . . . . . . . . . . . . . . . . . . . . . . . 2-29Weighted CLS Filter Design . . . . . . . . . . . . . . . . . . . . . . . . . 2-30

Page 6: MATLAB Signal Processing Toolbox user manual

iv Contents

Arbit ra ry-Response F ilt er Design . . . . . . . . . . . . . . . . . . . . . . . 2-31Mult iband Filt er Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-32Filter Design with Reduced Delay . . . . . . . . . . . . . . . . . . . . 2-34

Spec ial Topics in IIR Filte r Des ign . . . . . . . . . . . . . . . . . . . . . . . 2-37Analog Prototype Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-38Frequency Transformat ion . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-38Filter Discret iza t ion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-41Impulse Inva r iance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-42Bilinear Transformat ion . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-43

Re ference s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-46

3Statis t ica l S igna l P roce ss ing

Corre lation and Covariance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-2Bias and Normaliza t ion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-3Mult iple Channels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-4

Spec tra l Analys is . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-5Welch’s Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-6Power Spect ra l Density Funct ion . . . . . . . . . . . . . . . . . . . . . 3-10Bias and Normaliza t ion in Welch’s Method . . . . . . . . . . . . . 3-12Cross-Spect ra l Density Funct ion . . . . . . . . . . . . . . . . . . . . . 3-14Confidence In terva ls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-14Transfer Funct ion Est ima te . . . . . . . . . . . . . . . . . . . . . . . . . 3-14Coherence Funct ion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-15

Mult itaper Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-16Yule-Walker AR Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-19Burg Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-20Covar iance and Modified Covar iance Methods . . . . . . . . . . . . 3-22MUSIC and Eigenvector Analysis Methods . . . . . . . . . . . . . . . 3-23Eigenana lysis Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-24Cont rolling Subspace Thresholds . . . . . . . . . . . . . . . . . . . . . 3-25

Page 7: MATLAB Signal Processing Toolbox user manual

v

Re ference s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-27

4Specia l Topics

Window s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-2Basic Shapes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-2Genera lized Cosine Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-4Kaiser Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-4Kaiser Windows in FIR Design . . . . . . . . . . . . . . . . . . . . . . . . 4-7

Chebyshev Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-9

Parametric Mode ling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-10Time-Domain Based Modeling . . . . . . . . . . . . . . . . . . . . . . . . . 4-11Linear Predict ion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-12Prony’s Method (ARMA Modeling) . . . . . . . . . . . . . . . . . . . . 4-13Steiglit z-McBr ide Method (ARMA Modeling) . . . . . . . . . . . 4-15

Frequency-Domain Based Modeling . . . . . . . . . . . . . . . . . . . . . 4-16

Resampling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-20

Cepstrum Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-23Inverse Complex Cepst rum . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-25

FFT-Based Time -Frequency Analys is . . . . . . . . . . . . . . . . . . . . . 4-27

Median Filte ring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-28

Communications Applicat ions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-29

Deconvolu tion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-33

Spec ialized Transforms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-34Chirp z-Transform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-34Discrete Cosine Transform . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-36Hilber t Transform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-38

Page 8: MATLAB Signal Processing Toolbox user manual

vi Contents

Reference s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-40

5In teractive Tools

SPTool: An In te rac tive Signal P roce ss ing Environment . . . 5-2Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-2

Using SPTool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-3Opening SPTool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-3Quick Star t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-3Example: Impor t ing Signal Da ta from a MAT-File . . . . . . . . 5-3

Basic SPTool Funct ions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-5File Menu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-6Help Menu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-6

Impor t ing Signals, F ilter s, and Spect ra . . . . . . . . . . . . . . . . . . . 5-7Loading Var iables from the MATLAB Workspace . . . . . . . . 5-7Loading Var iables from Disk . . . . . . . . . . . . . . . . . . . . . . . . . 5-8Impor t ing Workspace Conten ts and File Conten ts . . . . . . . . 5-8

Working with Signals, F ilter s, and Spect ra . . . . . . . . . . . . . . . 5-13Component List s in SPTool . . . . . . . . . . . . . . . . . . . . . . . . . . 5-14Select ing Data Object s in SPTool . . . . . . . . . . . . . . . . . . . . . 5-15Edit ing Data Object s in SPTool . . . . . . . . . . . . . . . . . . . . . . 5-15Viewing a Signal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-17Viewing a Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-17Design ing a Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-17Applying a Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-18Crea t ing a Spect rum . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-19Viewing a Spect rum . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-19Updat ing a Spect rum . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-19

Page 9: MATLAB Signal Processing Toolbox user manual

v ii

Customizing Preferences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-20Ruler Set t ings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-21Color Set t ings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-22Signal Browser Set t ings . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-23Spect rum Viewer Set t ings . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-24Filter Viewer Set t ings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-25Filter Viewer Tiling Set t ings . . . . . . . . . . . . . . . . . . . . . . . . 5-26Filter Designer Set t ings . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-27Defau lt Session Set t ing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-28Expor t ing Components Set t ing . . . . . . . . . . . . . . . . . . . . . . . 5-29Plug-Ins Set t ing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-30Saving and Discarding Changes to Preferences Set t ings . . 5-30

Cont rols for Viewing and Measur ing . . . . . . . . . . . . . . . . . . . . 5-31Zoom Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-31Ruler Cont rols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-33Making Signal Measurement s . . . . . . . . . . . . . . . . . . . . . . . 5-37

Using the Signal Brow ser: In te ractive Signal Analys is . . . 5-43Opening the Signal Browser . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-43Basic Signa l Browser Funct ions . . . . . . . . . . . . . . . . . . . . . . . . 5-44Menus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-45Zoom Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-46Ruler and Line Display Controls . . . . . . . . . . . . . . . . . . . . . 5-46Help But ton . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-46Display Management Controls . . . . . . . . . . . . . . . . . . . . . . . 5-47Main Axes Display Area . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-47Panner . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-48Making Signal Measurement s . . . . . . . . . . . . . . . . . . . . . . . 5-49

Viewing and Explor ing Signa ls . . . . . . . . . . . . . . . . . . . . . . . . . 5-49Select ing and Displaying a Signal . . . . . . . . . . . . . . . . . . . . 5-49Panner Display . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-52Manipula t ing Displays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-53Working with Signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-54Pr in t ing Signal Da ta . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-54Saving Signa l Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-57

Us ing the F ilte r Des igner: In te rac tive F ilte r Des ign . . . . . . 5-59Opening the Filter Designer . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-59

Page 10: MATLAB Signal Processing Toolbox user manual

vii i Contents

Basic Filter Designer Funct ions . . . . . . . . . . . . . . . . . . . . . . . . 5-60Menus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-60Filter Pop-Up Menu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-60Zoom Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-61Help But ton . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-61Genera l Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-62Filter Specifica t ions Panel—Design Methods . . . . . . . . . . . 5-63Filter Measurements Panel—Design Methods . . . . . . . . . . 5-65Filter Specifica t ions Panel—Pole/Zero Editor . . . . . . . . . . . 5-66Filter Measurements Panel—Pole/Zero Editor . . . . . . . . . . 5-68Magnitude P lot (Display) Area—Design Methods . . . . . . . . 5-69Magnitude P lot (Display) Area—Pole/Zero Editor . . . . . . . . 5-71

Design ing F in it e Impulse Response (FIR) F ilter s . . . . . . . . . . 5-73Example: FIR Filter Design , Standard Band Configura t ion 5-73Filter Design Opt ions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-75Order Select ion for FIR Filt er Design . . . . . . . . . . . . . . . . . 5-75

Design ing Infin it e Impulse Response (IIR) F ilt er s . . . . . . . . . 5-76Example: Classica l IIR Filter Design . . . . . . . . . . . . . . . . . . 5-76Filter Design Opt ions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-77Order Select ion for IIR Filter Design . . . . . . . . . . . . . . . . . . 5-78

Redesign ing a Filter Using the Magnitude P lot . . . . . . . . . . . . 5-78Saving F ilter Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-79

Viewing Frequency Response P lots . . . . . . . . . . . . . . . . . . . . . . 5-82

Us ing the F ilte r View er: In teractive Filter Analys is . . . . . . 5-84Opening the Filter Viewer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-84Basic Filter Viewer Funct ions . . . . . . . . . . . . . . . . . . . . . . . . . . 5-84Menus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-86Filter Iden t ifica t ion Panel . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-86Plots Panel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-86Frequency Axis Set t ings . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-87Zoom Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-87Help But ton . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-87Main Plot s Area . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-88

Page 11: MATLAB Signal Processing Toolbox user manual

ix

Viewing Filt er Plots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-89Viewing Magnitude Response . . . . . . . . . . . . . . . . . . . . . . . . 5-89Viewing Phase Response . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-91Viewing Group Delay . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-93Viewing a Zero-Pole Plot . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-94Viewing Impulse Response . . . . . . . . . . . . . . . . . . . . . . . . . . 5-94Viewing Step Response . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-95

Using the Spec trum View er: In te ract ive PSD Analysis . . . 5-97Opening the Spect rum Viewer . . . . . . . . . . . . . . . . . . . . . . . . . 5-97Basic Spect rum Viewer Funct ions . . . . . . . . . . . . . . . . . . . . . . 5-98Menus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-99Signal ID Panel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-100Spect rum Management But tons . . . . . . . . . . . . . . . . . . . . . 5-100Zoom Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-101Ruler and Line Display Controls . . . . . . . . . . . . . . . . . . . . 5-101Help But ton . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-101Main Axes Display Area . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-101Making Spect rum Measurement s . . . . . . . . . . . . . . . . . . . . 5-102

Viewing Spect ra l Density Plot s . . . . . . . . . . . . . . . . . . . . . . . . 5-102Cont rolling and Manipu la t ing Plots . . . . . . . . . . . . . . . . . . . . 5-102Changing P lot P roper t ies . . . . . . . . . . . . . . . . . . . . . . . . . . 5-102Choosing Computa t ion Parameters . . . . . . . . . . . . . . . . . . 5-103Computa t ion Methods and Parameters . . . . . . . . . . . . . . . 5-104Set t ing Confidence In terva ls . . . . . . . . . . . . . . . . . . . . . . . . 5-107Pr in t ing Spect rum Data . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-107Saving Spect rum Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-110

Example : Generation of Bandlim ited Noise . . . . . . . . . . . . . . 5-113Crea te, Impor t , and Name a Signal . . . . . . . . . . . . . . . . . . . . 5-113Design a F ilter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-115Apply the F ilt er to a Signal . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-116View, Play, and Pr in t the Signals . . . . . . . . . . . . . . . . . . . . . . 5-117Compare Spect ra of Both Signals . . . . . . . . . . . . . . . . . . . . . . 5-120

6Reference

Page 12: MATLAB Signal Processing Toolbox user manual

x Contents

Page 13: MATLAB Signal Processing Toolbox user manual

Before You Begin

What Is the S ignal P rocess ing Toolbox? . . . . . . . . . . . . . . . .xii

How to Use Th is Manual . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiii

In sta lla t ion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv

Typograph ica l Conven tions . . . . . . . . . . . . . . . . . . . . . . . . . . xviTechnica l Nota t ions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xvii

Page 14: MATLAB Signal Processing Toolbox user manual

Before You Begin

xii

What Is the Signal Processing Toolbox?This sect ion descr ibes how to begin using the Signa l Processing Toolbox. Itexpla ins how to use th is manual and poin ts you to addit iona l books for toolboxinst a lla t ion informat ion .

The Signa l Processing Toolbox is a collect ion of tools bu ilt on the MATLAB®numer ic comput ing environment . The toolbox suppor ts a wide range of signa lprocessing opera t ions, from waveform genera t ion to filter design andimplementa t ion , paramet r ic modeling, and spect ra l ana lysis. The toolboxprovides two categor ies of tools:

• Signal processing funct ions•Graphica l, in teract ive tools

The fir st ca t egory of tools is made up of funct ions tha t you can ca ll from thecommand line or from your own applica t ions. Many of these funct ions a reMATLAB M-files, ser ies of MATLAB sta tement s tha t implement specia lizedsigna l processing a lgor ithms. You can view the MATLAB code for thesefunct ions using the sta tement

type function_name

or by opening the M-file in the MATLAB Editor /Debugger . You can change theway any toolbox funct ion works by copying and renaming the M-file, thenmodifying your copy. You can a lso extend the toolbox by adding your ownM-files.

Second, the toolbox provides a number of in teract ive tools tha t let you accessmany of the funct ions th rough a graphical user in terface (GUI). The GUI-basedtools provide an in tegra ted environment for filt er design , ana lysis, andimplementa t ion , a s well a s signa l explora t ion and edit ing. For example, withthe graph ica l user in ter face tools you can :

•Use the mouse to graph ica lly edit the magnitude response of a filt er ormeasure the slope of a signa l with onscreen ru ler s.

• Play a signa l on your syst em’s audio hardware by select ing a menu item orpressing a cor responding keyst roke combina t ion .

•Customize the pa rameters and method of comput ing the spect rum of asignal.

Page 15: MATLAB Signal Processing Toolbox user manual

How to Use This Manual

xii i

How to Use This ManualIf you are a new user. Begin with Chapter 1, “Signa l Processing Basics.” Thischapter in t roduces the MATLAB signa l processing environment th rough thetoolbox funct ions. It descr ibes the basic funct ions of the Signa l ProcessingToolbox, reviewing it s use in basic waveform genera t ion , filt er implementa t ionand ana lysis, impulse and frequency response, zero-pole ana lysis, linearsystem models, and the discrete Four ier t ransform.

When you feel comfor table with the basic funct ions, move on to Chapter 2 andChapter 3 for a more in-depth in t roduct ion to using the Signa l ProcessingToolbox:

•Chapter 2, “Filter Design ,” for a deta iled explana t ion of using the Signa lProcessing Toolbox in infin ite impulse response (IIR) and fin ite impulseresponse (FIR) filt er design and implementa t ion , including specia l topics inIIR filter design .

•Chapter 3, “Sta t ist ica l Signa l Processing,” for how to use the correla t ion ,covar iance, and spect ra l ana lysis tools to est ima te impor t an t funct ions ofdiscret e random signa ls.

Once you understand the genera l pr inciples and applica t ions of the toolbox,learn how to use the in t eract ive tools.

•Chapter 5, “In teract ive Tools,” for an overview of the in teract ive GUIenvironment and examples of how to use it for signa l explora t ion , filterdesign and implementa t ion , and spect ra l ana lysis.

F ina lly, see the following chapter for a discussion of specia lized toolboxfunct ions.

•Chapter 4, “Specia l Topics,” for specia lized funct ions, including filterwindows, paramet r ic modeling, resampling, cepst rum analysis,t ime-dependent Four ier t ransforms and spect rograms, median filter ing,communica t ions applica t ions, deconvolu t ion , and specia lized t ransforms.

If you are an experienced toolbox user. See Chapter 5, “In teract ive Tools,” for anoverview of the in teract ive GUI environment and examples of how to use it forsigna l viewing, filt er design and implementa t ion , and spect ra l ana lysis.

Page 16: MATLAB Signal Processing Toolbox user manual

Before You Begin

xiv

All toolbox users. Use Chapter 6, “Reference,” for loca t ing in format ion on specificfunct ions. Reference descr ipt ions include a synopsis of the funct ion’s syn tax, aswell as a complet e explana t ion of opt ions and opera t ions. Many referencedescr ipt ions a lso include helpfu l examples, a descr ipt ion of the funct ion’sa lgor ithm, and references to addit iona l reading ma ter ia l.

Use th is manua l in conjunct ion with the software to lea rn about the powerfu lfea tures tha t MATLAB provides. Each chapter provides numerous examplestha t apply the toolbox to representa t ive signa l processing tasks.

Some examples use MATLAB’s random number genera t ion funct ion randn. Inthese cases, to duplica te the resu lt s in the example, type

randn('seed',0)

before running the example.

Page 17: MATLAB Signal Processing Toolbox user manual

Installation

xv

InstallationTo insta ll t h is toolbox on a worksta t ion , see the MATLAB Installation Guidefor UN IX . To insta ll the toolbox on a PC, see the MATLAB PC InstallationGuide.

To determine if the Signa l Processing Toolbox is a lready insta lled on yoursystem, check for a subdirectory named signal within the main toolboxdirectory or folder .

Page 18: MATLAB Signal Processing Toolbox user manual

Before You Begin

xvi

Typographical Conventions

To Indicate This Manual Uses Example

Example code Monospace type. To assign the value 5 toA, en ter

A = 5

MATLABoutpu t

Monospace type. MATLAB responds with

A = 5

Funct ion names Monospace type. The cos funct ion findsthe cosine of each a r rayelement .

New terms Italics. An array is an orderedcollect ion ofinformat ion .

Keys Boldface with anin it ia l capita l let t er.

P ress the Return key.

Menu names,it ems, and GUIcont rols

Boldface with anin it ia l capita l let t er.

Choose the File menu.

Mathemat ica lexpressions

Var iables in italics.Funct ions,opera tors, andconstan ts instandard type.

This vector represen t sthe polynomia l

p = x2 + 2x + 3

Page 19: MATLAB Signal Processing Toolbox user manual

Typographical Conventions

xvii

Technical NotationsThis manua l and the Signa l Processing Toolbox funct ions use the followingtechnica l nota t ions:

Nyquist frequency One-ha lf the sampling frequency. Mosttoolbox funct ions normalize th is va lue to 1.

x(1) The fir st element of a da ta sequence orfilter, cor responding to zero lag.

Ω Ana log frequency in radians per second.

ω or w Digit a l frequency in radians per second.

f Digit a l frequency in Her tz.

[x, y) The in terva l from x t o y, including x but notincluding y

Page 20: MATLAB Signal Processing Toolbox user manual

Before You Begin

xvii i

Page 21: MATLAB Signal Processing Toolbox user manual

1

Signa l Processing Basics

Signal P roce ss ing Toolbox Cen tra l Feature s . . . . . . . . . . . 1-2

Repre sen ting Signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-4

Wave form Generation : Time Vectors and Sinusoids . . . . 1-6

Working w ith Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-13

Filte r Implementation and Analysis . . . . . . . . . . . . . . . . . . 1-14

fi lter Function Implementation and In it ia l Condition s . 1-17

Other Functions for Filte ring . . . . . . . . . . . . . . . . . . . . . . . . 1-19

Impu lse Response . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-23

Frequency Response . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-24

Zero-Pole Analys is . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-30

Linear System Mode ls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-32

Discre te Fourie r Transform . . . . . . . . . . . . . . . . . . . . . . . . . 1-43

Reference s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-46

Page 22: MATLAB Signal Processing Toolbox user manual

1 Signal Processing Basics

1-2

Signal Processing Toolbox Central FeaturesThis chapter descr ibes how to begin using MATLAB and the Signa l ProcessingToolbox for your signa l processing applica t ions. It assumes a basic knowledgeand underst anding of signa ls and syst ems, including such topics a s filter andlinear system theory and basic Four ier ana lysis.

Many examples th roughout the chapter demonst ra t e how to apply toolboxfunct ions. If you a re not a lready familia r with MATLAB’s signa l processingcapabilit ies, use th is chapter in conjunct ion with the software to t ry examplesand learn about the powerfu l fea tures ava ilable to you .

The Signa l Processing Toolbox funct ions are a lgor ithms, expressed most ly inM-files, tha t implement a var iety of signa l processing tasks. These toolboxfunct ions are a specia lized extension of the MATLAB computa t iona l andgraph ica l environment .

Filtering and FFTsTwo of the most impor t an t funct ions for signa l processing a re not in the Signa lProcessing Toolbox a t a ll, bu t are built -in MATLAB funct ions:

• filter applies a digita l filter to a da ta sequence.• fft ca lcu la tes the discret e Four ier t ransform of a sequence.

The opera t ions these funct ions per form are the main computa t iona lworkhorses of classica l signa l processing. Both are descr ibed in th is chapter .The Signa l Processing Toolbox uses many other standa rd MATLAB funct ionsand language fea tures, including polynomia l root finding, complex ar ithmet ic,mat r ix inversion and manipu la t ion, and graph ics tools.

Signals and SystemsThe basic en t it ies tha t toolbox funct ions work with a re signa ls and systems.The funct ions emphasize digita l, or discrete, signa ls and filter s, as opposed toana log, or cont inuous, signa ls. The pr incipa l filt er type the toolbox suppor t s isthe linear , t ime-inva r ian t digita l filt er with a single input and a single ou tput .You can represent linear t ime-inva r ian t syst ems using one of severa l models(such as t ransfer funct ion , sta te-space, zero-pole-ga in , and second-ordersect ion) and conver t between represen ta t ions.

Page 23: MATLAB Signal Processing Toolbox user manual

Signal Processing Toolbox Central Features

1-3

Key Areas: Filter Design and Spectral AnalysisIn addit ion to it s core funct ions, the toolbox provides r ich , customizable suppor tfor the key areas of filt er design and spect ra l ana lysis. It is easy to implementa design technique tha t su it s your applica t ion , design digita l filter s direct ly, orcrea te ana log prototypes and discret ize them. Toolbox funct ions a lso est imatepower spect ra l density and cross spect ra l density, using either pa rametr ic ornonparametr ic t echn iques. Chapters 2 and 3, respect ively, deta il toolboxfunct ions for filt er design and spect ra l ana lysis.

There are funct ions for computa t ion and graph ica l display of frequencyresponse, as well as funct ions for system iden t ifica t ion ; genera t ing signa ls;discret e cosine, ch irp-z, and Hilber t t ransforms; la t t ice filter s; resampling;t ime-frequency ana lysis; and basic communica t ion syst ems simula t ion .

Graphical User Interface (GUI)The power of the Signa l Processing Toolbox is grea t ly enhanced by itseasy-to-use graph ica l user in ter face. The GUI provides an in tegra t ed set ofin t eract ive tools for per forming a wide var iety of signa l processing tasks. Thesetools enable you to use the mouse and menus to manipula te a r ich graphica lenvironment for signa l viewing, filter design and implementa t ion , and spect ra lana lysis.

ExtensibilityPerhaps the most impor tan t fea tu re of the MATLAB environment is tha t it isextensible: MATLAB lets you crea t e your own M-files to meet numer iccomputa t ion needs for resea rch , design , or engineer ing of signa l processingsystems. Simply copy the M-files provided with the Signal Processing Toolboxand modify them as needed, or crea t e new funct ions to expand the funct iona lityof the toolbox.

Page 24: MATLAB Signal Processing Toolbox user manual

1 Signal Processing Basics

1-4

Representing SignalsThe cen t ra l da ta const ruct in MATLAB is the num eric array, an orderedcollect ion of rea l or complex numer ic da ta with two or more dimensions. Thebasic da ta object s of signa l processing (one-dimensiona l signa ls or sequences,mult ichannel signa ls, and two-dimensiona l signa ls) a re a ll na tu ra lly su ited toar ray represen ta t ion .

Vector RepresentationMATLAB represen ts ordinary one-dimensiona l sampled data signa ls, orsequences, as vectors. Vectors are 1-by-n or n -by-1 ar rays, where n is thenumber of samples in the sequence. One way to in t roduce a sequence in toMATLAB is to enter it a s a list of element s a t the command prompt . Thesta tement

x = [4 3 7 –9 1]

crea t es a simple five-element rea l sequence in a row vector . Transposit ionturns the sequence in to a column vector

x = x'

resu lt ing in

x =437–91

Column or ien ta t ion is preferable for single channel signa ls because it extendsna tura lly to the mult ichannel case. For mult ichannel da ta , each column of amatr ix represen t s one channel. Each row of such a matr ix then cor responds toa sample poin t . A three-channel signa l tha t consists of x, 2x, and x/π is

y = [x 2*x x/pi]

Page 25: MATLAB Signal Processing Toolbox user manual

Representing Signals

1-5

This result s in

y =

4.0000 8.0000 1.27323.0000 6.0000 0.95497.0000 14.0000 2.2282

–9.0000 –18.0000 –2.86481.0000 2.0000 0.3183

Page 26: MATLAB Signal Processing Toolbox user manual

1 Signal Processing Basics

1-6

Waveform Generation: Time Vectors and SinusoidsA var iety of toolbox funct ions genera te waveforms. Most requ ire you to beginwith a vector represen t ing a t ime base. Consider genera t ing da ta with a 1000Hz sample frequency, for example. An appropr ia t e t ime vector is

t = (0:0.001:1)';

where MATLAB’s colon opera tor crea tes a 1001-element row vector tha trepresen ts t ime running from zero to one second in steps of one millisecond.The t ranspose opera tor (') changes the row vector in to a column; thesemicolon (;) t ells MATLAB to compute but not display the resu lt .

Given t you can crea t e a sample signa l y consist ing of two sinusoids, one a t 50Hz and one a t 120 Hz with twice the amplitude:

y = sin(2*pi*50*t) + 2*sin(2*pi*120*t);

The new var iable y, formed from vector t, is a lso 1001 elements long. You canadd normally dist r ibu ted whit e noise to the signa l and graph the fir st fiftypoin ts using

yn = y + 0.5*randn(size(t));plot(t(1:50),yn(1:50))

0 0.01 0.02 0.03 0.04 0.05-4

-3

-2

-1

0

1

2

3

4

Page 27: MATLAB Signal Processing Toolbox user manual

Waveform Generation: Time Vectors and Sinusoids

1-7

Common Sequences: Unit Impulse, Unit Step, and Unit RampSince MATLAB is a programming language, an endless va r iety of differen tsigna ls is possible. Here are some sta tement s tha t genera t e severa l commonlyused sequences, including the unit impulse, un it step, and unit ramp funct ions:

t = (0:0.001:1)';y = [1; zeros(99,1)]; % impulsey = ones(100,1); % step (filter assumes 0 initial cond.)y = t; % rampy = t.^2;y = square(4*t);

All of these sequences a re column vectors – the last th ree inher it their shapesfrom t.

Multichannel SignalsUse standa rd MATLAB array syntax to work with mult ichannel signa ls. Forexample, a mult ichannel signa l consist ing of the la st th ree signa ls genera t edabove is

z = [t t.^2 square(4*t)];

You can genera t e a mult ichannel un it sample funct ion using the outer productopera tor . For example, a six-element column vector whose fir st element is one,and whose remain ing five elements are zeros, is

a = [1 zeros(1,5)]';

To duplica te column vector a in to a ma tr ix withou t per forming anymult iplica t ion , use MATLAB’s colon opera tor and the ones funct ion .

c = a(:,ones(1,3));

Common Periodic WaveformsThe toolbox provides funct ions for genera t ing widely used per iodic waveforms:

Page 28: MATLAB Signal Processing Toolbox user manual

1 Signal Processing Basics

1-8

• sawtooth genera tes a sawtooth wave with peaks a t ±1 and a per iod of 2π. Anopt iona l width pa rameter specifies a fract iona l mult iple of 2π a t which thesigna l’s maximum occurs.

• square genera tes a square wave with a per iod of 2π. An opt iona l parameterspecifies duty cycle, t he percen t of the per iod for which the signa l is posit ive.

To genera te 1.5 seconds of a 50 Hz sawtooth wave with a sample ra te of 10 kHzand plot 0.2 seconds of the genera ted waveform, use

Fs = 10000;t = 0:1/Fs:1.5;x = sawtooth(2*pi*50*t);plot(t,x), axis([0 0.2 –1 1])

Common Aperiodic WaveformsThe toolbox also provides funct ions for genera t ing severa l widely usedaper iodic waveforms:

• gauspuls genera tes a Gaussian-modula t ed sinusoida l pulse with a specifiedt ime, cen ter frequency, and fract iona l bandwidth . Opt iona l pa rameters

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

Page 29: MATLAB Signal Processing Toolbox user manual

Waveform Generation: Time Vectors and Sinusoids

1-9

return in-phase and quadra ture pu lses, the RF signa l envelope, and thecutoff t ime for the t ra iling pulse envelope.

• chirp genera tes a linear swept -frequency cosine signa l. An opt iona lparameter specifies a lterna t ive sweep methods. An opt iona l pa rameter phia llows in it ia l phase to be specified in degrees.

To compute 2 seconds of a linear ch irp signa l with a sample ra te of 1 kHz, tha tsta r t s a t DC and crosses 150 Hz a t 1 second, use

t = 0:1/1000:2;y = chirp(t,0,1,150);

To plot the spect rogram, use

specgram(y,256,1000,256,250)

The pulstran FunctionThe pulstran funct ion genera t es pu lse t ra ins from either con t inuous orsampled prototype pulses. The following example genera t es a pu lse t ra inconsist ing of the sum of mult iple delayed in terpola t ions of a Gaussian pulse.The pulse t ra in is defined to have a sample ra te of 50 kHz, a pulse t ra in length

Time

Freq

uenc

y

0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.60

50

100

150

200

250

300

350

400

450

500

Page 30: MATLAB Signal Processing Toolbox user manual

1 Signal Processing Basics

1-10

of 10 ms, and a pulse repet it ion ra t e of 1 kHz; D specifies the delay to each pulserepet it ion in column 1 and an opt iona l a t tenua t ion for each repet it ion incolumn 2. The pulse t ra in is const ruct ed by passing the name of the gauspulsfunct ion to pulstran, a long with addit iona l parameters tha t specify a 10 kHzGaussian pulse with 50% bandwidth :

T = 0:1/50E3:10E-3;D = [0:1/1E3:10E-3;0.8.^(0:10)]';Y = pulstran(T,D,'gauspuls',10E3,0.5);plot(T,Y)

The Sinc FunctionThe sinc funct ion computes the mathema t ica l sinc funct ion for an inpu t vectoror ma tr ix x. The sinc funct ion is the cont inuous inverse Four ier t ransform ofthe rect angular pu lse of width 2π and heigh t 1:

The sinc funct ion has a va lue of 1 where x is zero, and a va lue of

for a ll other elements of x.

0 0.001 0.002 0.003 0.004 0.005 0.006 0.007 0.008 0.009 0.01-0.8

-0.6

-0.4

-0.2

0

0.2

0.4

0.6

0.8

1

πx( )sinπx--------------------

Page 31: MATLAB Signal Processing Toolbox user manual

Waveform Generation: Time Vectors and Sinusoids

1-11

To plot the sinc funct ion for a linea r ly spaced vector with va lues ranging from–5 to 5,

x = linspace(–5,5);y = sinc(x);plot(x,y)

The Dirichlet FunctionThe toolbox funct ion diric computes the Dir ich let funct ion , somet imes ca lledthe period ic sinc or aliased sinc funct ion , for an input vector or mat r ix x. TheDir ich let funct ion is

where n is a user -specified posit ive in teger . For n odd, the Dir ich let funct ionhas a per iod of 2π; for n even , it s per iod is 4π. The magnitude of th is funct ion is(1/n ) t imes the magnitude of the discrete-t ime Four ier t ransform of the n -poin trectangular window.

-5 -4 -3 -2 -1 0 1 2 3 4 5-0.4

-0.2

0

0.2

0.4

0.6

0.8

1

dir ic x( )1 k n 1–( )– x 2πk k 0 1± 2± …, , ,=,=

n x 2⁄( )sinn x 2⁄( )sin---------------------------- otherwise⎩⎪⎨⎪⎧

=

Page 32: MATLAB Signal Processing Toolbox user manual

1 Signal Processing Basics

1-12

To plot the Dir ich let funct ion over the range 0 to 4π for n = 7 and n = 8, use

x = linspace(0,4*pi,300);plot(x,diric(x,7))plot(x,diric(x,8))

0 5 10 15-0.4

-0.2

0

0.2

0.4

0.6

0.8

1n = 7

0 5 10 15-1

-0.5

0

0.5

1n = 8

Page 33: MATLAB Signal Processing Toolbox user manual

Working with Data

1-13

Working with DataThe examples in the preceding sect ions obta in da ta in one of two ways:

•By direct inpu t , tha t is, en ter ing the da ta manua lly a t the keyboa rd•By using a MATLAB or toolbox funct ion , such as sin, cos, sawtooth, square,or sinc

Some applica t ions, however , may need to impor t da ta from outside MATLAB.Depending on your da ta format , you can do th is in the following ways:

• Load da ta from an ASCII file or MAT-file with MATLAB’s load command•Read the da ta in to MATLAB with a low-level file I/O funct ion , such as fopen,fread, and fscanf

•Develop a MEX-file to read the da ta

Other resources are a lso usefu l, such as a h igh-level language program (inFor t ran or C, for example) tha t conver ts your da ta in to MAT-file forma t—seethe MATLAB Application Programm ing In terface reference manua l for deta ils.MATLAB reads such files using the load command.

Simila r techniques a re ava ilable for expor t ing da ta genera ted with inMATLAB. See Using MATLAB for more deta ils on impor t ing and expor t ingda ta , and see the online MATLAB Function Reference for descr ipt ions of fileloading and I/O rout ines.

Page 34: MATLAB Signal Processing Toolbox user manual

1 Signal Processing Basics

1-14

Filter Implementation and AnalysisThis sect ion descr ibes how to filt er discrete signa ls using MATLAB’s filterfunct ion and other funct ions in the Signa l Processing Toolbox. It a lso discusseshow to use the toolbox funct ions to ana lyze filt er character ist ics, includingimpulse response, magnitude and phase response, group delay, and zero-poleloca t ions.

Convolution and FilteringThe mathemat ica l foundat ion of filter ing is convolu t ion . MATLAB’s convfunct ion per forms standard one-dimensiona l convolu t ion , convolving onevector with another .

conv([1 1 1],[1 1 1])

ans =

1 2 3 2 1

NOTE Convolve rectangula r ma t r ices for two-dimensiona l signa l processingusing the conv2 funct ion .

A digita l filt er ’s output y(n ) is rela t ed to it s input x(n ) by convolu t ion with it simpulse response h (n ).

If a digita l filt er ’s impulse response h (n ) is fin ite length , and the input x(n ) isa lso fin ite length , you can implement the filter using conv. Store x(n ) in a vectorx, h (n ) in a vector h, and convolve the two.

x = randn(5,1); % a random vector of length 5h = [1 1 1 1]/4; % length 4 averaging filtery = conv(h,x);

y n( ) h n( ) x n( )∗ h n m–( )x m( )m ∞–=

∑= =

Page 35: MATLAB Signal Processing Toolbox user manual

Filter Implementation and Analysis

1-15

Filters and Transfer FunctionsIn genera l, t he z-t r ansform Y (z) of a digita l filt er ’s ou tpu t y(n ) is rela ted to thez-t ransform X (z) of the inpu t by

where H (z) is the filter ’s transfer function . Here, the constan t s b(i) and a(i) a rethe filt er coefficien t s and the order of the filter is the maximum of na and nb.

NOTE The filter coefficien ts sta r t with subscr ipt 1, ra ther than 0. Thisreflect s MATLAB’s standard indexing scheme for vectors.

MATLAB stores the coefficien ts in two vectors, one for the numera tor and onefor the denomina tor . By convent ion, MATLAB uses row vectors for filt ercoefficien t s.

Filter Coefficients and Filter NamesMany standard names for filt er s reflect the number of a and b coefficien t spresen t :

•When nb = 0 (tha t is, b is a sca la r ), t he filter is an Infin it e Impulse Response(IIR), a ll-pole, recursive, or au toregressive (AR) filter .

•When na = 0 (tha t is, a is a sca la r ), the filt er is a Fin ite Impulse Response(FIR), a ll-zero, nonrecursive, or moving average (MA) filt er .

• If both na and nb a re grea ter than zero, the filt er is an IIR, pole-zero,recursive, or au toregressive moving average (ARMA) filt er .

The acronyms AR, MA, and ARMA are usua lly applied to filter s associa t edwith filtered stochast ic processes.

Y z( ) H z( )X z( ) b 1( ) b 2( )z 1– L b n b 1+( )z n b–+ + +a 1( ) a 2( )z 1– L a n a 1+( )z n a–+ + +-----------------------------------------------------------------------------------------X z( )= =

Page 36: MATLAB Signal Processing Toolbox user manual

1 Signal Processing Basics

1-16

Filtering with the filter FunctionIt is simple to work back to a difference equa t ion from the z-t ransform rela t ionshown ear lier . Assume tha t a(1) = 1. Move the denomina tor to the left -handside and take the inverse z-t r ansform.

In terms of cur ren t and past inpu ts, and past ou tpu t s, y(n ) is

This is the standard t ime-domain representa t ion of a digita l filter , computedsta r t ing with y(1) and assuming zero init ia l condit ions. This represen ta t ion’sprogression is

A filter in th is form is easy to implement with the filter funct ion . Forexample, a simple single-pole filt er (lowpass) is

b = 1; % numeratora = [1 –0.9]; % denominator

where the vectors b and a represen t the coefficien ts of a filt er in t ransferfunct ion form. To apply th is filter to your da ta

y = filter(b,a,x);

filter gives you as many output samples as there a re inpu t samples, tha t is,the length of y is the same as the length of x. If the fir st element of a is not 1,filter divides the coefficien t s by a(1) before implement ing the differenceequa t ion .

y n( ) a 2( )y n 1–( ) L a n a 1+( )y n n a–( )+ + + b 1( )x n( ) b 2( )x n 1–( ) L b n b 1+( )x n n b–( )+ + +=

y n( ) b 1( )x n( ) b 2( )x n 1–( ) L b n b 1+( )x n n b–( ) a 2( )y n 1–( ) L– a n a 1+( )– y n n a–( )–+ + +=

y 1( ) b 1( )x 1( )=y 2( ) b 1( )x 2( ) b 2( )x 1( ) a 2( )y 1( )–+=y 3( ) b 1( )x 3( ) b 2( )x 2( ) b 3( )x 1( ) a 2( )y 2( ) a 3( )y 1( )––+ +=M M=

Page 37: MATLAB Signal Processing Toolbox user manual

filter Function Implementation and Initial Conditions

1-17

filter Function Implementation and Initial Conditionsfilter is implemented as a t ransposed direct form II st ructure

where n -1 is the filt er order . This is a canonica l form tha t has the minimumnumber of delay element s.

At sample m , filter computes the difference equa t ions

In it s most basic form, filter in it ia lizes the delay outputs z i(1), i = 1, ..., n -1to 0. This is equiva lent to assuming both past inpu t s and outpu ts a re zero. Setthe in it ia l delay outpu t s using a four th inpu t pa rameter to filter, or accessthe fina l delay outpu t s using a second outpu t parameter .

[y,zf] = filter(b,a,x,zi)

Access to in it ia l and fina l condit ions is usefu l for filt er ing da ta in sect ions,especia lly if memory limita t ions a re a considera t ion . Suppose you havecollected da ta in two segments of 5000 poin t s each .

x1 = randn(5000,1); % two random sequences tox2 = randn(5000,1); % serve as simulated data

Perhaps the fir st sequence, x1, cor responds to the fir st 10 minutes of da ta andthe second, x2, t o an addit iona l 10 minutes. The whole sequence isx = [x1; x2]. If t here is not sufficien t memory to hold the combined sequence,

Σ Σ Σz -1 z -1

x(m)

y(m)

b(3) b(2) b(1)

–a(3) –a(2)z1(m)z2(m)

Σ z -1

b(n)

–a(n)zn -1(m)

...

...

...

y m( ) b 1( )x m( ) z1 m 1–( )+=

z1 m( ) b 2( )x m( ) z2 m 1–( ) a 2( )y m( )–+=

M M=zn 2– m( ) b n 1–( )x m( ) zn 1– m 1–( ) a n 1–( )y m( )–+=

zn 1– m( ) b n( )x m( ) a n( )y m( )–=

Page 38: MATLAB Signal Processing Toolbox user manual

1 Signal Processing Basics

1-18

filter the subsequences x1 and x2 one a t a t ime. To ensure con t inu ity of thefiltered sequences, use the fina l condit ions from x1 as in it ia l condit ions to filterx2.

[y1,zf] = filter(b,a,x1);y2 = filter(b,a,x2,zf);

The filtic funct ion genera tes in it ia l condit ions for filter. filtic computesthe delay vector to make the behavior of the filter reflect past inpu ts andoutput s tha t you specify. To obta in the same outpu t delay va lues zf as aboveusing filtic

zf = filtic(b,a,flipud(y1),flipud(x1));

This can be usefu l when filter ing shor t da ta sequences, as appropr ia te init ia lcondit ions help reduce t ransien t sta r tup effects.

Page 39: MATLAB Signal Processing Toolbox user manual

Other Functions for Filtering

1-19

Other Functions for FilteringIn addit ion to filter, severa l other funct ions in the Signa l Processing Toolboxper form the basic filter ing opera t ion. These funct ions include upfirdn, whichper forms FIR filter ing with resampling, filtfilt, which elimina tes phasedistor t ion in the filter ing process, fftfilt, which per forms the FIR filter ingopera t ion in the frequency domain , and latcfilt, which filt er s using a la t t iceimplementa t ion.

Multirate Filter Bank ImplementationThe funct ion upfirdn a lt ers the sampling ra te of a signa l by an integer ra t ioP /Q. It computes the resu lt of the cascade of th ree systems: (1) upsampling(zero inser t ion) by in teger factor p, (2) filt er ing by FIR filt er h, and (3)downsampling by integer factor q.

For example, to change the sample ra te of a signa l from 44.1 kHz to 48 kHz,we fir st find the sma llest in teger conversion ra t io p/q.

d = gcd(48000,44100);p = 48000/d;q = 44100/d;

where we find tha t p = 160 and q = 147. Sample ra t e conversion is thenaccomplished by y = upfirdn(x,h,p,q). This cascade of opera t ions isimplemented in an efficien t manner using polyphase filt er ing techniques, andit is a cen t ra l concept of mult ira te filt er ing (see reference [1] for deta ils onmult ira t e filter theory). Note tha t the qua lity of the resampling resu lt relies onthe qua lity of the FIR filter h.

F ilter banks may be implemented using upfirdn by allowing the filter h to bea matr ix, with one FIR filt er per column. A signa l vector is passedindependent ly through each FIR filter , resu lt ing in a mat r ix of output signa ls.

Other funct ions tha t per form mult ira te filt er ing (with fixed filt er ) includeresample, interp, and decimate.

Px(n) y(n)FIRH Q

Page 40: MATLAB Signal Processing Toolbox user manual

1 Signal Processing Basics

1-20

Anti-Causal, Zero-Phase Filter ImplementationIn the case of FIR filt ers, it is possible to design linear phase filter s tha t , whenapplied to da ta (using filter or conv), simply delay the outpu t by a fixednumber of samples. For IIR filter s, however , the phase distor t ion is usua llyhigh ly nonlinea r . The filtfilt funct ion uses the informa t ion in the signa l a tpoin ts before and a fter the cur ren t poin t , in essence “looking in to the fu ture,”to elimina te phase distor t ion .

To see how filtfilt does this, reca ll tha t if the z-t r ansform of a rea l sequencex(n ) is X(z), the z-t ransform of the t ime reversed sequence x(n ) is X(1/z).Consider the processing scheme

When | z | = 1, tha t is z = ejω, the ou tpu t reduces to X (ejω)| H (ejω)| 2. Given allthe samples of the sequence x(n ), a doubly filtered version of x tha t haszero-phase distor t ion is possible.

For example, a one-second dura t ion signa l sampled a t 100 Hz, composed of twosinusoida l components a t 3 Hz and 40 Hz, is

Fs = 100;t = 0:1/Fs:1;x = sin(2*pi*t*3)+.25*sin(2*pi*t*40);

H(z)X(z)

X(z)H(z) X(1/z)H(1/z) X(1/z)H(1/z)H(z)

X(z)H(1/z)H(z)H(z)TimeReverse

TimeReverse

Page 41: MATLAB Signal Processing Toolbox user manual

Other Functions for Filtering

1-21

Now crea te a 10-point averaging FIR filt er , and filt er x using both filter andfiltfilt for compar ison:

b = ones(1,10)/10; % 10 point averaging filtery = filtfilt(b,1,x); % non–causal filteringyy = filter(b,1,x); % normal filteringplot(t,x,t,y,'--',t,yy,':')

Both filt ered versions elimina te the 40 Hz sinusoid eviden t in the or igina l,solid line. The plot a lso shows how filter and filtfilt differ ; the dashed(filtfilt) line is in phase with the or igina l 3 Hz sinusoid, while the dot t ed(filter) line is delayed by about five samples. Also, the amplitude of thedashed line is smaller due to the magnitude squared effects of filtfilt.

filtfilt reduces filt er st a r tup t ransien t s by carefu lly choosing init ia lcondit ions, and by prepending onto the input sequence a shor t , reflected pieceof the input sequence. For best resu lt s, make sure the sequence you arefilt er ing has length a t least three t imes the filt er order and tapers to zero onboth 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

Page 42: MATLAB Signal Processing Toolbox user manual

1 Signal Processing Basics

1-22

Frequency Domain Filter ImplementationDua lity between the t ime domain and the frequency domain makes it possibleto per form any opera t ion in either doma in . Usually one domain or the other ismore convenien t for a par t icu la r opera t ion , but you can a lways accomplish agiven opera t ion in either domain .

To implement genera l IIR filt er ing in the frequency domain , mult iply thediscrete Four ier t ransform (DFT) of the input sequence with the quot ien t of theDFT of the filt er ,

n = length(x);y = ifft(fft(x).*fft(b,n)./fft(a,n));

This computes resu lt s tha t a re iden t ica l to filter, bu t with differen t sta r tupt ransient s (edge effects). For long sequences, th is computa t ion is veryinefficien t because of the la rge zero-padded FFT opera t ions on the filtercoefficien t s, and because the FFT algor ithm becomes less efficien t as thenumber of poin ts n increases.

For FIR filter s, however , it is possible to break longer sequences in to shor t er ,computa t iona lly efficien t FFT lengths. The funct ion

y = fftfilt(b,x)

uses the over lap add method (see reference [1] a t the end of th is chapter ) tofilter a long sequence with mult iple medium-length FFTs. It s ou tput isequ iva lent to filter(b,1,x).

Page 43: MATLAB Signal Processing Toolbox user manual

Impulse Response

1-23

Impulse ResponseThe impulse response of a digita l filt er is the outpu t a r ising from the inputsequence

In MATLAB, you can genera t e an impulse sequence a number of ways; onest ra igh t forward way is

imp = [1; zeros(49,1)];

The impulse response of the simple filt er b = 1 and a = [1 –0.9] is

h = filter(b,a,imp);

The impz funct ion in the toolbox simplifies th is opera t ion , choosing the numberof poin t s to genera te and then making a stem plot (using the stem funct ion).

impz(b,a)

The plot shows the exponent ia l decay h(n) = 0.9n of the single pole system.

x n( )1 n 1=,

0 n 1≠,⎩⎨⎧

=

0 10 20 30 40 50 60 70 80 900

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

1

Page 44: MATLAB Signal Processing Toolbox user manual

1 Signal Processing Basics

1-24

Frequency ResponseThe Signa l Processing Toolbox enables you to per form frequency domainana lysis of both ana log and digita l filt ers.

Digital Domainfreqz uses an FFT-based a lgor ithm to ca lcu la t e the z-t r ansform frequencyresponse of a digit a l filter . Specifica lly, the sta t ement

[h,w] = freqz(b,a,n)

returns the n -poin t complex frequency response, H (ejω), of the digit a l filter .

In it s simplest form, freqz accepts the filt er coefficien t vectors b and a, and anin teger n specifying the number of poin t s a t which to ca lcu la t e the frequencyresponse. freqz retu rns the complex frequency response in vector h, and theactua l frequency poin t s in vector w in radians/second.

freqz can accept other parameters, such as a sampling frequency or a vector ofarbit ra ry frequency point s. The example below finds the 256-poin t frequencyresponse for a 12th -order Chebyshev type I filter . The ca ll t o freqz specifies asampling frequency Fs of 1000 Hz.

[b,a] = cheby1(12,0.5,200/500);[h,f] = freqz(b,a,256,1000);

Because the parameter list includes a sampling frequency, freqz retu rns avector f tha t conta ins the 256 frequency point s between 0 and Fs/2 used in thefrequency response ca lcu la t ion.

H ejω( ) b 1( ) b 2( )e j– ω L b n b 1+( )e j– ω n b( )+ + +a 1( ) a 2( )e j– ω L a n a 1+( )e j– ω n a( )+ + +----------------------------------------------------------------------------------------------------=

Page 45: MATLAB Signal Processing Toolbox user manual

Frequency Response

1-25

Frequency Normalization This toolbox uses the convent ion tha t un itfrequency is the Nyquist frequency, defined as ha lf the sampling frequency.The cutoff frequency parameter for a ll basic filt er design funct ions isnormalized by the Nyquist frequency. For a syst em with a 1000 Hz samplingfrequency, for example, 300 Hz is 300/500 = 0.6. To conver t normalizedfrequency to angula r frequency around the unit circle, mult iply by π. Toconver t normalized frequency back to Her t z, mult iply by ha lf the samplefrequency.

If you ca ll freqz with no outpu t a rguments, it au tomat ica lly plot s bothmagnitude versus frequency and phase versus frequency. For example, an in th-order But t erwor th lowpass filter with a cu toff frequency of 400 Hz, basedon a 2000 Hz sampling frequency, is

[b,a] = butter(9,400/1000);

Now calcula te the 256-poin t complex frequency response for th is filter , and plotthe magnitude and phase with a ca ll to freqz.

freqz(b,a,256,2000)

0 100 200 300 400 500 600 700 800 900 1000-1000

-800

-600

-400

-200

0

Frequency (Hertz)

Phas

e (d

egre

es)

0 100 200 300 400 500 600 700 800 900 1000-400

-300

-200

-100

0

100

Frequency (Hertz)

Mag

nitu

de R

espo

nse

(dB)

Page 46: MATLAB Signal Processing Toolbox user manual

1 Signal Processing Basics

1-26

freqz can a lso accept a vector of arbit ra ry frequency poin t s for use in thefrequency response ca lcu la t ion. For example,

w = linspace(0,pi);h = freqz(b,a,w);

ca lcu la t es the complex frequency response a t the frequency poin ts in w for thefilter defined by vector s b and a. The frequency poin ts can range from 0 to 2π.To specify a frequency vector tha t ranges from zero to your sampling frequency,include both the frequency vector and the sampling frequency va lue in thepa rameter list .

Analog Domainfreqs eva lua tes frequency response for an ana log filt er defined by two inputcoefficien t vectors b and a. It s opera t ion is similar to tha t of freqz; you canspecify a number of frequency poin ts to use (by defau lt , the funct ion uses 200),supply a vector of a rbit ra ry frequency poin t s, and plot the magnitude andphase response of the filter .

Magnitude and PhaseMATLAB provides funct ions to ext ract magnitude and phase from a frequencyresponse vector h. The funct ion abs retu rns the magnitude of the response;angle returns the phase angle in radians. To ext ract and plot the magnitudeand phase of a But terwor th filter .

[b,a] = butter(6,300/500); [h,w] = freqz(b,a,512,1000);m = abs(h); p = angle(h);semilogy(w,m);plot(w,p*180/pi)

0 100 200 300 40010-15

10-10

10-5

100

0 100 200 300 400-200

-100

0

100

200

Page 47: MATLAB Signal Processing Toolbox user manual

Frequency Response

1-27

The unwrap funct ion is a lso usefu l in frequency ana lysis. unwrap unwraps thephase to make it cont inuous across 360° phase discon t inu it ies by addingmult iples of ±360°, as needed. To see how unwrap is usefu l, design a 25th-orderlowpass FIR filter .

h = fir1(25,0.4);

Obta in the filt er ’s frequency response with freqz, and plot the phase indegrees.

[H,f] = freqz(h,1,512,2);plot(f,angle(H)*180/pi); grid

It is difficu lt to dist ingu ish the 360° jumps (an a r t ifact of the a rctangentfunct ion inside angle) from the 180° jumps tha t sign ify zeros in the frequencyresponse.

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

Page 48: MATLAB Signal Processing Toolbox user manual

1 Signal Processing Basics

1-28

Use unwrap t o elimina te the 360° jumps.

plot(f,unwrap(angle(H))*180/pi); grid

DelayThe group delay of a filt er is a measure of the average delay of the filter a s afunct ion of frequency. It is defined as the nega t ive fir st der iva t ive of a filt er ’sphase response. If the complex frequency response of a filter is H (ejω), then thegroup delay is

where θ is the phase angle of H (ejω). Compute group delay with

[gd,w] = grpdelay(b,a,n)

which retu rns the n-poin t group delay, , of the digita l filter specified by band a, eva lua ted a t the frequencies in vector w.

The phase delay of a filter is the nega t ive of phase divided 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

τg ω( )d θ ω( )dω---------------–=

τg ω( )

τp ω( )θ ω( )ω-----------–=

Page 49: MATLAB Signal Processing Toolbox user manual

Frequency Response

1-29

To plot both the group and phase delays of a syst em on the same graph .

[b,a] = butter(10,200/1000);gd = grpdelay(b,a,128);[h,f] = freqz(b,a,128,2000);pd = –unwrap(angle(h))*(2000/(2*pi))./f;plot(f,gd,'–',f,pd,'– –')axis([0 1000 –30 30])legend('Group Delay','Phase Delay')

0 200 400 600 800 1000−30

−20

−10

0

10

20

30Group DelayPhase Delay

Page 50: MATLAB Signal Processing Toolbox user manual

1 Signal Processing Basics

1-30

Zero-Pole AnalysisThe zplane funct ion plots poles and zeros of a linea r system. For example, asimple filt er with a 0 a t -1/2 and a complex pole pa ir a t and

is

zer = –0.5; pol = .9*exp(j*2*pi*[–0.3 .3]');

The zero-pole plot for the filt er is

zplane(zer,pol)

For a syst em in zero-pole form, supply column vector arguments z and p tozplane.

zplane(z,p)

For a syst em in t ransfer funct ion form, supply row vectors b and a asa rguments to zplane.

zplane(b,a)

In th is case zplane finds the root s of b and a using the roots funct ion and plot sthe resu lt ing zeros and poles.

0.9ej2π 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

Imag

inar

y pa

rt

Page 51: MATLAB Signal Processing Toolbox user manual

Zero-Pole Analysis

1-31

See “Linea r System Models” on page 1-32 for deta ils on zero-pole and t ransferfunct ion represen ta t ion of syst ems.

Page 52: MATLAB Signal Processing Toolbox user manual

1 Signal Processing Basics

1-32

Linear System ModelsThe Signa l Processing Toolbox provides severa l models for represent ing linea rt ime-inva r ian t systems. This flexibility let s you choose the represen ta t iona lscheme tha t best su it s your applica t ion and, with in the bounds of numer icstability, conver t freely to and from most other models. This sect ion provides abr ief overview of suppor t ed linea r system models and descr ibes how to workwith these models in MATLAB.

Discrete-Time System ModelsThe discrete-t ime system models a re represen ta t iona l schemes for digit a lfilter s. MATLAB suppor ts severa l discrete-t ime system models:

• Transfer funct ion• Zero-pole-ga in form• Sta te-space form• Par t ia l fract ion expansion• Second-order sect ion form• La t t ice st ructure form•Convolu t ion ma tr ices

Transfer FunctionThe transfer function is a basic z-domain representa t ion of a digit a l filter ,expressing the filter as a ra t io of two polynomia ls. It is the pr incipa ldiscrete-t ime model for th is toolbox. The t ransfer funct ion model descr ipt ionfor the z-t ransform of a digit a l filt er ’s difference equa t ion is

Here, the constan t s b(i) and a(i) a re the filt er coefficien t s, and the order of thefilter is the maximum of na and nb. In MATLAB, you store these coefficient s intwo vectors (row vectors by convent ion), one row vector for the numera tor andone for the denominator . See “F ilt er s and Transfer Funct ions” on page 1-15 formore deta ils on the t ransfer funct ion form.

Y z( ) b 1( ) b 2( )z 1– L b n b 1+( )z n b–+ + +a 1( ) a 2( )z 1– L a n a 1+( )z n a–+ + +-----------------------------------------------------------------------------------------X z( )=

Page 53: MATLAB Signal Processing Toolbox user manual

Linear System Models

1-33

Zero-Pole-GainThe factored or zero-pole-gain form of a t ransfer funct ion is

By conven t ion , MATLAB stores polynomia l coefficien t s in row vectors andpolynomia l root s in column vectors. In zero-pole-ga in form, therefore, the zeroand pole loca t ions for the numera tor and denomina tor of a t ransfer funct ionreside in column vectors. The factored t ransfer funct ion ga in k is a MATLABscalar .

The poly and roots funct ions conver t between polynomia l and zero-pole-ga inrepresenta t ions. For example, a simple IIR filt er is

b = [2 3 4];a = [1 3 3 1];

The zeros and poles of th is filter a re

q = roots(b)

q =

–0.7500 + 1.1990i–0.7500 – 1.1990i

p = roots(a)

p =

–1.0000–1.0000 + 0.0000i–1.0000 – 0.0000i

k = b(1)/a(1)

k =

2

H z( ) q z( )p z( )---------- k z q 1( )–( ) z q 2( )–( )Lz q n( )–( )

z p 1( )–( ) z p 2( )–( )Lz p n( )–( )-----------------------------------------------------------------------------= =

Page 54: MATLAB Signal Processing Toolbox user manual

1 Signal Processing Basics

1-34

Returning to the or igina l polynomia ls,

bb = k*poly(q)

bb =

2.0000 3.0000 4.0000

aa = poly(p)

aa =

1.0000 3.0000 3.0000 1.0000

Note tha t b and a in th is case represen t the t ransfer funct ion

For b = [2 3 4], the roots funct ion misses the zero for z equal to 0. In fact , itmisses poles and zeros for z equa l to 0 whenever the inpu t t ransfer funct ion hasmore poles than zeros, or vice versa . This is acceptable in most cases. Tocircumvent the problem, however , simply append zeros to make the vectors thesame length before using the roots funct ion , for example, b = [b 0].

State-SpaceIt is a lways possible to represen t a digita l filter , or a syst em of differenceequa t ions, as a set of fir st -order difference equat ions. In mat r ix or state-spaceform, you can wr ite the equa t ions as

where u is the input , x is the st a te vector , and y is t he ou tpu t . Forsingle-channel systems, A is an m-by-m matr ix where m is the order of the filt er ,B is a column vector , C is a row vector , and D is a sca la r . St a te-space nota t ion isespecia lly convenien t for mult ichannel syst ems where inpu t u and outpu t ybecome vectors, and B, C, and D become mat r ices.

Sta te-space represen ta t ion extends easily to the MATLAB environment . InMATLAB, A, B, C, and D are rect angular ar rays; MATLAB trea ts them asindividua l var iables.

H z( ) 2 3 z 1– 4z 2–+ +1 3 z 1– 3z 2– z 3–+ + +------------------------------------------------------ 2 z3 3z 2 4z+ +

z 3 3z 2 3z 1+ + +--------------------------------------------= =

x n 1+( ) A x n( ) B u n( )+=y n( ) Cx n( ) Du n( )+=

Page 55: MATLAB Signal Processing Toolbox user manual

Linear System Models

1-35

Taking the z-t ransform of the sta te-space equa t ions and combin ing them showsthe equiva lence of sta te-space and t ransfer funct ion forms.

Don’t be concerned if you a re not familia r with the sta te-space representa t ionof linear systems. Some of the filter design a lgor ithms use sta te-space forminterna lly but do not require any knowledge of sta te-space concepts to use themsuccessfu lly. If your applica t ions use sta te-space based signa l processingextensively, however , consu lt the Cont rol Syst em Toolbox for a comprehensivelibrary of sta te-space tools.

Partial Fraction Expansion (Residue Form)Each t ransfer funct ion a lso has a cor responding partial fraction expansion orresidue form represen ta t ion , given by

provided H (z) has no repea ted poles. Here, n is the degree of the denomina torpolynomia l of the ra t iona l t ransfer funct ion b(z)/a(z). If r is a pole of mult iplicitysr , then H (z) has t erms of the form

The residuez funct ion in the Signal Processing Toolbox conver ts t ransferfunct ions to and from the par t ia l fract ion expansion form. The “z” on the end ofresiduez st ands for z-doma in , or discrete domain. residuez retu rns the polesin a column vector p, the residues cor responding to the poles in a column vectorr, and any improper par t of the or igina l t ransfer funct ion in a row vector k.residuez determines tha t two poles are the same if the magnitude of theirdifference is smaller than 0.1 percen t of either of the poles’magnitudes.

Par t ia l fract ion expansion ar ises in signa l processing as one method of findingthe inverse z-t ransform of a t ransfer funct ion . For example, the par t ia l fract ionexpansion of

Y z( ) H z( )U z( )= where H z( ) C zI A–( ) 1– B D+=,

b z( )a z( )---------- r 1( )

1 p 1( )z 1––---------------------------- L

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

r j( )1 p j( )z 1––--------------------------- r j 1+( )

1 p j( )z 1––( )2----------------------------------- L

r j sr 1–+( )

1 p j( )z 1––( )s r------------------------------------+ + +

H z( ) 4– 8z 1–+1 6z 1– 8 z 2–+ +----------------------------------------=

Page 56: MATLAB Signal Processing Toolbox user manual

1 Signal Processing Basics

1-36

is

b = [—4 8];a = [1 6 8];[r,p,k] = residuez(b,a)

r =–128

p =–4–2

k =[]

cor responding to

To find the inverse z-t r ansform ofH (z), find the sum of the inverse z-t ransformsof the two addends of H (z), giving the causa l impulse response

To ver ify th is in MATLAB

imp = [1 0 0 0 0];resptf = filter(b,a,imp)

resptf =

–4 32 –160 704 –2944

respres = filter(r(1),[1 –p(1)],imp) + filter(r(2),[1 –p(2)],imp)

respres =

–4 32 –160 704 –2944

Second-Order Sections (SOS)Any t ransfer funct ion H (z) has a second-order sect ions represen ta t ion

H z( ) 12–1 4 z 1–+--------------------- 8

1 2z 1–+---------------------+=

h n( ) 12– 4–( )n 8 2–( )n+ n 0 1 2 …, , ,=,=

Page 57: MATLAB Signal Processing Toolbox user manual

Linear System Models

1-37

where L is the number of second-order sect ions tha t descr ibe the syst em.MATLAB represen t s the second-order sect ion form of a discrete-t ime system asan L -by-6 ar ray sos. Each row of sos conta ins a single second-order sect ion ,where the row elements are the three numera tor and three denomina torcoefficien t s tha t descr ibe the second-order sect ion .

There are an uncountable number of ways to represen t a filter in second-ordersect ion form. Through carefu l pa ir ing of the pole and zero pa ir s, order ing of thesect ions in the cascade, and mult iplica t ive sca ling of the sect ions, it is possibleto reduce quant iza t ion noise ga in and avoid over flow in some fixed-poin t filt erimplementa t ions. The funct ions zp2sos and ss2sos, descr ibed la ter in “LinearSystem Transformat ions,” per form pole-zero pair ing, sect ion sca ling, andsect ion order ing.

Lattice StructureFor a discrete N t h order a ll-pole or a ll-zero filter descr ibed by the polynomia lcoefficien t s a(n ), n = 1,2,…,N+1, there are N cor responding la t t ice st ructurecoefficien t s k (n ), n = 1,2,…,N . The parameters k (n ) a re a lso ca lled the reflection

H z( ) Hk z( )k 1=

L

∏b0 k b1 k z 1– b2 k z 2–+ +a0 k a1 k z 1– a2 k z 2–+ +----------------------------------------------------------

k 1=

L

∏= =

sos

b01 b11 b21 a01 a11 a21b02 b12 b22 a02 a12 a22M M M M M M

b0L b1L b2L a0L a1L a2L

=

Page 58: MATLAB Signal Processing Toolbox user manual

1 Signal Processing Basics

1-38

coefficien ts of the filter . Given these reflect ion coefficien ts, you can implementa discret e filter as

For a genera l pole-zero IIR filt er descr ibed by polynomia l coefficien ts a and b,there a re both la t t ice coefficien ts k (n ) for the denominator a and laddercoefficien t s v(n ) for the numerator b. The la t t ice/ladder filt er may beimplemented as

Σ

Σ

z -1

y(m)

k(1)

k(1)

Σ

Σ

k(n)

k(n)

. . .

. . . z -1

FIR Lat t ice F ilter

x(m)

x(m)

Σ

Σ y(m)

k(1)

–k(1)Σ

k(n)

–k(n). . .

. . .z -1 Σ z -1

IIR La t t ice F ilter

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)

Page 59: MATLAB Signal Processing Toolbox user manual

Linear System Models

1-39

The toolbox funct ion tf2latc accept s an FIR or IIR filter in polynomia l formand retu rns the cor responding reflect ion coefficien ts. An example IIR filt er inpolynomia l form is

a = [1.0000 0.6149 0.9899 0.0000 0.0031 –0.0082];

This filter ’s la t t ice (reflect ion coefficien t ) represen ta t ion is

k = tf2latc(a)

k =

0.30900.98000.00310.0081

–0.0082

The magnitude of the reflect ion coefficien ts provides an easy stability check fora filt er . If a ll the reflect ion coefficien t s cor responding to a polynomia l havemagnitude less than 1, a ll of tha t polynomia l’s roots are inside the unit circle.

The funct ion latc2tf ca lcu la t es the polynomia l coefficien ts for a filter from itsla t t ice (reflect ion) coefficien t s. Given the reflect ion coefficien t vector k(above),the cor responding polynomia l form is

a = latc2tf(k)

a =

1.0000 0.6149 0.9899 –0.0000 0.0031 –0.0082

The la t t ice or la t t ice/ladder coefficient s can be used to implement the filterusing the funct ion latcfilt.

Convolution MatrixIn signa l processing, convolving two vectors or ma tr ices is equ iva len t tofilt er ing one of the input operands by the other . This rela t ionship permits therepresenta t ion of a digit a l filter as a convolu tion m atrix.

Given any vector , t he toolbox convmtx funct ion genera t es a mat r ix whose innerproduct with another vector is equiva lent to the convolu t ion of the two vectors.The genera t ed matr ix represent s a digita l filt er tha t you can apply to any

Page 60: MATLAB Signal Processing Toolbox user manual

1 Signal Processing Basics

1-40

vector of appropr ia t e length; the inner dimension of the operands must agreeto compute the inner product .

The convolu t ion matr ix for a vector b, r epresen t ing the numera tor coefficien t sfor a digit a l filter , is

b = [1 2 3]; x = randn(3,1);C = convmtx(b',3)

C =

1 0 02 1 03 2 10 3 20 0 3

Two ways to convolve b with x are

y1 = C*x;y2 = conv(b,x);

Type th is example in to MATLAB; the resu lt s for y1 and y2 are equal.

Continuous-Time System ModelsThe cont inuous-t ime system models a re representa t iona l schemes for ana logfilter s. Many of the discret e-t ime syst em models descr ibed ea r lier a re a lsoappropr ia t e for the representa t ion of cont inuous-t ime systems:

• Sta te-space form• Par t ia l fract ion expansion• Transfer funct ion• Zero-pole-ga in form

It is possible to represent any system of linear t ime-invar ian t differen t ia lequa t ions as a set of fir st -order differen t ia l equat ions. In matr ix or state-spaceform, you can express the equa t ions as

x· A x B u+=y Cx Du+=

Page 61: MATLAB Signal Processing Toolbox user manual

Linear System Models

1-41

where u is a vector of nu inpu ts, x is an nx-element st a te vector , and y is a vectorof ny outpu ts. In MATLAB, store A, B, C, and D in separa t e rect angular ar rays.

An equ iva len t represen ta t ion of the sta te-space system is the Laplacet ransform transfer funct ion descr ipt ion

where

For single-inpu t , single-outpu t systems, th is form is given by

Given the coefficien t s of a Laplace t ransform t ransfer funct ion, residuedetermines the par t ia l fract ion expansion of the syst em. See the descr ipt ion ofresidue in the MATLAB Language Reference Manual for deta ils.

The factored zero-pole-ga in form is

As in the discret e-t ime case, MATLAB stores polynomia l coefficient s in rowvectors in descending powers of s. MATLAB stores polynomia l roots, or zerosand poles, in column vectors.

Linear System TransformationsThe Signa l Processing Toolbox provides a number of funct ions tha t conver tbetween the va r ious linear syst em models; see the reference descr ipt ion inChapter 6 for a complete descr ipt ion of each . You can use the following cha r t tofind an appropr ia te t ransfer funct ion : find the row of the model to conver t fromon the left side of the char t and the column of the model to conver t to on the topof the char t and read the funct ion name(s) a t the int er sect ion of the row andcolumn.

Y s( ) H s( )U s( )=

H s( ) C sI A–( ) 1– B D+=

H s( ) b s( )a s( )---------- b 1( )sn b b 2( )sn b 1– L b n b 1+( )+ + +

a 1( )sn a a 2( )sn a 1– L a n a 1+( )+ + +----------------------------------------------------------------------------------------------= =

H s( ) z s( )p s( )---------- k s z 1( )–( ) s z 2( )–( )Ls z n( )–( )

s p 1( )–( ) s p 2( )–( )Ls p n( )–( )-----------------------------------------------------------------------------= =

Page 62: MATLAB Signal Processing Toolbox user manual

1 Signal Processing Basics

1-42

Many of the toolbox filter design funct ions use these funct ions int erna lly. Forexample, the zp2ss funct ion conver ts the poles and zeros of an ana logprototype in to the sta t e-space form requ ired for crea t ion of a But terwor th ,Chebyshev, or ellipt ic filt er . Once in sta t e-space form, the filt er design funct ionper forms any required frequency t ransforma t ion , tha t is, it t r ansforms thein it ia l lowpass design into a bandpass, h ighpass, or bandstop filt er , or alowpass filter with the desired cutoff frequency. See Chapter 6 and thereference descr ipt ions of the individua l filt er design funct ions for more deta ils.

Transfer function

State- space

Zero-polegain

Partial fraction

Lattice filter

Second-order sections

Convolutionmatrix

Transfer function

tf2ss tf2zproots

residuezresidue

tf2latc convmtx

State-space ss2tf ss2zp ss2sos

Zero-pole gain

zp2tf poly

zp2ss zp2sos

Partial fraction

residuezresidue

Lattice filter latc2tf

Second-order sections

sos2tf sos2ss sos2zp

Convolutionmatrix

Page 63: MATLAB Signal Processing Toolbox user manual

Discrete Fourier Transform

1-43

Discrete Fourier TransformThe discret e Four ier t ransform, or DFT, is the pr imary tool of digita l signa lprocessing. The founda t ion of the Signa l Processing Toolbox is the Fast Four ierTransform (FFT), a method for comput ing the DFT with reduced execu t iont ime. Many of the toolbox funct ions (including z-domain frequency response,spect rum and cepst rum ana lysis, and some filter design and implementa t ionfunct ions) incorpora te the FFT.

MATLAB provides the funct ions fft and ifft to compute the discret e Four iert ransform and it s inverse, respect ively. For the input sequence x and it st ransformed version X (the discrete-t ime Four ier t ransform at equa lly spacedfrequencies around the unit circle), t he two funct ions implement therela t ionsh ips

In these equat ions, the ser ies subscr ipts begin with 1 inst ead of 0 because ofMATLAB’s vector indexing scheme, and

NOTE MATLAB uses a negat ive j for the fft funct ion . This is an engineer ingconvent ion ; physics and pure mathemat ics typica lly use a posit ive j.

fft, with a single input a rgument x, computes the DFT of the input vector ormat r ix. If x is a vector , fft computes the DFT of the vector ; if x is a rect angula ra r ray, fft computes the DFT of each ar ray column.

X k 1+( ) x n 1+( )Wnk n

n 0=

N 1–

∑=

x n 1+( ) 1N---- X k 1+( )Wn

k n–

k 0=

N 1–

∑=

WN ej– 2πN-------⎝ ⎠

⎛ ⎞

=

Page 64: MATLAB Signal Processing Toolbox user manual

1 Signal Processing Basics

1-44

For example, crea t e a t ime vector and signa l.

t = (0:1/99:1); % time vectorx = sin(2*pi*15*t) + sin(2*pi*40*t);% signal

The DFT of the signa l, and the magnitude and phase of the t ransformedsequence, a re then

y = fft(x); % Compute DFT of x.m = abs(y); p = unwrap(angle(y)); % mag. and phase

To plot the magnitude and phase

f = (0:length(y)–1)*99/length(y); % frequency vectorplot(f,m)set(gca,'XTick',[15 40 60 85]);plot(f,p*180/pi)set(gca,'XTick',[15 40 60 85]);

A second a rgument to fft specifies a number of poin t s n for the t ransform,represen t ing DFT length .

y = fft(x,n);

In th is case, fft pads the input sequence with zeros if it is shor t er than n, ort runca tes the sequence if it is longer than n. If n is not specified, it defau lt s tothe length of the inpu t sequence.

15 40 60 850

10

20

30

40

50

15 40 60 85-1500

-1000

-500

0

Page 65: MATLAB Signal Processing Toolbox user manual

Discrete Fourier Transform

1-45

Execut ion t ime for fft depends on the length n of the DFT it per forms:

• For any n t ha t is a power of two, fft uses the h igh-speed radix-2 a lgor ithm.This resu lt s in the fastest execut ion t ime. Addit iona lly, the a lgor ithm forpower of two n is h igh ly opt imized for rea l x, providing a 40% speed-up overthe complex case.

• For any composite number n tha t is not a power of two, fft uses a pr imefactor a lgor ithm. The speed of th is a lgor ithm depends on both the size of nand number of pr ime factors it has. Although 1013 and 1000 a re close inmagnitude, fft t r ansforms a sequence of length 1000 much more quicklythan a sequence of length 1013.

• For a pr ime number n, fft cannot use an FFT a lgor ithm, and insteadper forms the slower , computa t ion-in t ensive DFT direct ly.

The inverse discret e Four ier t ransform funct ion ifft a lso accept s an inputsequence and, opt iona lly, the number of desired point s for the t ransform. Trythe example below; the or igina l sequence x and the reconst ructed sequence areiden t ica l (with in rounding er ror ).

t = (0:1/255:1);x = sin(2*pi*120*t);y = real(ifft(fft(x)));

This toolbox also includes funct ions for the two-dimensiona l FFT and itsinverse, fft2 and ifft2. These funct ions are usefu l for two-dimensiona l signa lor image processing; see the reference descr ipt ions in Chapter 6 for deta ils.

It is somet imes convenient to rear range the outpu t of the fft or fft2 funct ionso the zero frequency componen t is a t the cen ter of the sequence. The MATLABfunct ion fftshiftmoves the zero frequency component to the cen ter of a vectoror mat r ix.

Page 66: MATLAB Signal Processing Toolbox user manual

1 Signal Processing Basics

1-46

ReferencesAlgor ithm development for the Signal Processing Toolbox has drawn heavilyupon the references list ed below. All a re recommended to the in terested readerwho needs to know more about signa l processing than is covered in th ismanual.

1 Crochiere, R.E ., and L.R. Rabiner .Multi-Rate S ignal Processing. EnglewoodCliffs, NJ : Pren t ice Ha ll, 1983. Pgs. 88-91.

2 IEEE. Program s for Digital S ignal Processing. IEEE Press. New York: J ohnWiley & Sons, 1979.

3 J ackson , L.B. Digital Filters and S ignal Processing. Th ird Ed. Boston:Kluwer Academic Publishers, 1989.

4 Kay, S.M.Modern S pectral Estim ation . Englewood Cliffs, NJ : Pren t ice Hall,1988.

5 Oppenheim, A.V., and R.W. Schafer . Discrete-T im e S ignal Processing.Englewood Cliffs, NJ : Prent ice Hall, 1989.

6 Parks, T.W., and C.S. Burrus. Digital Filter Design . New York: J ohn Wiley& Sons, 1987.

7 Pra t t ,W.K. Digital Im age Processing. New York: J ohn Wiley & Sons, 1991.

8 Perciva l, D.B., and A.T. Walden . S pectral Analysis for Physical Applications:Multitaper and Conven tional Univariate Techniques. Cambr idge:Cambr idge University Press, 1993.

9 Proakis, J .G., and D.G. Manolakis. Digital S ignal Processing: Principles,Algorithm s, and Applications. Upper Saddle River , NJ : Prent ice Hall, 1996.

10 Rabiner , L.R., and B. Gold. Theory and Application of Digital S ignalProcessing. Englewood Cliffs, NJ : Prent ice Hall, 1975.

11Welch , P .D. “The Use of Fast Four ier Transform for the Est imat ion of PowerSpect ra : A Method Based on Time Averaging Over Shor t , ModifiedPer iodograms.” IEEE Trans. Audio E lectroacoust . Vol. AU-15 (J une 1967).Pgs. 70-73.

Page 67: MATLAB Signal Processing Toolbox user manual

2

Filter Design

Filte r Requ irements and Spec ification . . . . . . . . . . . . . . . . 2-2

IIR Filte r Des ign . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-4Classica l IIR Filter Design Using Ana log Prototyping . . . . . . . . 2-6Compar ison of Classica l IIR Filt er Types . . . . . . . . . . . . . . . . . . 2-8

FIR Filte r Des ign . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-16Linear Phase Filter s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-17Windowing Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-18Mult iband FIR Filt er Design with Transit ion Bands . . . . . . . . 2-22Const ra ined Least Squares FIR Filter Design . . . . . . . . . . . . . 2-27Arbit ra ry-Response Filter Design . . . . . . . . . . . . . . . . . . . . . . . 2-31

Specia l Topic s in IIR Filte r Des ign . . . . . . . . . . . . . . . . . . . 2-37Analog Prototype Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-38Frequency Transformat ion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-38Filter Discret iza t ion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-41

Reference s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-45

Page 68: MATLAB Signal Processing Toolbox user manual

2 Filter Design

2-2

Filter Requirements and SpecificationThe Signal Processing Toolbox provides funct ions tha t suppor t a range of filterdesign methodologies. This chapter expla ins how to apply the filt er design toolsto Infin ite Im pulse Response (IIR) and Fin ite Im pulse Response (FIR) filterdesign problems.

The goa l of filter design is to per form frequency dependen t a ltera t ion of a da tasequence. A possible requ irement might be to remove noise above 30 Hz froma data sequence sampled a t 100 Hz. A more r igorous specifica t ion might ca ll fora specific amount of passband r ipple, stopband a t tenua t ion , or t ransit ionwidth . A very precise specifica t ion could ask to achieve the per formance goalswith the minimum filter order , or it could ca ll for an a rbit ra ry magnitudeshape, or it migh t require an FIR filt er .

F ilter design methods differ pr imar ily in how per formance is specified. For“loosely specified” requirement s, as in the fir st case above, a But t erwor th IIRfilter is oft en sufficien t . To design a fifth-order 30 Hz lowpass But terwor thfilter and apply it to the da ta in vector x,

[b,a] = butter(5,30/50);y = filter(b,a,x);

The second input a rgument to butter indica t es the cu toff frequency,normalized to ha lf the sampling frequency (the Nyquist frequency).

Frequency Normalization in the Signal Processing Toolbox All of thefilter design funct ions opera te with normalized frequencies, so they do notrequ ire the syst em sampling ra te as an ext ra input a rgument . This toolboxuses the convent ion tha t unit frequency is the Nyquist frequency, defined asha lf the sampling frequency. The norma lized frequency, therefore, is a lways inthe in terva l 0 ≤ f ≤ 1. For a system with a 1000 Hz sampling frequency, 300 Hzis 300/500 = 0.6. To conver t normalized frequency to angular frequencyaround the unit circle, mult iply by π. To conver t normalized frequency back toHer tz, mult iply by ha lf the sample frequency.

Page 69: MATLAB Signal Processing Toolbox user manual

Filter Requirements and Specification

2-3

More r igorous filter requirements t radit iona lly include passband r ipple (Rp, indecibels), stopband a t tenua t ion (Rs, in decibels), and t ransit ion width (Ws–Wp,in Her t z).

You can design But terwor th , Chebyshev type I, Chebyshev type II, and ellipt icfilt er s tha t meet th is type of per formance specifica t ion . The toolbox orderselect ion funct ions est imate the min imum filt er order tha t meets a given set ofrequirement s.

To meet specifica t ions with more r igid const ra in ts like linea r phase ora rbit ra ry filter shape, use the FIR and direct IIR filter design rou t ines.

10-1 100 1010

0.2

0.4

0.6

0.8

1

Frequency(rad/sec)

Mag

nitu

de

Page 70: MATLAB Signal Processing Toolbox user manual

2 Filter Design

2-4

IIR Filter DesignThe pr imary advantage of IIR filter s over FIR filter s is tha t they typica lly meeta given set of specifica t ions with a much lower filt er order than a cor respondingFIR filt er . Although IIR filter s have nonlinear phase, da ta processing withinMATLAB is commonly per formed “off-line,” tha t is, the en t ire da ta sequence isava ilable pr ior to filt er ing. This a llows for a noncausa l, zero-phase filt er ingapproach (via the filtfilt funct ion), which elimina tes the nonlinear phasedistor t ion of an IIR filter .

The classica l IIR filter s, But terwor th , Chebyshev types I and II, ellipt ic, andBessel, a ll approximate the idea l “br ickwa ll” filt er in differen t ways. Thistoolbox provides funct ions to crea te a ll these types of cla ssica l IIR filt er s in boththe analog and digita l domains (except Bessel, for which only the ana log caseis suppor ted), and in lowpass, h ighpass, bandpass, and bandstopconfigura t ions. For most filt er types, you can also find the lowest filt er ordertha t fit s a given filter specifica t ion in t erms of passband and stopbanda t t enua t ion , and t ransit ion width(s).

The direct filt er design funct ion yulewalk finds a filt er with magnituderesponse approximat ing a desired funct ion . This is one way to crea te amult iband bandpass filter .

You can a lso use the paramet r ic modeling or syst em ident ifica t ion funct ions todesign IIR filt ers. These funct ions a re discussed in the “Paramet r ic Modeling”sect ion of Chapter 4.

The genera lized But terwor th design funct ion maxflat is discussed in thesect ion “Genera lized But t erwor th F ilt er Design” on page 2-14.

The following table summar izes the va r ious filt er methods in the toolbox andlist s the funct ions ava ilable to implement these methods.

Page 71: MATLAB Signal Processing Toolbox user manual

IIR Filter Design

2-5

* See the System Identification Toolbox for an extensive collection of parametric modeling tools.

Method Description Functions

AnalogPrototyping

Using the poles and zeros ofa classica l lowpassprototype filter in thecont inuous (Laplace)domain, obta in a digit a lfilt er th rough frequencyt ransformat ion and filt erdiscret iza t ion .

Complete design funct ions:

besself, butter, cheby1, cheby2, ellip

Order est imat ion funct ions:

buttord, cheb1ord, cheb2ord, ellipord

Lowpass ana log prototype funct ions:

besselap, buttap, cheb1ap, cheb2ap,ellipap

Frequency t ransformat ion funct ions:

lp2bp, lp2bs, lp2hp, lp2lp

Filter discret iza t ion funct ions:

bilinear, impinvar

Direct Design Design digita l filterdirect ly in the discret edomain by approxima t ing apiecewise linea r magnituderesponse.

yulewalk

Paramet r icModeling*

Find a digita l filt er tha tapproximates a prescr ibedt ime or frequency domainresponse.

Time-domain modeling funct ions:

lpc, prony, stmcb

Frequency-domain modeling funct ions:

invfreqs, invfreqz

Genera lizedBut terwor thDesign

Design lowpassBut terwor th filter s withmore zeros than poles.

maxflat

Page 72: MATLAB Signal Processing Toolbox user manual

2 Filter Design

2-6

Classical IIR Filter Design Using Analog PrototypingThe pr incipa l IIR digita l filt er design technique th is toolbox provides is basedon the conversion of classica l lowpass ana log filters to their digita l equiva len ts.The following sect ions descr ibe how to design filt er s and summar ize thecha racter ist ics of the suppor t ed filter types. See “Specia l Topics in IIR FilterDesign” on page 2-37 for deta iled st eps on the filter design process.

Complete Classical IIR Filter DesignYou can easily crea te a filt er of any order with a lowpass, h ighpass, bandpass,or bandstop configura t ion using the filter design funct ions.

By defau lt , each of these funct ions returns a lowpass filt er ; you need onlyspecify the desired cu toff frequency Wn in normalized frequency (Nyquistfrequency = 1 Hz). For a h ighpass filt er , append the st r ing 'high' to thefunct ion’s parameter list . For a bandpass or bandstop filt er , specify Wn as atwo-element vector con ta in ing the passband edge frequencies, appending thest r ing 'stop' for the bandstop configura t ion .

Filter Type Design Function

But t erwor th [b,a] = butter(n,Wn,options)[z,p,k] = butter(n,Wn,options)[A,B,C,D] = butter(n,Wn,options)

Chebyshev type I [b,a] = cheby1(n,Rp,Wn,options)[z,p,k] = cheby1(n,Rp,Wn,options)[A,B,C,D] = cheby1(n,Rp,Wn,options)

Chebyshev type II [b,a] = cheby2(n,Rs,Wn,options)[z,p,k] = cheby2(n,Rs,Wn,options)[A,B,C,D] = cheby2(n,Rs,Wn,options)

Ellipt ic [b,a] = ellip(n,Rp,Rs,Wn,options)[z,p,k] = ellip(n,Rp,Rs,Wn,options)[A,B,C,D] = ellip(n,Rp,Rs,Wn,options)

Bessel (ana log only) [b,a] = besself(n,Wn,options)[z,p,k] = besself(n,Wn,options)[A,B,C,D] = besself(n,Wn,options)

Page 73: MATLAB Signal Processing Toolbox user manual

IIR Filter Design

2-7

Here are some example digita l filters.

[b,a] = butter(5,0.4); % lowpass Butterworth[b,a] = cheby1(4,1,[0.4 0.7]); % bandpass Chebyshev type I[b,a] = cheby2(6,60,0.8,'high'); % highpass Chebyshev type II[b,a] = ellip(3,1,60,[0.4 0.7],'stop'); % bandstop elliptic

To design an analog filt er , perhaps for simula t ion , use a t ra iling 's' andspecify cutoff frequencies in radians/second.

[b,a] = butter(5,.4,'s'); % analog Butterworth filter

All filter design funct ions return a filt er in the t ransfer funct ion ,zero-pole-ga in , or sta te-space linear system model represen ta t ion , dependingon how many outpu t arguments a re presen t .

NOTE All classica l IIR lowpass filters a re ill-condit ioned for ext remely lowcut -off frequencies. Therefore, inst ead of design ing a lowpass IIR filt er with avery nar row passband, it can be bet t er to design a wider passband anddecimate the input signa l.

Designing IIR Filters to Frequency Domain SpecificationsThis toolbox provides order select ion funct ions tha t ca lcu la te the min imumfilt er order tha t meet s a given set of requ irements.

These a re usefu l in conjunct ion with the filter design funct ions. Suppose youwant a bandpass filter with a passband from 1000 to 2000 Hz, stopbandssta r t ing 500 Hz away on either side, a 10 kHz sampling frequency, a t most 1 dB

Filter Type Order Estimation Function

But terwor th [n,Wn] = buttord(Wp,Ws,Rp,Rs)

Chebyshev type I [n,Wn] = cheb1ord(Wp, Ws, Rp, Rs)

Chebyshev type II [n,Wn] = cheb2ord(Wp, Ws, Rp, Rs)

Ellipt ic [n,Wn] = ellipord(Wp, Ws, Rp, Rs)

Page 74: MATLAB Signal Processing Toolbox user manual

2 Filter Design

2-8

of passband r ipple, and at lea st 60 dB of stopband at tenua t ion . To meet thesespecifica t ions with the butter funct ion .

[n,Wn] = buttord([1000 2000]/5000,[500 2500]/5000,1,60)

n = 12

Wn = 0.1951 0.4080

[b,a] = butter(n,Wn);

An ellipt ic filter tha t meets the same requirements is given by

[n,Wn] = ellipord([1000 2000]/5000,[500 2500]/5000,1,60)

n = 5

Wn = 0.2000 0.4000

[b,a] = ellip(n,1,60,Wn);

These funct ions a lso work with the other standard band configura t ions, as wellas for ana log filters; see Chapter 6 for deta ils.

Comparison of Classical IIR Filter TypesThe toolbox provides five differen t types of classica l IIR filt ers, each opt imal insome way. This sect ion shows the basic ana log prototype form for each andsummar izes major charact er ist ics.

Butterworth FilterThe But t erwor th filt er provides the best Taylor Ser ies approximat ion to theidea l lowpass filter response a t Ω = 0 and Ω = ∞; for any order N , the magnitudesqua red response has 2N –1 zero der iva t ives a t these loca t ions (maxim ally flat

Page 75: MATLAB Signal Processing Toolbox user manual

IIR Filter Design

2-9

a t Ω = 0 and Ω = ∞). Response is monotonic overa ll, decreasing smooth ly fromΩ = 0 to Ω = ∞. | H (jΩ)| = sqrt(1/2) a t Ω = 1.

Chebyshev Type I FilterThe Chebyshev type I filt er minimizes the absolu te difference between theidea l and actua l frequency response over the en t ire passband by incorpora t ingan equal r ipple of Rp dB in the passband. Stopband response is maxima lly fla t .The t ransit ion from passband to stopband is more rapid than for theBut t erwor th filter . | H (jΩ)| = 10-Rp/20 a t Ω = 1.

10-1 100 1010

0.2

0.4

0.6

0.8

1

Frequency(rad/sec)

Mag

nitu

de

10-1 100 1010

0.2

0.4

0.6

0.8

1

Frequency(rad/sec)

Mag

nitu

de

Page 76: MATLAB Signal Processing Toolbox user manual

2 Filter Design

2-10

Chebyshev Type II FilterThe Chebyshev type II filt er min imizes the absolu te difference between theidea l and actua l frequency response over the ent ire stopband, by incorpora t ingan equa l r ipple of Rs dB in the stopband. Passband response is maximally fla t .

The stopband does not approach zero as quickly as the type I filt er (and doesnot approach zero a t a ll for even-va lued n). The absence of r ipple in thepassband, however , is oft en an impor tan t advantage. | H (jΩ)| = 10-Rs/20 a tΩ = 1.

Elliptic FilterEllipt ic filt ers are equir ipple in both the passband and stopband. Theygenera lly meet filter requ irements with the lowest order of any suppor ted filtertype. Given a filt er order n, passband r ipple Rp in decibels, and stopband r ipple

10-1 100 1010

0.2

0.4

0.6

0.8

1

Frequency(rad/sec)

Mag

nitu

de

Page 77: MATLAB Signal Processing Toolbox user manual

IIR Filter Design

2-11

Rs in decibels, ellipt ic filter s minimize t ransit ion width . | H (jΩ)| = 10-Rp/20 a tΩ = 1.

Bessel FilterAnalog Bessel lowpass filt ers have maximally fla t group delay a t zerofrequency and reta in nea r ly constan t group delay across the en t ire passband.F iltered signa ls therefore main ta in their waveshapes in the passbandfrequency range. F requency mapped and digit a l Bessel filt er s, however , do nothave th is maxima lly fla t proper ty; this toolbox suppor ts on ly the analog casefor the complete Bessel filt er design funct ion .

10-1 100 1010

0.2

0.4

0.6

0.8

1

Frequency(rad/sec)

Mag

nitu

de

Page 78: MATLAB Signal Processing Toolbox user manual

2 Filter Design

2-12

Bessel filter s genera lly requ ire a h igher filter order than other filter s forsa t isfactory stopband at tenuat ion . | H (jΩ)| < a t Ω = 1 and decreases as nincreases.

NOTE The lowpass filter s shown above were crea t ed with the analogprototype funct ions besselap, buttap, cheb1ap, cheb2ap, and ellipap. Thesefunct ions find the zeros, poles, and gain of an order n analog filt er of theappropr ia t e type with cutoff frequency of 1 rad/sec. The complete filt er designfunct ions (besself, butter, cheby1, cheby2, and ellip) ca ll t he prototypingfunct ions as a fir st step in the design process. See “Specia l Topics in IIR FilterDesign” on page 2-37 for deta ils.

To crea te simila r plot s, use n = 5 and, a s needed, Rp = 0.5 and Rs = 20. Forexample, to crea t e the ellipt ic filter plot :

[z,p,k] = ellipap(5,0.5,20);w = logspace(–1,1,1000);h = freqs(k*poly(z),poly(p),w);semilogx(w,abs(h)), grid

1 2⁄

10-1 100 1010

0.2

0.4

0.6

0.8

1

Frequency(rad/sec)

Mag

nitu

de

Page 79: MATLAB Signal Processing Toolbox user manual

IIR Filter Design

2-13

Direct IIR Filter DesignThis toolbox uses the term direct m ethods to descr ibe t echniques for IIR designtha t find a filter based on specifica t ions in the discret e domain. Unlike theana log prototyping method, direct design methods are not const ra ined to thestandard lowpass, h ighpass, bandpass, or bandstop configura t ions. Rather ,these funct ions design filt er s with an arbit ra ry, perhaps mult iband, frequencyresponse. Th is sect ion discusses the yulewalk funct ion , which is in tendedspecifica lly for filter design; “Paramet r ic Modeling” in Chapter 4 discussesother methods tha t may a lso be considered direct , such as Prony’s method,Linea r Predict ion , the Steiglit z-McBr ide method, and inverse frequencydesign .

yulewalk designs recursive IIR digit a l filter s by fit t ing a specified frequencyresponse. yulewalk’s name reflects it s method for finding the filt er ’sdenomina tor coefficient s: it finds the inverse FFT of the idea l desired powerspect rum and solves the “modified Yule-Walker equat ions” using the resu lt ingau tocor rela t ion funct ion samples. The st a t ement

[b,a] = yulewalk(n,f,m)

retu rns row vectors b and a conta in ing the n+1 numera tor and denomina torcoefficien t s of the order n IIR filt er whose frequency-magnitude character ist icsapproximate those given in vector s f and m. f is a vector of frequency poin t sranging from 0 to 1, where 1 represen ts the Nyquist frequency. m is a vectorcon ta in ing the desired magnitude response a t the poin ts in f. f and m candescr ibe any piecewise linear shape magnitude response, including amult iband response. The FIR counterpar t of th is funct ion is fir2, which a lsodesigns a filt er based on an arbit ra ry piecewise linear magnitude response. See“FIR Filt er Design” on page 2-16 for deta ils.

Note tha t yulewalk does not accept phase informat ion , and no sta tements a remade about the opt imality of the resu lt ing filter .

Page 80: MATLAB Signal Processing Toolbox user manual

2 Filter Design

2-14

Design a mult iband filt er with yulewalk, and plot the desired and actua lfrequency response.

m = [0 0 1 1 0 0 1 1 0 0];f = [0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 1];[b,a] = yulewalk(10,f,m);[h,w] = freqz(b,a,128);plot(f,m,w/pi,abs(h))

Generalized Butterworth Filter DesignThe toolbox funct ion maxflat enables you to design genera lized But t erwor thfilter s, tha t is, But t erwor th filt er s with differ ing numbers of zeros and poles.This is desirable in some implementa t ions where poles a re more expensivecomputa t iona lly than zeros. maxflat is just like the butter funct ion , excepttha t it you can specify two orders (one for the numera tor and one for thedenomina tor ) instead of just one. These filter s are maxim ally flat. Th is meanstha t the result ing filt er is opt imal for any numera tor and denominator orders,with the maximum number of der iva t ives a t 0 and the Nyquist frequency ω=πboth set to 0.

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 10

0.2

0.4

0.6

0.8

1

1.2

Page 81: MATLAB Signal Processing Toolbox user manual

IIR Filter Design

2-15

For example, when the two orders are the same, maxflat is the same as butter.

[b,a] = maxflat(3,3,0.25)

b = 0.0317 0.0951 0.0951 0.0317

a = 1.0000 –1.4590 0.9104 -0.1978

[b,a] = butter(3,0.25)

b = 0.0317 0.0951 0.0951 0.0317

a = 1.0000 –1.4590 0.9104 -0.1978

However , maxflat is more versa t ile, because you can design a filt er with morezeros than poles.

[b,a] = maxflat(3,1,0.25)

b = 0.0950 0.2849 0.2849 0.0950

a = 1.0000 -0.2402

The th ird inpu t to maxfla t is the half-power frequency, a frequency between0 and 1 with a desired magnitude response of .

You can a lso design linea r phase filter s tha t have the maximally fla t proper tyusing the 'sym' opt ion .

maxflat(4,'sym',0.3)

ans = 0.0331 0.2500 0.4337 0.2500 0.0331

For complete deta ils of the maxflat a lgor ithm, see Selesn ick and Burrus [2].

1 2⁄

Page 82: MATLAB Signal Processing Toolbox user manual

2 Filter Design

2-16

FIR Filter DesignDigita l filters with fin it e-dura t ion impulse response (a ll-zero, or FIR filt ers)have both advantages and disadvantages compared to infin ite-dura t ionimpulse response (IIR) filter s.

FIR filt ers have the following pr imary advantages:

• They can have exact ly linear phase.• They are a lways st able.• The design methods are genera lly linear .• They can be rea lized efficien t ly in hardware.• The filt er sta r tup t ransien ts have finite dura t ion .

The pr imary disadvan tage of FIR filt er s is tha t they oft en require a muchhigher filt er order than IIR filter s to ach ieve a given level of per formance.Cor respondingly, the delay of these filter s is often much grea ter than for anequa l performance IIR filt er .

Method Description Functions

Windowing Apply window to t runca tedinverse Four ier t ransform ofdesired “br ickwall” filter

fir1,fir2,kaiserord

Mult ibandwithTransit ionBands

Equir ipple or lea st squaresapproach over sub-bands of thefrequency range

firls,remez,remezord

Const ra inedLeastSquares

Minimize squared in tegra ler ror over en t ire frequencyrange subject to maximumerror const ra in t s

fircls,fircls1

Page 83: MATLAB Signal Processing Toolbox user manual

FIR Filter Design

2-17

Linear Phase FiltersExcept for cremez, a ll of the FIR filter design funct ions design linea r phasefilt ers only. The filter coefficient s, or “taps,” of such filter s obey either an evenor odd symmet ry rela t ion . Depending on th is symmetry, and on whether theorder n of the filt er is even or odd, a linear phase filt er (stored in length n+1vector b) has cer ta in inheren t rest r ict ions on it s frequency response.

The phase delay and group delay of linea r phase FIR filter s are equa l andconstan t over the frequency band. For an order n linear phase FIR filter , t hegroup delay is n /2, and the filt ered signa l is simply delayed by n /2 t ime steps(and the magnitude of it s Four ier t ransform is sca led by the filt er ’s magnituderesponse). This proper ty preserves the wave shape of signa ls in the passband,tha t is, t here is no phase distor t ion .

The funct ions fir1, fir2, firls, remez, fircls, fircls1, and firrcos a lldesign type I and II linear phase FIR filter s by default . Both firls and remezdesign type III and IV linear phase FIR filters given a 'hilbert' or'differentiator' flag. cremez can design any type of linear phase filter , andnonlinea r phase filt ers a s well.

Arbit ra ryResponse

Arbit ra ry responses, includingnonlinea r phase and complexfilter s

cremez

RaisedCosine

Lowpass response withsmooth , sinusoida l t ransit ion

firrcos

Method Description Functions

Linear Phase Filter Type

Filter Order n Symmetry of Coefficients

Response H(f), f = 0

Response H(f), f = 1 (Nyquist)

Type I Even even: No rest r ict ion No rest r ict ion

Type II Odd No rest r ict ion H (1) = 0

Type III Even odd: H (0) = 0 H (1) = 0

Type IV Odd H (0) = 0 No rest r ict ion

b k( ) b n 2 k–+( ) k 1= … n 1+, , ,=

b k( ) b– n 2 k–+( ) k 1= … n 1+, , ,=

Page 84: MATLAB Signal Processing Toolbox user manual

2 Filter Design

2-18

NOTE Because the frequency response of a type II filt er is zero a t the Nyquistra te (“h igh” frequency), fir1 does not design type II h ighpass and bandstopfilter s. For odd-va lued n in these cases, fir1 adds 1 to the order and returns atype I filter.

Windowing MethodConsider the idea l, or “br ick-wall,” digita l lowpass filt er with a cutoff frequencyofω0 rad/sec. This filt er has magnitude 1 a t a ll frequencies with magnitude lessthan ω0, and magnitude 0 a t frequencies with magnitude between ω0 and π. It simpulse response sequence h (n ) is

This filt er is not implementable since it s impulse response is infin it e andnoncausa l. To crea te a fin ite-dura t ion impulse response, t runca te it byapplying a window. By reta in ing the cent ra l sect ion of impulse response in th ist runca t ion , you obta in a linear phase FIR filter . For example, a length 51 filt erwith a lowpass cutoff frequency ω0 of 0.4π rad/sec is

b = 0.4*sinc(0.4*(–25:25));

The window applied here is a simple rect angular or “boxcar” window. ByParseva l’s theorem, th is is the length 51 filter tha t best approximates the idea l

h n( ) 12π------ H ω( )ejωn ωd

π–

π

∫12π------ ejωn ωd

ω0–

ω0

∫ω0π-------sinc

ω0π-------n( )= = =

Page 85: MATLAB Signal Processing Toolbox user manual

FIR Filter Design

2-19

lowpass filt er , in the in t egra t ed least squa res sense. To view its frequencyresponse:

[H,w] = freqz(b,1,512,2);plot(w,abs(H)), grid

Note the r inging and r ipples in the response, especia lly near the band edge.This “Gibbs effect” does not vanish as the filter length increases, but anonrectangula r window reduces it s magnitude. Mult iplica t ion by a window in

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 10

0.2

0.4

0.6

0.8

1

1.2Truncated Sinc Lowpass FIR Filter

Normalized Frequency (Nyquist == 1)

Mag

nitu

de R

espo

nse

Page 86: MATLAB Signal Processing Toolbox user manual

2 Filter Design

2-20

the t ime domain causes a convolu t ion or smooth ing in the frequency domain .Apply a length 51 Hamming window to the filt er .

b = b.*hamming(51)';[H,w] = freqz(b,1,512,2);plot(w,abs(H)), grid

As you can see, th is grea t ly reduces the r inging. This improvement is a t theexpense of t ransit ion width (the windowed version takes longer to ramp frompassband to stopband) and opt ima lity (the windowed version does notmin imize the in t egra t ed squared er ror ).

The funct ions fir1 and fir2 a re based on th is windowing process. Given afilter order and descr ipt ion of an idea l desired filter , these funct ions retu rn awindowed inverse Four ier t ransform of tha t idea l filt er . Both use a Hammingwindow by default , bu t they accept any window funct ion . See the “Windows”sect ion of Chapter 4 for an overview of windows and their proper t ies.

Standard Band FIR Filter Design: fir1fir1 implements the classica l method of windowed linea r phase FIR digita lfilter design . It resembles the IIR filter design funct ions in tha t it is formula t edto design filter s in st andard band configura t ions: lowpass, bandpass, h ighpass,and bandstop.

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 10

0.2

0.4

0.6

0.8

1

1.2

Normalized Frequency (Nyquist == 1)

Mag

nitu

de R

espo

nse

Hamming Windowed Truncated SINC LP FIR Filter

Page 87: MATLAB Signal Processing Toolbox user manual

FIR Filter Design

2-21

The sta tement s

n = 50;Wn = 0.4;b = fir1(n,Wn);

crea te row vector b conta in ing the coefficien ts of the order nHamming-windowed filt er . Th is is a lowpass, linea r phase FIR filter with cu tofffrequency Wn. Wn is a number between 0 and 1, where 1 cor responds to theNyquist frequency, ha lf the sampling frequency. (Unlike other methods, hereWn cor responds to the 6 dB point .) For a h ighpass filter , simply append thest r ing 'high' to the funct ion’s parameter list . For a bandpass or bandstopfilt er , specify Wn as a two-element vector con ta in ing the passband edgefrequencies; append the st r ing 'stop' for the bandstop configura t ion .

b = fir1(n,Wn,window) uses the window specified in column vector window forthe design . The vector window must be n+1 elements long. If you do not specifya window, fir1 applies a Hamming window.

Kaiser Window Order Estimation. The kaiserord funct ion est imates the filt erorder , cu toff frequency, and Kaiser window beta parameter needed to meet agiven set of specifica t ions. Given a vector of frequency band edges and acorresponding vector of magnitudes, as well as maximum allowable r ipple,kaiserord retu rns appropr ia t e input parameters for the fir1 funct ion . Fordeta ils on kaiserord, see the reference descr ipt ion in Chapter 6.

Multiband FIR Filter Design: fir2The funct ion fir2 a lso designs windowed FIR filters, bu t with an a rbit ra r ilyshaped piecewise linear frequency response. This is in cont rast to fir1, whichonly designs filt ers in standa rd lowpass, h ighpass, bandpass, and bandstopconfigura t ions.

The commands

n = 50;f = [0 .4 .5 1];m = [1 1 0 0];b = fir2(n,f,m);

retu rn row vector b conta in ing the n+1 coefficien t s of the order n FIR filterwhose frequency-magnitude charact er ist ics ma tch those given by vectors f andm. f is a vector of frequency point s ranging from 0 to 1, where 1 represen ts the

Page 88: MATLAB Signal Processing Toolbox user manual

2 Filter Design

2-22

Nyquist frequency. m is a vector conta in ing the desired magnitude response a tthe poin t s specified in f. (The IIR counterpar t of th is funct ion is yulewalk,which a lso designs filt ers based on a rbit ra ry piecewise linear magnituderesponses. See “IIR Filter Design” for deta ils.)

Multiband FIR Filter Design with Transition BandsThe firls and remez funct ions provide a more genera l means of specifying theidea l desired filter than the fir1 and fir2 funct ions. These funct ions designHilber t t ransformers, differen t ia tors, and other filter s with odd symmet r iccoefficien t s (type III and type IV linear phase). They a lso let you includet ransit ion or “don’t ca re” regions in which the er ror is not min imized, andper form band dependent weigh t ing of the min imiza t ion .

firls is an extension of the fir1 and fir2 funct ions in tha t it min imizes thein tegra l of the square of the er ror between the desired frequency response andthe actua l frequency response.

remez implements the Pa rks-McClellan a lgor ithm, which uses the Remezexchange a lgor ithm and Chebyshev approxima t ion theory to design filter s withopt imal fit s between the desired and actua l frequency responses. The filt ers areopt imal in the sense tha t they min imize the maximum error between thedesired frequency response and the actua l frequency response; they aresomet imes ca lled m inim ax filter s. F ilter s designed in th is way exhibit anequir ipple behavior in their frequency response, and hence a re a lso known asequiripple filter s. The Parks-McClellan FIR filter design a lgor ithm is perhapsthe most popular and widely used FIR filter design methodology.

The syntax for firls and remez is the same; the only difference is theirmin imiza t ion schemes. The next example shows how filter s designed withfirls and remez reflect these differen t schemes.

Basic ConfigurationsThe defau lt mode of opera t ion of firls and remez is to design type I or type IIlinear phase filter s, depending on whether the order you desire is even or odd,respect ively. A lowpass example with approxima te amplitude 1 from 0 to 0.4Hz, and approximate amplitude 0 from 0.5 to 1.0 Hz is

n = 20; % filter orderf = [0 .4 .5 1]; % frequency band edgesa = [1 1 0 0]; % desired amplitudesb = remez(n,f,a);

Page 89: MATLAB Signal Processing Toolbox user manual

FIR Filter Design

2-23

From 0.4 to 0.5 Hz, remez per forms no er ror minimiza t ion; this is a t ransit ionband or “don’t care” region . A transit ion band minimizes the er ror more in thebands tha t you do care abou t , a t the expense of a slower t ransit ion ra te. In th isway, these types of filt er s have an inheren t t r ade-off simila r to FIR design bywindowing.

To compare least squares to equir ipple filt er design , use firls t o crea t e asimila r filt er .

bb = firls(n,f,a);

and compare their frequency responses:

[H,w]=freqz(b);[HH,w]=freqz(bb);plot(w/pi,abs(H),w/pi,abs(HH),'--'), grid

You can see tha t the filt er designed with remez exh ibit s equ ir ipple behavior .Also note tha t the firls filter has a bet t er response over most of the passbandand stopband, but a t the band edges (f = 0.4 and f = 0.5), the response isfu r ther away from the idea l than the remez filter . Th is shows tha t the remezfilt er ’s maxim um er ror over the pass- and stopbands is smaller and, in fact , itis the smallest possible for th is band edge configura t ion and filter length .

Think of frequency bands as lines over shor t frequency in terva ls. remez andfirls use th is scheme to represen t any piecewise linea r desired funct ion with

10-1 100 1010

0.2

0.4

0.6

0.8

1

Frequency(rad/sec)

Mag

nitu

de

Page 90: MATLAB Signal Processing Toolbox user manual

2 Filter Design

2-24

any t ransit ion bands. firls and remez design lowpass, h ighpass, bandpass,and bandstop filters; a bandpass example is

f = [0 0.3 0.4 0.7 0.8 1]; % band edges in pairsa = [0 0 1 1 0 0]; % bandpass filter amplitude

Technica lly, these f and a vector s define five bands:

• Two stopbands, from 0.0 to 0.3 and from 0.8 to 1.0•A passband from 0.4 to 0.7• Two transit ion bands, from 0.3 to 0.4 and from 0.7 to 0.8

Example highpass and bandstop filt er s are

f = [0 0.7 0.8 1]; % band edges in pairsa = [0 0 1 1]; % highpass filter amplitude

f = [0 0.3 0.4 0.5 0.8 1]; % band edges in pairsa = [1 1 0 0 1 1]; % bandstop filter amplitude

An example mult iband bandpass filt er is

f = [0 0.1 0.15 0.25 0.3 0.4 0.45 0.55 0.6 0.7 0.75 0.85 0.9 1];a = [1 1 0 0 1 1 0 0 1 1 0 0 1 1];

Another possibility is a filt er tha t has as a t ransit ion region the line connect ingthe passband with the stopband; th is can help cont rol “runaway” magnituderesponse in wide t ransit ion regions:

f = [0 0.4 0.42 0.48 0.5 1];a = [1 1 0.8 0.2 0 0]; % passband,linear transition,stopband

The Weight VectorBoth firls and remez a llow you to place more or less emphasis on min imizingthe er ror in cer ta in frequency bands rela t ive to others. To do th is, specify aweight vector following the frequency and amplitude vectors. An example

Page 91: MATLAB Signal Processing Toolbox user manual

FIR Filter Design

2-25

lowpass equir ipple filt er with 10 t imes less r ipple in the stopband than thepassband is

n = 20; % filter orderf = [0 0.4 0.5 1]; % frequency band edgesa = [1 1 0 0]; % desired amplitudesw = [1 10]; % weight vectorb = remez(n,f,a,w);

A lega l weight vector is a lways half the length of the f and a vectors; there mustbe exact ly one weight per band.

Anti-Symmetric Filters / Hilbert TransformersWhen ca lled with a t ra iling 'h' or 'Hilbert' opt ion , remez and firls designFIR filt er s with odd symmet ry, tha t is, t ype III (for even order ) or type IV (forodd order) linea r phase filt ers. An idea l Hilber t t ransformer has th isan t i-symmetry proper ty and an amplitude of 1 across the ent ire frequencyrange. Try the following approxima te Hilber t t ransformers:

b = remez(21,[0.05 1],[1 1],'h'); % highpass Hilbertbb = remez(20,[0.05 0.95],[1 1],'h'); % bandpass Hilbert

You can find the delayed Hilber t t ransform of a signa l x by passing it throughthese filters:

Fs = 1000; % sampling frequencyt = (0:1/Fs:2)'; % two second time vectorx = sin(2*pi*300*t); % 300 Hz sine wave example signalxh = filter(bb,1,x); % Hilbert transform of x

0 0.25 0.5 0.75 10

0.2

0.4

0.6

0.8

1

Frequency (Normalized)

Bandpass Hilbert

0 0.25 0.5 0.75 10

0.2

0.4

0.6

0.8

1

Frequency (Normalized)

Highpass Hilbert

Page 92: MATLAB Signal Processing Toolbox user manual

2 Filter Design

2-26

The analyt ic signa l cor responding to x is the complex signa l tha t has x as it srea l par t and the Hilber t t ransform of x as it s imagina ry pa r t . For th is FIRmethod (an a lterna t ive to the hilbert funct ion), you must delay x by half thefilter order to crea t e the ana lyt ic signa l.

xd = [zeros(10,1); x(1:length(x)–10)]; % delay 10 samplesxa = xd + j*xh; % analytic signal

This method does not work direct ly for filt er s of odd order , which requ ire anonin teger delay. In th is case, the hilbert funct ion , descr ibed in the“Specia lized Transforms” sect ion in Chapter 4, est imates the ana lyt ic signa l.Alterna t ively, use the resample funct ion to delay the signa l by a nonin tegernumber of samples.

DifferentiatorsDifferent ia t ion of a signa l in the t ime domain is equiva lent to mult iplica t ion ofthe signa l’s Four ier t ransform by an imaginary ramp funct ion . Tha t is, todifferent ia t e a signa l, pass it t hrough a filter tha t has a response H (w ) = jw .Approximate the idea l different ia tor (with a delay) using remez or firls witha 'd' or 'differentiator' opt ion .

b = remez(21,[0 1],[0 pi*Fs],'d');

To obta in the cor rect der iva t ive, sca le by pi*Fs rad/sec, where Fs is thesampling frequency in Her tz. For a type III filt er , t he differen t ia t ion bandshould stop shor t of the Nyquist frequency, and the amplitude vector mustreflect tha t change to ensure the cor rect slope.

bb = remez(20,[0 0.9],[0 0.9*pi*Fs],'d');

In the 'd'mode, remezweights the er ror by 1/w in nonzero amplitude bands tominimize the maximum relative er ror . firls weights the er ror by (1/w )2 innonzero amplitude bands in the 'd' mode.

Page 93: MATLAB Signal Processing Toolbox user manual

FIR Filter Design

2-27

The magnitude response plots for the differen t ia tors shown above are

Constrained Least Squares FIR Filter DesignThe Const ra ined Least Squa res (CLS) FIR filt er design funct ions implement atechnique tha t enables you to design FIR filt ers without explicit ly defin ing thet ransit ion bands for the magnitude response. The abilit y to omit thespecifica t ion of t ransit ion bands is usefu l in severa l situa t ions. For example, itmay not be clear where a r igidly defined t ransit ion band should appear if noiseand signa l informat ion appea r together in the same frequency band. Simila r ly,it may make sense to omit the specifica t ion of t ransit ion bands if they appea ron ly to cont rol the resu lt s of Gibbs phenomena tha t appear in the filter ’sresponse. See Selesnick, Lang, and Burrus [2] for discussion of th is method.

Inst ead of defin ing passbands, stopbands, and t ransit ion regions, the CLSmethod accept s a cu toff frequency (for the h ighpass, lowpass, bandpass, orbandstop cases), or passband and stopband edges (for mult iband cases), for thedesired response. In th is way, the CLS method defines t ransit ion regionsimplicit ly, ra ther than explicit ly.

The key fea ture of the CLS method is tha t it enables you to define upper andlower thresholds tha t conta in the maximum allowable r ipple in the magnituderesponse. Given th is const ra in t , t he t echn ique applies the lea st squa re er rormin imiza t ion techn ique over the frequency range of the filt er ’s response,instead of over specific bands. The er ror min imiza t ion includes any areas ofdiscont inuity in the idea l, “br ick wa ll” response. An addit iona l benefit is tha t

0 100 200 300 400 5000

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)

Page 94: MATLAB Signal Processing Toolbox user manual

2 Filter Design

2-28

the technique enables you to specify arbit ra r ily sma ll peaks resu lt ing fromGibbs’ phenomena .

There a re two toolbox funct ions tha t implement th is design techn ique.

For deta ils on the ca lling syn tax for these funct ions, see their referencedescr ipt ions in Chapter 6.

Basic Lowpass and Highpass CLS Filter DesignThe most basic of the CLS design funct ions, fircls1, uses th is technique todesign lowpass and highpass FIR filt er s. As an example, consider design ing afilter with order 61 impulse response and cutoff frequency of 0.3 (normalized).Fur ther , define the upper and lower bounds tha t const ra in the design processas:

•Maximum passband devia t ion from 1 (passband r ipple) of 0.02.•Maximum stopband devia t ion from 0 (stopband r ipple) of 0.008.

Description Function

Const ra ined least square mult iband FIR filter design . fircls

Const ra ined least square filter design for lowpass andhighpass linear phase filter s

fircls1

0 ds = 0.0081dp = 0.02

Page 95: MATLAB Signal Processing Toolbox user manual

FIR Filter Design

2-29

To approach th is design problem using fircls1

n = 61;wo = 0.3;dp = 0.02;ds = 0.008;h = fircls1(n,wo,dp,ds,'plot');

Multiband CLS Filter Designfircls uses the same technique to design FIR filter s with a desired piecewiseconstan t magnitude response. In th is case, you can specify a vector of bandedges and a cor responding vector of band amplitudes. In addit ion , you canspecify the maximum amount of r ipple for each band.

For example, assume the specifica t ions for a filter ca ll for :

• From 0 to 0.3 (norma lized): amplitude 0, upper bound 0.005, lowerbound -0.005

• From 0.3 to 0.5: amplitude 0.5, upper bound 0.51, lower bound 0.49• From 0.5 to 0.7: amplitude 0, upper bound 0.03, lower bound -0.03• From 0.7 to 0.9: amplitude 1, upper bound 1.02, lower bound 0.98• From 0.9 to 1: amplitude 0, upper bound 0.05, lower bound -0.05

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-0.2

0

0.2

0.4

0.6

0.8

1

Page 96: MATLAB Signal Processing Toolbox user manual

2 Filter Design

2-30

Design a CLS filter with impulse response order 129 tha t meet s thesespecifica t ions.

n = 129;f = [0 0.3 0.5 0.7 0.9 1];a = [0 0.5 0 1 0];up = [0.005 0.51 0.03 1.02 0.05];lo = [–0.005 0.49 –0.03 0.98 –0.05];h = fircls(n,f,a,up,lo,'plot');

Weighted CLS Filter DesignWeighted CLS filt er design lets you design lowpass or highpass FIR filt ers withrela t ive weight ing of the er ror minimiza t ion in each band. The fircls1funct ion enables you to specify the passband and stopband edges for the lea stsqua res weigh t ing funct ion , as well as a constan t k tha t specifies the ra t io ofthe stopband to passband weigh t ing.

For example, consider specifica t ions tha t ca ll for an FIR filter with impulseresponse order of 55 and cutoff frequency of 0.3 (norma lized). Also assumemaximum allowable passband r ipple of 0.02 and maximum allowable stopbandripple of 0.004. In addit ion , add weight ing requirement s:

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-0.2

0

0.2

0.4

0.6

0.8

1

1.2

Page 97: MATLAB Signal Processing Toolbox user manual

FIR Filter Design

2-31

• Passband edge for the weigh t funct ion of 0.28 (normalized)• Stopband edge for the weigh t funct ion of 0.32•Weight er ror min imiza t ion 10 t imes as much in the stopband as in thepassband

To approach th is using fircls1:

n = 55;wo = 0.3;dp = 0.02;ds = 0.004;wp = 0.28;ws = 0.32;k = 10;h = fircls1(n,wo,dp,ds,wp,ws,k,'plot');

Arbitrary-Response Filter DesignThe cremez filt er design funct ion provides a tool for design ing FIR filter s witharbit ra ry complex responses. It differ s from the other filter design funct ions inhow the frequency response of the filt er is specified: it accepts the name of afunct ion which returns the filt er response ca lcu la t ed over a gr id of frequencies.This capability makes cremez a h igh ly versa t ile and powerfu l t echn ique forfilt er design .

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-0.2

0

0.2

0.4

0.6

0.8

1

Page 98: MATLAB Signal Processing Toolbox user manual

2 Filter Design

2-32

This design technique may be used to produce nonlinear -phase FIR filt ers,a symmetr ic frequency-response filt er s (with complex coefficien t s), or moresymmetr ic filt er s with custom frequency responses.

The design a lgor ithm opt im izes the Chebyshev (or min imax) er ror using anextended Remez-exchange a lgor ithm for an in it ia l est imate. If th is exchangemethod fa ils to obta in the opt imal filter , the a lgor ithm switches to anascen t -descen t a lgor ithm tha t takes over to fin ish the convergence to theopt imal solu t ion .

For deta ils on the ca lling syn tax for cremez, see the reference descr ipt ion inChapter 6.

Multiband Filter DesignConsider a mult iband filter with the following specia l frequency-domaincha racter ist ics:

A linear -phase mult iband filter may be designed using the predefinedfrequency-response funct ion multiband, as follows.

b = cremez(38, [–1 –0.5 –0.4 0.3 0.4 0.8], ... {’multiband’, [5 1 2 2 2 1]}, [1 10 5]);

For the specific case of a mult iband filt er , we can use a shorthand filter designnota t ion simila r to the syntax for remez:

b = cremez(38,[–1 –0.5 –0.4 0.3 0.4 0.8], ... [5 1 2 2 2 1], [1 10 5]);

As with remez, a vector of band edges is passed to cremez. This vector definesthe frequency bands over which opt imiza t ion is per formed; note tha t there a retwo transit ion bands, from -0.5 to -0.4 and from 0.3 to 0.4.

Band Amplitude Optimization Weighting

[-1 -0.5] [5 1] 1

[-0.4 +0.3] [2 2] 10

[+0.4 +0.8] [2 1] 5

Page 99: MATLAB Signal Processing Toolbox user manual

FIR Filter Design

2-33

In either case, the frequency response is obta ined and plot t ed using linearsca le.

[h,w] = freqz(b,1,512,’whole’);plot(w/pi–1,fftshift(abs(h)));

Note tha t the frequency response has been ca lcu la t ed over the en t irenormalized frequency range [-1 +1] by passing the opt ion 'whole' t o freqz. Inorder to plot the nega t ive frequency informat ion in a na tura l way, the responsehas been “wrapped,” just as FFT data is, using fftshift.

-1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 11

1.5

2

2.5

3

3.5

4

4.5

5

Normalized Frequency

Mag

nitu

de R

espo

nse

Page 100: MATLAB Signal Processing Toolbox user manual

2 Filter Design

2-34

The filter response for th is mult iband filt er is complex, which is expectedbecause of the asymmetry in the frequency domain . The filt er response is

Filter Design with Reduced DelayConsider the design of a 62-t ap lowpass filt er with a ha lf-Nyquist cu toff. If wespecify a negat ive offset va lue to the lowpass filt er design funct ion , the groupdelay offset for the design is significant ly less than tha t obta ined for a standa rdlinear -phase design . Th is filter design may be computed as follows.

b = cremez(61, [0 0.5 0.55 1], {'lowpass', –16});

0 5 10 15 20 25 30 35 40-0.5

0

0.5

1

1.5

2

2.5

Rea

l Par

t

0 5 10 15 20 25 30 35 40-0.2

0

0.2

Imag

Par

t

Page 101: MATLAB Signal Processing Toolbox user manual

FIR Filter Design

2-35

The resu lt ing magnitude response is

[h,w] = freqz(b,1,512,'whole');plot(w/pi–1,fftshift(abs(h)));

The group delay of the filt er revea ls tha t the offset has been reduced fromN/2=30.5 to N/2–16=14.5. Now, however , the group delay is no longer fla t inthe passband region (plot ted over the normalized frequency range 0 to 0.5 forcla r ity).

-1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 10

0.2

0.4

0.6

0.8

1

1.2

1.4

Normalized Frequency

Mag

nitu

de R

espo

nse

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)

Gro

up d

elay

(in

sam

ples

)

Page 102: MATLAB Signal Processing Toolbox user manual

2 Filter Design

2-36

If we compare th is nonlinear -phase filter to a linear -phase filt er tha t hasexact ly 14.5 samples of group delay, the resu lt ing filt er is of order 2*14.5 or 29.Using b = cremez(29,[0 0.5 0.55 1],'lowpass'), the passband andstopband r ipple is much grea ter for the order 29 filt er . These compar isons canassist you in deciding which filt er is more appropr ia t e for a specific applica t ion.

Page 103: MATLAB Signal Processing Toolbox user manual

Special Topics in IIR Filter Design

2-37

Special Topics in IIR Filter DesignThe classic IIR filter design technique finds an ana log lowpass filter with cutofffrequency of 1, t ransla tes th is “prototype” filter to the desired bandconfigura t ion , then t ransforms the filt er to the digita l domain . The toolboxprovides funct ions for each step of th is process.

The butter, cheby1, cheby2, and ellip funct ions are sufficien t for manydesign problems, and the lower level funct ions a re genera lly not needed. But ifyou do have an applica t ion where you need to t ransform the band edges of anana log filt er , or discret ize a ra t iona l t ransfer funct ion , th is sect ion descr ibestools to do so.

Classical IIR Filter Design

Analog Lowpass Prototype Creation Frequency Transformation Discretizationbuttapellipap

cheb1apcheb2ap

besselap lp2lplp2bp

lp2hplp2bs

bilinearimpinvar

butter cheby1 cheby2 ellip besself

Minimum Order Computation for Classical IIR Filter Designbuttord cheb1ord cheb2ord ellipord

Complete Design

Page 104: MATLAB Signal Processing Toolbox user manual

2 Filter Design

2-38

Analog Prototype DesignThis toolbox provides a number of funct ions to crea t e lowpass ana log prototypefilter s with cutoff frequency of 1, the fir st step in the classica l approach to IIRfilter design . The table below summar izes the ana log prototype designfunct ions for each suppor ted filt er type; plots for each type a re shown in the“IIR Filter Design” sect ion above.

Frequency TransformationThe second step in the ana log prototyping design techn ique is the frequencyt ransformat ion of a lowpass prototype. The toolbox provides a set of funct ionsto t ransform analog lowpass prototypes (with cutoff frequency of 1 rad/sec) in tobandpass, h ighpass, bandstop, and lowpass filt ers of the desired cutofffrequency.

Filter Type Analog Prototype Function

Bessel [z,p,k] = besselap(n)

But t erwor th [z,p,k] = buttap(n)

Chebyshev type I [z,p,k] = cheb1ap(n,Rp)

Chebyshev type II [z,p,k] = cheb2ap(n,Rs)

Ellipt ic [z,p,k] = ellipap(n,Rp,Rs)

Page 105: MATLAB Signal Processing Toolbox user manual

Special Topics in IIR Filter Design

2-39

As shown, a ll of the frequency t ransformat ion funct ions can accept two linearsystem models: t r ansfer funct ion and sta t e-space form. For the bandpass andbandstop cases

and

where ω1 is the lower band edge and ω2 is the upper band edge.

The frequency t ransformat ion funct ions per form frequency va r iablesubst itu t ion. In the case of lp2bp and lp2bs, t h is is a second-ordersubst itu t ion, so the outpu t filter is twice the order of the inpu t . For lp2lp andlp2hp, the ou tput filt er is the same order a s the inpu t .

Freq. Transformation Transformation Function

Lowpass to lowpass [numt,dent] = lp2lp(num,den,Wo)[At,Bt,Ct,Dt] = lp2lp(A,B,C,D,Wo)

Lowpass to h ighpass [numt,dent] = lp2hp(num,den,Wo)[At,Bt,Ct,Dt] = lp2hp(A,B,C,D,Wo)

Lowpass to bandpass [numt,dent] = lp2bp(num,den,Wo,Bw)[At,Bt,Ct,Dt] = lp2bp(A,B,C,D,Wo,Bw)

Lowpass to bandstop [numt,dent] = lp2bs(num,den,Wo,Bw)[At,Bt,Ct,Dt] = lp2bs(A,B,C,D,Wo,Bw)

s ' s ω0⁄=

s 'ω0s-------=

s 'ω0Bω-------

s ω0⁄( )2 1+s ω0⁄

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

s 'Bω

ω0-------

s ω0⁄

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

ω0 ω1ω2=

Bω ω2 ω1–=

Page 106: MATLAB Signal Processing Toolbox user manual

2 Filter Design

2-40

To begin designing an order 10 bandpass Chebyshev type I filter with a va lueof 3 dB for passband r ipple

[z,p,k] = cheb1ap(5,3);

z, p, and k con ta in the poles, zeros, and gain of a lowpass ana log filter withcu toff frequency Ωc equa l to 1 rad/sec. Use the lp2bp funct ion to t ransform th islowpass prototype to a bandpass ana log filter with band edges W1 = π/5 andW2 = π. F irst , conver t the filter to sta te-space form so the lp2bp funct ion canaccept it .

[A,B,C,D] = zp2ss(z,p,k); % Convert to state–space form.

Now, find the bandwidth and center frequency, and ca ll lp2bp.

u1 = 0.1*2*pi; u2 = 0.5*2*pi; % in radians per secondBw = u2–u1;Wo = sqrt(u1*u2);[At,Bt,Ct,Dt] = lp2bp(A,B,C,D,Wo,Bw);

Page 107: MATLAB Signal Processing Toolbox user manual

Special Topics in IIR Filter Design

2-41

Fina lly, ca lcu la t e the frequency response and plot it s magnitude.

[b,a] = ss2tf(At,Bt,Ct,Dt);% Convert to TF form.w = linspace(.01,1,500)*2*pi;% Generate frequency vector.h = freqs(b,a,w);% Compute frequency response.semilogy(w/2/pi,abs(h)), grid% Plot log magnitude vs. freq.

Filter DiscretizationThe th ird step in the ana log prototyping techn ique is the t ransforma t ion of thefilt er to the discrete-t ime domain . The toolbox provides two methods for th is:the impulse invar ian t and bilinear t ransformat ions. The filt er design funct ions

pi/5 pi10-7

10-6

10-5

10-4

10-3

10-2

10-1

100

Frequency (rad/sec)

Page 108: MATLAB Signal Processing Toolbox user manual

2 Filter Design

2-42

butter, cheby1, cheby2, and ellip use the bilinear t ransformat ion fordiscret iza t ion in th is st ep.

Impulse InvarianceThe toolbox funct ion impinvar crea t es a digit a l filter whose impulse responseis the samples of the con t inuous impulse response of an ana log filter . Th isfunct ion works only on filt er s in t ransfer funct ion form. For best resu lt s, theana log filter should have negligible frequency content above half the samplingfrequency, because such high frequency conten t is a lia sed in to lower bandsupon sampling. Impulse invar iance works for some lowpass and bandpassfilter s, bu t is not appropr ia t e for h ighpass and bandstop filt ers.

Analog to Digital Transformation

Transformation Function

Impulse invar iance [numd,dend] = impinvar(num,den,Fs)

Bilinea r t ransform [zd,pd,kd] = bilinear(z,p,k,Fs,Fp)[numd,dend] = bilinear(num,den,Fs,Fp)[Ad,Bd,Cd,Dd] = bilinear(At,Bt,Ct,Dt,Fs,Fp)

Page 109: MATLAB Signal Processing Toolbox user manual

Special Topics in IIR Filter Design

2-43

Design a Chebyshev type I filt er and plot it s frequency response.

[bz,az] = impinvar(b,a,2);freqz(bz,az)

Impulse invar iance ret a ins the cutoff frequencies of 0.1 Hz and 0.5 Hz.

Bilinear TransformationThe bilinear t ransformat ion is a nonlinear mapping of the cont inuous domainto the discrete doma in ; it maps the s-plane in to the z-plane by

Bilinea r t ransformat ion maps the jΩ axis of the cont inuous domain to the unitcircle of the discrete domain according to

The toolbox funct ion bilinear implements th is opera t ion , where the frequencywarping constan t k is equa l to twice the sampling frequency (2*Fs) by defaultand equal to 2*pi*Fp/tan(pi*Fp/Fs) if you give bilinear a t ra iling argumenttha t represen t s a “ma tch” frequency Fp. If a ma tch frequency Fp (in Her t z) is

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-800

-600

-400

-200

0

200

Normalized frequency (Nyquist == 1)

Phas

e (d

egre

es)

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-150

-100

-50

0

Normalized frequency (Nyquist == 1)

Mag

nitu

de R

espo

nse

(dB)

H z( ) H s( )s k z 1–

z 1+------------==

ω 2tan 1– Ωk----⎝ ⎠⎛ ⎞=

Page 110: MATLAB Signal Processing Toolbox user manual

2 Filter Design

2-44

presen t , bilinearmaps the frequency Ω = 2πfp (in radians/second) to the samefrequency in the discret e doma in , normalized to the sampling ra te: ω = 2πfp/ fs(a lso in radians/second).

The bilinear funct ion can perform th is t ransformat ion on three differen tlinear system representa t ions: zero-pole-ga in , t ransfer funct ion , andsta te-space form. Try ca lling bilinear with the sta te-space mat r ices tha tdescr ibe the Chebyshev type I filt er from the previous sect ion, using a samplingfrequency of 2 Hz, and reta in ing the lower band edge of 0.1 Hz.

[Ad,Bd,Cd,Dd] = bilinear(At,Bt,Ct,Dt,2,0.1);

The frequency response of the resu lt ing digita l filt er is

[bz,az] = ss2tf(Ad,Bd,Cd,Dd); % convert to TFfreqz(bz,az)

The lower band edge is a t 0.1 Hz as expected. Not ice, however , tha t the upperband edge is sligh t ly less than 0.5 Hz, a lthough in the ana log domain it wasexact ly 0.5 Hz. This illust ra tes the nonlinear na ture of the bilineart ransformat ion . To counteract th is nonlinear ity, it is necessary to crea t e ana logdomain filt er s with “prewarped” band edges, which map to the cor rect loca t ions

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-1000

-500

0

500

Normalized frequency (Nyquist == 1)

Phas

e (d

egre

es)

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)

Mag

nitu

de R

espo

nse

(dB)

Page 111: MATLAB Signal Processing Toolbox user manual

Special Topics in IIR Filter Design

2-45

upon bilinear t ransformat ion. Here the prewarped frequencies u1 and u2genera te Bw and Wo for the lp2bp funct ion .

Fs = 2; % sampling frequency (Hertz)u1 = 2*Fs*tan(.1*(2*pi/Fs)/2); % lower band edge (radians/second)u2 = 2*Fs*tan(.5*(2*pi/Fs)/2); % upper band edge (radians/second)Bw = u2–u1; % bandwidthWo = sqrt(u1*u2); % center frequency[At,Bt,Ct,Dt] = lp2bp(A,B,C,D,Wo,Bw);

A digita l bandpass filt er with cor rect band edges 0.1 and 0.5 t imes the Nyquistfrequency is

[Ad,Bd,Cd,Dd] = bilinear(At,Bt,Ct,Dt,Fs);

The example bandpass filter s from the la st two sect ions could a lso be crea tedin one st a t ement using the complet e IIR design funct ion cheby1. For instance,an analog version of the example Chebyshev filter is

[b,a] = cheby1(5,3,[0.1 0.5]*2*pi,'s');

Note tha t the band edges are in radians/second for analog filt ers, whereas forthe digit a l case, frequency is norma lized (the Nyquist frequency is equa l to 1Hz).

[bz,az] = cheby1(5,3,[0.1 0.5]);

All of the complete design funct ions ca ll bilinear in terna lly. They prewarp theband edges as needed to obta in the cor rect digita l filter . See Chapter 6 for moreon these funct ions.

Page 112: MATLAB Signal Processing Toolbox user manual

2 Filter Design

2-46

References1 Karam, L.J ., and J .H. McClellan . “Complex Chebyshev Approximat ion forFIR Filter Design .” IEEE Trans. on Circu its and S ystem s II . March 1995.

2 Selesn ick, I.W., and C.S. Burrus. “Genera lized Digita l But terwor th F ilterDesign .” Proceed ings of the IEEE In t. Conf. Acoust., S peech , S ignalProcessing. Vol. 3 (May 1996).

3 Selesn ick, I.W., M. Lang, and C.S. Burrus. “Const ra ined Least SquareDesign of FIR Filt ers without Specified Transit ion Bands.” Proceed ings ofthe IEEE Int. Conf. Acoust., S peech , S ignal Processing. Vol. 2 (May 1995).Pgs. 1260-1263.

Page 113: MATLAB Signal Processing Toolbox user manual

3Sta t ist ica l Signa lProcessing

Corre lation and Covariance . . . . . . . . . . . . . . . . . . . . . . . . . . 3-2Bias and Normaliza t ion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-3Mult iple Channels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-4

Spectral Analys is . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-5Welch’s Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-6Mult itaper Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-16Yule-Walker AR Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-19Burg Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-20Covar iance and Modified Covar iance Methods . . . . . . . . . . . . . 3-22MUSIC and Eigenvector Ana lysis Methods . . . . . . . . . . . . . . . 3-23

Reference s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-27

Page 114: MATLAB Signal Processing Toolbox user manual

3 Statistical Signal Processing

3-2

Correlation and CovarianceThe Signa l Processing Toolbox provides tools for est ima t ing impor tan tfunct ions of random signa ls. In par t icu la r , t here a re tools to est imatecor rela t ion and covar iance sequences and spect ra l density funct ions of discretesigna ls. This chapter expla ins the cor rela t ion and cova r iance funct ions anddiscusses the mathemat ica lly rela ted funct ions for est ima t ing the powerspect rum.

The funct ions xcorr and xcov est ima te the cross-cor rela t ion andcross-cova r iance sequences of random processes. They also handleautocorrela t ion and autocovar iance as specia l cases.

The t rue cross-cor rela t ion sequence is a st a t ist ica l quant ity defined as

where xn and yn are st a t iona ry random processes, - , and E{} is theexpected va lue opera tor . The cross-covar iance sequence is the mean-removedcross-cor rela t ion sequence

or , in terms of the cross-cor rela t ion ,

In pract ice, you must est imate these sequences, because it is possible to accessonly a fin ite segment of the infin it e-length random process. A common est imatebased on N samples of xn and yn is the determin ist ic cross-cor rela t ion sequence(a lso ca lled the t ime-ambigu ity funct ion)

γx y m( ) E {xn y*n m+ }=

∞ n ∞< <

Cxy m( ) E { xn µx–( ) y*n m+ µ*x–( )}=

Cxy m( ) γx y m( ) µxµ*y–=

R x y m( )xn yn m+

*

n 0=

N m– 1–

∑ m 0≥

R y x* m–( ) m 0<⎩

⎪⎪⎨⎪⎪⎧

=

Page 115: MATLAB Signal Processing Toolbox user manual

Correlation and Covariance

3-3

where we assume for this discussion tha t xn and yn are indexed from 0 to N -1,

and from -(N -1) to N -1. The xcorr funct ion evalua tes th is sum withan efficient FFT-based a lgor ithm, given input s xn and yn stored in length Nvectors x and y. It s opera t ion is equiva lent to convolu t ion with one of the twosubsequences reversed in t ime.

For example,

x = [1 1 1 1 1]';y = x;xyc = xcorr(x,y)

xyc =

1.0000 2.0000 3.0000 4.0000 5.0000 4.0000 3.0000 2.0000 1.0000

Notice tha t the resu lt ing sequence is twice the length of the inpu t sequenceminus 1. Thus, the N th element is the correla t ion a t lag 0. Also not ice thet r iangular pu lse of the output tha t resu lt s when convolving two square pu lses.

The xcov funct ion est ima tes au tocovar iance and cross-covar iance sequences.This funct ion has the same opt ions and eva lua tes the same sum as xcorr, bu tfir st removes the means of x and y.

Bias and NormalizationAn est imate of a quant ity is biased if it s expected va lue is not equa l to thequant ity it est imates. The expected value of the outpu t of xcorr is

R y x* m–( )

E {R x y m( )} E {xn y*n m+ }n 0=

N m– 1–

∑ N m–( )γxy m( )= =

Page 116: MATLAB Signal Processing Toolbox user manual

3 Statistical Signal Processing

3-4

xcorr provides the unbiased est imate, dividing by N -| m | , when you specify an'unbiased' flag after the inpu t sequences.

xcorr(x,y,'unbiased')

Although th is est ima te is unbiased, the end poin t s (near -(N -1) and N -1) sufferfrom large va r iance because xcorr computes them using only a few data poin ts.A possible t rade-off is to simply divide by N using the 'biased' flag.

xcorr(x,y,'biased')

With th is scheme, only the sample of the correla t ion a t 0 lag (the N th ou tpu telement ) is unbiased. This est ima te is often more desirable than the unbia sedone because it avoids random large va ria t ions a t the end poin ts of thecor rela t ion sequence.

xcorr provides one other normaliza t ion scheme. The syntax

xcorr(x,y,'coeff')

divides the output by norm(x)*norm(y) so tha t , for au tocorrela t ions, thesample a t 0 lag is 1.

Multiple ChannelsFor a mult ichannel signa l, xcorr and xcov est imate the au tocorrela t ion andcross-cor rela t ion and cova r iance sequences for a ll of the channels a t once. If Sis an M -by-N signa l matr ix represen t ing N channels in it s columns, xcorr(S)returns a (2M -1)-by-N 2 mat r ix with the au tocor rela t ions and cross-cor rela t ionsof the channels of S in it s N 2 columns. If S is a 3-channel signa l

S = [s1 s2 s3]

then the resu lt of xcorr(S) is organized as

R = [Rs1s1 Rs1s2 Rs1s3 Rs2s1 Rs2s2 Rs2s3 Rs3s1 Rs3s2 Rs3s3]

Two rela ted funct ions, cov and corrcoef, a re ava ilable in the st andardMATLAB environment . They est imate covar iance and normalized covar iancerespect ively between the differen t channels a t lag 0 and ar range them in asqua re ma tr ix.

Page 117: MATLAB Signal Processing Toolbox user manual

Spectral Analysis

3-5

Spectral AnalysisSpect ra l ana lysis seeks to descr ibe the frequency con ten t of a signa l, randomprocess, or syst em, based on a fin it e set of da ta . Est imat ion of power spect ra isusefu l in a var iety of applica t ions, including the detect ion of signa ls bur ied inwide-band noise.

The power spectral density (PSD) of a sta t ionary random process xn is rela tedmathema t ica lly to the correla t ion sequence by the discrete-t ime Four iert ransform,

This funct ion of frequency has the proper ty tha t it s in tegra l over a frequencyband is equa l to the power of the signa l xn in tha t band.

The PSD is a specia l case of the cross spectral density (CSD) funct ion , definedbetween two signals xn and yn as

As is the case for the cor rela t ion and covar iance sequences, the toolboxestim ates t he PSD and CSD because signa l lengths a re fin it e.

The var ious methods of PSD est ima t ion can be iden t ified as param etric ornonparam etric. One technique offered in the Signa l Processing Toolbox is thepopula r nonparamet r ic scheme developed by Welch [5]. This is complementedby more modern nonparamet r ic t echniques such as the multitaper m ethod(MTM) and the multiple signal classification (MUSIC) or eigenvector (EV)method , which is well su ited for line spect ra (da ta made up of sinusoids). TheYule-Walker autoregressive (AR)method is a pa rametr ic method tha t est imatesthe autocorrela t ion funct ion to solve for the AR model parameters. The Burgm ethod is another parametr ic spect ra l est imat ion method tha t min imizes theforward and backward linear predict ion er rors while sa t isfying theLevinson-Durbin recursion . These methods are listed in the table below withthe cor responding toolbox funct ion name. The number below each methodname indica tes the page tha t descr ibes the method in grea ter det a il. See

Pxx ω( ) γx x m( )e jωm–

m ∞–=

∑=

Pxy ω( ) γx y m( )e jωm–

m ∞–=

∑=

Page 118: MATLAB Signal Processing Toolbox user manual

3 Statistical Signal Processing

3-6

“Pa rametr ic Modeling” in Chapter 4 for deta ils about lpc and other paramet r icest ima t ion funct ions.

Welch’s MethodOne way of est ima t ing the power spect rum of a process is to simply find thediscrete-t ime Four ier t r ansform of the samples of the process (usua lly done on

Method Description Functions

Burg(3-20)

Autoregressive (AR) spect ra lest ima t ion of a t ime-ser ies byminimiza t ion of linea r predict ioner rors

pburg

Covar iance(3-22)

Autoregressive (AR) spect ra lest ima t ion of a t ime-ser ies byminimiza t ion of the forwardpredict ion er rors

pcov

ModifiedCova r iance(3-22)

Autoregressive (AR) spect ra lest ima t ion of a t ime-ser ies byminimiza t ion of the forward andbackward predict ion er rors

pmcov

Mult it aper(3-16)

Spect ra l est ima te from combina t ionof mult iple or thogona l windows (or“tapers”)

pmtm

MUSIC(3-23)

Mult iple signal cla ssifica t ion oreigenvector method

pmusic

Welch(3-6)

Averaged per iodograms ofover lapped, windowed signa l sect ions

pwelch, csd, tfe, cohere

Yule-Walker AR(3-19)

Autoregressive (AR) spect ra lest ima te of a t ime-ser ies from it sest ima ted au tocor rela t ion funct ion

pyulear

Page 119: MATLAB Signal Processing Toolbox user manual

Spectral Analysis

3-7

a gr id with an FFT) and take the magnitude squa red of the resu lt . An example1001-element signa l xn, which consist s of two sinusoids plus noise, is given by

Fs = 1000; % sampling frequencyt = 0:1/Fs:1; % one second worth of samplesxn = sin(2*pi*50*t) + 2*sin(2*pi*120*t) + randn(size(t));

A crude est imate of the PSD of xn is

Pxx = abs(fft(xn,1024)).^2/1001;

This est ima te is ca lled the periodogram . Sca le the magnitude squared of theFFT by the square of the norm of the da ta window applied to the signa l (in th iscase, a length 1001 rectangular window) to ensure tha t the est ima te isasym ptotically unbiased . Tha t is, as the number of samples increases, theexpected va lue of the per iodogram approaches the t rue PSD.

The problem with the per iodogram est ima te is tha t it s va r iance is la rge (on theorder of the PSD squared) and does not decrease as the number of samplesincreases. The following two examples show this; as FFT length increases, theper iodogram does not become smoother .

Pxx_short = abs(fft(xn,256)).^2/256;plot((0:255)/256*Fs,10*log10(Pxx_short))plot((0:1023)/1024*Fs,10*log10(Pxx))

Reduce the var iance of the PSD est imate by breaking the signa l in tononover lapping sect ions and averaging the per iodograms of these sect ions.

Pxx = (abs(fft(xn( 1:256))).^2 + abs(fft(xn(257:512))).^2 + ...abs(fft(xn(513:768))).^2 ) / (256*3);

plot((0:255)/256*Fs,10*log10(Pxx))

0 100 200 300 400 500 600 700 800 900 1000-10

-5

0

5

10

15

20

25

Frequency (Hz)

Pow

er S

pect

rum

(dB

)

Averaged Periodogram (no overlap)

Page 120: MATLAB Signal Processing Toolbox user manual

3 Statistical Signal Processing

3-8

This averaged est imate has one th ird the var iance of the length 256per iodogram shown ear lier . The more sect ions you average, the lower theva r iance of the result . However , the signa l length limits the number of sect ions

0 100 200 300 400 500 600 700 800 900 1000-20

-10

0

10

20

30

Frequency (Hz)

Pow

er S

pect

rum

(dB)

Short Periodogram

0 100 200 300 400 500 600 700 800 900 1000-30

-20

-10

0

10

20

30

Frequency (Hz)

Pow

er S

pect

rum

(dB)

Periodogram

Page 121: MATLAB Signal Processing Toolbox user manual

Spectral Analysis

3-9

possible (to three sect ions of length 256 in the previous example). To obta inmore sect ions, break the signa l in to over lapping sect ions.

Pxx = (abs(fft(xn( 1:256))).^2 + abs(fft(xn(129:384))).^2 + ...abs(fft(xn(257:512))).^2 + abs(fft(xn(385:640))).^2 + ...abs(fft(xn(513:768))).^2 + ...abs(fft(xn(641:896))).^2 ) / (256*6);

plot((0:255)/256*Fs,10*log10(Pxx))

In th is case the sect ions are sta t ist ica lly dependent , resu lt ing in h ighervar iance; thus there is a t rade-off between the number of sect ions and theover lap ra te.

Another way to improve the per iodogram est imate is to apply a nonrectangularda ta window to the sect ions before comput ing the per iodogram, resu lt ing in amodified periodogram . Th is reduces the effect of sect ion dependence due toover lap, because the window is tapered to 0 on the edges. Also, anonrectangula r window diminishes the side-lobe in ter ference or “spect ra lleakage” while increasing the width of spect ra l peaks. With a suit able window(such as Hamming, Hanning, or Kaiser ), over lap ra t es of about ha lf the sect ionlength have been found to lower the var iance of the est imate sign ifican t ly.

0 100 200 300 400 500 600 700 800 900 1000-10

-5

0

5

10

15

20

25

Frequency (Hz)

Pow

er S

pect

rum

(dB

)

Averaged Periodogram (128 sample overlap)

Page 122: MATLAB Signal Processing Toolbox user manual

3 Statistical Signal Processing

3-10

The applica t ion of a Hanning window resu lt s in

w = hanning(256)';Pxx = ( abs(fft(w.*xn( 1:256))).^2 + ... abs(fft(w.*xn(129:384))).^2 + ... abs(fft(w.*xn(257:512))).^2 + ... abs(fft(w.*xn(385:640))).^2 + ... abs(fft(w.*xn(513:768))).^2 + ... abs(fft(w.*xn(641:896))).^2 ) / (norm(w)^2*6);plot((0:255)/256*Fs,10*log10(Pxx))

Not ice in th is plot tha t the spect ra l peaks have widened, and the noise floor, orlevel of the noise, seems to be the fla t test of any est ima te so fa r . Th is methodof averaged, modified per iodograms is Welch’s method of PSD est imat ion .

The funct ions pwelch and csd provide cont rol over a ll the parameter s discussedso fa r (FFT length , window, and amount of over lap) in comput ing the PSD andCSD of signa ls using Welch’s method.

For a more deta iled discussion of Welch’s method of PSD est ima t ion , seeKay [1] and Welch [5].

Power Spectral Density FunctionThe pwelch funct ion averages and sca les the modified per iodograms of sect ionsof a signa l. Simply specify the pa rameters tha t con t rol the a lgor ithm asarguments to the funct ion .

An est imate for the PSD of a sequence xn using pwelch’s defau lt FFT length(256), window (Hanning of length 256), and over lap samples (none) is

Pxx = pwelch(xn);

0 100 200 300 400 500 600 700 800 900 1000-10

-5

0

5

10

15

20

25

Frequency (Hz)

Pow

er S

pect

rum

(dB)

Averaged Modified Periodogram (128 sample overlap, Hanning window)

Page 123: MATLAB Signal Processing Toolbox user manual

Spectral Analysis

3-11

Pxx has unit s of power per unit frequency in terva l. For example, if t he or igina lsequence xn has unit s of volt s, Pxx has unit s of Wat ts/Hz.

To recrea t e the la st example accura t ely, specify 128 as the number of samplesto over lap:

nfft = 256; % length of FFTwindow = hanning(256); % window functionnoverlap = 128; % number of samples overlapPxx = pwelch(xn,nfft,Fs,window,noverlap);

Pxx is sca led by the reciproca l of the sampling frequency, 1/Fs. pwelch withou tany outpu ts genera tes a plot of the PSD over the frequency range [0,Fs/2):

pwelch(xn,nfft,Fs,window,noverlap)

If you want to plot the PSD yourself, obta in the frequency vector th rough anaddit iona l ou tpu t a rgument .

[Pxx,f] = pwelch(xn,nfft,Fs,256,noverlap);plot(f,10*log10(Pxx))

All the spect ra l est imat ion funct ions a llow you to specify an empty mat r ix, [],in place of an input a rgument to use the defau lt va lue of tha t a rgument . In thecommand above, because the va lues for nfft and window are actua lly the sameas the defau lt s, you could replace them both with the empty mat r ix.

[Pxx,f] = pwelch(xn,[],Fs,[],noverlap);

0 50 100 150 200 250 300 350 400 450 500−40

−35

−30

−25

−20

−15

−10

−5Welch’s Spectral Estimate Pxx(f) / fs

Frequency (Hz)

Pow

er S

pect

ral D

ensi

ty (d

B)

Page 124: MATLAB Signal Processing Toolbox user manual

3 Statistical Signal Processing

3-12

Since the signa l xn is rea l, pwelch retu rns on ly the frequencies from 0 throughthe Nyquist frequency. In cont rast , t he ear lier FFT example genera t ed PSDest ima tes ranging from 0 through Fs.

Bias and Normalization in Welch’s MethodIn studying the outpu t of pwelch shown ear lier , severa l revea lingcha racter ist ics about the signa l xn a re evident . The noise floor is fla t a t 0decibels (dB), implying white noise of va r iance 1. Fur thermore, the “signa l”pa r t of xn is concen t ra ted in two peaks a t 50 and 120 Hz. The rela t ion of thepeak heigh t s is meaningfu l. For instance, the 50 Hz peak is 6 dB below the 120Hz peak, ver ifying tha t the h igher frequency sinusoid has twice the magnitudeas the lower (106/20 = 2.0). Unlike the rela t ive height s, the actua l heigh t of thepeaks does not t ell us much about the or igina l amplitude of the sinusoidswithout addit iona l ana lysis.

To obta in usefu l in forma t ion about the peak amplitudes of the under lyingsinusoids, note tha t the expected va lue of the est imated PSD is

Because the expected value is not equal to the t rue PSD, the est imate is biased .This quant ity is the convolu t ion of the t rue PSD with the squared magnitudeof the window’s discret e-t ime Four ier t ransform W(ω), sca led by the squarednorm of the window. The sca ling factor is the sum of the squa res of the windowfunct ion :

This says tha t if Pxx(ω) has a peak of heigh t 1 a t a pa r t icu la r frequency ω0, theest ima te will have approximate heigh t a t tha t frequency,provided the window W(ω) is na r row with respect to the spacing between thepeak and other spect ra l fea tures. So, to obta in an est imate which on averagereflects the heigh t of the or igina l peaks, mult iply the resu lt of pwelch by

E Pxx ω( ){ }1

2π w 2------------------- Pxx θ( ) W ω θ–( ) θdπ–π∫=

w 2 w n( )2∑=

W 0( ) 2 w 2⁄

Page 125: MATLAB Signal Processing Toolbox user manual

Spectral Analysis

3-13

norm(w)^2/sum(w)^2, where w is the window vector . This sca ling isindependent of window length and shape. For example:

w1 = hanning(256); w2 = hanning(500);[Pxx1,f1] = pwelch(xn,256,Fs,w1,128);[Pxx2,f2] = pwelch(xn,1024,Fs,w2,250);subplot(2,1,1)plot(f1,10*log10(Pxx1*norm(w1)^2/sum(w1)^2))axis([0 500 –70 –20]); gridsubplot(2,1,2)plot(f2,10*log10(Pxx2*norm(w2)^2/sum(w2)^2))axis([0 500 –70 –20]); grid

In both plots, which show the spect rum at posit ive frequencies only (thenega t ive frequencies are the same), the h igher frequency peak has a va lue of 0dB, and the lower frequency peak is a t -6 dB. The 120 Hz sinusoid heigh t of 0dB cor responds to a squa red amplitude of 1. This resu lt s from the sinusoid ofamplitude 2 having complex exponent ia l component s of amplitude 1 a t bothposit ive and negat ive frequency. Simila r ly, the 50 Hz sinusoid has bothposit ive and nega t ive frequency components with squa red amplitude of(½)2 = ¼ , or 10*log10(.25) = -6 dB, as shown in the plot . Also, note tha t thesecond plot reflect s a slight ly lower noise floor , which is the resu lt of a longerwindow length .

0 100 200 300 400 500−70

−60

−50

−40

−30

−20

0 100 200 300 400 500−70

−60

−50

−40

−30

−20

Page 126: MATLAB Signal Processing Toolbox user manual

3 Statistical Signal Processing

3-14

Cross-Spectral Density FunctionTo est ima te the cross-spect ra l density of two equal length signals x and y usingWelch’s method, the csd funct ion forms the per iodogram as the product of theFFT of x and the conjuga te of the FFT of y. Unlike the rea l-va lued PSD, theCSD is a complex funct ion. csd handles the sect ion ing and windowing of x andy in the same way as the pwelch funct ion .

Pxy = csd(x,y,nfft,Fs,window,noverlap)

Confidence IntervalsBoth the pwelch and csd funct ions can compute confidence in t erva ls. Simplyprovide an input a rgument p, which specifies the percen tage of the confidencein terva l.

[Pxx,Pxxc,f] = pwelch(x,nfft,Fs,window,noverlap,p)[Pxy,Pxyc,f] = csd(x,y,nfft,Fs,window,noverlap,p)

p must be a sca la r between 0 and 1. The funct ions assume chi-squareddist r ibu ted per iodograms of nonover lapping sect ions in comput ing theconfidence in t erva ls. (This assumpt ion is va lid when the signa l is a Gaussiandist r ibu ted random process.) P rovided these assumpt ions are cor rect , there isa p*100% probability tha t the confidence in terva l

[Pxx–Pxxc(:,1) Pxx+Pxxc(:,2)]

covers the t rue PSD. If the sect ions over lap, the confidence in terva l is notreliable and the funct ions display a warning message.

Transfer Function EstimateOne applica t ion of Welch’s method is nonparametr ic syst em ident ifica t ion .Assume tha t H is a linear , t ime invar ian t system, and x(n ) and y(n ) a re theinpu t to and outpu t of H , r espect ively. Then the PSD of x(n ) is rela ted to theCSD of x(n ) and y(n ) by

An est imate of the t ransfer funct ion between x(n ) and y(n ) is

Pxy ω( ) H ω( )Pxx ω( )=

H ω( ) P x y ω( )

P x x ω( )-----------------=

Page 127: MATLAB Signal Processing Toolbox user manual

Spectral Analysis

3-15

This method est imates both magnitude and phase in format ion . The tfefunct ion uses Welch’s method to compute the CSD and PSD and then formstheir quot ien t for the t ransfer funct ion est ima te. Use tfe t he same way tha tyou use the csd funct ion .

F ilter the signa l xn with an FIR filter , t hen plot the actua l magnitude responseand the est imated response.

h = ones(1,10)/10; % moving average filteryn = filter(h,1,xn);[HEST,f] = tfe(xn,yn,256,Fs,256,128,'none');H = freqz(h,1,f,Fs);subplot(2,1,1); plot(f,abs(H)); title('Actual Transfer Function Magnitude'); subplot(2,1,2); plot(f,abs(HEST));title('Transfer Function Magnitude Estimate'); xlabel('Frequency (Hz)');

Coherence FunctionThe magnitude-squared coherence between two signa ls x(n ) and y(n ) is

0 100 200 300 400 5000

0.2

0.4

0.6

0.8

1Actual Transfer Function Magnitude

0 100 200 300 400 5000

0.2

0.4

0.6

0.8

1Transfer Function Magnitude Estimate

Frequency (Hz)

Cxy ω( )Pxy ω( ) 2

Pxx ω( )Pyy ω( )-----------------------------------=

Page 128: MATLAB Signal Processing Toolbox user manual

3 Statistical Signal Processing

3-16

This quot ien t is a rea l number between 0 and 1 tha t measures the cor rela t ionbetween x(n ) and y(n ) a t the frequency ω.

The cohere funct ion takes sequences x and y, computes their PSDs and CSD,and returns the quot ien t of the magnitude squared of the CSD and the productof the PSDs. It s opt ions and opera t ion are simila r to the csd and tfe funct ions.

The coherence funct ion of xn and the filt er output yn versus frequency is

cohere(xn,yn,256,Fs,256,128,'none')

If the inpu t sequence length , window length , and over lap a re such tha t cohereopera tes on only a single record, the funct ion retu rns a ll ones.

Multitaper MethodThe multitaper m ethod (MTM) uses or thogonal windows (or “taper s”) to obta inapproximately independent est ima tes of the power spect rum and thencombines them to yield an est ima te. This est ima te exh ibit s more degrees offreedom and allows for easier quant ifica t ion of the bias and var iance t rade-offs,compared to convent iona l per iodogram methods. Many convent iona l spect ra lest ima tes use a single taper (or “window”), with some ir ret r ievable loss ofin format ion a t the beginn ing and the end of the ser ies. In the mult itapermethod, addit iona l t apers are used to recover some of the lost informa t ion .

This br ief discussion of the mult it aper method provides an in tu it ive look a t thea lgor ithm to assist in determining when to use it . For a more deta iled andthorough explana t ion , see Perciva l and Walden [3].

The simple pa rameter for the mult it aper method is the t ime-bandwidthproduct , NW . This parameter is a “resolu t ion” parameter direct ly rela t ed to thenumber of tapers used to compute the spect rum. There a re a lways 2*NW-1tapers used to form the est imate. This means tha t , as NW increases, there are

0 50 100 150 200 250 300 350 400 450 5000

0.2

0.4

0.6

0.8

1

Frequency

Cohe

renc

e Fu

nctio

n Es

timat

e

Coherence Function

Page 129: MATLAB Signal Processing Toolbox user manual

Spectral Analysis

3-17

more est ima tes of the power spect rum, and the var iance of the est imatedecreases. However , the bandwidth of each taper is a lso propor t iona l to NW , soas NW increases, each est ima te exhibit s more spect ra l leakage (i.e., widerpeaks) and the overa ll spect ra l est imate is more bia sed. For each data set ,there is usua lly a va lue for NW tha t a llows an opt ima l t rade-off between bia sand var iance.

Using pmtm on the da ta from the previous sect ion, xn, yields

Fs = 1000;t = 0:1/Fs:1;randn('seed',0)xn = sin(2*pi*50*t) + 2*sin(2*pi*120*t) + randn(size(t));

[P,f] = pmtm(xn,4,1024,Fs);plot(f,10*log10(P)) % plot in decibelsaxis([30 150 –20 30])

40 60 80 100 120 140-20

-15

-10

-5

0

5

10

15

20

25

30

Frequency (Hz)

Mag

nitu

de (d

B)

Page 130: MATLAB Signal Processing Toolbox user manual

3 Statistical Signal Processing

3-18

By lower ing the t ime-bandwidth product , t he peaks become nar rower .

[P1,f] = pmtm(xn,3/2,1024,Fs);plot(f,10*log10(P1)) % plot in decibelsaxis([30 150 –20 30])

Note tha t the a rea under the peaks remains about the same, as can be seenwhen both a re plot t ed together on a linear sca le.

plot(f,[P P1])axis([30 150 0 400])

40 60 80 100 120 140-20

-15

-10

-5

0

5

10

15

20

25

30

Frequency (Hz)

Mag

nitu

de (d

B)

40 60 80 100 120 1400

50

100

150

200

250

300

350

400

Frequency (Hz)

Mag

nitu

de

Page 131: MATLAB Signal Processing Toolbox user manual

Spectral Analysis

3-19

This conserva t ion of tota l power is ver ifiable numer ica lly.

sum(P)

ans = 1.8447e+03

sum(P1)

ans = 1.8699e+03

Note tha t tota l power is on ly approxima tely conserved in th is case. This isbecause the adapt ive weight ing procedure tha t is used to minimize leakagedoes not st r ict ly conserve tota l power .

This method is more expensive computa t iona lly than Welch’s method, becauseof the cost of comput ing the discrete prola te spheroida l sequences (DPSSs, a lsoknown as Slepian sequences). For long data ser ies (10,000 poin ts or more), it isusefu l to compute the DPSSs once and save them in a MAT-file. The M-filesdpsssave, dpssload, dpssdir, and dpssclear a re provided, to keep a databaseof saved DPSSs in the MAT-file dpss.mat.

Yule-Walker AR MethodThe Yule-Walker AR m ethod is an autoregressive technique for spect ra l densityest imat ion (see Marple [2], Chapter 7, and Proakis[4], Sect ion 12.3.2). Thismethod solves for the AR model parameters by the au tocor rela t ion method.

The Yule-Walker AR est imate is obta ined by solut ion of the norma l equat ions.

Here, a = [1 a(2) ... a(n+1)] is a vector of autoregressive coefficien t s, theelement s of vector r = [r(1) r(2) ... r(n+1)] are cor rela t ions, and the left -handside au tocorrela t ion mat r ix is Hermit ian Toeplitz and posit ive defin ite.

r 1( ) r 2( )* L r n( )*

r 2( ) r 1( ) L r n 1–( )*

M O O M

r n( ) L r 2( ) r 1( )

a 2( )a 3( )

M

a n 1+( )

r 2( )–r 3( )–M

r n 1+( )–

=

Page 132: MATLAB Signal Processing Toolbox user manual

3 Statistical Signal Processing

3-20

The spect ra l density est imate is

where e (f) is a complex sinusoid.

The toolbox funct ion pyulear implements the Yule-Walker AR method.

For example, compare the spect rum of a speech signa l using Welch’s methodand the Yule-Walker AR method:

load mtlb[P1,f] = pwelch(mtlb,1024,Fs,256);[P2,f] = pyulear(mtlb,14,1024,Fs); % 14th order modelplot(f,10*log10(P1),':',f,10*log10(P2)); gridylabel('Magnitude (dB)'); xlabel('Frequency (Hz)');legend('Welch','Yule–Walker AR')

The solid Yule-Walker AR spect rum is smoother than the per iodogram becauseof the simple under lying a ll-pole model.

Burg MethodThe Burg method for AR spect ra l est imat ion is based on minimizing theforward and backward predict ion er rors while sa t isfying the Levinson-Durbinrecursion (see Marple[2], Chapter 7, and Proakis[4], Sect ion 12.3.3). Incon t ra st to other AR est ima t ion methods, the Burg method avoids ca lcu la t ing

PYuleAR f( ) 1aH e f( ) 2-----------------------=

0 500 1000 1500 2000 2500 3000 3500 4000−90

−80

−70

−60

−50

−40

−30

−20

Mag

nitu

de (d

B)

Frequency (Hz)

Welch Yule–Walker AR

Page 133: MATLAB Signal Processing Toolbox user manual

Spectral Analysis

3-21

the autocorrela t ion funct ion , and inst ead est ima tes the reflect ion coefficien tsdirect ly.

The pr imary advantages of the Burg method a re resolving closely spacedsinusoids in signa ls with low noise levels, and est ima t ing shor t da t a records, inwhich case the AR power spect ra l density est imates are very close to the t rueva lues. In addit ion , the Burg method ensures a st able AR model and iscomputa t iona lly efficien t .

The accuracy of the Burg method is lower for h igh-order models, long datarecords, and high signa l-to-noise ra t ios (which can cause line splitting, or thegenera t ion of ext raneous peaks in the spect rum est ima te). The spect ra l densityest imate computed by the Burg method is a lso suscept ible to frequency shift s(rela t ive to the t rue frequency) resu lt ing from the in it ia l phase of noisysinusoida l signa ls. Th is effect is magnified when ana lyzing shor t da tasequences.

The toolbox funct ion pburg implements the Burg method. Compare thespect rum of the speech signa l genera t ed by both the Burg method and theYule-Walker AR method. They are very simila r for la rge signa l lengths.

load mtlb[P1,f] = pburg(mtlb(1:512),14,1024,Fs); % 14th order model[P2,f] = pyulear(mtlb(1:512),14,1024,Fs); % 14th order modelplot(f,10*log10(P1),':',f,10*log10(P2)); gridylabel('Magnitude (dB)'); xlabel('Frequency (Hz)');legend('Burg','Yule–Walker AR')

0 500 1000 1500 2000 2500 3000 3500 4000−90

−80

−70

−60

−50

−40

−30

−20

Mag

nitu

de (d

B)

Frequency (Hz)

Burg Yule–Walker AR

Page 134: MATLAB Signal Processing Toolbox user manual

3 Statistical Signal Processing

3-22

Compare the spect rum of a noisy signa l computed using the Burg method andthe Welch method.

Fs = 1000;t = 0:1/Fs:1;xn = sin(2*pi*50*t) + 2*sin(2*pi*120*t) + randn(size(t));[P1,f] = pwelch(xn,1024 ,Fs);[P2,f] = pburg(xn,17,1024,Fs); % 17th order modelplot(f,10*log10(P1),':',f,10*log10(P2)), gridylabel('Magnitude (dB)'); xlabel('Frequency (Hz)');axis([0 200 –50 0])legend('Welch','Burg')

Note tha t , as the model order for the Burg method is reduced, a frequency sh iftdue to the init ia l phase of the sinusoids will become apparent .

Covariance and Modified Covariance MethodsThe cova r iance method for AR spect ra l est ima t ion is based on min imizing theforward predict ion er ror . The modified covar iance method is based onminimizing the forward and backward predict ion er rors. The toolbox funct ionspcov and pmcov implement the respect ive methods.

0 50 100 150 200−50

−45

−40

−35

−30

−25

−20

−15

−10

−5

0

Mag

nitu

de (d

B)

Frequency (Hz)

WelchBurg

Page 135: MATLAB Signal Processing Toolbox user manual

Spectral Analysis

3-23

Compare the spect rum of the speech signa l genera ted by both the covar iancemethod and the modified covar iance method. They are nea r ly iden t ica l, evenfor a shor t signa l length .

load mtlb[P1,f] = pcov(mtlb(1:64),14,1024,Fs);% 14th order model[P2,f] = pmcov(mtlb(1:64),14,1024,Fs);% 14th order modelplot(f,10*log10(P1),':',f,10*log10(P2)); gridylabel('Magnitude (dB)'); xlabel('Frequency (Hz)');legend('Covariance','Modified Covariance')

MUSIC and Eigenvector Analysis MethodsThe pmusic funct ion provides two rela ted spect ra l ana lysis methods:

• The mult iple signa l cla ssifica t ion method (MUSIC) developed by Schmidt• The eigenvector (EV) method developed by J ohnson

See Marple [2] (pgs. 373-378) for a summary of these methods.

Both of these methods a re frequency est imator techniques based oneigenana lysis of the au tocor rela t ion mat r ix. This type of spect ra l ana lysisca t egor izes the informat ion in a cor rela t ion or da ta ma tr ix, a ssign inginformat ion to either a signa l subspace or a noise subspace.

0 500 1000 1500 2000 2500 3000 3500 4000−100

−90

−80

−70

−60

−50

−40

Mag

nitu

de (d

B)

Frequency (Hz)

Covariance Modified Covariance

Page 136: MATLAB Signal Processing Toolbox user manual

3 Statistical Signal Processing

3-24

Eigenanalysis OverviewConsider a number of complex sinusoids embedded in whit e noise. You canwrite the au tocorrela t ion ma tr ix R for th is system as the sum of the signa lau tocorrela t ion mat r ix (S ) and the noise autocorrela t ion matr ix (W).

There is a close rela t ionsh ip between the eigenvectors of the signa lau tocorrela t ion ma tr ix and the signa l and noise subspaces. The eigenvectors vof S span the same signa l subspace as the signa l vectors. If the system conta insM complex sinusoids and the order of the autocor rela t ion mat r ix is p ,eigenvectors vM+1 th rough vp+1 span the noise subspace of the autocorrela t ionmatr ix.

Frequency Estimator Functions. To genera te their frequency est ima tes,eigenana lysis methods ca lcu la t e funct ions of the vectors in the signa l and noisesubspaces. Both the MUSIC and EV techniques choose a funct ion tha ttheoret ica lly goes to in fin ity a t one of the sinusoida l frequencies in the inpu tsigna l. Using digita l technology, the resu lt ing est ima te has sharp peaks a t thefrequencies of in terest ; th is means tha t there won’t be infin ity va lues in thevectors.

The MUSIC est imate is given by the formula

where N is the size of the eigenvectors and e (f) is a complex sinusoid vector :

v represen t s the eigenvectors of the input signa l’s cor rela t ion matr ix; vk is thek th eigenvector . H is the con jugate t ranspose opera tor . The eigenvector s usedin the sum correspond to the sma llest eigenva lues and span the noise subspace(p is the size of the signa l subspace).

The expression is equiva len t to a Four ier t ransform (the vector e (f)consist s of complex exponent ia ls). Th is form is useful for numer ic computa t ionbecause the FFT can be computed for each vk and then the squa red magnitudescan be summed.

R S W+=

Pmusic f( )1

e H f( ) v k v kH

k p 1+=

N

∑⎝ ⎠⎜ ⎟⎜ ⎟⎛ ⎞

e f( )

---------------------------------------------------------------- 1

v kH e f( ) 2

k p 1+=

N

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

e f( ) 1 exp j2πf( ) exp j2πf 2⋅( ) exp j2πf 4⋅( ) … exp j2πf n 1–( )⋅( )[ ]H=

v kH e f( )

Page 137: MATLAB Signal Processing Toolbox user manual

Spectral Analysis

3-25

The EV method weigh ts the summat ion by the eigenva lues of the cor rela t ionmat r ix:

The pmusic funct ion in th is toolbox uses the svd (singular va lue decomposit ion)funct ion in the signa l case and the eig funct ion for ana lyzing the cor rela t ionmat r ix and assign ing eigenvectors to the signa l or noise subspaces. When svdis used, pmusic never computes the cor rela t ion ma tr ix explicit ly, bu t thesingular va lues are the eigenvalues.

Controlling Subspace ThresholdsTo provide user con t rol over the assignments of eigenvectors to the signal andnoise subspaces, the pmusic funct ion accept s a th reshold a rgument thresh.thresh is a two-element vector where the fir st element is the number ofeigenvectors spanning the signa l subspace and the second element is ath reshold test :

• If thresh(2) ≤ 1, t hen thresh(1) specifies the number of eigenvectorsspanning the signa l subspace. In th is ca se the va lues of thresh(1) must bein the range [0, N ), where N is:- The column length of xR if xR is a da ta mat r ix- The matr ix size if xR is a cor rela t ion mat r ix- The window length if xR is a signa l vector

• If thresh(1)≥ N , then thresh(2) is a va lue grea ter than or equa l to 1 tha tspecifies the absolu te threshold for split t ing the eigenva lues between thesigna l and noise subspaces. That is, if a given eigenvalue is less than or equalto the product thresh(2)min{λk}, then the given eigenvector is a ssigned tothe noise subspace.

• If thresh(1) < N and thresh(2) ≥ 1, thresh(1) st ill specifies the maximumnumber of eigenvectors in the signa l subspace. However , the th reshold testspecified by thresh(2) can a lso assign eigenvectors to the noise subspace.

• If thresh(1) ≥ N and thresh(2) < 1, there are no noise eigenvectors. Th is isan inva lid case and pmusic genera tes an er ror .

Pev f( )1

v kH e f( ) 2

k p 1+=

N

∑⎝ ⎠⎜ ⎟⎜ ⎟⎛ ⎞

λk⁄

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

Page 138: MATLAB Signal Processing Toolbox user manual

3 Statistical Signal Processing

3-26

For complet e deta ils on using the thresh parameter , see the referencedescr ipt ion of pmusic in Chapter 6.

Page 139: MATLAB Signal Processing Toolbox user manual

References

3-27

References1 Kay, S.M.Modern S pectral Estim ation . Englewood Cliffs, NJ : Prent ice Hall,1988.

2 Marple, S.L. Digital S pectral Analysis. Englewood Cliffs, NJ : Pren t ice Ha ll,1987.

3 Perciva l, D.B., and A.T. Walden . S pectral Analysis for Physical Applications:Multitaper and Conventional Univariate Techniques. Cambr idge:Cambr idge University Press, 1993.

4 Proakis, J .G., and D.G. Manolakis. Digital S ignal Processing: Principles,Algorithm s, and Applications. Englewood Cliffs, NJ : Pren t ice Hall, 1996.

5 Welch, P .D. “The Use of Fast Four ier Transform for the Est ima t ion of PowerSpect ra : A Method Based on Time Averaging Over Shor t , ModifiedPer iodograms.” IEEE Trans. Audio Electroacoust. Vol. AU-15 (J une 1967).Pgs. 70-73.

Page 140: MATLAB Signal Processing Toolbox user manual

3 Statistical Signal Processing

3-28

Page 141: MATLAB Signal Processing Toolbox user manual

4

Specia l Topics

Window s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-2Basic Shapes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-2Genera lized Cosine Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-4Ka iser Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-4Chebyshev Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-9

Parametric Mode ling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-10Time-Domain Based Modeling . . . . . . . . . . . . . . . . . . . . . . . . . . 4-11Frequency-Domain Based Modeling . . . . . . . . . . . . . . . . . . . . . 4-16

Resampling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-20

Cepstrum Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-23Inverse Complex Cepst rum . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-25

FFT-Based Time-Frequency Analys is . . . . . . . . . . . . . . . . . 4-27

Median Filte ring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-28

Communications Applicat ions . . . . . . . . . . . . . . . . . . . . . . . 4-29

Deconvolu tion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-33

Specia lized Transforms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-34Chirp z-Transform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-34Discrete Cosine Transform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-36Hilber t Transform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-38

Reference s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-40

Page 142: MATLAB Signal Processing Toolbox user manual

4 Special Topics

4-2

WindowsIn both digita l filt er design and power spect rum est imat ion, the choice of awindowing funct ion can play an impor t an t role in determining the qua lity ofovera ll r esu lt s. The main role of the window is to damp out the effects of theGibbs phenomenon tha t resu lt s from t runca t ion of an infin ite ser ies.

The toolbox window funct ions a re shown in the table below.

Basic ShapesThe basic window is the rectangular window , a vector of ones of the appropria telength . A rectangular window of length 50 is

n = 50;w = boxcar(n);

This toolbox stores windows in column vectors by convent ion , so an equiva len texpression is

w = ones(50,1);

The Bartlett (or t r iangular ) window is the convolu t ion of two rectangularwindows. The funct ions bartlett and triang compute simila r t r iangula rwindows, with th ree impor t an t differences. The bartlett funct ion a lways

Window Function

Bar t let t window bartlett

Blackman window blackman

Rectangular window boxcar

Chebyshev window chebwin

Hamming window hamming

Hanning window hanning

Kaiser window kaiser

Tr iangula r window triang

Page 143: MATLAB Signal Processing Toolbox user manual

Windows

4-3

retu rns a window with two zeros on the ends of the sequence, so tha t for n odd,the cen ter sect ion of bartlett(n+2) is equiva len t to triang(n):

bartlett(7)

ans =

0 0.3333 0.6667 1.0000 0.6667 0.3333 0

triang(5)

ans =

0.3333 0.6667 1.0000 0.6667 0.3333

For n even, bartlett is st ill the convolu t ion of two rectangu la r sequences.There is no st andard definit ion for the t r iangula r window for n even ; the slopesof the line segments of triang’s resu lt a re sligh t ly steeper than those ofbartlett’s in th is case:

w = bartlett(8); [w(2:7) triang(6)]

ans =

0.2857 0.1667 0.5714 0.5000 0.8571 0.8333 0.8571 0.8333 0.5714 0.5000 0.2857 0.1667

The fina l difference between the Bart let t and t r iangular windows is evident inthe Four ier t r ansforms of these funct ions. The Four ier t ransform of a Bar t let t

Page 144: MATLAB Signal Processing Toolbox user manual

4 Special Topics

4-4

window is negat ive for n even . The Four ier t ransform of a t r iangula r window,however , is a lways nonnegat ive.

This difference can be impor tan t when choosing a window for some spect ra lest ima t ion techn iques, such as the Blackman-Tukey method. Blackman-Tukeyforms the spect ra l est imate by ca lcu la t ing the Four ier t ransform of theautocorrela t ion sequence. The resu lt ing est imate might be negat ive a t somefrequencies if the window’s Four ier t ransform is nega t ive (see Kay [1], pg. 80).

Generalized Cosine WindowsBlackman, Hamming, Hanning, and rectangular windows are a ll specia l casesof the generalized cosine window . These windows a re combina t ions ofsinusoida l sequences with frequencies 0, 2π/(N -1), and 4π/(N -1), where N is thewindow length . One way to genera te them is

ind = (0:n–1)'*2*pi/(n–1);w = A – B*cos(ind) + C*cos(2*ind);

where A, B, and C are constant s you define. The concept behind these windowsis tha t by summing the individua l terms to form the window, the low frequencypeaks in the frequency domain combine in such a way as to decrease sidelobeheight . This has the side effect of increasing the mainlobe width .

The Hamming and Hanning windows are two-term genera lized cosinewindows, given by A = 0.54, B = 0.46 for Hamming and A = 0.5, B = 0.5 forHanning (C = 0 in both cases). The hamming and hanning funct ions,respect ively, compute these windows.

Note tha t the definit ion of the genera lized cosine window shown in the ear lierMATLAB code yields zeros a t samples 1 and n for A = 0.5 and B = 0.5. Toelimina te these zeros on the edges of the window, hanning uses a cosine offrequency 2π/(N+1) instead of 2π/(N -1).

The Blackman window is a popula r three-t erm window, given byA = 0.42, B = 0.5, C = 0.08. The blackman funct ion computes th is window.

Kaiser WindowThe Kaiser window is an approximat ion to the prola t e-spheroida l window, forwhich the ra t io of the main lobe energy to the sidelobe energy is maximized. Fora Kaiser window of a par t icu la r length , the pa rameter β cont rols the sidelobeheight . For a given β, t he sidelobe height is fixed with respect to window length .

Page 145: MATLAB Signal Processing Toolbox user manual

Windows

4-5

The sta tement kaiser(n,beta) computes a length n Kaiser window withparameter beta.

Examples of Kaiser windows with length 50 and var ious va lues for the betaparameter a re

n = 50;w1 = kaiser(n,1);w2 = kaiser(n,4);w3 = kaiser(n,9);[W1,f] = freqz(w1/sum(w1),1,512,2);[W2,f] = freqz(w2/sum(w2),1,512,2);[W3,f] = freqz(w3/sum(w3),1,512,2);plot(f,20*log10(abs([W1 W2 W3])))

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-180

-160

-140

-120

-100

-80

-60

-40

-20

0Three Kaiser Window Responses

Normalized Frequency (Nyquist == 1)

Nor

mal

ized

Mag

nitu

de (d

B)

beta = 1beta = 2beta = 3

Page 146: MATLAB Signal Processing Toolbox user manual

4 Special Topics

4-6

As β increases, the sidelobe heigh t decreases and the main lobe width increases.To see how the sidelobe heigh t st ays the same for a fixed β parameter as thelength is var ied, t ry

w1 = kaiser(50,4);w2 = kaiser(20,4);w3 = kaiser(101,4);[W1,f] = freqz(w1/sum(w1),1,512,2);[W2,f] = freqz(w2/sum(w2),1,512,2);[W3,f] = freqz(w3/sum(w3),1,512,2);plot(f,20*log10(abs([W1 W2 W3])))

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-120

-100

-80

-60

-40

-20

0Three Kaiser Window Responses, Beta Fixed

Normalized Frequency (Nyquist == 1)

Nor

mal

ized

Mag

nitu

de (d

B)

length = 50 length = 20 length = 101

Page 147: MATLAB Signal Processing Toolbox user manual

Windows

4-7

Kaiser Windows in FIR DesignThere are two design formulas tha t can help you design FIR filt ers to meet aset of filt er specifica t ions using a Kaiser window. To achieve a sidelobe heightof −α dB, the beta parameter is

For a t ransit ion width of Δω rad/sec, use the length

Filter s designed using these heur ist ics will meet the specifica t ionsapproximately, but you should ver ify th is. To design a lowpass filter with cutofffrequency 0.5π rad/sec, t ransit ion width 0.2π rad/sec, and 40 dB of a t tenua t ionin the stopband, t ry

[n,wn,beta] = kaiserord([0.4 0.6]*pi,[1 0],[0.01 0.01],2*pi);h = fir1(n,wn,kaiser(n+1,beta),'noscale');

The kaiserord funct ion est imates the filter order , cutoff frequency, and Kaiserwindow beta parameter needed to meet a given set of frequency domainspecifica t ions.

β0.1102 α 8.7–( ), α 50>

0.5842 α 21–( )0.4 0.07886 α 21–( )+ , 50 α 21≥ ≥0 , α 21<⎩

⎪⎨⎪⎧

=

n α 8–2.285 ωΔ----------------------- 1+=

Page 148: MATLAB Signal Processing Toolbox user manual

4 Special Topics

4-8

The r ipple in the passband is roughly the same as the r ipple in the stopband.As you can see from the frequency response, th is filt er near ly meets thespecifica t ions.

[H,f] = freqz(h,1,512,2);plot(f,20*log10(abs(H))), grid

For deta ils on kaiserord, see the reference descr ipt ion in Chapter 6.

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-100

-80

-60

-40

-20

0

20

Normalized Frequency (Nyquist == 1)

Mag

nitu

de (d

B)FIR Design using Kaiser Window

0.2 40 dB

Page 149: MATLAB Signal Processing Toolbox user manual

Windows

4-9

Chebyshev WindowThe Chebyshev window minimizes the main lobe width , given a par t icu la rsidelobe height . It is charact er ized by an equir ipple behavior , tha t is, it ssidelobes a ll have the same heigh t . The chebwin funct ion , with length andsidelobe heigh t parameters, computes a Chebyshev window.

n = 51;Rs = 40; % sidelobe height in decibelsw = chebwin(n,Rs);stem(w)

As shown in the plot , the Chebyshev window has la rge spikes a t it s outersamples.

P lot the frequency response to see the equir ipples a t -40 dB.

[W,f] = freqz(w,1,512,2);plot(f,20*log10(abs(W)/sum(w))), grid

For a deta iled discussion of the cha racter ist ics and applica t ions of the var iouswindow types, see [2] Oppenheim and Schafer , pgs. 444-462, and [3] Pa rks andBurrus, pgs. 71-73.

0 5 10 15 20 25 30 35 40 45 500

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)

Norm

ailze

d M

agni

tude

(dB)

Chebyshev Window Magnitude Response

Page 150: MATLAB Signal Processing Toolbox user manual

4 Special Topics

4-10

Parametric ModelingParamet r ic modeling techn iques find the parameter s for a mathemat ica l modeldescr ibing a signa l, system, or process. These techniques use knowninformat ion about the syst em to determine the model. Applica t ions forpa rametr ic modeling include speech and music syn thesis, da t a compression ,high-resolu t ion spect ra l est ima t ion , communica t ions, manufactur ing, andsimula t ion .

The toolbox pa rametr ic modeling funct ions opera te with the ra t iona l t ransferfunct ion model. Given appropr ia t e in format ion about an unknown system(impulse or frequency response da ta , or inpu t and outpu t sequences), t hesefunct ions find the coefficien ts of a linear system tha t models the syst em .

One impor tan t applica t ion of the pa ramet r ic modeling funct ions is in thedesign of filt ers tha t have a prescr ibed t ime or frequency response. Thesefunct ions provide a da ta -or ien ted a lterna t ive to the IIR and FIR filter designfunct ions discussed in Chapter 2.

Here is a summary of the parametr ic modeling funct ions in th is toolbox. Notetha t the System Ident ifica t ion Toolbox provides a more extensive collect ion ofpa rametr ic modeling funct ions.

Page 151: MATLAB Signal Processing Toolbox user manual

Parametric Modeling

4-11

Because yulewalk is geared explicit ly toward ARMA filt er design , it isdiscussed in Chapter 2. pburg and pyulear are discussed in Chapter 3 a longwith the other (nonpa rametr ic) spect ra l est imat ion methods.

Time-Domain Based ModelingThe lpc, prony, and stmcb funct ions find the coefficien t s of a digita l ra t iona lt ransfer funct ion tha t approxima tes a given t ime-domain impulse response.The a lgor ithms differ in complexity and accuracy of the resu lt ing model.

Domain Functions Description

Time arburg Genera t e a ll-pole filt er coefficien ts tha t model an input da tasequence using the Levinson-Durbin a lgor ithm.

arcov Genera t e a ll-pole filt er coefficien ts tha t model an input da tasequence by minimizing the forward predict ion er ror.

armcov Genera t e a ll-pole filt er coefficien ts tha t model an input da tasequence by minimizing the forward and backward predict ioner rors.

aryule Genera t e a ll-pole filt er coefficien ts tha t model an input da tasequence using an est imate of the autocor rela t ion funct ion .

lpc,levinson

Linea r Predict ive Coding. Genera t e a ll-pole recursive filt er whoseimpulse response matches a given sequence.

prony Genera t e IIR filter whose impulse response ma tches a givensequence.

stmcb Find IIR filt er whose outpu t , given a specified input sequence,matches a given outpu t sequence.

Frequency invfreqz,invfreqs

Genera te digita l or ana log filter coefficien ts given complexfrequency response da ta .

Page 152: MATLAB Signal Processing Toolbox user manual

4 Special Topics

4-12

Linear PredictionLinear predict ion modeling assumes tha t each outpu t sample of a signa l, x(k),is a linear combina t ion of the past n outputs (tha t is, it can be “linear lypredicted” from these ou tpu ts), and tha t the coefficien ts are constan t fromsample to sample.

An nth -order a ll-pole model of a signa l x is

a = lpc(x,n)

To illust ra te lpc, crea t e a sample signa l tha t is the impulse response of ana ll-pole filter with addit ive white noise.

randn('seed',0)x = impz(1,[1 0.1 0.1 0.1 0.1],10) + randn(10,1)/10;

The coefficient s for a four th-order a ll-pole filt er tha t models the system are

a = lpc(x,4)

a = 1.0000 0.0395 0.0338 0.0668 0.1264

lpc fir st ca lls xcorr to find a biased est ima te of the correla t ion funct ion of x,and then uses the Levinson-Durbin recursion , implemented in the levinsonfunct ion , to find the model coefficien ts a. The Levinson-Durbin recursion is afa st a lgor ithm for solving a syst em of symmet r ic Toeplitz linear equa t ions.lpc’s en t ire a lgor ithm for n = 4 is

r = xcorr(x);r(1:length(x)–1) = []; % remove corr. at negative lagsa = levinson(r,4)

a = 1.0000 0.0395 0.0338 0.0668 0.1264

x k( ) a 2( )x k 1–( )– a 3( )x k 2–( )– L– a n 1+( )x k n–( )–=

Page 153: MATLAB Signal Processing Toolbox user manual

Parametric Modeling

4-13

You could form the linear predict ion coefficien ts with other assumpt ions bypassing a different cor rela t ion est imate to levinson, such as the unbiasedcor rela t ion est imate.

r = xcorr(x,'unbiased');r(1:length(x)–1) = []; % remove corr. at negative lagsa = levinson(r,4)

a = 1.0000 0.0554 0.0462 0.0974 0.2115

Prony’s Method (ARMA Modeling)The prony funct ion models a signa l using a specified number of poles and zeros.Given a sequence x and numera tor and denomina tor orders nb and na,respect ively, the sta t ement

[b,a] = prony(x,nb,na)

finds the numera tor and denomina tor coefficien ts of an IIR filt er whoseimpulse response approximates the sequence x.

prony implement s the method descr ibed in [3] Parks and Burrus(pgs. 226-228). This method uses a var ia t ion of the covar iance method of ARmodeling to find the denomina tor coefficien ts a, and then finds the numera torcoefficien t s b for which the resu lt ing filter ’s impulse response matches exact lythe fir st nb + 1 samples of x. The filter is not necessar ily st able, but it canpotent ia lly recover the coefficien t s exact ly if the da ta sequence is t ru ly anau toregressive moving average (ARMA) process of the cor rect order .

NOTE The funct ions prony and stmcb (descr ibed next ) a re more accura telydescr ibed as ARX models in syst em iden t ifica t ion terminology. ARMAmodeling assumes noise only a t the inputs, while ARX assumes an externa linpu t . prony and stmcb know the input signa l: it is an impulse for prony andis arbit ra ry for stmcb.

Page 154: MATLAB Signal Processing Toolbox user manual

4 Special Topics

4-14

A model for the test sequence x (from the ear lier lpc example) using ath ird-order IIR filt er is

[b,a] = prony(x,3,3)

b = 1.1165 –0.2181 –0.6084 0.5369

a = 1.0000 –0.1619 –0.4765 0.4940

The impz command shows how well th is filter ’s impulse response matches theor igina l sequence.

format long[x impz(b,a,10)]

ans =

1.11649535105007 1.11649535105007 –0.03731609173676 –0.03731609173676 –0.08249198453223 –0.08249198453223 –0.04583930972315 –0.04583930972315 –0.14255125351637 –0.02829072973977 0.20400424807471 0.01433198229497 0.02685697779814 0.01148698991026 0.18956307836948 0.02266475846451 0.02717716288172 0.00206242734272 0.08057060786906 0.00545783754743

Not ice tha t the fir st four samples match exact ly. For an example of exactrecovery, recover the coefficien ts of a But terwor th filt er from it s impulseresponse.

[b,a] = butter(4,.2);h = impz(b,a,26);[bb,aa] = prony(h,4,4);

Try th is example; you’ll see tha t bb and aamatch the or igina l filter coefficient sto with in a tolerance of 10-13.

Page 155: MATLAB Signal Processing Toolbox user manual

Parametric Modeling

4-15

Steiglitz-McBride Method (ARMA Modeling)stmcb determines the coefficien t s for the syst em b(z)/a(z) given an approxima teimpulse response x, as well as the desired number of zeros and poles. Thisfunct ion ident ifies an unknown system based on both inpu t and outputsequences tha t descr ibe the system’s behavior , or just the impulse response ofthe system. In it s defau lt mode, stmcb works like prony

[b,a] = stmcb(x,3,3)

b = 1.1165 –0.6213 –0.8365 1.3331

a = 1.0000 –0.5401 –0.6109 1.1298

stmcb a lso finds systems tha t match given input and outpu t sequences

y = filter(1,[1 1],x); % Create an output signal.[b,a] = stmcb(y,x,0,1)

b = 1

a = 1 1

In th is example, stmcb cor rect ly iden t ifies the system used to crea t e y from x.

The Steiglit z-McBride method is a fast it era t ive a lgor ithm tha t solves for thenumera tor and denomina tor coefficien ts simultaneously in an at t empt tomin imize the signa l er ror between the filter ou tpu t and the given outpu tsigna l. Th is a lgor ithm usua lly converges rapidly, bu t migh t not converge if themodel order is too la rge. As for prony, stmcb’s resu lt ing filt er is not necessa r ilystable due to it s exact modeling approach .

stmcb provides cont rol over severa l impor tan t a lgor ithmic pa rameters; modifythese parameters if you are having t rouble modeling the da ta . To change thenumber of it era t ions from the defau lt of five and provide an in it ia l est imate forthe denomina tor coefficient s

n = 10; % number of iterationsa = lpc(x,3); % initial estimates for denominator[b,a] = stmcb(x,3,3,n,a);

Page 156: MATLAB Signal Processing Toolbox user manual

4 Special Topics

4-16

The funct ion uses an a ll-pole model crea t ed with prony as an in it ia l est ima tewhen you do not provide one of your own.

To compare the funct ions lpc, prony, and stmcb, compute the signa l er ror ineach case

a1 = lpc(x,3);[b2,a2] = prony(x,3,3);[b3,a3] = stmcb(x,3,3);[ x–impz(1,a1,10) x–impz(b2,a2,10) x–impz(b3,a3,10) ]

ans =

0.1165 0 0 –0.0058 0 –0.0190 –0.0535 0.0000 0.0818 0.0151 –0.0000 –0.0176 –0.1473 –0.1143 –0.0476 0.2005 0.1897 0.0869 0.0233 0.0154 –0.0103 0.1901 0.1669 –0.0093 0.0275 0.0251 0.0294 0.0808 0.0751 0.0022

sum(ans.^2)

ans =

0.1226 0.0834 0.0182

In compar ing modeling capabilit ies for a given order IIR model, the last resu ltshows tha t for this example, stmcb per forms best , followed by prony, then lpc.This rela t ive per formance is typica l of the modeling funct ions.

Frequency-Domain Based ModelingThe invfreqs and invfreqz funct ions implement the inverse opera t ions offreqs and freqz; t hey find an analog or digita l t ransfer funct ion of a specifiedorder tha t matches a given complex frequency response. Though the followingexamples demonst ra te invfreqz, t he discussion a lso applies to invfreqs.

Page 157: MATLAB Signal Processing Toolbox user manual

Parametric Modeling

4-17

To recover the or igina l filt er coefficien t s from the frequency response of asimple digita l filter

[b,a] = butter(4,.4) % design Butterworth lowpass

b = 0.0466 0.1863 0.2795 0.1863 0.0466

a = 1.0000 –0.7821 0.6800 –0.1827 0.0301

[h,w] = freqz(b,a,64); % compute frequency resp.[bb,aa] = invfreqz(h,w,4,4) % model: nb = 4, na = 4

bb =

0.0466 0.1863 0.2795 0.1863 0.0466

aa =

1.0000 –0.7821 0.6800 –0.1827 0.0301

The vector of frequencies w has the unit s in rads/sample, and the frequenciesneed not be equa lly spaced. invfreqz finds a filt er of any order to fit thefrequency da ta ; a th ird-order example is

[bb,aa] = invfreqz(h,w,3,3) % find third-order IIR

bb =

0.0464 0.1785 0.2446 0.1276

aa =

1.0000 –0.9502 0.7382 –0.2006

Both invfreqs and invfreqz design filt ers with rea l coefficien ts; for a da tapoin t a t posit ive frequency f, the funct ions fit t he frequency response a t both fand –f.

Page 158: MATLAB Signal Processing Toolbox user manual

4 Special Topics

4-18

By defau lt invfreqz uses an equa t ion er ror method to ident ify the best modelfrom the da ta . This finds b and a in

by crea t ing a syst em of linear equa t ions and solving them with MATLAB’s \opera tor . Here A (w (k )) and B (w (k )) a re the Four ier t ransforms of thepolynomia ls a and b respect ively a t the frequency w (k ), and n is the number offrequency poin t s (the length of h and w). wt(k ) weigh t s the er ror rela t ive to theer ror a t different frequencies. The syn tax

invfreqz(h,w,nb,na,wt)

includes a weigh t ing vector . In th is mode, the filter result ing from invfreqz isnot gua ran teed to be st able.

invfreqz provides a super ior (“outpu t -er ror”) a lgor ithm tha t solves the directproblem of minimizing the weighted sum of the squared er ror between theactua l frequency response poin t s and the desired response

To use this a lgor ithm, specify a pa rameter for the itera t ion count a ft er theweigh t vector parameter

wt = ones(size(w)); % create unity weighting vector[bbb,aaa] = invfreqz(h,w,3,3,wt,30) % 30 iterations

bbb =

0.0464 0.1829 0.2572 0.1549

aaa =

1.0000 –0.8664 0.6630 –0.1614

minb a,

w t k( ) h k( )A w k( )( ) B w k( )( )– 2

k 1=

n

minb a,

w t k( ) h k( ) B w k( )( )A w k( )( )--------------------–

2

k 1=

n

Page 159: MATLAB Signal Processing Toolbox user manual

Parametric Modeling

4-19

The resu lt ing filt er is a lways stable. Graphica lly compare the resu lt s of thefir st and second a lgor ithms to the or igina l But t erwor th filt er .

[H1,w1] = freqz(b,a,'magnitude','linear','phase','no');[H2,w2] = freqz(bb,aa,'magnitude','linear','phase','no');[H3,w3] = freqz(bbb,aaa,'magnitude','linear','phase','no');plot(w1/pi,abs(H1),w2/pi,abs(H2),'--',w3/pi,abs(H3),':')legend('Original','First Estimate','Second Estimate');grid on

To ver ify the super ior ity of the fit numer ica lly

sum(abs(h–freqz(bb,aa,w)).^2) % total error, algorithm 1

ans =

0.0200

sum(abs(h–freqz(bbb,aaa,w)).^2) % total error, algorithm 2

ans =

0.0096

0 0.2 0.4 0.6 0.8 10

0.2

0.4

0.6

0.8

1

1.2

1.4Original First Estimate Second Estimate

Page 160: MATLAB Signal Processing Toolbox user manual

4 Special Topics

4-20

ResamplingThe toolbox provides a number of funct ions tha t resample a signa l a t a h igheror lower ra te.

The resample funct ion changes the sampling ra te for a sequence to any ra t etha t is a ra t io of two integers. The basic syntax for resample is

y = resample(x,p,q)

where the funct ion resamples the sequence x a t p/q t imes the or igina lsampling ra te. The length of the resu lt y is p/q t imes the length of x.

One resampling applica t ion is the conversion of digit ized audio signa ls fromone sampling ra t e to another , such as from 48 kHz (the Digit a l Audio Tapestanda rd) to 44.1 kHz (the Compact Disc standard). In the next example, thesampling ra tes are differen t bu t the idea is the same.

Operation Function

Resample a t new ra te resample

Decimat ion decimate

In terpola t ion interp

Apply FIR filter with resampling upfirdn

Cubic spline in t erpola t ion spline

Other 1-D interpola t ion interp1

Page 161: MATLAB Signal Processing Toolbox user manual

Resampling

4-21

The example file conta ins a length 4001 vector of speech sampled a t 7418 Hz.

clearload mtlbwhos

Name Size Bytes Class

Fs 1x1 8 double array mtlb 4001x1 32008 double array

Grand total is 4002 elements using 32016 bytes

Fs

Fs = 7418

To play th is speech signa l on a workst a t ion tha t can only play sound at 8192Hz, use the rat funct ion to find in tegers p and q t ha t yield the cor rectresampling factor .

[p,q] = rat(8192/Fs,.0001)

p = 127

q = 115

Since p/q*Fs = 8192.05 Hz, the tolerance of 0.0001 is acceptable; to resamplethe signa l a t very close to 8192 Hz.

y = resample(mtlb,p,q);

resample applies a lowpass filt er to the input sequence to preven t a lia singdur ing resampling. It designs th is filt er using the firls funct ion with a Kaiserwindow. The syntax

resample(x,p,q,l,beta)

cont rols the filt er ’s length and the beta pa rameter of the Ka iser window.Alterna t ively, use the funct ion intfilt to design an in terpola t ion filter b anduse it with

resample(x,p,q,b)

Page 162: MATLAB Signal Processing Toolbox user manual

4 Special Topics

4-22

The decimate and interp funct ions do the same th ing as resample with p = 1and q = 1, r espect ively. These funct ions provide differen t an t i-a lias filt er ingopt ions, and they incur a sligh t signa l delay due to filter ing. The interpfunct ion is sign ifican t ly less efficien t than the resample funct ion with q = 1.

The toolbox also con ta ins a funct ion , upfirdn, tha t applies an FIR filt er to aninput sequence and output s the filtered sequence a t a differen t sample ra tethan it s or igina l ra t e. See “Mult ira te Filter Bank Implementa t ion” on page1-19 and the reference descr ipt ion of upfirdn in Chapter 6 for more deta ils.

The st andard MATLAB environment con ta ins a funct ion , spline, tha t workswith ir regular ly spaced da ta . The MATLAB funct ion interp1 per formsin terpola t ion , or table lookup, using var ious methods including linear andcubic in t erpola t ion . See the online MATLAB Function Reference forinformat ion on spline and interp1.

Page 163: MATLAB Signal Processing Toolbox user manual

Cepstrum Analysis

4-23

Cepstrum AnalysisCepst rum analysis is a nonlinear signa l processing technique with a var iety ofapplica t ions in areas such as speech and image processing. The Signa lProcessing Toolbox provides th ree funct ions for cepst rum ana lysis.

The complex cepst rum for a sequence x is ca lcu la t ed by finding the complexnatura l logar ithm of the Four ier t ransform of x, then the inverse Four iert ransform of the result ing sequence.

The toolbox funct ion cceps per forms th is opera t ion , est imat ing the complexcepst rum for an input sequence. It retu rns a rea l sequence the same size as theinpu t sequence

xhat = cceps(x)

The complex cepst rum transforma t ion is cen t ra l to the theory and applica t ionof hom om orphic system s, t ha t is, syst ems tha t obey cer t a in genera l ru les ofsuperposit ion . See [2] Oppenheim and Schafer for a discussion of the complexcepst rum and homomorph ic t ransformat ions, with deta ils on speech processingapplica t ions.

Try using cceps in an echo detect ion applica t ion . F irst , crea t e a 45 Hz sinewave sampled a t 100 Hz

t = 0:0.01:1.27;s1 = sin(2*pi*45*t);

Operation Function

Complex cepst rum cceps

Real cepst rum rceps

Inverse complex cepst rum icceps

x 12π------ X ejω( )[ ]log ejωn ωd

π–

π

∫=

Page 164: MATLAB Signal Processing Toolbox user manual

4 Special Topics

4-24

Add an echo of the signa l, with ha lf the amplitude, 0.2 seconds after thebeginn ing of the signa l.

s2 = s1 + 0.5*[zeros(1,20) s1(1:108)];

The complex cepst rum of th is new signa l is

c = cceps(s2);plot(t,c)

Note tha t the complex cepst rum shows a peak a t 0.2 seconds, indica t ing theecho.

The real cepstrum of a signa l x, somet imes ca lled simply the cepst rum, isca lcu la t ed by determin ing the na tura l loga r ithm of magnitude of the Four iert ransform of x, then obta ining the inverse Fourier t ransform of the resu lt ingsequence

0 0.2 0.4 0.6 0.8 1 1.2 1.4-1.5

-1

-0.5

0

0.5

1

cx12π------ X ejω( )log ejωn ωd

π–

π

∫=

Page 165: MATLAB Signal Processing Toolbox user manual

Cepstrum Analysis

4-25

The toolbox funct ion rceps per forms th is opera t ion , retu rn ing the rea lcepst rum for a sequence x. The returned sequence is a rea l-va lued vector thesame size as the input vector .

y = rceps(x)

By defin it ion , you cannot reconst ruct the or igina l sequence from it s rea lcepst rum transforma t ion , a s the rea l cepst rum is based only on the magnitudeof the Four ier t ransform for the sequence (see [2]). The rceps funct ion ,however , can reconst ruct a min imum-phase version of the or igina l sequence byapplying a windowing funct ion in the cepst ra l domain . To obta in both the rea lcepst rum and the min imum phase reconst ruct ion for a sequence, use

[y,ym] = rceps(x)

where y is the rea l cepst rum and ym is the minimum phase reconst ruct ion of x.

Inverse Complex CepstrumTo inver t the complex cepst rum, use the icceps funct ion . Inversion iscomplica t ed by the fact tha t the cceps funct ion per forms a data dependen tphase modifica t ion so tha t the unwrapped phase of it s input is con t inuous a tzero frequency. The phase modifica t ion is equiva len t to an in teger delay. Thisdelay term is retu rned by cceps if you ask for a second outpu t . For example,

x = 1:10;[xh,nd] = cceps(x)

xh = Columns 1 through 7 2.2428 -0.0420 -0.0210 0.0045 0.0366 0.0788 0.1386 Columns 8 through 10 0.2327 0.4114 0.9249

nd = 1

Page 166: MATLAB Signal Processing Toolbox user manual

4 Special Topics

4-26

To inver t the complex cepst rum, use icceps with the or igina l delay parameter .

icceps(xh,nd)

ans = Columns 1 through 7 1.0000 2.0000 3.0000 4.0000 5.0000 6.0000 7.0000 Columns 8 through 10 8.0000 9.0000 10.0000

NOTE With any modifica t ion of the complex cepst rum, the or igina l delayterm may no longer be valid. Use the icceps funct ion with care.

Page 167: MATLAB Signal Processing Toolbox user manual

FFT-Based Time-Frequency Analysis

4-27

FFT-Based Time-Frequency AnalysisThe Signa l Processing Toolbox provides a funct ion , specgram, tha t retu rns thet ime-dependent Four ier t ransform for a sequence, or displays th is informat ionas a spect rogram. The tim e-dependent Fourier transform is the discret e-t imeFour ier t ransform for a sequence, computed using a sliding window. This formof the Four ier t ransform, a lso known as the shor t -t ime Four ier t r ansform(STFT), has numerous applica t ions in speech , sonar , and radar processing. Thespectrogram of a sequence is the magnitude of the t ime-dependent Four iert ransform versus t ime.

To display the spect rogram of a linear FM signa l

Fs = 10000;t = 0:1/Fs:2;x = vco(sawtooth(2*pi*t,.75),[0.1 0.4]*Fs,Fs);specgram(x,512,Fs,kaiser(256,5),220)

Note tha t the spect rogram display is an image, not a plot .

Time

Freq

uenc

y

0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.80

500

1000

1500

2000

2500

3000

3500

4000

4500

5000

Page 168: MATLAB Signal Processing Toolbox user manual

4 Special Topics

4-28

Median FilteringThe funct ion medfilt1 implements one-dimensiona l median filter ing, anonlinear t echnique tha t applies a sliding window to a sequence. The medianfilter replaces the center va lue in the window with the median va lue of a ll thepoin ts with in the window [4]. In comput ing th is median , medfilt1 assumeszeros beyond the inpu t poin ts.

When the number of element s n in the window is even , medfilt1 sor ts thenumbers, then takes the average of the ((n–1)/2 & ((n–1)/2)+1) element s.

Two simple examples with four th- and th ird-order median filt er s are

medfilt1([4 3 5 2 8 9 1],4)

ans =

1.500 3.500 3.500 4.000 6.500 5.000 4.500

medfilt1([4 3 5 2 8 9 1],3)

ans =

3 4 3 5 8 8 1

See the Im age Processing Toolbox User’s Guide for in format ion ontwo-dimensiona l median filter ing.

Page 169: MATLAB Signal Processing Toolbox user manual

Communications Applications

4-29

Communications ApplicationsThe toolbox provides th ree funct ions for communica t ions simula t ion .

Modulation var ies the amplitude, phase, or frequency of a carrier signal withreference to a message signal. The modulate funct ion modula tes a messagesigna l with a specified modula t ion method.

The basic syn tax for the modulate funct ion is

y = modulate(x,Fc,Fs,'method',opt)

where:

• x is the message signal.• Fc is the car r ier frequency.• Fs is the sampling frequency.• method is a flag for the desired modula t ion method.• opt is any addit iona l a rgument tha t the method requires. (Not a llmodula t ion methods require an opt ion argument .)

The table below summar izes the modula t ion methods provided; see Chapter 6for complete deta ils on each .

Operation Function

Modula t ion modulate

Demodula t ion demod

Voltage cont rolled oscilla t ion vco

Method Description

amdsb–sc or am Amplitude modula t ion , double side-band, suppressedca r r ier

amdsb–tc Amplitude modula t ion , double side-band, t ransmit t edca r r ier

Page 170: MATLAB Signal Processing Toolbox user manual

4 Special Topics

4-30

If the inpu t x is an a r ray ra ther than a vector , modulate modula tes eachcolumn of the ar ray.

To obta in the t ime vector tha t modulate uses to compute the modula t ed signa l,specify a second outpu t parameter .

[y,t] = modulate(x,Fc,Fs,'method',opt)

The demod funct ion per forms dem odulation , tha t is, it obta ins the or igina lmessage signa l from the modula ted signa l.

The syn tax for demod is

x = demod(y, Fc,Fs,'method',opt)

demod uses any of the methods shown for modulate, but the syn tax forquadra ture amplitude demodula t ion requires two output parameters.

[X1,X2] = demod(y,Fc,Fs,'qam')

If the inpu t y is an a r ray, demod demodula tes a ll columns.

Try modula t ing and demodula t ing a signa l. A 50 Hz sine wave sampled a t 1000Hz is

t = (0:1/1000:2);x = sin(2*pi*50*t);

amssb Amplitude modula t ion , single side-band

fm Frequency modula t ion

pm Phase modula t ion

ptm Pulse t ime modula t ion

pwm Pulse width modula t ion

qam Quadra ture amplitude modula t ion

Method Description

Page 171: MATLAB Signal Processing Toolbox user manual

Communications Applications

4-31

With a car r ier frequency of 200 Hz, the modula t ed and demodula ted versionsof th is signa l are

y = modulate(x,200,1000,'am');z = demod(y,200,1000,'am');

To plot por t ions of the or igina l, modula ted, and demodula ted signa l

figure; plot(t(1:150),x(1:150)); title('Original Signal');figure; plot(t(1:150),y(1:150)); title('Modulated Signal');figure; plot(t(1:150),z(1:150)); title('Demodulated Signal');

The volt age cont rolled oscilla tor funct ion vco crea tes a signa l tha t oscilla t es a ta frequency determined by the input vector . The basic syn tax for vco is

y = vco(x,Fc,Fs)

where Fc is the ca r r ier frequency and Fs is the sampling frequency.

To sca le the frequency modula t ion range

y = vco(x,[Fmin Fmax],Fs)

0 0.05 0.1 0.15-1

-0.5

0

0.5

1Original Signal

0 0.05 0.1 0.15-2

-1

0

1

2Modulated Signal

0 0.05 0.1-1

-0.5

0

0.5

1Demodulated Signal

Page 172: MATLAB Signal Processing Toolbox user manual

4 Special Topics

4-32

In th is case, vco sca les the frequency modula t ion range so va lues of x on thein terva l [–1 1] map to oscilla t ions of frequency on [Fmin Fmax].

If t he inpu t x is an a r ray, vco produces an a rray whose columns oscilla teaccording to the columns of x.

See “FFT-Based Time-Frequency Ana lysis” on page 4-27 for an example usingthe vco funct ion .

Page 173: MATLAB Signal Processing Toolbox user manual

Deconvolution

4-33

DeconvolutionDeconvolu tion , or polynomia l division , is the inverse opera t ion of convolu t ion .Deconvolut ion is useful in recover ing the input to a known filter , given thefilt ered output . Th is method is very sensit ive to noise in the coefficien ts,however , so use caut ion in applying it .

The syntax for deconv is

[q,r] = deconv(b,a)

where b is the polynomia l dividend, a is the divisor , q is the quot ien t , and r isthe remainder .

To t ry deconv, fir st convolve two simple vectors a and b (see Chapter 1 for adescr ipt ion of the convolu t ion funct ion)

a = [1 2 3];b = [4 5 6];c = conv(a,b)

c = 4 13 28 27 18

Now use deconv t o deconvolve b from c

[q,r] = deconv(c,a)

q = 4 5 6

r = 0 0 0 0 0

See the S ystem Iden tification Toolbox User’s Guide for advanced applica t ionsof signa l deconvolu t ion .

Page 174: MATLAB Signal Processing Toolbox user manual

4 Special Topics

4-34

Specialized TransformsIn addit ion to the discrete Four ier t ransform (DFT) descr ibed in Chapter 1, theSigna l Processing Toolbox and the MATLAB environment together provide thefollowing t ransform funct ions:

• The chirp z-t ransform (CZT), usefu l in eva lua t ing the z-t r ansform a longcontours other than the unit circle. The ch irp z-t ransform is a lso moreefficien t than the DFT algor ithm for the computa t ion of pr ime-lengtht ransforms, and it is usefu l in comput ing a subset of the DFT for a sequence.

• The discrete cosine t ransform (DCT), closely rela t ed to the DFT. The DCT’senergy compact ion proper t ies a re usefu l for applica t ions like signa l coding.

• The Hilber t t ransform, which facilit a t es the format ion of the ana lyt ic signa l.The ana lyt ic signa l is usefu l in the area of communica t ions, par t icu la r ly inbandpass signa l processing.

Chirp z-TransformThe chirp z-t ransform, or CZT, computes the z-t r ansform a long spira l con toursin the z-plane for an inpu t sequence. Unlike the DFT, the CZT is notconst ra ined to opera te a long the unit circle, bu t can eva lua te the z-t ransformalong contours descr ibed by

where A is the complex st a r t ing poin t , W is a complex sca la r descr ibing thecomplex ra t io between poin ts on the contour , and M is the length of thet ransform.

z l AW l– l 0 … M 1–, ,=,=

Page 175: MATLAB Signal Processing Toolbox user manual

Specialized Transforms

4-35

One possible spira l is

A = 0.8*exp(j*pi/6);W = 0.995*exp(–j*pi*.05);M = 91;z = A*(W.^(–(0:M–1)));zplane([],z.')

czt(x,M,W,A) computes the z-t ransform of x on these point s.

An in terest ing and usefu l spira l set is m even ly spaced samples around the unitcircle, pa rameter ized by A = 1 and W = exp(–j*pi/M). The z-t ransform on th iscon tour is simply the DFT, obta ined by

y = czt(x)

czt is faster than the fft funct ion for comput ing the DFT of sequences withcer ta in odd lengths, par t icu la r ly long pr ime-length sequences. (Try compar ingthe execu t ion t ime for the fft and czt funct ions for a sequence of length 1013.)

-1.5 -1 -0.5 0 0.5 1 1.5

-1

-0.5

0

0.5

1

Real part

Imag

inar

y pa

rt

Page 176: MATLAB Signal Processing Toolbox user manual

4 Special Topics

4-36

Discrete Cosine TransformThe toolbox funct ion dct computes the unita ry discrete cosine t ransform, orDCT, for an input vector or mat r ix. Mathemat ica lly, the unita ry DCT of aninpu t sequence x is

where

The DCT is closely rela ted to the discret e Four ier t ransform; the DFT isactua lly one step in the computa t ion of the DCT for a sequence. The DCT,however , has bet t er energy com paction proper t ies, with just a few of thet ransform coefficien t s represen t ing the ma jor ity of the energy in the sequence.The energy compact ion propert ies of the DCT make it usefu l in applica t ionssuch as da ta communica t ions.

The funct ion idct computes the inverse DCT for an input sequence,reconst ruct ing a signa l from a complete or par t ia l set of DCT coefficien t s. Theinverse discrete cosine t ransform is

where

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

n 1=

N

∑ k 1 … N, ,=,=

w n( )

1N--------- n 1=,

2N---- 2 n N≤ ≤,

⎩⎪⎪⎨⎪⎪⎧

=

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

k 1=

N

∑ n 1 … N, ,=,=

w k( )

1N--------- k 1=,

2N---- 2 k N≤ ≤,

⎩⎪⎪⎨⎪⎪⎧

=

Page 177: MATLAB Signal Processing Toolbox user manual

Specialized Transforms

4-37

Because of the energy compact ion ment ioned above, it is possible to reconst ructa signa l from only a fract ion of it s DCT coefficien ts. For example, genera te a 10Hz sinusoida l sequence, sampled a t 1000 Hz.

t = (0:1/999:1);x = sin(2*pi*25*t);

Compute the DCT of th is sequence and reconst ruct the signa l using only thosecomponents with va lue grea ter than 53 (12 of the or igina l 1000 DCTcoefficien t s).

y = dct(x); % compute DCTy2 = find(abs(y) < 53); % use 12 coefs.y(y2) = zeros(size(y2)); % zero out points < 53z = idct(y); % reconstruct signal using inverse DCT

Plot the or igina l and reconst ructed sequences.

plot(t,x)plot(t,z), axis([0 1 –1 1])

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-1

-0.5

0

0.5

1Original Signal

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-1

-0.5

0

0.5

1Reconstructed Signal

Page 178: MATLAB Signal Processing Toolbox user manual

4 Special Topics

4-38

One measure of the accuracy of the reconst ruct ion is

norm(x–z)/norm(x)

tha t is, the norm of the difference between the or igina l and reconst ructedsigna ls, divided by the norm of the or igina l signa l. In th is case, the rela t iveer ror of reconst ruct ion is 0.1778. The reconst ructed signa l reta insapproximately 82% of the energy in the or igina l signa l.

Hilbert TransformThe toolbox funct ion hilbert computes the Hilber t t ransform for a rea l inputsequence x and retu rns a complex resu lt of the same length

y = hilbert(x)

where the rea l par t of y is the or igina l rea l da ta and the imaginary par t is theactua l Hilber t t ransform. y is somet imes ca lled the analytic signal, in referenceto the cont inuous-t ime ana lyt ic signa l. A key proper ty of the discrete-t imeanalyt ic signa l is tha t it s z-t ransform is 0 on the lower ha lf of the unit circle.Many applica t ions of the ana lyt ic signa l are rela ted to th is proper ty; forexample, the ana lyt ic signa l is useful in avoiding a liasing effects for bandpasssampling opera t ions. The magnitude of the ana lyt ic signa l is the complexenvelope of the or igina l signa l.

Page 179: MATLAB Signal Processing Toolbox user manual

Specialized Transforms

4-39

The Hilber t t ransform is rela t ed to the actua l da ta by a 90° phase shift ; sinesbecome cosines and vice versa . To plot a por t ion of da ta (solid line) and it sHilber t t ransform (dot ted line)

t = (0:1/1023:1);x = sin(2*pi*60*t);y = hilbert(x);plot(t(1:50),real(y(1:50))), hold onplot(t(1:50),imag(y(1:50)),':'), hold off

The ana lyt ic signa l is usefu l in ca lcu la t ing instan taneous attribu tes of a t imeser ies, the a t t r ibu tes of the ser ies a t any poin t in t ime. The instan taneousamplitude of the input sequence is the amplitude of the ana lyt ic signa l. Theinstan taneous phase angle of the input sequence is the (unwrapped) angle ofthe ana lyt ic signa l; the inst an taneous frequency is the t ime ra t e of change ofthe instan taneous phase angle. You can ca lcu la te the inst an taneous frequencyusing diff, as descr ibed in the online MATLAB Function Reference.

0 0.01 0.02 0.03 0.04 0.05-1

-0.8

-0.6

-0.4

-0.2

0

0.2

0.4

0.6

0.8

1

Page 180: MATLAB Signal Processing Toolbox user manual

4 Special Topics

4-40

References1 Kay, S.M.Modern S pectral Estim ation . Englewood Cliffs, NJ : Pren t ice Hall,1988.

2 Oppenheim, A.V., and R.W. Schafer . Discrete-T im e S ignal Processing.Englewood Cliffs, NJ : Prent ice Hall, 1989.

3 Parks, T.W., and C.S. Burrus. Digital Filter Design . New York: J ohn Wiley& Sons, 1987.

4 Pra t t ,W.K. Digital Im age Processing. New York: J ohn Wiley & Sons, 1991.

Page 181: MATLAB Signal Processing Toolbox user manual

5

In teract ive Tools

SPTool: An In te rac tive Signal P rocess ing Environment . 5-2

Using SPTool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-3

Using the Signal Brow ser: In te rac tive Signal Analys is . 5-43

Using the Filte r Des igner: In terac tive Filte r Design . . . 5-59

Using the Filte r View er: In te ractive Filte r Analys is . . . 5-84

Using the Spectrum View er: In te ractive PSD Analysis . 5-97

Example : Generation of Bandlim ited Noise . . . . . . . . . . 5-113

Page 182: MATLAB Signal Processing Toolbox user manual

5 Interactive Tools

5-2

SPTool: An Interactive Signal Processing EnvironmentThe Signa l Processing Toolbox includes an in teract ive graph ica l user in ter face(GUI), ca lled SPTool, for per forming digita l signa l processing tasks. SPToolprovides an easy-to-use in ter face to many of the most impor tan t toolboxfunct ions. With it , you can use the mouse and on-screen cont rols to impor t ,view, measure, and pr in t digit a l signa ls; design , view, and implement digit a lfilter s; and analyze the frequency conten t of signa ls.

Th is chapter descr ibes how to use the differen t components of SPTool. Whereappropr ia t e, we poin t you to other areas of the manual tha t descr ibe how toper form simila r t asks by ca lling funct ions from the command line or fromM-files.

The sect ion “Example: Genera t ion of Bandlimited Noise” a t the end of th ischapter descr ibes how to use th is graphica l environment for a complete filt erdesign and analysis task.

OverviewSPTool is a graph ica l environment for ana lyzing and manipula t ing digit a lsigna ls, filt ers, and spect ra . It is the sta r t ing poin t for using the in t eract ivesigna l processing environment . In SPTool, you can impor t signa ls, filt ers, andspect ra either from the workspace or as MAT-files. Through SPTool, you accessfour addit iona l GUI tools tha t provide an in tegra ted environment for signa lbrowsing, filt er design , ana lysis, and implementa t ion . The four component s ofthe in teract ive signa l processing environment include:

• The S ignal Browser, which provides a graph ica l view of the signa l objectscur ren t ly selected in SPTool and enables you to display, measure, ana lyze,and pr in t these signa ls int eract ively

• The Filter Designer, which enables you to crea t e and edit lowpass, h ighpass,bandpass, and bandstop FIR and IIR digita l filter s of var ious lengths andtypes using the filter design funct ions of the Signa l Processing Toolbox

• The Filter Viewer, which enables you to view var ious character ist ics of afilter tha t you’ve impor ted or designed, including it s magnitude and phaseresponses, group delay, zero-pole plot , and impulse and step responses

• The S pectrum Viewer, which enables you to crea t e, view, modify, and pr in tspect ra in teract ively, and to per form graphica l ana lysis of frequency domainda ta using a va r iety of common methods of spect ra l est ima t ion

Page 183: MATLAB Signal Processing Toolbox user manual

Using SPTool

5-3

Using SPToolSPTool is the da ta management tool for the in teract ive GUI environment of theSigna l Processing Toolbox. Using SPTool you can :

• Load a saved session• Impor t a signa l, filt er , or spect rum•Duplica t e or clea r a signa l, filter , or spect rum•Change the name of a signa l, filter , or spect rum•Change the sampling frequency of a signa l or filt er•Act iva te the Signal Browser , F ilt er Viewer , F ilt er Designer , or Spect rumViewer

• Save a session•Use the Window menu to change to any open MATLAB figure window

Opening SPToolOpen SPTool from the MATLAB command window by typing

sptool

and pressing Enter.

Quick StartOnce SPTool is open, you can impor t da ta from the workspace or a file. You canthen view it in the Signa l Browser or genera te it s spect rum in the Spect rumViewer .

To get st a r ted r igh t away, work through the following example. Then cont inuethrough th is chapter to lea rn the deta ils of using SPTool and its componenttools.

Or , you can skip the example, read through the rest of th is sect ion (from “BasicSPTool Funct ions” to “Using the Signa l Browser : In teract ive Signa l Analysis”),and then work through the example.

Example: Importing Signal Data from a MAT-FileThis example uses the sample file mtlb.mat, which is in thetoolbox/signal/signal directory.

Page 184: MATLAB Signal Processing Toolbox user manual

5 Interactive Tools

5-4

1 Select Import from the File menu.

The Import to SPTool window is displayed.

2 Make sure tha t Signal is displayed in the Import As pop-up menu .

3 Press the From Disk radio but ton .

You can either en ter a MAT-file name or press Brow se to open the file dia logbox and select a MAT-file.

4 To get sta r ted, type the file name mtlb and press Tab or Enter. Note tha tSPTool adds the .mat extension automat ica lly.

The data from the file you selected is displayed in the File Conten ts list . Inthis example, mtlb is the signa l da ta and Fs is the sampling frequency.

Not ice tha t sig1 is displayed in the Name field. This is the default name ofthe impor ted signa l.

5 Click on mtlb t o select it , and then press the ar row at the left of the Datafield. mtlb is t ransfer red to the Data field.

6 Click on Fs to select it , and then press the ar row a t the left of the SamplingFrequency field.

Fs is t ransfer red to the Sampling Frequency field.

Page 185: MATLAB Signal Processing Toolbox user manual

Using SPTool

5-5

7 Press OK.

The signa l has been impor t ed into SPTool with the name sig1.

You can look a t th is signa l in the Signa l Browser by pressing the View but tonunder Signals .

You can look a t the frequency conten t of the signa l in the Spect rum Viewer bypressing the Create but ton under Spectra and then pressing Apply in theSpect rum Viewer .

Basic SPTool FunctionsWhen you fir st open SPTool, it con ta ins a collect ion of defau lt signa ls, filter s,and spect ra . You can impor t addit iona l signa ls, filt ers, and spect ra into SPTool,and you can also design filter s using the F ilt er Designer and crea t e spect rausing the Spect rum Viewer . You can save and expor t da ta from SPTool andcustomize many proper t ies of the SPTool environment . The following figureshows the SPTool window and its File and Help menus, which are descr ibedbelow.

Page 186: MATLAB Signal Processing Toolbox user manual

5 Interactive Tools

5-6

File Menu

Open Session. Select Open Se ss ion… from the File menu to load a saved sessionfile. An SPTool session is saved in a file with an .spt extension .

Import. Select Import… from the File menu to impor t a signa l, filt er , orspect rum in to SPTool from either the workspace or from a file. You can impor tva r iables from any MAT-file in to SPTool. See “Impor t ing Signals, F ilters, andSpect ra” on page 5-7 and “Example: Impor t ing Signa l Data from a MAT-File”on page 5-3 for more informat ion .

Export. Select Export… from the File menu to expor t signals, filter s, andspect ra to the MATLAB workspace as st ructure var iables. See “Saving SignalDa ta” on page 5-57, “Saving Filter Da ta” on page 5-79, and “Saving Spect rumData” on page 5-110 for complet e in format ion.

Save Session. Select Save Sess ion and Save Sess ion As… from the File menuto save the cur ren t session . Save Sess ion overwr it es the exist ing session file.Save Sess ion As… saves the cur ren t session with a name you specify. AnSPTool session is saved in a MAT-file with an .spt extension .

Preferences. Select Pre ference s… from the File menu to customize preferencesfor the behavior of a ll t he Signa l Processing GUI tools. See “CustomizingPreferences” on page 5-20 for a complete discussion.

Close. Select Close from the File menu to close SPTool and a ll other act iveSignal Processing GUI tools. SPTool prompts you to save if you have notrecen t ly saved the cur ren t session .

When you close SPTool, a ll signa l and filt er customiza t ion and rulerinformat ion set in any of the GUI tools a re lost . Set t ings you changed and savedusing the Pre fe rence s dia log box in SPTool a re used the next t ime you openSPTool.

Help Menu

Overview… Select Overview… from the File menu to get genera l help onSPTool and the Signa l Processing Toolbox GUI environment . This a lso givesyou access to the MATLAB Help Desk.

Page 187: MATLAB Signal Processing Toolbox user manual

Using SPTool

5-7

Context Sensitive… Select Con text Sen sit ive… from the File menu for help on aspecific par t of SPTool. When you click on Context Sen sit ive…, t he mousepoin ter becomes an ar row with a quest ion mark symbol. You can then click onanyth ing in SPTool, including menu it ems, to find out wha t it is and how to useit .

Importing Signals, Filters, and SpectraYou can impor t a signa l, filt er , or spect rum into SPTool from either theworkspace or from a file.

Select Import… from the File menu to open the Import to SPTool window:

Loading Variables from the MATLAB WorkspaceTo impor t va r iables from the MATLAB workspace, fir st list t he workspacevar iables in the Workspace Conten ts list . Then select the va r iables to beimpor ted in to SPTool:

Load the contents of a file into the File Contents list by clicking here, and

either typing a filename in the box and pressing Tab or Enter, or pressing

Browse and selecting a MAT-file.

Display all MATLAB workspace variables in the

Workspace Contents list box by clicking here.

Workspace Contents or File Contents list.

Page 188: MATLAB Signal Processing Toolbox user manual

5 Interactive Tools

5-8

1 Click the From Workspace radio but ton .

The contents of the MATLAB workspace are displayed in the WorkspaceConten ts list .

2 You can now impor t one or more var iables from the Workspace Conten tslist in to SPTool. See “Impor t ing Workspace Conten t s and File Conten ts”below.

Loading Variables from DiskTo impor t va r iables from a MAT-file on disk, fir st list t he file’s var iables in theFile Conten ts list . Then select the var iables to be impor ted in to SPTool:

1 Click the From Disk radio but ton .

2 Type the name of the file you want to impor t in to the MAT-fi le Name fieldand press Tab or Enter.

or

P ress Brow se , and then find and select the file you want to impor t using theF ile Search window. Press OK.

The da ta from the file you select ed is displayed in the File Conten ts list .

3 You can now impor t one or more var iables from the File Con ten ts list in toSPTool (see below).

Importing Workspace Contents and File ContentsOnce you’ve loaded the conten ts of the workspace or a file in to the WorkspaceCon ten ts or File Conten ts list , you can select one or more var iables from thelist to impor t in to SPTool. You can impor t a va r iable as a signa l, a filt er , or aspect rum. You can a lso impor t a var iable whose va lue represen t s a samplingfrequency or other design parameter .

Depending on whether you’re impor t ing a signa l, a filt er , or a spect rum, youcan customize differen t pa rameters before you impor t the da ta in to SPTool. Ineach case, however , the genera l procedure for specifying a var iable or a va lueis the same. In the following example, the selected va r iable is being impor t edas a signa l. See “Impor t ing a Signa l” on page 5-10, “Impor t ing a F ilter” on page

Page 189: MATLAB Signal Processing Toolbox user manual

Using SPTool

5-9

5-11, and “Impor t ing a Spect rum” on page 5-13 for deta ils on customizingvar iables tha t a re impor t ed in to SPTool.

1 Click on a var iable name in the Workspace Conten ts list or theFile Conten ts list t o select it .

If the var iable is not a saved data object from SPTool, select the appropr ia teda ta type (Signal, Filte r , or Spectrum ) from the Import As pop-up menuand type a name in to the Name field.

If the va r iable is a saved data object from SPTool, it s name is displayed inthe Name field, and it s type (Signa l, Filte r , or Spectrum ) is au tomat ica llyselected in the Import As pop-up menu .

2 Press the a r row at the left of the Data field. The select ed va r iable ist ransfer red to the Data field.

NOTE You can also type a var iable name in to the Data field direct ly.

3 To change the sampling frequency of the var iable you’re impor t ing, you caneither :

a Click on a var iable in the Workspace Conten ts list or File Conten ts listwhose va lue is a sampling frequency, and then press the ar row a t the leftof the Sampling Frequency field.

The selected var iable is t ransfer red to the Sampling Frequency field.

or

b Type a value or va r iable name in the Sampling Frequency field.

Page 190: MATLAB Signal Processing Toolbox user manual

5 Interactive Tools

5-10

4 Press OK.

The signa l is impor t ed in to SPTool with the specified name and samplingfrequency.

5 To impor t another va r iable, select Import… aga in , press the FromWorkspace or From File radio bu t ton, and repea t steps 1 through 4 for eachvar iable tha t you want to load in to SPTool.

NOTE When you’re impor t ing from the workspace, you can specify either ava r iable or a va lue for each data field. When you’re impor t ing from a disk, youcan only specify var iables.

Importing a Signal. When you impor t a signa l, you specify:

•A var iable name for the signa l da ta (or the signa l da ta va lues) in the Datafield

•A var iable or a va lue for the signa l’s sampling frequency in the SamplingFrequency field

Page 191: MATLAB Signal Processing Toolbox user manual

Using SPTool

5-11

Importing a Filter. When you impor t a filt er , fir st select the appropr ia t e filt erform from the Form pop-up menu .

Each filter form requires differen t var iables.

• For Transfer Function , you specify the filt er by it s t ransfer funct ionrepresen ta t ion :

- The Numerator field specifies a var iable name or va lue for the numera torcoefficien t vector b, which conta ins m +1 coefficien ts in descending powersof z.

- The Denominator field specifies a var iable name or va lue for thedenomina tor coefficient vector a , which conta ins n+1 coefficien t s indescending powers of z.

• For State Space , you specify the filt er by it s sta te-space represen ta t ion :

The A-Matrix , B-Matrix , C-Matrix , and D-Matrix fields specify a va r iablename or a va lue for each mat r ix in this syst em.

• For Zeros , P o le s , Gain , you specify the filter by it s zero-pole-ga inrepresen ta t ion :

H z( ) B z( )A z( )----------- b 1( ) b 2( )z 1– L b m 1+( )z m–+ + +

a 1( ) a 2( )z 1– L a n 1+( )z n–+ + +------------------------------------------------------------------------------------= =

x· Ax B u+=y Cx Du+=

Page 192: MATLAB Signal Processing Toolbox user manual

5 Interactive Tools

5-12

- The Zeros field specifies a var iable name or va lue for the zeros vector z,which conta ins the loca t ions of m zeros.

- The Pole s field specifies a var iable name or va lue for the zeros vector p ,which conta ins the loca t ions of n poles.

- The Gain field specifies a var iable name or va lue for the ga in k .• For 2nd Order Section s you specify the filt er by it s second-order sect ionrepresen ta t ion :

The SOS Matrix field specifies a var iable name or a va lue for the L -by-6 SOSmatr ix

whose rows conta in the numera tor and denomina tor coefficien ts bik and a ikof the second-order sect ions of H (z):

• For every filt er , you specify:A var iable name or a va lue for the filter ’s sampling frequency in theSampling Frequency field

H z( ) Z z( )P z( )---------- k z z 1( )–( ) z z 2( )–( )Lz z m( )–( )

z p 1( )–( ) z p 2( )–( )Lz p n( )–( )---------------------------------------------------------------------------------= =

H z( ) H k z( )k 1=

L

∏b0 k b1 k z 1– b2 k z 2–+ +1 a1 k z 1– a2 k z 2–+ +----------------------------------------------------------

k 1=

L

∏= =

sos

b01 b11 b21 1 a11 a21b02 b12 b22 1 a12 a22M M M M M M

b0L b1L b2L 1 a1L a2L

=

Page 193: MATLAB Signal Processing Toolbox user manual

Using SPTool

5-13

Importing a Spectrum. When you impor t a spect rum, you specify:

•A var iable name or a value for the power spect ra l density (PSD) vector in thePSD field

•A var iable name or a va lue for the frequency vector in the Freq. Vector field

The PSD values in the PSD vector cor respond to the frequencies conta inedin the Freq. Vector vector ; the two vectors must have the same length .

Working with Signals, Filters, and SpectraWhen a signa l, filter , or spect rum is impor ted into SPTool or crea ted in SPTool,it is displayed in the appropr ia t e list box, as shown below. Using the Edit menufunct ions and SPTool but tons, you can edit var ious proper t ies of the da ta inSPTool and invoke all of SPTool’s digit a l signa l processing funct ions.

Page 194: MATLAB Signal Processing Toolbox user manual

5 Interactive Tools

5-14

Component Lists in SPToolEach signa l, filt er , and spect rum in SPTool is displayed in the appropr ia teSignals list , Filte rs list , or Spectra list .

• Signals a re displayed with the signal type [vector] or [array]:- A vector signal ([vector]) has one column of da ta .- An array signal ([array]) has more than one column of da ta .

• Filter s a re displayed with the filter type [design] or [imported]:- A designed filter ([design]) is a filter tha t was crea ted using the F ilt erDesigner . This type of filt er can a lso be edit ed in the Filter Designer .

- An im ported filter ([imported]) is a filt er tha t was impor ted from theMATLAB workspace or a file, or one tha t was edit ed in the Pole/ZeroEditor .

Spectrum View buttonSignal View button

Filter View button

Signals list

Filters list

Spectra list

Page 195: MATLAB Signal Processing Toolbox user manual

Using SPTool

5-15

• Spect ra are displayed with the spectrum type [auto]:An auto-spectrum ([auto]) is a spect rum whose source is a single signa l, asopposed to the cross-spect rum of two channels of da ta . spectrum[auto] is t heon ly spect rum type in SPTool.

Selecting Data Objects in SPToolEach signa l, filter , and spect rum in SPTool is one data object . A data object isselected when it is h igh lighted. When you first impor t or crea te a da ta object ,it is selected.

The Signals list shows all vector and a r ray signa ls in the curren t SPToolsession .

The Filte rs list shows a ll designed and impor ted filt ers in the cur ren t SPToolsession .

The Spectra list shows all spect ra in the cur ren t SPTool session .

You can select a single da ta object in a list , a range of da ta objects in a list , ormult iple separa t e da ta objects in a list . You can also have da ta objectssimultaneously selected in different list s:

• To select a single unselected da ta object , click on it . All other da ta objects intha t list box become unselected.

• To add or remove a range of da ta object s, Sh ift-click on the da ta objects a tthe top and bot tom of the sect ion of the list t ha t you want to add.

• To add a single da ta object to a select ion or remove a single da ta object froma mult iple select ion , Ctrl-click on the object . You can also use the r igh tmouse but ton .

Editing Data Objects in SPToolThe Edit menu ent r ies a re ava ilable only when there is a t lea st one select eddata object (signa l, filt er , or spect rum) in SPTool. Use the Edit menu toduplica t e and clear object s in SPTool and to edit object names and changesampling frequencies.

A signa l, filter , or spect rum must be select ed to be edit ed. When you click on anEdit menu ent ry, a ll selected da ta objects are displayed in a pop-up menu .

Page 196: MATLAB Signal Processing Toolbox user manual

5 Interactive Tools

5-16

To edit an SPTool object :

1 Select a signa l, filter , or spect rum.

2 Select the appropr ia te Edit menu funct ion .

The pop-up menu shows the names of a ll selected data objects.

3 Drag to choose a specific signa l, filt er , or spect rum for edit ing.

Duplicate. Use Duplicate from the Edit menu to make a copy of the selectedsigna l, filter , or spect rum in SPTool.

Select Duplicate and drag to choose the signa l, filt er , or spect rum you want tocopy. When you select a da ta object to duplica te it , a new data object of thesame type is automat ica lly crea t ed. The new data object is named as a copy ofthe selected da ta object . It is placed a t the bot tom of the list and is select ed. Youcan change it s name using Name… from the Edit menu.

Clear. Use Clear from the Edit menu to delete the select ed signa l, filt er , orspect rum from SPTool.

Select Clear and drag to choose the signa l, filt er , or spect rum you want toremove. The da ta object is deleted from the cur ren t SPTool session .

Name. Use Name… from the Edit menu to give the select ed signa l, filter , orspect rum a new, un ique name.

1 Select Name ... and drag to choose the signa l, filt er , or spect rum you want torename.

The Name Change dia log box is displayed.

2 Type in the new name and press OK.

Sampling Frequency. Use Sampling Frequency… from the Edit menu to supplya sampling frequency for a selected signa l or filt er . The sampling frequencymay be a number , such as 1, 0.001, or 1/5000, or a va lid MATLAB expressionincluding workspace var iables, such as Fs, 1/Ts, or cos(0.1*pi).

Page 197: MATLAB Signal Processing Toolbox user manual

Using SPTool

5-17

1 Select Sampling Frequency... and drag to choose the signa l or filter youwant to change.

The Sampling Frequency ... dia log box is displayed.

2 Type in the va lue, var iable name, or expression and press OK.

Viewing a SignalUse the Signal View but ton to make the Signal Browser act ive and view one ormore impor t ed signa ls. The Signa l Browser provides tools for graph ica lana lysis of the selected signa l(s).

Select one or more signa ls from the Signals list and press the View but ton inthe signa l panel. The Signal Browser displays the select ed signa l(s). See “Usingthe Signa l Browser : In teract ive Signal Analysis” on page 5-43 for a fulldescr ipt ion of Signa l Browser funct ions and opera t ions.

Viewing a FilterUse the View but ton in the Filte rs panel to make the F ilt er Viewer act ive andview impor t ed filter s or filt ers designed/edit ed in the Filter Designer . TheF ilter Viewer provides tools for ana lyzing filt ers; you can invest iga te themagnitude response, phase, group delay, zeros and poles, and impulse and stepresponses of the select ed filt er s.

Select one or more filt ers from the Filte rs list and press the View but ton in thefilt er panel. The Filter Viewer displays the select ed filt ers. See “Using theF ilter Viewer : In t eract ive Filter Analysis” on page 5-84 for a fu ll descr ipt ion ofF ilter Viewer funct ions and opera t ions.

Designing a Filter

New Design. Use the Filter New Des ign but ton to make the F ilt er Designeract ive and design a filt er . The Filter Designer let s you crea t e FIR and IIRdigita l filt ers of va r ious lengths and types using the filter design funct ions inthe Signa l Processing Toolbox.

Press the New Des ign but ton in the Filte r panel. The F ilter Designer displaysa filter crea ted with the default set t ings and assigns it a default name of filtn,where n is a unique sequent ia l iden t ifying digit . Once the default filt er iscrea ted, you can use it as is or edit it with the Filter Designer . You can renameit using Name… from the Edit menu.

Page 198: MATLAB Signal Processing Toolbox user manual

5 Interactive Tools

5-18

Edit Design. Use the Filte r panel’s Edit Des ign but ton to make the F ilt erDesigner act ive and edit a filt er . Impor ted filt ers a lways open in the Pole/ZeroEditor .

Select one or more filter s from the Filte rs list and press the Edit De signbut ton in the filt er panel. The Filter Designer displays the fir st of the select edfilter s. The other selected filter s can be edited, one a t a t ime, by select ing themfrom the Filte r pop-up menu . See “Using the Filter Designer : In t eract ive FilterDesign” on page 5-59 for a fu ll descr ipt ion of F ilt er Designer funct ions andopera t ions.

Applying a FilterUse the Apply F ilte r but ton to apply a filt er to a select ed signa l. Th is crea t esa new signal:

1 Select one signa l from the Signa ls list and one filt er from the Filte rs list andpress the Apply Filte r but ton in the filt er panel.

The Apply Filte r dia log box is displayed.

2 Select the filt er ing a lgor ithm from the Algorithm pop-up menu , type thename for the new signa l in the Output Signal field, and press OK.

The available filt er a lgor ithms are:- Transposed direct -form II (uses the filter funct ion)- Zero-phase IIR (uses the filtfilt funct ion)- FFT-based FIR (uses the fftfilt funct ion)

The selected filt er is applied to the select ed input signa l and the new outputsignal is list ed in the Signals list .

Drag to select the

algorithm you want

to use.

Type the new signal

name here.

Page 199: MATLAB Signal Processing Toolbox user manual

Using SPTool

5-19

Creating a SpectrumUse the Create but ton to act iva te the Spect rum Viewer and genera te a defau ltspect rum of a select ed signa l. Once you’ve genera t ed a spect rum, you can viewit in a va r iety of ways, measure it , and modify it in the Spect rum Viewer .

1 Select one signa l from the Signals list and press the Create but ton in theSpectra panel.

The Spect rum Viewer is act iva t ed and a spect rum object with defau ltparameters is crea ted in the Spectra panel. The PSD data is not computedor displayed yet . The newly crea ted spect rum object has a defau lt name ofspecn, where n is a un ique sequent ia l iden t ifying digit . Once the spect rumobject is crea ted, you can use it with the defau lt set t ings, or con t inue to editit in the Spect rum Viewer . You can rename it using Name… from the Editmenu.

2 Modify the spect rum parameters (e.g., Method and Nfft) as desired.

3 Press Apply in the Spect rum Viewer to compute the spect rum da ta . Thisbut ton is enabled when the spect rum has just been crea t ed or when you havechanged one or more pa rameters in the Spect rum Viewer .

The upda ted spect rum is displayed in the Spect rum Viewer . See “Using theSpect rum Viewer : In teract ive PSD Analysis” on page 5-97 for a fu lldescr ipt ion of Spect rum Viewer pa rameters and displays.

Viewing a SpectrumSelect one or more spect ra from the Spectra list and press View in the Spectrapanel. The Spect rum Viewer displays the selected spect rum or spect ra .

Updating a SpectrumUse the Update but ton to upda te the selected spect rum so tha t it reflects theda ta in the curren t ly select ed signa l.

1 Select one signa l from the Signals list and one spect rum from the Spectralist and press Update in the Spectra panel.

The spect ra l da ta from the cur ren t spect rum is removed from the Spect rumViewer . The Spect rum Viewer is act iva ted. No spect rum is displayed yet .

Page 200: MATLAB Signal Processing Toolbox user manual

5 Interactive Tools

5-20

2 Press Apply in the Spect rum Viewer to compute the spect rum and completethe update.

The spect rum is regenera ted with the same parameter s bu t using the da tain the curren t ly select ed signa l. This fea ture is usefu l when you have a ltereda signa l (by filter ing it , for example), and want to upda te the exist ingspect rum to reflect the change.

Customizing PreferencesUse Pre ference s… from the File menu to customize displays and cer t a inpa rameter s for SPTool and it s four component tools. The new set t ings a resaved on disk and are used when you resta r t MATLAB.

In the Pre ference s panels, you can:

• Select colors and markers for ru lers, and set the in it ia l ruler style• Select color and line style sequence for displayed signa ls•Configure axis labels, and enable/disable ru lers, panner , and mouse zoom inthe Signal Browser

•Configure axis parameters, and enable/disable ru lers and mouse zoom in theSpect rum Viewer

•Configure filter and axis parameters and enable/disable mouse zoom in theFilter Viewer

•Configure t iling preferences in the Filter Viewer• Specify FFT length , and enable/disable mouse zoom and gr id in the F ilterDesigner

• Enable/disable use of a default session file•Configure filter s for expor t to the Control System Toolbox (for users of tha tproduct )

• Enable/disable search for plug-ins a t st a r t -up

When you fir st select Pre ference s…, the Pre ference s dia log box displays theRulers panel. You can change the set t ings for ru lers, or choose on any of theother set t ings ca tegories to customize other set t ings.

Click once on a set t ings ca tegory to select it .

Page 201: MATLAB Signal Processing Toolbox user manual

Using SPTool

5-21

The following sect ions descr ibe a ll of the set t ings you can modify. Theillust ra t ions show the default set t ings for each ca tegory. For addit iona lin format ion on preference set t ings, use the He lp ... but ton a t the bot tom of thePre fe rence s dia log box.

Ruler SettingsThe Rulers preferences apply to the ru lers in the Signal Browser , Spect rumViewer , and F ilt er Viewer . These preferences a lso apply to pr in tou ts from theSigna l Browser and Spect rum Viewer .

Ruler Color. Specifies the color of the ru lers. Color is specified as a st r ing(e.g., 'r') or RGB tr iple (e.g., [1 0 0]).

Ruler Marker. Specifies the marker used in the t rack and slope ru lers.

Marker Size. Specifies the size of the ru ler marker in poin ts. This can be anyposit ive va lue.

Initial Type. Specifies the type of ru ler (hor izonta l, ver t ica l, t rack, or slope) tha tis selected when you first open the Signa l Browser , Spect rum Viewer , or F ilt erViewer .

Page 202: MATLAB Signal Processing Toolbox user manual

5 Interactive Tools

5-22

Color SettingsThe Colors preferences apply to signa ls displayed in the Signal Browser ,Spect rum Viewer , and Filt er Viewer . These preferences a lso apply to pr in tou tsfrom the Signa l Browser and Spect rum Viewer .

Color Order. Specifies the color order to cycle through for da ta plot ted in theSignal Browser , Spect rum Viewer , and Filter Viewer . The defau lt is the axiscolor order .

Type in a new value or va lue st r ing to change the color order . Color is specifiedas a st r ing (e.g., 'r') or RGB t r iple (e.g., [1 0 0]), an n -by-3 mat r ix of n colors,or an n -by-1 cell a r ray of such object s.

Line Style Order. Specifies the line styles to cycle through for da ta plot t ed in theSignal Browser , Spect rum Viewer , and Filter Viewer . The defau lt is the axisline style order .

Type in a new st r ing va lue (e.g., '--') or an ar ray of st r ings(e.g., {'-','--',':'}) to change the line style order .

Page 203: MATLAB Signal Processing Toolbox user manual

Using SPTool

5-23

Signal Browser SettingsThe Signal Brow se r preferences let you set opt iona l x-axis and y-axis labels,enable and disable the display of the ru lers and the panner , and toggle zoompersistence.

Except for zoom persistence, these preferences a lso apply to pr in t ing from theSigna l Browser . See “Pr in t ing Signa l Data” on page 5-54 for deta ils on pr in t ingfrom the Signal Browser .

X Label, Y Label. Type in a st r ing for the x-axis label and the y-axis label in theSigna l Browser . The default is Time for the x-axis.

Rulers. Click in the check box to display (checked) or h ide (unchecked) the rulerbu t tons and the ru ler panel in the Signal Browser . See “Ruler Controls” onpage 5-33 for deta ils on using the rulers in the Signal Browser .

Panner. Click in the check box to display (checked) or h ide (unchecked) thepanner in the Signa l Browser . See “Panner Display” on page 5-52 for deta ils onusing the panner in the Signa l Browser .

Stay in Zoom-mode After Zoom. Click in the check box to enable (checked) ordisable (unchecked) zoom persist ence in the Signal Browser . See “ZoomControls” on page 5-31 for deta ils on zoom cont rols in the Signa l Browser .

Page 204: MATLAB Signal Processing Toolbox user manual

5 Interactive Tools

5-24

Spectrum Viewer SettingsThe Spectrum View er preferences let you set axis parameter s, enable anddisable the display of the ru ler s, and toggle zoom persistence.

Except for zoom persistence, these preferences a lso apply to pr in t ing from theSpect rum Viewer . See “Prin t ing Spect rum Data” on page 5-107 for deta ils onpr int ing from the Spect rum Viewer .

Magnitude Axis Scaling. Specifies the sca ling unit s for the magnitude (y) axis inthe Spect rum Viewer . Sca ling unit s can be dec ibe ls or linear.

Frequency Axis Scaling. Specifies the sca ling unit s for the frequency (x) axis in theSpect rum Viewer . Sca ling unit s can be lin ear or log .

Frequency Axis Range. Specifies the numer ica l range for the frequency (x) axis inthe Spect rum Viewer . Sca ling opt ions are [0,Fs /2], [0,Fs], or [-Fs /2,Fs /2].

Rulers. Click in the check box to display (checked) or h ide (unchecked) the ru lerbu t tons and the ru ler panel in the Spect rum Viewer . See “Ruler Controls” onpage 5-33 for deta ils on using the ru lers in the Spect rum Viewer .

Stay in Zoom-mode After Zoom. Click in the check box to enable (checked) ordisable (unchecked) zoom persistence in the Spect rum Viewer . See “ZoomCont rols” on page 5-31 for deta ils on zoom cont rols in the Spect rum Viewer .

Page 205: MATLAB Signal Processing Toolbox user manual

Using SPTool

5-25

Filter Viewer SettingsThe Filte r View er preferences let you set key filt er plot configura t ionparameters and toggle zoom persistence.

FFT Length. Specifies the number of poin ts a t which the frequency response iscomputed (for the magnitude, phase, and group delay plot s).

Time Response Length. Specifies the t ime response length (in samples) for theimpulse and step response plots. An empty value, [ ], for an FIR filter indica t estha t the complete response length will be shown; an empty va lue for an IIRfilt er indica tes tha t the response length will be automa t ica lly determined usingthe impz funct ion .

Magnitude Axis Scaling. Specifies the sca ling unit s for the magnitude (y) axis inthe F ilt er Viewer . Sca ling unit s can be linear, log , or dec ibe ls .

Phase Units. Specifies the phase unit s for the phase response plot . Phase unit scan be degree s or radians .

Frequency Axis Scaling. Specifies the sca ling unit s for the frequency (x) axis in theF ilter Viewer . Sca ling unit s can be linear or log .

Frequency Axis Range. Specifies the numer ica l range for the frequency (x) axis inthe F ilt er Viewer . Sca ling opt ions a re [0,Fs/2], [0,Fs ], or [-Fs/2,Fs/2].

Page 206: MATLAB Signal Processing Toolbox user manual

5 Interactive Tools

5-26

Rulers. Click in the check box to display (checked) or h ide (unchecked) the ru lerbu t tons and the ru ler panel in the Filt er Viewer . See “Ruler Controls” on page5-33 for deta ils on using the ru lers in the F ilt er Viewer .

Stay in Zoom-mode After Zoom. Click in the check box to enable (checked) ordisable (unchecked) zoom persistence in the Filter Viewer . See “Zoom Controls”on page 5-31 for deta ils on zoom cont rols in the Filter Viewer .

Filter Viewer Tiling SettingsThe Filte r View er–Tiling preferences let you change the way the Filter Viewerdisplays the ana lysis plots.

Click the radio but ton to select how the plots are t iled in the display area .Opt ions are 2-by-3 Grid , 3-by-2 Grid , Vertica l (6-by-1 Grid), andHorizon tal (1-by-6 Grid).

This specifies how the plots are ar ranged when all six plot opt ions a re tu rnedon. When fewer opt ions are turned on , the plots a re displayed as symmetr ica llyas possible.

Page 207: MATLAB Signal Processing Toolbox user manual

Using SPTool

5-27

Filter Designer SettingsThe Filte r De signer preferences let you set key filter configura t ion and plotparameters.

FFT Length. Specifies the number of poin ts used to ca lcu la t e a filter ’s frequencyresponse.

Display grid lines. Turns plot gr id lines on (checked) or off (unchecked).

Auto Design – initial value. Specifies the defau lt set t ing for the Auto Des ign checkbox in the F ilt er Designer . When the Filter Designer is fir st launched, the AutoDes ign check box will have the same set t ing (checked or unchecked) as theAuto Des ign – in it ia l va lue check box here.

Stay in Zoom-mode After Zoom. Turns persist en t zooming on and off, as descr ibedin “Zoom Controls” on page 5-31.

Page 208: MATLAB Signal Processing Toolbox user manual

5 Interactive Tools

5-28

Default Session SettingThe Defau lt Se ss ion preference lets you specify whether or not to load adefault session file when SPTool is launched.

Default Session. Enables (checked) or disables (unchecked) loading of a defaultsession file, which must have the name startup.spt, when sta r t ing SPTool.An SPTool session file is a MAT-file (see Using MATLAB ) with a .sptextension .

The Defau lt Se ss ion preference only a ffects the session conten ts when yousta r t SPTool. You can load a new session file after sta r t ing SPTool using theOpen Se ss ion opt ion in the SPTool File menu. You can also save a session filea t any t ime using the Save Se ss ion opt ion in the File menu. If you close SPToolwithout having recen t ly saved a session file, you will be prompted to do so. (See“File Menu” on page 5-6.)

NOTE Changes tha t you make in the SPTool preference panels are saved ina separa te MAT-file, which is reloaded the next t ime you open SPTool (see“Saving and Disca rding Changes to Preferences Set t ings” on page 5-30). TheDe fau lt Se ss ion preference does not a ffect these preference set t ings.

Page 209: MATLAB Signal Processing Toolbox user manual

Using SPTool

5-29

Exporting Components SettingThe Exporting Components preference lets you specify whether or not toexpor t filter s crea t ed in SPTool as TF object s for the Control System Toolbox.

Export Filters as TF objects. Enables (checked) or disables (unchecked) expor t ing ofSPTool filt er s a s TF (t ransfer funct ion) objects, for use in the Control SystemToolbox (see the Control S ystem Toolbox User’s Guide).

NOTE This preference ca tegory only appears in the in SPTool Pre ference sdia log box if you have insta lled the Control System Toolbox.

Page 210: MATLAB Signal Processing Toolbox user manual

5 Interactive Tools

5-30

Plug-Ins SettingThe P lug-Ins preference let s you search for plug-ins when SPTool is sta r t ed up.

Search for Plug-Ins at start-up. Enables (checked) or disables (unchecked)searching for insta lled plug-ins.

A plug-in is an extension to SPTool. P lug-ins include customized add-on panelsand new but tons in the panels in SPTool, new spect ra l methods in theSpect rum Viewer , and new SPTool preferences. You can a lso plug one or moretoolboxes in to SPTool.

You need to use th is set t ing only when you have insta lled extensions or haveother toolboxes plugged in to SPTool.

To use SPTool with extensions, check Search for P lug-in s at start-up , closeSPTool, and rest a r t it .

Saving and Discarding Changes to Preferences SettingsThe but tons a t the bot tom of the Pre fe rence s panels let you save or discardany changes you have made, or retu rn to the default set t ings.

Factory Settings. Restores the preferences in the cur ren t panel to their or igina lset t ings; tha t is, the set t ings a t the t ime the Signa l Processing Toolbox wasfir st inst a lled.

Page 211: MATLAB Signal Processing Toolbox user manual

Using SPTool

5-31

Revert Panel. Cancels changes in the cur ren t panel on ly. Set t ings in the cur ren tpanel rever t to the previous set t ings.

Cancel. Cancels changes in a ll preference ca tegor ies and closes thePre fe rence s dia log box. Set t ings in a ll panels rever t to their previous sta te.

OK. Applies changes in a ll Pre ference s panels and closes the Pre ference sdia log box. Set t ings in a ll panels a re saved in a MAT-file ca lled sigprefs.mat.

If sigprefs.mat does not exist , either on the cur ren t MATLAB path or in thecur ren t directory, you are prompted for a loca t ion to save the file. The savedset t ings a re used the next t ime you open SPTool.

Controls for Viewing and MeasuringThe GUI tools share common cont rols for viewing and measur ing signa ls.These con t rols are descr ibed in th is sect ion . Not a ll tools use a ll of the viewingand measur ing cont rols; specific deta ils about the tools and procedures forviewing and measur ing are descr ibed in the sect ion on each tool.

Zoom ControlsThe GUI tools share a common set of zoom control bu t tons. The Signa l Browserand Spect rum Viewer use the same set of common zoom cont rol bu t tons, whichaffect both on-screen and pr in ted images.

The F ilt er Designer has one addit iona l viewing but ton , the Pass Band but ton .

The F ilt er Viewer has a subset of the zoom control bu t tons.

Each but ton works the same way in every GUI tool in which it occurs.

In ordina ry use, you press a bu t ton once to zoom in or ou t of the signa l display.

Page 212: MATLAB Signal Processing Toolbox user manual

5 Interactive Tools

5-32

Zoom In-X, Zoom Out-X, Zoom In-Y, and Zoom Out-Y. Click once to per form one zoomopera t ion (in or ou t ) on the x- or y-axis. Each zoom opera t ion changes the axeslimit s by a factor of two on the specified axis, about the cen ter of the displayedsigna l. You can press repea tedly on one or more but tons to con t inue to changethe sca le in one or both axes.

When you zoom in the x-axis (hor izonta l sca ling), the y limit s (ver t ica l sca ling)of the main axes a re not changed. Simila r ly, when you zoom in the y-axis, thex limit s of the main axes are not changed.

Full View. Click once to restore the displayed signa l to it s fu ll range in both axes.

Mouse Zoom. Click once to act iva t e zoom mode. The cursor changes to acrossha ir . You can either zoom in withou t specifying a zoom window, or you canuse a zoom rectangle to select a specific zoom window. In either case, the x- andy-axis are automa t ica lly adjusted to display the select ed signa l:

• To zoom in withou t specifying a zoom window, click on the plot . The posit ionof the crossha ir is the cen ter of a zoom opera t ion tha t ha lves both the x- andy-axis limits.

• To use a zoom rectangle, click where you want the rect angle to begin , dragthe mouse diagona lly to where you want it to end, and release the mousebut ton .

• To get ou t of mouse zoom mode withou t zooming in or ou t , press the MouseZoom but ton again .

Zoom Persistence. Mouse zooming can either be one-tim e or persisten t:

•One-t ime zooming is act iva ted when you press the Mouse Zoom but ton . Itau tomat ica lly tu rns it self off a fter you click in the display a rea and the zoomopera t ion occurs. This is the default for a ll the tools.

• Persist en t zooming is a lso act iva ted by pressing the Mouse Zoom but ton . Itdoes not turn off a ft er you click in the display area and a zoom opera t ionoccurs; you can cont inue to click and zoom without reset t ing the MouseZoom but ton .

You can change whether zooming is one-t ime or persistent by select ingPre ference s… from the File menu and toggling Stay in Zoom-mode AfterZoom in the Pre ference s panels for the Signa l Browser , the Spect rum Viewer ,the Filter Designer , and the Filter Viewer .

Page 213: MATLAB Signal Processing Toolbox user manual

Using SPTool

5-33

When Stay in Zoom-mode After Zoom is selected, zooming is persist en t . Toturn off mouse zooming when Stay in Zoom-mode After Zoom is selected,press the Mouse Zoom but ton .

Passband Zoom (Filter Designer). Click once to zoom in on the passband of theresponse.

Both the x- and y-limits of the ma in axes are changed so tha t the passband fillsthe main axes.

There is no stopband zoom but ton . To zoom the stopband, use st andard MouseZoom , cen ter ing the crossha ir on the area of the stopband you want to view. Ifyou are in passband zoom, fir st press Full View t o return to the standa rd view.

Ruler ControlsThe Signal Browser , F ilt er Viewer , and Spect rum Viewer share a common setof ruler con t rols. Use the ru ler s to make measurements on the signals orspect ra in the main axes (display) a rea . The ru ler con t rols give you a var iety ofways to read and cont rol the va lues of the ru lers in the main axes. With theru lers you can measure such informa t ion as the ver t ica l and hor izonta ldistance between fea tures in a signa l or spect rum, the dimensions of peaks andvalleys, and slope informat ion .

In the following discussion , the Signa l Browser is shown. The ru ler con t rolsinclude the Se lec tion cont rols a t the top r igh t of the window and the but tonsand edit boxes in the Rule rs panel. The cont rols in the Filter Viewer andSpect rum Viewer work the same way. The cont rols in the Signa l Browser andthe Spect rum Viewer a lso affect images pr in ted from these tools.

In the F ilter Viewer , the ru lers appear on only one subplot a t a t ime. You canchoose which subplot the rulers appear on by select ing the subplot from thepop-up menu a t the top of the Rulers panel, or by clicking on a line in the plottha t you want to measure. If a subplot is not cur ren t ly visible when you selectit s name from the pop-up menu , the Filter Viewer crea tes the subplot andplaces the ru ler s in it .

Page 214: MATLAB Signal Processing Toolbox user manual

5 Interactive Tools

5-34

Selecting a Line to Measure. When there is on ly one signa l displayed, the displayedsigna l is au tomat ica lly selected and is measured when you use the ru lers.When there is more than one signa l displayed, on ly one signa l (line) may beselected and measured a t a t ime.

When a signa l (line) is selected, you can use the ru ler con t rols (Vertica l ,Horizon tal, Track , or Slope ) and the Peaks and/or Valleys cont rols on theselected line. The label of the selected signa l (line) is displayed in the Se lectionpop-up menu .

There a re two ways to select a signal (line):

•Click on the Se lection pop-up menu and drag to select the line to measure.All signa ls tha t a re cur ren t ly select ed in SPTool are list ed. Vector signa ls inthe Signa l Browser , spect ra in the Spect rum Viewer , and filt ers in the F ilt erViewer are listed as single va r iables; in the Signa l Browser , each column ofa two-dimensiona l signa l mat r ix is list ed as a separa te va r iable.

•Move the mouse poin ter over any point in the line you want to select and clickon it .

Find ruler buttons

Ruler control buttons

Selection pop-up menu Selection display

Color… button

Rulers panel

Display peaks and valleys

buttons

Save Rulers… button

Edit boxes

Page 215: MATLAB Signal Processing Toolbox user manual

Using SPTool

5-35

The label of the signa l, including the column number if the line is one columnof a mat r ix, is displayed in the Se lection pop-up menu .

The line select ion display changes to the color and pat t ern of the selectedsigna l, spect rum, or filter .

Line Selection Pop-Up Menu. Use to select a line (vector signa l, a r ray column,filt er , or spect rum) to measure.

Click the Se le c tion pop-up menu and drag to select the line.

Line Selection Display. The line color and style of the selected signa l a re displayed.

Color… Button. Use to edit the line style or display color of the select ed line.

Click on the Color… but ton a t the top r igh t of the window to display theEdit Line pop-up menu , which is shown on the left . The label of the selectedline is displayed in the Labe l field.

•Click the Line Style pop-up menu and drag to select a line style, a s shownon the left .

•Click a radio but ton to select a color . If you select Other, you can type a colorva lue in the Ente r colorspe c box; the color va lue can be a st r ing (e.g., 'r')or an RGB tr iple (e.g., [1 0 0]).

•Click OK to apply the line style and color you select ed.

Find Ruler Buttons. Use the find ru ler but tons to br ing one or both ru lers in to theviewing area of the main axes. When both ru lers are with in the signa l display(main axes) area , the Find Ruler but tons, a t the top r ight of the main axesarea , a re not displayed.

If the ru lers are not with in the signa l display area , both Find Rule rbut tons a re displayed, as shown on the r ight .

If one ru ler is with in the signa l display area , the but ton for the otherru ler is displayed, a s shown on the r ight .

Click a Find Ruler but ton to br ing the specified ru ler in to the display area .

When a ru ler is visible, you can click on it and drag it to make a measurementon the selected signa l. See “Making Signal Measurements” on page 5-37 fordeta ils on manipula t ing the ru lers and measur ing the selected signa l.

Page 216: MATLAB Signal Processing Toolbox user manual

5 Interactive Tools

5-36

Ruler Control Buttons. Use the ruler con t rol bu t tons to select the type ofmeasurement you want to make: Vertica l, Horizon tal, Track , or Slope . Thedefau lt set t ing is Track .

Click a ru ler con t rol but ton to select it . The Rule rs panel changes dependingon which ru ler con t rol is selected. See “Making Signa l Measurements” on page5-37 for deta ils on the four kinds of measurements you can make and thepa rameters for each one.

Rulers Panel and Edit Boxes. The Rulers panel changes depending on which ru lercon t rol is select ed: Vertica l, Horizon tal, Track , or Slope . It shows thepa rameter s for the selected ruler con t rol. Depending on which ru ler con t rol isselected, the following fields are displayed: x1 , y1 , x2 , y2, dx , dy , m . Thepictu re on the left shows the Rulers panel when Slope is selected.

When you press a ru ler con t rol but ton , ru ler s a re displayed super imposed onthe signa l(s) in the main axes display area . The ru lers a re either ver t ica l (forVertica l, Track , and Slope ) or hor izon ta l (for Horizon tal). For Track andSlope , ru ler markers are a lso displayed. The rulers and ru ler markers areassocia t ed with the curren t ly selected signa l. The following pictu re shows theru ler s and ru ler markers tha t a re displayed when Slope is select ed.

To posit ion a ru ler , you can click and drag on it . When you drag a ru ler , thepa rameters in the Rule rs panel change to reflect the measurements on theselected signal.

You can a lso posit ion a ru ler by specifying parameters in the edit boxes in theRulers panel. The parameters are either the x1 and x2 values or the y1 and y2va lues, depending on which ru ler con t rol is select ed.

Page 217: MATLAB Signal Processing Toolbox user manual

Using SPTool

5-37

Type the va lue or var iable for the ru ler pa rameter in the x1 and x2 boxes or they1 and y2 boxes. See “Making Signal Measurements” on page 5-37 for deta ilson manipu la t ing the ru lers and the pa rameters you can measure with eachone.

Peaks and Valleys. Use these but tons to show or h ide the loca l maxima and/orloca l min ima of the cur ren t ly selected signa l, filt er response, or spect rum. Onlypeaks or va lleys, or both peaks and va lleys may be displayed.

•Click Peaks to toggle showing (down) or h iding (up) the maxima of thesigna l.

•Click Valle ys to toggle showing (down) or h iding (up) the min ima of thesigna l.

In t rack and slope mode (see “Making Signa l Measurements” on page 5-37), theru lers are const ra ined to the peaks or va lleys. In hor izonta l and ver t ica l mode,the peaks and valleys are only visua l and do not a ffect the behavior of theru lers.

Save Rulers… Button. Once you’ve set up and made a cer ta in set ofmeasurements, you may find it usefu l to save them for fu ture reference. Usethe Save Rulers… but ton to save a st ructure in the MATLAB workspace withthe fields x1, y1, x2, y2, dx, dy, m, peaks, and valleys. Undefined values a re setto NaN.

1 Click Save Rulers… t o save the curren t measurements a s a va r iable in theworkspace.

The Save Rulers dia log box is displayed.

2 Type a var iable name in the edit field and press OK.

Making Signal MeasurementsUse the ru ler s to make measurements on a selected line, which is a vector or acolumn of a ma tr ix in the Signa l Browser , a filt er response in the Filt er Viewer ,or a spect rum in the Spect rum Viewer . To make a measurement :

1 Select a line as descr ibed in “Select ing a Line to Measure” on page 5-34.

2 Apply a ru ler to the display as descr ibed in “Ruler Control But tons” on page5-36.

Page 218: MATLAB Signal Processing Toolbox user manual

5 Interactive Tools

5-38

3 Posit ion a ru ler where you want it in the main axes area by clicking anddragging it :

a Move the mouse over the ru ler (1 or 2) tha t you want to drag.

The hand cursor is displayed when you’re over a ru ler , with the rulernumber inside it :

b Click and drag the ru ler to where you want it on the signa l.

Depending on which ru ler con t rol is select ed, you can drag the ru ler to ther igh t and left (Vertica l, Track , and Slope ) or up and down (Horizon tal).

As you drag a ru ler , the Ru le rs panel shows the cur ren t posit ion of bothru ler s. Depending on which ru ler con t rol is selected, the following fields aredisplayed: x1, y1, x2, y2, dx , dy , m . These fields will a lso be displayed inpr in tou ts from the Signa l Browser , un less you suppress them. See “Pr in t ingSigna l Data” on page 5-54 and “Pr in t ing Spect rum Data” on page 5-107 fordeta ils on pr in t ing from these tools.

You can also posit ion a ruler by typing it s x1 and x2 or y1 and y2 values in theRulers panel, a s descr ibed on page 5-36.

Ruler Controls: Vertical. There are two ver t ica l ru lers, ca lled ru ler 1 and ru ler 2.When ver t ica l ru lers are in use, the measurement s displayed in the Rulers

Page 219: MATLAB Signal Processing Toolbox user manual

Using SPTool

5-39

panel are x1 (the posit ion of ruler 1 on the x-axis), x2 (the posit ion of ru ler 2 onthe x-axis), and dx (the va lue of x2-x1).

P ress Vertica l t o pu t the ru lers in ver t ica l mode.

In ver t ica l mode, you may change the x-va lues of the ru ler s (tha t is, t heirhor izon ta l posit ion). As the x1 and x2 va lues change, the va lue of dx changesautoma t ica lly.

Change the x1 and x2 values in one of two ways:

•Drag the ru lers to the left and the r igh t with the mouse• Enter their va lues in the x1 and x2 edit boxes in the Rulers panel

Ruler Controls: Horizontal. There are two hor izon ta l ru lers, ca lled ru ler 1 andru ler 2. When hor izon ta l rulers a re in use, the measurements displayed in the

Page 220: MATLAB Signal Processing Toolbox user manual

5 Interactive Tools

5-40

Rulers panel are y1 (the posit ion of ru ler 1 on the y-axis), y2 (the posit ion ofru ler 2 on the y-axis), and dy (the va lue of y2-y1).

Press Horizon tal t o pu t the ru ler s in hor izon ta l mode.

In hor izon ta l mode, you may change the y-va lues of the ru lers (tha t is, theirver t ica l posit ion). As the y1 and y2 va lues change, the va lue of dy changesautomat ica lly.

Change the y1 and y2 values in one of two ways:

•Dragging the ru ler s up and down with the mouse• Enter ing their va lues in the y1 and y2 edit boxes in the Rulers panel

Ruler Controls: Track. There a re two ver t ica l ru lers, ca lled ru ler 1 and ruler 2,with a marker on each tha t shows the y-va lues of the signa l a t the x-va lues ofthe rulers. When t rack ru lers are in use, the measurements displayed in theRulers panel are x1 (the posit ion of ru ler 1 on the x-axis), y1 (the posit ion of

Page 221: MATLAB Signal Processing Toolbox user manual

Using SPTool

5-41

ru ler 1 on the y-axis), x2 (the posit ion of ru ler 2 on the x-axis), y2 (the posit ionof ruler 2 on the y-axis), dx (the va lue of x2-x1), and dy (the va lue of y2-y1).

P ress Track to pu t the ru lers in t rack mode.

You can change the t rack marker in the Rulers panel from the Pre ference sdia log box; see “Ruler Set t ings” on page 5-21.

In t rack mode, you may change the x-va lues of the ru lers (tha t is, theirhor izon ta l posit ion). As the x1 and x2 values change, the va lues of y1, y2, dx ,and dy change automa t ica lly.

Change the x1 and x2 values in one of two ways:

•Dragging the ru lers to the left and the r igh t with the mouse• Enter ing their va lues in the x1 and x2 edit boxes in the Rulers panel

Ruler Controls: Slope. There a re two ver t ica l ru lers, ca lled ru ler 1 and ru ler 2,with the slope line passing through the y-axis in ter sect ions of the two ver t ica lru lers and the signa l. The ru lers a lso t rack the signa l with markers on eachru ler tha t shows the y-va lues of the signa l a t the x-va lues of the ruler s. The lineconnect ing (x1, y1) and (x2, y2) is included in the ma in plot , so you canapproximate der iva t ives and slopes of the signa l.

Page 222: MATLAB Signal Processing Toolbox user manual

5 Interactive Tools

5-42

When slope ru ler s a re in use, the measurements displayed in the Rule rs panela re x1 (the posit ion of ru ler 1 on the x-axis), y1 (the posit ion of ru ler 1 on they-axis), x2 (the posit ion of ruler 2 on the x-axis), y2 (the posit ion of ru ler 2 onthe y-axis), dx (the va lue of x2 - x1), dy (the va lue of y2 - y1), and m (equa l tody / dx , t he slope of the line between x1 and x2).

Press Slope t o pu t the ru lers in slope mode.

In slope mode, you may change the x-va lues of the ru ler s (tha t is, t heirhor izon ta l posit ion). As the x1 and x2 values change, the va lues of dy and mchange automa t ica lly.

Change the x1 and x2 values in one of two ways:

•Dragging the ru ler s to the left and the r igh t with the mouse• Enter ing their va lues in the x1 and x2 edit boxes in the Rulers panel

Page 223: MATLAB Signal Processing Toolbox user manual

Using the Signal Browser: Interactive Signal Analysis

5-43

Using the Signal Browser: Interactive Signal AnalysisThe Signa l Browser tool is an in teract ive signa l explora t ion environment . Itprovides a graph ica l view of the signa l object (s) cur rent ly selected in theSignals column of SPTool.

Using the Signa l Browser you can :

•View and compare vector or a r ray signa ls• Zoom in on a range of signa l da ta to examine it more closely•Measure a va r iety of character ist ics of signa l da ta• Play signa l da ta on audio hardware• Pr in t signa l da ta

Opening the Signal BrowserTo open or act iva t e the Signal Browser from SPTool:

1 Click on one or more signa ls in the Signals list of SPTool.

2 Press View in the Signals panel of SPTool.

The Signal Browser is act iva ted and the selected signa l(s) a re loaded in tothe Signa l Browser and displayed.

Page 224: MATLAB Signal Processing Toolbox user manual

5 Interactive Tools

5-44

Basic Signal Browser FunctionsThe Signa l Browser has the following components:

•A main axes (display) a rea for viewing signa ls graph ica lly•Display management con t rols: Array Signa ls… and the complex signa ldisplay pop-up menu

• Zoom controls for get t ing a closer look at signa l fea tu res•Rulers and line display cont rols for making signa l measurements andcomparisons

•A panner for seeing what par t of the signa l is cur rent ly being displayed andfor quickly moving the view to other fea tu res of the signa l

•Menu opt ions for pr in t ing signa l da ta•A menu opt ion for playing a selected signa l th rough audio equ ipment

Viewing (zoom) controls Measuring (line and ruler) controls

Panner

Main axes

(display) area

Display management controls

Page 225: MATLAB Signal Processing Toolbox user manual

Using the Signal Browser: Interactive Signal Analysis

5-45

Menus

File Menu. Use Page Se tup... from the File menu to open the standa rdMATLAB Page Se tup dia log box, in which you can set the or ien ta t ion, size andposit ion, limit s, and color of your pr intout .

See Using MATLAB Graphics for more in format ion about the Page Se tupdia log box.

Use Prin t P review ... from the File menu to open a MATLAB figure windowwith a preview of the in format ion from the Signal Browser window that willappear in your pr in tout . See “Signal Browser Set t ings” on page 5-23 and“Pr in t ing Signa l Data” on page 5-54 for deta ils about pr int ing from the Signa lBrowser .

Use Prin t... from the File menu to open the standard pr in t dia log box, fromwhich you can pr in t your signa l da ta .

Use Close from the File menu to close the Signa l Browser . All signa l select ionand ru ler informa t ion will be lost . (You may want to save ru ler informat ion tothe workspace using the Save Rulers ... but ton , as descr ibed on page 5-37.)Set t ings you changed and saved using the Pre ference s dia log box in SPToola re saved and used the next t ime you open a Signa l Browser .

Page 226: MATLAB Signal Processing Toolbox user manual

5 Interactive Tools

5-46

Options Menu. Use P lay from the Option s menu to play the selected signa l.

P lay works only when you have sound capabilit ies on your computer . If yourcomputer does not have sound capabilit ies, t h is menu choice does noth ing.

The ent ire select ed signa l is played at either Fs (the sampling frequency of thesigna l) or a t the default pla t form sampling frequency if Fs is less than 25 Hz.The rea l par t and the imagina ry pa r t of a complex signa l a re played in separa t echannels.

Window Menu. Use the Window menu to select a cur ren t ly open MATLABwindow.

Zoom ControlsThe available zoom cont rols in the Signa l Browser are Mouse Zoom , Fu llView , Zoom In-Y, Zoom Out-Y, Zoom In -X, and Zoom Out-X. See “ZoomCont rols” on page 5-31 for deta ils on using the zoom controls in the SignalBrowser .

Zoom persistence is off by defau lt in the Signa l Browser ; use the Signa lBrowser set t ings panel in the Pre fe rence s dia log box in SPTool to toggle zoompersist ence on and off. See “Signa l Browser Set t ings” on page 5-23.

Ruler and Line Display ControlsUsing the ru lers and line display cont rols, you can measure a var iety ofcha racter ist ics of signa ls in the Signa l Browser . See “Ruler Cont rols” on page5-33 for deta ils on using ru lers and modifying line displays in the Signa lBrowser .

The ru lers are displayed by defau lt in the Signa l Browser ; you can turn off theru ler display in the Signal Brow se r set t ings panel in the Pre ference s dia logbox. See “Signal Browser Set t ings” on page 5-23.

Help ButtonTo use con text -sensit ive help, press the He lp but ton . The mouse poin terbecomes an ar row with a quest ion mark symbol. You can then click on anythingin the Signa l Browser , including menu items, to find out wha t it is and how touse it .

Page 227: MATLAB Signal Processing Toolbox user manual

Using the Signal Browser: Interactive Signal Analysis

5-47

Display Management Controls

Array Signals… Button. Use th is to en ter a column index vector for a selectedar ray signa l. All a r ray signa ls st a r t ou t with on ly the fir st column displayed.

The Array Signa ls… but ton is enabled when a t least one ar ray signa l isselected in SPTool:

1 Press Array Signals…

The Column Se le ction for Array Signa ls dia log box is displayed.

All a r ray signa ls tha t a re selected in SPTool a re shown in the list .

2 Select a signa l from the list .

3 Type a column index vector for the selected signa l.

Va lid index vectors are of the form 1 or 1:3 or [1 3 5].

Complex Signal Display. Use to specify whether the Signa l Browser plot s the rea lpar t , the imagina ry pa r t , t he magnitude, or the angle of a complex signa l.

This menu is enabled when a t least one of the signa l va r iables select ed inSPTool is complex. The Complex Display mode a ffects a ll of the var iables in thecur ren t select ion , even those tha t are st r ict ly rea l.

Click and drag to select the plot t ing mode.

Main Axes Display AreaThe Signals list in SPTool shows all signa ls in the curren t SPTool session . Oneor more signa ls may be select ed. The signa l da ta of a ll select ed signa ls aredisplayed graph ica lly in the ma in axes display area of the Signa l Browser .

Page 228: MATLAB Signal Processing Toolbox user manual

5 Interactive Tools

5-48

When there is only one signa l displayed, it s proper t ies a re reflected in thedisplay management cont rols and it s measurement s a re displayed in the ru lerdisplay panel. When more than one signa l is displayed, select the line you wantto focus on .

When a signa l is select ed, you can use the ru ler cont rols on the selected line(see “Making Signa l Measurement s” on page 5-37), you can choose how todisplay the signa l (see “Display Management Cont rols” on page 5-47), and youcan play the signa l (see “Opt ions Menu” on page 5-46). The label of the select edsigna l (line) is displayed in the Se lec tion pop-up menu .

Use one of three ways to select a signa l (line) in the Signa l Browser :

•Click on the Se lection pop-up menu and drag to select the line to measure.•Move the mouse poin ter over any poin t in the line in the main axes displayand click on it .

•Move the mouse poin ter over any poin t in the line in the panner and click onit .

See “Select ing a Line to Measure” on page 5-34 for deta ils.

Axes Labels. By defau lt , the x-axis in the Signal Browser is labeled Time. Youcan change the x-axis label and add a y-axis label using the Signal Brow serset t ings panel in the Pre ference s dia log box in SPTool. See “Signal BrowserSet t ings” on page 5-23.

Click-and-Drag Panning. You can use the mouse to pan around the main axesdisplay; click on a line in the main axes, hold down the mouse but ton , and dragthe mouse.

Click-and-drag panning is not enabled in mouse zoom mode.

PannerThe panner gives a panoramic view of the signa l(s) displayed in the ma in axes.The panner a lways displays the en t ire signa l sample. When you zoom in on themain axes, a pa tch in the panner shows the sect ion of the plot tha t is cur rent lyin view in the main axes. Click-and-drag the patch in the panner window to pandynamica lly across the signa l da ta in the main axes.

You can a lso select a line by clicking on it in the panner ; the select ed line ishighlighted in both the panner and in the ma in axes display a rea .

Page 229: MATLAB Signal Processing Toolbox user manual

Using the Signal Browser: Interactive Signal Analysis

5-49

See “Panner Display” on page 5-52 for more deta ils.

The panner is displayed by defau lt in the Signa l Browser ; you can turn off thepanner in the Signa l Browser set t ings panel in the Pre ference s dia log box inSPTool. See “Signal Browser Set t ings” on page 5-23.

Making Signal MeasurementsUse the ru lers to make a var iety of measurement s on the select ed signa l. See“Making Signal Measurements” on page 5-37 for deta ils.

Viewing and Exploring SignalsYou can open or act iva t e the Signa l Browser in SPTool by select ing one or moresigna ls and pressing View in the Signa l panel. The selected signa ls are loadedin to the Signal Browser . See “Viewing a Signa l” on page 5-17 for deta ils.

Selecting and Displaying a SignalWhen the Signal Browser is act iva ted, a ll selected signa ls a re displayed in themain axes display a rea and in the panner . The data of the selected signa ls areplot ted aga inst an equa lly spaced t ime vector in both the ma in axes display andthe panner .

Page 230: MATLAB Signal Processing Toolbox user manual

5 Interactive Tools

5-50

When the var iable is a vector , one signa l is displayed, a s in the example above.It is au toma t ica lly selected and it s name, size, type, and sampling frequencyare displayed above the main axes display; the name is a lso high lighted in theSe lection pop-up menu .

When more than one signa l is select ed, each signa l is displayed in a differentcolor in both the main axes display and the panner .

The names of a ll signa ls are displayed above the main axes display. The fir stsigna l in the list is au tomat ica lly selected in both the ma in axes display andthe panner , it s name is h ighligh ted in the Se lec tion pop-up menu , and it s coloris shown in the Se lection display.

Page 231: MATLAB Signal Processing Toolbox user manual

Using the Signal Browser: Interactive Signal Analysis

5-51

When the signa l is an a r ray, on ly the fir st column is in it ia lly displayed in boththe main axes and the panner .

To display a differen t a r ray column, or more than one column of the ar ray,press the Array Signa ls… but ton and specify the columns to be displayed (see“Array Signa ls… But ton” on page 5-47). All displayed columns of an ar ray areshown in the same color ; the selected column is emphasized with a heavier line

Page 232: MATLAB Signal Processing Toolbox user manual

5 Interactive Tools

5-52

in both the ma in axes and the panner , and it s label is displayed in theSe lection pop-up menu .

Panner DisplayThe panner displays the ent ire signa l sample a t a ll t imes.

Page 233: MATLAB Signal Processing Toolbox user manual

Using the Signal Browser: Interactive Signal Analysis

5-53

When the signa l in the main axes is zoomed, the pa r t of the signa l tha t is shownin the ma in axes is shown in the panner with a window around it .

Each t ime you zoom, the panner is upda ted to frame the region of da tadisplayed in the main axes.

Click-and-drag on the panner window to move it . As the window moves over thesigna l in the panner , the signa l in the main axes area is panned.

Manipulating Displays

Changing Signal Displays. The signa ls a re displayed in the default line colors anddefault line styles. You can change the defau lt s using the Color Order andLine Style Order fields in the Colors set t ings panel (see “Color Set t ings” onpage 5-22).

Changing the Sample Interval. You can change the sample in terva l by select ingSampling Frequency… from the Edit menu in SPTool. See “Edit ing DataObject s in SPTool” on page 5-15.

Displaying Complex Signals. You can change how complex numbers are displayedby select ing Real, Imaginary , Magnitude , or Angle from the pop-up menu .See “Array Signa ls… But ton” on page 5-47.

Changing Signal Browser Displays. Using the Signa l Brow ser set t ings panel in thePre fe rence s dia log box in SPTool, you can set opt ional x-axis and y-axis labels,

Page 234: MATLAB Signal Processing Toolbox user manual

5 Interactive Tools

5-54

enable and disable the display of the ru lers and the panner , and toggle zoompersist ence. See “Signal Browser Set t ings” on page 5-23.

Working with SignalsOnce a signa l is displayed, you can browse it in a var iety of ways:

•You can zoom in on a specific a rea of the display (see “Zoom Cont rols” on page5-31).

•You can mark off a segment of the display with the ru lers (see “RulerCont rols” on page 5-33) and save ruler set t ings (see “Save Rulers… But ton”on page 5-37).

•You can select a segment of the display with the panner (see “PannerDisplay” on page 5-52).

•You can make cer ta in measurements on the displayed signa ls (see “MakingSignal Measurements” on page 5-37).

•When there is more than one signa l in the display, you can select which oneyou want to measure (see “Select ing a Line to Measure” on page 5-34).

You can use the other GUI tools to manipula te signa ls in a var iety of ways:

•You can in teract ively design and ana lyze filt ers to be applied to signa ls (see“Using the Filter Designer : Int eract ive Filter Design” on page 5-59 and“Using the Filter Viewer : Int eract ive Filter Analysis” on page 5-84).

•You can crea t e a spect rum for a signa l and in teract ively ana lyze it s spect ra ldensity with a var iety of est imat ion methods (see “Using the Spect rumViewer : In t eract ive PSD Analysis” on page 5-97).

You access the Filter Designer , F ilt er Viewer , and Spect rum Viewer tools fromSPTool. You can access SPTool from the Signa l Browser in one of two ways:

•Click on an act ive SPTool window•Act iva te SPTool using the Window menu in the Signa l Browser

Printing Signal DataYou can pr in t a ll of the signa l da ta tha t you can display and manipula t e in theSigna l Browser . Your pr in tou t will conta in up to three components:

Page 235: MATLAB Signal Processing Toolbox user manual

Using the Signal Browser: Interactive Signal Analysis

5-55

• The plot s of one or more signa ls, a s displayed in the main axes area• The panner display of the signa l(s) displayed in the ma in axes a rea• The ru ler measurements of the selected signa l

You can preview your pr in tou t by choosing Prin t P review ... from the Filemenu in the Signa l Browser window. This opens the Signal Brow ser Prin tP rev iew window, shown below with default set t ings for signa l mtlb.

The Close but ton on the Signal Brow ser Prin t P rev iew window closes thepr in t preview window and retu rns you to the Signal Browser .

The Prin t... but ton on the Signal Brow se r Prin t P review window opens thestandard pr in t dia log box, from which you can pr int the contents of your pr in tpreview window.

If you choose to pr in t from the pr in t dia log, both tha t dia log and the Signa lBrow ser Prin t P rev iew window will close, and the con ten ts of the pr in tpreview will pr in t .

If you choose not to pr in t , the pr in t dia log and the Signal Brow ser Prin tP rev iew window will close, and you will r etu rn to the Signal Browser .

Any changes you make, before open ing the pr in t preview window, tha t affectthe display of da ta in the Signal Browser (see “Viewing and Explor ing Signals”

Page 236: MATLAB Signal Processing Toolbox user manual

5 Interactive Tools

5-56

on page 5-49) will a ffect the display of da ta in the Signa l Brow ser Prin tP review window in exact ly the same way. For example, in the pr in t previewshown below:

• The plot of the mtlb data has been mouse zoomed (see “Zoom Controls” onpage 5-31).

• The panner display reflects the cur ren t zoom level by enclosing the zoomedpor t ion of the whole signa l in a window (see “Panner Display” on page 5-52).

• The ru lers have been moved in to the zoomed area and the ru ler con t rols havebeen changed from Track to Slope (see “Ruler Cont rols” on page 5-33).

• The ru ler measurements displayed reflect the changes to the ru ler s in thedisplay area (see “Making Signal Measurements” on page 5-37).

Changes you make in the Pre fe rence s dia log box in SPTool, before open ing thepr int preview window, will a lso affect the Signal Brow se r P rin t P reviewwindow in the same way tha t they affect the Signa l Browser it self. Forexample, in the pr in t preview shown below, the panner display and the ru lermeasurement s have been suppressed, and the axis labels have been changed,

Page 237: MATLAB Signal Processing Toolbox user manual

Using the Signal Browser: Interactive Signal Analysis

5-57

by changes to the Signa l Browser preferences (see “Signa l Browser Set t ings”on page 5-23).

NOTE The HandleVisibility proper ty of the Prin t P review figure windowis set to 'on'. Th is a llows you to modify the preview using Handle Graph icscommands from the MATLAB command line or the Plot Editor tools (seeUsing MATLAB Graphics for more in format ion). Changes tha t you make inthe preview window pr in t exact ly as they appear on the screen ; however, theyare not saved when the Prin t P rev iew figure window is closed.

Saving Signal DataAfter crea t ing a signa l in SPTool (by applying a filter to an impor t ed signa l, forexample), you can expor t the signa l in forma t ion to the workspace or to diskusing Export... from the File menu in SPTool. The signa l informat ion is storedin a st ructure tha t you can access to ret r ieve the signa l da ta and samplefrequency. The signa l st ructu re a lso conta ins a number of fields tha t a re usedin terna lly by SPTool.

To see the fields of the signa l st ructu re, t ry expor t ing a signa l to the workspace:

Page 238: MATLAB Signal Processing Toolbox user manual

5 Interactive Tools

5-58

1 Import a signa l in to SPTool if there are none cur ren t ly loaded (see“Impor t ing Signa ls, F ilter s, and Spect ra” on page 5-7). Label the impor tedsigna l sig1.

2 Expor t the signa l. Select Export... from the File menu.

3 In the Export dia log box, select sig1 and press the Export to Workspacebut ton .

4 Type who a t the MATLAB command line to look at the var iables in theworkspace. The var iable ca lled sig1 is the signa l st ructu re you expor tedfrom SPTool.

5 Type sig1 a t the command line to list t he fields of the signa l st ructu re.

The data and Fs fields of the signa l st ructu re conta in the informat ion tha tdefines the signa l. The other fields a re used in terna lly by SPTool and a resubject to change in fu ture releases:

• The data field is a vector or ar ray con ta in ing the signa l’s da ta .• The Fs field conta ins the sample frequency of the signa l in Her tz.

Page 239: MATLAB Signal Processing Toolbox user manual

Using the Filter Designer: Interactive Filter Design

5-59

Using the Filter Designer: Interactive Filter DesignThe Filt er Designer provides an in teract ive graph ica l environment for thedesign of digita l IIR and FIR filt ers based on specifica t ions tha t you enter on amagnitude or pole-zero plot . Using the F ilter Designer , you can design IIR andFIR filter s of var ious lengths and types, with standard frequency bandconfigura t ions (h ighpass, lowpass, bandpass, bandstop, and mult iband).

Using the Filter Designer you can :

•Design IIR filter s with st andard band configura t ions, using the But terwor th ,Chebyshev type I, Chebyshev type II, and ellipt ic design opt ions

•Design FIR filters with st andard band configura t ions, using the equir ipple,least squa res, and Kaiser window design opt ions

•Design FIR and IIR filt er s with arbit ra ry band configura t ions, using thePole/Zero Editor

•Redesign a filter by manua lly adjust ing indica tors in the magnitude plot , orby graphica lly reposit ion ing the t ransfer funct ion’s poles and zeros

•Over lay a spect rum on the filter ’s magnitude response plot

When you have designed a filt er to your specifica t ions, you can apply the filterto a selected signa l using the Apply but ton in SPTool (see “Applying a Filter”on page 5-18).

NOTE For informat ion on using filter design funct ions from the commandline or from M-files, see Chapter 2.

Opening the Filter DesignerYou can open or act iva t e the Filter Designer from SPTool by pressing the NewDes ign or Edit Des ign but tons:

• To crea te a filter , press New Design in SPTool. A default filt er is genera t edand displayed in the F ilter Designer . You can view the filter in a va r iety ofways in the F ilt er Viewer and modify it in the Filter Designer .

• To edit a filter , select it in SPTool and press Edit De sign . You can modify thefilt er in a var iety of ways in the F ilter Designer .

Page 240: MATLAB Signal Processing Toolbox user manual

5 Interactive Tools

5-60

See “Design ing a F ilt er” on page 5-17 for complete deta ils.

Basic Filter Designer FunctionsThe Filter Designer has the following component s:

•A pop-up menu for select ing differen t filter design methods•A magnitude plot (display) area for graphica lly adjust ing filter responses•A pole-zero plot (display) area for graph ica lly adjust ing filt er t ransferfunct ions

•A Spec ification s panel for viewing and modifying the design pa rameter s orpole-zero loca t ions of the curren t filt er

•A Measurements panel for viewing the response cha racter ist ics andst ability of the curren t filt er

• Specifica t ion lines for graphica lly adjust ing the magnitude responseparameters of a filt er

•Measurement lines for measur ing the magnitude response parameters of afilter

• Zoom controls for get t ing a closer look a t the magnitude response or pole-zerofea tu res

The following sect ions descr ibe the differen t component s of the F ilt erDesigner ’s in ter face and how you can use them together to crea te and editfilter s.

Menus

File Menu. Use Close from the File menu to close the Filt er Designer . Set t ingsyou changed and saved using the Pre ference s dia log box in SPTool are savedand used the next t ime you open the Filter Designer .

Window Menu. Use the Window menu to select a MATLAB figure window.

Filter Pop-Up MenuThe Filte r pop-up menu displays a ll of the filt ers cur rent ly selected in SPTool.Select a filt er in the menu to make it the cur ren t filter in the F ilt er Designer .

Page 241: MATLAB Signal Processing Toolbox user manual

Using the Filter Designer: Interactive Filter Design

5-61

Zoom ControlsThe ava ilable zoom cont rols in the F ilt er Designer are Zoom In -Y, ZoomOut-Y, Zoom In-X, Zoom Out-X, Pass Band , Full View , and Mouse Zoom .

See “Zoom Cont rols” on page 5-31 for deta ils on using the zoom cont rols.

Zoom persist ence is off by defau lt in the Filter Designer ; use the F ilt erDesigner set t ings panel in the Pre ference s dia log box to toggle zoompersistence on and off. See “F ilt er Designer Set t ings” on page 5-27.

Help ButtonTo use context -sensit ive help, press the Help but ton . The mouse pointerbecomes an a r row with a quest ion mark symbol. You can then click on any

General controls

Viewing (zoom) controls

Specifications panel for

setting filter parameters

Magnitude response and pole-zero display area

Measurements panel for

viewing filter

characteristics

Apply the specifications,

or revert to the previous

specifications

Page 242: MATLAB Signal Processing Toolbox user manual

5 Interactive Tools

5-62

object in the Filter Designer , including menu items, to find out wha t it is andhow to use it .

General ControlsBeneath the zoom cont rols are severa l genera l cont rols for filt er design anddisplay. Some of these cont rols a re ava ilable only when an opt imal filt er designmethod (e.g., Equiripple FIR , Butte rw orth IIR) is selected from theAlgorithm menu, and are not ava ilable when the Pole /Zero Editor is selected.

Algorithm. Use the Algorithm pop-up menu to select a design method for thecur ren t filter . The fir st seven opt ions in the Algorithm menu – the optim aldesign m ethods – a ll design filt ers based on a high-level specifica t ion of filtermagnitude response charact er ist ics (such as passband frequencies or stopbanda t t enua t ion). The filter character ist ics are specified numer ica lly in theSpecifications panel or graphica lly on the magnitude response plot .

The eigh th opt ion , Pole /Zero Editor, is not an opt ima l design method buta llows low-level specifica t ion of the filt er ’s t ransfer funct ion via numer ica l orgraphica l pole-zero placement .

When you select one of the opt imal design methods from the menu, themagnitude response plot , Specification s panel, and Measuremen ts panel a llupdate to reflect the design pa rameters ava ilable for tha t method. When youselect Pole /Zero Editor, t he magnitude response plot is replaced by the z-planefor pole-zero placement .

Auto Design (optimal design methods only). When the Auto Des ign check box ischecked, the filt er’s magnitude response is redrawn whenever you change afilter specifica t ion , either by enter ing a va lue in the Specifications panel or bydragging a specifica t ion line on the plot . When the box is not checked, the newresponse is computed and redrawn only when you press the Apply but ton orrelease the specifica t ion line. Auto Des ign is in it ia lly off by default ; use the

Optimal design

methods

Transfer function

pole-zero placement

Page 243: MATLAB Signal Processing Toolbox user manual

Using the Filter Designer: Interactive Filter Design

5-63

Filte r Des igner set t ings panel in the Pre ference s dia log box to change th isdefault set t ing. See “Filter Designer Set t ings” on page 5-27.

Sampling Frequency. The Sampling Frequency field a llows you to specify thefilt er ’s sampling frequency in Her tz. To change the sampling frequency, type ava lue in the box and press Enter. Th is is the same as changing the samplingfrequency by select ing Sampling Frequency... from the SPTool Edit menu (see“Edit ing Data Object s in SPTool” on page 5-15). The frequency axis of themagnitude response plot is upda ted to reflect the new sampling frequency.Changing the Sampling Frequency in the Pole/Zero Editor does not a lter thepole-zero plot , bu t does sca le the cor responding magnitude plot in the F ilt erViewer (if the Viewer is open).

Overlay Spectrum (design methods only). The Filter Designer a llows you to over laya signa l spect rum on the filter ’s magnitude response plot . Press the OverlaySpectrum... but ton to display a list of the cur ren t spect ra in SPTool. Select aspect rum from the list and press OK t o over lay it on the cur ren t magnituderesponse plot . Note tha t the spect rum is plot ted on the exist ing frequency axis,which is sca led to the filt er ’s sampling frequency.

Filter Specifications Panel—Design MethodsWhen you design a new filter with the design methods, the F ilt er Designerin it ia lly conta ins the specifica t ions and magnitude response plot for an order22, lowpass, equir ipple filt er .

Use the Type pop-up menu in the Spec ifications panel to select a bandconfigura t ion . Use the edit boxes below it in the panel to change the band edgefrequencies and the amount of r ipple in the passband and at tenua t ion in thestopband. Check the Minimum Order box to let the Filter Designerau toma t ica lly determine the lowest filt er order tha t ach ieves the cur ren tspecifica t ions.

The design parameters ava ilable in the Spec ifications panel depend on thefilt er design select ed in the Algorithm pop-up menu , the band configura t ionselected in the Type pop-up menu , and the st a te of the Minimum Order checkbox.

Specifications Parameters – Automatic Order Selection. When the Minimum Orderbox is checked, a ll of the filt er designs except Least Square s FIR display thesame set of parameters in the Specifica tions panel. (The order for the LeastSquare s FIR design cannot be automat ica lly computed). For lowpass and

Page 244: MATLAB Signal Processing Toolbox user manual

5 Interactive Tools

5-64

highpass band configura t ions, these parameter s include the passband edgefrequency Fp, the stopband edge frequency Fs, the passband r ipple Rp, and thestopband a t t enua t ion Rs. For bandpass and bandstop configura t ions, thepa rameters include the lower and upper passband edge frequencies, Fp1 andFp2, the lower and upper stopband edge frequencies, Fs1 and Fs2, thepassband r ipple Rp, and the stopband at t enua t ion Rs. Frequency values are inHer tz, and r ipple and a t t enuat ion va lues a re in dB.

Specifications Parameters—Manual Order Selection. When the Min imum Order boxis not checked, an Order parameter for set t ing the filter order appears belowit , and each filter design displays a unique set of parameters in theSpecifications panel. These are shown in the table below, where Wp and Wsare the weigh ts for the passband and stopband, Beta is the Kaiser window βpa rameter , Fc is the cu toff frequency, and F3db is the -3 dB frequency.

Designing a New Filter With the Design Methods. In genera l, follow these st eps todesign a new filter using the Specifications panel parameters:

1 Click-and-drag to select an appropr ia te opt imalfilt er design method from the Algorithm pop-upmenu .

2 Click-and-drag to select the band configura t ionfrom the Type pop-up menu .

3 Type in the Specifica tions panel’s edit able fieldsto change the va lues for band edge frequencies, r ipple, a t tenua t ion , andother filt er character ist ics.

Lowpass Highpass Bandpass BandstopEquiripple FIR Fp, Fs, Wp, Ws Fp, Fs, Wp, Ws Fp1, Fp2, Fs1, Fs2, Wp, Ws Fp1, Fp2, Fs1, Fs2, Wp, WsLeast Squares FIR Fp, Fs, Wp, Ws Fp, Fs, Wp, Ws Fp1, Fp2, Fs1, Fs2, Wp, Ws Fp1, Fp2, Fs1, Fs2, Wp, WsKaiser Window FIR Fc, Beta Fc, Beta Fc1, Fc2, Beta Fc1, Fc2, BetaButterworth IIR F3db F3db F3db 1, F3db 2 F3db 1, F3db 2Chebyshev Type I IIR Fp, Rp Fp, Rp Fp1, Fp2, Rp Fp1, Fp2, RpChebyshev Type II IIR Fs, Rs Fs, Rs Fs1, Fs2, Rs Fs1, Fs2, RsElliptic IIR Fp, Rp, Rs Fp, Rp, Rs Fp1, Fp2, Rp, Rs Fp1, Fp2, Rp, Rs

Page 245: MATLAB Signal Processing Toolbox user manual

Using the Filter Designer: Interactive Filter Design

5-65

4 Press Enter after typing in an editable t ext box to enter the va lue. If AutoDe sign is not checked, press the Apply but ton below the Spec ifica tionspanel to upda te the magnitude plot .

5 To specify a filt er order , press Minim ize Order t o deselect the check box anddisable automat ic filt er order select ion . Then type a va lue for the Orderpa rameter . If Auto Des ign is not checked, press Apply .

Edit a new filter or an exist ing filter in the same way. Note tha t when AutoDes ign is disabled and you change a filter ’s parameter va lues, the magnituderesponse plot changes from solid lines to dashed lines. This indica t es tha t theplot no longer reflect s the cur ren t specifica t ions. When you press the Applybut ton , the new response is computed and the lines rever t to the solid style.When Auto De sign is enabled, the plot updates whenever you change a filterspecifica t ion .

Filter Measurements Panel—Design MethodsWhen you design a filt er , the Measurements panel (shown at left ) displays thevalues of filter parameter s tha t do not appear in the Specifications panel. Forexample, when the F ilt er Designer provides an Fs parameter in theSpec ifications panel, it displays the Actual Fs va lue in the Measurementspanel. Simila r ly, when the Min imum Order opt ion is selected in theSpec ification s panel, t he computed filt er order is displayed in the Order fieldof the Measurements panel. The va lues in the Measurements panel a reupda ted whenever the magnitude plot is redrawn.

Measurement Parameters – Automatic Order Selection. The pa rameter combina t ionstha t appear in the Measuremen ts panel a re shown in the following two tables.The fir st t able list s the pa rameters tha t appea r when Minimum Order ischecked (au tomat ic order select ion). The stopband edge frequency parameterslisted (Fs, Fs1, Fs2) are the actual edge frequencies for the design, ra ther thanthe desired frequencies en tered in the Spec ifications panel.

Page 246: MATLAB Signal Processing Toolbox user manual

5 Interactive Tools

5-66

Measurement Parameters – Manual Order Selection. The next table shows thepa rameter sets tha t appear in the Measurements panel when MinimumOrder is not selected. The measurements tha t can be in teract ively changed bydragging the red measurement lines on the response plot are shown shaded.

Filter Specifications Panel—Pole/Zero EditorWhen you design a new filt er using the Pole/Zero Editor , t he F ilt er Designerin it ia lly displays a pole-zero plot for the default order -22 filt er .

The genera l pole-zero (factored) form of the t ransfer funct ion of a digita l filt eris:

where z1, z2, ..., zm a re the filt er zeros, p1, p2, ..., pn a re the filter poles, and k isthe overa ll t ransfer funct ion ga in . The number of zeros and poles do not needto be the same.

The con t rols in the Specifica tions panel a llow you to set the overa ll ga in andto numer ica lly adjust the posit ion of each pole and zero using pola r orrect angular coordina tes.

Lowpass Highpass Bandpass Bandstop

Equiripple FIROrder, Rp, Rs, Wp,Ws

Order, Rp, Rs, Wp,Ws Order, Rp, Rs, Wp, Ws Order, Rp, Rs, Wp, Ws

Least Squares FIR Order cannot be au tomat ica lly computed.

Kaiser Window FIROrder, Fc, Beta ,Rp, Rs

Order, Fc, Beta ,Rp, Rs

Order, Fc1, Fc2, Beta , Rp,Rs

Order, Fc1, Fc2, Beta , Rp,Rs

Butterworth IIR Order, Rp, F3db Order, Rp, F3db Order, Rp, F3db 1, F3db 2 Order, Rp, F3db 1, F3db 2Chebyshev Type I IIR Order, Fs Order, Fs Order, Fs1, Fs2 Order, F s1, Fs2Chebyshev Type II IIR Order, Fs Order, Fs Order, Fs1, Fs2 Order, F s1, Fs2Elliptic IIR Order, Fs Order, Fs Order, Fs1, Fs2 Order, F s1, Fs2

Lowpass Highpass Bandpass BandstopEquiripple FIR Rp, Rs Rp, Rs Rp, Rs Rp, RsLeast Squares FIR Rp, Rs Rp, Rs Rp, Rs Rp, RsKaiser Window FIR Fp, Fs, Rp, Rs Fp, Fs, R p, Rs Fp1, Fp2, Fs1, Fs2, Rp, R s Fp1, Fp2, Fs1, Fs2, Rp, R sButterworth IIR Fp, Fs, Rp, Rs Fp, Fs, R p, Rs Fp1, Fp2, Fs1, Fs2, Rp, R s Fp1, Fp2, Fs1, Fs2, Rp, R sChebyshev Type I IIR Fs, Rs Fs, R s Fs1, Fs2, R s Fs1, Fs2, RsChebyshev Type II IIR Fp, Rp Fp, Rp Fp1, Fp2, Rp Fp1, Fp2, RpElliptic IIR Fs Fs Fs1, Fs2 Fs1, Fs2

H z( ) Z z( )P z( )---------- k

z z1–( ) z z2–( )Lz zm–( )

z p1–( ) z p2–( )Lz pn–( )----------------------------------------------------------------= =

Page 247: MATLAB Signal Processing Toolbox user manual

Using the Filter Designer: Interactive Filter Design

5-67

The va lue you enter in the Gain edit box specifies the ga in , k . The Coordinate spop-up menu let s you posit ion the poles and zeros using either polar orrectangula r measurement s. When Polar is selected, you can specify thecoordina tes of the cur ren t ly select ed pole or zero by enter ing va lues in theMagand Angle edit boxes. The resu lt ing loca t ion of the selected pole or zero is

where M is the magnitude specified by Mag , and θ is t he angle in radiansspecified by Angle .

When Rectangu lar is selected, you can specify the coordina tes of the cur ren t lyselected pole or zero by enter ing values in the X and Y edit boxes. The resu lt ingloca t ion of the select ed pole or zero is

The Conjugate pair checkbox cont rols whether the cur rent select ion is acomplex conjugate pa ir of poles or zeros, or a lone pole or zero. When a lone poleor zero is selected on the pole-zero plot , the Conjugate pa ir checkbox isinact ive. If you now enable the Conjugate pair checkbox by clicking it , a newconjuga te pole or zero (as appropr ia te) is crea ted to complet e the pa ir .

When a conjugate pa ir of poles or zeros is selected on the plot (by clicking oneof the pa ir ), the Conjugate pa ir checkbox is act ive. If you now disable theConjugate pa ir checkbox by clicking it , the conjuga te pa ir is broken in to twolone poles or zeros a t the same posit ions, and only one of these remainsselected.

When the Conjugate pair checkbox is select ed, the coordina tes you specify (ineither angula r or rectangula r form) cont rol the loca t ion of the cur ren t lyselected complex conjugate pa ir of poles or zeros, with loca t ions

or

Designing a New Filter with the Pole/Zero Editor. In genera l, follow these steps todesign a new filt er using the Spec ifications panel pa rameter s:

z M ejθ=

z X jY+=

z X jY±=

z M e j± θ=

Page 248: MATLAB Signal Processing Toolbox user manual

5 Interactive Tools

5-68

1 Click-and-drag to select the Pole /Zero Editoropt ion from the Algorithm pop-up menu .

2 Enter the desired filt er ga in in the Gain edit box.

3 Select a pole or zero (or conjuga te pa ir ) by clickingon one of the or symbols on the plot .

4 Choose the coordina tes to work in by specifying Polar or Rectangu lar fromthe Coordinate s pop-up menu .

5 Specify the new loca t ion(s) of the selected pole, zero, or con jugate pa ir bytyping va lues in to the Mag and Angle (for angu lar coordina tes) or X and Y(for rectangu la r coordina tes) edit boxes.

6 Use the Con jugate pair checkbox to crea te a conjuga te pa ir from a lone poleor zero or to break a con juga te pa ir in to two individua l poles or zeros.

Edit a new filt er or an exist ing filter in the same way.

TIP Keep the Filt er Viewer open while design ing a filt er with the Pole/ZeroEditor. Any changes tha t you make to the filter t ransfer funct ion in thePole/Zero Editor a re then simultaneously reflected in the response plots of theFilter Viewer.

Filter Measurements Panel—Pole/Zero EditorWhen you design a filter , t he Measuremen ts panel (shown at left ) displaysusefu l in format ion about the filt er being designed. The panel a lways shows thenumber of zeros and poles (the la rger of which is the order of the filter ), andindica tes whether the filt er is st able or unst able (poles outside the unit circle).

The panel a lso shows the phase charact er ist ics of the filt er . Where m is thetota l number of zeros, the four possible phase condit ions are:

•Minimum Phase , which indica t es tha t between 1 and m -1 zeros are on theunit circle, while the rest of the zeros are inside the unit circle

Pole

Zero

i 1 … m, ,=z i 1≤

Page 249: MATLAB Signal Processing Toolbox user manual

Using the Filter Designer: Interactive Filter Design

5-69

• Stric tly Min imum Phase , which indica t es tha t a ll of the zeros are inside theunit circle

•Maximum Phase , which indica tes tha t between 1 and m zeros a re on theunit circle, while the rest of the zeros are ou t side the unit circle

• Stric tly Maximum Phase , which indica t es tha t a ll of the zeros are outsidethe unit circle

When the Measurements panel does not indica te any of the above condit ions,zeros are both inside and outside the unit circle.

When a new pole or zero is being placed on the plot (using the Add Pole s orAdd Zeros t ools, descr ibed on page 5-72) the Measuremen ts panel showsaddit iona l posit ion ing informat ion . After pressing either the Add Pole s or AddZeros but ton , and before clicking on the plot to place the new pole(s) or zero(s),the Measurements panel displays the precise posit ion of the poin ter over theplot a rea .

All va lues in the Measurements panel a re upda ted cont inuously as a pole orzero is reposit ioned.

Magnitude Plot (Display) Area—Design MethodsThe response of the filter select ed in the Filte r pop-up menu is displayedgraphica lly in the magnitude response plot area of the Filter Designer , and itscharact er ist ics are shown in the Specifica tions and Measurements panels.

i 1 … m, ,=z i 1<

i 1 … m, ,=z i 1≥

i 1 … m, ,=z i 1>

Add Poles Pointer

Add Zeros Pointer

Page 250: MATLAB Signal Processing Toolbox user manual

5 Interactive Tools

5-70

You can zoom in on the displayed filt er in the magnitude plot (see “ZoomCont rols” on page 5-31) and you can drag the specifica t ion lines to redesign thedisplayed filter visua lly (see the next sect ion).

Specification Lines. You can redesign a filter by manipula t ing the greenspecifica t ion lines in the magnitude plot . Using the specifica t ion lines, you canchange the passband r ipple, stopband at tenua t ion , and edge frequencies of afilter :

• Set passband r ipple or stopband at tenua t ion by clicking on a green line anddragging it up or down. The Rp and Rs va lues displayed in theSpec ification s panel change as you drag. If Auto De sign is checked, theresponse plot a lso upda tes as you drag the lines. If Auto De sign is disabled,the response plot upda tes when you release the mouse.

NOTE With IIR filt ers you can only drag the lower passband bar and thestopband bar. The upper passband bar is fixed a t 0.

• Set edge frequencies either by clicking on the edge of a horizontal green line(the mouse poin ter changes to ) and dragging the edge to a new frequency,or by clicking anywhere on a vertical green line (if the Filter Designerprovides one) and dragging it hor izon ta lly to a new frequency. The Fp and Fsva lues displayed in the Spec ifications panel change as you drag. If AutoDes ign is checked, the response plot a lso updates as you drag the lines. IfAuto Design is disabled, the response plot upda tes when you release themouse.

See “Redesigning a F ilter Using the Magnitude P lot” on page 5-78 for deta ils.

Measurement Lines. A number of the filter designs provide ru ler s on the responseplot tha t a llow you to measure response magnitude levels. These measurementlines, which appear in red on the plot , a re ava ilable for the Ka iser window,But terwor th , Chebyshev type I, and Chebyshev type II filt er s when theMin imum Order check box is not select ed. As you drag a measurement line,the corresponding va lues in the Measurements panel change to reflect themeasurement line’s cur ren t posit ion .

Page 251: MATLAB Signal Processing Toolbox user manual

Using the Filter Designer: Interactive Filter Design

5-71

Magnitude Plot (Display) Area—Pole/Zero EditorThe plot area of the Pole/Zero Editor displays the filt er t ransfer funct ion’s poleand zeros on the complex z-plane. The unit circle is shown in dashed lines,a long with the ver t ica l and hor izon ta l gr id lines, to provide a visua l referencefor pole-zero placement .

You can zoom in on the z-plane (see “Zoom Controls” on page 5-31) and you candrag the pole and zero symbols to redesign the filt er t ransfer funct ion visua lly(see the next sect ion).

Positioning Poles and Zeros. You can redesign the t ransfer funct ion by simplyclicking and dragging on one of the pole or zero symbols. Poles or zeros appeargreen (ra ther than the usua l blue) when selected. In a conjugate pa ir of polesor zeros, both conjuga tes a re select ed when either is clicked; con juga te pa ir smove together when dragged, ma in ta in ing equal distance from the rea l axis a ta ll t imes. To ungroup conjuga tes, select the desired pa ir and uncheckConjugate pa ir in the Specifications panel.

When two or more pole symbols (or two or more zero symbols) are placeddirect ly on top of each other , a number is displayed next to the symbols (on theleft for poles, and on the r igh t for zeros) indica t ing the number of poles or zerosa t tha t loca t ion (e.g., ). Th is number makes it ea sy to keep t rack of a ll thepoles and zeros in the plot a rea , even when severa l a re super imposed on eachother and are not visua lly differen t iable. Note, however , tha t this number doesnot indica te the multiplicity of the poles or zeros to which it is a t tached.

Page 252: MATLAB Signal Processing Toolbox user manual

5 Interactive Tools

5-72

To help detect whether a set of poles or zeros are t ru ly mult iples, use the zoomtools to magnify the region around the poles or zeros in quest ion . Becausenumer ica l limita t ions usua lly preven t any set of poles or zeros from shar ingexactly the same va lue, a t a h igh enough zoom level even t ru ly mult iple polesor zeros appear dist inct from each other . A common way to assess whether apa r t icu la r group of poles or zeros conta ins mult iples is by compar ing themutua l proximity of the group members aga inst a selected threshold va lue. Asan example, the residuez funct ion defines a pole or zero as being a mult iple ofanother pole or zero if the absolu te distance separa t ing them is less than 0.1%of the la rger pole or zero’s magnitude.

Tools. The Pole/Zero Editor provides severa l tools to assist with pole-zeroplacement . The tools are loca ted a t the top left of the pole-zero plot area .

At the bot tom of the plot area , there are two addit iona l bu t tons, Send To Backand De le te All. Use Send To Back when you are unable to select a pole or zerobecause another pole or zero is in the way. Select the in ter fer ing pole or zero onthe plot , and press Send To Back to move tha t pole or zero behind a ll othersymbols on the plot (i.e., la st in the stacking order ). You can then select thedesired pole or zero withou t the in ter ference of the other symbol.

Icon Name Description

Drag Poles/Zeros Tool Use th is tool to select and drag poles and zeros onthe plot .

Add Poles Tool

Use th is tool to add poles to the plot . Simply clickon the plot where you wan t to place the new pole(or con juga te pa ir, when the Conjugate paircheckbox is selected).

Add Zeros Tool

Use th is tool to add zeros to the plot . Simply clickon the plot where you wan t to place the new zero(or con juga te pa ir, when the Conjugate paircheckbox is selected).

Delete Poles/Zeros Tool

Use th is tool to delete poles and zeros from theplot . Simply click on any pole or zero to delete it .When you click on a set of poles or zero occupyingthe same loca t ion , on ly the top-most pole or zerois removed. You can a lso use the Dele te orBackspace key on the keyboard to delete thecu r r en t ly selected pole or zero.

Page 253: MATLAB Signal Processing Toolbox user manual

Using the Filter Designer: Interactive Filter Design

5-73

The De le te All but ton delet es every pole and zero in the plot area .

NOTE The Dele te All opera t ion cannot be undone. Once a ll t he poles andzeros are removed, they cannot be restored.

Designing Finite Impulse Response (FIR) FiltersThe Filt er Designer provides three opt ions for basic FIR filter design . Theseopt ions a llow you to crea t e FIR filt ers with st andard band configura t ions(lowpass, h ighpass, bandpass, or bandstop configura t ions on ly). The threeopt ions for FIR filter design in the Algorithm pop-up menu are:

• Equ iripple FIR , which accesses the toolbox funct ion remez t o crea t e anequir ipple FIR filt er .

• Least Square s FIR , wh ich accesses the toolbox funct ion firls to crea te anFIR filt er using the least square design method.

•Kaiser Window FIR , which accesses the fir1 funct ion to crea te an FIR filterusing a Kaiser window.

Example: FIR Filter Design, Standard Band ConfigurationIn the following example, use the Kaiser window filter design opt ion :

1 Select Kaise r Window FIR as the filter design from the Algorithm pop-upmenu .

2 Select bandpass from the Type pop-up menu as the configura t ion .

3 Set the filt er ’s sampling frequency to 2000 Hz by enter ing th is va lue in theSampling Frequency text box.

4 Press Apply to redraw the response with these set t ings.

NOTE You must press Apply before you change the following parameters.

5 Check the Minimum Order check box to enable automa t ic order select ion .

Page 254: MATLAB Signal Processing Toolbox user manual

5 Interactive Tools

5-74

6 Set Fp1 t o 290 and Fp2 t o 525.

These fields respect ively define the lower and upper passband edgefrequencies in Her tz.

7 Set Fs1 to 200 and Fs2 to 625.

These fields respect ively define the lower and upper stopband edgefrequencies in Her tz.

8 Set Rp (passband r ipple) to 4 and Rs (stopband at t enuat ion) to 30.

Rp and Rs are specified in dB.

9 Press the Apply but ton .

The Filter Designer ca lls fir1 to crea te the filt er using a Kaiser window. TheFilter Designer upda tes the magnitude plot to show the new filter ’s magnituderesponse.

Page 255: MATLAB Signal Processing Toolbox user manual

Using the Filter Designer: Interactive Filter Design

5-75

Filter Design OptionsWhen theMinimum Order opt ion is disabled, you can specify parameter s tha tdefine character ist ics unique to cer ta in filter types:

• For equir ipple and least squares filter s: the weigh ts for er ror minimiza t ion• For Kaiser window filter s: the cu toff frequency and β pa rameter of the Kaiserwindow

Order Selection for FIR Filter DesignAs descr ibed ear lier , the FIR filt er design opt ions ava ilable through the F ilt erDesigner ca ll the toolbox funct ions remez, firls, and fir1. In ca lcu la t ing filterorder , t he F ilt er Designer uses the same guidelines as the toolbox funct ions:

• The Equiripple FIR design opt ion ca lls the remezord order est imat ionfunct ion to determine a filt er order tha t meet s a set of specifica t ions. In somecases, remezord underest imates the filter order n. If the filter does notappear to meet the given specifica t ions using Minimum Order orderselect ion, deselect Minimum Order and manually specify a sligh t ly la rgerorder (n+1 or n+2).

• The Least Squares FIR design opt ion calls the toolbox funct ion firls.Because the toolbox does not provide an order est imat ion funct ion for usewith firls, you cannot use the Min imum Order opt ion with the LeastSquare s FIR method.

• The Kaiser Window FIR design opt ion ca lls kaiserord, the order est imat ionfunct ion , which somet imes underest ima tes the filter order n. If the filt er doesnot appear to meet the given specifica t ions using Minimum Order orderselect ion, deselect Minimum Order and manually specify a sligh t ly la rgerorder (n+1 or n+2).

All of the FIR filter design opt ions in the F ilt er Designer requ ire an even filterorder for the h ighpass and bandstop configura t ions. For more informat ion onorder select ion with the FIR filter design opt ions, see the reference descr ipt ionsof remez, remezord, kaiserord, firls, and fir1 in Chapter 6.

Page 256: MATLAB Signal Processing Toolbox user manual

5 Interactive Tools

5-76

Designing Infinite Impulse Response (IIR) FiltersThe Filt er Designer let s you design a number of cla ssica l IIR filter s, includingBut terwor th , Chebyshev type I, Chebyshev type II, and ellipt ic filt ers.

Example: Classical IIR Filter DesignIn the following example, design a simple Chebyshev type I filt er :

1 Select Chebyshev Type I IIR as the filt er design from the Algorithmpop-up menu.

2 Select highpass from the Type menu as the configura t ion .

3 Set the filter ’s sample frequency to 2000 Hz by enter ing th is va lue in theSampling Frequency t ext box.

4 Press Apply t o redraw the response with these set t ings.

NOTE You must press Apply before you change the following parameters.

5 Check the Minimum Order check box.

6 Set Fp (passband edge frequency) to 800 and Fs (stopband edge frequency)to 700.

Fp and Fs are specified in Her tz.

7 Set Rp (passband r ipple) to 2.5 and Rs (stopband at tenua t ion) to 35.

Rp and Rs are specified in dB.

8 Press Apply t o draw the magnitude response.

9 Deselect Minimum Order and specify a filt er order of 7. Press Apply toredraw the magnitude response.

Page 257: MATLAB Signal Processing Toolbox user manual

Using the Filter Designer: Interactive Filter Design

5-77

The Filt er Designer ca lls the appropr ia te filt er design funct ion to crea t e thefilt er .

To zoom in on plot deta ils, use the zoom control bu t tons as descr ibed in “ZoomControls” on page 5-31.

Filter Design OptionsWhen theMinimum Order opt ion is disabled, you can specify parameter s tha tdefine character ist ics unique to cer ta in filter types:

• For But terwor th filt er s: the -3 dB frequencies• For Chebyshev type I filt ers: the passband edge frequencies• For Chebyshev type II filt ers: the stopband edge frequencies• For ellipt ic filt ers: the passband edge frequencies

In the following example, redesign the Chebyshev type I filter from theprevious example as a But t erwor th filt er , using a -3 dB frequency of 800 Hz:

Page 258: MATLAB Signal Processing Toolbox user manual

5 Interactive Tools

5-78

1 Select the Butterw orth IIR filt er design from the Algorithm menu.

The magnitude response plot changes to reflect the new design .

2 Type a va lue of 800 in the F3db t ext field.

3 Press Apply to update the response plot .

Order Selection for IIR Filter DesignThe IIR filter design opt ions ava ilable through the Filter Designer ca ll thetoolbox filt er design funct ions. In ca lcu la t ing the order for a given filt er , theFilter Designer uses the cor responding order est ima t ion funct ion if theMin imum Order check box is selected.

For deta ils on order select ion with the IIR filt er design opt ions, see thereference descr ipt ions of buttord, cheb1ord, cheb2ord, and ellipord inChapter 6.

Redesigning a Filter Using the Magnitude PlotAfter designing a filt er in the Filter Designer , you can redesign it by draggingthe specifica t ion lines in the magnitude plot . Use the specifica t ion lines tochange passband r ipple, stopband at tenua t ion , and edge frequencies (see“Specifica t ion Lines” on page 5-70 for deta ils). In the following example, crea t ea Chebyshev filter and modify it by dragging the specifica t ion lines:

1 Create a Chebyshev type I h ighpass filter with a sample frequency of2000 Hz. Set the following parameters:Fp = 800Fs = 700Rp = 2.5Rs = 35

2 Check Minimum Order so the Filter Designer can ca lcu la t e the lowest filt erorder tha t produces the desired charact er ist ics.

3 Press Apply t o update the response plot .

4 Posit ion the cursor over the green line specifying the stopband.

The cursor changes to the up/down drag indica tor .

Page 259: MATLAB Signal Processing Toolbox user manual

Using the Filter Designer: Interactive Filter Design

5-79

5 Drag the line unt il the Rs (stopband at t enua t ion) field reads 100.

Note tha t the Order value in the Measurements panel changes because ah igher filt er order is needed to meet the new specifica t ions.

Saving Filter DataAfter design ing a filter in the F ilt er Designer , you can expor t the filterinformat ion to the workspace or to disk using Export... from the File menu inSPTool. The filt er in format ion is stored in a st ructure tha t you can access toret r ieve the coefficien t s and design parameter s of the filt er you crea ted. Thefilt er st ructure a lso conta ins a number of fields tha t a re used in terna lly bySPTool.

To see the fields of the filter st ructu re, fir st expor t a filter to the workspace:

1 Crea te a new filter by pressing New Design in SPTool. The new filter isca lled filt1.

2 Select Export... from the File menu.

3 In the Export from SPTool dia log box, select filt1 and press the Exportto Workspace but ton .

4 Type who a t the MATLAB command line to look a t the var iables in theworkspace. The var iable ca lled filt1 is the filt er st ructure you expor tedfrom SPTool.

5 At the command line type filt1 to list the fields of the filter st ructu re.

The tf, Fs, and specs fields of the filter st ructu re conta in the in forma t ion tha tdescr ibes the filt er . These fields a re discussed below. The other fields in thest ructure are used in terna lly by SPTool, and are subject to change in fu turereleases.

tf. The tf field is a st ructu re con ta in ing the t ransfer funct ion represen ta t ion ofthe filt er :

• tf.num conta ins the numera tor coefficien ts• tf.den conta ins the denomina tor coefficient s

Page 260: MATLAB Signal Processing Toolbox user manual

5 Interactive Tools

5-80

both in descending powers of z

where b is a vector con ta ining the coefficien t s from the tf.num field, a is avector con ta ining the coefficien t s from the tf.den field, m is the numera tororder , and n is the denomina tor order . You can change the filt er represen ta t ionfrom the defau lt t ransfer funct ion to another form by using the tf2ss or tf2zpfunct ions.

Fs. The Fs field conta ins the sampling frequency of the filt er in Her t z.

specs. The specs field is a st ructure conta in ing informat ion about the filt erdesign . The fir st field, specs.currentModule, conta ins a st r ing represen t ingthe design selected for the filter in the F ilt er Designer ’s Algorithm pop-upmenu . The possible con ten t s of the currentModule field, and the cor respondingdesigns, a re shown below.

Following the specs.currentModule field, there may be up to seven addit iona lfields, with labels such as specs.fdremez, specs.fdfirls, etc. The designspecifica t ions for the most recent ly expor ted filter a re con ta ined in the field

currentModule Algorithm

fdbutter But terwor th IIR

fdcheby1 Chebyshev Type I IIR

fdcheby2 Chebyshev Type II IIR

fdellip Ellipt ic IIR

fdfirls Least Squa res FIR

fdkaiser Kaiser Window FIR

fdremez Equir ipple FIR

H z( ) B z( )A z( )----------- b 1( ) b 2( )z 1– L b n b 1+( )z m–+ + +

a 1( ) a 2( )z 1– L a n a 1+( )z n–+ + +--------------------------------------------------------------------------------------= =

Page 261: MATLAB Signal Processing Toolbox user manual

Using the Filter Designer: Interactive Filter Design

5-81

whose label matches the currentModule st r ing. For example, if the specsst ructure is

currentModule: 'fdkaiser'fdremez: [1x1 struct]fdfirls: [1x1 struct]fdkaiser: [1x1 struct]

the filt er specifica t ions are conta ined in the fdkaiser field, which is it self ada ta st ructure.

The specifica t ions include the parameter va lues from the Specification s panelof the Filter Designer , such as band edges and filter order . For example, theKaiser window filt er above has the following specifica t ions stored inspecs.fdkaiser.

setOrderFlag: 0type: 1f: [0 0.1000 0.1500 1]Rp: 3Rs: 20Wn: 0.1250order: 34Beta: 0wind: [35x1 double]

Because cer ta in filt er parameters are unique to a par t icu la r design , th isst ructure has a different set of fields for each filter design . For example, theBeta field above only appea rs in the specs st ructure if the design is a Kaiserwindow FIR filt er .

The table below list s the possible specifica t ions fields tha t can appea r in theexpor t st ructure, and descr ibes their con ten t s.

Parameter Description

Beta Kaiser window β parameter.

f Conta ins a vector of band-edge frequencies, norma lizedto 1 (i.e., 1 = Nyquist ).

Page 262: MATLAB Signal Processing Toolbox user manual

5 Interactive Tools

5-82

Viewing Frequency Response PlotsIt is oft en usefu l to view a filter ’s frequency response, impulse response, andstep response dur ing the filt er design process. You can use the Filt er Viewer toview frequency-domain informa t ion about filt er s in the Filter Designer :

Fpass Passband cutoff frequencies. Sca la r for lowpass andh ighpass designs, two-element vector for bandpass andbandstop designs.

Fstop Stopband cutoff frequencies. Sca lar for lowpass andh ighpass designs, two-element vector for bandpass andbandstop designs.

m The response magnitudes cor responding to the band-edgefrequencies in f.

order Filter order.

Rp Passband r ipple (dB)

Rs Stopband a t t enuat ion (dB)

setOrderFlag Conta ins 1 if t he filt er order was specified manua lly (i.e.,the Minimum Order box in the Spec ifications panel wasnot checked). Conta ins 0 if the filter order was computedautomat ica lly.

type Conta ins 1 for lowpass, 2 for highpass, 3 for bandpass, or4 for bandstop.

w3db -3 dB frequency for But terwor th IIR designs.

wind Vector of Kaiser window coefficien t s.

Wn Cutoff frequency for the Kaiser window FIR filter whensetOrderFlag = 1.

wt Vector of weigh t s, one weigh t per frequency band.

Parameter Description

Page 263: MATLAB Signal Processing Toolbox user manual

Using the Filter Designer: Interactive Filter Design

5-83

1 Act iva te SPTool from the Window menu.

2 Make sure the filt ers you want to ana lyze are selected in the Filte rs list .

3 Press View in the Filter panel.

The Filter Viewer is act iva ted with the select ed filt ers displayed.

4 To edit one of the filt ers you’re viewing, you can react iva te the F ilt erDesigner from the Window menu in the Filter Viewer .

5 When you want to review a filter ’s charact er ist ics a ft er you’ve edited it ,r eact iva te the Filter Viewer from the Window menu in the Filter Designer .

When the F ilt er Viewer is open a t the same t ime tha t the Filter Designer isopen , they both display the same filter . You can move back and for th betweenthe F ilt er Designer and the F ilt er Viewer unt il the filt er design is fin ished.

You can apply the filt er to a signal by act iva t ing SPTool, select ing the filter inthe Filte rs list , and the signa l to apply it to from the Signals list , and pressingApply . See “Applying a Filter” on page 5-18 for deta ils.

See “Using the Filter Viewer : Int eract ive Filter Ana lysis” on page 5-84 for moreinformat ion on the F ilter Viewer .

Page 264: MATLAB Signal Processing Toolbox user manual

5 Interactive Tools

5-84

Using the Filter Viewer: Interactive Filter AnalysisAn impor t ant aspect of filt er design is filt er ana lysis, which encompasses bothfrequency and t ime-domain ana lysis of a filter . The Filter Viewer is aGUI-based frequency ana lysis tool tha t provides an in teract ive environmentfor the graphica l display of digit a l filt er character ist ics.

The F ilter Viewer can display six differen t charact er ist ics subplot s of a select edfilter . Any combina t ion of the six subplot s may be displayed.

Using the F ilter Viewer you can:

•View magnitude-response plots for one or more filt er s•View phase-response plot s for one or more filter s•View group-delay plots for one or more filt er s•View zero-pole plots for one or more filt er s•View impulse-response plot s for one or more filter s•View step-response plot s for one or more filter s• Zoom in to explore filter response deta ils•Modify selected plot parameters and display charact er ist ics•Measure a var iety of charact er ist ics of the filt er response

For informa t ion on frequency ana lysis using toolbox funct ions from thecommand line or from M-files, see “Frequency Response” in Chapter 1 of th ismanual.

Opening the Filter ViewerOpen or act iva te the Filter Viewer from SPTool:

1 Select one or more filt er s from the Filte rs list in SPTool.

2 Press View in the Filte rs panel in SPTool.

The F ilt er Viewer is act iva ted and the select ed filters a re loaded in to theF ilt er Viewer and displayed.

Basic Filter Viewer FunctionsThe Filter Viewer has the following component s:

Page 265: MATLAB Signal Processing Toolbox user manual

Using the Filter Viewer: Interactive Filter Analysis

5-85

•A P lots panel for select ing which subplots display in the main plot s window•A Rulers panel and line display cont rols for making signa l measurementsand compar isons

•A Frequency Axis panel for specifying x-axis sca ling in the main plotswindow

•A filter ident ifica t ion panel tha t displays informat ion about the curren t lyselect ed filter (s)

•A main plot s (display) area for viewing one or more frequency-domain plot sfor the selected filt er (s)

• Zoom cont rols for get t ing a closer look at filter response charact er ist ics

When you fir st open or act iva te the F ilter Viewer , it displays the default plotconfigura t ion for the select ed filt er (s):

The filt er s’magnitude and phase plots a re displayed. The frequency axis of theplots is set to linear, and the frequency axis range is set to [0,Fs /2].

Plots panel, including menus for

modifying plot characteristics

Frequency Axis panel

Filter ID panel

View (zoom) controls

Rulers panel, including controls for measuring filter responses

Line display controls

Page 266: MATLAB Signal Processing Toolbox user manual

5 Interactive Tools

5-86

You can choose to display one or any combina t ion of the six ava ilable subplotsby using the check boxes in the P lots panel, and you can modify many of theplot display character ist ics using the pop-up menus in the P lo ts panel and theFrequency Axis panel.

Menus

File Menu. Use Close from the File menu to close the Filter Viewer . Set t ings youchanged and saved using the Pre fe rence s dia log box in SPTool a re saved andused the next t ime you open a F ilter Viewer .

Window Menu. Use the Window menu to select a cur ren t ly open MATLABfigure window.

Filter Identification PanelThis panel displays the va r iable names and the highest sampling frequency ofthe curren t ly selected filter s. To change names or sampling frequencies, useName… or Sampling Frequency… from the Edit menu in SPTool.

Plots PanelThe check boxes in this panel select the subplots to display in the main plot sarea . Any combina t ion of subplots may be displayed.

To display a subplot , check the box a t the left of the plot descr ipt ion .

There a re six ava ilable subplots:

•Magnitude : displays the magnitude of the frequency response of thecur ren t ly selected filt er (s).

• Phase : displays the phase of the frequency response.•Group De lay : displays the nega t ive of the der iva t ive of the phase response.• Zeros and Pole s : displays the poles and zeros of the filter t ransferfunct ion(s) and their proximity to the unit circle.

• Impu lse Response : displays the response of the curren t ly select ed filter (s)to a discrete-t ime unit -height impulse a t t=0.

• Step Re sponse : displays the response of the curren t ly selected filter (s) to adiscrete-t ime unit -heigh t step funct ion .

Page 267: MATLAB Signal Processing Toolbox user manual

Using the Filter Viewer: Interactive Filter Analysis

5-87

You can customize the display character ist ics of the magnitude and phasesubplot s using the Magnitude and Phase pop-up menus. The opt ions include:

•Magn itude : Sca ling for the magnitude plot may be linear, log , or dec ibe ls .• Phase : Phase unit s may be degre es or radians .

You can a lso change the magnitude and phase display charact er ist ics for theF ilter Viewer using the F ilt er set t ings panel of the Pre ference s dia log box inSPTool.

Frequency Axis SettingsYou can change frequency axis sca ling and range parameters for plot s in theF ilter Viewer .

Click on the opt ion in the Frequency Axis panel you want to edit and drag toselect a va lue. The opt ions include:

• Scale : Sca ling for the frequency axis may be linear or log .

•Range : The range for the frequency axis may be [0,Fs /2], [0,Fs], or[-Fs /2,Fs /2], where Fs represen ts the filter ’s sampling frequency.The frequency range cannot be nega t ive if Scale is set to log .

You can also change the frequency axis display character ist ics for the F ilt erViewer using the Filte r View er set t ings panel of the Pre fe rence s dia log boxin SPTool.

Zoom ControlsThe ava ilable zoom cont rols in the F ilt er Viewer are Mouse Zoom and Fu llView . You can zoom independen t ly in each displayed subplot .

By default , persist en t zooming is disabled in the F ilt er Viewer . You can turnpersisten t zooming on from the Filte r View er set t ings panel of thePre fe rence s dia log box in SPTool.

See “Zoom Cont rols” on page 5-31 for deta ils on using the zoom cont rols in theF ilter Viewer .

Help ButtonTo use context -sensit ive help, press the Help but ton . The mouse pointerbecomes an ar row with a quest ion mark symbol. You can then click on anyth ing

Page 268: MATLAB Signal Processing Toolbox user manual

5 Interactive Tools

5-88

in the Filter Viewer , including menu items, to find out what it is and how touse it .

Main Plots AreaOne or more of the six filt er response subplot s may be displayed graphica lly inthe main plots a rea of the F ilt er Viewer . You can specify how the subplot s a rear ranged by select ing Filte r View er Tiling from the Pre ference s dia log box inSPTool. The opt ions are 2-by-3 Grid , 3-by-2 Grid , Vertica l (6-by-1 Grid), andHorizon tal (1-by-6 Grid).

The following figure shows the Filter Viewer when four subplot s a re tu rned onand the 2-by-3 gr id opt ion is selected.

You can exper imen t to find the t iling opt ion tha t works best for each specificcombina t ion and number of subplot s.

You can zoom in on a subplot by pressing Mouse Zoom and then clicking on ordragging over a selected a rea of the subplot . By defau lt , mouse zooming in theFilter Viewer is not persist en t ; a fter you click once, the zoom mode is tu rnedoff. You can make zooming persist en t by checking Stay in Zoom-mode after

Page 269: MATLAB Signal Processing Toolbox user manual

Using the Filter Viewer: Interactive Filter Analysis

5-89

Zoom in the SPTool Pre fe rence s dia log box. This a llows you to click repea tedlyin a subplot to cont inue to zoom in on a par t icu la r fea ture of the display.

After you zoom in on a subplot , you can click and drag to pan around thesubplot :

1 Press Mouse Zoom to tu rn on mouse zoom mode.

2 Click on a fea ture of a subplot to zoom in on it .

3 If persisten t zooming is enabled, press Mouse Zoom aga in to turn off mousezoom mode.

4 Click aga in in the same subplot , hold down the mouse but ton unt il the handcursor is displayed, and drag the mouse to pan around the subplot .

Viewing Filter PlotsThis sect ion has a br ief descr ipt ion and picture of each of the six filt er responseplots ava ilable in the Filter Viewer . A sequence of connected examples showsyou how to display each plot on it s own; you can also display any combina t ionof plot s, as needed.

Each plot in the example sequence displays the response of an order 22equ ir ipple lowpass filt er with a sampling frequency of 1 Hz.

Regardless of how many or wha t combina t ion of plot s is displayed, you canzoom in on and pan each subplot independent ly.

Viewing Magnitude ResponseA magnitude response plot is genera lly the simplest way to obta in a h igh-levelview of a filter ’s shape and fit to specifica t ions. In the following example, usethe F ilt er Designer to crea te a st andard default filt er and then view it smagnitude response plot in the Filter Viewer :

Page 270: MATLAB Signal Processing Toolbox user manual

5 Interactive Tools

5-90

1 From SPTool, press Create .

The Filter Designer is act iva t ed and a st andard default filt er is crea t ed anddisplayed.

This is an order 22 equir ipple lowpass filter with a sampling frequency of1 Hz.

2 Use the Window menu in the F ilter Designer to act iva te SPTool.

3 Press View from the Filte rs panel in SPTool to act iva t e the Filter Viewer .

The F ilt er Viewer is displayed with a magnitude response plot and a phaseresponse plot .

Page 271: MATLAB Signal Processing Toolbox user manual

Using the Filter Viewer: Interactive Filter Analysis

5-91

4 Click the check box next to the Phase opt ion to turn off the phase plot .

The magnitude plot for the defau lt filt er is displayed.

By defau lt , th is plot uses the defau lt sca ling (lin ear) for both axes and thedefau lt range for the frequency axis.

You can change the following display cha racter ist ics of the magnitude plot :

•Use the Magnitude pop-up menu to choose between linear, log , or dec ibe lssca ling of the y-axis.

•Use the Sca le pop-up menu to choose between linear and log sca ling of thex-axis.

•Use the Range pop-up menu to choose between the following ranges for thex-axis: [0,Fs /2], [0,Fs ], or [-Fs/2,Fs/2], where Fs represen ts the filt er ’ssampling frequency.

Viewing Phase ResponseIn addit ion to displaying magnitude response, the F ilter Viewer can ca lcu la t eand plot the filter ’s phase response. Phase response is the angular componentof a filt er ’s frequency response. To display on ly a phase response plot for thecur ren t filt er :

Page 272: MATLAB Signal Processing Toolbox user manual

5 Interactive Tools

5-92

1 Click the check box next to the Magn itude opt ion to tu rn off the magnitudeplot .

2 Click the check box next to the Phase opt ion to turn on the phase plot andupdate the display.

By defau lt , th is plot uses the default phase (degrees ) and the defau lt sca lingand range for the frequency axis.

You can change the following display charact er ist ics of the phase plot :

•Use the Phase pop-up menu to choose between displaying phase in degree sor radians .

•Use the Scale pop-up menu to choose between linear and log sca ling of thex-axis.

•Use the Range pop-up menu to choose between the following ranges for thex-axis: [0,Fs/2], [0,Fs], or [-Fs /2,Fs /2], where Fs represen ts the filter ’ssampling frequency.

Page 273: MATLAB Signal Processing Toolbox user manual

Using the Filter Viewer: Interactive Filter Analysis

5-93

Viewing Group DelayGroup delay is a measure of the average delay of a filt er as a funct ion offrequency. To display only a group delay plot for the cur ren t ly select ed filter (s):

1 Click the check box next to the Phase opt ion to turn off the phase plot .

2 Click the check box next to the Group De lay opt ion to turn on the groupdelay plot and upda te the display.

By defau lt , th is plot uses the defau lt sca ling and range for the frequencyaxis.

You can change the following display cha racter ist ics of the group delay plot :

•Use the Sca le pop-up menu to choose between linear and log sca ling of thex-axis.

•Use the Range pop-up menu to choose between the following ranges for thex-axis: [0,Fs /2], [0,Fs ], or [-Fs/2,Fs/2], where Fs represen ts the h ighestsampling frequency of the cur ren t ly selected filt er s.

Page 274: MATLAB Signal Processing Toolbox user manual

5 Interactive Tools

5-94

Viewing a Zero-Pole PlotThe zero-pole plot displays the poles and zeros of the t ransfer funct ion and theirproximity to the unit circle. An represen ts a pole of the t ransfer funct ion ; arepresen ts a zero of the t ransfer funct ion . To display only a zero-pole plot for

the cur ren t ly selected filt er (s):

1 Click the check box next to the Group De lay opt ion to turn off the groupdelay plot .

2 Click the check box next to the Zeros and Pole s opt ion to turn on thezero-pole plot and update the display.

Viewing Impulse ResponseThe im pulse response plot displays the response of the cur ren t filt er (s) to adiscrete-t ime unit -height impulse a t t=0.

To display only an impulse response plot for the cur rent ly selected filt er (s):

Page 275: MATLAB Signal Processing Toolbox user manual

Using the Filter Viewer: Interactive Filter Analysis

5-95

1 Click the check box next to the Zeros and Pole s opt ion to turn off thezero-pole plot .

2 Click the check box next to the Impulse Response opt ion to tu rn on theimpulse response plot and update the display.

You can change the following display cha racter ist ics of the impulse responseplot :

Edit the Time Response Length field in the Filte r View er Pre fe rence s panelto set the number of samples used to display the impulse response.

Viewing Step ResponseThe step response plot displays the response of the cur ren t filter (s) to adiscret e-t ime unit -height step funct ion . To display only a step response plot forthe current ly selected filt er (s):

Page 276: MATLAB Signal Processing Toolbox user manual

5 Interactive Tools

5-96

1 Click the check box next to the Impu lse Response opt ion to turn off theimpulse response plot .

2 Click the check box next to the Step Response opt ion to turn on the stepresponse plot and update the display.

You can change the following display charact er ist ics of the step response plot :

Edit the Time Response Length field in the Filte r View er Pre ference s panelto set the number of samples used to display the st ep response.

Page 277: MATLAB Signal Processing Toolbox user manual

Using the Spectrum Viewer: Interactive PSD Analysis

5-97

Using the Spectrum Viewer: Interactive PSD AnalysisThe Spect rum Viewer provides an in teract ive environment for the est ima t ionof power spect ra l density for one data channel. It a llows you to view and modifyspect ra crea ted in SPTool.

Using the Spect rum Viewer you can :

•View and compare spect ra l density plot s•Use differen t est imat ion methods, including Burg, FFT, MTM, MUSIC,Welch , and Yule-Walker AR

•Modify spect rum parameters such as FFT length , window type, and samplefrequency

• Pr in t spect rum data

For in format ion on spect ra l ana lysis using toolbox funct ions from the commandline or from M-files, see Chapter 3 of th is manua l.

Opening the Spectrum ViewerYou can open or act iva te the Spect rum Viewer from SPTool by pressing one ofthe following but tons: Create , View , and Update . See “Crea t ing a Spect rum”on page 5-19, “Viewing a Spect rum” on page 5-19, and “Updat ing a Spect rum”on page 5-19 for complete deta ils.

Here is a br ief summary of each method of act iva t ing the Spect rum Viewer :

• To crea te a spect rum, select a signa l in SPTool and press Create . P ressApply in the Spect rum Viewer .A defau lt spect rum of the selected signa l is genera ted and displayed. You canview it in a var iety of ways, measure it , and modify it in the Spect rumViewer .

• To view a spect rum, select one or more spect ra in SPTool and press View inthe Spectra panel.

• To upda te a spect rum, select exact ly one signa l and one spect rum in SPTooland press Update . P ress Apply in the Spect rum Viewer .

The spect rum is upda ted to reflect the da ta in the cur ren t ly select ed signa l.

Page 278: MATLAB Signal Processing Toolbox user manual

5 Interactive Tools

5-98

Basic Spectrum Viewer FunctionsThe Spect rum Viewer window has the following components:

•A Parame ters panel for viewing and modifying the parameters or method ofthe cur ren t spect rum

•A signa l ident ifica t ion panel tha t displays informat ion about the signa llinked to the cur ren t spect rum

•A main axes (display) a rea for viewing spect ra graph ica lly• Zoom cont rols for get t ing a closer look at spect ra l fea tures•Rulers and line-display cont rols for making spect ra l measurements andcomparisons

• Spect rum management con t rols: Inherit from..., Revert , and Apply•Menu opt ions for modifying plot display character ist ics•Menu opt ions for pr in t ing spect rum da ta

Main axes area

Signal ID

Ruler and line display controls

Zoom controls

Parameters panel

Page 279: MATLAB Signal Processing Toolbox user manual

Using the Spectrum Viewer: Interactive PSD Analysis

5-99

Menus

File Menu. Use Page Se tup... from the File menu to open the standa rdMATLAB Page Se tup dia log box (see Using MATLAB Graphics), in which youcan set the or ien ta t ion, size and posit ion , limit s, and color of your pr in tou t .

Use Prin t P review ... from the File menu to open a MATLAB figure windowwith a preview of the in format ion from the Spect rum Viewer window that willappear in your pr in tout . See “Spect rum Viewer Set t ings” on page 5-24 and“Pr in t ing Spect rum Data” on page 5-107 for deta ils of pr in t ing from theSpect rum Viewer .

Use Prin t... from the File menu to open the standard opera t ing system pr in tdia log box, from which you can pr in t your spect rum data .

Use Close from the File menu to close the Spect rum Viewer . All spect rumselect ion and ruler in format ion will be lost . Set t ings you changed and savedusing the Pre fe rence s dia log box in SPTool are saved and used the next t imeyou open the Spect rum Viewer.

Options Menu. Use these opt ions to change sca ling and range parameters forplots in the Spect rum Viewer .

Click on the opt ion you want to edit and drag to select a va lue.

Page 280: MATLAB Signal Processing Toolbox user manual

5 Interactive Tools

5-100

The opt ions include:

•Magnitude Scale : Sca ling for the magnitude plot may be dB or lin ear.

• Frequency Range : The range for the frequency axis may be [0, Fs /2], [0, Fs ],or [-Fs/2, Fs /2], where Fs is the sampling frequency. If mult iple spect ra a redisplayed, the va lue of Fs is the maximum of a ll the sampling frequencies.Fs is not defined for the case of a spect rum whose signa l is <None>, tha t is, aspect rum whose associa ted signa l has been deleted from SPTool. In th is case,a va lue twice the h ighest frequency in the spect rum’s frequency vector ischosen .The frequency range cannot be nega t ive if Frequency Sca le is set to log .

• Frequency Scale : Sca ling for the frequency axis may be linear or log .

Window Menu. Use the Window menu to select a cur ren t ly open MATLABfigure window.

Signal ID PanelThis panel displays informat ion about the signa l linked to the cur rent lyselected spect rum. The informa t ion includes the signa l’s name, size, da ta type(real or complex), and sampling frequency. To change any of these signa lproper t ies, use SPTool.

To associa t e a complet ely new signa l with a displayed spect rum, select thesigna l in SPTool and press Update in the Spectra panel.

Spectrum Management Buttons

Inherit from… Choose a spect rum from th is menu to let the act ive spect ruminher it it s pa rameters (not including the associa ted signa l).

Press Inherit from… and drag to select the spect rum from which you want toinher it parameters.

Revert. Restores the proper t ies of the cur ren t spect rum to what they were thelast t ime Apply was pressed.

Apply. Compute and display the act ive spect rum using the pa rameters set inthe Parameters panel.

Page 281: MATLAB Signal Processing Toolbox user manual

Using the Spectrum Viewer: Interactive PSD Analysis

5-101

Zoom ControlsThe ava ilable zoom cont rols in the Spect rum Viewer are Mouse Zoom , Fu llView , Zoom In-Y, Zoom Out-Y, Zoom In-X, and Zoom Out-X. See “ZoomControls” on page 5-31 for deta ils on using the zoom cont rols in the Spect rumViewer .

Ruler and Line Display ControlsUsing the rulers and line-display cont rols, you can measure a var iety ofcharact er ist ics of spect ra in the Spect rum Viewer . See “Ruler Cont rols” on page5-33 for deta ils on using ru lers and modifying line displays in the Spect rumViewer .

Help ButtonTo use context -sensit ive help, press the Help but ton . The mouse pointerbecomes an ar row with a quest ion mark symbol. You can then click on anyth ingin the Spect rum Viewer , including menu it ems, to find out what it is and howto use it .

Main Axes Display AreaThe Spectra list in SPTool shows all spect ra in the cur ren t SPTool session . Oneor more spect ra may be selected. The spect ra l da ta of a ll selected spect ra a redisplayed graph ica lly in the ma in axes display area of the Spect rum Viewer .

NOTE If a spect rum is not displayed, or if it is displayed with the wrongsigna l in format ion , press Apply to recompute the spect ra l da ta .

When there is on ly one spect rum displayed, it s proper t ies are displayed in theParameters panel and it s measurement s are displayed in the Rulers panel.When more than one spect rum is displayed, select the line you want to focus on .

When a spect rum is select ed, you can use the ru ler con t rols on the selected line(see “Making Signa l Measurements” on page 5-37) and you can modify it sparameters (see below). The label of the selected spect rum (line) is displayed inthe Se lec tion pop-up menu.

Page 282: MATLAB Signal Processing Toolbox user manual

5 Interactive Tools

5-102

Select a spect rum (line) in one of two ways:

•Click on the Se lection pop-up menu and drag to select the line to measure•Move the mouse poin ter over any point in the line you want to select and clickon it

See “Select ing a Line to Measure” on page 5-34 for deta ils.

Click-and-Drag Panning. You can use the mouse to pan around the main axesdisplay:

Click on a line in the ma in axes, hold down the mouse but ton , and drag themouse.

Click-and-drag panning is not enabled in mouse zoom mode.

Making Spectrum MeasurementsUse the ru ler s to make a va r iety of measurements on the selected spect rum.See “Making Signa l Measurement s” on page 5-37 for deta ils.

Viewing Spectral Density PlotsSpect ra l density est imat ion is a technique tha t finds the approximatefrequency conten t of a signa l. The Spect rum Viewer ca lcu la t es single-channelpower spect ra l density (PSD). When you fir st genera te a spect rum, theSpect rum Viewer shows a defau lt power spect ra l density funct ion of the inpu tda ta . By defau lt , the Spect rum Viewer uses the Welch method of PSDest ima t ion with a length-256 Hanning window and an FFT length of 1024.

You can change plot proper t ies and computa t ion pa rameter s for a displayedspect rum, and you can set confidence in terva ls.

Controlling and Manipulating Plots

Changing Plot PropertiesYou can cont rol the axes unit s and sca ling proper t ies tha t a ffect the Spect rumViewer ’s plot s.

Page 283: MATLAB Signal Processing Toolbox user manual

Using the Spectrum Viewer: Interactive PSD Analysis

5-103

Use the Options menu to select :

• Linear or decibel sca ling for the magnitude axis• Linear or loga r ithmic sca ling for the frequency axis• The frequency range to view

See “Opt ions Menu” on page 5-99 for deta ils.

You can also zoom in on any of the Spect rum Viewer’s plots. See “ZoomControls” on page 5-31 for deta ils.

You can set other sca ling proper t ies in the Parame te rs panel, depending onthe PSD method computa t ion parameters you choose.

Choosing Computation ParametersThe Spect rum Viewer let s you cont rol the PSD est imat ion parameters of theselected spect rum. Differen t parameters are ava ilable, depending on whichmethod of PSD computa t ion you choose. Set these pa rameter s from theParameters panel, a s illust ra t ed in the following steps:

1 Click on the Method pop-up menu and drag to select one of the followingmethods:

- Burg- Covar iance- FFT- Modified Cova r iance- MTM- MUSIC- Welch- Yule AR

Appropr ia t e parameter select ions are displayed for each method you choose.

Page 284: MATLAB Signal Processing Toolbox user manual

5 Interactive Tools

5-104

2 Modify the appropria te parameters.

- When a parameter is in a pop-up menu, click on the pa rameter label anddrag to select a va lue from the menu.

- When a parameter is in an edit box, type the value or var iable in to the box.

You can a lso modify the parameters by using Inherit from to copy theparameters of another spect rum in SPTool. See “Inher it from…” on page5-100 for deta ils.

3 If you change your mind, you can disca rd changes you make by pressingRevert .

4 To apply the modified parameter s, press Apply .

The new parameters a re applied to the selected spect rum; the Spect rumViewer reca lcu la t es the spect ra l density funct ion and displays the modifiedspect rum.

Computation Methods and ParametersYou can choose from seven PSD computa t ion methods. Each method has it sown set of parameters.

Th is sect ion shows the Paramete rs panel for each of the PSD computa t ionmethods. For deta iled defin it ions and values for each parameter , usecontext -sensit ive help (see “Help But ton” on page 5-101).

Burg. For the Burg method, you can specify the followingpa rameters:

•Order•Nfft

Page 285: MATLAB Signal Processing Toolbox user manual

Using the Spectrum Viewer: Interactive PSD Analysis

5-105

Covariance. For the Covar iance method, you can specify thefollowing parameters:

•Order•Nfft

FFT. For the FFT method, you can specify the followingparameter :

•Nfft

Mod. Covar. For the Modified Covar iance method, you canspecify the following parameters:

•Order•Nfft

MTM. For the MTM method, you can specify the followingparameters:

•NW•Nfft

Page 286: MATLAB Signal Processing Toolbox user manual

5 Interactive Tools

5-106

•WeightsSelect one of the following from the pop-up menu:- adapt- un ity- e igen

•Conf. In t.Check to compute a confidence in terva l and type in a value (see “Set t ingConfidence In terva ls” on page 5-107).

MUSIC. For the MUSIC method, you can specify the followingpa rameters:

• Signa l Dim.• Threshold•Nfft•Nw ind•Window•Overlap•Corr. MatrixCheck if select ed signa l is a cor rela t ion mat r ix.

• Eigenve ctor WeightsCheck to select eigenvector weigh ts.

Welch. For Welch’s method, you can specify the followingpa rameters:

•NFFT•Nw ind•Window•Overlap• Sca lingSelect one of the following from the pop-up menu:- Unbiased- Peaks

Page 287: MATLAB Signal Processing Toolbox user manual

Using the Spectrum Viewer: Interactive PSD Analysis

5-107

•Conf. In t.Check to compute a confidence int erva l and type in a va lue (see “Set t ingConfidence In terva ls” on page 5-107).

Yule AR. For the Yule AR method, you can specify the followingparameters:

•Order•Nfft•Corr. MatrixCheck if selected signa l is a cor rela t ion matr ix.

Setting Confidence IntervalsBy default , t he Spect rum Viewer does not compute confidence in terva ls forspect ra l density. You can enable the computa t ion of confidence in terva ls for theWelch and MTM methods by following these st eps:

1 Click the Conf. In t. check box so tha t it is selected.

2 Type a value for the confidence level in the Conf. In t. edit box.

This va lue must be a sca la r between 0 and 1.

3 Press Apply .

NOTE Confidence in terva ls are reliable on ly for nonover lapping sect ions.

Printing Spectrum DataYou can pr in t a ll of the spect rum data tha t you can display and manipula t e inthe Spect rum Viewer . Your pr intout will a lways conta in :

• The plot s of one or more spect ra , a s displayed in the main axes area•A legend displayed in the main axes a rea to label each spect rum by name,line color /style, method, and FFT length

The ru ler measurements of the curren t ly selected spect rum will be displayedat the bot tom of the figure, unless you suppress them with the Rule rs check

Page 288: MATLAB Signal Processing Toolbox user manual

5 Interactive Tools

5-108

box in the Spectrum View er preferences panel of the Pre fe rence s dia log boxin SPTool (see “Spect rum Viewer Set t ings” on page 5-24).

You can preview your pr intout by choosing Prin t P rev iew ... from the Filemenu in the Spect rum Viewer window. This opens the Spectrum View erPrin t P review window, shown below with default set t ings for the spect rummtlbse.

The Close but ton on the Spectrum View er Prin t P rev iew window closes thepr int preview window and returns you to the Spect rum Viewer .

The Prin t... but ton on the Spectrum View er Prin t P review window opens thestanda rd pr in t dia log box, from which you can pr in t the content s of your pr intpreview window.

If you choose to pr in t from the pr in t dia log, both tha t dia log and the SpectrumView er Prin t P rev iew window will close, and the conten t s of the pr in t previewwill pr in t .

If you choose not to pr int , t he pr in t dia log and the Spectrum View er Prin tP review window will close, and you will retu rn to the Spect rum Viewer .

Any changes you make, pr ior to open ing the pr int preview window, tha t a ffectthe display of da ta in the Spect rum Viewer (see “Cont rolling and Manipu la t ingPlots” on page 5-102) will a ffect the display of da ta in the Spectrum View er

Page 289: MATLAB Signal Processing Toolbox user manual

Using the Spectrum Viewer: Interactive PSD Analysis

5-109

Prin t P rev iew window in exact ly the same way. For example, in the pr in tpreview shown below:

•Data from three differen t sample spect ra have been selected for display inthe same main axes area (see “Opening the Filter Viewer” on page 5-84).

•Using the tools in the Edit Line pop-up menu (see “Ruler and Line DisplayCont rols” on page 5-101), the spect rum lines have a ll been changed to blackand their line styles have been different ia t ed, a s is reflected in the legend.

• The plots of a ll th ree spect ra have been zoomed to an in terva l between theirru lers (see “Zoom Controls” on page 5-101). Note tha t the rulermeasurements displayed a re for the trainse spect rum, which is thecur ren t ly select ed spect rum.

Changes you make in the Pre ference s dia log box in SPTool will a lso a ffect theSpectrum View er Prin t P review window in the same way tha t they a ffect theSpect rum Viewer it self. For example, in the pr int preview shown below, the

Page 290: MATLAB Signal Processing Toolbox user manual

5 Interactive Tools

5-110

ru ler measurements have been suppressed by changes in the Spect rum Viewerpreferences (see “Spect rum Viewer Set t ings” on page 5-24).

NOTE The HandleVisibility proper ty of the Prin t P rev iew figure window isset to 'on'. This a llows you to modify the preview using Handle Graphicscommands from the MATLAB command line or the P lot Editor tools (see UsingMATLAB Graphics for more informa t ion). For example, you can drag thelegend to a differen t posit ion within the figure, as has been done in the figureshown above

Changes tha t you make in the preview window pr in t exact ly as they appear onthe screen ; however, they are not saved when the Prin t P review figurewindow is closed.

Saving Spectrum DataAfter crea t ing a spect rum in SPTool, you can expor t spect rum informat ion tothe workspace or to disk using Export... from the File menu in SPTool. Thespect rum informat ion is stored in a st ructure tha t you can access to ret r ieve thespect ra l power and frequency da ta . The spect rum st ructure a lso conta ins anumber of fields tha t a re used in terna lly by SPTool.

Page 291: MATLAB Signal Processing Toolbox user manual

Using the Spectrum Viewer: Interactive PSD Analysis

5-111

To see the fields of the spect rum st ructure, t ry expor t ing a spect rum to theworkspace:

1 Crea te a new spect rum if none are cur ren t ly loaded. Label the spect rumspect1.

2 In SPTool, select Export... from the File menu.

3 In the Export dia log box, select spect1 and press the Export to Workspacebut ton .

4 Type who a t the MATLAB command line to look a t the var iables in theworkspace. The var iable ca lled spect1 is the spect rum st ructure youexpor t ed from SPTool.

5 Type spect1 t o list the fields of the spect rum st ructure.

The following st ructure fields descr ibe the spect rum.

Field Description

P The spect ra l power vector.

f The spect ra l frequency vector.

confid A structure conta in ing the confidence in terva ls da ta :

• The confid.level field conta ins the chosenconfidence level.

• The confid.Pc field con ta ins the spect ra l powerda ta for the confidence in terva ls.

• The confid.enable field conta ins a 1 if confidencelevels a re enabled for the spect rum.

signalLabel The name of the signa l from which the spect rum wasgenera ted.

Fs The associa ted signa l’s sample ra te.

Page 292: MATLAB Signal Processing Toolbox user manual

5 Interactive Tools

5-112

The other fields a re used in terna lly by SPTool, and a re subject to change infu ture releases.

Page 293: MATLAB Signal Processing Toolbox user manual

Example: Generation of Bandlimited Noise

5-113

Example: Generation of Bandlimited NoiseThis sect ion provides a complet e example of using the GUI-based interact ivetools to design and implement an FIR digit a l filt er , apply it to a signa l, anddisplay signa ls and spect ra . The steps include:

• Impor t ing and naming a signa l using SPTool•Design ing a filter using the F ilter Designer• In SPTool, applying the filter to the signa l to crea t e another signa l•Viewing the t ime domain informa t ion of the or igina l and filt ered signa lsusing the Signa l Browser

•Compar ing the spect ra of both signa ls using the Spect rum Viewer

Create, Import, and Name a SignalYou can impor t an exist ing signa l in to SPTool, or you can crea t e a new signa land edit and name it in SPTool. In th is step, you’ll crea te a new signa l a t thecommand line and then impor t it in to SPTool.

1 At the command line, crea te a random signa l by typing:x = randn(5000,1);

2 Act iva t e SPTool by typing:sptool

The SPTool window is displayed.

Page 294: MATLAB Signal Processing Toolbox user manual

5 Interactive Tools

5-114

3 Select Import... from the File menu:

The Import to SPTool window is displayed.

Not ice tha t the var iable x is displayed in the Workspace Con ten ts list . (Ifit is not , click the From Workspace radio but ton to display the contents ofthe workspace.)

4 Name the signa l and impor t it in to SPTool:

a Make sure tha t Signal is selected in the Import As pop-up menu .

b Click in the Data field and type x.

You can also move the var iable x in to the Data field by clicking on x intheWorkspace Conten ts list and then clicking on the ar row to the left ofthe Data field.

c Click in the Sampling Frequency field and type 5000.

d Name the signa l by clicking in the Name field and typing noise.

e Press OK.

The SPTool window is react iva ted, and the signa l noise[vector] is selectedin the Signals list .

Page 295: MATLAB Signal Processing Toolbox user manual

Example: Generation of Bandlimited Noise

5-115

Design a FilterYou can impor t an exist ing filter in to SPTool, or you can design and edit a newfilt er using the Filter Designer . In th is step, you’ll crea te a defau lt filter andcustomize it in the Filter Designer .

1 Press New Design in SPTool to act iva t e the Filter Designer and genera te adefault filt er .

The Filter Designer window is displayed with the default filt er filt1.

2 Change the filt er sampling frequency to 5000 by enter ing this va lue in theSampling Frequency text box in the F ilter Designer .

3 Specify the filter parameter s shown at left :

a Make sure Equiripple FIR is selected in the Algorithm pop-up menu .

b Select bandpass from the Type pop-up menu .

c Set the passband edge frequencies by enter ing 750 for Fp1 and 1250 forFp2 .

d Set the stopband edge frequencies by en ter ing 500 for Fs1 and 1500 forFs2 .

e Type .01 in to the Rp field and 75 in to the Rs field.

Rp set s the maximum passband r ipple and Rs sets the stopbanda t t enua t ion for the filter .

f Press the Apply but ton to compute the new filt er .

Page 296: MATLAB Signal Processing Toolbox user manual

5 Interactive Tools

5-116

When the new filt er is computed, the magnitude response of the filter isdisplayed with a solid line in the main axes display a rea .

The result ing filt er is an order 78 bandpass equ ir ipple filter .

Apply the Filter to a SignalIn this step, you apply the filt er to the signa l in SPTool. The new, filt ered signa lis au tomat ica lly crea t ed in SPTool.

Page 297: MATLAB Signal Processing Toolbox user manual

Example: Generation of Bandlimited Noise

5-117

1 Act iva te SPTool from the Window menu in the F ilt er Designer .

2 Click to select the signa l noise[vector] from the Signa ls list and click toselect the filter (named filt1[design]) from the Filte rs list , as shownbelow.

3 Press Apply to apply the filt er filt1 t o the signa l noise.

The Apply Filte r dia log box is displayed.

4 Name the new signal by clicking in the Outpu t Signal field and typingblnoise.

5 Press OK.

The filter is applied to the selected signa l. The new, filtered signa lblnoise[vector] is displayed in the Signa ls list .

View, Play, and Print the SignalsYou can view and pr in t the t ime domain informat ion of the signa ls using theSigna l Browser . You can a lso play the signa ls, if your computer has audiooutput capabilit ies. In th is step, you’ll display both signa ls in the Signa lBrowser , select and play each signa l, and pr int both signa ls.

Page 298: MATLAB Signal Processing Toolbox user manual

5 Interactive Tools

5-118

1 Sh ift-click on the noise and blnoise signa ls in the Signa ls list of SPTool toselect both signa ls.

2 Press View in the Signals panel.

The Signa l Browser is act iva ted and both signa ls a re displayed in the ma inaxes display a rea . In it ia lly, the noise signa l covers up the bandlimitedblnoise signa l, but you can see tha t both signa ls a re displayed because thenames of both signa ls a re shown above the ma in axes display area .

3 Click-and-drag in the Se lec tion pop-up menu to select the blnoise signa l.

The ma in axes display a rea is redisplayed. Now you can see the blnoisesigna l super imposed on top of the noise signa l. The signa ls a re displayed indifferen t colors in both the ma in axes display a rea and the panner . Not ice

Page 299: MATLAB Signal Processing Toolbox user manual

Example: Generation of Bandlimited Noise

5-119

tha t the color of the line in the Se lection display changes to correspond tothe color of the signa l tha t you’ve select ed.

The signa l tha t ’s displayed in the Se le c tion pop-up menu and in theSe lection display is the act ive signa l. When you select P lay , or use therulers, t he act ive signa l is the one tha t is played or measured.

4 To hear the act ive signa l, select P lay from the Options menu.

5 To hear the other signal, select it as in st ep 3 above (you can also select thesignal by clicking on it in the main axes display area). Select P lay from theOptions menu aga in .

6 Before pr int ing the two signa ls together , use the line cont rols to maximizethe visua l con t rast between the signa ls by set t ing the line color for noise t o

Page 300: MATLAB Signal Processing Toolbox user manual

5 Interactive Tools

5-120

gray and the line color for blnoise to whit e. (See “Ruler Controls” on page5-33 for deta ils on using these cont rols.)

Use the Signal Browser panel in the Pre ference s dia log box in SPTool tosuppress pr in t ing of both the panner and the ru ler set t ings. (See “Signa lBrowser Set t ings” on page 5-23 for deta ils on these preferences.)

To pr in t both signa ls, as seen in the pictu re below, select Prin t... from theFile menu in the Signa l Browser .

Compare Spectra of Both SignalsYou can get an idea of the frequency conten t of the two signa ls by displayingtheir power spect ra using the Spect rum Viewer , a s descr ibed below.

1 React iva te SPTool by select ing it from the Window menu of the Signa lBrowser .

2 Click on the noise[vector] signa l in the Signa ls list of SPTool to select it .

Page 301: MATLAB Signal Processing Toolbox user manual

Example: Generation of Bandlimited Noise

5-121

3 Press Create in the Spectra panel.

The Spect rum Viewer is act iva ted, and a spect rum object (spect1)cor responding to the noise signa l is crea t ed in the Spectra list . Thespect rum is not computed or displayed yet .

4 Press Apply in the Spect rum Viewer to compute and display spect1. Thespect rum of the noise signa l is displayed in the main axes display area .

Not ice tha t the spect rum’s signa l iden t ifica t ion informa t ion – including it sname, it s type, and it s sampling frequency – is displayed above theParameters panel, and the spect rum’s name is displayed both above themain axes display a rea and in the Se le ction pop-up menu .

The spect rum est imate is with in 2 or 3 dB of 0, so the noise has a fa ir ly “fla t”spect rum.

5 React iva t e SPTool by select ing it from the Window menu in the Spect rumViewer .

6 Click on the blnoise signa l in the Signa ls list of SPTool to select it .

Page 302: MATLAB Signal Processing Toolbox user manual

5 Interactive Tools

5-122

7 Press Create in the Spectra panel.

The Spect rum Viewer is aga in act iva ted, and a spect rum object (spect2)cor responding to the blnoise signa l is crea t ed in the Spectra list . Thespect rum is not computed or displayed yet .

8 Press Apply in the Spect rum Viewer to display spect2.

The spect rum of the blnoise signa l is displayed in the main axes displayarea .

The new spect rum’s signa l iden t ifica t ion informa t ion – including it s name,it s type, and it s sampling frequency – is displayed above the Parame te rspanel, and the spect rum’s name is displayed both above the ma in axesdisplay area and in the Se lec tion pop-up menu .

This spect rum is fla t between 750 and 1250 Hz and has 75 dB less power inthe stopband regions of filt1.

9 React iva te SPTool aga in , as in step 5 above.

Page 303: MATLAB Signal Processing Toolbox user manual

Example: Generation of Bandlimited Noise

5-123

10 Sh ift-click on spect1 and spect2 in the Spectra list t o select them both .

11 Press View in the Spectra panel to react iva te the Spect rum Viewer anddisplay both spect ra together .

12 To select one of the spect ra for measur ing or edit ing, use the Se lectionpop-up menu, or click on the spect rum in the main axes display area .

The color of the line in the Se lection display changes to cor respond to thecolor of the spect rum tha t you’ve select ed.

The spect rum tha t ’s displayed in the Se lection pop-up menu and in theSe lection display is the act ive spect rum. When you use the ru lers or changepa rameters, the act ive spect rum is the one tha t is measured or modified.

13 Before pr in t ing the two spect ra together , use the select ion and ru ler con t rolsto different ia t e the two plot s by line style, ra ther than by color . Drag therulers to demark the stopband edge frequencies and change the ru lers from

Page 304: MATLAB Signal Processing Toolbox user manual

5 Interactive Tools

5-124

Track t o Vertica l. (See “Ruler Cont rols” on page 5-33 for deta ils on usingthese con t rols.)

Select Prin t P review ... from the File menu in the Spect rum Viewer . F romthe Spectrum View er Prin t P rev iew window, drag the legend out of theaxes display a rea so tha t it doesn’t obscure par t of the plot .

To pr int both signa ls, a s seen in the pictu re below, select the Prin t... but tonon the Spectrum View er Prin t P review window.

Page 305: MATLAB Signal Processing Toolbox user manual

6

Reference

Page 306: MATLAB Signal Processing Toolbox user manual

6 Reference

6-2

This chapter con ta ins deta iled descr ipt ions of a ll Signa l Processing Toolboxfunct ions. It begins with a list of funct ions grouped by subject a rea andcont inues with the reference en t r ies in a lphabet ica l order . For moreinformat ion , see the online MATLAB Function Reference.

Waveform Generation and Plotting

chirp Swept-frequency cosine genera tor.

diric Dir ichlet or per iodic sinc funct ion .

gauspuls Gaussian-modula t ed sinusoida l pu lse genera tor.

pulstran Pulse t ra in genera tor.

rectpuls Sampled aper iodic rectangle genera tor.

sawtooth Sawtooth or t r iangle wave genera tor.

sinc Sinc funct ion .

square Square wave genera tor.

strips St r ip plot .

tripuls Sampled aper iodic t r iangle genera tor.

Filter Analysis and Implementation

abs Absolu te va lue (magnitude).

angle Phase angle.

conv Convolu t ion and polynomia l mult iplica t ion .

conv2 Two-dimensiona l convolu t ion.

fftfilt FFT-based FIR filter ing using the over lap-add method.

filter Filter da ta with a recursive (IIR) or nonrecursive (FIR)filter.

Page 307: MATLAB Signal Processing Toolbox user manual

6-3

filter2 Two-dimensiona l digita l filt er ing.

filtfilt Zero-phase digita l filter ing.

filtic Find in it ia l condit ions for a t ransposed direct form II filt erimplementa t ion .

freqs Frequency response of ana log filt ers.

freqspace Frequency spacing for frequency response.

freqz Frequency response of digita l filt er s.

grpdelay Average filter delay (group delay).

impz Impulse response of digita l filt er s.

latcfilt Lat t ice and la t t ice-ladder filt er implementa t ion .

sgolayfilt Savit zky-Golay filter ing.

sosfilt Second-order (biquadra t ic) IIR filt er ing.

unwrap Unwrap phase angles.

zplane Zero-pole plot .

Linear System Transformations

ac2poly Conversion of au tocor rela t ion sequence to predict ionpolynomia l.

ac2rc Conversion of au tocorrela t ion sequence to reflect ioncoefficien t s.

convmtx Convolu t ion mat r ix.

latc2tf Lat t ice filt er to t ransfer funct ion conversion .

Filter Analysis and Implementation

Page 308: MATLAB Signal Processing Toolbox user manual

6 Reference

6-4

poly2ac Conversion of predict ion polynomia l to autocorrela t ionsequence.

poly2rc Conversion of predict ion polynomia l to reflect ioncoefficien t s.

rc2ac Conversion of reflect ion coefficien t s to au tocor rela t ionsequence.

rc2poly Conversion of reflect ion coefficien t s to predict ionpolynomia l.

residuez z-t ransform par t ia l-fract ion expansion.

sos2ss Conversion of second-order sect ions to st a te-space.

sos2tf Conversion of second-order sect ions to t ransfer funct ion .

sos2zp Conversion of second-order sect ions to zero-pole-ga in .

ss2sos Conversion of st a t e-space to second-order sect ions.

ss2tf Conversion of st a t e-space to t ransfer funct ion .

ss2zp Conversion of st a t e-space to zero-pole-ga in .

tf2latc Conversion of t ransfer funct ion to la t t ice filt er.

tf2sos Conversion of t ransfer funct ion to second-order sect ions.

tf2ss Conversion of t ransfer funct ion to st a te-space.

tf2zp Conversion of t ransfer funct ion to zero-pole-ga in .

zp2sos Conversion of zero-pole-ga in to second-order sect ions.

zp2ss Conversion of zero-pole-ga in to st a te-space.

zp2tf Conversion of zero-pole-ga in to t ransfer funct ion .

Linear System Transformations

Page 309: MATLAB Signal Processing Toolbox user manual

6-5

IIR Filter Design—Classical and Direct

besself Bessel ana log filter design .

butter But terwor th ana log and digit a l filt er design .

cheby1 Chebyshev type I filter design (passband r ipple).

cheby2 Chebyshev type II filter design (stopband r ipple).

ellip Ellipt ic (Cauer) filter design .

maxflat Genera lized digita l But t erwor th filt er design.

yulewalk Recursive digit a l filter design .

IIR Filter Order Selection

buttord But terwor th filt er order select ion .

cheb1ord Chebyshev type I filter order select ion .

cheb2ord Chebyshev type II filter order select ion .

ellipord Ellipt ic filter order select ion .

FIR Filter Design

cremez Complex and nonlinea r-phase equir ipple FIR filter design .

fir1 Window-based fin ite impulse response filt er design –standa rd response.

fir2 Window-based fin ite impulse response filt er design –a rbit ra ry response.

fircls Const ra ined least square FIR filt er design for mult ibandfilter s.

Page 310: MATLAB Signal Processing Toolbox user manual

6 Reference

6-6

fircls1 Const ra ined least square filter design for lowpass andhighpass linear phase FIR filter s.

firls Least squa re linea r-phase FIR filter design .

firrcos Raised cosine FIR filter design .

intfilt In terpola t ion FIR filter design .

kaiserord Est ima te parameters for an FIR filt er design with Kaiserwindow.

remez Parks-McClellan opt imal FIR filter design .

remezord Parks-McClellan opt imal FIR filter order est imat ion .

sgolay Savitzky-Golay filt er design.

Transforms

czt Chirp z-t ransform.

dct Discrete cosine t ransform (DCT).

dftmtx Discrete Four ier t ransform mat r ix.

fft One-dimensiona l fa st Four ier t ransform.

fft2 Two-dimensiona l fast Four ier t ransform.

fftshift Rear range the outpu t s of the FFT funct ions.

hilbert Hilber t t ransform.

idct Inverse discrete cosine t ransform.

ifft One-dimensiona l inverse fast Four ier t ransform.

ifft2 Two-dimensiona l inverse fast Four ier t ransform.

FIR Filter Design

Page 311: MATLAB Signal Processing Toolbox user manual

6-7

Statistical Signal Processing

cohere Est imate magnitude squared coherence funct ion betweentwo signa ls.

corrcoef Correla t ion coefficien t mat r ix.

cov Covar iance ma t r ix.

csd Est imate the cross spect ra l density (CSD) of two signa ls.

pburg Power spect rum est ima te using the Burg method.

pcov Power spect rum est ima te using the covar iance method.

pmcov Power spect rum est ima te using the modified covar iancemethod.

pmtm Power spect rum est ima te using the mult it aper method(MTM).

pmusic Power spect rum est ima te using MUSIC eigenvectormethod.

pwelch Est imate the power spect ra l density (PSD) of a signa l usingWelch’s method.

pyulear Power spect rum est ima te using Yule-Walker AR method.

tfe Transfer funct ion est ima te from input and outpu t .

xcorr Cross-cor rela t ion funct ion est imate.

xcorr2 Two-dimensiona l cross-cor rela t ion .

xcov Cross-cova r iance funct ion est imate (equa l tomean-removed cross-cor rela t ion).

Page 312: MATLAB Signal Processing Toolbox user manual

6 Reference

6-8

Windows

bartlett Bar t let t window.

blackman Blackman window.

boxcar Rectangular window.

chebwin Chebyshev window.

hamming Hamming window.

hanning Hanning window.

kaiser Kaiser window.

triang Tr iangula r window.

Parametric Modeling

arburg Compute an est imate of AR model parameters using theBurg method.

arcov Compute an est imate of AR model parameters using thecova r iance method.

armcov Compute an est imate of AR model parameters using themodified covar iance method.

aryule Compute an est imate of AR model parameters using theYule-Walker method.

invfreqs Cont inuous-t ime (ana log) filt er iden t ifica t ion fromfrequency data .

invfreqz Discrete-t ime filter ident ifica t ion from frequency data .

levinson Levinson-Durbin recursion .

lpc Linea r predict ion coefficien t s.

prony Prony’s method for t ime domain IIR filt er design .

Page 313: MATLAB Signal Processing Toolbox user manual

6-9

rlevinson Reverse Levinson-Durbin recursion .

stmcb Linear model using Steiglitz-McBride it era t ion .

Specialized Operations

buffer Buffer a signa l vector in to a matr ix of da ta frames.

cceps Complex cepst ra l ana lysis.

cplxpair Group complex numbers in to complex conjuga te pa ir s.

decimate Decrease the sampling ra t e for a sequence (decimat ion).

deconv Deconvolu t ion and polynomia l division .

demod Demodula t ion for communica t ions simula t ion .

dpss Discrete prola te spheroida l sequences (Slepian sequences).

dpssclear Remove discrete prola te spheroida l sequences fromdatabase.

dpssdir Discrete prola te spheroida l sequences da tabase directory.

dpssload Load discrete prola t e spheroida l sequences from da tabase.

dpsssave Save discrete prola t e spheroida l sequences in da tabase.

icceps Inverse complex cepst rum.

interp Increase sampling ra te by an in teger factor (in t erpola t ion).

medfilt1 One-dimensiona l median filt er ing.

modulate Modula t ion for communica t ions simula t ion .

polystab Stabilize polynomia l.

rceps Real cepst rum and minimum phase reconst ruct ion .

Parametric Modeling

Page 314: MATLAB Signal Processing Toolbox user manual

6 Reference

6-10

resample Change sampling ra te by any ra t iona l factor.

specgram Time-dependent frequency ana lysis (spect rogram).

upfirdn Upsample, apply an FIR filt er, and downsample.

vco Voltage cont rolled oscilla tor.

Analog Prototype Design

besselap Bessel ana log lowpass filt er prototype.

buttap Butt erwor th ana log lowpass filter prototype.

cheb1ap Chebyshev type I ana log lowpass filter prototype.

cheb2ap Chebyshev type II ana log lowpass filter prototype.

ellipap Ellipt ic ana log lowpass filter prototype.

Frequency Translation

lp2bp Lowpass to bandpass ana log filter t ransforma t ion .

lp2bs Lowpass to bandstop ana log filter t ransformat ion .

lp2hp Lowpass to h ighpass ana log filter t ransformat ion .

lp2lp Lowpass to lowpass ana log filter t ransformat ion .

Specialized Operations

Page 315: MATLAB Signal Processing Toolbox user manual

6-11

Filter Discretization

bilinear Bilinear t ransformat ion method of ana log-to-digit a l filt erconversion .

impinvar Impulse inva r iance method of ana log-to-digita l filt erconversion .

Interactive Tools

sptool In t eract ive digita l signa l processing tool (SPTool).

Page 316: MATLAB Signal Processing Toolbox user manual

abs

6-12

6absPurpose Absolu te va lue (magnitude).

Syntax y = abs(x)

Description y = abs(x) returns the absolu te va lue of the elements of x. If x is complex, absretu rns the complex modulus (magnitude):

abs(x) = sqrt(real(x).^2 + imag(x).^2)

If x is a MATLAB st r ing, abs retu rns the numer ic va lues of the ASCIIcharacters in the st r ing. The display format of the st r ing changes; the in terna lrepresen ta t ion does not .

The abs funct ion is pa r t of the st andard MATLAB language.

Example Calcula t e the magnitude of the FFT of a sequence:

t = (0:99)/100; % time vectorx = sin(2*pi*15*t) + sin(2*pi*40*t); % signaly = fft(x); % compute DFT of xm = abs(y); % magnitude

Plot the magnitude:

f = (0:length(y)–1)'/length(y)*100; % frequency vectorplot(f,m)

See Also angle Phase angle.

Page 317: MATLAB Signal Processing Toolbox user manual

ac2poly

6-13

6ac2polyPurpose Conversion of autocorrela t ion sequence to predict ion polynomia l.

Syntax a = ac2poly(r)[a,efinal] = ac2poly(r)

Description a = ac2poly(r) finds the predict ion polynomia l, a, corresponding to theau tocor rela t ion sequence r. a is the same length as r, and a(1) = 1.

[a,efinal] = ac2poly(r) retu rns the fina l predict ion error , efinal.

Example Consider the autocor rela t ion sequence

r = [5.0000 –1.5450 –3.9547 3.9331 1.4681 –4.7500];

The equiva len t predict ion polynomia l is

a = ac2poly(r)

a =

1.0000 0.6147 0.9898 0.0004 0.0034 –0.0077

See Also

References [1] Kay, S.M. Modern S pectral Estim ation . Englewood Cliffs, NJ :Prent ice-Ha ll, 1988.

ac2rc Conversion of autocorrela t ion sequence to reflect ioncoefficien t s.

poly2ac Conversion of predict ion polynomia l toautocorrela t ion sequence.

rc2poly Conversion of predict ion polynomia l to reflect ioncoefficien t s.

Page 318: MATLAB Signal Processing Toolbox user manual

ac2rc

6-14

6ac2rcPurpose Conversion of autocor rela t ion sequence to reflect ion coefficien ts.

Syntax [k,r0] = ac2rc(r)

Description [k,r0] = ac2rc(r) finds the reflect ion coefficien t s, k, cor responding to theautocor rela t ion sequence r. r0 conta ins the zero-lag autocorrela t ion .

See Also

References [1] Kay, S.M. Modern S pectral Estim ation . Englewood Cliffs, NJ :Prent ice-Hall, 1988.

ac2poly Conversion of au tocor rela t ion sequence to predict ionpolynomia l.

poly2rc Conversion of predict ion polynomia l to reflect ioncoefficien ts.

rc2ac Conversion of reflect ion coefficien ts toautocor rela t ion sequence.

Page 319: MATLAB Signal Processing Toolbox user manual

angle

6-15

6anglePurpose Phase angle.

Syntax p = angle(h)

Description p = angle(h) returns the phase angles, in radians, of the element s of complexvector or a r ray h. The phase angles lie between -π and π.

For complex sequence h = x + iy = m eip, the magnitude and phase are given by

m = abs(h)p = angle(h)

To conver t to the or igina l h from its magnitude and phase:

i = sqrt(–1)h = m.*exp(i*p)

The angle funct ion is pa r t of the st andard MATLAB language.

Example Calcu la t e the phase of the FFT of a sequence:

t = (0:99)/100; % time vectorx = sin(2*pi*15*t) + sin(2*pi*40*t); % signaly = fft(x); % compute DFT of xp = unwrap(angle(y)); % phase

Plot the phase:

f = (0:length(y)–1)'/length(y)*100; % frequency vectorplot(f,p)

Algorithm angle can be expressed as:

angle(x) = imag(log(x)) = atan2(imag(x),real(x))

See Also abs Absolu te va lue (magnitude).

Page 320: MATLAB Signal Processing Toolbox user manual

arburg

6-16

6arburgPurpose Compute an est imate of AR model parameters using the Burg method.

Syntax a = arburg(x,p)[a,e] = arburg(x,p)[a,e,k] = arburg(x,p)

Description a = arburg(x,p) uses the Burg method to fit a p-th order autoregressive (AR)model to the inpu t signa l, x, by minimizing (least squares) the forward andbackward predict ion er rors while const ra in ing the AR parameters to sa t isfythe Levinson-Durbin recursion . x is a ssumed to be the outpu t of an AR systemdr iven by white noise. Vector a conta ins the normalized est ima te of the ARsystem parameter s, A (z), in descending powers of z .

Since the method character izes the inpu t da ta using an a ll-pole model, t hecor rect choice of the model order p is impor tan t .

[a,e] = arburg(x,p) retu rns the var iance est ima te, e, of the white noiseinpu t to the AR model.

[a,e,k] = arburg(x,p) retu rns a vector , k, of reflect ion coefficien ts.

See Also

H z( )e

A z( )------------ e

1 a2z1–

… a p 1+( )zp–+ + +

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

arcov Compute an est ima te of AR model parameters usingthe covar iance method.

armcov Compute an est ima te of AR model parameters usingthe modified covar iance method.

aryule Compute an est ima te of AR model parameters usingthe Yule-Walker method.

lpc Linear predict ion coefficien ts.pburg Power spect rum est ima te using the Burg method.prony Prony’s method for t ime domain IIR filter design .

Page 321: MATLAB Signal Processing Toolbox user manual

arcov

6-17

6arcovPurpose Compute an est imate of AR model parameters using the covar iance method.

Syntax a = arcov(x,p)[a,e] = arcov(x,p)

Description a = arcov(x,p) uses the cova r iance method to fit a p-th order au toregressive(AR) model to the inpu t signa l, x, which is assumed to be the outpu t of an ARsystem dr iven by white noise. This method minimizes the forward predict ioner ror in the least -squa res sense. Vector a conta ins the normalized est imate ofthe AR system parameter s, A(z), in descending powers of z .

Because the method charact er izes the inpu t da ta using an a ll-pole model, t hecor rect choice of the model order p is impor tan t .

[a,e] = arcov(x,p) retu rns the var iance est imate, e, of the whit e noise inpu tto the AR model.

See Also

H z( )e

A z( )------------ e

1 a2z1–

… a p 1+( )zp–+ + +

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

arburg Compute an est imate of AR model parameters usingthe Burg method.

armcov Compute an est imate of AR model parameters usingthe modified covar iance method.

aryule Compute an est imate of AR model parameters usingthe Yule-Walker method.

lpc Linea r predict ion coefficient s.pcov Power spect rum est ima te using the covar iance

method.prony Prony’s method for t ime domain IIR filter design .

Page 322: MATLAB Signal Processing Toolbox user manual

armcov

6-18

6armcovPurpose Compute an est imate of AR model parameters using the modified cova r iancemethod.

Syntax a = armcov(x,p)[a,e] = armcov(x,p)

Description a = armcov(x,p) uses the modified covar iance method to fit a p-th orderau toregressive (AR) model to the inpu t signa l, x, which is assumed to be theou tpu t of an AR system dr iven by whit e noise. Th is method min imizes theforward and backward predict ion er rors in the least -squares sense. Vector aconta ins the normalized est ima te of the AR system parameters, A (z), indescending powers of z.

Because the method character izes the inpu t da ta using an a ll-pole model, t hecor rect choice of the model order p is impor tan t .

[a,e] = armcov(x,p) retu rns the var iance est ima te, e, of the white noiseinpu t to the AR model.

See Also

H z( )e

A z( )------------ e

1 a2z1–

… a p 1+( )zp–+ + +

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

arburg Compute an est ima te of AR model parameters usingthe Burg method.

arcov Compute an est ima te of AR model parameters usingthe covar iance method.

aryule Compute an est ima te of AR model parameters usingthe Yule-Walker method.

lpc Linear predict ion coefficien ts.pmcov Power spect rum est ima te using the modified

covar iance method.prony Prony’s method for t ime domain IIR filter design .

Page 323: MATLAB Signal Processing Toolbox user manual

aryule

6-19

6aryulePurpose Compute an est imate of AR model parameters using the Yule-Walker method.

Syntax a = aryule(x,p)[a,e] = aryule(x,p)[a,e,k] = aryule(x,p)

Description a = aryule(x,p) uses the Yule-Walker method, a lso ca lled theautocor rela t ion method, to fit a p-th order au toregressive (AR) model to thewindowed input signa l, x, by minimizing the forward predict ion er ror in theleast -squares sense. Th is formula t ion leads to the Yule-Walker equat ions,which are solved by the Levinson-Durbin recursion . x is assumed to be theou tpu t of an AR system dr iven by whit e noise. Vector a conta ins the normalizedest imate of the AR system parameter s, A(z), in descending powers of z .

Because the method charact er izes the inpu t da ta using an a ll-pole model, t hecor rect choice of the model order p is impor tan t .

[a,e] = aryule(x,p) returns the var iance est ima te, e, of the white noiseinput to the AR model.

[a,e,k] = aryule(x,p) retu rns a vector , k, of reflect ion coefficien ts.

See Also

H z( )e

A z( )------------ e

1 a2z1–

… a p 1+( )zp–+ + +

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

arburg Compute an est imate of AR model parameters usingthe Burg method.

arcov Compute an est imate of AR model parameters usingthe covar iance method.

armcov Compute an est imate of AR model parameters usingthe modified covar iance method.

lpc Linea r predict ion coefficient s.prony Prony’s method for t ime domain IIR filter design .pyulear Power spect rum est ima te using Yule-Walker AR

method.

Page 324: MATLAB Signal Processing Toolbox user manual

bartlett

6-20

6ba r tlet tPurpose Bar t let t window.

Syntax w = bartlett(n)

Description w = bartlett(n) retu rns an n-poin t Ba r t let t window in the column vector w.The coefficien t s of a Bar t let t window are:

• For n odd

• For n even

The Bar t let t window is very simila r to a t r iangula r window as returned by thetriang funct ion . The Bar t let t window always ends with zeros a t samples 1 andn, however , while the t r iangula r window is nonzero a t those point s. For n odd,the cen ter n–2 poin ts of bartle9tt(n) are equiva len t to triang(n–2).

See Also

References [1] Oppenheim, A.V., and R.W. Schafer . Discrete-T im e S ignal Processing.Englewood Cliffs, NJ : Prent ice-Hall, 1989.

w k[ ]

2 k 1–( )n 1–--------------------- 1 k n 1+

2-------------≤ ≤,

2 2 k 1–( )n 1–---------------------– n 1+

2------------- k n≤ ≤,⎩⎪⎨⎪⎧

=

w k[ ]

2 k 1–( )n 1–--------------------- 1 k n

2---≤ ≤,

2 n k–( )n 1–--------------------- n

2--- 1+ k n≤ ≤,⎩⎪⎨⎪⎧

=

blackman Blackman window.boxcar Rectangula r window.chebwin Chebyshev window.hamming Hamming window.hanning Hanning window.kaiser Kaiser window.triang Tr iangular window.

Page 325: MATLAB Signal Processing Toolbox user manual

besselap

6-21

6besselapPurpose Bessel ana log lowpass filter prototype.

Syntax [z,p,k] = besselap(n)

Description [z,p,k] = besselap(n) retu rns the zeros, poles, and ga in of an order n Besselana log lowpass filter prototype. It returns the poles in the length n columnvector p and the ga in in sca la r k. z is an empty mat r ix, because there are nozeros. n must be less than or equal to 25. The t ransfer funct ion is

besselap norma lizes the poles and gain so tha t a t low frequency and highfrequency the Bessel prototype is asymptot ica lly equ iva len t to the But terwor thprototype of the same order [1]. The magnitude of the filter is less thansqrt(1/2) a t the unity cu toff frequency Ωc = 1.

Analog Bessel filt er s are cha racter ized by a group delay tha t is maximally fla ta t zero frequency and a lmost constan t th roughout the passband. The groupdelay a t zero frequency is

Algorithm besselap finds the filter roots from a look-up table const ructed using theSymbolic Math Toolbox.

See Also

Also see the S ym bolic Math Toolbox User’s Guide.

References [1] Rabiner , L.R., and B. Gold. Theory and Application of Digital S ignalProcessing. Englewood Cliffs, NJ : Pren t ice-Ha ll, 1975. Pgs. 228-230.

H s( ) ks p 1( )–( ) s p 2( )–( )Ls p n( )–( )-----------------------------------------------------------------------------=

2n( )!2n n !--------------⎝ ⎠⎛ ⎞ 1 n⁄

besself Bessel ana log filter design .buttap But terwor th analog lowpass filter prototype.cheb1ap Chebyshev type I ana log lowpass filt er prototype.cheb2ap Chebyshev type II ana log lowpass filter prototype.ellipap Ellipt ic ana log lowpass filt er prototype.

Page 326: MATLAB Signal Processing Toolbox user manual

besself

6-22

6besselfPurpose Bessel ana log filter design .

Syntax [b,a] = besself(n,Wn)[b,a] = besself(n,Wn,'ftype')[z,p,k] = besself(...)[A,B,C,D] = besself(...)

Description besself designs lowpass, bandpass, h ighpass, and bandstop ana log Besselfilt ers. Ana log Bessel filt er s are character ized by almost constan t group delayacross the ent ire passband, thus preserving the wave shape of filtered signa lsin the passband. Digit a l Bessel filt ers do not reta in th is qua lity, and besselft herefore does not support the design of digita l Bessel filter s.

[b,a] = besself(n,Wn) designs an order n lowpass analog filter with cutofffrequency Wn. It r etu rns the filter coefficien ts in the length n+1 row vectors band a, with coefficien ts in descending powers of s:

Cutoff frequency is the frequency a t which the magnitude response of the filt erbegins to decrease significant ly. For besself, t he cu toff frequency Wn must begrea ter than 0. The magnitude response of a Bessel filter designed by besselfis a lways less than sqrt(1/2) a t the cutoff frequency, and it decreases as theorder n increases.

If Wn is a two-element vector , Wn = [w1 w2] with w1 < w2, besself(n,Wn) retu rns an order 2*n bandpass ana log filter with passband w1 < ω < w2.

[b,a] = besself(n,Wn,'ftype') designs a highpass or bandstop filt er , whereftype is

• high for a h ighpass ana log filter with cu toff frequency Wn• stop for an order 2*n bandstop ana log filter if Wn is a two-element vector ,Wn = [w1 w2]

The stopband is w1 < ω < w2.With differen t numbers of ou tput argument s, besself direct ly obta ins otherrea liza t ions of the ana log filt er . To obta in zero-pole-ga in form, use three outpu ta rguments:

H s( ) B s( )A s( )----------- b 1( )sn b 2( )sn 1– L b n 1+( )+ + +

sn a 2( )sn 1– L a n 1+( )+ + +----------------------------------------------------------------------------------= =

Page 327: MATLAB Signal Processing Toolbox user manual

besself

6-23

[z,p,k] = besself(n,Wn) or

[z,p,k] = besself(n,Wn,'ftype')

besself retu rns the zeros and poles in length n or 2*n column vectors z and pand the gain in the sca la r k.

To obta in sta te-space form, use four ou tpu t a rguments:

[A,B,C,D] = besself(n,Wn) or

[A,B,C,D] = besself(n,Wn,'ftype') where A, B, C, and D are

and u is the input , x is the st a te vector , and y is the output .

Example Design a fifth-order ana log lowpass Bessel filter tha t suppresses frequenciesgrea ter than 10,000 rad/sec and plot the frequency response of the filt er usingfreqs:

[b,a] = besself(5,10000);freqs(b,a) % plot frequency response

x· Ax B u+=y Cx Du+=

102 103 104 105-200

0

200

Frequency (radians)

Phas

e (d

egre

es)

102 103 104 10510-5

100

Frequency (radians)

Mag

nitu

de

Frequency Response

Page 328: MATLAB Signal Processing Toolbox user manual

besself

6-24

Limitations Lowpass Bessel filt ers have a monoton ica lly decreasing magnitude response,as do lowpass But t erwor th filt ers. Compared to the But terwor th , Chebyshev,and ellipt ic filt er s, t he Bessel filter has the slowest rolloff and requires theh ighest order to meet an a t tenua t ion specifica t ion .

For high order filter s, the st a te-space form is the most numer ica lly accura te,followed by the zero-pole-ga in form. The t ransfer funct ion coefficien t form isthe least accura te; numer ica l problems can a r ise for filter orders as low as 15.

Algorithm besself per forms a four -step a lgor ithm:

1 It finds lowpass ana log prototype poles, zeros, and gain using the besselapfunct ion .

2 It conver ts the poles, zeros, and ga in in to sta te-space form.3 It t ransforms the lowpass filter in to a bandpass, h ighpass, or bandstop filterwith desired cu toff frequencies, using a sta t e-space t ransforma t ion .

4 It conver t s the st a te-space filt er back to t ransfer funct ion or zero-pole-ga inform, as requ ired.

See Also besselap Bessel ana log lowpass filter prototype.butter But terwor th ana log and digita l filt er design.cheby1 Chebyshev type I filter design (passband r ipple).cheby2 Chebyshev type II filter design (stopband r ipple).ellip Ellipt ic (Cauer ) filt er design .

Page 329: MATLAB Signal Processing Toolbox user manual

bilinear

6-25

6bilinearPurpose Bilinea r t ransformat ion method of ana log-to-digita l filt er conversion.

Syntax [zd,pd,kd] = bilinear(z,p,k,Fs)[zd,pd,kd] = bilinear(z,p,k,Fs,Fp)[numd,dend] = bilinear(num,den,Fs)[numd,dend] = bilinear(num,den,Fs,Fp)[Ad,Bd,Cd,Dd] = bilinear(A,B,C,D,Fs)[Ad,Bd,Cd,Dd] = bilinear(A,B,C,D,Fs,Fp)

Description The bilinear transform ation is a ma thema t ica l mapping of va r iables. In digit a lfilt er ing, it is a standard method of mapping the s or ana log plane in to the z ordigita l plane. It t ransforms analog filters, designed using classica l filt er designtechn iques, in to their discrete equ iva len ts.

The bilinear t ransformat ion maps the s-plane in to the z-plane by

This t ransformat ion maps the jΩ axis (from Ω = -∞ to +∞) repea tedly a roundthe unit circle (exp(jω), from ω = −π to π) by

bilinear can accept an opt iona l parameter Fp tha t specifies prewarping. Fp, inHer tz, indica t es a “match” frequency, tha t is, a frequency for which thefrequency responses before and after mapping match exact ly. In prewarpedmode, the bilinear t ransformat ion maps the s-plane in to the z-plane with

H z( ) H s( )s 2 f s

z 1–z 1+------------=

=

ω 2tan 1– Ω2 fs--------⎝ ⎠⎛ ⎞=

H z( ) H s( )s

2π f p

πfpf s----⎝ ⎠

⎛ ⎞t an------------------------ z 1–( )

z 1+( )-----------------=

=

Page 330: MATLAB Signal Processing Toolbox user manual

bilinear

6-26

With the prewarping opt ion , bilinear maps the jΩ axis (from Ω = -∞ t o +∞)repea tedly around the unit circle (exp(jω), from ω = −π to π) by

In prewarped mode, bilinear matches the frequency 2πfp (in radians persecond) in the s-plane to the normalized frequency 2πfp/fs (in radians persecond) in the z-plane.

The bilinear funct ion works with three differen t linear systemrepresen ta t ions: zero-pole-ga in , t r ansfer funct ion , and sta te-space form.

Zero-Pole-Gain

[zd,pd,kd] = bilinear(z,p,k,Fs) and

[zd,pd,kd] = bilinear(z,p,k,Fs,Fp) conver t the s-domain t ransferfunct ion specified by z, p, and k t o a discrete equiva len t . Input s z and p arecolumn vectors con ta in ing the zeros and poles, and k is a sca la r ga in . Fs is thesampling frequency in Her t z. bilinear retu rns the discrete equiva len t incolumn vectors zd and pd and sca la r kd. Fp is the opt iona l match frequency, inHer t z, for prewarping.

Transfer Function

[numd,dend] = bilinear(num,den,Fs) and

[numd,dend] = bilinear(num,den,Fs,Fp) conver t an s-doma in t ransferfunct ion given by num and den t o a discrete equiva lent . Row vectors num and denspecify the coefficien ts of the numera tor and denomina tor , respect ively, indescending powers of s

ω 2tan 1–Ω π

fpf s----⎝ ⎠

⎛ ⎞t an

2πfp-----------------------------

⎝ ⎠⎜ ⎟⎜ ⎟⎜ ⎟⎛ ⎞

=

n um s( )d en s( )-------------------- n um 1( )sn n L n um n n( )s n um n n 1+( )+ + +

d en 1( )sn d L d en n d( )s d en n d 1+( )+ + +-------------------------------------------------------------------------------------------------------------------=

Page 331: MATLAB Signal Processing Toolbox user manual

bilinear

6-27

Fs is the sampling frequency in Her tz. bilinear retu rns the discreteequiva len t in row vectors numd and dend in descending powers of z (ascendingpowers of z -1). Fp is the opt iona l match frequency, in Her tz, for prewarping.

State-Space

[Ad,Bd,Cd,Dd] = bilinear(A,B,C,D,Fs) and

[Ad,Bd,Cd,Dd] = bilinear(A,B,C,D,Fs,Fp) conver t the cont inuous-t imesta t e-space system in mat r ices A, B, C, D,

to the discrete-t ime system

Fs is the sampling frequency in Her tz. bilinear retu rns the discreteequiva len t in matr ices Ad, Bd, Cd, Dd. Fp is the opt iona l match frequency, inHer tz, for prewarping.

Algorithm bilinear uses one of two a lgor ithms, depending on the format of the inpu tlinear syst em you supply. One a lgor ithm works on the zero-pole-ga in formatand the other on the sta te-space format . For t ransfer funct ion represen ta t ions,bilinear conver ts to sta t e-space form, per forms the t ransformat ion , andconver ts the resu lt ing st a te-space syst em back to t ransfer funct ion form.

Zero-Pole-Gain AlgorithmFor a system in zero-pole-ga in form, bilinear per forms four steps:

1 If Fp is presen t , k = 2*pi*Fp/tan(pi*Fp/Fs); otherwise k = 2*Fs.2 It st r ips any zeros a t plus or minus infin ity using

z = z(find(finite(z)));

x· Ax B u+=y Cx Du+=

x n 1+[ ] Ad x n[ ] B du n[ ]+=

y n[ ] Cdx n[ ] Ddu n[ ]+=

Page 332: MATLAB Signal Processing Toolbox user manual

bilinear

6-28

3 It t ransforms the zeros, poles, and gain using pd = (1+p/k)./(1–p/k); zd = (1+z/k)./(1–z/k); kd = real(k*prod(fs–z)./prod(fs–p));

4 It adds ext ra zeros a t -1 so the result ing system has equiva len t numera torand denomina tor order .

State-Space AlgorithmFor a system in sta te-space form, bilinear performs two steps:

1 If Fp is present , k = 2*pi*Fp/tan(pi*Fp/Fs); else k = 2*Fs.2 It computes Ad, Bd, Cd, and Dd in t erms of A, B, C, and D using

bilinear implements these rela t ions using convent iona l MATLABsta t ements. The sca lar r is a rbit ra ry; bilinear uses sqrt(2/k) to ensure goodquant iza t ion noise proper t ies in the resu lt ing system.

Diagnostics bilinear requires tha t the numera tor order be no grea ter than thedenomina tor order . If th is is not the case, bilinear displays:

Numerator cannot be higher order than denominator.

For bilinear t o dist ingu ish between the zero-pole-ga in and t ransfer funct ionlinear syst em format s, the fir st two input parameters must be vectors with thesame or ien ta t ion in these cases. If th is is not the case, bilinear displays:

First two arguments must have the same orientation.

Ad I 1k---⎝ ⎠⎛ ⎞A+⎝ ⎠

⎛ ⎞ I 1k---⎝ ⎠⎛ ⎞A–⎝ ⎠

⎛ ⎞1–

=

Bd2kr------- I

1k---⎝ ⎠⎛ ⎞A–⎝ ⎠

⎛ ⎞1–B=

Cd rC I 1k---⎝ ⎠⎛ ⎞A–⎝ ⎠

⎛ ⎞1–

=

Dd1k---⎝ ⎠⎛ ⎞C I 1

k---⎝ ⎠⎛ ⎞A–⎝ ⎠

⎛ ⎞1–B D+=

Page 333: MATLAB Signal Processing Toolbox user manual

bilinear

6-29

See Also

References [1] Parks, T.W., and C.S. Burrus. Digital Filter Design . New York: J ohn Wiley& Sons, 1987. Pgs. 209-213.

[2] Oppenheim, A.V., and R.W. Schafer . Discrete-T im e S ignal Processing.Englewood Cliffs, NJ : Prent ice-Hall, 1989. Pgs. 415-430.

impinvar Impulse inva r iance method of ana log-to-digita l filterconversion .

lp2bp Lowpass to bandpass ana log filter t ransformat ion .lp2bs Lowpass to bandstop analog filt er t ransformat ion .lp2hp Lowpass to h ighpass ana log filt er t ransformat ion .lp2lp Lowpass to lowpass ana log filt er t ransformat ion .

Page 334: MATLAB Signal Processing Toolbox user manual

blackman

6-30

6blackmanPurpose Blackman window.

Syntax w = blackman(n)w = blackman(n,sflag)

Description w = blackman(n) retu rns the n-poin t symmetr ica lly sampled Blackmanwindow in the column vector w. n should be a nonnega t ive in teger . Theequat ion for a Blackman window is

Blackman windows have sligh t ly wider cent ra l lobes and less sideband leakagethan equiva len t length Hamming and Hanning windows.

w = blackman(n,sflag) retu rns an n-poin t Blackman window using thewindow sampling specified by sflag, which can be either 'periodic' or'symmetric' (the defau lt ). When 'periodic' is specified, blackman computesa length n+1 window and returns the fir st n poin ts.

Algorithm w = (0.42 – 0.5*cos(2*pi*(0:N–1)/(N–1)) + ...0.08*cos(4*pi*(0:N–1)/(N–1)))';

Diagnostics An error message is displayed when incor rect a rgument s are used:

Order cannot be less than zero.Sampling must be either 'symmetric' or 'periodic'.

A warning message is displayed for noninteger n:

Warning: Rounding order to nearest integer.

w k[ ] 0.42 0.5 2πk 1–n 1–-------------⎝ ⎠

⎛ ⎞cos– 0.08 4πk 1–n 1–-------------⎝ ⎠

⎛ ⎞cos+ k 1= … n, , ,=

Page 335: MATLAB Signal Processing Toolbox user manual

blackman

6-31

See Also

References [1] Oppenheim, A.V., and R.W. Schafer . Discrete-T im e S ignal Processing.Englewood Cliffs, NJ : Prent ice-Hall, 1989.

bartlett Bar t let t window.boxcar Rectangula r window.chebwin Chebyshev window.hamming Hamming window.hanning Hanning window.kaiser Kaiser window.triang Tr iangular window.

Page 336: MATLAB Signal Processing Toolbox user manual

boxcar

6-32

6boxcarPurpose Rectangula r window.

Syntax w = boxcar(n)

Description w = boxcar(n) retu rns a rect angular window of length n in the column vectorw. This funct ion is provided for complet eness; a rectangula r window isequiva len t to no window at a ll.

Algorithm w = ones(n,1);

See Also

References [1] Oppenheim, A.V., and R.W. Schafer . Discrete-T im e S ignal Processing.Englewood Cliffs, NJ : Prent ice-Hall, 1989.

bartlett Bar t let t window.blackman Blackman window.chebwin Chebyshev window.hamming Hamming window.hanning Hanning window.kaiser Kaiser window.triang Tr iangular window.

Page 337: MATLAB Signal Processing Toolbox user manual

buffer

6-33

6bufferPurpose Buffer a signa l vector in to a matr ix of da ta frames.

Syntax y = buffer(x,n)y = buffer(x,n,p)y = buffer(x,n,p,opt)[y,z] = buffer(...)[y,z,opt] = buffer(...)

Description y = buffer(x,n) par t it ions a length-L signa l vector x in to nonover lappingdata segments (frames) of length n. Each da ta frame occupies one column ofmat r ix output y, which has n rows and ceil(L/n) columns. If L is not even lydivisible by n, the last column is zero-padded to length n.

y = buffer(x,n,p) over laps or under laps successive frames in the ou tpu tmat r ix by p samples:

• For 0<p<n (over lap), buffer repea ts the fina l p samples of each frame a t thebeginn ing of the following frame. For example, if x=1:30 and n=7, an over lapof p=3 looks like th is:

The fir st frame star t s with p zeros (the defau lt in it ia l condit ion), and thenumber of columns in y is ceil(L/(n–p)).

y = 0 2 6 10 14 18 22 26 0 3 7 11 15 19 23 27 0 4 8 12 16 20 24 28 1 5 9 13 17 21 25 29 2 6 10 14 18 22 26 30 3 7 11 15 19 23 27 0 4 8 12 16 20 24 28 0

Page 338: MATLAB Signal Processing Toolbox user manual

buffer

6-34

• For p<0 (under lap), buffer skips p samples between consecut ive frames. Forexample, if x=1:30 and n=7, a buffer with underlap of p=–3 looks like th is:

The number of columns in y is ceil(L/(n–p)).

y = buffer(x,n,p,opt) specifies a vector of samples to precede x(1) in anover lapping buffer , or the number of in it ia l samples to skip in an under lappingbuffer :

• For 0<p<n (over lap), opt specifies a length-p vector to inser t before x(1) inthe buffer . Th is vector can be considered an in itial condition , which is neededwhen the cur rent buffer ing opera t ion is one in a sequence of consecu t ivebuffer ing opera t ions. To main ta in the desired frame over lap from one bufferto the next , opt should conta in the fina l p samples of the previous buffer inthe sequence. See “Cont inuous Buffer ing” below.

• By defau lt , opt is zeros(p,1) for an over lapping buffer . Set opt t o'nodelay' to skip the in it ia l condit ion and begin filling the bufferimmedia tely with x(1). In this case, L must be length(p) or longer . Forexample, if x=1:30 and n=7, a buffer with over lap of p=3 looks like th is:

• For p<0 (under lap), opt is an int eger va lue in the range [0,–p] specifying thenumber of in it ia l inpu t samples, x(1:opt), to skip before adding samples to

y = 1 11 21 2 12 22 3 13 23 4 14 24 5 15 25 6 16 26 7 17 27

8 18 289 19 2910 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

Page 339: MATLAB Signal Processing Toolbox user manual

buffer

6-35

the buffer . The first va lue in the buffer is therefore x(opt+1). By default , optis zero for an under lapping buffer .Th is opt ion is especia lly usefu l when the curren t buffer ing opera t ion is onein a sequence of consecu t ive buffer ing opera t ions. To main ta in the desiredframe under lap from one buffer to the next , opt should equa l the differencebetween the tota l number of poin t s to skip between frames (p) and thenumber of point s tha t were available t o be skipped in the previous inpu t tobuffer. If the previous inpu t had fewer than p poin ts tha t could be skippeda ft er filling the fina l frame of tha t buffer , the remain ing opt poin t s need tobe removed from the fir st frame of the cur ren t buffer . See “Cont inuousBuffer ing” below for an example of how th is works in pract ice.

[y,z] = buffer(...) pa r t it ions the length-L signa l vector x in to frames oflength n, and outpu ts on ly the fu ll frames in y. If y is an over lapping buffer , ithas n rows and m columns, where

m = floor(L/(n–p)) % when length(opt) = p

or

m = floor((L–n)/(n–p))+1 % when opt = 'nodelay'

If y is an under lapping buffer , it has n rows and m columns, where

m = floor((L–opt)/(n–p)) + (rem((L–opt),(n–p)) >= n)

If the number of samples in the input vector (aft er the appropria te over lappingor under lapping opera t ions) exceeds the number of places ava ilable in then-by-m buffer , t he rema in ing samples in x are outpu t in vector z, which for anover lapping buffer has length

length(z) = L – m*(n–p) % when length(opt) = p

or

length(z) = L – ((m–1)*(n–p)+n) % when opt = 'nodelay'

and for an under lapping buffer has length

length(z) = (L–opt) – m*(n–p)

Page 340: MATLAB Signal Processing Toolbox user manual

buffer

6-36

Outpu t z sha res the same or ien ta t ion (row or column) as x. If there are noremain ing samples in the input a ft er the buffer with the specified over lap orunder lap is filled, z is an empty vector .

[y,z,opt] = buffer(...) retu rns the last p samples of a over lapping bufferin ou tput opt. In an under lapping buffer , opt is the difference between the tot a lnumber of poin ts to skip between frames (–p) and the number of poin ts in x tha twere available to be skipped a ft er filling the la st frame:

• For 0<p<n (over lap), opt (as an outpu t ) conta ins the fina l p samples in thelast frame of the buffer . Th is vector can be used as the in itial condition for asubsequen t buffer ing opera t ion in a sequence of consecut ive buffer ingopera t ions. This a llows the desired frame over lap to be main ta ined from onebuffer to the next . See “Cont inuous Buffer ing” below.

• For p<0 (under lap), opt (a s an ou tpu t ) is the difference between the tota lnumber of poin ts to skip between frames (–p) and the number of poin ts in xtha t were available t o be skipped after filling the last frame.opt = m*(n–p) + opt – L % for z = empty vector

where opt on the r igh t -hand side is the inpu t argument to buffer, and opton the left -hand side is the outpu t argument . Here m is the number ofcolumns in the buffer , which ism = floor((L–opt)/(n–p)) + (rem((L–opt),(n–p)) >= n)

Note tha t for an under lapping buffer ou tpu t opt is a lways zero when outpu tz conta ins da ta .The opt outpu t for an under lapping buffer is especia lly usefu l when thecur ren t buffer ing opera t ion is one in a sequence of consecut ive buffer ingopera t ions. The opt outpu t from each buffer ing opera t ion specifies thenumber of samples tha t need to be skipped a t the sta r t of the next buffer ingopera t ion to main ta in the desired frame under lap from one buffer to thenext . If fewer than p poin ts were ava ilable to be skipped after filling the fina lframe of the cur rent buffer , the rema in ing opt poin ts need to be removedfrom the fir st frame of the next buffer .

In a sequence of buffer ing opera t ions, the opt outpu t from each opera t ionshould be used as the opt inpu t to the subsequent buffer ing opera t ion . Thisensures tha t the desired frame over lap or under lap is main ta ined from buffer

Page 341: MATLAB Signal Processing Toolbox user manual

buffer

6-37

to buffer , as well as from frame to frame with in the same buffer . See“Cont inuous Buffer ing” below for an example of how th is works in pract ice.

Continuous BufferingIn a cont inuous buffer ing opera t ion, the vector inpu t to the buffer funct ionrepresen t s one frame in a sequence of frames tha t make up a discret e signa l.These signa l frames can or igina te in a frame-based data acquisit ion process, orwith in a frame-based a lgor ithm like the FFT.

As an example, you might acquire da ta from an A/D ca rd in frames of 64samples. In the simplest case, you could rebuffer the da ta into frames of 16samples; buffer with n=16 crea t es a buffer of four frames from each64-element inpu t frame. The resu lt is tha t the signa l of frame size 64 has beenconver ted to a signa l of frame size 16; no samples were added or removed.

In the genera l case where the or igina l signa l frame size, L, is not equallydivisible by the new frame size, n, t he over flow from the last frame needs to becaptured and recycled into the following buffer . You can do th is by itera t ivelyca lling buffer on inpu t x with the two-outpu t -a rgument syn tax:

[y,z] = buffer([z;x],n) % for column vector x

[y,z] = buffer([z,x],n) % for row vector x

This simply captures any buffer over flow in z, and prepends the da ta to thesubsequent input in the next ca ll to buffer. Aga in , the inpu t signa l, x, of framesize L, has been conver ted to a signa l of frame size n without any inser t ion ordelet ion of samples.

Note tha t cont inuous buffer ing cannot be done with the single-ou tpu t syn taxy = buffer(...), because the last frame of y in th is case is zero padded, whichadds new samples to the signa l.

Cont inuous buffer ing in the presence of over lap and under lap is handled withthe opt pa rameter , which is used as both an input and outpu t to buffer. Thefollowing two examples demonst ra te how the opt parameter should be used.

Examples Example 1: Continuous Overlapping BuffersFirst crea te a buffer conta in ing 100 frames, each with 11 samples.

data = buffer(1:1100,11); % 11 samples per frame

Page 342: MATLAB Signal Processing Toolbox user manual

buffer

6-38

Imagine tha t the frames (columns) in the mat r ix ca lled data are the sequen t ia lou tputs of a da ta acquisit ion board sampling a physica l signa l: data(:,1) isthe fir st D/A outpu t , conta in ing the fir st 11 signa l samples; data(:,2) is thesecond output , con ta in ing the next 11 signa l samples, and so on .

You want to rebuffer th is signa l from the acquired frame size of 11 to a framesize of 4 with an over lap of 1. To do th is, you will repea tedly ca ll buffer toopera te on each successive inpu t frame, using the opt parameter to ma in ta inconsistency in the over lap from one buffer to the next .

Set the buffer pa rameters.

n = 4; % new frame sizep = 1; % overlapopt = –5; % value of y(1)z = []; % initialize the carry-over vector

Now repea tedly ca ll buffer, each t ime passing in a new signa l frame fromdata. Note tha t over flow samples (retu rned in z) a re ca r r ied over andprepended to the input in the subsequent ca ll to buffer.

for i=1:size(data,2), % Loop over each source frame (column) x = data(:,i); % A single frame of the D/A output

[y,z,opt] = buffer([z;x],n,p,opt);

disp(y); % Do something with the buffer of datapause

end

Page 343: MATLAB Signal Processing Toolbox user manual

buffer

6-39

Here’s what happens dur ing the fir st four it era t ions.

Note tha t the size of the outpu t ma tr ix, y, can va ry by a single column from oneit era t ion to the next . This is typica l for buffer ing opera t ions with over lap orunder lap.

Example 2: Continuous Underlapping BuffersAgain crea t e a buffer con ta in ing 100 frames, each with 11 samples.

data = buffer(1:1100,11); % 11 samples per frame

Again , imagine tha t data(:,1) is the fir st D/A outpu t , conta in ing the fir st 11signa l samples; data(:,2) is the second outpu t , conta in ing the next 11 signa lsamples, and so on .

You want to rebuffer th is signa l from the acquired frame size of 11 to a framesize of 4 with an under lap of 2. To do th is, you will repea tedly ca ll buffer toopera t e on each successive inpu t frame, using the opt pa rameter to main ta inconsistency in the under lap from one buffer to the next .

[1:11]i=1

5– 3 61 4 72 5 83 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 1810 13 16 1911 14 17 2012 15 18 21

[22]

i=3 [22 23:33] 21 33

21 24 27 3022 25 28 3123 26 29 3224 27 30 33

[]

33 36 3934 37 4035 38 4136 39 42

[43 44]42[34:44]i=4 33

Page 344: MATLAB Signal Processing Toolbox user manual

buffer

6-40

Set the buffer pa rameters:

n = 4; % new frame sizep = –2; % underlapopt = 1; % skip the first input element, x(1)z = []; % initialize the carry-over vector

Now repea tedly ca ll buffer, each t ime passing in a new signa l frame fromdata. Note tha t over flow samples (retu rned in z) a re ca r r ied over andprepended to the input in the subsequent ca ll to buffer.

for i=1:size(data,2), % Loop over each source frame (column) x = data(:,i); % A single frame of the D/A output

[y,z,opt] = buffer([z;x],n,p,opt);

disp(y); % Do something with the buffer of datapause

end

Page 345: MATLAB Signal Processing Toolbox user manual

buffer

6-41

Here’s what happens dur ing the fir st th ree itera t ions.

Diagnostics Error messages are displayed when p≥n or length(opt)≠length(p) in anover lapping buffer case:

Frame overlap P must be less than the buffer size N.Initial conditions must be specified as a length-P vector.

See Also

[1:11]i=1

2 83 94 105 11

Iteration Input frame [z;x]' opt (input) opt (output) Output buffer (y) Overflow (z)

[]1 2

i=2 [12:22] 2 0

14151617

[20 21 22]

i=3 [20 21 22 23:33] 0 0

20 2621 2722 2823 29

[32 33]

6 –7 –

1 –

1819

1213

– –

24 3025 31

skip

skip

skip

skip

skip

skip

reshape Reshape a r ray.

Page 346: MATLAB Signal Processing Toolbox user manual

buttap

6-42

6bu t tapPurpose But terwor th analog lowpass filter prototype.

Syntax [z,p,k] = buttap(n)

Description [z,p,k] = buttap(n) retu rns the zeros, poles, and gain of an order nBut terwor th analog lowpass filter prototype. It r etu rns the poles in the lengthn column vector p and the gain in sca la r k. z is an empty mat r ix, because thereare no zeros. The t ransfer funct ion is

But terwor th filters a re cha racter ized by a magnitude response tha t ismaximally fla t in the passband and monotonic overa ll. In the lowpass case, thefir st 2n–1 der iva t ives of the squared magnitude response a re zero a t ω = 0. Thesquared magnitude response funct ion is

cor responding to a t ransfer funct ion with poles equa lly spaced around a circlein the left ha lf plane. The magnitude response a t the cutoff frequency ω0 isa lways 1/sqrt(2), r egardless of the filter order . buttap sets ω0 to 1 for anormalized resu lt .

Algorithm z = [];p = exp(sqrt(–1)*(pi*(1:2:2*n–1)/(2*n)+pi/2)).';k = real(prod(–p));

See Also

References [1] Parks, T.W., and C.S. Burrus. Digital Filter Design . New York: J ohn Wiley& Sons, 1987. Chapter 7.

H s( ) z s( )p s( )---------- k

s p 1( )–( ) s p 2( )–( )Ls p n( )–( )-----------------------------------------------------------------------------= =

H ω( ) 2 11 ω ω0⁄( )2n+------------------------------------=

besselap Bessel ana log lowpass filter prototype.butter But terwor th ana log and digita l filt er design.cheb1ap Chebyshev type I ana log lowpass filt er prototype.cheb2ap Chebyshev type II ana log lowpass filt er prototype.ellipap Ellipt ic ana log lowpass filt er prototype.

Page 347: MATLAB Signal Processing Toolbox user manual

butter

6-43

6but terPurpose But t erwor th ana log and digita l filt er design .

Syntax [b,a] = butter(n,Wn)[b,a] = butter(n,Wn,'ftype')[b,a] = butter(n,Wn,'s')[b,a] = butter(n,Wn,'ftype','s')[z,p,k] = butter(...)[A,B,C,D] = butter(...)

Description butter designs lowpass, bandpass, h ighpass, and bandstop digita l and ana logBut t erwor th filt er s. But terwor th filt er s are charact er ized by a magnituderesponse tha t is maxima lly fla t in the passband and monotonic overa ll.

But t erwor th filt er s sacr ifice rolloff st eepness for monoton icity in the pass- andstopbands. Unless the smoothness of the But terwor th filter is needed, anellipt ic or Chebyshev filt er can genera lly provide st eeper rolloff cha racter ist icswith a lower filter order .

Digital Domain

[b,a] = butter(n,Wn) designs an order n lowpass digita l But terwor th filterwith cu toff frequency Wn. It r etu rns the filter coefficien ts in length n + 1 rowvectors b and a, with coefficien t s in descending powers of z:

Cutoff frequency is tha t frequency where the magnitude response of the filt eris sqrt(1/2). For butter, t he cutoff frequency Wnmust be a number between 0and 1, where 1 cor responds to ha lf the sampling frequency (the Nyquistfrequency).

If Wn is a two-element vector , Wn = [w1 w2], butter retu rns an order 2*n digita lbandpass filter with passband w1 < < w2.

[b,a] = butter(n,Wn,'ftype') designs a h ighpass or bandstop filt er , whereftype is

H z( ) B z( )A z( )----------- b 1( ) b 2( )z 1– L b n 1+( )z n–+ + +

1 a 2( )z 1– L a n 1+( )z n–+ + +---------------------------------------------------------------------------------= =

ω

Page 348: MATLAB Signal Processing Toolbox user manual

butter

6-44

• high for a h ighpass digit a l filter with cu toff frequency Wn• stop for an order 2*n bandstop digita l filter if Wn is a two-element vector ,Wn = [w1 w2]

The stopband is w1 < ω < w2.With differen t numbers of ou tput argument s, butter direct ly obta ins otherrea liza t ions of the filter . To obta in zero-pole-ga in form, use three outpu ta rguments:

[z,p,k] = butter(n,Wn) or

[z,p,k] = butter(n,Wn,'ftype')

butter retu rns the zeros and poles in length n column vectors z and p, and thega in in the sca la r k.

To obta in sta te-space form, use four ou tpu t arguments:

[A,B,C,D] = butter(n,Wn) or

[A,B,C,D] = butter(n,Wn,'ftype') where A, B, C, and D are

and u is the inpu t , x is the st a te vector , and y is the ou tpu t .

Analog Domain

[b,a] = butter(n,Wn,'s') designs an order n lowpass ana log But t erwor thfilt er with cu toff frequency Wn. It r eturns the filt er coefficien t s in the lengthn + 1 row vectors b and a, in descending powers of s:

butter’s cu toff frequency Wn must be grea ter than 0.

If Wn is a two-element vector with w1 < w2, butter(n,Wn,'s') retu rns an order2*n bandpass ana log filter with passband w1 < ω < w2.

x n 1+[ ] Ax n[ ] B u n[ ]+=y n[ ] Cx n[ ] Du n[ ]+=

H s( ) B s( )A s( )----------- b 1( )sn b 2( )sn 1– L b n 1+( )+ + +

sn a 2( )sn 1– L a n 1+( )+ + +----------------------------------------------------------------------------------= =

Page 349: MATLAB Signal Processing Toolbox user manual

butter

6-45

[b,a] = butter(n,Wn,'ftype','s') designs a h ighpass or bandstop filter ,where ftype is

• high for a h ighpass ana log filter with cu toff frequency Wn• stop for an order 2*n bandstop analog filter if Wn is a two-element vector ,Wn = [w1 w2]

The stopband is w1 < ω < w2.With differen t numbers of ou tpu t argument s, butter direct ly obta ins otherrea liza t ions of the ana log filter . To obta in zero-pole-ga in form, use three outpu ta rgument s:

[z,p,k] = butter(n,Wn,'s') or

[z,p,k] = butter(n,Wn,'ftype','s') retu rns the zeros and poles in lengthn or 2*n column vectors z and p and the gain in the sca la r k.

To obta in sta te-space form, use four ou tpu t a rguments:

[A,B,C,D] = butter(n,Wn,'s') or

[A,B,C,D] = butter(n,Wn,'ftype','s') where A, B, C, and D are

and u is the input , x is the st a te vector , and y is the output .

Examples For da ta sampled a t 1000 Hz, design a 9th-order h ighpass But terwor th filterwith cutoff frequency of 300 Hz:

[b,a] = butter(9,300/500,'high');

x· Ax B u+=y Cx Du+=

Page 350: MATLAB Signal Processing Toolbox user manual

butter

6-46

The filt er ’s frequency response is

freqz(b,a,128,1000)

Design a 10th-order bandpass But terwor th filt er with a passband from 100 to200 Hz and plot it s impulse response, or unit sam ple response:

n = 5; Wn = [100 200]/500;[b,a] = butter(n,Wn);[y,t] = impz(b,a,101);stem(t,y)

0 100 200 300 400 500−800

−600

−400

−200

0

200

Frequency (Hz)

Phas

e (d

egre

es)

0 100 200 300 400 500−400

−300

−200

−100

0

100

Frequency (Hz)

Mag

nitu

de (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

Page 351: MATLAB Signal Processing Toolbox user manual

butter

6-47

Limitations For h igh order filter s, the st a te-space form is the most numer ica lly accura t e,followed by the zero-pole-ga in form. The t ransfer funct ion coefficien t form isthe least accura te; numer ica l problems can a r ise for filter orders as low as 15.

Algorithm butter uses a five-step a lgor ithm:

1 It finds the lowpass ana log prototype poles, zeros, and ga in using the buttapfunct ion .

2 It conver ts the poles, zeros, and ga in in to sta t e-space form.3 It t ransforms the lowpass filter in to a bandpass, h ighpass, or bandstop filterwith desired cu toff frequencies, using a sta t e-space t ransformat ion .

4 For digita l filter design , butter uses bilinear to conver t the analog filterinto a digit a l filt er through a bilinea r t ransforma t ion with frequencyprewarping. Carefu l frequency adjustment gua ran tees tha t the ana logfilter s and the digita l filter s will have the same frequency responsemagnitude a t Wn or w1 and w2.

5 It conver ts the sta te-space filter back to t ransfer funct ion or zero-pole-ga inform, as requ ired.

See Also besself Bessel ana log filter design .buttap But terwor th analog lowpass filter prototype.buttord But terwor th filt er order select ion .cheby1 Chebyshev type I filter design (passband r ipple).cheby2 Chebyshev type II filter design (stopband r ipple).ellip Ellipt ic (Cauer ) filt er design.maxflat Genera lized digita l But terwor th filt er design .

Page 352: MATLAB Signal Processing Toolbox user manual

buttord

6-48

6bu t tordPurpose But terwor th filt er order select ion .

Syntax [n,Wn] = buttord(Wp,Ws,Rp,Rs)[n,Wn] = buttord(Wp,Ws,Rp,Rs,'s')

Description buttord selects the minimum order digita l or ana log But terwor th filterrequired to meet a set of filt er design specifica t ions:

Digital Domain

[n,Wn] = buttord(Wp,Ws,Rp,Rs) retu rns the order n of the lowest orderdigit a l But terwor th filter tha t loses no more than Rp dB in the passband andhas a t lea st Rs dB of a t tenua t ion in the stopband. The passband runs from 0 toWp and the stopband runs from Ws to 1, the Nyquist frequency. buttord alsoreturns Wn, the But terwor th cutoff frequency tha t a llows butter to ach ieve thegiven specifica t ions (the “-3 dB” frequency).

Use buttord for h ighpass, bandpass, and bandstop filter s. For h ighpass filters,Wp is grea ter than Ws. For bandpass and bandstop filters, Wp and Ws a retwo-element vectors tha t specify the corner frequencies a t both edges of thefilt er , lower frequency edge fir st . For the band filters, buttord retu rns Wn as atwo-element row vector for inpu t to butter.

If filter specifica t ions ca ll for a bandpass or bandstop filter with unequal r ipplein each of the passbands or stopbands, design the filt er as separa t e lowpass andhighpass sect ions and cascade the two filter s together .

Wp Passband corner frequency. Wp, the cu toff frequency, has a va luebetween 0 and 1, where 1 cor responds to ha lf the samplingfrequency (the Nyquist frequency).

Ws Stopband corner frequency. Ws is in the same unit s a s Wp; it hasa va lue between 0 and 1, where 1 corresponds to ha lf thesampling frequency (the Nyquist frequency).

Rp Passband ripple, in decibels. This va lue is the maximumpermissible passband loss in decibels. The passband is 0 < w < Wp.

Rs Stopband at tenua t ion , in decibels. Th is va lue is the number ofdecibels the stopband is down from the passband. The stopbandis Ws < w < 1.

Page 353: MATLAB Signal Processing Toolbox user manual

buttord

6-49

Analog Domain

[n,Wn] = buttord(Wp,Ws,Rp,Rs,'s') finds the minimum order n and cutofffrequencies Wn for an ana log filt er . In th is case the frequencies in Wp and Ws arein radians per second and may be grea ter than 1.

Use buttord for h ighpass, bandpass, and bandstop filt ers, as descr ibed under“Digit a l Domain.”

Examples For da ta sampled a t 1000 Hz, design a lowpass filter with less than 3 dB ofa t tenuat ion from 0 to 100 Hz, and a t t enuat ion a t lea st 15 dB from 150 Hz tothe Nyquist frequency. P lot the filter ’s frequency response:

Wp = 100/500; Ws = 150/500;[n,Wn] = buttord(Wp,Ws,3,15)

n = 4

Wn = 0.2042

[b,a] = butter(n,Wn);freqz(b,a,512,1000); title('n=4 Butterworth Lowpass Filter')

0 50 100 150 200 250 300 350 400 450 500-400

-300

-200

-100

0

Frequency (Hertz)

Phas

e (d

egre

es)

0 50 100 150 200 250 300 350 400 450 500-300

-200

-100

0

100

Frequency (Hertz)

Mag

nitu

de R

espo

nse

(dB)

n = 4 Butterworth Lowpass Filter

Page 354: MATLAB Signal Processing Toolbox user manual

buttord

6-50

Next design a bandpass filt er with passband of 100 Hz to 200 Hz, less than3 dB of a t tenua t ion a t the passband corners, and a t tenua t ion down 30 dB by50 Hz out on both sides of the passband:

Wp = [100 200]/500; Ws = [50 250]/500;Rp = 3; Rs = 30;[n,Wn] = buttord(Wp,Ws,Rp,Rs); [b,a] = butter(n,Wn);freqz(b,a,128,1000)

Algorithm buttord’s order predict ion formula is descr ibed in [1]. It opera tes in the ana logdomain for both ana log and digita l cases. For the digita l case, it conver t s thefrequency parameter s to the s-domain before est imat ing the order and na tura lfrequency, then conver t s back to the z-doma in .

buttord in it ia lly develops a lowpass filter prototype by t ransforming thepassband frequencies of the desired filt er to 1 rad/sec (for low- and highpassfilt ers) and to -1 and 1 rad/sec (for bandpass and bandstop filters). It thencomputes the min imum order requ ired for a lowpass filter to meet the stopbandspecifica t ion .

0 50 100 150 200 250 300 350 400 450 500-300

-200

-100

0

100

Frequency (Hertz)

Mag

nitu

de R

espo

nse

(dB)

0 50 100 150 200 250 300 350 400 450 500-1000

-500

0

500

Frequency (Hertz)

Phas

e (d

egre

es)

Page 355: MATLAB Signal Processing Toolbox user manual

buttord

6-51

See Also

References [1] Rabiner , L.R., and B. Gold. Theory and Application of Digital S ignalProcessing. Englewood Cliffs, NJ : Pren t ice-Ha ll, 1975. Pg. 227.

butter But terwor th analog and digita l filt er design .cheb1ord Chebyshev type I filter order select ion.cheb2ord Chebyshev type II filter order select ion .ellipord Ellipt ic filt er order select ion.kaiserord Est imate parameter s for an FIR filter design with

Kaiser window.

Page 356: MATLAB Signal Processing Toolbox user manual

cceps

6-52

6ccepsPurpose Complex cepst ra l ana lysis.

Syntax xhat = cceps(x)[xhat,nd] = cceps(x)[xhat,nd,xhat1] = cceps(x)[...] = cceps(x,n)

Description Cepst ra l ana lysis is a nonlinea r signa l processing technique tha t is appliedmost commonly in speech processing and homomorphic filter ing [1].

xhat = cceps(x) retu rns the complex cepst rum of the (assumed rea l)sequence x. The input is a lt ered, by the applica t ion of a linear phase t erm, tohave no phase discont inuity a t ±π radians. Tha t is, it is circu lar ly sh ifted (a ft erzero padding) by some samples, if necessa ry, to have zero phase a t π radians.

[xhat,nd] = cceps(x) retu rns the number of samples nd of (circu la r ) delayadded to x pr ior to finding the complex cepst rum.

[xhat,nd,xhat1] = cceps(x) retu rns a second complex cepst rum, computedusing an alterna te root ing a lgor ithm, in xhat1. The a lt erna te method([1] p.795) is usefu l for shor t sequences tha t can be rooted and do not have zeroson the unit circle. For these signa ls, xhat1 can provide a ver ifica t ion of xhat.

[...] = cceps(x,n) zero pads x to length n and retu rns the length n complexcepst rum of x.

Algorithm cceps, in it s basic form , is an M-file implementa t ion of a lgor ithm 7.1 in [2]. Alengthy For t ran program reduces to th ree lines of MATLAB code:

h = fft(x);logh = log(abs(h)) + sqrt(–1)*rcunwrap(angle(h));y = real(ifft(logh));

rcunwrap is a specia l version of unwrap tha t subt ract s a st ra igh t line from thephase.

Page 357: MATLAB Signal Processing Toolbox user manual

cceps

6-53

See Also

References [1] Oppenheim, A.V., and R.W. Schafer . Discrete-T im e S ignal Processing.Englewood Cliffs, NJ : Prent ice-Hall, 1989.

[2] IEEE. Program s for Digital S ignal Processing. IEEE Press. New York: J ohnWiley & Sons, 1979.

icceps Inverse complex cepst rum.hilbert Hilber t t ransform.rceps Real cepst rum and minimum phase reconst ruct ion .unwrap Unwrap phase angles.

Page 358: MATLAB Signal Processing Toolbox user manual

cheb1ap

6-54

6cheb1apPurpose Chebyshev type I ana log lowpass filt er prototype.

Syntax [z,p,k] = cheb1ap(n,Rp)

Description [z,p,k] = cheb1ap(n,Rp) retu rns the zeros, poles, and gain of an order nChebyshev type I ana log lowpass filt er prototype with Rp dB of r ipple in thepassband. It retu rns the poles in the length n column vector p and the ga in insca la r k. z is an empty mat r ix, because there are no zeros. The t ransfer funct ionis

Chebyshev type I filter s are equ ir ipple in the passband and monoton ic in thestopband. The poles are evenly spaced about an ellipse in the left ha lf plane.The Chebyshev type I cutoff frequency is set to 1.0 for a norma lized resu lt .Th is is the frequency a t which the passband ends and the filter has magnituderesponse of 10-Rp/20.

See Also

References [1] Parks, T.W., and C.S. Burrus. Digital Filter Design . New York: J ohn Wiley& Sons, 1987. Chapter 7.

H s( ) z s( )p s( )---------- k

s p 1( )–( ) s p 2( )–( )Ls p n( )–( )-----------------------------------------------------------------------------= =

ω0

besselap Bessel ana log lowpass filter prototype.buttap But terwor th ana log and digita l filt er design.cheb2ap Chebyshev type I ana log lowpass filt er prototype.cheby1 Chebyshev type I filter design (passband r ipple).ellipap Ellipt ic ana log lowpass filt er prototype.

Page 359: MATLAB Signal Processing Toolbox user manual

cheb1ord

6-55

6cheb1ordPurpose Chebyshev type I filter order select ion .

Syntax [n,Wn] = cheb1ord(Wp,Ws,Rp,Rs)[n,Wn] = cheb1ord(Wp,Ws,Rp,Rs,'s')

Description cheb1ord selects the min imum order digita l or ana log Chebyshev type I filterrequired to meet a set of filter design specifica t ions:

Digital Domain

[n,Wn] = cheb1ord(Wp,Ws,Rp,Rs) returns the order n of the lowest orderChebyshev filter tha t loses no more than Rp dB in the passband and has a tleast Rs dB of a t tenuat ion in the stopband. The passband runs from 0 to Wp andthe stopband runs from Ws to 1, the Nyquist frequency. cheb1ord a lso returnsWn, t he Chebyshev type I cu toff frequency tha t a llows cheby1 t o ach ieve thegiven specifica t ions.

Use cheb1ord for lowpass, h ighpass, bandpass, and bandstop filt ers. Forh ighpass filt er s, Wp > Ws. For bandpass and bandstop filters, Wp and Ws a retwo-element vectors tha t specify the corner frequencies a t both edges of thefilt er , lower frequency edge fir st . For the band filt ers, cheb1ord retu rns Wn asa two-element row vector for inpu t to cheby1.

If filt er specifica t ions ca ll for a bandpass or bandstop filt er with unequal r ipplein each of the passbands or stopbands, design the filt er a s separa t e lowpass andhighpass sect ions and cascade the two filt ers together .

Wp Passband corner frequency. Wp, the cu toff frequency, has a va luebetween 0 and 1, where 1 corresponds to ha lf the samplingfrequency (the Nyquist frequency).

Ws Stopband corner frequency. Ws is in the same unit s a s Wp; it hasa va lue between 0 and 1, where 1 cor responds to ha lf thesampling frequency (the Nyquist frequency).

Rp Passband ripple, in decibels. This value is the maximumpermissible passband loss in decibels. The passband is 0 < w < Wp.

Rs Stopband at tenua t ion , in decibels. This va lue is the number ofdecibels the stopband is down from the passband. The stopbandis Ws < w < 1.

Page 360: MATLAB Signal Processing Toolbox user manual

cheb1ord

6-56

Analog Domain

[n,Wn] = cheb1ord(Wp,Ws,Rp,Rs,'s') finds the min imum order n and cutofffrequencies Wn for an ana log filt er . In th is case the frequencies in Wp and Ws arein radians per second and may be grea ter than 1.

Use cheb1ord for lowpass, h ighpass, bandpass, and bandstop filt er s, a sdescr ibed under “Digita l Domain .”

Examples For da ta sampled a t 1000 Hz, design a lowpass filter with less than 3 dB ofa t tenuat ion from 0 to 100 Hz and a t t enuat ion a t lea st 15 dB from 150 Hz to theNyquist frequency:

Wp = 100/500; Ws = 150/500;Rp = 3; Rs = 15;[n,Wn] = cheb1ord(Wp,Ws,Rp,Rs)

n = 3

Wn = 0.2000

[b,a] = cheby1(n,Rp,Wn);freqz(b,a,512,1000); title('n=3 Chebyshev Type I Lowpass Filter')

0 50 100 150 200 250 300 350 400 450 500-300

-200

-100

0

Frequency (Hertz)

Phas

e (d

egre

es)

0 50 100 150 200 250 300 350 400 450 500-200

-150

-100

-50

0

50

Frequency (Hertz)

Mag

nitu

de R

espo

nse

(dB)

n = 3 Chebyshev Type I Lowpass Filter

Page 361: MATLAB Signal Processing Toolbox user manual

cheb1ord

6-57

Next design a bandpass filt er with a passband of 100 Hz to 200 Hz, less than3 dB of a t tenua t ion throughout the passband, and 30 dB stopbands 50 Hz outon both sides of the passband:

Wp = [100 200]/500; Ws = [50 250]/500;Rp = 3; Rs = 30;[n,Wn] = cheb1ord(Wp,Ws,Rp,Rs)

n = 4

Wn = 0.2000 0.4000

[b,a] = cheby1(n,Rp,Wn);freqz(b,a,512,1000);title('n=4 Chebyshev Type I Bandpass Filter')

Algorithm cheb1ord uses the Chebyshev lowpass filt er order predict ion formula descr ibedin [1]. The funct ion per forms it s ca lcu la t ions in the ana log domain for bothana log and digit a l cases. For the digit a l ca se, it conver t s the frequencyparameters to the s-doma in before the order and na tura l frequency est imat ionprocess, then conver t s them back to the z-domain .

0 50 100 150 200 250 300 350 400 450 500-800

-600

-400

-200

0

Frequency (Hertz)

Phas

e (d

egre

es)

0 50 100 150 200 250 300 350 400 450 500-300

-200

-100

0

Frequency (Hertz)

Mag

nitu

de R

espo

nse

(dB)

n = 4 Chebyshev Type I Bandpass Filter

Page 362: MATLAB Signal Processing Toolbox user manual

cheb1ord

6-58

cheb1ord in it ia lly develops a lowpass filter prototype by t ransforming thepassband frequencies of the desired filt er to 1 rad/sec (for low- or highpassfilt ers) or to -1 and 1 rad/sec (for bandpass or bandstop filt ers). It t hencomputes the min imum order requ ired for a lowpass filter to meet the stopbandspecifica t ion .

See Also

References [1] Rabiner , L.R., and B. Gold. Theory and Application of Digital S ignalProcessing. Englewood Cliffs, NJ : Prent ice-Hall, 1975. Pg. 241.

buttord But terwor th filt er order select ion.cheby1 Chebyshev type I filter design (passband r ipple).cheb2ord Chebyshev type II filter order select ion.ellipord Ellipt ic filt er order select ion .kaiserord Est imate parameters for an FIR filter design with

Kaiser window.

Page 363: MATLAB Signal Processing Toolbox user manual

cheb2ap

6-59

6cheb2apPurpose Chebyshev type II ana log lowpass filter prototype.

Syntax [z,p,k] = cheb2ap(n,Rs)

Description [z,p,k] = cheb2ap(n,Rs) finds the zeros, poles, and ga in of an order nChebyshev type II ana log lowpass filter prototype with stopband r ipple Rs dBdown from the passband peak value. cheb2ap retu rns the zeros and poles inlength n column vectors z and p and the ga in in sca la r k. If n is odd, z is lengthn–1. The t ransfer funct ion is

Chebyshev type II filt er s a re monoton ic in the passband and equir ipple in thestopband. The pole loca t ions are the inverse of the pole loca t ions of cheb1ap,whose poles are evenly spaced about an ellipse in the left ha lf plane. TheChebyshev type II cu toff frequency ω0 is set to 1 for a normalized resu lt . Thisis the frequency a t which the stopband begins and the filt er has magnituderesponse of 10-Rs/20.

Algorithm Chebyshev type II filt er s a re somet imes ca lled inverse Chebyshev filter sbecause of their rela t ionship to Chebyshev type I filt er s. The cheb2ap funct ionis a modifica t ion of the Chebyshev type I prototype a lgor ithm:

1 cheb2ap replaces the frequency va r iable ω with 1/ω, t urn ing the lowpassfilter in to a highpass filter while preserving the per formance a t ω = 1.

2 cheb2ap subt racts the filter t r ansfer funct ion from unity.

See Also

References [1] Parks, T.W., and C.S. Burrus. Digital Filter Design . New York: J ohn Wiley& Sons, 1987. Chapter 7.

H s( ) z s( )p s( )---------- k s z 1( )–( ) s z 2( )–( )Ls z n( )–( )

s p 1( )–( ) s p 2( )–( )Ls p n( )–( )-----------------------------------------------------------------------------= =

besselap Bessel ana log lowpass filter prototype.buttap But terwor th analog lowpass filter prototype.cheb1ap Chebyshev type I ana log lowpass filt er prototype.cheby2 Chebyshev type II filter design (stopband r ipple).ellipap Ellipt ic ana log lowpass filt er prototype.

Page 364: MATLAB Signal Processing Toolbox user manual

cheb2ord

6-60

6cheb2ordPurpose Chebyshev type II filter order select ion .

Syntax [n,Wn] = cheb2ord(Wp,Ws,Rp,Rs)[n,Wn] = cheb2ord(Wp,Ws,Rp,Rs,'s')

Description cheb2ord selects the minimum order digit a l or ana log Chebyshev type II filt errequired to meet a set of filt er design specifica t ions:

Digital Domain

[n,Wn] = cheb2ord(Wp,Ws,Rp,Rs) retu rns the order n of the lowest orderChebyshev filter tha t loses no more than Rp dB in the passband and has a tleast Rs dB of a t tenuat ion in the stopband. The passband runs from 0 to Wp andthe stopband runs from Ws to 1, the Nyquist frequency. cheb2ord a lso retu rnsWn, the Chebyshev type II cu toff frequency tha t a llows cheby2 t o ach ieve thegiven specifica t ions.

Use cheb2ord for lowpass, h ighpass, bandpass, and bandstop filt er s. Forh ighpass filter s, Wp is grea t er than Ws. For bandpass and bandstop filter s, Wpand Ws are two-element vectors tha t specify the corner frequencies a t bothedges of the filter , lower frequency edge fir st . For the band filter s, cheb2ordretu rns Wn as a two-element row vector for inpu t to cheby2.

If filter specifica t ions ca ll for a bandpass or bandstop filter with unequal r ipplein each of the passbands or stopbands, design the filt er as separa t e lowpass andhighpass sect ions and cascade the two filter s together .

Wp Passband corner frequency. Wp, the cu toff frequency, has a va luebetween 0 and 1, where 1 cor responds to ha lf the samplingfrequency (the Nyquist frequency).

Ws Stopband corner frequency. Ws is in the same unit s a s Wp; it hasa va lue between 0 and 1, where 1 corresponds to ha lf thesampling frequency (the Nyquist frequency).

Rp Passband ripple, in decibels. This va lue is the maximumpermissible passband loss in decibels. The passband is 0 < w < Wp.

Rs Stopband at tenua t ion , in decibels. Th is va lue is the number ofdecibels the stopband is down from the passband. The stopbandis Ws < w < 1.

Page 365: MATLAB Signal Processing Toolbox user manual

cheb2ord

6-61

Analog Domain

[n,Wn] = cheb2ord(Wp,Ws,Rp,Rs,'s') finds the minimum order n and cutofffrequencies Wn for an ana log filt er . In th is case the frequencies in Wp and Ws arein radians per second and may be grea ter than 1.

Use cheb2ord for lowpass, h ighpass, bandpass, and bandstop filt ers, a sdescr ibed under “Digita l Domain .”

Examples For da ta sampled a t 1000 Hz, design a lowpass filter with less than 3 dB ofa t tenuat ion from 0 to 100 Hz, and a t t enuat ion a t lea st 15 dB from 150 Hz tothe Nyquist frequency:

Wp = 100/500; Ws = 150/500;Rp = 3; Rs = 15;[n,Wn] = cheb2ord(Wp,Ws,Rp,Rs)

n = 3

Wn = 0.2609

[b,a] = cheby2(n,Rs,Wn);freqz(b,a,512,1000); title('n=3 Chebyshev Type II Lowpass Filter')

0 50 100 150 200 250 300 350 400 450 500-200

-150

-100

-50

0

Frequency (Hertz)

Phas

e (d

egre

es)

0 50 100 150 200 250 300 350 400 450 500-80

-60

-40

-20

0

20

Frequency (Hertz)

Mag

nitu

de R

espo

nse

(dB)

n = 3 Chebyshev Type II Lowpass Filter

Page 366: MATLAB Signal Processing Toolbox user manual

cheb2ord

6-62

Next design a bandpass filt er with a passband of 100 Hz to 200 Hz, less than3 dB of a t tenua t ion throughout the passband, and 30 dB stopbands 50 Hz outon both sides of the passband:

Wp = [100 200]/500; Ws = [50 250]/500;Rp = 3; Rs = 30;[n,Wn] = cheb2ord(Wp,Ws,Rp,Rs)

n = 4

Wn = 0.1633 0.4665

[b,a] = cheby2(n,Rs,Wn);freqz(b,a,512,1000)title('n=4 Chebyshev Type II Bandpass Filter')

Algorithm cheb2ord uses the Chebyshev lowpass filt er order predict ion formula descr ibedin [1]. The funct ion per forms it s ca lcu la t ions in the ana log domain for bothana log and digita l cases. For the digita l case, it conver ts the frequencyparameters to the s-doma in before the order and na tura l frequency est imat ionprocess, then conver ts them back to the z-domain.

0 50 100 150 200 250 300 350 400 450 500-400

-200

0

200

400

Frequency (Hertz)

Phas

e (d

egre

es)

0 50 100 150 200 250 300 350 400 450 500-80

-60

-40

-20

0

Frequency (Hertz)

Mag

nitu

de R

espo

nse

(dB)

n = 4 Chebyshev Type II Bandpass Filter

Page 367: MATLAB Signal Processing Toolbox user manual

cheb2ord

6-63

cheb2ord in it ia lly develops a lowpass filter prototype by t ransforming thestopband frequencies of the desired filt er to 1 rad/sec (for low- and highpassfilt ers) and to -1 and 1 rad/sec (for bandpass and bandstop filters). It thencomputes the minimum order requ ired for a lowpass filter to meet thepassband specifica t ion.

See Also

References [1] Rabiner , L.R., and B. Gold. Theory and Application of Digital S ignalProcessing. Englewood Cliffs, NJ : Pren t ice-Ha ll, 1975. Pg. 241.

buttord But terwor th filt er order select ion .cheb1ord Chebyshev type I filter order select ion.cheby2 Chebyshev type II filter design (stopband r ipple).ellipord Ellipt ic filt er order select ion.kaiserord Est imate parameter s for an FIR filter design with

Kaiser window.

Page 368: MATLAB Signal Processing Toolbox user manual

chebwin

6-64

6chebwinPurpose Chebyshev window.

Syntax w = chebwin(n,r)

Description w = chebwin(n,r) retu rns the column vector w, con ta in ing the length nChebyshev window whose Four ier t ransform magnitude sidelobe r ipple is r dBbelow the main lobe magnitude.

See Also

References [1] IEEE. Program s for Digital S ignal Processing. IEEE Press. New York: J ohnWiley & Sons, 1979. Program 5.2.

bartlett Bar t let t window.blackman Blackman window.boxcar Rectangula r window.hamming Hamming window.hanning Hanning window.kaiser Kaiser window.triang Tr iangular window.

Page 369: MATLAB Signal Processing Toolbox user manual

cheby1

6-65

6cheby1Purpose Chebyshev type I filter design (passband r ipple).

Syntax [b,a] = cheby1(n,Rp,Wn)[b,a] = cheby1(n,Rp,Wn,'ftype')[b,a] = cheby1(n,Rp,Wn,'s')[b,a] = cheby1(n,Rp,Wn,'ftype','s')[z,p,k] = cheby1(...)[A,B,C,D] = cheby1(...)

Description cheby1 designs lowpass, bandpass, h ighpass, and bandstop digita l and ana logChebyshev type I filter s. Chebyshev type I filt er s are equir ipple in thepassband and monoton ic in the stopband. Type I filt ers roll off faster than typeII filt ers, bu t a t the expense of grea ter devia t ion from unity in the passband.

Digital Domain

[b,a] = cheby1(n,Rp,Wn) designs an order n lowpass digita l Chebyshev filterwith cu toff frequency Wn and Rp dB of r ipple in the passband. It retu rns thefilt er coefficien t s in the length n+1 row vectors b and a, with coefficien ts indescending powers of z:

Cutoff frequency is the frequency a t which the magnitude response of the filt eris equal to –Rp dB. For cheby1, the cu toff frequency Wn is a number between 0and 1, where 1 cor responds to ha lf the sampling frequency (the Nyquistfrequency). Sma ller va lues of passband r ipple Rp lead to wider t ransit ionwidths (sha llower rolloff cha racter ist ics).

If Wn is a two-element vector , Wn = [w1 w2], cheby1 returns an order 2*nbandpass filter with passband w1 < < w2.

[b,a] = cheby1(n,Rp,Wn,'ftype') designs a highpass or bandstop filter ,where ftype is

H z( ) B z( )A z( )----------- b 1( ) b 2( )z 1– L b n 1+( )z n–+ + +

1 a 2( )z 1– L a n 1+( )z n–+ + +---------------------------------------------------------------------------------= =

ω

Page 370: MATLAB Signal Processing Toolbox user manual

cheby1

6-66

• high for a h ighpass digit a l filter with cu toff frequency Wn• stop for an order 2*n bandstop digita l filter if Wn is a two-element vector ,Wn = [w1 w2]

The stopband is w1 < ω < w2.With differen t numbers of ou tput argument s, cheby1 direct ly obta ins otherrea liza t ions of the filter . To obta in zero-pole-ga in form, use three outpu ta rguments:

[z,p,k] = cheby1(n,Rp,Wn) or

[z,p,k] = cheby1(n,Rp,Wn,'ftype') retu rns the zeros and poles in length ncolumn vectors z and p and the ga in in the sca la r k.

To obta in sta te-space form, use four ou tpu t arguments:

[A,B,C,D] = cheby1(n,Rp,Wn) or

[A,B,C,D] = cheby1(n,Rp,Wn,'ftype') where A, B, C, and D are

and u is the inpu t , x is the st a te vector , and y is the ou tpu t .

Analog Domain

[b,a] = cheby1(n,Rp,Wn,'s') designs an order n lowpass analog Chebyshevtype I filter with cutoff frequency Wn. It r eturns the filt er coefficien ts in lengthn + 1 row vectors b and a, in descending powers of s:

Cutoff frequency is the frequency a t which the magnitude response of the filt eris –Rp dB. For cheby1, the cu toff frequency Wn must be grea ter than 0.

If Wn is a two-element vector , Wn = [w1 w2], with w1 < w2, thencheby1(n,Rp,Wn,'s') retu rns an order 2*n bandpass ana log filter withpassband w1 < ω < w2.

x n 1+[ ] Ax n[ ] B u n[ ]+=y n[ ] Cx n[ ] Du n[ ]+=

H s( ) B s( )A s( )----------- b 1( )sn b 2( )sn 1– L b n 1+( )+ + +

sn a 2( )sn 1– L a n 1+( )+ + +----------------------------------------------------------------------------------= =

Page 371: MATLAB Signal Processing Toolbox user manual

cheby1

6-67

[b,a] = cheby1(n,Rp,Wn,'ftype','s') designs a h ighpass or bandstopfilt er , where ftype is

• high for a h ighpass ana log filter with cu toff frequency Wn• stop for an order 2*n bandstop ana log filter if Wn is a two-element vector ,Wn = [w1 w2]

The stopband is w1 < ω < w2.You can supply differen t numbers of ou tpu t a rguments for cheby1 t o direct lyobta in other rea liza t ions of the ana log filt er . To obta in zero-pole-ga in form, usethree ou tpu t argument s:

[z,p,k] = cheby1(n,Rp,Wn,'s') or

[z,p,k] = cheby1(n,Rp,Wn,'ftype','s') retu rns the zeros and poles inlength n or 2*n column vectors z and p and the gain in the sca la r k.

To obta in sta te-space form, use four ou tpu t a rguments:

[A,B,C,D] = cheby1(n,Rp,Wn,'s') or

[A,B,C,D] = cheby1(n,Rp,Wn,'ftype','s') where A, B, C, and D are definedas

and u is the input , x is the st a te vector , and y is the output .

Examples For da ta sampled a t 1000 Hz, design a 9th-order lowpass Chebyshev type Ifilt er with 0.5 dB of r ipple in the passband and a cu toff frequency of 300 Hz:

[b,a] = cheby1(9,0.5,300/500);

x· Ax B u+=y Cx Du+=

Page 372: MATLAB Signal Processing Toolbox user manual

cheby1

6-68

The frequency response of the filt er is

freqz(b,a,512,1000)

Design a 10th-order bandpass Chebyshev type I filt er with a passband from100 to 200 Hz and plot it s impulse response:

n = 10; Rp = 0.5;Wn = [100 200]/500;[b,a] = cheby1(n,Rp,Wn);[y,t] = impz(b,a,101); stem(t,y)

0 50 100 150 200 250 300 350 400 450 500-1000

-800

-600

-400

-200

0

Frequency (Hertz)

Phas

e (d

egre

es)

0 50 100 150 200 250 300 350 400 450 500-300

-200

-100

0

100

Frequency (Hertz)

Mag

nitu

de R

espo

nse

(dB)

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.15Impulse Response of n = 10 Chebyshev Type I Filter

Page 373: MATLAB Signal Processing Toolbox user manual

cheby1

6-69

Limitations For h igh order filter s, the st a te-space form is the most numer ica lly accura t e,followed by the zero-pole-ga in form. The t ransfer funct ion form is the leastaccura t e; numer ica l problems can ar ise for filter orders a s low as 15.

Algorithm cheby1 uses a five-step a lgor ithm:

1 It finds the lowpass ana log prototype poles, zeros, and ga in using thecheb1ap funct ion .

2 It conver ts the poles, zeros, and ga in in to sta t e-space form.3 It t ransforms the lowpass filter in to a bandpass, h ighpass, or bandstop filterwith desired cu toff frequencies, using a sta t e-space t ransformat ion .

4 For digita l filter design , cheby1 uses bilinear to conver t the analog filterinto a digit a l filt er through a bilinea r t ransforma t ion with frequencyprewarping. Carefu l frequency adjustment gua ran tees tha t the ana logfilter s and the digita l filter s will have the same frequency responsemagnitude a t Wn or w1 and w2.

5 It conver ts the sta te-space filter back to t ransfer funct ion or zero-pole-ga inform, as requ ired.

See Also besself Bessel ana log filter design .butter But terwor th analog and digita l filt er design .cheb1ap Chebyshev type I ana log lowpass filt er prototype.cheb1ord Chebyshev type I filter order select ion.cheby2 Chebyshev type II filter design (stopband r ipple).ellip Ellipt ic (Cauer ) filt er design.

Page 374: MATLAB Signal Processing Toolbox user manual

cheby2

6-70

6cheby2Purpose Chebyshev type II filter design (stopband r ipple).

Syntax [b,a] = cheby2(n,Rs,Wn)[b,a] = cheby2(n,Rs,Wn,'ftype')[b,a] = cheby2(n,Rs,Wn,'s')[b,a] = cheby2(n,Rs,Wn,'ftype','s')[z,p,k] = cheby2(...)[A,B,C,D] = cheby2(...)

Description cheby2 designs lowpass, h ighpass, bandpass, and bandstop digit a l and ana logChebyshev type II filter s. Chebyshev type II filt er s are monoton ic in thepassband and equir ipple in the stopband. Type II filt er s do not roll off a s fa stas type I filt ers, but are free of passband r ipple.

Digital Domain

[b,a] = cheby2(n,Rs,Wn) designs an order n lowpass digit a l Chebyshev typeII filt er with cu toff frequency Wn and stopband r ipple Rs dB down from the peakpassband va lue. It retu rns the filter coefficient s in the length n + 1 row vectorsb and a, with coefficien t s in descending powers of z:

Cutoff frequency is the beginn ing of the stopband, where the magnituderesponse of the filt er is equa l to –Rs dB. For cheby2, the cu toff frequency Wn isa number between 0 and 1, where 1 cor responds to ha lf the sampling frequency(the Nyquist frequency). Larger va lues of stopband a t tenua t ion Rs lead towider t ransit ion widths (sha llower rolloff charact er ist ics).

If Wn is a two-element vector , Wn = [w1 w2], cheby2 retu rns an order 2*nbandpass filter with passband w1 < ω < w2.

[b,a] = cheby2(n,Rs,Wn,'ftype') designs a h ighpass or bandstop filter ,where ftype is

H z( ) B z( )A z( )----------- b 1( ) b 2( )z 1– L b n 1+( )z n–+ + +

1 a 2( )z 1– L a n 1+( )z n–+ + +---------------------------------------------------------------------------------= =

Page 375: MATLAB Signal Processing Toolbox user manual

cheby2

6-71

• high for a h ighpass digita l filt er with cu toff frequency Wn• stop for an order 2*n bandstop digit a l filter if Wn is a two-element vector ,Wn = [w1 w2].

The stopband is w1 < ω < w2.With differen t numbers of ou tpu t argument s, cheby2 direct ly obta ins otherrea liza t ions of the filter . To obta in zero-pole-ga in form, use three outputa rgument s:

[z,p,k] = cheby2(n,Rs,Wn) or

[z,p,k] = cheby2(n,Rs,Wn,'ftype') retu rns the zeros and poles in length ncolumn vectors z and p and the ga in in the sca lar k.

To obta in sta te-space form, use four ou tpu t a rguments:

[A,B,C,D] = cheby2(n,Rs,Wn) or

[A,B,C,D] = cheby2(n,Rs,Wn,'ftype') where A, B, C, and D are

and u is the input , x is the st a te vector , and y is the output .

Analog Domain

[b,a] = cheby2(n,Rs,Wn,'s') designs an order n lowpass ana log Chebyshevtype II filter with cutoff frequency Wn. It r etu rns the filter coefficien ts in thelength n + 1 row vectors b and a, with coefficien t s in descending powers of s:

Cutoff frequency is the frequency a t which the magnitude response of the filt eris equa l to –Rs dB. For cheby2, the cu toff frequency Wn must be grea ter than 0.

If Wn is a two-element vector , Wn = [w1 w2], with w1 < w2, thencheby2(n,Rs,Wn,'s') retu rns an order 2*n bandpass ana log filter withpassband w1 < ω < w2.

x n 1+[ ] A x n[ ] B u n[ ]+=y n[ ] Cx n[ ] Du n[ ]+=

H s( ) B s( )A s( )----------- b 1( )sn b 2( )sn 1– L b n 1+( )+ + +

sn a 2( )sn 1– L a n 1+( )+ + +----------------------------------------------------------------------------------= =

Page 376: MATLAB Signal Processing Toolbox user manual

cheby2

6-72

[b,a] = cheby2(n,Rs,Wn,'ftype','s') designs a h ighpass or bandstopfilt er , where ftype is

• high for a h ighpass ana log filter with cu toff frequency Wn• stop for an order 2*n bandstop ana log filter if Wn is a two-element vector ,Wn = [w1 w2]

The stopband is w1 < ω < w2.With differen t numbers of ou tput argument s, cheby2 direct ly obta ins otherrea liza t ions of the ana log filt er . To obta in zero-pole-ga in form, use three outpu ta rguments:

[z,p,k] = cheby2(n,Rs,Wn,'s') or

[z,p,k] = cheby2(n,Rs,Wn,'ftype','s') retu rns the zeros and poles inlength n or 2*n column vectors z and p and the gain in the sca la r k.

To obta in sta te-space form, use four ou tpu t arguments:

[A,B,C,D] = cheby2(n,Rs,Wn,'s') or

[A,B,C,D] = cheby2(n,Rs,Wn,'ftype','s') where A, B, C, and D a re

and u is the inpu t , x is the st a te vector , and y is the ou tpu t .

Examples For da ta sampled a t 1000 Hz, design a n in th-order lowpass Chebyshev type IIfilt er with stopband at tenua t ion 20 dB down from the passband and a cutofffrequency of 300 Hz:

[b,a] = cheby2(9,20,300/500);

x· Ax B u+=y Cx Du+=

Page 377: MATLAB Signal Processing Toolbox user manual

cheby2

6-73

The frequency response of the filt er is

freqz(b,a,512,1000)

Design a fifth -order bandpass Chebyshev type II filter with passband from 100to 200 Hz and plot the impulse response of the filter :

n = 5; r = 20;Wn = [100 200]/500;[b,a] = cheby2(n,r,Wn);[y,t] = impz(b,a,101); stem(t,y)

0 50 100 150 200 250 300 350 400 450 500-400

-300

-200

-100

0

100

Frequency (Hertz)

Phas

e (d

egre

es)

0 50 100 150 200 250 300 350 400 450 500-80

-60

-40

-20

0

20

Frequency (Hertz)

Mag

nitu

de R

espo

nse

(dB)

n = 9 Chebyshev Type II Filter

0 10 20 30 40 50 60 70 80 90 100-0.2

-0.15

-0.1

-0.05

0

0.05

0.1

0.15

0.2Impulse Response of n = 5 Chebyshev Type II Filter

Page 378: MATLAB Signal Processing Toolbox user manual

cheby2

6-74

Limitations For high order filter s, the st a te-space form is the most numer ica lly accura te,followed by the zero-pole-ga in form. The t ransfer funct ion coefficien t form isthe least accura te; numer ica l problems can a r ise for filter orders as low as 15.

Algorithm cheby2 uses a five-step a lgor ithm:

1 It finds the lowpass ana log prototype poles, zeros, and ga in using thecheb2ap funct ion .

2 It conver t s poles, zeros, and ga in in to sta t e-space form.3 It t ransforms the lowpass filter in to a bandpass, h ighpass, or bandstop filterwith desired cu toff frequencies, using a sta t e-space t ransforma t ion .

4 For digita l filt er design , cheby2 uses bilinear to conver t the ana log filterin to a digit a l filter through a bilinea r t ransforma t ion with frequencyprewarping. Carefu l frequency adjustment gua ran tees tha t the ana logfilter s and the digita l filt er s will have the same frequency responsemagnitude a t Wn or w1 and w2.

5 It conver t s the st a te-space filt er back to t ransfer funct ion or zero-pole-ga inform, as requ ired.

See Also besself Bessel ana log filter design .butter But terwor th ana log and digita l filt er design.cheb2ap Chebyshev type II ana log lowpass filt er prototype.cheb2ord Chebyshev type II filter order select ion.cheby1 Chebyshev type I filter design (passband r ipple).ellip Ellipt ic (Cauer ) filt er design .

Page 379: MATLAB Signal Processing Toolbox user manual

chirp

6-75

6ch irpPurpose Swept-frequency cosine genera tor .

Syntax y = chirp(t,f0,t1,f1)y = chirp(t,f0,t1,f1,'method')y = chirp(t,f0,t1,f1,'method',phi)

Description y = chirp(t,f0,t1,f1) genera tes samples of a linear swept -frequency cosinesigna l a t the t ime instances defined in ar ray t, where f0 is the inst an taneousfrequency at t ime 0, and f1 is the inst an taneous frequency a t t ime t1. f0 andf1 a re both in Her t z. If unspecified, f0 is 0, t1 is 1, and f1 is 100.

y = chirp(t,f0,t1,f1,'method') specifies a lterna t ive sweep methodopt ions, where method can be

• linear, which specifies an instantaneous frequency sweep fi(t) given by

•where

• β ensures tha t the desired frequency breakpoin t f1 a t t ime t1 is main ta ined.• quadratic, which specifies an inst an taneous frequency sweep fi(t) given by

•where

• logarithmic specifies an inst an taneous frequency sweep fi(t) given by

where

• For a log-sweep, f1 must be grea ter than f0.

f i t( ) f0 βt+=

β f1 f0–( ) t1⁄=

f i t( ) f0 βt 2+=

β f1 f0–( ) t1⁄=

f i t( ) f0 10β t+=

β log10 f1 f0–( )[ ] t1⁄=

Page 380: MATLAB Signal Processing Toolbox user manual

chirp

6-76

y = chirp(t,f0,t1,f1,'method',phi) a llows an init ia l phase phi to bespecified in degrees. If unspecified, phi is 0. Default va lues are subst itu ted forempty or omit ted t ra iling input a rgument s.

Examples Compute the spect rogram of a ch irp with linear instan taneous frequencydevia t ion :

t = 0:0.001:2; % 2 secs @ 1kHz sample ratey = chirp(t,0,1,150); % Start @ DC, cross 150Hz at t=1 secspecgram(y,256,1e3,256,250) % Display the spectrogram

Time

Freq

uenc

y

0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.60

50

100

150

200

250

300

350

400

450

500

Page 381: MATLAB Signal Processing Toolbox user manual

chirp

6-77

Compute the spect rogram of a chirp with quadra t ic instan taneous frequencydevia t ion :

t = –2:0.001:2; % ±2 secs @ 1kHz sample ratey = chirp(t,100,1,200,'quadratic'); % Start @ 100Hz, cross 200Hz

% at t=1 secspecgram(y,128,1e3,128,120) % Display the spectrogram

Time

Freq

uenc

y

0 0.5 1 1.5 2 2.5 3 3.50

50

100

150

200

250

300

350

400

450

500

Page 382: MATLAB Signal Processing Toolbox user manual

chirp

6-78

See Also cos Cosine of vector /matr ix elements (see the onlineMATLAB Function Reference).

diric Dir ich let or per iodic sinc funct ion .gauspuls Gaussian-modula t ed sinusoida l pu lse genera tor.pulstran Pulse t ra in genera tor.rectpuls Sampled aperiodic rect angle genera tor.sawtooth Sawtooth or t r iangle wave genera tor.sin Sine of vector /matr ix elements (see the online

MATLAB Function Reference).sinc Sinc funct ion .square Square wave genera tor.tripuls Sampled aperiodic t r iangle genera tor.

Page 383: MATLAB Signal Processing Toolbox user manual

cohere

6-79

6coher ePurpose Est ima te magnitude squared coherence funct ion between two signa ls.

Syntax Cxy = cohere(x,y)Cxy = cohere(x,y,nfft)[Cxy,f] = cohere(x,y,nfft,Fs)Cxy = cohere(x,y,nfft,Fs,window)Cxy = cohere(x,y,nfft,Fs,window,noverlap)Cxy = cohere(x,y,...,'dflag')cohere(x,y)

Description Cxy = cohere(x,y) finds the magnitude squa red coherence between length nsigna l vector s x and y. The coherence is a funct ion of the power spect ra of x andy and the cross spect rum of x and y:

x and ymust be the same length . Cxy = cohere(x,y) uses the following defau ltva lues:

• nfft = min(256,length(x))• Fs = 2• window = hanning(nfft)

• noverlap = 0

nfft specifies the FFT length tha t cohere uses. This va lue determines thefrequencies a t which the coherence is est imated. Fs is a sca la r tha t specifies thesampling frequency. window specifies a windowing funct ion and the number ofsamples cohere uses in it s sect ion ing of the x and y vector s. noverlap is thenumber of samples by which the sect ions over lap. Any arguments tha t you omitfrom the end of the parameter list use the default va lues shown above.

If x is rea l, cohere est imates the coherence funct ion a t posit ive frequencieson ly; in th is case, the ou tpu t Cxy is a column vector of length nfft/2 + 1 fornfft even and (nfft + 1)/2 for n odd. If x or y is complex, cohere est ima testhe coherence funct ion a t both posit ive and negat ive frequencies, and Cxy haslength nfft.

Cxy f( )Pxy f( ) 2

Pxx f( )Pyy f( )-------------------------------=

Page 384: MATLAB Signal Processing Toolbox user manual

cohere

6-80

Cxy = cohere(x,y,nfft) uses the FFT length nfft in est ima t ing the powerspect rum for x. Specify nfft as a power of 2 for fast est execu t ion .

[Cxy,f] = cohere(x,y,nfft,Fs) retu rns a vector f of frequencies a t whichthe funct ion eva lua tes the coherence. Fs is the sampling frequency. f is t hesame size as Cxy, so plot(f,Cxy) plot s the coherence funct ion versus proper lysca led frequency. Fs has no effect on the ou tpu t Cxy; it is a frequency sca lingmult iplier .

Cxy = cohere(x,y,nfft,Fs,window) specifies a windowing funct ion and thenumber of samples per sect ion of the vectors x and y. If you supply a sca lar forwindow, cohere uses a Hanning window of tha t length . The length of thewindow must be less than or equa l to nfft; cohere zero pads the sect ions if thewindow length exceeds nfft.

Cxy = cohere(x,y,nfft,Fs,window,noverlap) over laps the sect ions of x bynoverlap samples.

You can use the empty mat r ix [] t o specify the defau lt va lue for any inputa rgument except x or y. For example,

Cxy = cohere(x,y,[],[],kaiser(128,5));

uses 256 as the va lue for nfft and 2 as the va lue for Fs.

Cxy = cohere(x,y,...,'dflag') specifies a det rend opt ion , where dflag is

• linear, to remove the best st ra igh t -line fit from the prewindowed sect ions ofx and y

• mean, t o remove the mean from the prewindowed sect ions of x and y• none, for no det rending (defau lt )

The dflag parameter must appear last in the list of inpu t argument s. cohererecognizes a dflag st r ing no mat t er how many in termedia t e a rguments areomit t ed.

cohere with no outpu t a rgument s plot s the coherence est imate versusfrequency in the cur ren t figure window.

Page 385: MATLAB Signal Processing Toolbox user manual

cohere

6-81

Example Compute and plot the coherence est ima te between two colored noise sequencesx and y:

h = fir1(30,0.2,boxcar(31));h1 = ones(1,10)/sqrt(10);r = randn(16384,1);x = filter(h1,1,r);y = filter(h,1,x);cohere(x,y,1024,[],[],512)

Diagnostics An appropr ia te diagnost ic message is displayed when incorrect a rguments a reused:

Requires window's length to be no greater than the FFT length.Requires NOVERLAP to be strictly less than the window length.Requires positive integer values for NFFT and NOVERLAP.Requires vector (either row or column) input.Requires inputs X and Y to have the same length.

Algorithm cohere est imates the magnitude squared coherence funct ion [1] using Welch’smethod of power spect rum est imat ion (see references [2] and [3]), as follows:

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 10

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

1

Frequency

Coh

eren

ce F

unct

ion

Estim

ate

Coherence Function Estimate

Page 386: MATLAB Signal Processing Toolbox user manual

cohere

6-82

1 It divides the signa ls x and y in to over lapping sect ions, det rends eachsect ion , and mult iplies each sect ion by window.

2 It ca lcu la tes the length nfft fast Four ier t ransform of each sect ion .3 It averages the squa res of the spect ra of the x sect ions to form Pxx, averagesthe squa res of the spect ra of the y sect ions to form Pyy, and averages theproducts of the spect ra of the x and y sect ions to form Pxy. It ca lcu la tes Cxyby

Cxy = abs(Pxy).^2/(Pxx.*Pyy)

See Also

References [1] Kay, S.M. Modern S pectral Estim ation . Englewood Cliffs, NJ :Prent ice-Hall, 1988. Pg. 454.

[2] Rabiner , L.R., and B. Gold. Theory and Application of Digital S ignalProcessing. Englewood Cliffs, NJ : Prent ice-Hall, 1975.

[3]Welch , P .D. “The Use of Fast Four ier Transform for the Est ima t ion of PowerSpect ra : A Method Based on Time Averaging Over Shor t , ModifiedPer iodograms.” IEEE Trans. Audio E lectroacoust . Vol. AU-15 (J une 1967).Pgs. 70-73.

csd Est imate the cross spect ra l density (CSD) of twosigna ls.

pwelch Est imate the power spect ra l density (PSD) of a signa lusing Welch’s method.

tfe Transfer funct ion est imate from inpu t and ou tpu t .

Page 387: MATLAB Signal Processing Toolbox user manual

conv

6-83

6convPurpose Convolu t ion and polynomia l mult iplica t ion .

Syntax c = conv(a,b)

Description conv(a,b) convolves vectors a and b. The convolu t ion sum is

where N is the maximum sequence length . The ser ies is indexed from n + 1 andk + 1 inst ead of the usua l n and k because MATLAB vectors run from 1 to ninstead of from 0 to n -1.

The conv funct ion is pa r t of the st andard MATLAB language.

Example The convolu t ion of a = [1 2 3] and b = [4 5 6] is

c = conv(a,b)

c =4 13 28 27 18

Algorithm The conv funct ion is an M-file tha t uses the filter pr imit ive. conv computesthe convolu t ion opera t ion as FIR filt er ing with an appropr ia te number of zerosappended to the input .

See Also

c n 1+( ) a k 1+( )b n k–( )k 0=

N 1–

∑=

conv2 Two-dimensiona l convolu t ion .convmtx Convolu t ion matr ix.convn N -dimensiona l convolut ion (see the online MATLAB

Function Reference).deconv Deconvolu t ion and polynomia l division .filter Filt er da ta with a recursive (IIR) or nonrecursive

(FIR) filter.residuez z-t ransform par t ia l fract ion expansion .xcorr Cross-cor rela t ion funct ion est imate.

Page 388: MATLAB Signal Processing Toolbox user manual

conv2

6-84

6conv2Purpose Two-dimensiona l convolu t ion .

Syntax C = conv2(A,B)C = conv2(A,B,'shape')

Description C = conv2(A,B) computes the two-dimensiona l convolu t ion of mat r ices A andB. If one of these matr ices descr ibes a two-dimensiona l FIR filt er , the otherma t r ix is filt ered in two dimensions.

Each dimension of the outpu t matr ix C is equa l in size to the sum of thecor responding dimensions of the input mat r ices minus 1. For[ma,na] = size(A) and [mb,nb] = size(B), then

size(C) = [ma+mb–1,na+nb–1]

C = conv2(A,B,'shape') retu rns a subsect ion of the two-dimensiona lconvolu t ion with size specified by shape, where:

• full retu rns the fu ll two-dimensiona l convolu t ion (defau lt )• same retu rns the cen t ra l par t of the convolu t ion tha t is the same size as A• valid retu rns only those pa r t s of the convolu t ion tha t are computed withoutthe zero-padded edges. Using th is opt ion , size(C) = [ma–mb+1,na–nb+1]when size(A) > size(B)

conv2 execu tes most quickly when size(A) > size(B).

The conv2 funct ion is par t of the standard MATLAB language.

Examples In image processing, the Sobel edge-finding opera t ion is a two-dimensiona lconvolu t ion of an input a r ray with the specia l mat r ix

s = [1 2 1; 0 0 0; –1 –2 –1];

Given any image, the following line ext racts the hor izon ta l edges:

h = conv2(I,s);

The lines below ext ract first the ver t ica l edges, then both hor izonta l andver t ica l edges combined:

v = conv2(I,s');v2 = (sqrt(h.^2 + v.^2))

Page 389: MATLAB Signal Processing Toolbox user manual

conv2

6-85

See Also conv Convolu t ion and polynomia l mult iplica t ion .convn N -dimensiona l convolut ion (see the online MATLAB

Function Reference).deconv Deconvolu t ion and polynomia l division .filter2 Two-dimensiona l digita l filt er ing.xcorr Cross-cor rela t ion funct ion est imate.xcorr2 Two-dimensiona l cross-cor rela t ion .

Page 390: MATLAB Signal Processing Toolbox user manual

convmtx

6-86

6convmtxPurpose Convolu t ion matr ix.

Syntax A = convmtx(c,n)A = convmtx(r,n)

Description A convolution m atrix is a ma tr ix, formed from a vector , whose inner productwith another vector is the convolu t ion of the two vectors.

A = convmtx(c,n) where c is a length m column vector retu rns a mat r ix A ofsize (m + n–1)-by-n. The product of A and another column vector x of length nis the convolut ion of c with x.

A = convmtx(r,n) where r is a length m row vector returns a matr ix A of sizen-by-(m + n–1). The product of A and another row vector x of length n is theconvolu t ion of r with x.

Example Genera t e a simple convolu t ion mat r ix:

h = [1 2 3 2 1];convmtx(h,7)ans =

1 2 3 2 1 0 0 0 0 0 0 0 1 2 3 2 1 0 0 0 0 0 0 0 1 2 3 2 1 0 0 0 0 0 0 0 1 2 3 2 1 0 0 0 0 0 0 0 1 2 3 2 1 0 0 0 0 0 0 0 1 2 3 2 1 0 0 0 0 0 0 0 1 2 3 2 1

Note tha t convmtx handles edge condit ions by zero padding.

In pract ice, it is more efficien t to compute convolut ion using

y = conv(c,x)

t han by using a convolu t ion matr ix:

n = length(x);y = convmtx(c,n)*x

Algorithm convmtx uses the funct ion toeplitz to genera te the convolu t ion matr ix.

Page 391: MATLAB Signal Processing Toolbox user manual

convmtx

6-87

See Also conv Convolu t ion and polynomia l mult iplica t ion .convn N -dimensiona l convolut ion (see the online MATLAB

Function Reference).conv2 Two-dimensiona l convolu t ion .dftmtx Discret e Four ier t ransform mat r ix.

Page 392: MATLAB Signal Processing Toolbox user manual

corrcoef

6-88

6cor r coefPurpose Correla t ion coefficien t mat r ix.

Syntax C = corrcoef(X)C = corrcoef(X,Y)

Description corrcoef retu rns a mat r ix of cor rela t ion coefficien t s ca lcu la ted from an inputma tr ix whose rows are observa t ions and whose columns a re var iables. IfC = cov(X), t hen corrcoef(X) is the matr ix whose element (i, j) is

C = corrcoef(X) is the zeroth lag of the covar iance funct ion , tha t is, thezeroth lag of xcov(x,'coeff') packed in to a square ar ray.

C = corrcoef(X,Y) is the same as corrcoef([X Y]), t ha t is, it conca tena tes Xand Y in the row direct ion before it s computa t ion .

corrcoef removes the mean from each column before ca lcula t ing the resu lt s.See the xcorr funct ion for cross-cor rela t ion opt ions.

The corrcoef funct ion is par t of the standa rd MATLAB language.

See Also

cor rcoef i j,( ) C i j,( )C i i,( )C j j,( )-----------------------------------=

cov Covar iance ma t r ix.mean Average va lue (see the online MATLAB Function

Reference).median Median va lue (see the online MATLAB Function

Reference).std Standard devia t ion (see the online MATLAB

Function Reference).xcorr Cross-correla t ion funct ion est imate.xcov Cross-cova r iance funct ion est ima te (equa l to

mean-removed cross-cor rela t ion).

Page 393: MATLAB Signal Processing Toolbox user manual

cov

6-89

6covPurpose Covar iance mat r ix.

Syntax c = cov(x)c = cov(x,y)

Description cov computes the covar iance mat r ix. If x is a vector , c is a sca la r conta in ing thevar iance. For an ar ray where each row is an observa t ion and each column avar iable, cov(X) is the covar iance matr ix. diag(cov(X)) is a vector ofvar iances for each column, and sqrt(diag(cov(X))) is a vector of st andarddevia t ions.

cov(x) is the zeroth lag of the covar iance funct ion , tha t is, the zeroth lag ofxcov(x)/(n–1) packed in to a square ar ray.

cov(x,y) where x and y a re column vectors of equa l length is equiva len t tocov([x y])), t ha t is, it conca tena tes x and y in the row direct ion before it scomputa t ion .

cov removes the mean from each column before ca lcu la t ing the resu lt s.

The cov funct ion is pa r t of the st andard MATLAB language.

Algorithm [n,p] = size(x);x = x–ones(n,1)*(sum(x)/n);y = x'*x/(n–1);

See Also corrcoef Correla t ion coefficien t mat r ix.mean Average va lue (see the online MATLAB Function

Reference).median Median va lue (see the online MATLAB Function

Reference).std Standard devia t ion (see the online MATLAB

Function Reference).xcorr Cross-cor rela t ion funct ion est imate.xcov Cross-covar iance funct ion est ima te (equa l to

mean-removed cross-correla t ion).

Page 394: MATLAB Signal Processing Toolbox user manual

cplxpair

6-90

6cplxpa irPurpose Group complex numbers in to complex con jugate pa ir s.

Syntax y = cplxpair(x)y = cplxpair(x,tol)

Description y = cplxpair(x) retu rns x with complex conjugate pa ir s grouped together .cplxpair orders the conjuga te pa irs by increasing rea l par t . With in a pa ir , theelement with nega t ive imagina ry pa r t comes fir st . The funct ion retu rns a llpurely rea l va lues following all the complex pairs.

y = cplxpair(x,tol) includes a tolerance, tol, for determin ing whichnumbers are rea l and which are pa ired complex conjuga tes. By defau lt ,cplxpair uses a tolerance of 100*eps rela t ive to abs(x(i)). cplxpair forcesthe complex conjuga te pa ir s to be exact complex conjuga tes.

The cplxpair funct ion is par t of the standa rd MATLAB language.

Example Order five poles even ly spaced a round the unit circle in to complex pa ir s:

cplxpair(exp(2*pi*sqrt(–1)*(0:4)/5)')

ans =–0.8090 – 0.5878i–0.8090 + 0.5878i0.3090 – 0.9511i0.3090 + 0.9511i1.0000

Diagnostics If there is an odd number of complex numbers, or if the complex numberscannot be grouped into complex conjuga te pa ir s with in the tolerance, cplxpairgenera t es the er ror message:

Complex numbers can't be paired.

Page 395: MATLAB Signal Processing Toolbox user manual

cremez

6-91

6cremezPurpose Complex and nonlinear -phase equir ipple FIR filt er design .

Syntax b = cremez(n,f,'fresp')b = cremez(n,f,'fresp',w)b = cremez(n,f,{'fresp',p1,p2,...},w)b = cremez(n,f,a,w)b = cremez(...,'sym')b = cremez(...,'skip_stage2')b = cremez(...,'debug')b = cremez(...,{lgrid})[b,delta,opt] = cremez(...)

Description cremez a llows arbit ra ry frequency-domain const ra in t s to be specified for thedesign of a possibly complex FIR filter . The Chebyshev (or min imax) filt er er roris opt imized, producing equir ipple FIR filt er designs.

b = cremez(n,f,'fresp') retu rns a length n+1 FIR filt er with the bestapproximat ion to the desired frequency response as retu rned by funct ionfresp. f is a vector of frequency band edge pa irs, specified in the range-1 and 1, where 1 cor responds to ha lf the sampling frequency (the Nyquistfrequency). The frequencies must be in increasing order , and fmust have evenlength . The frequency bands span f(k) to f(k+1) for k odd; the in terva lsf(k+1) t o f(k+2) for k odd are “t ransit ion bands” or “don’t care” regions dur ingopt imiza t ion .

b = cremez(n,f,'fresp',w) uses the rea l, non-nega t ive weigh ts in vector w toweigh t the fit in each frequency band. The length of w is ha lf the length of f, sothere is exact ly one weight per band.

b = cremez(n,f,{'fresp',p1,p2,...},...) supplies opt iona l pa rameter sp1, p2, ..., to the frequency response funct ion fresp. P redefined 'fresp'frequency response funct ions a re included for a number of common filterdesigns, as descr ibed below. For a ll of the predefined frequency responsefunct ions, the symmetry opt ion 'sym' defau lt s to 'even' if no nega t ivefrequencies are conta ined in f and d = 0; otherwise 'sym' defau lt s to 'none'.(See the 'sym' opt ion below for deta ils.) For a ll of the predefined frequencyresponse funct ions, d specifies a group-delay offset such tha t the filter response

Page 396: MATLAB Signal Processing Toolbox user manual

cremez

6-92

has a group delay of n/2+d in unit s of the sample in terva l. Negat ive va luescrea te less delay; posit ive va lues crea t e more delay. By default , d = 0.

• lowpass, highpass, bandpass, bandstop

These funct ions share a common syntax, exemplified here by 'lowpass':b = cremez(n,f,'lowpass',...) andb = cremez(n,f,{'lowpass',d},...) design a linear -phase (n/2+d delay)filter .

• multiband designs a linear -phase frequency response filter with arbit ra ryband amplitudes.b = cremez(n,f,{'multiband',a},...) andb = cremez(n,f,{'multiband',a,d},...) specify vector a conta in ing thedesired amplitudes a t the band edges in f. The desired amplitude a tfrequencies between pair s of poin ts f(k) and f(k+1) for k odd is the linesegment connect ing the poin ts (f(k),a(k)) and (f(k+1),a(k+1)).

• differentiator designs a linear -phase differen t ia tor . For these designs,zero-frequency must be in a t ransit ion band, and band weight ing is set to beinversely propor t iona l to frequency.b = cremez(n,f,{'differentiator',Fs},...) andb = cremez(n,f,{'differentiator',Fs,d},...) specify the sample ra te Fsused to determine the slope of the differen t ia tor response. If omit ted, Fsdefau lt s to 1.

• hilbfilt designs a linear -phase Hilber t t ransform filt er response. ForHilber t designs, zero-frequency must be in a t ransit ion band.b = cremez(n,f,'hilbfilt',...) andb = cremez(N,F,{'hilbfilt',d},...) design a linear -phase (n/2+d delay)Hilber t t ransform filter .

b = cremez(n,f,a,w) is a synonym forb = cremez(n,f,{'multiband',a},w).

b = cremez(...,'sym') imposes a symmetry const ra in t on the impulseresponse of the design , where 'sym' may be one of the following:

Page 397: MATLAB Signal Processing Toolbox user manual

cremez

6-93

• 'none' indica tes no symmetry const ra in tThis is the default if any negat ive band edge frequencies are passed, or if'fresp' does not supply a defau lt .

• 'even' indica tes a rea l and even impulse responseThis is the default for highpass, lowpass, bandpass, bandstop, andmult iband designs.

• 'odd' indica t es a rea l and odd impulse responseThis is the default for Hilber t and different ia tor designs.

• 'real' indica tes con juga te symmet ry for the frequency response

If any 'sym' opt ion other than 'none' is specified, the band edges should onlybe specified over posit ive frequencies; the nega t ive frequency region is filled infrom symmetry. If a 'sym' opt ion is not specified, the 'fresp' funct ion isquer ied for a default set t ing.

b = cremez(...,'skip_stage2') disables the second-stage opt imiza t iona lgor ithm, which executes on ly when cremez determines tha t an opt imalsolu t ion has not been reached by the standard Remez er ror -exchange.Disabling th is a lgorithm may increase the speed of computa t ion , but may incura reduct ion in accuracy. By defau lt , t he second-stage opt im iza t ion is enabled.

b = cremez(...,'debug') enables the display of int ermedia t e resu lt s dur ingthe filt er design , where 'debug' may be one of 'trace', 'plots', 'both', or 'off'. By default , it is set to 'off'.

b = cremez(...,{lgrid}) uses the in teger lgrid to con t rol the density of thefrequency gr id, which has roughly 2^nextpow2(lgrid*n) frequency poin ts.The defau lt va lue for lgrid is 25. Note tha t the {lgrid} argument must be a1-by-1 cell a r ray.

Any combina t ion of the 'sym', 'skip_stage2', 'debug', and {lgrid} opt ionsmay be specified.

[b,delta] = cremez(...) retu rns the maximum ripple heigh t delta.

Page 398: MATLAB Signal Processing Toolbox user manual

cremez

6-94

[b,delta,opt] = cremez(...) retu rns a st ructure opt of opt iona l resu lt scomputed by cremez and conta ins the following fields:

Examples Example 1Design a 31-tap, linear -phase, lowpass filter :

b = cremez(30,[–1 –0.5 –0.4 0.7 0.8 1],'lowpass');freqz(b,1,512,'whole');

opt.fgrid Frequency gr id vector used for the filter design opt imiza t ion

opt.des Desired frequency response for each poin t in opt.fgrid

opt.wt Weight ing for each poin t in opt.fgrid

opt.H Actua l frequency response for each poin t in opt.fgrid

opt.error Error a t each poin t in opt.fgrid

opt.iextr Vector of indices in to opt.fgrid for ext remal frequencies

opt.fextr Vector of ext remal frequencies

0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2−4000

−3000

−2000

−1000

0

Normalized Angular Frequency (×π rads/sample)

Phas

e (d

egre

es)

0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2−100

−50

0

50

Normalized Angular Frequency (×π rads/sample)

Mag

nitu

de (d

B)

Page 399: MATLAB Signal Processing Toolbox user manual

cremez

6-95

Example 2Design a nonlinear -phase a llpass FIR filt er .

F ir st select (or crea te) the funct ion fresp t ha t returns the desired frequencyresponse. For th is example, fresp is the allpass.m funct ion in thesignal/signal/private directory which returns the frequency response of anonlinea r -phase a llpass filt er . Copy allpass.m to another loca t ion on theMATLAB path before t rying the example.

Before using cremez with allpass.m to genera te the filt er coefficien t s, ca llallpass a lone to crea te the desired response.

n = 22; % Filter orderf = [–1 1]; % Frequency band edgesw = [1 1]; % Weights for optimizationgf = linspace(–1,1,256); % Grid of frequency points d = allpass(n,f,gf,w); % Desired frequency response

Vector d now conta ins the complex frequency response tha t we desire for theFIR filter computed by cremez.

Now compute the FIR filt er tha t best approximates this response:

b = cremez(n,f,'allpass',w,'real' ); % Approximationfreqz(b,1,256,'whole');

0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2−3000

−2000

−1000

0

Normalized Angular Frequency (×π rads/sample)

Phas

e (d

egre

es)

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)

Mag

nitu

de (d

B)

Page 400: MATLAB Signal Processing Toolbox user manual

cremez

6-96

The freqz plot shows the frequency response of the filter computed by cremez to approximate the desired response. Check the accuracy of the approximat ionby over laying the desired frequency response on the plot .

subplot(2,1,1); hold onplot(pi*(gf+1),20*log10(abs(fftshift(d))),'r--')

subplot(2,1,2); hold onplot(pi*(gf+1),unwrap(angle(fftshift(d)))*180/pi,'r--')legend('Approximation','Desired')

Remarks User -definable funct ions may be used, instead of the predefined frequencyresponse funct ions for 'fresp'. The funct ion is ca lled from within cremez usingthe following syntax:

[dh,dw] = fresp(n,f,gf,w,p1,p2,...) where

• n is the filter order .• f is the vector of frequency band edges tha t appear monotonica lly between-1 and 1, where 1 is the Nyquist frequency.

• gf is a vector of gr id poin ts tha t have been linear ly in terpola t ed over eachspecified frequency band by cremez. gf determines the frequency gr id a twhich the response funct ion must be eva lua ted. This is the same da taretu rned by cremez in the fgrid field of the opt st ructure.

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)

Phas

e (d

egre

es)

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)

Mag

nitu

de (d

B)

ApproximationDesired

Page 401: MATLAB Signal Processing Toolbox user manual

cremez

6-97

• w is a vector of rea l, posit ive weight s, one per band, used dur ing opt imiza t ion .w is opt iona l in the ca ll t o cremez; if not specified, it is set to unity weight ingbefore being passed to 'fresp'.

• dh and dw a re the desired complex frequency response and band weigh tvectors, respect ively, eva lua ted a t each frequency in gr id gf.

• p1, p2, ..., a re opt iona l pa rameters tha t may be passed to 'fresp'.

Addit iona lly, a preliminary ca ll is made to 'fresp' to determine the defau ltsymmet ry proper ty 'sym'. This ca ll is made using the syntax:

sym = fresp('defaults',{n,f,[],w,p1,p2,...})

The a rguments may be used in determining an appropr ia t e symmetry defau ltas necessa ry. The funct ion private/lowpass.mmay be usefu l as a templa te forgenera t ing new frequency response funct ions.

Algorithm An extended version of the Remez exchange method is implemented for thecomplex case. This exchange method obta ins the opt imal filter when theequir ipple na ture of the filt er is rest r icted to have n+2 ext remals. When it doesnot converge, the a lgor ithm switches to an ascent -descent a lgor ithm tha t t akesover to fin ish the convergence to the opt imal solu t ion . See the references forfur ther deta ils.

Page 402: MATLAB Signal Processing Toolbox user manual

cremez

6-98

Diagnostics The following diagnost ic messages ar ise from incorrect usage of cremez:

Not enough input arguments.

F must contain an even number of band edge entries.

Band edges must be monotonically increasing.

Expecting a string argument.

Invalid argument arg specified.

Invalid default symmetry option sym returned from response function fresp. Must be one of 'none', 'real', 'even', or 'odd'.

Frequency band edges must be in the range [–1,+1] for designs with SYM = 'sym'.

Frequency band edges must be in the range [0,+1] for designs with SYM = 'sym'.

Incorrect size of results from response function fresp. Sizes must be the same size as the frequency grid GF.

Both –1 and 1 have been specified as frequencies in F, and the frequency spacing is too close to move either of them toward its neighbor.

Internal error: Grid frequencies out of range.

Internal error: domain must be "whole" or "half".

Internal error: obtained a negative bandwidth.

Internal error: two extremal frequecies at the same grid point.

Internal error: dBrange must be > 0.

Page 403: MATLAB Signal Processing Toolbox user manual

cremez

6-99

See Also

References [1] Karam, L.J ., and J .H. McClellan . “Complex Chebyshev Approximat ion forFIR Filter Design .” IEEE Trans. on Circuits and S ystem s II. March 1995.Pgs. 207-216.

[2] Karam, L.J . Design of Com plex Digital FIR Filters in the Chebyshev S ense.Ph.D. Thesis, Georgia Inst itu t e of Technology, March 1995.

[3] Demjan jov, V.F ., and V.N. Malozemov. In troduction to Minim ax. New York:J ohn Wiley & Sons, 1974.

fir1 Window-based fin it e impulse response filter design –standard response.

fir2 Window-based fin it e impulse response filter design –arbit ra ry response.

firls Least square linear -phase FIR filter design .remez Parks-McClellan opt ima l FIR filter design .private/bandpass Bandpass filter design funct ion .private/bandstop Bandstop filter design funct ion .private/differentiator

Differen t ia tor filt er design funct ion .

private/highpass Highpass filter design funct ion .private/hilbfilt Hilber t filter design funct ion .private/lowpass Lowpass filter design funct ion .private/multiband Mult iband filt er design funct ion .

Page 404: MATLAB Signal Processing Toolbox user manual

csd

6-100

6csdPurpose Est imate the cross spect ra l density (CSD) of two signa ls.

Syntax Pxy = csd(x,y)Pxy = csd(x,y,nfft)[Pxy,f] = csd(x,y,nfft,Fs)Pxy = csd(x,y,nfft,Fs,window)Pxy = csd(x,y,nfft,Fs,window,noverlap)Pxy = csd(x,y,...,'dflag')[Pxy,Pxyc,f] = csd(x,y,nfft,Fs,window,noverlap,p)csd(x,y,...)

Description Pxy = csd(x,y) est imates the cross spect ra l density of the length n sequencesx and y using the Welch method of spect ra l est imat ion . Pxy = csd(x,y) usesthe following defau lt va lues:

• nfft = min(256,length(x))• Fs = 2• window = hanning(nfft)

• noverlap = 0

nfft specifies the FFT length tha t csd uses. This va lue determines thefrequencies a t which the cross spect rum is est imated. Fs is a sca la r tha tspecifies the sampling frequency. window specifies a windowing funct ion andthe number of samples csd uses in it s sect ion ing of the x and y vectors.noverlap is the number of samples by which the sect ions over lap. Anyarguments omit t ed from the end of the parameter list use the defau lt va luesshown above.

If x and y are rea l, csd est ima tes the cross spect ra l density a t posit ivefrequencies on ly; in th is case, the outpu t Pxy is a column vector of lengthnfft/2 + 1 for nfft even and (nfft + 1)/2 for nfft odd. If x or y is complex,csd est ima tes the cross spect ra l density a t both posit ive and nega t ivefrequencies and Pxy has length nfft.

Pxy = csd(x,y,nfft) uses the FFT length nfft in est imat ing the crossspect ra l density of x and y. Specify nfft as a power of 2 for fastest execu t ion .

[Pxy,f] = csd(x,y,nfft,Fs) retu rns a vector f of frequencies a t which thefunct ion eva lua tes the CSD. f is the same size as Pxy, so plot(f,Pxy) plots the

Page 405: MATLAB Signal Processing Toolbox user manual

csd

6-101

spect rum versus proper ly sca led frequency. Fs has no effect on the outpu t Pxy;it is a frequency sca ling mult iplier .

Pxy = csd(x,y,nfft,Fs,window) specifies a windowing funct ion and thenumber of samples per sect ion of the x vector . If you supply a sca lar for window,csd uses a Hanning window of tha t length . The length of the window must beless than or equal to nfft; csd zero pads the sect ions if the length of the windowis less than nfft. csd retu rns an er ror if the length of the window is grea terthan nfft.

Pxy = csd(x,y,nfft,Fs,window,noverlap) over laps the sect ions of x and yby noverlap samples.

You can use the empty mat r ix [] to specify the defau lt va lue for any inputa rgument except x or y. For example,

csd(x,y,[],10000)

is equiva len t to

csd(x)

but with a sampling frequency of 10,000 Hz inst ead of the defau lt of 2 Hz.

Pxy = csd(x,y,...,'dflag') specifies a det rend opt ion , where dflag is:

• linear, to remove the best st r a igh t -line fit from the prewindowed sect ions ofx and y

• mean, to remove the mean from the prewindowed sect ions of x and y• none, for no det rending (defau lt )

The dflag parameter must appear la st in the list of input a rgument s. csdrecognizes a dflag st r ing no mat ter how many in termedia te a rguments areomit t ed.

[Pxy,Pxyc,f] = csd(x,y,nfft,Fs,window,noverlap,p) where p is a posit ivesca la r between 0 and 1 returns a vector Pxyc t ha t con ta ins an est imate of thep*100 percen t confidence in terva l for Pxy. Pxyc is a two-column mat r ix thesame length as Pxy. The in terva l [Pxyc(:,1), Pxyc(:,2)] covers the t rueCSD with probabilit y p. plot(f,[Pxy Pxyc]) plot s the cross spect rum insidethe p*100 percen t confidence in terva l. If unspecified, p defau lt s to 0.95.

Page 406: MATLAB Signal Processing Toolbox user manual

csd

6-102

csd(x,y,...) plot s the CSD versus frequency in the cur rent figure window. Ifthe p pa rameter is specified, the plot includes the confidence in terva l.

Example Genera t e two colored noise signa ls and plot their CSD with a confidencein t erva l of 95%. Specify a length 1024 FFT, a 500 poin t t r iangular window withno over lap, and a sampling frequency of 10 Hz:

h = fir1(30,0.2,boxcar(31));h1 = ones(1,10)/sqrt(10);r = randn(16384,1);x = filter(h1,1,r);y = filter(h,1,x);csd(x,y,1024,10000,triang(500),0,[])

Algorithm csd implements the Welch method of spect ra l density est ima t ion (seereferences [1] and [2]):

1 It applies the window specified by the window vector to each successivedet rended sect ion .

2 It t ransforms each sect ion with an nfft-poin t FFT.3 It forms the per iodogram of each sect ion by sca ling the product of thet ransform of the y sect ion and the conjugate of the t ransformed x sect ion .

0 1000 2000 3000 4000 5000-70

-60

-50

-40

-30

-20

-10

0

10

20

Frequency

Cro

ss S

pect

rum

Mag

nitu

de (d

B)

Page 407: MATLAB Signal Processing Toolbox user manual

csd

6-103

4 It averages the per iodograms of the successive over lapping sect ions to formPxy, the cross spect ra l density of x and y.

The number of sect ions tha t csd averages is k, where k is

fix((length(x)–noverlap)/(length(window)–noverlap))

Diagnostics An appropr ia te diagnost ic message is displayed when incor rect a rguments tocsd a re used:

Requires window's length to be no greater than the FFT length.Requires NOVERLAP to be strictly less than the window length.Requires positive integer values for NFFT and NOVERLAP.Requires vector (either row or column) input.Requires inputs X and Y to have the same length.Requires confidence parameter to be a scalar between 0 and 1.

See Also

References [1] Rabiner , L.R., and B. Gold. Theory and Application of Digital S ignalProcessing. Englewood Cliffs, NJ : Pren t ice-Ha ll, 1975. Pgs. 414-419.

[2]Welch , P .D. “The Use of Fast Four ier Transform for the Est imat ion of PowerSpect ra : A Method Based on Time Averaging Over Shor t , ModifiedPer iodograms.” IEEE Trans. Audio Electroacoust . Vol. AU-15 (J une 1967).Pgs. 70-73.

cohere Est imate magnitude squared coherence funct ionbetween two signals.

pburg Power spect rum est ima te using the Burg method.pmtm Power spect rum est ima te using the mult itaper

method (MTM).pmusic Power spect rum est ima te using MUSIC eigenvector

method.pwelch Est imate the power spect ra l density (PSD) of a signa l

using Welch’s method.pyulear Power spect rum est ima te using Yule-Walker AR

method.tfe Transfer funct ion est imate from inpu t and ou tpu t .

Page 408: MATLAB Signal Processing Toolbox user manual

csd

6-104

[3] Oppenheim, A.V., and R.W. Schafer . Discrete-T im e S ignal Processing.Englewood Cliffs, NJ : Prent ice-Hall, 1989. Pg. 737.

Page 409: MATLAB Signal Processing Toolbox user manual

czt

6-105

6cztPurpose Chirp z-t ransform.

Syntax y = czt(x,m,w,a)y = czt(x)

Description y = czt(x,m,w,a) retu rns the ch irp z-t ransform of signa l x. The ch irpz-t ransform is the z-t ransform of x a long a spira l contour defined by w and a. mis a sca la r tha t specifies the length of the t ransform, w is the ra t io betweenpoin ts a long the z-plane spira l con tour of in t erest , and sca lar a is the complexsta r t ing poin t on tha t contour . The contour , a spira l or “ch irp” in the z-plane, isgiven by

z = a*(w.^–(0:m–1))

y = czt(x) uses the following defau lt va lues:

• m = length(x)

• w = exp(j*2*pi/m)

• a = 1

With these defau lt s, czt retu rns the z-t r ansform of x a t m equally spaced poin t sa round the unit circle. This is equiva len t to the discrete Four ier t ransform ofx, or fft(x). The empty mat r ix [] specifies the default va lue for a parameter .

If x is a matr ix, czt(x,m,w,a) t r ansforms the columns of x.

Examples Create a random vector x of length 1013 and compute it s DFT using czt. Th isis faster than the fft funct ion on the same sequence.

x = randn(1013,1);y = czt(x);

Use czt to zoom in on a nar row-band sect ion (100 to 150 Hz) of a filter ’sfrequency response. F ir st design the filt er :

h = fir1(30,125/500,boxcar(31)); % filter

Page 410: MATLAB Signal Processing Toolbox user manual

czt

6-106

Establish frequency and CZT parameters:

Fs = 1000; f1 = 100; f2 = 150; % in Hertzm = 1024;w = exp(–j*2*pi*(f2–f1)/(m*Fs));a = exp(j*2*pi*f1/Fs);

Compute both the DFT and CZT of the filt er :

y = fft(h,1000);z = czt(h,m,w,a);

Create frequency vector s and compare the result s:

fy = (0:length(y)–1)'*1000/length(y); fz = ((0:length(z)–1)'*(f2–f1)/length(z)) + f1;plot(fy(1:500),abs(y(1:500))); axis([1 500 0 1.2])title('FFT')figureplot(fz,abs(z)); axis([f1 f2 0 1.2])title('CZT')

Algorithm czt uses the next power-of-2 length FFT to per form a fast convolu t ion whencomput ing the z-t ransform on a specified ch irp contour [1]. czt can besign ificant ly fa st er than fft for la rge, pr ime-length sequences.

Diagnostics If m, w, or a is not a sca la r , czt gives the following error message:

Inputs M, W, and A must be scalars.

100 200 300 400 5000

0.2

0.4

0.6

0.8

1

FFT

100 110 120 130 1400

0.2

0.4

0.6

0.8

1

CZT

Page 411: MATLAB Signal Processing Toolbox user manual

czt

6-107

See Also

References [1] Rabiner , L.R., and B. Gold. Theory and Application of Digital S ignalProcessing. Englewood Cliffs, NJ : Pren t ice-Ha ll, 1975. Pgs. 393-399.

fft One-dimensiona l fast Four ier t ransform.freqz Frequency response of digita l filter s.

Page 412: MATLAB Signal Processing Toolbox user manual

dct

6-108

6dctPurpose Discret e cosine t ransform (DCT).

Syntax y = dct(x)y = dct(x,n)

Description y = dct(x) retu rns the unita ry discret e cosine t ransform of x

where

N is the length of x, and x and y are the same size. If x is a mat r ix, dctt r ansforms it s columns. The ser ies is indexed from n = 1 and k = 1 inst ead ofthe usua l n = 0 and k = 0 because MATLAB vectors run from 1 to N inst ead offrom 0 to N - 1.

y = dct(x,n) pads or t runca tes x to length n before t ransforming.

The DCT is closely rela t ed to the discrete Four ier t ransform. You can oftenreconst ruct a sequence very accura tely from only a few DCT coefficien t s, ausefu l proper ty for applica t ions requir ing da ta reduct ion .

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

n 1=

N

∑ k 1 … N, ,=,=

w k( )

1N--------- k 1=,

2N---- 2 k N≤ ≤,

⎩⎪⎪⎨⎪⎪⎧

=

Page 413: MATLAB Signal Processing Toolbox user manual

dct

6-109

Example Find how many DCT coefficien t s represen t 99% of the energy in a sequence:

x = (1:100) + 50*cos((1:100)*2*pi/40);X = dct(x);[XX,ind] = sort(abs(X)); ind = fliplr(ind);i = 1;while (norm([X(ind(1:i)) zeros(1,100–i)])/norm(X)<.99)

i = i + 1;end

i = 3

See Also

References [1] J a in , A.K. Fundam entals of Digital Im age Processing. Englewood Cliffs, NJ :Prent ice-Ha ll, 1989.

[2] Pennebaker , W.B., and J .L. Mitchell. J PEG S till Im age Data Com pressionS tandard . New York, NY: Van Nost rand Reinhold, 1993. Chapter 4.

fft One-dimensiona l fast Four ier t ransform.idct Inverse discrete cosine t ransform.dct2 Two-dimensiona l DCT (see Im age Processing Toolbox

User’s Guide).idct2 Two-dimensiona l inverse DCT (see Im age Processing

Toolbox User’s Guide).

Page 414: MATLAB Signal Processing Toolbox user manual

decimate

6-110

6decima tePurpose Decrease the sampling ra t e for a sequence (decimat ion).

Syntax y = decimate(x,r)y = decimate(x,r,n)y = decimate(x,r,'fir')y = decimate(x,r,n,'fir')

Description Decimat ion reduces the or igina l sampling ra te for a sequence to a lower ra t e.It is the opposite of in terpola t ion . The decimat ion process filt ers the inpu t da tawith a lowpass filt er and then resamples the result ing smoothed signa l a t alower ra te.

y = decimate(x,r) reduces the sample ra te of x by a factor r. The decima tedvector y is r t imes shor t er in length than the input vector x. By default ,decimate employs an eigh th -order lowpass Chebyshev type I filter . It filter sthe input sequence in both the forward and reverse direct ions to remove allphase distor t ion , effect ively doubling the filter order .

y = decimate(x,r,n) uses an order n Chebyshev filt er . Orders above 13 arenot recommended because of numer ica l instabilit y. MATLAB displays awarning in th is case.

y = decimate(x,r,'fir') uses a 30-poin t F IR filter , instead of the ChebyshevIIR filt er . Here decimate filter s the inpu t sequence in only one direct ion . Thist echnique conserves memory and is usefu l for working with long sequences.

y = decimate(x,r,n,'fir') uses a length n FIR filter .

Example Decimate a signa l by a factor of four :

t = 0:.00025:1; % time vectorx = sin(2*pi*30*t) + sin(2*pi*60*t);y = decimate(x,4);

Page 415: MATLAB Signal Processing Toolbox user manual

decimate

6-111

View the or igina l and decima ted signa ls:

stem(x(1:120)), axis([0 120 –2 2]) % original signaltitle('Original Signal')figurestem(y(1:30)) % decimated signaltitle('Decimated Signal')

Algorithm decimate uses decima t ion a lgor ithms 8.2 and 8.3 from [1]:

1 It designs a lowpass filt er . By default , decimate uses a Chebyshev type Ifilter with normalized cu toff frequency 0.8/r and 0.05 dB of passband r ipple.For the fir opt ion , decimate designs a lowpass FIR filter with cutofffrequency 1/r using fir1.

2 For the FIR filter , decimate applies the filt er to the input vector in onedirect ion . In the IIR case, decimate applies the filt er in forward and reversedirect ions with filtfilt.

3 decimate resamples the filt ered data by select ing every r-th point .

Diagnostics If r is not an in teger , decimate gives the following er ror message:

Resampling rate R must be an integer.

If n specifies an IIR filt er with order grea ter than 13, decimate gives thefollowing warn ing:

Warning: IIR filters above order 13 may be unreliable.

0 50 100-2

-1

0

1

2Original Signal

0 10 20 30-2

-1

0

1

2Decimated Signal

Page 416: MATLAB Signal Processing Toolbox user manual

decimate

6-112

See Also

References [1] IEEE. Program s for Digital S ignal Processing. IEEE Press. New York: J ohnWiley & Sons, 1979. Chapter 8.

interp Increase sampling ra te by an in teger factor (in t erpola t ion).resample Change sampling ra te by any ra t iona l factor.spline Cubic spline in terpola t ion (see the online MATLAB

Function Reference).upfirdn Upsample, apply an FIR filter, and downsample.

Page 417: MATLAB Signal Processing Toolbox user manual

deconv

6-113

6deconvPurpose Deconvolut ion and polynomia l division .

Syntax [q,r] = deconv(b,a)

Description [q,r] = deconv(b,a) deconvolves vector a out of vector b, using long division.The resu lt (quot ien t ) is retu rned in vector q and the remainder in vector r suchtha t b = conv(q,a) + r.

If a and b are vectors of polynomia l coefficien ts, convolving them is equiva len tto polynomia l mult iplica t ion , and deconvolu t ion is equiva len t to polynomia ldivision . The resu lt of dividing b by a is quot ien t q and rema inder r.

The deconv funct ion is par t of the standard MATLAB language.

Example The convolu t ion of a = [1 2 3] and b = [4 5 6] is

c = conv(a,b)

c =4 13 28 27 18

Use deconv to divide b back out :

[q,r] = deconv(c,a)

q =4 5 6

r =0 0 0 0 0

Algorithm This funct ion ca lls filter t o compute the deconvolu t ion as the impulseresponse of an IIR filter .

See Also conv Convolu t ion and polynomia l mult iplica t ion .filter Filt er da ta with a recursive (IIR) or nonrecursive

(FIR) filter.residuez z-t ransform par t ia l fract ion expansion .

Page 418: MATLAB Signal Processing Toolbox user manual

demod

6-114

6demodPurpose Demodula t ion for communica t ions simula t ion .

Syntax x = demod(y,Fc,Fs,'method')x = demod(y,Fc,Fs,'method',opt)x = demod(y,Fc,Fs,'pwm','centered')[x1,x2] = demod(y,Fc,Fs,'qam')

Description demod per forms demodula t ion , tha t is, it obta ins the origina l signa l from amodula t ed version of the signa l. demod undoes the opera t ion per formed bymodulate.

x = demod(y,Fc,Fs,'method') and

x = demod(y,Fc,Fs,'method',opt) demodula t e the rea l ca r r ier signa l y witha car r ier frequency Fc and sampling frequency Fs, using one of the opt ionslist ed below for method. (Note tha t some methods accept an opt ion, opt.)

amdsb–sc

or

am

Amplitude demodu la tion , double s ideband, suppre ssedcarrie r. Mult iplies y by a sinusoid of frequency Fc and applies afifth -order But terwor th lowpass filter using filtfilt:

x = y.*cos(2*pi*Fc*t);[b,a] = butter(5,Fc*2/Fs);x = filtfilt(b,a,x);

amdsb–tc Amplitude demodu la tion , double s ideband, transmittedcarrie r. Mult iplies y by a sinusoid of frequency Fc, and applies afifth -order But terwor th lowpass filter using filtfilt:

x = y.*cos(2*pi*Fc*t);[b,a] = butter(5,Fc*2/Fs);x = filtfilt(b,a,x);

If you specify opt, demod subt racts sca la r opt from x. The defau ltva lue for opt is 0.

amssb Amplitude demodu la tion , s ingle s ideband. Mult iplies y by asinusoid of frequency Fc and applies a fifth-order But terwor thlowpass filt er using filtfilt:

x = y.*cos(2*pi*Fc*t);[b,a] = butter(5,Fc*2/Fs);x = filtfilt(b,a,x);

Page 419: MATLAB Signal Processing Toolbox user manual

demod

6-115

The defau lt method is 'am'. Except for the 'ptm' and 'pwm' cases, x is thesame size as y.

If y is a matr ix, demod demodula t es it s columns.

x = demod(y,Fc,Fs,'pwm','centered') finds the pulse widths assumingthey are centered a t the beginn ing of each per iod. x is lengthlength(y)*Fc/Fs.

fm Frequency demodu lation . Demodula t es the FM waveform bymodula t ing the Hilber t t ransform of y by a complex exponent ia lof frequency –Fc Hz and obta ins the instan taneous frequency ofthe resu lt .

pm Phase demodu lation . Demodula tes the PM waveform bymodula t ing the Hilber t t ransform of y by a complex exponent ia lof frequency –Fc Hz and obta ins the inst an taneous phase of theresu lt .

ptm Pulse -t ime demodu lation . Finds the pulse t imes of a pu lse-t imemodula ted signa l y. For cor rect demodula t ion , the pu lses cannotover lap. x is length length(t)*Fc/Fs.

pwm Pu lse -w idth demodu lation . Finds the pulse widths of apu lse-width modula t ed signal y. demod retu rns in x a vector whoseelement s specify the width of each pulse in fract ions of a per iod.The pu lses in y should st a r t a t the beginn ing of each ca r r ierper iod, tha t is, they should be left just ified.

qam Quadrature amplitude demodu lation .[x1,x2] = demod(y,Fc,Fs,'qam') mult iplies y by a cosine and asine of frequency Fc and applies a fifth -order But t erwor thlowpass filt er using filtfilt:

x1 = y.*cos(2*pi*Fc*t);x2 = y.*sin(2*pi*Fc*t);[b,a] = butter(5,Fc*2/Fs);x1 = filtfilt(b,a,x1);x2 = filtfilt(b,a,x2);

Page 420: MATLAB Signal Processing Toolbox user manual

demod

6-116

See Also modulate Modula t ion for communica t ions simula t ion .vco Voltage cont rolled oscilla tor.

Page 421: MATLAB Signal Processing Toolbox user manual

dftmtx

6-117

6dftmtxPurpose Discret e Fourier t ransform mat r ix.

Syntax A = dftmtx(n)

Description A discrete Fourier transform matrix is a complex mat r ix of va lues around theunit circle, whose mat r ix product with a vector computes the discret e Four iert ransform of the vector .

A = dftmtx(n) retu rns the n-by-n complex mat r ix A tha t , when mult iplied intoa length n column vector x:

y = A*x

computes the discret e Four ier t ransform of x.

The inverse discret e Four ier t ransform matr ix is

Ai = conj(dftmtx(n))/n

Example In pract ice, the discrete Four ier t ransform is computed more efficien t ly anduses less memory with an FFT algor ithm

x = 1:256;y1 = fft(x);

than by using the Four ier t ransform matr ix:

n = length(x);y2 = x*dftmtx(n);norm(y1–y2)

ans = 1.8297e-009

Algorithm dftmtx uses an outer product to genera te the t ransform mat r ix.

See Also convmtx Convolu t ion matr ix.fft One-dimensiona l fast Four ier t ransform.

Page 422: MATLAB Signal Processing Toolbox user manual

diric

6-118

6dir icPurpose Dir ich let or per iodic sinc funct ion .

Syntax y = diric(x,n)

Description y = diric(x,n) retu rns a vector or a r ray y t he same size as x. The elementsof y a re the Dir ich let funct ion of the element s of x. n must be a posit ive in teger .

The Dir ich let funct ion , or per iodic sinc funct ion , is

for any nonzero in teger n. Th is funct ion has per iod 2π for n odd and per iod 4πfor n even . It s peak va lue is 1, and it s min imum value is -1 for n even . Themagnitude of th is funct ion is (1/n) t imes the magnitude of the discret e-t imeFour ier t ransform of the n-poin t rect angular window.

Diagnostics If n is not a posit ive in t eger , diric gives the following er ror message:

Requires n to be a positive integer.

See Also

dir ic x n,( )1–x2π------- n 1–( )

x 0 2π± 4π± …, , ,=

n x 2⁄( )sinn x 2⁄( )sin---------------------------- else⎩⎪⎨⎪⎧

=

cos Cosine of vector /matr ix elements (see the onlineMATLAB Function Reference).

gauspuls Gaussian-modula t ed sinusoida l pu lse genera tor.pulstran Pulse t ra in genera tor.rectpuls Sampled aperiodic rect angle genera tor.sawtooth Sawtooth or t r iangle wave genera tor.sin Sine of vector /matr ix elements (see the online

MATLAB Function Reference).sinc Sinc or sin(πt )/πt funct ion .square Square wave genera tor.tripuls Sampled aperiodic t r iangle genera tor.

Page 423: MATLAB Signal Processing Toolbox user manual

dpss

6-119

6dpssPurpose Discrete prola t e spheroida l sequences (Slepian sequences).

Syntax [e,v] = dpss(n,nw)[e,v] = dpss(n,nw,k)[e,v] = dpss(n,nw,[k1 k2])[e,v] = dpss(n,nw,'spline')[e,v] = dpss(n,nw,'spline',Ni)[e,v] = dpss(n,nw,'linear')[e,v] = dpss(n,nw,'linear',Ni)[e,v] = dpss(...,'trace')[e,v] = dpss(...,'int','trace')

Description [e,v] = dpss(n,nw) genera tes the fir st 2*nw discrete prolate spheroidalsequences (DPSS) of length n in the columns of e, and their cor respondingconcen t ra t ions in vector v. They are a lso genera ted in the DPSS MAT-fileda tabase dpss.mat. nw must be less than n/2.

[e,v] = dpss(n,nw,k) retu rns the k most band-limit ed sequences of the 2*nwdiscrete prola t e spheroida l sequences ca lcu la t ed. k must be between 0 and2*nw.

[e,v] = dpss(n,nw,[k1 k2]) retu rns the k1-th through the k2-th sequencesfrom the 2*nw discret e prola te spheroida l sequences ca lcu la t ed, where1 ≤ k1 ≤ k2 ≤ (2*nw).

For a ll of the above forms,

• The Slepian sequences are ca lcu la ted direct ly.• The sequences are genera t ed in the frequency band |ω| ≤ (2πW), where W = nw/n is t he ha lf-bandwidth and ω is in radians.

• e(:,1) is the length n signa l most concent ra ted in the frequency band|ω| ≤ (2πW) radians, e(:,2) is the signa l or thogona l to e(:,1) t ha t is mostconcent ra t ed in th is band, e(:,3) is the signa l or thogonal to both e(:,1)and e(:,2) t ha t is most concent ra ted in th is band, etc.

• For mult itaper spect ra l ana lysis, typica l choices for nw are 2, 5/2, 3, 7/2, or 4.

[e,v] = dpss(n,nw,'spline') uses spline in terpola t ion to compute e and vfrom the sequences in dpss.mat with length closest to n.

Page 424: MATLAB Signal Processing Toolbox user manual

dpss

6-120

[e,v] = dpss(n,nw,'spline',Ni) in terpola tes from exist ing length Nisequences.

[e,v] = dpss(n,nw,'linear') and

[e,v] = dpss(n,nw,'linear',Ni) use linear in terpola t ion , which is muchfaster but less accura t e than spline in terpola t ion . 'linear' requires Ni > n.

[e,v] = dpss(...,'trace') and

[e,v] = dpss(...,'int','trace') use a t ra iling 'trace' a rgument to findout which method DPSS uses, where 'int' is either 'spline' or 'linear'.

See Also

References [1] Perciva l, D.B., and A.T. Walden . S pectral Analysis for PhysicalApplications:Multitaper and Conven tional Univariate Techniques . Cambr idge:Cambr idge University Press, 1993.

dpssclear Remove discrete prola te spheroida l sequences fromdatabase.

dpssdir Discrete prola te spheroida l sequences da tabasedirectory.

dpssload Load discrete prola t e spheroida l sequences fromdatabase.

dpsssave Save discrete prola t e spheroida l sequences inda tabase.

pmtm Power spect rum est ima te using the mult it apermethod (MTM).

Page 425: MATLAB Signal Processing Toolbox user manual

dpssclear

6-121

6dpssclearPurpose Remove discrete prola t e spheroida l sequences from database.

Syntax dpssclear(n,nw)

Description dpssclear(n,nw) removes sequences with length n and t ime-bandwidthproduct nw from the DPSS MAT-file da tabase dpss.mat.

See Also dpss Discrete prola te spheroida l sequences (Slepiansequences).

dpssdir Discrete prola te spheroida l sequences da tabasedirectory.

dpssload Load discrete prola te spheroida l sequences fromdatabase.

dpsssave Save discrete prola te spheroida l sequences inda tabase.

Page 426: MATLAB Signal Processing Toolbox user manual

dpssdir

6-122

6dpssdirPurpose Discrete prola te spheroida l sequences da tabase directory.

Syntax dpssdirdpssdir(n)dpssdir(nw,'nw')dpssdir(n,nw)index = dpssdir

Description dpssdir manages the da tabase directory tha t conta ins the genera t ed DPSSsamples in the DPSS MAT-file da tabase dpss.mat.

dpssdir list s the directory of saved sequences in dpss.mat.

dpssdir(n) list s the sequences saved with length n.

dpssdir(nw,'nw') list s the sequences saved with t ime-bandwidth product nw.

dpssdir(n,nw) list s the sequences saved with length n and t ime-bandwidthproduct nw.

index = dpssdir is a st ructure ar ray descr ibing the DPSS database. Pass n and nw opt ions as for the no outpu t case to get a filtered index.

See Also dpss Discrete prola te spheroida l sequences (Slepiansequences).

dpssclear Remove discrete prola te spheroida l sequences fromdatabase.

dpssload Load discrete prola t e spheroida l sequences fromdatabase.

dpsssave Save discrete prola t e spheroida l sequences inda tabase.

Page 427: MATLAB Signal Processing Toolbox user manual

dpssload

6-123

6dpssloadPurpose Load discrete prola te spheroida l sequences from database.

Syntax [e,v] = dpssload(n,nw)

Description [e,v] = dpssload(n,nw) loads a ll sequences with length n andt ime-bandwidth product nw in the columns of e and their cor respondingconcen t ra t ions in vector v from the DPSS MAT-file da tabase dpss.mat.

See Also dpss Discrete prola te spheroida l sequences (Slepiansequences).

dpssclear Remove discrete prola te spheroida l sequences fromdatabase.

dpssdir Discrete prola te spheroida l sequences da tabasedirectory.

dpsssave Save discrete prola te spheroida l sequences inda tabase.

Page 428: MATLAB Signal Processing Toolbox user manual

dpsssave

6-124

6dpsssavePurpose Save discrete prola te spheroida l sequences in da tabase.

Syntax dpsssave(nw,e,v)status = dpsssave(nw,e,v)

Description dpsssave(nw,e,v) saves the sequences in the columns of e and theircor responding concen t ra t ions in vector v in the DPSS MAT-file da tabasedpss.mat.

• It is not necessa ry to specify sequence length , because the length of thesequence is determined by the number of rows of e.

• nw is the tim e-bandwidth product tha t was specified when the sequence wascrea ted using dpss.

status = dpsssave(nw,e,v) retu rns 0 if the save was successful and 1 if therewas an er ror .

See Also dpss Discrete prola te spheroida l sequences (Slepiansequences).

dpssclear Remove discrete prola te spheroida l sequences fromdatabase.

dpssdir Discrete prola te spheroida l sequences da tabasedirectory.

dpssload Load discrete prola t e spheroida l sequences fromdatabase.

Page 429: MATLAB Signal Processing Toolbox user manual

ellip

6-125

6ellipPurpose Ellipt ic (Cauer ) filt er design .

Syntax [b,a] = ellip(n,Rp,Rs,Wn)[b,a] = ellip(n,Rp,Rs,Wn,'ftype')[b,a] = ellip(n,Rp,Rs,Wn,'s')[b,a] = ellip(n,Rp,Rs,Wn,'ftype','s')[z,p,k] = ellip(...)[A,B,C,D] = ellip(...)

Description ellip designs lowpass, bandpass, h ighpass, and bandstop digita l and ana logellipt ic filt ers. Ellipt ic filter s offer steeper rolloff cha racter ist ics thanBut t erwor th or Chebyshev filter s, bu t are equ ir ipple in both the pass- andstopbands. In genera l, ellipt ic filt ers meet given per formance specifica t ionswith the lowest order of any filter type.

Digital Domain

[b,a] = ellip(n,Rp,Rs,Wn) designs an order n lowpass digita l ellipt ic filterwith cu toff frequency Wn, Rp dB of r ipple in the passband, and a stopband Rs dBdown from the peak value in the passband. It returns the filter coefficients in thelength n + 1 row vectors b and a, with coefficients in descending powers of z:

The cu toff frequency is the edge of the passband, a t which the magnituderesponse of the filter is –Rp dB. For ellip, the cu toff frequency Wn is a numberbetween 0 and 1, where 1 cor responds to ha lf the sample frequency (Nyquistfrequency). Smaller va lues of passband r ipple Rp and larger va lues of stopbandat tenuat ion Rs both lead to wider t ransit ion widths (sha llower rolloffcharact er ist ics).

If Wn is a two-element vector , Wn = [w1 w2], ellip retu rns an order 2*nbandpass filter with passband w1 < < w2.

[b,a] = ellip(n,Rp,Rs,Wn,'ftype') designs a h ighpass or bandstop filter ,where ftype is:

H z( ) B z( )A z( )----------- b 1( ) b 2( )z 1– L b n 1+( )z n–+ + +

1 a 2( )z 1– L a n 1+( )z n–+ + +---------------------------------------------------------------------------------= =

ω

Page 430: MATLAB Signal Processing Toolbox user manual

ellip

6-126

• high for a h ighpass digit a l filter with cu toff frequency Wn• stop for an order 2*n bandstop digita l filter if Wn is a two-element vector ,Wn = [w1 w2]

The stopband is w1 < ω < w2.With differen t numbers of ou tput argument s, ellip direct ly obta ins otherrea liza t ions of the filter . To obta in zero-pole-ga in form, use three outpu ta rguments:

[z,p,k] = ellip(n,Rp,Rs,Wn) or

[z,p,k] = ellip(n,Rp,Rs,Wn,'ftype') retu rns the zeros and poles in lengthn column vectors z and p and the gain in the sca la r k.

To obta in sta te-space form, use four ou tpu t arguments:

[A,B,C,D] = ellip(n,Rp,Rs,Wn) or

[A,B,C,D] = ellip(n,Rp,Rs,Wn,'ftype') where A, B, C, and D are

and u is the inpu t , x is the st a te vector , and y is the ou tpu t .

Analog Domain

[b,a] = ellip(n,Rp,Rs,Wn,'s') designs an order n lowpass ana log ellipt icfilt er with cu toff frequency Wn and retu rns the filter coefficien ts in the lengthn + 1 row vectors b and a, in descending powers of s:

The cu toff frequency is the edge of the passband, a t which the magnituderesponse of the filter is –Rp dB. For ellip, the cu toff frequency Wn must begrea ter than 0.

If Wn is a two-element vector with w1 < w2, t hen ellip(n,Rp,Rs,Wn,'s')retu rns an order 2*n bandpass ana log filter with passband w1 < ω < w2.

x n 1+[ ] Ax n[ ] B u n[ ]+=y n[ ] Cx n[ ] Du n[ ]+=

H s( ) B s( )A s( )----------- b 1( )sn b 2( )sn 1– L b n 1+( )+ + +

sn a 2( )sn 1– L a n 1+( )+ + +----------------------------------------------------------------------------------= =

Page 431: MATLAB Signal Processing Toolbox user manual

ellip

6-127

[b,a] = ellip(n,Rp,Rs,Wn,'ftype','s') designs a h ighpass or bandstopfilt er , where ftype is:

• high for a h ighpass ana log filter with cu toff frequency Wn• stop for an order 2*n bandstop ana log filter . Wn is a two-element vector , [w1 w2], specifying the stopband w1 < ω < w2.

With differen t numbers of ou tpu t argument s, ellip direct ly obta ins otherrea liza t ions of the ana log filter . To obta in zero-pole-ga in form, use three outpu ta rgument s:

[z,p,k] = ellip(n,Rp,Rs,Wn,'s') or

[z,p,k] = ellip(n,Rp,Rs,Wn,'ftype','s') retu rns the zeros and poles inlength n or 2*n column vectors z and p and the gain in the sca la r k.

To obta in sta te-space form, use four ou tpu t a rguments:

[A,B,C,D] = ellip(n,Rp,Rs,Wn,'s') or

[A,B,C,D] = ellip(n,Rp,Rs,Wn,'ftype','s') where A, B, C, and D a re

and u is the input , x is the st a te vector , and y is the output .

Examples For da ta sampled at 1000 Hz, design a sixth-order lowpass ellipt ic filter with acu toff frequency of 300 Hz, 3 dB of r ipple in the passband, and 50 dB ofa t tenuat ion in the stopband:

[b,a] = ellip(6,3,50,300/500);

x· Ax B u+=y Cx Du+=

Page 432: MATLAB Signal Processing Toolbox user manual

ellip

6-128

The filt er ’s frequency response is

freqz(b,a,512,1000)title('n=6 Lowpass Elliptic Filter')

0 50 100 150 200 250 300 350 400 450 500-600

-400

-200

0

200

Frequency (Hertz)

Phas

e (d

egre

es)

0 50 100 150 200 250 300 350 400 450 500-100

-80

-60

-40

-20

0

Frequency (Hertz)

Mag

nitu

de R

espo

nse

(dB)

n = 6 Lowpass Elliptic Filter

Page 433: MATLAB Signal Processing Toolbox user manual

ellip

6-129

Design a 20th-order bandpass ellipt ic filt er with a passband from 100 to 200 Hzand plot it s impulse response:

n = 10; Rp = 0.5; Rs = 20;Wn = [100 200]/500;[b,a] = ellip(n,Rp,Rs,Wn);[y,t] = impz(b,a,101); stem(t,y)title('Impulse Response of n=10 Elliptic Filter')

Limitations For h igh order filter s, the st a te-space form is the most numer ica lly accura t e,followed by the zero-pole-ga in form. The t ransfer funct ion form is the leastaccura t e; numer ica l problems can ar ise for filter orders a s low as 15.

Algorithm The design of ellipt ic filt ers is the most difficu lt and computa t iona lly in t ensiveof the But t erwor th , Chebyshev type I and II, and ellipt ic designs. ellip uses afive-step a lgor ithm:

1 It finds the lowpass ana log prototype poles, zeros, and ga in using theellipap funct ion .

2 It conver ts the poles, zeros, and ga in in to sta t e-space form.3 It t ransforms the lowpass filt er to a bandpass, h ighpass, or bandstop filt erwith the desired cu toff frequencies using a sta t e-space t ransformat ion.

0 10 20 30 40 50 60 70 80 90 100-0.2

-0.15

-0.1

-0.05

0

0.05

0.1

0.15

0.2Impulse Response of n = 10 Elliptic Filter

Page 434: MATLAB Signal Processing Toolbox user manual

ellip

6-130

4 For digita l filt er design , ellip uses bilinear to conver t the ana log filterin to a digit a l filter through a bilinea r t ransforma t ion with frequencyprewarping. Carefu l frequency adjustment gua ran tees tha t the ana logfilter s and the digita l filt er s will have the same frequency responsemagnitude a t Wn or w1 and w2.

5 It conver t s the st a te-space filt er back to t ransfer funct ion or zero-pole-ga inform, as requ ired.

See Also besself Bessel ana log filter design .butter But terwor th ana log and digita l filt er design.cheby1 Chebyshev type I filter design (passband r ipple).cheby2 Chebyshev type II filter design (stopband r ipple).ellipap Ellipt ic ana log lowpass filt er prototype.ellipord Ellipt ic filt er order select ion .

Page 435: MATLAB Signal Processing Toolbox user manual

ellipap

6-131

6ellipapPurpose Ellipt ic analog lowpass filter prototype.

Syntax [z,p,k] = ellipap(n,Rp,Rs)

Description [z,p,k] = ellipap(n,Rp,Rs) returns the zeros, poles, and ga in of an order nellipt ic analog lowpass filter prototype, with Rp dB of r ipple in the passband,and a stopband Rs dB down from the peak va lue in the passband. The zeros andpoles are returned in length n column vectors z and p and the ga in in sca la r k.If n is odd, z is length n – 1. The t ransfer funct ion is

Ellipt ic filter s a re equir ipple in both the passband and stopband. They offersteeper rolloff character ist ics than But terwor th and Chebyshev filter s, bu tthey are equir ipple in both the passband and the stopband. Of the four classica lfilt er types, ellipt ic filter s usua lly meet a given set of filter per formancespecifica t ions with the lowest filt er order .

ellip sets the cutoff frequency of the ellipt ic filt er to 1 for a normalizedresu lt . The cu toff frequency is the frequency a t which the passband ends andthe filt er has a magnitude response of 10-Rp/20.

Algorithm ellipap uses the a lgor ithm out lined in [1]. It employs the M-file ellipk toca lcula te the complete ellipt ic in tegra l of the fir st kind and the M-file ellipjto ca lcu la t e J acobi ellipt ic funct ions.

See Also

References [1] Parks, T.W., and C.S. Burrus. Digital Filter Design . New York: J ohn Wiley& Sons, 1987. Chapter 7.

H s( ) z s( )p s( )---------- k s z 1( )–( ) s z 2( )–( )Ls z n( )–( )

s p 1( )–( ) s p 2( )–( )Ls p n( )–( )-----------------------------------------------------------------------------= =

ω0

besselap Bessel ana log lowpass filter prototype.buttap But terwor th analog lowpass filter prototype.cheb1ap Chebyshev type I ana log lowpass filt er prototype.cheb2ap Chebyshev type II ana log lowpass filter prototype.ellip Ellipt ic (Cauer ) filt er design.

Page 436: MATLAB Signal Processing Toolbox user manual

ellipord

6-132

6ellipordPurpose Ellipt ic filt er order select ion.

Syntax [n,Wn] = ellipord(Wp,Ws,Rp,Rs)[n,Wn] = ellipord(Wp,Ws,Rp,Rs,'s')

Description ellipord selects the minimum order digit a l or ana log ellipt ic filter required tomeet a set of lowpass filt er design specifica t ions:

Digital Domain

[n,Wn] = ellipord(Wp,Ws,Rp,Rs) retu rns the order n of the lowest orderellipt ic filt er tha t loses no more than Rp dB in the passband and has a t leastRs dB of a t tenuat ion in the stopband. The passband runs from 0 to Wp and thestopband extends from Ws to 1, the Nyquist frequency. ellipord a lso returnsWn, the cu toff frequency tha t a llows ellip to ach ieve the given specifica t ions.

Use ellipord for lowpass, h ighpass, bandpass, and bandstop filt er s. Forh ighpass filter s, Wp is grea t er than Ws. For bandpass and bandstop filter s, Wpand Ws are two-element vectors tha t specify the corner frequencies a t bothedges of the filter , lower frequency edge fir st . For the band filter s, ellipordretu rns Wn as a two-element row vector for inpu t to ellip.

If filter specifica t ions ca ll for a bandpass or bandstop filter with unequal r ipplein each of the passbands or stopbands, design the filt er as separa t e lowpass andhighpass sect ions and cascade the two filter s together .

Wp Passband corner frequency. Wp, the cu toff frequency, has a va luebetween 0 and 1, where 1 cor responds to ha lf the samplingfrequency (the Nyquist frequency).

Ws Stopband corner frequency. Ws is in the same unit s a s Wp; it ha s ava lue between 0 and 1, where 1 corresponds to ha lf the samplingfrequency (the Nyquist frequency).

Rp Passband r ipple, in decibels. This va lue is the maximumpermissible passband loss in decibels. The passband is 0 < w < Wp.

Rs Stopband at tenua t ion , in decibels. Th is va lue is the number ofdecibels the stopband is down from the passband. The stopbandis Ws < w < 1.

Page 437: MATLAB Signal Processing Toolbox user manual

ellipord

6-133

Analog Domain

[n,Wn] = ellipord(Wp,Ws,Rp,Rs,'s') finds the minimum order n and cutofffrequencies Wn for an ana log filt er . In th is case the frequencies in Wp and Ws arein radians per second and may be grea ter than 1.

Use ellipord for lowpass, h ighpass, bandpass, and bandstop filt ers asdescr ibed under “Digita l Domain .”

Page 438: MATLAB Signal Processing Toolbox user manual

ellipord

6-134

Examples For 1000 Hz da ta , design a lowpass filt er with less than 3 dB of a t tenuat ionfrom 0 to 100 Hz and at lea st 15 dB of a t tenuat ion from 150 Hz to the Nyquistfrequency:

Wp = 100/500; Ws = 150/500;Rp = 3; Rs = 15;[n,Wn] = ellipord(Wp,Ws,Rp,Rs)

n = 2

Wn = 0.2000

[b,a] = ellip(n,Rp,Rs,Wn);freqz(b,a,512,1000);title('n=2 Elliptic Lowpass Filter')

0 50 100 150 200 250 300 350 400 450 500-200

-150

-100

-50

0

50

Frequency (Hertz)

Phas

e (d

egre

es)

0 50 100 150 200 250 300 350 400 450 500-80

-60

-40

-20

0

Frequency (Hertz)

Mag

nitu

de R

espo

nse

(dB)

n = 2 Elliptic Lowpass Filter

Page 439: MATLAB Signal Processing Toolbox user manual

ellipord

6-135

Now design a bandpass filter with a passband from 90 Hz to 200 Hz, less than3 dB of r ipple th roughout the passband, and 30 dB stopbands 50 Hz out on bothsides of the passband:

Wp = [90 200]/500; Ws = [50 250]/500;Rp = 3; Rs = 30;[n,Wn] = ellipord(Wp,Ws,Rp,Rs)

n = 3

Wn = 0.1800 0.4000

[b,a] = ellip(n,Rp,Rs,Wn);freqz(b,a,512,1000);title('n=3 Elliptic Bandpass Filter')

Algorithm ellipord uses the ellipt ic lowpass filter order predict ion formula descr ibed in[1]. The funct ion per forms it s ca lcula t ions in the ana log domain for both theana log and digit a l cases. For the digit a l ca se, it conver t s the frequency

0 50 100 150 200 250 300 350 400 450 500-400

-200

0

200

400

Frequency (Hertz)

Phas

e (d

egre

es)

0 50 100 150 200 250 300 350 400 450 500-300

-200

-100

0

Frequency (Hertz)

Mag

nitu

de R

espo

nse

(dB)

n = 3 Elliptic Bandpass Filter

Page 440: MATLAB Signal Processing Toolbox user manual

ellipord

6-136

parameters to the s-doma in before the order and na tura l frequency est imat ionprocess, then conver ts them back to the z-domain.

ellipord in it ia lly develops a lowpass filter prototype by t ransforming thepassband frequencies of the desired filt er to 1 rad/sec (for low- and highpassfilt ers) and to -1 and 1 rad/sec (for bandpass and bandstop filters). It thencomputes the min imum order requ ired for a lowpass filter to meet the stopbandspecifica t ion .

See Also

References [1] Rabiner , L.R., and B. Gold. Theory and Application of Digital S ignalProcessing. Englewood Cliffs, NJ : Prent ice-Hall, 1975. Pg. 241.

buttord But terwor th filt er order select ion.cheb1ord Chebyshev type I filter order select ion .cheb2ord Chebyshev type II filter order select ion.ellip Ellipt ic (Cauer ) filt er design .

Page 441: MATLAB Signal Processing Toolbox user manual

fft

6-137

6fftPurpose One-dimensiona l fa st Four ier t ransform.

Syntax y = fft(x)y = fft(x,n)

Description fft computes the discrete Four ier t ransform of a vector or ma tr ix. Thisfunct ion implement s the t ransform given by

where WN = e-j(2π/N) and N = length(x). Note tha t the ser ies is indexed asn + 1 and k + 1 instead of the usua l n and k because MATLAB vectors run from1 to N inst ead of from 0 to N -1.

y = fft(x) is the discrete Four ier t ransform of vector x, computed with a fa stFour ier t ransform (FFT) a lgor ithm. If x is a matr ix, y is the FFT of each columnof the matr ix. The fft funct ion employs a radix-2 fast Four ier t ransformalgor ithm if the length of the sequence is a power of two, and a slowera lgor ithm if it is not ; see the “Algor ithm” sect ion for deta ils.

y = fft(x,n) is the n-poin t FFT. If the length of x is less than n, fft pads xwith t ra iling zeros to length n. If the length of x is grea ter than n, fft t runca testhe sequence x. If x is an ar ray, fft adjusts the length of the columns in thesame manner .

The fft funct ion is pa r t of the st andard MATLAB language.

Example A common use of the Four ier t ransform is to find the frequency components ofa t ime-domain signa l bur ied in noise. Consider da ta sampled a t 1000 Hz. Form

X k 1+( ) x n 1+( )Wnk n

n 0=

N 1–

∑=

Page 442: MATLAB Signal Processing Toolbox user manual

fft

6-138

a signa l consist ing of 50 Hz and 120 Hz sinusoids and corrupt the signa l withzero-mean random noise:

t = 0:0.001:0.6;x = sin(2*pi*50*t) + sin(2*pi*120*t);y = x + 2*randn(1,length(t));plot(y(1:50))

It is difficu lt to iden t ify the frequency components by studying the or igina lsigna l. Conver t to the frequency domain by taking the discrete Four iert ransform of the noisy signa l y using a 512-point fa st Four ier t ransform (FFT):

Y = fft(y,512);

The power spect ra l density, a measurement of the energy a t var iousfrequencies, is

Pyy = Y.*conj(Y) / 512;

0 5 10 15 20 25 30 35 40 45 50-6

-5

-4

-3

-2

-1

0

1

2

3

4

Page 443: MATLAB Signal Processing Toolbox user manual

fft

6-139

Graph the fir st 256 poin ts (the other 256 poin t s a re symmet r ic) on ameaningfu l frequency axis:

f = 1000*(0:255)/512;plot(f,Pyy(1:256))

See the pwelch funct ion for deta ils on ca lcula t ing spect ra l density.

Somet imes it is usefu l to normalize the outpu t of fft so tha t a un it sinusoid inthe t ime domain cor responds to unit amplitude in the frequency domain . Toproduce a normalized discrete-t ime Four ier t ransform in th is manner , use

Pn = abs(fft(x))*2/length(x)

Algorithm fft is a bu ilt -in MATLAB funct ion . When the sequence length is a power oftwo, fft uses a h igh-speed radix-2 fast Four ier t ransform a lgor ithm. Theradix-2 FFT rout ine is opt imized to per form a rea l FFT if the inpu t sequence ispurely rea l; otherwise it computes the complex FFT. This causes a rea lpower-of-two FFT to be about 40% fast er than a complex FFT of the samelength .

When the sequence length is not an exact power of two, a separa t e a lgor ithmfinds the pr ime factors of the sequence length and computes the mixed-radixdiscret e Fourier t ransforms of the short er sequences.

0 100 200 300 400 5000

10

20

30

40

50

60

70

Page 444: MATLAB Signal Processing Toolbox user manual

fft

6-140

The execu t ion t ime for fft depends on the sequence length . If the length of asequence has many pr ime factors, the funct ion computes the FFT quickly; ifthe length has few pr ime factors, execu t ion is slower . For sequences whoselengths are pr ime numbers, fft uses the raw (and slow) DFT algor ithm. Forthis reason it is usua lly bet ter to use power-of-two FFTs, if th is is suppor ted byyour applica t ion . For example, on one machine a 4096-poin t rea l FFT takes 2.1seconds and a complex FFT of the same length takes 3.7 seconds. The FFTs ofneighboring sequences of length 4095 and 4097, however , take 7 seconds and58 seconds, respect ively.

Suppose a sequence x of N poin ts is obta ined a t a sample frequency of . Then ,for up to the Nyquist frequency, or poin t n =N / 2 + 1, the rela t ionship betweenthe actua l frequency and the index k in to x (ou t of N possible indices) is

See Also

f s

f k 1–( ) f s∗ N=

dct Discret e cosine t ransform (DCT).dftmtx Discret e Four ier t ransform mat r ix.fft2 Two-dimensiona l fa st Four ier t ransform.fftshift Rear range the outpu ts of fft and fft2.filter Filt er da ta with a recursive (IIR) or nonrecursive

(FIR) filter.freqz Frequency response of digita l filter s.ifft One-dimensiona l inverse fast Fourier t ransform.pwelch Est imate the power spect ra l density (PSD) of a signa l

using Welch’s method.

Page 445: MATLAB Signal Processing Toolbox user manual

fft2

6-141

6fft2Purpose Two-dimensiona l fast Four ier t ransform.

Syntax Y = fft2(X)Y = fft2(X,m,n)

Description Y = fft2(X) per forms a two-dimensiona l FFT, producing a resu lt Y the samesize as X. If X is a vector , Y has the same or ien ta t ion as X.

Y = fft2(X,m,n) t runca tes or zero pads X, if necessary, to crea te an m-by-nar ray before per forming the FFT. The resu lt Y is a lso m-by-n.

The fft2 funct ion is pa r t of the st andard MATLAB language.

Algorithm fft2(x) is simply

fft(fft(x).').'

This computes the one-dimensiona l fft of each column of x, then of each rowof the resu lt . The t ime required to compute fft2(x) depends on the number ofpr ime factors in [m,n] = size(x). fft2 is fa st est when m and n are powers of 2.

See Also fft One-dimensiona l fast Four ier t ransform.fftshift Rear range the outpu ts of fft and fft2.ifft One-dimensiona l inverse fa st Four ier t ransform.ifft2 Two-dimensiona l inverse fast Four ier t ransform.

Page 446: MATLAB Signal Processing Toolbox user manual

fftfilt

6-142

6fft filtPurpose FFT-based FIR filt er ing using the over lap-add method.

Syntax y = fftfilt(b,x)y = fftfilt(b,x,n)

Description fftfilt filt ers da ta using the efficien t FFT-based method of overlap-add , afrequency domain filt er ing technique tha t works on ly for FIR filt ers.

y = fftfilt(b,x) filter s the da ta in vector x with the filt er descr ibed bycoefficien t vector b. It r etu rns the da ta vector y. The opera t ion per formed byfftfilt is descr ibed in the tim e dom ain by the difference equa t ion

An equiva lent representat ion is the z-t ransform or frequency dom ain descr ipt ion

By defau lt , fftfilt chooses an FFT length and da ta block length tha tguarantee efficien t execut ion t ime.

y = fftfilt(b,x,n) uses an FFT length of nfft = 2^nextpow2(n) and a datablock length of nfft – length(b) + 1.

fftfilt works for both rea l and complex inputs.

Example Show tha t the result s from fftfilt and filter are ident ica l:

b = [1 2 3 4];x = [1 zeros(1,99)]';norm(fftfilt(b,x) – filter(b,1,x))

ans = 9.5914e–15

Algorithm fftfilt uses fft t o implement the overlap-add m ethod [1], a techn ique tha tcombines successive frequency domain filtered blocks of an input sequence.fftfilt breaks an input sequence x in to length L da ta blocks:

y n( ) b 1( )x n( ) b 2( )x n 1–( ) L b n b 1+( )x n n b–( )+ + +=

Y z( ) b 1( ) b 2( )z 1– L b n b 1+( )z n b–+ + +( )X z( )=

xL 2L 3L ceil(nx/L)*L

. . .

Page 447: MATLAB Signal Processing Toolbox user manual

fftfilt

6-143

and convolves each block with the filter b by

y = ifft(fft(x(i:i+L–1),nfft).*fft(b,nfft));

where nfft is the FFT length . fftfilt over laps successive outpu t sect ions bynb–1 poin ts, where nb is the length of the filter , and sums them:

fftfilt chooses the key parameters L and nfft in differen t ways, dependingon whether you supply an FFT length n and on the lengths of the filt er andsigna l. If you do not specify a va lue for n (which determines FFT length),fftfilt chooses these key parameters au toma t ica lly:

• If length(x) > length(b), fftfilt chooses va lues tha t min imize thenumber of blocks t imes the number of flops per FFT.

• If length(b) >= length(x), fftfilt uses a single FFT of length

2^nextpow2(length(b) + length(x) – 1)

This essent ia lly computesy = ifft(fft(B,nfft).*fft(X,nfft))

If you supply a va lue for n, fftfilt chooses an FFT length , nfft, of2^nextpow2(n)and a data block length of nfft – length(b) + 1. If n is lessthan length(b), fftfilt sets n t o length(b).

See Also

References [1] Oppenheim, A.V., and R.W. Schafer . Discrete-T im e S ignal Processing.Englewood Cliffs, NJ : Prent ice Hall, 1989.

nb–1L

nb–12L

nb–13L. . .

conv Convolu t ion and polynomia l mult iplica t ion .filter Filt er da ta with a recursive (IIR) or nonrecursive

(FIR) filter.filtfilt Zero-phase digit a l filter ing.

Page 448: MATLAB Signal Processing Toolbox user manual

fftshift

6-144

6fft sh iftPurpose Rear range the ou tpu ts of the FFT funct ions.

Syntax y = fftshift(x)

Description y = fftshift(x) rea r ranges the outpu t s of fft and fft2 by moving the zerofrequency component to the cen ter of the spect rum, which is somet imes a moreconvenien t form.

For vectors, fftshift(x) retu rns a vector with the left and r igh t ha lvesswapped.

For ar rays, fftshift(x) swaps quadran ts one and three with quadran ts twoand four .

The fftshift funct ion is par t of the standa rd MATLAB language.

Example For any ar ray X,

Y = fft2(x)

has Y(1,1) = sum(sum(X)); the DC component of the signa l is in the upper-leftcorner of the two-dimensiona l FFT. For

Z = fftshift(Y)

t he DC component is near the cen ter of the mat r ix.

See Also fft One-dimensiona l fast Four ier t ransform.fft2 Two-dimensiona l fa st Four ier t ransform.

Page 449: MATLAB Signal Processing Toolbox user manual

filter

6-145

6filt erPurpose Filter da ta with a recursive (IIR) or nonrecursive (FIR) filter .

Syntax y = filter(b,a,x)[y,zf] = filter(b,a,x)[...] = filter(b,a,x,zi)[...] = filter(b,a,x,zi,dim)

Description filter filter s rea l or complex data using a digita l filt er . The filter rea liza t ionis the transposed direct form II st ructure [1], which can handle both FIR andIIR filt er s.

If a(1) ≠ 1, filter normalizes the filt er coefficien t s by a(1). If a(1) = 0, the inpu tis in er ror .

y = filter(b,a,x) filter s the da ta in vector x with the filt er descr ibed bycoefficien t vectors a and b to crea t e the filtered da ta vector y. When x is amat r ix, filter opera tes on the columns of x. When x is an N -dimensiona l a r ray,filt er opera tes on the fir st non-singleton dimension .

[y,zf] = filter(b,a,x) retu rns the fina l va lues of the sta t es in the vectorzf.

[...] = filter(b,a,x,zi) specifies in it ia l sta te condit ions in the vector zi.

The size of the in it ia l/fina l condit ion vector is max(length(b),length(a))–1.zi or zf can also be an ar ray of such vectors, one for each column of x if x is amat r ix. If x is a mult idimensiona l ar ray, filter works across the fir stnonsingleton dimension of x by defau lt .

[...] = filter(b,a,x,zi,dim) works across the dimension dim of x. Set zito empty to get the defau lt in it ia l condit ions.

The filter funct ion is par t of the standard MATLAB language.

Page 450: MATLAB Signal Processing Toolbox user manual

filter

6-146

Example Find and graph the 100-poin t un it impulse response of a digita l filt er :

x = [1 zeros(1,100)];[b,a] = butter(12,400/1000);y = filter(b,a,x);stem(y)

Algorithm filter is implemented as a t ransposed direct form II st ructure

where n -1 is the filter order .

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)z1(m)z2(m)

Σ z -1

b(n)

–a(n)zn -1(m)

...

...

...

Page 451: MATLAB Signal Processing Toolbox user manual

filter

6-147

The opera t ion of filter a t sample m is given by the t ime domain differenceequat ions for y and the st a tes z i:

You can use filtic to genera te the sta te vector z i(0) from past inpu ts andou tpu ts.

The input -ou tpu t descr ipt ion of th is filter ing opera t ion in the z-t r ansformdomain is a ra t iona l t ransfer funct ion :

Diagnostics If a(1) = 0, filter gives the following er ror message:

First denominator coefficient must be nonzero.

If the length of the in it ia l condit ion vector is not the grea ter of na and nb,filter gives the following er ror message:

Initial condition vector has incorrect dimensions.

See Also

References [1] Oppenheim, A.V., and R.W. Schafer . Discrete-T im e S ignal Processing.Englewood Cliffs, NJ : Prent ice Hall, 1989. Pgs. 311-312.

y m( ) b 1( )x m( ) z1 m 1–( ) a 1( )y m( )–+=

z1 m( ) b 2( )x m( ) z2 m 1–( ) a 2( )y m( )–+=

M M=zn 2– m( ) b n 1–( )x m( ) zn 1– m 1–( ) a n 1–( )y m( )–+=

zn 1– m( ) b n( )x m( ) a n( )y m( )–=

Y z( ) b 1( ) b 2( )z 1– L b n b 1+( )z n b–+ + +a 1( ) a 2( )z 1– L a n a 1+( )z n a–+ + +-----------------------------------------------------------------------------------------X z( )=

fftfilt FFT-based FIR filter ing using the over lap-addmethod.

filter2 Two-dimensiona l digita l filt er ing.filtfilt Zero-phase digit a l filter ing.filtic Make in it ia l condit ions for filter funct ion .

Page 452: MATLAB Signal Processing Toolbox user manual

filter2

6-148

6filt er2Purpose Two-dimensiona l digita l filt er ing.

Syntax Y = filter2(B,X)Y = filter2(B,X,'shape')

Description Y = filter2(B,X) filter s the two-dimensiona l da ta in X with thetwo-dimensiona l FIR filt er in the mat r ix B. The resu lt , Y, is computed usingtwo-dimensiona l convolut ion and is the same size as X.

Y = filter2(B,X,'shape') retu rns Y computed with size specified by shape:

• same retu rns the cen t ra l par t of the convolu t ion tha t is the same size as X(default ).

• full retu rns the fu ll two-dimensiona l convolu t ion , size(Y) > size(X).• valid retu rns only those pa r t s of the convolu t ion tha t are computed withoutthe zero-padded edges, size(Y) < size(X).

The filter2 funct ion is par t of the standa rd MATLAB language.

Algorithm The filter2 funct ion uses conv2 t o compute the fu ll two-dimensiona lconvolu t ion of the FIR filter with the input ma tr ix. By defau lt , filter2ext ract s and returns the cent ra l pa r t of the convolu t ion tha t is the same size asthe input matr ix. Use the shape pa rameter to specify an a lterna te par t of theconvolu t ion for retu rn .

See Also conv2 Two-dimensiona l convolu t ion .filter Filt er da ta with a recursive (IIR) or nonrecursive

(FIR) filter.

Page 453: MATLAB Signal Processing Toolbox user manual

filtfilt

6-149

6filt filtPurpose Zero-phase digit a l filter ing.

Syntax y = filtfilt(b,a,x)

Description y = filtfilt(b,a,x) per forms zero-phase digita l filt er ing by processing theinput da ta in both the forward and reverse direct ions (see problem 5.39 in [1]).After filt er ing in the forward direct ion , it reverses the filt ered sequence andruns it back through the filter . The resu lt ing sequence has precisely zero-phasedistor t ion and double the filt er order . filtfiltminimizes st a r t -up and endingt ransien ts by matching in it ia l condit ions, and works for both rea l and complexinputs.

Note tha t filtfilt should not be used with different ia tor and Hilber t F IRfilt ers, since the opera t ion of these filt ers depends heavily on their phaseresponse.

Algorithm filtfilt is an M-file tha t uses the filter funct ion . In addit ion to theforward-reverse filter ing, it a t t empt s to minimize sta r tup t ransient s byadjust ing in it ia l condit ions to match the DC component of the signa l and byprepending severa l filt er lengths of a flipped, reflected copy of the input signa l.

See Also

References [1] Oppenheim, A.V., and R.W. Schafer . Discrete-T im e S ignal Processing.Englewood Cliffs, NJ : Prent ice Hall, 1989. Pgs. 311-312.

fftfilt FFT-based FIR filter ing using the over lap-addmethod.

filter Filt er da ta with a recursive (IIR) or nonrecursive(FIR) filter.

filter2 Two-dimensiona l digita l filt er ing.

Page 454: MATLAB Signal Processing Toolbox user manual

filtic

6-150

6filt icPurpose Find in it ia l condit ions for a t ransposed direct form II filter implementa t ion .

Syntax z = filtic(b,a,y,x)z = filtic(b,a,y)

Description z = filtic(b,a,y,x) finds the in it ia l condit ions z for the delays in thetransposed direct form II filt er implementa t ion given past outpu ts y and inputsx. The vectors b and a represen t the numera tor and denomina tor coefficien ts,respect ively, of the filter ’s t ransfer funct ion .

The vectors x and y conta in the most recen t inpu t or ou tpu t fir st , and oldestinpu t or outpu t last :

where nb is length(b)–1 (the numera tor order ) and na is length(a)–1 (thedenomina tor order ). If length(x) is less than nb, filtic pads it with zeros tolength nb; if length(y) is less than na, filtic pads it with zeros to length na.E lements of x beyond x(nb–1) and elements of y beyond y(na–1) areunnecessa ry so filtic ignores them.

Outpu t z is a column vector of length equa l to the la rger of nb and na .z descr ibes the sta te of the delays given past inpu t s x and past outpu ts y.

z = filtic(b,a,y) assumes tha t the inpu t x is 0 in the past .

The t ransposed direct form II st ructure is

where n -1 is the filter order .

filtic works for both rea l and complex inputs.

x x 1–( ) x 2–( ) x 3–( ) … x n b–( ) …, , , , ,{ }=y y 1–( ) y 2–( ) y 3–( ) … y n– a( ) …, , , , ,{ }=

Σ Σ Σz -1 z -1

x(m)

y(m)

b(3) b(2) b(1)

–a(3) –a(2)z1(m)z2(m)

Σ z -1

b(n)

–a(n)zn -1(m)

...

...

...

Page 455: MATLAB Signal Processing Toolbox user manual

filtic

6-151

Algorithm filtic performs a reverse difference equa t ion to obta in the delay sta t es z.

Diagnostics If any of the inpu t argument s y, x, b, or a is not a vector (tha t is, if anyargument is a sca la r or ar ray), filtic gives the following er ror message:

Requires vector inputs.

See Also

References [1] Oppenheim, A.V., and R.W. Schafer . Discrete-T im e S ignal Processing.Englewood Cliffs, NJ : Prent ice Hall, 1989. Pgs. 296, 301-302.

filter Filt er da ta with a recursive (IIR) or nonrecursive(FIR) filter.

filtfilt Zero-phase digit a l filter ing.

Page 456: MATLAB Signal Processing Toolbox user manual

fir1

6-152

6fir1Purpose Window-based fin ite impulse response filter design – standa rd response.

Syntax b = fir1(n,Wn)b = fir1(n,Wn,'ftype')b = fir1(n,Wn,window)b = fir1(n,Wn,'ftype',window)b = fir1(...,'noscale')

Description fir1 implements the classica l method of windowed linear -phase FIR digita lfilt er design [1]. It designs filters in st andard lowpass, bandpass, h ighpass, andbandpass configura t ions. (For windowed filt ers with arbit ra ry frequencyresponse, use fir2.)

b = fir1(n,Wn) retu rns row vector b conta ining the n+1 coefficien t s of anorder n lowpass FIR filter . This is a Hamming-windowed, linear -phase filterwith cu toff frequency Wn. The outpu t filt er coefficien t s, b, a re ordered indescending powers of z:

Wn, the cu toff frequency, is a number between 0 and 1, where 1 cor responds toha lf the sampling frequency (the Nyquist frequency).

If Wn is a two-element vector , Wn = [w1 w2], fir1 retu rns a bandpass filter withpassband w1 < ω < w2.

If Wn is a mult i-element vector , Wn = [w1 w2 w3 w4 w5 ... wn], fir1 retu rnsan order n mult iband filt er with bands 0 < ω < w1, w1 < ω < w2, ..., wn < ω < 1.

By defau lt , the filter is sca led so tha t the cen ter of the fir st pa ssband hasmagnitude exact ly 1 after windowing.

b = fir1(n,Wn,'ftype') specifies a filt er type, where ftype is

• high for a h ighpass filt er with cu toff frequency Wn• stop for a bandstop filt er , if Wn = [w1 w2]The stopband is w1 < ω < w2.

• 'DC-1' t o make the fir st band of a mult iband filt er a passband• 'DC-0' t o make the fir st band of a mult iband filt er a stopband

B z( ) b 1( ) b 2( )z 1– L b n 1+( )z n–+ + +=

Page 457: MATLAB Signal Processing Toolbox user manual

fir1

6-153

fir1 a lways uses an even filter order for the h ighpass and bandstopconfigura t ions. This is because for odd orders, t he frequency response a t theNyquist frequency is 0, which is inappropr ia te for h ighpass and bandstopfilt er s. If you specify an odd-va lued n, fir1 increments it by 1.

b = fir1(n,Wn,window) uses the window specified in column vector windowfor the design. The vector window must be n+1 elements long. If no window isspecified, fir1 employs a Hamming window.

b = fir1(n,Wn,'ftype',window) accept s both ftype and window parameters.

b = fir1(...,'noscale') tu rns off the defau lt sca ling.

The group delay of the FIR filter designed by fir1 is n/2.

Algorithm fir1 uses the window method of FIR filt er design [1]. If w (n ) denotes a window,where 1 ≤ n ≤ N , and the impulse response of the idea l filt er is h (n ), whereh (n ) is the inverse Four ier t ransform of the idea l frequency response, then thewindowed digita l filt er coefficien ts are given by

b n( ) w n( )h n( ) 1 n N≤ ≤,=

Page 458: MATLAB Signal Processing Toolbox user manual

fir1

6-154

Examples Example 1Design a 48th-order FIR bandpass filt er with passband 0.35 ≤ w ≤ 0.65:

b = fir1(48,[0.35 0.65]);freqz(b,1,512)

Example 2The chirp.mat file conta ins a signa l, y, tha t has most of it s power above Fs/4,or ha lf the Nyquist frequency. Design a 34th-order FIR highpass filter toa t tenua te the components of the signa l below Fs/4. Use a cu toff frequency of0.48 and a Chebyshev window with 30 dB of r ipple:

load chirp % loads y and Fsb = fir1(34,0.48,'high',chebwin(35,30));yfilt = filter(b,1,y);

0 0.2 0.4 0.6 0.8 1−2500

−2000

−1500

−1000

−500

0

Normalized Angular Frequency (×π rads/sample)

Phas

e (d

egre

es)

0 0.2 0.4 0.6 0.8 1−100

−50

0

50

Normalized Angular Frequency (×π rads/sample)

Mag

nitu

de (d

B)

Page 459: MATLAB Signal Processing Toolbox user manual

fir1

6-155

Check the spect ra of the or igina l and filtered signa ls.

[Py,fy] = pburg(y,10,512,Fs);[Pyfilt,fyfilt] = pburg(yfilt,10,512,Fs);plot(fy,10*log10(Py),':',fyfilt,10*log10(Pyfilt)); gridylabel('Magnitude (dB)'); xlabel('Frequency (Hz)');legend('Chirp','Filtered Chirp')

Play the two signa ls using sound.

sound(y,Fs);sound(yfilt,Fs);

Diagnostics If n is odd and you specify a bandstop or h ighpass filt er , fir1 gives thefollowing warn ing message:

For highpass and bandstop filters, N must be even.Order is being increased by 1.

0 500 1000 1500 2000 2500 3000 3500 4000 4500−140

−130

−120

−110

−100

−90

−80

−70

−60

−50

−40

Mag

nitu

de (d

B)

Frequency (Hz)

Chirp Filtered Chirp

Page 460: MATLAB Signal Processing Toolbox user manual

fir1

6-156

See Also

References [1] IEEE. Program s for Digital S ignal Processing. IEEE Press. New York: J ohnWiley & Sons, 1979. Algor ithm 5.2.

filter Filt er da ta with a recursive (IIR) or nonrecursive(FIR) filter.

fir2 Window-based fin it e impulse response filt erdesign—arbit ra ry response.

fircls Const ra ined least square FIR filter design formult iband filter s.

fircls1 Const ra ined least square filt er design for lowpassand highpass linear phase FIR filt ers.

firls Least square linear-phase FIR filter design .freqz Frequency response of digita l filter s.kaiserord Est imate parameters for fir1 with Ka iser window.remez Parks-McClellan opt ima l FIR filter design .

Page 461: MATLAB Signal Processing Toolbox user manual

fir2

6-157

6fir2Purpose Window-based finite impulse response filter design – a rbit ra ry response.

Syntax b = fir2(n,f,m)b = fir2(n,f,m,window)b = fir2(n,f,m,npt)b = fir2(n,f,m,npt,window)b = fir2(n,f,m,npt,lap)b = fir2(n,f,m,npt,lap,window)

Description fir2 designs windowed digita l F IR filters with a rbit ra r ily shaped frequencyresponse. (For standard lowpass, bandpass, h ighpass, and bandstopconfigura t ions, use fir1.)

b = fir2(n,f,m) retu rns row vector b conta ining the n+1 coefficien t s of anorder n FIR filt er . The frequency-magnitude charact er ist ics of th is filt er matchthose given by vectors f and m:

• f is a vector of frequency poin t s in the range from 0 to 1, where 1 cor respondsto ha lf the sampling frequency (the Nyquist frequency). The fir st poin t of fmust be 0 and the last poin t 1. The frequency poin ts must be in increasingorder .

• m is a vector conta in ing the desired magnitude response a t the point sspecified in f.

• f and m must be the same length .•Duplica te frequency point s are a llowed, cor responding to st eps in thefrequency response.

Use plot(f,m) t o view the filt er shape.

The outpu t filter coefficien ts, b, a re ordered in descending powers of z:

b = fir2(n,f,m,window) uses the window specified in column vector windowfor the filter design . The vector windowmust be n+1 elements long. If no windowis specified, fir2 employs a Hamming window.

b z( ) b 1( ) b 2( )z 1– L b n 1+( )z n–+ + +=

Page 462: MATLAB Signal Processing Toolbox user manual

fir2

6-158

b = fir2(n,f,m,npt) and

b = fir2(n,f,m,npt, window) specify the number of point s npt for the gr idon to which fir2 in terpola tes the frequency response, with or without a windowspecifica t ion .

b = fir2(n,f,m,npt,lap) and

b = fir2(n,f,m,npt,lap,window) specify the size of the region , lap, tha tfir2 inser t s around duplica te frequency poin ts, with or without a windowspecifica t ion .

See the “Algor ithm” sect ion for more on npt and lap.

Algorithm The desired frequency response is in terpola ted on to a dense, even ly spaced gr idof length npt. npt is 512 by defau lt . If two successive va lues of f are the same,a region of lap point s is set up around th is frequency to provide a smooth butsteep t ransit ion in the request ed frequency response. By defau lt , lap is 25. Thefilt er coefficien ts a re obta ined by applying an inverse fast Four ier t ransform tothe gr id and mult iplying by a window; by defau lt , th is is a Hamming window.

Page 463: MATLAB Signal Processing Toolbox user manual

fir2

6-159

Example Design a 30th-order lowpass filt er and overplot the desired frequency responsewith the actua l frequency response:

f = [0 0.6 0.6 1]; m = [1 1 0 0];b = fir2(30,f,m);[h,w] = freqz(b,1,128);plot(f,m,w/pi,abs(h))

See Also

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 10

0.2

0.4

0.6

0.8

1

1.2

butter But terwor th analog and digita l filt er design .cheby1 Chebyshev type I filter design (passband r ipple).cheby2 Chebyshev type II filter design (stopband r ipple).ellip Ellipt ic (Cauer ) filt er design.fir1 Window-based fin ite impulse response filter design –

standard response.maxflat Genera lized digita l But terwor th filt er design .remez Parks-McClellan opt imal FIR filter design .yulewalk Recursive digit a l filt er design.

Page 464: MATLAB Signal Processing Toolbox user manual

fircls

6-160

6fir clsPurpose Const ra ined least square FIR filter design for mult iband filt ers.

Syntax b = fircls(n,f,amp,up,lo)fircls(n,f,amp,up,lo,'design_flag')

Description b = fircls(n,f,amp,up,lo) genera t es a length n+1 linea r phase FIR filter b.The frequency-magnitude character ist ics of th is filt er match those given byvectors f and amp:

• f is a vector of t ransit ion frequencies in the range from 0 to 1, where 1cor responds to ha lf the sampling frequency (the Nyquist frequency). The fir stpoin t of f must be 0 and the last poin t 1. The frequency poin ts must be inincreasing order .

• amp is a vector descr ibing the piecewise constan t desired amplitude of thefrequency response. The length of amp is equa l to the number of bands in theresponse and shou ld be equal to length(f)–1.

• up and lo are vectors with the same length as amp. They define the upper andlower bounds for the frequency response in each band.

fircls(n,f,amp,up,lo,'design_flag') enables you to monitor the filterdesign , where design_flag can be:

• trace, for a t extua l display of the design er ror a t each itera t ion st ep.• plots, for a collect ion of plots showing the filter ’s fu ll-band magnituderesponse and a zoomed view of the magnitude response in each sub-band. Allplot s a re updated a t each it era t ion step.

• both, for both the textua l display and plots.

Page 465: MATLAB Signal Processing Toolbox user manual

fircls

6-161

Example Design an order 50 bandpass filt er :

n = 50;f = [0 0.4 0.8 1];amp = [0 1 0];up = [0.02 1.02 0.01];lo = [–0.02 0.98 –0.01];b = fircls(n,f,amp,up,lo,'plots'); % plots magnitude response

NOTE Normally, the lower va lue in the stopband will be specified asnega t ive. By set t ing lo equa l to 0 in the stopbands, a nonnega t ive frequencyresponse amplitude can be obta ined. Such filt ers can be spect ra lly factored toobta in minimum phase filter s.

Algorithm The a lgor ithm is a mult iple exchange a lgor ithm tha t uses Lagrangemult iplier s and Kuhn-Tucker condit ions on each itera t ion .

0 0.2 0.4 0.6 0.8 1 1.2 1.4-2

0

2

0 0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4-0.02

00.02

Band

#1

0.4 0.45 0.5 0.55 0.6 0.65 0.7 0.75 0.80.98

11.02

Band

#2

0.8 0.85 0.9 0.95 1-0.01

00.01

Band

#3

Frequency

Page 466: MATLAB Signal Processing Toolbox user manual

fircls

6-162

See Also

References [1] Selesn ick, I.W., M. Lang, and C.S. Burrus. “Const ra ined Least SquareDesign of FIR Filt er s without Specified Transit ion Bands.” Proceed ings of theIEEE Int. Conf. Acoust., S peech , S ignal Processing. Vol. 2 (May 1995).Pgs. 1260-1263.

[2] Selesn ick, I.W., M. Lang, and C.S. Burrus. “Const ra ined Least SquareDesign of FIR Filter s withou t Specified Transit ion Bands.” IEEE Transactionson S ignal Processing, Vol. 44, No. 8 (August 1996).

fircls1 Const ra ined least square filt er design for lowpassand highpass linear phase FIR filt ers.

firls Least square linear-phase FIR filter design .remez Parks-McClellan opt ima l FIR filter design .

Page 467: MATLAB Signal Processing Toolbox user manual

fircls1

6-163

6fir cls1Purpose Const ra ined least square filter design for lowpass and highpass linear phaseFIR filter s.

Syntax b = fircls1(n,wo,dp,ds)b = fircls1(n,wo,dp,ds,'high')b = fircls1(n,wo,dp,ds,wt)b = fircls1(n,wo,dp,ds,wt,'high')b = fircls1(n,wo,dp,ds,wp,ws,k)b = fircls1(n,wo,dp,ds,wp,ws,k,'high')b = fircls1(n,wo,dp,ds,…,'design_flag')

Description b = fircls1(n,wo,dp,ds) genera t es a lowpass FIR filt er b. n+1 is t he filterlength , wo is the normalized cu toff frequency in the range between 0 and 1(where 1 cor responds to ha lf the sampling frequency, tha t is, the Nyquistfrequency), dp is the maximum passband devia t ion from 1 (passband r ipple),and ds is the maximum stopband devia t ion from 0 (stopband r ipple).

b = fircls1(n,wo,dp,ds,'high') genera tes a h ighpass FIR filter b.

b = fircls1(n,wo,dp,ds,wt) and

b = fircls1(n,wo,dp,ds,wt,'high') specify a frequency wt above which (forwt>wo) or below which (for wt<wo) the filter is guaranteed to meet the givenband cr iter ion. This will help you design a filter tha t meet s a passband orstopband edge requ irement . There are four cases:

• Lowpass: - 0<wt<wo<1: the amplitude of the filt er is with in dp of 1 over the frequencyrange 0 < < wt.

- 0<wo<wt<1: the amplitude of the filt er is with in ds of 0 over the frequencyrange wt < < 1.

•Highpass:- 0<wt<wo<1: the amplitude of the filt er is with in ds of 0 over the frequencyrange 0 < < wt.

- 0<wo<wt<1: the amplitude of the filt er is with in dp of 1 over the frequencyrange wt < < 1.

ω

ω

ω

ω

Page 468: MATLAB Signal Processing Toolbox user manual

fircls1

6-164

b = fircls1(n,wo,dp,ds,wp,ws,k) generates a lowpass FIR filter b with aweighted funct ion . n+1 is the filter length, wo is the normalized cutoff frequency,dp is the maximum passband deviat ion from 1 (passband ripple), and ds is themaximum stopband deviat ion from 0 (stopband ripple). wp is the passband edgeof the L2 weight funct ion and ws is the stopband edge of the L2 weight function,where wp < wo < ws. k is the rat io (passband L2 error)/(stopband L2 error):

b = fircls1(n,wo,dp,ds,wp,ws,k,'high') genera tes a h ighpass FIR filt er bwith a weighted funct ion , where ws < wo < wp.

b = fircls1(n,wo,dp,ds,…,'design_flag') enables you to monitor the filterdesign , where design_flag can be

• trace, for a t extua l display of the design table used in the design• plots, for plots of the filter ’s magnitude, group delay, and zeros and poles• both, for both the textua l display and plots

NOTE In the design of very na r row band filter s with small dp and ds, theremay not exist a filt er of the given length tha t meets the specifica t ions.

A ω( ) D ω( )– 2 ωd0

w p

A ω( ) D ω( )– 2 ωdw s

π

∫------------------------------------------------------ k=

Page 469: MATLAB Signal Processing Toolbox user manual

fircls1

6-165

Example Design an order 55 lowpass filter with a cu toff frequency a t 0.3:

n = 55; wo = 0.3;dp = 0.02; ds = 0.008;b = fircls1(n,wo,dp,ds,'plots'); % plot magnitude response

Algorithm The a lgor ithm is a mult iple exchange a lgor ithm tha t uses Lagrangemult iplier s and Kuhn-Tucker condit ions on each itera t ion .

See Also

References [1] Selesnick, I.W., M. Lang, and C.S. Burrus. “Const ra ined Least SquareDesign of FIR Filt ers without Specified Transit ion Bands.” Proceed ings of theIEEE In t. Conf. Acoust., S peech , S ignal Processing. Vol. 2 (May 1995).Pgs. 1260-1263.

[2] Selesnick, I.W., M. Lang, and C.S. Burrus. “Const ra ined Least SquareDesign of FIR Filt ers without Specified Transit ion Bands.” IEEE Transactionson S ignal Processing, Vol. 44, No. 8 (August 1996).

0 0.2 0.4 0.6 0.8 10

0.5

1

0 0.05 0.1 0.15 0.2 0.25-0.04-0.02

00.020.04

0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

-0.01

0

0.01

fircls Const ra ined least square FIR filter design formult iband filter s.

firls Least square linear-phase FIR filter design .remez Parks-McClellan opt imal FIR filter design .

Page 470: MATLAB Signal Processing Toolbox user manual

firls

6-166

6fir lsPurpose Least square linear -phase FIR filter design .

Syntax b = firls(n,f,a)b = firls(n,f,a,w)b = firls(n,f,a,'ftype')b = firls(n,f,a,w,'ftype')

Description firls designs a linear -phase FIR filt er tha t minimizes the weighted,in t egra t ed squared er ror between an idea l piecewise linea r funct ion and themagnitude response of the filter over a set of desired frequency bands.

b = firls(n,f,a) retu rns row vector b conta in ing the n+1 coefficien t s of theorder n FIR filter whose frequency-amplitude cha racter ist ics approximatelyma tch those given by vectors f and a. The outpu t filt er coefficien t s, or “taps,”in b obey the symmet ry rela t ion

These are type I (n odd) and type II (n even) linea r -phase filter s. Vectors f anda specify the frequency-amplitude cha racter ist ics of the filter :

• f is a vector of pa irs of frequency poin ts, specified in the range between 0 and1, where 1 cor responds to ha lf the sampling frequency (the Nyquistfrequency). The frequencies must be in increasing order . Duplica te frequencypoin t s are a llowed and, in fact , can be used to design a filter exact ly the sameas those retu rned by the fir1 and fir2 funct ions with a rectangular orboxcar window.

• a is a vector conta in ing the desired amplitude a t the poin t s specified in f.

The desired amplitude funct ion a t frequencies between pa irs of poin ts (f(k ),f(k+1)) for k odd is the line segment connect ing the poin ts (f(k ), a(k )) and(f(k+1), a(k+1)).The desired amplitude funct ion a t frequencies between pa irs of poin ts (f(k ),f(k+1)) for k even is unspecified. These a re t ransit ion or “don’t care” regions.

• f and a a re the same length . This length must be an even number .

b k( ) b n 2 k–+( ) k 1= … n 1+, , ,=

Page 471: MATLAB Signal Processing Toolbox user manual

firls

6-167

The rela t ionship between the f and a vectors in defin ing a desired amplituderesponse is

b = firls(n,f,a,w) uses the weigh ts in vector w to weight the fit in eachfrequency band. The length of w is ha lf the length of f and a, so there is exact lyone weigh t per band.

b = firls(n,f,a,'ftype') and

b = firls(n,f,a,w,'ftype') specify a filter type, where ftype is

• hilbert for linear -phase filt er s with odd symmetry (type III and type IV)The outpu t coefficien ts in b obey the rela t ion b(k ) = -b(n + 2 - k ),k = 1, ..., n + 1. This class of filt er s includes the Hilber t t ransformer , whichhas a desired amplitude of 1 across the en t ire band.

• differentiator for type III and type IV filt ers, using a specia l weight ingtechniqueFor nonzero amplitude bands, the in tegra ted squa red er ror has a weight of(1/f)2 so tha t the er ror a t low frequencies is much sma ller than a t h ighfrequencies. For FIR differen t ia tors, which have an amplitude cha racter ist icpropor t iona l to frequency, the filter s min imize the rela t ive in tegra tedsquared er ror (the int egra l of the squa re of the ra t io of the er ror to thedesired amplitude).

1.0

0.0

Desired amplituderesponse (a)

Normalizedfrequency (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.70.0 0.8 0.9 1.0 (Nyquist)

Page 472: MATLAB Signal Processing Toolbox user manual

firls

6-168

Examples Design an order 255 lowpass filt er with t ransit ion band:

b = firls(255,[0 0.25 0.3 1],[1 1 0 0]);

Design a 31 coefficien t different ia tor :

b = firls(30,[0 0.9],[0 0.9],'differentiator');

Design a 24th-order ant i-symmetr ic filt er with piecewise linear passbands andplot the desired and actua l frequency response:

F = [0 0.3 0.4 0.6 0.7 0.9]; A = [0 1 0 0 0.5 0.5];b = firls(24,F,A,'hilbert');for i=1:2:6, plot([F(i) F(i+1)],[A(i) A(i+1)],'– –'), hold onend[H,f] = freqz(b,1,512,2);plot(f,abs(H)), grid on, hold off

Algorithm Reference [1] descr ibes the theoret ica l approach tha t firls t akes. The funct ionsolves a system of linear equa t ions involving an inner product mat r ix of sizeroughly n/2 using MATLAB’s \ opera tor .

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 10

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

1

Page 473: MATLAB Signal Processing Toolbox user manual

firls

6-169

This funct ion designs type I, II, III, and IV linea r -phase filter s. Type I and IIa re the defau lt s for n even and odd respect ively, while the 'hilbert' and'differentiator' flags produce type III (n even) and IV (n odd) filt er s. Thevar ious filter types have differen t symmet r ies and const ra in t s on theirfrequency responses (see [2] for deta ils).

Diagnostics An appropr ia te diagnost ic message is displayed when incorrect a rguments a reused:

F must be even length.F and A must be equal lengths.Requires symmetry to be 'hilbert' or 'differentiator'.Requires one weight per band.Frequencies in F must be nondecreasing.Frequencies in F must be in range [0,1].

A more ser ious warning message is

Warning: Matrix is close to singular or badly scaled.

This t ends to happen when the filt er length t imes the t ransit ion width growsla rge. In th is case, the filter coefficien ts bmight not represen t the desired filter .You can check the filter by looking a t it s frequency response.

Linear Phase Filter Type

Filter Order n Symmetry of Coefficients

Response H(f), f = 0

Response H(f), f = 1 (Nyquist)

Type I Even even: No rest r ict ion No rest r ict ion

Type II Odd No rest r ict ion H (1) = 0

Type III Even odd: H (0) = 0 H (1) = 0

Type IV Odd H (0) = 0 No rest r ict ion

b k( ) b n 2 k–+( ) k 1= … n 1+, , ,=

b k( ) b– n 2 k–+( ) k 1= … n 1+, , ,=

Page 474: MATLAB Signal Processing Toolbox user manual

firls

6-170

See Also

References [1] Parks, T.W., and C.S. Burrus. Digital Filter Design . New York: J ohn Wiley& Sons, 1987. Pgs. 54-83.

[2] Oppenheim, A.V., and R.W. Schafer . Discrete-T im e S ignal Processing.Englewood Cliffs, NJ : Prent ice Hall, 1989. Pgs. 256-266.

fir1 Window-based fin it e impulse response filt er design –standard response.

fir2 Window-based fin it e impulse response filt er design –a rbit ra ry response.

firrcos Raised cosine FIR filt er design .remez Parks-McClellan opt ima l FIR filter design .

Page 475: MATLAB Signal Processing Toolbox user manual

firrcos

6-171

6fir r cosPurpose Raised cosine FIR filter design .

b = firrcos(n,F0,df,Fs)b = firrcos(n,F0,df)b = firrcos(n,F0,r,Fs,'rolloff')b = firrcos(...,'type')b = firrcos(...,'type',delay)b = firrcos(...,'type',delay,window)[b,a] = firrcos(...)

Description firrcos(n,F0,df,Fs) returns an order n lowpass linear -phase FIR filt er witha ra ised cosine t ransit ion band. The filter has cu toff frequency F0, t r ansit ionbandwidth df, and sampling frequency Fs, a ll in Her tz. df must be smallenough so tha t F0 ± df/2 is between 0 and Fs/2. The coefficien ts in b a renormalized so tha t the nomina l passband ga in is a lways equal to one.

firrcos(n,F0,df) uses a defau lt sampling frequency of Fs = 2.

b = firrcos(n,F0,r,Fs,'rolloff') in terpret s the th ird argument , r, as therolloff factor inst ead of the t ransit ion bandwidth , df. r must be in the range[0,1].

b = firrcos(...,'type') designs either a norma l ra ised cosine filt er or asquare root ra ised cosine filt er depending on the type specifica t ion , which canbe

• normal, for a regula r ra ised cosine filt er . This is the defau lt , and is a lso ineffect when the 'type' argument is left empty, [].

• sqrt, for a square root ra ised cosine filter .

b = firrcos(...,'type',delay) specifies an in teger delay in the range[0,n+1]. The defau lt is n/2 for even n and (n+1)/2 for odd n.

b = firrcos(...,'type',delay,window) applies a length n+1 window to thedesigned filter to reduce the r ipple in the frequency response. window must bea n+1 long column vector . If no window is specified, a boxcar (rect angula r )window is used. Care must be exercised when using a window with a delayother than the defau lt .

[b,a] = firrcos(...) a lways returns a = 1.

Page 476: MATLAB Signal Processing Toolbox user manual

firrcos

6-172

Example Design an order 20 ra ised cosine FIR filt er with cutoff frequency 0.25 of theNyquist frequency and a t ransit ion bandwidth of 0.25:

h = firrcos(20,0.25,0.25);freqz(h,1,'Fs',2,'phase','no')

See Also

0 0.2 0.4 0.6 0.8 1−120

−100

−80

−60

−40

−20

0

20

Frequency (Hz)

Mag

nitu

de (d

B)

fir1 Window-based fin it e impulse response filt er design –standard response.

fir2 Window-based fin it e impulse response filt er design –a rbit ra ry response.

firls Least square linear-phase FIR filter design .remez Parks-McClellan opt ima l FIR filter design .

Page 477: MATLAB Signal Processing Toolbox user manual

freqs

6-173

6freqsPurpose Frequency response of ana log filter s.

Syntax h = freqs(b,a,w)[h,w] = freqs(b,a)[h,w] = freqs(b,a,n)freqs(b,a)

Description freqs retu rns the complex frequency response H(jw) (Laplace t ransform) of anana log filt er :

given the numera tor and denomina tor coefficien ts in vectors b and a.

h = freqs(b,a,w) retu rns the complex frequency response of the ana log filt erspecified by coefficien t vectors b and a. freqs eva lua tes the frequency responsea long the imaginary axis in the complex plane a t the frequencies specified inrea l vector w.

[h,w] = freqs(b,a) au tomat ica lly picks a set of 200 frequency poin ts w onwhich to compute the frequency response h.

[h,w] = freqs(b,a,n) picks n frequencies on which to compute the frequencyresponse h.

freqs with no outpu t a rgument s plots the magnitude and phase responseversus frequency in the cur ren t figure window.

freqs works only for rea l input systems and posit ive frequencies.

H s( ) B s( )A s( )----------- b 1( )sn b b 2( )sn b 1– L b n b 1+( )+ + +

a 1( )sn a a 2( )sn a 1– L a n a 1+( )+ + +----------------------------------------------------------------------------------------------= =

Page 478: MATLAB Signal Processing Toolbox user manual

freqs

6-174

Example Find and graph the frequency response of the t ransfer funct ion given by

a = [1 0.4 1];b = [0.2 0.3 1];w = logspace(–1,1);freqs(b,a,w)

You can also crea te the plot with

h = freqs(b,a,w);mag = abs(h);phase = angle(h);subplot(2,1,1), loglog(w,mag)subplot(2,1,2), semilogx(w,phase)

To conver t to Her t z, degrees, and decibels, use

f = w/(2*pi);mag = 20*log10(mag);phase = phase*180/pi;

H s( ) 0.2s2 0.3 s 1+ +s2 0.4s 1+ +

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

10-1 100 10110-1

100

101

Frequency

Mag

nitu

de

10-1 100 101-150

-100

-50

0

Frequency

Phas

e (d

egre

es)

Page 479: MATLAB Signal Processing Toolbox user manual

freqs

6-175

Algorithm freqs eva lua tes the polynomia ls a t each frequency point , t hen divides thenumera tor response by the denomina tor response:

s = i*w;h = polyval(b,s)./polyval(a,s);

See Also abs Absolu te va lue (magnitude).angle Phase angle.freqz Frequency response of digita l filter s.invfreqs Cont inuous-t ime (ana log) filt er iden t ifica t ion from

frequency da ta .logspace Genera t e loga r ithmica lly spaced vectors (see the

online MATLAB Function Reference).polyval Polynomia l eva lua t ion (see the online MATLAB

Function Reference).

Page 480: MATLAB Signal Processing Toolbox user manual

freqspace

6-176

6freqspacePurpose Frequency spacing for frequency response.

Syntax f = freqspace(n)f = freqspace(n,'whole')[f1,f2] = freqspace(n)[f1,f2] = freqspace([m n])[x1,y1] = freqspace(n,'meshgrid')[x1,y1] = freqspace([m n],'meshgrid')

Description freqspace retu rns the implied frequency range for equa lly spaced frequencyresponses. This is usefu l when crea t ing frequency vectors for use with freqz.

f = freqspace(n) retu rns the frequency vector f assuming n even ly spacedpoin ts around the unit circle. For n even or odd, f is (0:2/n:1). For n even ,freqspace retu rns (n + 2)/2 poin t s. For N odd, it retu rns (n + 1)/2 point s.

f = freqspace(n,'whole') retu rns n even ly spaced poin ts around the wholeunit circle. In th is case, f is 0:2/n:2*(n–1)/n.

[f1,f2] = freqspace(n) retu rns the two-dimensiona l frequency vectors f1and f2 for an n-by-n matr ix. For n odd, both f1 and f2 are [–1 + 1/n:2/n:1–1/n]. For n even , both f1 and f2 are [–1:2/n:1–2/n].

[f1,f2] = freqspace([m n]) retu rns the two-dimensiona l frequency vectorsf1 and f2 for an m-by-n matr ix.

[x1,y1] = freqspace(n,'meshgrid') and

[x1,y1] = freqspace([m n],'meshgrid') a re equiva len t to

[f1,f2] = freqspace(...);[x1,y1] = meshgrid(f1,f2);

See the online MATLAB Function Reference for deta ils on the meshgridfunct ion .

See Also freqz Frequency response of digita l filter s.invfreqz Discret e-t ime filt er ident ifica t ion from frequency

data .

Page 481: MATLAB Signal Processing Toolbox user manual

freqz

6-177

6freqzPurpose Frequency response of digit a l filter s.

Syntax [h,w] = freqz(b,a,n)[h,f] = freqz(b,a,n,Fs)[h,w] = freqz(b,a,n,'whole')[h,f] = freqz(b,a,n,'whole',Fs)h = freqz(b,a,w)h = freqz(b,a,f,Fs)freqz(...)

Description freqz retu rns the complex frequency response H (ejω) of a digita l filter , giventhe (rea l or complex) numera tor and denomina tor coefficient s in vectors band a.

[h,w] = freqz(b,a,n) retu rns the n-poin t complex frequency response of thedigita l filt er

eva lua ted a t z=ejω given the coefficien t vectors b and a. freqz retu rns both h,the complex frequency response, and w, a vector conta in ing the n frequencypoin ts in un it s of rads/sample. freqz eva lua tes the frequency response a t npoin ts equa lly spaced a round the upper ha lf of the unit circle, so w conta ins npoin ts between 0 and π.

It is best , a lthough not necessa ry, to choose a va lue for n t ha t is an exact powerof two, because this a llows fast computa t ion using an FFT algor ithm. If you donot specify a va lue for n, it default s to 512.

[h,f] = freqz(b,a,n,Fs) specifies a posit ive sampling frequency Fs, inHer tz. The default for Fs is 1. It retu rns a vector f conta in ing the actua lfrequency poin ts between 0 and Fs/2 (the Nyquist frequency) a t which itca lcula ted the frequency response. f is of length n.

[h,w] = freqz(b,a,n,'whole') uses n poin ts a round the whole unit circle, sow has range [0,2π).

[h,f] = freqz(b,a,n,'whole',Fs) uses n poin t s a round the whole un itcircle, so f has range [0,Fs).

H z( ) B z( )A z( )----------- b 1( ) b 2( )z 1– L b n b 1+( )z n b–+ + +

a 1( ) a 2( )z 1– L a n a 1+( )z n a–+ + +-----------------------------------------------------------------------------------------= =

Page 482: MATLAB Signal Processing Toolbox user manual

freqz

6-178

h = freqz(b,a,w) retu rns the frequency response a t the frequencies in vectorw (specified in rads/sample).

h = freqz(b,a,f,Fs) retu rns the frequency response a t the frequencies invector f (specified in Hz).

freqz(...) with no outpu t a rguments plots the magnitude and phaseresponse versus frequency in the cur ren t figure window.

Examples Plot the magnitude and phase response of an FIR filter .

b = fir1(80,0.5,kaiser(81,8));freqz(b,1);

Algorithm freqz uses an FFT algor ithm when argument n is presen t . It computes thefrequency response as the ra t io of the t ransformed numera tor and denomina torcoefficien ts, padded with zeros to the desired length :

h = fft(b,n)./fft(a,n)

If n is not a power of two, the FFT a lgor ithm is not as efficien t and may causelong computa t ion t imes.

When a frequency vector w or f is presen t , or if n is less thanmax(length(b),length(a)), freqz evalua tes the polynomia ls a t eachfrequency poin t using Horner ’s method of polynomia l eva lua t ion and thendivides the numera tor response by the denomina tor response.

0 0.2 0.4 0.6 0.8 1−5000

−4000

−3000

−2000

−1000

0

Normalized Angular Frequency (×π rads/sample)

Phas

e (d

egre

es)

0 0.2 0.4 0.6 0.8 1−150

−100

−50

0

50

Normalized Angular Frequency (×π rads/sample)

Mag

nitu

de (d

B)

Page 483: MATLAB Signal Processing Toolbox user manual

freqz

6-179

See Also abs Absolu te va lue (magnitude).angle Phase angle.fft One-dimensiona l fast Four ier t ransform.filter Filt er da ta with a recursive (IIR) or nonrecursive

(FIR) filter.freqs Frequency response of ana log filter s.impz Impulse response of digita l filt er s.invfreqz Discret e-t ime filter ident ifica t ion from frequency

data .logspace Genera t e loga r ithmica lly spaced vectors (see the

online MATLAB Function Reference).

Page 484: MATLAB Signal Processing Toolbox user manual

gauspuls

6-180

6gauspulsPurpose Gaussian-modula t ed sinusoida l pu lse genera tor .

Syntax yi = gauspuls(t,fc,bw)yi = gauspuls(t,fc,bw,bwr)[yi,yq] = gauspuls(…)[yi,yq,ye] = gauspuls(…)tc = gauspuls('cutoff',fc,bw,bwr,tpe)

Description gauspuls genera tes Gaussian-modula ted sinusoida l pulses.

yi = gauspuls(t,fc,bw) retu rns a unity-amplitude Gaussian RF pulse a t thet imes indica t ed in a r ray t, with a cen ter frequency fc in Her tz and a fract iona lbandwidth bw, which must be grea ter than 0. The default va lue for fc is1000 Hz and for bw is 0.5.

yi = gauspuls(t,fc,bw,bwr) retu rns a unity-amplitude Gaussian RF pulsewith a fract iona l bandwidth of bw as measured a t a level of bwr dB with respectto the normalized signa l peak. The fract iona l bandwidth reference level bwr must be less than 0, because it indica tes a reference level less than the peak(un ity) envelope amplitude. The defau lt va lue for bwr is -6 dB.

[yi,yq] = gauspuls(…) retu rns both the in-phase and quadra ture pulses.

[yi,yq,ye] = gauspuls(…) retu rns the RF signa l envelope.

tc = gauspuls('cutoff',fc,bw,bwr,tpe) retu rns the cu toff t ime tc (grea terthan or equa l to 0) a t which the t ra iling pulse envelope fa lls below tpe dB withrespect to the peak envelope amplitude. The t ra iling pulse envelope level tpe must be less than 0, because it indica tes a reference level less than the peak(un ity) envelope amplitude. The defau lt va lue for tpe is -60 dB.

Remarks Defau lt va lues are subst itu t ed for empty or omit ted t ra iling input a rguments.

Page 485: MATLAB Signal Processing Toolbox user manual

gauspuls

6-181

Example Plot a 50 kHz Gaussian RF pulse with 60% bandwidth , sampled a t a ra te of1 MHz. Trunca te the pulse where the envelope fa lls 40 dB below the peak:

tc = gauspuls('cutoff',50e3,0.6,[],–40); t = –tc : 1e–6 : tc; yi = gauspuls(t,50e3,0.6); plot(t,yi)

See Also

-4 -2 0 2 4x 10-5

-0.8

-0.6

-0.4

-0.2

0

0.2

0.4

0.6

0.8

1

chirp Swept-frequency cosine genera tor.cos Cosine of vector /mat r ix element s (see the online

MATLAB Function Reference).diric Dir ich let or per iodic sinc funct ion .pulstran Pulse t ra in genera tor.rectpuls Sampled aper iodic rectangle genera tor.sawtooth Sawtooth or t r iangle wave genera tor.sin Sine of vector /matr ix elements (see the online

MATLAB Function Reference).sinc Sinc or sin (πt )/πt funct ion .square Square wave genera tor.tripuls Sampled aper iodic t r iangle genera tor.

Page 486: MATLAB Signal Processing Toolbox user manual

grpdelay

6-182

6grpdelayPurpose Average filter delay (group delay).

Syntax [gd,w] = grpdelay(b,a,n)[gd,f] = grpdelay(b,a,n,Fs)[gd,w] = grpdelay(b,a,n,'whole')[gd,f] = grpdelay(b,a,n,'whole',Fs)gd = grpdelay(b,a,w)gd = grpdelay(b,a,f,Fs)grpdelay(b,a)

Description The group delay of a filter is a measure of the average delay of the filter as afunct ion of frequency. It is the nega t ive fir st der iva t ive of the phase responseof the filter . If the complex frequency response of a filter is H (ejω), t hen thegroup delay is

where ω is frequency and θ is the phase angle of H(ejω).

[gd,w] = grpdelay(b,a,n) retu rns the n-poin t group delay, , of thedigit a l filt er

given the numera tor and denomina tor coefficien ts in vectors b and a. grpdelayretu rns both gd, the group delay, and w, a vector con ta in ing the n frequencypoin ts in radians. grpdelay eva lua tes the group delay a t n poin t s equallyspaced a round the upper ha lf of the unit circle, so w conta ins n poin ts between0 and π. A value for n tha t is an exact power of two allows fast computa t ionusing an FFT algor ithm.

[gd,f] = grpdelay(b,a,n,Fs) specifies a posit ive sampling frequency Fs inHer t z. It retu rns a length n vector f conta in ing the actua l frequency poin ts a twhich the group delay is ca lcu la ted, a lso in Her t z. f conta ins n poin t s between0 and Fs/2.

τg ω( )d θ ω( )dω---------------–=

τg ω( )

H z( ) B z( )A z( )----------- b 1( ) b 2( )z 1– L b n b 1+( )z n b–+ + +

a 1( ) a 2( )z 1– L a n a 1+( )z n a–+ + +-----------------------------------------------------------------------------------------= =

Page 487: MATLAB Signal Processing Toolbox user manual

grpdelay

6-183

[gd,w] = grpdelay(b,a,n,'whole') and

[gd,f] = grpdelay(b,a,n,'whole',Fs) use n poin ts a round the whole un itcircle (from 0 to 2π, or from 0 to Fs).

gd = grpdelay(b,a,w) and

gd = grpdelay(b,a,f,Fs) return the group delay eva lua ted a t the poin ts in w(in radians) or f (in Her tz), r espect ively, where Fs is the sampling frequency inHer tz.

grpdelay with no outpu t a rgument s plots the group delay versus frequency inthe cur rent figure window.

grpdelay works for both rea l and complex input syst ems.

Examples Plot the group delay of But t erwor th filt er b(z)/a(z):

[b,a] = butter(6,0.2);grpdelay(b,a,128)

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 10

2

4

6

8

10

12

Normalized frequency (Nyquist == 1)

Gro

up d

elay

(in

sam

ples

)

Page 488: MATLAB Signal Processing Toolbox user manual

grpdelay

6-184

Plot both the group and phase delays of a system on the same graph:

gd = grpdelay(b,a,512);gd(1) = []; % avoid NaNs[h,w] = freqz(b,a,512); h(1) = []; w(1) = [];pd = –unwrap(angle(h))./w;plot(w,gd,w,pd,':')xlabel('Frequency (rads/sec)'); grid;legend('Group Delay','Phase Delay');

Algorithm grpdelay mult iplies the filt er coefficien ts by a unit ramp. After Four iert ransformat ion , th is process cor responds to differen t ia t ion .

See Also

0 0.5 1 1.5 2 2.5 3 3.5−8

−6

−4

−2

0

2

4

6

8

10

12

Frequency (rads/sec)

Group DelayPhase Delay

cceps Complex cepst ra l ana lysis.fft One-dimensiona l fast Four ier t ransform.freqz Frequency response of digita l filter s.hilbert Hilber t t ransform.icceps Inverse complex cepst rum.rceps Real cepst rum and min imum phase reconst ruct ion.

Page 489: MATLAB Signal Processing Toolbox user manual

hamming

6-185

6hammingPurpose Hamming window.

Syntax w = hamming(n)w = hamming(n,sflag)

Description w = hamming(n) retu rns an n-poin t symmetr ica lly sampled Hamming windowin the column vector w. n should be a nonnegat ive in teger . The coefficien ts of aHamming window are

w = hamming(n,sflag) retu rns an n-poin t Hamming window using thewindow sampling specified by sflag, which can be either 'periodic' or'symmetric' (the defau lt ). When 'periodic' is specified, hamming computes alength n+1 window and returns the fir st n poin t s.

Diagnostics An error message is displayed when incor rect a rgument s a re used:

Order cannot be less than zero.Sampling must be either 'symmetric' or 'periodic'.

A warning message is displayed for nonin teger n:

Warning: Rounding order to nearest integer.

See Also

References [1] Oppenheim, A.V., and R.W. Schafer , Discrete-T im e S ignal Processing.Englewood Cliffs, NJ : Prent ice-Hall, 1989.

w k 1+[ ] 0.54 0.46 2π kn 1–-------------⎝ ⎠

⎛ ⎞cos– k 0= … n 1–, , ,=

bartlett Bar t let t window.blackman Blackman window.boxcar Rectangula r window.chebwin Chebyshev window.hanning Hanning window.kaiser Kaiser window.triang Tr iangular window.

Page 490: MATLAB Signal Processing Toolbox user manual

hanning

6-186

6hanningPurpose Hanning window.

Syntax w = hanning(n)w = hanning(n,sflag)

Description w = hanning(n) retu rns an n-poin t symmet r ica lly sampled Hanning windowin the column vector w. n shou ld be a nonnegat ive in teger . The coefficien ts of aHanning window are

w = hanning(n,sflag) retu rns an n-poin t Hanning window using the windowsampling specified by sflag, which can be either 'periodic' or 'symmetric'(the defau lt ). When 'periodic' is specified, hanning computes a length n+1window and returns the fir st n poin t s.

Diagnostics An error message is displayed when incor rect a rgument s are used:

Order cannot be less than zero.Sampling must be either 'symmetric' or 'periodic'.

A warning message is displayed for noninteger n:

Warning: Rounding order to nearest integer.

See Also

References [1] Oppenheim, A.V., and R.W. Schafer , Discrete-T im e S ignal Processing.Englewood Cliffs, NJ : Prent ice-Hall, 1989.

w k[ ] 0.5 1 2π kn 1+-------------⎝ ⎠

⎛ ⎞cos–⎝ ⎠⎛ ⎞ k 1= … n, , ,=

bartlett Bar t let t window.blackman Blackman window.boxcar Rectangula r window.chebwin Chebyshev window.hamming Hamming window.kaiser Kaiser window.triang Tr iangular window.

Page 491: MATLAB Signal Processing Toolbox user manual

hilbert

6-187

6hilber tPurpose Hilber t t ransform.

Syntax y = hilbert(x)

Description y = hilbert(x) returns a complex helica l sequence, somet imes ca lled theanalytic signal, from a rea l da ta sequence. The ana lyt ic signa l has a rea l par t ,which is the or igina l da ta , and an imaginary par t , which conta ins the Hilber tt ransform. The imaginary par t is a version of the or igina l rea l sequence with a90° phase sh ift . Sines are therefore t ransformed to cosines and vice versa . TheHilber t t ransformed ser ies has the same amplitude and frequency conten t asthe or igina l rea l da ta and includes phase informa t ion tha t depends on thephase of the or igina l da ta .

If x is a matr ix, y = hilbert(x) opera t es columnwise on the mat r ix, findingthe Hilber t t ransform of each column.

The Hilber t t ransform is usefu l in ca lcu la t ing instan taneous a t t r ibu tes of at ime ser ies, especia lly the amplitude and frequency. The instantaneousamplitude is the amplitude of the complex Hilber t t ransform; theinstan taneous frequency is the t ime ra te of change of the inst an taneous phaseangle. For a pure sinusoid, the inst an taneous amplitude and frequency areconstan t . The instan taneous phase, however , is a sawtooth , reflect ing the wayin which the loca l phase angle var ies linea r ly over a single cycle. For mixturesof sinusoids, the a t t r ibu tes are shor t t erm, or loca l, averages spanning no morethan two or th ree poin ts.

Reference [1] descr ibes the Kolmogorov method for min imum phasereconst ruct ion , which involves taking the Hilber t t ransform of the logar ithm ofthe spect rum of a t ime ser ies. The toolbox funct ion rceps per forms th isreconst ruct ion .

Algorithm The ana lyt ic signa l for a sequence x has a one-sided Fourier transform , tha t is,nega t ive frequencies a re 0. To approximate the ana lyt ic signa l, hilbertca lcula tes the FFT of the input sequence, replaces those FFT coefficien t s tha tcor respond to nega t ive frequencies with zeros, and ca lcu la tes the inverse FFTof the resu lt .

In deta il, hilbert uses a four -step a lgor ithm:

Page 492: MATLAB Signal Processing Toolbox user manual

hilbert

6-188

1 It ca lcu la tes the FFT of the input sequence, stor ing the resu lt in a vector y.Before t ransforming, it zero pads the input sequence so it s length n is theclosest power of two, if necessary. This ensures the most efficien t FFTcomputa t ion .

2 It crea tes a vector h whose elements h(i) have the va lues- 1 for i = 1, (n/2) + 1- 2 for i = 2, 3, ..., (n/2)- 0 for i = (n/2) + 2, ... , n

3 It ca lcu la tes the element -wise product of y and h.4 It ca lcu la tes the inverse FFT of the sequence obta ined in step 3 and returnsthe fir st n elements of the resu lt .

If t he input da ta x is a ma tr ix, hilbert opera tes in a simila r manner , extendingeach step above to handle the matr ix case.

See Also

References [1] Claerbou t , J .F . Fundam entals of Geophysical Data Processing. New York:McGraw-Hill, 1976. Pgs. 59-62.

fft One-dimensiona l fast Four ier t ransform.ifft One-dimensiona l inverse fast Fourier t ransform.rceps Real cepst rum and min imum phase reconst ruct ion.

Page 493: MATLAB Signal Processing Toolbox user manual

icceps

6-189

6iccepsPurpose Inverse complex cepst rum.

Syntax x = icceps(xhat,nd)

Description x = icceps(xhat,nd) returns the inverse complex cepst rum of the (assumedrea l) sequence xhat, r emoving nd samples of delay. If xhat was obta ined withcceps(x), then the amount of delay tha t was added to x was the element ofround(unwrap(angle(fft(x)))/pi) cor responding to π radians.

See Also

References [1] Oppenheim, A.V., and R.W. Schafer . Digital S ignal Processing. EnglewoodCliffs, NJ : Pren t ice Ha ll, 1975.

cceps Complex cepst ra l ana lysis.hilbert Hilber t t ransform.rceps Real cepst rum and minimum phase reconst ruct ion .unwrap Unwrap phase angles.

Page 494: MATLAB Signal Processing Toolbox user manual

idct

6-190

6idctPurpose Inverse discrete cosine t ransform.

Syntax x = idct(y)x = idct(y,n)

Description The inverse discret e cosine t ransform reconst ruct s a sequence from it s discret ecosine t ransform (DCT) coefficien t s. The idct funct ion is the inverse of the dctfunct ion .

x = idct(y) retu rns the inverse discrete cosine t ransform of y

where

and N = length(x), which is the same as length(y). The ser ies is indexedfrom n = 1 and k = 1 inst ead of the usua l n = 0 and k = 0 because MATLABvectors run from 1 to N inst ead of from 0 to N -1.

x = idct(y,n) appends zeros or t runca tes the vector y to length n beforet ransforming.

If y is a matr ix, idct t r ansforms it s columns.

See Also

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

k 1=

N

∑ n 1 … N, ,=,=

w k( )

1N--------- k 1=,

2N---- 2 k N≤ ≤,

⎩⎪⎪⎨⎪⎪⎧

=

dct Discrete cosine t ransform (DCT).dct2 Two-dimensiona l DCT (see Im age Processing Toolbox User’s

Guide).idct2 Two-dimensiona l inverse DCT (see Im age Processing Toolbox

User’s Guide).ifft One-dimensiona l inverse fast Four ier t ransform.

Page 495: MATLAB Signal Processing Toolbox user manual

idct

6-191

References [1] J a in , A.K. Fundam entals of Digital Im age Processing. Englewood Cliffs, NJ :Prent ice-Ha ll, 1989.

[2] Pennebaker , W.B., and J .L. Mitchell. J PEG S till Im age Data Com pressionS tandard . New York, NY: Van Nost rand Reinhold, 1993. Chapter 4.

Page 496: MATLAB Signal Processing Toolbox user manual

ifft

6-192

6ifftPurpose One-dimensiona l inverse fa st Four ier t ransform.

Syntax y = ifft(x)y = ifft(x,n)

Description ifft computes the inverse Four ier t ransform of a vector or ar ray. This funct ionimplements the inverse t ransform given by

where WN = e-j(2p/N) and N = length(x). Note tha t the ser ies is indexed as n + 1and k + 1 instead of the usua l n and k because MATLAB vectors run from 1 to Ninstead of from 0 to N -1.

y = ifft(x) is the inverse Four ier t ransform of vector x. If x is an ar ray, y isthe inverse FFT of each column of the mat r ix.

y = ifft(x,n) is the n-poin t inverse FFT. If the length of x is less than n, ifftpads x with t ra iling zeros to length n. If the length of x is grea t er than n, ifftt runca tes the sequence x. When x is an a r ray, ifft adjusts the length of thecolumns in the same manner .

The ifft funct ion is par t of the standard MATLAB language.

Algorithm The ifft funct ion is an M-file. The a lgor ithm for ifft is the same as tha t forfft, except for a sign change and a sca le factor of n = length(x). The execu t iont ime is fa st est when n is a power of two and slowest when n is a la rge pr ime.

See Also

x n 1+( ) 1N---- X k 1+( )Wn

k n–

k 0=

N 1–

∑=

fft One-dimensiona l fast Four ier t ransform.fft2 Two-dimensiona l fa st Four ier t ransform.fftshift Rear range the outpu ts of fft and fft2.ifft2 Two-dimensiona l inverse fa st Four ier t ransform.

Page 497: MATLAB Signal Processing Toolbox user manual

ifft2

6-193

6ifft2Purpose Two-dimensiona l inverse fast Fourier t ransform.

Syntax Y = ifft2(X)Y = ifft2(X,m,n)

Description Y = ifft2(X) retu rns the two-dimensiona l inverse fa st Four ier t ransform(FFT) of the ar ray X. If X is a vector , Y has the same or ien ta t ion as X.

Y = ifft2(X,m,n) t runca tes or zero pads X, if necessa ry, to crea te an m-by-nar ray before per forming the inverse FFT. The resu lt Y is a lso m-by-n.

For any X, ifft2(fft2(X)) equals X to with in roundoff er ror . If X is rea l,ifft2(fft2(X)) may have small imagina ry pa r ts.

The ifft2 funct ion is pa r t of the st andard MATLAB language.

Algorithm The algor ithm for ifft2 is the same as tha t for fft2, except for a sign changeand sca le factors of [m n]= size(X). The execu t ion t ime is fa st est when m andn a re powers of two and slowest when they are la rge pr imes.

See Also fft One-dimensiona l fast Four ier t ransform.fft2 Two-dimensiona l fa st Four ier t ransform.fftn N -dimensiona l fast Four ier t ransform (see the online

MATLAB Function Reference).fftshift Rear range the outpu ts of fft and fft2.ifft One-dimensiona l inverse fa st Four ier t ransform.ifftn N -dimensiona l inverse fast Four ier t ransform (see

the online MATLAB Function Reference).

Page 498: MATLAB Signal Processing Toolbox user manual

impinvar

6-194

6impinvarPurpose Impulse inva r iance method of ana log-to-digita l filter conversion .

Syntax [bz,az] = impinvar(b,a,Fs)[bz,az] = impinvar(b,a)[bz,az] = impinvar(b,a,Fs,tol)

Description [bz,az] = impinvar(b,a,Fs) crea t es a digit a l filter with numera tor anddenomina tor coefficien ts bz and az, r espect ively, whose impulse response isequal to the impulse response of the ana log filter with coefficien ts b and a,sca led by 1/Fs.

[bz,az] = impinvar(b,a) uses the default va lue of 1 Hz for Fs.

[bz,az] = impinvar(b,a,Fs,tol) uses the tolerance specified by tol todetermine whether poles are repea ted. A la rger tolerance increases thelikelihood tha t impinvar will consider nea rby poles to be repea ted. The defaultis 0.001, or 0.1% of a pole’s magnitude. Note tha t the accuracy of the pole va luesis st ill limited to the accuracy obta inable by the roots funct ion .

Example Conver t an ana log lowpass filter to a digita l filter using impinvar with asampling frequency of 10 Hz:

[b,a] = butter(4,0.3,'s');[bz,az] = impinvar(b,a,10)

bz =

1.0e-006 *

-0.0000 0.1324 0.5192 0.1273 0

az =

1.0000 -3.9216 5.7679 -3.7709 0.9246

Algorithm impinvar per forms the impulse-invar ian t method of ana log-to-digit a l t ransferfunct ion conversion discussed in reference [1]:

1 It finds the par t ia l fract ion expansion of the syst em represen ted by b and a.2 It r eplaces the poles p by the poles exp(p/Fs).

Page 499: MATLAB Signal Processing Toolbox user manual

impinvar

6-195

3 It finds the t ransfer funct ion coefficien ts of the system from the residuesfrom step 1 and the poles from step 2.

See Also

References [1] Parks, T.W., and C.S. Burrus. Digital Filter Design . New York: J ohn Wiley& Sons, 1987. Pgs. 206-209.

bilinear Bilinear t ransformat ion method of ana log-to-digita lfilt er conversion .

lp2bp Lowpass to bandpass ana log filter t ransformat ion .lp2bs Lowpass to bandstop analog filt er t ransformat ion .lp2hp Lowpass to h ighpass ana log filt er t ransformat ion .lp2lp Lowpass to lowpass ana log filt er t ransformat ion .

Page 500: MATLAB Signal Processing Toolbox user manual

impz

6-196

6impzPurpose Impulse response of digita l filt er s.

Syntax [h,t] = impz(b,a)[h,t] = impz(b,a,n)[h,t] = impz(b,a,n,Fs)impz(b,a)impz(...)

Description [h,t] = impz(b,a) computes the impulse response of the filter withnumera tor coefficien ts b and denominator coefficien ts a. impz chooses thenumber of samples and retu rns the response in column vector h and t imes (orsample in terva ls) in column vector t (where t = (0:n–1)' and n is thecomputed impulse response length).

[h,t] = impz(b,a,n) computes n samples of the impulse response. If n is avector of in tegers, impz computes the impulse response a t those in t egerloca t ions where 0 is the st a r t ing poin t of the filt er .

[h,t] = impz(b,a,n,Fs) computes n samples and sca les t so tha t samples arespaced 1/Fs units apa r t . Fs is 1 by default . Leave n empty, [], to let impz selectthe number of samples.

impz with no outpu t a rgument s plots the impulse response in the cur rentfigure window using stem(t,h).

impz works for both rea l and complex input syst ems.

Page 501: MATLAB Signal Processing Toolbox user manual

impz

6-197

Example Plot the fir st 50 samples of the impulse response of a four th-order lowpassellipt ic filt er with cutoff frequency of 0.4 t imes the Nyquist frequency:

[b,a] = ellip(4,0.5,20,0.4);impz(b,a,50)

Algorithm impz filter s a length n impulse sequence using

filter(b,a,[1 zeros(1,n–1)])

To compute n in the au to-length case, impz either uses n = length(b) for theFIR case or fir st finds the poles using p = roots(a), if length(a) is grea t erthan 1.

If the filter is unstable, n is chosen to be the poin t a t which the term from thela rgest pole reaches 10^6 t imes it s or igina l va lue.

If the filter is stable, n is chosen to be the poin t a t which the term due to thela rgest amplitude pole is 5*10^–5 of it s or igina l amplitude.

If the filt er is oscilla tory (poles on the unit circle only), impz computes fiveper iods of the slowest oscilla t ion .

If the filter has both oscilla tory and damped terms, n is chosen to equa l fiveper iods of the slowest oscilla t ion or the point a t which the term due to the

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

Page 502: MATLAB Signal Processing Toolbox user manual

impz

6-198

la rgest (nonunity) amplitude pole is 5*10^–5 of it s or igina l amplitude,whichever is grea ter .

impz a lso a llows for delay in the numera tor polynomia l, which it adds to theresu lt ing n.

See Also impulse Unit impulse response (see Control S ystem ToolboxUser’s Guide).

stem Plot discrete sequence da ta (see the online MATLABFunction Reference).

Page 503: MATLAB Signal Processing Toolbox user manual

interp

6-199

6interpPurpose Increase sampling ra t e by an in teger factor (in terpola t ion).

Syntax y = interp(x,r)y = interp(x,r,l,alpha)[y,b] = interp(x,r,l,alpha)

Description In terpola t ion increases the or igina l sampling ra te for a sequence to a h igherra t e. interp performs lowpass in terpola t ion by inser t ing zeros in to the or igina lsequence and then applying a specia l lowpass filt er .

y = interp(x,r) increases the sampling ra te of x by a factor of r. Thein t erpola t ed vector y is r t imes longer than the or igina l input x.

y = interp(x,r,l,alpha) specifies l (filter length) and alpha (cu t -offfrequency). The default va lue for l is 4 and the default va lue for alpha is 0.5.

[y,b] = interp(x,r,l,alpha) retu rns vector b conta in ing the filt ercoefficien t s used for the in terpola t ion .

Example In terpola te a signa l by a factor of four :

t = 0:0.001:1; % time vectorx = sin(2*pi*30*t) + sin(2*pi*60*t);y = interp(x,4);stem(x(1:30)); title('Original Signal');figurestem(y(1:120)); title('Interpolated Signal');

0 20 40 60 80 100 120-2

-1.5

-1

-0.5

0

0.5

1

1.5

2Interpolated Signal

0 5 10 15 20 25 30-2

-1.5

-1

-0.5

0

0.5

1

1.5

2Original Signal

Page 504: MATLAB Signal Processing Toolbox user manual

interp

6-200

Algorithm interp uses the lowpass in terpola t ion Algor ithm 8.1 descr ibed in [1]:

1 It expands the input vector to the cor rect length by inser t ing zeros betweenthe or igina l da ta va lues.

2 It designs a specia l symmetr ic FIR filt er tha t a llows the or igina l da ta to passth rough unchanged and in terpola tes between so tha t the mean-squareer rors between the in terpola ted poin t s and their idea l va lues are minimized.

3 It applies the filter to the inpu t vector to produce the in terpola ted outputvector .

The length of the FIR lowpass in terpola t ing filter is 2*l*r+1. The number ofor igina l sample va lues used for in terpola t ion is 2*l. Ordina r ily, l should beless than or equal to 10. The or igina l signa l is assumed to be band limit ed withnormalized cutoff frequency 0 ≤ alpha ≤ 1, where 1 is ha lf the or igina lsampling frequency (the Nyquist frequency). The defau lt va lue for l is 4 andthe defau lt va lue for alpha is 0.5.

Diagnostics If r is not an in teger , interp gives the following er ror message:

Resampling rate R must be an integer.

See Also

References [1] IEEE. Program s for Digital S ignal Processing. IEEE Press. New York: J ohnWiley & Sons, 1979. Algor ithm 8.1.

decimate Decrease the sampling ra t e for a sequence(decimat ion).

interp1 One-dimensiona l da ta in t erpola t ion (t able lookup)(see the online MATLAB Function Reference).

resample Change sampling ra t e by any ra t iona l factor.spline Cubic spline in terpola t ion (see the on line MATLAB

Function Reference).upfirdn Upsample, apply an FIR filter, and downsample.

Page 505: MATLAB Signal Processing Toolbox user manual

intfilt

6-201

6int filtPurpose In terpola t ion FIR filt er design .

Syntax b = intfilt(r,l,alpha)b = intfilt(r,n,'Lagrange')

Description b = intfilt(r,l,alpha) designs a linear phase FIR filter tha t per forms idea lbandlimited in t erpola t ion using the nearest 2*l nonzero samples, when usedon a sequence in ter leaved with r–1 consecu t ive zeros every r samples. Itassumes an or igina l bandlimitedness of alpha t imes the Nyquist frequency.The retu rned filter is iden t ica l to tha t used by interp.

b = intfilt(r,n,'Lagrange') or b = intfilt(r,n,'l') designs an FIRfilt er tha t per forms nt h -order Lagrange polynomia l in terpola t ion on a sequencein t er leaved with r–1 consecu t ive zeros every r samples. b has length (n + 1)*rfor n even , and length (n + 1)*r–1 for n odd.

Both types of filt ers are basica lly lowpass and a re in tended for in terpola t ionand decimat ion .

Examples Design a digit a l in terpola t ion filt er to upsample a signa l by four , using thebandlimited method:

alpha = 0.5; % "bandlimitedness" factorh1 = intfilt(4,2,alpha); % bandlimited interpolation

The filter h1 works best when the or igina l signa l is bandlimit ed to alpha t imesthe Nyquist frequency. Crea te a bandlimit ed noise signa l:

randn('seed',0)x = filter(fir1(40,0.5),1,randn(200,1)); % bandlimit

Now zero pad the signa l with th ree zeros between every sample. The resu lt ingsequence is four t imes the length of x:

xr = reshape([x zeros(length(x),3)]',4*length(x),1);

In terpola te using the filter command:

y = filter(h1,1,xr);

Page 506: MATLAB Signal Processing Toolbox user manual

intfilt

6-202

y is an in terpola ted version of x, delayed by seven samples (the group-delay ofthe filt er). Zoom in on a sect ion to see th is:

plot(100:200,y(100:200),7+(101:4:196),x(26:49),'o')

intfilt’s other type of filter per forms Lagrange polynomia l in terpola t ion ofthe or igina l signa l. For example, fir st -order polynomia l in terpola t ion is justlinear in terpola t ion , which is accomplished with a t r iangula r filt er :

h2 = intfilt(4,1,'l') % Lagrange interpolation

h2 = 0.2500 0.5000 0.7500 1.0000 0.7500 0.5000 0.2500

Algorithm The bandlimited method uses firls t o design an in terpola t ion FIR equiva len tto tha t presented in [1]. The polynomia l method uses Lagrange’s polynomia lin t erpola t ion formula on equally spaced samples to const ruct the appropr ia tefilt er .

See Also

References [1] Oetken , Parks, and Schüßler . “New Result s in the Design of Digita lIn terpola tors.” IEEE Trans. Acoust., S peech , S ignal Processing. Vol. ASSP-23(J une 1975). Pgs. 301-309.

100 110 120 130 140 150 160 170 180 190 200-1.5

-1

-0.5

0

0.5

1

1.5

Sample Number

Solid = interpolated, ’o’ = original

decimate Decrease the sampling ra t e for a sequence(decimat ion).

interp Increase sampling ra te by an integer factor(in t erpola t ion).

resample Change sampling ra t e by any ra t iona l factor.

Page 507: MATLAB Signal Processing Toolbox user manual

invfreqs

6-203

6invfr eqsPurpose Cont inuous-t ime (ana log) filt er ident ifica t ion from frequency data .

Syntax [b,a] = invfreqs(h,w,nb,na)[b,a] = invfreqs(h,w,nb,na,wt)[b,a] = invfreqs(h,w,nb,na,wt,iter)[b,a] = invfreqs(h,w,nb,na,wt,iter,tol)[b,a] = invfreqs(h,w,nb,na,wt,iter,tol,'trace')[b,a] = invfreqs(h,w,'complex',nb,na,...)

Description invfreqs is the inverse opera t ion of freqs; it finds a cont inuous-t ime t ransferfunct ion tha t cor responds to a given complex frequency response. F rom alabora tory ana lysis st andpoin t , invfreqs is usefu l in conver t ing magnitudeand phase da ta in to t ransfer funct ions.

[b,a] = invfreqs(h,w,nb,na) retu rns the rea l numera tor and denomina torcoefficien t vectors b and a of the t ransfer funct ion

whose complex frequency response is given in vector h a t the frequency poin t sspecified in vector w. Sca la rs nb and na specify the desired orders of thenumera tor and denomina tor polynomia ls.

Frequency is specified in radians between 0 and π, and the length of h must bethe same as the length of w. invfreqs uses conj(h) a t —w t o ensure the properfrequency domain symmetry for a rea l filter .

[b,a] = invfreqs(h,w,nb,na,wt) weights the fit -er rors versus frequency. wtis a vector of weigh t ing factors the same length as w.

invfreqs(h,w,nb,na,wt,iter) and

invfreqs(h,w,nb,na,wt,iter,tol) provide a super ior a lgor ithm thatguarantees stabilit y of the resu lt ing linear system and searches for the best fitusing a numer ica l, it era t ive scheme. The iter parameter t ells invfreqs to endthe it era t ion when the solu t ion has converged, or a ft er iter it era t ions,whichever comes fir st . invfreqs defines convergence as occur r ing when the

H s( ) B s( )A s( )----------- b 1( )sn b b 2( )sn b 1– L b n b 1+( )+ + +

a 1( )sn a a 2( )sn a 1– L a n a 1+( )+ + +----------------------------------------------------------------------------------------------= =

Page 508: MATLAB Signal Processing Toolbox user manual

invfreqs

6-204

norm of the (modified) gradien t vector is less than tol. tol is an opt iona lparameter tha t default s to 0.01. To obta in a weigh t vector of a ll ones, use

invfreqs(h,w,nb,na,[],iter,tol)

invfreqs(h,w,nb,na,wt,iter,tol,'trace') displays a t extua l progressrepor t of the itera t ion .

invfreqs(h,w,'complex',nb,na,...) crea tes a complex filt er . In th is case nosymmet ry is enforced, and the frequency is specified in radians between -π andπ.

Remarks When building h igher order models using h igh frequencies, it is impor t an t tosca le the frequencies, dividing by a factor such as ha lf the highest frequencypresen t in w, so as to obta in well condit ioned values of a and b. Th is cor respondsto a resca ling of t ime.

Examples Conver t a simple t ransfer funct ion to frequency response da ta and then backto the or igina l filter coefficien ts:

a = [1 2 3 2 1 4]; b = [1 2 3 2 3];[h,w] = freqs(b,a,64);[bb,aa] = invfreqs(h,w,4,5)

bb =

1.0000 2.0000 3.0000 2.0000 3.0000

aa =

1.0000 2.0000 3.0000 2.0000 1.0000 4.0000

Page 509: MATLAB Signal Processing Toolbox user manual

invfreqs

6-205

Not ice tha t bb and aa are equiva lent to b and a, r espect ively. However , aa haspoles in the left ha lf-plane and thus the system is unst able. Use invfreqs’sit era t ive a lgor ithm to find a st able approximat ion to the system:

[bbb,aaa] = invfreqs(h,w,4,5,[],30)

bbb =

0.6816 2.1015 2.6694 0.9113 -0.1218

aaa =

1.0000 3.4676 7.4060 6.2102 2.5413 0.0001

Suppose you have two vector s, mag and phase, tha t conta in magnitude andphase da ta ga thered in a labora tory, and a third vector w of frequencies. Youcan conver t the da ta in to a cont inuous-t ime t ransfer funct ion using invfreqs:

[b,a] = invfreqs(mag.*exp(j*phase),w,2,3);

Algorithm By defau lt , invfreqs uses an equa t ion er ror method to iden t ify the best modelfrom the da ta . This finds b and a in

by crea t ing a system of linear equa t ions and solving them with MATLAB’s \opera tor . Here A(w (k )) and B (w (k )) a re the Four ier t ransforms of thepolynomia ls a and b, r espect ively, a t the frequency w (k ), and n is the numberof frequency poin t s (the length of h and w). Th is a lgorithm is based on Levi [1].Severa l var ian ts have been suggest ed in the lit era ture, where the weight ingfunct ion wt gives less a t ten t ion to high frequencies.

The super ior (“output -error”) a lgor ithm uses the damped Gauss-Newton methodfor itera t ive search [2], with the output of the first algor ithm as the init ia lest imate. This solves the direct problem of minimizing the weighted sum of thesquared error between the actual and the desired frequency response poin ts:

minb a,

w t k( ) h k( )A w k( )( ) B w k( )( )– 2

k 1=

n

minb a,

w t k( ) h k( ) B w k( )( )A w k( )( )--------------------–

2

k 1=

n

Page 510: MATLAB Signal Processing Toolbox user manual

invfreqs

6-206

See Also

References [1] Levi, E .C. “Complex-Curve F it t ing.” IRE Trans. on Autom atic Control.Vol. AC-4 (1959). Pgs. 37-44.

[2] Dennis, J .E ., J r ., and R.B. Schnabel. Num erical Methods for UnconstrainedOptim ization and Nonlinear Equations. Englewood Cliffs, NJ : Prent ice Ha ll,1983.

freqs Frequency response of ana log filt er s.freqz Frequency response of digita l filter s.invfreqz Discret e-t ime filt er ident ifica t ion from frequency

data .prony Prony’s method for t ime domain IIR filter design .

Page 511: MATLAB Signal Processing Toolbox user manual

invfreqz

6-207

6invfr eqzPurpose Discret e-t ime filter ident ifica t ion from frequency data .

Syntax [b,a] = invfreqz(h,w,nb,na)[b,a] = invfreqz(h,w,nb,na,wt)[b,a] = invfreqz(h,w,nb,na,wt,iter)[b,a] = invfreqz(h,w,nb,na,wt,iter,tol)[b,a] = invfreqz(h,w,nb,na,wt,iter,tol,'trace')[b,a] = invfreqz(h,w,'complex',nb,na,...)

Description invfreqz is the inverse opera t ion of freqz; it finds a discrete-t ime t ransferfunct ion tha t cor responds to a given complex frequency response. F rom alabora tory ana lysis st andpoin t , invfreqz can be used to conver t magnitudeand phase da ta in to t ransfer funct ions.

[b,a] = invfreqz(h,w,nb,na) retu rns the rea l numera tor and denomina torcoefficien t s in vectors b and a of the t ransfer funct ion

whose complex frequency response is given in vector h a t the frequency poin t sspecified in vector w. Sca la rs nb and na specify the desired orders of thenumera tor and denomina tor polynomia ls.

Frequency is specified in radians between 0 and π, and the length of h must bethe same as the length of w. invfreqz uses conj(h) a t —w t o ensure the properfrequency domain symmetry for a rea l filter .

[b,a] = invfreqz(h,w,nb,na,wt) weights the fit -er rors versus frequency. wtis a vector of weigh t ing factors the same length as w.

invfreqz(h,w,nb,na,wt,iter) and

invfreqz(h,w,nb,na,wt,iter,tol) provide a super ior a lgor ithm thatguarantees stabilit y of the resu lt ing linear system and searches for the best fitusing a numer ica l, it era t ive scheme. The iter parameter t ells invfreqz to endthe it era t ion when the solu t ion has converged, or a ft er iter it era t ions,whichever comes fir st . invfreqz defines convergence as occur r ing when the

H z( ) B z( )A z( )----------- b 1( ) b 2( )z 1– L b n b 1+( )z n b–+ + +

a 1( ) a 2( )z 1– L a n a 1+( )z n a–+ + +-----------------------------------------------------------------------------------------= =

Page 512: MATLAB Signal Processing Toolbox user manual

invfreqz

6-208

norm of the (modified) gradien t vector is less than tol. tol is an opt iona lparameter tha t default s to 0.01. To obta in a weigh t vector of a ll ones, use

invfreqz(h,w,nb,na,[],iter,tol)

invfreqz(h,w,nb,na,wt,iter,tol,'trace') displays a t extua l progressrepor t of the itera t ion .

invfreqz(h,w,'complex',nb,na,...) crea tes a complex filt er . In th is case nosymmet ry is enforced, and the frequency is specified in radians between -π andπ.

Example Conver t a simple t ransfer funct ion to frequency response da ta and then backto the or igina l filter coefficien ts:

a = [1 2 3 2 1 4]; b = [1 2 3 2 3];[h,w] = freqz(b,a,64);[bb,aa] = invfreqz(h,w,4,5)

bb =

1.0000 2.0000 3.0000 2.0000 3.0000

aa =

1.0000 2.0000 3.0000 2.0000 1.0000 4.0000

Not ice tha t bb and aa are equiva len t to b and a, r espect ively. However , aa haspoles ou tside the unit circle and thus the syst em is unstable. Use invfreqz’sit era t ive a lgor ithm to find a stable approxima t ion to the system:

[bbb,aaa] = invfreqz(h,w,4,5,[],30)

bbb =

0.2427 0.2788 0.0069 0.0971 0.1980

aaa =

1.0000 –0.8944 0.6954 0.9997 –0.8933 0.6949

Algorithm By defau lt , invfreqz uses an equa t ion er ror method to iden t ify the best modelfrom the data . This finds b and a in

Page 513: MATLAB Signal Processing Toolbox user manual

invfreqz

6-209

by crea t ing a system of linear equa t ions and solving them with MATLAB’s \opera tor . Here A(w (k )) and B (w (k )) a re the Four ier t ransforms of thepolynomia ls a and b, r espect ively, a t the frequency w (k ), and n is the numberof frequency poin t s (the length of h and w). Th is a lgor ithm is a based on Levi [1].

The super ior (“outpu t -er ror”) a lgorithm uses the damped Gauss-Newtonmethod for it era t ive search [2], with the outpu t of the fir st a lgor ithm as thein it ia l est imate. This solves the direct problem of minimizing the weighted sumof the squared er ror between the actua l and the desired frequency responsepoin ts:

See Also

References [1] Levi, E .C. “Complex-Curve Fit t ing.” IRE Trans. on Autom atic Control.Vol. AC-4 (1959). Pgs. 37-44.

[2] Dennis, J .E ., J r ., and R.B. Schnabel. Num erical Methods for UnconstrainedOptim ization and Nonlinear Equations. Englewood Cliffs, NJ : Prent ice Hall,1983.

minb a,

w t k( ) h k( )A w k( )( ) B w k( )( )– 2

k 1=

n

minb a,

w t k( ) h k( ) B w k( )( )A w k( )( )--------------------–

2

k 1=

n

freqs Frequency response of ana log filter s.freqz Frequency response of digita l filter s.invfreqs Cont inuous-t ime (ana log) filt er iden t ifica t ion from

frequency da ta .prony Prony’s method for t ime domain IIR filter design .

Page 514: MATLAB Signal Processing Toolbox user manual

kaiser

6-210

6ka iserPurpose Kaiser window.

Syntax w = kaiser(n,beta)

Description w = kaiser(n,beta) retu rns an n-poin t Ka iser ( - sinh) window in thecolumn vector w. beta is the Ka iser window parameter tha t a ffect s thesidelobe a t t enuat ion of the Four ier t ransform of the window.

To obta in a Kaiser window tha t designs an FIR filter with sidelobe height-α dB, use the following β:

Increasing beta widens the ma in lobe and decreases the amplitude of thesidelobes (increases the a t t enua t ion).

See Also

References [1] Ka iser , J .F . “Nonrecursive Digita l F ilter Design Using the - sinh WindowFunct ion .” Proc. 1974 IEEE S ym p. Circu its and S yst. (Apr il 1974). Pgs. 20-23.

[2] IEEE. Digital S ignal Processing II . IEEE Press. New York: J ohn Wiley &Sons, 1975.

I0β

β0.1102 α 8.7–( ), α 50>

0.5842 α 21–( )0.4 0.07886 α 21–( )+ , 50 α 21≥ ≥

0 , α 21<⎩⎪⎨⎪⎧

=

bartlett Bar t let t window.blackman Blackman window.boxcar Rectangula r window.chebwin Chebyshev window.hamming Hamming window.hanning Hanning window.kaiserord Est imate parameters for fir1 with Ka iser window.triang Tr iangular window.

I0

Page 515: MATLAB Signal Processing Toolbox user manual

kaiserord

6-211

6ka iserordPurpose Est ima te parameters for an FIR filter design with Kaiser window.

Syntax [n,Wn,beta,ftype] = kaiserord(f,a,dev)[n,Wn,beta,ftype] = kaiserord(f,a,dev,Fs)c = kaiserord(f,a,dev,Fs,'cell')

Description kaiserord retu rns a filt er order n and beta pa rameter to specify a Kaiserwindow for use with the fir1 funct ion . Given a set of specifica t ions in thefrequency domain , kaiserord est ima tes the min imum FIR filt er order tha t willapproximately meet the specifica t ions. kaiserord conver t s the given filt erspecifica t ions in to passband and stopband ripples and conver ts cu tofffrequencies in to the form needed for windowed FIR filter design .

NOTE If the band r ipples a re specified as unequal, the smallest one is used,since the Kaiser window method is const ra ined to give filt er s with equa l r ippleheight s in a ll the passbands and stopbands.

[n,Wn,beta,ftype] = kaiserord(f,a,dev) finds the approxima te order n,normalized frequency band edges Wn, and weigh ts tha t meet inpu tspecifica t ions f, a, and dev. f is a vector of band edges and a is a vectorspecifying the desired amplitude on the bands defined by f. The length of f istwice the length of a, minus 2. Together , f and a define a desired piecewiseconstan t response funct ion . dev is a vector the same size as a tha t specifies themaximum allowable er ror or devia t ion between the frequency response of theoutput filt er and it s desired amplitude, for each band.

fir1 can use the resu lt ing order n, fr equency vector Wn, mult iband magnitudetype ftype, and the Kaiser window parameter beta. The ftype st r ing isin t ended for use with fir1; it is equa l to 'high' for a h ighpass filter and 'stop'for a bandstop filter . For mult iband filt ers, it can be equa l to 'dc–0' when thefir st band is a stopband (st a r t ing a t f = 0) or 'dc–1' when the fir st band is apassband.

To design a filt er b tha t approxima tely meet s the specifica t ions given by kaiserparameters f, a, and dev:

b = fir1(n,Wn,kaiser(n+1,beta),ftype,'noscale')

Page 516: MATLAB Signal Processing Toolbox user manual

kaiserord

6-212

[n,Wn,beta,ftype] = kaiserord(f,a,dev,Fs) specifies a samplingfrequency Fs. If not presen t , Fs defau lt s to 2 Hz, implying a Nyquist frequencyof 1 Hz. You can therefore specify band edges sca led to a pa r t icu la rapplica t ion’s sampling frequency.

c = kaiserord(f,a,dev,Fs,'cell') is a cell-a r ray whose element s are theparameters to fir1.

NOTE In some cases, kaiserord underest imates or overest imates the order n.If the filt er does not meet the specifica t ions, t ry a h igher order such as n+1, n+2,and so on , or a lower order .

Result s are inaccura t e if the cu toff frequencies a re near 0 or the Nyquistfrequency, or if dev is la rge (grea ter than 10%).

Algorithm kaiserord uses empir ica lly der ived formulas for est imat ing the orders oflowpass filt ers, as well a s differen t ia tors and Hilber t t ransformers. Est ima tesfor mult iband filt ers (such as bandpass filter s) a re der ived from the lowpassdesign formulas.

The design formulas tha t under lie the Kaiser window and it s applica t ion toFIR filt er design a re

where α = -20log10δ is the stopband at t enuat ion expressed in decibels (reca llt ha t δp = δs is required). The design formula is:

where n is the filter order and Δω is the width of the smallest t ransit ion region .

β0.1102 α 8.7–( ), α 50>

0.5842 α 21–( )0.4 0.07886 α 21–( )+ , 50 α 21≥ ≥0 , α 21<⎩

⎪⎨⎪⎧

=

n α 7.95–2.285 ωΔ( )----------------------------=

Page 517: MATLAB Signal Processing Toolbox user manual

kaiserord

6-213

Examples Design a lowpass filter with passband from 0 to 1 kHz and stopband from1500 Hz to 4 kHz. Specify passband r ipple of 5% and stopband at t enuat ion of40 dB:

fsamp = 8000;fcuts = [1000 1500];mags = [1 0];devs = [0.05 0.01];[n,Wn,beta,ftype] = kaiserord(fcuts,mags,devs,fsamp);hh = fir1(n,Wn,ftype,kaiser(n+1,beta),'noscale');freqz(hh)

0 0.2 0.4 0.6 0.8 1−1500

−1000

−500

0

Normalized Angular Frequency (×π rads/sample)

Phas

e (d

egre

es)

0 0.2 0.4 0.6 0.8 1−150

−100

−50

0

50

Normalized Angular Frequency (×π rads/sample)

Mag

nitu

de (d

B)

Page 518: MATLAB Signal Processing Toolbox user manual

kaiserord

6-214

Design an odd-length bandpass filt er (note tha t odd length means even order ,so the input to fir1 must be an even integer ):

fsamp = 8000;fcuts = [1000 1300 2210 2410];mags = [0 1 0];devs = [0.01 0.05 0.01];[n,Wn,beta,ftype] = kaiserord(fcuts,mags,devs,fsamp);n = n + rem(n,2);hh = fir1(n,Wn,ftype,kaiser(n+1,beta),'noscale');[H,f] = freqz(hh,1,1024,fsamp);plot(f,abs(H)), grid on

Design a lowpass filter with a passband cutoff of 1500 Hz, a stopband cutoff of2000 Hz, passband r ipple of 0.01, stopband r ipple of 0.1, and a samplingfrequency of 8000 Hz:

[n,Wn,beta,ftype] = kaiserord([1500 2000],[1 0],[0.01 0.1],8000);b = fir1(n,Wn,ftype,kaiser(n+1,beta),'noscale');

This is equiva lent to

c = kaiserord([1500 2000],[1 0],[0.01 0.1],8000,'cell');b = fir1(c{:});

0 500 1000 1500 2000 2500 3000 3500 40000

0.2

0.4

0.6

0.8

1

1.2

1.4

Page 519: MATLAB Signal Processing Toolbox user manual

kaiserord

6-215

Remarks Be carefu l to dist ingu ish between the meanings of filter length and filter order .The filt er length is the number of impulse response samples in the FIR filter .Genera lly, the impulse response is indexed from n = 0 to n = L -1, where L is thefilt er length . The filter order is the h ighest power in a z-t ransformrepresen ta t ion of the filter . For an FIR transfer funct ion , th is represen ta t ion isa polynomia l in z, where the h ighest power is zL-1 and the lowest power is z0.The filt er order is 1 less than the length (L -1) and is a lso equa l to the numberof zeros of the z polynomia l.

Diagnostics The lengths of the frequency, magnitude, and devia t ion vectors must ma tch ;otherwise, kaiserord gives the following er ror message:

Requires M and DEV to be the same length.Length of F must be 2*length(M)–2.

When magnitudes are not specified correct ly, kaiserord gives the followinger ror messages:

Stopbands must be zero.All passbands must have the same height.

If the band edges are not st r ict ly increasing, kaiserord gives the followinger ror message:

Bandedges must be strictly increasing.

See Also

References [1] Ka iser , J .F . “Nonrecursive Digita l F ilter Design Using the - sinh WindowFunct ion.” P roc. 1974 IEEE S ym p. Circu its and S yst. (Apr il 1974). Pgs. 20-23.

[2] IEEE. Digital S ignal Processing II . IEEE Press. New York: J ohn Wiley &Sons, 1975. Pgs. 123-126.

fir1 Window-based fin ite impulse response filter design –standard response.

kaiser Kaiser window.remezord Parks-McClellan opt imal FIR filter order est imat ion .

I0

Page 520: MATLAB Signal Processing Toolbox user manual

latc2tf

6-216

6la tc2t fPurpose Lat t ice filter to t ransfer funct ion conversion .

Syntax [num,den] = latc2tf(k,v)[num,den] = latc2tf(k,'iir')num = latc2tf(k,'fir')num = latc2tf(k)

Description [num,den] = latc2tf(k,v) finds the t ransfer funct ion numera tor num anddenomina tor den from the IIR la t t ice coefficien ts k and ladder coefficien t s v.

[num,den] = latc2tf(k,'iir') assumes tha t k is a ssocia ted with an a ll-poleIIR la t t ice filt er .

num = latc2tf(k,'fir') and

num = latc2tf(k) find the t ransfer funct ion numera tors from the FIR la t t icecoefficien t s specified by k.

See Also latcfilt Lat t ice and la t t ice-ladder filt er implementa t ion .tf2latc Conversion of t ransfer funct ion to la t t ice filter.

Page 521: MATLAB Signal Processing Toolbox user manual

latcfilt

6-217

6la tcfiltPurpose Lat t ice and la t t ice-ladder filt er implementa t ion .

Syntax [f,g] = latcfilt(k,x)[f,g] = latcfilt(k,v,x)[f,g] = latcfilt(k,1,x)[f,g,zf] = latcfilt(...,'ic',zi)

Description [f,g] = latcfilt(k,x) filter s x with the FIR la t t ice coefficien t s in vector k. fis the forward la t t ice filter resu lt and g is the backward filter resu lt .

If k and x a re vectors, the resu lt is a (signa l) vector .

Matr ix a rguments are permit t ed under the following ru les:

• If x is a mat r ix and k is a vector , each column of x is processed th rough thela t t ice filter specified by k.

• If x is a vector and k is a ma tr ix, each column of k is used to filt er x, and asigna l matr ix is retu rned.

• If x and k a re both matr ices with the same number of columns, then the i-thcolumn of k is used to filter the i-th column of x. A signa l mat r ix is retu rned.

[f,g] = latcfilt(k,v,x) filt ers x with the IIR la t t ice coefficien ts k andladder coefficien t s v. k and v must be vectors, while x may be a signa l ma t r ix.

[f,g] = latcfilt(k,1,x) filt ers x with the IIR all-pole la t t ice specified by k.k and x may be vectors or mat r ices according to the ru les given for the FIRla t t ice.

[f,g,zf] = latcfilt(...,'ic',zi) accept s a length-k vector zi specifyingthe in it ia l condit ion of the la t t ice st a tes. Output zf is a length-k vectorspecifying the fina l condit ion of the la t t ice sta tes.

See Also filter Filt er da ta with a recursive (IIR) or nonrecursive(FIR) filter.

latc2tf Lat t ice filter to t ransfer funct ion conversion .tf2latc Conversion of t ransfer funct ion to la t t ice filt er.

Page 522: MATLAB Signal Processing Toolbox user manual

levinson

6-218

6levin sonPurpose Levinson-Durbin recursion .

Syntax a = levinson(r,p)

Description The Levinson-Durbin recursion is an a lgor ithm for finding an a ll-pole IIR filt erwith a prescr ibed determinist ic au tocor rela t ion sequence. It has applica t ions infilt er design , coding, and spect ra l est imat ion . The filter tha t levinson producesis min imum phase.

a = levinson(r,p) finds the coefficien t s of an pth -order au toregressive linearprocess which has r as it s au tocorrela t ion sequence. r is a rea l or complexdeterminist ic au tocor rela t ion sequence (a vector ), and p is the order ofdenomina tor polynomia l A(z); tha t is, a = [1 a(2) ... a(p+1)]. The filtercoefficien t s a re ordered in descending powers of z:

Algorithm levinson solves the symmetr ic Toeplitz system of linear equa t ions.

where r = [r(1) ... r(p+1)] is the input au tocor rela t ion vector , and r(i)* denotesthe complex con juga te of r(i). The a lgor ithm requires O(p2) flops and is thusmuch more efficien t than the MATLAB \ command for la rge p. However , thelevinson funct ion uses \ for low orders to provide the fastest possibleexecu t ion .

See Also

H z( ) 1A z( )----------- 1

1 a 2( )z 1– L a p 1+( )z p–+ + +--------------------------------------------------------------------------= =

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

r 2( ) r 1( ) L r p 1–( )∗

M O O M

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

a 2( )a 3( )

M

a p 1+( )

r 2( )–r 3( )–M

r p 1+( )–

=

lpc Linear predict ion coefficien ts.prony Prony’s method for t ime domain IIR filter design .rlevinson Reverse Levinson-Durbin recursion .stmcb Linear model using Steiglitz-McBride itera t ion .

Page 523: MATLAB Signal Processing Toolbox user manual

levinson

6-219

References [1] Ljung, L. S ystem Iden tification: Theory for the User. Englewood Cliffs, NJ :Prent ice Hall, 1987. Pgs. 278-280.

Page 524: MATLAB Signal Processing Toolbox user manual

lp2bp

6-220

6lp2bpPurpose Lowpass to bandpass ana log filter t ransformat ion .

Syntax [bt,at] = lp2bp(b,a,Wo,Bw)[At,Bt,Ct,Dt] = lp2bp(A,B,C,D,Wo,Bw)

Description lp2bp t ransforms ana log lowpass filter prototypes with a cu toff frequency of1 rad/sec in to bandpass filt er s with desired bandwidth and cen ter frequency.The t ransformat ion is one st ep in the digita l filt er design process for thebutter, cheby1, cheby2, and ellip funct ions.

lp2bp can per form the t ransformat ion on two differen t linea r systemrepresen ta t ions: t ransfer funct ion form and sta te-space form. In both cases, theinpu t syst em must be an ana log filter prototype.

Transfer Function Form (Polynomial)

[bt,at] = lp2bp(b,a,Wo,Bw) t r ansforms an analog lowpass filter prototypegiven by polynomia l coefficien ts in to a bandpass filter with center frequency Woand bandwidth Bw. Row vectors b and a specify the coefficient s of the numera torand denomina tor of the prototype in descending powers of s:

Sca la rs Wo and Bw specify the center frequency and bandwidth in unit s ofradians/second. For a filt er with lower band edge w1 and upper band edge w2,u se Wo = sqrt(w1*w2) and Bw = w2–w1.

lp2bp retu rns the frequency t ransformed filter in row vectors bt and at.

State-Space Form

[At,Bt,Ct,Dt] = lp2bp(A,B,C,D,Wo,Bw) conver ts the con t inuous-t imesta t e-space lowpass filter prototype in matr ices A, B, C, D:

b s( )a s( )---------- b 1( )sn b L b n b( )s b n b 1+( )+ + +

a 1( )sn a L a n a( )s a n a 1+( )+ + +------------------------------------------------------------------------------------=

x· Ax B u+=y Cx Du+=

Page 525: MATLAB Signal Processing Toolbox user manual

lp2bp

6-221

in to a bandpass filt er with center frequency Wo and bandwidth Bw. For a filterwith lower band edge w1 and upper band edge w2, use Wo = sqrt(w1*w2) andBw = w2–w1.

The bandpass filt er is returned in mat r ices At, Bt, Ct, Dt.

Algorithm lp2bp is a h ighly accura t e st a te-space formula t ion of the classic ana log filt erfrequency t ransformat ion . Consider the sta te-space system:

where u is the input , x is the st a te vector , and y is the output . The Laplacet ransform of the fir st equa t ion (assuming zero in it ia l condit ions) is

Now if a bandpass filt er is to have cen ter frequency ω0 and bandwidth Bw, t hestandard s-doma in t ransformat ion is

where Q = ω0/Bw and p = s/ω0. Subst itu t ing th is for s in the Laplacet ransformed sta t e-space equa t ion , and consider ing the opera tor p as d /dt:

or

Now define

which , when subst it u ted, leads to

x· Ax B u+=y Cx Du+=

sX s( ) AX s( ) BU s( )+=

s Q p 2 1+( ) p⁄=

Qx·· Qx+ A·x B u·+=

Qx·· A·

– x B– u· Qx–=

Qω· Qx–=

Qx· A x Qω B u+ +=

Page 526: MATLAB Signal Processing Toolbox user manual

lp2bp

6-222

The last two equat ions give equa t ions of sta t e. Write them in standa rd formand mult iply the differen t ia l equa t ions by ω0 to recover the t ime/frequencysca ling represented by p and find st a te mat r ices for the bandpass filter :

Q = Wo/Bw; [ma,na] = size(A);At = Wo*[A/Q eye(ma,na);–eye(ma,na) zeros(ma,na)];Bt = Wo*[B/Q; zeros(ma,nb)];Ct = [C zeros(mc,ma)];Dt = d;

If the inpu t to lp2bp is in t ransfer funct ion form, the funct ion t ransforms it in tosta t e-space form before applying th is a lgor ithm.

See Also bilinear Bilinear t ransformat ion method of ana log-to-digita lfilt er conversion .

impinvar Impulse inva r iance method of ana log-to-digita l filterconversion.

lp2bs Lowpass to bandstop analog filt er t ransformat ion.lp2hp Lowpass to h ighpass ana log filt er t ransforma t ion .lp2lp Lowpass to lowpass ana log filt er t ransformat ion .

Page 527: MATLAB Signal Processing Toolbox user manual

lp2bs

6-223

6lp2bsPurpose Lowpass to bandstop ana log filter t ransformat ion .

Syntax [bt,at] = lp2bs(b,a,Wo,Bw)[At,Bt,Ct,Dt] = lp2bs(A,B,C,D,Wo,Bw)

Description lp2bs t ransforms analog lowpass filt er prototypes with a cutoff frequency of1 rad/sec in to bandstop filt er s with desired bandwidth and cen ter frequency.The t ransformat ion is one st ep in the digita l filter design process for thebutter, cheby1, cheby2, and ellip funct ions.

lp2bs can per form the t ransformat ion on two differen t linear syst emrepresen ta t ions: t ransfer funct ion form and sta t e-space form. In both cases, theinpu t syst em must be an ana log filt er prototype.

Transfer Function Form (Polynomial)

[bt,at] = lp2bs(b,a,Wo,Bw) t r ansforms an analog lowpass filt er prototypegiven by polynomia l coefficien ts in to a bandstop filt er with cen ter frequency Woand bandwidth Bw. Row vectors b and a specify the coefficien t s of the numera torand denomina tor of the prototype in descending powers of s:

Sca la rs Wo and Bw specify the cen ter frequency and bandwidth in unit s ofradians/second. For a filt er with lower band edge w1 and upper band edge w2,use Wo = sqrt(w1*w2) and Bw = w2–w1.

lp2bs retu rns the frequency t ransformed filter in row vectors bt and at.

State-Space Form

[At,Bt,Ct,Dt] = lp2bs(A,B,C,D,Wo,Bw) conver ts the con t inuous-t imesta t e-space lowpass filter prototype in matr ices A, B, C, D:

b s( )a s( )---------- b 1( )sn b L b n b( )s b n b 1+( )+ + +

a 1( )sn a L a n a( )s a n a 1+( )+ + +------------------------------------------------------------------------------------=

x· Ax B u+=y Cx Du+=

Page 528: MATLAB Signal Processing Toolbox user manual

lp2bs

6-224

in to a bandstop filter with cen ter frequency Wo and bandwidth Bw. For a filterwith lower band edge w1 and upper band edge w2, use Wo = sqrt(w1*w2) andBw = w2–w1.

The bandstop filter is retu rned in ma tr ices At, Bt, Ct, Dt.

Algorithm lp2bs is a h ighly accura te st a te-space formula t ion of the cla ssic ana log filterfrequency t ransformat ion . If a bandstop filter is to have center frequency ω0and bandwidth Bw, the st andard s-doma in t ransformat ion is

where Q = ω0/Bw and p = s/ω0. The st a te-space version of th is t ransformat ion is

Q = Wo/Bw;At = [Wo/Q*inv(A) Wo*eye(ma);–Wo*eye(ma) zeros(ma)];Bt = –[Wo/Q*(A B); zeros(ma,nb)];Ct = [C/A zeros(mc,ma)];Dt = D – C/A*B;

See lp2bp for a der iva t ion of the bandpass version of th is t ransformat ion .

See Also

s pQ p 2 1+( )------------------------=

bilinear Bilinear t ransformat ion method of ana log-to-digita lfilt er conversion .

impinvar Impulse inva r iance method of ana log-to-digita l filterconversion.

lp2bp Lowpass to bandpass ana log filter t ransformat ion .lp2hp Lowpass to h ighpass ana log filt er t ransforma t ion .lp2lp Lowpass to lowpass ana log filt er t ransformat ion .

Page 529: MATLAB Signal Processing Toolbox user manual

lp2hp

6-225

6lp2hpPurpose Lowpass to highpass ana log filt er t ransformat ion.

Syntax [bt,at] = lp2hp(b,a,Wo)[At,Bt,Ct,Dt] = lp2hp(A,B,C,D,Wo)

Description lp2hp t ransforms analog lowpass filt er prototypes with a cutoff frequency of1 rad/sec in to h ighpass filter s with desired cu toff frequency. Thet ransformat ion is one step in the digit a l filter design process for the butter,cheby1, cheby2, and ellip funct ions.

The lp2hp funct ion can per form the t ransformat ion on two differen t linea rsystem represen ta t ions: t ransfer funct ion form and sta te-space form. In bothcases, the inpu t system must be an ana log filter prototype.

Transfer Function Form (Polynomial)

[bt,at] = lp2hp(b,a,Wo) t ransforms an analog lowpass filt er prototypegiven by polynomia l coefficient s in to a h ighpass filter with cutoff frequency Wo.Row vectors b and a specify the coefficien ts of the numera tor and denomina torof the prototype in descending powers of s:

Sca la r Wo specifies the cu toff frequency in unit s of radians/second. Thefrequency t ransformed filt er is returned in row vectors bt and at.

State-Space Form

[At,Bt,Ct,Dt] = lp2hp(A,B,C,D,Wo) conver ts the cont inuous-t imesta t e-space lowpass filter prototype in matr ices A, B, C, D:

in to a h ighpass filt er with cutoff frequency Wo. The h ighpass filt er is retu rnedin ma t r ices At, Bt, Ct, Dt.

b s( )a s( )---------- b 1( )sn b L b n b( )s b n b 1+( )+ + +

a 1( )sn a L a n a( )s a n a 1+( )+ + +------------------------------------------------------------------------------------=

x· Ax B u+=y Cx Du+=

Page 530: MATLAB Signal Processing Toolbox user manual

lp2hp

6-226

Algorithm lp2hp is a h ighly accura te st a te-space formula t ion of the cla ssic ana log filterfrequency t ransforma t ion . If a h ighpass filter is to have cu toff frequency ω0, thestandard s-domain t ransformat ion is

The sta te-space version of th is t ransformat ion is

At = Wo*inv(A);Bt = –Wo*(A\B);Ct = C/A;Dt = D – C/A*B;

See lp2bp for a der iva t ion of the bandpass version of th is t ransformat ion .

See Also

sω0p-------=

bilinear Bilinear t ransformat ion method of ana log-to-digita lfilt er conversion .

impinvar Impulse inva r iance method of ana log-to-digita l filterconversion.

lp2bp Lowpass to bandpass ana log filter t ransformat ion .lp2bs Lowpass to bandstop analog filt er t ransformat ion.lp2lp Lowpass to lowpass ana log filt er t ransformat ion .

Page 531: MATLAB Signal Processing Toolbox user manual

lp2lp

6-227

6lp2lpPurpose Lowpass to lowpass ana log filt er t ransformat ion.

Syntax [bt,at] = lp2lp(b,a,Wo)[At,Bt,Ct,Dt] = lp2lp(A,B,C,D,Wo)

Description lp2lp t r ansforms an ana log lowpass filt er prototype with a cutoff frequency of1 rad/sec in to a lowpass filt er with any specified cu toff frequency. Thet ransformat ion is one step in the digit a l filter design process for the butter,cheby1, cheby2, and ellip funct ions.

The lp2lp funct ion can per form the t ransformat ion on two differen t linea rsystem represen ta t ions: t ransfer funct ion form and sta te-space form. In bothcases, the inpu t system must be an ana log filter prototype.

Transfer Function Form (Polynomial)

[bt,at] = lp2lp(b,a,Wo) t ransforms an analog lowpass filt er prototypegiven by polynomia l coefficien ts in to a lowpass filt er with cu toff frequency Wo.Row vectors b and a specify the coefficien ts of the numera tor and denomina torof the prototype in descending powers of s:

Sca la r Wo specifies the cu toff frequency in unit s of radians/second. lp2lpretu rns the frequency t ransformed filt er in row vectors bt and at.

State-Space Form

[At,Bt,Ct,Dt] = lp2lp(A,B,C,D,Wo) conver ts the cont inuous-t imesta t e-space lowpass filter prototype in matr ices A, B, C, D:

in to a lowpass filter with cu toff frequency Wo. lp2lp retu rns the lowpass filt erin ma t r ices At, Bt, Ct, Dt.

b s( )a s( )---------- b 1( )sn b L b n b( )s b n b 1+( )+ + +

a 1( )sn a L a n a( )s a n a 1+( )+ + +------------------------------------------------------------------------------------=

x· Ax B u+=y Cx Du+=

Page 532: MATLAB Signal Processing Toolbox user manual

lp2lp

6-228

Algorithm lp2lp is a h ighly accura te st a te-space formula t ion of the cla ssic ana log filterfrequency t ransforma t ion . If a lowpass filter is to have cu toff frequency ω0, thestandard s-domain t ransformat ion is

The sta te-space version of th is t ransformat ion is

At = Wo*A;Bt = Wo*B;Ct = C;Dt = D;

See lp2bp for a der iva t ion of the bandpass version of th is t ransformat ion .

See Also

s p ω0⁄=

bilinear Bilinear t ransformat ion method of ana log-to-digita lfilt er conversion .

impinvar Impulse inva r iance method of ana log-to-digita l filterconversion.

lp2bp Lowpass to bandpass ana log filter t ransformat ion .lp2bs Lowpass to bandstop analog filt er t ransformat ion.lp2hp Lowpass to h ighpass ana log filt er t ransforma t ion .

Page 533: MATLAB Signal Processing Toolbox user manual

lpc

6-229

6lpcPurpose Linea r predict ion coefficien t s.

Syntax a = lpc(x,p)

Description lpc determines the coefficien ts of a forward linea r predictor by min imizing thepredict ion er ror in the lea st -squa res sense. It has applica t ions in filter designand speech coding.

a = lpc(x,p) finds the coefficien t s of a pt h -order linear predictor (F IR filt er )tha t predict s the cur ren t va lue of the rea l t ime ser ies x based on past samples:

p is the order of the predict ion polynomia l, a = [1 a(2) ... a(p+1)].

If p is unspecified, lpc uses as a default p = length(x)–1. If x is a mat r ixconta in ing a sepa ra te signa l in each column, lpc retu rns a model est imate foreach column in the rows of mat r ix a.

Example Est ima te a da ta ser ies using a 3rd-order forward predictor , and compare to theor igina l signa l.

F ir st , crea t e the signa l da ta as the outpu t of an au toregressive process dr ivenby whit e noise. Use the la st 4096 samples of the AR process output to avoidsta r t -up t ransien t s.

noise = randn(50000,1); % Normalized white Gaussian noisex = filter(1,[1 1/2 1/3 1/4],noise);x = x(45904:50000);

Compute the predictor coefficien t s, est ima ted signa l, predict ion er ror , andautocor rela t ion sequence of the predict ion er ror .

a = lpc(x,3);

est_x = filter([0 –a(2:end)],1,x); % Estimated signale = x – est_x; % Prediction error[acs,lags] = xcorr(e,'coeff'); % ACS of prediction error

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

Page 534: MATLAB Signal Processing Toolbox user manual

lpc

6-230

The predict ion er ror , e(n ), can be viewed as the outpu t of the predict ion er rorfilt er A(z) shown below, where H (z) is the opt imal linear predictor , x(n ) is theinpu t signa l, and is the predict ed signa l.

Compare the predict ed signa l to the origina l signa l.

plot(1:97,x(4001:4097),1:97,est_x(4001:4097),'--');title('Original Signal vs. LPC Estimate');xlabel('Samples'); ylabel('Amplitude'); grid;legend('Original Signal','LPC Estimate')

Look a t the au tocor rela t ion of the predict ion er ror .

plot(lags,acs); title('Autocorrelation of the Prediction Error');xlabel('Lags'); ylabel('Normalized Value'); grid;

x n( )

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

–+

e n( )

Prediction Error Filter

A z( )

0 20 40 60 80 100−4

−3

−2

−1

0

1

2

3Original Signal vs. LPC Estimate

Samples

Ampl

itude

Original SignalLPC Estimate

Page 535: MATLAB Signal Processing Toolbox user manual

lpc

6-231

The predict ion er ror is approximately white Gaussian noise, a s expected for a3rd-order AR input process.

Algorithm lpc uses the autocor rela t ion method of autoregressive (AR) modeling to findthe filt er coefficien ts. The genera ted filter migh t not model the process exact lyeven if the da ta sequence is t ru ly an AR process of the cor rect order . This isbecause the autocor rela t ion method implicit ly windows the data , tha t is, ita ssumes tha t signa l samples beyond the length of x a re 0.

lpc computes the least -squares solu t ion to

where

−5000 0 5000−0.2

0

0.2

0.4

0.6

0.8

1

1.2Autocorrelation of the Prediction Error

Lags

Nor

mal

ized

Val

ue

Xa b≈

X

x 1( ) 0 L 0x 2( ) x 1( ) O M

M x 2( ) O 0x m( ) M Ox 1( )0 x m( ) Ox 2( )M O O M

0 L 0 x m( )

= a

1a 2( )

M

a p 1+( )

= b

10M

0

=, ,

Page 536: MATLAB Signal Processing Toolbox user manual

lpc

6-232

and m is the length of x. Solving the least -squa res problem via the normalequat ions

leads to the Yule-Walker equa t ions

where r = [r(1) r(2) ... r(p+1)] is an au tocor rela t ion est imate for x computedusing xcorr. The Yule-Walker equa t ions a re solved in O(p2) flops by theLevinson-Durbin a lgor ithm (see levinson).

See Also

References [1] J ackson , L.B. Digital Filters and S ignal Processing. Second Ed. Boston :Kluwer Academic Publishers, 1989. Pgs. 255-257.

XHXa XHb=

r 1( ) r 2( )* L r p( )*r 2( ) r 1( ) O M

M O O r 2( )*r p( ) L r 2( ) r 1( )

a 2( )a 3( )

M

a p 1+( )

r 2( )–r 3( )–M

r p 1+( )–

=

aryule Compute an est ima te of AR model parameters usingthe Yule-Walker method.

levinson Levinson-Durbin recursion .prony Prony’s method for t ime domain IIR filter design .pyulear Power spect rum est ima te using Yule-Walker AR

method.stmcb Linear model using Steiglitz-McBride itera t ion .

Page 537: MATLAB Signal Processing Toolbox user manual

maxflat

6-233

6maxfla tPurpose Genera lized digit a l But terwor th filter design .

Syntax [b,a,] = maxflat(nb,na,Wn)b = maxflat(nb,'sym',Wn)[b,a,b1,b2] = maxflat(nb,na,Wn)[...] = maxflat(nb,na,Wn,'design_flag')

Description [b,a,] = maxflat(nb,na,Wn) is a lowpass But t erwor th filter with numera torand denominator coefficien t s b and a of orders nb and na respect ively. Wn is t hecu toff frequency at which the magnitude response of the filt er is equa l to

(approx. -3 dB). Wn must be between 0 and 1, where 1 cor responds to ha lfthe sampling frequency (the Nyquist frequency).

b = maxflat(nb,'sym',Wn) is a symmetr ic FIR But terwor th filter . nbmust beeven , and Wn is rest r icted to a subin terva l of [0,1]. The funct ion ra ises an er rorif Wn is specified outside of this subin terva l.

[b,a,b1,b2] = maxflat(nb,na,Wn) retu rns two polynomia ls b1 and b2whoseproduct is equa l to the numera tor polynomia l b (tha t is, b = conv(b1,b2)). b1 conta ins a ll the zeros a t z = –1, and b2 con ta ins a ll t he other zeros.

[...] = maxflat(nb,na,Wn,'design_flag') enables you to monitor the filt erdesign , where design_flag is

• trace, for a t extua l display of the design table used in the design• plots, for plot s of the filt er ’s magnitude, group delay, and zeros and poles• both, for both the textua l display and plots

Page 538: MATLAB Signal Processing Toolbox user manual

maxflat

6-234

Examples nb = 10; na = 2; Wn = 0.2*pi;[b,a,b1,b2] = maxflat(nb,na,Wn,'plots')

Algorithm The method consist s of the use of formulae, polynomia l root finding, and at ransformat ion of polynomia l root s.

See Also

References [1] Selesn ick, I.W., and C.S. Bur rus. “Genera lized Digita l But terworth FilterDesign .”Proceedings of the IEEE Int. Conf. Acoust., S peech, S ignal Processing.Vol. 3 (May 1996).

0 0.2 0.4 0.6 0.8 10

0.5

1

w/p

Mag

nitu

de

Frequency response

-1 0 1

-1

-0.5

0

0.5

1

Real

Imag

Pole-zero plot

<- deg 4

0 0.5 10

1

2

3

4

5

w/p

Sam

ples

Group delay

butter But terwor th ana log and digita l filt er design.filter Filt er da ta with a recursive (IIR) or nonrecursive

(FIR) filter.freqz Frequency response of digita l filter s.

Page 539: MATLAB Signal Processing Toolbox user manual

medfilt1

6-235

6medfilt1Purpose One-dimensiona l median filter ing.

Syntax y = medfilt1(x,n)y = medfilt1(x,n,blksz)

Description y = medfilt1(x,n) applies an order n, one-dimensiona l median filt er to vectorx. y is the same length as x; the funct ion t rea ts the signa l a s if it is 0 beyondthe end poin t s.

For n odd, y(k) is the median of x(k–(n–1)/2:k+(n–1)/2).

For n even, y(k) is the median of x(k–n/2), x(k–(n/2)+1), ..., x(k+(n/2)–1).In th is case, medfilt1 sor ts the numbers, then takes the average of the (n–1)/2 and ((n–1)/2)+1 elements.

The defau lt for n is 3.

y = medfilt1(x,n,blksz) uses a for-loop to compute blksz (block size)ou tpu t samples a t a t ime. Use blksz << length(x) if you a re low on memory,since medfilt1 uses a working matr ix of size n-by-blksz. By defau lt ,blksz = length(x); t h is is the fa st est execu t ion if you have sufficien t memory.

If x is a matr ix, medfilt1 median filter s it s columns using

y(:,i) = medfilt1(x(:,i),n,blksz)

in a loop over the columns of x.

See Also

References [1] Pra t t , W.K. Digital Im age Processing. New York: J ohn Wiley & Sons, 1978.Pgs. 330-333.

filter Filt er da ta with a recursive (IIR) or nonrecursive(FIR) filter.

medfilt2 Two-dimensiona l median filter ing (see Im ageProcessing Toolbox User’s Guide).

median Median va lue (see the online MATLAB FunctionReference).

Page 540: MATLAB Signal Processing Toolbox user manual

modulate

6-236

6modulatePurpose Modula t ion for communica t ions simula t ion .

Syntax y = modulate(x,Fc,Fs,'method')y = modulate(x,Fc,Fs,'method',opt)[y,t] = modulate(x,Fc,Fs)

Description y = modulate(x,Fc,Fs,'method') and

y = modulate(x,Fc,Fs,'method',opt) modula te the rea l message signa l xwith a car r ier frequency Fc and sampling frequency Fs, using one of the opt ionslist ed below for method. Note tha t some methods accept an opt ion , opt.

amdsb–scor

am

Amplitude modu la tion , double s ideband, suppre ssed carrie r.Mult iplies x by a sinusoid of frequency Fc:

y = x.*cos(2*pi*Fc*t)

amdsb–tc Amplitude modu la tion , double s ideband, tran smitted carrie r.Subt racts sca la r opt from x and mult iplies the result by a sinusoidof frequency Fc:

y = (x–opt).*cos(2*pi*Fc*t)

If the opt pa rameter is not presen t , modulate uses a defau lt ofmin(min(x)) so tha t the message signa l (x–opt) is en t irelynon-negat ive and has a minimum value of 0.

amssb Amplitude modu la tion , s ingle s ideband. Mult iplies x by asinusoid of frequency Fc and adds the result to the Hilbert t ransformof x mult iplied by a phase shifted sinusoid of frequency Fc:

y = x.*cos(2*pi*Fc*t)+imag(hilbert(x)).*sin(2*pi*Fc*t)

This effect ively removes the upper sideband.

Page 541: MATLAB Signal Processing Toolbox user manual

modulate

6-237

fm Frequency modu lation . Crea tes a sinusoid with inst an taneousfrequency tha t var ies with the message signa l x:

y = cos(2*pi*Fc*t + opt*cumsum(x))

cumsum is a rectangula r approxima t ion to the in t egra l of x.modulate uses opt as the constan t of frequency modula t ion. If optis not presen t , modulate uses a default of

opt = (Fc/Fs)*2*pi/(max(max(x)))

so the maximum frequency excursion from Fc is Fc Hz.

pm Phase modu la t ion . Creates a sinusoid of frequency Fc whosephase var ies with the message signa l x:

y = cos(2*pi*Fc*t + opt*x)

modulate uses opt as the constan t of phase modula t ion . If opt isnot presen t , modulate uses a default of

opt = pi/(max(max(x)))

so the maximum phase excursion is π radians.

pwm Pulse -w idth modu lation . Crea tes a pulse-width modula tedsigna l from the pulse widths in x. The elements of x must bebetween 0 and 1, specifying the width of each pulse in fract ions ofa per iod. The pulses sta r t a t the beginn ing of each per iod, tha t is,they are left just ified.

modulate(x,Fc,Fs,'pwm','centered')

yields pu lses cen tered a t the beginning of each per iod. y is length length(x)*Fs/Fc.

ptm Pulse time modu la tion . Creates a pu lse t ime modula t ed signa lfrom the pulse t imes in x. The elements of x must be between 0and 1, specifying the left edge of each pulse in fract ions of a per iod.opt is a sca la r between 0 and 1 tha t specifies the length of eachpulse in fract ions of a per iod. The default for opt is 0.1. y is lengthlength(x)*Fs/Fc.

qam Quadrature amplitude modu lation . Creates a quadra tu reamplitude modula t ed signa l from signa ls x and opt:

y = x.*cos(2*pi*Fc*t) + opt.*sin(2*pi*Fc*t)

opt must be the same size as x.

Page 542: MATLAB Signal Processing Toolbox user manual

modulate

6-238

If you do not specify method, t hen modulate assumes am. Except for the pwm andptm cases, y is the same size as x.

If x is an ar ray, modulate modula tes it s columns.

[y,t] = modulate(x,Fc,Fs) retu rns the in t erna l t ime vector t tha t modulateuses in it s computa t ions.

See Also demod Demodula t ion for communica t ions simula t ion .vco Voltage cont rolled oscilla tor.

Page 543: MATLAB Signal Processing Toolbox user manual

pburg

6-239

6pbu rgPurpose Power spect rum est imate using the Burg method.

Syntax Pxx = pburg(x,p,nfft)[Pxx,freq] = pburg(x,p,nfft)[Pxx,freq] = pburg(x,p,nfft,Fs)[Pxx,freq] = pburg(x,p,nfft,Fs,'range')pburg(...)pburg(...,'squared')

Description pburg est ima tes the power spect ra l density (PSD) of the signa l vector x[n ]using the Burg method. This method fit s an au toregressive (AR) model to thesigna l by minimizing (least squares) the forward and backward predict ioner rors while const ra in ing the AR parameters to sa t isfy the Levinson-Durbinrecursion . The spect ra l est ima te returned by pburg is the magnitude squaredfrequency response of th is AR model. The cor rect choice of the model order p isimpor tan t .

Pxx = pburg(x,p,nfft) retu rns Pxx, the power spect rum est ima te. x is theinpu t signa l, p is the model order for the a ll-pole filter , and nfft is the FFTlength (default s to 256 if not specified). Pxx has length (nfft/2+1) for nffteven , (nfft+1)/2 for nfft odd, and nfft if x is complex.

[Pxx,freq] = pburg(x,p,nfft) retu rns Pxx, t he power spect rum est imate,and freq, a vector of frequencies a t which the PSD was est imated. If the inpu tsigna l is rea l-va lued, the range of freq is [0,π). If the input signa l is complex,the range of freq is [0,2π).

[Pxx,freq] = pburg(x,p,nfft,Fs) uses the signa l’s sampling frequency, Fs,to sca le both the PSD vector (Pxx) and the frequency vector (freq). Pxx is sca ledby 1/Fs. If the input signa l is rea l-va lued, the range of freq is [0,Fs/2). If theinput signa l is complex, the range of freq is [0,Fs). Fs defau lt s to 1 if leftempty, [].

[Pxx,freq] = pburg(x,p,nfft,Fs,'range') specifies the range of frequencyva lues to include in freq. range can be:

• half, to compute the PSD over the range [0,Fs/2) for rea l x, and [0,Fs) forcomplex x. If Fs is left blank, [], t he range is [0,1/2) for rea l x, and [0,1)

Page 544: MATLAB Signal Processing Toolbox user manual

pburg

6-240

for complex x. If Fs is omit t ed ent irely, t he range is [0,pi) for rea l x, and[0,2*pi) for complex x. half is the defau lt range.

• whole, t o compute the PSD over the range [0,Fs) for a ll x. If Fs is leftblank, [], the range is [0,1) for a ll x. If Fs is omit t ed ent irely, the range is[0,2*pi) for a ll x.

pburg(...) plot s the power spect ra l density in the cur ren t figure window. Thefrequency range on the plot is the same as the range of ou tpu t freq for a givenset of pa rameter s.

pburg(...,'squared') plot s the magnitude of Pxx direct ly, ra ther thanconver t ing the va lues to dB.

Example Because the method est imates the spect rum by fit t ing an AR model to thesigna l, fir st define the AR system (a ll-pole filt er ) tha t genera t es the input .Check the magnitude response of the process with freqz.

a = [1 –2.2137 2.9403 –2.1697 0.9606]; % AR system coefficientsfreqz(1,a,'phase','no') % AR system magnitude responsetitle('AR System Magnitude Response')

0 0.2 0.4 0.6 0.8 1−20

−10

0

10

20

30

40

Normalized Angular Frequency (×π rads/sample)

Mag

nitu

de (d

B)

AR System Magnitude Response

Page 545: MATLAB Signal Processing Toolbox user manual

pburg

6-241

Now genera te the inpu t signa l x by filt er ing white noise through the ARsystem. Est imate the PSD of x based on a four th -order AR model (since weknow that the or igina l AR system, a, has order 4).

x = filter(1,a,randn(150,1)); % AR system outputpburg(x,4) % 4th order estimate

Diagnostics The fir st inpu t argument must be a fu ll vector ; otherwise pburg genera tes thefollowing er ror message:

Input signal cannot be sparse.

If you specify an empty ma tr ix for the second a rgument , pburg genera t es thefollowing er ror message:

Model order must be an integer.

0 0.2 0.4 0.6 0.8 1−20

−10

0

10

20

30

40

Normalized Angular Frequency (×π rads/sample)

Pow

er S

pect

ral D

ensi

ty (d

B)Burg Spectral Estimate Pxx(ω)

Page 546: MATLAB Signal Processing Toolbox user manual

pburg

6-242

See Also

References [1] Marple, S.L. Digital S pectral Analysis. Englewood Cliffs, NJ : Pren t ice Hall,1987. Chapter 7.

arburg Compute an est ima te of AR model parameters usingthe Burg method.

lpc Linear predict ion coefficien ts.pcov Power spect rum est ima te using the covar iance

method.pmcov Power spect rum est ima te using the modified

covar iance method.pmtm Power spect rum est ima te using the mult it aper

method (MTM).pmusic Power spect rum est ima te using MUSIC eigenvector

method.prony Prony’s method for t ime domain IIR filter design .pwelch Est imate the power spect ra l density (PSD) of a signa l

using Welch’s method.pyulear Power spect rum est ima te using Yule-Walker AR

method.

Page 547: MATLAB Signal Processing Toolbox user manual

pcov

6-243

6pcovPurpose Power spect rum est imate using the covar iance method.

Syntax Pxx = pcov(x,p,nfft)[Pxx,freq] = pcov(x,p,nfft)[Pxx,freq] = pcov(x,p,nfft,Fs)[Pxx,freq] = pcov(x,p,nfft,Fs,'range')pcov(...)pcov(...,'squared')

Description pcov est imates the power spect ra l density (PSD) of the signa l vector x[n ] usingthe cova r iance method. This method fit s an au toregressive (AR) model to thesigna l by minimizing the forward predict ion er ror in the least -squares sense.The spect ra l est ima te retu rned by pcov is the magnitude squared frequencyresponse of th is AR model. The cor rect choice of the model order p is impor tan t .

Pxx = pcov(x,p,nfft) retu rns Pxx, the power spect rum est imate. x is theinpu t signa l, p is the model order for the a ll-pole filter , and nfft is the FFTlength (default s to 256 if not specified). Pxx has length (nfft/2+1) for nffteven , (nfft+1)/2 for nfft odd, and nfft if x is complex.

[Pxx,freq] = pcov(x,p,nfft) retu rns Pxx, t he power spect rum est imate,and freq, a vector of frequencies a t which the PSD was est imated. If the inpu tsigna l is rea l-va lued, the range of freq is [0,π). If the input signa l is complex,the range of freq is [0,2π).

[Pxx,freq] = pcov(x,p,nfft,Fs) uses the signa l’s sampling frequency, Fs,to sca le both the PSD vector (Pxx) and the frequency vector (freq). Pxx is sca ledby 1/Fs. If the input signa l is rea l-va lued, the range of freq is [0,Fs/2). If theinput signa l is complex, the range of freq is [0,Fs). Fs defau lt s to 1 if leftempty, [].

[Pxx,freq] = pcov(x,p,nfft,Fs,'range') specifies the range of frequencyva lues to include in freq. range can be:

• half, to compute the PSD over the range [0,Fs/2) for rea l x, and [0,Fs) forcomplex x. If Fs is left blank, [], t he range is [0,1/2) for rea l x, and [0,1)

Page 548: MATLAB Signal Processing Toolbox user manual

pcov

6-244

for complex x. If Fs is omit t ed ent irely, t he range is [0,pi) for rea l x, and[0,2*pi) for complex x. half is the defau lt range.

• whole, t o compute the PSD over the range [0,Fs) for a ll x. If Fs is leftblank, [], the range is [0,1) for a ll x. If Fs is omit t ed ent irely, the range is[0,2*pi) for a ll x.

pcov(...) plots the power spect ra l density in the fir st ava ilable figure window.The frequency range on the plot is the same as the range of ou tpu t freq for agiven set of parameter s.

pcov(...,'squared') plot s the magnitude of Pxx direct ly, ra ther thanconver t ing the va lues to dB.

Example Because the method est imates the spect rum by fit t ing an AR model to thesigna l, fir st define the AR system (a ll-pole filt er ) tha t genera t es the input .Check the magnitude response of the process with freqz.

a = [1 –2.2137 2.9403 –2.1697 0.9606]; % AR system coefficientsfreqz(1,a,'phase','no') % AR system magnitude responsetitle('AR System Magnitude Response')

0 0.2 0.4 0.6 0.8 1−20

−10

0

10

20

30

40

Normalized Angular Frequency (×π rads/sample)

Mag

nitu

de (d

B)

AR System Magnitude Response

Page 549: MATLAB Signal Processing Toolbox user manual

pcov

6-245

Now genera te the inpu t signa l x by filt er ing white noise through the ARsystem. Est imate the PSD of x based on a four th -order AR model (since weknow that the or igina l AR system, a, has order 4).

x = filter(1,a,randn(150,1)); % AR system outputpcov(x,4) % 4th order estimate

Diagnostics The fir st inpu t argument must be a fu ll vector ; otherwise pcov genera tes thefollowing er ror message:

Input signal cannot be sparse.

If you specify an empty ma tr ix for the second a rgument , pcov genera t es thefollowing er ror message:

Model order must be an integer.

0 0.2 0.4 0.6 0.8 1−20

−10

0

10

20

30

40

Normalized Angular Frequency (×π rads/sample)

Pow

er S

pect

ral D

ensi

ty (d

B)Covariance Spectral Estimate Pxx(ω)

Page 550: MATLAB Signal Processing Toolbox user manual

pcov

6-246

See Also

References [1] Marple, S.L. Digital S pectral Analysis. Englewood Cliffs, NJ : Pren t ice Hall,1987. Chapter 7.

arcov Compute an est ima te of AR model parameters usingthe covar iance method.

lpc Linear predict ion coefficien ts.pburg Power spect rum est ima te using the Burg method.pmcov Power spect rum est ima te using the modified

covar iance method.pmtm Power spect rum est ima te using the mult it aper

method (MTM).pmusic Power spect rum est ima te using MUSIC eigenvector

method.prony Prony’s method for t ime domain IIR filter design .pwelch Est imate the power spect ra l density (PSD) of a signa l

using Welch’s method.pyulear Power spect rum est ima te using Yule-Walker AR

method.

Page 551: MATLAB Signal Processing Toolbox user manual

pmcov

6-247

6pmcovPurpose Power spect rum est imate using the modified covar iance method.

Syntax Pxx = pmcov(x,p,nfft)[Pxx,freq] = pmcov(x,p,nfft)[Pxx,freq] = pmcov(x,p,nfft,Fs)[Pxx,freq] = pmcov(x,p,nfft,Fs,'range')pmcov(...)pmcov(...,'squared')

Description pmcov est ima tes the power spect ra l density (PSD) of the signa l vector x[n ]using the modified covar iance method. This method fit s an au toregressive (AR)model to the signa l by min imizing the forward and backward predict ion er rorsin the lea st -squares sense. The spect ra l est imate returned by pmcov is themagnitude squared frequency response of th is AR model. The cor rect choice ofthe model order p is impor tan t .

Pxx = pmcov(x,p,nfft) retu rns Pxx, the power spect rum est ima te. x is theinpu t signa l, p is the model order for the a ll-pole filter , and nfft is the FFTlength (default s to 256 if not specified). Pxx has length (nfft/2+1) for nffteven , (nfft+1)/2 for nfft odd, and nfft if x is complex.

[Pxx,freq] = pmcov(x,p,nfft) retu rns Pxx, t he power spect rum est imate,and freq, a vector of frequencies a t which the PSD was est imated. If the inpu tsigna l is rea l-va lued, the range of freq is [0,π). If the input signa l is complex,the range of freq is [0,2π).

[Pxx,freq] = pmcov(x,p,nfft,Fs) uses the signa l’s sampling frequency, Fs,to sca le both the PSD vector (Pxx) and the frequency vector (freq). Pxx is sca ledby 1/Fs. If the input signa l is rea l-va lued, the range of freq is [0,Fs/2). If theinput signa l is complex, the range of freq is [0,Fs). Fs defau lt s to 1 if leftempty, [].

[Pxx,freq] = pmcov(x,p,nfft,Fs,'range') specifies the range of frequencyva lues to include in freq. range can be:

• half, to compute the PSD over the range [0,Fs/2) for rea l x, and [0,Fs) forcomplex x. If Fs is left blank, [], t he range is [0,1/2) for rea l x, and [0,1)

Page 552: MATLAB Signal Processing Toolbox user manual

pmcov

6-248

for complex x. If Fs is omit t ed ent irely, t he range is [0,pi) for rea l x, and[0,2*pi) for complex x. half is the defau lt range.

• whole, t o compute the PSD over the range [0,Fs) for a ll x. If Fs is leftblank, [], the range is [0,1) for a ll x. If Fs is omit t ed ent irely, the range is[0,2*pi) for a ll x.

pmcov(...) plots the power spect ra l density in the fir st ava ilable figurewindow. The frequency range on the plot is the same as the range of ou tpu tfreq for a given set of parameters.

pmcov(...,'squared') plot s the magnitude of Pxx direct ly, ra ther thanconver t ing the va lues to dB.

Example Because the method est imates the spect rum by fit t ing an AR model to thesigna l, fir st crea t e the AR system (a ll-pole filt er ) tha t genera t es the input .Check the magnitude response of the process with freqz.

a = [1 –2.2137 2.9403 –2.1697 0.9606]; % AR system coefficientsfreqz(1,a,'phase','no') % AR system magnitude responsetitle('AR System Magnitude Response')

0 0.2 0.4 0.6 0.8 1−20

−10

0

10

20

30

40

Normalized Angular Frequency (×π rads/sample)

Mag

nitu

de (d

B)

AR System Magnitude Response

Page 553: MATLAB Signal Processing Toolbox user manual

pmcov

6-249

Now genera te the inpu t signa l x by filt er ing white noise through the ARsystem. Est imate the PSD of x based on a four th -order AR model (since weknow that the or igina l AR system, a, has order 4).

x = filter(1,a,randn(150,1)); % AR system outputpmcov(x,4) % 4th order estimate

Diagnostics The fir st inpu t argument must be a fu ll vector ; otherwise pmcov genera tes thefollowing er ror message:

Input signal cannot be sparse.

If you specify an empty ma tr ix for the second a rgument , pmcov genera t es thefollowing er ror message:

Model order must be an integer.

0 0.2 0.4 0.6 0.8 1−30

−20

−10

0

10

20

30

40

Normalized Angular Frequency (×π rads/sample)

Pow

er S

pect

ral D

ensi

ty (d

B)Modified Covariance Spectral Estimate Pxx(ω)

Page 554: MATLAB Signal Processing Toolbox user manual

pmcov

6-250

See Also

References [1] Marple, S.L. Digital S pectral Analysis. Englewood Cliffs, NJ : Pren t ice Hall,1987. Chapter 7.

armcov Compute an est ima te of AR model parameters usingthe modified covar iance method.

lpc Linear predict ion coefficien ts.pburg Power spect rum est ima te using the Burg method.pcov Power spect rum est ima te using the covar iance

method.pmtm Power spect rum est ima te using the mult it aper

method (MTM).pmusic Power spect rum est ima te using MUSIC eigenvector

method.prony Prony’s method for t ime domain IIR filter design .pwelch Est imate the power spect ra l density (PSD) of a signa l

using Welch’s method.pyulear Power spect rum est ima te using Yule-Walker AR

method.

Page 555: MATLAB Signal Processing Toolbox user manual

pmtm

6-251

6pmtmPurpose Power spect rum est imate using the mult itaper method (MTM).

Syntax Pxx = pmtm(x,nw)Pxx = pmtm(x,nw,nfft)[Pxx,f] = pmtm(x,nw,nfft,Fs)[Pxx,f] = pmtm(x,nw,nfft,Fs,'method')[Pxx,Pxxc,f] = pmtm(x,nw,nfft,Fs,'method')[Pxx,Pxxc,f] = pmtm(x,nw,nfft,Fs,'method',p)[Pxx,Pxxc,f] = pmtm(x,e,v,nfft,Fs,'method',p)[Pxx,Pxxc,f] = pmtm(x,dpss_params,nfft,Fs,'method',p)

Description pmtm est ima tes the power spect ra l density (PSD) of the rea l t ime ser ies x usingthe mult itaper method (MTM), descr ibed in [1].

Pxx = pmtm(x,nw) est ima tes the PSD using nw as the t ime-bandwidth productfor the discrete prola te spheroida l sequences (Slepian sequences) tha t a re usedas da ta windows. The default for nw is 4; other typica l choices are2, 5/2, 3, 7/2. The number of sequences used to form Pxx is 2*nw–1.

Pxx = pmtm(x,nw,nfft) defines the frequency gr id as length nfft. When x isrea l, Pxx is length (nfft/2+1) for nfft even and (nfft+1)/2 for nfft odd;when x is complex, Pxx is length nfft. The defau lt for nfft is 256 or the nextpower of 2 grea ter than the length of x, whichever is la rger .

[Pxx,f] = pmtm(x,nw,nfft,Fs) retu rns f, the vector of frequencies a t whichthe PSD is est imated, for the sampling frequency Fs. The defau lt for Fs is 1 Hz.

[Pxx,f] = pmtm(x,nw,nfft,Fs,'method') specifies the a lgor ithm used forcombining the individua l spect ra l est imates, where method is:

• adapt, t o specify Thomson’s adapt ive non linear combina t ion (defau lt )• unity, t o specify a linear combina t ion with unity weights• eigen, t o specify a linear combina t ion with eigenva lue weigh ts

[Pxx,Pxxc,f] = pmtm(x,nw,nfft,Fs,'method') retu rns Pxxc, the 95%confidence in terva l for Pxx, and

[Pxx,Pxxc,f] = pmtm(x,nw,nfft,Fs,'method',p) retu rns Pxxc, the p*100%confidence in terva l for Pxx, where p is a sca la r between 0 and 1. Confidence

Page 556: MATLAB Signal Processing Toolbox user manual

pmtm

6-252

in t erva ls are computed using a ch i-squared approach , where Pxxc(:,1) is thelower bound and Pxxc(:,2) is the upper bound of the confidence in terva l.

[Pxx,Pxxc,f] = pmtm(x,e,v,nfft,Fs,'method',p) retu rns the PSDest imate Pxx, the confidence in terva l Pxxc, and the frequency vector f from thedata t apers in e and their concent ra t ions v.

[Pxx,Pxxc,f] = pmtm(x,dpss_params,nfft,Fs,'method',p) retu rns thePSD est imate Pxx, t he confidence in terva l Pxxc, and the frequency vector ffrom the data tapers computed using dpss with parameters from the cell a r raydpss_params, whose fir st element is the second inpu t to dpss. The fir st dpssparameter (n) is determined by the length of x. For example,pmtm(x,{3.5,'trace'},512,Fs) ca lcu la tes the Slepian sequences for nw = 3.5,and displays the method tha t dpss uses. See dpss for other opt ions.

Remarks pmtm with no output arguments plots the PSD in the curren t or next ava ilablefigure, with confidence in terva ls.

To use defau lt pa rameters for any argument in an expression , inser t an emptyma tr ix []. For example, pmtm(x,[],[],1000) uses default s for the second andthird elements, in th is case, nw and nfft.

Page 557: MATLAB Signal Processing Toolbox user manual

pmtm

6-253

Example This example ana lyzes a sinusoid in white noise:

Fs = 1000; t = 0:1/Fs:0.3;x = cos(2*pi*t*200) + randn(size(t));[Pxx,Pxxc,f] = pmtm(x,3.5,512,Fs,[],0.99);plot(f,10*log10([Pxx Pxxc]))

See Also

0 100 200 300 400 500-10

-5

0

5

10

15

20

dpss Discrete prola te spheroida l sequences (Slepiansequences).

pburg Power spect rum est ima te using the Burg method.pcov Power spect rum est ima te using the covar iance

method.pmcov Power spect rum est ima te using the modified

cova r iance method.pmusic Power spect rum est ima te using MUSIC eigenvector

method.pwelch Est imate the power spect ra l density (PSD) of a signa l

using Welch’s method.pyulear Power spect rum est ima te using Yule-Walker AR

method.

Page 558: MATLAB Signal Processing Toolbox user manual

pmtm

6-254

References [1] Perciva l, D.B., and A.T. Walden . S pectral Analysis for PhysicalApplications:Multitaper and Conven tional Univariate Techniques . Cambr idge:Cambr idge University Press, 1993.

[2] Thomson , D.J . “Spect rum est imat ion and harmonic ana lysis.” InProceed ings of the IEEE . Vol. 70 (1982). Pgs. 1055-1096.

Page 559: MATLAB Signal Processing Toolbox user manual

pmusic

6-255

6pmusicPurpose Power spect rum est imate using MUSIC eigenvector method.

Syntax [Pxx,f] = pmusic(x,p)[Pxx,f] = pmusic(x,[p thresh])[Pxx,f] = pmusic(x,[p thresh],nfft,Fs,window,noverlap)[Pxx,f] = pmusic(x,...,'corr')[Pxx,f] = pmusic(x,...,'ev')[Pxx,f,evects,svals] = pmusic(x,...)

Description pmusic est imates the power spect ra l density (PSD) of a signa l or cor rela t ionmat r ix using Schmidt ’s eigen-ana lysis method [1]. The name MUSIC is anacronym for MUlt iple SIgna l Classifica t ion . The eigenvector m ethod , whichuses eigenvalue weight ing, is a lso suppor t ed [2]. The ca lling syntax is simila rto tha t of pwelch, which a lso per forms spect rum est imat ion . pwelch uses thecla ssica l FFT-based approach while pmusic performs eigen-ana lysis of thesigna l’s cor rela t ion mat r ix.

[Pxx,f] = pmusic(x,p) and

[Pxx,f] = pmusic(x,[p thresh]) return Pxx, the power spect rum est imate,and f, a vector of frequencies a t which the PSD is est imated. x is the inputsigna l, where:

•A row or column vector represen ts one observa t ion of the process ou tpu t (forexample, one “signa l”)

•A rectangula r (possibly square) ar ray assumes tha t each column of x is asepa ra te observa t ion of the process outpu t (for example, each column is oneoutpu t of an ar ray of sensors, as in ar ray processing)

•A squa re matr ix, given the t ra iling a rgument 'corr', r epresen t s acor rela t ion mat r ix

The second argument is a one- or two-element vector , either p or [p thresh].If on ly p is specified, the signa l subspace dimension is p. If [p thresh] isspecified, thresh is mult iplied by λmin, the smallest eigenvalue; eigenvaluesbelow the threshold λmin*thresh are assigned to the noise subspace. In th iscase, p is the maximum dimension of the signa l subspace.

Page 560: MATLAB Signal Processing Toolbox user manual

pmusic

6-256

NOTE pmusic must assign eigenvectors to the noise and signa l subspaces,but th is is very difficu lt to do in pract ice. The two parameters p and threshare provided for flexibilit y and cont rol.

[Pxx,f] = pmusic(x,[p thresh],nfft,Fs,window,noverlap) specifies theFFT length nfft (defau lt is 256) and the sampling frequency for the signa l Fs(defau lt is 1). If Fs is specified, the ou tpu t frequency vector f is sca led by th isva lue. If the input signa l is rea l-va lued, the frequency range is 0 to Fs/2; forthe complex case, it is 0 to Fs. window is a sca la r specifying the rect angularwindow length , or a vector giving the actua l window coefficien ts. noverlap,used in conjunct ion with window, is a sca la r tha t gives the number of poin t s bywhich to over lap successive windows.

[Pxx,f] = pmusic(x,...,'corr') forces x to be taken as a correla t ionma tr ix. In this case, the a rguments window and noverlap are ignored.

[Pxx,f] = pmusic(x,...,'ev') select s the eigenvector var ian t of the MUSICest imator . See the “Algor ithm” sect ion below for an explana t ion of how this isdifferen t from the MUSIC method.

[Pxx,f,evects,svals] = pmusic(x,...) returns two addit iona l a rgument s.evects is a ma tr ix of eigenvectors spanning the noise subspace (one percolumn). svals is either a vector of singula r va lues (squared) from svd or avector of eigenva lues of the cor rela t ion matr ix when the 'corr' opt ion ispresen t .

Remarks The inpu t x can be a vector or a ma tr ix. x can be in terpreted as signa l da ta oras a correla t ion mat r ix, in one of three ways:

• x is a vector of signa l va lues (row or column). In th is case, the dimension ofthe eigenvectors must be given . This is done either by taking the defau ltva lue of 2*p or by specifying a window length using window.

• x is a rectangula r (m-by-n, possibly square) ma t r ix. In th is case, each columnof x is a separa t e observa t ion signa l tha t en ters in to the SVD analysis, n is

Page 561: MATLAB Signal Processing Toolbox user manual

pmusic

6-257

t he number of observat ions, and the dimension of the eigenvectors is equa lto m, the length of a column.

• x is a square mat r ix and the t ra iling 'corr' is present . x is t rea ted as acor rela t ion matr ix. In th is case, the mat r ix must have only rea l, nonnega t iveeigenva lues.

The inpu ts p and thresh can determine the number of noise eigenvectors in oneof four ways:

• If thresh < 1, or if it is unspecified, the number of eigenvectors spanning thesigna l subspace will be equal to p. pmust be an in teger sa t isfying 0 ≤ p < n,where n is the dimension of the eigenvector s. This dimension n is the columnlength in the da ta ma tr ix case, the mat r ix size in the cor rela t ion mat r ix case,or the window length for signa l vector s. The va lue of thresh is unused.

• If p ≥ n, thresh must be a t lea st 1. thresh is used as the mult iplier todetermine an absolu te threshold for split t ing the eigenvalues between thesigna l and noise subspaces:

• If thresh < 1, t here will be no noise eigenvectors. This case is not a llowedand gives the following er ror message:Noise subspace dimension cannot be zero.

•When p < n and thresh ≥ 1, p specifies the maximum number of signa leigenvector s. However , the th reshold test specified by thresh can a lso takeeigenvectors from the signa l subspace and assign them to the noise subspace.

Examples This example analyzes a signa l vector xx, a ssuming tha t two rea l signa ls arepresen t in the signa l subspace. In th is case, the dimension of the signa lsubspace is 4 because each rea l sinusoid is the sum of two complexexponent ia ls:

nn = 0:199;xx = cos(0.257*pi*nn) + sin(0.2*pi*nn) + 0.01*randn(size(nn));[PP,ff] = pmusic(xx,4);

This example ana lyzes the same signa l vector xx with an eigenva lue cu toff of10% above the minimum. Set t ing p = Inf forces the signa l/noise subspace

λk thresh( )m in λk( )≤ λk vk{ , } belong to noise subspace⇒

Page 562: MATLAB Signal Processing Toolbox user manual

pmusic

6-258

decision to be based on thresh. Use eigenvectors of dimension 7 and a samplingfrequency Fs of 8 kHz:

[PP,ff] = pmusic(xx,[Inf,1.1],[],8000,7); % window length = 7

With the th ird and four th outpu ts, by plot t ing the zeros of the noise-eigenvectorpolynomia ls, it is possible to crea t e a “Root -MUSIC” a lgor ithm, as the followingzplane plot illust ra tes:

[PP,ff,v_noise] = pmusic(xx,4);for kk = 1:size(v_noise,2) rr(:,kk) = roots(v_noise(:,kk));endzplane(rr)

Assume tha t RR is a square cor rela t ion mat r ix (for example, 7-by-7):

RR = toeplitz(cos(0.1*pi*[0:6])) + 0.1*eye(7);[PP,ff] = pmusic(RR,4,'corr');

Make an observa t ion ma tr ix xx t ha t is rectangular (100-by-7):

xx = reshape(cos(0.257*pi*(0:699)),7,100) + 0.1*randn(7,100);[PP,ff] = pmusic(xx,4);

Use the same signa l, bu t let pmusic form the 100-by-7 da ta mat r ix using it swindow and over lap inputs. In addit ion , use a longer FFT:

yy = xx(:);[PP,ff] = pmusic(yy,4,512,[],7,0);

If we set p = 0, a ll the eigenvectors a re assigned to the noise subspace. 'ev'specifies the eigenvector weigh t ing. This tu rns ou t to be equiva len t to MVDL(Capon’s MLM):

[PP,ff] = pmusic(RR,0,'ev','corr');

Algorithm The MUSIC est ima te is given by the formula

Pmusic f( )1

e H f( ) v k v kH

k p 1+=

N

∑⎝ ⎠⎜ ⎟⎜ ⎟⎛ ⎞

e f( )

---------------------------------------------------------------- 1

v kH e f( ) 2

k p 1+=

N

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

Page 563: MATLAB Signal Processing Toolbox user manual

pmusic

6-259

where N is the dimension of the eigenvectors and v k is the k -th eigenvector ofthe cor rela t ion mat r ix of the inpu t signa l. The in teger p is the dimension of thesigna l subspace, so the eigenvectors v k used in the sum cor respond to thesmallest eigenvalues and also span the noise subspace. The vector e (f) consist sof complex exponent ia ls, so the inner product

amounts to a Four ier t ransform . The second form is prefer red for computa t ionbecause the FFT is computed for each v k and then the squared magnitudes a resummed.

In the eigenvector method, the summat ion is weigh ted by the eigenva lues λk ofthe correla t ion ma tr ix:

The funct ion relies on the svd mat r ix decomposit ion in the signa l case, and ituses the eig funct ion for ana lyzing the cor rela t ion mat r ix. If SVD is used, thecorrela t ion mat r ix is never explicit ly computed, but the singula r va lues a rethe λk .

Diagnostics There must be a t lea st one ou tpu t argument and at least two inpu ts; otherwise,pmusic stops and gives one of the following er ror messages:

Must have at least 1 output argument.Must have at least 2 input arguments.

The fir st a rgument must be a full ma tr ix, otherwise pmusic gives the followinger ror message:

Input signal or correlation cannot be sparse.

v kH e f( )

Pev f( )1

v kH e f( ) 2

k p 1+=

N

∑⎝ ⎠⎜ ⎟⎜ ⎟⎛ ⎞

λk⁄

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

Page 564: MATLAB Signal Processing Toolbox user manual

pmusic

6-260

If the second argument was en tered as an empty matr ix, or if it ha s more thantwo element s, or if it has negat ive or non-in teger elements, pmusic gives one ofthe following er ror messages:

P cannot be empty.Second input must have only 1 or 2 elements.P must be an integer.Second input must contain non-negative entries.

If the va lue of p is too large with respect to the eigenvector dimension , andthresh is less than 1, no eigenvectors can be assigned to the noise subspace andthe a lgor ithm fa ils. In th is case, pmusic gives the following er ror message:

Noise subspace dimension cannot be zero.

If the 'corr' pa rameter is used, then the fir st inpu t must be a squarecor rela t ion ma t r ix. If it is not , pmusic gives the following er ror message:

Correlation matrix (R) is not square.

The correla t ion matr ix is then checked for va lidity; if it fa ils, pmusic gives thefollowing er ror message:

Correlation matrix (R) has negative or complex eigenvalue.

See Also lpc Linear predict ion coefficien ts.pburg Power spect rum est imate using the Burg method.pcov Power spect rum est imate using the cova r iance

method.pmcov Power spect rum est imate using the modified

covar iance method.pmtm Power spect rum est imate using the mult itaper

method (MTM).prony Prony’s method for t ime domain IIR filt er design .pwelch Est imate the power spect ra l density (PSD) of a signa l

using Welch’s method.pyulear Power spect rum est imate using Yule-Walker AR

method.

Page 565: MATLAB Signal Processing Toolbox user manual

pmusic

6-261

References [1] Schmidt , R.O. “Mult iple Emit ter Loca t ion and Signa l ParameterEst ima t ion .” IEEE Trans. Antennas Propagation . Vol. AP-34 (March 1986).Pgs. 276-280.

[2] Marple, S.L. Digital S pectral Analysis. Englewood Cliffs, NJ : Pren t ice Hall,1987. Pgs. 373-378.

Page 566: MATLAB Signal Processing Toolbox user manual

poly2ac

6-262

6poly2acPurpose Conversion of predict ion polynomia l to au tocor rela t ion sequence.

Syntax r = poly2ac(a,efinal)

Description r = poly2ac(a,efinal) finds the au tocor rela t ion sequence cor responding topredict ion polynomia l a and fina l predict ion er ror efinal. If a(1) is not equa lto 1, poly2ac normalizes the predict ion polynomia l by a(1). a(1) cannot be 0.

See Also

References [1] Kay, S.M. Modern S pectral Estim ation . Englewood Cliffs, NJ :Prent ice-Hall, 1988.

ac2poly Conversion of au tocor rela t ion sequence to predict ionpolynomia l.

poly2rc Conversion of predict ion polynomia l to reflect ioncoefficien ts.

rc2ac Conversion of reflect ion coefficien ts toautocor rela t ion sequence.

Page 567: MATLAB Signal Processing Toolbox user manual

poly2rc

6-263

6poly2rcPurpose Conversion of predict ion polynomial to reflect ion coefficien t s.

Syntax k = poly2rc(a)[k,r0] = poly2rc(a,efinal)

Description k = poly2rc(a) finds the reflect ion coefficien t s of the AR la t t ice st ructurecor responding to predict ion polynomia l a. amust be rea l, and a(1) cannot be 0.If a (1) is not equa l to 1, poly2rc norma lizes the predict ion polynomia l by a(1).k is a row vector of size length(a)–1.

[k,r0] = poly2rc(a,efinal) retu rns the zero-lag au tocor rela t ion , r0, basedon the fina l predict ion er ror , efinal.

A simple, fast way to check if a has a ll of it s roots inside the unit circle is tocheck if each of the elements of k has magnitude less than 1:

stable = all(abs(poly2rc(a))<1)

Example Consider an IIR filter given by

a = [1.0000 0.6149 0.9899 0.0000 0.0031 –0.0082];

It s reflect ion coefficien t represen ta t ion is

k = poly2rc(a)

k = 0.3090 0.9801 0.0031 0.0081 –0.0082

Limitations If abs(k(i)) == 1 for any i, finding the reflect ion coefficien t s is anill-condit ioned problem. poly2rc will retu rn some NaNs and provide a warn ingmessage in th is case.

Algorithm poly2rc implement s the recursive rela t ionship:

Page 568: MATLAB Signal Processing Toolbox user manual

poly2rc

6-264

This rela t ionship is based on Levinson’s recursion [1]. To implement it ,poly2rc loops through a in reverse order a fter disca rding it s fir st element . Foreach loop itera t ion i, the funct ion

1 sets k(i) equal to a(i)2 applies the second rela t ionsh ip above to elements 1 through i of the vector a:

a = (a–k(i)*fliplr(a))/(1–k(i)^2);

See Also

References [1] Kay, S.M.Modern S pectral Estim ation: Theory and Application . EnglewoodCliffs, NJ : Pren t ice Ha ll, 1988.

k n( ) an n( )=

an 1– m( )an m( ) k n( )an n m–( )–

1 k n( )2–---------------------------------------------------------- m 1= 2 … n 1–, , , ,=

ac2rc Conversion of au tocorrela t ion sequence to reflect ioncoefficien ts.

latc2tf Lat t ice filt er to t ransfer funct ion conversion .latcfilt Lat t ice and la t t ice-ladder filt er implementa t ion .poly2ac Conversion of predict ion polynomia l to

autocor rela t ion sequence.rc2poly Conversion of reflect ion coefficien ts to predict ion

polynomia l.tf2latc Conversion of t ransfer funct ion to la t t ice filter.

Page 569: MATLAB Signal Processing Toolbox user manual

polystab

6-265

6polystabPurpose Stabilize polynomia l.

Syntax b = polystab(a)

Description polystab st abilizes a polynomia l with respect to the unit circle; it reflects root swith magnitudes grea ter than 1 inside the unit circle.

b = polystab(a) where a is a vector of polynomia l coefficien ts norma lly in thez-domain :

returns a row vector con ta ining the st abilized polynomia l.

Example polystab can conver t a linear -phase filter in to a minimum-phase filt er withthe same magnitude response:

h = fir1(25,0.4);hmin = polystab(h)*norm(h)/norm(polystab(h));

Algorithm polystab finds the root s of the polynomia l and maps those roots found outsidethe unit circle to the inside of the unit circle:

v = roots(a);vs = 0.5*(sign(abs(v)–1)+1);v = (1–vs).*v + vs./conj(v);b = a(1)*poly(v);

See Also

a z( ) a 1( ) a 2( )z 1– L a n a 1+( )z n a–+ + +=

roots Polynomia l roots (see the online MATLAB FunctionReference).

Page 570: MATLAB Signal Processing Toolbox user manual

prony

6-266

6pronyPurpose Prony’s method for t ime domain IIR filter design .

Syntax [b,a] = prony(h,nb,na)

Description Prony’s method is an a lgor ithm for finding an IIR filt er with a prescr ibed t imedomain impulse response. It ha s applica t ions in filt er design, exponent ia lsigna l modeling, and system iden t ifica t ion (pa rametr ic modeling).

[b,a] = prony(h,nb,na) finds a filter with numera tor order nb, denominatororder na, and the t ime domain impulse response in h. prony returns the filt ercoefficien ts in row vectors b and a, of length nb + 1 and na + 1, r espect ively.The filter coefficien ts are in descending powers of z:

Example Recover the coefficien ts of a But terwor th filter from its impulse response:

[b,a] = butter(4,0.2)

b = 0.0048 0.0193 0.0289 0.0193 0.0048

a =1.0000 –2.3695 2.3140 –1.0547 0.1874

h = filter(b,a,[1 zeros(1,25)]);[bb,aa] = prony(h,4,4)

bb = 0.0048 0.0193 0.0289 0.0193 0.0048

ab =1.0000 –2.3695 2.3140 –1.0547 0.1874

Algorithm prony implements the method descr ibed in reference [1]. This method uses avar ia t ion of the covar iance method of AR modeling to find the denomina torcoefficien t s a and then finds the numera tor coefficien t s b for which the impulseresponse of the outpu t filt er ma tches exact ly the fir st nb + 1 samples of x. Thefilt er is not necessar ily st able, but potent ia lly can recover the coefficien ts

H z( ) B z( )A z( )----------- b 1( ) b 2( )z 1– L b n b 1+( )z n b–+ + +

a 1( ) a 2( )z 1– L a n a 1+( )z n a–+ + +-----------------------------------------------------------------------------------------= =

Page 571: MATLAB Signal Processing Toolbox user manual

prony

6-267

exact ly if the da ta sequence is t ru ly an au toregressive moving average (ARMA)process of the cor rect order .

See Also

References [1] Parks, T.W., and C.S. Burrus. Digital Filter Design . New York: J ohn Wiley& Sons, 1987. Pgs. 226-228.

butter But terwor th analog and digita l filt er design .cheby1 Chebyshev type I filter design (passband r ipple).cheby2 Chebyshev type II filter design (stopband r ipple).ellip Ellipt ic (Cauer ) filt er design.invfreqz Discret e-t ime filter ident ifica t ion from frequency

data .levinson Levinson-Durbin recursion .lpc Linea r predict ion coefficient s.stmcb Linea r model using Steiglitz-McBr ide itera t ion .

Page 572: MATLAB Signal Processing Toolbox user manual

psd

6-268

6psdSuperseded The psd funct ion for spect ra l est imat ion by Welch’s method has beensuperseded by pwelch.

The pwelch funct ion improves upon psd in three ways:

• The magnitude of the spect rum is sca led by 1/Fs• The default va lue of Fs is 1•No detrending is per formed

The psd funct ion will con t inue to be included in the Signa l Processing Toolboxfor backwards compat ibility.

Page 573: MATLAB Signal Processing Toolbox user manual

pulstran

6-269

6pulst r anPurpose Pulse t ra in genera tor .

Syntax y = pulstran(t,d,'func')y = pulstran(t,d,'func',p1,p2,...)y = pulstran(t,d,p,Fs)y = pulstran(t,d,p)

Description pulstran genera tes pu lse t ra ins from cont inuous funct ions or sampledprototype pulses.

y = pulstran(t,d,'func') genera t es a pu lse t ra in based on samples of acont inuous funct ion , 'func', where func is:

• gauspuls, for Gaussian-modula t ed sinusoida l pulse genera tor• rectpuls, for sampled aper iodic rectangle genera tor• tripuls, for sampled aper iodic t r iangle genera tor

pulstran is eva lua ted length(d) t imes and retu rns the sum of the eva lua t ionsy = func(t–d(1)) + func(t–d(2)) + ...

The funct ion is eva lua ted over the range of argument va lues specified in ar rayt, a ft er removing a sca la r argument offset taken from the vector d. Note tha tfunc must be a vector ized funct ion tha t can take an ar ray t as an argument .

An opt iona l ga in factor may be applied to each delayed evalua t ion by specifyingd as a two-column matr ix, with the offset defined in column 1 and associa tedga in in column 2 of d. Note tha t a row vector will be in t erpreted as specifyingdelays on ly.

pulstran(t,d,'func',p1,p2,...) a llows addit iona l parameters to be passedto 'func' a s necessary. For example,

func(t–d(1),p1,p2,...) + func(t–d(2),p1,p2,...) + ...

pulstran(t,d,p,Fs) genera tes a pulse t ra in tha t is the sum of mult ipledelayed interpola t ions of the prototype pulse in vector p, sampled a t the ra teFs, where p spans the t ime in terva l [0,(length(p)–1)/Fs], and it s samplesare ident ica lly 0 outside th is in t erva l. By default , linear in terpola t ion is usedfor genera t ing delays.

Page 574: MATLAB Signal Processing Toolbox user manual

pulstran

6-270

pulstran(t,d,p) assumes tha t the sampling ra te Fs is equa l to 1 Hz.

pulstran(...,'func') specifies a lterna t ive int erpola t ion methods. Seeinterp1 for a list of ava ilable methods.

Examples This example genera t es an asymmetr ic sawtooth waveform with a repet it ionfrequency of 3 Hz and a sawtooth width of 0.1 sec. It has a signa l length of 1 secand a 1 kHz sample ra t e:

t = 0 : 1/1e3 : 1; % 1 kHz sample freq for 1 sec d = 0 : 1/3 : 1; % 3 Hz repetition freq y = pulstran(t,d,'tripuls',0.1,–1);plot(t,y)

This example genera tes a per iodic Gaussian pulse signa l a t 10 kHz, with 50%bandwidth . The pulse repet it ion frequency is 1 kHz, sample ra t e is 50 kHz, and

0 0.2 0.4 0.6 0.8 10

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

1

Page 575: MATLAB Signal Processing Toolbox user manual

pulstran

6-271

pulse t ra in length is 10 msec. The repet it ion amplitude should a t tenua te by 0.8each t ime:

t = 0 : 1/50E3 : 10e–3;d = [0 : 1/1E3 : 10e–3 ; 0.8.^(0:10)]';y = pulstran(t,d,'gauspuls',10e3,0.5); plot(t,y)

0 0.002 0.004 0.006 0.008 0.01-0.8

-0.6

-0.4

-0.2

0

0.2

0.4

0.6

0.8

1

Page 576: MATLAB Signal Processing Toolbox user manual

pulstran

6-272

This example genera t es a t ra in of 10 Hamming windows:

p = hamming(32);t = 0:320; d = (0:9)'*32;y = pulstran(t,d,p);plot(t,y)

See Also

0 50 100 150 200 250 300 3500

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

1

chirp Swept-frequency cosine genera tor.cos Cosine of vector /matr ix elements (see the online

MATLAB Function Reference).diric Dir ich let or per iodic sinc funct ion .gauspuls Gaussian-modula t ed sinusoida l pu lse genera tor.rectpuls Sampled aperiodic rect angle genera tor.sawtooth Sawtooth or t r iangle wave genera tor.sin Sine of vector /matr ix elements (see the online

MATLAB Function Reference).sinc Sinc or sin(πt )/πt funct ion .square Square wave genera tor.tripuls Sampled aperiodic t r iangle genera tor.

Page 577: MATLAB Signal Processing Toolbox user manual

pwelch

6-273

6pwelchPurpose Est ima te the power spect ra l density (PSD) of a signa l using Welch’s method.

Syntax Pxx = pwelch(x)Pxx = pwelch(x,nfft)[Pxx,w] = pwelch(x,nfft)[Pxx,f] = pwelch(x,nfft,Fs)[Pxx,f] = pwelch(x,nfft,Fs,window)[Pxx,f] = pwelch(x,nfft,Fs,window,noverlap)[Pxx,Pxxc,f] = pwelch(x,nfft,Fs,window,noverlap,p)[Pxx,Pxxc,f] = pwelch(...,'range')pwelch(...)pwelch(...,'magunits')

Description Pxx = pwelch(x) est imates the power spect rum of the sequence x using theWelch method of spect ra l est imat ion . If x is rea l, pwelch est imates thespect rum a t posit ive frequencies on ly; in th is case, ou tpu t Pxx is a columnvector of length nfft/2+1 for nfft even and (nfft+1)/2 for nfft odd. If x iscomplex, pwelch est imates the spect rum at both posit ive and negat ivefrequencies and Pxx has length nfft.

Pxx = pwelch(x,nfft) uses the specified FFT length nfft in est imat ing thepower spect rum for x. Th is va lue determines the number of differen tfrequencies a t which the power spect rum is est ima ted. Specify nfft as a powerof 2 for fa st est execu t ion . Specify an empty matr ix for nfft, [], to use thedefault va lue of min(256,length(x)).

[Pxx,w] = pwelch(x,nfft) retu rns a vector w of normalized angula rfrequencies (in rads/sample) a t which the funct ion eva lua tes the PSD. Therange of w is [0,π) for rea l x and [0,2π) for complex x. Since the frequency vectorw is the same size as Pxx, plot(w,Pxx) plot s the power spect rum versus thenormalized angular frequency.

[Pxx,f] = pwelch(x,nfft,Fs) retu rns a vector f of linear frequencies (in Hz)a t which the funct ion eva lua tes the PSD. Fs is a sca la r tha t specifies thesampling frequency of x, and Pxx is sca led by 1/Fs. The range of f is [0,Fs/2)for rea l x and [0,Fs) for complex x. Since the frequency vector f is t he samesize as Pxx, plot(f,Pxx) plot s the power spect rum versus the linear frequency.Specify an empty mat r ix for Fs, [], t o use the default va lue of 1 Hz.

Page 578: MATLAB Signal Processing Toolbox user manual

pwelch

6-274

[Pxx,f] = pwelch(x,nfft,Fs,window) specifies a windowing funct ion andthe number of samples per windowed sect ion of the x vector (e.g., kaiser(64)).The length of the window must be less than or equa l to nfft; pwelch zero padsthe sect ions if the length of the window is less than nfft. Specify a sca la r forwindow to use a Hanning window of tha t length ; specify an empty ma tr ix, [],t o use the defau lt va lue of hanning(nfft).

[Pxx,f] = pwelch(x,nfft,Fs,window,noverlap) over laps the windowedsect ions of x by noverlap samples. Specify an empty matr ix for noverlap, [],t o use the defau lt va lue of 0.

[Pxx,Pxxc,f] = pwelch(x,nfft,Fs,window,noverlap,p) where p is aposit ive sca la r between 0 and 1 returns a vector Pxxc t ha t conta ins an est ima teof the p*100 percen t confidence in terva l for Pxx. Pxxc is a two-column matr ixtha t is the same length as Pxx. The in terva l [Pxxc(:,1),Pxxc(:,2)] covers thet rue PSD with probability p. plot(f,[Pxx Pxxc]) plots the power spect ruminside the p*100 percen t confidence in t erva l. Specify an empty ma tr ix for p, [],t o use the defau lt va lue of 0.95.

[Pxx,Pxxc,f] = pwelch(...,'range') specifies the range of frequencyva lues to include in f. range can be:

• half, t o compute the PSD over the range [0,π) for rea l or complex x. If Fs isspecified, the range is [0,Fs/2) for rea l or complex x. If Fs is specified by anempty ma tr ix, [], the default va lue of 1 is used, and the range is [0,1/2) forrea l or complex x.

• whole, t o compute the PSD over the range [0,2π) for rea l or complex x. If Fsis specified, the range is [0,Fs) for rea l or complex x. If Fs is specified by anempty mat r ix, [], the defau lt va lue of 1 is used, and the range is [0,1) for rea lor complex x.

pwelch(x,...) with no outpu t a rguments plot s the PSD aga inst frequency inthe cur ren t figure window. If p is specified, the plot includes the confidencein t erva l.

pwelch(...,'magunits') specifies the unit s in which to express to themagnitude axis of the PSD plot . The opt ions are:

Page 579: MATLAB Signal Processing Toolbox user manual

pwelch

6-275

• 'db', to express the PSD da ta in decibels (dB). This is the defau lt .• 'squared', to express the PSD in linea r unit s (magnitude squa red).

Example Genera t e a colored noise signa l and plot it s PSD with a confidence in terva l of95%. Specify a length 1024 FFT, a 512-poin t Kaiser window with no over lap,and a sampling frequency of 10 kHz:

h = fir1(30,0.2,boxcar(31)); % design a lowpass filterr = randn(16384,1); % white noisex = filter(h,1,r); % color the noisepwelch(x,1024,10000,kaiser(512,5),0,0.95)

Algorithm pwelch ca lcu la tes the power spect ra l density using Welch’s method (seereferences [1] and [2]):

1 It applies the window specified by the window vector to each successivesect ion of inpu t x.

2 It t ransforms each sect ion with an nfft-poin t FFT.3 It forms the per iodogram of each sect ion by sca ling the magnitude squaredof each t ransformed sect ion.

0 1000 2000 3000 4000 5000−110

−100

−90

−80

−70

−60

−50

−40

−30Welch’s Spectral Estimate Pxx(f) / fs

Frequency (Hz)

Pow

er S

pect

ral D

ensi

ty (d

B)

Page 580: MATLAB Signal Processing Toolbox user manual

pwelch

6-276

4 It averages the per iodograms of the over lapping sect ions to form Pxx(f).5 It sca les Pxx(f) by 1/Fs to form Pxx(f)/Fs, the power spect rum of x.

The number of sect ions tha t pwelch averages is

k = fix((length(x)–noverlap)/(length(window)–noverlap))

Diagnostics An appropr ia t e diagnost ic message is displayed when incorrect a rguments topwelch are used:

Requires window’s length to be no greater than FFT length.Requires NOVERLAP to be strictly less than the window length.Requires positive integer values for NFFT and NOVERLAP.Requires confidence parameter to be a scalar between 0 and 1.Requires vector input.

See Also cohere Est imate magnitude squared coherence funct ionbetween two signals.

csd Est imate the cross spect ra l density (CSD) of twosigna ls.

pburg Power spect rum est ima te using the Burg method.pcov Power spect rum est ima te using the covar iance

method.pmcov Power spect rum est ima te using the modified

covar iance method.pmtm Power spect rum est ima te using the mult it aper

method (MTM).pmusic Power spect rum est ima te using MUSIC eigenvector

method.pyulear Power spect rum est ima te using Yule-Walker AR

method.specgram Time-dependent frequency ana lysis (spect rogram).tfe Transfer funct ion est imate from inpu t and ou tpu t .

Page 581: MATLAB Signal Processing Toolbox user manual

pwelch

6-277

References [1] Rabiner , L.R., and B. Gold. Theory and Application of Digital S ignalProcessing. Englewood Cliffs, NJ : Pren t ice Hall, 1975. Pgs. 399-419.

[2]Welch , P .D. “The Use of Fast Four ier Transform for the Est imat ion of PowerSpect ra : A Method Based on Time Averaging Over Shor t , ModifiedPer iodograms.” IEEE Trans. Audio Electroacoust . Vol. AU-15 (J une 1967).Pgs. 70-73.

[3] Oppenheim, A.V., and R.W. Schafer . Discrete-T im e S ignal Processing.Englewood Cliffs, NJ : Prent ice Hall, 1989. Pgs. 311-312.

Page 582: MATLAB Signal Processing Toolbox user manual

pyulear

6-278

6pyulea rPurpose Power spect rum est ima te using Yule-Walker AR method.

Syntax Pxx = pyulear(x,p,nfft)[Pxx,freq] = pyulear(x,p,nfft)[Pxx,freq] = pyulear(x,p,nfft,Fs)[Pxx,freq] = pyulear(x,p,nfft,Fs,'range')pyulear(...)pyulear(...,'squared')

Description pyulear est imates the power spect ra l density (PSD) of the signa l vector x[n ]using the Yule-Walker AR method. This method, a lso ca lled theautocorrela t ion method, fit s an autoregressive (AR) model to the signa l bymin imizing the forward predict ion er ror in the least -squares sense. Thisformula t ion leads to the Yule-Walker equat ions, which are solved by theLevinson-Durbin recursion . The spect ra l est imate returned by pyulear is themagnitude squared frequency response of this AR model. The cor rect choice ofthe model order p is impor tan t .

Pxx = pyulear(x,p,nfft) retu rns Pxx, t he power spect rum est imate. x is theinpu t signa l, p is the model order for the a ll-pole filter , and nfft is the FFTlength (default s to 256 if not specified). Pxx has length (nfft/2+1) for nffteven , (nfft+1)/2 for nfft odd, and nfft if x is complex.

[Pxx,freq] = pyulear(x,p,nfft) retu rns Pxx, the power spect rumest imate, and freq, a vector of frequencies a t which the PSD was est imated. Ifthe inpu t signa l is rea l-va lued, the range of freq is [0,π). If the input signa l iscomplex, the range of freq is [0,2π).

[Pxx,freq] = pyulear(x,p,nfft,Fs) uses the signa l’s sampling frequency,Fs, to sca le both the PSD vector (Pxx) and the frequency vector (freq). Pxx issca led by 1/Fs. If t he inpu t signa l is rea l-va lued, the range of freq is [0,Fs/2).If the input signa l is complex, the range of freq is [0,Fs). Fs defau lt s to 1 ifleft empty, [].

[Pxx,freq] = pyulear(x,p,nfft,Fs,'range') specifies the range offrequency va lues to include in freq. range can be:

• half, to compute the PSD over the range [0,Fs/2) for rea l x, and [0,Fs) forcomplex x. If Fs is left blank, [], t he range is [0,1/2) for rea l x, and [0,1)

Page 583: MATLAB Signal Processing Toolbox user manual

pyulear

6-279

for complex x. If Fs is omit ted ent irely, the range is [0,pi) for rea l x, and[0,2*pi) for complex x. half is the default range.

• whole, t o compute the PSD over the range [0,Fs) for a ll x. If Fs is leftblank, [], t he range is [0,1) for a ll x. If Fs is omit ted ent irely, the range is[0,2*pi) for a ll x.

pyulear(...) plots the power spect ra l density in the fir st ava ilable figurewindow. The frequency range on the plot is the same as the range of ou tpu tfreq for a given set of parameter s.

pyulear(...,'squared') plots the magnitude of Pxx direct ly, ra ther thancomnver t ing the va lues to dB.

Example Since the method est imates the spect rum by fit t ing an AR model to the signa l,fir st define the AR system (a ll-pole filt er ) tha t genera tes the input . Check themagnitude response of the process with freqz.

a = [1 –2.2137 2.9403 –2.1697 0.9606]; % AR system coefficientsfreqz(1,a,'phase','no') % AR system magnitude responsetitle('AR System Magnitude Response')

0 0.2 0.4 0.6 0.8 1−20

−10

0

10

20

30

40

Normalized Angular Frequency (×π rads/sample)

Mag

nitu

de (d

B)

AR System Magnitude Response

Page 584: MATLAB Signal Processing Toolbox user manual

pyulear

6-280

Now genera te the inpu t signa l x by filt er ing whit e noise through the ARsystem. Est imate the PSD of x based on a four th -order AR model (since weknow tha t the or igina l AR system, a, has order 4).

x = filter(1,a,randn(150,1)); % AR system outputpyulear(x,4) % 4th order estimate

Diagnostics The fir st inpu t argument must be a fu ll vector ; otherwise pyulear genera testhe following er ror message:

Input signal cannot be sparse.

If you specify an empty matr ix for the second argument , pyulear genera tes thefollowing er ror message:

Model order must be an integer.

0 0.2 0.4 0.6 0.8 1−10

−5

0

5

10

15

20

25

Normalized Angular Frequency (×π rads/sample)

Pow

er S

pect

ral D

ensi

ty (d

B)

Yule−Walker Spectral Estimate Pxx(ω)

Page 585: MATLAB Signal Processing Toolbox user manual

pyulear

6-281

See Also

References [1] Marple, S.L. Digital S pectral Analysis. Englewood Cliffs, NJ : Pren t ice Hall,1987. Chapter 7.

aryule Compute an est imate of AR model parameters usingthe Yule-Walker method.

lpc Linea r predict ion coefficient s.pburg Power spect rum est ima te using the Burg method.pcov Power spect rum est ima te using the covar iance

method.pmcov Power spect rum est ima te using the modified

cova r iance method.pmtm Power spect rum est ima te using the mult itaper

method (MTM).pmusic Power spect rum est ima te using MUSIC eigenvector

method.prony Prony’s method for t ime domain IIR filter design .pwelch Est imate the power spect ra l density (PSD) of a signa l

using Welch’s method.

Page 586: MATLAB Signal Processing Toolbox user manual

rc2ac

6-282

6rc2acPurpose Conversion of reflect ion coefficien t s to au tocor rela t ion sequence.

Syntax r = rc2ac(k,r0)

Description r = rc2ac(k,r0) finds the au tocor rela t ion coefficien t s, r, of the discrete filterwith reflect ion coefficien ts k and zero-lag autocorrela t ion r0.

See Also

References [1] Kay, S.M. Modern S pectral Estim ation . Englewood Cliffs, NJ :Prent ice-Hall, 1988.

ac2rc Conversion of au tocorrela t ion sequence to reflect ioncoefficien ts.

poly2ac Conversion of predict ion polynomia l toautocor rela t ion sequence.

rc2poly Conversion of reflect ion coefficien ts to predict ionpolynomia l.

Page 587: MATLAB Signal Processing Toolbox user manual

rc2poly

6-283

6rc2polyPurpose Conversion of reflect ion coefficien t s to predict ion polynomial.

Syntax a = rc2poly(k)[a,efinal] = rc2poly(k,r0)

Description a = rc2poly(k) finds the predict ion polynomia l a, with a(1) = 1, from thereflect ion coefficien t s k of the cor responding la t t ice st ructure. Outpu t a is rowvector of length k + 1.

[a,efinal] = rc2poly(k,r0) retu rns the fina l predict ion er ror , efinal,ba sed on the zero-lag autocor rela t ion , r0.

Example Consider an IIR filter given by reflect ion coefficien ts k:

k = [0.3090 0.9800 0.0031 0.0082 –0.0082];

It s polynomia l representa t ion is

a = rc2poly(k)

a =

1.0000 0.6148 0.9899 0.0000 0.0032 –0.0082

Algorithm rc2poly computes outpu t a using Levinson’s recursion [1]. The funct ion :

1 Set s the outpu t vector a to the first element of k2 Loops th rough the remain ing elements of kFor each loop it era t ion i, a = [a + a(i–1:–1:1)*k(i) k(i)].

3 Implements a = [1 a]

Page 588: MATLAB Signal Processing Toolbox user manual

rc2poly

6-284

See Also

References [1] Kay, S.M. Modern S pectral Estim ation . Englewood Cliffs, NJ :Prent ice-Hall, 1988.

ac2poly Conversion of au tocor rela t ion sequence to predict ionpolynomia l.

latc2tf Lat t ice filt er to t ransfer funct ion conversion .latcfilt Lat t ice and la t t ice-ladder filt er implementa t ion .poly2rc Conversion of predict ion polynomia l to reflect ion

coefficien ts.rc2ac Conversion of reflect ion coefficien ts to

autocor rela t ion sequence.tf2latc Conversion of t ransfer funct ion to la t t ice filter.

Page 589: MATLAB Signal Processing Toolbox user manual

rceps

6-285

6rcepsPurpose Real cepst rum and minimum phase reconst ruct ion .

Syntax y = rceps(x)[y,ym] = rceps(x)

Description The real cepstrum is the inverse Four ier t ransform of the rea l loga r ithm of themagnitude of the Four ier t ransform of a sequence.

rceps(x) returns the rea l cepst rum of the rea l sequence x. The rea l cepst rumis a rea l-va lued funct ion .

[y,ym] = rceps(x) retu rns both the rea l cepst rum y and a minimum phasereconst ructed version ym of the inpu t sequence.

Algorithm rceps is an M-file implementa t ion of a lgor ithm 7.2 in [2], t ha t is:

y = real(ifft(log(abs(fft(x)))));

Appropr ia te windowing in the cepst ra l domain forms the reconst ructedminimum phase signa l:

w = [1; 2*ones(n/2–1,1); ones(1 – rem(n,2),1); zeros(n/2–1,1)];ym = real(ifft(exp(fft(w.*y))));

See Also

References [1] Oppenheim, A.V., and R.W. Schafer . Digital S ignal Processing. EnglewoodCliffs, NJ : Pren t ice Ha ll, 1975.

[2] IEEE. Program s for Digital S ignal Processing. IEEE Press. New York: J ohnWiley & Sons, 1979.

cceps Complex cepst ra l ana lysis.fft One-dimensiona l fast Four ier t ransform.hilbert Hilber t t ransform.icceps Inverse complex cepst rum.unwrap Unwrap phase angles.

Page 590: MATLAB Signal Processing Toolbox user manual

rectpuls

6-286

6rectpulsPurpose Sampled aper iodic rectangle genera tor .

Syntax y = rectpuls(t)y = rectpuls(t,w)

Description y = rectpuls(t) retu rns a cont inuous, aper iodic, unity-heigh t rectangula rpu lse a t the sample t imes indica ted in ar ray t, centered about t = 0 and witha defau lt width of 1. Note tha t the in terva l of non-zero amplitude is defined tobe open on the r igh t , tha t is, rectpuls(–0.5) = 1 while rectpuls(0.5) = 0.

y = rectpuls(t,w) genera tes a rectangle of width w.

rectpuls is typica lly used in conjunct ion with the pulse t ra in genera t ingfunct ion , pulstran.

See Also chirp Swept-frequency cosine genera tor.cos Cosine of vector /matr ix elements (see the online

MATLAB Function Reference).diric Dir ich let or per iodic sinc funct ion .gauspuls Gaussian-modula t ed sinusoida l pu lse genera tor.pulstran Pulse t ra in genera tor.sawtooth Sawtooth or t r iangle wave genera tor.sin Sine of vector /matr ix elements (see the online

MATLAB Function Reference).sinc Sinc or sin(πt )/πt funct ion .square Square wave genera tor.tripuls Sampled aperiodic t r iangle genera tor.

Page 591: MATLAB Signal Processing Toolbox user manual

remez

6-287

6remezPurpose Parks-McClellan opt imal FIR filter design .

Syntax b = remez(n,f,a)b = remez(n,f,a,w)b = remez(n,f,a,'ftype')b = remez(n,f,a,w,'ftype')b = remez(...,{lgrid})b = remez(n,f,'fresp',w)b = remez(n,f,'fresp',w,'ftype')b = remez(n,f,{'fresp',p1,p2,...},w)b = remez(n,f,{'fresp',p1,p2,...},w,'ftype')[b,delta] = remez(...)[b,delta,opt] = remez(...)

Description remez designs a linear -phase FIR filter using the Pa rks-McClellana lgor ithm [1]. The Parks-McClellan a lgor ithm uses the Remez exchangea lgor ithm and Chebyshev approximat ion theory to design filter s with anopt imal fit between the desired and actua l frequency responses. The filt er s a reopt imal in the sense tha t the maximum error between the desired frequencyresponse and the actua l frequency response is minimized. F ilt ers designed thisway exhibit an equir ipple behavior in their frequency responses and hence aresomet imes ca lled equiripple filter s.

b = remez(n,f,a) retu rns row vector b conta in ing the n+1 coefficien t s of theorder n FIR filt er whose frequency-amplitude cha racter ist ics match thosegiven by vectors f and a.

The ou tpu t filter coefficien ts (t aps) in b obey the symmetry rela t ion

Vectors f and a specify the frequency-magnitude charact er ist ics of the filt er :

b k( ) b n 2 k–+( ) k 1= … n 1+, , ,=

Page 592: MATLAB Signal Processing Toolbox user manual

remez

6-288

• f is a vector of pa irs of frequency poin ts, specified in the range between 0 and1, where 1 cor responds to ha lf the sampling frequency (the Nyquistfrequency). The frequencies must be in increasing order .

• a is a vector conta in ing the desired amplitudes a t the poin ts specified in f.The desired amplitude a t frequencies between pairs of poin ts (f(k ), f(k+1)) fork odd is the line segment connect ing the poin ts (f(k ), a(k )) and (f(k+1),a(k+1)).The desired amplitude a t frequencies between pairs of poin ts (f(k ), f(k+1)) fork even is unspecified. The areas between such poin t s a re t ransit ion or “don’tca re” regions.

• f and a must be the same length . The length must be an even number .

The rela t ionsh ip between the f and a vectors in defin ing a desired frequencyresponse is shown below:

remez(n,f,a,w) uses the weigh ts in vector w to weight the fit in each frequencyband. The length of w is ha lf the length of f and a, so there is exact ly one weigh tper band.

b = remez(n,f,a,'ftype') and

b = remez(n,f,a,w,'ftype') specify a filter type, where ftype is

1.0

0.0

Desired amplituderesponse (a)

Normalizedfrequency (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.70.0 0.8 0.9 1.0 (Nyquist)

Page 593: MATLAB Signal Processing Toolbox user manual

remez

6-289

• hilbert, for linear -phase filt er s with odd symmet ry (type III and type IV)The ou tpu t coefficien t s in b obey the rela t ion b(k ) = -b(n +2 -k ), k = 1,...,n + 1.This class of filt er s includes the Hilber t t ransformer , which has a desiredamplitude of 1 across the ent ire band.For example,h = remez(30,[0.1 0.9],[1 1],'hilbert');

designs an approximate FIR Hilber t t ransformer of length 31.

• differentiator, for type III and IV filters, using a specia l weight ingtechniqueFor nonzero amplitude bands, it weigh ts the er ror by a factor of 1/f so tha tthe er ror a t low frequencies is much smaller than a t h igh frequencies. ForFIR differen t ia tors, which have an amplitude charact er ist ic propor t iona l tofrequency, these filter s min imize the maximum rela t ive er ror (the maximumof the ra t io of the er ror to the desired amplitude).

b = remez(...,{lgrid}) uses the in teger lgrid to cont rol the density of thefrequency gr id, which has roughly (lgrid*n)/(2*bw) frequency poin ts, wherebw is the fract ion of the tot a l frequency band in terva l [0,1] covered by f.Increasing lgrid oft en result s in filt er s tha t a re more exact ly equir ipple, bu twhich take longer to compute. The defau lt va lue of 16 is the min imum valuetha t should be specified for lgrid. Note tha t the {lgrid} a rgument must be a1-by-1 cell a r ray.

b = remez(n,f,'fresp',w) retu rns row vector b conta in ing the n+1coefficien t s of the order n FIR filt er whose frequency-amplitude character ist icsbest approximate the response specified by funct ion fresp. The funct ion isca lled from with in remez with the following syn tax:

[dh,dw] = fresp(n,f,gf,w)

The a rguments are simila r to those for remez:

• n is the filter order .• f is the vector of frequency band edges tha t appea r monotonica lly between0 and 1, where 1 is the Nyquist frequency.

• gf is a vector of gr id poin ts tha t have been linea r ly in terpola ted over eachspecified frequency band by remez. gf determines the frequency gr id a t

Page 594: MATLAB Signal Processing Toolbox user manual

remez

6-290

which the response funct ion must be eva lua ted, and conta ins the same da taretu rned by cremez in the fgrid field of the opt st ructure.

• w is a vector of rea l, posit ive weight s, one per band, used dur ing opt imiza t ion .w is opt iona l in the ca ll t o remez; if not specified, it is set to unity weight ingbefore being passed to 'fresp'.

• dh and dw a re the desired complex frequency response and band weightvectors, respect ively, eva lua ted a t each frequency in gr id gf.

The predefined frequency response funct ion (fresp) tha t remez ca lls isremezfrf in the signal/private directory.

b = remez(n,f,{'fresp',p1,p2,...},w) a llows you to specify addit iona lparameters (p1, p2, et c.) to pass to fresp. Note tha t b = remez(n,f,a,w) is asynonym for b = remez(n,f,{'remezfrf',a},w), where a is a vectorconta in ing the desired amplitudes a t the poin t s specified in f.

b = remez(n,f,'fresp',w,'ftype') and

b = remez(n,f,{'fresp',p1,p2,...},w,'ftype') design ant isymmetr ic(odd) ra ther than symmetr ic (even) filter s, where 'ftype' is either 'd' for adifferen t ia tor or 'h' for a Hilber t t ransformer .

In the absence of a specifica t ion for ftype, a preliminary ca ll is made to frespto determine the defau lt symmet ry proper ty sym. This ca ll is made using thesyn tax:

sym = fresp('defaults',{n,f,[],w,p1,p2,...})

The a rguments n, f, w, etc., may be used as necessa ry in determin ing anappropr ia te va lue for sym, which remez expect s to be either 'even' or 'odd'. Ift he fresp funct ion does not suppor t this ca lling syntax, remez defau lt s to evensymmet ry.

[b,delta] = remez(...) retu rns the maximum ripple heigh t in delta.

Page 595: MATLAB Signal Processing Toolbox user manual

remez

6-291

[b,delta,opt] = remez(...) retu rns a st ructure, opt, of opt iona l resu lt swith the following fields.

Example Graph the desired and actua l frequency responses of a 17th-orderParks-McClellan bandpass filter :

f = [0 0.3 0.4 0.6 0.7 1]; a = [0 0 1 1 0 0];b = remez(17,f,a);[h,w] = freqz(b,1,512);plot(f,a,w/pi,abs(h))

opt.fgrid Frequency gr id vector used for the filter design opt imiza t ion

opt.des Desired frequency response for each point in opt.fgrid

opt.wt Weight ing for each poin t in opt.fgrid

opt.H Actua l frequency response for each poin t in opt.fgrid

opt.error Error a t each poin t in opt.fgrid (opt.des–opt.H)

opt.iextr Vector of indices in to opt.fgrid for ext remal frequencies

opt.fextr Vector of ext remal frequencies

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 10

0.2

0.4

0.6

0.8

1

1.2

Page 596: MATLAB Signal Processing Toolbox user manual

remez

6-292

Algorithm remez is a MEX-file version of the or igina l For t ran code from [1], a ltered todesign a rbit ra r ily long filter s with arbit ra r ily many linear bands.

remez designs type I, II, III, and IV linear -phase filt er s. Type I and Type II a rethe defau lt s for n even and n odd, respect ively, while Type III (n even) andType IV (n odd) a re obta ined with the 'hilbert' and 'differentiator' flags.The differen t types of filt er s have different symmet r ies and cer ta in const ra in tson their frequency responses (see [5] for more deta ils).

Diagnostics An appropr ia t e diagnost ic message is displayed if incor rect a rguments areused:

Filter order must be 3 or more.There should be one weight per band.Frequency and amplitude vectors must be the same length.The number of frequency points must be even.Frequencies must lie between 0 and 1.Frequencies must be specified in bands.Frequencies must be nondecreasing.Adjacent bands not allowed.

A more ser ious warning message is

–– Failure to Converge ––Probable cause is machine rounding error.

In the ra re event tha t you see th is message, it is possible tha t the filter designmay st ill be cor rect . Ver ify the design by checking it s frequency response.

Linear Phase Filter Type

Filter Order n Symmetry of Coefficients

Response H(f), f = 0

Response H(f), f = 1 (Nyquist)

Type I Even even : No rest r ict ion No rest r ict ion

Type II Odd No rest r ict ion H (1) = 0

Type III Even odd: H (0) = 0 H (1) = 0

Type IV Odd H (0) = 0 No rest r ict ion

b k( ) b n 2 k–+( ) k 1= … n 1+, , ,=

b k( ) b– n 2 k–+( ) k 1= … n 1+, , ,=

Page 597: MATLAB Signal Processing Toolbox user manual

remez

6-293

See Also

References [1] IEEE. Program s for Digital S ignal Processing. IEEE Press. New York: J ohnWiley & Sons, 1979. Algor ithm 5.1.

[2] IEEE. S elected Papers in Digital S ignal Processing, II. IEEE Press. NewYork: J ohn Wiley & Sons, 1979.

[3] Parks, T.W., and C.S. Burrus. Digital Filter Design . New York: J ohn Wiley& Sons, 1987. Pg. 83.

[4] Rabiner , L.R., J .H. McClellan , and T.W. Pa rks. “FIR Digita l F ilt er DesignTechniques Using Weighted Chebyshev Approximat ions.” Proc. IEEE 63(1975).

[5] Oppenheim, A.V., and R.W. Schafer . Discrete-T im e S ignal Processing.Englewood Cliffs, NJ : Prent ice Hall, 1989. Pgs. 256-266.

butter But terwor th analog and digita l filt er design .cheby1 Chebyshev type I filter design (passband r ipple).cheby2 Chebyshev type II filter design (stopband r ipple).cremez Complex and nonlinear-phase equir ipple FIR filt er

design .ellip Ellipt ic (Cauer ) filt er design.fir1 Window-based fin ite impulse response filter design –

standard response.fir2 Window-based fin ite impulse response filter design –

arbit ra ry response.fircls Const ra ined least square FIR filter design for

mult iband filter s.fircls1 Const ra ined least square filt er design for lowpass

and highpass linea r phase FIR filt ers.firls Least square linear-phase FIR filter design .firrcos Raised cosine FIR filter design .remezord Parks-McClellan opt imal FIR filter order est imat ion .yulewalk Recursive digit a l filt er design.

Page 598: MATLAB Signal Processing Toolbox user manual

remezord

6-294

6remezordPurpose Parks-McClellan opt ima l FIR filter order est ima t ion .

Syntax [n,fo,ao,w] = remezord(f,a,dev)[n,fo,ao,w] = remezord(f,a,dev,Fs)c = remezord(f,a,dev,Fs,'cell')

Description [n,fo,ao,w] = remezord(f,a,dev) finds the approximate order , normalizedfrequency band edges, frequency band amplitudes, and weight s tha t meetinpu t specifica t ions f, a, and dev, t o use with the remez command.

• f is a vector of frequency band edges (between 0 and Fs/2, where Fs is thesampling frequency), and a is a vector specifying the desired amplitude onthe bands defined by f. The length of f is twice the length of a, minus 2. Thedesired funct ion is piecewise constan t .

• dev is a vector the same size as a tha t specifies the maximum allowabledevia t ion or r ipples between the frequency response and the desiredamplitude of the output filt er , for each band.

Use remez with the resu lt ing order n, frequency vector fo, amplitude responsevector ao, and weigh ts w to design the filter b which approxima tely meet s thespecifica t ions given by remezord inpu t parameters f, a, and dev:

b = remez(n,fo,ao,w)

[n,fo,ao,w] = remezord(f,a,dev,Fs) specifies a sampling frequency Fs.Fs defau lt s to 2 Hz, implying a Nyquist frequency of 1 Hz. You can thereforespecify band edges sca led to a pa r t icu la r applica t ion’s sampling frequency.

In some cases remezord underest ima tes the order n. If the filt er does not meetthe specifica t ions, t ry a higher order such as n+1 or n+2.

c = remezord(f,a,dev,Fs,'cell') specifies a cell-a r ray whose element s a rethe parameters to remez.

Examples Design a min imum-order lowpass filt er with a 500 Hz passband cutofffrequency and 600 Hz stopband cutoff frequency, with a sampling frequency of

Page 599: MATLAB Signal Processing Toolbox user manual

remezord

6-295

2000 Hz), a t least 40 dB at tenua t ion in the stopband, and less than 3 dB ofr ipple in the passband:

rp = 3; % passband ripplers = 40; % stopband rippleFs = 2000; % sampling frequencyf = [500 600]; % cutoff frequenciesa = [1 0]; % desired amplitudes

% compute deviationsdev = [(10^(rp/20)–1)/(10^(rp/20)+1) 10^(–rs/20)];

[n,fo,ao,w] = remezord(f,a,dev,Fs);b = remez(n,fo,ao,w);[h,f] = freqz(b,1,1024,Fs);plot(f,20*log10(abs(h)));

title('Lowpass Filter Designed to Specifications');xlabel('Frequency (Hz)'); ylabel('Magnitude (dB)'); grid;

Note tha t the filt er fa lls slight ly shor t of meet ing the stopband at tenuat ion andpassband r ipple specifica t ions. Using n+1 in the ca ll to remez inst ead of nach ieves the desired amplitude character ist ics.

0 100 200 300 400 500 600 700 800 900 1000-60

-50

-40

-30

-20

-10

0

10

Frequency (Hz)

Mag

nitu

de (d

B)

Lowpass Filter Designed to Specifications

Page 600: MATLAB Signal Processing Toolbox user manual

remezord

6-296

Design a lowpass filter with a 1500 Hz passband cutoff frequency and 2000 Hzstopband cutoff frequency, with a sampling frequency of 8000 Hz, a maximumstopband amplitude of 0.1, and a maximum passband er ror (r ipple) of 0.01:

[n,fo,ao,w] = remezord( [1500 2000], [1 0], [0.01 0.1], 8000 );b = remez(n,fo,ao,w);

This is equiva lent to

c = remezord( [1500 2000], [1 0], [0.01 0.1], 8000, 'cell');b = remez(c{:});

NOTE In some cases, remezord underest imates or overest imates the order n.If the filt er does not meet the specifica t ions, t ry a higher order such as n+1 or n+2.

Result s a re inaccura t e if the cu toff frequencies a re near 0 or the Nyquistfrequency.

Algorithm remezord uses the a lgor ithm suggested in [1]. This method is inaccura te forband edges close to either 0 or the Nyquist frequency (Fs/2).

Diagnostics If the inpu t parameter lengths a re not consisten t , remezord gives the followinger ror messages:

Requires M and DEV to be the same length.Length of F must be length(M)–2.

See Also buttord But terwor th filt er order select ion.cheb1ord Chebyshev type I filter order select ion .cheb2ord Chebyshev type II filter order select ion.ellipord Ellipt ic filt er order select ion .kaiserord Est imate parameters for an FIR filter design with

Kaiser window.remez Parks-McClellan opt ima l FIR filter design .

Page 601: MATLAB Signal Processing Toolbox user manual

remezord

6-297

References [1] Rabiner , L.R., and O. Herrmann. “The Predictabilit y of Cer ta in Opt imumFin ite Impulse Response Digit a l Filter s.” IEEE Trans. on Circu it Theory.Vol. CT-20, No. 4 (J u ly 1973). Pgs. 401-408.

[2] Rabiner , L.R., and B. Gold. Theory and Application of Digital S ignalProcessing. Englewood Cliffs, NJ : Pren t ice Hall, 1975. Pgs. 156-157.

Page 602: MATLAB Signal Processing Toolbox user manual

resample

6-298

6resamplePurpose Change sampling ra t e by any ra t iona l factor .

Syntax y = resample(x,p,q)y = resample(x,p,q,n)y = resample(x,p,q,n,beta)y = resample(x,p,q,b)[y,b] = resample(x,p,q)

Description y = resample(x,p,q) resamples the sequence in vector x a t p/q t imes theor igina l sampling ra te, using a polyphase filt er implementa t ion . The length ofy is equal to ceil(length(x)*p/q). p and q must be posit ive in t egers. If x is ama tr ix, resample works down the columns of x.

resample applies an ant i-a liasing (lowpass) FIR filter to x dur ing theresampling process. It designs the filter using firls with a Kaiser window.

y = resample(x,p,q,n) uses n terms on either side of the cur ren t sample,x(k), to per form the resampling. The length of the FIR filter resample uses ispropor t iona l to n; la rger va lues of n provide bet t er accuracy a t the expense ofmore computa t ion t ime. The defau lt for n is 10. If you let n = 0, resampleper forms a nearest -neighbor in terpola t ion :

y(k) = x(round((k-1)*q/p)+1)

where y(k) = 0 if the index to x is grea ter than length(x).

y = resample(x,p,q,n,beta) uses beta as the design parameter for theKaiser window tha t resample employs in design ing the lowpass filter . Thedefau lt for beta is 5.

y = resample(x,p,q,b) filt ers x with b, a vector of filter coefficien ts.

[y,b] = resample(x,p,q) retu rns the vector b, which conta ins thecoefficien ts of the filter applied to x dur ing the resampling process.

Page 603: MATLAB Signal Processing Toolbox user manual

resample

6-299

Examples Resample a simple linear sequence a t 3/2 the or igina l ra t e:

Fs1 = 10; % original sampling frequency in Hzt1 = 0:1/Fs1:1; % time vectorx = t1; % define a linear sequencey = resample(x,3,2); % now resample it

t2 = (0:(length(y)–1))*2/(3*Fs1); % new time vectorplot(t1,x,'*',t2,y,'o',–0.5:0.01:1.5,–0.5:0.01:1.5,':')legend('original','resampled'); xlabel('Time')

Not ice tha t the la st few poin ts of the outpu t y are inaccura te. In it s filter ingprocess, resample assumes the samples a t t imes before and after the givensamples in x are equa l to zero. Thus large devia t ions from zero a t the end

−0.5 0 0.5 1 1.5−0.5

0

0.5

1

1.5

Time

original resampled

Page 604: MATLAB Signal Processing Toolbox user manual

resample

6-300

poin ts of the sequence x can cause inaccuracies in y a t it s end poin t s. Thefollowing two plot s illust ra t e th is side effect of resample:

x = [1:10 9:–1:1]; y = resample(x,3,2);subplot(2,1,1);plot(1:19,x,'*',(0:28)*2/3 + 1,y,'o');title('Edge Effects Not Noticeable');legend('original','resampled');

x = [10:–1:1 2:10]; y = resample(x,3,2);subplot(2,1,2);plot(1:19,x,'*',(0:28)*2/3 + 1,y,'o')title('Edge Effects Very Noticeable');legend('original','resampled');

Diagnostics If p or q a re not posit ive in tegers, resample gives the appropr ia t e er rormessage:

P must be a positive integer.Q must be a positive integer.

If x is not a vector , resample gives the following er ror message:

Input X must be a vector.

0 5 10 15 200

2

4

6

8

10Edge Effects Not Noticeable

original resampled

0 5 10 15 200

5

10

15Edge Effects Very Noticeable

original resampled

Page 605: MATLAB Signal Processing Toolbox user manual

resample

6-301

See Also decimate Decrease the sampling ra t e for a sequence(decimat ion).

firls Least square linear-phase FIR filter design .interp Increase sampling ra t e by an in teger factor

(in terpola t ion).interp1 One-dimensiona l da ta in terpola t ion (table lookup)

(see the online MATLAB Function Reference).intfilt In terpola t ion FIR filt er design .kaiser Kaiser window.spline Cubic spline in terpola t ion (see the on line MATLAB

Function Reference).upfirdn Upsample, apply an FIR filter, and downsample.

Page 606: MATLAB Signal Processing Toolbox user manual

residuez

6-302

6residuezPurpose z-t r ansform par t ia l-fract ion expansion .

Syntax [r,p,k] = residuez(b,a)[b,a] = residuez(r,p,k)

Description residuez conver t s a discrete t ime syst em, expressed as the ra t io of twopolynomia ls, to pa r t ia l fract ion expansion , or residue, form . It a lso conver ts thepar t ia l fract ion expansion back to the or igina l polynomia l coefficien t s.

[r,p,k] = residuez(b,a) finds the residues, poles, and direct t erms of apar t ia l fract ion expansion of the ra t io of two polynomia ls, b(z) and a(z). Vectorsb and a specify the coefficient s of the polynomia ls of the discrete-t ime systemb(z)/ a(z) in descending powers of z:

If there are no mult iple root s and a > n–1,

The retu rned column vector r conta ins the residues, column vector p conta insthe pole loca t ions, and row vector k con ta ins the direct terms. The number ofpoles is

n = length(a)–1 = length(r) = length(p)

The direct term coefficien t vector k is empty if length(b) < length(a);otherwise

length(k) = length(b) – length(a) + 1

If p(j) = ... = p(j+s–1) is a pole of mult iplicity s, t hen the expansionincludes terms of the form

b z( ) b0 b1z 1– b2z 2– L bm z m–+ + + +=

a z( ) a0 a1z 1– a2z 2– L an 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------------------------------------+ + +

Page 607: MATLAB Signal Processing Toolbox user manual

residuez

6-303

[b,a] = residuez(r,p,k) with three inpu t a rguments and two outpu targument s, conver t s the par t ia l fract ion expansion back to polynomia ls withcoefficien t s in row vectors b and a.

The residue funct ion in the standa rd MATLAB language is very simila r toresiduez. It computes the par t ia l fract ion expansion of cont inuous-t imesystems in the Laplace domain (see reference [1]), r a ther than discrete-t imesystems in the z-domain as does residuez.

Algorithm residuez applies st andard MATLAB funct ions and par t ia l fract ion techniquesto find r, p, and k from b and a. It finds:

1 The direct terms a using deconv (polynomia l long division) whenlength(b)>length(a)–1.

2 The poles using p = roots(a). mpoles finds repea ted poles and reorders thepoles according to their mult iplicit ies.

3 The residue for each nonrepea t ing pole p i by mult iplying b(z)/ a(z) by1/(1-p iz-1) and eva lua t ing the result ing ra t iona l funct ion a t z = p i.

4 The residues for the repea ted poles by solvingS2*r2 = h – S1*r1

for r2 using \. h is the impulse response of the reduced b(z)/ a(z), S1 is ama tr ix whose columns a re impulse responses of the fir st -order systemsmade up of the nonrepea t ing root s, and r1 is a column conta in ing theresidues for the nonrepea t ing roots. Each column of mat r ix S2 is an impulseresponse. For each root p j of mult iplicity sj, S2 conta ins sj columnsrepresen t ing the impulse responses of each of the following syst ems:

The vector h and matr ices S1 and S2 have n + xtra rows, where n is the tota lnumber of roots and the in t erna l parameter xtra, set to 1 by defau lt ,determines the degree of overdetermina t ion of the system of equat ions.

Diagnostics If a(1) == 0 while comput ing the pa r t ia l fract ion decomposit ion using[r,p,k] = residuez(b,a), residuez gives the following er ror message:

First coefficient in A vector must be nonzero.

11 p jz 1––----------------------- 1

1 p jz 1––( )2------------------------------- L

11 p jz 1––( )s j--------------------------------, , ,

Page 608: MATLAB Signal Processing Toolbox user manual

residuez

6-304

If the number of residues r and poles p is not the same, residuez gives thefollowing er ror message:

R and P vectors must be the same size.

See Also

References [1] Oppenheim , A.V., and R.W. Schafer . Digital S ignal Processing. EnglewoodCliffs, NJ : Pren t ice Ha ll, 1975. Pgs. 166-170.

convmtx Convolut ion mat r ix.deconv Deconvolu t ion and polynomia l division (see the

online MATLAB Function Reference).poly Polynomia l with specified root s (see the online

MATLAB Function Reference).prony Prony’s method for t ime domain IIR filter design .residue Par t ia l fract ion expansion (see the online MATLAB

Function Reference).roots Polynomia l root s (see the online MATLAB Function

Reference).ss2tf Conversion of sta te-space to zero-pole-ga in .tf2ss Conversion of t ransfer funct ion to sta t e-space.tf2zp Conversion of t ransfer funct ion to zero-pole-ga in .zp2ss Conversion of zero-pole-ga in to sta t e-space.

Page 609: MATLAB Signal Processing Toolbox user manual

rlevinson

6-305

6rlevinsonPurpose Reverse Levinson-Durbin recursion.

Syntax r = rlevinson(a,efinal)[r,u] = rlevinson(a,efinal)[r,u,k] = rlevinson(a,efinal)[r,u,k,e] = rlevinson(a,efinal)

Description The reverse Levinson-Durbin recursion implements the step-down algor ithmfor solving the following symmet r ic Toeplitz syst em of linea r equa t ions for r,where r = [r(1) ... r(p+1)] and r(i)* denotes the complex conjuga te of r(i).

r = rlevinson(a,efinal) solves the above syst em of equat ions for r givenvector a, where a = [1 a(2) ... a(p+1)]. In linea r predict ion applica t ions, rrepresen t s the au tocor rela t ion sequence of the inpu t to the predict ion er rorfilt er , where r(1) is the zero-lag element . The figure below shows the typica lfilt er of th is type, where H (z) is the opt imal linear predictor , x(n ) is the inpu tsigna l, is the predicted signa l, and e(n ) is the predict ion er ror .

Input vector a represen ts the polynomia l coefficien ts of th is predict ion er rorfilt er in descending powers of z

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

r 2( ) r 1( ) L r p 1–( )∗

M O O M

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

a 2( )a 3( )

M

a p 1+( )

r 2( )–r 3( )–M

r p 1+( )–

=

x n( )

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

–+

e n( )

Prediction Error Filter

A z( )

A z( ) 1 a 2( )z 1– L a n 1+( )z p–+ + +=

Page 610: MATLAB Signal Processing Toolbox user manual

rlevinson

6-306

The filter must be minimum phase to genera t e a va lid au tocorrela t ionsequence. efinal is the sca la r predict ion er ror power , which is equa l to thevar iance of the predict ion er ror signa l, σ2(e).

[r,u] = rlevinson(a,efinal) returns upper t r iangula r ma t r ix U from theUDU* decomposit ion

where

and E is a diagona l mat r ix with elements retu rned in outpu t e (see below). Thisdecomposit ion permits the efficien t eva lua t ion of the inverse of theautocorrela t ion matr ix, R -1.

Output matr ix u conta ins the predict ion polynomia l, a, from each itera t ion ofthe reverse Levinson-Durbin recursion

where a i(j) is the jth coefficien t of the ith order predict ion polynomia l (i.e., stepi in the recursion). For example, the 5th order predict ion polynomia l is

a5 = u(5:-1:1,5)'

Note tha t u(p+1:-1:1,p+1)' is the input polynomia l coefficien t vector a.

R 1– UE 1– U ∗=

R

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

r 2( ) r 1( ) L r p 1–( )∗

M O O M

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

=

U

a1 1( )∗ a2 2( )

∗Lap 1+ p 1+( )

0 a2 1( )∗

O ap 1+ p( )∗

0 0 Oap 1+ p 1–( )∗

M O O M

0 L 0 ap 1+ 1( )∗

=

Page 611: MATLAB Signal Processing Toolbox user manual

rlevinson

6-307

[r,u,k] = rlevinson(a,efinal) retu rns a vector k of length (p+1) conta in ingthe reflect ion coefficien t s. The reflect ion coefficien t s a re the con juga tes of theva lues in the fir st row of u

k = conj(u(1,2:end))

[r,u,k,e] = rlevinson(a,efinal) retu rns a vector of length (p+1)conta in ing the predict ion er rors from each itera t ion of the reverseLevinson-Durbin recursion : e(1) is the predict ion er ror from the fir st -ordermodel, e(2) is the predict ion er ror from the second-order model, and so on .

These predict ion er ror va lues form the diagona l of the mat r ix E in the UDU*decomposit ion of R -1,

.

See Also

References [1] Kay, S.M.Modern S pectral Estim ation: Theory and Application . EnglewoodCliffs, NJ : Pren t ice Ha ll, 1988.

R 1– UE 1– U ∗=

levinson Levinson-Durbin recursion .lpc Linea r predict ion coefficient s.prony Prony’s method for t ime domain IIR filter design .stmcb Linea r model using Steiglitz-McBr ide itera t ion .

Page 612: MATLAB Signal Processing Toolbox user manual

sawtooth

6-308

6sawtoothPurpose Sawtooth or t r iangle wave genera tor .

Syntax x = sawtooth(t)x = sawtooth(t,width)

Description sawtooth(t) genera tes a sawtooth wave with per iod 2π for the elements oft ime vector t. sawtooth(t) is simila r to sin(t), bu t it crea tes a sawtooth wavewith peaks of -1 and 1 inst ead of a sine wave. The sawtooth wave is defined tobe -1 a t mult iples of 2π and to increase linear ly with t ime with a slope of 1/π a ta ll other t imes.

sawtooth(t,width) genera tes a modified t r iangle wave where width, a sca la rparameter between 0 and 1, determines the fract ion between 0 and 2π a t whichthe maximum occurs. The funct ion increases from -1 to 1 on the int erva l 0 to2π*width, then decreases linea r ly from 1 to -1 on the in terva l 2π*width t o 2π.Thus a pa rameter of 0.5 specifies a standa rd t r iangle wave, symmet r ic aboutt ime instant π with peak-to-peak amplitude of 1. sawtooth(t,1) is equiva len tto sawtooth(t).

Diagnostics If the width pa rameter is not a sca la r , sawtooth gives the following er rormessage:

Requires WIDTH parameter to be a scalar.

See Also chirp Swept-frequency cosine genera tor.cos Cosine of vector /matr ix elements (see the online

MATLAB Function Reference).diric Dir ich let or per iodic sinc funct ion .gauspuls Gaussian-modula t ed sinusoida l pu lse genera tor.pulstran Pulse t ra in genera tor.rectpuls Sampled aperiodic rect angle genera tor.sin Sine of vector /matr ix elements (see the online

MATLAB Function Reference).sinc Sinc or sin(πt )/πt funct ion .square Square wave genera tor.tripuls Sampled aperiodic t r iangle genera tor.

Page 613: MATLAB Signal Processing Toolbox user manual

sgolay

6-309

6sgolayPurpose Savitzky-Golay filt er design .

Syntax b = sgolay(k,f)b = sgolay(k,f,w)

Description b = sgolay(k,f) designs a Savitzky-Golay FIR smooth ing filt er b. Thepolynomia l order k must be less than the frame size, f, which must be odd. Ifk = f–1, the designed filter produces no smooth ing. The ou tpu t , b, is an f-by-fmat r ix whose rows represen t the t ime-va rying FIR filt er coefficien t s. In asmoothing filt er implementa t ion (for example, sgolayfilt), t he la st (f–1)/2rows (each an FIR filter ) a re applied to the signa l dur ing the sta r tup t ransien t ,and the fir st (f–1)/2 rows a re applied to the signa l dur ing the termina lt ransien t . The center row is applied to the signal in the st eady sta te.

b = sgolay(k,f,w) specifies a weigh t ing vector w with length f, whichconta ins the rea l, posit ive-va lued weigh ts to be used dur ing the least -squaresmin imiza t ion .

Remarks Savitzky-Golay smoothing filt ers (a lso ca lled digit a l smoothing polynomia lfilt ers or least squares smooth ing filter s) a re typica lly used to “smooth out” anoisy signa l whose frequency span (withou t noise) is la rge. In th is type ofapplica t ion , Savitzky-Golay smooth ing filters per form much bet ter thanstandard averaging FIR filter s, which tend to filt er out a sign ifican t por t ion ofthe signa l’s h igh frequency content a long with the noise. AlthoughSavitzky-Golay filt er s are more effect ive a t preserving the per t inen t h ighfrequency components of the signa l, they a re less successful than standa rdaveraging FIR filter s a t reject ing noise.

Savitzky-Golay filt er s are opt imal in the sense tha t they minimize theleast -squares er ror in fit t ing a polynomia l to each frame of noisy da ta .

See Also fir1 Window-based fin ite impulse response filter design –standard response.

firls Least square linear-phase FIR filter design .filter Filt er da ta with a recursive (IIR) or nonrecursive

(FIR) filter.sgolayfilt Savitzky-Golay filter ing.

Page 614: MATLAB Signal Processing Toolbox user manual

sgolay

6-310

References [1] Orfan idis, S.J . In troduction to S ignal Processing. Englewood Cliffs, NJ :Prent ice Hall, 1996.

Page 615: MATLAB Signal Processing Toolbox user manual

sgolayfilt

6-311

6sgolayfiltPurpose Savitzky-Golay filt er ing.

Syntax y = sgolayfilt(x,k,f)y = sgolayfilt(x,k,f,w)

Description y = sgolayfilt(x,k,f) applies a Savit zky-Golay FIR smooth ing filter to theda ta in vector x. If x is a matr ix, sgolayfilt opera t es on each column. Thepolynomia l order k must be less than the frame size, f, which must be odd. Ifk = f–1, t he filter produces no smooth ing.

y = sgolayfilt(x,k,f,w) specifies a weight ing vector w with length f, whichconta ins the rea l, posit ive-va lued weigh ts to be used dur ing the least -squaresmin imiza t ion .

Remarks Savitzky-Golay smoothing filt ers (a lso ca lled digit a l smoothing polynomia lfilt ers or least -squa res smoothing filt ers) a re typica lly used to “smooth out” anoisy signa l whose frequency span (withou t noise) is la rge. In th is type ofapplica t ion , Savitzky-Golay smooth ing filters per form much bet ter thanstandard averaging FIR filter s, which tend to filt er out a sign ifican t por t ion ofthe signa l’s h igh frequency content a long with the noise. AlthoughSavitzky-Golay filt er s are more effect ive a t preserving the per t inen t h ighfrequency components of the signa l, they a re less successful than standa rdaveraging FIR filter s a t reject ing noise.

Savitzky-Golay filt er s are opt imal in the sense tha t they minimize theleast -squares er ror in fit t ing a polynomia l to frames of noisy da ta .

Page 616: MATLAB Signal Processing Toolbox user manual

sgolayfilt

6-312

Example Smooth the mtlb signa l by applying a cubic Savitzky-Golay filt er to da taframes of length 41.

load mtlb % load the datasmtlb = sgolayfilt(mtlb,3,41); % apply the 3rd-order filter

subplot(2,1,1)plot([1:2000],mtlb(1:2000)); axis([0 2000 –4 4]);title('mtlb'); grid;

subplot(2,1,2)plot([1:2000],smtlb(1:2000)); axis([0 2000 –4 4]);title('smtlb'); grid;

See Also

References [1] Orfan idis, S.J . In troduction to S ignal Processing. Englewood Cliffs, NJ :Prent ice Hall, 1996.

0 500 1000 1500 2000−4

−2

0

2

4mtlb

0 500 1000 1500 2000−4

−2

0

2

4smtlb

medfilt1 One-dimensiona l median filt er ing.filter Filt er da ta with a recursive (IIR) or nonrecursive

(FIR) filter.sgolay Savit zky-Golay filter design .sosfilt Second-order (biquadra t ic) IIR filt er ing.

Page 617: MATLAB Signal Processing Toolbox user manual

sinc

6-313

6sin cPurpose Sinc funct ion.

Syntax y = sinc(x)

Description sinc computes the sinc funct ion of an input vector or ar ray, where the sincfunct ion is

This funct ion is the cont inuous inverse Four ier t ransform of the rect angula rpu lse of width 2π and heigh t 1:

y = sinc(x) retu rns an ar ray y t he same size as x, whose elements a re thesinc funct ion of the elements of x.

The space of funct ions bandlimited in the frequency band is spannedby the infin ite (yet countable) set of sinc funct ions sh ifted by in tegers. Thus anysuch bandlimited funct ion g(t) can be reconst ruct ed from it s samples a t in tegerspacings:

sinc t( )1 t 0=,

πt( )sinπt------------------- t 0≠,

⎩⎪⎨⎪⎧

=

sinc t( ) 12π------ ejω t ωd

π–

π

∫=

ω π– π[ , ]∈

g t( ) g n( )sinc t n–( )n ∞–=

∑=

Page 618: MATLAB Signal Processing Toolbox user manual

sinc

6-314

Example Perform idea l bandlimit ed in terpola t ion by assuming tha t the signa l to bein t erpola t ed is 0 outside of the given t ime interva l and tha t it ha s been sampleda t exact ly the Nyquist frequency:

t = (1:10)'; % a column vector of time samplesrandn('seed',0);x = randn(size(t)); % a column vector of data% ts is times at which to interpolate datats = linspace(–5,15,600)';y = sinc(ts(:,ones(size(t))) – t(:,ones(size(ts)))')*x;plot(t,x,'o',ts,y)

-5 0 5 10 15-1

-0.5

0

0.5

1

1.5

2

Page 619: MATLAB Signal Processing Toolbox user manual

sinc

6-315

See Also chirp Swept-frequency cosine genera tor.cos Cosine of vector /mat r ix element s (see the online

MATLAB Function Reference).diric Dir ich let or per iodic sinc funct ion .gauspuls Gaussian-modula t ed sinusoida l pu lse genera tor.pulstran Pulse t ra in genera tor.rectpuls Sampled aper iodic rectangle genera tor.sawtooth Sawtooth or t r iangle wave genera tor.sin Sine of vector /matr ix elements (see the online

MATLAB Function Reference).square Square wave genera tor.tripuls Sampled aper iodic t r iangle genera tor.

Page 620: MATLAB Signal Processing Toolbox user manual

sos2ss

6-316

6sos2ssPurpose Conversion of second-order sect ions to sta t e-space.

Syntax [A,B,C,D] = sos2ss(sos)[A,B,C,D] = sos2ss(sos,g)

Description sos2ss conver t s a second-order sect ion represen ta t ion of a given system to anequiva len t st a te-space represen ta t ion .

[A,B,C,D] = sos2ss(sos) conver ts the system sos, in second-order sect ionform, to a single-input , single-ou tpu t sta te-space represen ta t ion :

The discrete t ransfer funct ion in second-order sect ion form is given by

sos is a L -by-6 matr ix organized as

The en t r ies of sos must be rea l for proper conversion to sta te space. Thereturned mat r ix A is size N -by-N , where N = 2L-1, B is a length N -1 columnvector , C is a length N -1 row vector , and D is a sca la r .

[A,B,C,D] = sos2ss(sos,g) conver t s the system sos in second-order sect ionform with gain g:

x n 1+[ ] Ax n[ ] B u n[ ]+=y n[ ] Cx n[ ] Du n[ ]+=

H z( ) Hk z( )k 1=

L

∏b0 k b1 k z 1– b2 k z 2–+ +1 a1 k z 1– a2 k z 2–+ +----------------------------------------------------------

k 1=

L

∏= =

sos

b01 b11 b21 1 a11 a21b02 b12 b22 1 a12 a22M M M M M M

b0L b1L b2L 1 a1L a2L

=

H z( ) g H k z( )k 1=

L

∏=

Page 621: MATLAB Signal Processing Toolbox user manual

sos2ss

6-317

Example Compute the st a te-space represen ta t ion of a simple second-order sect ionsystem with a gain of 2:

sos = [1 1 1 1 0 –1; –2 3 1 1 10 1];[A,B,C,D] = sos2ss(sos)

A = –10 0 10 1 1 0 0 0 0 1 0 0 0 0 1 0

B = 1 0 0 0

C = 21 2 –16 –1

D = –2

Algorithm sos2ss fir st conver t s from second-order sect ions to t ransfer funct ion usingsos2tf, and then from transfer funct ion to sta te-space using tf2ss.

See Also sos2tf Conversion of second-order sect ions to t ransferfunct ion .

sos2zp Conversion of second-order sect ions to zero-pole-ga in .ss2sos Conversion of sta t e-space to second-order sect ions.tf2ss Conversion of t ransfer funct ion to st a t e-space.zp2ss Conversion of zero-pole-ga in to st a t e-space.

Page 622: MATLAB Signal Processing Toolbox user manual

sos2tf

6-318

6sos2t fPurpose Conversion of second-order sect ions to t ransfer funct ion .

Syntax [b,a] = sos2tf(sos)[b,a] = sos2tf(sos,g)

Description sos2tf conver t s a second-order sect ion represen ta t ion of a given system to anequiva len t t ransfer funct ion represen ta t ion .

[b,a] = sos2tf(sos) retu rns the numera tor coefficien ts b and denominatorcoefficien t s a of the t ransfer funct ion tha t descr ibes a discret e-t ime syst emgiven by sos in second-order sect ion form. The second-order sect ion format ofH (z) is given by

sos is an L-by-6 ma tr ix tha t conta ins the coefficien t s of each second-ordersect ion stored in it s rows:

Row vectors b and a conta in the numera tor and denomina tor coefficien ts ofH (z) stored in descending powers of z:

[b,a] = sos2tf(sos,g) retu rns the t ransfer funct ion tha t descr ibes adiscrete-t ime system given by sos in second-order sect ion form with ga in g:

H z( ) Hk z( )k 1=

L

∏b0 k b1 k z 1– b2 k z 2–+ +1 a1 k z 1– a2 k z 2–+ +----------------------------------------------------------

k 1=

L

∏= =

sos

b01 b11 b21 1 a11 a21b02 b12 b22 1 a12 a22M M M M M M

b0L b1L b2L 1 a1L a2L

=

H z( ) B z( )A z( )-----------

b1 b2z 1– L bn 1+ z n–+ + +a1 a2z 1– L am 1+ z m–+ + +---------------------------------------------------------------------= =

H z( ) g H k z( )k 1=

L

∏=

Page 623: MATLAB Signal Processing Toolbox user manual

sos2tf

6-319

Algorithm sos2tf uses the conv funct ion to mult iply a ll of the numera tor anddenomina tor second-order polynomia ls together .

Example Compute the t ransfer funct ion represen ta t ion of a simple second-order sect ionsystem:

sos = [1 1 1 1 0 –1; –2 3 1 1 10 1];[b,a] = sos2tf(sos)

b = –2 1 2 4 1

a = 1 10 0 –10 –1

See Also latc2tf Lat t ice filter to t ransfer funct ion conversion .sos2ss Conversion of second-order sect ions to sta t e-space.sos2zp Conversion of second-order sect ions to zero-pole-ga in .ss2tf Conversion of sta t e-space to t ransfer funct ion .tf2sos Conversion of t ransfer funct ion to second-order

sect ions.zp2tf Conversion of zero-pole-ga in to t ransfer funct ion .

Page 624: MATLAB Signal Processing Toolbox user manual

sos2zp

6-320

6sos2zpPurpose Conversion of second-order sect ions to zero-pole-ga in .

Syntax [z,p,k] = sos2zp(sos)[z,p,k] = sos2zp(sos,g)

Description sos2zp conver t s a second-order sect ion represen ta t ion of a given system to anequ iva len t zero-pole-ga in represen ta t ion .

[z,p,k] = sos2zp(sos) retu rns the zeros z, poles p, and ga in k of the syst emgiven by sos in second-order sect ion form. The second-order sect ion format ofH (z) is given by

sos is an L -by-6 ma tr ix tha t con ta ins the coefficien t s of each second-ordersect ion stored in it s rows:

Column vectors z and p conta in the zeros and poles of the t ransferfunct ion H (z):

where the orders n and m are determined by the ma tr ix sos.

[z,p,k] = sos2zp(sos,g) retu rns the zeros z, poles p, and ga in k of thesystem given by sos in second-order sect ion form with ga in g:

H z( ) Hk z( )k 1=

L

∏b0 k b1 k z 1– b2 k z 2–+ +1 a1 k z 1– a2 k z 2–+ +----------------------------------------------------------

k 1=

L

∏= =

sos

b01 b11 b21 1 a11 a21b02 b12 b22 1 a12 a22M M M M M M

b0L b1L b2L 1 a1L a2L

=

H z( ) kz z1–( ) z z2–( )Lz zn–( )

p p1–( ) p p2–( )Lp pm–( )-------------------------------------------------------------------=

H z( ) g H k z( )k 1=

L

∏=

Page 625: MATLAB Signal Processing Toolbox user manual

sos2zp

6-321

Example Compute the poles, zeros, and ga in of a simple system in second-order sect ionform:

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 the poles and zeros of each second-order sect ion by repea tedlyca lling tf2zp.

See Also sos2ss Conversion of second-order sect ions to sta t e-space.sos2tf Conversion of second-order sect ions to t ransfer

funct ion .ss2zp Conversion of sta t e-space to zero-pole-ga in .tf2zp Conversion of t ransfer funct ion to zero-pole-ga in .zp2sos Conversion of zero-pole-ga in to second-order sect ions.

Page 626: MATLAB Signal Processing Toolbox user manual

sosfilt

6-322

6sosfiltPurpose Second-order (biquadra t ic) IIR filt er ing.

Syntax y = sosfilt(sos,x)

Description y = sosfilt(sos,x) applies the second-order sect ion filter sos t o vector x.The ou tpu t , y, is the same length as x.

sos represen ts the second-order sect ion filt er H (z)

by an L -by-6 mat r ix conta in ing the coefficien t s of each second-order sect ion init s rows

If x is a matr ix, sosfilt applies the filt er to each column of x independent ly.Outpu t y is a ma tr ix of the same size, con ta in ing the filtered da tacor responding to each column of x.

See Also

References [1] Orfan idis, S.J . In troduction to S ignal Processing. Englewood Cliffs, NJ :Prent ice Hall, 1996.

H z( ) Hk z( )k 1=

L

∏b0 k b1 k z 1– b2 k z 2–+ +1 a1 k z 1– a2 k z 2–+ +----------------------------------------------------------

k 1=

L

∏= =

sos

b01 b11 b21 1 a11 a21b02 b12 b22 1 a12 a22M M M M M M

b0L b1L b2L 1 a1L a2L

=

filter Filt er da ta with a recursive (IIR) or nonrecursive(FIR) filter.

medfilt1 One-dimensiona l median filt er ing.sgolayfilt Savit zky-Golay filter ing.

Page 627: MATLAB Signal Processing Toolbox user manual

specgram

6-323

6specgramPurpose Time-dependent frequency ana lysis (spect rogram).

Syntax B = specgram(a)B = specgram(a,nfft)[B,f] = specgram(a,nfft,Fs)[B,f,t] = specgram(a,nfft,Fs)B = specgram(a,nfft,Fs,window)B = specgram(a,nfft,Fs,window,noverlap)specgram(a)B = specgram(a,f,Fs,window,noverlap)

Description specgram computes the windowed discret e-t ime Four ier t ransform of a signa lusing a sliding window. The spect rogram is the magnitude of th is funct ion .

B = specgram(a) ca lcu la t es the spect rogram for the signa l in vector a. Th issyntax uses the defau lt va lues:

• nfft = min(256,length(a)) • Fs = 2 • window = hanning(nfft)

• noverlap = length(window)/2

nfft specifies the FFT length tha t specgram uses. This va lue determines thefrequencies a t which the discrete-t ime Four ier t ransform is computed. Fs is asca la r tha t specifies the sampling frequency. window specifies a windowingfunct ion and the number of samples specgram uses in it s sect ion ing of vector a.noverlap is the number of samples by which the sect ions over lap. Anyargument s tha t you omit from the end of the input parameter list use thedefault va lues shown above.

If a is rea l, specgram computes the discrete-t ime Four ier t ransform at posit ivefrequencies on ly. If n is even, specgram returns nfft/2+1 rows (including thezero and Nyquist frequency terms). If n is odd, specgram retu rns nfft/2 rows.The number of columns in B is

k = fix((n–noverlap)/(length(window)–noverlap))

If a is complex, specgram computes the discrete-t ime Four ier t r ansform at bothposit ive and nega t ive frequencies. In th is case, B is a complex mat r ix with nfft

Page 628: MATLAB Signal Processing Toolbox user manual

specgram

6-324

rows. Time increases linear ly across the columns of B, sta r t ing with sample 1in column 1. Frequency increases linear ly down the rows, st a r t ing a t 0.

B = specgram(a,nfft) uses the specified FFT length nfft in it s ca lcu la t ions.Specify nfft as a power of 2 for fa stest execu t ion .

[B,f] = specgram(a,nfft,Fs) retu rns a vector f of frequencies a t which thefunct ion computes the discrete-t ime Four ier t ransform. Fs has no effect on theou tpu t B; it is a frequency sca ling mult iplier .

[B,f,t] = specgram(a,nfft,Fs) retu rns frequency and t ime vectors f and trespect ively. t is a column vector of sca led t imes, with length equal to thenumber of columns of B. t(j) is the ear liest t ime at which the j-th windowintersects a. t(1) is a lways equa l to 0.

B = specgram(a,nfft,Fs,window) specifies a windowing funct ion and thenumber of samples per sect ion of the x vector . If you supply a sca la r for window,specgram uses a Hanning window of tha t length . The length of the windowmust be less than or equa l to nfft; specgram zero pads the sect ions if the lengthof the window exceeds nfft.

B = specgram(a,nfft,Fs,window,noverlap) overlaps the sect ions of x bynoverlap samples.

You can use the empty mat r ix [] t o specify the defau lt va lue for any inputa rgument . For example,

B = specgram(x,[],10000)

is equiva len t to

B = specgram(x)

but with a sampling frequency of 10,000 Hz inst ead of the default 2 Hz.

specgram with no outpu t a rguments displays the sca led logar ithm of thespect rogram in the cur ren t figure window using

imagesc(t,f,20*log10(abs(b))),axis xy,colormap(jet)

Page 629: MATLAB Signal Processing Toolbox user manual

specgram

6-325

The axis xy mode displays the low-frequency conten t of the fir st por t ion of thesigna l in the lower-left corner of the axes. specgram uses Fs t o label the axesaccording to t rue t ime and frequency.

B = specgram(a,f,Fs,window,noverlap) computes the spect rogram at thefrequencies specified in f, using either the ch irp z-t r ansform (for more than 20even ly spaced frequencies) or a polyphase decimat ion filter bank. f is a vectorof frequencies in Her tz; it must have a t least two element s.

Algorithm specgram ca lcu la tes the spect rogram for a given signa l a s follows:

1 It split s the signa l in to over lapping sect ions and applies the windowspecified by the window parameter to each sect ion .

2 It computes the discret e-t ime Four ier t ransform of each sect ion with alength nfft FFT to produce an est imate of the shor t -t erm frequency conten tof the signa l; t hese t ransforms make up the columns of B. specgram zeropads the windowed sect ions if nfft > length(window), so the quant ity(length(window) – noverlap) specifies by how many samples specgramsh ift s the window.

3 For rea l inpu t , specgram t runca tes the spect rogram to the fir st nfft/2 + 1poin ts for nfft even and (nfft + 1)/2 for nfft odd.

Page 630: MATLAB Signal Processing Toolbox user manual

specgram

6-326

Example Plot the spect rogram of a digit ized speech signa l:

load mtlbspecgram(mtlb,512,Fs,kaiser(500,5),475)title('Spectrogram')

Diagnostics An appropr ia te diagnost ic message is displayed when incor rect a rguments areused:

Requires window's length to be no greater than the FFT length.Requires NOVERLAP to be strictly less than the window length.Requires positive integer values for NFFT and NOVERLAP.Requires vector input.

See Also

Time

Freq

uenc

ySpectrogram

0 0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4 0.450

500

1000

1500

2000

2500

3000

3500

cohere Est imate magnitude squared coherence funct ionbetween two signals.

csd Est imate the cross spect ra l density (CSD) of twosigna ls.

pwelch Est imate the power spect ra l density (PSD) of a signa lusing Welch’s method.

tfe Transfer funct ion est imate from inpu t and ou tpu t .

Page 631: MATLAB Signal Processing Toolbox user manual

specgram

6-327

References [1] Oppenheim, A.V., and R.W. Schafer . Discrete-T im e S ignal Processing.Englewood Cliffs, NJ : Prent ice Hall, 1989. Pgs. 713-718.

[2] Rabiner , L.R., and R.W. Schafer . Digital Processing of S peech S ignals.Englewood Cliffs, NJ : Prent ice Hall, 1978.

Page 632: MATLAB Signal Processing Toolbox user manual

sptool

6-328

6sptoolPurpose In teract ive digit a l signa l processing tool (SPTool).

Syntax sptool

Description The sptool command invokes a su it e of graph ica l user in t er face (GUI) toolstha t provides access to many of the signa l, filter , and spect ra l ana lysisfunct ions in the toolbox in a powerfu l, easy-to-use in teract ive signa l displayand explora t ion environment .

Using SPTool, you can impor t , expor t , and manage signa ls, filter s, and spect ra .F rom SPTool, you can act iva te it s four in tegra ted signa l processing tools:

• The S ignal Browser, for viewing, measur ing, and ana lyzing the t ime-domaininformat ion of one or more signa ls.

Page 633: MATLAB Signal Processing Toolbox user manual

sptool

6-329

• The Filter Designer, for designing and edit ing FIR and IIR filt er s of var iouslengths and types, with standard (lowpass, h ighpass, bandpass, bandstop,and mult iband) configura t ions.

Page 634: MATLAB Signal Processing Toolbox user manual

sptool

6-330

• The Filter Viewer, for viewing the charact er ist ics of a designed or impor t edfilter , including it s magnitude response, phase response, group delay,pole-zero plot , impulse response, and step response.

Page 635: MATLAB Signal Processing Toolbox user manual

sptool

6-331

• The S pectrum Viewer, for graphica l ana lysis of frequency-domain data usinga var iety of methods of spect ra l density est imat ion , including the Burgmethod, the FFT method, the mult itaper method (MTM), the MUSICeigenvector method, Welch’s method, and the Yule-Walker AR method.

See Chapter 5, “In teract ive Tools” for a fu ll discussion of how to use SPTool.

Page 636: MATLAB Signal Processing Toolbox user manual

square

6-332

6squa rePurpose Square wave genera tor .

Syntax x = square(t)x = square(t,duty)

Description x = square(t) genera tes a square wave with per iod 2π for the elements oft ime vector t. square(t) is simila r to sin(t), bu t it crea t es a square wave withpeaks of ±1 inst ead of a sine wave.

x = square(t,duty) genera tes a square wave with specified duty cycle, duty.The duty cycle is the percen t of the per iod in which the signa l is posit ive.

See Also chirp Swept-frequency cosine genera tor.cos Cosine of vector /matr ix elements (see the online

MATLAB Function Reference).diric Dir ich let or per iodic sinc funct ion .gauspuls Gaussian-modula t ed sinusoida l pu lse genera tor.pulstran Pulse t ra in genera tor.rectpuls Sampled aperiodic rect angle genera tor.sawtooth Sawtooth or t r iangle wave genera tor.sin Sine of vector /matr ix elements (see the online

MATLAB Function Reference).sinc Sinc or sin(πt )/πt funct ion .tripuls Sampled aperiodic t r iangle genera tor.

Page 637: MATLAB Signal Processing Toolbox user manual

ss2sos

6-333

6ss2sosPurpose Conversion of sta t e-space to second-order sect ions.

Syntax [sos,g] = ss2sos(A,B,C,D)[sos,g] = ss2sos(A,B,C,D,iu)[sos,g] = ss2sos(A,B,C,D,'order')[sos,g] = ss2sos(A,B,C,D,iu,'order')[sos,g] = ss2sos(A,B,C,D,iu,'order','scale')sos = ss2sos(...)

Description ss2sos conver ts a sta te-space represen ta t ion of a given syst em to anequiva len t second-order sect ion representa t ion .

[sos,g] = ss2sos(A,B,C,D) finds a mat r ix sos in second-order sect ion formwith ga in g tha t is equ iva len t to the st a t e-space syst em represen ted by inputa rgument s A, B, C and D. The input syst em must be single outpu t and rea l. sosis an L -by-6 mat r ix

whose rows conta in the numera tor and denomina tor coefficien ts bik and a ik ofthe second-order sect ions of H (z):

[sos,g] = ss2sos(A,B,C,D,iu) specifies a sca la r iu t ha t determines whichinput of the st a te-space system A, B, C, D is used in the conversion . The defau ltfor iu is 1.

[sos,g] = ss2sos(A,B,C,D,'order') and

[sos,g] = ss2sos(A,B,C,D,iu,'order') specify the order of the rows in sos,where order is:

sos

b01 b11 b21 1 a11 a21b02 b12 b22 1 a12 a22M M M M M M

b0L b1L b2L 1 a1L a2L

=

H z( ) g H k z( )k 1=

L

∏ gb0 k b1 k z 1– b2 k z 2–+ +1 a1 k z 1– a2 k z 2–+ +----------------------------------------------------------

k 1=

L

∏= =

Page 638: MATLAB Signal Processing Toolbox user manual

ss2sos

6-334

• down, t o order the sect ions so the fir st row of sos conta ins the poles closest tothe unit circle

• up, to order the sect ions so the fir st row of sos conta ins the poles fa r thestfrom the un it circle (defau lt )

The zeros a re a lways pa ired with the poles closest to them.

[sos,g] = ss2sos(A,B,C,D,iu,'order','scale') specifies the desiredsca ling of the ga in and the numera tor coefficien ts of a ll second-order sect ions,where scale is:

• none, t o apply no sca ling (default )• inf, t o apply infinity-norm sca ling• two, t o apply 2-norm sca ling

Using infin ity-norm sca ling in conjunct ion with up-order ing minimizes theprobabilit y of over flow in the rea liza t ion . Using 2-norm sca ling in conjunct ionwith down-order ing minimizes the peak round-off noise.

sos = ss2sos(...) embeds the overa ll system gain , g, in the fir st sect ion ,H 1(z), so tha t :

Example Find a second-order sect ion form of a But t erwor th lowpass filt er :

[A,B,C,D] = butter(5,0.2);sos = ss2sos(A,B,C,D)

sos = 0.0013 0.0013 0 1.0000 –0.5095 0 1.0000 2.0008 1.0008 1.0000 –1.0966 0.3554 1.0000 1.9979 0.9979 1.0000 –1.3693 0.6926

Algorithm ss2sos uses a four -step a lgor ithm to determine the second-order sect ionrepresen ta t ion for an input st a te-space system:

H z( ) Hk z( )k 1=

L

∏=

Page 639: MATLAB Signal Processing Toolbox user manual

ss2sos

6-335

1 It finds the poles and zeros of the system given by A, B, C and D.2 It uses the funct ion zp2sos, which fir st groups the zeros and poles in tocomplex conjuga te pa irs using the cplxpair funct ion . zp2sos then forms thesecond-order sect ions by match ing the pole and zero pa ir s according to thefollowing ru les:a Match the poles closest to the unit cir cle with the zeros closest to thosepoles.

b Match the poles next closest to the unit circle with the zeros closest tothose poles.

c Cont inue unt il a ll of the poles and zeros a re matched.ss2sos groups rea l poles in to sect ions with the rea l poles closest to them inabsolu te va lue. The same rule holds for rea l zeros.

3 It orders the sect ions according to the proximity of the pole pa ir s to the unitcircle. ss2sos normally orders the sect ions with poles closest to the unitcircle last in the cascade. You can tell ss2sos to order the sect ions in thereverse order by specifying the 'down' flag.

4 ss2sos sca les the sect ions by the norm specified in the 'scale' argument .For arbit ra ry H (ω), the sca ling is defined by:

where p can be either ∞ or 2. See the references for deta ils on the sca ling.This sca ling is an a t tempt to min imize over flow or peak round-off noise infixed poin t filter implementa t ions.

Diagnostics If there is more than one input to the syst em, ss2sos gives the following er rormessage:

State–space system must have only one input.

H p12π------ H ω( )

pωd

0

1p---

=

Page 640: MATLAB Signal Processing Toolbox user manual

ss2sos

6-336

See Also

References [1] J ackson , L.B. Digital Filters and S ignal Processing. 3rd ed. Boston : KluwerAcademic Publishers, 1996. Chapter 11.

[2] Mit ra , S.K. Digital S ignal Processing: A Com puter-Based Approach . NewYork: McGraw-Hill, 1998. Chapter 9.

[3] Va idyana than , P .P . “Robust Digita l F ilter St ructures.” Handbook forDigital S ignal Processing. S.K. Mit ra and J .F . Kaiser , ed. Chapter 7. New York:J ohn Wiley & Sons, 1993.

cplxpair Group complex numbers into complex conjuga tepa ir s.

sos2ss Conversion of second-order sect ions to sta t e-space.ss2tf Conversion of sta te-space to t ransfer funct ion .ss2zp Conversion of sta te-space to zero-pole-ga in .tf2sos Conversion of t ransfer funct ion to second-order

sect ions.zp2sos Conversion of zero-pole-ga in to second-order sect ions.

Page 641: MATLAB Signal Processing Toolbox user manual

ss2tf

6-337

6ss2t fPurpose Conversion of sta t e-space to t ransfer funct ion .

Syntax [b,a] = ss2tf(A,B,C,D,iu)

Description ss2tf conver ts a sta te-space represen ta t ion of a given system to an equ iva len tt ransfer funct ion represen ta t ion .

[b,a] = ss2tf(A,B,C,D,iu) retu rns the t ransfer funct ion

of the system

from the iu-th inpu t . Vector a conta ins the coefficien ts of the denomina tor indescending powers of s. The numera tor coefficien t s are retu rned in ar ray bwithas many rows as there are ou tpu ts y. ss2tf a lso works with systems in discretet ime, in which case it retu rns the z-t ransform represen ta t ion .

The ss2tf funct ion is pa r t of the st andard MATLAB language.

Algorithm The ss2tf funct ion uses poly to find the character ist ic polynomia l det (sI-A)and the equality

See Also

H s( ) B s( )A s( )----------- C sI A–( ) 1– B D+= =

x· Ax B u+=y Cx Du+=

H s( ) C sI A–( ) 1– B det s I A– BC+( ) det s I A–( )–det s I A–( )------------------------------------------------------------------------------= =

latc2tf Lat t ice filter to t ransfer funct ion conversion .sos2tf Conversion of second-order sect ions to t ransfer

funct ion .ss2sos Conversion of sta t e-space to second-order sect ions.ss2zp Conversion of sta t e-space to zero-pole-ga in .tf2ss Conversion of t ransfer funct ion to st a t e-space.zp2tf Conversion of zero-pole-ga in to t ransfer funct ion .

Page 642: MATLAB Signal Processing Toolbox user manual

ss2zp

6-338

6ss2zpPurpose Conversion of sta t e-space to zero-pole-ga in .

Syntax [z,p,k] = ss2zp(A,B,C,D,iu)

Description ss2zp conver t s a sta te-space represen ta t ion of a given system to an equ iva len tzero-pole-ga in representa t ion . The zeros, poles, and gains of sta te-spacesystems represen t the t ransfer funct ion in factored form.

[z,p,k] = ss2zp(A,B,C,D,iu) ca lcu la t es the t ransfer funct ion in factoredform

of the system

from the iu-th inpu t . Returned column vector p conta ins the pole loca t ions ofthe denomina tor coefficien ts of the t ransfer funct ion . Matr ix z conta ins thenumera tor zeros in it s columns, with as many columns as there a re outpu ts y.Column vector k conta ins the ga ins for each numera tor t ransfer funct ion .

ss2zp a lso works with systems in discrete t ime, in which case it returns thez-t r ansform represen ta t ion . The inpu t sta te-space system must be rea l.

The ss2zp funct ion is par t of the standard MATLAB language.

H s( ) Z s( )P s( )---------- k

s z1–( ) s z2–( )Ls zn–( )

s p1–( ) s p2–( )Ls pn–( )---------------------------------------------------------------= =

x· Ax B u+=y Cx Du+=

Page 643: MATLAB Signal Processing Toolbox user manual

ss2zp

6-339

Example Here are two ways of finding the zeros, poles, and ga ins of a system:

b = [2 3]; a = [1 0.4 1];[z,p,k] = tf2zp(b,a)

z =–1.5000

p =–0.2000 + 0.9798i–0.2000 – 0.9798i

k =2

[A,B,C,D] = tf2ss(b,a);[z,p,k] = ss2zp(A,B,C,D,1)

z =–1.5000

p =–0.2000 + 0.9798i–0.2000 – 0.9798i

k =2

Algorithm ss2zp finds the poles from the eigenva lues of the A a r ray. The zeros a re thefin it e solu t ions to a genera lized eigenva lue problem:

z = eig([A B;C D], diag([ones(1,n) 0]);

In many situa t ions th is a lgor ithm produces spur ious la rge, bu t fin ite, zeros.ss2zp in terpret s these la rge zeros as infin ite.

ss2zp finds the ga ins by solving for the fir st nonzero Markov parameters.

Page 644: MATLAB Signal Processing Toolbox user manual

ss2zp

6-340

See Also

References [1] Laub, A.J ., and B.C. Moore. “Calcu la t ion of Transmission Zeros Using QZTechniques.” Autom atica 14 (1978). Pg. 557.

pzmap Pole-zero map of LTI system (Control S ystem ToolboxUser’s Guide).

sos2zp Conversion of second-order sect ions to zero-pole-ga in .ss2sos Conversion of sta te-space to second-order sect ions.ss2tf Conversion of sta te-space to t ransfer funct ion .tf2zp Conversion of t ransfer funct ion to zero-pole-ga in .zp2ss Conversion of zero-pole-ga in to sta t e-space.

Page 645: MATLAB Signal Processing Toolbox user manual

stmcb

6-341

6stmcbPurpose Linea r model using Steiglitz-McBr ide itera t ion .

Syntax [b,a] = stmcb(x,nb,na)[b,a] = stmcb(x,u,nb,na)[b,a] = stmcb(x,nb,na,niter)[b,a] = stmcb(x,u,nb,na,niter)[b,a] = stmcb(x,nb,na,niter,ai)[b,a] = stmcb(x,u,nb,na,niter,ai)

Description Steiglitz-McBride itera t ion is an a lgor ithm for finding an IIR filt er with aprescr ibed t ime domain impulse response. It has applica t ions in both filt erdesign and system ident ifica t ion (paramet r ic modeling).

[b,a] = stmcb(x,nb,na) finds the coefficien ts b and a of the syst em b(z)/ a(z)with approximate impulse response x, exact ly nb zeros, and exact ly na poles.

[b,a] = stmcb(x,u,nb,na) finds the system coefficien ts b and a of the systemtha t , given u as input , has x as output . x and u must be the same length.

[b,a] = stmcb(x,nb,na,niter) and

[b,a] = stmcb(x,u,nb,na,niter) use niter itera t ions. The defau lt for niteris 5.

[b,a] = stmcb(x,nb,na,niter,ai) and

[b,a] = stmcb(x,u,nb,na,niter,ai) use the vector ai as the in it ia l est imateof the denominator coefficien ts. If ai is not specified, stmcb uses the outpu ta rgument from [b,ai] = prony(x,0,na) as the vector ai.

stmcb returns the IIR filt er coefficien t s in length nb+1 and na+1 row vectors band a. The filter coefficien ts are ordered in descending powers of z:

H z( ) B z( )A z( )----------- b 1( ) b 2( )z 1– L b n b 1+( )z n b–+ + +

a 1( ) a 2( )z 1– L a n a 1+( )z n a–+ + +-----------------------------------------------------------------------------------------= =

Page 646: MATLAB Signal Processing Toolbox user manual

stmcb

6-342

Example Approximate the impulse response of a But terwor th filt er with a syst em oflower order :

[b,a] = butter(6,0.2);h = filter(b,a,[1 zeros(1,100)]);freqz(b,a,128)

[bb,aa] = stmcb(h,4,4);freqz(bb,aa,128)

0 0.2 0.4 0.6 0.8 1−600

−400

−200

0

Normalized Angular Frequency (×π rads/sample)

Phas

e (d

egre

es)

0 0.2 0.4 0.6 0.8 1−300

−200

−100

0

Normalized Angular Frequency (×π rads/sample)

Mag

nitu

de (d

B)

0 0.2 0.4 0.6 0.8 1−800

−600

−400

−200

0

Normalized Angular Frequency (×π rads/sample)

Phas

e (d

egre

es)

0 0.2 0.4 0.6 0.8 1−60

−40

−20

0

20

Normalized Angular Frequency (×π rads/sample)

Mag

nitu

de (d

B)

Page 647: MATLAB Signal Processing Toolbox user manual

stmcb

6-343

Algorithm stmcb a t t empts to min imize the squared er ror between the impulse response x'of b(z)/ a(z) and the input signa l x:

stmcb it era t es using two steps:

1 It prefilt er s x and u using 1/a(z).2 It solves a system of linea r equa t ions for b and a using \ .

stmcb repea t s this process niter t imes. No checking is done to see if the b anda coefficien ts have converged in fewer than niter it era t ions.

Diagnostics If x and u have differen t lengths, stmcb gives the following er ror message:

X and U must have same length.

See Also

References [1] Steiglit z, K., and L.E. McBride. “A Technique for the Ident ifica t ion of LinearSystems.” IEEE Trans. Autom atic Control. Vol. AC-10 (1965). Pgs. 461-464.

[2] Ljung, L. S ystem Iden tification: Theory for the User. Englewood Cliffs, NJ :Prent ice Hall, 1987. Pg. 297.

mina b,

x i( ) x ' i( )– 2

i 0=

levinson Levinson-Durbin recursion .lpc Linea r predict ion coefficient s.aryule Compute an est imate of AR model parameters using

the Yule-Walker method.prony Prony’s method for t ime domain IIR filter design .

Page 648: MATLAB Signal Processing Toolbox user manual

strips

6-344

6st r ipsPurpose Str ip plot .

Syntax strips(x)strips(x,n)strips(x,sd,Fs)strips(x,sd,Fs,scale)

Description strips(x) plots vector x in hor izon ta l st r ips of length 250. If x is a mat r ix,strips(x) plots each column of x. The left -most column (column 1) is the tophor izon ta l st r ip.

strips(x,n) plots vector x in st r ips tha t a re each n samples long.

strips(x,sd,Fs) plots vector x in st r ips of dura t ion sd seconds, given asampling frequency of Fs samples per second.

strips(x,sd,Fs,scale) sca les the ver t ica l axes.

If x is a matr ix, strips(x,n), strips(x,sd,Fs), and strips(x,sd,Fs,scale)plot the differen t columns of x on the same st r ip plot .

strips ignores the imagina ry pa r t of x if it is complex.

Page 649: MATLAB Signal Processing Toolbox user manual

strips

6-345

Example Plot two seconds of a frequency modula t ed sinusoid in 0.25 second st r ips:

Fs = 1000; % sampling frequencyt = 0:1/Fs:2; % time vectorx = vco(sin(2*pi*t),[10 490],Fs); % FM waveformstrips(x,0.25,Fs)

See Also

0 0.05 0.1 0.15 0.2 0.25

1.75

1.5

1.25

1

0.75

0.5

0.25

0

plot Linea r two-dimensiona l plot (see the online MATLABFunction Reference).

stem Plot discrete sequence data (see the on line MATLABFunction Reference).

Page 650: MATLAB Signal Processing Toolbox user manual

tf2latc

6-346

6t f2la tcPurpose Conversion of t ransfer funct ion to la t t ice filt er .

Syntax [k,v] = tf2latc(b,a)k = tf2latc(1,a)[k,v] = tf2latc(1,a)k = tf2latc(b)

Description [k,v] = tf2latc(b,a) finds the la t t ice pa rameters k and the ladderparameters v for an IIR (ARMA) la t t ice-ladder filt er , norma lized by a(1). Notetha t an er ror is genera t ed if one or more of the la t t ice parameters a re exact lyequal to 1.

k = tf2latc(1,a) finds the la t t ice pa rameters k for an IIR a ll-pole (AR) la t t icefilt er .

[k,v] = tf2latc(1,a) retu rns the sca la r ladder coefficien t a t the cor rectposit ion in vector v. All other elements of v a re zero.

k = tf2latc(b) finds the la t t ice parameters k for an FIR (MA) la t t ice filter ,normalized by b(1).

See Also latc2tf Lat t ice filt er to t ransfer funct ion conversion .latcfilt Lat t ice and la t t ice-ladder filt er implementa t ion .tf2sos Conversion of t ransfer funct ion to second-order

sect ions.tf2ss Conversion of t ransfer funct ion to sta t e-space.tf2zp Conversion of t ransfer funct ion to zero-pole-ga in .

Page 651: MATLAB Signal Processing Toolbox user manual

tf2sos

6-347

6tf2sosPurpose Conversion of t ransfer funct ion to second-order sect ions.

Syntax [sos,g] = tf2sos(b,a)[sos,g] = tf2sos(b,a,'order')[sos,g] = tf2sos(b,a,'order','scale')sos = tf2sos(...)

Description tf2sos conver t s a t ransfer funct ion represen ta t ion of a given system to anequiva len t second-order sect ion representa t ion .

[sos,g] = tf2sos(b,a) finds a matr ix sos in second-order sect ion form withgain g tha t is equ iva len t to the syst em represen ted by t ransfer funct ioncoefficien t vectors a and b.

sos is an L -by-6 ma tr ix

whose rows conta in the numera tor and denomina tor coefficien ts bik and a ik ofthe second-order sect ions of H (z):

[sos,g] = tf2sos(b,a,'order') specifies the order of the rows in sos, whereorder is:

H z( ) B z( )A z( )-----------

b1 b2z 1– L bn b 1+ z n b–+ + +a1 a2z 1– L an a 1+ z n a–+ + +-------------------------------------------------------------------------= =

sos

b01 b11 b21 1 a11 a21b02 b12 b22 1 a12 a22M M M M M M

b0L b1L b2L 1 a1L a2L

=

H z( ) g H k z( )k 1=

L

∏ gb0 k b1 k z 1– b2 k z 2–+ +1 a1 k z 1– a2 k z 2–+ +----------------------------------------------------------

k 1=

L

∏= =

Page 652: MATLAB Signal Processing Toolbox user manual

tf2sos

6-348

• down, t o order the sect ions so the fir st row of sos conta ins the poles closest tothe unit circle

• up, to order the sect ions so the fir st row of sos conta ins the poles fa r thestfrom the un it circle (defau lt )

[sos,g] = tf2sos(b,a,'order','scale') specifies the desired sca ling of thega in and numera tor coefficien t s of a ll second-order sect ions, where scale is:

• none, t o apply no sca ling (default )• inf, t o apply infinity-norm sca ling• two, t o apply 2-norm sca ling

Using infin ity-norm sca ling in conjunct ion with up-order ing minimizes theprobabilit y of over flow in the rea liza t ion . Using 2-norm sca ling in conjunct ionwith down-order ing minimizes the peak round-off noise.

sos = tf2sos(...) embeds the overa ll system gain , g, in the fir st sect ion ,H 1(z), so tha t

See Also

H z( ) Hk z( )k 1=

L

∏=

cplxpair Group complex numbers into complex conjuga tepa ir s.

sos2tf Conversion of second-order sect ions to t ransferfunct ion .

ss2sos Conversion of sta te-space to second-order sect ions.tf2ss Conversion of t ransfer funct ion to sta t e-space.tf2zp Conversion of t ransfer funct ion to zero-pole-ga in .zp2sos Conversion of zero-pole-ga in to second-order sect ions.

Page 653: MATLAB Signal Processing Toolbox user manual

tf2sos

6-349

References [1] J ackson , L.B. Digital Filters and S ignal Processing . 3rd ed. Boston : KluwerAcademic Publishers, 1996. Chapter 11.

[2] Mit ra , S.K. Digital S ignal Processing: A Com puter-Based Approach . NewYork: McGraw-Hill, 1998. Chapter 9.

[3] Vaidyana than , P .P . “Robust Digita l Filter St ructures.” Handbook forDigital S ignal Processing. S.K. Mit ra and J .F . Kaiser , ed. Chapter 7. New York:J ohn Wiley & Sons, 1993.

Page 654: MATLAB Signal Processing Toolbox user manual

tf2ss

6-350

6t f2ssPurpose Conversion of t ransfer funct ion to st a t e-space.

Syntax [A,B,C,D] = tf2ss(b,a)

Description tf2ss conver t s a t ransfer funct ion represen ta t ion of a given syst em to anequiva len t st a te-space represen ta t ion .

[A,B,C,D] = tf2ss(b,a) finds a st a t e-space representa t ion:

given a system in t ransfer funct ion form:

from a single input . Inpu t vector a conta ins the denomina tor coefficien ts indescending powers of s. Matr ix b conta ins the numera tor coefficient s with asmany rows as there a re outpu ts y. tf2ss retu rns the A, B, C, and D matr ices incont roller canonica l form.

tf2ss a lso works for discrete systems, bu t you must pad the numera tor witht ra iling zeros to make it the same length as the denomina tor .

The tf2ss funct ion is par t of the standard MATLAB language.

Example Consider the system

x· Ax B u+=y Cx Du+=

H s( ) B s( )A s( )----------- C sI A–( ) 1– B D+= =

H s( )

2 s 3+s2 2s 1+ +s2 0.4s 1+ +---------------------------------=

Page 655: MATLAB Signal Processing Toolbox user manual

tf2ss

6-351

To conver t th is system to sta te-space:

b = [0 2 3; 1 2 1];a = [1 0.4 1];[A,B,C,D] = tf2ss(b,a)

A = –0.4000 –1.0000 1.0000 0

B = 1 0

C = 2.0000 3.0000 1.6000 0

D = 0 1

There is disagreement in the litera tu re on naming conven t ions for thecanonica l forms. It is easy, however , to genera te simila r ity t ransformat ionstha t conver t to other forms. For example:

T = fliplr(eye(n));A = T\A*T;

Algorithm tf2ss writes the outpu t in cont roller canonica l form by inspect ion.

See Also sos2ss Conversion of second-order sect ions to sta t e-space.ss2tf Conversion of sta t e-space to t ransfer funct ion .tf2sos Conversion of t ransfer funct ion to second-order

sect ions.tf2zp Conversion of t ransfer funct ion to zero-pole-ga in .zp2ss Conversion of zero-pole-ga in to st a t e-space.

Page 656: MATLAB Signal Processing Toolbox user manual

tf2zp

6-352

6t f2zpPurpose Conversion of t ransfer funct ion to zero-pole-ga in .

Syntax [z,p,k] = tf2zp(b,a)

Description tf2zp finds the zeros, poles, and gains of a system in polynomia l t ransferfunct ion form.

[z,p,k] = tf2zp(b,a) finds the single-input , mult i-ou tpu t (SIMO) factoredt ransfer funct ion form:

given a SIMO system in polynomia l t ransfer funct ion form:

Vector a specifies the coefficien ts of the denominator in descending powers ofs. Matr ix b indica tes the numera tor coefficien ts with as many rows as there areoutpu ts. The zero loca t ions are returned in the columns of matr ix z, with asmany columns as there are rows in b. The pole loca t ions are returned in columnvector p and the ga ins for each numera tor t ransfer funct ion in vector k.

The tf2zp funct ion a lso works for discrete systems, and is par t of the standardMATLAB language.

H s( ) Z s( )P s( )---------- k

s Z 1–( ) s Z 2–( )Ls Zm–( )

s p1–( ) s p2–( )Ls pn–( )------------------------------------------------------------------= =

B s( )A s( )-----------

b1s n b 1–( ) L b n b 1–( )s b n b( )+ + +a1s n a 1–( ) L a n a 1–( )s a n a( )+ + +---------------------------------------------------------------------------------------=

Page 657: MATLAB Signal Processing Toolbox user manual

tf2zp

6-353

Example Find the zeros, poles, and gains of the system

b = [2 3];a = [1 0.4 1];[z,p,k] = tf2zp(b,a)

z =

–1.5000

p =

–0.2000 + 0.9798i –0.2000 – 0.9798i

k =

2

Algorithm The system is conver t ed to sta te-space using tf2ss and then to zeros, poles,and ga ins using ss2zp.

See Also

H s( ) 2 s 3+s2 0.4s 1+ +---------------------------------=

sos2zp Conversion of second-order sect ions to zero-pole-ga in .ss2zp Conversion of sta t e-space to zero-pole-ga in .tf2sos Conversion of t ransfer funct ion to second-order

sect ions.tf2ss Conversion of t ransfer funct ion to st a t e-space.zp2tf Conversion of zero-pole-ga in to t ransfer funct ion .

Page 658: MATLAB Signal Processing Toolbox user manual

tfe

6-354

6t fePurpose Transfer funct ion est imate from inpu t and ou tpu t .

Syntax Txy = tfe(x,y)Txy = tfe(x,y,nfft)[Txy,f] = tfe(x,y,nfft,Fs)Txy = tfe(x,y,nfft,Fs,window)Txy = tfe(x,y,nfft,Fs,window,noverlap)Txy = tfe(x,y,...,'dflag')tfe(x,y)

Description Txy = tfe(x,y) finds a t ransfer funct ion est imate Txy given inpu t signa lvector x and outpu t signa l vector y. The transfer function is the quot ien t of thecross spect rum of x and y and the power spect rum of x:

The rela t ionsh ip between the input x and output y is modeled by the linea r ,t ime-invar ian t t ransfer funct ion Txy.

Vectors x and y must be the same length . Txy = tfe(x,y) uses the followingdefau lt va lues:

• nfft = min(256,(length(x)) • Fs = 2 • window = hanning(nfft) • noverlap = 0

nfft specifies the FFT length tha t tfe uses. This va lue determines thefrequencies a t which the power spect rum is est imated. Fs is a sca la r tha tspecifies the sampling frequency. window specifies a windowing funct ion andthe number of samples tfe uses in it s sect ion ing of the x and y vectors.noverlap is the number of samples by which the sect ions over lap. Anyarguments tha t a re omit ted from the end of the parameter list use the defau ltva lues shown above.

If x is rea l, tfe est imates the t ransfer funct ion a t posit ive frequencies only; inthis case, the outpu t Txy is a column vector of length nfft/2+1 for nfft evenand (nfft+1)/2 for nfft odd. If x or y is complex, tfe est imates the t ransferfunct ion for both posit ive and nega t ive frequencies and Txy has length nfft.

T xy f( )Pxy f( )Pxx f( )---------------=

Page 659: MATLAB Signal Processing Toolbox user manual

tfe

6-355

Txy = tfe(x,y,nfft) uses the specified FFT length nfft in est imat ing thet ransfer funct ion . Specify nfft as a power of 2 for fastest execu t ion .

[Txy,f] = tfe(x,y,nfft,Fs) retu rns a vector f of frequencies a t which tfeest ima tes the t ransfer funct ion . Fs is the sampling frequency. f is the same sizeas Txy, so plot(f,Txy) plot s the t ransfer funct ion est imate versus proper lysca led frequency. Fs has no effect on the ou tput Txy; it is a frequency sca lingmult iplier .

Txy = tfe(x,y,nfft,Fs,window) specifies a windowing funct ion and thenumber of samples per sect ion of the x vector . If you supply a sca lar for window,Txy uses a Hanning window of tha t length . The length of the window must beless than or equal to nfft; tfe zero pads the sect ions if the length of the windowexceeds nfft.

Txy = tfe(x,y,nfft,Fs,window,noverlap) over laps the sect ions of x bynoverlap samples.

You can use the empty mat r ix [] to specify the defau lt va lue for any inputa rgument except x or y. For example,

Txy = tfe(x,y,[],[],kaiser(128,5))

uses 256 as the value for nfft and 2 as the va lue for Fs.

Txy = tfe(x,y,...,'dflag') specifies a det rend opt ion , where dflag is:

• linear, to remove the best st r a igh t -line fit from the prewindowed sect ions ofx and y

• mean, to remove the mean from the prewindowed sect ions of x and y• none, for no det rending (defau lt )

The dflag parameter must appear la st in the list of input a rgument s. tferecognizes a dflag st r ing no mat ter how many in termedia te a rguments areomit t ed.

tfe(...) with no output argument s plot s the magnitude of the t ransferfunct ion est imate in decibels versus frequency in the cur ren t figure window.

Page 660: MATLAB Signal Processing Toolbox user manual

tfe

6-356

Example Compute and plot the t ransfer funct ion est ima te between two colored noisesequences x and y:

h = fir1(30,0.2,boxcar(31));x = randn(16384,1);y = filter(h,1,x);tfe(x,y,1024,[],[],512)title('Transfer Function Estimate')

Algorithm tfe uses a four -st ep a lgor ithm:

1 It mult iplies the det rended sect ions by window.2 It takes the length nfft FFT of each sect ion .3 It averages the squares of the spect ra of the x sect ions to form Pxx andaverages the products of the spect ra of the x and y sect ions to form Pxy.

4 It ca lcu la tes 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

Tran

fer F

unct

ion

Estim

ate

(dB)

Transfer Function Estimate

Page 661: MATLAB Signal Processing Toolbox user manual

tfe

6-357

Diagnostics An appropr ia te diagnost ic message is displayed when incorrect a rguments a reused:

Requires window's length to be no greater than the FFT length.Requires NOVERLAP to be strictly less than the window length.Requires positive integer values for NFFT and NOVERLAP.Requires vector (either row or column) input.Requires inputs X and Y to have the same length.

See Also etfe Compute empir ica l t ransfer funct ion est imate andper iodogram (see S ystem Iden tification ToolboxUser’s Guide).

cohere Est imate magnitude squared coherence funct ionbetween two signals.

csd Est imate the cross spect ra l density (CSD) of twosignals.

pwelch Est imate the power spect ra l density (PSD) of a signa lusing Welch’s method.

spa Per form spect ra l ana lysis for inpu t -ou tpu t da ta (seeS ystem Identification Toolbox User’s Guide).

Page 662: MATLAB Signal Processing Toolbox user manual

triang

6-358

6t riangPurpose Tr iangular window.

Syntax w = triang(n)

Description triang(n) retu rns an n-poin t t r iangula r window in the column vector w. Thecoefficien t s of a t r iangular window are

For n odd:

For n even :

The t r iangular window is very simila r to a Bar t let t window. The Bar t let twindow always ends with zeros a t samples 1 and n, while the t r iangula rwindow is nonzero a t those poin t s. For n odd, the cen ter n–2 poin t s oftriang(n–2) a re equiva len t to bartlett(n).

See Also

References [1] Oppenheim, A.V., and R.W. Schafer , Discrete-T im e S ignal Processing.Englewood Cliffs, NJ : Prent ice-Hall, 1989.

w k[ ]

2kn 1+------------- 1 k n 1+

2-------------≤ ≤,

2 n k 1+–( )n 1+------------------------------- n 1+

2------------- k n≤ ≤,⎩⎪⎨⎪⎧

=

w k[ ]

2k 1–n---------------- 1 k n

2---≤ ≤,

2 n k 1+–( )n------------------------------- n

2--- 1+ k n≤ ≤,⎩⎪⎨⎪⎧

=

bartlett Bar t let t window.blackman Blackman window.boxcar Rectangula r window.chebwin Chebyshev window.hamming Hamming window.hanning Hanning window.kaiser Kaiser window.

Page 663: MATLAB Signal Processing Toolbox user manual

tripuls

6-359

6tr ipulsPurpose Sampled aper iodic t r iangle genera tor .

Syntax y = tripuls(T)y = tripuls(T,w)y = tripuls(T,w,s)

Description y = tripuls(T) retu rns a cont inuous, aper iodic, symmet r ic, un ity-heigh tt r iangula r pu lse a t the t imes indica ted in ar ray T, cen tered about T=0 and witha default width of 1.

y = tripuls(T,w) genera t es a t r iangula r pu lse of width w.

y = tripuls(T,w,s) genera tes a t r iangular pu lse with skew s, where –1<s<1.When s is 0, a symmetr ic t r iangular pu lse is genera ted.

See Also chirp Swept-frequency cosine genera tor.cos Cosine of vector /mat r ix element s (see the online

MATLAB Function Reference).diric Dir ich let or per iodic sinc funct ion .gauspuls Gaussian-modula t ed sinusoida l pu lse genera tor.pulstran Pulse t ra in genera tor.rectpuls Sampled aper iodic rectangle genera tor.sawtooth Sawtooth or t r iangle wave genera tor.sin Sine of vector /matr ix elements (see the online

MATLAB Function Reference).sinc Sinc or sin (πt )/πt funct ion .square Square wave genera tor.

Page 664: MATLAB Signal Processing Toolbox user manual

unwrap

6-360

6unwrapPurpose Unwrap phase angles.

Syntax p = unwrap(p)

Description p = unwrap(p) cor rect s the phase angles in vector p by adding mult iples of, where needed, to smooth the t ransit ions across branch cu ts. When p is a

ma tr ix, unwrap cor rects the phase angles down each column. The phase mustbe in radians.

The unwrap funct ion is par t of the standard MATLAB language.

Limitations unwrap t r ies to detect branch cut crossings, bu t it can be fooled by sparse,rapidly changing phase va lues.

See Also

2π±

abs Absolu te va lue (magnitude).angle Phase angle.

Page 665: MATLAB Signal Processing Toolbox user manual

upfirdn

6-361

6upfirdnPurpose Upsample, apply an FIR filter , and downsample.

Syntax yout = upfirdn(xin,h)yout = upfirdn(xin,h,p)yout = upfirdn(xin,h,p,q)

Description upfirdn per forms a cascade of three opera t ions:

1 Upsampling by p (zero inser t ing)2 FIR filt er ing with the impulse response given in h

3 Downsampling by q (th rowing away samples)

upfirdn has been implemented as a MEX-file for maximum speed, so only theoutputs actua lly needed are computed. The FIR filt er is usua lly a lowpassfilt er , which you must design using another funct ion such as remez or fir1.

NOTE The funct ion resample per forms an FIR design using firls, followedby ra t e changing implemented with upfirdn.

yout = upfirdn(xin,h) retu rns the outpu t signa l yout. If yout is a row orcolumn vector , then it represent s one signa l; if yout is an ar ray, then eachcolumn is a sepa ra te outpu t . xin is the input signa l. If xin is a row or columnvector , then it represen ts one signa l; if xin is an a r ray, then each column isfilt ered. h is the impulse response of the FIR filt er . If h is a row or columnvector , then it represen ts one filt er ; if h is an a r ray, then each column is asepara te impulse response.

yout = upfirdn(xin,h,p) specifies the upsampling factor p. p is an in tegerwith a default of 1.

yout = upfirdn(xin,h,p,q) specifies the downsampling factor q. q is anin t eger with a defau lt of 1.

Page 666: MATLAB Signal Processing Toolbox user manual

upfirdn

6-362

NOTE Since upfirdn per forms convolu t ion and ra t e changing, the youtsigna ls have a differen t length than xin. The length of y[n ] is approximatelyp/q t imes the length of x[n ].

Remarks Usually the inputs xin and the filt er h are vectors, in which case only oneoutpu t signa l is produced. However , when these arguments are a r rays, eachcolumn is t rea t ed as a separa t e signa l or filter . Va lid combina t ions a re

1 xin is a vector and h is a vector .There is one filt er and one signa l, so the funct ion convolves xin with h. Theoutpu t signal yout is a row vector if xin is a row; otherwise, it is a columnvector .

2 xin is an a r ray and h is a vector .There is one filter and many signa ls, so the funct ion convolves h with eachcolumn of xin. The resu lt ing yout will be an a r ray with the same number ofcolumns as xin.

3 xin is a vector and h is an ar ray.There are many filt er s and one signa l, so the funct ion convolves each columnof h with xin. The resu lt ing yout will be an ar ray with the same number ofcolumns as h.

4 xin is an a r ray and h is an a r ray, both with the same number of columns.There a re many filter s and many signa ls, so the funct ion convolvescor responding columns of xin and h. The resu lt ing yout is an ar ray with thesame number of columns as xin and h.

Examples If both p and q are equa l to 1 (tha t is, t here is no ra te changing), the resu lt isordinary convolu t ion of two signa ls (equ iva len t to conv):

yy = upfirdn(xx,hh);

This example implements a seven-channel filt er bank by convolving sevendifferen t filter s with one inpu t signa l, then downsamples by five:

% Assume that hh is an L-by-7 array of filters.yy = upfirdn(xx,hh,1,5);

Page 667: MATLAB Signal Processing Toolbox user manual

upfirdn

6-363

Implement a ra te change from 44.1 kHz (CD sampling ra t e) to 48 kHz (DATrate), a ra t io of 160/147. This requires a lowpass filter with cutoff frequency atωc = 2π/160:

% Design lowpass filter with cutoff at 1/160th of Fs.hh = fir1(300,2/160); % need a very long lowpass filteryy = upfirdn(xx,hh,160,147);

In th is example, the filt er design and resampling are separa te steps. Note tha tresample would do both steps as one.

Algorithm upfirdn uses a polyphase in terpola t ion st ructure. The number of mult iply-addopera t ions in the polyphase st ructure is approxima tely (LhLx-pLx)/q where Lhand Lx are the lengths of h [n ] and x[n ], respect ively.

A more accura t e flops count is computed in the program, bu t the actua l countis st ill approxima te. For long signa ls x[n ], the formula is quit e often exact .

Diagnostics There must be one outpu t a rgument and at lea st two input a rgument s. If eitherof these condit ions a re viola ted, upfirdn gives the appropr ia te er ror message:

UPFIRDN needs at least two input arguments.UPFIRDN should have exactly one output argument.

If the ar rays are spa rse, upfirdn gives the er ror message

H must be full numeric matrix.

When the input signa ls a re in the columns of a ma tr ix and there are mult iplefilt er s a lso in the columns of a matr ix, the number of signa ls and filt er s mustbe the same. If they are not , upfirdn gives the er ror message

X and H must have the same number of columns, if more than one.

The a rguments p and q must be in tegers. If they are not , upfirdn gives theer ror message

P and/or Q must be greater than zero

If the argument s p and q are not rela t ively pr ime, upfirdn gives the warn ingmessage

WARNING (upfirdn) p & q have common factor

Page 668: MATLAB Signal Processing Toolbox user manual

upfirdn

6-364

See Also

References [1] Crochiere, R.E ., and L.R. Rabiner . Multi-Rate S ignal Processing.Englewood Cliffs, NJ : Prent ice Hall, 1983. Pgs. 88-91.

[2] Crochiere, R.E . “A Genera l P rogram to Per form Sampling Ra te Conversionof Data by Rat iona l Ra t ios.” In Program s for Digital S ignal Processing. IEEEPress. New York: J ohn Wiley & Sons, 1979. Pgs. 8.2-1 to 8.2-7.

conv Convolut ion and polynomia l mult iplica t ion.decimate Decrease the sampling ra t e for a sequence

(decimat ion).filter Filt er da ta with a recursive (IIR) or nonrecursive

(FIR) filter.interp Increase sampling ra te by an integer factor

(in t erpola t ion).intfilt In terpola t ion FIR filt er design.resample Change sampling ra t e by any ra t iona l factor.

Page 669: MATLAB Signal Processing Toolbox user manual

vco

6-365

6vcoPurpose Voltage cont rolled oscilla tor .

Syntax y = vco(x,Fc,Fs)y = vco(x,[Fmin Fmax],Fs)

Description y = vco(x,Fc,Fs) crea t es a signa l tha t oscilla tes a t a frequency determinedby the rea l input vector or a r ray xwith sampling frequency Fs. Fc is the car r ieror reference frequency; when x is 0, y is an Fc Hz cosine with amplitude 1sampled a t Fs Hz. x r anges from -1 to 1, where -1 corresponds to a 0 frequencyoutpu t , 0 to Fc, and 1 to 2*Fc. y is the same size as x.

y = vco(x,[Fmin Fmax],Fs) sca les the frequency modula t ion range so tha t -1and 1 va lues of x yield oscilla t ions of Fmin Hz and Fmax Hz respect ively. Forbest resu lt s, Fmin and Fmax should be in the range 0 to Fs/2.

By default , Fs is 1 and Fc is Fs/4.

If x is a matr ix, vco produces a ma tr ix whose columns oscilla te according to thecolumns of x.

Example Genera te two seconds of a signa l sampled a t 10,000 samples/second whoseinstan taneous frequency is a t r iangle funct ion of t ime:

Fs = 10000;t = 0:1/Fs:2;x = vco(sawtooth(2*pi*t,0.75),[.1 0.4]*Fs,Fs);

Page 670: MATLAB Signal Processing Toolbox user manual

vco

6-366

Plot the spect rogram of the genera t ed signa l.

specgram(x,512,Fs,kaiser(256,5),220)

Algorithm vco per forms FM modula t ion using the modulate funct ion .

Diagnostics If any values of x lie ou t side [-1,1], vco gives the following er ror message:

X outside of range [–1,1].

See Also

Time

Freq

uenc

y

0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.80

500

1000

1500

2000

2500

3000

3500

4000

4500

5000

demod Demodula t ion for communica t ions simula t ion .modulate Modula t ion for communica t ions simula t ion .

Page 671: MATLAB Signal Processing Toolbox user manual

xcorr

6-367

6xcor rPurpose Cross-cor rela t ion funct ion est ima te.

Syntax c = xcorr(x,y)c = xcorr(x)c = xcorr(x,y,'option')c = xcorr(x,'option')c = xcorr(x,y,maxlags)c = xcorr(x,maxlags)c = xcorr(x,y,maxlags,'option')c = xcorr(x,maxlags,'option')[c,lags] = xcorr(...)

Description xcorr est ima tes the cross-cor rela t ion sequence of a random process.Autocor rela t ion is handled as a specia l case.

The t rue cross-cor rela t ion sequence is

where xn and yn are st a t ionary random processes, , and E {} is theexpected va lue opera tor . xcorr must est imate the sequence because, inpract ice, on ly a fin ite segment of the infin ite-length random process isava ilable.

c = xcorr(x,y) retu rns the cross-cor rela t ion sequence in a length 2N -1vector , where x and y a re length N vectors (N>1). If x and y are not the samelength , the shor ter vector is zero-padded to the length of the longer vector .

By default , xcorr computes raw cor rela t ions with no normaliza t ion :

The ou tpu t vector c has element s given by c(m ) = cxy(m -N ), m =1, ..., 2N -1.

In genera l, the cor rela t ion funct ion requ ires normaliza t ion to produce anaccura t e est imate (see below).

γxy m( ) E {xn y*n m+ }=

∞– n ∞< <

cxy m( )xn yn m+

*

n 0=

N m– 1–

∑ m 0≥

cyx* m–( ) m 0<⎩⎪⎪⎨⎪⎪⎧

=

Page 672: MATLAB Signal Processing Toolbox user manual

xcorr

6-368

c = xcorr(x) is the au tocor rela t ion sequence for the vector x. If x is an N -by-Pmatr ix, c is a mat r ix with 2N -1 rows whose P 2 columns conta in thecross-cor rela t ion sequences for a ll combina t ions of the columns of x.

c = xcorr(x,y,'option') specifies a normaliza t ion opt ion for thecross-cor rela t ion , where 'option' is:

• biased, for bia sed est imates of the cross-cor rela t ion funct ion

• unbiased, for unbia sed est imates of the cross-cor rela t ion funct ion

• coeff, t o normalize the sequence so the au tocor rela t ions a t zero lag areident ica lly 1.0

• none, t o use the raw, unsca led cross-cor rela t ions (defau lt )

See reference [1] for more informat ion on the proper t ies of biased and unbiasedcor rela t ion est imates.

c = xcorr(x,'option') specifies one of the above normaliza t ion opt ions forthe autocorrela t ion.

c = xcorr(x,y,maxlags) retu rns the cross-cor rela t ion sequence over the lagrange [–maxlags:maxlags]. Outpu t c has length 2*maxlags+1.

c = xcorr(x,maxlags) retu rns the au tocor rela t ion sequence over the lagrange [–maxlags:maxlags]. Outpu t c has length 2*maxlags+1. If x is anN -by-P mat r ix, c is a ma tr ix with 2*maxlags+1 rows whose P2 columns conta inthe autocor rela t ion sequences for a ll combina t ions of the columns of x.

c = xcorr(x,y,maxlags,'option') specifies both a maximum number of lagsand a sca ling opt ion for the cross-cor rela t ion .

c = xcorr(x,maxlags,'option') specifies both a maximum number of lagsand a sca ling opt ion for the autocorrela t ion.

cxy biased, m( ) 1N----cx y m( )=

cxy unbiased, m( ) 1N m–-------------------cxy m( )=

Page 673: MATLAB Signal Processing Toolbox user manual

xcorr

6-369

[c,lags] = xcorr(...) retu rns a vector of the lag indices a t which c wasest imated, with the range [–maxlags:maxlags]. When maxlags is notspecified, the range of lags is [–N+1:N–1].

In a ll cases, the cross-cor rela t ion or au tocor rela t ion computed by xcorr has the0-th lag in the middle of the sequence, a t element or row maxlags+1 (elementor row N if maxlags is not specified).

Examples The second outpu t , lags, is usefu l for plot t ing the cross-cor rela t ion orau tocor rela t ion . For example, the est imated autocor rela t ion of zero-meanGaussian white noise cww(m ) can be displayed for -10 ≤ m ≤ 10 using

ww = randn(1000,1);[c_ww,lags] = xcorr(ww,10,'coeff');stem(lags,c_ww)

Swapping the x and y inpu t a rguments reverses (and conjuga tes) the ou tpu tcor rela t ion sequence. For row vectors, t he resu lt ing sequences are reversed leftto r igh t ; for column vectors, up and down. The following example illust ra testh is proper ty (mat2str is used for a compact display of complex numbers).

x = [1,2i,3]; y = [4,5,6];[c1,lags] = xcorr(x,y);c1 = mat2str(c1,2), lags

c1 =

[12–i*8.9e–016 15–i*8 22–i*10 5–i*12 6+i*8.9e–016]

lags =

–2 –1 0 1 2

c2 = conj(fliplr(xcorr(y,x)));c2 = mat2str(c2,2)

c2 =

[12–i*8.9e–016 15–i*8 22–i*10 5–i*12 6+i*8.9e–016]

For the case where inpu t a rgument x is a ma tr ix, the outpu t columns arear ranged so tha t ext ract ing a row and rear ranging it in to a square a r ray

Page 674: MATLAB Signal Processing Toolbox user manual

xcorr

6-370

produces the cross-cor rela t ion ma t r ix cor responding to the lag of the chosenrow. For example, the cross-cor rela t ion a t zero lag can be ret r ieved by

randn('seed',0)X = randn(2,2);[M,P] = size(X);c = xcorr(X);c0 = zeros(P); c0(:) = c(M,:) % Extract zero-lag row

c0 =

1.7500 0.3079 0.3079 0.1293

You can ca lcu la te the mat r ix of cor rela t ion coefficien t s tha t the MATLABfunct ion corrcoef genera tes by subst itu t ing

c = xcov(X,'coef')

in the last example. The funct ion xcov subt ract s the mean and then ca llsxcorr.

Use fftshift t o move the second ha lf of the sequence st a r t ing a t the zeroth lagto the fron t of the sequence. fftshift swaps the fir st and second ha lves of asequence.

Algorithm For more informat ion on est imat ing covar iance and cor rela t ion funct ions, see[1] and [2].

Diagnostics There must be a t least one vector inpu t a rgument ; otherwise, xcorr gives thefollowing er ror message:

1st arg must be a vector or matrix.

The st r ing 'option' must be the last a rgument ; otherwise, xcorr gives thefollowing er ror message:

Argument list not in correct order.

If the second argument was en tered as a sca la r , it is taken to be maxlags andno succeeding input can be a sca la r . When the second argument is a vector , thefir st must a lso be a signa l vector . The th ird argument , when presen t , must be

Page 675: MATLAB Signal Processing Toolbox user manual

xcorr

6-371

a sca lar or a st r ing. If they are not , xcorr gives the appropr ia te er rormessage(s):

3rd arg is maxlag, 2nd arg cannot be scalar.When b is a vector, a must be a vector.Maxlag must be a scalar.

Normally the lengths of the vector inputs should be the same; if they are not ,then the only a llowable sca ling opt ion is 'none'. If it is not , xcorr gives thefollowing er ror message:

OPTION must be 'none' for different length vectors A and B.

See Also

References [1] Benda t , J .S., and A.G. P iersol. Random Data: Analysis and Measurem entProcedures. New York: J ohn Wiley & Sons, 1971. Pg. 332.

[2] Oppenheim, A.V., and R.W. Schafer . Digital S ignal Processing. EnglewoodCliffs, NJ : Pren t ice Ha ll, 1975. Pgs. 63-67, 746-747, 839-842.

conv Convolu t ion and polynomia l mult iplica t ion .corrcoef Correla t ion coefficien t mat r ix.cov Covar iance ma t r ix.xcorr2 Two-dimensiona l cross-cor rela t ion .xcov Cross-covar iance funct ion est ima te (equa l to

mean-removed cross-correla t ion).

Page 676: MATLAB Signal Processing Toolbox user manual

xcorr2

6-372

6xcor r2Purpose Two-dimensiona l cross-cor rela t ion .

Syntax C = xcorr2(A)C = xcorr2(A,B)

Description C = xcorr2(A,B) retu rns the cross-cor rela t ion of mat r ices A and B with nosca ling. xcorr2 is the two-dimensiona l version of xcorr. It has it s maximumvalue when the two matr ices are a ligned so tha t they a re shaped as sim ila r lyas possible.

xcorr2(A) is the autocorrela t ion ma tr ix of input mat r ix A. It is ident ica l toxcorr2(A,A).

See Also conv2 Two-dimensiona l convolu t ion .filter2 Two-dimensiona l digita l filt er ing.xcorr Cross-correla t ion funct ion est imate.

Page 677: MATLAB Signal Processing Toolbox user manual

xcov

6-373

6xcovPurpose Cross-covar iance funct ion est imate (equa l to mean-removed cross-cor rela t ion).

Syntax v = xcov(x,y)v = xcov(x)v = xcov(x,'option')[c,lags] = xcov(x,y,maxlags)[c,lags] = xcov(x,maxlags)[c,lags] = xcov(x,y,maxlags,'option')

Description xcov est ima tes the cross-cova r iance sequence of random processes.Autocova r iance is handled as a specia l case.

The t rue cross-covar iance sequence is the mean-removed cross-cor rela t ionsequence

where m x and m y are the mean va lues of the two sta t ionary random processes,and E{}is the expected va lue opera tor . xcov est ima tes the sequence because, inpract ice, access is ava ilable to on ly a finite segment of the infin ite-lengthrandom process.

v = xcov(x,y) retu rns the cross-covar iance sequence in a length 2N -1 vector ,where x and y are length N vectors.

v = xcov(x) is the au tocovar iance sequence for the vector x. Where x is anN -by-P a r ray, v = xcov(X) returns am array with 2N -1 rows whose P 2 columnsconta in the cross-cova r iance sequences for a ll combina t ions of the columns of X.

By defau lt , xcov computes raw covar iances with no normaliza t ion . For a lengthN vector :

The ou tpu t vector c has element s given by c(m ) = cxy(m -N ), m =1,...,2N -1.

φx y m( ) E xn m x–( ) yn m+ m y–( )*{ }=

cxy m( )x n( ) 1

N---- xii 0=

N 1–

∑–⎝ ⎠⎜ ⎟⎜ ⎟⎛ ⎞

yn m+* 1

N---- yi*

=

∑–⎝ ⎠⎜ ⎟⎜ ⎟⎛ ⎞

n 0=

N m– 1–

∑ m 0≥

cyx* m–( ) m 0<⎩⎪⎪⎨⎪⎪⎧

=

Page 678: MATLAB Signal Processing Toolbox user manual

xcov

6-374

The covar iance funct ion requires normaliza t ion to est imate the funct ionproper ly.

v = xcov(x,'option') specifies a sca ling opt ion , where option is:

• biased, for bia sed est imates of the cross-cova r iance funct ion• unbiased, for unbia sed est imates of the cross-cova r iance funct ion• coeff, t o normalize the sequence so the au to-cova r iances a t zero lag a reident ica lly 1.0

• none, t o use the raw, unsca led cross-covar iances (defau lt )

See [1] for more informat ion on the proper t ies of biased and unbiasedcorrela t ion and covar iance est ima tes.

[c,lags] = xcov(x,y,maxlags) where x and y a re length m vectors, retu rnsthe cross-covar iance sequence in a length 2*maxlags+1 vector c. lags is avector of the lag indices where c was est ima ted, tha t is, [–maxlags:maxlags].

[c,lags] = xcov(x,maxlags) is the au tocovar iance sequence over the rangeof lags [–maxlags:maxlags].

[c,lags] = xcov(x,maxlags) where x is an m-by-p ar ray, retu rns ar ray cwith2*maxlags+1 rows whose P2 columns conta in the cross-covar iance sequencesfor a ll combina t ions of the columns of x.

[c,lags] = xcov(x,y,maxlags,'option') specifies a sca ling opt ion , whereoption is the last input a rgument .

In a ll cases, xcov gives an outpu t such tha t the zeroth lag of the cova r iancevector is in the middle of the sequence, a t element or row maxlag+1 or a t m.

Examples The second outpu t lags is useful when plot t ing. For example, the est imatedautocovar iance of uniform whit e noise cww(m ) can be displayed for -10 ≤ m ≤ 10using

ww = randn(1000,1); % generate uniform noise with mean = 1/2[cov_ww,lags] = xcov(ww,10,'coeff');stem(lags,cov_ww)

Page 679: MATLAB Signal Processing Toolbox user manual

xcov

6-375

Algorithm xcov computes the mean of it s inputs, subt ract s the mean , and then ca llsxcorr. For more informat ion on est ima t ing cova r iance and correla t ionfunct ions, see [1] and [2].

Diagnostics xcov does not check for any er rors other than the cor rect number of inpu ta rgument s. Inst ead, it relies on the er ror checking in xcorr, which it ca lls.

See Also

References [1] Benda t , J .S., and A.G. P iersol. Random Data: Analysis and Measurem entProcedures. New York: J ohn Wiley & Sons, 1971. Pg. 332.

[2] Oppenheim, A.V., and R.W. Schafer . Digital S ignal Processing. EnglewoodCliffs, NJ : Pren t ice Ha ll, 1975. Pgs. 63-67, 746-747, 839-842.

conv Convolu t ion and polynomia l mult iplica t ion .corrcoef Correla t ion coefficien t mat r ix.cov Covar iance ma t r ix.xcorr Cross-cor rela t ion funct ion est imate.xcorr2 Two-dimensiona l cross-cor rela t ion .

Page 680: MATLAB Signal Processing Toolbox user manual

yulewalk

6-376

6yulewa lkPurpose Recursive digit a l filt er design .

Syntax [b,a] = yulewalk(n,f,m)

Description yulewalk designs recursive IIR digita l filter s using a least -squares fit t o aspecified frequency response.

[b,a] = yulewalk(n,f,m) retu rns row vectors b and a conta in ing the n+1coefficien t s of the order n IIR filter whose frequency-magnitude character ist icsapproximately match those given in vectors f and m:

• f is a vector of frequency poin ts, specified in the range between 0 and 1,where 1 cor responds to ha lf the sample frequency (the Nyquist frequency).The fir st point of f must be 0 and the last poin t 1, with a ll in termedia tepoin t s in increasing order . Duplica te frequency poin ts are a llowed,cor responding to st eps in the frequency response.

• m is a vector conta in ing the desired magnitude response a t the poin tsspecified in f.

• f and m must be the same length .• plot(f,m) displays the filt er shape.

The outpu t filter coefficien ts are ordered in descending powers of z ,

When specifying the frequency response, avoid excessively sha rp t ransit ionsfrom passband to stopband. You may need to exper iment with the slope of thet ransit ion region to get the best filter design .

Example Design an 8th-order lowpass filt er and overplot the desired frequency responsewith the actua l frequency response:

f = [0 0.6 0.6 1];m = [1 1 0 0];

B z( )A z( )----------- b 1( ) b 2( )z 1– L b n 1+( )z n–+ + +

a 1( ) a 2( )z 1– L a n 1+( )z n–+ + +----------------------------------------------------------------------------------=

Page 681: MATLAB Signal Processing Toolbox user manual

yulewalk

6-377

[b,a] = yulewalk(8,f,m);[h,w] = freqz(b,a,128);plot(f,m,w/pi,abs(h),'--')

Algorithm yulewalk per forms a least -squares fit in the t ime domain . It computes thedenomina tor coefficient s using modified Yule-Walker equa t ions, withcor rela t ion coefficien t s computed by inverse Four ier t ransformat ion of thespecified frequency response. To compute the numera tor , yulewalk t akes thefollowing steps:

1 Computes a numera tor polynomia l cor responding to an addit ivedecomposit ion of the power frequency response.

2 Eva lua tes the complet e frequency response cor responding to the numera torand denominator polynomia ls.

3 Uses a spect ra l factor iza t ion technique to obta in the impulse response of thefilter .

4 Obta ins the numera tor polynomia l by a least -squa res fit t o th is impulseresponse.

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 10

0.2

0.4

0.6

0.8

1

1.2

Page 682: MATLAB Signal Processing Toolbox user manual

yulewalk

6-378

See Also

References [1] Fr iedlander , B., and B. Pora t . “The Modified Yule-Walker Method of ARMASpect ra l Est imat ion .” IEEE Transactions on Aerospace Electron ic S ystem s.AES-20, No. 2 (March 1984). Pgs. 158-173.

butter But terwor th ana log and digita l filt er design.cheby1 Chebyshev type I filter design (passband r ipple).cheby2 Chebyshev type II filter design (stopband r ipple).ellip Ellipt ic (Cauer ) filt er design .fir2 Window-based fin it e impulse response filt er design –

a rbit ra ry response.firls Least square linear-phase FIR filter design .maxflat Genera lized digita l But t erwor th filt er design .remez Parks-McClellan opt ima l FIR filter design .

Page 683: MATLAB Signal Processing Toolbox user manual

zp2sos

6-379

6zp2sosPurpose Conversion of zero-pole-ga in to second-order sect ions.

Syntax [sos,g] = zp2sos(z,p,k)[sos,g] = zp2sos(z,p,k,'order')[sos,g] = zp2sos(z,p,k,'order','scale')sos = zp2sos(...)

Description zp2sos conver ts a zero-pole-ga in representa t ion of a given system to anequiva len t second-order sect ion representa t ion .

[sos,g] = zp2sos(z,p,k) finds a mat r ix sos in second-order sect ion formwith ga in g equiva len t to the zero-pole-ga in syst em represen ted by inputa rgument s z, p, and k. Vectors z and p conta in the zeros and poles of the systemH (z), not necessar ily in any order :

where n and m are the lengths of z and p, r espect ively, and k is a sca la r ga in .The zeros and poles must be rea l or complex con jugate pa ir s. sos is an L -by-6mat r ix:

whose rows conta in the numera tor and denomina tor coefficien ts bik and a ik ofthe second-order sect ions of H (z):

The number of rows L of mat r ix sos is the maximum of the ceiling of n /2 andthe ceiling of m /2.

H z( ) kz z1–( ) z z2–( )Lz zn–( )

z p1–( ) z p2–( )Lz pm–( )-----------------------------------------------------------------=

sos

b01 b11 b21 1 a11 a21b02 b12 b22 1 a12 a22M M M M M M

b0L b1L b2L 1 a1L a2L

=

H z( ) g H k z( )k 1=

L

∏ gb0 k b1 k z 1– b2 k z 2–+ +1 a1 k z 1– a2 k z 2–+ +----------------------------------------------------------

k 1=

L

∏= =

Page 684: MATLAB Signal Processing Toolbox user manual

zp2sos

6-380

[sos,g] = zp2sos(z,p,k,'order') specifies the order of the rows in sos,where order is:

• down, t o order the sect ions so the fir st row of sos conta ins the poles closest tothe unit circle

• up, to order the sect ions so the fir st row of sos conta ins the poles fa r thestfrom the un it circle (defau lt )

[sos,g] = zp2sos(z,p,k,'order','scale') specifies the desired sca ling ofthe ga in and the numera tor coefficien ts of a ll second-order sect ions, wherescale is:

• none, t o apply no sca ling (default )• inf, t o apply infinity-norm sca ling• two, t o apply 2-norm sca ling

Using infin ity-norm sca ling in conjunct ion with up-order ing minimizes theprobabilit y of over flow in the rea liza t ion . Using 2-norm sca ling in conjunct ionwith down-order ing minimizes the peak round-off noise.

sos = zp2sos(...) embeds the overa ll system gain , g, in the fir st sect ion ,H 1(z), so tha t

Example Find a second-order sect ion form of a But t erwor th lowpass filt er :

[z,p,k] = butter(5,0.2);sos = zp2sos(z,p,k);

Algorithm zp2sos uses a four -step a lgor ithm to determine the second-order sect ionrepresen ta t ion for an input zero-pole-ga in system:

1 It groups the zeros and poles in to complex conjuga te pair s using thecplxpair funct ion .

2 It forms the second-order sect ion by ma tch ing the pole and zero pa ir saccording to the following ru les:

H z( ) Hk z( )k 1=

L

∏=

Page 685: MATLAB Signal Processing Toolbox user manual

zp2sos

6-381

a Match the poles closest to the unit cir cle with the zeros closest to thosepoles.

b Match the poles next closest to the unit circle with the zeros closest tothose poles.

c Cont inue unt il a ll of the poles and zeros a re matched.zp2sos groups rea l poles in to sect ions with the rea l poles closest to them inabsolu te va lue. The same rule holds for rea l zeros.

3 It orders the sect ions according to the proximity of the pole pa ir s to the unitcircle. zp2sos normally orders the sect ions with poles closest to the unitcircle last in the cascade. You can tell zp2sos to order the sect ions in thereverse order by specifying the down flag.

4 zp2sos sca les the sect ions by the norm specified in the 'scale' argument .For arbit ra ry H (ω), the sca ling is defined by:

where p can be either ∞ or 2. See the references for deta ils on the sca ling.This sca ling is an a t tempt to min imize over flow or peak round-off noise infixed poin t filter implementa t ions.

See Also

H p12π------ H ω( )

pωd

0

1p---

=

cplxpair Group complex numbers in to complex con jugatepa irs.

sos2zp Conversion of second-order sect ions to zero-pole-ga in .ss2sos Conversion of sta t e-space to second-order sect ions.tf2sos Conversion of t ransfer funct ion to second-order

sect ions.zp2ss Conversion of zero-pole-ga in to st a t e-space.zp2tf Conversion of zero-pole-ga in to t ransfer funct ion .

Page 686: MATLAB Signal Processing Toolbox user manual

zp2sos

6-382

References [1] J ackson , L.B. Digital Filters and S ignal Processing. 3rd ed. Boston : KluwerAcademic Publishers, 1996. Chapter 11.

[2] Mit ra , S.K. Digital S ignal Processing: A Com puter-Based Approach . NewYork: McGraw-Hill, 1998. Chapter 9.

[3] Va idyana than , P .P . “Robust Digita l F ilter St ructures.” Handbook forDigital S ignal Processing. S.K. Mit ra and J .F . Kaiser , ed. Chapter 7. New York:J ohn Wiley & Sons, 1993.

Page 687: MATLAB Signal Processing Toolbox user manual

zp2ss

6-383

6zp2ssPurpose Conversion of zero-pole-ga in to st a te-space.

Syntax [A,B,C,D] = zp2ss(z,p,k)

Description zp2ss conver t s a zero-pole-ga in represen ta t ion of a given system to anequiva len t sta te-space representa t ion .

[A,B,C,D] = zp2ss(z,p,k) finds a single input , mult iple ou tpu t , st a te-spacerepresen ta t ion

given a system in factored transfer funct ion form

Column vector p specifies the pole loca t ions, and ma tr ix z t he zero loca t ionswith as many columns as there are outpu ts. The ga ins for each numera tort ransfer funct ion a re in vector k. The A, B, C, and D matr ices a re returned incont roller canonica l form.

Inf values may be used as place holders in z if some columns have fewer zerosthan others.

Algorithm zp2ss, for single-inpu t systems, groups complex pa ir s together in to two-by-twoblocks down the diagona l of the A mat r ix. This requires the zeros and poles tobe rea l or complex conjuga te pa irs.

See Also

x· Ax B u+=y Cx Du+=

H s( ) Z s( )P s( )---------- k

s z1–( ) s z2–( )Ls zn–( )

s p1–( ) s p2–( )Ls pn–( )---------------------------------------------------------------= =

sos2ss Conversion of second-order sect ions to sta t e-space.ss2zp Conversion of sta t e-space to zero-pole-ga in .tf2ss Conversion of t ransfer funct ion to st a t e-space.zp2sos Conversion of zero-pole-ga in to second-order sect ions.zp2tf Conversion of zero-pole-ga in to t ransfer funct ion .

Page 688: MATLAB Signal Processing Toolbox user manual

zp2tf

6-384

6zp2t fPurpose Conversion of zero-pole-ga in to t ransfer funct ion .

Syntax [b,a] = zp2tf(z,p,k)

Description zp2tf forms t ransfer funct ion polynomia ls from the zeros, poles, and ga ins of asystem in factored form.

[b,a] = zp2tf(z,p,k) finds a ra t iona l t ransfer funct ion :

given a system in factored t ransfer funct ion form:

Column vector p specifies the pole loca t ions, and matr ix z the zero loca t ions,with as many columns as there are outpu ts. The ga ins for each numera tort ransfer funct ion are in vector k. The zeros and poles must be rea l or come incomplex con juga te pa ir s. The polynomia l coefficien ts are retu rned in vector s:the denominator coefficien ts in row vector a and the numera tor coefficient s inma tr ix b, with as many rows as there are columns of z.

Inf values can be used as place holders in z if some columns have fewer zerosthan others.

Algorithm The system is conver ted to t ransfer funct ion form using poly with p and thecolumns of Z.

See Also

B s( )A s( )-----------

b1s n b 1–( ) L b n b 1–( )s bn b+ + +a1s n a 1–( ) L a n a 1–( )s an a+ + +-----------------------------------------------------------------------------------=

H s( ) Z s( )P s( )---------- k

s z1–( ) s z2–( )Ls zm–( )

s p1–( ) s p2–( )Ls pn–( )---------------------------------------------------------------= =

sos2tf Conversion of second-order sect ions to t ransferfunct ion .

ss2tf Conversion of sta te-space to t ransfer funct ion .tf2zp Conversion of t ransfer funct ion to zero-pole-ga in .zp2sos Conversion of zero-pole-ga in to second-order sect ions.zp2ss Conversion of zero-pole-ga in to sta t e-space.

Page 689: MATLAB Signal Processing Toolbox user manual

zplane

6-385

6zplanePurpose Zero-pole plot .

Syntax zplane(z,p)zplane(b,a)[hz,hp,ht] = zplane(z,p)

Description This funct ion displays the poles and zeros of discrete-t ime systems.

zplane(z,p) plot s the zeros specified in column vector z and the poles specifiedin column vector p in the cur ren t figure window. The symbol 'o' represent s azero and the symbol 'x' represen ts a pole. The plot includes the un it circle forreference. If z and p are ar rays, zplane plots the poles and zeros in the columnsof z and p, r espect ively, in differen t colors.

You can overr ide the automat ic sca ling of zplane using

axis([xmin xmax ymin ymax])

or

set(gca,'ylim',[ymin ymax])

or

set(gca,'xlim',[xmin xmax])

after ca lling zplane. Th is is usefu l in the case where one or a few of the zerosor poles have such a la rge magnitude tha t the others a re grouped t igh t lya round the or igin and are hard to dist ingu ish .

zplane(b,a) where b and a are row vectors, first uses roots to find the zerosand poles of the t ransfer funct ion represen ted by numera tor coefficien ts b anddenomina tor coefficient s a.

[hz,hp,ht] = zplane(z,p) retu rns vectors of handles to the zero lines, hz,and the pole lines, hp. ht is a vector of handles to the axes/unit circle line andto text objects, which are presen t when there a re mult iple zeros or poles. Ifthere are no zeros or no poles, hz or hp is set to the empty matr ix [].

Page 690: MATLAB Signal Processing Toolbox user manual

zplane

6-386

Examples Plot the poles and zeros of a 5th-order But t erwor th lowpass digit a l filter withcu toff frequency of 0.2:

[z,p,k] = butter(5,0.2);zplane(z,p);title('5th-Order Butterworth Lowpass Digital Filter');

To genera te the same plot with a t ransfer funct ion represen ta t ion of the filt er :

[b,a] = butter(5,0.2); % transfer functionzplane(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

Imag

inar

y Pa

rt

5th−Order Butterworth Lowpass Digital Filter

freqz Frequency response of digita l filter s.

Page 691: MATLAB Signal Processing Toolbox user manual

I-1

Index

Aabs 6-2, 6-12ac2poly 6-3, 6-13ac2rc 6-3, 6-14a lgor ithm, filter ing in SPTool 5-18a liased sinc funct ion . S ee Dir ich let funct iona liasingand impu lse invar iance 2-42preven t ing dur ing resampling 4-21reducing with ana lyt ic signa l 4-38

a ll-pole filt er . S ee IIR filt era ll-zero filter . S ee FIR filt eram 4-29AM. S ee amplitude modu la t ionamdsb–sc 4-29, 6-236amdsb–tc 4-29, 6-236amplitude demodula t iondouble side-band, suppressed car r ier 6-114double side-band, t ransmit ted car r ier 6-114single side-band 6-114

amplitude modula t ion 4-29double side-band, suppressed car r ier 6-236double side-band, t ransmit ted car r ier 6-236single side-band 6-236

amssb 4-30, 6-236ana log filterBessel 6-22Butterwor th 6-44Chebyshev type I 6-66Chebyshev type II 6-71conver t ing to digita l 2-41, 6-194

design 2-7Bessel 2-11, 6-22But terwor th 6-43Chebyshev type I 6-65Chebyshev type II 6-71ellipt ic 6-125, 6-126inverse 6-203

frequency response 1-26, 6-173order est imat ionBut terwor th 6-49Chebyshev type I 6-56Chebyshev type II 6-61ellipt ic 6-133

represen ta t iona l models 1-40ana log fr equency xviiana log prototype 2-38Bessel filt er 2-11, 6-21But terwor th filt er 2-8, 6-42Chebyshev type I filt er 2-9, 6-54Chebyshev type II filt er 2-10, 6-59conversion to bandpass 6-220conversion to bandstop 6-223conversion to h ighpass 6-225conversion to lowpass 6-227ellipt ic filter 6-131frequency response 2-12plot t ing 2-12

ana log prototype designBessel 2-38bilinear t r ansformat ion 2-43But terwor th 2-38Chebyshev 2-38ellipt ic 2-38filt er discret iza t ion 2-41frequency tr ansformat ion 2-38impulse invar iance 2-42

Page 692: MATLAB Signal Processing Toolbox user manual

Index

I-2

S ee also IIR filter designana log signa l. S ee signa lana lyt ic signa l 2-26, 6-187applica t ions 4-38proper t ies 4-38

angle 6-2, 6-15ant i-symmetr ic filt er 2-25Apply but ton , Spectrum Viewer 5-97Apply Filter bu t ton 5-18applying parameters with Apply but ton 5-100arburg 4-11, 6-16arcov 4-11, 6-17ARMA filter 1-15S ee also IIR filter

ARMA model 4-13, 4-15Prony’s method 4-13Steiglit z-McBr ide method 4-15

armcov 4-11, 6-18ar raydisplay in Signa l Browser 5-47, 5-51in SPTool 5-14

Array Signa ls but ton , Signa l Browser 5-47, 5-51ARX model 4-13aryule 4-11, 6-19ASCII file, impor t ing 1-13a t tenua t ion , stopband 5-70a t t r ibu tes, in stan taneous 6-187autocor rela t ion 6-368mult iple channels 3-4two-dimensiona l 6-372

autocor rela t ion sequenceconver t ing from filt er coefficien ts 6-262conver t ing from reflect ion coefficient s 6-282conver t ing to filt er coefficien ts 6-13conver t ing to reflect ion coefficient s 6-14

autocovar iance 6-373mult iple channels 3-4

autoregressive (AR) filter 1-15S ee also IIR filter

au toregressive (AR) modelvia Burg method 6-16, 6-239via covar iance method 6-17, 6-243via modified covar iance method 6-18, 6-247via Yule-Walker AR method 6-19, 6-278

autoregressive moving average (ARMA) filt er 1-15S ee also IIR filter

au to-spectrum, in SPTool 5-15averaging filter 1-14axis labels, in Signa l Browser 5-20, 5-23axis parametersin Filt er Viewer 5-20in Spect rum Viewer 5-20

axis sca ling rangein Filt er Viewer 5-25, 5-87in Spect rum Viewer 5-24, 5-100, 5-102

axis sca ling unit sin Filt er Viewer 5-25, 5-87in Spect rum Viewer 5-24, 5-100, 5-102

Bband edges, prewarping 2-44bandlimited in terpola t ion 6-314bandpass filterana log prototype design 2-6and impu lse invar iance 2-42Bessel 6-22Butterwor th 6-43, 6-44Chebyshev type I 6-65, 6-66Chebyshev type II 6-70, 6-71ellipt ic 6-125, 6-126example, Chebyshev type I 2-40FIR design , with window method 2-21, 6-154t ransformat ion from lowpass to 6-220

Page 693: MATLAB Signal Processing Toolbox user manual

Index

I-3

bandstop filt erana log prototype design 2-6Bessel 6-22Butterwor th 6-44, 6-45Chebyshev type I 6-66, 6-67Chebyshev type II 6-71, 6-72ellipt ic 6-126, 6-127FIR design , with window method 2-21, 6-153t ransformat ion from lowpass to 6-223

bandwidth 2-40bartlett 4-2, 6-8, 6-20compared to triang 6-20example 4-2

Bar t let t window 4-2coefficients 6-20

Bessel filterana log 6-22ana log prototype 2-11, 2-38, 6-21bandpass configu ra t ion , ana log 6-22bandstop configura t ion , ana log 6-22character ist ics 2-11h ighpass configura t ion , ana log 6-22limita t ions 6-24lowpass configura t ion , ana log 6-22

besselap 2-5, 6-10, 6-21example 2-11

besself 2-5, 2-6, 6-5, 6-22beta parameter , of Kaiser window 5-75biascor rela t ion 3-3, 4-12power spect ra l density 3-12spect ra l density 3-12var iance t r ade-off 3-4

bilinear 2-5, 2-42, 2-43, 6-11, 6-25bilinear t ransformat ion 2-43, 6-25defined 2-43outpu t represen ta t ion 6-26

prewarping 2-44, 6-25blackman 4-2, 6-8, 6-30Blackman window 4-4, 6-30defined 4-4

boxcar 4-2, 6-8, 6-32example 4-2

boxcar window. S ee rectangu la r windowbrackets, indica t ing closed in terva l xviibuffer ing 6-33Burg method 3-5, 3-6, 3-20compared to Welch’s method 3-22defined 3-20example 3-21in Spect rum Viewer 5-104

buttap 2-5, 6-10, 6-42example 2-8

butter 2-5, 2-6, 6-5, 6-43But terwor th filt erana log 6-44ana log prototype 2-8, 2-38, 6-42bandpass configura t ionana log 6-44digita l 6-43

bandstop configura t ionana log 6-45digita l 6-44

character ist ics 2-8design 6-43digita l 6-43genera lized 2-14highpass configura t ionana log 6-45digita l 6-44

limita t ions 6-47lowpass configu ra t ionana log 6-44digita l 6-43

Page 694: MATLAB Signal Processing Toolbox user manual

Index

I-4

order est imat ion 2-7, 6-48buttord 2-5, 6-5, 6-48

Ccanonica l forms 1-17, 6-351car r ier frequency 4-29, 6-236, 6-365car r ier signa l 4-29, 6-114cascade, digita l filt er 1-37Cauer filt er . S ee ellipt ic filt ercceps 4-23, 6-9, 6-52example 4-23

cen ter fr equency 2-40cen tr a l fea tures 1-2cepst rumapplica t ions 4-23complex 4-23inverse 4-23, 4-25

overview 4-23rea l 4-23S ee also rea l cepst rum, complex cepst rum

cepst rum analysis 4-23cheb1ap 2-5, 6-10, 6-54example 2-9, 2-40

cheb1ord 2-5, 6-5, 6-55cheb2ap 2-5, 6-10, 6-59example 2-10

cheb2ord 2-5, 6-5, 6-60chebwin 4-2, 6-8, 6-64cheby1 2-5, 2-6, 6-5, 6-65example 2-45

cheby2 2-5, 2-6, 6-5, 6-70Chebyshev er ror minimiza t ion 2-22, 6-287Chebyshev type I filterana log 6-66ana log prototype 2-9, 2-38, 6-54

bandpass configura t ionana log 6-66digita l 6-65

bandstop configura t ionana log 6-67digita l 6-66

character ist ics 2-9design 6-65digita l 6-65highpass configu ra t ionana log 6-67digita l 6-66

lowpass configu ra t ionana log 6-66digita l 6-65

order est imat ion 2-7, 6-55Chebyshev type II filt erana log 6-71ana log prototype 2-38, 6-59bandpass configura t ionana log 6-71digita l 6-70

bandstop configura t ionana log 6-72digita l 6-71

character ist ics 2-10design 6-70digita l 6-70highpass configu ra t ionana log 6-72digita l 6-71

limita t ions 6-69lowpass configu ra t ionana log 6-71digita l 6-70

order est imat ion 2-7, 6-60Chebyshev window 4-9, 6-64

Page 695: MATLAB Signal Processing Toolbox user manual

Index

I-5

frequency response 4-9chirp 1-9, 6-2, 6-75ch irp signa l 1-9ch irp z-t ransform (CZT) 4-34, 6-105compared to discrete Four ier t ransform 4-34execut ion t ime 4-35for nar rowband frequency ana lysis 6-105

classica l IIR filt er design 2-8click-and-drag pann ing, in Signa l Browser 5-48coefficientscor rela t ion 6-88filt er 1-15, 5-79, 6-13, 6-262, 6-263, 6-283linear predict ion 6-229reflect ion 1-37, 6-14, 6-263, 6-282, 6-283sequence 6-282

cohere 3-6, 3-16, 6-7, 6-79coherence 3-15, 6-79defined 3-15

coherence funct ion 3-15Color bu t ton 5-35color orderin Signa l Browser 5-22in Spect rum Viewer 5-22

Color Order text box 5-22color , customizing in SPTool 5-20column index vector , en ter ing in Signa l Browser

5-47column, ar ray 5-47communica t ions 4-10communica t ions simula t ion 4-29, 6-114, 6-236S ee also modulat ion , demodu la t ion , voltage

cont rolled oscilla t ionCompact Disc standard 4-20complex cepst rum, defined 4-23complex conjuga te 6-90Complex Display mode 5-47complex envelope 4-38

complex numbers, grouping by conjugate 6-90complex signa ls, in Signa l Browser 5-47computa t ion parameters, in Spect rum Viewer

5-103, 5-104Conf. In t . check box 5-107confidence in terva lfor cross spectr a l density 3-14for power spect ra l density 3-14, 5-107set t ing in Spect rum Viewer 5-107

conserva t ion of tota l power , using pmtm 3-19context sensit ive help in SPTool 5-7cont inuous signa l. S ee signa lcont inuous-t ime filt er . S ee ana log filt ercont rol systems 1-35Cont rol Systems Toolbox 1-35, 6-198conv 1-14, 1-20, 6-2, 6-83conv2 1-14, 6-2, 6-84conversionautocor rela t ion sequence to filt er coefficien ts

6-13autocor rela t ion sequence to reflect ion

coefficien ts 6-14filt er coefficien ts to au tocor rela t ion sequence

6-262filt er coefficien ts to reflect ion coefficien ts 6-263,

6-283reflect ion coefficien ts to au tocorrela t ion

sequence 6-282second-order sect ions to sta te-space 6-316second-order sect ions to t ransfer funct ion

6-318second-order sect ions to zero-pole-ga in 6-320sta te-space to second-order sect ions 6-333sta te-space to zero-pole-ga in 6-338t ransfer funct ion to la t t ice 6-346t ransfer funct ion to second-order sect ions

6-347

Page 696: MATLAB Signal Processing Toolbox user manual

Index

I-6

t r ansfer funct ion to sta te-space 6-350zero-pole-ga in to second-order sect ion 6-379zero-pole-ga in to sta te-space 6-383

convmtx 1-39, 1-42, 6-3, 6-86convolu t ionand cross-cor rela t ion 3-3and filter ing 1-14, 6-148convolu t ion mat r ix 1-39, 6-86defined 6-83example 1-14two-dimensiona l 6-84obta in ing subsect ion 6-84

convolu t ion mat r ix 1-42, 6-86defined 1-39example 6-86

corrcoef 6-7, 6-88cor r ela t ion 3-2coefficien t mat r ix 6-88S ee also au tocor rela t ion , cross-cor rela t ion

cosine window 4-4cov 6-7, 6-89covar iance 3-2mat r ix 6-89S ee also au tocovar iance, cross-covar iance

covar iance method 3-6, 3-22defined 3-22example 3-23

covar iance method, in Spect rum Viewer 5-105cplxpair 6-9, 6-90Crea te but ton , in Spectra panel 5-19, 5-97cremez 2-17, 6-5, 6-91cross spect ra l density 3-14, 6-100confidence in terva l 3-14defined 3-5

cross-cor rela t ion 6-367biased 3-3mult iple channels 3-4

normaliza t ion 3-4two-dimensiona l 6-372unbiased 3-3

cross-covar iance 6-373mult iple channels 3-4

csd 3-6, 3-14, 6-7, 6-100CSD. S ee cross spect ra l densitycu toff frequency 2-38defined 6-22for Kaiser window filt er 5-75

czt 4-35, 6-6, 6-105CZT. S ee chirp z-t ransform

Ddataduplica t ing in SPTool 5-16edit ing in SPTool 5-13, 5-15enter ing 1-13expor t ing from SPTool 5-6impor t ing 1-13impor t ing in to SPTool 5-3, 5-6, 5-7measur ing in SPTool 5-31mult ichannel 1-4, 1-7viewing in SPTool 5-31

data compression 4-10da ta mat r ix 1-4, 1-7da ta vector 1-4dct 4-36, 6-6, 6-108example 4-37

decimate 6-9, 6-110decimat ion 6-110FIR filt er for 6-201

deconv 4-33, 6-9, 6-113example 4-33

deconvolu t ion 4-33, 6-113defau lt plot , in Spect rum Viewer 5-102

Page 697: MATLAB Signal Processing Toolbox user manual

Index

I-7

Default Session check box, in Prefer ences dia logbox 5-28

Defau lt SPTool session file 5-20, 5-28defau lt va lues, using empty matr ix 3-11delayadding to signa l 2-25group 1-28nonin teger 2-26phase 1-28

demod 4-29, 4-30, 6-9, 6-114example 4-30

demodu la t ion 4-30, 6-114example 4-30methods 4-30, 6-114

design , genera lized filt er 2-5designed filter , in SPTool 5-14DFT. S ee discrete Four ier t ransformdftmtx 6-6, 6-117difference equa t ion , rela t ion to t ransfer funct ion

1-32differen t ia tor 2-26, 6-167, 6-289Digita l Audio Tape standard 4-20digita l filteran t i-causa l 1-20as convolu t ion mat r ix 1-40Butterwor th 6-43cascade 1-37Chebyshev type I 6-65Chebyshev type II 6-70coefficients 1-15design 2-2ellipt ic 6-125FIR 2-16compared to IIR 2-16

fixed-poin t implementa t ion 1-37frequency response 1-24group delay 1-28, 6-182

ident ifica t ion from frequency data 6-207IIR 2-4compared to FIR 2-4

implementa t ion 1-14, 6-142, 6-145FFT-based (FIR) 6-142over lap-add method 1-22using convolu t ion 1-14using filter funct ion 1-16

impulse response 1-14, 1-23, 6-196in it ia l condit ions 1-17linea r system models 1-32names 1-15order 1-15in sta te-space represen ta t ion 1-34

order est imat ionBut terwor th 6-48Chebyshev type I 6-55Chebyshev type II 6-60ellipt ic 6-132equ ir ipple FIR 6-294

phase delay 1-28, 6-182poles 1-30, 1-33represen ta t iona l models 1-32represen t ing in MATLAB 1-32second-order sect ions 1-37specifica t ions 2-7sta r tup t ransien ts 1-21, 1-22structurela t t ice 1-37t ransposed direct form II 1-17

t ime-domain represen ta t ion 1-16t ransfer funct ion represen ta t ion 1-15two-dimensiona l 6-148zero-phase 1-20, 6-149zeros 1-30, 1-33zeros and poles 1-33S ee also FIR filter , IIR filt er

Page 698: MATLAB Signal Processing Toolbox user manual

Index

I-8

digita l filt er designFIR 2-16IIR 2-4

digita l frequency xviidirect design 2-13descr ibed 2-13summary 2-5

diric 6-2, 6-118Dir ich let funct ion 1-11, 6-118defined 1-11example 1-12

discrete cosine t ransform (DCT) 6-108applica t ions 4-36energy compact ion proper ty 4-37example 4-37inverse 4-36, 6-190reconst ruct ing signal from few coefficient s

4-37discrete Four ier t ransform (DFT) 1-2, 1-43a lgor ithms 1-45and IIR filt er implemen ta t ion 1-22and spect ra l ana lysis 3-6applica t ions 6-137dependence on signa l length 1-45example 1-44execu t ion t ime, using chirp z-t ransform 4-35inverse 1-43, 6-192mat r ix 6-117two-dimensiona l 1-45, 6-193

mat r ix 6-117two-dimensiona l 1-45, 6-141S ee also fast Four ier t ransform (FFT), fft

discrete prola te spheroida l sequences (DPSSs)3-19

discrete-t ime Four ier t ransform 3-5discret iza t ion 2-41, 6-194

bilinear t ransformat ion 2-43prewarping 2-44

impulse invar iance 2-42disk, loading var iables from 5-8dpss 6-9, 6-119dpss.mat 3-19dpssclear 3-19, 6-9, 6-121dpssdir 3-19, 6-9, 6-122dpssload 3-19, 6-9, 6-123DPSSs. S ee discrete prola te spheroida l sequencesdpsssave 3-19, 6-9, 6-124du ty cycle, specifying 1-8

Eecho detect ion 4-23edge effect s 1-22edge fr equencies, set t ing in Filter Designer 5-70Edit Design but ton 5-18, 5-59eig, in pmusic funct ion 3-25eigenanalysisdefined 3-24fr equency est imator funct ions 3-24

eigenvector method 3-5, 3-23S ee also mult iple signa l classifica t ion method

ellip 2-5, 2-6, 6-5, 6-125ellipap 2-5, 6-10, 6-131example 2-10

ellipord 2-5, 6-5, 6-132ellipt ic filt erana log 6-126ana log prototype 2-38, 6-131bandpass configura t ionana log 6-126digita l 6-125

Page 699: MATLAB Signal Processing Toolbox user manual

Index

I-9

bandstop configura t ionana log 6-127digita l 6-126

character ist ics 2-10design 6-125digita l 6-125h ighpass configura t ionana log 6-127digita l 6-126

limita t ions 6-129lowpass configura t ionana log 6-126digita l 6-125

order est imat ion 2-7, 6-132energy compact ion 4-37equir ipple character ist icsChebyshev type I filt er (passband) 2-9Chebyshev type II filt er (stopband) 2-10Chebyshev window 4-9ellipt ic filt er 2-10, 6-125, 6-131from Parks-McClellan design 6-287

equir ipple filt er 2-22er ror min imiza t ionbetween desired and actua l response 2-22for equir ipple filt er 5-75for least squares filt er 5-75in tegra l of square 2-22min imax 2-22weight ing in frequency bands 2-24

est imat ioncross spect rum 3-14power spect rum 3-6t ransfer funct ion 3-14S ee also paramet r ic modeling

est imat ion methodsin Spect rum Viewer 5-103, 5-104

nonparamet r icFFT method 5-105mult iple signa l classifica t ion method

(MUSIC) 3-5, 5-106mult it aper method (MTM) 3-5, 5-105Welch’s method 3-5, 5-106

paramet r ic 3-5Burg method 5-104, 6-16covar iance method 6-17modified covar iance method 6-18Yule-Walker AR method 5-107Yule-Walker method 6-19

Expor t F ilt ers as TF objects check box, inPreferences dia log box 5-29

Expor t menu item 5-6Expor t ing Components check box, in Preferences

dia log box 5-29expor t ing da ta from MATLAB 1-13extensions to SPTool 5-30

FFactory Set t ings but ton , in Preferences dia log box

5-30fast Four ier t ransform (FFT) 1-22, 1-43and frequency response 1-24fft 1-22pr ime factor a lgor ithm 1-45, 6-139radix-2 a lgor ithm 1-45, 6-139role in signa l processing 1-43two-dimensiona l 6-141

fft 1-2, 1-22, 1-43, 6-6, 6-137complex inputs 1-45example 1-44execut ion t ime 1-45, 6-140pr ime factor a lgor ithm 1-45, 6-139radix-2 a lgor ithm 1-45, 6-139

Page 700: MATLAB Signal Processing Toolbox user manual

Index

I-10

rea l inputs 1-45rear r anging output 1-45, 6-144specifying number of poin t s 1-44

FFT lengthin Filt er Designer 5-20, 5-27in Filt er Viewer 5-25

FFT Length edit box, in Preferences dia log box5-25, 5-27

FFT method, in Spect rum Viewer 5-105FFT. S ee fast Four ier t ransformfft2 1-45, 6-6, 6-141rear r anging output 1-45

FFT-based filt er ing 1-22fftfilt 1-19, 6-2, 6-142compared to filter 6-142

fftshift 1-45, 6-6, 6-144File Con tents list 5-8filt erana log prototype 2-8, 2-11, 6-21, 6-42, 6-54,

6-59, 6-131ana lyzing in Filt er Viewer 5-17applying to a signa l 5-18But terwor th 2-7, 6-43genera lized 2-14

Chebyshev 2-7Chebyshev type I 6-65Chebyshev type II 6-70coefficients 1-15, 2-17, 5-79designFIR 6-287genera lized 2-5IIR 2-5inverse 6-203, 6-207

discret iza t ion 2-41ellipt ic 2-7, 6-125equ ir ipple 2-22

expor t ing as TF object s for Con trol SystemToolbox 5-29

group delay 5-17ident ifica t ion from frequency da ta 6-203implementa t ion 1-22, 6-142, 6-145impor t ing in to SPTool 5-7, 5-8, 5-11impulse response 5-17linear t ime-invar ian t digita l 1-2magnitude response 5-17measuremen ts 5-37median 4-28, 6-235min imax 2-22min imum phase 6-265mult iband FIR 2-22names 1-15naming in SPTool 5-16order 1-15, 2-7, 6-48, 6-55, 6-60, 6-132order select ion 2-7phase response 5-17pr incipa l suppor ted 1-2Savitzky-Golay 6-309, 6-311second-order sect ions 6-322single band FIR 2-20specifica t ions 2-7step response 5-17t ransposed direct form II st ructure 1-17two-dimensiona l 6-148types 2-17viewing in Filt er Viewer 5-17zeros and poles 5-17S ee also FIR filt er , IIR filt er , digita l filt er ,

ana log filt erfilter 1-2, 1-16, 1-20, 6-2, 6-145compared to fftfilt 6-142compared to filtfilt 1-21fina l condit ion parameters 1-17implementa t ion 1-17

Page 701: MATLAB Signal Processing Toolbox user manual

Index

I-11

in it ia l condit ion parameter s 1-17in it ia l condit ions 6-150

filt er coefficient sconver t ing from autocorr ela t ion sequence

6-13conver t ing to autocor r ela t ion sequence 6-262conver t ing to reflect ion coefficien ts 6-263,

6-283filt er designin Filter Designer 5-59, 5-73, 5-76standard band configura t ions 5-59using specifica t ion lines 5-70

Filter Designer 5-2, 5-17, 5-59, 6-329act iva t ing 5-17, 5-59changing plot proper t ies 5-27classica l IIR filt er design 5-76closing 5-60customizing 5-20magnitude plot 5-63, 5-69, 5-78measur ing response character ist ics 5-70saving da ta to workspace 5-79, 5-110set t ing edge frequencies 5-70set t ing passband r ipple 5-70set t ing stopband a t tenua t ion 5-70single band FIR filter design 5-73window 5-60

filt er parameter s, in F ilt er Viewer 5-20filt er response, peaks and va lleys 5-37filt er typedesign 5-14impor ted 5-14, 5-18

Filt er Viewer 5-2, 5-17, 5-84, 6-330act iva t ing 5-17, 5-84customizing 5-20defau lt plot 5-85plot s 5-86preferences 5-86

set t ings 5-86subplots 5-86viewing fr equency response 5-82viewing group delay 5-93viewing impulse response 5-94viewing magnitude response 5-89viewing phase response 5-91viewing step response 5-95viewing zero-pole plot 5-94window 5-85

filter2 6-3, 6-148filt er ingand convolu t ion 1-14ant i-causa l 1-20frequency domain 1-22in it ia l condit ions 1-17genera t ing 1-18

zero-phase 1-20filt er ing a lgor ithm 5-18filtfilt 1-19, 1-20, 2-4, 6-3, 6-149compared to filter 1-21example 1-20in it ia l condit ions 1-21

filtic 1-18, 6-3, 6-150FIR filt era rbit ra ry frequency response 6-157compared to IIR 2-16design 2-16decimat ion 6-201in terpola t ion 6-201least squares method 6-166linear phase 6-166mult iband frequency response 6-157Parks-McClellan method 6-287window method 6-152

differ ent ia tor 2-26, 6-167, 6-289Hilber t t ransformer 2-25, 6-167, 6-289

Page 702: MATLAB Signal Processing Toolbox user manual

Index

I-12

implementa t ion 1-17, 6-145FFT-based 1-22, 6-142over lap-add method 1-22, 6-142

linear phase 2-17, 6-287order est imat ion , remez funct ion 6-294types 6-169, 6-292

FIR filt er design 2-16ant i-symmetr ic 2-25arbit r a ry responses 2-31complex filt er s 2-17, 6-91nonlinear phase 2-17, 6-91reduced delay 2-34

const ra ined least squares 2-16, 2-27linear phase 2-28mult iband 2-28, 2-29weighted 2-30

equ ir ipple 2-16, 2-22, 2-23, 5-73, 5-75example 5-73, 5-113in Filt er Designer 5-59, 5-73Kaiser window 5-73, 5-75least squares 2-16, 2-22, 2-23, 5-73, 5-75least squares compared to equir ipple 2-23linear phase filt er s 2-17, 2-22mult iband 2-16, 2-21, 2-22order select ion 5-75parameters in Filter Designer 5-75Parks-McClellan method 2-22ra ised cosine method 2-17role of Kaiser window 4-7standard band 2-20windowing method 2-16, 2-18

FIR filt er ing, in frequency domain 1-19FIR la t t ice filt er , implemen ta t ion 1-38fir1 2-16, 2-20, 6-5, 6-152accessing from Filter Designer 5-73, 5-75

fir2 2-16, 2-20, 6-5, 6-157example 2-21

fircls 2-16, 6-5, 6-160fircls1 2-16, 6-6, 6-163firls 2-16, 2-22, 6-6, 6-166accessing from Filter Designer 5-73, 5-75compared to remez 2-23filt er character ist ics 6-169for differen t ia tor design 2-26weight vector 2-24

firrcos 2-17, 6-6, 6-171fixed-poin t implementa t ion , digita l filt er 1-37fm 4-30FM. S ee frequency modula t ionfopen 1-13Four ier t ransform, eigenvector equ iva len t 3-24Four ier t ransform, t ime dependen t . S ee

t ime-dependent Four ier t ransformFour ier t ransform. S ee discrete Four ier t ransform,

fast Four ier t ransformfread 1-13freqs 1-26, 6-3, 6-173freqspace 6-176fr equency 6-287ana log xviiangula r 2-2car r ier 4-29, 6-236, 6-365center 2-40cu toff 2-38digita l xviinormaliza t ion 2-2Nyquist xvii, 2-2prewarping 6-25t ransformat ion 6-220, 6-223, 6-225, 6-227vector 2-24, 6-157, 6-160, 6-376

fr equency analysisin Filt er Viewer 5-84t ime-dependent 6-323

Page 703: MATLAB Signal Processing Toolbox user manual

Index

I-13

Frequency Axis Range pop-up menu , inPrefer ences dia log box 5-24, 5-25

Frequency Axis Sca ling pop-up menu, inPrefer ences dia log box 5-24, 5-25

frequency axis sca ling, in Spect rum Viewer 5-100frequency demodula t ion 6-115frequency domaindua lity with t ime domain 1-22FIR filter ing 1-19for filt er implementa t ion 1-22

frequency domain based modeling. S ee paramet r icmodeling

frequency est imator funct ions, in eigenana lysis3-24

frequency est imator techn iqueseigenvector (EV) method 3-23mult iple signa l classifica t ion (MUSIC) method

3-23frequency modu la t ion 6-237frequency point s

freqz 1-24, 1-26range 1-26spacing 1-26

Frequency Range pop-up menu, Spect rum Viewer5-100

frequency response 1-24arbit ra ry 2-13, 6-157example 1-25in Filter Viewer 5-82, 5-84, 5-89inver se 6-203Kaiser window 4-6linear phase 2-17magnitude 1-26min imized er ror between desired and actua l

2-22monoton ic 2-9mult iband 2-13

of Bessel prototype 2-11of But terwor th prototype 2-8of Chebyshev type I prototype 2-9of Chebyshev type II prototype 2-10of Chebyshev window 4-9of ellipt ic prototype 2-10phase 1-26unwrapping 1-27

plot t ing 1-25poin ts a t which eva lua ted 1-24spacing 6-176specifying sampling frequency 1-24

Frequency Sca le pop-up menu, Spect rum Viewer5-100

frequency tr ansformat ion 2-38example 2-40lowpass to bandpass 6-220lowpass to bandstop 6-223lowpass to highpass 6-225lowpass to lowpass 6-227

frequency vector 6-287freqz 1-24, 6-3, 6-177frequency point s 1-24sampling frequency 1-24spacing 6-176

From Disk radio but ton , in Impor t dia log box 5-8From Workspace radio bu t ton , in Impor t dia log

box 5-8fscanf 1-13Full View but ton 5-32

Ggauspuls 1-8, 1-10, 6-2, 6-180Gauss-Newton method 6-205, 6-209genera lized But terwor th filt er 2-14genera lized cosine window 4-4

Page 704: MATLAB Signal Processing Toolbox user manual

Index

I-14

Gibbs effect 2-19reduced by window 4-2

graphica l user in ter face (GUI) xii, 1-3gr id lines, in Filter Designer 5-20, 5-27group delay 1-28, 5-17, 6-182defined 1-28example 1-29of linear response filt er 2-17passband 2-11viewing in Filter Viewer 5-93

Group Delay check box, F ilter Viewer 5-86group delay plot 5-86, 5-93grpdelay 1-28, 6-3, 6-182GUI. S ee graph ica l user in ter faceGUI-based tools. S ee in teract ive tools

Hhamming 4-2, 6-8, 6-185Hamming window 2-20, 4-4, 6-185HandleVisibility proper ty 5-57, 5-110hanning 4-2, 6-8, 6-186Hanning window 4-4, 6-186highpass filt erana log prototype design 2-6Bessel 6-22But terwor th 6-44, 6-45Chebyshev type I 6-66, 6-67Chebyshev type II 6-71, 6-72ellipt ic 6-126, 6-127FIR designwith window method 2-21, 6-154

tr ansformat ion from lowpass to 6-225hilbert 2-26, 4-38, 6-6, 6-187example 4-39

Hilber t t ransform 4-34, 4-38, 6-187and ana lyt ic signa l 2-26

and instan taneous a t t r ibu tes 4-39example 4-39

Hilber t t ransformer 6-167, 6-289homomorph ic systems 4-23Hor izonta l bu t ton , for ru lers 5-36, 5-38, 5-39

Iicceps 4-23, 4-25, 6-9, 6-189example 4-26

idct 4-36, 6-6, 6-190idea l lowpass filter 2-18ifft 1-43, 6-6, 6-192specifying number of poin ts 1-45

ifft2 1-45, 6-6, 6-193IIR filtera rbit ra ry frequency response 2-13Bessel 2-11Butterwor th 2-8Chebyshev type I 2-9Chebyshev type II 2-10compared to FIR 2-4design 2-4dir ect 2-13Levinson-Durbin recursion 6-218mult iband 2-13Prony’s method 6-266Steiglit z-McBr ide itera t ion 6-341Yule-Walker 6-376

ellipt ic 2-10implementa t ion 6-145fr equency domain 1-22zero-phase 1-20

IIR filter design 2-4, 2-5ana log prototype 2-5Butterwor th 2-7, 2-8, 5-76, 5-77Chebyshev 2-7, 2-9, 2-10, 5-76, 5-77

Page 705: MATLAB Signal Processing Toolbox user manual

Index

I-15

classica l (ana log prototype) 2-5, 2-8compar ison of filt er types 2-8genera l steps 2-37illust ra t ion 2-37in Filt er Designer 5-76order est imat ion 2-7plot t ing prototypes 2-12single step 2-6single step order est imat ion 2-7system model 2-7

direct methods 2-13Yule-Walker 2-13

ellipt ic 2-7, 2-10, 5-76, 5-77example 5-76, 5-77genera lized But terwor th 2-14in Filter Designer 5-59, 5-76maximally fla t 2-14parameters in Filt er Designer 5-77to specifica t ions 2-7S ee also direct design , paramet r ic modeling

IIR la t t ice filt er , implemen ta t ion 1-38image processing 6-84with fft2 and ifft2 1-45

impinvar 2-5, 2-42, 6-11, 6-194Impor t As pop-up menu , in Impor t dia log box 5-9Impor t menu item 5-4, 5-6impor ted filt er , in SPTool 5-14impulse invar iance 2-42, 6-194limita t ions 2-42

impulse response 1-23, 5-17, 6-196and impu lse invar iance 2-42comput ing with filter 1-23comput ing with impz 1-23defined 1-23example 1-23of idea l lowpass filter 2-18viewing in Filter Viewer 5-94

Impulse Response check box, F ilter Viewer 5-86impulse response plot 5-86, 5-94impz 6-3, 6-196example 1-23

indexing, of vectors 1-15Inher it from pop-up menu, Spect rum Viewer

5-100inher it ing parameters 5-100in it ia l condit ions 1-17, 1-21, 6-150genera t ing 1-18

In it ia l Type pop-up menu, in Preferences dia logbox 5-21

instan taneous a t t r ibu tes 4-39, 6-187in teract ive tools 5-2extended example 5-113Filter Designer 5-2, 5-59, 6-329Filter Viewer 5-2, 5-84, 6-330Signal Browser 5-2, 5-43, 6-328Spect rum Viewer 5-2, 5-97, 6-331SPTool 5-2, 6-328

interp 6-9, 6-199in terpola t ion 6-199FIR filt er design 6-201

in terva l nota t ion xviiintfilt 6-6, 6-201inverse complex cepst rum 4-25inverse discrete cosine transform 6-190accuracy of signa l reconstruct ion 4-38

inverse discrete Four ier t ransform 1-43, 6-192ifft 1-43mat r ix 6-117two-dimensiona l 1-45, 6-193

inverse filter design 6-207, 6-266ana log 6-203digita l 6-207

inverse Four ier t ransform, cont inuous. S ee sincfunct ion

Page 706: MATLAB Signal Processing Toolbox user manual

Index

I-16

invfreqs 2-5, 4-11, 4-16, 6-8, 6-203invfreqz 2-5, 4-11, 4-16, 6-8, 6-207

Kkaiser 4-2, 6-8, 6-210accessing from Filter Designer 5-73example 4-5

Kaiser window 4-4, 6-210and FIR filter design 4-7, 5-73beta parameter 4-4, 6-210example 4-5frequency response 4-6

kaiserord 2-16, 6-6, 6-211accessing from Filter Designer 5-75

Lladder coefficien ts 1-38Lagrange in terpola t ion filter 6-201Laplace t ransform 1-41equ iva len t to sta te-space represen ta t ion 1-41

latc2tf 1-39, 1-42, 6-3, 6-216latcfilt 1-19, 1-39, 6-3, 6-217la t t ice coefficients 1-38la t t ice filt er 1-42implementa t ion 1-38implementa t ion with latcfilt 1-39

la t t ice formconver t ing from transfer funct ion 6-346

la t t ice st ructu re 1-37la t t ice/ladder filt erimplementa t ion 1-38implementa t ion with latcfilt 1-39

least squares method, FIR filt er design 6-166filt er character ist ics 6-169

levinson 4-11, 6-8, 6-218, 6-305

and paramet r ic modeling 4-12Levinson-Durbin recursion 4-12, 6-218, 6-305line colorin Filt er Viewer 5-35in Signa l Browser 5-35in Spect rum Viewer 5-35

line select ionin Filt er Viewer 5-34, 5-35in Signa l Browser 5-34, 5-35in Spect rum Viewer 5-34, 5-35

line stylecustomizing in SPTool 5-20in Filt er Viewer 5-22, 5-35in Signa l Browser 5-22, 5-35in Spect rum Viewer 5-22, 5-35

Line Style Order edit box, in Preferences dia log box5-22

linear phase 2-16, 2-17, 6-166filt er design 6-287rela ted character ist ics 2-17

linear predict ion coefficien ts 6-229linear predict ion modeling 4-12linear predict ive codinglinea r swept -fr equency cosine. S ee chirplinear system models 1-32linear system transformat ions 1-41conversion char t 1-41

linear t ime-invar ian t differen t ia l equa t ions,represented in sta te-space form 1-40

load 1-13lowpass filt erana log prototype design 2-6and impu lse invar iance 2-42Bessel 6-22Butterwor th 6-43, 6-44Chebyshev type I 6-65, 6-66Chebyshev type II 6-70, 6-71

Page 707: MATLAB Signal Processing Toolbox user manual

Index

I-17

ellipt ic 6-125, 6-126FIR design , with window method 2-21for decimat ion 6-110for in terpola t ion 6-199idea l impulse response 2-18t ransla t ion of cu toff frequency 6-227

lp2bp 2-5, 2-39, 6-10, 6-220example 2-40

lp2bs 2-5, 2-39, 6-10, 6-223lp2hp 2-5, 2-39, 6-10, 6-225lp2lp 2-5, 2-39, 6-10, 6-227lpc 2-5, 4-11, 6-8, 6-229S ee also linear predict ive coding, Prony’s

methodLPC. S ee linear predict ion coefficien t s

Mmagnitudeof Four ier t ransform of sequence 1-44of fr equency response 1-26viewing in Filter Viewer 5-89

of t ransfer funct ion est imate 3-15vector 2-24, 6-157, 6-160, 6-376

Magn itude Axis Sca ling pop-up menu, inPrefer ences dia log box 5-24, 5-25

Magn itude check box, Filt er Viewer 5-86magnitude plot 5-78magnitude plot , in Filter Designer 5-69, 5-78magnitude response 5-17magnitude response plot 5-86, 5-89in Filt er Designer 5-63

Magn itude Scale pop-up menu, Spect rum Viewer5-100

magnitude sca le, in Spect rum Viewer 5-100manufactu r ing 4-10

Marker Size edit box, in Preferences dia log box5-21

match frequency (for prewarping) 6-25MAT-file

dpss.mat 3-19impor t ing 1-13impor t ing in to SPTool 5-4, 5-6loading in to SPTool 5-8

MAT-file format , conver t ing to 1-13mat r icesconvolu t ion 1-39, 6-86cor rela t ion coefficien t 6-88covar iance 6-89da ta 1-4, 1-7discrete Four ier t ransform 6-117for second-order sect ions form 1-37inverse discrete Four ier t ransform 6-117

mat r ix form. S ee sta te-space formmaxflat 2-5, 2-14, 6-5, 6-233maxima, loca l 5-37maximally fla t 2-14measuremen t lines 5-70measuremen tsin Filt er Viewer 5-37in Signa l Browser 5-37in Spect rum Viewer 5-37, 5-101saving in Filter Viewer 5-37saving in Signal Browser 5-37saving in Spect rum Viewer 5-37

medfilt1 4-28, 6-9, 6-235median filter 4-28, 6-235message signa l 4-29, 6-236Method pop-up menu, Spect rum Viewer 5-103MEX-file 1-13M-files 1-3crea t ing xii, 1-3modifying xii

Page 708: MATLAB Signal Processing Toolbox user manual

Index

I-18

viewing xiimin ima, loca l 5-37minimax method, FIR filt er design 2-22S ee also Parks-McClellan method

minimum phase filter 6-265modelsau toregressive 6-16, 6-17, 6-18, 6-19via Burg method 6-239via covar iance method 6-243via modified covar iance method 6-247via Yule-Walker AR method 6-278

models, system represen ta t ion 1-32modified covar iance method 3-6, 3-22defined 3-22example 3-23

modified per iodogram 3-9modulate 4-29, 6-9example 4-30method flags 4-29

modula t ion 6-236amplitudedefined 4-29example 4-30frequencymethods 4-29, 6-236phase 4-30pulse t ime 4-30pulse width 4-30quadra tu re amplitude 4-30

mouse zoom 5-32in Filt er Designer 5-20in Filt er Viewer 5-20, 5-88in Signa l Browser 5-20in Spect rum Viewer 5-20tu rn ing off 5-33

Mouse Zoom but ton 5-32moving average (MA) filt er 1-15

S ee also FIR filt erMTM. S ee mult it aper methodmult iband filt erFIR 2-21FIR, with tr ansit ion bands 2-22IIR 2-13

mult ichannel da ta 1-4, 1-7mult ichannel signa l 3-4mult iple signa l classifica t ion method (MUSIC) 3-5,

3-6, 3-23defined 3-23in Spect rum Viewer 5-106

mult iplicity, of zeros and poles 5-71mult ira te filt er bank, implemen tat ion 1-19mult ira te filt er ing 1-19mult it aper method (MTM) 3-5, 3-6, 3-16compared to Welch’s method 3-19defined 3-16example 3-17in Spect rum Viewer 5-105

MUSIC. S ee mult iple signa l classifica t ion method

NNew Design but ton 5-17, 5-59nonin teger delay 2-26nonrecur sive filt er . S ee FIR filt ernormaliza t ion 3-3cor rela t ion 3-4, 6-367, 6-368power spect ra l density 3-12

Nyquist frequency xvii, 2-2

Oobjects, edit ing in SPTool 5-15one-t ime mouse zooming 5-32Open Session menu item 5-6

Page 709: MATLAB Signal Processing Toolbox user manual

Index

I-19

order est imat ion 2-7, 6-294Butterwor th 6-48Chebyshev type I 6-55Chebyshev type II 6-60ellipt ic 6-132in Filter Designer 5-75, 5-78

order select ion 2-7in Filter Designer 5-75, 5-78

order , of filt er 1-15, 2-7or thogona l windows, in PSD est imates 3-16oscilla tor , voltage cont rolled 6-365over lap-add method, FIR filt er implementa t ion

1-22, 6-142

PPage Setup dia log box 5-45, 5-99panner 5-52in Signa l Browser 5-20, 5-23, 5-48

Panner check box, in Preferences dia log box 5-23parametersin Spect rum Viewer 5-99, 5-100, 5-103inher it ing in Spect rum Viewer 5-100

parametr ic modeling 4-10, 6-207applica t ions 4-10frequency domain based 4-16summary 2-5techniques 4-10t ime domain basedlinear predict ive coding 4-12, 4-13Steiglitz-McBride method 4-15

t ime-domain based 4-11Burg method 6-16covar iance method 6-17modified covar iance method 6-18Yule-Walker method 6-19

paren theses, indica t ing open in terva l xvii

Parks-McClellan method, FIR filt er design 2-22,6-287

par t ia l fract ion 1-42par t ia l fract ion expansion 1-40defined 1-35determin ing with residue 1-41example 1-35

par t ia l fract ion form 1-35, 6-302passbandequ ir ipple 2-9, 2-10group delay 2-11

passband r ipple, set t ing in Filter Designer 5-70passband zoom 5-33Passband Zoom button 5-33pburg 3-6, 3-21, 6-7, 6-239example 3-21

pcov 3-6, 3-22, 6-7, 6-243example 3-23

Peaks but ton , Signa l Browser 5-37per iodic sinc funct ion 6-118S ee also Dir ich let funct ion

per iodogram 3-7modified 3-9

persisten t mouse zooming 5-32phasecomputing with angle 6-15of Four ier t ransform of sequence 1-44of frequency response 1-26viewing in Filt er Viewer 5-91

of t ransfer funct ion est imate 3-15unwrapping 1-27, 6-360

Phase check box, F ilter Viewer 5-86phase delay 1-28, 6-182defined 1-28example 1-29of linear response filter 2-17

phase demodula t ion 6-115

Page 710: MATLAB Signal Processing Toolbox user manual

Index

I-20

phase distor t ionelimina t ingdur ing filt er ing 1-19example 1-20using filtfilt 1-20

in FIR filt er s 1-20nonlinearin IIR filters 1-20

phase modifica t iondata dependent , using >cceps 4-25

phase modula t ion 4-30, 6-237phase response 5-17phase response plot 5-86, 5-91Phase Units pop-up menu, in Prefer ences dia log

box 5-25phase unit s, in Filter Viewer 5-25Play menu item, Signa l Browser 5-46playing a signa l 5-46plotana log prototypes 2-12coherence funct ion 3-16complex cepstrum 4-24DFT 1-44frequency response 1-25magn itude 1-26phase 1-26

group delay 1-29, 5-86, 5-93impu lse response 5-86, 5-94in Filt er Viewer 5-84, 5-86, 5-88, 5-89magn itude response 5-78, 5-86, 5-89modified per iodogram 3-10mult it aper est imate 3-17, 3-18per iodogram 3-7phase delay 1-29phase response 5-86, 5-91power spectra l density 3-11spect ra l density 5-101

step response 5-86, 5-95str ip plot 6-344t iling in Filt er Viewer 5-88t ransfer funct ion 3-15zero-pole 1-30, 5-86, 5-94, 6-385

plug-ins 5-20, 5-30pm 4-30pmcov 3-6, 3-22, 6-7, 6-247example 3-23

p-model. S ee paramet r ic modelingpmtm 3-6, 6-7, 6-251example 3-17

pmusic 3-6, 3-23, 6-7, 6-255pole-zero filt er . S ee IIR filt erpoly 1-33, 1-42poly2ac 6-4, 6-262poly2rc 6-4, 6-263polynomia ldivision 4-33, 6-113mult iplica t ion 6-83roots 1-33stabiliza t ion 6-265

polyphase filt er ing techn iques 1-19polystab 6-9, 6-265power spect ra l density 6-273bias 3-12computa t ion parameters 5-103, 5-104confidence in terva l 3-14defau lt plot 5-102defined 3-5est imat ion by Burg method 3-6, 3-20, 5-104,

6-239est imat ion by covar iance method 3-6, 3-22,

5-105, 6-243est imat ion by FFT method 5-105est imat ion by modified covar iance method 3-6,

6-247

Page 711: MATLAB Signal Processing Toolbox user manual

Index

I-21

est imat ion by mult itaper method 3-6, 3-16,5-105

est imat ion by MUSIC method 3-6, 3-23, 5-106est imat ion by Welch’s method 3-6, 3-10, 5-106est imat ion by Yule-Walker AR method 3-6,

3-19, 5-107, 6-278est imat ion methods 5-103, 5-104in SPTool 5-13normaliza t ion 3-12unit s of 3-11viewing in Spect rum Viewer 5-97, 5-102,

5-104preferencesru lers 5-21saving in Signa l Browser 5-45

preferences filein SPTool 5-31sigprefs.mat 5-31

Prefer ences menu item 5-6, 5-20, 5-30prewarping 6-25Pr in t dia log box 5-45, 5-55, 5-99, 5-108, 5-120,

5-124Pr in t Preview windowHandle Graph ics 5-57, 5-110Signa l Browser 5-45, 5-55, 5-56preferences 5-56, 5-120

Spect rum Viewer 5-99, 5-108, 5-124preferences 5-109

pr in t ingfrom Signa l Browser 5-2, 5-21, 5-22, 5-31, 5-33,

5-38, 5-117from Spect rum Viewer 5-2, 5-21, 5-22, 5-31,

5-33, 5-38, 5-98prola te-spheroida l window 4-4prony 2-5, 4-11, 4-13, 6-8, 6-266Prony’s method 4-13, 6-266modeling 4-13

prototypeBessel filt er 2-11, 6-21But terwor th filt er 2-8, 6-42Chebyshev type I filt er 6-54Chebyshev type II filt er 6-59ellipt ic filter 6-131

PSD. S ee power spect ra l densitypsd. S ee pwelch 6-268ptm 4-30pu lse t ime demodu la t ion 6-115pu lse t ime modula t ion 4-30, 6-237pu lse t ra in genera tor 6-269pu lse t ra insgenera t ing 1-9pulstran 1-9

pu lse width demodula t ion 6-115pu lse width modula t ion 4-30, 6-237pulstran 1-9, 6-2, 6-75, 6-119, 6-121, 6-122, 6-123,

6-124, 6-269, 6-286, 6-346, 6-359pwelch 3-6, 3-10, 6-7, 6-273example 3-12

pwm 4-30pyulear 3-6, 3-20, 6-7, 6-278example 3-20, 3-21

Qqam 4-30quadra tu re amplitude demodu la t ion 6-115quadra tu re amplitude modu la t ion 4-30, 6-237

Rradar applica t ions 4-27radix-2 a lgor ithm 1-45ra ised cosine filt er design 6-171randn xiv

Page 712: MATLAB Signal Processing Toolbox user manual

Index

I-22

random number , genera t ion xivrange nota t ion xviiRange pop-up menu, F ilter Viewer 5-87rc2poly 6-4, 6-283rceps 4-23, 4-25, 6-9, 6-285rea l cepst rum 6-285defined 4-24reconst ruct ing signa l (min imum-phase) 4-25

rebuffer ing 6-33rectangula r window 2-18, 4-2, 6-32rectpuls 6-2, 6-286recu rsive filter . S ee IIR filterreferences 1-46, 3-27, 4-40reflect ion coefficien ts 1-37, 1-39conver t ing from autocorrela t ion sequence

6-14conver t ing from filt er coefficien ts 6-263,

6-283conver t ing to autocor rela t ion sequence 6-282

remez 2-16, 2-22, 6-6, 6-287accessing from Filter Designer 5-73, 5-75compared to firls 2-23filt er character ist ics 6-292for differen t ia tor design 2-26for Hilber t t ransformer design 2-25order est imat ion 6-294weight vector 2-24

Remez exchange a lgor ithm 2-22, 6-287remezord 2-16, 6-6, 6-294accessing from Filter Designer 5-75

resample 6-10, 6-298resampling 4-20, 6-298in FIR filt er ing 1-19S ee also decimat ion , in terpola t ion

residue 1-41, 1-42residue form. S ee par t ia l fract ion formresiduez 1-42, 6-4, 6-302

Rever t panel 5-31r ipple, passband 5-70rlevinson 6-9, 6-305rootsof Bessel filt er 6-21polynomia l 1-33

roots 1-33, 1-42ru ler color 5-21Ruler Color edit box, in Prefer ences dia log box

5-21Ruler Marker pop-up menu, in Preferences dia log

box 5-21ru ler markers 5-21, 5-36ru ler typein Signa l Browser 5-21in Spect rum Viewer 5-21

ru lersbr inging to center 5-35customizing in SPTool 5-20dragging 5-36find ru ler but tons 5-35hor izonta l 5-36hor izonta l mode 5-40in Filt er Viewer 5-26, 5-33in Signa l Browser 5-20, 5-21, 5-23, 5-33in Spect rum Viewer 5-20, 5-21, 5-24, 5-33parameters 5-36posit ioning 5-38preferences 5-21saving measuremen ts 5-37slope 5-36slope mode 5-42t rack 5-36t rack mode 5-41ver t ica l 5-36ver t ica l mode 5-39

Page 713: MATLAB Signal Processing Toolbox user manual

Index

I-23

Rulers check box, in Preferences dia log box 5-23,5-24, 5-26

Ssampling fr equencychanging in SPTool 5-9in SPTool 5-16

Sampling Frequency edit box, in Impor t dialog box5-4, 5-9

Sampling Frequency menu item 5-16sampling ra techanging by non in teger factor 4-20, 6-298changing for ir regu lar ly spaced data 4-22changing with upfirdn 1-19decreasing by integer factor 6-110increasing by in teger factor 6-199

Save Rulers but ton 5-37Save Session menu item 5-6saving changes in SPTool 5-30saving da tafrom Filter Designer 5-79, 5-110from Signa l Browser 5-57

saving da ta , from Filter Designer 5-79, 5-110saving da ta , from Signa l Browser 5-57saving set t ings, in Filt er Viewer 5-86Savitzky-Golayfilt er design 6-309filt er ing 6-311

sawtooth 1-8, 6-2, 6-308sawtooth wave 1-8sca la rfor sta te-space form 1-34represent ing ga in 1-33

Sca le pop-up menu, F ilt er Viewer 5-87Search for P lug-Ins a t sta r t -up check box, in

Prefer ences dia log box 5-30

second-order sect ion formconver t ing from transfer funct ion 6-347conver t ing from zero-pole-ga in 6-379

second-order sect ions 1-42second-order sect ions form 1-36conver t ing from sta te-space form 6-333conver t ing to sta te-space 6-316conver t ing to t ransfer funct ion 6-318conver t ing to zero-pole-ga in 6-320defined 1-36filt er ing 6-322specifying in SPTool 5-12

select ing da ta object s in SPTool 5-15sequenceautocor rela t ion 6-13, 6-14, 6-262

set t ingsrestor ing in SPTool 5-30ru lers 5-21saving in Signal Browser 5-45saving in SPTool 5-31

sgolay 6-309, 6-311sgolayfilt 6-311signa ladding noise 1-6ana lyt ic 4-38, 6-187buffer ing 6-33car r ier 4-29, 6-114complex 5-47cont inuous (ana log) 1-2differ ent ia t ion 2-26discrete (digita l) 1-2genera t ing 1-7impor t ing in to SPTool 5-3, 5-7, 5-8, 5-10linking to spectrum 5-100measuremen ts 5-37measuremen ts in Signa l Browser 5-36message 4-29, 6-236

Page 714: MATLAB Signal Processing Toolbox user manual

Index

I-24

mult ichannel 3-4naming in SPTool 5-16peaks 5-37playing 5-46plot t ing 1-6rebuffer ing 6-33reconst ruct ionfrom DCT coefficient s 4-37minimum phase 4-25, 6-285

represent ingin MATLAB 1-4mult ichannel 1-4single channel 1-4

select ing in Signa l Browser 5-48va lleys 5-37viewing in Signa l Browser 5-17, 5-48S ee also waveform

Signa l Browser 5-2, 5-17, 5-43, 6-328act iva t ing 5-17, 5-43customizing 5-20pr in t ing from 5-23, 5-43, 5-44, 5-54saving da ta to workspace 5-57window 5-44

Signa l Processing Toolbox 1-2signa l typear ray 5-14vector 5-14

sigprefs.mat 5-31sinc 1-10, 6-2, 6-313bandlimited in terpola t ion example 6-314

sinc funct ion 1-10, 6-313and bandlimited in terpola t ion 6-314basic example 1-10defined 1-10

sinusoida l wave 1-8Slepian sequences. S ee discrete prola te

spheroida l sequences

Slope bu t ton , for ru ler s 5-36Slope cont rol 5-38, 5-41sonar applica t ions 4-27sos2ss 1-42, 6-4, 6-316sos2tf 1-42, 6-4, 6-318sos2zp 1-42, 6-4, 6-320specgram 4-27, 6-10, 6-323example 4-27, 6-365

specifica t ion lines 5-78dragging to edit filt er 5-70

specifica t ions for filt er design 2-7spect ra l ana lysis 3-5cross spect ra l density 3-14defined 3-5power spect ra l density 3-5using Spectrum Viewer 5-97

spect ra l density 3-5S ee also power spect ra l density, cross spect ra l

densityspect ra l density plotin Spect rum Viewer 5-101

spect rogram 4-27, 6-323example 4-27, 6-365

spect rumcomput ing in SPTool 5-19impor t ing in to SPTool 5-7, 5-8, 5-13linking to signa l 5-100measuremen ts 5-37measuremen ts in Spect rum Viewer 5-36, 5-101naming in SPTool 5-16peaks 5-37upda t ing in SPTool 5-19va lleys 5-37viewing in Spect rum Viewer 5-97viewing in SPTool 5-19

spect rum type, au to 5-15Spect rum Viewer 5-2, 5-19, 5-97, 6-331

Page 715: MATLAB Signal Processing Toolbox user manual

Index

I-25

act iva t ing 5-19, 5-97changing plot proper t ies 5-102customizing 5-20defau lt plot 5-102pr in t ing from 5-24, 5-97, 5-98, 5-107, 5-108set t ing confidence in terva ls 5-107viewing power spect ra l density plot s 5-102window 5-98

speech processing 4-10, 4-21spline 4-22spt extension 5-6SPTool 5-2, 6-328act iva t ing from Signa l Browser 5-54closing 5-6customizing 5-6, 5-20loading 5-3preferences 5-6window 5-5

sptool command 6-11, 6-328square 1-8, 6-2, 6-332square wave 1-8ss2sos 1-42, 6-4, 6-333ss2tf 1-42, 6-337ss2zp 1-42, 6-4, 6-338stabiliza t ion , polynomia l 6-265standardsCompact Disc 4-20Digita l Audio Tape 4-20

sta r tup t ransien t s 1-22reducing 1-21, 6-149

sta te-space form 1-40, 1-42conver t ing from second-order sect ions 6-316conver t ing from transfer funct ion 6-350conver t ing from zero-pole-ga in 6-383conver t ing to second-order sect ion 6-333conver t ing to zero-pole-ga in 6-338defined 1-34

represen t ing in MATLAB 1-34specifying in SPTool 5-11

sta t ist ica l opera t ions 3-2Stay in Zoom-mode After Zoom check box, in

Preferences dia log box 5-23, 5-24, 5-26,5-27

Steiglit z-McBr ide method 4-15, 6-341step response 5-17viewing in Filt er Viewer 5-95

Step Response check box, F ilt er Viewer 5-86step response plot 5-86, 5-95stmcb 2-5, 4-11, 4-15, 6-9, 6-341stopbanda t tenua t ion , set t ing in Filt er Designer 5-70equ ir ipple 2-10

str ip plot 6-344defined 6-344

strips 6-2, 6-344st ructure, digita l filt erla t t ice 1-37t ransposed direct form II 1-17

subplots 5-84in Filt er Viewer 5-86

subspace th resholds, con trolling in pmusicfunct ion 3-25

svd, in pmusic funct ion 3-25swept -frequency cosine genera tor . S ee chirpsystem ident ifica t ion 4-13system models 1-32and bilinear t ransformat ion 2-44and filt er design funct ions 2-7and frequency t ransformat ion funct ions 2-39

Tt apers, in PSD est imates 3-16taps 2-17

Page 716: MATLAB Signal Processing Toolbox user manual

Index

I-26

text s, rela ted 1-46tf2latc 1-39, 1-42, 6-4, 6-346tf2ss 1-42, 6-4, 6-350tf2zp 1-42, 6-339, 6-352tfe 3-6, 3-14, 6-7, 6-354thresh 3-25t iling 5-88t iling display, in F ilter Viewer 5-26t iling preferences, in F ilt er Viewer 5-20Time Response Length edit box, in Preferences

dia log box 5-25t ime response length , in F ilter Viewer 5-25t ime vector 1-6returned by modulate 4-30

t ime-dependent Four ier t ransform 4-27t ime-domain ana lysis, in Filter Viewer 5-84t ime-domain based modeling. S ee paramet r ic

modelingtoolboxCon trol Systems Toolbox 1-35, 6-198, 6-340Image Processing Toolbox 6-109, 6-190, 6-235Signa l Processing Toolbox 1-2Symbolic Math Toolbox 6-21System Iden t ifica t ion Toolbox 6-357

Track but ton , for ru lers 5-36, 5-38, 5-40tr ansfer funct ion 1-32, 1-35, 1-40, 1-42coefficients 1-15, 5-79defined 1-15der iva t ion 1-15est imate from input and ou tput 6-354est imat ing using Welch’s method 3-14expor t ing from SPTool 5-79factored form 1-33for ana log filt er 1-41represent ing in MATLAB 1-32zero-pole-ga in form 1-33

tr ansfer funct ion form

conver t ing from second-order sect ions 6-318conver t ing to la t t ice 6-346conver t ing to second-order sect ions 6-347conver t ing to sta te-space 6-350specifying in SPTool 5-11

t ransform 4-34ch irp z-t ransform (CZT) 4-34, 6-105discrete cosine 6-108discrete Four ier 1-43Hilber t 4-38, 6-187inverse discrete cosine 4-36, 6-190inverse discrete Four ier 6-192

t ransformat ionsbetween system models 1-41bilinear 2-43, 6-25fr equency 2-38, 6-220, 6-223, 6-225, 6-227

t ransit ion band 2-23t ransposed direct form II 6-145in it ia l condit ions 6-150

triang 4-2, 6-8, 6-358compared to bartlett 6-20example 4-2

t r iangula r window 6-358tripuls 6-2, 6-359two-dimensiona l opera t ionsau tocor r ela t ion 6-372convolu t ion 6-84obta in ing subsect ion 6-84

cross-cor rela t ion 6-372discrete Four ier t ransform 1-45, 6-141filt er ing 6-148inverse discrete Four ier t ransform 1-45, 6-193

two-dimensiona l signa l processing, with fft2 andifft2 1-45

Page 717: MATLAB Signal Processing Toolbox user manual

Index

I-27

Uun it circle 6-265un it impulse funct ion 1-7un it r amp funct ion 1-7un it sample, mult ichannel represen ta t ion 1-7un it step funct ion 1-7un it s of power spect ra l density (PSD) funct ion

3-11unwrap 1-27, 6-3, 6-360Update but ton 5-19, 5-97upfirdn 1-19, 4-22, 6-10, 6-361

VValleys but ton , Signa l Browser 5-37var ianceof cor rela t ion sequence est imate 3-4of power spect rum est imate 3-8

vco 4-29, 4-31, 6-10, 6-365vectorda ta 1-4display, in Signa l Browser 5-50for filt er coefficien ts 1-16, 1-32frequency 2-24, 6-157, 6-160, 6-287, 6-376in SPTool 5-14indexing xvii, 1-15magnitude 2-24, 6-157, 6-160, 6-376t ime 1-6weight ing 2-24, 6-167, 6-288

Ver t ica l bu t ton , for ru lers 5-36, 5-38View bu t ton 5-17, 5-19voltage cont rolled oscilla tor 4-31, 6-365

Wwaveformaper iodic 1-8

chirp 1-9chirp, example 1-9from sinusoids 1-6genera t ing with diric funct ion 1-11genera t ing with pulstran 1-9genera t ing with sinc funct ion 1-10linea r swept -frequency cosine. S ee ch irpper iodic 1-7sawtooth 1-8, 6-308example 1-8

sinusoida l pu lse, Gaussian -modu la ted 1-8square 1-8, 6-332t r iangle 6-308

Welch’s method 3-6bias 3-12compared to the Burg method 3-22compared to the MTM method 3-19compared to the Yule-Walker AR method 3-20for cross spectr a l density est imat ion 3-14,

6-102for nonparamet r ic system ident ifica t ion 3-14for power spect ra l density est imat ion 3-5, 3-10,

6-81, 6-275in Spect rum Viewer 5-106normaliza t ion 3-12

white noise 1-6windowapplied to per iodogram 3-9Bar t let t 4-2, 6-20Blackman 4-4, 6-30boxcar 2-18Chebyshev 4-9, 6-64for filt er design 2-18genera lized cosine 4-4Hamming 2-20, 4-4, 6-185Hanning 4-4, 6-186Kaiser 4-4, 6-210

Page 718: MATLAB Signal Processing Toolbox user manual

Index

I-28

rectangula r 2-18, 6-32shapes, overview 4-2specifying for fir1 2-21tr iangu la r 6-358

window methodFIR filt er design 2-18mult iband design 2-21single band design 2-20

window method, FIR filt er designbandpass configura t ion 6-152bandstop configu ra t ion 6-152highpass configura t ion 6-152lowpass configura t ion 6-152

Workspace Conten ts list , in Impor t dia log box5-7

workspace, loading var iables from 5-7

XX Label edit box, in Preferences dia log box 5-23xcorr 3-2, 6-7, 6-367and parametr ic modeling 4-12

xcorr2 6-7, 6-372xcov 3-2, 6-7, 6-373

YY Label edit box, in Preferences dia log box 5-23yulewalk 2-5, 2-13, 6-5, 6-376example 2-14

Yule-Walker AR method 3-5, 3-6, 3-19compared to Welch’s method 3-20defined 3-19example 3-20, 3-21

Yule-Walker AR method, in Spectrum Viewer5-107

Yule-Walker equa t ions 2-13

Yule-Walker filt er design 6-376

Zzero frequency component , center ing with fftshift

1-45zero-order hold. S ee averaging filterzero-phase filter ing 6-149zero-pole ana lysisexample 1-30zero-pole plot s 6-385

zero-pole ga in 1-42zero-pole plot 5-86, 5-94viewing in Filt er Viewer 5-94

zero-pole-ga in form 1-40conver t ing from second-order sect ions 6-320conver t ing from sta te-space form 6-338conver t ing to second-order sect ion 6-379conver t ing to sta te-space 6-383defined 1-33represent ing in MATLAB 1-33specifying in SPTool 5-11

zeros and poles 5-17in t ransfer funct ion 1-33mult iplicity of 5-71

Zeros and Poles check box, F ilt er Viewer 5-86zoom con trolsin Filt er Designer 5-31in Filt er Viewer 5-31in Signa l Browser 5-31in Spect rum Viewer 5-31in SPTool 5-31

Zoom In-X bu t ton 5-32Zoom In-Y bu t ton 5-32Zoom Out-X bu t ton 5-32Zoom Out-Y bu t ton 5-32zoom per sistence 5-32

Page 719: MATLAB Signal Processing Toolbox user manual

Index

I-29

changing 5-32in Filt er Designer 5-27in Filt er Viewer 5-26, 5-87in Signa l Browser 5-23, 5-46in Spect rum Viewer 5-24

zoomingin Filt er Designer 5-77in Filt er Viewer 5-87in Signa l Browser 5-46in Spect rum Viewer 5-103one-t ime 5-32persisten t 5-32

zp2sos 1-42, 6-4, 6-379zp2ss 1-42, 6-4, 6-383zp2tf 1-42, 6-384zplane 1-30, 6-3, 6-385z-t ransform 1-15, 1-32ch irp z-t ransform (CZT) 4-34, 6-105discrete Four ier t ransform 1-43

Page 720: MATLAB Signal Processing Toolbox user manual

Index

I-30